MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / ff_http_auth_create_response

Function ff_http_auth_create_response

libavformat/httpauth.c:240–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240char *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}

Callers 3

http_connectFunction · 0.85
http_proxy_openFunction · 0.85

Calls 6

ff_urldecodeFunction · 0.85
av_base64_encodeFunction · 0.85
av_strlcatFunction · 0.85
make_digest_authFunction · 0.85
av_mallocFunction · 0.50
av_freeFunction · 0.50

Tested by

no test coverage detected