changeset 5007:1d5f8836c8a8 libavformat

Introduce http_get_line and modify http_connect to use http_get_line. Patch by Peter Holik <$firstname @ $lastname . at>
author jai_menon
date Sat, 06 Jun 2009 16:44:21 +0000
parents 686de8748c36
children 370160e040d9
files http.c
diffstat 1 files changed, 27 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/http.c	Sat Jun 06 09:35:15 2009 +0000
+++ b/http.c	Sat Jun 06 16:44:21 2009 +0000
@@ -151,6 +151,30 @@
     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 @@
                         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 @@
     }
 
     /* 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 @@
             if (err == 0)
                 break;
             s->line_count++;
-            q = line;
-        } else {
-            if ((q - line) < sizeof(line) - 1)
-                *q++ = ch;
-        }
     }
 
     return (off == s->off) ? 0 : -1;