Mercurial > libavformat.hg
comparison rtsp.c @ 6175:0e737c9247fd libavformat
RTSP: Remove skip_spaces in favor of strspn
Patch by Josh Allmann, joshua dot allmann at gmail
author | mstorsjo |
---|---|
date | Fri, 25 Jun 2010 07:56:45 +0000 |
parents | 72ea866c62fd |
children | 5708c6d4223d |
comparison
equal
deleted
inserted
replaced
6174:563496476a23 | 6175:0e737c9247fd |
---|---|
51 * and read_packet(), in seconds */ | 51 * and read_packet(), in seconds */ |
52 #define SELECT_TIMEOUT_MS 100 | 52 #define SELECT_TIMEOUT_MS 100 |
53 #define READ_PACKET_TIMEOUT_S 10 | 53 #define READ_PACKET_TIMEOUT_S 10 |
54 #define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / SELECT_TIMEOUT_MS | 54 #define MAX_TIMEOUTS READ_PACKET_TIMEOUT_S * 1000 / SELECT_TIMEOUT_MS |
55 | 55 |
56 #define SPACE_CHARS " \t\r\n" | |
57 /* we use memchr() instead of strchr() here because strchr() will return | |
58 * the terminating '\0' of SPACE_CHARS instead of NULL if c is '\0'. */ | |
59 #define redir_isspace(c) memchr(SPACE_CHARS, c, 4) | |
60 static void skip_spaces(const char **pp) | |
61 { | |
62 const char *p; | |
63 p = *pp; | |
64 while (redir_isspace(*p)) | |
65 p++; | |
66 *pp = p; | |
67 } | |
68 | |
69 static void get_word_until_chars(char *buf, int buf_size, | 56 static void get_word_until_chars(char *buf, int buf_size, |
70 const char *sep, const char **pp) | 57 const char *sep, const char **pp) |
71 { | 58 { |
72 const char *p; | 59 const char *p; |
73 char *q; | 60 char *q; |
74 | 61 |
75 p = *pp; | 62 p = *pp; |
76 skip_spaces(&p); | 63 p += strspn(p, SPACE_CHARS); |
77 q = buf; | 64 q = buf; |
78 while (!strchr(sep, *p) && *p != '\0') { | 65 while (!strchr(sep, *p) && *p != '\0') { |
79 if ((q - buf) < buf_size - 1) | 66 if ((q - buf) < buf_size - 1) |
80 *q++ = *p; | 67 *q++ = *p; |
81 p++; | 68 p++; |
177 int c, len, v; | 164 int c, len, v; |
178 | 165 |
179 len = 0; | 166 len = 0; |
180 v = 1; | 167 v = 1; |
181 for (;;) { | 168 for (;;) { |
182 skip_spaces(&p); | 169 p += strspn(p, SPACE_CHARS); |
183 if (*p == '\0') | 170 if (*p == '\0') |
184 break; | 171 break; |
185 c = toupper((unsigned char) *p++); | 172 c = toupper((unsigned char) *p++); |
186 if (c >= '0' && c <= '9') | 173 if (c >= '0' && c <= '9') |
187 c = c - '0'; | 174 c = c - '0'; |
254 * is broken out as a function because it is used in rtp_h264.c, which is | 241 * is broken out as a function because it is used in rtp_h264.c, which is |
255 * forthcoming. */ | 242 * forthcoming. */ |
256 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, | 243 int ff_rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, |
257 char *value, int value_size) | 244 char *value, int value_size) |
258 { | 245 { |
259 skip_spaces(p); | 246 *p += strspn(*p, SPACE_CHARS); |
260 if (**p) { | 247 if (**p) { |
261 get_word_sep(attr, attr_size, "=", p); | 248 get_word_sep(attr, attr_size, "=", p); |
262 if (**p == '=') | 249 if (**p == '=') |
263 (*p)++; | 250 (*p)++; |
264 get_word_sep(value, value_size, ";", p); | 251 get_word_sep(value, value_size, ";", p); |
306 */ | 293 */ |
307 static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end) | 294 static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end) |
308 { | 295 { |
309 char buf[256]; | 296 char buf[256]; |
310 | 297 |
311 skip_spaces(&p); | 298 p += strspn(p, SPACE_CHARS); |
312 if (!av_stristart(p, "npt=", &p)) | 299 if (!av_stristart(p, "npt=", &p)) |
313 return; | 300 return; |
314 | 301 |
315 *start = AV_NOPTS_VALUE; | 302 *start = AV_NOPTS_VALUE; |
316 *end = AV_NOPTS_VALUE; | 303 *end = AV_NOPTS_VALUE; |
545 SDPParseState sdp_parse_state, *s1 = &sdp_parse_state; | 532 SDPParseState sdp_parse_state, *s1 = &sdp_parse_state; |
546 | 533 |
547 memset(s1, 0, sizeof(SDPParseState)); | 534 memset(s1, 0, sizeof(SDPParseState)); |
548 p = content; | 535 p = content; |
549 for (;;) { | 536 for (;;) { |
550 skip_spaces(&p); | 537 p += strspn(p, SPACE_CHARS); |
551 letter = *p; | 538 letter = *p; |
552 if (letter == '\0') | 539 if (letter == '\0') |
553 break; | 540 break; |
554 p++; | 541 p++; |
555 if (*p != '=') | 542 if (*p != '=') |
725 { | 712 { |
726 const char *p; | 713 const char *p; |
727 int v; | 714 int v; |
728 | 715 |
729 p = *pp; | 716 p = *pp; |
730 skip_spaces(&p); | 717 p += strspn(p, SPACE_CHARS); |
731 v = strtol(p, (char **)&p, 10); | 718 v = strtol(p, (char **)&p, 10); |
732 if (*p == '-') { | 719 if (*p == '-') { |
733 p++; | 720 p++; |
734 *min_ptr = v; | 721 *min_ptr = v; |
735 v = strtol(p, (char **)&p, 10); | 722 v = strtol(p, (char **)&p, 10); |
752 char buf[256]; | 739 char buf[256]; |
753 | 740 |
754 reply->nb_transports = 0; | 741 reply->nb_transports = 0; |
755 | 742 |
756 for (;;) { | 743 for (;;) { |
757 skip_spaces(&p); | 744 p += strspn(p, SPACE_CHARS); |
758 if (*p == '\0') | 745 if (*p == '\0') |
759 break; | 746 break; |
760 | 747 |
761 th = &reply->transports[reply->nb_transports]; | 748 th = &reply->transports[reply->nb_transports]; |
762 | 749 |
862 } else if (av_stristart(p, "CSeq:", &p)) { | 849 } else if (av_stristart(p, "CSeq:", &p)) { |
863 reply->seq = strtol(p, NULL, 10); | 850 reply->seq = strtol(p, NULL, 10); |
864 } else if (av_stristart(p, "Range:", &p)) { | 851 } else if (av_stristart(p, "Range:", &p)) { |
865 rtsp_parse_range_npt(p, &reply->range_start, &reply->range_end); | 852 rtsp_parse_range_npt(p, &reply->range_start, &reply->range_end); |
866 } else if (av_stristart(p, "RealChallenge1:", &p)) { | 853 } else if (av_stristart(p, "RealChallenge1:", &p)) { |
867 skip_spaces(&p); | 854 p += strspn(p, SPACE_CHARS); |
868 av_strlcpy(reply->real_challenge, p, sizeof(reply->real_challenge)); | 855 av_strlcpy(reply->real_challenge, p, sizeof(reply->real_challenge)); |
869 } else if (av_stristart(p, "Server:", &p)) { | 856 } else if (av_stristart(p, "Server:", &p)) { |
870 skip_spaces(&p); | 857 p += strspn(p, SPACE_CHARS); |
871 av_strlcpy(reply->server, p, sizeof(reply->server)); | 858 av_strlcpy(reply->server, p, sizeof(reply->server)); |
872 } else if (av_stristart(p, "Notice:", &p) || | 859 } else if (av_stristart(p, "Notice:", &p) || |
873 av_stristart(p, "X-Notice:", &p)) { | 860 av_stristart(p, "X-Notice:", &p)) { |
874 reply->notice = strtol(p, NULL, 10); | 861 reply->notice = strtol(p, NULL, 10); |
875 } else if (av_stristart(p, "Location:", &p)) { | 862 } else if (av_stristart(p, "Location:", &p)) { |
876 skip_spaces(&p); | 863 p += strspn(p, SPACE_CHARS); |
877 av_strlcpy(reply->location, p , sizeof(reply->location)); | 864 av_strlcpy(reply->location, p , sizeof(reply->location)); |
878 } else if (av_stristart(p, "WWW-Authenticate:", &p) && auth_state) { | 865 } else if (av_stristart(p, "WWW-Authenticate:", &p) && auth_state) { |
879 skip_spaces(&p); | 866 p += strspn(p, SPACE_CHARS); |
880 ff_http_auth_handle_header(auth_state, "WWW-Authenticate", p); | 867 ff_http_auth_handle_header(auth_state, "WWW-Authenticate", p); |
881 } else if (av_stristart(p, "Authentication-Info:", &p) && auth_state) { | 868 } else if (av_stristart(p, "Authentication-Info:", &p) && auth_state) { |
882 skip_spaces(&p); | 869 p += strspn(p, SPACE_CHARS); |
883 ff_http_auth_handle_header(auth_state, "Authentication-Info", p); | 870 ff_http_auth_handle_header(auth_state, "Authentication-Info", p); |
884 } | 871 } |
885 } | 872 } |
886 | 873 |
887 /* skip a RTP/TCP interleaved packet */ | 874 /* skip a RTP/TCP interleaved packet */ |