Line | Count | Source |
1 | | /*************************************************************************** |
2 | | * _ _ ____ _ |
3 | | * Project ___| | | | _ \| | |
4 | | * / __| | | | |_) | | |
5 | | * | (__| |_| | _ <| |___ |
6 | | * \___|\___/|_| \_\_____| |
7 | | * |
8 | | * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. |
9 | | * |
10 | | * This software is licensed as described in the file COPYING, which |
11 | | * you should have received as part of this distribution. The terms |
12 | | * are also available at https://curl.se/docs/copyright.html. |
13 | | * |
14 | | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
15 | | * copies of the Software, and permit persons to whom the Software is |
16 | | * furnished to do so, under the terms of the COPYING file. |
17 | | * |
18 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
19 | | * KIND, either express or implied. |
20 | | * |
21 | | * SPDX-License-Identifier: curl |
22 | | * |
23 | | ***************************************************************************/ |
24 | | #include "curl_setup.h" |
25 | | #include "urldata.h" |
26 | | #include "rtsp.h" |
27 | | |
28 | | #ifndef CURL_DISABLE_RTSP |
29 | | |
30 | | #include "transfer.h" |
31 | | #include "sendf.h" |
32 | | #include "curl_trc.h" |
33 | | #include "multiif.h" |
34 | | #include "http.h" |
35 | | #include "url.h" |
36 | | #include "progress.h" |
37 | | #include "strcase.h" |
38 | | #include "select.h" |
39 | | #include "connect.h" |
40 | | #include "cfilters.h" |
41 | | #include "curlx/strdup.h" |
42 | | #include "bufref.h" |
43 | | #include "curlx/strparse.h" |
44 | | |
45 | | /* meta key for storing protocol meta at easy handle */ |
46 | 0 | #define CURL_META_RTSP_EASY "meta:proto:rtsp:easy" |
47 | | /* meta key for storing protocol meta at connection */ |
48 | 0 | #define CURL_META_RTSP_CONN "meta:proto:rtsp:conn" |
49 | | |
50 | | typedef enum { |
51 | | RTP_PARSE_SKIP, |
52 | | RTP_PARSE_CHANNEL, |
53 | | RTP_PARSE_LEN, |
54 | | RTP_PARSE_DATA |
55 | | } rtp_parse_st; |
56 | | |
57 | | /* RTSP Connection data |
58 | | * Currently, only used for tracking incomplete RTP data reads */ |
59 | | struct rtsp_conn { |
60 | | struct dynbuf buf; |
61 | | int rtp_channel; |
62 | | size_t rtp_len; |
63 | | rtp_parse_st state; |
64 | | BIT(in_header); |
65 | | }; |
66 | | |
67 | | /* RTSP transfer data */ |
68 | | struct RTSP { |
69 | | uint32_t CSeq_sent; /* CSeq of this request */ |
70 | | uint32_t CSeq_recv; /* CSeq received */ |
71 | | }; |
72 | | |
73 | 0 | #define RTP_PKT_LENGTH(p) ((((unsigned int)((unsigned char)((p)[2]))) << 8) | \ |
74 | 0 | ((unsigned int)((unsigned char)((p)[3])))) |
75 | | |
76 | | /* this returns the socket to wait for in the DO and DOING state for the multi |
77 | | interface and then we are always _sending_ a request and thus we wait for |
78 | | the single socket to become writable only */ |
79 | | static CURLcode rtsp_do_pollset(struct Curl_easy *data, |
80 | | struct easy_pollset *ps) |
81 | 0 | { |
82 | | /* write mode */ |
83 | 0 | return Curl_pollset_add_out(data, ps, data->conn->sock[FIRSTSOCKET]); |
84 | 0 | } |
85 | | |
86 | 0 | #define MAX_RTP_BUFFERSIZE 1000000 /* arbitrary */ |
87 | | |
88 | | static void rtsp_easy_dtor(const void *key, size_t klen, void *entry) |
89 | 0 | { |
90 | 0 | struct RTSP *rtsp = entry; |
91 | 0 | (void)key; |
92 | 0 | (void)klen; |
93 | 0 | curlx_free(rtsp); |
94 | 0 | } |
95 | | |
96 | | static void rtsp_conn_dtor(const void *key, size_t klen, void *entry) |
97 | 0 | { |
98 | 0 | struct rtsp_conn *rtspc = entry; |
99 | 0 | (void)key; |
100 | 0 | (void)klen; |
101 | 0 | curlx_dyn_free(&rtspc->buf); |
102 | 0 | curlx_free(rtspc); |
103 | 0 | } |
104 | | |
105 | | static CURLcode rtsp_setup_connection(struct Curl_easy *data, |
106 | | struct connectdata *conn) |
107 | 0 | { |
108 | 0 | struct rtsp_conn *rtspc; |
109 | 0 | struct RTSP *rtsp; |
110 | |
|
111 | 0 | rtspc = curlx_calloc(1, sizeof(*rtspc)); |
112 | 0 | if(!rtspc) |
113 | 0 | return CURLE_OUT_OF_MEMORY; |
114 | 0 | curlx_dyn_init(&rtspc->buf, MAX_RTP_BUFFERSIZE); |
115 | 0 | if(Curl_conn_meta_set(conn, CURL_META_RTSP_CONN, rtspc, rtsp_conn_dtor)) |
116 | 0 | return CURLE_OUT_OF_MEMORY; |
117 | | |
118 | 0 | rtsp = curlx_calloc(1, sizeof(struct RTSP)); |
119 | 0 | if(!rtsp || |
120 | 0 | Curl_meta_set(data, CURL_META_RTSP_EASY, rtsp, rtsp_easy_dtor)) |
121 | 0 | return CURLE_OUT_OF_MEMORY; |
122 | | |
123 | 0 | return CURLE_OK; |
124 | 0 | } |
125 | | |
126 | | /* |
127 | | * Function to check on various aspects of a connection. |
128 | | */ |
129 | | static bool rtsp_conn_is_dead(struct Curl_easy *data, |
130 | | struct connectdata *conn) |
131 | 0 | { |
132 | 0 | bool input_pending; |
133 | | /* Contrary to default handling, this protocol allows pending |
134 | | * input on an unused connection. */ |
135 | 0 | return !Curl_conn_is_alive(data, conn, &input_pending); |
136 | 0 | } |
137 | | |
138 | | static CURLcode rtsp_connect(struct Curl_easy *data, bool *done) |
139 | 0 | { |
140 | 0 | struct rtsp_conn *rtspc = |
141 | 0 | Curl_conn_meta_get(data->conn, CURL_META_RTSP_CONN); |
142 | |
|
143 | 0 | if(!rtspc) |
144 | 0 | return CURLE_FAILED_INIT; |
145 | | |
146 | | /* Initialize the CSeq if not already done */ |
147 | 0 | if(data->state.rtsp_next_client_CSeq == 0) |
148 | 0 | data->state.rtsp_next_client_CSeq = 1; |
149 | 0 | if(data->state.rtsp_next_server_CSeq == 0) |
150 | 0 | data->state.rtsp_next_server_CSeq = 1; |
151 | |
|
152 | 0 | rtspc->rtp_channel = -1; |
153 | 0 | *done = TRUE; |
154 | 0 | return CURLE_OK; |
155 | 0 | } |
156 | | |
157 | | static CURLcode rtsp_done(struct Curl_easy *data, |
158 | | CURLcode status, bool premature) |
159 | 0 | { |
160 | 0 | struct rtsp_conn *rtspc = |
161 | 0 | Curl_conn_meta_get(data->conn, CURL_META_RTSP_CONN); |
162 | 0 | struct RTSP *rtsp = Curl_meta_get(data, CURL_META_RTSP_EASY); |
163 | 0 | CURLcode result; |
164 | |
|
165 | 0 | if(!rtspc || !rtsp) |
166 | 0 | return CURLE_FAILED_INIT; |
167 | | |
168 | | /* Bypass HTTP empty-reply checks on receive */ |
169 | 0 | if(data->set.rtspreq == RTSPREQ_RECEIVE) |
170 | 0 | premature = TRUE; |
171 | |
|
172 | 0 | result = Curl_http_done(data, status, premature); |
173 | |
|
174 | 0 | if(!status && !result) { |
175 | | /* Check the sequence numbers */ |
176 | 0 | uint32_t CSeq_sent = rtsp->CSeq_sent; |
177 | 0 | uint32_t CSeq_recv = rtsp->CSeq_recv; |
178 | 0 | if((data->set.rtspreq != RTSPREQ_RECEIVE) && (CSeq_sent != CSeq_recv)) { |
179 | 0 | failf(data, |
180 | 0 | "The CSeq of this request %u did not match the response %u", |
181 | 0 | CSeq_sent, CSeq_recv); |
182 | 0 | return CURLE_RTSP_CSEQ_ERROR; |
183 | 0 | } |
184 | 0 | if(data->set.rtspreq == RTSPREQ_RECEIVE && (rtspc->rtp_channel == -1)) { |
185 | 0 | infof(data, "Got an RTP Receive with a CSeq of %u", CSeq_recv); |
186 | 0 | } |
187 | 0 | if(data->set.rtspreq == RTSPREQ_RECEIVE && |
188 | 0 | data->req.eos_written) { |
189 | 0 | failf(data, "Server prematurely closed the RTSP connection."); |
190 | 0 | return CURLE_RECV_ERROR; |
191 | 0 | } |
192 | 0 | } |
193 | | |
194 | 0 | return result; |
195 | 0 | } |
196 | | |
197 | | static CURLcode rtsp_setup_body(struct Curl_easy *data, |
198 | | unsigned char rtspreq, |
199 | | struct dynbuf *reqp) |
200 | 0 | { |
201 | 0 | CURLcode result; |
202 | 0 | if(rtspreq == RTSPREQ_ANNOUNCE || |
203 | 0 | rtspreq == RTSPREQ_SET_PARAMETER || |
204 | 0 | rtspreq == RTSPREQ_GET_PARAMETER) { |
205 | 0 | curl_off_t req_clen; /* request content length */ |
206 | |
|
207 | 0 | if(data->state.upload) { |
208 | 0 | req_clen = data->state.infilesize; |
209 | 0 | data->state.httpreq = HTTPREQ_PUT; |
210 | 0 | result = Curl_creader_set_fread(data, req_clen); |
211 | 0 | if(result) |
212 | 0 | return result; |
213 | 0 | } |
214 | 0 | else { |
215 | 0 | if(data->set.postfields) { |
216 | 0 | size_t plen = (data->set.postfieldsize >= 0) ? |
217 | 0 | (size_t)data->set.postfieldsize : strlen(data->set.postfields); |
218 | 0 | req_clen = (curl_off_t)plen; |
219 | 0 | result = Curl_creader_set_buf(data, data->set.postfields, plen); |
220 | 0 | } |
221 | 0 | else if(data->state.infilesize >= 0) { |
222 | 0 | req_clen = data->state.infilesize; |
223 | 0 | result = Curl_creader_set_fread(data, req_clen); |
224 | 0 | } |
225 | 0 | else { |
226 | 0 | req_clen = 0; |
227 | 0 | result = Curl_creader_set_null(data); |
228 | 0 | } |
229 | 0 | if(result) |
230 | 0 | return result; |
231 | 0 | } |
232 | | |
233 | 0 | if(req_clen > 0) { |
234 | | /* As stated in the http comments, it is probably not wise to |
235 | | * actually set a custom Content-Length in the headers */ |
236 | 0 | if(!Curl_checkheaders(data, STRCONST("Content-Length"))) { |
237 | 0 | result = curlx_dyn_addf(reqp, "Content-Length: %" FMT_OFF_T "\r\n", |
238 | 0 | req_clen); |
239 | 0 | if(result) |
240 | 0 | return result; |
241 | 0 | } |
242 | | |
243 | 0 | if(rtspreq == RTSPREQ_SET_PARAMETER || |
244 | 0 | rtspreq == RTSPREQ_GET_PARAMETER) { |
245 | 0 | if(!Curl_checkheaders(data, STRCONST("Content-Type"))) { |
246 | 0 | result = curlx_dyn_addn(reqp, STRCONST("Content-Type: " |
247 | 0 | "text/parameters\r\n")); |
248 | 0 | if(result) |
249 | 0 | return result; |
250 | 0 | } |
251 | 0 | } |
252 | | |
253 | 0 | if(rtspreq == RTSPREQ_ANNOUNCE) { |
254 | 0 | if(!Curl_checkheaders(data, STRCONST("Content-Type"))) { |
255 | 0 | result = curlx_dyn_addn(reqp, STRCONST("Content-Type: " |
256 | 0 | "application/sdp\r\n")); |
257 | 0 | if(result) |
258 | 0 | return result; |
259 | 0 | } |
260 | 0 | } |
261 | 0 | } |
262 | 0 | else if(rtspreq == RTSPREQ_GET_PARAMETER) { |
263 | | /* Check for an empty GET_PARAMETER (heartbeat) request */ |
264 | 0 | data->state.httpreq = HTTPREQ_HEAD; |
265 | 0 | data->req.no_body = TRUE; |
266 | 0 | } |
267 | 0 | } |
268 | 0 | else |
269 | 0 | result = Curl_creader_set_null(data); |
270 | 0 | return result; |
271 | 0 | } |
272 | | |
273 | | struct rtspselect { |
274 | | const char *method; |
275 | | bool no_body; |
276 | | }; |
277 | | |
278 | | static CURLcode pick_method(struct Curl_easy *data, |
279 | | const unsigned char rtspreq, |
280 | | const char **p) |
281 | 0 | { |
282 | 0 | static const struct rtspselect req[] = { |
283 | 0 | { "OPTIONS", TRUE }, |
284 | 0 | { "DESCRIBE", FALSE }, |
285 | 0 | { "ANNOUNCE", TRUE }, |
286 | 0 | { "SETUP", TRUE }, |
287 | 0 | { "PLAY", TRUE }, |
288 | 0 | { "PAUSE", TRUE }, |
289 | 0 | { "TEARDOWN", TRUE }, |
290 | 0 | { "GET_PARAMETER", FALSE }, |
291 | 0 | { "SET_PARAMETER", TRUE }, |
292 | 0 | { "RECORD", TRUE }, |
293 | 0 | { "", FALSE }, /* RECEIVE: treat interleaved RTP as body */ |
294 | 0 | }; |
295 | | /* this is verified already in setopt, this is just added precaution */ |
296 | 0 | DEBUGASSERT((rtspreq > RTSPREQ_NONE) && (rtspreq < RTSPREQ_LAST)); |
297 | 0 | if((rtspreq <= RTSPREQ_NONE) || (rtspreq >= RTSPREQ_LAST)) |
298 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
299 | 0 | *p = req[rtspreq - 1].method; |
300 | 0 | data->req.no_body = req[rtspreq - 1].no_body; |
301 | 0 | return CURLE_OK; |
302 | 0 | } |
303 | | |
304 | | /* Allocate and store a header string. */ |
305 | | static CURLcode rtsp_header_alloc(const char *header_name, |
306 | | const char *value, |
307 | | char **target) |
308 | 0 | { |
309 | 0 | if(!value) |
310 | 0 | return CURLE_OK; |
311 | 0 | curlx_free(*target); |
312 | 0 | *target = curl_maprintf("%s: %s\r\n", header_name, value); |
313 | 0 | if(!*target) |
314 | 0 | return CURLE_OUT_OF_MEMORY; |
315 | 0 | return CURLE_OK; |
316 | 0 | } |
317 | | |
318 | | struct rtsp_blocks { |
319 | | const char *request; |
320 | | const char *session_id; |
321 | | const char *accept; |
322 | | const char *range; |
323 | | const char *stream_uri; |
324 | | const char *hd_proxy_auth; |
325 | | const char *hd_auth; |
326 | | char *referrer; |
327 | | char *accept_encoding; |
328 | | char *transport; |
329 | | BIT(transport_alloc); /* if 'transport' is allocated */ |
330 | | }; |
331 | | |
332 | | static CURLcode rtsp_setup_request(struct Curl_easy *data, |
333 | | struct rtsp_blocks *b, |
334 | | const unsigned char rtspreq) |
335 | 0 | { |
336 | 0 | CURLcode result = CURLE_OK; |
337 | 0 | struct connectdata *conn = data->conn; |
338 | |
|
339 | 0 | b->session_id = CURL_EASY_STR(data, STRING_RTSP_SESSION_ID); |
340 | | |
341 | | /* Stream URI. Default to server '*' if not specified */ |
342 | 0 | if(CURL_EASY_STR(data, STRING_RTSP_STREAM_URI)) |
343 | 0 | b->stream_uri = CURL_EASY_STR(data, STRING_RTSP_STREAM_URI); |
344 | 0 | else |
345 | 0 | b->stream_uri = "*"; |
346 | | |
347 | | /* Transport Header for SETUP requests */ |
348 | 0 | b->transport = Curl_checkheaders(data, STRCONST("Transport")); |
349 | 0 | if(rtspreq == RTSPREQ_SETUP && !b->transport) { |
350 | | /* New Transport: setting? */ |
351 | 0 | if(CURL_EASY_STR(data, STRING_RTSP_TRANSPORT)) { |
352 | 0 | result = rtsp_header_alloc( |
353 | 0 | "Transport", CURL_EASY_STR(data, STRING_RTSP_TRANSPORT), |
354 | 0 | &b->transport); |
355 | 0 | if(result) |
356 | 0 | return result; |
357 | 0 | b->transport_alloc = TRUE; |
358 | 0 | } |
359 | 0 | else { |
360 | 0 | failf(data, |
361 | 0 | "Refusing to issue an RTSP SETUP without a Transport: header."); |
362 | 0 | return CURLE_BAD_FUNCTION_ARGUMENT; |
363 | 0 | } |
364 | 0 | } |
365 | | |
366 | | /* Accept Headers for DESCRIBE requests */ |
367 | 0 | if(rtspreq == RTSPREQ_DESCRIBE) { |
368 | | /* Accept Header */ |
369 | 0 | b->accept = Curl_checkheaders(data, STRCONST("Accept")) ? |
370 | 0 | NULL : "Accept: application/sdp\r\n"; |
371 | | |
372 | | /* Accept-Encoding header */ |
373 | 0 | if(!Curl_checkheaders(data, STRCONST("Accept-Encoding")) && |
374 | 0 | CURL_EASY_STR(data, STRING_ENCODING)) { |
375 | 0 | result = rtsp_header_alloc("Accept-Encoding", |
376 | 0 | CURL_EASY_STR(data, STRING_ENCODING), |
377 | 0 | &b->accept_encoding); |
378 | 0 | if(result) |
379 | 0 | return result; |
380 | 0 | } |
381 | 0 | } |
382 | | |
383 | | /* setup the authentication headers */ |
384 | 0 | result = Curl_http_output_auth(data, conn, b->request, HTTPREQ_GET, |
385 | 0 | b->stream_uri, NULL, FALSE); |
386 | 0 | if(result) |
387 | 0 | return result; |
388 | | |
389 | 0 | #ifndef CURL_DISABLE_PROXY |
390 | 0 | b->hd_proxy_auth = data->req.hd_proxy_auth; |
391 | 0 | #endif |
392 | 0 | b->hd_auth = data->req.hd_auth; |
393 | | |
394 | | /* Referrer */ |
395 | 0 | if(Curl_bufref_ptr(&data->state.referer) && |
396 | 0 | !Curl_checkheaders(data, STRCONST("Referer"))) { |
397 | 0 | b->referrer = |
398 | 0 | curl_maprintf("Referer: %s\r\n", Curl_bufref_ptr(&data->state.referer)); |
399 | 0 | if(!b->referrer) |
400 | 0 | result = CURLE_OUT_OF_MEMORY; |
401 | 0 | } |
402 | | |
403 | | /* |
404 | | * Range Header |
405 | | * Only applies to PLAY, PAUSE, RECORD |
406 | | * |
407 | | * Go ahead and use the Range stuff supplied for HTTP |
408 | | */ |
409 | 0 | if(!result && |
410 | 0 | data->state.use_range && |
411 | 0 | ((rtspreq == RTSPREQ_PLAY) || |
412 | 0 | (rtspreq == RTSPREQ_PAUSE) || |
413 | 0 | (rtspreq == RTSPREQ_RECORD)) && |
414 | | /* Check to see if there is a range set in the custom headers */ |
415 | 0 | !Curl_checkheaders(data, STRCONST("Range")) && data->state.range) { |
416 | 0 | result = rtsp_header_alloc("Range", |
417 | 0 | data->state.range, |
418 | 0 | &data->state.rangeline); |
419 | 0 | if(!result) |
420 | 0 | b->range = data->state.rangeline; |
421 | 0 | } |
422 | 0 | return result; |
423 | 0 | } |
424 | | |
425 | 0 | #define HTTPVERSION 11 /* RTSP is close to HTTP/1.1, sort of... */ |
426 | | |
427 | | static CURLcode rtsp_do(struct Curl_easy *data, bool *done) |
428 | 0 | { |
429 | 0 | CURLcode result = CURLE_OK; |
430 | 0 | const unsigned char rtspreq = data->set.rtspreq; |
431 | 0 | const char *str; |
432 | 0 | struct RTSP *rtsp = Curl_meta_get(data, CURL_META_RTSP_EASY); |
433 | 0 | struct dynbuf req_buffer; |
434 | 0 | struct rtsp_blocks block; |
435 | 0 | memset(&block, 0, sizeof(block)); |
436 | |
|
437 | 0 | *done = TRUE; |
438 | 0 | if(!rtsp) |
439 | 0 | return CURLE_FAILED_INIT; |
440 | | |
441 | | /* Initialize a dynamic send buffer */ |
442 | 0 | curlx_dyn_init(&req_buffer, DYN_RTSP_REQ_HEADER); |
443 | |
|
444 | 0 | rtsp->CSeq_sent = data->state.rtsp_next_client_CSeq; |
445 | 0 | rtsp->CSeq_recv = 0; |
446 | | |
447 | | /* Setup the 'p_request' pointer to the proper method. */ |
448 | 0 | result = pick_method(data, rtspreq, &block.request); |
449 | 0 | if(result) |
450 | 0 | goto out; |
451 | | |
452 | 0 | if(rtspreq == RTSPREQ_RECEIVE) { |
453 | 0 | Curl_xfer_setup_recv(data, FIRSTSOCKET, -1); |
454 | 0 | goto out; |
455 | 0 | } |
456 | | |
457 | 0 | result = rtsp_setup_request(data, &block, rtspreq); |
458 | 0 | if(result) |
459 | 0 | goto out; |
460 | | /* |
461 | | * Sanity check the custom headers |
462 | | */ |
463 | 0 | if(Curl_checkheaders(data, STRCONST("CSeq"))) { |
464 | 0 | failf(data, "CSeq cannot be set as a custom header."); |
465 | 0 | result = CURLE_RTSP_CSEQ_ERROR; |
466 | 0 | goto out; |
467 | 0 | } |
468 | 0 | if(Curl_checkheaders(data, STRCONST("Session"))) { |
469 | 0 | failf(data, "Session ID cannot be set as a custom header."); |
470 | 0 | result = CURLE_BAD_FUNCTION_ARGUMENT; |
471 | 0 | goto out; |
472 | 0 | } |
473 | | |
474 | 0 | result = |
475 | 0 | curlx_dyn_addf(&req_buffer, |
476 | 0 | "%s %s RTSP/1.0\r\n" /* Request Stream-URI RTSP/1.0 */ |
477 | 0 | "CSeq: %u\r\n", /* CSeq */ |
478 | 0 | block.request, block.stream_uri, rtsp->CSeq_sent); |
479 | 0 | if(result) |
480 | 0 | goto out; |
481 | | |
482 | | /* |
483 | | * Rather than do a normal alloc line, keep the session_id unformatted |
484 | | * to make comparison easier |
485 | | */ |
486 | 0 | if(block.session_id) { |
487 | 0 | result = curlx_dyn_addf(&req_buffer, "Session: %s\r\n", block.session_id); |
488 | 0 | if(result) |
489 | 0 | goto out; |
490 | 0 | } |
491 | | |
492 | | /* |
493 | | * Shared HTTP-like options |
494 | | */ |
495 | 0 | result = curlx_dyn_addf(&req_buffer, |
496 | 0 | "%s" /* transport */ |
497 | 0 | "%s" /* accept */ |
498 | 0 | "%s" /* accept-encoding */ |
499 | 0 | "%s" /* range */ |
500 | 0 | "%s" /* referrer */ |
501 | 0 | , |
502 | 0 | block.transport ? block.transport : "", |
503 | 0 | block.accept ? block.accept : "", |
504 | 0 | block.accept_encoding ? block.accept_encoding : "", |
505 | 0 | block.range ? block.range : "", |
506 | 0 | block.referrer ? block.referrer : ""); |
507 | |
|
508 | 0 | str = CURL_EASY_STR(data, STRING_USERAGENT); |
509 | 0 | if(!result && str && *str && |
510 | 0 | !Curl_checkheaders(data, STRCONST("User-Agent"))) |
511 | 0 | result = curlx_dyn_addf(&req_buffer, |
512 | 0 | "User-Agent: %s\r\n", str); |
513 | |
|
514 | 0 | if(!result) |
515 | 0 | result = curlx_dyn_addf(&req_buffer, |
516 | 0 | "%s" /* hd_proxy_auth */ |
517 | 0 | "%s", /* hd_auth */ |
518 | 0 | block.hd_proxy_auth ? block.hd_proxy_auth : "", |
519 | 0 | block.hd_auth ? block.hd_auth : ""); |
520 | 0 | if(result) |
521 | 0 | goto out; |
522 | | |
523 | 0 | if((rtspreq == RTSPREQ_SETUP) || (rtspreq == RTSPREQ_DESCRIBE)) { |
524 | 0 | result = Curl_add_timecondition(data, &req_buffer); |
525 | 0 | if(result) |
526 | 0 | goto out; |
527 | 0 | } |
528 | | |
529 | 0 | result = Curl_add_custom_headers(data, FALSE, HTTPVERSION, &req_buffer); |
530 | 0 | if(result) |
531 | 0 | goto out; |
532 | | |
533 | 0 | result = rtsp_setup_body(data, rtspreq, &req_buffer); |
534 | 0 | if(result) |
535 | 0 | goto out; |
536 | | |
537 | | /* Finish the request buffer */ |
538 | 0 | result = curlx_dyn_addn(&req_buffer, STRCONST("\r\n")); |
539 | 0 | if(result) |
540 | 0 | goto out; |
541 | | |
542 | 0 | Curl_xfer_setup_sendrecv(data, FIRSTSOCKET, -1); |
543 | | |
544 | | /* issue the request */ |
545 | 0 | result = Curl_req_send(data, &req_buffer, HTTPVERSION); |
546 | 0 | if(result) { |
547 | 0 | failf(data, "Failed sending RTSP request"); |
548 | 0 | goto out; |
549 | 0 | } |
550 | | |
551 | | /* Increment the CSeq on success */ |
552 | 0 | data->state.rtsp_next_client_CSeq++; |
553 | |
|
554 | 0 | if(data->req.writebytecount) { |
555 | | /* if a request-body has been sent off, we make sure this progress is |
556 | | noted properly */ |
557 | 0 | Curl_pgrsSetUploadCounter(data, data->req.writebytecount); |
558 | 0 | result = Curl_pgrsUpdate(data); |
559 | 0 | } |
560 | 0 | out: |
561 | 0 | if(block.transport_alloc) |
562 | 0 | curlx_free(block.transport); |
563 | 0 | curlx_free(block.accept_encoding); |
564 | 0 | curlx_free(block.referrer); |
565 | 0 | curlx_dyn_free(&req_buffer); |
566 | 0 | return result; |
567 | 0 | } |
568 | | |
569 | | /** |
570 | | * write any BODY bytes missing to the client, ignore the rest. |
571 | | */ |
572 | | static CURLcode rtp_write_body_junk(struct Curl_easy *data, |
573 | | struct rtsp_conn *rtspc, |
574 | | const char *buf, |
575 | | size_t blen) |
576 | 0 | { |
577 | 0 | curl_off_t body_remain; |
578 | 0 | bool in_body; |
579 | |
|
580 | 0 | in_body = (data->req.headerline && !rtspc->in_header) && |
581 | 0 | (data->req.size >= 0) && |
582 | 0 | (data->req.bytecount < data->req.size); |
583 | 0 | body_remain = in_body ? (data->req.size - data->req.bytecount) : 0; |
584 | 0 | DEBUGASSERT(body_remain >= 0); |
585 | 0 | if(body_remain) { |
586 | 0 | if((curl_off_t)blen > body_remain) |
587 | 0 | blen = (size_t)body_remain; |
588 | 0 | return Curl_client_write(data, CLIENTWRITE_BODY, buf, blen); |
589 | 0 | } |
590 | 0 | return CURLE_OK; |
591 | 0 | } |
592 | | |
593 | | static CURLcode rtp_client_write(struct Curl_easy *data, const char *ptr, |
594 | | size_t len) |
595 | 0 | { |
596 | 0 | struct Curl_mapi_guard guard; |
597 | 0 | size_t wrote; |
598 | 0 | curl_write_callback writeit; |
599 | 0 | void *user_ptr; |
600 | |
|
601 | 0 | if(len == 0) { |
602 | 0 | failf(data, "Cannot write a 0 size RTP packet."); |
603 | 0 | return CURLE_WRITE_ERROR; |
604 | 0 | } |
605 | | |
606 | | /* If the user has configured CURLOPT_INTERLEAVEFUNCTION then use that |
607 | | function and any configured CURLOPT_INTERLEAVEDATA to write out the RTP |
608 | | data. Otherwise, use the CURLOPT_WRITEFUNCTION with the CURLOPT_WRITEDATA |
609 | | pointer to write out the RTP data. */ |
610 | 0 | if(data->set.fwrite_rtp) { |
611 | 0 | writeit = data->set.fwrite_rtp; |
612 | 0 | user_ptr = data->set.rtp_out; |
613 | 0 | } |
614 | 0 | else { |
615 | 0 | writeit = data->set.fwrite_func; |
616 | 0 | user_ptr = data->set.out; |
617 | 0 | } |
618 | |
|
619 | 0 | CURL_CBAPI_START(&guard, data, easy_fwrite_rtp); |
620 | 0 | wrote = writeit((char *)CURL_UNCONST(ptr), 1, len, user_ptr); |
621 | 0 | CURL_CBAPI_END(&guard); |
622 | |
|
623 | 0 | if(wrote == CURL_WRITEFUNC_PAUSE) { |
624 | 0 | failf(data, "Cannot pause RTP"); |
625 | 0 | return CURLE_WRITE_ERROR; |
626 | 0 | } |
627 | | |
628 | 0 | if(wrote != len) { |
629 | 0 | failf(data, "Failed writing RTP data"); |
630 | 0 | return CURLE_WRITE_ERROR; |
631 | 0 | } |
632 | | |
633 | 0 | return CURLE_OK; |
634 | 0 | } |
635 | | |
636 | | static CURLcode rtsp_filter_rtp(struct Curl_easy *data, |
637 | | struct rtsp_conn *rtspc, |
638 | | const char *buf, |
639 | | size_t blen, |
640 | | size_t *pconsumed) |
641 | 0 | { |
642 | 0 | CURLcode result = CURLE_OK; |
643 | 0 | size_t skip_len = 0; |
644 | |
|
645 | 0 | *pconsumed = 0; |
646 | 0 | while(blen) { |
647 | 0 | bool in_body = (data->req.headerline && !rtspc->in_header) && |
648 | 0 | (data->req.size >= 0) && |
649 | 0 | (data->req.bytecount < data->req.size); |
650 | 0 | switch(rtspc->state) { |
651 | | |
652 | 0 | case RTP_PARSE_SKIP: { |
653 | 0 | DEBUGASSERT(curlx_dyn_len(&rtspc->buf) == 0); |
654 | 0 | while(blen && buf[0] != '$') { |
655 | 0 | if(!in_body && buf[0] == 'R' && |
656 | 0 | data->set.rtspreq != RTSPREQ_RECEIVE) { |
657 | 0 | if(!strncmp(buf, "RTSP/", (blen < 5) ? blen : 5)) { |
658 | | /* This could be the next response, no consume and return */ |
659 | 0 | if(*pconsumed) { |
660 | 0 | DEBUGF(infof(data, "RTP rtsp_filter_rtp[SKIP] RTSP/ prefix, " |
661 | 0 | "skipping %zu bytes of junk", *pconsumed)); |
662 | 0 | } |
663 | 0 | rtspc->state = RTP_PARSE_SKIP; |
664 | 0 | rtspc->in_header = TRUE; |
665 | 0 | goto out; |
666 | 0 | } |
667 | 0 | } |
668 | | /* junk/BODY, consume without buffering */ |
669 | 0 | *pconsumed += 1; |
670 | 0 | ++buf; |
671 | 0 | --blen; |
672 | 0 | ++skip_len; |
673 | 0 | } |
674 | 0 | if(blen && buf[0] == '$') { |
675 | | /* possible start of an RTP message, buffer */ |
676 | 0 | if(skip_len) { |
677 | | /* end of junk/BODY bytes, flush */ |
678 | 0 | result = rtp_write_body_junk(data, rtspc, buf - skip_len, skip_len); |
679 | 0 | skip_len = 0; |
680 | 0 | if(result) |
681 | 0 | goto out; |
682 | 0 | } |
683 | 0 | if(curlx_dyn_addn(&rtspc->buf, buf, 1)) { |
684 | 0 | result = CURLE_OUT_OF_MEMORY; |
685 | 0 | goto out; |
686 | 0 | } |
687 | 0 | *pconsumed += 1; |
688 | 0 | ++buf; |
689 | 0 | --blen; |
690 | 0 | rtspc->state = RTP_PARSE_CHANNEL; |
691 | 0 | } |
692 | 0 | break; |
693 | 0 | } |
694 | | |
695 | 0 | case RTP_PARSE_CHANNEL: { |
696 | 0 | int idx = ((unsigned char)buf[0]) / 8; |
697 | 0 | int off = ((unsigned char)buf[0]) % 8; |
698 | 0 | DEBUGASSERT(curlx_dyn_len(&rtspc->buf) == 1); |
699 | 0 | if(!(data->state.rtp_channel_mask[idx] & (1 << off))) { |
700 | | /* invalid channel number, junk or BODY data */ |
701 | 0 | rtspc->state = RTP_PARSE_SKIP; |
702 | 0 | DEBUGASSERT(skip_len == 0); |
703 | | /* we do not consume this byte, it is BODY data */ |
704 | 0 | DEBUGF(infof(data, "RTSP: invalid RTP channel %d, skipping", idx)); |
705 | 0 | if(*pconsumed == 0) { |
706 | | /* We did not consume the initial '$' in our buffer, but had |
707 | | * it from an earlier call. We cannot un-consume it and have |
708 | | * to write it directly as BODY data */ |
709 | 0 | result = rtp_write_body_junk(data, rtspc, |
710 | 0 | curlx_dyn_ptr(&rtspc->buf), 1); |
711 | 0 | if(result) |
712 | 0 | goto out; |
713 | 0 | } |
714 | 0 | else { |
715 | | /* count the '$' as skip and continue */ |
716 | 0 | skip_len = 1; |
717 | 0 | } |
718 | 0 | curlx_dyn_free(&rtspc->buf); |
719 | 0 | break; |
720 | 0 | } |
721 | | /* a valid channel, so we expect this to be a real RTP message */ |
722 | 0 | rtspc->rtp_channel = (unsigned char)buf[0]; |
723 | 0 | if(curlx_dyn_addn(&rtspc->buf, buf, 1)) { |
724 | 0 | result = CURLE_OUT_OF_MEMORY; |
725 | 0 | goto out; |
726 | 0 | } |
727 | 0 | *pconsumed += 1; |
728 | 0 | ++buf; |
729 | 0 | --blen; |
730 | 0 | rtspc->state = RTP_PARSE_LEN; |
731 | 0 | break; |
732 | 0 | } |
733 | | |
734 | 0 | case RTP_PARSE_LEN: { |
735 | 0 | size_t rtp_len = curlx_dyn_len(&rtspc->buf); |
736 | 0 | const char *rtp_buf; |
737 | 0 | DEBUGASSERT(rtp_len >= 2 && rtp_len < 4); |
738 | 0 | if(curlx_dyn_addn(&rtspc->buf, buf, 1)) { |
739 | 0 | result = CURLE_OUT_OF_MEMORY; |
740 | 0 | goto out; |
741 | 0 | } |
742 | 0 | *pconsumed += 1; |
743 | 0 | ++buf; |
744 | 0 | --blen; |
745 | 0 | if(rtp_len == 2) |
746 | 0 | break; |
747 | 0 | rtp_buf = curlx_dyn_ptr(&rtspc->buf); |
748 | 0 | rtspc->rtp_len = RTP_PKT_LENGTH(rtp_buf) + 4; |
749 | 0 | if(rtspc->rtp_len == 4) { |
750 | | /* zero-length payload, the 4-byte header is the complete RTP |
751 | | message. Dispatch immediately without entering RTP_PARSE_DATA. */ |
752 | 0 | DEBUGF(infof(data, "RTP write channel %d rtp_len %zu (no payload)", |
753 | 0 | rtspc->rtp_channel, rtspc->rtp_len)); |
754 | 0 | result = rtp_client_write(data, rtp_buf, rtspc->rtp_len); |
755 | 0 | curlx_dyn_free(&rtspc->buf); |
756 | 0 | rtspc->state = RTP_PARSE_SKIP; |
757 | 0 | if(result) |
758 | 0 | goto out; |
759 | 0 | break; |
760 | 0 | } |
761 | 0 | rtspc->state = RTP_PARSE_DATA; |
762 | 0 | break; |
763 | 0 | } |
764 | | |
765 | 0 | case RTP_PARSE_DATA: { |
766 | 0 | size_t rtp_len = curlx_dyn_len(&rtspc->buf); |
767 | 0 | size_t needed; |
768 | 0 | DEBUGASSERT(rtp_len < rtspc->rtp_len); |
769 | 0 | needed = rtspc->rtp_len - rtp_len; |
770 | 0 | if(needed <= blen) { |
771 | 0 | if(curlx_dyn_addn(&rtspc->buf, buf, needed)) { |
772 | 0 | result = CURLE_OUT_OF_MEMORY; |
773 | 0 | goto out; |
774 | 0 | } |
775 | 0 | *pconsumed += needed; |
776 | 0 | buf += needed; |
777 | 0 | blen -= needed; |
778 | | /* complete RTP message in buffer */ |
779 | 0 | DEBUGF(infof(data, "RTP write channel %d rtp_len %zu", |
780 | 0 | rtspc->rtp_channel, rtspc->rtp_len)); |
781 | 0 | result = rtp_client_write(data, curlx_dyn_ptr(&rtspc->buf), |
782 | 0 | rtspc->rtp_len); |
783 | 0 | curlx_dyn_free(&rtspc->buf); |
784 | 0 | rtspc->state = RTP_PARSE_SKIP; |
785 | 0 | if(result) |
786 | 0 | goto out; |
787 | 0 | } |
788 | 0 | else { |
789 | 0 | if(curlx_dyn_addn(&rtspc->buf, buf, blen)) { |
790 | 0 | result = CURLE_OUT_OF_MEMORY; |
791 | 0 | goto out; |
792 | 0 | } |
793 | 0 | *pconsumed += blen; |
794 | 0 | buf += blen; |
795 | 0 | blen = 0; |
796 | 0 | } |
797 | 0 | break; |
798 | 0 | } |
799 | | |
800 | 0 | default: |
801 | 0 | DEBUGASSERT(0); |
802 | 0 | return CURLE_RECV_ERROR; |
803 | 0 | } |
804 | 0 | } |
805 | 0 | out: |
806 | 0 | if(!result && skip_len) |
807 | 0 | result = rtp_write_body_junk(data, rtspc, buf - skip_len, skip_len); |
808 | 0 | return result; |
809 | 0 | } |
810 | | |
811 | | /* |
812 | | * Parse and write out an RTSP response. |
813 | | * @param data the transfer |
814 | | * @param conn the connection |
815 | | * @param buf data read from connection |
816 | | * @param blen amount of data in buf |
817 | | * @param is_eos TRUE iff this is the last write |
818 | | * @param readmore out, TRUE iff complete buf was consumed and more data |
819 | | * is needed |
820 | | */ |
821 | | static CURLcode rtsp_rtp_write_resp(struct Curl_easy *data, |
822 | | const char *buf, |
823 | | size_t blen, |
824 | | bool is_eos) |
825 | 0 | { |
826 | 0 | struct rtsp_conn *rtspc = |
827 | 0 | Curl_conn_meta_get(data->conn, CURL_META_RTSP_CONN); |
828 | 0 | CURLcode result = CURLE_OK; |
829 | 0 | size_t consumed = 0; |
830 | |
|
831 | 0 | if(!rtspc) |
832 | 0 | return CURLE_FAILED_INIT; |
833 | | |
834 | 0 | if(!data->req.header) |
835 | 0 | rtspc->in_header = FALSE; |
836 | 0 | if(!blen) { |
837 | 0 | goto out; |
838 | 0 | } |
839 | | |
840 | 0 | DEBUGF(infof(data, "rtsp_rtp_write_resp(len=%zu, in_header=%d, eos=%d)", |
841 | 0 | blen, rtspc->in_header, is_eos)); |
842 | | |
843 | | /* If header parsing is not ongoing, extract RTP messages */ |
844 | 0 | if(!rtspc->in_header) { |
845 | 0 | result = rtsp_filter_rtp(data, rtspc, buf, blen, &consumed); |
846 | 0 | if(result) |
847 | 0 | goto out; |
848 | 0 | buf += consumed; |
849 | 0 | blen -= consumed; |
850 | | /* either we consumed all or are at the start of header parsing */ |
851 | 0 | if(blen && !data->req.header) |
852 | 0 | DEBUGF(infof(data, "RTSP: %zu bytes, possibly excess in response body", |
853 | 0 | blen)); |
854 | 0 | } |
855 | | |
856 | | /* we want to parse headers, do so */ |
857 | 0 | if(data->req.header && blen) { |
858 | 0 | rtspc->in_header = TRUE; |
859 | 0 | result = Curl_http_write_resp_hds(data, buf, blen, &consumed); |
860 | 0 | if(result) |
861 | 0 | goto out; |
862 | | |
863 | 0 | buf += consumed; |
864 | 0 | blen -= consumed; |
865 | |
|
866 | 0 | if(!data->req.header) |
867 | 0 | rtspc->in_header = FALSE; |
868 | |
|
869 | 0 | if(!rtspc->in_header) { |
870 | | /* If header parsing is done, extract interleaved RTP messages */ |
871 | 0 | if(data->req.size <= -1) { |
872 | | /* Respect section 4.4 of rfc2326: If the Content-Length header is |
873 | | absent, a length 0 must be assumed. */ |
874 | 0 | data->req.size = 0; |
875 | 0 | data->req.download_done = TRUE; |
876 | 0 | } |
877 | 0 | result = rtsp_filter_rtp(data, rtspc, buf, blen, &consumed); |
878 | 0 | if(result) |
879 | 0 | goto out; |
880 | 0 | buf += consumed; |
881 | 0 | blen -= consumed; |
882 | 0 | } |
883 | 0 | } |
884 | | |
885 | 0 | if(rtspc->state != RTP_PARSE_SKIP) |
886 | 0 | data->req.done = FALSE; |
887 | | /* we SHOULD have consumed all bytes, unless the response is borked. |
888 | | * In which case we write out the left over bytes, letting the client |
889 | | * writer deal with it (it will report EXCESS and fail the transfer). */ |
890 | 0 | DEBUGF(infof(data, "rtsp_rtp_write_resp(len=%zu, in_header=%d, done=%d, " |
891 | 0 | "rtspc->state=%d, req.size=%" FMT_OFF_T ")", |
892 | 0 | blen, rtspc->in_header, data->req.done, (int)rtspc->state, |
893 | 0 | data->req.size)); |
894 | 0 | if(!result && (is_eos || blen)) { |
895 | 0 | result = Curl_client_write(data, CLIENTWRITE_BODY | |
896 | 0 | (is_eos ? CLIENTWRITE_EOS : 0), buf, blen); |
897 | 0 | } |
898 | |
|
899 | 0 | out: |
900 | 0 | if((data->set.rtspreq == RTSPREQ_RECEIVE) && |
901 | 0 | (rtspc->state == RTP_PARSE_SKIP)) { |
902 | | /* In special mode RECEIVE, we process one chunk of network |
903 | | * data, so we stop the transfer here, if we have no incomplete |
904 | | * RTP message pending. */ |
905 | 0 | data->req.download_done = TRUE; |
906 | 0 | } |
907 | 0 | return result; |
908 | 0 | } |
909 | | |
910 | | static CURLcode rtsp_rtp_write_resp_hd(struct Curl_easy *data, |
911 | | const char *buf, |
912 | | size_t blen, |
913 | | bool is_eos) |
914 | 0 | { |
915 | 0 | return rtsp_rtp_write_resp(data, buf, blen, is_eos); |
916 | 0 | } |
917 | | |
918 | | static CURLcode rtsp_parse_transport(struct Curl_easy *data, |
919 | | const char *transport) |
920 | 0 | { |
921 | | /* If we receive multiple Transport response-headers, the interleaved |
922 | | channels of each response header is recorded and used together for |
923 | | subsequent data validity checks.*/ |
924 | | /* e.g.: ' RTP/AVP/TCP;unicast;interleaved=5-6' */ |
925 | 0 | const char *start, *end; |
926 | 0 | start = transport; |
927 | 0 | while(start && *start) { |
928 | 0 | curlx_str_passblanks(&start); |
929 | 0 | end = strchr(start, ';'); |
930 | 0 | if(checkprefix("interleaved=", start)) { |
931 | 0 | curl_off_t chan1, chan2, chan; |
932 | 0 | const char *p = start + 12; |
933 | 0 | if(!curlx_str_number(&p, &chan1, 255)) { |
934 | 0 | unsigned char *rtp_channel_mask = data->state.rtp_channel_mask; |
935 | 0 | chan2 = chan1; |
936 | 0 | if(!curlx_str_single(&p, '-') && curlx_str_number(&p, &chan2, 255)) { |
937 | 0 | infof(data, "Unable to read the interleaved parameter from " |
938 | 0 | "Transport header: [%s]", transport); |
939 | 0 | chan2 = chan1; |
940 | 0 | } |
941 | 0 | for(chan = chan1; chan <= chan2; chan++) { |
942 | 0 | int idx = (int)chan / 8; |
943 | 0 | int off = (int)chan % 8; |
944 | 0 | rtp_channel_mask[idx] |= (unsigned char)(1 << off); |
945 | 0 | } |
946 | 0 | } |
947 | 0 | else { |
948 | 0 | infof(data, "Unable to read the interleaved parameter from " |
949 | 0 | "Transport header: [%s]", transport); |
950 | 0 | } |
951 | 0 | break; |
952 | 0 | } |
953 | | /* skip to next parameter */ |
954 | 0 | start = (!end) ? end : (end + 1); |
955 | 0 | } |
956 | 0 | return CURLE_OK; |
957 | 0 | } |
958 | | |
959 | | CURLcode Curl_rtsp_parseheader(struct Curl_easy *data, const char *header) |
960 | 0 | { |
961 | 0 | if(checkprefix("CSeq:", header)) { |
962 | 0 | curl_off_t CSeq = 0; |
963 | 0 | struct RTSP *rtsp = Curl_meta_get(data, CURL_META_RTSP_EASY); |
964 | 0 | const char *p = &header[5]; |
965 | 0 | if(!rtsp) |
966 | 0 | return CURLE_FAILED_INIT; |
967 | 0 | curlx_str_passblanks(&p); |
968 | 0 | if(curlx_str_number(&p, &CSeq, UINT_MAX)) { |
969 | 0 | failf(data, "Unable to read the CSeq header: [%s]", header); |
970 | 0 | return CURLE_RTSP_CSEQ_ERROR; |
971 | 0 | } |
972 | 0 | data->state.rtsp_CSeq_recv = rtsp->CSeq_recv = (uint32_t)CSeq; |
973 | 0 | } |
974 | 0 | else if(checkprefix("Session:", header)) { |
975 | 0 | const char *start, *end, *str; |
976 | 0 | size_t idlen; |
977 | | |
978 | | /* Find the first non-space letter */ |
979 | 0 | start = header + 8; |
980 | 0 | curlx_str_passblanks(&start); |
981 | |
|
982 | 0 | if(!*start) { |
983 | 0 | failf(data, "Got a blank Session ID"); |
984 | 0 | return CURLE_RTSP_SESSION_ERROR; |
985 | 0 | } |
986 | | |
987 | | /* Find the end of Session ID |
988 | | * |
989 | | * Allow any non whitespace content, up to the field separator or end of |
990 | | * line. RFC 2326 is not 100% clear on the session ID and for example |
991 | | * gstreamer does URL-encoded session ID's not covered by the standard. |
992 | | */ |
993 | 0 | end = start; |
994 | 0 | while((*end > ' ') && (*end != ';')) |
995 | 0 | end++; |
996 | 0 | idlen = end - start; |
997 | |
|
998 | 0 | str = CURL_EASY_STR(data, STRING_RTSP_SESSION_ID); |
999 | 0 | if(str) { |
1000 | | |
1001 | | /* If the Session ID is set, then compare */ |
1002 | 0 | if(strlen(str) != idlen || |
1003 | 0 | strncmp(start, str, idlen)) { |
1004 | 0 | failf(data, "Got RTSP Session ID Line [%s], but wanted ID [%s]", |
1005 | 0 | start, str); |
1006 | 0 | return CURLE_RTSP_SESSION_ERROR; |
1007 | 0 | } |
1008 | 0 | } |
1009 | 0 | else { |
1010 | | /* If the Session ID is not set, and we find it in a response, then set |
1011 | | * it. |
1012 | | * Copy the id substring into a new buffer */ |
1013 | 0 | void *mem = curlx_memdup0(start, idlen); |
1014 | 0 | if(!mem || |
1015 | 0 | CURL_EASY_STR_SETN(data, STRING_RTSP_SESSION_ID, mem)) |
1016 | 0 | return CURLE_OUT_OF_MEMORY; |
1017 | 0 | } |
1018 | 0 | } |
1019 | 0 | else if(checkprefix("Transport:", header)) { |
1020 | 0 | CURLcode result; |
1021 | 0 | result = rtsp_parse_transport(data, header + 10); |
1022 | 0 | if(result) |
1023 | 0 | return result; |
1024 | 0 | } |
1025 | 0 | return CURLE_OK; |
1026 | 0 | } |
1027 | | |
1028 | | /* |
1029 | | * RTSP handler interface. |
1030 | | */ |
1031 | | const struct Curl_protocol Curl_protocol_rtsp = { |
1032 | | rtsp_setup_connection, /* setup_connection */ |
1033 | | rtsp_do, /* do_it */ |
1034 | | rtsp_done, /* done */ |
1035 | | ZERO_NULL, /* do_more */ |
1036 | | rtsp_connect, /* connect_it */ |
1037 | | ZERO_NULL, /* connecting */ |
1038 | | ZERO_NULL, /* doing */ |
1039 | | ZERO_NULL, /* proto_pollset */ |
1040 | | rtsp_do_pollset, /* doing_pollset */ |
1041 | | ZERO_NULL, /* domore_pollset */ |
1042 | | Curl_http_perform_pollset, /* perform_pollset */ |
1043 | | ZERO_NULL, /* disconnect */ |
1044 | | rtsp_rtp_write_resp, /* write_resp */ |
1045 | | rtsp_rtp_write_resp_hd, /* write_resp_hd */ |
1046 | | rtsp_conn_is_dead, /* connection_is_dead */ |
1047 | | ZERO_NULL, /* attach connection */ |
1048 | | Curl_http_follow, /* follow */ |
1049 | | }; |
1050 | | |
1051 | | #endif /* CURL_DISABLE_RTSP */ |