Added http.c from 1.4.

Added support for estream and gnutls.
This commit is contained in:
Werner Koch 2006-08-11 11:04:38 +00:00
parent 8c21960251
commit 6c94373609
5 changed files with 1885 additions and 12 deletions

View File

@ -1,3 +1,22 @@
2006-08-11 Werner Koch <wk@g10code.com>
* http.c: Major internal changes to optionallly support GNUTLS and
ESTREAM.
(http_open): Move initialization of the stream ...
(send_request): .. here.
(http_register_tls_callback): New.
* estream.c (es_writen): Try to seek only is a seek function has
been registered.
2006-08-09 Werner Koch <wk@g10code.com>
* http.c, http.h: New. Taken from gnupg 1.4.5, merged with
changes done for the Dirmngr project (by g10 Code) and cleaned up
some stuff.
(make_header_line): New. Change all caller to make user of the new
* Makefile.am (libcommon_a_SOURCES): Added http.c and http.h.
2006-05-23 Werner Koch <wk@g10code.com>
* gettime.c (isotimestamp): New.

View File

@ -52,7 +52,8 @@ libcommon_a_SOURCES = \
dynload.h \
estream.c estream.h \
dns-cert.c dns-cert.h \
pka.c pka.h
pka.c pka.h \
http.c http.h
libsimple_pwquery_a_SOURCES = \

View File

@ -559,7 +559,7 @@ static es_cookie_io_functions_t estream_functions_mem =
es_func_mem_read,
es_func_mem_write,
es_func_mem_seek,
es_func_mem_destroy,
es_func_mem_destroy
};
/* Implementation of fd I/O. */
@ -1402,16 +1402,19 @@ es_writen (estream_t ES__RESTRICT stream,
if (! (stream->flags & ES_FLAG_WRITING))
{
/* Switching to writing mode -> discard input data and seek to
position at which reading has stopped. */
err = es_seek (stream, 0, SEEK_CUR, NULL);
if (err)
{
if (errno == ESPIPE)
err = 0;
else
goto out;
}
position at which reading has stopped. We can do this only
if a seek function has been registered. */
if (stream->intern->func_seek)
{
err = es_seek (stream, 0, SEEK_CUR, NULL);
if (err)
{
if (errno == ESPIPE)
err = 0;
else
goto out;
}
}
}
switch (stream->intern->strategy)

1729
common/http.c Normal file

File diff suppressed because it is too large Load Diff

121
common/http.h Normal file
View File

@ -0,0 +1,121 @@
/* http.h - HTTP protocol handler
* Copyright (C) 1999, 2000, 2001, 2003,
* 2006 Free Software Foundation, Inc.
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (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
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
#ifndef GNUPG_COMMON_HTTP_H
#define GNUPG_COMMON_HTTP_H
#include <gpg-error.h>
#ifdef HTTP_USE_ESTREAM
#include "estream.h"
#endif
struct uri_tuple_s {
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;
struct parsed_uri_s
{
/* All these pointers point into BUFFER; most stuff is not escaped. */
char *scheme; /* Pointer to the scheme string (lowercase). */
int use_tls; /* Whether TLS should be used. */
char *auth; /* username/password for basic auth */
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;
typedef enum
{
HTTP_REQ_GET = 1,
HTTP_REQ_HEAD = 2,
HTTP_REQ_POST = 3
}
http_req_t;
/* We put the flag values into an enum, so that gdb can display them. */
enum
{
HTTP_FLAG_TRY_PROXY = 1,
HTTP_FLAG_NO_SHUTDOWN = 2,
HTTP_FLAG_TRY_SRV = 4
};
struct http_context_s
{
int initialized;
unsigned int status_code;
int sock;
int in_data;
#ifdef HTTP_USE_ESTREAM
estream_t fp_read;
estream_t fp_write;
void *write_cookie;
#else /*!HTTP_USE_ESTREAM*/
FILE *fp_read;
FILE *fp_write;
#endif /*!HTTP_USE_ESTREAM*/
void *tls_context;
int is_http_0_9;
parsed_uri_t uri;
http_req_t req_type;
char *buffer; /* Line buffer. */
size_t buffer_size;
unsigned int flags;
};
typedef struct http_context_s *http_t;
void http_register_tls_callback (gpg_error_t (*cb) (http_t, void *, int));
gpg_error_t http_parse_uri (parsed_uri_t *ret_uri, const char *uri);
void http_release_parsed_uri (parsed_uri_t uri);
gpg_error_t http_open (http_t hd, http_req_t reqtype,
const char *url,
const char *auth,
unsigned int flags,
const char *proxy,
void *tls_context);
void http_start_data (http_t hd);
gpg_error_t http_wait_response (http_t hd, unsigned int *ret_status);
void http_close (http_t hd, int keep_read_stream);
gpg_error_t http_open_document (http_t hd,
const char *document,
const char *auth,
unsigned int flags,
const char *proxy,
void *tls_context);
#endif /*GNUPG_COMMON_HTTP_H*/