Luke Huang | f71a722 | 2021-03-17 14:27:28 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | // This file is autogenerated by: |
| 18 | // cbindgen --config cbindgen.toml doh.rs >doh.h |
| 19 | // Don't modify manually. |
| 20 | |
| 21 | #pragma once |
| 22 | |
Luke Huang | fe45340 | 2021-06-24 03:15:03 +0800 | [diff] [blame] | 23 | /* Generated with cbindgen:0.17.0 */ |
Luke Huang | f71a722 | 2021-03-17 14:27:28 +0800 | [diff] [blame] | 24 | |
| 25 | #include <stdint.h> |
| 26 | #include <sys/types.h> |
| 27 | |
Luke Huang | fe45340 | 2021-06-24 03:15:03 +0800 | [diff] [blame] | 28 | /// The return code of doh_query means that there is no answer. |
| 29 | static const ssize_t RESULT_INTERNAL_ERROR = -1; |
| 30 | |
| 31 | /// The return code of doh_query means that query can't be sent. |
| 32 | static const ssize_t RESULT_CAN_NOT_SEND = -2; |
| 33 | |
| 34 | /// The return code of doh_query to indicate that the query timed out. |
| 35 | static const ssize_t RESULT_TIMEOUT = -255; |
| 36 | |
Luke Huang | 53d3eb2 | 2021-07-19 15:08:56 +0800 | [diff] [blame] | 37 | /// The error log level. |
| 38 | static const uint32_t LOG_LEVEL_ERROR = 0; |
| 39 | |
| 40 | /// The warning log level. |
| 41 | static const uint32_t LOG_LEVEL_WARN = 1; |
| 42 | |
| 43 | /// The info log level. |
| 44 | static const uint32_t LOG_LEVEL_INFO = 2; |
| 45 | |
| 46 | /// The debug log level. |
| 47 | static const uint32_t LOG_LEVEL_DEBUG = 3; |
| 48 | |
| 49 | /// The trace log level. |
| 50 | static const uint32_t LOG_LEVEL_TRACE = 4; |
| 51 | |
Luke Huang | fe45340 | 2021-06-24 03:15:03 +0800 | [diff] [blame] | 52 | /// Context for a running DoH engine. |
| 53 | struct DohDispatcher; |
| 54 | |
| 55 | using ValidationCallback = void (*)(uint32_t net_id, bool success, const char* ip_addr, |
| 56 | const char* host); |
Luke Huang | f71a722 | 2021-03-17 14:27:28 +0800 | [diff] [blame] | 57 | |
| 58 | extern "C" { |
| 59 | |
Luke Huang | 53d3eb2 | 2021-07-19 15:08:56 +0800 | [diff] [blame] | 60 | /// Performs static initialization for android logger. |
| 61 | void doh_init_logger(uint32_t level); |
| 62 | |
| 63 | /// Set the log level. |
| 64 | void doh_set_log_level(uint32_t level); |
| 65 | |
| 66 | /// Performs the initialization for the DoH engine. |
Luke Huang | f71a722 | 2021-03-17 14:27:28 +0800 | [diff] [blame] | 67 | /// Creates and returns a DoH engine instance. |
Luke Huang | fe45340 | 2021-06-24 03:15:03 +0800 | [diff] [blame] | 68 | DohDispatcher* doh_dispatcher_new(ValidationCallback ptr); |
Luke Huang | f71a722 | 2021-03-17 14:27:28 +0800 | [diff] [blame] | 69 | |
Luke Huang | fe45340 | 2021-06-24 03:15:03 +0800 | [diff] [blame] | 70 | /// Deletes a DoH engine created by doh_dispatcher_new(). |
| 71 | /// # Safety |
| 72 | /// `doh` must be a non-null pointer previously created by `doh_dispatcher_new()` |
| 73 | /// and not yet deleted by `doh_dispatcher_delete()`. |
| 74 | void doh_dispatcher_delete(DohDispatcher* doh); |
Luke Huang | f71a722 | 2021-03-17 14:27:28 +0800 | [diff] [blame] | 75 | |
Luke Huang | fe45340 | 2021-06-24 03:15:03 +0800 | [diff] [blame] | 76 | /// Probes and stores the DoH server with the given configurations. |
| 77 | /// Use the negative errno-style codes as the return value to represent the result. |
| 78 | /// # Safety |
| 79 | /// `doh` must be a non-null pointer previously created by `doh_dispatcher_new()` |
| 80 | /// and not yet deleted by `doh_dispatcher_delete()`. |
| 81 | /// `url`, `domain`, `ip_addr`, `cert_path` are null terminated strings. |
| 82 | int32_t doh_net_new(DohDispatcher* doh, uint32_t net_id, const char* url, const char* domain, |
| 83 | const char* ip_addr, uint32_t sk_mark, const char* cert_path, |
| 84 | uint64_t timeout_ms); |
| 85 | |
| 86 | /// Sends a DNS query via the network associated to the given |net_id| and waits for the response. |
| 87 | /// The return code should be either one of the public constant RESULT_* to indicate the error or |
| 88 | /// the size of the answer. |
| 89 | /// # Safety |
| 90 | /// `doh` must be a non-null pointer previously created by `doh_dispatcher_new()` |
| 91 | /// and not yet deleted by `doh_dispatcher_delete()`. |
| 92 | /// `dns_query` must point to a buffer at least `dns_query_len` in size. |
| 93 | /// `response` must point to a buffer at least `response_len` in size. |
| 94 | ssize_t doh_query(DohDispatcher* doh, uint32_t net_id, uint8_t* dns_query, size_t dns_query_len, |
| 95 | uint8_t* response, size_t response_len, uint64_t timeout_ms); |
| 96 | |
| 97 | /// Clears the DoH servers associated with the given |netid|. |
| 98 | /// # Safety |
| 99 | /// `doh` must be a non-null pointer previously created by `doh_dispatcher_new()` |
| 100 | /// and not yet deleted by `doh_dispatcher_delete()`. |
| 101 | void doh_net_delete(DohDispatcher* doh, uint32_t net_id); |
Luke Huang | f71a722 | 2021-03-17 14:27:28 +0800 | [diff] [blame] | 102 | |
| 103 | } // extern "C" |