aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2005-04-16 22:21:28 +0000
committerDavid Shaw <[email protected]>2005-04-16 22:21:28 +0000
commitd8e1f7656bac0d65e62c3aac62171fee5da30078 (patch)
tree2542a3694efd25df68c8b03101b0f15aaac3c17f
parent* gpgkeys_curl.c (main): If the http-proxy option is given without any (diff)
downloadgnupg-d8e1f7656bac0d65e62c3aac62171fee5da30078.tar.gz
gnupg-d8e1f7656bac0d65e62c3aac62171fee5da30078.zip
* curl-shim.h, curl-shim.c (curl_escape, curl_free): Emulate
curl_escape and curl_free.
-rw-r--r--keyserver/ChangeLog3
-rw-r--r--keyserver/curl-shim.c61
-rw-r--r--keyserver/curl-shim.h2
3 files changed, 66 insertions, 0 deletions
diff --git a/keyserver/ChangeLog b/keyserver/ChangeLog
index 2a9fa0c10..84eec3ae5 100644
--- a/keyserver/ChangeLog
+++ b/keyserver/ChangeLog
@@ -1,5 +1,8 @@
2005-04-16 David Shaw <[email protected]>
+ * curl-shim.h, curl-shim.c (curl_escape, curl_free): Emulate
+ curl_escape and curl_free.
+
* gpgkeys_curl.c (main): If the http-proxy option is given without
any arguments, try to get the proxy from the environment.
diff --git a/keyserver/curl-shim.c b/keyserver/curl-shim.c
index 088d65fc2..f9ef61aa0 100644
--- a/keyserver/curl-shim.c
+++ b/keyserver/curl-shim.c
@@ -151,3 +151,64 @@ CURLcode curl_easy_perform(CURL *curl)
return handle_error(curl,err,errstr);
}
+
+/* This is not the same exact set that is allowed according to
+ RFC-2396, but it is what the real curl uses. */
+#define VALID_URI_CHARS "abcdefghijklmnopqrstuvwxyz" \
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
+ "0123456789"
+
+char *curl_escape(char *str,int length)
+{
+ int len,max,idx,enc_idx=0;
+ char *enc;
+
+ if(length)
+ len=length;
+ else
+ len=strlen(str);
+
+ enc=malloc(len+1);
+ if(!enc)
+ return enc;
+
+ max=len;
+
+ for(idx=0;idx<len;idx++)
+ {
+ if(enc_idx+3>max)
+ {
+ char *tmp;
+
+ max+=100;
+
+ tmp=realloc(enc,max+1);
+ if(!tmp)
+ {
+ free(enc);
+ return NULL;
+ }
+
+ enc=tmp;
+ }
+
+ if(strchr(VALID_URI_CHARS,str[idx]))
+ enc[enc_idx++]=str[idx];
+ else
+ {
+ char numbuf[5];
+ sprintf(numbuf,"%%%02X",str[idx]);
+ strcpy(&enc[enc_idx],numbuf);
+ enc_idx+=3;
+ }
+ }
+
+ enc[enc_idx]='\0';
+
+ return enc;
+}
+
+void curl_free(char *ptr)
+{
+ free(ptr);
+}
diff --git a/keyserver/curl-shim.h b/keyserver/curl-shim.h
index 906d4345c..dc3d959bd 100644
--- a/keyserver/curl-shim.h
+++ b/keyserver/curl-shim.h
@@ -68,5 +68,7 @@ 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);
+char *curl_escape(char *str,int len);
+void curl_free(char *ptr);
#endif /* !_CURL_SHIM_H_ */