| 238 | } |
| 239 | |
| 240 | char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth, |
| 241 | const char *path, const char *method) |
| 242 | { |
| 243 | char *authstr = NULL; |
| 244 | |
| 245 | /* Clear the stale flag, we assume the auth is ok now. It is reset |
| 246 | * by the server headers if there's a new issue. */ |
| 247 | state->stale = 0; |
| 248 | if (!auth || !strchr(auth, ':')) |
| 249 | return NULL; |
| 250 | |
| 251 | if (state->auth_type == HTTP_AUTH_BASIC) { |
| 252 | int auth_b64_len, len; |
| 253 | char *ptr, *decoded_auth = ff_urldecode(auth, 0); |
| 254 | |
| 255 | if (!decoded_auth) |
| 256 | return NULL; |
| 257 | |
| 258 | auth_b64_len = AV_BASE64_SIZE(strlen(decoded_auth)); |
| 259 | len = auth_b64_len + 30; |
| 260 | |
| 261 | authstr = av_malloc(len); |
| 262 | if (!authstr) { |
| 263 | av_free(decoded_auth); |
| 264 | return NULL; |
| 265 | } |
| 266 | |
| 267 | snprintf(authstr, len, "Authorization: Basic "); |
| 268 | ptr = authstr + strlen(authstr); |
| 269 | av_base64_encode(ptr, auth_b64_len, decoded_auth, strlen(decoded_auth)); |
| 270 | av_strlcat(ptr, "\r\n", len - (ptr - authstr)); |
| 271 | av_free(decoded_auth); |
| 272 | } else if (state->auth_type == HTTP_AUTH_DIGEST) { |
| 273 | char *username = ff_urldecode(auth, 0), *password; |
| 274 | |
| 275 | if (!username) |
| 276 | return NULL; |
| 277 | |
| 278 | if ((password = strchr(username, ':'))) { |
| 279 | *password++ = 0; |
| 280 | authstr = make_digest_auth(state, username, password, path, method); |
| 281 | } |
| 282 | av_free(username); |
| 283 | } |
| 284 | return authstr; |
| 285 | } |
no test coverage detected