gnupg/keyserver (5 files)

cvs user dshaw cvs at cvs.gnupg.org
Fri Feb 11 18:55:03 CET 2005


    Date: Friday, February 11, 2005 @ 19:05:13
  Author: dshaw
    Path: /cvs/gnupg/gnupg/keyserver

   Added: curl-shim.c curl-shim.h
Modified: ChangeLog Makefile.am gpgkeys_curl.c

* curl-shim.h, curl-shim.c: New.  This is code to fake the curl API in
terms of the current HTTP iobuf API.

* gpgkeys_curl.c [FAKE_CURL], Makefile.am: If FAKE_CURL is set, link with
the iobuf code rather than libcurl.


----------------+
 ChangeLog      |    8 ++
 Makefile.am    |    7 ++
 curl-shim.c    |  153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 curl-shim.h    |   71 +++++++++++++++++++++++++
 gpgkeys_curl.c |    4 +
 5 files changed, 243 insertions(+)


Index: gnupg/keyserver/ChangeLog
diff -u gnupg/keyserver/ChangeLog:1.111 gnupg/keyserver/ChangeLog:1.112
--- gnupg/keyserver/ChangeLog:1.111	Sat Feb  5 16:04:59 2005
+++ gnupg/keyserver/ChangeLog	Fri Feb 11 19:05:13 2005
@@ -1,3 +1,11 @@
+2005-02-11  David Shaw  <dshaw at jabberwocky.com>
+
+	* curl-shim.h, curl-shim.c: New.  This is code to fake the curl
+	API in terms of the current HTTP iobuf API.
+
+	* gpgkeys_curl.c [FAKE_CURL], Makefile.am: If FAKE_CURL is set,
+	link with the iobuf code rather than libcurl.
+
 2005-02-05  David Shaw  <dshaw at jabberwocky.com>
 
 	* gpgkeys_finger.c (main), gpgkeys_hkp.c (main): Fix --version
Index: gnupg/keyserver/Makefile.am
diff -u gnupg/keyserver/Makefile.am:1.25 gnupg/keyserver/Makefile.am:1.26
--- gnupg/keyserver/Makefile.am:1.25	Tue Jan 18 05:24:52 2005
+++ gnupg/keyserver/Makefile.am	Fri Feb 11 19:05:13 2005
@@ -39,5 +39,12 @@
 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_finger_LDADD = ../util/libutil.a @NETLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
+
+if FAKE_CURL
+gpgkeys_curl_SOURCES += curl-shim.c curl-shim.h
+gpgkeys_curl_CPPFLAGS = -DFAKE_CURL
+gpgkeys_curl_LDADD = ../util/libutil.a @NETLIBS@ @SRVLIBS@ $(other_libs) @GETOPT@ @W32LIBS@
+else
 gpgkeys_curl_CPPFLAGS = @LIBCURL_CPPFLAGS@
 gpgkeys_curl_LDADD = @LIBCURL@ @GETOPT@
