summaryrefslogtreecommitdiff
path: root/libavformat/utils.c
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2010-08-19 14:49:53 +0000
committerMartin Storsjö <martin@martin.st>2010-08-19 14:49:53 +0000
commitf9c399c4fd85ac140ea3b81d0eeb649df29ade3d (patch)
treedf512bccb2887a264855827fbaa2bf4731ca8def /libavformat/utils.c
parent8d88402013acf73e2a0e70c6a36df793742fd4f5 (diff)
Make parse_key_value from httpauth a common lavf internal function
Originally committed as revision 24832 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r--libavformat/utils.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 3fe5eaf635..117179715c 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3707,3 +3707,57 @@ int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
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;
+ }
+}
+