| OLD | NEW |
| 1 /* | 1 /* |
| 2 * HTTP authentication | 2 * HTTP authentication |
| 3 * Copyright (c) 2010 Martin Storsjo | 3 * Copyright (c) 2010 Martin Storsjo |
| 4 * | 4 * |
| 5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
| 6 * | 6 * |
| 7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 #include "httpauth.h" | 22 #include "httpauth.h" |
| 23 #include "libavutil/base64.h" | 23 #include "libavutil/base64.h" |
| 24 #include "libavutil/avstring.h" | 24 #include "libavutil/avstring.h" |
| 25 #include "internal.h" | 25 #include "internal.h" |
| 26 #include "libavutil/random_seed.h" | 26 #include "libavutil/random_seed.h" |
| 27 #include "libavutil/md5.h" | 27 #include "libavutil/md5.h" |
| 28 #include "avformat.h" | 28 #include "avformat.h" |
| 29 #include <ctype.h> | 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 static void handle_basic_params(HTTPAuthState *state, const char *key, | 31 static void handle_basic_params(HTTPAuthState *state, const char *key, |
| 88 int key_len, char **dest, int *dest_len) | 32 int key_len, char **dest, int *dest_len) |
| 89 { | 33 { |
| 90 if (!strncmp(key, "realm=", key_len)) { | 34 if (!strncmp(key, "realm=", key_len)) { |
| 91 *dest = state->realm; | 35 *dest = state->realm; |
| 92 *dest_len = sizeof(state->realm); | 36 *dest_len = sizeof(state->realm); |
| 93 } | 37 } |
| 94 } | 38 } |
| 95 | 39 |
| 96 static void handle_digest_params(HTTPAuthState *state, const char *key, | 40 static void handle_digest_params(HTTPAuthState *state, const char *key, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 86 |
| 143 void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, | 87 void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, |
| 144 const char *value) | 88 const char *value) |
| 145 { | 89 { |
| 146 if (!strcmp(key, "WWW-Authenticate")) { | 90 if (!strcmp(key, "WWW-Authenticate")) { |
| 147 const char *p; | 91 const char *p; |
| 148 if (av_stristart(value, "Basic ", &p) && | 92 if (av_stristart(value, "Basic ", &p) && |
| 149 state->auth_type <= HTTP_AUTH_BASIC) { | 93 state->auth_type <= HTTP_AUTH_BASIC) { |
| 150 state->auth_type = HTTP_AUTH_BASIC; | 94 state->auth_type = HTTP_AUTH_BASIC; |
| 151 state->realm[0] = 0; | 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 } else if (av_stristart(value, "Digest ", &p) && | 98 } else if (av_stristart(value, "Digest ", &p) && |
| 154 state->auth_type <= HTTP_AUTH_DIGEST) { | 99 state->auth_type <= HTTP_AUTH_DIGEST) { |
| 155 state->auth_type = HTTP_AUTH_DIGEST; | 100 state->auth_type = HTTP_AUTH_DIGEST; |
| 156 memset(&state->digest_params, 0, sizeof(DigestParams)); | 101 memset(&state->digest_params, 0, sizeof(DigestParams)); |
| 157 state->realm[0] = 0; | 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 choose_qop(state->digest_params.qop, | 105 choose_qop(state->digest_params.qop, |
| 160 sizeof(state->digest_params.qop)); | 106 sizeof(state->digest_params.qop)); |
| 161 } | 107 } |
| 162 } else if (!strcmp(key, "Authentication-Info")) { | 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 |
| 167 | 114 |
| 168 static void update_md5_strings(struct AVMD5 *md5ctx, ...) | 115 static void update_md5_strings(struct AVMD5 *md5ctx, ...) |
| 169 { | 116 { |
| 170 va_list vl; | 117 va_list vl; |
| 171 | 118 |
| 172 va_start(vl, md5ctx); | 119 va_start(vl, md5ctx); |
| 173 while (1) { | 120 while (1) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 259 |
| 313 if ((password = strchr(username, ':'))) { | 260 if ((password = strchr(username, ':'))) { |
| 314 *password++ = 0; | 261 *password++ = 0; |
| 315 authstr = make_digest_auth(state, username, password, path, method); | 262 authstr = make_digest_auth(state, username, password, path, method); |
| 316 } | 263 } |
| 317 av_free(username); | 264 av_free(username); |
| 318 } | 265 } |
| 319 return authstr; | 266 return authstr; |
| 320 } | 267 } |
| 321 | 268 |
| OLD | NEW |