annotate src/neon/neon.c @ 1741:f86ddc8e543b

branch merge
author Ralf Ertzinger <ralf@skytale.net>
date Wed, 19 Sep 2007 12:06:35 +0200
parents 8feacd004f50 f0b53c4db5ba
children 4f4634573e41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1 #include <audacious/vfs.h>
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
2 #include <audacious/plugin.h>
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
3
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
4 #include <ne_socket.h>
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
5 #include <ne_utils.h>
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
6 #include <ne_redirect.h>
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
7 #include <ne_request.h>
1740
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
8 #include <ne_auth.h>
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
9
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
10 #include "debug.h"
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
11 #include "neon.h"
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
12 #include "rb.h"
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
13
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
14 #define NBUFSIZ (128u*1024u)
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
15 #define NETBLKSIZ (4096u)
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
16
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
17 DECLARE_PLUGIN(neon, init, fini)
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
18
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
19 VFSConstructor neon_http_const = {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
20 "http://",
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
21 neon_vfs_fopen_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
22 neon_vfs_fclose_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
23 neon_vfs_fread_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
24 neon_vfs_fwrite_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
25 neon_vfs_getc_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
26 neon_vfs_ungetc_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
27 neon_vfs_fseek_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
28 neon_vfs_rewind_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
29 neon_vfs_ftell_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
30 neon_vfs_feof_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
31 neon_vfs_truncate_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
32 neon_vfs_fsize_impl,
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
33 neon_vfs_metadata_impl
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
34 };
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
35
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
36 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
37 * ========
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
38 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
39
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
40 static struct neon_handle* handle_init(void) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
41
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
42 struct neon_handle* h;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
43
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
44 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
45
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
46 if (NULL == (h = malloc(sizeof(struct neon_handle)))) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
47 _ERROR("Could not allocate memory for handle");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
48 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
49 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
50
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
51 if (0 != init_rb(&(h->rb), NBUFSIZ)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
52 _ERROR("Could not initialize buffer");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
53 free(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
54 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
55 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
56
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
57 h->url = NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
58 h->purl = &purl;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
59 memset(h->purl, 0, sizeof(ne_uri));
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
60 h->session = NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
61 h->request = NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
62 h->redircount = 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
63 h->pos = 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
64 h->content_length = -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
65 h->can_ranges = FALSE;
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
66 h->icy_metaint = 0;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
67 h->icy_metaleft = 0;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
68 h->icy_metadata.stream_name = NULL;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
69 h->icy_metadata.stream_title = NULL;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
70 h->icy_metadata.stream_url = NULL;
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
71 h->reader = NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
72 h->reader_status.mutex = g_mutex_new();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
73 h->reader_status.cond = g_cond_new();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
74 h->reader_status.reading = FALSE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
75 h->reader_status.status = NEON_READER_INIT;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
76 h->eof = FALSE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
77
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
78 _LEAVE h;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
79 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
80
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
81 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
82 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
83 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
84
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
85 static void handle_free(struct neon_handle* h) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
86
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
87 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
88
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
89 ne_uri_free(h->purl);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
90 destroy_rb(&h->rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
91 free(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
92
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
93 _LEAVE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
94 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
95
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
96 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
97 * ----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
98 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
99
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
100 static void init(void) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
101
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
102 int ret;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
103
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
104 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
105
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
106 if (0 != (ret = ne_sock_init())) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
107 _ERROR("Could not initialize neon library: %d\n", ret);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
108 _LEAVE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
109 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
110
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
111 vfs_register_transport(&neon_http_const);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
112
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
113 if (0 != ne_has_support(NE_FEATURE_SSL)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
114 _DEBUG("neon compiled with thread-safe SSL, enabling https:// transport");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
115 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
116
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
117 _LEAVE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
118 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
119
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
120 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
121 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
122 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
123
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
124 static void fini(void) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
125
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
126 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
127
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
128 ne_sock_exit();
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
129
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
130 _LEAVE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
131 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
132
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
133 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
134 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
135 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
136
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
137 static void add_icy(struct icy_metadata* m, gchar* name, gchar* value) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
138
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
139 _ENTER;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
140
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
141 if (0 == g_ascii_strncasecmp(name, "StreamTitle", 11)) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
142 _DEBUG("Found StreamTitle: %s", value);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
143 if (NULL != m->stream_title) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
144 free(m->stream_title);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
145 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
146 m->stream_title = g_strdup(value);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
147 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
148
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
149 if (0 == g_ascii_strncasecmp(name, "StreamUrl", 9)) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
150 _DEBUG("Found StreamUrl: %s", value);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
151 if (NULL != m->stream_url) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
152 free(m->stream_url);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
153 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
154 m->stream_url = g_strdup(value);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
155 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
156
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
157 _LEAVE;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
158 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
159
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
160 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
161 * -----
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
162 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
163
1735
f0b53c4db5ba Call g_strlcpy() on static name/value buffers instead of strcpy().
William Pitcock <nenolod@atheme.org>
parents: 1730
diff changeset
164 #define TAGSIZE 4096
f0b53c4db5ba Call g_strlcpy() on static name/value buffers instead of strcpy().
William Pitcock <nenolod@atheme.org>
parents: 1730
diff changeset
165
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
166 static void parse_icy(struct icy_metadata* m, gchar* metadata, int len) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
167
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
168 gchar* p;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
169 gchar* tstart;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
170 gchar* tend;
1735
f0b53c4db5ba Call g_strlcpy() on static name/value buffers instead of strcpy().
William Pitcock <nenolod@atheme.org>
parents: 1730
diff changeset
171 gchar name[TAGSIZE];
f0b53c4db5ba Call g_strlcpy() on static name/value buffers instead of strcpy().
William Pitcock <nenolod@atheme.org>
parents: 1730
diff changeset
172 gchar value[TAGSIZE];
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
173 int state;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
174 int pos;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
175
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
176 _ENTER;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
177
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
178 p = metadata;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
179 state = 1;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
180 pos = 0;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
181 name[0] = '\0';
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
182 value[0] = '\0';
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
183 tstart = metadata;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
184 tend = metadata;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
185 while ((pos < len) && (*p != '\0')) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
186 switch (state) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
187 case 1:
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
188 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
189 * Reading tag name
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
190 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
191 if ('=' == *p) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
192 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
193 * End of tag name.
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
194 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
195 *p = '\0';
1735
f0b53c4db5ba Call g_strlcpy() on static name/value buffers instead of strcpy().
William Pitcock <nenolod@atheme.org>
parents: 1730
diff changeset
196 g_strlcpy(name, tstart, TAGSIZE);
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
197 _DEBUG("Found tag name: %s", name);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
198 state = 2;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
199 } else {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
200 tend = p;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
201 };
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
202 break;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
203 case 2:
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
204 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
205 * Waiting for start of value
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
206 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
207 if ('\'' == *p) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
208 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
209 * Leading ' of value
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
210 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
211 tend = tstart = p + 1;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
212 state = 3;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
213 value[0] = '\0';
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
214 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
215 break;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
216 case 3:
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
217 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
218 * Reading value
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
219 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
220 if ('\'' == *p) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
221 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
222 * End of value
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
223 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
224 *p = '\0';
1735
f0b53c4db5ba Call g_strlcpy() on static name/value buffers instead of strcpy().
William Pitcock <nenolod@atheme.org>
parents: 1730
diff changeset
225 g_strlcpy(value, tstart, TAGSIZE);
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
226 _DEBUG("Found tag value: %s", value);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
227 add_icy(m, name, value);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
228 state = 4;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
229 } else {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
230 tend = p;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
231 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
232 break;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
233 case 4:
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
234 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
235 * Waiting for next tag start
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
236 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
237 if (';' == *p) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
238 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
239 * Next tag name starts after this char
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
240 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
241 tend = tstart = p + 1;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
242 state = 1;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
243 name[0] = '\0';
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
244 value[0] = '\0';
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
245 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
246 break;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
247 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
248 p++;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
249 pos++;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
250 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
251
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
252 _LEAVE;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
253 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
254
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
255 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
256 * -----
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
257 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
258
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
259 static void kill_reader(struct neon_handle* h) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
260
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
261 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
262
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
263 _DEBUG("Signaling reader thread to terminate");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
264 g_mutex_lock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
265 h->reader_status.reading = FALSE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
266 g_cond_signal(h->reader_status.cond);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
267 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
268
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
269 _DEBUG("Waiting for reader thread to die...");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
270 g_thread_join(h->reader);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
271 _DEBUG("Reader thread has died");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
272 h->reader = NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
273 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
274
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
275 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
276 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
277 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
278
1740
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
279 static int auth_callback(void* userdata, const char* realm, int attempt, char* username, char* password) {
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
280
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
281 struct neon_handle* h = (struct neon_handle*)userdata;
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
282 gchar* authcpy;
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
283 gchar** authtok;
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
284
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
285 _ENTER;
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
286
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
287 if ((NULL == h->purl->userinfo) || ('\0' == *(h->purl->userinfo))) {
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
288 _ERROR("Authentication required, but no credentials set");
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
289 _LEAVE 1;
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
290 }
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
291
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
292 if (NULL == (authcpy = g_strdup(h->purl->userinfo))) {
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
293 /*
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
294 * No auth data
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
295 */
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
296 _ERROR("Could not allocate memory for authentication data");
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
297 _LEAVE 1;
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
298 }
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
299
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
300 authtok = g_strsplit(authcpy, ":", 2);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
301 if ((strlen(authtok[1]) > (NE_ABUFSIZ-1)) || (strlen(authtok[0]) > (NE_ABUFSIZ-1))) {
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
302 _ERROR("Username/Password too long");
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
303 g_strfreev(authtok);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
304 free(authcpy);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
305 _LEAVE 1;
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
306 }
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
307
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
308 strncpy(username, authtok[0], NE_ABUFSIZ);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
309 strncpy(password, authtok[1], NE_ABUFSIZ);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
310
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
311 _DEBUG("Authenticating: Username: %s, Password: %s", username, password);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
312
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
313 g_strfreev(authtok);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
314 free(authcpy);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
315
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
316 _LEAVE attempt;
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
317 }
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
318
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
319 /*
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
320 * -----
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
321 */
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
322
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
323 static void handle_headers(struct neon_handle* h) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
324
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
325 const gchar* name;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
326 const gchar* value;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
327 void* cursor = NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
328 long len;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
329 gchar* endptr;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
330
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
331 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
332
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
333 _DEBUG("Header responses:");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
334 while(NULL != (cursor = ne_response_header_iterate(h->request, cursor, &name, &value))) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
335 _DEBUG("HEADER: %s: %s", name, value);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
336 if (0 == g_ascii_strncasecmp("accept-ranges", name, 13)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
337 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
338 * The server advertises range capability. we need "bytes"
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
339 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
340 if (NULL != g_strrstr(value, "bytes")) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
341 _DEBUG("server can_ranges");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
342 h->can_ranges = TRUE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
343 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
344 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
345
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
346 if (0 == g_ascii_strncasecmp("content-length", name, 14)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
347 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
348 * The server sent us the content length. Parse and store.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
349 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
350 len = strtol(value, &endptr, 10);
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
351 if ((*value != '\0') && (*endptr == '\0') && (len >= 0)) {
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
352 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
353 * Valid data.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
354 */
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
355 _DEBUG("Content length as advertised by server: %ld", len);
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
356 h->content_length = len;
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
357 } else {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
358 _ERROR("Invalid content length header: %s", value);
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
359 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
360 }
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
361
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
362 if (0 == g_ascii_strncasecmp("icy-metaint", name, 11)) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
363 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
364 * The server sent us a ICY metaint header. Parse and store.
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
365 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
366 len = strtol(value, &endptr, 10);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
367 if ((*value != '\0') && (*endptr == '\0') && (len > 0)) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
368 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
369 * Valid data
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
370 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
371 _DEBUG("ICY MetaInt as advertised by server: %ld", len);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
372 h->icy_metaint = len;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
373 h->icy_metaleft = len;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
374 } else {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
375 _ERROR("Invalid ICY MetaInt header: %s", value);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
376 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
377 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
378
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
379 if (0 == g_ascii_strncasecmp("icy-name", name, 8)) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
380 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
381 * The server sent us a ICY name. Save it for later
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
382 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
383 _DEBUG("ICY stream name: %s", value);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
384 if (NULL != h->icy_metadata.stream_name) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
385 free(h->icy_metadata.stream_name);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
386 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
387 h->icy_metadata.stream_name = g_strdup(value);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
388 }
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
389 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
390
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
391 _LEAVE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
392 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
393
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
394 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
395 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
396 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
397
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
398 static int open_request(struct neon_handle* handle, unsigned long startbyte) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
399
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
400 int ret;
1740
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
401 const ne_status* status;
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
402
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
403 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
404
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
405 handle->request = ne_request_create(handle->session, "GET", handle->purl->path);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
406 ne_print_request_header(handle->request, "Range", "bytes=%ld-", startbyte);
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
407 ne_print_request_header(handle->request, "Icy-MetaData", "1");
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
408
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
409 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
410 * Try to connect to the server.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
411 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
412 _DEBUG("Connecting...");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
413 ret = ne_begin_request(handle->request);
1740
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
414 status = ne_get_status(handle->request);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
415 if ((NE_OK == ret) && (401 == status->code)) {
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
416 /*
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
417 * Authorization required. Reconnect to
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
418 * authenticate
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
419 */
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
420 _DEBUG("Reconnecting due to 401");
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
421 ne_end_request(handle->request);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
422 ret = ne_begin_request(handle->request);
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
423 }
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
424
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
425 switch (ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
426 case NE_OK:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
427 /* URL opened OK */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
428 _DEBUG("URL opened OK");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
429 handle->content_start = startbyte;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
430 handle->pos = startbyte;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
431 handle_headers(handle);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
432 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
433 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
434
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
435 case NE_REDIRECT:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
436 /* We hit a redirect. Handle it. */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
437 _DEBUG("Redirect encountered");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
438 handle->redircount += 1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
439 handle->purl = ne_redirect_location(handle->session);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
440 ne_request_destroy(handle->request);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
441 if (NULL == handle->purl) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
442 _ERROR("Could not parse redirect response");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
443 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
444 }
1722
2e33cfa6a872 - Correct some compiler warnings
Ralf Ertzinger <ralf@skytale.net>
parents: 1719
diff changeset
445 _LEAVE 1;
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
446 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
447
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
448 default:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
449 /* Something went wrong. */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
450 _ERROR("Could not open URL: %d", ret);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
451 if (1 == ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
452 _ERROR("neon error string: %s", ne_get_error(handle->session));
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
453 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
454 ne_request_destroy(handle->request);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
455 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
456 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
457 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
458 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
459
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
460 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
461 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
462 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
463
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
464 static int open_handle(struct neon_handle* handle, unsigned long startbyte) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
465
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
466 int ret;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
467
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
468 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
469
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
470 handle->redircount = 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
471
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
472 _DEBUG("Parsing URL");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
473 if (0 != ne_uri_parse(handle->url, handle->purl)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
474 _ERROR("Could not parse URL '%s'", handle->url);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
475 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
476 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
477
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
478 if (0 == handle->purl->port) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
479 handle->purl->port = 80;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
480 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
481
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
482 while (handle->redircount < 10) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
483
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
484 _DEBUG("Creating session");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
485 handle->session = ne_session_create(handle->purl->scheme, handle->purl->host, handle->purl->port);
1740
8feacd004f50 - Add HTTP auth support (http://<username>:<password>@.... scheme)
Ralf Ertzinger <ralf@skytale.net>
parents: 1730
diff changeset
486 ne_add_server_auth(handle->session, NE_AUTH_BASIC, auth_callback, (void *)handle);
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
487 ne_set_session_flag(handle->session, NE_SESSFLAG_ICYPROTO, 1);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
488 ne_set_session_flag(handle->session, NE_SESSFLAG_PERSIST, 0);
1729
eaa8a5747628 - Add network timeouts
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
489 ne_set_connect_timeout(handle->session, 10);
eaa8a5747628 - Add network timeouts
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
490 ne_set_read_timeout(handle->session, 10);
eaa8a5747628 - Add network timeouts
Ralf Ertzinger <ralf@skytale.net>
parents: 1722
diff changeset
491 ne_set_useragent(handle->session, "Audacious/1.4.0");
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
492 ne_redirect_register(handle->session);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
493
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
494 _DEBUG("Creating request");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
495 ret = open_request(handle, startbyte);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
496
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
497 if (0 == ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
498 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
499 } else if (-1 == ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
500 ne_session_destroy(handle->session);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
501 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
502 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
503 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
504
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
505 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
506 * If we get here, our redirect count exceeded
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
507 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
508
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
509 _ERROR("Redirect count exceeded for URL");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
510
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
511 _LEAVE 1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
512 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
513
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
514 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
515 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
516 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
517
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
518 static int fill_buffer(struct neon_handle* h) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
519
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
520 ssize_t bsize;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
521 char buffer[NETBLKSIZ];
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
522 ssize_t to_read;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
523
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
524 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
525
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
526 bsize = free_rb(&h->rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
527 to_read = MIN(bsize, NETBLKSIZ);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
528
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
529 _DEBUG("%d bytes free in buffer, trying to read %d bytes max", bsize, to_read);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
530
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
531 _DEBUG("Reading from the network....");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
532 if (0 >= (bsize = ne_read_response_block(h->request, buffer, to_read))) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
533 if (0 == bsize) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
534 _DEBUG("End of file encountered");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
535 _LEAVE 1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
536 } else {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
537 _ERROR("Error while reading from the network");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
538 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
539 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
540 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
541 _DEBUG("Read %d bytes from the network", bsize);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
542
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
543 if (0 != write_rb(&(h->rb), buffer, bsize)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
544 _ERROR("Error putting data into buffer");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
545 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
546 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
547
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
548 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
549 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
550
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
551 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
552 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
553 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
554
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
555 static int fill_buffer_limit(struct neon_handle* h, unsigned int maxfree) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
556
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
557 ssize_t bfree;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
558 int ret;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
559
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
560 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
561
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
562 bfree = free_rb(&h->rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
563 _DEBUG("Filling buffer up to max %d bytes free, %d bytes free now", maxfree, bfree);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
564
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
565 while (bfree > maxfree) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
566 ret = fill_buffer(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
567 if (-1 == ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
568 _ERROR("Error while filling buffer");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
569 _LEAVE ret;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
570 } else if (1 == ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
571 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
572 * EOF while filling the buffer. Return what we have.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
573 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
574 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
575 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
576
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
577 bfree = free_rb(&h->rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
578 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
579
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
580 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
581 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
582
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
583 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
584 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
585 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
586
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
587 static gpointer reader_thread(void* data) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
588
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
589 struct neon_handle* h = (struct neon_handle*)data;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
590 int ret;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
591
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
592 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
593
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
594 g_mutex_lock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
595
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
596 while(h->reader_status.reading) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
597 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
598
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
599 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
600 * Hit the network only if we have more than NETBLKSIZ of free buffer
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
601 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
602 if (NETBLKSIZ < free_rb(&h->rb)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
603
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
604 _DEBUG("Filling buffer...");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
605 ret = fill_buffer(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
606
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
607 g_mutex_lock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
608 if (-1 == ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
609 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
610 * Error encountered while reading from the network.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
611 * Set the error flag and terminate the
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
612 * reader thread.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
613 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
614 _DEBUG("Error while reading from the network. Terminating reader thread");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
615 h->reader_status.status = NEON_READER_ERROR;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
616 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
617 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
618 } else if (1 == ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
619 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
620 * EOF encountered while reading from the
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
621 * network. Set the EOF status and exit.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
622 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
623 _DEBUG("EOF encountered while reading from the network. Terminating reader thread");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
624 h->reader_status.status = NEON_READER_EOF;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
625 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
626 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
627 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
628
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
629 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
630 * So we actually got some data out of the stream.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
631 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
632 _DEBUG("Network read succeeded");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
633 } else {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
634 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
635 * Not enough free space in the buffer.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
636 * Sleep until the main thread wakes us up.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
637 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
638 g_mutex_lock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
639 if (h->reader_status.reading) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
640 _DEBUG("Reader thread going to sleep");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
641 g_cond_wait(h->reader_status.cond, h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
642 _DEBUG("Reader thread woke up");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
643 } else {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
644 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
645 * Main thread has ordered termination of this thread.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
646 * Leave the loop.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
647 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
648 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
649 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
650 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
651 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
652
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
653 _DEBUG("Reader thread terminating gracefully");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
654 h->reader_status.status = NEON_READER_TERM;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
655 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
656
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
657 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
658 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
659
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
660 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
661 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
662 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
663
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
664 VFSFile* neon_vfs_fopen_impl(const gchar* path, const gchar* mode) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
665
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
666 VFSFile* file;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
667 struct neon_handle* handle;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
668
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
669 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
670
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
671 _DEBUG("Trying to open '%s' with neon", path);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
672
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
673 if (NULL == (file = malloc(sizeof(VFSFile)))) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
674 _ERROR("Could not allocate memory for filehandle");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
675 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
676 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
677
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
678 if (NULL == (handle = handle_init())) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
679 _ERROR("Could not allocate memory for neon handle");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
680 free(file);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
681 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
682 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
683
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
684 if (NULL == (handle->url = strdup(path))) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
685 _ERROR("Could not copy URL string");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
686 handle_free(handle);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
687 free(file);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
688 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
689 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
690
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
691 if (0 != open_handle(handle, 0)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
692 _ERROR("Could not open URL");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
693 handle_free(handle);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
694 free(file);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
695 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
696 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
697
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
698 file->handle = handle;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
699 file->base = &neon_http_const;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
700
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
701 _LEAVE file;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
702 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
703
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
704 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
705 * ----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
706 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
707
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
708 gint neon_vfs_fclose_impl(VFSFile* file) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
709
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
710 struct neon_handle* h = (struct neon_handle *)file->handle;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
711
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
712 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
713
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
714 if (NULL != h->reader) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
715 kill_reader(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
716 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
717
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
718 _DEBUG("Destroying request");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
719 if (NULL != h->request) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
720 ne_request_destroy(h->request);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
721 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
722
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
723 _DEBUG("Destroying session");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
724 ne_session_destroy(h->session);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
725
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
726 handle_free(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
727
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
728 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
729 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
730
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
731 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
732 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
733 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
734
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
735 size_t neon_vfs_fread_impl(gpointer ptr_, size_t size, size_t nmemb, VFSFile* file) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
736
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
737 struct neon_handle* h = (struct neon_handle*)file->handle;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
738 int belem;
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
739 int relem;
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
740 int ret;
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
741 char icy_metadata[4096];
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
742 unsigned char icy_metalen;
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
743
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
744 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
745
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
746 if (NULL == h->request) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
747 _ERROR("No request to read from, seek gone wrong?");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
748 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
749 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
750
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
751 _DEBUG("Requesting %d elements of %d bytes size each (%d bytes total), to be stored at %p",
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
752 nmemb, size, (nmemb*size), ptr_);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
753
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
754 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
755 * Look how much data is in the buffer
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
756 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
757 belem = used_rb(&h->rb) / size;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
758
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
759 if ((NULL != h->reader) && (0 == belem)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
760 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
761 * There is a reader thread, but the buffer is empty.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
762 * If we are running normally we will have to rebuffer.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
763 * Kill the reader thread and restart.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
764 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
765 g_mutex_lock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
766 if (NEON_READER_RUN == h->reader_status.status) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
767 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
768 _ERROR("Buffer underrun, trying rebuffering");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
769 kill_reader(h);
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
770
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
771 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
772 * We have to check if the reader terminated gracefully
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
773 * again
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
774 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
775 if (NEON_READER_TERM != h->reader_status.status) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
776 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
777 * Reader thread did not terminate gracefully.
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
778 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
779 _LEAVE 0;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
780 }
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
781 } else {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
782 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
783 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
784 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
785
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
786 if (NULL == h->reader) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
787 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
788 * There is no reader thread yet. Read the first bytes from
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
789 * the network ourselves, and then fire up the reader thread
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
790 * to keep the buffer filled up.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
791 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
792 _DEBUG("Doing initial buffer fill");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
793 ret = fill_buffer_limit(h, NBUFSIZ/2);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
794
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
795 if (-1 == ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
796 _ERROR("Error while reading from the network");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
797 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
798 } else if (1 == ret) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
799 _ERROR("EOF during initial read");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
800 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
801 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
802
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
803 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
804 * We have some data in the buffer now.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
805 * Start the reader thread.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
806 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
807 h->reader_status.reading = TRUE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
808 if (NULL == (h->reader = g_thread_create(reader_thread, h, TRUE, NULL))) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
809 h->reader_status.reading = FALSE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
810 _ERROR("Error creating reader thread!");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
811 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
812 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
813 g_mutex_lock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
814 h->reader_status.status = NEON_READER_RUN;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
815 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
816 } else {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
817 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
818 * There already is a reader thread. Look if it is in good
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
819 * shape.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
820 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
821 g_mutex_lock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
822 _DEBUG("Reader thread status: %d", h->reader_status.status);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
823 switch (h->reader_status.status) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
824 case NEON_READER_INIT:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
825 case NEON_READER_RUN:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
826 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
827 * All is well, nothing to be done.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
828 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
829 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
830 case NEON_READER_EOF:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
831 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
832 * If there still is data in the buffer, carry on.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
833 * If not, terminate the reader thread and return 0.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
834 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
835 if (0 == used_rb(&h->rb)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
836 _DEBUG("Reached end of stream");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
837 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
838 kill_reader(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
839 h->eof = TRUE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
840 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
841 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
842 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
843 case NEON_READER_ERROR:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
844 /* Terminate the reader and return 0 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
845 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
846 kill_reader(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
847 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
848 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
849 case NEON_READER_TERM:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
850 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
851 * The reader thread terminated gracefully, most
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
852 * likely on our own request.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
853 * We should not get here.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
854 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
855 _ERROR("Reader thread terminated and fread() called. How did we get here?");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
856 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
857 kill_reader(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
858 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
859 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
860 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
861 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
862
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
863 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
864 * Deliver data from the buffer
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
865 */
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
866 if (0 == used_rb(&h->rb)) {
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
867 /*
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
868 * The buffer is still empty, we can deliver no data!
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
869 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
870 _ERROR("Buffer still underrun, fatal.");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
871 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
872 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
873
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
874 if (0 != h->icy_metaint) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
875 _DEBUG("%ld bytes left before next ICY metadata announcement", h->icy_metaleft);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
876 if (0 == h->icy_metaleft) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
877 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
878 * The next data in the buffer is a ICY metadata announcement.
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
879 * Get the length byte
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
880 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
881 read_rb(&h->rb, &icy_metalen, 1);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
882
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
883 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
884 * We need enough data in the buffer to
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
885 * a) Read the complete ICY metadata block
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
886 * b) deliver at least one byte to the reader
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
887 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
888 _DEBUG("Expecting %d bytes of ICY metadata", (icy_metalen*16));
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
889
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
890 if ((free_rb(&h->rb)-(icy_metalen*16)) < size) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
891 /* There is not enough data. We do not have much choice at this point,
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
892 * so we'll deliver the metadata as normal data to the reader and
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
893 * hope for the best.
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
894 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
895 _ERROR("Buffer underrun when reading metadata. Expect audio degradation");
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
896 h->icy_metaleft = h->icy_metaint + (icy_metalen*16);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
897 } else {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
898 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
899 * Grab the metadata from the buffer and send it to the parser
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
900 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
901 read_rb(&h->rb, icy_metadata, (icy_metalen*16));
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
902 parse_icy(&h->icy_metadata, icy_metadata, (icy_metalen*16));
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
903 h->icy_metaleft = h->icy_metaint;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
904 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
905 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
906
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
907 /*
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
908 * The maximum number of bytes we can deliver is determined
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
909 * by the number of bytes left until the next metadata announcement
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
910 */
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
911 belem = h->icy_metaleft / size;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
912 } else {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
913 belem = used_rb(&h->rb) / size;
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
914 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
915
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
916 relem = MIN(belem, nmemb);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
917 _DEBUG("%d elements of returnable data in the buffer", belem);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
918 read_rb(&h->rb, ptr_, relem*size);
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
919
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
920 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
921 * Signal the network thread to continue reading
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
922 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
923 _DEBUG("Waking up reader thread");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
924 g_mutex_lock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
925 g_cond_signal(h->reader_status.cond);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
926 g_mutex_unlock(h->reader_status.mutex);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
927
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
928 h->pos += (relem*size);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
929 h->icy_metaleft -= (relem*size);
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
930
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
931 _DEBUG("Returning %d elements", relem);
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
932
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
933 _LEAVE relem;
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
934 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
935
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
936
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
937 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
938 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
939 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
940
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
941 size_t neon_vfs_fwrite_impl(gconstpointer ptr, size_t size, size_t nmemb, VFSFile* file) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
942
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
943 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
944
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
945 _ERROR("NOT IMPLEMENTED");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
946
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
947 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
948 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
949
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
950 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
951 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
952 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
953
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
954 gint neon_vfs_getc_impl(VFSFile* file) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
955
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
956 gchar c;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
957
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
958 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
959
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
960 if (1 != neon_vfs_fread_impl(&c, 1, 1, file)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
961 _ERROR("Could not getc()!");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
962 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
963 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
964
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
965 _LEAVE c;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
966 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
967
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
968 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
969 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
970 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
971
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
972 gint neon_vfs_ungetc_impl(gint c, VFSFile* stream) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
973
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
974 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
975
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
976 _ERROR("NOT IMPLEMENTED");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
977
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
978 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
979 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
980
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
981 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
982 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
983 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
984
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
985 void neon_vfs_rewind_impl(VFSFile* file) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
986
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
987 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
988
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
989 (void)neon_vfs_fseek_impl(file, 0L, SEEK_SET);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
990
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
991 _LEAVE;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
992 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
993
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
994 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
995 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
996 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
997
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
998 glong neon_vfs_ftell_impl(VFSFile* file) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
999
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1000 struct neon_handle* h = (struct neon_handle *)file->handle;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1001
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1002 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1003
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1004 _DEBUG("Current file position: %ld", h->pos);
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1005
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1006 _LEAVE h->pos;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1007 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1008
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1009 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1010 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1011 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1012
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1013 gboolean neon_vfs_feof_impl(VFSFile* file) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1014
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1015 struct neon_handle* h = (struct neon_handle*)file->handle;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1016
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1017 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1018
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1019 _LEAVE h->eof;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1020 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1021
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1022 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1023 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1024 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1025
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1026 gint neon_vfs_truncate_impl(VFSFile* file, glong size) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1027
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1028 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1029
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1030 _ERROR("NOT IMPLEMENTED");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1031
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1032 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1033 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1034
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1035 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1036 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1037 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1038
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1039 gint neon_vfs_fseek_impl(VFSFile* file, glong offset, gint whence) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1040
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1041 struct neon_handle* h = (struct neon_handle*)file->handle;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1042 long newpos;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1043 long content_length;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1044
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1045 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1046
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1047 _DEBUG("Seek requested: offset %ld, whence %d", offset, whence);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1048 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1049 * Two things must be satisfied for us to be able to seek:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1050 * - the server must advertise a content-length
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1051 * - the server must advertise accept-ranges: bytes
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1052 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1053 if ((-1 == h->content_length) || !h->can_ranges) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1054 _DEBUG("Can not seek due to server restrictions");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1055 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1056 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1057
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1058 content_length = h->content_length + h->content_start;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1059
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1060 switch (whence) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1061 case SEEK_SET:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1062 newpos = offset;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1063 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1064 case SEEK_CUR:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1065 newpos = h->pos + offset;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1066 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1067 case SEEK_END:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1068 newpos = content_length + offset;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1069 break;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1070 default:
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1071 _ERROR("Invalid whence specified");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1072 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1073 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1074
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1075 _DEBUG("Position to seek to: %ld, current: %ld", newpos, h->pos);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1076 if (0 > newpos) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1077 _ERROR("Can not seek before start of stream");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1078 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1079 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1080
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1081 if (newpos > content_length) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1082 _ERROR("Can not seek beyond end of stream");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1083 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1084 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1085
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1086 if (newpos == h->pos) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1087 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1088 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1089
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1090 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1091 * To seek to the new position we have to
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1092 * - stop the current reader thread, if there is one
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1093 * - destroy the current request
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1094 * - dump all data currently in the ringbuffer
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1095 * - create a new request starting at newpos
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1096 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1097 if (NULL != h->reader) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1098 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1099 * There may be a thread still running.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1100 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1101 kill_reader(h);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1102 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1103
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1104 ne_request_destroy(h->request);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1105 ne_session_destroy(h->session);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1106 reset_rb(&h->rb);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1107
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1108 if (0 != open_handle(h, newpos)) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1109 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1110 * Something went wrong while creating the new request.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1111 * There is not much we can do now, we'll set the request
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1112 * to NULL, so that fread() will error out on the next
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1113 * read request
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1114 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1115 _ERROR("Error while creating new request!");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1116 h->request = NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1117 _LEAVE -1;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1118 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1119
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1120 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1121 * Things seem to have worked. The next read request will start
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1122 * the reader thread again.
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1123 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1124
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1125 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1126 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1127
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1128 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1129 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1130 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1131
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1132 gchar *neon_vfs_metadata_impl(VFSFile* file, const gchar* field) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1133
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1134 struct neon_handle* h = (struct neon_handle*)file->handle;
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1135
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1136 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1137
1730
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1138 _DEBUG("Field name: %s", field);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1139
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1140 if (0 == g_ascii_strncasecmp(field, "track-name", 10)) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1141 _LEAVE g_strdup(h->icy_metadata.stream_title);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1142 }
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1143
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1144 if (0 == g_ascii_strncasecmp(field, "stream-name", 11)) {
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1145 _LEAVE g_strdup(h->icy_metadata.stream_name);
50d151b259bb - Add lots of code to support the completely braindead concept that is StreamCast
Ralf Ertzinger <ralf@skytale.net>
parents: 1729
diff changeset
1146 }
1719
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1147
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1148 _LEAVE NULL;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1149 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1150
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1151 /*
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1152 * -----
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1153 */
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1154
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1155 off_t neon_vfs_fsize_impl(VFSFile* file) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1156
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1157 struct neon_handle* h = (struct neon_handle*)file->handle;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1158
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1159 _ENTER;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1160
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1161 if (-1 == h->content_length) {
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1162 _DEBUG("Unknown content length");
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1163 _LEAVE 0;
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1164 }
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1165
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1166 _LEAVE (h->content_start + h->content_length);
29c35cb8873e - Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff changeset
1167 }