blob: cf94a5d1b73d5e8b3a4dc092b6af8c9e150f0cfd [file] [log] [blame]
Luke Huangf71a7222021-03-17 14:27:28 +08001/*
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 Huangfe453402021-06-24 03:15:03 +080023/* Generated with cbindgen:0.17.0 */
Luke Huangf71a7222021-03-17 14:27:28 +080024
25#include <stdint.h>
26#include <sys/types.h>
27
Luke Huangfe453402021-06-24 03:15:03 +080028/// The return code of doh_query means that there is no answer.
29static const ssize_t RESULT_INTERNAL_ERROR = -1;
30
31/// The return code of doh_query means that query can't be sent.
32static const ssize_t RESULT_CAN_NOT_SEND = -2;
33
34/// The return code of doh_query to indicate that the query timed out.
35static const ssize_t RESULT_TIMEOUT = -255;
36
Luke Huang53d3eb22021-07-19 15:08:56 +080037/// The error log level.
38static const uint32_t LOG_LEVEL_ERROR = 0;
39
40/// The warning log level.
41static const uint32_t LOG_LEVEL_WARN = 1;
42
43/// The info log level.
44static const uint32_t LOG_LEVEL_INFO = 2;
45
46/// The debug log level.
47static const uint32_t LOG_LEVEL_DEBUG = 3;
48
49/// The trace log level.
50static const uint32_t LOG_LEVEL_TRACE = 4;
51
Luke Huangfe453402021-06-24 03:15:03 +080052/// Context for a running DoH engine.
53struct DohDispatcher;
54
55using ValidationCallback = void (*)(uint32_t net_id, bool success, const char* ip_addr,
56 const char* host);
Luke Huangf71a7222021-03-17 14:27:28 +080057
58extern "C" {
59
Luke Huang53d3eb22021-07-19 15:08:56 +080060/// Performs static initialization for android logger.
61void doh_init_logger(uint32_t level);
62
63/// Set the log level.
64void doh_set_log_level(uint32_t level);
65
66/// Performs the initialization for the DoH engine.
Luke Huangf71a7222021-03-17 14:27:28 +080067/// Creates and returns a DoH engine instance.
Luke Huangfe453402021-06-24 03:15:03 +080068DohDispatcher* doh_dispatcher_new(ValidationCallback ptr);
Luke Huangf71a7222021-03-17 14:27:28 +080069
Luke Huangfe453402021-06-24 03:15:03 +080070/// 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()`.
74void doh_dispatcher_delete(DohDispatcher* doh);
Luke Huangf71a7222021-03-17 14:27:28 +080075
Luke Huangfe453402021-06-24 03:15:03 +080076/// 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.
82int32_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.
94ssize_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()`.
101void doh_net_delete(DohDispatcher* doh, uint32_t net_id);
Luke Huangf71a7222021-03-17 14:27:28 +0800102
103} // extern "C"