Mercurial > mplayer.hg
annotate libmpdemux/realrtsp/rtsp.c @ 10123:8bf6c57c5bbd
wrappers for 14.4 and 28.8 codecs
author | rtognimp |
---|---|
date | Sat, 17 May 2003 18:19:48 +0000 |
parents | 6b88f67564ce |
children | 35e306346e59 |
rev | line source |
---|---|
9922 | 1 /* |
2 * This file was ported to MPlayer from xine CVS rtsp.c,v 1.9 2003/04/10 02:30:48 | |
3 */ | |
4 | |
5 /* | |
6 * Copyright (C) 2000-2002 the xine project | |
7 * | |
8 * This file is part of xine, a free video player. | |
9 * | |
10 * xine is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * xine is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
23 * | |
24 * | |
25 * a minimalistic implementation of rtsp protocol, | |
26 * *not* RFC 2326 compilant yet. | |
27 */ | |
28 | |
29 #include <unistd.h> | |
30 #include <stdio.h> | |
31 #include <assert.h> | |
32 #include <sys/socket.h> | |
33 #include <netinet/in.h> | |
34 #include <netdb.h> | |
35 #include <string.h> | |
36 #include <sys/stat.h> | |
37 #include <fcntl.h> | |
38 #include <errno.h> | |
39 #include <stdlib.h> | |
40 #include <time.h> | |
41 #include <sys/time.h> | |
42 #include <sys/types.h> | |
9939
6b88f67564ce
Fix compilation for *BSD, Mac OS X and maybe others (info by Steven M. Schultz and Dan Christiansen)
rtognimp
parents:
9922
diff
changeset
|
43 #include <inttypes.h> |
9922 | 44 |
45 #include "rtsp.h" | |
46 | |
47 /* | |
48 #define LOG | |
49 */ | |
50 | |
51 #define BUF_SIZE 4096 | |
52 #define HEADER_SIZE 1024 | |
53 #define MAX_FIELDS 256 | |
54 | |
55 struct rtsp_s { | |
56 | |
57 int s; | |
58 | |
59 char *host; | |
60 int port; | |
61 char *path; | |
62 char *mrl; | |
63 char *user_agent; | |
64 | |
65 char *server; | |
66 unsigned int server_state; | |
67 uint32_t server_caps; | |
68 | |
69 char buffer[BUF_SIZE]; /* scratch buffer */ | |
70 | |
71 unsigned int cseq; | |
72 char *session; | |
73 | |
74 char *answers[MAX_FIELDS]; /* data of last message */ | |
75 char *scheduled[MAX_FIELDS]; /* will be sent with next message */ | |
76 }; | |
77 | |
78 /* | |
79 * constants | |
80 */ | |
81 | |
82 const char rtsp_protocol_version[]="RTSP/1.0"; | |
83 | |
84 /* server states */ | |
85 #define RTSP_CONNECTED 1 | |
86 #define RTSP_INIT 2 | |
87 #define RTSP_READY 4 | |
88 #define RTSP_PLAYING 8 | |
89 #define RTSP_RECORDING 16 | |
90 | |
91 /* server capabilities */ | |
92 #define RTSP_OPTIONS 0x001 | |
93 #define RTSP_DESCRIBE 0x002 | |
94 #define RTSP_ANNOUNCE 0x004 | |
95 #define RTSP_SETUP 0x008 | |
96 #define RTSP_GET_PARAMETER 0x010 | |
97 #define RTSP_SET_PARAMETER 0x020 | |
98 #define RTSP_TEARDOWN 0x040 | |
99 #define RTSP_PLAY 0x080 | |
100 #define RTSP_RECORD 0x100 | |
101 | |
102 /* | |
103 * network utilities | |
104 */ | |
105 | |
106 static int host_connect_attempt(struct in_addr ia, int port) { | |
107 | |
108 int s; | |
109 struct sockaddr_in sin; | |
110 | |
111 s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); | |
112 if (s == -1) { | |
113 printf ("rtsp: socket(): %s\n", strerror(errno)); | |
114 return -1; | |
115 } | |
116 | |
117 sin.sin_family = AF_INET; | |
118 sin.sin_addr = ia; | |
119 sin.sin_port = htons(port); | |
120 | |
121 if (connect(s, (struct sockaddr *)&sin, sizeof(sin))==-1 | |
122 && errno != EINPROGRESS) { | |
123 printf ("rtsp: connect(): %s\n", strerror(errno)); | |
124 close(s); | |
125 return -1; | |
126 } | |
127 | |
128 return s; | |
129 } | |
130 | |
131 static int host_connect(const char *host, int port) { | |
132 | |
133 struct hostent *h; | |
134 int i, s; | |
135 | |
136 h = gethostbyname(host); | |
137 if (h == NULL) { | |
138 printf ("rtsp: unable to resolve '%s'.\n", host); | |
139 return -1; | |
140 } | |
141 | |
142 for (i = 0; h->h_addr_list[i]; i++) { | |
143 struct in_addr ia; | |
144 | |
145 memcpy (&ia, h->h_addr_list[i], 4); | |
146 s = host_connect_attempt(ia, port); | |
147 if(s != -1) | |
148 return s; | |
149 } | |
150 printf ("rtsp: unable to connect to '%s'.\n", host); | |
151 return -1; | |
152 } | |
153 | |
154 static int write_stream(int s, const char *buf, int len) { | |
155 int total, timeout; | |
156 | |
157 total = 0; timeout = 30; | |
158 while (total < len){ | |
159 int n; | |
160 | |
161 n = write (s, &buf[total], len - total); | |
162 | |
163 if (n > 0) | |
164 total += n; | |
165 else if (n < 0) { | |
166 if ((timeout>0) && ((errno == EAGAIN) || (errno == EINPROGRESS))) { | |
167 sleep (1); timeout--; | |
168 } else | |
169 return -1; | |
170 } | |
171 } | |
172 | |
173 return total; | |
174 } | |
175 | |
176 static ssize_t read_stream(int fd, void *buf, size_t count) { | |
177 | |
178 ssize_t ret, total; | |
179 | |
180 total = 0; | |
181 | |
182 while (total < count) { | |
183 | |
184 ret=read (fd, ((uint8_t*)buf)+total, count-total); | |
185 | |
186 if (ret<0) { | |
187 if(errno == EAGAIN) { | |
188 fd_set rset; | |
189 struct timeval timeout; | |
190 | |
191 FD_ZERO (&rset); | |
192 FD_SET (fd, &rset); | |
193 | |
194 timeout.tv_sec = 30; | |
195 timeout.tv_usec = 0; | |
196 | |
197 if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) { | |
198 return -1; | |
199 } | |
200 continue; | |
201 } | |
202 | |
203 printf ("rtsp: read error.\n"); | |
204 return ret; | |
205 } else | |
206 total += ret; | |
207 | |
208 /* end of stream */ | |
209 if (!ret) break; | |
210 } | |
211 | |
212 return total; | |
213 } | |
214 | |
215 /* | |
216 * debugging utilities | |
217 */ | |
218 #if 0 | |
219 static void hexdump (char *buf, int length) { | |
220 | |
221 int i; | |
222 | |
223 printf ("rtsp: ascii>"); | |
224 for (i = 0; i < length; i++) { | |
225 unsigned char c = buf[i]; | |
226 | |
227 if ((c >= 32) && (c <= 128)) | |
228 printf ("%c", c); | |
229 else | |
230 printf ("."); | |
231 } | |
232 printf ("\n"); | |
233 | |
234 printf ("rtsp: hexdump> "); | |
235 for (i = 0; i < length; i++) { | |
236 unsigned char c = buf[i]; | |
237 | |
238 printf ("%02x", c); | |
239 | |
240 if ((i % 16) == 15) | |
241 printf ("\nrtsp: "); | |
242 | |
243 if ((i % 2) == 1) | |
244 printf (" "); | |
245 | |
246 } | |
247 printf ("\n"); | |
248 } | |
249 #endif | |
250 | |
251 /* | |
252 * rtsp_get gets a line from stream | |
253 * and returns a null terminated string. | |
254 */ | |
255 | |
256 static char *rtsp_get(rtsp_t *s) { | |
257 | |
258 int n=0; | |
259 char *string; | |
260 | |
261 while (n<BUF_SIZE) { | |
262 read_stream(s->s, &s->buffer[n], 1); | |
263 if ((s->buffer[n-1]==0x0d)&&(s->buffer[n]==0x0a)) break; | |
264 n++; | |
265 } | |
266 | |
267 if (n>=BUF_SIZE) { | |
268 printf("librtsp: buffer overflow in rtsp_get\n"); | |
269 exit(1); | |
270 } | |
271 string=malloc(sizeof(char)*n); | |
272 memcpy(string,s->buffer,n-1); | |
273 string[n-1]=0; | |
274 | |
275 #ifdef LOG | |
276 printf("librtsp: << '%s'\n", string); | |
277 #endif | |
278 | |
279 | |
280 return string; | |
281 } | |
282 | |
283 /* | |
284 * rtsp_put puts a line on stream | |
285 */ | |
286 | |
287 static void rtsp_put(rtsp_t *s, const char *string) { | |
288 | |
289 int len=strlen(string); | |
290 char *buf=malloc(sizeof(char)*len+2); | |
291 | |
292 #ifdef LOG | |
293 printf("librtsp: >> '%s'", string); | |
294 #endif | |
295 | |
296 memcpy(buf,string,len); | |
297 buf[len]=0x0d; | |
298 buf[len+1]=0x0a; | |
299 | |
300 write_stream(s->s, buf, len+2); | |
301 | |
302 #ifdef LOG | |
303 printf(" done.\n"); | |
304 #endif | |
305 | |
306 free(buf); | |
307 } | |
308 | |
309 /* | |
310 * extract server status code | |
311 */ | |
312 | |
313 static int rtsp_get_code(const char *string) { | |
314 | |
315 char buf[4]; | |
316 int code=0; | |
317 | |
318 if (!strncmp(string, rtsp_protocol_version, strlen(rtsp_protocol_version))) | |
319 { | |
320 memcpy(buf, string+strlen(rtsp_protocol_version)+1, 3); | |
321 buf[3]=0; | |
322 code=atoi(buf); | |
323 } else if (!strncmp(string, "SET_PARAMETER",8)) | |
324 { | |
325 return RTSP_STATUS_SET_PARAMETER; | |
326 } | |
327 | |
328 if(code != 200) printf("librtsp: server responds: '%s'\n",string); | |
329 | |
330 return code; | |
331 } | |
332 | |
333 /* | |
334 * send a request | |
335 */ | |
336 | |
337 static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) { | |
338 | |
339 char **payload=s->scheduled; | |
340 sprintf(s->buffer,"%s %s %s",type, what, rtsp_protocol_version); | |
341 rtsp_put(s,s->buffer); | |
342 if (payload) | |
343 while (*payload) { | |
344 rtsp_put(s,*payload); | |
345 payload++; | |
346 } | |
347 rtsp_put(s,""); | |
348 rtsp_unschedule_all(s); | |
349 } | |
350 | |
351 /* | |
352 * schedule standard fields | |
353 */ | |
354 | |
355 static void rtsp_schedule_standard(rtsp_t *s) { | |
356 | |
357 sprintf(s->buffer, "Cseq: %u", s->cseq); | |
358 rtsp_schedule_field(s, s->buffer); | |
359 if (s->session) { | |
360 sprintf(s->buffer, "Session: %s", s->session); | |
361 rtsp_schedule_field(s, s->buffer); | |
362 } | |
363 } | |
364 /* | |
365 * get the answers, if server responses with something != 200, return NULL | |
366 */ | |
367 | |
368 static int rtsp_get_answers(rtsp_t *s) { | |
369 | |
370 char *answer=NULL; | |
371 unsigned int answer_seq; | |
372 char **answer_ptr=s->answers; | |
373 int code; | |
374 | |
375 answer=rtsp_get(s); | |
376 code=rtsp_get_code(answer); | |
377 free(answer); | |
378 | |
379 rtsp_free_answers(s); | |
380 | |
381 do { /* while we get answer lines */ | |
382 | |
383 answer=rtsp_get(s); | |
384 | |
385 if (!strncmp(answer,"Cseq:",5)) { | |
386 sscanf(answer,"Cseq: %u",&answer_seq); | |
387 if (s->cseq != answer_seq) { | |
388 #ifdef LOG | |
389 printf("librtsp: warning: Cseq mismatch. got %u, assumed %u", answer_seq, s->cseq); | |
390 #endif | |
391 s->cseq=answer_seq; | |
392 } | |
393 } | |
394 if (!strncmp(answer,"Server:",7)) { | |
395 sscanf(answer,"Server: %s",s->buffer); | |
396 if (s->server) free(s->server); | |
397 s->server=strdup(s->buffer); | |
398 } | |
399 if (!strncmp(answer,"Session:",8)) { | |
400 memset(s->buffer,0, BUF_SIZE); | |
401 sscanf(answer,"Session: %s",s->buffer); | |
402 if (s->session) { | |
403 if (strcmp(s->buffer, s->session)) { | |
404 printf("rtsp: warning: setting NEW session: %s\n", s->buffer); | |
405 free(s->session); | |
406 s->session=strdup(s->buffer); | |
407 } | |
408 } else | |
409 { | |
410 #ifdef LOG | |
411 printf("rtsp: setting session id to: %s\n", s->buffer); | |
412 #endif | |
413 s->session=strdup(s->buffer); | |
414 } | |
415 } | |
416 *answer_ptr=answer; | |
417 answer_ptr++; | |
418 } while (strlen(answer)!=0); | |
419 | |
420 s->cseq++; | |
421 | |
422 *answer_ptr=NULL; | |
423 rtsp_schedule_standard(s); | |
424 | |
425 return code; | |
426 } | |
427 | |
428 /* | |
429 * send an ok message | |
430 */ | |
431 | |
432 int rtsp_send_ok(rtsp_t *s) { | |
433 char cseq[16]; | |
434 | |
435 rtsp_put(s, "RTSP/1.0 200 OK"); | |
436 sprintf(cseq,"CSeq: %u", s->cseq); | |
437 rtsp_put(s, cseq); | |
438 rtsp_put(s, ""); | |
439 return 0; | |
440 } | |
441 | |
442 /* | |
443 * implementation of must-have rtsp requests; functions return | |
444 * server status code. | |
445 */ | |
446 | |
447 int rtsp_request_options(rtsp_t *s, const char *what) { | |
448 | |
449 char *buf; | |
450 | |
451 if (what) { | |
452 buf=strdup(what); | |
453 } else | |
454 { | |
455 buf=malloc(sizeof(char)*(strlen(s->host)+16)); | |
456 sprintf(buf,"rtsp://%s:%i", s->host, s->port); | |
457 } | |
458 rtsp_send_request(s,"OPTIONS",buf); | |
459 free(buf); | |
460 | |
461 return rtsp_get_answers(s); | |
462 } | |
463 | |
464 int rtsp_request_describe(rtsp_t *s, const char *what) { | |
465 | |
466 char *buf; | |
467 | |
468 if (what) { | |
469 buf=strdup(what); | |
470 } else | |
471 { | |
472 buf=malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16)); | |
473 sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); | |
474 } | |
475 rtsp_send_request(s,"DESCRIBE",buf); | |
476 free(buf); | |
477 | |
478 return rtsp_get_answers(s); | |
479 } | |
480 | |
481 int rtsp_request_setup(rtsp_t *s, const char *what) { | |
482 | |
483 rtsp_send_request(s,"SETUP",what); | |
484 | |
485 return rtsp_get_answers(s); | |
486 } | |
487 | |
488 int rtsp_request_setparameter(rtsp_t *s, const char *what) { | |
489 | |
490 char *buf; | |
491 | |
492 if (what) { | |
493 buf=strdup(what); | |
494 } else | |
495 { | |
496 buf=malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16)); | |
497 sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); | |
498 } | |
499 rtsp_send_request(s,"SET_PARAMETER",buf); | |
500 free(buf); | |
501 | |
502 return rtsp_get_answers(s); | |
503 } | |
504 | |
505 int rtsp_request_play(rtsp_t *s, const char *what) { | |
506 | |
507 char *buf; | |
508 | |
509 if (what) { | |
510 buf=strdup(what); | |
511 } else | |
512 { | |
513 buf=malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16)); | |
514 sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); | |
515 } | |
516 rtsp_send_request(s,"PLAY",buf); | |
517 free(buf); | |
518 | |
519 return rtsp_get_answers(s); | |
520 } | |
521 | |
522 int rtsp_request_tearoff(rtsp_t *s, const char *what) { | |
523 | |
524 rtsp_send_request(s,"TEAROFF",what); | |
525 | |
526 return rtsp_get_answers(s); | |
527 } | |
528 | |
529 /* | |
530 * read opaque data from stream | |
531 */ | |
532 | |
533 int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size) { | |
534 | |
535 int i,seq; | |
536 | |
537 if (size>=4) { | |
538 i=read_stream(s->s, buffer, 4); | |
539 if (i<4) return i; | |
540 if ((buffer[0]=='S')&&(buffer[1]=='E')&&(buffer[2]=='T')&&(buffer[3]=='_')) | |
541 { | |
542 char *rest=rtsp_get(s); | |
543 /* a real server wanna play table tennis? */ | |
544 memcpy(s->buffer, buffer, 4); | |
545 strcpy(s->buffer+4, rest); | |
546 seq=-1; | |
547 do { | |
548 free(rest); | |
549 rest=rtsp_get(s); | |
550 if (!strncmp(rest,"Cseq:",5)) | |
551 sscanf(rest,"Cseq: %u",&seq); | |
552 } while (strlen(rest)!=0); | |
553 free(rest); | |
554 if (seq<0) { | |
555 #ifdef LOG | |
556 printf("rtsp: warning: cseq not recognized!\n"); | |
557 #endif | |
558 seq=1; | |
559 } | |
560 /* lets make the server happy */ | |
561 rtsp_put(s, "RTSP/1.0 451 Parameter Not Understood"); | |
562 rest=malloc(sizeof(char)*16); | |
563 sprintf(rest,"CSeq: %u", seq); | |
564 rtsp_put(s, rest); | |
565 rtsp_put(s, ""); | |
566 i=read_stream(s->s, buffer, size); | |
567 } else | |
568 { | |
569 i=read_stream(s->s, buffer+4, size-4); | |
570 i+=4; | |
571 } | |
572 } else | |
573 i=read_stream(s->s, buffer, size); | |
574 #ifdef LOG | |
575 printf("librtsp: << %d of %d bytes\n", i, size); | |
576 #endif | |
577 | |
578 return i; | |
579 } | |
580 | |
581 /* | |
582 * connect to a rtsp server | |
583 */ | |
584 | |
585 //rtsp_t *rtsp_connect(const char *mrl, const char *user_agent) { | |
586 rtsp_t *rtsp_connect(int fd, char* mrl, char *path, char *host, int port, char *user_agent) { | |
587 | |
588 rtsp_t *s=malloc(sizeof(rtsp_t)); | |
589 int i; | |
590 | |
591 for (i=0; i<MAX_FIELDS; i++) { | |
592 s->answers[i]=NULL; | |
593 s->scheduled[i]=NULL; | |
594 } | |
595 | |
596 s->server=NULL; | |
597 s->server_state=0; | |
598 s->server_caps=0; | |
599 | |
600 s->cseq=0; | |
601 s->session=NULL; | |
602 | |
603 if (user_agent) | |
604 s->user_agent=strdup(user_agent); | |
605 else | |
606 s->user_agent=strdup("User-Agent: RealMedia Player Version 6.0.9.1235 (linux-2.0-libc6-i386-gcc2.95)"); | |
607 | |
608 s->mrl = strdup(mrl); | |
609 s->host = strdup(host); | |
610 s->port = port; | |
611 s->path = strdup(path); | |
612 s->s = fd; | |
613 | |
614 if (s->s < 0) { | |
615 printf ("rtsp: failed to connect to '%s'\n", s->host); | |
616 rtsp_close(s); | |
617 return NULL; | |
618 } | |
619 | |
620 s->server_state=RTSP_CONNECTED; | |
621 | |
622 /* now lets send an options request. */ | |
623 rtsp_schedule_field(s, "CSeq: 1"); | |
624 rtsp_schedule_field(s, s->user_agent); | |
625 rtsp_schedule_field(s, "ClientChallenge: 9e26d33f2984236010ef6253fb1887f7"); | |
626 rtsp_schedule_field(s, "PlayerStarttime: [28/03/2003:22:50:23 00:00]"); | |
627 rtsp_schedule_field(s, "CompanyID: KnKV4M4I/B2FjJ1TToLycw=="); | |
628 rtsp_schedule_field(s, "GUID: 00000000-0000-0000-0000-000000000000"); | |
629 rtsp_schedule_field(s, "RegionData: 0"); | |
630 rtsp_schedule_field(s, "ClientID: Linux_2.4_6.0.9.1235_play32_RN01_EN_586"); | |
631 /*rtsp_schedule_field(s, "Pragma: initiate-session");*/ | |
632 rtsp_request_options(s, NULL); | |
633 | |
634 return s; | |
635 } | |
636 | |
637 | |
638 /* | |
639 * closes an rtsp connection | |
640 */ | |
641 | |
642 void rtsp_close(rtsp_t *s) { | |
643 | |
644 if (s->server_state) close(s->s); /* TODO: send a TEAROFF */ | |
645 if (s->path) free(s->path); | |
646 if (s->host) free(s->host); | |
647 if (s->mrl) free(s->mrl); | |
648 if (s->session) free(s->session); | |
649 if (s->user_agent) free(s->user_agent); | |
650 rtsp_free_answers(s); | |
651 rtsp_unschedule_all(s); | |
652 free(s); | |
653 } | |
654 | |
655 /* | |
656 * search in answers for tags. returns a pointer to the content | |
657 * after the first matched tag. returns NULL if no match found. | |
658 */ | |
659 | |
660 char *rtsp_search_answers(rtsp_t *s, const char *tag) { | |
661 | |
662 char **answer; | |
663 char *ptr; | |
664 | |
665 if (!s->answers) return NULL; | |
666 answer=s->answers; | |
667 | |
668 while (*answer) { | |
669 if (!strncasecmp(*answer,tag,strlen(tag))) { | |
670 ptr=strchr(*answer,':'); | |
671 ptr++; | |
672 while(*ptr==' ') ptr++; | |
673 return ptr; | |
674 } | |
675 answer++; | |
676 } | |
677 | |
678 return NULL; | |
679 } | |
680 | |
681 /* | |
682 * session id management | |
683 */ | |
684 | |
685 void rtsp_set_session(rtsp_t *s, const char *id) { | |
686 | |
687 if (s->session) free(s->session); | |
688 | |
689 s->session=strdup(id); | |
690 | |
691 } | |
692 | |
693 char *rtsp_get_session(rtsp_t *s) { | |
694 | |
695 return s->session; | |
696 | |
697 } | |
698 | |
699 char *rtsp_get_mrl(rtsp_t *s) { | |
700 | |
701 return s->mrl; | |
702 | |
703 } | |
704 | |
705 /* | |
706 * schedules a field for transmission | |
707 */ | |
708 | |
709 void rtsp_schedule_field(rtsp_t *s, const char *string) { | |
710 | |
711 int i=0; | |
712 | |
713 if (!string) return; | |
714 | |
715 while(s->scheduled[i]) { | |
716 i++; | |
717 } | |
718 s->scheduled[i]=strdup(string); | |
719 } | |
720 | |
721 /* | |
722 * removes the first scheduled field which prefix matches string. | |
723 */ | |
724 | |
725 void rtsp_unschedule_field(rtsp_t *s, const char *string) { | |
726 | |
727 char **ptr=s->scheduled; | |
728 | |
729 if (!string) return; | |
730 | |
731 while(*ptr) { | |
732 if (!strncmp(*ptr, string, strlen(string))) | |
733 break; | |
734 } | |
735 if (*ptr) free(*ptr); | |
736 ptr++; | |
737 do { | |
738 *(ptr-1)=*ptr; | |
739 } while(*ptr); | |
740 } | |
741 | |
742 /* | |
743 * unschedule all fields | |
744 */ | |
745 | |
746 void rtsp_unschedule_all(rtsp_t *s) { | |
747 | |
748 char **ptr; | |
749 | |
750 if (!s->scheduled) return; | |
751 ptr=s->scheduled; | |
752 | |
753 while (*ptr) { | |
754 free(*ptr); | |
755 *ptr=NULL; | |
756 ptr++; | |
757 } | |
758 } | |
759 /* | |
760 * free answers | |
761 */ | |
762 | |
763 void rtsp_free_answers(rtsp_t *s) { | |
764 | |
765 char **answer; | |
766 | |
767 if (!s->answers) return; | |
768 answer=s->answers; | |
769 | |
770 while (*answer) { | |
771 free(*answer); | |
772 *answer=NULL; | |
773 answer++; | |
774 } | |
775 } |