This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch master in repository ffmpeg.
commit d3d2e7f1f691b8ac06062e37b826dc673a7a864e Author: Romain Beauxis <[email protected]> AuthorDate: Fri Aug 21 08:27:16 2026 -0500 Commit: Romain Beauxis <[email protected]> CommitDate: Thu Aug 27 13:43:01 2026 +0000 avformat/http: split the response status line parser out of process_line Makes the parser reachable from a test program. No functional change, beyond checking the allocation of the exported version string. --- libavformat/http.c | 55 ++++++++++++++++++++++++++++++++++++++++-------------- libavformat/http.h | 21 +++++++++++++++++++++ 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index 69d4c8ab72..50fd88970d 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -890,6 +890,34 @@ static int http_get_line(HTTPContext *s, char *line, int line_size) } } +int ff_http_parse_status_line(void *logctx, const char *line, HTTPStatusLine *st) +{ + const char *p = line; + char *end; + + memset(st, 0, sizeof(*st)); + + if (av_strncasecmp(p, "HTTP/1.0", 8) == 0) + st->willclose = 1; + + while (*p != '/' && *p != '\0') + p++; + while (*p == '/') + p++; + av_strlcpy(st->version, p, sizeof(st->version)); + + while (!av_isspace(*p) && *p != '\0') + p++; + while (av_isspace(*p)) + p++; + st->code = strtol(p, &end, 10); + st->reason = end; + + av_log(logctx, AV_LOG_TRACE, "http_code=%d\n", st->code); + + return 0; +} + static int check_http_code(URLContext *h, int http_code, const char *end) { HTTPContext *s = h->priv_data; @@ -1181,7 +1209,7 @@ static int process_line(URLContext *h, char *line, int line_count, int *parsed_h { HTTPContext *s = h->priv_data; const char *auto_method = h->flags & AVIO_FLAG_READ ? "POST" : "GET"; - char *tag, *p, *end, *method, *resource, *version; + char *tag, *p, *method, *resource, *version; int ret; /* end of header */ @@ -1245,25 +1273,24 @@ static int process_line(URLContext *h, char *line, int line_count, int *parsed_h } av_log(h, AV_LOG_TRACE, "HTTP version string: %s\n", version); } else { - if (av_strncasecmp(p, "HTTP/1.0", 8) == 0) + HTTPStatusLine st; + + if ((ret = ff_http_parse_status_line(h, p, &st)) < 0) + return ret; + + /* Only ever set: a keep-alive decision made earlier must survive. */ + if (st.willclose) s->willclose = 1; - while (*p != '/' && *p != '\0') - p++; - while (*p == '/') - p++; + av_freep(&s->http_version); - s->http_version = av_strndup(p, 3); - while (!av_isspace(*p) && *p != '\0') - p++; - while (av_isspace(*p)) - p++; - s->http_code = strtol(p, &end, 10); + if (!(s->http_version = av_strdup(st.version))) + return AVERROR(ENOMEM); - av_log(h, AV_LOG_TRACE, "http_code=%d\n", s->http_code); + s->http_code = st.code; *parsed_http_code = 1; - if ((ret = check_http_code(h, s->http_code, end)) < 0) + if ((ret = check_http_code(h, s->http_code, st.reason)) < 0) return ret; } } else { diff --git a/libavformat/http.h b/libavformat/http.h index 08605c8f91..dd2c15789e 100644 --- a/libavformat/http.h +++ b/libavformat/http.h @@ -27,6 +27,27 @@ #define HTTP_HEADERS_SIZE 4096 +/** + * Parsed form of a response status line. + */ +typedef struct HTTPStatusLine { + char version[4]; /**< protocol version, e.g. "1.1" */ + int code; /**< response status code */ + const char *reason; /**< reason phrase, points into the parsed line */ + int willclose; /**< the version implies the connection will close */ +} HTTPStatusLine; + +/** + * Parse the status line of an HTTP response. + * + * @param logctx context used for logging, may be NULL + * @param line NUL terminated status line, without its trailing CRLF + * @param st filled in with the parsed status line + * @return 0 on success, a negative AVERROR code on failure + */ +int ff_http_parse_status_line(void *logctx, const char *line, + HTTPStatusLine *st); + /** * Initialize the authentication state based on another HTTP URLContext. * This can be used to pre-initialize the authentication parameters if -- To stop receiving notification emails like this one, please contact [email protected]. _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
