aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Shaw <[email protected]>2005-04-17 01:52:04 +0000
committerDavid Shaw <[email protected]>2005-04-17 01:52:04 +0000
commit5609f5eafdaee3d610a63854e1acc56cb1b1e3ea (patch)
tree7c302ab00f508538561fd87779bb9485b9e75339
parent* curl-shim.h, curl-shim.c (handle_error, curl_easy_setopt, (diff)
downloadgnupg-5609f5eafdaee3d610a63854e1acc56cb1b1e3ea.tar.gz
gnupg-5609f5eafdaee3d610a63854e1acc56cb1b1e3ea.zip
* 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 single session.
-rw-r--r--keyserver/ChangeLog4
-rw-r--r--keyserver/gpgkeys_curl.c6
-rw-r--r--keyserver/ksutil.c37
-rw-r--r--keyserver/ksutil.h10
4 files changed, 39 insertions, 18 deletions
diff --git a/keyserver/ChangeLog b/keyserver/ChangeLog
index ea3e20533..d38e7816f 100644
--- a/keyserver/ChangeLog
+++ b/keyserver/ChangeLog
@@ -1,5 +1,9 @@
2005-04-16 David Shaw <[email protected]>
+ * 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
+ single session.
+
* curl-shim.h, curl-shim.c (handle_error, curl_easy_setopt,
curl_easy_perform): Add POST functionality to the curl shim.
diff --git a/keyserver/gpgkeys_curl.c b/keyserver/gpgkeys_curl.c
index 1ec7a8ae6..c827253f6 100644
--- a/keyserver/gpgkeys_curl.c
+++ b/keyserver/gpgkeys_curl.c
@@ -48,6 +48,9 @@ get_key(char *getkey)
CURLcode res;
char errorbuffer[CURL_ERROR_SIZE];
char request[MAX_URL];
+ struct curl_writer_ctx ctx;
+
+ memset(&ctx,0,sizeof(ctx));
if(strncmp(getkey,"0x",2)==0)
getkey+=2;
@@ -62,7 +65,8 @@ get_key(char *getkey)
curl_easy_setopt(curl,CURLOPT_URL,request);
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,curl_writer);
- curl_easy_setopt(curl,CURLOPT_FILE,output);
+ ctx.stream=output;
+ curl_easy_setopt(curl,CURLOPT_FILE,&ctx);
curl_easy_setopt(curl,CURLOPT_ERRORBUFFER,errorbuffer);
res=curl_easy_perform(curl);
diff --git a/keyserver/ksutil.c b/keyserver/ksutil.c
index 490a83feb..141d31c82 100644
--- a/keyserver/ksutil.c
+++ b/keyserver/ksutil.c
@@ -329,39 +329,44 @@ curl_err_to_gpg_err(CURLcode error)
}
size_t
-curl_writer(const void *ptr,size_t size,size_t nmemb,void *stream)
+curl_writer(const void *ptr,size_t size,size_t nmemb,void *cw_ctx)
{
+ struct curl_writer_ctx *ctx=cw_ctx;
const char *buf=ptr;
size_t i;
- static int markeridx=0,begun=0,done=0;
- static const char *marker=BEGIN;
+
+ if(!ctx->initialized)
+ {
+ ctx->marker=BEGIN;
+ ctx->initialized=1;
+ }
/* scan the incoming data for our marker */
- for(i=0;!done && i<(size*nmemb);i++)
+ for(i=0;!ctx->done && i<(size*nmemb);i++)
{
- if(buf[i]==marker[markeridx])
+ if(buf[i]==ctx->marker[ctx->markeridx])
{
- markeridx++;
- if(marker[markeridx]=='\0')
+ ctx->markeridx++;
+ if(ctx->marker[ctx->markeridx]=='\0')
{
- if(begun)
- done=1;
+ if(ctx->begun)
+ ctx->done=1;
else
{
/* We've found the BEGIN marker, so now we're looking
for the END marker. */
- begun=1;
- marker=END;
- markeridx=0;
- fprintf(stream,BEGIN);
+ ctx->begun=1;
+ ctx->marker=END;
+ ctx->markeridx=0;
+ fprintf(ctx->stream,BEGIN);
continue;
}
}
}
else
- markeridx=0;
+ ctx->markeridx=0;
- if(begun)
+ if(ctx->begun)
{
/* Canonicalize CRLF to just LF by stripping CRs. This
actually makes sense, since on Unix-like machines LF is
@@ -372,7 +377,7 @@ curl_writer(const void *ptr,size_t size,size_t nmemb,void *stream)
the like. */
if(buf[i]!='\r')
- fputc(buf[i],stream);
+ fputc(buf[i],ctx->stream);
}
}
diff --git a/keyserver/ksutil.h b/keyserver/ksutil.h
index a859687d9..1b123922b 100644
--- a/keyserver/ksutil.h
+++ b/keyserver/ksutil.h
@@ -101,6 +101,14 @@ int parse_ks_options(char *line,struct ks_options *opt);
const char *ks_action_to_string(enum ks_action action);
void print_nocr(FILE *stream,const char *str);
int curl_err_to_gpg_err(CURLcode error);
-size_t curl_writer(const void *ptr,size_t size,size_t nmemb,void *stream);
+
+struct curl_writer_ctx
+{
+ int initialized,markeridx,begun,done;
+ const char *marker;
+ FILE *stream;
+};
+
+size_t curl_writer(const void *ptr,size_t size,size_t nmemb,void *cw_ctx);
#endif /* !_KSUTIL_H_ */