1 /* http.h - HTTP protocol handler
2 * Copyright (C) 1999, 2000, 2001, 2003, 2006,
3 * 2010 Free Software Foundation, Inc.
4 * Copyright (C) 2015 g10 Code GmbH
6 * This file is part of GnuPG.
8 * This file is free software; you can redistribute it and/or modify
9 * it under the terms of either
11 * - the GNU Lesser General Public License as published by the Free
12 * Software Foundation; either version 3 of the License, or (at
13 * your option) any later version.
17 * - the GNU General Public License as published by the Free
18 * Software Foundation; either version 2 of the License, or (at
19 * your option) any later version.
21 * or both in parallel, as here.
23 * This file is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, see <https://www.gnu.org/licenses/>.
31 #ifndef GNUPG_COMMON_HTTP_H
32 #define GNUPG_COMMON_HTTP_H
34 #include <gpg-error.h>
38 struct uri_tuple_s *next;
39 const char *name; /* A pointer into name. */
40 char *value; /* A pointer to value (a Nul is always appended). */
41 size_t valuelen; /* The real length of the value; we need it
42 because the value may contain embedded Nuls. */
43 int no_value; /* True if no value has been given in the URL. */
45 typedef struct uri_tuple_s *uri_tuple_t;
49 /* All these pointers point into BUFFER; most stuff is not escaped. */
50 char *original; /* Unmodified copy of the parsed URI. */
51 char *scheme; /* Pointer to the scheme string (always lowercase). */
52 unsigned int is_http:1; /* This is a HTTP style URI. */
53 unsigned int use_tls:1; /* Whether TLS should be used. */
54 unsigned int opaque:1;/* Unknown scheme; PATH has the rest. */
55 unsigned int v6lit:1; /* Host was given as a literal v6 address. */
56 unsigned int onion:1; /* .onion address given. */
57 unsigned int explicit_port :1; /* The port was explicitly specified. */
58 char *auth; /* username/password for basic auth. */
59 char *host; /* Host (converted to lowercase). */
60 unsigned short port; /* Port (always set if the host is set). */
61 char *path; /* Path. */
62 uri_tuple_t params; /* ";xxxxx" */
63 uri_tuple_t query; /* "?xxx=yyy" */
64 char buffer[1]; /* Buffer which holds a (modified) copy of the URI. */
66 typedef struct parsed_uri_s *parsed_uri_t;
68 struct uri_tuple_s *uri_query_lookup (parsed_uri_t uri, const char *key);
75 HTTP_REQ_OPAQUE = 4 /* Internal use. */
79 /* We put the flag values into an enum, so that gdb can display them. */
82 HTTP_FLAG_TRY_PROXY = 1, /* Try to use a proxy. */
83 HTTP_FLAG_SHUTDOWN = 2, /* Close sending end after the request. */
84 HTTP_FLAG_FORCE_TOR = 4, /* Force a TOR connection. */
85 HTTP_FLAG_LOG_RESP = 8, /* Log the server response. */
86 HTTP_FLAG_FORCE_TLS = 16, /* Force the use of TLS. */
87 HTTP_FLAG_IGNORE_CL = 32, /* Ignore content-length. */
88 HTTP_FLAG_IGNORE_IPv4 = 64, /* Do not use IPv4. */
89 HTTP_FLAG_IGNORE_IPv6 = 128, /* Do not use IPv6. */
90 HTTP_FLAG_TRUST_DEF = 256, /* Use the CAs configured for HKP. */
91 HTTP_FLAG_TRUST_SYS = 512, /* Also use the system defined CAs. */
92 HTTP_FLAG_NO_CRL = 1024 /* Do not consult CRLs for https. */
96 struct http_session_s;
97 typedef struct http_session_s *http_session_t;
99 struct http_context_s;
100 typedef struct http_context_s *http_t;
102 /* A TLS verify callback function. */
103 typedef gpg_error_t (*http_verify_cb_t) (void *opaque,
105 http_session_t session,
109 void http_set_verbose (int verbose, int debug);
111 void http_register_tls_callback (gpg_error_t (*cb)(http_t,http_session_t,int));
112 void http_register_tls_ca (const char *fname);
113 void http_register_netactivity_cb (void (*cb)(void));
116 gpg_error_t http_session_new (http_session_t *r_session,
117 const char *intended_hostname,
121 http_session_t http_session_ref (http_session_t sess);
122 void http_session_release (http_session_t sess);
124 void http_session_set_log_cb (http_session_t sess,
125 void (*cb)(http_session_t, gpg_error_t,
127 const void **, size_t *));
128 void http_session_set_timeout (http_session_t sess, unsigned int timeout);
131 gpg_error_t http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
132 int no_scheme_check);
134 void http_release_parsed_uri (parsed_uri_t uri);
136 gpg_error_t http_raw_connect (http_t *r_hd,
137 const char *server, unsigned short port,
138 unsigned int flags, const char *srvtag,
139 unsigned int timeout);
141 gpg_error_t http_open (http_t *r_hd, http_req_t reqtype,
143 const char *httphost,
147 http_session_t session,
151 void http_start_data (http_t hd);
153 gpg_error_t http_wait_response (http_t hd);
155 void http_close (http_t hd, int keep_read_stream);
157 gpg_error_t http_open_document (http_t *r_hd,
158 const char *document,
162 http_session_t session,
166 estream_t http_get_read_ptr (http_t hd);
167 estream_t http_get_write_ptr (http_t hd);
168 unsigned int http_get_status_code (http_t hd);
169 const char *http_get_tls_info (http_t hd, const char *what);
170 const char *http_get_header (http_t hd, const char *name);
171 const char **http_get_header_names (http_t hd);
172 gpg_error_t http_verify_server_credentials (http_session_t sess);
174 char *http_escape_string (const char *string, const char *specials);
175 char *http_escape_data (const void *data, size_t datalen, const char *specials);
178 #endif /*GNUPG_COMMON_HTTP_H*/