deadbeef | f137e97 | 2017-03-23 22:45:49 | [diff] [blame] | 1 | /* |
| 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 Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #ifndef RTC_BASE_HTTP_COMMON_H_ |
| 12 | #define RTC_BASE_HTTP_COMMON_H_ |
deadbeef | f137e97 | 2017-03-23 22:45:49 | [diff] [blame] | 13 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 14 | #include <string> |
deadbeef | f137e97 | 2017-03-23 22:45:49 | [diff] [blame] | 15 | |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 16 | #include "absl/strings/string_view.h" |
| 17 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 18 | namespace rtc { |
deadbeef | f137e97 | 2017-03-23 22:45:49 | [diff] [blame] | 19 | |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 20 | class CryptString; |
| 21 | class SocketAddress; |
| 22 | |
| 23 | ////////////////////////////////////////////////////////////////////// |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 24 | // Http Authentication |
| 25 | ////////////////////////////////////////////////////////////////////// |
| 26 | |
| 27 | struct HttpAuthContext { |
| 28 | std::string auth_method; |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 29 | HttpAuthContext(absl::string_view auth) : auth_method(auth) {} |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 30 | virtual ~HttpAuthContext() {} |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | enum 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 Bauch | 5b32f23 | 2018-03-07 19:02:26 | [diff] [blame] | 38 | // TODO(bugs.webrtc.org/8905): Change "response" to "ZeroOnFreeBuffer". |
Ali Tofigh | 2ab914c | 2022-04-13 10:55:15 | [diff] [blame] | 39 | HttpAuthResult HttpAuthenticate(absl::string_view challenge, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 40 | const SocketAddress& server, |
Ali Tofigh | 7fa9057 | 2022-03-17 14:47:49 | [diff] [blame] | 41 | absl::string_view method, |
| 42 | absl::string_view uri, |
| 43 | absl::string_view username, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 44 | const CryptString& password, |
| 45 | HttpAuthContext*& context, |
| 46 | std::string& response, |
| 47 | std::string& auth_method); |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 48 | |
| 49 | ////////////////////////////////////////////////////////////////////// |
| 50 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 51 | } // namespace rtc |
Henrik Kjellander | ec78f1c | 2017-06-29 05:52:50 | [diff] [blame] | 52 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 53 | #endif // RTC_BASE_HTTP_COMMON_H_ |