Changeset 6e5f468a1e77d3986e2bd8b9f0dd5fb2f5aaa964
- Timestamp:
- 30/08/07 23:36:40
(1 year ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1188509800 +0000
- git-parent:
[1706407b93acb91819eedeb9557d67c6bbe23de4]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1188509800 +0000
- Message:
Fix a bunch of bugs I added, and simplify some stuff
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r4d9440e |
r6e5f468 |
|
| 2 | 2 | * rtsp.c: RTSP support for RTP stream output module |
|---|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | | * Copyright (C) 2003-2007 the VideoLAN team |
|---|
| | 4 | * Copyright (C) 2003-2004 the VideoLAN team |
|---|
| | 5 | * Copyright © 2007 Rémi Denis-Courmont |
|---|
| | 6 | * |
|---|
| 5 | 7 | * $Id: rtp.c 21407 2007-08-22 20:10:41Z courmisch $ |
|---|
| 6 | 8 | * |
|---|
| … | … | |
| 32 | 34 | #include <vlc_network.h> |
|---|
| 33 | 35 | #include <assert.h> |
|---|
| | 36 | #include <errno.h> |
|---|
| | 37 | #include <stdlib.h> |
|---|
| 34 | 38 | |
|---|
| 35 | 39 | #include "rtp.h" |
|---|
| … | … | |
| 52 | 56 | |
|---|
| 53 | 57 | static int RtspCallback( httpd_callback_sys_t *p_args, |
|---|
| 54 | | httpd_client_t *cl, |
|---|
| 55 | | httpd_message_t *answer, httpd_message_t *query ); |
|---|
| | 58 | httpd_client_t *cl, httpd_message_t *answer, |
|---|
| | 59 | const httpd_message_t *query ); |
|---|
| 56 | 60 | static int RtspCallbackId( httpd_callback_sys_t *p_args, |
|---|
| 57 | | httpd_client_t *cl, |
|---|
| 58 | | httpd_message_t *answer, httpd_message_t *query ); |
|---|
| | 61 | httpd_client_t *cl, httpd_message_t *answer, |
|---|
| | 62 | const httpd_message_t *query ); |
|---|
| 59 | 63 | static void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session ); |
|---|
| 60 | 64 | |
|---|
| … | … | |
| 141 | 145 | { |
|---|
| 142 | 146 | rtsp_stream_t *stream; |
|---|
| | 147 | uint64_t id; |
|---|
| 143 | 148 | |
|---|
| 144 | 149 | /* output (id-access) */ |
|---|
| 145 | 150 | int trackc; |
|---|
| 146 | 151 | rtsp_strack_t *trackv; |
|---|
| 147 | | |
|---|
| 148 | | char name[0]; |
|---|
| 149 | 152 | }; |
|---|
| 150 | 153 | |
|---|
| … | … | |
| 230 | 233 | /** rtsp must be locked */ |
|---|
| 231 | 234 | static |
|---|
| 232 | | rtsp_session_t *RtspClientNew( rtsp_stream_t *rtsp, const char *name ) |
|---|
| 233 | | { |
|---|
| 234 | | rtsp_session_t *s = malloc( sizeof( *s ) + strlen( name ) + 1 ); |
|---|
| | 235 | rtsp_session_t *RtspClientNew( rtsp_stream_t *rtsp ) |
|---|
| | 236 | { |
|---|
| | 237 | rtsp_session_t *s = malloc( sizeof( *s ) ); |
|---|
| | 238 | if( s == NULL ) |
|---|
| | 239 | return NULL; |
|---|
| 235 | 240 | |
|---|
| 236 | 241 | s->stream = rtsp; |
|---|
| | 242 | s->id = rand(); /* FIXME: not enough entropy */ |
|---|
| 237 | 243 | s->trackc = 0; |
|---|
| 238 | 244 | s->trackv = NULL; |
|---|
| 239 | | strcpy( s->name, name ); |
|---|
| 240 | 245 | |
|---|
| 241 | 246 | TAB_APPEND( rtsp->sessionc, rtsp->sessionv, s ); |
|---|
| … | … | |
| 249 | 254 | rtsp_session_t *RtspClientGet( rtsp_stream_t *rtsp, const char *name ) |
|---|
| 250 | 255 | { |
|---|
| | 256 | char *end; |
|---|
| | 257 | uint64_t id; |
|---|
| 251 | 258 | int i; |
|---|
| 252 | 259 | |
|---|
| … | … | |
| 254 | 261 | return NULL; |
|---|
| 255 | 262 | |
|---|
| | 263 | errno = 0; |
|---|
| | 264 | id = strtoull( name, &end, 0x10 ); |
|---|
| | 265 | if( errno || *end ) |
|---|
| | 266 | return NULL; |
|---|
| | 267 | |
|---|
| 256 | 268 | /* FIXME: use a hash/dictionary */ |
|---|
| 257 | 269 | for( i = 0; i < rtsp->sessionc; i++ ) |
|---|
| 258 | 270 | { |
|---|
| 259 | | if( !strcmp( rtsp->sessionv[i]->name, name ) ) |
|---|
| | 271 | if( rtsp->sessionv[i]->id == id ) |
|---|
| 260 | 272 | return rtsp->sessionv[i]; |
|---|
| 261 | 273 | } |
|---|
| … | … | |
| 285 | 297 | static int RtspCallback( httpd_callback_sys_t *p_args, |
|---|
| 286 | 298 | httpd_client_t *cl, |
|---|
| 287 | | httpd_message_t *answer, httpd_message_t *query ) |
|---|
| | 299 | httpd_message_t *answer, |
|---|
| | 300 | const httpd_message_t *query ) |
|---|
| 288 | 301 | { |
|---|
| 289 | 302 | rtsp_stream_t *rtsp = (rtsp_stream_t *)p_args; |
|---|
| … | … | |
| 305 | 318 | { |
|---|
| 306 | 319 | answer->i_status = 551; |
|---|
| 307 | | httpd_MsgAdd( query, "Unsupported", "%s", |
|---|
| | 320 | httpd_MsgAdd( answer, "Unsupported", "%s", |
|---|
| 308 | 321 | httpd_MsgGet( query, "Require" ) ); |
|---|
| 309 | 322 | } |
|---|
| … | … | |
| 433 | 446 | static int RtspCallbackId( httpd_callback_sys_t *p_args, |
|---|
| 434 | 447 | httpd_client_t *cl, |
|---|
| 435 | | httpd_message_t *answer, httpd_message_t *query ) |
|---|
| | 448 | httpd_message_t *answer, |
|---|
| | 449 | const httpd_message_t *query ) |
|---|
| 436 | 450 | { |
|---|
| 437 | 451 | rtsp_stream_id_t *id = (rtsp_stream_id_t *)p_args; |
|---|
| 438 | 452 | rtsp_stream_t *rtsp = id->stream; |
|---|
| 439 | 453 | sout_stream_t *p_stream = id->stream->owner; |
|---|
| 440 | | char psz_session_init[21]; |
|---|
| | 454 | char psz_sesbuf[17]; |
|---|
| 441 | 455 | const char *psz_session, *psz; |
|---|
| 442 | 456 | |
|---|
| 443 | 457 | if( answer == NULL || query == NULL ) |
|---|
| 444 | 458 | return VLC_SUCCESS; |
|---|
| 445 | | //fprintf( stderr, "RtspCallback query: type=%d\n", query->i_type ); |
|---|
| 446 | 459 | |
|---|
| 447 | 460 | /* */ |
|---|
| … | … | |
| 452 | 465 | answer->p_body = NULL; |
|---|
| 453 | 466 | |
|---|
| 454 | | /* Create new session ID if needed */ |
|---|
| 455 | 467 | psz_session = httpd_MsgGet( query, "Session" ); |
|---|
| 456 | | if( psz_session == NULL ) |
|---|
| 457 | | { |
|---|
| 458 | | /* FIXME: should be somewhat secure randomness */ |
|---|
| 459 | | snprintf( psz_session_init, sizeof(psz_session_init), I64Fu, |
|---|
| 460 | | NTPtime64() + rand() ); |
|---|
| 461 | | } |
|---|
| 462 | 468 | |
|---|
| 463 | 469 | if( httpd_MsgGet( query, "Require" ) != NULL ) |
|---|
| 464 | 470 | { |
|---|
| 465 | 471 | answer->i_status = 551; |
|---|
| 466 | | httpd_MsgAdd( query, "Unsupported", "%s", |
|---|
| | 472 | httpd_MsgAdd( answer, "Unsupported", "%s", |
|---|
| 467 | 473 | httpd_MsgGet( query, "Require" ) ); |
|---|
| 468 | 474 | } |
|---|
| … | … | |
| 516 | 522 | } |
|---|
| 517 | 523 | else |
|---|
| | 524 | if( strncmp( opt,"destination=", 12 ) == 0 ) |
|---|
| | 525 | { |
|---|
| | 526 | answer->i_status = 403; |
|---|
| | 527 | b_unsupp = VLC_TRUE; |
|---|
| | 528 | } |
|---|
| | 529 | else |
|---|
| 518 | 530 | { |
|---|
| 519 | 531 | /* |
|---|
| 520 | 532 | * Every other option is unsupported: |
|---|
| 521 | 533 | * |
|---|
| 522 | | * "source" and "append" are invalid. |
|---|
| | 534 | * "source" and "append" are invalid (server-only); |
|---|
| | 535 | * "ssrc" also (as clarified per RFC2326bis). |
|---|
| 523 | 536 | * |
|---|
| 524 | 537 | * For multicast, "port", "layers", "ttl" are set by the |
|---|
| 525 | 538 | * stream output configuration. |
|---|
| 526 | 539 | * |
|---|
| 527 | | * For unicast, we do not allow "destination" as it |
|---|
| 528 | | * carries a DoS risk, and we decide on "server_port". |
|---|
| | 540 | * For unicast, we want to decide "server_port" values. |
|---|
| 529 | 541 | * |
|---|
| 530 | | * "interleaved" and "ssrc" are not implemented. |
|---|
| | 542 | * "interleaved" is not implemented. |
|---|
| 531 | 543 | */ |
|---|
| 532 | 544 | b_unsupp = VLC_TRUE; |
|---|
| … | … | |
| 586 | 598 | if( psz_session == NULL ) |
|---|
| 587 | 599 | { |
|---|
| 588 | | psz_session = psz_session_init; |
|---|
| 589 | | ses = RtspClientNew( rtsp, psz_session ); |
|---|
| | 600 | ses = RtspClientNew( rtsp ); |
|---|
| | 601 | snprintf( psz_sesbuf, sizeof( psz_sesbuf ), I64Fx, |
|---|
| | 602 | ses->id ); |
|---|
| | 603 | psz_session = psz_sesbuf; |
|---|
| 590 | 604 | } |
|---|
| 591 | 605 | else |
|---|