2006-08-11 11:04:38 +00:00
|
|
|
/* http.h - HTTP protocol handler
|
2010-07-16 13:19:45 +00:00
|
|
|
* Copyright (C) 1999, 2000, 2001, 2003, 2006,
|
|
|
|
* 2010 Free Software Foundation, Inc.
|
2011-02-04 12:57:53 +01:00
|
|
|
*
|
2006-08-11 11:04:38 +00:00
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-04 19:49:40 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2006-08-11 11:04:38 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-04 19:49:40 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2006-08-11 11:04:38 +00:00
|
|
|
*/
|
|
|
|
#ifndef GNUPG_COMMON_HTTP_H
|
2011-02-04 12:57:53 +01:00
|
|
|
#define GNUPG_COMMON_HTTP_H
|
2006-08-11 11:04:38 +00:00
|
|
|
|
|
|
|
#include <gpg-error.h>
|
2010-03-10 12:24:58 +00:00
|
|
|
#include "../common/estream.h"
|
2006-08-11 11:04:38 +00:00
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
struct uri_tuple_s
|
2011-01-10 14:30:17 +01:00
|
|
|
{
|
2006-08-11 11:04:38 +00:00
|
|
|
struct uri_tuple_s *next;
|
|
|
|
const char *name; /* A pointer into name. */
|
|
|
|
char *value; /* A pointer to value (a Nul is always appended). */
|
|
|
|
size_t valuelen; /* The real length of the value; we need it
|
|
|
|
because the value may contain embedded Nuls. */
|
|
|
|
int no_value; /* True if no value has been given in the URL. */
|
|
|
|
};
|
|
|
|
typedef struct uri_tuple_s *uri_tuple_t;
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
struct parsed_uri_s
|
2006-08-11 11:04:38 +00:00
|
|
|
{
|
|
|
|
/* All these pointers point into BUFFER; most stuff is not escaped. */
|
2011-01-10 14:30:17 +01:00
|
|
|
char *scheme; /* Pointer to the scheme string (always lowercase). */
|
|
|
|
unsigned int is_http:1; /* This is a HTTP style URI. */
|
|
|
|
unsigned int use_tls:1; /* Whether TLS should be used. */
|
2011-02-08 21:11:19 +01:00
|
|
|
unsigned int opaque:1;/* Unknown scheme; PATH has the rest. */
|
|
|
|
char *auth; /* username/password for basic auth. */
|
2006-08-11 11:04:38 +00:00
|
|
|
char *host; /* Host (converted to lowercase). */
|
|
|
|
unsigned short port; /* Port (always set if the host is set). */
|
|
|
|
char *path; /* Path. */
|
|
|
|
uri_tuple_t params; /* ";xxxxx" */
|
|
|
|
uri_tuple_t query; /* "?xxx=yyy" */
|
|
|
|
char buffer[1]; /* Buffer which holds a (modified) copy of the URI. */
|
|
|
|
};
|
|
|
|
typedef struct parsed_uri_s *parsed_uri_t;
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
typedef enum
|
2006-08-11 11:04:38 +00:00
|
|
|
{
|
|
|
|
HTTP_REQ_GET = 1,
|
|
|
|
HTTP_REQ_HEAD = 2,
|
2011-02-08 21:11:19 +01:00
|
|
|
HTTP_REQ_POST = 3,
|
|
|
|
HTTP_REQ_OPAQUE = 4 /* Internal use. */
|
2011-02-04 12:57:53 +01:00
|
|
|
}
|
2006-08-11 11:04:38 +00:00
|
|
|
http_req_t;
|
|
|
|
|
|
|
|
/* We put the flag values into an enum, so that gdb can display them. */
|
|
|
|
enum
|
2011-02-04 12:57:53 +01:00
|
|
|
{
|
2006-08-11 11:04:38 +00:00
|
|
|
HTTP_FLAG_TRY_PROXY = 1,
|
2010-07-16 13:19:45 +00:00
|
|
|
HTTP_FLAG_SHUTDOWN = 2,
|
|
|
|
HTTP_FLAG_LOG_RESP = 8,
|
|
|
|
HTTP_FLAG_IGNORE_CL = 32
|
2006-08-11 11:04:38 +00:00
|
|
|
};
|
|
|
|
|
2006-08-14 14:40:07 +00:00
|
|
|
struct http_context_s;
|
2006-08-11 11:04:38 +00:00
|
|
|
typedef struct http_context_s *http_t;
|
|
|
|
|
|
|
|
void http_register_tls_callback (gpg_error_t (*cb) (http_t, void *, int));
|
|
|
|
|
2010-08-06 13:52:01 +00:00
|
|
|
gpg_error_t _http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
2011-01-10 14:30:17 +01:00
|
|
|
int no_scheme_check, gpg_err_source_t errsource);
|
|
|
|
#define http_parse_uri(a,b,c) \
|
|
|
|
_http_parse_uri ((a), (b), (c), GPG_ERR_SOURCE_DEFAULT)
|
2006-08-11 11:04:38 +00:00
|
|
|
|
|
|
|
void http_release_parsed_uri (parsed_uri_t uri);
|
|
|
|
|
2011-02-08 21:11:19 +01:00
|
|
|
gpg_error_t _http_raw_connect (http_t *r_hd,
|
|
|
|
const char *server, unsigned short port,
|
|
|
|
unsigned int flags, const char *srvtag,
|
|
|
|
gpg_err_source_t errsource);
|
|
|
|
#define http_raw_connect(a,b,c,d,e) \
|
|
|
|
_http_raw_connect ((a),(b),(c),(d),(e), GPG_ERR_SOURCE_DEFAULT)
|
|
|
|
|
2010-08-06 13:52:01 +00:00
|
|
|
gpg_error_t _http_open (http_t *r_hd, http_req_t reqtype,
|
|
|
|
const char *url,
|
|
|
|
const char *auth,
|
|
|
|
unsigned int flags,
|
|
|
|
const char *proxy,
|
|
|
|
void *tls_context,
|
|
|
|
const char *srvtag,
|
|
|
|
strlist_t headers,
|
|
|
|
gpg_err_source_t errsource);
|
|
|
|
#define http_open(a,b,c,d,e,f,g,h,i) \
|
|
|
|
_http_open ((a),(b),(c),(d),(e),(f),(g),(h),(i), GPG_ERR_SOURCE_DEFAULT)
|
2006-08-11 11:04:38 +00:00
|
|
|
|
|
|
|
void http_start_data (http_t hd);
|
|
|
|
|
2010-08-06 13:52:01 +00:00
|
|
|
gpg_error_t _http_wait_response (http_t hd, gpg_err_source_t errsource);
|
|
|
|
#define http_wait_response(a) \
|
|
|
|
_http_wait_response ((a), GPG_ERR_SOURCE_DEFAULT)
|
2006-08-11 11:04:38 +00:00
|
|
|
|
|
|
|
void http_close (http_t hd, int keep_read_stream);
|
|
|
|
|
2010-08-06 13:52:01 +00:00
|
|
|
gpg_error_t _http_open_document (http_t *r_hd,
|
|
|
|
const char *document,
|
|
|
|
const char *auth,
|
|
|
|
unsigned int flags,
|
|
|
|
const char *proxy,
|
|
|
|
void *tls_context,
|
|
|
|
const char *srvtag,
|
|
|
|
strlist_t headers,
|
|
|
|
gpg_err_source_t errsource);
|
|
|
|
#define http_open_document(a,b,c,d,e,f,g,h) \
|
|
|
|
_http_open_document ((a),(b),(c),(d),(e),(f),(g),(h), GPG_ERR_SOURCE_DEFAULT)
|
2006-08-11 11:04:38 +00:00
|
|
|
|
2006-08-14 14:40:07 +00:00
|
|
|
estream_t http_get_read_ptr (http_t hd);
|
|
|
|
estream_t http_get_write_ptr (http_t hd);
|
|
|
|
unsigned int http_get_status_code (http_t hd);
|
2006-09-04 11:00:52 +00:00
|
|
|
const char *http_get_header (http_t hd, const char *name);
|
2006-08-14 14:40:07 +00:00
|
|
|
|
|
|
|
char *http_escape_string (const char *string, const char *specials);
|
2011-01-20 14:12:53 +01:00
|
|
|
char *http_escape_data (const void *data, size_t datalen, const char *specials);
|
2006-08-14 14:40:07 +00:00
|
|
|
|
|
|
|
|
2006-08-11 11:04:38 +00:00
|
|
|
#endif /*GNUPG_COMMON_HTTP_H*/
|