chiark / gitweb /
gpg: Fix searching for mail addresses in keyrings.
[gnupg2.git] / dirmngr / http.h
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
5  *
6  * This file is part of GnuPG.
7  *
8  * This file is free software; you can redistribute it and/or modify
9  * it under the terms of either
10  *
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.
14  *
15  * or
16  *
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.
20  *
21  * or both in parallel, as here.
22  *
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.
27  *
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/>.
30  */
31 #ifndef GNUPG_COMMON_HTTP_H
32 #define GNUPG_COMMON_HTTP_H
33
34 #include <gpg-error.h>
35
36 struct uri_tuple_s
37 {
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. */
44 };
45 typedef struct uri_tuple_s *uri_tuple_t;
46
47 struct parsed_uri_s
48 {
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   unsigned int explicit_port :1; /* The port was explicitly specified.  */
57   char *auth;           /* username/password for basic auth.  */
58   char *host;           /* Host (converted to lowercase). */
59   unsigned short port;  /* Port (always set if the host is set). */
60   char *path;           /* Path. */
61   uri_tuple_t params;   /* ";xxxxx" */
62   uri_tuple_t query;    /* "?xxx=yyy" */
63   char buffer[1];       /* Buffer which holds a (modified) copy of the URI. */
64 };
65 typedef struct parsed_uri_s *parsed_uri_t;
66
67 struct uri_tuple_s *uri_query_lookup (parsed_uri_t uri, const char *key);
68
69 typedef enum
70   {
71     HTTP_REQ_GET  = 1,
72     HTTP_REQ_HEAD = 2,
73     HTTP_REQ_POST = 3,
74     HTTP_REQ_OPAQUE = 4  /* Internal use.  */
75   }
76 http_req_t;
77
78 /* We put the flag values into an enum, so that gdb can display them. */
79 enum
80   {
81     HTTP_FLAG_TRY_PROXY = 1,     /* Try to use a proxy.  */
82     HTTP_FLAG_SHUTDOWN = 2,      /* Close sending end after the request.  */
83     HTTP_FLAG_FORCE_TOR = 4,     /* Force a TOR connection.  */
84     HTTP_FLAG_LOG_RESP = 8,      /* Log the server response.  */
85     HTTP_FLAG_FORCE_TLS = 16,    /* Force the use of TLS.  */
86     HTTP_FLAG_IGNORE_CL = 32,    /* Ignore content-length.  */
87     HTTP_FLAG_IGNORE_IPv4 = 64,  /* Do not use IPv4.  */
88     HTTP_FLAG_IGNORE_IPv6 = 128, /* Do not use IPv6.  */
89     HTTP_FLAG_TRUST_DEF   = 256, /* Use the default CAs.  */
90     HTTP_FLAG_TRUST_SYS   = 512  /* Also use the system defined CAs.  */
91   };
92
93
94 struct http_session_s;
95 typedef struct http_session_s *http_session_t;
96
97 struct http_context_s;
98 typedef struct http_context_s *http_t;
99
100 void http_set_verbose (int verbose, int debug);
101
102 void http_register_tls_callback (gpg_error_t (*cb)(http_t,http_session_t,int));
103 void http_register_tls_ca (const char *fname);
104 void http_register_netactivity_cb (void (*cb)(void));
105
106
107 gpg_error_t http_session_new (http_session_t *r_session,
108                               const char *tls_priority,
109                               const char *intended_hostname,
110                               unsigned int flags);
111 http_session_t http_session_ref (http_session_t sess);
112 void http_session_release (http_session_t sess);
113
114 void http_session_set_log_cb (http_session_t sess,
115                               void (*cb)(http_session_t, gpg_error_t,
116                                          const char *,
117                                          const void **, size_t *));
118
119
120 gpg_error_t http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
121                             int no_scheme_check);
122
123 void http_release_parsed_uri (parsed_uri_t uri);
124
125 gpg_error_t http_raw_connect (http_t *r_hd,
126                               const char *server, unsigned short port,
127                               unsigned int flags, const char *srvtag);
128
129 gpg_error_t http_open (http_t *r_hd, http_req_t reqtype,
130                        const char *url,
131                        const char *httphost,
132                        const char *auth,
133                        unsigned int flags,
134                        const char *proxy,
135                        http_session_t session,
136                        const char *srvtag,
137                        strlist_t headers);
138
139 void http_start_data (http_t hd);
140
141 gpg_error_t http_wait_response (http_t hd);
142
143 void http_close (http_t hd, int keep_read_stream);
144
145 gpg_error_t http_open_document (http_t *r_hd,
146                                 const char *document,
147                                 const char *auth,
148                                 unsigned int flags,
149                                 const char *proxy,
150                                 http_session_t session,
151                                 const char *srvtag,
152                                 strlist_t headers);
153
154 estream_t http_get_read_ptr (http_t hd);
155 estream_t http_get_write_ptr (http_t hd);
156 unsigned int http_get_status_code (http_t hd);
157 const char *http_get_tls_info (http_t hd, const char *what);
158 const char *http_get_header (http_t hd, const char *name);
159 const char **http_get_header_names (http_t hd);
160 gpg_error_t http_verify_server_credentials (http_session_t sess);
161
162 char *http_escape_string (const char *string, const char *specials);
163 char *http_escape_data (const void *data, size_t datalen, const char *specials);
164
165
166 #endif /*GNUPG_COMMON_HTTP_H*/