Mercurial > audlegacy-plugins
annotate src/daap/xmms2-daap/daap_conn.c @ 3198:83b1a4e5f453
alsa-ng: Keep mixer open even when playback stopped.
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Wed, 22 Jul 2009 16:42:16 -0400 |
parents | 7b3290336f3b |
children |
rev | line source |
---|---|
1407
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
1 /** @file daap_conn.c |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
2 * Manages the connection to a DAAP server. |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
3 * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
4 * Copyright (C) 2006-2007 XMMS2 Team |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
5 * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
7 * modify it under the terms of the GNU General Public License |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
8 * as published by the Free Software Foundation; either version 2 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
9 * of the License, or (at your option) any later version. |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
10 * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
15 */ |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
16 #include <string.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
17 #include <stdio.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
18 #include <stdlib.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
19 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
20 #include <glib.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
21 #include <glib/gprintf.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
22 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
23 #include <sys/types.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
24 #include <sys/socket.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
25 #include <sys/select.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
26 #include <sys/time.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
27 #include <netinet/in.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
28 #include <netinet/tcp.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
29 #include <arpa/inet.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
30 #include <netdb.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
31 #include <fcntl.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
32 #include <unistd.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
33 #include <errno.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
34 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
35 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
36 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
37 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
38 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
39 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
40 #include "cc_handlers.h" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
41 #include "daap_md5.h" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
42 #include "daap_conn.h" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
43 #include "daap_util.h" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
44 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
45 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
46 GIOChannel * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
47 daap_open_connection (gchar *host, gint port) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
48 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
49 gint ai_status; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
50 gint sockfd; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
51 struct sockaddr_in server; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
52 struct addrinfo *ai_hint, *ai_result; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
53 GIOChannel *sock_chan; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
54 GError *err = NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
55 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
56 sockfd = socket (AF_INET, SOCK_STREAM, 0); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
57 if (sockfd == -1) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
58 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
59 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
60 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
61 sock_chan = g_io_channel_unix_new (sockfd); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
62 if (!g_io_channel_get_close_on_unref (sock_chan)) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
63 g_io_channel_set_close_on_unref (sock_chan, TRUE); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
64 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
65 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
66 g_io_channel_set_flags (sock_chan, G_IO_FLAG_NONBLOCK, &err); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
67 if (NULL != err) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
68 g_print ("Error setting nonblock flag: %s\n", err->message); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
69 g_io_channel_unref (sock_chan); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
70 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
71 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
72 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
73 /* call getaddrinfo() to convert a hostname to ip */ |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
74 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
75 ai_hint = g_new0 (struct addrinfo, 1); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
76 /* FIXME sometime in the future, we probably want to append |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
77 * " | {A,P}F_INET6" for IPv6 support */ |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
78 ai_hint->ai_family = AF_INET; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
79 ai_hint->ai_protocol = PF_INET; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
80 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
81 while ((ai_status = getaddrinfo (host, NULL, ai_hint, &ai_result))) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
82 if (ai_status != EAI_AGAIN) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
83 g_print ("Error with getaddrinfo(): %s", gai_strerror (ai_status)); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
84 g_io_channel_unref (sock_chan); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
85 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
86 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
87 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
88 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
89 memset (&server, 0, sizeof (struct sockaddr_in)); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
90 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
91 server.sin_addr = ((struct sockaddr_in *) ai_result->ai_addr)->sin_addr; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
92 server.sin_family = AF_INET; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
93 server.sin_port = htons (port); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
94 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
95 g_free (ai_hint); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
96 freeaddrinfo (ai_result); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
97 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
98 while (42) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
99 fd_set fds; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
100 struct timeval tmout; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
101 gint sret; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
102 gint err = 0; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
103 guint errsize = sizeof (err); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
104 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
105 tmout.tv_sec = 3; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
106 tmout.tv_usec = 0; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
107 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
108 sret = connect (sockfd, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
109 (struct sockaddr *) &server, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
110 sizeof (struct sockaddr_in)); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
111 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
112 if (sret == 0) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
113 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
114 } else if (sret == -1 && errno != EINPROGRESS) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
115 g_print ("connect says: %s", strerror (errno)); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
116 g_io_channel_unref (sock_chan); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
117 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
118 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
119 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
120 FD_ZERO (&fds); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
121 FD_SET (sockfd, &fds); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
122 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
123 sret = select (sockfd + 1, NULL, &fds, NULL, &tmout); |
1448 | 124 if (sret <= 0 ) { |
1407
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
125 g_io_channel_unref (sock_chan); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
126 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
127 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
128 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
129 /** Haha, lol lol ololo sockets in POSIX */ |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
130 if (getsockopt (sockfd, SOL_SOCKET, SO_ERROR, &err, &errsize) < 0) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
131 g_io_channel_unref (sock_chan); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
132 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
133 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
134 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
135 if (err != 0) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
136 g_print ("Connect call failed!"); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
137 g_io_channel_unref (sock_chan); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
138 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
139 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
140 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
141 if (FD_ISSET (sockfd, &fds)) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
142 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
143 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
144 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
145 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
146 g_io_channel_set_encoding (sock_chan, NULL, &err); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
147 if (NULL != err) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
148 g_print ("Error setting encoding: %s\n", err->message); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
149 g_io_channel_unref (sock_chan); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
150 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
151 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
152 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
153 return sock_chan; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
154 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
155 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
156 gchar * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
157 daap_generate_request (const gchar *path, gchar *host, gint request_id) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
158 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
159 gchar *req; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
160 gint8 hash[33]; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
161 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
162 memset (hash, 0, 33); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
163 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
164 daap_hash_generate (DAAP_VERSION, (guchar *) path, 2, (guchar *) hash, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
165 request_id); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
166 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
167 req = g_strdup_printf ("GET %s %s\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
168 "Host: %s\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
169 "Accept: */*\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
170 "User-Agent: %s\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
171 "Accept-Language: en-us, en;q=5.0\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
172 "Client-DAAP-Access-Index: 2\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
173 "Client-DAAP-Version: 3.0\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
174 "Client-DAAP-Validation: %s\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
175 "Client-DAAP-Request-ID: %d\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
176 "Connection: close\r\n" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
177 "\r\n", |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
178 path, HTTP_VER_STRING, host, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
179 USER_AGENT, hash, request_id); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
180 return req; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
181 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
182 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
183 void |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
184 daap_send_request (GIOChannel *sock_chan, gchar *request) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
185 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
186 gint n_bytes_to_send; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
187 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
188 n_bytes_to_send = strlen (request); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
189 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
190 write_buffer_to_channel (sock_chan, request, n_bytes_to_send); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
191 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
192 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
193 void |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
194 daap_receive_header (GIOChannel *sock_chan, gchar **header) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
195 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
196 guint n_total_bytes_recvd = 0; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
197 gsize linelen; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
198 gchar *response, *recv_line; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
199 GIOStatus io_stat; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
200 GError *err = NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
201 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
202 if (NULL != header) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
203 *header = NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
204 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
205 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
206 response = (gchar *) g_malloc0 (sizeof (gchar) * MAX_HEADER_LENGTH); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
207 if (NULL == response) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
208 g_print ("Error: couldn't allocate memory for response.\n"); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
209 return; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
210 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
211 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
212 /* read data from the io channel one line at a time, looking for |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
213 * the end of the header */ |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
214 do { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
215 io_stat = g_io_channel_read_line (sock_chan, &recv_line, &linelen, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
216 NULL, &err); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
217 if (io_stat == G_IO_STATUS_ERROR) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
218 g_print ("Error reading from channel: %s\n", err->message); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
219 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
220 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
221 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
222 if (NULL != recv_line) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
223 memcpy (response+n_total_bytes_recvd, recv_line, linelen); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
224 n_total_bytes_recvd += linelen; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
225 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
226 if (strcmp (recv_line, "\r\n") == 0) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
227 g_free (recv_line); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
228 if (NULL != header) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
229 *header = (gchar *) g_malloc0 (sizeof (gchar) * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
230 n_total_bytes_recvd); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
231 if (NULL == *header) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
232 g_print ("error: couldn't allocate header\n"); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
233 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
234 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
235 memcpy (*header, response, n_total_bytes_recvd); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
236 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
237 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
238 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
239 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
240 g_free (recv_line); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
241 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
242 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
243 if (io_stat == G_IO_STATUS_EOF) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
244 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
245 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
246 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
247 if (n_total_bytes_recvd >= MAX_HEADER_LENGTH) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
248 g_print ("Warning: Maximum header size reached without finding " |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
249 "end of header; bailing.\n"); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
250 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
251 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
252 } while (TRUE); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
253 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
254 g_free (response); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
255 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
256 if (sock_chan) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
257 g_io_channel_flush (sock_chan, &err); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
258 if (NULL != err) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
259 g_print ("Error flushing buffer: %s\n", err->message); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
260 return; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
261 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
262 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
263 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
264 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
265 cc_data_t * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
266 daap_handle_data (GIOChannel *sock_chan, gchar *header) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
267 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
268 cc_data_t * retval; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
269 gint response_length; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
270 gchar *response_data; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
271 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
272 response_length = get_data_length (header); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
273 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
274 if (BAD_CONTENT_LENGTH == response_length) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
275 g_print ("warning: Header does not contain a \""CONTENT_LENGTH |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
276 "\" parameter.\n"); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
277 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
278 } else if (0 == response_length) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
279 g_print ("warning: "CONTENT_LENGTH" is zero, most likely the result of " |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
280 "a bad request.\n"); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
281 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
282 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
283 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
284 response_data = (gchar *) g_malloc0 (sizeof (gchar) * response_length); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
285 if (NULL == response_data) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
286 g_print ("error: could not allocate response memory\n"); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
287 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
288 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
289 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
290 read_buffer_from_channel (sock_chan, response_data, response_length); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
291 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
292 retval = cc_handler (response_data, response_length); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
293 g_free (response_data); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
294 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
295 return retval; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
296 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
297 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
298 gint |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
299 get_data_length (gchar *header) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
300 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
301 gint len; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
302 gchar *content_length; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
303 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
304 content_length = strstr (header, CONTENT_LENGTH); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
305 if (NULL == content_length) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
306 len = BAD_CONTENT_LENGTH; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
307 } else { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
308 content_length += strlen (CONTENT_LENGTH); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
309 len = atoi (content_length); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
310 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
311 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
312 return len; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
313 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
314 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
315 gint |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
316 get_server_status (gchar *header) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
317 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
318 gint status; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
319 gchar *server_status; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
320 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
321 server_status = strstr (header, HTTP_VER_STRING); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
322 if (NULL == server_status) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
323 status = UNKNOWN_SERVER_STATUS; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
324 } else { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
325 server_status += strlen (HTTP_VER_STRING" "); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
326 status = atoi (server_status); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
327 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
328 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
329 return status; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
330 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
331 |