1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-22 14:57:02 +01:00

* gpgkeys_hkp.c: New hkp handler that uses curl or curl-shim.

* Makefile.am: Build new gpgkeys_hkp.

* curl-shim.c (curl_easy_perform): Cleanup.
This commit is contained in:
David Shaw 2005-04-17 02:18:32 +00:00
parent 5609f5eafd
commit 0884653a13
4 changed files with 343 additions and 797 deletions

View File

@ -1,5 +1,11 @@
2005-04-16 David Shaw <dshaw@jabberwocky.com> 2005-04-16 David Shaw <dshaw@jabberwocky.com>
* gpgkeys_hkp.c: New hkp handler that uses curl or curl-shim.
* Makefile.am: Build new gpgkeys_hkp.
* curl-shim.c (curl_easy_perform): Cleanup.
* ksutil.h, ksutil.c (curl_writer), gpgkeys_curl.c (get_key): Pass * ksutil.h, ksutil.c (curl_writer), gpgkeys_curl.c (get_key): Pass
a context to curl_writer so we can support multiple fetches in a a context to curl_writer so we can support multiple fetches in a
single session. single session.

View File

@ -29,7 +29,7 @@ gpglibexec_SCRIPTS = @GPGKEYS_MAILTO@
noinst_SCRIPTS = gpgkeys_test noinst_SCRIPTS = gpgkeys_test
gpgkeys_ldap_SOURCES = gpgkeys_ldap.c ksutil.c ksutil.h gpgkeys_ldap_SOURCES = gpgkeys_ldap.c ksutil.c ksutil.h
gpgkeys_hkp_SOURCES = gpgkeys_hkp.c ksutil.c ksutil.h gpgkeys_hkp_SOURCES = ksutil.c ksutil.h
gpgkeys_http_SOURCES = gpgkeys_http.c ksutil.c ksutil.h gpgkeys_http_SOURCES = gpgkeys_http.c ksutil.c ksutil.h
gpgkeys_finger_SOURCES = gpgkeys_finger.c ksutil.c ksutil.h gpgkeys_finger_SOURCES = gpgkeys_finger.c ksutil.c ksutil.h
gpgkeys_curl_SOURCES = gpgkeys_curl.c ksutil.c ksutil.h gpgkeys_curl_SOURCES = gpgkeys_curl.c ksutil.c ksutil.h
@ -37,15 +37,25 @@ gpgkeys_curl_SOURCES = gpgkeys_curl.c ksutil.c ksutil.h
other_libs = $(LIBICONV) $(LIBINTL) $(CAPLIBS) other_libs = $(LIBICONV) $(LIBINTL) $(CAPLIBS)
gpgkeys_ldap_LDADD = ../util/libutil.a @LDAPLIBS@ @NETLIBS@ $(other_libs) @GETOPT@ @W32LIBS@ gpgkeys_ldap_LDADD = ../util/libutil.a @LDAPLIBS@ @NETLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
gpgkeys_hkp_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
gpgkeys_http_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@ gpgkeys_http_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
gpgkeys_finger_LDADD = ../util/libutil.a @NETLIBS@ $(other_libs) @GETOPT@ @W32LIBS@ gpgkeys_finger_LDADD = ../util/libutil.a @NETLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
if WITH_CURL
gpgkeys_hkp_SOURCES += gpgkeys_hkp.c
if FAKE_CURL if FAKE_CURL
gpgkeys_curl_SOURCES += curl-shim.c curl-shim.h gpgkeys_curl_SOURCES += curl-shim.c curl-shim.h
gpgkeys_curl_CPPFLAGS = -DFAKE_CURL gpgkeys_curl_CPPFLAGS = -DFAKE_CURL
gpgkeys_curl_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@ gpgkeys_curl_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
gpgkeys_hkp_SOURCES += curl-shim.c curl-shim.h
gpgkeys_hkp_CPPFLAGS = -DFAKE_CURL
gpgkeys_hkp_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
else else
gpgkeys_curl_CPPFLAGS = @LIBCURL_CPPFLAGS@ gpgkeys_curl_CPPFLAGS = @LIBCURL_CPPFLAGS@
gpgkeys_curl_LDADD = @LIBCURL@ @GETOPT@ gpgkeys_curl_LDADD = @LIBCURL@ @GETOPT@
gpgkeys_hkp_CPPFLAGS = @LIBCURL_CPPFLAGS@
gpgkeys_hkp_LDADD = @LIBCURL@ @GETOPT@
endif
else
gpgkeys_hkp_SOURCES += gpgkeys_oldhkp.c
gpgkeys_hkp_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
endif endif

View File

