annotate src/curl/curl.c @ 430:ed94145472df trunk

[svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept failure on seeking to the end of the file.
author iabervon
date Sun, 14 Jan 2007 23:53:59 -0800
parents 37b3f45b3a68
children cc7faecc7619
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
1 /* Audacious
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
2 * Copyright (c) 2007 Daniel Barkalow
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
3 *
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
7 * (at your option) any later version.
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
8 *
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
12 * GNU General Public License for more details.
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
13 *
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
17 */
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
18
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
19 #include <audacious/vfs.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
20 #include <audacious/plugin.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
21
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
22 #include <curl/curl.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
23
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
24 #include <string.h>
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
25
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
26 #define BUFFER_SIZE 256 * 1024
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
27
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
28 typedef struct _CurlHandle CurlHandle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
29
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
30 struct _CurlHandle {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
31 CURL *curl;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
32
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
33 gssize length; // the length of the file
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
34 gsize rd_abs; // the absolute position for reading from the stream
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
35 gsize wr_abs; // the absolute position where the input connection is
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
36
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
37 gsize buffer_length;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
38 gchar *buffer;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
39
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
40 gsize rd_index;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
41 gsize wr_index;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
42
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
43 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
44 gboolean cancel; // true if the thread should be cancelled
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
45 GThread *thread; // the thread that's reading from the connection
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
46 };
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
47
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
48 /* TODO:
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
49 * - 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
50 * - 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
51 * end of a file
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
52 */
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 /* 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
55 * 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
56 * 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
57 * 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
58 */
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
59
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
60 static size_t buf_space(CurlHandle *handle)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
61 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
62 size_t rd_edge = handle->rd_abs - 2048;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
63 if (rd_edge < 0)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
64 rd_edge = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
65 size_t buffer_limit = handle->buffer_length -
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
66 (handle->wr_abs - rd_edge);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
67 size_t cont_limit = handle->buffer_length - handle->wr_index;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
68 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
69 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
70
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
71 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
72 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
73 size_t buffer_limit = handle->wr_abs - handle->rd_abs;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
74 size_t cont_limit = handle->buffer_length - handle->rd_index;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
75 if (buffer_limit <= 0)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
76 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
77 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
78 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
79
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
80 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
81 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
82 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
83 (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
84 printf("%p Not aligned! wr %d rd %d\n", handle,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
85 (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
86 (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
87 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
88
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
89 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
90 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
91 if (handle->length == -1)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
92 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
93 double value;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
94 int retcode =
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
95 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
96 &value);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
97 if (retcode == CURLE_OK)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
98 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
99 handle->length = value;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
100 if (handle->length == 0)
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
101 handle->length = -2;
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
102 //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
103 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
104 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
105 {
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
106 handle->length = -2;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
107 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
108 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
109 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
110 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
111
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
112 #define PROBE 262140
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
113
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
114 static size_t curl_writecb(void *ptr, size_t size, size_t nmemb, void *stream)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
115 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
116 CurlHandle *handle = stream;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
117 gint sz = size * nmemb;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
118 gint ret = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
119 gint trans;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
120
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
121 update_length(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
122
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
123 while (ret < sz)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
124 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
125 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
126 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
127 g_usleep(10000);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
128 //g_print("Wait for free space\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
129 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
130 if (handle->cancel)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
131 break;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
132 if (trans > sz - ret)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
133 trans = sz - ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
134 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
135
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
136 handle->wr_abs += trans;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
137 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
138 ret += trans;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
139 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
140 return ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
141 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
142
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
143 static gpointer
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
144 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
145 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
146 CurlHandle *handle = arg;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
147 CURLcode result;
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
148 //g_print("Connect %p\n", handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
149
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
150 if (handle->no_data)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
151 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 1);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
152 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
153 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
154 //g_print("Start from %d\n", handle->wr_abs);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
155 curl_easy_setopt(handle->curl, CURLOPT_RESUME_FROM, handle->wr_abs);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
156
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
157 curl_easy_setopt(handle->curl, CURLOPT_NOBODY, 0);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
158 curl_easy_setopt(handle->curl, CURLOPT_HTTPGET, 1);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
159 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
160
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
161 result = curl_easy_perform(handle->curl);
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
162 if (result == CURLE_OK)
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
163 update_length(handle);
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
164 if (result != CURLE_OK && result != CURLE_WRITE_ERROR)
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
165 {
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
166 g_print("Got curl error %d\n", result);
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
167 }
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
168 //g_print("Done %p%s", handle, handle->cancel ? " (aborted)\n" : "\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
169 handle->cancel = 1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
170 return NULL;
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 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
174 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
175 if (!handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
176 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
177 handle->cancel = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
178 handle->wr_index = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
179 handle->rd_index = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
180 handle->wr_abs = handle->rd_abs;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
181 //g_print("Starting connection %p at %d\n", handle, handle->wr_abs);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
182 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
183 TRUE, NULL);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
184 }
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
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
187 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
188 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
189 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
190 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
191 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
192
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
193 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
194 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
195 if (handle->thread)
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 handle->cancel = 1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
198 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
199 handle->thread = NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
200 handle->cancel = 0;
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 VFSFile *
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
205 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
206 const gchar * mode)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
207 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
208 gchar *url = g_malloc(strlen(path) + strlen("http://") + 1);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
209 CurlHandle *handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
210 VFSFile *file;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
211 if (!path || !mode)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
212 return NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
213
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
214 sprintf(url, "http://%s", path);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
215
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
216 file = g_new(VFSFile, 1);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
217
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
218 handle = g_new(CurlHandle, 1);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
219 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
220 handle->rd_index = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
221 handle->wr_index = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
222 handle->rd_abs = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
223 handle->wr_abs = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
224 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
225 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
226 handle->thread = NULL;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
227 handle->length = -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
228 handle->cancel = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
229 handle->no_data = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
230 curl_easy_setopt(handle->curl, CURLOPT_URL, url);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
231 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
232 curl_easy_setopt(handle->curl, CURLOPT_WRITEDATA, handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
233
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
234 file->handle = handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
235
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
236 //g_print("Open %s with curl => %p\n", url, handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
237
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
238 return file;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
239 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
240
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
241 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
242 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
243 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
244 gint ret = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
245 if (file == NULL)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
246 return -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
247 //g_print("Close %p\n", file->handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
248 if (file->handle)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
249 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
250 CurlHandle *handle = file->handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
251 //g_print("Cancel transfer\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
252 curl_req_no_xfer(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
253 //g_print("Okay\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
254
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
255 g_free(handle->buffer);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
256 curl_easy_cleanup(handle->curl);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
257 g_free(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
258 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
259 return ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
260 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
261
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
262 size_t
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
263 curl_vfs_fread_impl(gpointer ptr,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
264 size_t size,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
265 size_t nmemb,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
266 VFSFile * file)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
267 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
268 CurlHandle *handle = file->handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
269 ssize_t sz = size * nmemb;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
270 size_t ret = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
271
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
272 if (sz < 0)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
273 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
274
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
275 //g_print("Reading %d*%d=%d from %p\n", size, nmemb, sz, handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
276
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
277 curl_req_xfer(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
278
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
279 check(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
280
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
281 while (ret < sz)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
282 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
283 size_t available;
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
284 while (!(available = buf_available(handle)) && !handle->cancel)
428
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
285 g_usleep(10000);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
286 if (available > sz - ret)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
287 available = sz - ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
288 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
289
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
290 handle->rd_index =
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
291 (handle->rd_index + available) % handle->buffer_length;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
292 handle->rd_abs += available;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
293 ret += available;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
294 if (!available)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
295 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
296 //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
297 break;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
298 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
299 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
300
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
301 //g_print("Read %d from %p\n", ret, handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
302
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
303 return ret;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
304 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
305
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
306 size_t
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
307 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
308 size_t size,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
309 size_t nmemb,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
310 VFSFile * file)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
311 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
312 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
313 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
314
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
315 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
316 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
317 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
318 gchar c;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
319 if (curl_vfs_fread_impl(&c, 1, 1, stream) != 1)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
320 return -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
321 return c;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
322 }
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 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
325 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
326 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
327 g_print("Tried ungetc\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
328 return -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
329 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
330
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
331 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
332 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
333 glong offset,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
334 gint whence)
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 size_t posn;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
337 CurlHandle *handle = file->handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
338 //g_print("Seek %p to %d %d\n", handle, offset, whence);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
339 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
340 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
341 if (!handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
342 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
343 // 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
344 handle->no_data = 1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
345 //g_print("Request for head info\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
346 curl_manage_request(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
347 //g_print("Completed\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
348 handle->no_data = 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
349 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
350 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
351 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
352 // Wait a bit?
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
353 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
354 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
355
430
ed94145472df [svn] Support shoutcast (over TCP) with VFS HTTP code. mpg123 has to accept
iabervon
parents: 428
diff changeset
356 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
357 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
358 //g_print("Tried to seek to the end of a file with unknown length\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
359 // 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
360 return -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
361 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
362
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
363 posn = handle->rd_abs;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
364
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
365 if (whence == SEEK_SET)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
366 handle->rd_abs = offset;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
367 else if (whence == SEEK_END)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
368 handle->rd_abs = handle->length + offset;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
369 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
370 handle->rd_abs = handle->rd_abs + offset;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
371
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
372 // XXXX
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
373 // 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
374 // 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
375
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
376 if (handle->thread)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
377 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
378 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
379 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
380 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
381 //g_print("Stop transfer\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
382 curl_req_no_xfer(handle);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
383 //g_print("Okay\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
384 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
385 else
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
386 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
387 //g_print("Continue transfer\n");
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
388 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
389 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
390 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
391
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
392 //g_print("Seeked %p from %d to %d\n", handle, posn, handle->rd_abs);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
393 return 0;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
394 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
395
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
396 void
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
397 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
398 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
399 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
400 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
401
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
402 glong
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
403 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
404 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
405 CurlHandle *handle = file->handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
406 return handle->rd_abs;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
407 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
408
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
409 gboolean
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
410 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
411 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
412 CurlHandle *handle = file->handle;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
413 return handle->rd_abs == handle->length;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
414 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
415
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
416 gint
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
417 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
418 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
419 return -1;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
420 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
421
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
422 VFSConstructor curl_const = {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
423 "http://",
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
424 curl_vfs_fopen_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
425 curl_vfs_fclose_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
426 curl_vfs_fread_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
427 curl_vfs_fwrite_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
428 curl_vfs_getc_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
429 curl_vfs_ungetc_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
430 curl_vfs_fseek_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
431 curl_vfs_rewind_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
432 curl_vfs_ftell_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
433 curl_vfs_feof_impl,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
434 curl_vfs_truncate_impl
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
435 };
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
436
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
437 static void init(void)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
438 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
439 vfs_register_transport(&curl_const);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
440 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
441
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
442 static void cleanup(void)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
443 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
444 #if 0
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
445 vfs_unregister_transport(&curl_const);
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
446 #endif
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
447 }
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
448
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
449 LowlevelPlugin llp_curl = {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
450 NULL,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
451 NULL,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
452 "http:// URI Transport",
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
453 init,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
454 cleanup,
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
455 };
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
456
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
457 LowlevelPlugin *get_lplugin_info(void)
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
458 {
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
459 return &llp_curl;
37b3f45b3a68 [svn] Add code for a plugin to use CURL for http. Needs some build-system
iabervon
parents:
diff changeset
460 }