| 286 | } |
| 287 | |
| 288 | char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth, |
| 289 | const char *path, const char *method) |
| 290 | { |
| 291 | char *authstr = NULL; |
| 292 | |
| 293 | if (!auth || !strchr(auth, ':')) |
| 294 | return NULL; |
| 295 | |
| 296 | if (state->auth_type == HTTP_AUTH_BASIC) { |
| 297 | int auth_b64_len = (strlen(auth) + 2) / 3 * 4 + 1; |
| 298 | int len = auth_b64_len + 30; |
| 299 | char *ptr; |
| 300 | authstr = av_malloc(len); |
| 301 | if (!authstr) |
| 302 | return NULL; |
| 303 | snprintf(authstr, len, "Authorization: Basic "); |
| 304 | ptr = authstr + strlen(authstr); |
| 305 | av_base64_encode(ptr, auth_b64_len, auth, strlen(auth)); |
| 306 | av_strlcat(ptr, "\r\n", len); |
| 307 | } else if (state->auth_type == HTTP_AUTH_DIGEST) { |
| 308 | char *username = av_strdup(auth), *password; |
| 309 | |
| 310 | if (!username) |
| 311 | return NULL; |
| 312 | |
| 313 | if ((password = strchr(username, ':'))) { |
| 314 | *password++ = 0; |
| 315 | authstr = make_digest_auth(state, username, password, path, method); |
| 316 | } |
| 317 | av_free(username); |
| 318 | } |
| 319 | return authstr; |
| 320 | } |
| 321 |
no test coverage detected