summaryrefslogtreecommitdiff
path: root/libavformat/http.c
diff options
context:
space:
mode:
authorPeter Holik <peter@holik.at>2009-06-06 16:44:21 +0000
committerJai Menon <jmenon86@gmail.com>2009-06-06 16:44:21 +0000
commit682d49f4eaa310a4958287579473982010449f95 (patch)
treef442218b0e7714d5dd46565d54b4a95d068816fd /libavformat/http.c
parent3bbc46102b54f7ac7c764c03e8718331b577797d (diff)
Introduce http_get_line and modify http_connect to use http_get_line.
Patch by Peter Holik <$firstname @ $lastname . at> Originally committed as revision 19124 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/http.c')
-rw-r--r--libavformat/http.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index d904e7a1e8..f8c44ce7ae 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -151,6 +151,30 @@ static int http_getc(HTTPContext *s)
return *s->buf_ptr++;
}
+static int http_get_line(HTTPContext *s, char *line, int line_size)
+{
+ int ch;
+ char *q;
+
+ q = line;
+ for(;;) {
+ ch = http_getc(s);
+ if (ch < 0)
+ return AVERROR(EIO);
+ if (ch == '\n') {
+ /* process line */
+ if (q > line && q[-1] == '\r')
+ q--;
+ *q = '\0';
+
+ return 0;
+ } else {
+ if ((q - line) < line_size - 1)
+ *q++ = ch;
+ }
+ }
+}
+
static int process_line(URLContext *h, char *line, int line_count,
int *new_location)
{
@@ -209,8 +233,8 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
const char *auth, int *new_location)
{
HTTPContext *s = h->priv_data;
- int post, err, ch;
- char line[1024], *q;
+ int post, err;
+ char line[1024];
char *auth_b64;
int auth_b64_len = (strlen(auth) + 2) / 3 * 4 + 1;
int64_t off = s->off;
@@ -251,16 +275,9 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
}
/* wait for header */
- q = line;
for(;;) {
- ch = http_getc(s);
- if (ch < 0)
+ if (http_get_line(s, line, sizeof(line)) < 0)
return AVERROR(EIO);
- if (ch == '\n') {
- /* process line */
- if (q > line && q[-1] == '\r')
- q--;
- *q = '\0';
#ifdef DEBUG
printf("header='%s'\n", line);
#endif
@@ -270,11 +287,6 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
if (err == 0)
break;
s->line_count++;
- q = line;
- } else {
- if ((q - line) < sizeof(line) - 1)
- *q++ = ch;
- }
}
return (off == s->off) ? 0 : -1;