blob: d287bd5d7c657fd330d3b7ff1bfd545a146b898b [file] [log] [blame]
deadbeeff137e972017-03-23 15:45:49 -07001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef RTC_BASE_HTTP_COMMON_H_
12#define RTC_BASE_HTTP_COMMON_H_
deadbeeff137e972017-03-23 15:45:49 -070013
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020014#include <string>
deadbeeff137e972017-03-23 15:45:49 -070015
Ali Tofigh7fa90572022-03-17 15:47:49 +010016#include "absl/strings/string_view.h"
17
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020018namespace rtc {
deadbeeff137e972017-03-23 15:45:49 -070019
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020020class CryptString;
21class SocketAddress;
22
23//////////////////////////////////////////////////////////////////////
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020024// Http Authentication
25//////////////////////////////////////////////////////////////////////
26
27struct HttpAuthContext {
28 std::string auth_method;
Ali Tofigh7fa90572022-03-17 15:47:49 +010029 HttpAuthContext(absl::string_view auth) : auth_method(auth) {}
Yves Gerey665174f2018-06-19 15:03:05 +020030 virtual ~HttpAuthContext() {}
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020031};
32
33enum HttpAuthResult { HAR_RESPONSE, HAR_IGNORE, HAR_CREDENTIALS, HAR_ERROR };
34
35// 'context' is used by this function to record information between calls.
36// Start by passing a null pointer, then pass the same pointer each additional
37// call. When the authentication attempt is finished, delete the context.
Joachim Bauch5b32f232018-03-07 20:02:26 +010038// TODO(bugs.webrtc.org/8905): Change "response" to "ZeroOnFreeBuffer".
Yves Gerey665174f2018-06-19 15:03:05 +020039HttpAuthResult HttpAuthenticate(const char* challenge,
40 size_t len,
41 const SocketAddress& server,
Ali Tofigh7fa90572022-03-17 15:47:49 +010042 absl::string_view method,
43 absl::string_view uri,
44 absl::string_view username,
Yves Gerey665174f2018-06-19 15:03:05 +020045 const CryptString& password,
46 HttpAuthContext*& context,
47 std::string& response,
48 std::string& auth_method);
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020049
50//////////////////////////////////////////////////////////////////////
51
Yves Gerey665174f2018-06-19 15:03:05 +020052} // namespace rtc
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020053
Steve Anton10542f22019-01-11 09:11:00 -080054#endif // RTC_BASE_HTTP_COMMON_H_