1 /* http.h - HTTP protocol handler
2 * Copyright (C) 1999, 2000, 2001, 2003, 2006,
3 * 2010 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuPG is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef GNUPG_COMMON_HTTP_H
21 #define GNUPG_COMMON_HTTP_H
23 #include <gpg-error.h>
24 #include "../common/estream.h"
28 struct uri_tuple_s *next;
29 const char *name; /* A pointer into name. */
30 char *value; /* A pointer to value (a Nul is always appended). */
31 size_t valuelen; /* The real length of the value; we need it
32 because the value may contain embedded Nuls. */
33 int no_value; /* True if no value has been given in the URL. */
35 typedef struct uri_tuple_s *uri_tuple_t;
39 /* All these pointers point into BUFFER; most stuff is not escaped. */
40 char *scheme; /* Pointer to the scheme string (always lowercase). */
41 unsigned int is_http:1; /* This is a HTTP style URI. */
42 unsigned int use_tls:1; /* Whether TLS should be used. */
43 char *auth; /* username/password for basic auth */
44 char *host; /* Host (converted to lowercase). */
45 unsigned short port; /* Port (always set if the host is set). */
46 char *path; /* Path. */
47 uri_tuple_t params; /* ";xxxxx" */
48 uri_tuple_t query; /* "?xxx=yyy" */
49 char buffer[1]; /* Buffer which holds a (modified) copy of the URI. */
51 typedef struct parsed_uri_s *parsed_uri_t;
61 /* We put the flag values into an enum, so that gdb can display them. */
64 HTTP_FLAG_TRY_PROXY = 1,
65 HTTP_FLAG_SHUTDOWN = 2,
66 HTTP_FLAG_LOG_RESP = 8,
67 HTTP_FLAG_IGNORE_CL = 32
70 struct http_context_s;
71 typedef struct http_context_s *http_t;
73 void http_register_tls_callback (gpg_error_t (*cb) (http_t, void *, int));
75 gpg_error_t _http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
76 int no_scheme_check, gpg_err_source_t errsource);
77 #define http_parse_uri(a,b,c) \
78 _http_parse_uri ((a), (b), (c), GPG_ERR_SOURCE_DEFAULT)
80 void http_release_parsed_uri (parsed_uri_t uri);
82 gpg_error_t _http_open (http_t *r_hd, http_req_t reqtype,
90 gpg_err_source_t errsource);
91 #define http_open(a,b,c,d,e,f,g,h,i) \
92 _http_open ((a),(b),(c),(d),(e),(f),(g),(h),(i), GPG_ERR_SOURCE_DEFAULT)
94 void http_start_data (http_t hd);
96 gpg_error_t _http_wait_response (http_t hd, gpg_err_source_t errsource);
97 #define http_wait_response(a) \
98 _http_wait_response ((a), GPG_ERR_SOURCE_DEFAULT)
100 void http_close (http_t hd, int keep_read_stream);
102 gpg_error_t _http_open_document (http_t *r_hd,
103 const char *document,
110 gpg_err_source_t errsource);
111 #define http_open_document(a,b,c,d,e,f,g,h) \
112 _http_open_document ((a),(b),(c),(d),(e),(f),(g),(h), GPG_ERR_SOURCE_DEFAULT)
114 estream_t http_get_read_ptr (http_t hd);
115 estream_t http_get_write_ptr (http_t hd);
116 unsigned int http_get_status_code (http_t hd);
117 const char *http_get_header (http_t hd, const char *name);
119 char *http_escape_string (const char *string, const char *specials);
120 char *http_escape_data (const void *data, size_t datalen, const char *specials);
123 #endif /*GNUPG_COMMON_HTTP_H*/