annotate libmpdemux/http.c @ 15837:dbc964f2f00a

Synced with 1023
author jheryan
date Tue, 28 Jun 2005 12:05:37 +0000
parents 52edb32f0c2a
children 4ee24ec6ac16
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
1 /*
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
2 * HTTP Helper
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
3 * by Bertrand Baudet <bertrand_baudet@yahoo.com>
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
4 * (C) 2001, MPlayer team.
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
5 */
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
6
15614
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
7 #include "config.h"
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
8
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
9 #include <stdio.h>
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
10 #include <stdlib.h>
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
11 #include <string.h>
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
12 #include <unistd.h>
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
13
15614
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
14 #ifndef HAVE_WINSOCK2
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
15 #define closesocket close
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
16 #else
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
17 #include <winsock2.h>
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
18 #include <ws2tcpip.h>
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
19 #endif
a4a46131ee71 Change header order to avoid compile error because of STREAM_SEEK
reimar
parents: 15585
diff changeset
20
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
21 #include "http.h"
4816
f1dea39a50bb Fixed the http response parser when the http header only has the HTTP
bertrand
parents: 4311
diff changeset
22 #include "url.h"
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
23 #include "mp_msg.h"
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
24
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
25 #include "stream.h"
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
26 #include "demuxer.h"
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
27 #include "network.h"
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
28 #include "help_mp.h"
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
29
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
30
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
31 extern mime_struct_t mime_type_table[];
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
32 extern int stream_cache_size;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
33 extern int network_bandwidth;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
34
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
35 extern int http_seek(stream_t *stream, off_t pos);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
36
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
37 static int nop_streaming_start( stream_t *stream ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
38 HTTP_header_t *http_hdr = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
39 char *next_url=NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
40 URL_t *rd_url=NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
41 int fd,ret;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
42 if( stream==NULL ) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
43
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
44 fd = stream->fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
45 if( fd<0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
46 fd = http_send_request( stream->streaming_ctrl->url, 0 );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
47 if( fd<0 ) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
48 http_hdr = http_read_response( fd );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
49 if( http_hdr==NULL ) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
50
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
51 switch( http_hdr->status_code ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
52 case 200: // OK
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
53 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
54 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
55 if( http_hdr->body_size>0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
56 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
57 http_free( http_hdr );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
58 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
59 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
60 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
61 break;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
62 // Redirect
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
63 case 301: // Permanently
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
64 case 302: // Temporarily
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
65 ret=-1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
66 next_url = http_get_field( http_hdr, "Location" );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
67
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
68 if (next_url != NULL)
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
69 rd_url=url_new(next_url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
70
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
71 if (next_url != NULL && rd_url != NULL) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
72 mp_msg(MSGT_NETWORK,MSGL_STATUS,"Redirected: Using this url instead %s\n",next_url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
73 stream->streaming_ctrl->url=check4proxies(rd_url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
74 ret=nop_streaming_start(stream); //recursively get streaming started
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
75 } else {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
76 mp_msg(MSGT_NETWORK,MSGL_ERR,"Redirection failed\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
77 closesocket( fd );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
78 fd = -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
79 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
80 return ret;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
81 break;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
82 case 401: //Authorization required
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
83 case 403: //Forbidden
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
84 case 404: //Not found
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
85 case 500: //Server Error
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
86 default:
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
87 mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned code %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
88 closesocket( fd );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
89 fd = -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
90 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
91 break;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
92 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
93 stream->fd = fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
94 } else {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
95 http_hdr = (HTTP_header_t*)stream->streaming_ctrl->data;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
96 if( http_hdr->body_size>0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
97 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
98 http_free( http_hdr );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
99 stream->streaming_ctrl->data = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
100 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
101 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
102 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
103 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
104
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
105 if( http_hdr ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
106 http_free( http_hdr );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
107 stream->streaming_ctrl->data = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
108 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
109
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
110 stream->streaming_ctrl->streaming_read = nop_streaming_read;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
111 stream->streaming_ctrl->streaming_seek = nop_streaming_seek;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
112 stream->streaming_ctrl->prebuffer_size = 64*1024; // 64 KBytes
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
113 stream->streaming_ctrl->buffering = 1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
114 stream->streaming_ctrl->status = streaming_playing_e;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
115 return 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
116 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
117
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
118 HTTP_header_t *
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
119 http_new_header() {
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
120 HTTP_header_t *http_hdr;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
121
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
122 http_hdr = (HTTP_header_t*)malloc(sizeof(HTTP_header_t));
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
123 if( http_hdr==NULL ) return NULL;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
124 memset( http_hdr, 0, sizeof(HTTP_header_t) );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
125
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
126 return http_hdr;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
127 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
128
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
129 void
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
130 http_free( HTTP_header_t *http_hdr ) {
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
131 HTTP_field_t *field, *field2free;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
132 if( http_hdr==NULL ) return;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
133 if( http_hdr->protocol!=NULL ) free( http_hdr->protocol );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
134 if( http_hdr->uri!=NULL ) free( http_hdr->uri );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
135 if( http_hdr->reason_phrase!=NULL ) free( http_hdr->reason_phrase );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
136 if( http_hdr->field_search!=NULL ) free( http_hdr->field_search );
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
137 if( http_hdr->method!=NULL ) free( http_hdr->method );
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
138 if( http_hdr->buffer!=NULL ) free( http_hdr->buffer );
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
139 field = http_hdr->first_field;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
140 while( field!=NULL ) {
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
141 field2free = field;
14460
475c551d9890 free http field_name to fix memleak
reimar
parents: 12391
diff changeset
142 if (field->field_name)
475c551d9890 free http field_name to fix memleak
reimar
parents: 12391
diff changeset
143 free(field->field_name);
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
144 field = field->next;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
145 free( field2free );
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
146 }
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
147 free( http_hdr );
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
148 http_hdr = NULL;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
149 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
150
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
151 int
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
152 http_response_append( HTTP_header_t *http_hdr, char *response, int length ) {
1027
2803b7076c83 Checked the length arg when appending data.
bertrand
parents: 902
diff changeset
153 if( http_hdr==NULL || response==NULL || length<0 ) return -1;
7304
7da2c2a68547 Check if realloc failed on http_hdr->buffer instead of ptr in http_response_append,
bertrand
parents: 7293
diff changeset
154
7293
0d7942100437 - simpler http_response_append (uses realloc())
arpi
parents: 6514
diff changeset
155 http_hdr->buffer = (char*)realloc( http_hdr->buffer, http_hdr->buffer_size+length+1 );
7304
7da2c2a68547 Check if realloc failed on http_hdr->buffer instead of ptr in http_response_append,
bertrand
parents: 7293
diff changeset
156 if( http_hdr->buffer==NULL ) {
7293
0d7942100437 - simpler http_response_append (uses realloc())
arpi
parents: 6514
diff changeset
157 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory (re)allocation failed\n");
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
158 return -1;
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
159 }
7293
0d7942100437 - simpler http_response_append (uses realloc())
arpi
parents: 6514
diff changeset
160 memcpy( http_hdr->buffer+http_hdr->buffer_size, response, length );
0d7942100437 - simpler http_response_append (uses realloc())
arpi
parents: 6514
diff changeset
161 http_hdr->buffer_size += length;
0d7942100437 - simpler http_response_append (uses realloc())
arpi
parents: 6514
diff changeset
162 http_hdr->buffer[http_hdr->buffer_size]=0; // close the string!
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
163 return http_hdr->buffer_size;
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
164 }
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
165
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
166 int
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
167 http_is_header_entire( HTTP_header_t *http_hdr ) {
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
168 if( http_hdr==NULL ) return -1;
7293
0d7942100437 - simpler http_response_append (uses realloc())
arpi
parents: 6514
diff changeset
169 if( http_hdr->buffer==NULL ) return 0; // empty
0d7942100437 - simpler http_response_append (uses realloc())
arpi
parents: 6514
diff changeset
170
3784
8b7722329a27 warning fix == cleanup
arpi
parents: 3514
diff changeset
171 if( strstr(http_hdr->buffer, "\r\n\r\n")==NULL &&
8b7722329a27 warning fix == cleanup
arpi
parents: 3514
diff changeset
172 strstr(http_hdr->buffer, "\n\n")==NULL ) return 0;
8b7722329a27 warning fix == cleanup
arpi
parents: 3514
diff changeset
173 return 1;
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
174 }
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
175
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
176 int
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
177 http_response_parse( HTTP_header_t *http_hdr ) {
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
178 char *hdr_ptr, *ptr;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
179 char *field=NULL;
8179
63a5e03f4346 Removed hard coded value for the length of the header separator.
bertrand
parents: 7304
diff changeset
180 int pos_hdr_sep, hdr_sep_len, len;
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
181 if( http_hdr==NULL ) return -1;
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
182 if( http_hdr->is_parsed ) return 0;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
183
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
184 // Get the protocol
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
185 hdr_ptr = strstr( http_hdr->buffer, " " );
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
186 if( hdr_ptr==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
187 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. No space separator found.\n");
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
188 return -1;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
189 }
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
190 len = hdr_ptr-http_hdr->buffer;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
191 http_hdr->protocol = (char*)malloc(len+1);
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
192 if( http_hdr->protocol==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
193 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
194 return -1;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
195 }
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
196 strncpy( http_hdr->protocol, http_hdr->buffer, len );
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
197 http_hdr->protocol[len]='\0';
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
198 if( !strncasecmp( http_hdr->protocol, "HTTP", 4) ) {
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
199 if( sscanf( http_hdr->protocol+5,"1.%d", &(http_hdr->http_minor_version) )!=1 ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
200 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get HTTP minor version.\n");
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
201 return -1;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
202 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
203 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
204
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
205 // Get the status code
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
206 if( sscanf( ++hdr_ptr, "%d", &(http_hdr->status_code) )!=1 ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
207 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get status code.\n");
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
208 return -1;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
209 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
210 hdr_ptr += 4;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
211
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
212 // Get the reason phrase
3514
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
213 ptr = strstr( hdr_ptr, "\n" );
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
214 if( hdr_ptr==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
215 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get the reason phrase.\n");
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
216 return -1;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
217 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
218 len = ptr-hdr_ptr;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
219 http_hdr->reason_phrase = (char*)malloc(len+1);
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
220 if( http_hdr->reason_phrase==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
221 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
222 return -1;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
223 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
224 strncpy( http_hdr->reason_phrase, hdr_ptr, len );
4311
c9f861653fe2 Modified the output of the http_debug function.
bertrand
parents: 3785
diff changeset
225 if( http_hdr->reason_phrase[len-1]=='\r' ) {
c9f861653fe2 Modified the output of the http_debug function.
bertrand
parents: 3785
diff changeset
226 len--;
c9f861653fe2 Modified the output of the http_debug function.
bertrand
parents: 3785
diff changeset
227 }
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
228 http_hdr->reason_phrase[len]='\0';
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
229
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
230 // Set the position of the header separator: \r\n\r\n
8179
63a5e03f4346 Removed hard coded value for the length of the header separator.
bertrand
parents: 7304
diff changeset
231 hdr_sep_len = 4;
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
232 ptr = strstr( http_hdr->buffer, "\r\n\r\n" );
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
233 if( ptr==NULL ) {
3514
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
234 ptr = strstr( http_hdr->buffer, "\n\n" );
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
235 if( ptr==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
236 mp_msg(MSGT_NETWORK,MSGL_ERR,"Header may be incomplete. No CRLF CRLF found.\n");
3514
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
237 return -1;
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
238 }
8179
63a5e03f4346 Removed hard coded value for the length of the header separator.
bertrand
parents: 7304
diff changeset
239 hdr_sep_len = 2;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
240 }
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
241 pos_hdr_sep = ptr-http_hdr->buffer;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
242
3514
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
243 // Point to the first line after the method line.
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
244 hdr_ptr = strstr( http_hdr->buffer, "\n" )+1;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
245 do {
3514
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
246 ptr = hdr_ptr;
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
247 while( *ptr!='\r' && *ptr!='\n' ) ptr++;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
248 len = ptr-hdr_ptr;
4816
f1dea39a50bb Fixed the http response parser when the http header only has the HTTP
bertrand
parents: 4311
diff changeset
249 if( len==0 ) break;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
250 field = (char*)realloc(field, len+1);
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
251 if( field==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
252 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
253 return -1;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
254 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
255 strncpy( field, hdr_ptr, len );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
256 field[len]='\0';
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
257 http_set_field( http_hdr, field );
3514
43518985def8 Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents: 3497
diff changeset
258 hdr_ptr = ptr+((*ptr=='\r')?2:1);
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
259 } while( hdr_ptr<(http_hdr->buffer+pos_hdr_sep) );
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
260
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
261 if( field!=NULL ) free( field );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
262
8179
63a5e03f4346 Removed hard coded value for the length of the header separator.
bertrand
parents: 7304
diff changeset
263 if( pos_hdr_sep+hdr_sep_len<http_hdr->buffer_size ) {
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
264 // Response has data!
8179
63a5e03f4346 Removed hard coded value for the length of the header separator.
bertrand
parents: 7304
diff changeset
265 http_hdr->body = http_hdr->buffer+pos_hdr_sep+hdr_sep_len;
63a5e03f4346 Removed hard coded value for the length of the header separator.
bertrand
parents: 7304
diff changeset
266 http_hdr->body_size = http_hdr->buffer_size-(pos_hdr_sep+hdr_sep_len);
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
267 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
268
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
269 http_hdr->is_parsed = 1;
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
270 return 0;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
271 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
272
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
273 char *
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
274 http_build_request( HTTP_header_t *http_hdr ) {
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
275 char *ptr, *uri=NULL;
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
276 int len;
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
277 HTTP_field_t *field;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
278 if( http_hdr==NULL ) return NULL;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
279
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
280 if( http_hdr->method==NULL ) http_set_method( http_hdr, "GET");
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
281 if( http_hdr->uri==NULL ) http_set_uri( http_hdr, "/");
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
282 else {
12391
2677bfac3838 Fix url escaping and avoid double escape
rtognimp
parents: 12083
diff changeset
283 uri = (char*)malloc(strlen(http_hdr->uri) + 1);
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
284 if( uri==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
285 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
286 return NULL;
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
287 }
12391
2677bfac3838 Fix url escaping and avoid double escape
rtognimp
parents: 12083
diff changeset
288 strcpy(uri,http_hdr->uri);
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
289 }
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
290
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
291 //**** Compute the request length
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
292 // Add the Method line
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
293 len = strlen(http_hdr->method)+strlen(uri)+12;
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
294 // Add the fields
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
295 field = http_hdr->first_field;
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
296 while( field!=NULL ) {
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
297 len += strlen(field->field_name)+2;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
298 field = field->next;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
299 }
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
300 // Add the CRLF
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
301 len += 2;
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
302 // Add the body
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
303 if( http_hdr->body!=NULL ) {
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
304 len += http_hdr->body_size;
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
305 }
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
306 // Free the buffer if it was previously used
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
307 if( http_hdr->buffer!=NULL ) {
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
308 free( http_hdr->buffer );
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
309 http_hdr->buffer = NULL;
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
310 }
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
311 http_hdr->buffer = (char*)malloc(len+1);
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
312 if( http_hdr->buffer==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
313 mp_msg(MSGT_NETWORK,MSGL_ERR,"Memory allocation failed\n");
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
314 return NULL;
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
315 }
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
316 http_hdr->buffer_size = len;
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
317
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
318 //*** Building the request
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
319 ptr = http_hdr->buffer;
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
320 // Add the method line
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
321 ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", http_hdr->method, uri, http_hdr->http_minor_version );
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
322 field = http_hdr->first_field;
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
323 // Add the field
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
324 while( field!=NULL ) {
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
325 ptr += sprintf( ptr, "%s\r\n", field->field_name );
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
326 field = field->next;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
327 }
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
328 ptr += sprintf( ptr, "\r\n" );
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
329 // Add the body
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
330 if( http_hdr->body!=NULL ) {
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
331 memcpy( ptr, http_hdr->body, http_hdr->body_size );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
332 }
3497
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
333
6c1e57bdbd96 Made the HTTP request escaped the url.
bertrand
parents: 3039
diff changeset
334 if( uri ) free( uri );
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
335 return http_hdr->buffer;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
336 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
337
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
338 char *
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
339 http_get_field( HTTP_header_t *http_hdr, const char *field_name ) {
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
340 if( http_hdr==NULL || field_name==NULL ) return NULL;
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
341 http_hdr->field_search_pos = http_hdr->first_field;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
342 http_hdr->field_search = (char*)realloc( http_hdr->field_search, strlen(field_name)+1 );
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
343 if( http_hdr->field_search==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
344 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
345 return NULL;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
346 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
347 strcpy( http_hdr->field_search, field_name );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
348 return http_get_next_field( http_hdr );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
349 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
350
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
351 char *
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
352 http_get_next_field( HTTP_header_t *http_hdr ) {
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
353 char *ptr;
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
354 HTTP_field_t *field;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
355 if( http_hdr==NULL ) return NULL;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
356
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
357 field = http_hdr->field_search_pos;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
358 while( field!=NULL ) {
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
359 ptr = strstr( field->field_name, ":" );
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
360 if( ptr==NULL ) return NULL;
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
361 if( !strncasecmp( field->field_name, http_hdr->field_search, ptr-(field->field_name) ) ) {
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
362 ptr++; // Skip the column
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
363 while( ptr[0]==' ' ) ptr++; // Skip the spaces if there is some
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
364 http_hdr->field_search_pos = field->next;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
365 return ptr; // return the value without the field name
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
366 }
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
367 field = field->next;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
368 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
369 return NULL;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
370 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
371
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
372 void
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
373 http_set_field( HTTP_header_t *http_hdr, const char *field_name ) {
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
374 HTTP_field_t *new_field;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
375 if( http_hdr==NULL || field_name==NULL ) return;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
376
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
377 new_field = (HTTP_field_t*)malloc(sizeof(HTTP_field_t));
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
378 if( new_field==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
379 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
380 return;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
381 }
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
382 new_field->next = NULL;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
383 new_field->field_name = (char*)malloc(strlen(field_name)+1);
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
384 if( new_field->field_name==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
385 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
386 return;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
387 }
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
388 strcpy( new_field->field_name, field_name );
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
389
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
390 if( http_hdr->last_field==NULL ) {
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
391 http_hdr->first_field = new_field;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
392 } else {
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
393 http_hdr->last_field->next = new_field;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
394 }
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
395 http_hdr->last_field = new_field;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
396 http_hdr->field_nb++;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
397 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
398
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
399 void
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
400 http_set_method( HTTP_header_t *http_hdr, const char *method ) {
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
401 if( http_hdr==NULL || method==NULL ) return;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
402
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
403 http_hdr->method = (char*)malloc(strlen(method)+1);
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
404 if( http_hdr->method==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
405 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
406 return;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
407 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
408 strcpy( http_hdr->method, method );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
409 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
410
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
411 void
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
412 http_set_uri( HTTP_header_t *http_hdr, const char *uri ) {
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
413 if( http_hdr==NULL || uri==NULL ) return;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
414
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
415 http_hdr->uri = (char*)malloc(strlen(uri)+1);
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
416 if( http_hdr->uri==NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
417 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
418 return;
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
419 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
420 strcpy( http_hdr->uri, uri );
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
421 }
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
422
6514
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
423 int
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
424 http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
425 char *auth, *usr_pass, *b64_usr_pass;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
426 int encoded_len, pass_len=0, out_len;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
427 if( http_hdr==NULL || username==NULL ) return -1;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
428
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
429 if( password!=NULL ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
430 pass_len = strlen(password);
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
431 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
432
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
433 usr_pass = (char*)malloc(strlen(username)+pass_len+2);
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
434 if( usr_pass==NULL ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
435 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
436 return -1;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
437 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
438
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
439 sprintf( usr_pass, "%s:%s", username, (password==NULL)?"":password );
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
440
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
441 // Base 64 encode with at least 33% more data than the original size
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
442 encoded_len = strlen(usr_pass)*2;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
443 b64_usr_pass = (char*)malloc(encoded_len);
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
444 if( b64_usr_pass==NULL ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
445 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
446 return -1;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
447 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
448
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
449 out_len = base64_encode( usr_pass, strlen(usr_pass), b64_usr_pass, encoded_len);
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
450 if( out_len<0 ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
451 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Base64 out overflow\n");
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
452 return -1;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
453 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
454
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
455 b64_usr_pass[out_len]='\0';
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
456
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
457 auth = (char*)malloc(encoded_len+22);
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
458 if( auth==NULL ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
459 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n");
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
460 return -1;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
461 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
462
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
463 sprintf( auth, "Authorization: Basic %s", b64_usr_pass);
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
464 http_set_field( http_hdr, auth );
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
465
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
466 free( usr_pass );
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
467 free( b64_usr_pass );
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
468 free( auth );
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
469
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
470 return 0;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
471 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
472
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
473 void
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
474 http_debug_hdr( HTTP_header_t *http_hdr ) {
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
475 HTTP_field_t *field;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
476 int i = 0;
902
ede5785faa53 Bugs fix, improvements...
bertrand
parents: 870
diff changeset
477 if( http_hdr==NULL ) return;
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
478
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
479 mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- START ---\n");
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
480 mp_msg(MSGT_NETWORK,MSGL_V,"protocol: [%s]\n", http_hdr->protocol );
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
481 mp_msg(MSGT_NETWORK,MSGL_V,"http minor version: [%d]\n", http_hdr->http_minor_version );
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
482 mp_msg(MSGT_NETWORK,MSGL_V,"uri: [%s]\n", http_hdr->uri );
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
483 mp_msg(MSGT_NETWORK,MSGL_V,"method: [%s]\n", http_hdr->method );
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
484 mp_msg(MSGT_NETWORK,MSGL_V,"status code: [%d]\n", http_hdr->status_code );
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
485 mp_msg(MSGT_NETWORK,MSGL_V,"reason phrase: [%s]\n", http_hdr->reason_phrase );
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
486 mp_msg(MSGT_NETWORK,MSGL_V,"body size: [%d]\n", http_hdr->body_size );
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
487
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
488 mp_msg(MSGT_NETWORK,MSGL_V,"Fields:\n");
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
489 field = http_hdr->first_field;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
490 while( field!=NULL ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
491 mp_msg(MSGT_NETWORK,MSGL_V," %d - %s\n", i++, field->field_name );
3039
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
492 field = field->next;
80189681c02b Removed the field number limitation.
bertrand
parents: 2489
diff changeset
493 }
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 4816
diff changeset
494 mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- END ---\n");
870
f641c96e431b Some simple code to handle HTTP requests/responses.
bertrand
parents:
diff changeset
495 }
6514
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
496
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
497 int
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
498 base64_encode(const void *enc, int encLen, char *out, int outMax) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
499 static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
500
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
501 unsigned char *encBuf;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
502 int outLen;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
503 unsigned int bits;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
504 unsigned int shift;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
505
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
506 encBuf = (unsigned char*)enc;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
507 outLen = 0;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
508 bits = 0;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
509 shift = 0;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
510
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
511 while( outLen<outMax ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
512 if( encLen>0 ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
513 // Shift in byte
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
514 bits <<= 8;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
515 bits |= *encBuf;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
516 shift += 8;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
517 // Next byte
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
518 encBuf++;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
519 encLen--;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
520 } else if( shift>0 ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
521 // Pad last bits to 6 bits - will end next loop
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
522 bits <<= 6 - shift;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
523 shift = 6;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
524 } else {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
525 // Terminate with Mime style '='
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
526 *out = '=';
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
527 outLen++;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
528
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
529 return outLen;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
530 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
531
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
532 // Encode 6 bit segments
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
533 while( shift>=6 ) {
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
534 shift -= 6;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
535 *out = b64[ (bits >> shift) & 0x3F ];
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
536 out++;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
537 outLen++;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
538 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
539 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
540
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
541 // Output overflow
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
542 return -1;
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
543 }
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
544
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
545 static int http_streaming_start(stream_t *stream, int* file_format) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
546 HTTP_header_t *http_hdr;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
547 unsigned int i;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
548 int fd=-1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
549 int redirect = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
550 int auth_retry=0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
551 int seekable=0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
552 char *content_type;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
553 char *next_url;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
554 URL_t *url = stream->streaming_ctrl->url;
6514
37b0b3302395 Added base64 encoder
bertrand
parents: 6465
diff changeset
555
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
556 do
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
557 {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
558 fd = http_send_request( url, 0 );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
559 if( fd<0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
560 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
561 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
562
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
563 http_hdr = http_read_response( fd );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
564 if( http_hdr==NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
565 closesocket( fd );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
566 http_free( http_hdr );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
567 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
568 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
569
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
570 stream->fd=fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
571 if( verbose>0 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
572 http_debug_hdr( http_hdr );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
573 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
574
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
575 stream->streaming_ctrl->data = (void*)http_hdr;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
576
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
577 // Check if we can make partial content requests and thus seek in http-streams
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
578 if( http_hdr!=NULL && http_hdr->status_code==200 ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
579 char *accept_ranges;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
580 if( (accept_ranges = http_get_field(http_hdr,"Accept-Ranges")) != NULL )
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
581 seekable = strncmp(accept_ranges,"bytes",5)==0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
582 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
583
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
584 // Check if the response is an ICY status_code reason_phrase
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
585 if( !strcasecmp(http_hdr->protocol, "ICY") ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
586 switch( http_hdr->status_code ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
587 case 200: { // OK
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
588 char *field_data = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
589 // note: I skip icy-notice1 and 2, as they contain html <BR>
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
590 // and are IMHO useless info ::atmos
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
591 if( (field_data = http_get_field(http_hdr, "icy-name")) != NULL )
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
592 mp_msg(MSGT_NETWORK,MSGL_INFO,"Name : %s\n", field_data); field_data = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
593 if( (field_data = http_get_field(http_hdr, "icy-genre")) != NULL )
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
594 mp_msg(MSGT_NETWORK,MSGL_INFO,"Genre : %s\n", field_data); field_data = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
595 if( (field_data = http_get_field(http_hdr, "icy-url")) != NULL )
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
596 mp_msg(MSGT_NETWORK,MSGL_INFO,"Website: %s\n", field_data); field_data = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
597 // XXX: does this really mean public server? ::atmos
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
598 if( (field_data = http_get_field(http_hdr, "icy-pub")) != NULL )
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
599 mp_msg(MSGT_NETWORK,MSGL_INFO,"Public : %s\n", atoi(field_data)?"yes":"no"); field_data = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
600 if( (field_data = http_get_field(http_hdr, "icy-br")) != NULL )
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
601 mp_msg(MSGT_NETWORK,MSGL_INFO,"Bitrate: %skbit/s\n", field_data); field_data = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
602
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
603 // If content-type == video/nsv we most likely have a winamp video stream
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
604 // otherwise it should be mp3. if there are more types consider adding mime type
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
605 // handling like later
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
606 if ( (field_data = http_get_field(http_hdr, "content-type")) != NULL && (!strcmp(field_data, "video/nsv") || !strcmp(field_data, "misc/ultravox")))
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
607 *file_format = DEMUXER_TYPE_NSV;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
608 else
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
609 *file_format = DEMUXER_TYPE_AUDIO;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
610 return 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
611 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
612 case 400: // Server Full
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
613 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server is full, skipping!\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
614 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
615 case 401: // Service Unavailable
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
616 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return service unavailable, skipping!\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
617 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
618 case 403: // Service Forbidden
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
619 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return 'Service Forbidden'\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
620 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
621 case 404: // Resource Not Found
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
622 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server couldn't find requested stream, skipping!\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
623 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
624 default:
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
625 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: unhandled ICY-Errorcode, contact MPlayer developers!\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
626 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
627 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
628 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
629
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
630 // Assume standard http if not ICY
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
631 switch( http_hdr->status_code ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
632 case 200: // OK
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
633 // Look if we can use the Content-Type
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
634 content_type = http_get_field( http_hdr, "Content-Type" );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
635 if( content_type!=NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
636 char *content_length = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
637 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", content_type );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
638 if( (content_length = http_get_field(http_hdr, "Content-Length")) != NULL)
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
639 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length"));
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
640 // Check in the mime type table for a demuxer type
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
641 i = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
642 while(mime_type_table[i].mime_type != NULL) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
643 if( !strcasecmp( content_type, mime_type_table[i].mime_type ) ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
644 *file_format = mime_type_table[i].demuxer_type;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
645 return seekable;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
646 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
647 i++;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
648 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
649 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
650 // Not found in the mime type table, don't fail,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
651 // we should try raw HTTP
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
652 return seekable;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
653 // Redirect
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
654 case 301: // Permanently
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
655 case 302: // Temporarily
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
656 // TODO: RFC 2616, recommand to detect infinite redirection loops
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
657 next_url = http_get_field( http_hdr, "Location" );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
658 if( next_url!=NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
659 closesocket( fd );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
660 url_free( url );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
661 stream->streaming_ctrl->url = url = url_new( next_url );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
662 http_free( http_hdr );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
663 redirect = 1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
664 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
665 break;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
666 case 401: // Authentication required
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
667 if( http_authenticate(http_hdr, url, &auth_retry)<0 ) return STREAM_UNSUPORTED;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
668 redirect = 1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
669 break;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
670 default:
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
671 mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
672 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
673 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
674 } while( redirect );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
675
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
676 return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
677 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
678
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
679 static int fixup_open(stream_t *stream,int seekable) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
680
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
681 stream->type = STREAMTYPE_STREAM;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
682 if(seekable)
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
683 {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
684 stream->flags |= STREAM_SEEK;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
685 stream->seek = http_seek;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
686 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
687 stream->streaming_ctrl->bandwidth = network_bandwidth;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
688 if(nop_streaming_start( stream )) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
689 mp_msg(MSGT_NETWORK,MSGL_ERR,"nop_streaming_start failed\n");
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
690 streaming_ctrl_free(stream->streaming_ctrl);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
691 stream->streaming_ctrl = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
692 return STREAM_UNSUPORTED;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
693 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
694
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
695 fixup_network_stream_cache(stream);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
696 return STREAM_OK;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
697 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
698
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
699 static int open_s1(stream_t *stream,int mode, void* opts, int* file_format) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
700 int seekable=0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
701 URL_t *url;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
702
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
703 stream->streaming_ctrl = streaming_ctrl_new();
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
704 if( stream->streaming_ctrl==NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
705 return STREAM_ERROR;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
706 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
707 stream->streaming_ctrl->bandwidth = network_bandwidth;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
708 url = url_new(stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
709 stream->streaming_ctrl->url = check4proxies(url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
710 //url_free(url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
711
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
712 mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_HTTP(1), URL: %s\n", stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
713 seekable = http_streaming_start(stream, file_format);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
714 if((seekable < 0) || (*file_format == DEMUXER_TYPE_ASF)) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
715 streaming_ctrl_free(stream->streaming_ctrl);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
716 stream->streaming_ctrl = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
717 return STREAM_UNSUPORTED;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
718 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
719
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
720 return fixup_open(stream, seekable);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
721 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
722
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
723 static int open_s2(stream_t *stream,int mode, void* opts, int* file_format) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
724 int seekable=0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
725 URL_t *url;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
726
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
727 stream->streaming_ctrl = streaming_ctrl_new();
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
728 if( stream->streaming_ctrl==NULL ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
729 return STREAM_ERROR;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
730 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
731 stream->streaming_ctrl->bandwidth = network_bandwidth;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
732 url = url_new(stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
733 stream->streaming_ctrl->url = check4proxies(url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
734 //url_free(url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
735
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
736 mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_HTTP(2), URL: %s\n", stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
737 seekable = http_streaming_start(stream, file_format);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
738 if(seekable < 0) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
739 streaming_ctrl_free(stream->streaming_ctrl);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
740 stream->streaming_ctrl = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
741 return STREAM_UNSUPORTED;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
742 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
743
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
744 return fixup_open(stream, seekable);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
745 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
746
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
747
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
748 stream_info_t stream_info_http1 = {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
749 "http streaming",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
750 "null",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
751 "Bertrand, Albeau, Reimar Doeffinger, Arpi?",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
752 "plain http",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
753 open_s1,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
754 {"http", "http_proxy", NULL},
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
755 NULL,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
756 0 // Urls are an option string
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
757 };
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
758
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
759 stream_info_t stream_info_http2 = {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
760 "http streaming",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
761 "null",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
762 "Bertrand, Albeu, Arpi? who?",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
763 "plain http, aslo used as falback for many other protocols",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
764 open_s2,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
765 {"http", "http_proxy", "pnm", "mms", "mmsu", "mmst", "rtsp", NULL}, //all the others as fallback
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
766 NULL,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
767 0 // Urls are an option string
281d155fb37f ported all network streams to the new API
nicodvb
parents: 14460
diff changeset
768 };