Mercurial > audlegacy-plugins
annotate src/flac112/http.c @ 104:4b31176c198a trunk
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
author | nenolod |
---|---|
date | Mon, 23 Oct 2006 19:55:09 -0700 |
parents | |
children |
rev | line source |
---|---|
104
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
1 /* XMMS - Cross-platform multimedia player |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
2 * Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
3 * |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
7 * (at your option) any later version. |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
8 * |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
12 * GNU General Public License for more details. |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
13 * |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
15 * along with this program; if not, write to the Free Software |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
17 */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
18 /* modified for FLAC support by Steven Richman (2003) */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
19 #include <sys/types.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
20 #include <sys/socket.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
21 #include <sys/time.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
22 #include <netinet/in.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
23 #include <arpa/inet.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
24 #include <netdb.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
25 #include <glib.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
26 #include <string.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
27 #include <fcntl.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
28 #include <unistd.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
29 #include <errno.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
30 #include <stdio.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
31 #include <stdlib.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
32 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
33 #include <audacious/plugin.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
34 #include <audacious/util.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
35 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
36 #ifdef HAVE_CONFIG_H |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
37 #include <config.h> |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
38 #endif |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
39 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
40 #include "configure.h" |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
41 #include "plugin_common/locale_hack.h" |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
42 #include "FLAC/format.h" |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
43 #include "plugin.h" |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
44 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
45 #define min(x,y) ((x)<(y)?(x):(y)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
46 #define min3(x,y,z) (min(x,y)<(z)?min(x,y):(z)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
47 #define min4(x,y,z,w) (min3(x,y,z)<(w)?min3(x,y,z):(w)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
48 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
49 static gchar *icy_name = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
50 static gint icy_metaint = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
51 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
52 extern InputPlugin flac_ip; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
53 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
54 #undef DEBUG_UDP |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
55 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
56 /* Static udp channel functions */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
57 static int udp_establish_listener (gint *sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
58 static int udp_check_for_data(gint sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
59 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
60 static char *flac_http_get_title(char *url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
61 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
62 static gboolean prebuffering, going, eof = FALSE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
63 static gint sock, rd_index, wr_index, buffer_length, prebuffer_length; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
64 static guint64 buffer_read = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
65 static gchar *buffer; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
66 static guint64 offset; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
67 static GThread *thread; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
68 static GtkWidget *error_dialog = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
69 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
70 static FILE *output_file = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
71 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
72 #define BASE64_LENGTH(len) (4 * (((len) + 2) / 3)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
73 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
74 /* Encode the string S of length LENGTH to base64 format and place it |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
75 to STORE. STORE will be 0-terminated, and must point to a writable |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
76 buffer of at least 1+BASE64_LENGTH(length) bytes. */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
77 static void base64_encode (const gchar *s, gchar *store, gint length) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
78 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
79 /* Conversion table. */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
80 static gchar tbl[64] = { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
81 'A','B','C','D','E','F','G','H', |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
82 'I','J','K','L','M','N','O','P', |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
83 'Q','R','S','T','U','V','W','X', |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
84 'Y','Z','a','b','c','d','e','f', |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
85 'g','h','i','j','k','l','m','n', |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
86 'o','p','q','r','s','t','u','v', |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
87 'w','x','y','z','0','1','2','3', |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
88 '4','5','6','7','8','9','+','/' |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
89 }; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
90 gint i; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
91 guchar *p = (guchar *)store; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
92 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
93 /* Transform the 3x8 bits to 4x6 bits, as required by base64. */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
94 for (i = 0; i < length; i += 3) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
95 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
96 *p++ = tbl[s[0] >> 2]; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
97 *p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)]; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
98 *p++ = tbl[((s[1] & 0xf) << 2) + (s[2] >> 6)]; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
99 *p++ = tbl[s[2] & 0x3f]; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
100 s += 3; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
101 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
102 /* Pad the result if necessary... */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
103 if (i == length + 1) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
104 *(p - 1) = '='; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
105 else if (i == length + 2) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
106 *(p - 1) = *(p - 2) = '='; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
107 /* ...and zero-terminate it. */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
108 *p = '\0'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
109 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
110 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
111 /* Create the authentication header contents for the `Basic' scheme. |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
112 This is done by encoding the string `USER:PASS' in base64 and |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
113 prepending `HEADER: Basic ' to it. */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
114 static gchar *basic_authentication_encode (const gchar *user, const gchar *passwd, const gchar *header) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
115 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
116 gchar *t1, *t2, *res; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
117 gint len1 = strlen (user) + 1 + strlen (passwd); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
118 gint len2 = BASE64_LENGTH (len1); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
119 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
120 t1 = g_strdup_printf("%s:%s", user, passwd); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
121 t2 = g_malloc0(len2 + 1); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
122 base64_encode (t1, t2, len1); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
123 res = g_strdup_printf("%s: Basic %s\r\n", header, t2); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
124 g_free(t2); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
125 g_free(t1); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
126 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
127 return res; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
128 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
129 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
130 static void parse_url(const gchar * url, gchar ** user, gchar ** pass, gchar ** host, int *port, gchar ** filename) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
131 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
132 gchar *h, *p, *pt, *f, *temp, *ptr; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
133 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
134 temp = g_strdup(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
135 ptr = temp; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
136 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
137 if (!strncasecmp("http://", ptr, 7)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
138 ptr += 7; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
139 h = strchr(ptr, '@'); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
140 f = strchr(ptr, '/'); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
141 if (h != NULL && (!f || h < f)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
142 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
143 *h = '\0'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
144 p = strchr(ptr, ':'); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
145 if (p != NULL && p < h) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
146 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
147 *p = '\0'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
148 p++; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
149 *pass = g_strdup(p); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
150 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
151 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
152 *pass = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
153 *user = g_strdup(ptr); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
154 h++; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
155 ptr = h; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
156 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
157 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
158 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
159 *user = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
160 *pass = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
161 h = ptr; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
162 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
163 pt = strchr(ptr, ':'); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
164 if (pt != NULL && (f == NULL || pt < f)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
165 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
166 *pt = '\0'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
167 *port = atoi(pt + 1); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
168 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
169 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
170 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
171 if (f) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
172 *f = '\0'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
173 *port = 80; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
174 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
175 *host = g_strdup(h); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
176 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
177 if (f) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
178 *filename = g_strdup(f + 1); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
179 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
180 *filename = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
181 g_free(temp); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
182 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
183 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
184 void flac_http_close(void) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
185 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
186 going = FALSE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
187 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
188 g_thread_join(thread); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
189 g_free(icy_name); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
190 icy_name = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
191 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
192 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
193 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
194 static gint http_used(void) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
195 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
196 if (wr_index >= rd_index) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
197 return wr_index - rd_index; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
198 return buffer_length - (rd_index - wr_index); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
199 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
200 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
201 static gint http_free(void) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
202 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
203 if (rd_index > wr_index) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
204 return (rd_index - wr_index) - 1; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
205 return (buffer_length - (wr_index - rd_index)) - 1; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
206 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
207 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
208 static void http_wait_for_data(gint bytes) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
209 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
210 while ((prebuffering || http_used() < bytes) && !eof && going) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
211 xmms_usleep(10000); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
212 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
213 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
214 static void show_error_message(gchar *error) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
215 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
216 if(!error_dialog) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
217 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
218 GDK_THREADS_ENTER(); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
219 error_dialog = xmms_show_message(_("Error"), error, _("Ok"), FALSE, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
220 NULL, NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
221 g_signal_connect(G_OBJECT(error_dialog), |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
222 "destroy", |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
223 G_CALLBACK(gtk_widget_destroyed), |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
224 &error_dialog); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
225 GDK_THREADS_LEAVE(); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
226 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
227 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
228 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
229 int flac_http_read(gpointer data, gint length) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
230 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
231 gint len, cnt, off = 0, meta_len, meta_off = 0, i; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
232 gchar *meta_data, **tags, *temp, *title; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
233 if (length > buffer_length) { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
234 length = buffer_length; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
235 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
236 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
237 http_wait_for_data(length); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
238 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
239 if (!going) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
240 return 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
241 len = min(http_used(), length); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
242 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
243 while (len && http_used()) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
244 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
245 if ((flac_cfg.stream.cast_title_streaming) && (icy_metaint > 0) && (buffer_read % icy_metaint) == 0 && (buffer_read > 0)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
246 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
247 meta_len = *((guchar *) buffer + rd_index) * 16; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
248 rd_index = (rd_index + 1) % buffer_length; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
249 if (meta_len > 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
250 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
251 http_wait_for_data(meta_len); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
252 meta_data = g_malloc0(meta_len); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
253 if (http_used() >= meta_len) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
254 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
255 while (meta_len) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
256 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
257 cnt = min(meta_len, buffer_length - rd_index); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
258 memcpy(meta_data + meta_off, buffer + rd_index, cnt); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
259 rd_index = (rd_index + cnt) % buffer_length; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
260 meta_len -= cnt; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
261 meta_off += cnt; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
262 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
263 tags = g_strsplit(meta_data, "';", 0); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
264 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
265 for (i = 0; tags[i]; i++) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
266 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
267 if (!strncasecmp(tags[i], "StreamTitle=", 12)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
268 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
269 temp = g_strdup(tags[i] + 13); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
270 title = g_strdup_printf("%s (%s)", temp, icy_name); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
271 set_track_info(title, -1); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
272 g_free(title); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
273 g_free(temp); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
274 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
275 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
276 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
277 g_strfreev(tags); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
278 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
279 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
280 g_free(meta_data); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
281 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
282 if (!http_used()) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
283 http_wait_for_data(length - off); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
284 cnt = min3(len, buffer_length - rd_index, http_used()); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
285 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
286 else if ((icy_metaint > 0) && (flac_cfg.stream.cast_title_streaming)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
287 cnt = min4(len, buffer_length - rd_index, http_used(), icy_metaint - (gint) (buffer_read % icy_metaint)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
288 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
289 cnt = min3(len, buffer_length - rd_index, http_used()); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
290 if (output_file) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
291 fwrite(buffer + rd_index, 1, cnt, output_file); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
292 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
293 memcpy((gchar *)data + off, buffer + rd_index, cnt); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
294 rd_index = (rd_index + cnt) % buffer_length; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
295 buffer_read += cnt; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
296 len -= cnt; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
297 off += cnt; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
298 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
299 if (!off) { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
300 fprintf(stderr, "returning zero\n"); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
301 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
302 return off; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
303 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
304 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
305 static gboolean http_check_for_data(void) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
306 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
307 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
308 fd_set set; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
309 struct timeval tv; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
310 gint ret; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
311 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
312 tv.tv_sec = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
313 tv.tv_usec = 20000; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
314 FD_ZERO(&set); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
315 FD_SET(sock, &set); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
316 ret = select(sock + 1, &set, NULL, NULL, &tv); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
317 if (ret > 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
318 return TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
319 return FALSE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
320 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
321 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
322 gint flac_http_read_line(gchar * buf, gint size) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
323 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
324 gint i = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
325 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
326 while (going && i < size - 1) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
327 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
328 if (http_check_for_data()) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
329 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
330 if (read(sock, buf + i, 1) <= 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
331 return -1; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
332 if (buf[i] == '\n') |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
333 break; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
334 if (buf[i] != '\r') |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
335 i++; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
336 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
337 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
338 if (!going) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
339 return -1; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
340 buf[i] = '\0'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
341 return i; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
342 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
343 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
344 /* returns the file descriptor of the socket, or -1 on error */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
345 static int http_connect (gchar *url_, gboolean head, guint64 offset) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
346 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
347 gchar line[1024], *user, *pass, *host, *filename, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
348 *status, *url, *temp, *file; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
349 gchar *chost; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
350 gint cnt, error, port, cport; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
351 guint err_len; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
352 gboolean redirect; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
353 int udp_sock = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
354 fd_set set; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
355 struct hostent *hp; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
356 struct sockaddr_in address; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
357 struct timeval tv; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
358 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
359 url = g_strdup (url_); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
360 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
361 do |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
362 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
363 redirect=FALSE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
364 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
365 g_strstrip(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
366 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
367 parse_url(url, &user, &pass, &host, &port, &filename); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
368 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
369 if ((!filename || !*filename) && url[strlen(url) - 1] != '/') |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
370 temp = g_strconcat(url, "/", NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
371 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
372 temp = g_strdup(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
373 g_free(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
374 url = temp; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
375 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
376 chost = flac_cfg.stream.use_proxy ? flac_cfg.stream.proxy_host : host; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
377 cport = flac_cfg.stream.use_proxy ? flac_cfg.stream.proxy_port : port; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
378 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
379 sock = socket(AF_INET, SOCK_STREAM, 0); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
380 fcntl(sock, F_SETFL, O_NONBLOCK); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
381 address.sin_family = AF_INET; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
382 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
383 status = g_strdup_printf(_("LOOKING UP %s"), chost); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
384 flac_ip.set_info_text(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
385 g_free(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
386 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
387 if (!(hp = gethostbyname(chost))) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
388 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
389 status = g_strdup_printf(_("Couldn't look up host %s"), chost); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
390 show_error_message(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
391 g_free(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
392 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
393 flac_ip.set_info_text(NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
394 eof = TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
395 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
396 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
397 if (!eof) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
398 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
399 memcpy(&address.sin_addr.s_addr, *(hp->h_addr_list), sizeof (address.sin_addr.s_addr)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
400 address.sin_port = (gint) g_htons(cport); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
401 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
402 status = g_strdup_printf(_("CONNECTING TO %s:%d"), chost, cport); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
403 flac_ip.set_info_text(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
404 g_free(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
405 if (connect(sock, (struct sockaddr *) &address, sizeof (struct sockaddr_in)) == -1) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
406 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
407 if (errno != EINPROGRESS) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
408 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
409 status = g_strdup_printf(_("Couldn't connect to host %s"), chost); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
410 show_error_message(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
411 g_free(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
412 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
413 flac_ip.set_info_text(NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
414 eof = TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
415 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
416 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
417 while (going) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
418 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
419 tv.tv_sec = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
420 tv.tv_usec = 10000; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
421 FD_ZERO(&set); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
422 FD_SET(sock, &set); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
423 if (select(sock + 1, NULL, &set, NULL, &tv) > 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
424 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
425 err_len = sizeof (error); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
426 getsockopt(sock, SOL_SOCKET, SO_ERROR, &error, &err_len); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
427 if (error) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
428 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
429 status = g_strdup_printf(_("Couldn't connect to host %s"), |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
430 chost); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
431 show_error_message(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
432 g_free(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
433 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
434 flac_ip.set_info_text(NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
435 eof = TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
436 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
437 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
438 break; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
439 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
440 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
441 if (!eof) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
442 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
443 gchar *auth = NULL, *proxy_auth = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
444 gchar udpspace[30]; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
445 int udp_port; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
446 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
447 if (flac_cfg.stream.use_udp_channel) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
448 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
449 udp_port = udp_establish_listener (&udp_sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
450 if (udp_port > 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
451 sprintf (udpspace, "x-audiocast-udpport: %d\r\n", udp_port); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
452 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
453 udp_sock = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
454 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
455 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
456 if(user && pass) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
457 auth = basic_authentication_encode(user, pass, "Authorization"); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
458 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
459 if (flac_cfg.stream.use_proxy) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
460 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
461 file = g_strdup(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
462 if(flac_cfg.stream.proxy_use_auth && flac_cfg.stream.proxy_user && flac_cfg.stream.proxy_pass) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
463 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
464 proxy_auth = basic_authentication_encode(flac_cfg.stream.proxy_user, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
465 flac_cfg.stream.proxy_pass, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
466 "Proxy-Authorization"); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
467 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
468 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
469 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
470 file = g_strconcat("/", filename, NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
471 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
472 temp = g_strdup_printf("GET %s HTTP/1.0\r\n" |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
473 "Host: %s\r\n" |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
474 "User-Agent: %s/%s\r\n" |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
475 "%s%s%s%s", |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
476 file, host, "Reference FLAC Player", FLAC__VERSION_STRING, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
477 proxy_auth ? proxy_auth : "", auth ? auth : "", |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
478 flac_cfg.stream.cast_title_streaming ? "Icy-MetaData:1\r\n" : "", |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
479 flac_cfg.stream.use_udp_channel ? udpspace : ""); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
480 if (offset && !head) { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
481 gchar *temp_dead = temp; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
482 temp = g_strconcat ("%sRange: %ll-\r\n", temp, offset, NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
483 fprintf (stderr, "%s", temp); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
484 g_free (temp_dead); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
485 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
486 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
487 g_free(file); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
488 if(proxy_auth) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
489 g_free(proxy_auth); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
490 if(auth) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
491 g_free(auth); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
492 write(sock, temp, strlen(temp)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
493 write(sock, "\r\n", 2); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
494 g_free(temp); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
495 flac_ip.set_info_text(_("CONNECTED: WAITING FOR REPLY")); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
496 while (going && !eof) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
497 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
498 if (http_check_for_data()) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
499 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
500 if (flac_http_read_line(line, 1024)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
501 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
502 status = strchr(line, ' '); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
503 if (status) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
504 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
505 if (status[1] == '2') |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
506 break; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
507 else if(status[1] == '3' && status[2] == '0' && status[3] == '2') |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
508 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
509 while(going) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
510 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
511 if(http_check_for_data()) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
512 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
513 if((cnt = flac_http_read_line(line, 1024)) != -1) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
514 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
515 if(!cnt) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
516 break; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
517 if(!strncmp(line, "Location:", 9)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
518 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
519 g_free(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
520 url = g_strdup(line+10); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
521 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
522 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
523 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
524 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
525 eof=TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
526 flac_ip.set_info_text(NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
527 break; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
528 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
529 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
530 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
531 redirect=TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
532 break; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
533 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
534 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
535 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
536 status = g_strdup_printf(_("Couldn't connect to host %s\nServer reported: %s"), chost, status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
537 show_error_message(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
538 g_free(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
539 break; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
540 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
541 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
542 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
543 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
544 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
545 eof = TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
546 flac_ip.set_info_text(NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
547 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
548 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
549 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
550 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
551 while (going && !redirect) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
552 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
553 if (http_check_for_data()) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
554 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
555 if ((cnt = flac_http_read_line(line, 1024)) != -1) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
556 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
557 if (!cnt) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
558 break; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
559 if (!strncmp(line, "icy-name:", 9)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
560 icy_name = g_strdup(line + 9); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
561 else if (!strncmp(line, "x-audiocast-name:", 17)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
562 icy_name = g_strdup(line + 17); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
563 if (!strncmp(line, "icy-metaint:", 12)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
564 icy_metaint = atoi(line + 12); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
565 if (!strncmp(line, "x-audiocast-udpport:", 20)) { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
566 #ifdef DEBUG_UDP |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
567 fprintf (stderr, "Server wants udp messages on port %d\n", atoi (line + 20)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
568 #endif |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
569 /*udp_serverport = atoi (line + 20);*/ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
570 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
571 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
572 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
573 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
574 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
575 eof = TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
576 flac_ip.set_info_text(NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
577 break; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
578 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
579 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
580 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
581 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
582 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
583 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
584 if(redirect) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
585 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
586 if (output_file) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
587 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
588 fclose(output_file); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
589 output_file = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
590 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
591 close(sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
592 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
593 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
594 g_free(user); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
595 g_free(pass); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
596 g_free(host); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
597 g_free(filename); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
598 } while(redirect); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
599 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
600 g_free(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
601 return eof ? -1 : sock; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
602 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
603 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
604 static void *http_buffer_loop(void *arg) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
605 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
606 gchar *status, *url, *temp, *file; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
607 gint cnt, written; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
608 int udp_sock = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
609 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
610 url = (gchar *) arg; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
611 sock = http_connect (url, false, offset); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
612 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
613 if (sock >= 0 && flac_cfg.stream.save_http_stream) { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
614 gchar *output_name; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
615 file = flac_http_get_title(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
616 output_name = file; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
617 if (!strncasecmp(output_name, "http://", 7)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
618 output_name += 7; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
619 temp = strrchr(output_name, '.'); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
620 if (temp && (!strcasecmp(temp, ".fla") || !strcasecmp(temp, ".flac"))) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
621 *temp = '\0'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
622 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
623 while ((temp = strchr(output_name, '/'))) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
624 *temp = '_'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
625 output_name = g_strdup_printf("%s/%s.flac", flac_cfg.stream.save_http_path, output_name); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
626 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
627 g_free(file); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
628 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
629 output_file = fopen(output_name, "wb"); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
630 g_free(output_name); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
631 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
632 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
633 while (going) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
634 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
635 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
636 if (!http_used() && !flac_ip.output->buffer_playing()) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
637 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
638 prebuffering = TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
639 flac_ip.set_status_buffering(TRUE); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
640 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
641 if (http_free() > 0 && !eof) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
642 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
643 if (http_check_for_data()) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
644 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
645 cnt = min(http_free(), buffer_length - wr_index); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
646 if (cnt > 1024) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
647 cnt = 1024; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
648 written = read(sock, buffer + wr_index, cnt); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
649 if (written <= 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
650 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
651 eof = TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
652 if (prebuffering) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
653 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
654 prebuffering = FALSE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
655 flac_ip.set_status_buffering(FALSE); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
656 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
657 flac_ip.set_info_text(NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
658 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
659 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
660 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
661 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
662 wr_index = (wr_index + written) % buffer_length; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
663 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
664 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
665 if (prebuffering) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
666 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
667 if (http_used() > prebuffer_length) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
668 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
669 prebuffering = FALSE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
670 flac_ip.set_status_buffering(FALSE); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
671 flac_ip.set_info_text(NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
672 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
673 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
674 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
675 status = g_strdup_printf(_("PRE-BUFFERING: %dKB/%dKB"), http_used() / 1024, prebuffer_length / 1024); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
676 flac_ip.set_info_text(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
677 g_free(status); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
678 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
679 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
680 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
681 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
682 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
683 xmms_usleep(10000); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
684 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
685 if (flac_cfg.stream.use_udp_channel && udp_sock != 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
686 if (udp_check_for_data(udp_sock) < 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
687 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
688 close(udp_sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
689 udp_sock = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
690 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
691 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
692 if (output_file) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
693 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
694 fclose(output_file); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
695 output_file = NULL; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
696 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
697 if (sock >= 0) { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
698 close(sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
699 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
700 if (udp_sock != 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
701 close(udp_sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
702 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
703 g_free(buffer); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
704 g_free(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
705 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
706 g_thread_exit(NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
707 return NULL; /* avoid compiler warning */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
708 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
709 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
710 int flac_http_open(gchar * _url, guint64 _offset) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
711 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
712 gchar *url; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
713 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
714 url = g_strdup(_url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
715 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
716 rd_index = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
717 wr_index = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
718 buffer_length = flac_cfg.stream.http_buffer_size * 1024; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
719 prebuffer_length = (buffer_length * flac_cfg.stream.http_prebuffer) / 100; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
720 buffer_read = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
721 icy_metaint = 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
722 prebuffering = TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
723 flac_ip.set_status_buffering(TRUE); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
724 going = TRUE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
725 eof = FALSE; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
726 buffer = g_malloc(buffer_length); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
727 offset = _offset; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
728 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
729 thread = g_thread_create((GThreadFunc)http_buffer_loop, url, TRUE, NULL); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
730 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
731 return 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
732 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
733 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
734 char *flac_http_get_title(char *url) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
735 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
736 if (icy_name) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
737 return g_strdup(icy_name); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
738 if (g_basename(url) && strlen(g_basename(url)) > 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
739 return g_strdup(g_basename(url)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
740 return g_strdup(url); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
741 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
742 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
743 /* Start UDP Channel specific stuff */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
744 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
745 /* Find a good local udp port and bind udp_sock to it, return the port */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
746 static int udp_establish_listener(int *sock) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
747 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
748 struct sockaddr_in sin; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
749 socklen_t sinlen = sizeof (struct sockaddr_in); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
750 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
751 #ifdef DEBUG_UDP |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
752 fprintf (stderr,"Establishing udp listener\n"); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
753 #endif |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
754 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
755 if ((*sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
756 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
757 g_log(NULL, G_LOG_LEVEL_CRITICAL, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
758 "udp_establish_listener(): unable to create socket"); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
759 return -1; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
760 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
761 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
762 memset(&sin, 0, sinlen); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
763 sin.sin_family = AF_INET; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
764 sin.sin_addr.s_addr = g_htonl(INADDR_ANY); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
765 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
766 if (bind(*sock, (struct sockaddr *)&sin, sinlen) < 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
767 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
768 g_log(NULL, G_LOG_LEVEL_CRITICAL, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
769 "udp_establish_listener(): Failed to bind socket to localhost: %s", strerror(errno)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
770 close(*sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
771 return -1; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
772 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
773 if (fcntl(*sock, F_SETFL, O_NONBLOCK) < 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
774 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
775 g_log(NULL, G_LOG_LEVEL_CRITICAL, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
776 "udp_establish_listener(): Failed to set flags: %s", strerror(errno)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
777 close(*sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
778 return -1; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
779 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
780 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
781 memset(&sin, 0, sinlen); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
782 if (getsockname(*sock, (struct sockaddr *)&sin, &sinlen) < 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
783 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
784 g_log(NULL, G_LOG_LEVEL_CRITICAL, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
785 "udp_establish_listener(): Failed to retrieve socket info: %s", strerror(errno)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
786 close(*sock); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
787 return -1; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
788 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
789 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
790 #ifdef DEBUG_UDP |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
791 fprintf (stderr,"Listening on local %s:%d\n", inet_ntoa(sin.sin_addr), g_ntohs(sin.sin_port)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
792 #endif |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
793 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
794 return g_ntohs(sin.sin_port); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
795 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
796 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
797 static int udp_check_for_data(int sock) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
798 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
799 char buf[1025], **lines; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
800 char *valptr; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
801 gchar *title; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
802 gint len, i; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
803 struct sockaddr_in from; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
804 socklen_t fromlen; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
805 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
806 fromlen = sizeof(struct sockaddr_in); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
807 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
808 if ((len = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&from, &fromlen)) < 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
809 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
810 if (errno != EAGAIN) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
811 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
812 g_log(NULL, G_LOG_LEVEL_CRITICAL, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
813 "udp_read_data(): Error reading from socket: %s", strerror(errno)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
814 return -1; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
815 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
816 return 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
817 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
818 buf[len] = '\0'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
819 #ifdef DEBUG_UDP |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
820 fprintf (stderr,"Received: [%s]\n", buf); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
821 #endif |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
822 lines = g_strsplit(buf, "\n", 0); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
823 if (!lines) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
824 return 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
825 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
826 for (i = 0; lines[i]; i++) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
827 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
828 while ((lines[i][strlen(lines[i]) - 1] == '\n') || |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
829 (lines[i][strlen(lines[i]) - 1] == '\r')) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
830 lines[i][strlen(lines[i]) - 1] = '\0'; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
831 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
832 valptr = strchr(lines[i], ':'); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
833 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
834 if (!valptr) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
835 continue; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
836 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
837 valptr++; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
838 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
839 g_strstrip(valptr); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
840 if (!strlen(valptr)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
841 continue; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
842 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
843 if (strstr(lines[i], "x-audiocast-streamtitle") != NULL) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
844 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
845 title = g_strdup_printf ("%s (%s)", valptr, icy_name); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
846 if (going) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
847 set_track_info(title, -1); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
848 g_free (title); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
849 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
850 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
851 #if 0 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
852 else if (strstr(lines[i], "x-audiocast-streamlength") != NULL) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
853 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
854 if (atoi(valptr) != -1) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
855 set_track_info(NULL, atoi(valptr)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
856 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
857 #endif |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
858 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
859 else if (strstr(lines[i], "x-audiocast-streammsg") != NULL) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
860 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
861 /* set_track_info(title, -1); */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
862 /* xmms_show_message(_("Message"), valptr, _("Ok"), */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
863 /* FALSE, NULL, NULL); */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
864 g_message("Stream_message: %s", valptr); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
865 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
866 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
867 #if 0 |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
868 /* Use this to direct your webbrowser.. yeah right.. */ |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
869 else if (strstr(lines[i], "x-audiocast-streamurl") != NULL) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
870 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
871 if (lasturl && g_strcmp (valptr, lasturl)) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
872 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
873 c_message (stderr, "Song URL: %s\n", valptr); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
874 g_free (lasturl); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
875 lasturl = g_strdup (valptr); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
876 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
877 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
878 #endif |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
879 else if (strstr(lines[i], "x-audiocast-udpseqnr:") != NULL) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
880 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
881 gchar obuf[60]; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
882 sprintf(obuf, "x-audiocast-ack: %ld \r\n", atol(valptr)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
883 if (sendto(sock, obuf, strlen(obuf), 0, (struct sockaddr *) &from, fromlen) < 0) |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
884 { |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
885 g_log(NULL, G_LOG_LEVEL_WARNING, |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
886 "udp_check_for_data(): Unable to send ack to server: %s", strerror(errno)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
887 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
888 #ifdef DEBUG_UDP |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
889 else |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
890 fprintf(stderr,"Sent ack: %s", obuf); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
891 fprintf (stderr,"Remote: %s:%d\n", inet_ntoa(from.sin_addr), g_ntohs(from.sin_port)); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
892 #endif |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
893 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
894 } |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
895 g_strfreev(lines); |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
896 return 0; |
4b31176c198a
[svn] - 1.1.2 compatible plugin (I HATE YOU FLAC PEOPLE)
nenolod
parents:
diff
changeset
|
897 } |