No more warnings for AMD64 (at least when cross-compiling). Thus tehre is a
[gnupg.git] / keyserver / curl-shim.c
index f4fdc0c..406e26e 100644 (file)
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <errno.h>
+
 #include "http.h"
 #include "util.h"
 #include "ksutil.h"
@@ -100,7 +101,11 @@ curl_easy_init(void)
 void
 curl_easy_cleanup(CURL *curl)
 {
-  free(curl);
+  if (curl)
+    {
+      http_close (curl->hd, 0);
+      free(curl);
+    }
 }
 
 CURLcode
@@ -177,42 +182,48 @@ curl_easy_perform(CURL *curl)
 
   if(curl->flags.post)
     {
-      rc=http_open(&curl->hd,HTTP_REQ_POST,curl->url,curl->auth,0,proxy);
-      if(rc==0)
+      rc = http_open (&curl->hd, HTTP_REQ_POST, curl->url, curl->auth,
+                      0, proxy, NULL);
+      if (!rc)
        {
-         char content_len[50];
-         unsigned int post_len=strlen(curl->postfields);
-
-         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 && curl->flags.failonerror && curl->status>=300)
-           err=CURLE_HTTP_RETURNED_ERROR;
+         unsigned int post_len = strlen(curl->postfields);
+
+         es_fprintf (http_get_write_ptr (curl->hd),
+                      "Content-Type: application/x-www-form-urlencoded\r\n"
+                      "Content-Length: %u\r\n", post_len);
+         http_start_data (curl->hd);
+         es_write (http_get_write_ptr (curl->hd),
+                    curl->postfields, post_len, NULL);
+
+         rc = http_wait_response (curl->hd);
+          curl->status = http_get_status_code (curl->hd);
+         if (!rc && curl->flags.failonerror && curl->status>=300)
+           err = CURLE_HTTP_RETURNED_ERROR;
+          http_close (curl->hd, 0);
+          curl->hd = NULL;
        }
     }
   else
     {
-      rc=http_open(&curl->hd,HTTP_REQ_GET,curl->url,curl->auth,0,proxy);
-      if(rc==0)
+      rc = http_open (&curl->hd, HTTP_REQ_GET, curl->url, curl->auth,
+                      0, proxy, NULL);
+      if (!rc)
        {
-         rc=http_wait_response(&curl->hd,&curl->status);
-         if(rc==0)
+         rc = http_wait_response (curl->hd);
+          curl->status = http_get_status_code (curl->hd);
+         if (!rc)
            {
-             if(curl->flags.failonerror && curl->status>=300)
-               err=CURLE_HTTP_RETURNED_ERROR;
+             if (curl->flags.failonerror && curl->status>=300)
+               err = CURLE_HTTP_RETURNED_ERROR;
              else
                {
-                 unsigned int maxlen=1024,buflen,len;
-                 byte *line=NULL;
+                 size_t maxlen = 1024;
+                  size_t buflen;
+                  unsigned int len;
+                 char *line = NULL;
 
-                 while((len=iobuf_read_line(curl->hd.fp_read,
-                                            &line,&buflen,&maxlen)))
+                 while ((len = es_read_line (http_get_read_ptr (curl->hd),
+                                              &line, &buflen, &maxlen)))
                    {
                      size_t ret;
 
@@ -226,31 +237,30 @@ curl_easy_perform(CURL *curl)
                        }
                    }
 
-                 xfree(line);
-                 http_close(&curl->hd);
+                 es_free (line);
+                 http_close(curl->hd, 0);
+                  curl->hd = NULL;
                }
            }
          else
-           http_close(&curl->hd);
+            {
+              http_close (curl->hd, 0);
+              curl->hd = NULL;
+            }
        }
     }
 
-  switch(rc)
+  switch(gpg_err_code (rc))
     {
     case 0:
       break;
 
-    case G10ERR_INVALID_URI:
+    case GPG_ERR_INV_URI:
       err=CURLE_UNSUPPORTED_PROTOCOL;
       break;
 
-    case G10ERR_NETWORK:
-      errstr=strerror(errno);
-      err=CURLE_COULDNT_CONNECT;
-      break;
-
     default:
-      errstr=g10_errstr(rc);
+      errstr=gpg_strerror (rc);
       err=CURLE_COULDNT_CONNECT;
       break;
     }
@@ -304,7 +314,7 @@ curl_escape(char *str,int length)
       else
        {
          char numbuf[5];
-         sprintf(numbuf,"%%%02X",(unsigned char)str[idx]);
+         sprintf(numbuf,"%%%02X",str[idx]);
          strcpy(&enc[enc_idx],numbuf);
          enc_idx+=3;
        }