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 *scheme; /* Pointer to the scheme string (always lowercase). */
51 unsigned int is_http:1; /* This is a HTTP style URI. */
52 unsigned int use_tls:1; /* Whether TLS should be used. */
53 unsigned int opaque:1;/* Unknown scheme; PATH has the rest. */
54 unsigned int v6lit:1; /* Host was given as a literal v6 address. */
55 unsigned int onion:1; /* .onion address given. */
56 char *auth; /* username/password for basic auth. */
57 char *host; /* Host (converted to lowercase). */
58 unsigned short port; /* Port (always set if the host is set). */
59 char *path; /* Path. */
60 uri_tuple_t params; /* ";xxxxx" */
61 uri_tuple_t query; /* "?xxx=yyy" */
62 char buffer[1]; /* Buffer which holds a (modified) copy of the URI. */
64 typedef struct parsed_uri_s *parsed_uri_t;
66 struct uri_tuple_s *uri_query_lookup (parsed_uri_t uri, const char *key);
73 HTTP_REQ_OPAQUE = 4 /* Internal use. */
77 /* We put the flag values into an enum, so that gdb can display them. */
80 HTTP_FLAG_TRY_PROXY = 1, /* Try to use a proxy. */
81 HTTP_FLAG_SHUTDOWN = 2, /* Close sending end after the request. */
82 HTTP_FLAG_FORCE_TOR = 4, /* Force a TOR connection. */
83 HTTP_FLAG_LOG_RESP = 8, /* Log the server response. */
84 HTTP_FLAG_FORCE_TLS = 16, /* Force the use of TLS. */
85 HTTP_FLAG_IGNORE_CL = 32, /* Ignore content-length. */
86 HTTP_FLAG_IGNORE_IPv4 = 64, /* Do not use IPv4. */
87 HTTP_FLAG_IGNORE_IPv6 = 128, /* Do not use IPv6. */
88 HTTP_FLAG_TRUST_DEF = 256, /* Use the default CAs. */
89 HTTP_FLAG_TRUST_SYS = 512 /* Also use the system defined CAs. */
93 struct http_session_s;
94 typedef struct http_session_s *http_session_t;
96 struct http_context_s;
97 typedef struct http_context_s *http_t;
99 void http_register_tls_callback (gpg_error_t (*cb)(http_t,http_session_t,int));
100 void http_register_tls_ca (const char *fname);
101 void http_register_netactivity_cb (void (*cb)(void));
104 gpg_error_t http_session_new (http_session_t *r_session,
105 const char *tls_priority,
106 const char *intended_hostname,
108 http_session_t http_session_ref (http_session_t sess);
109 void http_session_release (http_session_t sess);
111 void http_session_set_log_cb (http_session_t sess,
112 void (*cb)(http_session_t, gpg_error_t,
114 const void **, size_t *));
117 gpg_error_t http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
118 int no_scheme_check);
120 void http_release_parsed_uri (parsed_uri_t uri);
122 gpg_error_t http_raw_connect (http_t *r_hd,
123 const char *server, unsigned short port,
124 unsigned int flags, const char *srvtag);
126 gpg_error_t http_open (http_t *r_hd, http_req_t reqtype,
128 const char *httphost,
132 http_session_t session,
136 void http_start_data (http_t hd);
138 gpg_error_t http_wait_response (http_t hd);
140 void http_close (http_t hd, int keep_read_stream);
142 gpg_error_t http_open_document (http_t *r_hd,
143 const char *document,
147 http_session_t session,
151 estream_t http_get_read_ptr (http_t hd);
152 estream_t http_get_write_ptr (http_t hd);
153 unsigned int http_get_status_code (http_t hd);
154 const char *http_get_tls_info (http_t hd, const char *what);
155 const char *http_get_header (http_t hd, const char *name);
156 const char **http_get_header_names (http_t hd);
157 gpg_error_t http_verify_server_credentials (http_session_t sess);
159 char *http_escape_string (const char *string, const char *specials);
160 char *http_escape_data (const void *data, size_t datalen, const char *specials);
163 #endif /*GNUPG_COMMON_HTTP_H*/