* 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.
This commit is contained in:
David Shaw 2005-04-17 01:52:04 +00:00
parent f50e99ed7b
commit 5609f5eafd
4 changed files with 39 additions and 18 deletions

View File

@ -1,5 +1,9 @@
2005-04-16 David Shaw <dshaw@jabberwocky.com>
* 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.

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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_ */