Revision f9c399c4 libavformat/httpauth.c

View differences:

libavformat/httpauth.c
28 28
#include "avformat.h"
29 29
#include <ctype.h>
30 30

  
31
static void parse_key_value(const char *params,
32
                            void (*callback_get_buf)(HTTPAuthState *state,
33
                            const char *key, int key_len,
34
                            char **dest, int *dest_len), HTTPAuthState *state)
35
{
36
    const char *ptr = params;
37

  
38
    /* Parse key=value pairs. */
39
    for (;;) {
40
        const char *key;
41
        char *dest = NULL, *dest_end;
42
        int key_len, dest_len = 0;
43

  
44
        /* Skip whitespace and potential commas. */
45
        while (*ptr && (isspace(*ptr) || *ptr == ','))
46
            ptr++;
47
        if (!*ptr)
48
            break;
49

  
50
        key = ptr;
51

  
52
        if (!(ptr = strchr(key, '=')))
53
            break;
54
        ptr++;
55
        key_len = ptr - key;
56

  
57
        callback_get_buf(state, key, key_len, &dest, &dest_len);
58
        dest_end = dest + dest_len - 1;
59

  
60
        if (*ptr == '\"') {
61
            ptr++;
62
            while (*ptr && *ptr != '\"') {
63
                if (*ptr == '\\') {
64
                    if (!ptr[1])
65
                        break;
66
                    if (dest && dest < dest_end)
67
                        *dest++ = ptr[1];
68
                    ptr += 2;
69
                } else {
70
                    if (dest && dest < dest_end)
71
                        *dest++ = *ptr;
72
                    ptr++;
73
                }
74
            }
75
            if (*ptr == '\"')
76
                ptr++;
77
        } else {
78
            for (; *ptr && !(isspace(*ptr) || *ptr == ','); ptr++)
79
                if (dest && dest < dest_end)
80
                    *dest++ = *ptr;
81
        }
82
        if (dest)
83
            *dest = 0;
84
    }
85
}
86

  
87 31
static void handle_basic_params(HTTPAuthState *state, const char *key,
88 32
                                int key_len, char **dest, int *dest_len)
89 33
{
......
149 93
            state->auth_type <= HTTP_AUTH_BASIC) {
150 94
            state->auth_type = HTTP_AUTH_BASIC;
151 95
            state->realm[0] = 0;
152
            parse_key_value(p, handle_basic_params, state);
96
            ff_parse_key_value(p, (ff_parse_key_val_cb) handle_basic_params,
97
                               state);
153 98
        } else if (av_stristart(value, "Digest ", &p) &&
154 99
                   state->auth_type <= HTTP_AUTH_DIGEST) {
155 100
            state->auth_type = HTTP_AUTH_DIGEST;
156 101
            memset(&state->digest_params, 0, sizeof(DigestParams));
157 102
            state->realm[0] = 0;
158
            parse_key_value(p, handle_digest_params, state);
103
            ff_parse_key_value(p, (ff_parse_key_val_cb) handle_digest_params,
104
                               state);
159 105
            choose_qop(state->digest_params.qop,
160 106
                       sizeof(state->digest_params.qop));
161 107
        }
162 108
    } else if (!strcmp(key, "Authentication-Info")) {
163
        parse_key_value(value, handle_digest_update, state);
109
        ff_parse_key_value(value, (ff_parse_key_val_cb) handle_digest_update,
110
                           state);
164 111
    }
165 112
}
166 113

  

Also available in: Unified diff