Mercurial > audlegacy-plugins
annotate src/curl/curl.c @ 949:d3b9627861de trunk
[svn] - revert r2028.
author | nenolod |
---|---|
date | Thu, 12 Apr 2007 15:03:53 -0700 |
parents | 8dd7c03376bb |
children | 668110a6a412 |
rev | line source |
---|---|
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
1 /* Audacious |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
2 * Copyright (c) 2007 Daniel Barkalow |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
3 * |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
7 * (at your option) any later version. |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
8 * |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
12 * GNU General Public License for more details. |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
13 * |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
15 * along with this program; if not, write to the Free Software |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
17 */ |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
18 |
556
cd730d42b2bd
[svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents:
543
diff
changeset
|
19 #ifdef HAVE_CONFIG_H |
cd730d42b2bd
[svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents:
543
diff
changeset
|
20 # include "config.h" |
cd730d42b2bd
[svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents:
543
diff
changeset
|
21 #endif |
cd730d42b2bd
[svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents:
543
diff
changeset
|
22 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
23 #include <audacious/vfs.h> |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
24 #include <audacious/plugin.h> |
707 | 25 #include <audacious/configdb.h> |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
26 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
27 #include <curl/curl.h> |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
28 |
936 | 29 #include <stdlib.h> |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
30 #include <string.h> |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
31 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
32 #define BUFFER_SIZE 256 * 1024 |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
33 #define REVERSE_SEEK_SIZE 2048 |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
34 |
945 | 35 #define DEBUG_CONNECTION 0 |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
36 #define DEBUG_OPEN_CLOSE 1 |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
37 #define DEBUG_SEEK 0 |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
38 #define DEBUG_READ 0 |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
39 #define DEBUG_HEADERS 0 |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
40 #define DEBUG_ICY 0 |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
41 #define DEBUG_ICY_WRAP 0 |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
42 #define DEBUG_ICY_VERBOSE 0 |
485 | 43 #define DEBUG_METADATA_REPORT 0 |
949 | 44 #define DEBUG_CURL 1 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
45 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
46 typedef struct _CurlHandle CurlHandle; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
47 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
48 struct _CurlHandle { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
49 CURL *curl; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
50 |
430
ed94145472df
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents:
428
diff
changeset
|
51 gssize length; // the length of the file |
934 | 52 gssize rd_abs; // the absolute position for reading from the stream |
53 gssize wr_abs; // the absolute position where the input connection is | |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
54 |
934 | 55 gssize icy_left; |
56 gssize icy_interval; | |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
57 gint in_icy_meta; // 0=no, 1=before size, 2=in data |
934 | 58 gssize meta_abs; // the absolute position where the metadata changes |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
59 |
934 | 60 gssize buffer_length; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
61 gchar *buffer; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
62 |
934 | 63 gssize rd_index; |
64 gssize wr_index; | |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
65 |
934 | 66 gssize hdr_index; |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
67 |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
68 GSList *stream_stack; // stack for stream functions (getc, ungetc) |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
69 |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
70 gboolean header; // true if we haven't finished the header yet |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
71 gboolean no_data; // true if we're only looking for length currently |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
72 gboolean cancel; // true if the thread should be cancelled |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
73 gboolean failed; // true if we've tried and failed already |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
74 GThread *thread; // the thread that's reading from the connection |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
75 |
543
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
76 VFSFile *download; // file to write to as we download |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
77 |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
78 gchar *name; |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
79 gchar *title; |
717 | 80 |
81 struct { | |
82 gchar *proxy_host; | |
83 gchar *proxy_auth; | |
84 } proxy_info; | |
731
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
85 |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
86 gchar *local_ip; |
946
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
87 |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
88 GMutex *curl_mutex; |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
89 GCond *curl_cond; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
90 }; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
91 |
936 | 92 void curl_vfs_rewind_impl(VFSFile * file); |
93 glong curl_vfs_ftell_impl(VFSFile * file); | |
94 gboolean curl_vfs_feof_impl(VFSFile * file); | |
95 gint curl_vfs_truncate_impl(VFSFile * file, glong size); | |
96 gchar *curl_vfs_metadata_impl(VFSFile * file, const gchar * field); | |
97 size_t curl_vfs_fwrite_impl(gconstpointer ptr, size_t size, | |
98 size_t nmemb, | |
99 VFSFile * file); | |
939 | 100 size_t curl_vfs_fread_impl(gpointer ptr_, size_t size, |
936 | 101 size_t nmemb, |
102 VFSFile * file); | |
103 gint curl_vfs_fclose_impl(VFSFile * file); | |
104 gint curl_vfs_getc_impl(VFSFile *stream); | |
105 gint curl_vfs_ungetc_impl(gint c, VFSFile *stream); | |
106 gint curl_vfs_fseek_impl(VFSFile * file, glong offset, gint whence); | |
107 VFSFile *curl_vfs_fopen_impl(const gchar * path, | |
108 const gchar * mode); | |
941 | 109 LowlevelPlugin *get_lplugin_info(void); |
936 | 110 |
483 | 111 VFSConstructor curl_const; |
112 | |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
113 /* TODO: |
430
ed94145472df
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents:
428
diff
changeset
|
114 * - Fix hang if the server closes the connection in the middle |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
115 * - Clever buffer stuff when you read a bit of the beginning and a bit of the |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
116 * end of a file |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
117 */ |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
118 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
119 /* The goal here is to have a buffering system which handles the following: |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
120 * 1) open, seek, read (without fetching the beginning of the file) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
121 * 2) open, seek END, tell (using HEAD only) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
122 * 3) open, read, seek 0, read (without restarting fetch) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
123 */ |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
124 |
934 | 125 static ssize_t buf_space(CurlHandle *handle) |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
126 { |
934 | 127 ssize_t rd_edge = handle->rd_abs - REVERSE_SEEK_SIZE; |
128 ssize_t buffer_limit; | |
129 ssize_t cont_limit; | |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
130 if (rd_edge < 0) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
131 rd_edge = 0; |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
132 buffer_limit = handle->buffer_length - |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
133 (handle->wr_abs - rd_edge); |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
134 cont_limit = handle->buffer_length - handle->wr_index; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
135 if (cont_limit < buffer_limit) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
136 buffer_limit = cont_limit; |
754
a77533b76084
[svn] - fix a ringbuffering error in curl which caused trouble with icecast2
nenolod
parents:
753
diff
changeset
|
137 if (handle->icy_interval && handle->icy_left) |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
138 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
139 if (handle->icy_left < buffer_limit) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
140 buffer_limit = handle->icy_left; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
141 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
142 return buffer_limit; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
143 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
144 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
145 static size_t buf_available(CurlHandle *handle) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
146 { |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
147 size_t buffer_limit; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
148 size_t cont_limit; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
149 if (handle->header) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
150 return 0; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
151 buffer_limit = handle->wr_abs - handle->rd_abs; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
152 cont_limit = handle->buffer_length - handle->rd_index; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
153 if (buffer_limit <= 0) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
154 return 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
155 return buffer_limit < cont_limit ? buffer_limit : cont_limit; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
156 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
157 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
158 static void check(CurlHandle *handle) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
159 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
160 if (!((handle->wr_abs - handle->wr_index) % handle->buffer_length == |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
161 (handle->rd_abs - handle->rd_index) % handle->buffer_length)) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
162 printf("%p Not aligned! wr %d rd %d\n", handle, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
163 (handle->wr_abs - handle->wr_index) % handle->buffer_length, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
164 (handle->rd_abs - handle->rd_index) % handle->buffer_length); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
165 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
166 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
167 static void update_length(CurlHandle *handle) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
168 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
169 if (handle->length == -1) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
170 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
171 double value; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
172 int retcode = |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
173 curl_easy_getinfo(handle->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
174 &value); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
175 if (retcode == CURLE_OK) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
176 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
177 handle->length = value; |
430
ed94145472df
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents:
428
diff
changeset
|
178 if (handle->length == 0) |
ed94145472df
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents:
428
diff
changeset
|
179 handle->length = -2; |
ed94145472df
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents:
428
diff
changeset
|
180 //g_print("Length: %d\n", handle->length); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
181 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
182 else |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
183 { |
430
ed94145472df
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents:
428
diff
changeset
|
184 handle->length = -2; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
185 g_print("getinfo gave error\n"); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
186 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
187 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
188 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
189 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
190 #define PROBE 262140 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
191 |
534 | 192 #define ICE_NAME "ice-name:" |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
193 #define ICY_NAME "icy-name:" |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
194 #define ICY_METAINT "icy-metaint:" |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
195 |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
196 static gboolean match_header(CurlHandle *handle, size_t size, |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
197 const char *header) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
198 { |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
199 if (strlen(header) > size) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
200 return FALSE; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
201 // XXXX wrapped headers |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
202 return !(strncmp(handle->buffer + handle->hdr_index, |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
203 header, strlen(header))); |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
204 } |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
205 |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
206 static gchar *get_value(CurlHandle *handle, size_t size, const char *header) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
207 { |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
208 // XXXX wrapped headers |
940
356d2335a975
[svn] - fix curl.c:913: warning: implicit declaration of function 'strdup'
nenolod
parents:
939
diff
changeset
|
209 return g_strdup(handle->buffer + |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
210 (handle->hdr_index + strlen(header)) % handle->buffer_length); |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
211 } |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
212 |
934 | 213 static void got_header(CurlHandle *handle, ssize_t size) |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
214 { |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
215 if (DEBUG_HEADERS) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
216 g_print("Got header %d bytes\n", size); |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
217 if (match_header(handle, size, ICY_NAME)) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
218 { |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
219 handle->name = get_value(handle, size, ICY_NAME); |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
220 if (DEBUG_HEADERS) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
221 { |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
222 g_print("Stream name: %s\n", handle->name); |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
223 } |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
224 } |
534 | 225 if (match_header(handle, size, ICE_NAME)) |
226 { | |
227 handle->name = get_value(handle, size, ICE_NAME); | |
228 if (DEBUG_HEADERS) | |
229 { | |
230 g_print("Stream name: %s\n", handle->name); | |
231 } | |
232 } | |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
233 if (match_header(handle, size, ICY_METAINT)) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
234 { |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
235 gchar *value = get_value(handle, size, ICY_METAINT); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
236 handle->icy_interval = atoi(value); |
936 | 237 g_free(value); |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
238 if (DEBUG_HEADERS) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
239 g_print("Metadata interval: %d\n", handle->icy_interval); |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
240 } |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
241 } |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
242 |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
243 #define TITLE_INLINE "StreamTitle=" |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
244 |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
245 static gboolean match_inline(CurlHandle *handle, size_t posn, |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
246 const char *name) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
247 { |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
248 size_t len = strlen(name); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
249 size_t i; |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
250 if (DEBUG_ICY_WRAP) |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
251 g_print("Posn=%d\n", posn); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
252 if (DEBUG_ICY_WRAP && posn + len > handle->buffer_length) |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
253 g_print("Wrapped inline key\n"); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
254 if (((handle->wr_index - posn + handle->buffer_length) % |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
255 handle->buffer_length) <= len) |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
256 return FALSE; |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
257 for (i = 0; i < len; i++) |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
258 if (handle->buffer[(posn + i) % handle->buffer_length] != name[i]) |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
259 { |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
260 return FALSE; |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
261 } |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
262 return TRUE; |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
263 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
264 |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
265 static gchar *get_inline_value(CurlHandle *handle, size_t posn, |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
266 const char *name) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
267 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
268 size_t end; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
269 size_t sz; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
270 gchar *ret; |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
271 posn = (posn + strlen(name) + 1) % handle->buffer_length; |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
272 end = posn; |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
273 while (handle->buffer[end % handle->buffer_length] != ';') |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
274 end++; |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
275 sz = (end - posn + handle->buffer_length) % handle->buffer_length; |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
276 ret = g_malloc(sz); |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
277 if (end % handle->buffer_length < posn % handle->buffer_length) |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
278 { |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
279 size_t prewrap = handle->buffer_length - posn; |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
280 memcpy(ret, handle->buffer + posn, prewrap); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
281 memcpy(ret + prewrap, handle->buffer, sz - prewrap); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
282 if (DEBUG_ICY_WRAP) |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
283 g_print("Wrapped inline metadata value\n"); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
284 } |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
285 else |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
286 { |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
287 memcpy(ret, handle->buffer + posn, sz); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
288 } |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
289 ret[sz - 1] = '\0'; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
290 return ret; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
291 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
292 |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
293 static void got_inline_metadata(CurlHandle *handle) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
294 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
295 size_t i = (handle->hdr_index + 1) % handle->buffer_length; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
296 if (match_inline(handle, i, TITLE_INLINE)) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
297 { |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
298 if (handle->title) |
936 | 299 g_free(handle->title); |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
300 handle->title = get_inline_value(handle, i, TITLE_INLINE); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
301 if (DEBUG_ICY) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
302 g_print("Title: '%s'\n", handle->title); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
303 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
304 handle->meta_abs = handle->wr_abs; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
305 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
306 |
938
31089767a3e3
[svn] - use unsigned char instead of gpointer for arithmetic to ensure that writes are 8-bit aligned.
nenolod
parents:
937
diff
changeset
|
307 static size_t curl_writecb(unsigned char *ptr, size_t size, size_t nmemb, void *stream) |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
308 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
309 CurlHandle *handle = stream; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
310 gint sz = size * nmemb; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
311 gint ret = 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
312 gint trans; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
313 |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
314 if (!handle->header) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
315 update_length(handle); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
316 |
946
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
317 g_cond_signal(handle->curl_cond); |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
318 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
319 while (ret < sz) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
320 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
321 while (!(trans = buf_space(handle)) && !handle->cancel) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
322 { |
543
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
323 //g_print("Wait for free space on %p\n", handle); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
324 g_usleep(10000); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
325 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
326 if (handle->cancel) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
327 break; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
328 if (trans > sz - ret) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
329 trans = sz - ret; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
330 memcpy(handle->buffer + handle->wr_index, ptr + ret, trans); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
331 |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
332 if (!handle->header) |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
333 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
334 if (handle->icy_interval) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
335 handle->icy_left -= trans; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
336 if (!handle->in_icy_meta) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
337 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
338 handle->wr_abs += trans; |
543
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
339 if (handle->download) |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
340 { |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
341 vfs_fwrite(ptr + ret, trans, 1, handle->download); |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
342 } |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
343 if (handle->icy_interval && !handle->icy_left) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
344 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
345 if (DEBUG_ICY) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
346 g_print("Metadata inline after %d\n", handle->wr_abs); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
347 handle->in_icy_meta = 1; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
348 handle->icy_left = 1; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
349 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
350 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
351 else if (handle->in_icy_meta == 1) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
352 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
353 // Track where the header insert starts |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
354 handle->hdr_index = handle->wr_index; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
355 handle->icy_left = |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
356 ((unsigned char)(handle->buffer[handle->wr_index])) * 16; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
357 if (DEBUG_ICY) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
358 g_print("Metadata of size %d\n", handle->icy_left); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
359 if (handle->icy_left) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
360 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
361 handle->in_icy_meta = 2; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
362 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
363 else |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
364 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
365 handle->in_icy_meta = 0; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
366 handle->icy_left = handle->icy_interval; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
367 handle->wr_index--; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
368 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
369 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
370 else |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
371 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
372 if (!handle->icy_left) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
373 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
374 handle->wr_index = (handle->wr_index + trans) % |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
375 handle->buffer_length; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
376 if (DEBUG_ICY_VERBOSE) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
377 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
378 if (handle->wr_index < handle->hdr_index) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
379 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
380 // wrapped |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
381 fwrite(handle->buffer + handle->hdr_index + 1, |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
382 handle->buffer_length - handle->hdr_index - 1, |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
383 1, stdout); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
384 fwrite(handle->buffer, handle->wr_index, 1, stdout); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
385 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
386 else |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
387 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
388 fwrite(handle->buffer + handle->hdr_index, |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
389 handle->wr_index - handle->hdr_index, 1, |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
390 stdout); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
391 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
392 g_print("\n"); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
393 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
394 got_inline_metadata(handle); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
395 |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
396 // Rewind the buffer usage to write over the |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
397 // metadata with content. -trans because we're about |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
398 // to add it. |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
399 handle->wr_index = handle->hdr_index - trans; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
400 handle->in_icy_meta = 0; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
401 handle->icy_left = handle->icy_interval; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
402 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
403 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
404 } |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
405 handle->wr_index = (handle->wr_index + trans) % handle->buffer_length; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
406 ret += trans; |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
407 |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
408 if (handle->header) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
409 { |
934 | 410 gssize i = handle->hdr_index; |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
411 while (1) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
412 { |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
413 if ((i + 1) % handle->buffer_length == handle->wr_index) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
414 break; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
415 if (handle->buffer[i] == '\r' && |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
416 handle->buffer[(i + 1) % handle->buffer_length] == '\n') |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
417 { |
937 | 418 gssize size_ = (handle->buffer_length + i - |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
419 handle->hdr_index) % handle->buffer_length; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
420 handle->buffer[i] = '\0'; |
937 | 421 got_header(handle, size_); |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
422 if (i == handle->hdr_index) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
423 { |
543
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
424 size_t leftover; |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
425 // Empty header means the end of the headers |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
426 handle->header = 0; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
427 handle->hdr_index = (i + 2) % handle->buffer_length; |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
428 // We read from the start of the data in the request |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
429 handle->rd_index = handle->hdr_index; |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
430 // We've already written the amount that's after |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
431 // the header. |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
432 leftover = (handle->wr_index - handle->hdr_index + handle->buffer_length) % handle->buffer_length; |
543
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
433 handle->wr_abs += leftover; |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
434 if (handle->download) |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
435 { |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
436 // the data which has to go into the |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
437 // beginning of the file must be at the end |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
438 // of the input that we've dealt with. |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
439 vfs_fwrite(ptr + ret - leftover, leftover, 1, |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
440 handle->download); |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
441 } |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
442 handle->icy_left = handle->icy_interval; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
443 if (handle->icy_interval) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
444 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
445 handle->icy_left -= |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
446 (handle->wr_index - handle->hdr_index + handle->buffer_length) % handle->buffer_length; |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
447 } |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
448 if (DEBUG_ICY) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
449 g_print("Left %d\n", handle->icy_left); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
450 handle->in_icy_meta = 0; |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
451 break; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
452 } |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
453 handle->hdr_index = (i + 2) % handle->buffer_length; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
454 } |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
455 i = (i + 1) % handle->buffer_length; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
456 } |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
457 } |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
458 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
459 return ret; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
460 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
461 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
462 static gpointer |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
463 curl_manage_request(gpointer arg) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
464 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
465 CurlHandle *handle = arg; |
430
ed94145472df
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents:
428
diff
changeset
|
466 CURLcode result; |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
467 if (DEBUG_CONNECTION) |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
468 g_print("Connect %p\n", handle); |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
469 |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
470 if (handle->no_data) |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
471 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 1); |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
472 else |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
473 { |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
474 if (DEBUG_CONNECTION) |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
475 g_print("Start from %d\n", handle->wr_abs); |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
476 curl_easy_setopt(handle->curl, CURLOPT_RESUME_FROM, handle->wr_abs); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
477 |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
478 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 0); |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
479 curl_easy_setopt(handle->curl, CURLOPT_HTTPGET, 1); |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
480 } |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
481 |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
482 handle->header = 1; |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
483 handle->hdr_index = 0; |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
484 handle->icy_interval = 0; |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
485 |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
486 result = curl_easy_perform(handle->curl); |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
487 if (result == CURLE_OK) |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
488 update_length(handle); |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
489 // We expect to get CURLE_WRITE_ERROR if we cancel. |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
490 // We get CURLE_GOT_NOTHING if we send a HEAD request to a shoutcast server. |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
491 // We get CURLE_HTTP_RANGE_ERROR if we try to use range with shoutcast. |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
492 if (result != CURLE_OK && result != CURLE_WRITE_ERROR && |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
493 result != CURLE_GOT_NOTHING && result != CURLE_HTTP_RANGE_ERROR && |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
494 result != CURLE_PARTIAL_FILE) |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
495 { |
790
c199c1f23921
[svn] - translate curl error number into corresponding error message. patch by Joker.
yaz
parents:
774
diff
changeset
|
496 g_print("Got curl error %d: %s\n", result, curl_easy_strerror(result)); |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
497 handle->failed = 1; |
430
ed94145472df
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents:
428
diff
changeset
|
498 } |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
499 if (DEBUG_CONNECTION) |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
500 g_print("Done %p%s", handle, handle->cancel ? " (aborted)\n" : "\n"); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
501 handle->cancel = 1; |
946
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
502 |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
503 g_cond_signal(handle->curl_cond); |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
504 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
505 return NULL; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
506 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
507 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
508 static void curl_req_xfer(CurlHandle *handle) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
509 { |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
510 if (handle->failed) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
511 { |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
512 handle->cancel = 1; |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
513 return; |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
514 } |
949 | 515 if (!handle->thread) |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
516 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
517 handle->cancel = 0; |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
518 handle->wr_index = 0; |
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
519 handle->rd_index = 0; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
520 handle->wr_abs = handle->rd_abs; |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
521 if (DEBUG_CONNECTION) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
522 g_print("Starting connection %p at %d\n", handle, handle->wr_abs); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
523 handle->thread = g_thread_create(curl_manage_request, handle, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
524 TRUE, NULL); |
946
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
525 |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
526 g_cond_wait(handle->curl_cond, handle->curl_mutex); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
527 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
528 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
529 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
530 static void curl_req_sync_xfer(CurlHandle *handle, size_t old_rd_abs) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
531 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
532 handle->rd_index = (handle->rd_index + handle->rd_abs - old_rd_abs + |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
533 handle->buffer_length) % handle->buffer_length; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
534 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
535 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
536 static void curl_req_no_xfer(CurlHandle *handle) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
537 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
538 if (handle->thread) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
539 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
540 handle->cancel = 1; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
541 g_thread_join(handle->thread); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
542 handle->thread = NULL; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
543 handle->cancel = 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
544 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
545 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
546 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
547 VFSFile * |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
548 curl_vfs_fopen_impl(const gchar * path, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
549 const gchar * mode) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
550 { |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
551 gchar *url; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
552 CurlHandle *handle; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
553 VFSFile *file; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
554 if (!path || !mode) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
555 return NULL; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
556 |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
557 url = g_strdup(path); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
558 |
473 | 559 file = g_new0(VFSFile, 1); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
560 |
473 | 561 handle = g_new0(CurlHandle, 1); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
562 handle->curl = curl_easy_init(); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
563 handle->rd_index = 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
564 handle->wr_index = 0; |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
565 handle->meta_abs = 0; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
566 handle->rd_abs = 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
567 handle->wr_abs = 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
568 handle->buffer_length = BUFFER_SIZE; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
569 handle->buffer = g_malloc(handle->buffer_length); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
570 handle->thread = NULL; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
571 handle->length = -1; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
572 handle->cancel = 0; |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
573 handle->failed = 0; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
574 handle->no_data = 0; |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
575 handle->stream_stack = NULL; |
946
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
576 handle->curl_mutex = g_mutex_new(); |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
577 handle->curl_cond = g_cond_new(); |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
578 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
579 curl_easy_setopt(handle->curl, CURLOPT_URL, url); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
580 curl_easy_setopt(handle->curl, CURLOPT_WRITEFUNCTION, curl_writecb); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
581 curl_easy_setopt(handle->curl, CURLOPT_WRITEDATA, handle); |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
582 curl_easy_setopt(handle->curl, CURLOPT_HEADERDATA, handle); |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
583 |
753 | 584 curl_easy_setopt(handle->curl, CURLOPT_CONNECTTIMEOUT, 3); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
585 |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
586 curl_easy_setopt(handle->curl, CURLOPT_SSL_VERIFYPEER, 0); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
587 curl_easy_setopt(handle->curl, CURLOPT_SSL_VERIFYHOST, 0); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
588 |
625
fdae06cbebc9
[svn] - set CURLOPT_FOLLOWLOCATION to true, closes #771.
nenolod
parents:
556
diff
changeset
|
589 curl_easy_setopt(handle->curl, CURLOPT_FOLLOWLOCATION, 1); |
fdae06cbebc9
[svn] - set CURLOPT_FOLLOWLOCATION to true, closes #771.
nenolod
parents:
556
diff
changeset
|
590 |
948
8dd7c03376bb
[svn] - add DEBUG_CURL to enable curl internal debugging messages
nenolod
parents:
947
diff
changeset
|
591 if (DEBUG_CURL) |
8dd7c03376bb
[svn] - add DEBUG_CURL to enable curl internal debugging messages
nenolod
parents:
947
diff
changeset
|
592 curl_easy_setopt(handle->curl, CURLOPT_VERBOSE, 1); |
8dd7c03376bb
[svn] - add DEBUG_CURL to enable curl internal debugging messages
nenolod
parents:
947
diff
changeset
|
593 |
707 | 594 { |
595 gboolean tmp = FALSE; | |
596 ConfigDb *db; | |
597 | |
598 db = bmp_cfg_db_open(); | |
599 | |
731
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
600 bmp_cfg_db_get_bool(db, NULL, "use_local_ip", &tmp); |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
601 if (tmp == TRUE) |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
602 { |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
603 bmp_cfg_db_get_string(db, NULL, "local_ip", &handle->local_ip); |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
604 curl_easy_setopt(handle->curl, CURLOPT_INTERFACE, handle->local_ip); |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
605 } |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
606 tmp = FALSE; |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
607 |
714
e758e9d4f861
[svn] - fix proxy_use vs use_proxy. reported by joker on IRC.
nenolod
parents:
708
diff
changeset
|
608 bmp_cfg_db_get_bool(db, NULL, "use_proxy", &tmp); |
707 | 609 if (tmp == TRUE) |
610 { | |
611 gint proxy_port = 0; | |
612 | |
717 | 613 bmp_cfg_db_get_string(db, NULL, "proxy_host", |
614 &handle->proxy_info.proxy_host); | |
707 | 615 bmp_cfg_db_get_int(db, NULL, "proxy_port", &proxy_port); |
616 | |
717 | 617 curl_easy_setopt(handle->curl, CURLOPT_PROXY, handle->proxy_info.proxy_host); |
707 | 618 curl_easy_setopt(handle->curl, CURLOPT_PROXYPORT, proxy_port); |
619 | |
620 tmp = FALSE; | |
621 | |
622 bmp_cfg_db_get_bool(db, NULL, "proxy_use_auth", &tmp); | |
623 if (tmp == TRUE) | |
624 { | |
717 | 625 gchar *proxy_user = NULL, *proxy_pass = NULL; |
707 | 626 |
627 bmp_cfg_db_get_string(db, NULL, "proxy_user", &proxy_user); | |
628 bmp_cfg_db_get_string(db, NULL, "proxy_pass", &proxy_pass); | |
629 | |
717 | 630 handle->proxy_info.proxy_auth = g_strdup_printf("%s:%s", |
707 | 631 proxy_user != NULL ? proxy_user : "", |
632 proxy_pass != NULL ? proxy_pass : ""); | |
633 | |
717 | 634 curl_easy_setopt(handle->curl, CURLOPT_PROXYUSERPWD, |
635 handle->proxy_info.proxy_auth); | |
707 | 636 } |
637 } | |
708 | 638 |
639 bmp_cfg_db_close(db); | |
707 | 640 } |
641 | |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
642 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
643 struct curl_slist *hdr = NULL; |
754
a77533b76084
[svn] - fix a ringbuffering error in curl which caused trouble with icecast2
nenolod
parents:
753
diff
changeset
|
644 hdr = curl_slist_append(hdr, "Icy-MetaData: 1"); |
556
cd730d42b2bd
[svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents:
543
diff
changeset
|
645 hdr = curl_slist_append(hdr, "User-Agent: Audacious/" VERSION " (curl transport)"); |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
646 curl_easy_setopt(handle->curl, CURLOPT_HTTPHEADER, hdr); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
647 } |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
648 |
543
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
649 //handle->download = vfs_fopen(FILENAME, "wb"); |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
650 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
651 file->handle = handle; |
483 | 652 file->base = &curl_const; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
653 |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
654 if (DEBUG_OPEN_CLOSE) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
655 g_print("Open %s with curl => %p\n", url, handle); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
656 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
657 return file; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
658 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
659 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
660 gint |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
661 curl_vfs_fclose_impl(VFSFile * file) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
662 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
663 gint ret = 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
664 if (file == NULL) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
665 return -1; |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
666 if (DEBUG_OPEN_CLOSE) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
667 g_print("Close %p\n", file->handle); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
668 if (file->handle) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
669 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
670 CurlHandle *handle = file->handle; |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
671 if (DEBUG_CONNECTION) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
672 g_print("Cancel transfer\n"); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
673 curl_req_no_xfer(handle); |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
674 if (DEBUG_CONNECTION) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
675 g_print("Okay\n"); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
676 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
677 g_free(handle->buffer); |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
678 if (handle->name) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
679 g_free(handle->name); |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
680 if (handle->stream_stack != NULL) |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
681 g_slist_free(handle->stream_stack); |
945 | 682 curl_easy_cleanup(handle->curl); |
543
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
683 |
946
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
684 g_mutex_free(handle->curl_mutex); |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
685 g_cond_free(handle->curl_cond); |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
686 |
731
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
687 if (handle->local_ip != NULL) |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
688 g_free(handle->local_ip); |
645849c1e725
[svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents:
718
diff
changeset
|
689 |
717 | 690 if (handle->proxy_info.proxy_host != NULL) |
691 g_free(handle->proxy_info.proxy_host); | |
692 | |
693 if (handle->proxy_info.proxy_auth != NULL) | |
694 g_free(handle->proxy_info.proxy_auth); | |
695 | |
543
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
696 if (handle->download) |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
697 { |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
698 vfs_fclose(handle->download); |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
699 } |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
700 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
701 g_free(handle); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
702 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
703 return ret; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
704 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
705 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
706 size_t |
939 | 707 curl_vfs_fread_impl(gpointer ptr_, |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
708 size_t size, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
709 size_t nmemb, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
710 VFSFile * file) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
711 { |
939 | 712 unsigned char *ptr = ptr_; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
713 CurlHandle *handle = file->handle; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
714 ssize_t sz = size * nmemb; |
934 | 715 ssize_t ret = 0; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
716 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
717 if (sz < 0) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
718 return 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
719 |
534 | 720 // g_print("Reading %d*%d=%d from %p\n", size, nmemb, sz, handle); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
721 |
946
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
722 memset(ptr, '\0', sz); |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
723 |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
724 /* check if there are ungetted chars that should be picked before the real fread */ |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
725 if ( handle->stream_stack != NULL ) |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
726 { |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
727 guchar uc; |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
728 while ( (ret < sz) && (handle->stream_stack != NULL) ) |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
729 { |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
730 uc = GPOINTER_TO_INT(handle->stream_stack->data); |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
731 handle->stream_stack = g_slist_delete_link( handle->stream_stack , handle->stream_stack ); |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
732 memcpy( ptr + ret , &uc , 1 ); |
521 | 733 handle->rd_abs++; |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
734 ret++; |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
735 } |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
736 } |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
737 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
738 curl_req_xfer(handle); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
739 |
946
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
740 if (handle->failed == 1) |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
741 { |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
742 g_print("failed!\n"); |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
743 return 0; |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
744 } |
2d06a4e9b032
[svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents:
945
diff
changeset
|
745 |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
746 if (DEBUG_SEEK) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
747 check(handle); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
748 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
749 while (ret < sz) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
750 { |
934 | 751 ssize_t available; |
430
ed94145472df
[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents:
428
diff
changeset
|
752 while (!(available = buf_available(handle)) && !handle->cancel) |
543
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
753 { |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
754 //g_print("Wait for data on %p\n", handle); |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
755 g_usleep(10000); |
282bede45eef
[svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents:
534
diff
changeset
|
756 } |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
757 if (available > sz - ret) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
758 available = sz - ret; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
759 memcpy(ptr + ret, handle->buffer + handle->rd_index, available); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
760 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
761 handle->rd_index = |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
762 (handle->rd_index + available) % handle->buffer_length; |
466
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
763 if (handle->rd_abs < handle->meta_abs && |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
764 handle->rd_abs + available >= handle->meta_abs) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
765 { |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
766 if (DEBUG_METADATA_REPORT) |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
767 g_print("New song: '%s'\n", handle->title); |
20657d994de8
[svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents:
465
diff
changeset
|
768 } |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
769 handle->rd_abs += available; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
770 ret += available; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
771 if (!available) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
772 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
773 //g_print("EOF reading from %p\n", handle); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
774 break; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
775 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
776 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
777 |
534 | 778 // g_print("Read %d from %p\n", ret, handle); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
779 |
774 | 780 return (size_t)(ret / size); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
781 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
782 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
783 size_t |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
784 curl_vfs_fwrite_impl(gconstpointer ptr, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
785 size_t size, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
786 size_t nmemb, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
787 VFSFile * file) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
788 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
789 return 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
790 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
791 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
792 gint |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
793 curl_vfs_getc_impl(VFSFile *stream) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
794 { |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
795 CurlHandle *handle = (CurlHandle *) stream->handle; |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
796 guchar uc; |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
797 |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
798 g_return_val_if_fail(handle != NULL, EOF); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
799 |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
800 if ( handle->stream_stack != NULL ) /* check if some char was ungetc'ed before */ |
494 | 801 { |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
802 uc = GPOINTER_TO_INT(handle->stream_stack->data); |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
803 handle->stream_stack = g_slist_delete_link( handle->stream_stack , handle->stream_stack ); |
521 | 804 handle->rd_abs++; |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
805 return uc; |
494 | 806 } |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
807 else if (curl_vfs_fread_impl(&uc, 1, 1, stream) != 1) |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
808 return EOF; |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
809 return uc; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
810 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
811 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
812 gint |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
813 curl_vfs_ungetc_impl(gint c, VFSFile *stream) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
814 { |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
815 CurlHandle *handle = (CurlHandle *) stream->handle; |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
816 |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
817 g_return_val_if_fail(handle != NULL, EOF); |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
818 |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
819 handle->stream_stack = g_slist_prepend( handle->stream_stack , GINT_TO_POINTER(c) ); |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
820 if ( handle->stream_stack != NULL ) |
521 | 821 { |
822 handle->rd_abs--; | |
494 | 823 return c; |
521 | 824 } |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
825 else |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
826 return EOF; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
827 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
828 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
829 gint |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
830 curl_vfs_fseek_impl(VFSFile * file, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
831 glong offset, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
832 gint whence) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
833 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
834 size_t posn; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
835 CurlHandle *handle = file->handle; |
510
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
836 /* when a seek is requested, trash the stack of ungetted chars */ |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
837 if ( handle->stream_stack != NULL ) |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
838 { |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
839 g_slist_free( handle->stream_stack ); |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
840 handle->stream_stack = NULL; |
48e9efba7eb0
[svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents:
507
diff
changeset
|
841 } |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
842 if (DEBUG_SEEK) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
843 g_print("Seek %p to %d %d\n", handle, offset, whence); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
844 if (whence == SEEK_END && handle->length == -1) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
845 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
846 if (!handle->thread) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
847 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
848 // We need a HEAD to find out the length |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
849 handle->no_data = 1; |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
850 if (DEBUG_CONNECTION) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
851 g_print("Request for head info\n"); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
852 curl_manage_request(handle); |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
853 if (DEBUG_CONNECTION) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
854 g_print("Completed\n"); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
855 handle->no_data = 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
856 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
857 else |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
858 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
859 // Wait a bit? |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
860 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
861 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
862 |
742 | 863 if (whence == SEEK_END && handle->length <= 0) |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
864 { |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
865 if (DEBUG_SEEK) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
866 g_print("Tried to seek to the end of a file with unknown length\n"); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
867 // don't know how long it is... |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
868 return -1; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
869 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
870 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
871 posn = handle->rd_abs; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
872 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
873 if (whence == SEEK_SET) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
874 handle->rd_abs = offset; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
875 else if (whence == SEEK_END) |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
876 handle->rd_abs = handle->length + offset; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
877 else |
764
5810f14fc8e6
[svn] - revert r1624 due to the fact that it breaks
nenolod
parents:
763
diff
changeset
|
878 handle->rd_abs = handle->rd_abs + offset; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
879 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
880 // XXXX |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
881 // There's a race here between finding available space and |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
882 // allocating it and the check below. |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
883 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
884 if (handle->thread) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
885 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
886 if (handle->rd_abs + handle->buffer_length < handle->wr_abs || |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
887 handle->rd_abs > handle->wr_abs) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
888 { |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
889 if (DEBUG_CONNECTION) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
890 g_print("Stop transfer\n"); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
891 curl_req_no_xfer(handle); |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
892 if (DEBUG_CONNECTION) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
893 g_print("Okay\n"); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
894 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
895 else |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
896 { |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
897 if (DEBUG_CONNECTION) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
898 g_print("Continue transfer\n"); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
899 curl_req_sync_xfer(handle, posn); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
900 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
901 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
902 |
460
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
903 if (DEBUG_SEEK) |
cc7faecc7619
[svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents:
430
diff
changeset
|
904 g_print("Seeked %p from %d to %d\n", handle, posn, handle->rd_abs); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
905 return 0; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
906 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
907 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
908 void |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
909 curl_vfs_rewind_impl(VFSFile * file) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
910 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
911 curl_vfs_fseek_impl(file, 0, SEEK_SET); |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
912 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
913 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
914 glong |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
915 curl_vfs_ftell_impl(VFSFile * file) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
916 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
917 CurlHandle *handle = file->handle; |
521 | 918 return handle->rd_abs; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
919 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
920 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
921 gboolean |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
922 curl_vfs_feof_impl(VFSFile * file) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
923 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
924 CurlHandle *handle = file->handle; |
521 | 925 return handle->rd_abs == handle->length; |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
926 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
927 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
928 gint |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
929 curl_vfs_truncate_impl(VFSFile * file, glong size) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
930 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
931 return -1; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
932 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
933 |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
934 gchar * |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
935 curl_vfs_metadata_impl(VFSFile * file, const gchar * field) |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
936 { |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
937 CurlHandle *handle = file->handle; |
469 | 938 if (!strcmp(field, "stream-name") && handle->name != NULL) |
940
356d2335a975
[svn] - fix curl.c:913: warning: implicit declaration of function 'strdup'
nenolod
parents:
939
diff
changeset
|
939 return g_strdup(handle->name); |
469 | 940 if (!strcmp(field, "track-name") && handle->title != NULL) |
940
356d2335a975
[svn] - fix curl.c:913: warning: implicit declaration of function 'strdup'
nenolod
parents:
939
diff
changeset
|
941 return g_strdup(handle->title); |
741
775c18c4c907
[svn] - add metadata key "content-length", which allows for getting a content length.
nenolod
parents:
731
diff
changeset
|
942 if (!strcmp(field, "content-length")) |
775c18c4c907
[svn] - add metadata key "content-length", which allows for getting a content length.
nenolod
parents:
731
diff
changeset
|
943 return g_strdup_printf("%ld", handle->length); |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
944 return NULL; |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
945 } |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
946 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
947 VFSConstructor curl_const = { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
948 "http://", |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
949 curl_vfs_fopen_impl, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
950 curl_vfs_fclose_impl, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
951 curl_vfs_fread_impl, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
952 curl_vfs_fwrite_impl, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
953 curl_vfs_getc_impl, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
954 curl_vfs_ungetc_impl, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
955 curl_vfs_fseek_impl, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
956 curl_vfs_rewind_impl, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
957 curl_vfs_ftell_impl, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
958 curl_vfs_feof_impl, |
465
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
959 curl_vfs_truncate_impl, |
ffa685855003
[svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents:
460
diff
changeset
|
960 curl_vfs_metadata_impl |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
961 }; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
962 |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
963 VFSConstructor curl_https_const = { |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
964 "https://", |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
965 curl_vfs_fopen_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
966 curl_vfs_fclose_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
967 curl_vfs_fread_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
968 curl_vfs_fwrite_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
969 curl_vfs_getc_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
970 curl_vfs_ungetc_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
971 curl_vfs_fseek_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
972 curl_vfs_rewind_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
973 curl_vfs_ftell_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
974 curl_vfs_feof_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
975 curl_vfs_truncate_impl, |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
976 curl_vfs_metadata_impl |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
977 }; |
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
978 |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
979 static void init(void) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
980 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
981 vfs_register_transport(&curl_const); |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
982 vfs_register_transport(&curl_https_const); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
983 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
984 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
985 static void cleanup(void) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
986 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
987 #if 0 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
988 vfs_unregister_transport(&curl_const); |
519
bbc597d9875d
[svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents:
510
diff
changeset
|
989 vfs_unregister_transport(&curl_https_const); |
428
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
990 #endif |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
991 } |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
992 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
993 LowlevelPlugin llp_curl = { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
994 NULL, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
995 NULL, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
996 "http:// URI Transport", |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
997 init, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
998 cleanup, |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
999 }; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
1000 |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
1001 LowlevelPlugin *get_lplugin_info(void) |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
1002 { |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
1003 return &llp_curl; |
37b3f45b3a68
[svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff
changeset
|
1004 } |