[FFmpeg-cvslog] r24832 - in trunk/libavformat: httpauth.c internal.h utils.c

mstorsjo subversion
Thu Aug 19 16:49:53 CEST 2010


Author: mstorsjo
Date: Thu Aug 19 16:49:53 2010
New Revision: 24832

Log:
Make parse_key_value from httpauth a common lavf internal function

Modified:
   trunk/libavformat/httpauth.c
   trunk/libavformat/internal.h
   trunk/libavformat/utils.c

Modified: trunk/libavformat/httpauth.c
==============================================================================
--- trunk/libavformat/httpauth.c	Thu Aug 19 16:32:36 2010	(r24831)
+++ trunk/libavformat/httpauth.c	Thu Aug 19 16:49:53 2010	(r24832)
@@ -28,62 +28,6 @@
 #include "avformat.h"
 #include <ctype.h>
 
-static void parse_key_value(const char *params,
-                            void (*callback_get_buf)(HTTPAuthState *state,
-                            const char *key, int key_len,
-                            char **dest, int *dest_len), HTTPAuthState *state)
-{
-    const char *ptr = params;
-
-    /* Parse key=value pairs. */
-    for (;;) {
-        const char *key;
-        char *dest = NULL, *dest_end;
-        int key_len, dest_len = 0;
-
-        /* Skip whitespace and potential commas. */
-        while (*ptr && (isspace(*ptr) || *ptr == ','))
-            ptr++;
-        if (!*ptr)
-            break;
-
-        key = ptr;
-
-        if (!(ptr = strchr(key, '=')))
-            break;
-        ptr++;
-        key_len = ptr - key;
-
-        callback_get_buf(state, key, key_len, &dest, &dest_len);
-        dest_end = dest + dest_len - 1;
-
-        if (*ptr == '\"') {
-            ptr++;
-            while (*ptr && *ptr != '\"') {
-                if (*ptr == '\\') {
-                    if (!ptr[1])
-                        break;
-                    if (dest && dest < dest_end)
-                        *dest++ = ptr[1];
-                    ptr += 2;
-                } else {
-                    if (dest && dest < dest_end)
-                        *dest++ = *ptr;
-                    ptr++;
-                }
-            }
-            if (*ptr == '\"')
-                ptr++;
-        } else {
-            for (; *ptr && !(isspace(*ptr) || *ptr == ','); ptr++)
-                if (dest && dest < dest_end)
-                    *dest++ = *ptr;
-        }
-        if (dest)
-            *dest = 0;
-    }
-}
-
 static void handle_basic_params(HTTPAuthState *state, const char *key,
                                 int key_len, char **dest, int *dest_len)
 {
@@ -149,18 +93,21 @@ void ff_http_auth_handle_header(HTTPAuth
             state->auth_type <= HTTP_AUTH_BASIC) {
             state->auth_type = HTTP_AUTH_BASIC;
             state->realm[0] = 0;
-            parse_key_value(p, handle_basic_params, state);
+            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;
-            parse_key_value(p, handle_digest_params, state);
+            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));
         }
     } else if (!strcmp(key, "Authentication-Info")) {
-        parse_key_value(value, handle_digest_update, state);
+        ff_parse_key_value(value, (ff_parse_key_val_cb) handle_digest_update,
+                           state);
     }
 }
 

Modified: trunk/libavformat/internal.h
==============================================================================
--- trunk/libavformat/internal.h	Thu Aug 19 16:32:36 2010	(r24831)
+++ trunk/libavformat/internal.h	Thu Aug 19 16:49:53 2010	(r24832)
@@ -192,4 +192,28 @@ int ff_get_line(ByteIOContext *s, char *
 
 #define SPACE_CHARS " \t\r\n"
 
+/**
+ * Callback function type for ff_parse_key_value.
+ *
+ * @param key a pointer to the key
+ * @param key_len the number of bytes that belong to the key, including the '='
+ *                char
+ * @param dest return the destination pointer for the value in *dest, may
+ *             be null to ignore the value
+ * @param dest_len the length of the *dest buffer
+ */
+typedef void (*ff_parse_key_val_cb)(void *context, const char *key,
+                                    int key_len, char **dest, int *dest_len);
+/**
+ * Parse a string with comma-separated key=value pairs. The value strings
+ * may be quoted and may contain escaped characters within quoted strings.
+ *
+ * @param str the string to parse
+ * @param callback_get_buf function that returns where to store the
+ *                         unescaped value string.
+ * @param context the opaque context pointer to pass to callback_get_buf
+ */
+void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
+                        void *context);
+
 #endif /* AVFORMAT_INTERNAL_H */

Modified: trunk/libavformat/utils.c
==============================================================================
--- trunk/libavformat/utils.c	Thu Aug 19 16:32:36 2010	(r24831)
+++ trunk/libavformat/utils.c	Thu Aug 19 16:49:53 2010	(r24832)
@@ -3707,3 +3707,57 @@ int ff_write_chained(AVFormatContext *ds
     return av_write_frame(dst, &local_pkt);
 }
 
+void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
+                        void *context)
+{
+    const char *ptr = str;
+
+    /* Parse key=value pairs. */
+    for (;;) {
+        const char *key;
+        char *dest = NULL, *dest_end;
+        int key_len, dest_len = 0;
+
+        /* Skip whitespace and potential commas. */
+        while (*ptr && (isspace(*ptr) || *ptr == ','))
+            ptr++;
+        if (!*ptr)
+            break;
+
+        key = ptr;
+
+        if (!(ptr = strchr(key, '=')))
+            break;
+        ptr++;
+        key_len = ptr - key;
+
+        callback_get_buf(context, key, key_len, &dest, &dest_len);
+        dest_end = dest + dest_len - 1;
+
+        if (*ptr == '\"') {
+            ptr++;
+            while (*ptr && *ptr != '\"') {
+                if (*ptr == '\\') {
+                    if (!ptr[1])
+                        break;
+                    if (dest && dest < dest_end)
+                        *dest++ = ptr[1];
+                    ptr += 2;
+                } else {
+                    if (dest && dest < dest_end)
+                        *dest++ = *ptr;
+                    ptr++;
+                }
+            }
+            if (*ptr == '\"')
+                ptr++;
+        } else {
+            for (; *ptr && !(isspace(*ptr) || *ptr == ','); ptr++)
+                if (dest && dest < dest_end)
+                    *dest++ = *ptr;
+        }
+        if (dest)
+            *dest = 0;
+    }
+}
+



More information about the ffmpeg-cvslog mailing list