annotate src/curl/curl.c @ 1226:f15ae221c54c

Add support for mimetypes.
author William Pitcock <nenolod@atheme-project.org>
date Mon, 09 Jul 2007 05:30:14 -0500
parents ed2d7787779e
children 01efa0e5b554
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
556
cd730d42b2bd [svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents: 543
diff changeset
19 #ifdef HAVE_CONFIG_H
cd730d42b2bd [svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents: 543
diff changeset
20 # include "config.h"
cd730d42b2bd [svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents: 543
diff changeset
21 #endif
cd730d42b2bd [svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents: 543
diff changeset
22
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
23 #include <audacious/vfs.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
24 #include <audacious/plugin.h>
707
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
25 #include <audacious/configdb.h>
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
26
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
27 #include <curl/curl.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
28
936
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
29 #include <stdlib.h>
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
30 #include <string.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
31
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
32 #define BUFFER_SIZE 256 * 1024
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
33 #define REVERSE_SEEK_SIZE 2048
1155
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
34 #define DEFAULT_CONNECT_TIMEOUT 3
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
35
945
4f7a55282201 [svn] - back out r2016,2018.
nenolod
parents: 944
diff changeset
36 #define DEBUG_CONNECTION 0
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
37 #define DEBUG_OPEN_CLOSE 1
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
38 #define DEBUG_SEEK 0
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
39 #define DEBUG_READ 0
961
25bc2010e9f0 [svn] - merge some local changes which makes curl threading more reliable.
nenolod
parents: 950
diff changeset
40 #define DEBUG_HEADERS 1
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
41 #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
42 #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
43 #define DEBUG_ICY_VERBOSE 0
485
c257bcf92d90 [svn] - turn debugging back off
nenolod
parents: 483
diff changeset
44 #define DEBUG_METADATA_REPORT 0
961
25bc2010e9f0 [svn] - merge some local changes which makes curl threading more reliable.
nenolod
parents: 950
diff changeset
45 #define DEBUG_CURL 0
1155
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
46 #define DEBUG_SETTINGS 1
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
47
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
48 #if DEBUG_SETTINGS>0
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
49 #define DEBUG_SETTINGS_MSG(...) g_print(__VA_ARGS__);
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
50 #else
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
51 #define DEBUG_SETTINGS_MSG(...)
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
52 #endif
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
53
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
54 typedef struct _CurlHandle CurlHandle;
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 struct _CurlHandle {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
57 CURL *curl;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
58
950
668110a6a412 [svn] - curl: do NOT use signals with the new multi-thread layout, and take care of the url string value
giacomo
parents: 949
diff changeset
59 gchar *url; // URL string, must remain present until curl no longer needs it
668110a6a412 [svn] - curl: do NOT use signals with the new multi-thread layout, and take care of the url string value
giacomo
parents: 949
diff changeset
60
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
61 gssize length; // the length of the file
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
62 gssize rd_abs; // the absolute position for reading from the stream
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
63 gssize wr_abs; // the absolute position where the input connection is
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
64
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
65 gssize icy_left;
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
66 gssize icy_interval;
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
67 gint in_icy_meta; // 0=no, 1=before size, 2=in data
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
68 gssize meta_abs; // the absolute position where the metadata changes
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
69
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
70 gssize buffer_length;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
71 gchar *buffer;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
72
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
73 gssize rd_index;
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
74 gssize wr_index;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
75
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
76 gssize hdr_index;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
77
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
78 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
79
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
80 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
81 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
82 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
83 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
84 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
85
543
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
86 VFSFile *download; // file to write to as we download
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
87
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
88 gchar *name;
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
89 gchar *title;
717
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
90
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
91 struct {
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
92 gchar *proxy_host;
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
93 gchar *proxy_auth;
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
94 } proxy_info;
731
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
95
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
96 gchar *local_ip;
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
97
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
98 GMutex *curl_mutex;
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
99 GCond *curl_cond;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
100 };
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
101
1155
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
102 typedef struct {
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
103 gint connect_timeout;
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
104 } CurlOptions;
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
105
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
106 CurlOptions curl_options;
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
107
936
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
108 void curl_vfs_rewind_impl(VFSFile * file);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
109 glong curl_vfs_ftell_impl(VFSFile * file);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
110 gboolean curl_vfs_feof_impl(VFSFile * file);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
111 gint curl_vfs_truncate_impl(VFSFile * file, glong size);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
112 gchar *curl_vfs_metadata_impl(VFSFile * file, const gchar * field);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
113 size_t curl_vfs_fwrite_impl(gconstpointer ptr, size_t size,
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
114 size_t nmemb,
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
115 VFSFile * file);
939
0e40e86fe338 [svn] - clear up instantiation warnings
nenolod
parents: 938
diff changeset
116 size_t curl_vfs_fread_impl(gpointer ptr_, size_t size,
936
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
117 size_t nmemb,
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
118 VFSFile * file);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
119 gint curl_vfs_fclose_impl(VFSFile * file);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
120 gint curl_vfs_getc_impl(VFSFile *stream);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
121 gint curl_vfs_ungetc_impl(gint c, VFSFile *stream);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
122 gint curl_vfs_fseek_impl(VFSFile * file, glong offset, gint whence);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
123 VFSFile *curl_vfs_fopen_impl(const gchar * path,
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
124 const gchar * mode);
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
125
483
1b48e9ce21e1 [svn] Set file->base
hansmi
parents: 482
diff changeset
126 VFSConstructor curl_const;
1b48e9ce21e1 [svn] Set file->base
hansmi
parents: 482
diff changeset
127
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
128 /* TODO:
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
129 * - 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
130 * - 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
131 * end of a file
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
134 /* 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
135 * 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
136 * 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
137 * 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
138 */
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
139
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
140 static ssize_t buf_space(CurlHandle *handle)
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
141 {
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
142 ssize_t rd_edge = handle->rd_abs - REVERSE_SEEK_SIZE;
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
143 ssize_t buffer_limit;
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
144 ssize_t cont_limit;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
145 if (rd_edge < 0)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
146 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
147 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
148 (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
149 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
150 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
151 buffer_limit = cont_limit;
754
a77533b76084 [svn] - fix a ringbuffering error in curl which caused trouble with icecast2
nenolod
parents: 753
diff changeset
152 if (handle->icy_interval && handle->icy_left)
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
153 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
154 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
155 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
156 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
157 return buffer_limit;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
158 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
159
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
160 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
161 {
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
162 size_t buffer_limit;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
163 size_t cont_limit;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
164 if (handle->header)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
165 return 0;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
166 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
167 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
168 if (buffer_limit <= 0)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
169 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
170 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
171 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
172
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
173 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
174 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
175 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
176 (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
177 printf("%p Not aligned! wr %d rd %d\n", handle,
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
178 (int)((handle->wr_abs - handle->wr_index) % handle->buffer_length),
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
179 (int)((handle->rd_abs - handle->rd_index) % handle->buffer_length));
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
180 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
181
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
182 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
183 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
184 if (handle->length == -1)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
185 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
186 double value;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
187 int retcode =
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
188 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
189 &value);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
190 if (retcode == CURLE_OK)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
191 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
192 handle->length = value;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
193 if (handle->length == 0)
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
194 handle->length = -2;
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
195 //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
196 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
197 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
198 {
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
199 handle->length = -2;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
200 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
201 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
202 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
203 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
204
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
205 #define PROBE 262140
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
206
534
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
207 #define ICE_NAME "ice-name:"
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
208 #define ICY_NAME "icy-name:"
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
209 #define ICY_METAINT "icy-metaint:"
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
210
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
211 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
212 const char *header)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
213 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
214 if (strlen(header) > size)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
215 return FALSE;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
216 // XXXX wrapped headers
961
25bc2010e9f0 [svn] - merge some local changes which makes curl threading more reliable.
nenolod
parents: 950
diff changeset
217 return !(strncasecmp(handle->buffer + handle->hdr_index,
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
218 header, strlen(header)));
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
219 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
220
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
221 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
222 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
223 // XXXX wrapped headers
940
356d2335a975 [svn] - fix curl.c:913: warning: implicit declaration of function 'strdup'
nenolod
parents: 939
diff changeset
224 return g_strdup(handle->buffer +
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
225 (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
226 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
227
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
228 static void got_header(CurlHandle *handle, ssize_t size)
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
229 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
230 if (DEBUG_HEADERS)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
231 g_print("Got header %d bytes\n", (int)size);
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
232 if (match_header(handle, size, ICY_NAME))
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
233 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
234 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
235 if (DEBUG_HEADERS)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
236 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
237 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
238 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
239 }
534
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
240 if (match_header(handle, size, ICE_NAME))
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
241 {
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
242 handle->name = get_value(handle, size, ICE_NAME);
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
243 if (DEBUG_HEADERS)
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
244 {
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
245 g_print("Stream name: %s\n", handle->name);
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
246 }
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
247 }
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
248 if (match_header(handle, size, ICY_METAINT))
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
249 {
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
250 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
251 handle->icy_interval = atoi(value);
936
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
252 g_free(value);
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
253 if (DEBUG_HEADERS)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
254 g_print("Metadata interval: %d\n", (int)handle->icy_interval);
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
255 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
256 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
257
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
258 #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
259
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
260 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
261 const char *name)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
262 {
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
263 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
264 size_t i;
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
265 if (DEBUG_ICY_WRAP)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
266 g_print("Posn=%d\n", (int)posn);
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
267 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
268 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
269 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
270 handle->buffer_length) <= len)
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
271 return FALSE;
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
272 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
273 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
274 {
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
275 return FALSE;
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
276 }
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
277 return TRUE;
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
278 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
279
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
280 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
281 const char *name)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
282 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
283 size_t end;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
284 size_t sz;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
285 gchar *ret;
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
286 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
287 end = posn;
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
288 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
289 end++;
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
290 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
291 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
292 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
293 {
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
294 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
295 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
296 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
297 if (DEBUG_ICY_WRAP)
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
298 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
299 }
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
300 else
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
301 {
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
302 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
303 }
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
304 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
305 return ret;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
306 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
307
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
308 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
309 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
310 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
311 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
312 {
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
313 if (handle->title)
936
c9fe8b112bb2 [svn] - fix a ton of warnings
nenolod
parents: 934
diff changeset
314 g_free(handle->title);
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
315 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
316 if (DEBUG_ICY)
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
317 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
318 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
319 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
320 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
321
938
31089767a3e3 [svn] - use unsigned char instead of gpointer for arithmetic to ensure that writes are 8-bit aligned.
nenolod
parents: 937
diff changeset
322 static size_t curl_writecb(unsigned char *ptr, size_t size, size_t nmemb, void *stream)
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
323 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
324 CurlHandle *handle = stream;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
325 gint sz = size * nmemb;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
326 gint ret = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
327 gint trans;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
328
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
329 if (!handle->header)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
330 update_length(handle);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
331
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
332 g_cond_signal(handle->curl_cond);
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
333
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
334 while (ret < sz)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
335 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
336 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
337 {
543
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
338 //g_print("Wait for free space on %p\n", handle);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
339 g_usleep(10000);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
340 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
341 if (handle->cancel)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
342 break;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
343 if (trans > sz - ret)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
344 trans = sz - ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
345 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
346
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
347 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
348 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
349 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
350 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
351 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
352 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
353 handle->wr_abs += trans;
543
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
354 if (handle->download)
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
355 {
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
356 vfs_fwrite(ptr + ret, trans, 1, handle->download);
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
357 }
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
358 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
359 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
360 if (DEBUG_ICY)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
361 g_print("Metadata inline after %d\n", (int)handle->wr_abs);
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
362 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
363 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
364 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
365 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
366 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
367 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
368 // 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
369 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
370 handle->icy_left =
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
371 ((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
372 if (DEBUG_ICY)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
373 g_print("Metadata of size %d\n", (int)handle->icy_left);
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
374 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
375 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
376 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
377 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
378 else
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
379 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
380 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
381 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
382 handle->wr_index--;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
383 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
384 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
385 else
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
386 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
387 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
388 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
389 handle->wr_index = (handle->wr_index + trans) %
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
390 handle->buffer_length;
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
391 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
392 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
393 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
394 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
395 // wrapped
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
396 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
397 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
398 1, stdout);
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
399 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
400 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
401 else
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
402 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
403 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
404 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
405 stdout);
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
406 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
407 g_print("\n");
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
408 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
409 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
410
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
411 // 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
412 // 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
413 // to add it.
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
414 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
415 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
416 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
417 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
418 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
419 }
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
420 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
421 ret += trans;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
422
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
423 if (handle->header)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
424 {
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
425 gssize i = handle->hdr_index;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
426 while (1)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
427 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
428 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
429 break;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
430 if (handle->buffer[i] == '\r' &&
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
431 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
432 {
937
c11425915fcb [svn] - get rid of shadowed variable
nenolod
parents: 936
diff changeset
433 gssize size_ = (handle->buffer_length + i -
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
434 handle->hdr_index) % handle->buffer_length;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
435 handle->buffer[i] = '\0';
937
c11425915fcb [svn] - get rid of shadowed variable
nenolod
parents: 936
diff changeset
436 got_header(handle, size_);
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
437 if (i == handle->hdr_index)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
438 {
543
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
439 size_t leftover;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
440 // 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
441 handle->header = 0;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
442 handle->hdr_index = (i + 2) % handle->buffer_length;
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
443 // We read from the start of the data in the request
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
444 handle->rd_index = handle->hdr_index;
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
445 // We've already written the amount that's after
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
446 // the header.
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
447 leftover = (handle->wr_index - handle->hdr_index + handle->buffer_length) % handle->buffer_length;
543
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
448 handle->wr_abs += leftover;
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
449 if (handle->download)
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
450 {
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
451 // the data which has to go into the
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
452 // beginning of the file must be at the end
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
453 // of the input that we've dealt with.
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
454 vfs_fwrite(ptr + ret - leftover, leftover, 1,
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
455 handle->download);
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
456 }
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
457 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
458 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
459 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
460 handle->icy_left -=
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
461 (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
462 }
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
463 if (DEBUG_ICY)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
464 g_print("Left %d\n", (int)handle->icy_left);
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
465 handle->in_icy_meta = 0;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
466 break;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
467 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
468 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
469 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
470 i = (i + 1) % handle->buffer_length;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
471 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
472 }
428
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 return ret;
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
477 static gpointer
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
478 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
479 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
480 CurlHandle *handle = arg;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
481 CURLcode result;
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
482 if (DEBUG_CONNECTION)
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
483 g_print("Connect %p\n", handle);
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
484
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
485 if (handle->no_data)
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
486 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 1);
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
487 else
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
488 {
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
489 if (DEBUG_CONNECTION)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
490 g_print("Start from %d\n", (int)handle->wr_abs);
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
491 curl_easy_setopt(handle->curl, CURLOPT_RESUME_FROM, handle->wr_abs);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
492
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
493 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 0);
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
494 curl_easy_setopt(handle->curl, CURLOPT_HTTPGET, 1);
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
495 }
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
496
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
497 handle->header = 1;
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
498 handle->hdr_index = 0;
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
499 handle->icy_interval = 0;
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
500
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
501 result = curl_easy_perform(handle->curl);
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
502 if (result == CURLE_OK)
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
503 update_length(handle);
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
504 // We expect to get CURLE_WRITE_ERROR if we cancel.
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
505 // We get CURLE_GOT_NOTHING if we send a HEAD request to a shoutcast server.
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
506 // We get CURLE_HTTP_RANGE_ERROR if we try to use range with shoutcast.
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
507 if (result != CURLE_OK && result != CURLE_WRITE_ERROR &&
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
508 result != CURLE_GOT_NOTHING && result != CURLE_HTTP_RANGE_ERROR &&
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
509 result != CURLE_PARTIAL_FILE)
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
510 {
790
c199c1f23921 [svn] - translate curl error number into corresponding error message. patch by Joker.
yaz
parents: 774
diff changeset
511 g_print("Got curl error %d: %s\n", result, curl_easy_strerror(result));
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
512 handle->failed = 1;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
513 }
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
514 if (DEBUG_CONNECTION)
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
515 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
516 handle->cancel = 1;
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
517
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
518 g_cond_signal(handle->curl_cond);
961
25bc2010e9f0 [svn] - merge some local changes which makes curl threading more reliable.
nenolod
parents: 950
diff changeset
519 handle->thread = NULL;
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
520
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
521 return NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
522 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
523
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
524 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
525 {
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
526 if (handle->failed)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
527 {
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
528 handle->cancel = 1;
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
529 return;
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
530 }
949
d3b9627861de [svn] - revert r2028.
nenolod
parents: 948
diff changeset
531 if (!handle->thread)
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
532 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
533 handle->cancel = 0;
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
534 handle->wr_index = 0;
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
535 handle->rd_index = 0;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
536 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
537 if (DEBUG_CONNECTION)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
538 g_print("Starting connection %p at %d\n", handle, (int)handle->wr_abs);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
539 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
540 TRUE, NULL);
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
541
961
25bc2010e9f0 [svn] - merge some local changes which makes curl threading more reliable.
nenolod
parents: 950
diff changeset
542 g_mutex_lock(handle->curl_mutex);
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
543 g_cond_wait(handle->curl_cond, handle->curl_mutex);
961
25bc2010e9f0 [svn] - merge some local changes which makes curl threading more reliable.
nenolod
parents: 950
diff changeset
544 g_mutex_unlock(handle->curl_mutex);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
545 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
546 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
547
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
548 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
549 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
550 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
551 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
552 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
553
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
554 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
555 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
556 if (handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
557 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
558 handle->cancel = 1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
559 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
560 handle->thread = NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
561 handle->cancel = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
562 }
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
565 VFSFile *
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
566 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
567 const gchar * mode)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
568 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
569 CurlHandle *handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
570 VFSFile *file;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
571 if (!path || !mode)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
572 return NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
573
473
e1e98289c1ab [svn] - use g_new0
nenolod
parents: 469
diff changeset
574 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
575
473
e1e98289c1ab [svn] - use g_new0
nenolod
parents: 469
diff changeset
576 handle = g_new0(CurlHandle, 1);
950
668110a6a412 [svn] - curl: do NOT use signals with the new multi-thread layout, and take care of the url string value
giacomo
parents: 949
diff changeset
577 handle->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
578 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
579 handle->rd_index = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
580 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
581 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
582 handle->rd_abs = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
583 handle->wr_abs = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
584 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
585 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
586 handle->thread = NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
587 handle->length = -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
588 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
589 handle->failed = 0;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
590 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
591 handle->stream_stack = NULL;
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
592 handle->curl_mutex = g_mutex_new();
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
593 handle->curl_cond = g_cond_new();
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
594
950
668110a6a412 [svn] - curl: do NOT use signals with the new multi-thread layout, and take care of the url string value
giacomo
parents: 949
diff changeset
595 curl_easy_setopt(handle->curl, CURLOPT_URL, handle->url);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
596 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
597 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
598 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
599
1155
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
600 if ( curl_options.connect_timeout > 0 )
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
601 curl_easy_setopt(handle->curl, CURLOPT_CONNECTTIMEOUT, curl_options.connect_timeout);
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
602 else
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
603 curl_easy_setopt(handle->curl, CURLOPT_CONNECTTIMEOUT, DEFAULT_CONNECT_TIMEOUT);
950
668110a6a412 [svn] - curl: do NOT use signals with the new multi-thread layout, and take care of the url string value
giacomo
parents: 949
diff changeset
604 curl_easy_setopt(handle->curl, CURLOPT_NOSIGNAL, 1);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
605
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
606 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
607 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
608
625
fdae06cbebc9 [svn] - set CURLOPT_FOLLOWLOCATION to true, closes #771.
nenolod
parents: 556
diff changeset
609 curl_easy_setopt(handle->curl, CURLOPT_FOLLOWLOCATION, 1);
fdae06cbebc9 [svn] - set CURLOPT_FOLLOWLOCATION to true, closes #771.
nenolod
parents: 556
diff changeset
610
948
8dd7c03376bb [svn] - add DEBUG_CURL to enable curl internal debugging messages
nenolod
parents: 947
diff changeset
611 if (DEBUG_CURL)
8dd7c03376bb [svn] - add DEBUG_CURL to enable curl internal debugging messages
nenolod
parents: 947
diff changeset
612 curl_easy_setopt(handle->curl, CURLOPT_VERBOSE, 1);
8dd7c03376bb [svn] - add DEBUG_CURL to enable curl internal debugging messages
nenolod
parents: 947
diff changeset
613
707
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
614 {
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
615 gboolean tmp = FALSE;
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
616 ConfigDb *db;
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
617
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
618 db = bmp_cfg_db_open();
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
619
731
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
620 bmp_cfg_db_get_bool(db, NULL, "use_local_ip", &tmp);
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
621 if (tmp == TRUE)
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
622 {
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
623 bmp_cfg_db_get_string(db, NULL, "local_ip", &handle->local_ip);
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
624 curl_easy_setopt(handle->curl, CURLOPT_INTERFACE, handle->local_ip);
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
625 }
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
626 tmp = FALSE;
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
627
714
e758e9d4f861 [svn] - fix proxy_use vs use_proxy. reported by joker on IRC.
nenolod
parents: 708
diff changeset
628 bmp_cfg_db_get_bool(db, NULL, "use_proxy", &tmp);
707
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
629 if (tmp == TRUE)
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
630 {
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
631 gint proxy_port = 0;
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
632
717
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
633 bmp_cfg_db_get_string(db, NULL, "proxy_host",
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
634 &handle->proxy_info.proxy_host);
707
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
635 bmp_cfg_db_get_int(db, NULL, "proxy_port", &proxy_port);
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
636
717
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
637 curl_easy_setopt(handle->curl, CURLOPT_PROXY, handle->proxy_info.proxy_host);
707
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
638 curl_easy_setopt(handle->curl, CURLOPT_PROXYPORT, proxy_port);
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
639
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
640 tmp = FALSE;
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
641
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
642 bmp_cfg_db_get_bool(db, NULL, "proxy_use_auth", &tmp);
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
643 if (tmp == TRUE)
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
644 {
717
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
645 gchar *proxy_user = NULL, *proxy_pass = NULL;
707
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
646
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
647 bmp_cfg_db_get_string(db, NULL, "proxy_user", &proxy_user);
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
648 bmp_cfg_db_get_string(db, NULL, "proxy_pass", &proxy_pass);
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
649
717
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
650 handle->proxy_info.proxy_auth = g_strdup_printf("%s:%s",
707
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
651 proxy_user != NULL ? proxy_user : "",
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
652 proxy_pass != NULL ? proxy_pass : "");
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
653
717
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
654 curl_easy_setopt(handle->curl, CURLOPT_PROXYUSERPWD,
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
655 handle->proxy_info.proxy_auth);
707
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
656 }
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
657 }
708
9684a1b4e494 [svn] - close configdb handle
nenolod
parents: 707
diff changeset
658
9684a1b4e494 [svn] - close configdb handle
nenolod
parents: 707
diff changeset
659 bmp_cfg_db_close(db);
707
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
660 }
88d78a61a9fb [svn] - proxy support. somebody test this.
nenolod
parents: 625
diff changeset
661
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
662 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
663 struct curl_slist *hdr = NULL;
754
a77533b76084 [svn] - fix a ringbuffering error in curl which caused trouble with icecast2
nenolod
parents: 753
diff changeset
664 hdr = curl_slist_append(hdr, "Icy-MetaData: 1");
556
cd730d42b2bd [svn] - User-Agent: Audacious/$version (curl transport)
nenolod
parents: 543
diff changeset
665 hdr = curl_slist_append(hdr, "User-Agent: Audacious/" VERSION " (curl transport)");
466
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
666 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
667 }
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
668
543
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
669 //handle->download = vfs_fopen(FILENAME, "wb");
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
670
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
671 file->handle = handle;
483
1b48e9ce21e1 [svn] Set file->base
hansmi
parents: 482
diff changeset
672 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
673
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
674 if (DEBUG_OPEN_CLOSE)
950
668110a6a412 [svn] - curl: do NOT use signals with the new multi-thread layout, and take care of the url string value
giacomo
parents: 949
diff changeset
675 g_print("Open %s with curl => %p\n", handle->url, handle);
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 return file;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
678 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
679
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
680 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
681 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
682 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
683 gint ret = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
684 if (file == NULL)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
685 return -1;
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
686 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
687 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
688 if (file->handle)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
689 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
690 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
691 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
692 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
693 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
694 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
695 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
696
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
697 g_free(handle->buffer);
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
698 if (handle->name)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
699 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
700 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
701 g_slist_free(handle->stream_stack);
945
4f7a55282201 [svn] - back out r2016,2018.
nenolod
parents: 944
diff changeset
702 curl_easy_cleanup(handle->curl);
543
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
703
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
704 g_mutex_free(handle->curl_mutex);
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
705 g_cond_free(handle->curl_cond);
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
706
731
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
707 if (handle->local_ip != NULL)
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
708 g_free(handle->local_ip);
645849c1e725 [svn] - add a (hidden for now) configuration option, use_local_ip and local_ip
nenolod
parents: 718
diff changeset
709
717
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
710 if (handle->proxy_info.proxy_host != NULL)
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
711 g_free(handle->proxy_info.proxy_host);
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
712
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
713 if (handle->proxy_info.proxy_auth != NULL)
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
714 g_free(handle->proxy_info.proxy_auth);
c1ec0d8d9553 [svn] - store proxy info
nenolod
parents: 714
diff changeset
715
543
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
716 if (handle->download)
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
717 {
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
718 vfs_fclose(handle->download);
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
719 }
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
720
950
668110a6a412 [svn] - curl: do NOT use signals with the new multi-thread layout, and take care of the url string value
giacomo
parents: 949
diff changeset
721 if (handle->url != NULL)
668110a6a412 [svn] - curl: do NOT use signals with the new multi-thread layout, and take care of the url string value
giacomo
parents: 949
diff changeset
722 g_free(handle->url);
668110a6a412 [svn] - curl: do NOT use signals with the new multi-thread layout, and take care of the url string value
giacomo
parents: 949
diff changeset
723
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
724 g_free(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
725 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
726 return ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
727 }
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 size_t
939
0e40e86fe338 [svn] - clear up instantiation warnings
nenolod
parents: 938
diff changeset
730 curl_vfs_fread_impl(gpointer ptr_,
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
731 size_t size,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
732 size_t nmemb,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
733 VFSFile * file)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
734 {
939
0e40e86fe338 [svn] - clear up instantiation warnings
nenolod
parents: 938
diff changeset
735 unsigned char *ptr = ptr_;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
736 CurlHandle *handle = file->handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
737 ssize_t sz = size * nmemb;
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
738 ssize_t ret = 0;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
739
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
740 if (sz < 0)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
741 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
742
534
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
743 // g_print("Reading %d*%d=%d from %p\n", size, nmemb, sz, handle);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
744
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
745 memset(ptr, '\0', sz);
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
746
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
747 /* 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
748 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
749 {
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
750 guchar uc;
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
751 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
752 {
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
753 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
754 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
755 memcpy( ptr + ret , &uc , 1 );
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
756 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
757 ret++;
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
758 }
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
759 }
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
760
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
761 curl_req_xfer(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
762
946
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
763 if (handle->failed == 1)
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
764 {
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
765 g_print("failed!\n");
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
766 return 0;
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
767 }
2d06a4e9b032 [svn] - use a g_cond_wait() to ensure curl has started up before we try to read.
nenolod
parents: 945
diff changeset
768
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
769 if (DEBUG_SEEK)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
770 check(handle);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
771
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
772 while (ret < sz)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
773 {
934
d49227a584b0 [svn] - fix warnings with -Wunsigned -Wextra
nenolod
parents: 790
diff changeset
774 ssize_t available;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
775 while (!(available = buf_available(handle)) && !handle->cancel)
543
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
776 {
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
777 //g_print("Wait for data on %p\n", handle);
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
778 g_usleep(10000);
282bede45eef [svn] Support for writing downloaded data to a file (no UI provided yet).
iabervon
parents: 534
diff changeset
779 }
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
780 if (available > sz - ret)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
781 available = sz - ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
782 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
783
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
784 handle->rd_index =
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
785 (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
786 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
787 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
788 {
20657d994de8 [svn] Handle inline metadata. Parsing of tags needs work before it will not crash on
iabervon
parents: 465
diff changeset
789 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
790 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
791 }
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
792 handle->rd_abs += available;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
793 ret += available;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
794 if (!available)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
795 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
796 //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
797 break;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
798 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
799 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
800
534
c00fd2a0736f [svn] - support ice-name: icecast2 header
nenolod
parents: 521
diff changeset
801 // g_print("Read %d from %p\n", ret, handle);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
802
774
b02927277ccb [svn] - fread() should return number of items.
yaz
parents: 764
diff changeset
803 return (size_t)(ret / size);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
804 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
805
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
806 size_t
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
807 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
808 size_t size,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
809 size_t nmemb,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
810 VFSFile * file)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
811 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
812 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
813 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
814
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
815 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
816 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
817 {
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
818 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
819 guchar uc;
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
820
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
821 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
822
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
823 if ( handle->stream_stack != NULL ) /* check if some char was ungetc'ed before */
494
631bd25d2380 [svn] - getc/ungetc emulation
nenolod
parents: 485
diff changeset
824 {
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
825 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
826 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
827 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
828 return uc;
494
631bd25d2380 [svn] - getc/ungetc emulation
nenolod
parents: 485
diff changeset
829 }
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
830 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
831 return EOF;
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
832 return uc;
428
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
835 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
836 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
837 {
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
838 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
839
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
840 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
841
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
842 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
843 if ( handle->stream_stack != NULL )
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
844 {
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
845 handle->rd_abs--;
494
631bd25d2380 [svn] - getc/ungetc emulation
nenolod
parents: 485
diff changeset
846 return c;
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
847 }
510
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
848 else
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
849 return EOF;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
850 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
851
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
852 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
853 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
854 glong offset,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
855 gint whence)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
856 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
857 size_t posn;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
858 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
859 /* 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
860 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
861 {
48e9efba7eb0 [svn] - written ungetc for curl vfs plugin (works along with getc, fread, ftell, feof, fseek)
giacomo
parents: 507
diff changeset
862 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
863 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
864 }
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
865 if (DEBUG_SEEK)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
866 g_print("Seek %p to %d %d\n", handle, (int)offset, whence);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
867 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
868 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
869 if (!handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
870 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
871 // 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
872 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
873 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
874 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
875 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
876 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
877 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
878 handle->no_data = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
879 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
880 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
881 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
882 // Wait a bit?
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
883 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
884 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
885
742
2804b98b09b9 [svn] - fix icecast2, i think.
nenolod
parents: 741
diff changeset
886 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
887 {
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
888 if (DEBUG_SEEK)
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
889 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
890 // 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
891 return -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
892 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
893
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
894 posn = handle->rd_abs;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
895
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
896 if (whence == SEEK_SET)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
897 handle->rd_abs = offset;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
898 else if (whence == SEEK_END)
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
899 handle->rd_abs = handle->length + offset;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
900 else
764
5810f14fc8e6 [svn] - revert r1624 due to the fact that it breaks
nenolod
parents: 763
diff changeset
901 handle->rd_abs = handle->rd_abs + offset;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
902
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
903 // XXXX
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
904 // 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
905 // 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
906
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
907 if (handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
908 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
909 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
910 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
911 {
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
912 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
913 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
914 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
915 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
916 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
917 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
918 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
919 {
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
920 if (DEBUG_CONNECTION)
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
921 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
922 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
923 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
924 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
925
460
cc7faecc7619 [svn] Time out curl connections eventually, and don't retry them on the same VFSFile.
iabervon
parents: 430
diff changeset
926 if (DEBUG_SEEK)
1190
ed2d7787779e more warning elimination.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 1155
diff changeset
927 g_print("Seeked %p from %d to %d\n", handle, (int)posn, (int)handle->rd_abs);
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
928 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
929 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
930
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
931 void
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
932 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
933 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
934 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
935 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
936
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
937 glong
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
938 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
939 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
940 CurlHandle *handle = file->handle;
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
941 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
942 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
943
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
944 gboolean
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
945 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
946 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
947 CurlHandle *handle = file->handle;
521
72515e5313cf [svn] - refinements for getc/ungetc in curl
giacomo
parents: 519
diff changeset
948 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
949 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
950
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
951 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
952 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
953 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
954 return -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
955 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
956
965
ertzing
parents: 961
diff changeset
957 off_t
ertzing
parents: 961
diff changeset
958 curl_vfs_fsize_impl(VFSFile * file)
ertzing
parents: 961
diff changeset
959 {
967
ertzing
parents: 965
diff changeset
960 CurlHandle *handle = file->handle;
ertzing
parents: 965
diff changeset
961
ertzing
parents: 965
diff changeset
962 if (handle->length == -1)
ertzing
parents: 965
diff changeset
963 {
ertzing
parents: 965
diff changeset
964 if (!handle->thread)
ertzing
parents: 965
diff changeset
965 {
ertzing
parents: 965
diff changeset
966 // We need a HEAD to find out the length
ertzing
parents: 965
diff changeset
967 handle->no_data = 1;
ertzing
parents: 965
diff changeset
968 if (DEBUG_CONNECTION)
ertzing
parents: 965
diff changeset
969 g_print("Request for head info\n");
ertzing
parents: 965
diff changeset
970 curl_manage_request(handle);
ertzing
parents: 965
diff changeset
971 if (DEBUG_CONNECTION)
ertzing
parents: 965
diff changeset
972 g_print("Completed\n");
ertzing
parents: 965
diff changeset
973 handle->no_data = 0;
ertzing
parents: 965
diff changeset
974 }
ertzing
parents: 965
diff changeset
975 else
ertzing
parents: 965
diff changeset
976 {
ertzing
parents: 965
diff changeset
977 // Wait a bit?
ertzing
parents: 965
diff changeset
978 }
ertzing
parents: 965
diff changeset
979 }
ertzing
parents: 965
diff changeset
980
ertzing
parents: 965
diff changeset
981 if (handle->length <= 0)
ertzing
parents: 965
diff changeset
982 {
ertzing
parents: 965
diff changeset
983 if (DEBUG_SEEK)
ertzing
parents: 965
diff changeset
984 g_print("Tried to get the length of a file with unknown length\n");
ertzing
parents: 965
diff changeset
985 // don't know how long it is...
ertzing
parents: 965
diff changeset
986 return -1;
ertzing
parents: 965
diff changeset
987 }
ertzing
parents: 965
diff changeset
988 return handle->length;
965
ertzing
parents: 961
diff changeset
989 }
ertzing
parents: 961
diff changeset
990
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
991 gchar *
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
992 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
993 {
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
994 CurlHandle *handle = file->handle;
469
1256144d2a6e [svn] - fix crash
nenolod
parents: 466
diff changeset
995 if (!strcmp(field, "stream-name") && handle->name != NULL)
940
356d2335a975 [svn] - fix curl.c:913: warning: implicit declaration of function 'strdup'
nenolod
parents: 939
diff changeset
996 return g_strdup(handle->name);
469
1256144d2a6e [svn] - fix crash
nenolod
parents: 466
diff changeset
997 if (!strcmp(field, "track-name") && handle->title != NULL)
940
356d2335a975 [svn] - fix curl.c:913: warning: implicit declaration of function 'strdup'
nenolod
parents: 939
diff changeset
998 return g_strdup(handle->title);
741
775c18c4c907 [svn] - add metadata key "content-length", which allows for getting a content length.
nenolod
parents: 731
diff changeset
999 if (!strcmp(field, "content-length"))
775c18c4c907 [svn] - add metadata key "content-length", which allows for getting a content length.
nenolod
parents: 731
diff changeset
1000 return g_strdup_printf("%ld", handle->length);
1226
f15ae221c54c Add support for mimetypes.
William Pitcock <nenolod@atheme-project.org>
parents: 1190
diff changeset
1001 if (!strcmp(field, "content-type"))
f15ae221c54c Add support for mimetypes.
William Pitcock <nenolod@atheme-project.org>
parents: 1190
diff changeset
1002 {
f15ae221c54c Add support for mimetypes.
William Pitcock <nenolod@atheme-project.org>
parents: 1190
diff changeset
1003 char *out = NULL;
f15ae221c54c Add support for mimetypes.
William Pitcock <nenolod@atheme-project.org>
parents: 1190
diff changeset
1004 curl_easy_getinfo(handle->curl, CURLINFO_CONTENT_TYPE, &out);
f15ae221c54c Add support for mimetypes.
William Pitcock <nenolod@atheme-project.org>
parents: 1190
diff changeset
1005
f15ae221c54c Add support for mimetypes.
William Pitcock <nenolod@atheme-project.org>
parents: 1190
diff changeset
1006 if (out)
f15ae221c54c Add support for mimetypes.
William Pitcock <nenolod@atheme-project.org>
parents: 1190
diff changeset
1007 return g_strdup(out);
f15ae221c54c Add support for mimetypes.
William Pitcock <nenolod@atheme-project.org>
parents: 1190
diff changeset
1008 }
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
1009 return NULL;
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
1010 }
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
1011
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1012 VFSConstructor curl_const = {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1013 "http://",
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1014 curl_vfs_fopen_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1015 curl_vfs_fclose_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1016 curl_vfs_fread_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1017 curl_vfs_fwrite_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1018 curl_vfs_getc_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1019 curl_vfs_ungetc_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1020 curl_vfs_fseek_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1021 curl_vfs_rewind_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1022 curl_vfs_ftell_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1023 curl_vfs_feof_impl,
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
1024 curl_vfs_truncate_impl,
965
ertzing
parents: 961
diff changeset
1025 curl_vfs_fsize_impl,
465
ffa685855003 [svn] Provide "name" metadata when the url is a shoutcast stream.
iabervon
parents: 460
diff changeset
1026 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
1027 };
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1028
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1029 VFSConstructor curl_https_const = {
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1030 "https://",
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1031 curl_vfs_fopen_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1032 curl_vfs_fclose_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1033 curl_vfs_fread_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1034 curl_vfs_fwrite_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1035 curl_vfs_getc_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1036 curl_vfs_ungetc_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1037 curl_vfs_fseek_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1038 curl_vfs_rewind_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1039 curl_vfs_ftell_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1040 curl_vfs_feof_impl,
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1041 curl_vfs_truncate_impl,
965
ertzing
parents: 961
diff changeset
1042 curl_vfs_fsize_impl,
519
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1043 curl_vfs_metadata_impl
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1044 };
bbc597d9875d [svn] - re-add code that was accidentally removed after merge of getc/ungetc implementation
giacomo
parents: 510
diff changeset
1045
1155
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1046 static void curl_load_settings(void)
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1047 {
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1048 ConfigDb *cfgfile = bmp_cfg_db_open();
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1049 DEBUG_SETTINGS_MSG("curl - load settings called\n");
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1050
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1051 if ( ( !bmp_cfg_db_get_int( cfgfile , "curl" ,
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1052 "connect_timeout" , &(curl_options.connect_timeout) ) ) ||
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1053 ( curl_options.connect_timeout < 1 ) )
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1054 {
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1055 curl_options.connect_timeout = -1; /* -1 means "use default value" */
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1056 DEBUG_SETTINGS_MSG("curl - connect_timeout set to default value (%i)\n", DEFAULT_CONNECT_TIMEOUT);
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1057 }
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1058 DEBUG_SETTINGS_MSG("curl - connect_timeout value set (%i)\n", curl_options.connect_timeout);
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1059
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1060 bmp_cfg_db_close( cfgfile );
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1061 return;
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1062 }
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1063
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1064 static void curl_save_settings(void)
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1065 {
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1066 ConfigDb *cfgfile = bmp_cfg_db_open();
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1067 DEBUG_SETTINGS_MSG("curl - save settings called\n");
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1068
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1069 bmp_cfg_db_set_int( cfgfile , "curl" ,
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1070 "connect_timeout" , curl_options.connect_timeout );
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1071 DEBUG_SETTINGS_MSG("curl - connect_timeout value saved (%i)\n", curl_options.connect_timeout);
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1072
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1073 bmp_cfg_db_close( cfgfile );
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1074 return;
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1075 }
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1076
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1077 static void init(void)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1078 {
1155
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1079 curl_load_settings();
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1080 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
1081 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
1082 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1083
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1084 static void cleanup(void)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1085 {
1155
6f5a4f0b6fb4 [svn] - curl: allow user to customize connect timeout value using a connect_timeout entry in config file
giacomo
parents: 1146
diff changeset
1086 curl_save_settings();
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1087 #if 0
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1088 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
1089 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
1090 #endif
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1091 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1092
1146
183d03932c9e [svn] - curl, stdio: convert to plugin2 architecture
nenolod
parents: 967
diff changeset
1093 DECLARE_PLUGIN(curl, init, cleanup, NULL, NULL, NULL, NULL, NULL);