@ -30,10 +30,13 @@
#include "util.h" #include "util.h"
#include "curl-shim.h" #include "curl-shim.h"
static CURLcode handle_error(CURL *curl,CURLcode err,const char *str) static CURLcode
handle_error(CURL *curl,CURLcode err,const char *str)
{ {
if(curl->errorbuffer) if(curl->errorbuffer)
{ {
/* Make sure you never exceed CURL_ERROR_SIZE, currently set to
256 in curl-shim.h */
switch(err) switch(err)
{ {
case CURLE_OK: case CURLE_OK:
@ -67,24 +70,29 @@ static CURLcode handle_error(CURL *curl,CURLcode err,const char *str)
return err; return err;
} }
CURLcode curl_global_init(long flags) CURLcode
curl_global_init(long flags)
{ {
return CURLE_OK; return CURLE_OK;
} }
void curl_global_cleanup(void) {} void
curl_global_cleanup(void) {}
CURL *curl_easy_init(void) CURL *
curl_easy_init(void)
{ {
return calloc(1,sizeof(CURL)); return calloc(1,sizeof(CURL));
} }
void curl_easy_cleanup(CURL *curl) void
curl_easy_cleanup(CURL *curl)
{ {
free(curl); free(curl);
} }
CURLcode curl_easy_setopt(CURL *curl,CURLoption option,...) CURLcode
curl_easy_setopt(CURL *curl,CURLoption option,...)
{ {
va_list ap; va_list ap;
@ -124,7 +132,8 @@ CURLcode curl_easy_setopt(CURL *curl,CURLoption option,...)
return handle_error(curl,CURLE_OK,NULL); return handle_error(curl,CURLE_OK,NULL);
} }
CURLcode curl_easy_perform(CURL *curl) CURLcode
curl_easy_perform(CURL *curl)
{ {
int rc; int rc;
CURLcode err=CURLE_OK; CURLcode err=CURLE_OK;
@ -133,16 +142,7 @@ CURLcode curl_easy_perform(CURL *curl)
if(curl->flags.post) if(curl->flags.post)
{ {
rc=http_open(&curl->hd,HTTP_REQ_POST,curl->url,0,curl->proxy); rc=http_open(&curl->hd,HTTP_REQ_POST,curl->url,0,curl->proxy);
if(rc!=0) if(rc==0)
{
if(rc==G10ERR_NETWORK)
errstr=strerror(errno);
else
errstr=g10_errstr(rc);
err=CURLE_COULDNT_CONNECT;
}
else
{ {
char content_len[50]; char content_len[50];
unsigned int post_len=strlen(curl->postfields); unsigned int post_len=strlen(curl->postfields);
@ -156,73 +156,58 @@ CURLcode curl_easy_perform(CURL *curl)
http_start_data(&curl->hd); http_start_data(&curl->hd);
iobuf_write(curl->hd.fp_write,curl->postfields,post_len); iobuf_write(curl->hd.fp_write,curl->postfields,post_len);
rc=http_wait_response(&curl->hd,&curl->status); rc=http_wait_response(&curl->hd,&curl->status);
if(rc!=0) if(rc==0 && curl->flags.failonerror && curl->status>=300)
{
if(rc==G10ERR_NETWORK)
errstr=strerror(errno);
else
errstr=g10_errstr(rc);
err=CURLE_COULDNT_CONNECT;
}
if(curl->flags.failonerror && curl->status>=300)
err=CURLE_HTTP_RETURNED_ERROR; err=CURLE_HTTP_RETURNED_ERROR;
} }
} }
else else
{ {
rc=http_open(&curl->hd,HTTP_REQ_GET,curl->url,0,curl->proxy); rc=http_open(&curl->hd,HTTP_REQ_GET,curl->url,0,curl->proxy);
if(rc!=0) if(rc==0)
{
if(rc==G10ERR_NETWORK)
errstr=strerror(errno);
else
errstr=g10_errstr(rc);
err=CURLE_COULDNT_CONNECT;
}
else
{ {
rc=http_wait_response(&curl->hd,&curl->status); rc=http_wait_response(&curl->hd,&curl->status);
if(rc) if(rc==0)
{ {
http_close(&curl->hd); if(curl->flags.failonerror && curl->status>=300)
err=CURLE_HTTP_RETURNED_ERROR;
if(rc==G10ERR_NETWORK)
errstr=strerror(errno);
else else
errstr=g10_errstr(rc);
err=CURLE_COULDNT_CONNECT;
}
else if(curl->flags.failonerror && curl->status>=300)
err=CURLE_HTTP_RETURNED_ERROR;
else
{
unsigned int maxlen=1024,buflen,len;
byte *line=NULL;
while((len=iobuf_read_line(curl->hd.fp_read,
&line,&buflen,&maxlen)))
{ {
maxlen=1024; unsigned int maxlen=1024,buflen,len;
size_t ret; byte *line=NULL;
ret=(curl->writer)(line,len,1,curl->file); while((len=iobuf_read_line(curl->hd.fp_read,
if(ret!=len) &line,&buflen,&maxlen)))
{ {
err=CURLE_WRITE_ERROR; maxlen=1024;
break; size_t ret;
}
}
m_free(line); ret=(curl->writer)(line,len,1,curl->file);
http_close(&curl->hd); if(ret!=len)
{
err=CURLE_WRITE_ERROR;
break;
}
}
m_free(line);
http_close(&curl->hd);
}
} }
else
http_close(&curl->hd);
} }
} }
if(rc!=0)
{
if(rc==G10ERR_NETWORK)
errstr=strerror(errno);
else
errstr=g10_errstr(rc);
err=CURLE_COULDNT_CONNECT;
}
return handle_error(curl,err,errstr); return handle_error(curl,err,errstr);
} }
@ -232,7 +217,8 @@ CURLcode curl_easy_perform(CURL *curl)
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
"0123456789" "0123456789"
char *curl_escape(char *str,int length) char *
curl_escape(char *str,int length)
{ {
int len,max,idx,enc_idx=0; int len,max,idx,enc_idx=0;
char *enc; char *enc;
@ -282,7 +268,8 @@ char *curl_escape(char *str,int length)
return enc; return enc;
} }
void curl_free(char *ptr) void
curl_free(char *ptr)
{ {
free(ptr); free(ptr);
} }

File diff suppressed because it is too large Load Diff