comparison utils.c @ 6389:054de75e4a49 libavformat

Make parse_key_value from httpauth a common lavf internal function
author mstorsjo
date Thu, 19 Aug 2010 14:49:53 +0000
parents 4974b3d4992b
children 515e6aad6a82
comparison
equal deleted inserted replaced
6388:8ba781dd8b2b 6389:054de75e4a49
3705 src->streams[pkt->stream_index]->time_base, 3705 src->streams[pkt->stream_index]->time_base,
3706 dst->streams[dst_stream]->time_base); 3706 dst->streams[dst_stream]->time_base);
3707 return av_write_frame(dst, &local_pkt); 3707 return av_write_frame(dst, &local_pkt);
3708 } 3708 }
3709 3709
3710 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
3711 void *context)
3712 {
3713 const char *ptr = str;
3714
3715 /* Parse key=value pairs. */
3716 for (;;) {
3717 const char *key;
3718 char *dest = NULL, *dest_end;
3719 int key_len, dest_len = 0;
3720
3721 /* Skip whitespace and potential commas. */
3722 while (*ptr && (isspace(*ptr) || *ptr == ','))
3723 ptr++;
3724 if (!*ptr)
3725 break;
3726
3727 key = ptr;
3728
3729 if (!(ptr = strchr(key, '=')))
3730 break;
3731 ptr++;
3732 key_len = ptr - key;
3733
3734 callback_get_buf(context, key, key_len, &dest, &dest_len);
3735 dest_end = dest + dest_len - 1;
3736
3737 if (*ptr == '\"') {
3738 ptr++;
3739 while (*ptr && *ptr != '\"') {
3740 if (*ptr == '\\') {
3741 if (!ptr[1])
3742 break;
3743 if (dest && dest < dest_end)
3744 *dest++ = ptr[1];
3745 ptr += 2;
3746 } else {
3747 if (dest && dest < dest_end)
3748 *dest++ = *ptr;
3749 ptr++;
3750 }
3751 }
3752 if (*ptr == '\"')
3753 ptr++;
3754 } else {
3755 for (; *ptr && !(isspace(*ptr) || *ptr == ','); ptr++)
3756 if (dest && dest < dest_end)
3757 *dest++ = *ptr;
3758 }
3759 if (dest)
3760 *dest = 0;
3761 }
3762 }
3763