annotate src/curl/curl.c @ 521:72515e5313cf trunk

[svn] - refinements for getc/ungetc in curl
author giacomo
date Mon, 22 Jan 2007 12:21:31 -0800
parents bbc597d9875d
children c00fd2a0736f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
19 #include <audacious/vfs.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
20 #include <audacious/plugin.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
21
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
22 #include <curl/curl.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
23
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
24 #include <string.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
25
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
26 #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
27 #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
28
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
29 #define DEBUG_CONNECTION 0
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
30 #define DEBUG_OPEN_CLOSE 0
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
31 #define DEBUG_SEEK 0
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
32 #define DEBUG_READ 0
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
33 #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
34 #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
35 #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
36 #define DEBUG_ICY_VERBOSE 0
485
c257bcf92d90 [svn] - turn debugging back off
nenolod
parents: 483
diff changeset
37 #define DEBUG_METADATA_REPORT 0
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
38
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
39 typedef struct _CurlHandle CurlHandle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
40
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
41 struct _CurlHandle {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
42 CURL *curl;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
43
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
44 gssize length; // the length of the file
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
45 gsize rd_abs; // the absolute position for reading from the stream
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
46 gsize wr_abs; // the absolute position where the input connection is
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
47
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
48 gsize icy_left;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
49 gsize icy_interval;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
50 gint in_icy_meta; // 0=no, 1=before size, 2=in data
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
51 gsize meta_abs; // the absolute position where the metadata changes
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
52
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
53 gsize buffer_length;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
54 gchar *buffer;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
55
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
56 gsize rd_index;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
57 gsize wr_index;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
58
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
59 gsize hdr_index;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
60
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
61 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
62
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
63 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
64 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
65 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
66 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
67 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
68
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
69 gchar *name;
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
70 gchar *title;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
71 };
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
72
483
1b48e9ce21e1 [svn] Set file->base
hansmi
parents: 482
diff changeset
73 VFSConstructor curl_const;
1b48e9ce21e1 [svn] Set file->base
hansmi
parents: 482
diff changeset
74
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
75 /* TODO:
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
76 * - 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
77 * - 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
78 * end of a file
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
79 */
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
80
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
81 /* 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
82 * 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
83 * 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
84 * 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
85 */
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
86
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
87 static size_t buf_space(CurlHandle *handle)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
88 {
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
89 size_t rd_edge = handle->rd_abs - REVERSE_SEEK_SIZE;
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
90 size_t buffer_limit;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
91 size_t cont_limit;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
92 if (rd_edge < 0)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
93 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
94 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
95 (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
96 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
97 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
98 buffer_limit = cont_limit;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
99 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
100 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
101 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
102 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
103 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
104 return buffer_limit;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
105 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
106
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
107 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
108 {
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
109 size_t buffer_limit;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
110 size_t cont_limit;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
111 if (handle->header)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
112 return 0;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
113 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
114 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
115 if (buffer_limit <= 0)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
116 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
117 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
118 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
119
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
120 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
121 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
122 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
123 (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
124 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
125 (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
126 (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
127 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
128
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
129 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
130 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
131 if (handle->length == -1)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
132 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
133 double value;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
134 int retcode =
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
135 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
136 &value);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
137 if (retcode == CURLE_OK)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
138 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
139 handle->length = value;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
140 if (handle->length == 0)
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
141 handle->length = -2;
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
142 //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
143 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
144 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
145 {
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
146 handle->length = -2;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
147 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
148 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
149 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
150 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
151
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
152 #define PROBE 262140
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
153
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
154 #define ICY_NAME "icy-name:"
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
155 #define ICY_METAINT "icy-metaint:"
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
156
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
157 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
158 const char *header)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
159 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
160 if (strlen(header) > size)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
161 return FALSE;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
162 // XXXX wrapped headers
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
163 return !(strncmp(handle->buffer + handle->hdr_index,
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
164 header, strlen(header)));
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
165 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
166
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
167 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
168 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
169 // XXXX wrapped headers
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
170 return strdup(handle->buffer +
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
171 (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
172 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
173
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
174 static void got_header(CurlHandle *handle, size_t size)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
175 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
176 if (DEBUG_HEADERS)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
177 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
178 if (match_header(handle, size, ICY_NAME))
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
179 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
180 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
181 if (DEBUG_HEADERS)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
182 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
183 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
184 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
185 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
186 if (match_header(handle, size, ICY_METAINT))
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
187 {
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
188 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
189 handle->icy_interval = atoi(value);
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
190 free(value);
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
191 if (DEBUG_HEADERS)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
192 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
193 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
194 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
195
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
196 #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
197
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
198 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
199 const char *name)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
200 {
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
201 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
202 size_t i;
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
203 if (DEBUG_ICY_WRAP)
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
204 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
205 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
206 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
207 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
208 handle->buffer_length) <= len)
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
209 return FALSE;
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
210 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
211 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
212 {
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
213 return FALSE;
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
214 }
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
215 return TRUE;
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
216 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
217
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
218 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
219 const char *name)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
220 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
221 size_t end;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
222 size_t sz;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
223 gchar *ret;
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
224 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
225 end = posn;
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
226 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
227 end++;
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
228 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
229 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
230 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
231 {
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
232 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
233 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
234 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
235 if (DEBUG_ICY_WRAP)
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
236 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
237 }
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
238 else
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
239 {
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
240 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
241 }
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
242 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
243 return ret;
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
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
246 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
247 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
248 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
249 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
250 {
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
251 if (handle->title)
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
252 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
253 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
254 if (DEBUG_ICY)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
255 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
256 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
257 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
258 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
259
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
260 static size_t curl_writecb(void *ptr, size_t size, size_t nmemb, void *stream)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
261 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
262 CurlHandle *handle = stream;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
263 gint sz = size * nmemb;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
264 gint ret = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
265 gint trans;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
266
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
267 if (!handle->header)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
268 update_length(handle);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
269
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
270 while (ret < sz)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
271 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
272 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
273 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
274 g_usleep(10000);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
275 //g_print("Wait for free space\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
276 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
277 if (handle->cancel)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
278 break;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
279 if (trans > sz - ret)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
280 trans = sz - ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
281 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
282
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
283 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
284 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
285 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
286 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
287 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
288 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
289 handle->wr_abs += trans;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
290 // write download here
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
291 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
292 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
293 if (DEBUG_ICY)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
294 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
295 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
296 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
297 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
298 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
299 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
300 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
301 // 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
302 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
303 handle->icy_left =
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
304 ((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
305 if (DEBUG_ICY)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
306 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
307 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
308 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
309 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
310 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
311 else
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
312 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
313 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
314 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
315 handle->wr_index--;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
316 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
317 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
318 else
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
319 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
320 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
321 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
322 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
323 handle->buffer_length;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
324 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
325 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
326 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
327 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
328 // wrapped
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
329 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
330 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
331 1, stdout);
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
332 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
333 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
334 else
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
335 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
336 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
337 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
338 stdout);
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
339 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
340 g_print("\n");
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
341 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
342 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
343
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
344 // 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
345 // 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
346 // to add it.
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
347 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
348 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
349 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
350 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
351 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
352 }
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
353 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
354 ret += trans;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
355
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
356 if (handle->header)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
357 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
358 gsize i = handle->hdr_index;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
359 while (1)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
360 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
361 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
362 break;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
363 if (handle->buffer[i] == '\r' &&
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
364 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
365 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
366 gsize size = (handle->buffer_length + i -
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
367 handle->hdr_index) % handle->buffer_length;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
368 handle->buffer[i] = '\0';
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
369 got_header(handle, size);
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
370 if (i == handle->hdr_index)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
371 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
372 // 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
373 handle->header = 0;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
374 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
375 // We read from the start of the data in the request
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
376 handle->rd_index = handle->hdr_index;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
377 // We've already written the amount that's after
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
378 // the header.
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
379 handle->wr_abs +=
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
380 (handle->wr_index - handle->hdr_index + 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
381 // write download here...
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
382 //handle->icy_interval = 0;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
383 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
384 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
385 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
386 handle->icy_left -=
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
387 (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
388 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
389 if (DEBUG_ICY)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
390 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
391 handle->in_icy_meta = 0;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
392 break;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
393 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
394 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
395 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
396 i = (i + 1) % handle->buffer_length;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
397 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
398 }
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
399 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
400 return ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
401 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
402
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
403 static gpointer
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
404 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
405 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
406 CurlHandle *handle = arg;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
407 CURLcode result;
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
408 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
409 g_print("Connect %p\n", handle);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
410
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
411 if (handle->no_data)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
412 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 1);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
413 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
414 {
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
415 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
416 g_print("Start from %d\n", handle->wr_abs);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
417 curl_easy_setopt(handle->curl, CURLOPT_RESUME_FROM, handle->wr_abs);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
418
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
419 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 0);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
420 curl_easy_setopt(handle->curl, CURLOPT_HTTPGET, 1);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
421 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
422
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
423 handle->header = 1;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
424 handle->hdr_index = 0;
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
425 handle->icy_interval = 0;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
426
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
427 result = curl_easy_perform(handle->curl);
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
428 if (result == CURLE_OK)
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
429 update_length(handle);
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
430 // We expect to get CURLE_WRITE_ERROR if we cancel.
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
431 // We get CURLE_GOT_NOTHING if we send a HEAD request to a shoutcast server.
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
432 // We get CURLE_HTTP_RANGE_ERROR if we try to use range with shoutcast.
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
433 if (result != CURLE_OK && result != CURLE_WRITE_ERROR &&
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
434 result != CURLE_GOT_NOTHING && result != CURLE_HTTP_RANGE_ERROR &&
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
435 result != CURLE_PARTIAL_FILE)
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
436 {
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
437 g_print("Got curl error %d\n", result);
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
438 handle->failed = 1;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
439 }
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
440 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
441 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
442 handle->cancel = 1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
443 return NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
444 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
445
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
446 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
447 {
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
448 if (handle->failed)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
449 {
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
450 handle->cancel = 1;
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
451 return;
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
452 }
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
453 if (!handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
454 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
455 handle->cancel = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
456 handle->wr_index = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
457 handle->rd_index = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
458 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
459 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
460 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
461 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
462 TRUE, NULL);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
463 }
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
466 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
467 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
468 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
469 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
470 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
471
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
472 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
473 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
474 if (handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
475 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
476 handle->cancel = 1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
477 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
478 handle->thread = NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
479 handle->cancel = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
480 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
481 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
482
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
483 VFSFile *
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
484 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
485 const gchar * mode)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
486 {
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
487 gchar *url;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
488 CurlHandle *handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
489 VFSFile *file;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
490 if (!path || !mode)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
491 return NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
492
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
493 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
494
473
e1e98289c1ab [svn] - use g_new0
nenolod
parents: 469
diff changeset
495 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
496
473
e1e98289c1ab [svn] - use g_new0
nenolod
parents: 469
diff changeset
497 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
498 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
499 handle->rd_index = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
500 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
501 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
502 handle->rd_abs = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
503 handle->wr_abs = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
504 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
505 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
506 handle->thread = NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
507 handle->length = -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
508 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
509 handle->failed = 0;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
510 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
511 handle->stream_stack = NULL;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
512
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
513 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
514 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
515 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
516 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
517
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
518 curl_easy_setopt(handle->curl, CURLOPT_CONNECTTIMEOUT, 10);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
519
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
520 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
521 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
522
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
523 //add header icy-metadata:1 (when we're ready for it)
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
524 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
525 struct curl_slist *hdr = NULL;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
526 hdr = curl_slist_append(hdr, "icy-metadata:1");
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
527 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
528 }
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
529
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
530 file->handle = handle;
483
1b48e9ce21e1 [svn] Set file->base
hansmi
parents: 482
diff changeset
531 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
532
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
533 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
534 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
535
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
536 return file;
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
539 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
540 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
541 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
542 gint ret = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
543 if (file == NULL)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
544 return -1;
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
545 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
546 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
547 if (file->handle)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
548 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
549 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
550 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
551 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
552 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
553 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
554 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
555
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
556 g_free(handle->buffer);
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
557 if (handle->name)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
558 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
559 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
560 g_slist_free(handle->stream_stack);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
561 curl_easy_cleanup(handle->curl);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
562 g_free(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
563 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
564 return ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
565 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
566
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
567 size_t
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
568 curl_vfs_fread_impl(gpointer ptr,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
569 size_t size,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
570 size_t nmemb,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
571 VFSFile * file)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
572 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
573 CurlHandle *handle = file->handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
574 ssize_t sz = size * nmemb;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
575 size_t ret = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
576
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
577 if (sz < 0)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
578 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
579
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
580 //g_print("Reading %d*%d=%d from %p\n", size, nmemb, sz, handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
581
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
582 /* 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
583 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
584 {
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
585 guchar uc;
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
586 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
587 {
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
588 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
589 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
590 memcpy( ptr + ret , &uc , 1 );
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
591 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
592 ret++;
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
593 }
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
594 }
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
595
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
596 curl_req_xfer(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
597
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
598 if (DEBUG_SEEK)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
599 check(handle);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
600
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
601 while (ret < sz)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
602 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
603 size_t available;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
604 while (!(available = buf_available(handle)) && !handle->cancel)
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
605 g_usleep(10000);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
606 if (available > sz - ret)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
607 available = sz - ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
608 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
609
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
610 handle->rd_index =
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
611 (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
612 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
613 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
614 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
615 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
616 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
617 }
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
618 handle->rd_abs += available;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
619 ret += available;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
620 if (!available)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
621 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
622 //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
623 break;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
624 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
625 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
626
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
627 //g_print("Read %d from %p\n", ret, handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
628
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
629 return ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
630 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
631
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
632 size_t
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
633 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
634 size_t size,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
635 size_t nmemb,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
636 VFSFile * file)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
637 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
638 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
639 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
640
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
641 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
642 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
643 {
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
644 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
645 guchar uc;
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
646
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
647 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
648
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
649 if ( handle->stream_stack != NULL ) /* check if some char was ungetc'ed before */
494
631bd25d2380 [svn] - getc/ungetc emulation
nenolod
parents: 485
diff changeset
650 {
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
651 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
652 handle->stream_stack = g_slist_delete_link( handle->stream_stack , handle->stream_stack );
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
653 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
654 return uc;
494
631bd25d2380 [svn] - getc/ungetc emulation
nenolod
parents: 485
diff changeset
655 }
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
656 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
657 return EOF;
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
658 return uc;
428
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
661 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
662 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
663 {
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
664 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
665
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
666 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
667
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
668 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
669 if ( handle->stream_stack != NULL )
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
670 {
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
671 handle->rd_abs--;
494
631bd25d2380 [svn] - getc/ungetc emulation
nenolod
parents: 485
diff changeset
672 return c;
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
673 }
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
674 else
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
675 return EOF;
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
678 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
679 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
680 glong offset,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
681 gint whence)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
682 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
683 size_t posn;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
684 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
685 /* 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
686 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
687 {
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
688 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
689 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
690 }
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
691 if (DEBUG_SEEK)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
692 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
693 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
694 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
695 if (!handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
696 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
697 // 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
698 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
699 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
700 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
701 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
702 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
703 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
704 handle->no_data = 0;
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 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
707 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
708 // Wait a bit?
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
709 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
710 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
711
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
712 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
713 {
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
714 if (DEBUG_SEEK)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
715 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
716 // 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
717 return -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
718 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
719
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
720 posn = handle->rd_abs;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
721
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
722 if (whence == SEEK_SET)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
723 handle->rd_abs = offset;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
724 else if (whence == SEEK_END)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
725 handle->rd_abs = handle->length + offset;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
726 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
727 handle->rd_abs = handle->rd_abs + offset;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
728
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
729 // XXXX
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
730 // 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
731 // 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
732
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
733 if (handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
734 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
735 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
736 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
737 {
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
738 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
739 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
740 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
741 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
742 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
743 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
744 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
745 {
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
746 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
747 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
748 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
749 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
750 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
751
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
752 if (DEBUG_SEEK)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
753 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
754 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
755 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
756
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
757 void
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
758 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
759 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
760 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
761 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
762
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
763 glong
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
764 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
765 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
766 CurlHandle *handle = file->handle;
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
767 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
768 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
769
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
770 gboolean
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
771 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
772 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
773 CurlHandle *handle = file->handle;
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
774 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
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 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
778 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
779 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
780 return -1;
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
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
783 gchar *
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
784 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
785 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
786 CurlHandle *handle = file->handle;
469
1256144d2a6e [svn] - fix crash
nenolod
parents: 466
diff changeset
787 if (!strcmp(field, "stream-name") && handle->name != NULL)
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
788 return strdup(handle->name);
469
1256144d2a6e [svn] - fix crash
nenolod
parents: 466
diff changeset
789 if (!strcmp(field, "track-name") && handle->title != NULL)
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
790 return strdup(handle->title);
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
791 return NULL;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
792 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
793
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
794 VFSConstructor curl_const = {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
795 "http://",
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
796 curl_vfs_fopen_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
797 curl_vfs_fclose_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
798 curl_vfs_fread_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
799 curl_vfs_fwrite_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
800 curl_vfs_getc_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
801 curl_vfs_ungetc_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
802 curl_vfs_fseek_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
803 curl_vfs_rewind_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
804 curl_vfs_ftell_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
805 curl_vfs_feof_impl,
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
806 curl_vfs_truncate_impl,
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
807 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
808 };
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
809
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
810 VFSConstructor curl_https_const = {
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
811 "https://",
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
812 curl_vfs_fopen_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
813 curl_vfs_fclose_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
814 curl_vfs_fread_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
815 curl_vfs_fwrite_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
816 curl_vfs_getc_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
817 curl_vfs_ungetc_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
818 curl_vfs_fseek_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
819 curl_vfs_rewind_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
820 curl_vfs_ftell_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
821 curl_vfs_feof_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
822 curl_vfs_truncate_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
823 curl_vfs_metadata_impl
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
824 };
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
825
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
826 static void init(void)
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 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
829 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
830 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
831
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
832 static void cleanup(void)
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 #if 0
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
835 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
836 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
837 #endif
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
838 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
839
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
840 LowlevelPlugin llp_curl = {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
841 NULL,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
842 NULL,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
843 "http:// URI Transport",
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
844 init,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
845 cleanup,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
846 };
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 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
849 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
850 return &llp_curl;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
851 }