void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, const char *value) { if (!strcmp(key, "WWW-Authenticate") || !strcmp(key, "Proxy-Authenticate")) { const char *p; if (av_stristart(value, "Basic ", &p) && state->auth_type <= HTTP_AUTH_BASIC) { state->auth_type = HTTP_AUTH_BASIC; state->realm[0] = 0; state->stale = 0; ff_parse_key_value(p, (ff_parse_key_val_cb) handle_basic_params, state); } else if (av_stristart(value, "Digest ", &p) && state->auth_type <= HTTP_AUTH_DIGEST) { state->auth_type = HTTP_AUTH_DIGEST; memset(&state->digest_params, 0, sizeof(DigestParams)); state->realm[0] = 0; state->stale = 0; ff_parse_key_value(p, (ff_parse_key_val_cb) handle_digest_params, state); choose_qop(state->digest_params.qop, sizeof(state->digest_params.qop)); if (!av_strcasecmp(state->digest_params.stale, "true")) state->stale = 1; } } else if (!strcmp(key, "Authentication-Info")) { ff_parse_key_value(value, (ff_parse_key_val_cb) handle_digest_update, state); } }
static inline int has_header(const char *str, const char *header) { /* header + 2 to skip over CRLF prefix. (make sure you have one!) */ if (!str) return 0; return av_stristart(str, header + 2, NULL) || av_stristr(str, header); }
static char* mpjpeg_get_boundary(AVIOContext* pb) { uint8_t *mime_type = NULL; const char *start; const char *end; uint8_t *res = NULL; int len; /* get MIME type, and skip to the first parameter */ av_opt_get(pb, "mime_type", AV_OPT_SEARCH_CHILDREN, &mime_type); start = mime_type; while (start != NULL && *start != '\0') { start = strchr(start, ';'); if (!start) break; start = start+1; while (av_isspace(*start)) start++; if (!av_stristart(start, "boundary=", &start)) { end = strchr(start, ';'); if (end) len = end - start - 1; else len = strlen(start); res = av_strndup(start, len); break; } } av_freep(&mime_type); return res; }
void rtsp_parse_line(RTSPHeader *reply, const char *buf) { const char *p; /* NOTE: we do case independent match for broken servers */ p = buf; if (av_stristart(p, "Session:", &p)) { get_word_sep(reply->session_id, sizeof(reply->session_id), ";", &p); } else if (av_stristart(p, "Content-Length:", &p)) { reply->content_length = strtol(p, NULL, 10); } else if (av_stristart(p, "Transport:", &p)) { rtsp_parse_transport(reply, p); } else if (av_stristart(p, "CSeq:", &p)) { reply->seq = strtol(p, NULL, 10); } else if (av_stristart(p, "Range:", &p)) { rtsp_parse_range_npt(p, &reply->range_start, &reply->range_end); } }
char *av_stristr(const char *s1, const char *s2) { if (!*s2) return (char*)(intptr_t)s1; do { if (av_stristart(s1, s2, NULL)) return (char*)(intptr_t)s1; } while (*s1++); return NULL; }
char *av_stristr(const char *s1, const char *s2) { if (!*s2) return s1; do if (av_stristart(s1, s2, NULL)) return s1; while (*s1++); return NULL; }
/** Parse a string \p in the form of Range:npt=xx-xx, and determine the start * and end time. * Used for seeking in the rtp stream. */ static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end) { char buf[256]; skip_spaces(&p); if (!av_stristart(p, "npt=", &p)) return; *start = AV_NOPTS_VALUE; *end = AV_NOPTS_VALUE; get_word_sep(buf, sizeof(buf), "-", &p); *start = parse_date(buf, 1); if (*p == '-') { p++; get_word_sep(buf, sizeof(buf), "-", &p); *end = parse_date(buf, 1); } // av_log(NULL, AV_LOG_DEBUG, "Range Start: %lld\n", *start); // av_log(NULL, AV_LOG_DEBUG, "Range End: %lld\n", *end); }
/** * Identify if the stream as an AD binary stream */ static int adbinary_probe(AVProbeData *p) { int score = 0; unsigned char *dataPtr; uint32_t dataSize; int bufferSize = p->buf_size; uint8_t *bufPtr = p->buf; // Netvu protocol can only send adbinary or admime if ( (p->filename) && (av_stristart(p->filename, "netvu://", NULL) == 1)) score += AVPROBE_SCORE_MAX / 4; while ((bufferSize >= PKT_SEPARATOR_SIZE) && (score < AVPROBE_SCORE_MAX)) { dataSize = (bufPtr[PKT_SIZE_BYTE_0] << 24) + (bufPtr[PKT_SIZE_BYTE_1] << 16) + (bufPtr[PKT_SIZE_BYTE_2] << 8 ) + (bufPtr[PKT_SIZE_BYTE_3]); // Sanity check on dataSize if ((dataSize < 6) || (dataSize > 0x1000000)) return 0; // Maximum of 32 cameras can be connected to a system if (bufPtr[PKT_DATACHANNEL] > 32) return 0; dataPtr = &bufPtr[PKT_SEPARATOR_SIZE]; bufferSize -= PKT_SEPARATOR_SIZE; switch (bufPtr[PKT_DATATYPE]) { case AD_DATATYPE_JPEG: case AD_DATATYPE_MPEG4I: case AD_DATATYPE_MPEG4P: case AD_DATATYPE_H264I: case AD_DATATYPE_H264P: if (bufferSize >= NetVuImageDataHeaderSize) { struct NetVuImageData test; ad_network2host(&test, dataPtr); if (pic_version_valid(test.version)) { av_log(NULL, AV_LOG_DEBUG, "%s: Detected video packet\n", __func__); score += AVPROBE_SCORE_MAX; } } break; case AD_DATATYPE_JFIF: if (bufferSize >= 2) { if ( (*dataPtr == 0xFF) && (*(dataPtr + 1) == 0xD8) ) { av_log(NULL, AV_LOG_DEBUG, "%s: Detected JFIF packet\n", __func__); score += AVPROBE_SCORE_MAX; } } break; case AD_DATATYPE_AUDIO_ADPCM: if (bufferSize >= NetVuAudioDataHeaderSize) { struct NetVuAudioData test; audioheader_network2host(&test, dataPtr); if (test.version == AUD_VERSION) { av_log(NULL, AV_LOG_DEBUG, "%s: Detected audio packet\n", __func__); score += AVPROBE_SCORE_MAX; } } break; case AD_DATATYPE_AUDIO_RAW: // We don't handle this format av_log(NULL, AV_LOG_DEBUG, "%s: Detected raw audio packet (unsupported)\n", __func__); break; case AD_DATATYPE_MINIMAL_MPEG4: if (bufferSize >= 10) { uint32_t sec = AV_RB32(dataPtr); uint32_t vos = AV_RB32(dataPtr + 6); if (mpegOrH264(vos) == PIC_MODE_MPEG4_411) { // Check for MPEG4 start code in data along with a timestamp // of 1980 or later. Crappy test, but there isn't much data // to go on. Should be able to use milliseconds <= 1000 but // servers often send larger values than this, // nonsensical as that is if (sec > 315532800) { if ((vos >= 0x1B0) && (vos <= 0x1B6)) { av_log(NULL, AV_LOG_DEBUG, "%s: Detected minimal MPEG4 packet %u\n", __func__, dataSize); score += AVPROBE_SCORE_MAX / 4; } } break; } } // Servers can send h264 identified as MPEG4, so fall through // to next case //case(AD_DATATYPE_MINIMAL_H264): if (bufferSize >= 10) { uint32_t sec = AV_RB32(dataPtr); uint32_t vos = AV_RB32(dataPtr + 6); // Check for h264 start code in data along with a timestamp // of 1980 or later. Crappy test, but there isn't much data // to go on. Should be able to use milliseconds <= 1000 but // servers often send larger values than this, // nonsensical as that is if (sec > 315532800) { if (vos == 0x01) { av_log(NULL, AV_LOG_DEBUG, "%s: Detected minimal h264 packet %u\n", __func__, dataSize); score += AVPROBE_SCORE_MAX / 4; } } } break; case AD_DATATYPE_MINIMAL_AUDIO_ADPCM: if (bufferSize >= 8) { MinimalAudioHeader test; test.t = AV_RB32(dataPtr); test.ms = AV_RB16(dataPtr + 4); test.mode = AV_RB16(dataPtr + 6); switch(test.mode) { case RTP_PAYLOAD_TYPE_8000HZ_ADPCM: case RTP_PAYLOAD_TYPE_11025HZ_ADPCM: case RTP_PAYLOAD_TYPE_16000HZ_ADPCM: case RTP_PAYLOAD_TYPE_22050HZ_ADPCM: case RTP_PAYLOAD_TYPE_32000HZ_ADPCM: case RTP_PAYLOAD_TYPE_44100HZ_ADPCM: case RTP_PAYLOAD_TYPE_48000HZ_ADPCM: case RTP_PAYLOAD_TYPE_8000HZ_PCM: case RTP_PAYLOAD_TYPE_11025HZ_PCM: case RTP_PAYLOAD_TYPE_16000HZ_PCM: case RTP_PAYLOAD_TYPE_22050HZ_PCM: case RTP_PAYLOAD_TYPE_32000HZ_PCM: case RTP_PAYLOAD_TYPE_44100HZ_PCM: case RTP_PAYLOAD_TYPE_48000HZ_PCM: av_log(NULL, AV_LOG_DEBUG, "%s: Detected minimal audio packet\n", __func__); score += AVPROBE_SCORE_MAX / 4; } } break; case AD_DATATYPE_LAYOUT: av_log(NULL, AV_LOG_DEBUG, "%s: Detected layout packet\n", __func__); break; case AD_DATATYPE_INFO: if ( (bufferSize >= 1) && (dataPtr[0] == 0) || (dataPtr[0] == 1) ) { av_log(NULL, AV_LOG_DEBUG, "%s: Detected info packet (%d)\n", __func__, dataPtr[0]); if ((bufferSize >= 5) && (strncmp(&dataPtr[1], "SITE", 4) == 0)) score += AVPROBE_SCORE_MAX; else if ((bufferSize >= 15) && (strncmp(&dataPtr[1], "(JPEG)TARGSIZE", 14) == 0)) score += AVPROBE_SCORE_MAX; else score += 5; } break; case AD_DATATYPE_XML_INFO: if (bufferSize >= dataSize) { const char *infoString = "<infoList>"; int infoStringLen = strlen(infoString); if ( (infoStringLen <= dataSize) && (av_strncasecmp(dataPtr, infoString, infoStringLen) == 0) ) { av_log(NULL, AV_LOG_DEBUG, "%s: Detected xml info packet\n", __func__); score += AVPROBE_SCORE_MAX; } } break; case AD_DATATYPE_BMP: av_log(NULL, AV_LOG_DEBUG, "%s: Detected bmp packet\n", __func__); break; case AD_DATATYPE_PBM: if (bufferSize >= 3) { if ((dataPtr[0] == 'P') && (dataPtr[1] >= '1') && (dataPtr[1] <= '6')) { if (dataPtr[2] == 0x0A) { score += AVPROBE_SCORE_MAX; av_log(NULL, AV_LOG_DEBUG, "%s: Detected pbm packet\n", __func__); } } } break; case AD_DATATYPE_SVARS_INFO: if ( (bufferSize >= 1) && (dataPtr[0] == 0) || (dataPtr[0] == 1) ) { av_log(NULL, AV_LOG_DEBUG, "%s: Detected svars info packet (%d)\n", __func__, dataPtr[0]); score += 5; } break; default: av_log(NULL, AV_LOG_DEBUG, "%s: Detected unknown packet type\n", __func__); break; } if (dataSize <= bufferSize) { bufferSize -= dataSize; bufPtr = dataPtr + dataSize; } else { bufferSize = 0; bufPtr = p->buf; } } if (score > AVPROBE_SCORE_MAX) score = AVPROBE_SCORE_MAX; av_log(NULL, AV_LOG_DEBUG, "%s: Score %d\n", __func__, score); return score; }