gnupg/keyserver (ChangeLog curl-shim.c curl-shim.h)
cvs user dshaw
cvs at cvs.gnupg.org
Sun Apr 17 03:22:51 CEST 2005
Date: Sunday, April 17, 2005 @ 03:39:25
Author: dshaw
Path: /cvs/gnupg/gnupg/keyserver
Modified: ChangeLog curl-shim.c curl-shim.h
* curl-shim.h, curl-shim.c (handle_error, curl_easy_setopt,
curl_easy_perform): Add POST functionality to the curl shim.
-------------+
ChangeLog | 3 +
curl-shim.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++----------
curl-shim.h | 19 +++++++---
3 files changed, 110 insertions(+), 22 deletions(-)
Index: gnupg/keyserver/ChangeLog
diff -u gnupg/keyserver/ChangeLog:1.122 gnupg/keyserver/ChangeLog:1.123
--- gnupg/keyserver/ChangeLog:1.122 Sun Apr 17 00:21:28 2005
+++ gnupg/keyserver/ChangeLog Sun Apr 17 03:39:24 2005
@@ -1,5 +1,8 @@
2005-04-16 David Shaw <dshaw at jabberwocky.com>
+ * curl-shim.h, curl-shim.c (handle_error, curl_easy_setopt,
+ curl_easy_perform): Add POST functionality to the curl shim.
+
* curl-shim.h, curl-shim.c (curl_escape, curl_free): Emulate
curl_escape and curl_free.
Index: gnupg/keyserver/curl-shim.c
diff -u gnupg/keyserver/curl-shim.c:1.3 gnupg/keyserver/curl-shim.c:1.4
--- gnupg/keyserver/curl-shim.c:1.3 Sun Apr 17 00:21:28 2005
+++ gnupg/keyserver/curl-shim.c Sun Apr 17 03:39:24 2005
@@ -48,6 +48,10 @@
strcpy(curl->errorbuffer,"write error");
break;
+ case CURLE_HTTP_RETURNED_ERROR:
+ sprintf(curl->errorbuffer,"url returned error %u",curl->status);
+ break;
+
default:
strcpy(curl->errorbuffer,"generic error");
break;
@@ -103,6 +107,15 @@
case CURLOPT_PROXY:
curl->proxy=va_arg(ap,char *);
break;
+ case CURLOPT_POST:
+ curl->flags.post=va_arg(ap,unsigned int);
+ break;
+ case CURLOPT_POSTFIELDS:
+ curl->postfields=va_arg(ap,char *);
+ break;
+ case CURLOPT_FAILONERROR:
+ curl->flags.failonerror=va_arg(ap,unsigned int);
+ break;
default:
/* We ignore the huge majority of curl options */
break;
@@ -117,36 +130,97 @@
CURLcode err=CURLE_OK;
const char *errstr=NULL;
- rc=http_open_document(&curl->hd,curl->url,0,curl->proxy);
- if(rc!=0)
+ if(curl->flags.post)
{
- if(rc==G10ERR_NETWORK)
- errstr=strerror(errno);
+ rc=http_open(&curl->hd,HTTP_REQ_POST,curl->url,0,curl->proxy);
+ if(rc!=0)
+ {
+ if(rc==G10ERR_NETWORK)
+ errstr=strerror(errno);
+ else
+ errstr=g10_errstr(rc);
+
+ err=CURLE_COULDNT_CONNECT;
+ }
else
- errstr=g10_errstr(rc);
+ {
+ char content_len[50];
+ unsigned int post_len=strlen(curl->postfields);
- err=CURLE_COULDNT_CONNECT;
+ iobuf_writestr(curl->hd.fp_write,
+ "Content-Type: application/x-www-form-urlencoded\r\n");
+ sprintf(content_len,"Content-Length: %u\r\n",post_len);
+
+ iobuf_writestr(curl->hd.fp_write,content_len);
+
+ http_start_data(&curl->hd);
+ iobuf_write(curl->hd.fp_write,curl->postfields,post_len);
+ rc=http_wait_response(&curl->hd,&curl->status);
+ if(rc!=0)
+ {
+ 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;
+ }
}
else
{
- unsigned int maxlen=1024,buflen,len;
- byte *line=NULL;
+ rc=http_open(&curl->hd,HTTP_REQ_GET,curl->url,0,curl->proxy);
+ if(rc!=0)
+ {
+ if(rc==G10ERR_NETWORK)
+ errstr=strerror(errno);
+ else
+ errstr=g10_errstr(rc);
- while((len=iobuf_read_line(curl->hd.fp_read,&line,&buflen,&maxlen)))
+ err=CURLE_COULDNT_CONNECT;
+ }
+ else
{
- maxlen=1024;
- size_t ret;
+ rc=http_wait_response(&curl->hd,&curl->status);
+ if(rc)
+ {
+ http_close(&curl->hd);
- ret=(curl->writer)(line,len,1,curl->file);
- if(ret!=len)
+ if(rc==G10ERR_NETWORK)
+ errstr=strerror(errno);
+ else
+ errstr=g10_errstr(rc);
+
+ err=CURLE_COULDNT_CONNECT;
+ }
+ else if(curl->flags.failonerror && curl->status>=300)
+ err=CURLE_HTTP_RETURNED_ERROR;
+ else
{
- err=CURLE_WRITE_ERROR;
- break;
+ unsigned int maxlen=1024,buflen,len;
+ byte *line=NULL;
+
+ while((len=iobuf_read_line(curl->hd.fp_read,
+ &line,&buflen,&maxlen)))
+ {
+ maxlen=1024;
+ size_t ret;
+
+ ret=(curl->writer)(line,len,1,curl->file);
+ if(ret!=len)
+ {
+ err=CURLE_WRITE_ERROR;
+ break;
+ }
+ }
+
+ m_free(line);
+ http_close(&curl->hd);
}
}
-
- m_free(line);
- http_close(&curl->hd);
}
return handle_error(curl,err,errstr);
Index: gnupg/keyserver/curl-shim.h
diff -u gnupg/keyserver/curl-shim.h:1.3 gnupg/keyserver/curl-shim.h:1.4
--- gnupg/keyserver/curl-shim.h:1.3 Sun Apr 17 00:21:28 2005
+++ gnupg/keyserver/curl-shim.h Sun Apr 17 03:39:24 2005
@@ -26,9 +26,10 @@
typedef enum
{
CURLE_OK=0,
- CURLE_FTP_COULDNT_RETR_FILE,
- CURLE_COULDNT_CONNECT,
- CURLE_WRITE_ERROR
+ CURLE_COULDNT_CONNECT=7,
+ CURLE_FTP_COULDNT_RETR_FILE=19,
+ CURLE_HTTP_RETURNED_ERROR=22,
+ CURLE_WRITE_ERROR=23
} CURLcode;
typedef enum
@@ -43,7 +44,10 @@
CURLOPT_VERBOSE,
CURLOPT_SSL_VERIFYPEER,
CURLOPT_PROXY,
- CURLOPT_CAINFO
+ CURLOPT_CAINFO,
+ CURLOPT_POST,
+ CURLOPT_POSTFIELDS,
+ CURLOPT_FAILONERROR
} CURLoption;
typedef size_t (*write_func)(char *buffer,size_t size,
@@ -56,6 +60,13 @@
char *proxy;
write_func writer;
void *file;
+ char *postfields;
+ unsigned int status;
+ struct
+ {
+ unsigned int post:1;
+ unsigned int failonerror:1;
+ } flags;
struct http_context hd;
} CURL;
More information about the Gnupg-commits
mailing list