annotate Plugins/Input/vorbis/http.c @ 553:82346a6312c2 trunk

[svn] make WMA plugin strings translatable
author nenolod
date Wed, 01 Feb 2006 13:09:00 -0800
parents 4e1d41a93cb3
children 3787176f9875
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 * Based on XMMS:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 * (at your option) any later version.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22 #ifdef HAVE_CONFIG_H
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 # include "config.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 #include <glib/gi18n.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28 #include <gtk/gtk.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 #include <fcntl.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33 #include <unistd.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 #include <errno.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 #include <netinet/in.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 #include <arpa/inet.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37 #include <netdb.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38 #include <sys/types.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 #include <sys/socket.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 #include <sys/time.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42 #include "vorbis.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43 #include "http.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 #include "libaudacious/util.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 #include "audacious/plugin.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48 #define min(x,y) ((x)<(y)?(x):(y))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 #define min3(x,y,z) (min(x,y)<(z)?min(x,y):(z))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 #define min4(x,y,z,w) (min3(x,y,z)<(w)?min3(x,y,z):(w))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 static gchar *ice_name = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 static gboolean prebuffering, going, eof = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 static gint sock, rd_index, wr_index, buffer_length, prebuffer_length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56 static guint64 buffer_read = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 static gchar *buffer;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 static GThread *thread;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 static GtkWidget *error_dialog = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 extern vorbis_config_t vorbis_cfg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 extern InputPlugin vorbis_ip;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 extern int vorbis_playing;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65 static VFSFile *output_file = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 #define BASE64_LENGTH(len) (4 * (((len) + 2) / 3))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69 /* Encode the string S of length LENGTH to base64 format and place it
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 to STORE. STORE will be 0-terminated, and must point to a writable
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 buffer of at least 1+BASE64_LENGTH(length) bytes. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 base64_encode(const gchar * s, gchar * store, gint length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 /* Conversion table. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 static gchar tbl[64] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 'w', 'x', 'y', 'z', '0', '1', '2', '3',
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 '4', '5', '6', '7', '8', '9', '+', '/'
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 gint i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 guchar *p = (guchar *) store;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89 /* Transform the 3x8 bits to 4x6 bits, as required by base64. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 for (i = 0; i < length; i += 3) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 *p++ = tbl[s[0] >> 2];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 *p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 *p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 *p++ = tbl[s[2] & 0x3f];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 s += 3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 /* Pad the result if necessary... */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 if (i == length + 1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 *(p - 1) = '=';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 else if (i == length + 2)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 *(p - 1) = *(p - 2) = '=';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 /* ...and zero-terminate it. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 *p = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 /* Create the authentication header contents for the `Basic' scheme.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107 This is done by encoding the string `USER:PASS' in base64 and
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108 prepending `HEADER: Basic ' to it. */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 static gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 basic_authentication_encode(const gchar * user,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 const gchar * passwd, const gchar * header)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 gchar *t1, *t2, *res;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114 gint len1 = strlen(user) + 1 + strlen(passwd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 gint len2 = BASE64_LENGTH(len1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 t1 = g_strdup_printf("%s:%s", user, passwd);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118 t2 = g_malloc0(len2 + 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 base64_encode(t1, t2, len1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120 res = g_strdup_printf("%s: Basic %s\r\n", header, t2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121 g_free(t2);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 g_free(t1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 return res;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 parse_url(const gchar * url, gchar ** user, gchar ** pass,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 gchar ** host, int *port, gchar ** filename)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 gchar *h, *p, *pt, *f, *temp, *ptr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 temp = g_strdup(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134 ptr = temp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136 if (!strncasecmp("http://", ptr, 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 ptr += 7;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 h = strchr(ptr, '@');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 f = strchr(ptr, '/');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140 if (h != NULL && (!f || h < f)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 *h = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 p = strchr(ptr, ':');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 if (p != NULL && p < h) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 *p = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 p++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 *pass = g_strdup(p);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 *pass = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150 *user = g_strdup(ptr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151 h++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 ptr = h;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 *user = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 *pass = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 h = ptr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 pt = strchr(ptr, ':');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160 if (pt != NULL && (f == NULL || pt < f)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 *pt = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 *port = atoi(pt + 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 if (f)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 *f = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167 *port = 80;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169 *host = g_strdup(h);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 if (f)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 *filename = g_strdup(f + 1);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 *filename = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 g_free(temp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179 vorbis_http_close(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 going = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 g_thread_join(thread);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 g_free(ice_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185 ice_name = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189 static gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 http_used(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192 if (wr_index >= rd_index)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193 return wr_index - rd_index;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 return buffer_length - (rd_index - wr_index);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197 static gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198 http_free(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 if (rd_index > wr_index)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201 return (rd_index - wr_index) - 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202 return (buffer_length - (wr_index - rd_index)) - 1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 http_wait_for_data(gint bytes)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 while ((prebuffering || http_used() < bytes) && !eof && going
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 && vorbis_playing)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213 static void
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 show_error_message(gchar * error)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 if (!error_dialog) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 GDK_THREADS_ENTER();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 error_dialog = xmms_show_message(_("Error"), error, _("Ok"), FALSE,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 NULL, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 g_signal_connect(G_OBJECT(error_dialog),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 "destroy",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 G_CALLBACK(gtk_widget_destroyed), &error_dialog);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223 GDK_THREADS_LEAVE();
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 vorbis_http_read(gpointer data, gint length)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 gint len, cnt, off = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232 http_wait_for_data(length);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 if (!going && !vorbis_playing)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 len = min(http_used(), length);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 while (len && http_used()) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 cnt = min3(len, buffer_length - rd_index, http_used());
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 if (output_file)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 vfs_fwrite(buffer + rd_index, 1, cnt, output_file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 memcpy((gchar *) data + off, buffer + rd_index, cnt);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 rd_index = (rd_index + cnt) % buffer_length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245 buffer_read += cnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 len -= cnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 off += cnt;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 return off;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 static gboolean
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 http_check_for_data(void)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 fd_set set;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 struct timeval tv;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 gint ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 tv.tv_sec = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261 tv.tv_usec = 20000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 FD_ZERO(&set);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 FD_SET(sock, &set);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 ret = select(sock + 1, &set, NULL, NULL, &tv);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 if (ret > 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 return TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 return FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270 gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 vorbis_http_read_line(gchar * buf, gint size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273 gint i = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
275 while (going && i < size - 1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
276 if (http_check_for_data()) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
277 if (read(sock, buf + i, 1) <= 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
278 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 if (buf[i] == '\n')
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281 if (buf[i] != '\r')
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 i++;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285 if (!going)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287 buf[i] = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 return i;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 static gpointer
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
292 http_buffer_loop(gpointer arg)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294 gchar line[1024], *user, *pass, *host, *filename,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295 *status, *url, *temp, *file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296 gchar *chost;
377
4e1d41a93cb3 [svn] Start caring about pointer signedness.
chainsaw
parents: 61
diff changeset
297 gint cnt, written, error, port, cport;
4e1d41a93cb3 [svn] Start caring about pointer signedness.
chainsaw
parents: 61
diff changeset
298 guint err_len;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299 gboolean redirect;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 fd_set set;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 struct hostent *hp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 struct sockaddr_in address;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
303 struct timeval tv;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
304
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
305 url = (gchar *) arg;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
306 do {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307 redirect = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309 g_strstrip(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
310
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
311 parse_url(url, &user, &pass, &host, &port, &filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
312
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 if ((!filename || !*filename) && url[strlen(url) - 1] != '/')
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314 temp = g_strconcat(url, "/", NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316 temp = g_strdup(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317 g_free(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318 url = temp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320 chost = vorbis_cfg.use_proxy ? vorbis_cfg.proxy_host : host;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 cport = vorbis_cfg.use_proxy ? vorbis_cfg.proxy_port : port;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323 sock = socket(AF_INET, SOCK_STREAM, 0);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324 fcntl(sock, F_SETFL, O_NONBLOCK);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325 address.sin_family = AF_INET;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 status = g_strdup_printf(_("LOOKING UP %s"), chost);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 vorbis_ip.set_info_text(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329 g_free(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 if (!(hp = gethostbyname(chost))) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 status = g_strdup_printf(_("Couldn't look up host %s"), chost);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 show_error_message(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334 g_free(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336 vorbis_ip.set_info_text(NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340 if (!eof) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 memcpy(&address.sin_addr.s_addr, *(hp->h_addr_list),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342 sizeof(address.sin_addr.s_addr));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 address.sin_port = g_htons(cport);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345 status = g_strdup_printf(_("CONNECTING TO %s:%d"), chost, cport);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346 vorbis_ip.set_info_text(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 g_free(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348 if (connect
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 (sock, (struct sockaddr *) &address,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 sizeof(struct sockaddr_in)) == -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351 if (errno != EINPROGRESS) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352 status =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 g_strdup_printf(_("Couldn't connect to host %s"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354 chost);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 show_error_message(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 g_free(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 vorbis_ip.set_info_text(NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 while (going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363 tv.tv_sec = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364 tv.tv_usec = 10000;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 FD_ZERO(&set);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366 FD_SET(sock, &set);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 if (select(sock + 1, NULL, &set, NULL, &tv) > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368 err_len = sizeof(error);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
369 getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &err_len);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370 if (error) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
371 status =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
372 g_strdup_printf(_
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373 ("Couldn't connect to host %s"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 chost);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 show_error_message(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
376 g_free(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378 vorbis_ip.set_info_text(NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379 eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
380
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
381 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 if (!eof) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386 gchar *auth = NULL, *proxy_auth = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 if (user && pass)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389 auth =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 basic_authentication_encode(user, pass,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 "Authorization");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393 if (vorbis_cfg.use_proxy) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394 file = g_strdup(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 if (vorbis_cfg.proxy_use_auth && vorbis_cfg.proxy_user
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396 && vorbis_cfg.proxy_pass) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 proxy_auth =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398 basic_authentication_encode(vorbis_cfg.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 proxy_user,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400 vorbis_cfg.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 proxy_pass,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 "Proxy-Authorization");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406 file = g_strconcat("/", filename, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
407 temp = g_strdup_printf("GET %s HTTP/1.0\r\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
408 "Host: %s\r\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
409 "User-Agent: %s/%s\r\n"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 "%s%s\r\n",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411 file, host, PACKAGE, VERSION,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412 proxy_auth ? proxy_auth : "",
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 auth ? auth : "");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414 g_free(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
415 if (proxy_auth)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
416 g_free(proxy_auth);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417 if (auth)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 g_free(auth);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
419 write(sock, temp, strlen(temp));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
420 g_free(temp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
421 vorbis_ip.set_info_text(_("CONNECTED: WAITING FOR REPLY"));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422 while (going && !eof) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
423 if (http_check_for_data()) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
424 if (vorbis_http_read_line(line, 1024)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
425 status = strchr(line, ' ');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
426 if (status) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
427 if (status[1] == '2')
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
429 else if (status[1] == '3'
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
430 && status[2] == '0'
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431 && status[3] == '2') {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
432 while (going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
433 if (http_check_for_data()) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434 if ((cnt =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435 vorbis_http_read_line
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436 (line, 1024)) != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 if (!cnt)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
438 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
439 if (!strncmp
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440 (line, "Location:", 9)) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441 g_free(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442 url = g_strdup(line + 10);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
446 eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 vorbis_ip.set_info_text(NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452 redirect = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456 status =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457 g_strdup_printf(_
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
458 ("Couldn't connect to host %s\nServer reported: %s"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459 chost, status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
460 show_error_message(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
461 g_free(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
464 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
466 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
467 eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
468 vorbis_ip.set_info_text(NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
473 while (going && !redirect) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
474 if (http_check_for_data()) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475 if ((cnt = vorbis_http_read_line(line, 1024)) != -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476 if (!cnt)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
478 if (!strncmp(line, "ice-name:", 9))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
479 ice_name = g_strdup(line + 9);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
481 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
482 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
483 eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
484 vorbis_ip.set_info_text(NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
485 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
486 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
487 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
488 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
490 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
491
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
492 if (redirect) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
493 if (output_file) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
494 vfs_fclose(output_file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
495 output_file = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
496 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
497 close(sock);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
498 g_free(user);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
499 g_free(pass);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
500 g_free(host);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
501 g_free(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
502 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
503 } while (redirect);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
504
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
505 if (vorbis_cfg.save_http_stream) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506 gchar *output_name;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
507 file = vorbis_http_get_title(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
508 output_name = file;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
509 if (!strncasecmp(output_name, "http://", 7))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
510 output_name += 7;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
511 temp = strrchr(output_name, '.');
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
512 if (temp && !strcasecmp(temp, ".ogg"))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
513 *temp = '\0';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
514
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
515 while ((temp = strchr(output_name, '/')))
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
516 *temp = '_';
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
517 output_name =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
518 g_strdup_printf("%s/%s.ogg", vorbis_cfg.save_http_path,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
519 output_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
520
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
521 g_free(file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
522
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
523 output_file = vfs_fopen(output_name, "wb");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
524 g_free(output_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
525 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
526
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
527 while (going) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
528
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
529 if (!http_used() && !vorbis_ip.output->buffer_playing())
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
530 prebuffering = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
531 if (http_free() > 0 && !eof) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
532 if (http_check_for_data()) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
533 cnt = min(http_free(), buffer_length - wr_index);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
534 if (cnt > 1024)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
535 cnt = 1024;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
536 written = read(sock, buffer + wr_index, cnt);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
537 if (written <= 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
538 eof = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
539 if (prebuffering) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
540 prebuffering = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
541
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
542 vorbis_ip.set_info_text(NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
543 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
544
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
545 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
546 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
547 wr_index = (wr_index + written) % buffer_length;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
548 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
549
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
550 if (prebuffering) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
551 if (http_used() > prebuffer_length) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
552 prebuffering = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
553 vorbis_ip.set_info_text(NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
554 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
555 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
556 status =
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
557 g_strdup_printf(_("PRE-BUFFERING: %dKB/%dKB"),
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
558 http_used() / 1024,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
559 prebuffer_length / 1024);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
560 vorbis_ip.set_info_text(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
561 g_free(status);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
562 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
563
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
564 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
565 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
566 else
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
567 xmms_usleep(10000);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
568
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
569 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
570 if (output_file) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
571 vfs_fclose(output_file);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
572 output_file = NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
573 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
574 close(sock);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
575
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
576
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
577 g_free(user);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
578 g_free(pass);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
579 g_free(host);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
580 g_free(filename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
581 g_free(buffer);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
582 g_free(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
583
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
584 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
585 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
586
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
587 gint
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
588 vorbis_http_open(const gchar * _url)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
589 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
590 gchar *url;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
591
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
592 url = g_strdup(_url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
593
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
594 rd_index = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
595 wr_index = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
596 buffer_length = vorbis_cfg.http_buffer_size * 1024;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
597 prebuffer_length = (buffer_length * vorbis_cfg.http_prebuffer) / 100;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
598 buffer_read = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
599 prebuffering = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
600 going = TRUE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
601 eof = FALSE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
602 buffer = g_malloc(buffer_length);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
603
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
604 thread = g_thread_create(http_buffer_loop, url, TRUE, NULL);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
605
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
606 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
607 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
608
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
609 gchar *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
610 vorbis_http_get_title(const gchar * url)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
611 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
612 gchar *url_basename;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
613
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
614 if (ice_name)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
615 return g_strdup(ice_name);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
616
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
617 url_basename = g_path_get_basename(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
618
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
619 if (strlen(url_basename) > 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
620 return url_basename;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
621
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
622 g_free(url_basename);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
623
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
624 return g_strdup(url);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
625 }