+endif
Index: gnupg/keyserver/curl-shim.c
diff -u /dev/null gnupg/keyserver/curl-shim.c:1.1
--- /dev/null	Fri Feb 11 19:05:13 2005
+++ gnupg/keyserver/curl-shim.c	Fri Feb 11 19:05:13 2005
@@ -0,0 +1,153 @@
+/* curl-shim.c - Implement a small subset of the curl API in terms of
+ * the iobuf HTTP API
+ *
+ * Copyright (C) 2005 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include <config.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include "http.h"
+#include "util.h"
+#include "curl-shim.h"
+
+static CURLcode handle_error(CURL *curl,CURLcode err,const char *str)
+{
+  if(curl->errorbuffer)
+    {
+      switch(err)
+	{
+	case CURLE_OK:
+	  strcpy(curl->errorbuffer,"okay");
+	  break;
+
+	case CURLE_COULDNT_CONNECT:
+	  strcpy(curl->errorbuffer,"couldn't connect");
+	  break;
+
+	case CURLE_WRITE_ERROR:
+	  strcpy(curl->errorbuffer,"write error");
+	  break;
+
+	default:
+	  strcpy(curl->errorbuffer,"generic error");
+	  break;
+	}
+
+      if(str && (strlen(curl->errorbuffer)+2+strlen(str)+1)<=CURL_ERROR_SIZE)
+	{
+	  strcat(curl->errorbuffer,": ");
+	  strcat(curl->errorbuffer,str);
+	}
+    }
+
+  return err;
+}
+
+CURLcode curl_global_init(long flags)
+{
+  return CURLE_OK;
+}
+
+void curl_global_cleanup(void) {}
+
+CURL *curl_easy_init(void)
+{
+  return calloc(1,sizeof(CURL));
+}
+
+void curl_easy_cleanup(CURL *curl)
+{
+  free(curl);
+}
+
+CURLcode curl_easy_setopt(CURL *curl,CURLoption option,...)
+{
+  va_list ap;
+
+  va_start(ap,option);
+
+  switch(option)
+    {
+    case CURLOPT_URL:
+      curl->url=va_arg(ap,char *);
+      break;
+    case CURLOPT_WRITEFUNCTION:
+      curl->writer=va_arg(ap,write_func);
+      break;
+    case CURLOPT_FILE:
+      curl->file=va_arg(ap,void *);
+      break;
+    case CURLOPT_ERRORBUFFER:
+      curl->errorbuffer=va_arg(ap,char *);
+      break;
+    case CURLOPT_PROXY:
+      curl->proxy=va_arg(ap,char *);
+      break;
+    default:
+      /* We ignore the huge majority of curl options */
+      break;
+    }
+
+  return handle_error(curl,CURLE_OK,NULL);
+}
+
+CURLcode curl_easy_perform(CURL *curl)
+{
+  int rc;
+  CURLcode err=CURLE_OK;
+  const char *errstr=NULL;
+
+  rc=http_open_document(&curl->hd,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
+    {
+      size_t 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);
+    }
+
+  return handle_error(curl,err,errstr);
+}
Index: gnupg/keyserver/curl-shim.h
diff -u /dev/null gnupg/keyserver/curl-shim.h:1.1
--- /dev/null	Fri Feb 11 19:05:13 2005
+++ gnupg/keyserver/curl-shim.h	Fri Feb 11 19:05:13 2005
@@ -0,0 +1,71 @@
+/* curl-shim.h
+ * Copyright (C) 2005 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef _CURL_SHIM_H_
+#define _CURL_SHIM_H_
+
+#include "http.h"
+
+typedef enum
+  {
+    CURLE_OK=0,
+    CURLE_FTP_COULDNT_RETR_FILE,
+    CURLE_COULDNT_CONNECT,
+    CURLE_WRITE_ERROR
+  } CURLcode;
+
+typedef enum
+  {
+    CURLOPT_URL,
+    CURLOPT_WRITEFUNCTION,
+    CURLOPT_FILE,
+    CURLOPT_ERRORBUFFER,
+    CURLOPT_FOLLOWLOCATION,
+    CURLOPT_MAXREDIRS,
+    CURLOPT_STDERR,
+    CURLOPT_VERBOSE,
+    CURLOPT_SSL_VERIFYPEER,
+    CURLOPT_PROXY
+  } CURLoption;
+
+typedef size_t (*write_func)(char *buffer,size_t size,
+			     size_t nitems,void *outstream);
+
+typedef struct
+{
+  char *url;
+  char *errorbuffer;
+  char *proxy;
+  write_func writer;
+  void *file;
+  struct http_context hd;
+} CURL;
+
+#define CURL_ERROR_SIZE 256
+#define CURL_GLOBAL_DEFAULT 0
+
+CURLcode curl_global_init(long flags);
+void curl_global_cleanup(void);
+CURL *curl_easy_init(void);
+CURLcode curl_easy_setopt(CURL *curl,CURLoption option,...);
+CURLcode curl_easy_perform(CURL *curl);
+void curl_easy_cleanup(CURL *curl);
+
+#endif /* !_CURL_SHIM_H_ */
Index: gnupg/keyserver/gpgkeys_curl.c
diff -u gnupg/keyserver/gpgkeys_curl.c:1.12 gnupg/keyserver/gpgkeys_curl.c:1.13
--- gnupg/keyserver/gpgkeys_curl.c:1.12	Sat Feb  5 16:04:59 2005
+++ gnupg/keyserver/gpgkeys_curl.c	Fri Feb 11 19:05:13 2005
@@ -27,7 +27,11 @@
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
+#ifdef FAKE_CURL
+#include "curl-shim.h"
+#else
 #include <curl/curl.h>
+#endif
 #include "keyserver.h"
 #include "ksutil.h"
 




More information about the Gnupg-commits mailing list