re-indented to curl style

This commit is contained in:
Daniel Stenberg
2004-11-22 13:48:35 +00:00
parent b7a6b78e0c
commit 7f44713487

View File

@@ -4,9 +4,9 @@
This is a little program to demonstrate the usage of This is a little program to demonstrate the usage of
- an ssl initialisation callback setting a user key and trustbases - an ssl initialisation callback setting a user key and trustbases
coming from a pkcs12 file coming from a pkcs12 file
- using an ssl application callback to find a URI in the - using an ssl application callback to find a URI in the
certificate presented during ssl session establishment. certificate presented during ssl session establishment.
*/ */
@@ -95,38 +95,38 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
static char *curlx_usage[]={ static char *curlx_usage[]={
"usage: curlx args\n", "usage: curlx args\n",
" -p12 arg - tia file ", " -p12 arg - tia file ",
" -envpass arg - environement variable which content the tia private key password", " -envpass arg - environement variable which content the tia private key password",
" -out arg - output file (response)- default stdout", " -out arg - output file (response)- default stdout",
" -in arg - input file (request)- default stdin", " -in arg - input file (request)- default stdin",
" -connect arg - URL of the server for the connection ex: www.openevidenve.org", " -connect arg - URL of the server for the connection ex: www.openevidenve.org",
" -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query", " -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query",
" -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none", " -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none",
" -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping", " -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping",
NULL NULL
}; };
/* /*
./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS ./curlx -p12 psy.p12 -envpass XX -in request -verbose -accesstype AD_DVCS
-mimetype application/dvcs -acceptmime application/dvcs -out response -mimetype application/dvcs -acceptmime application/dvcs -out response
*/ */
/* This is a context that we pass to all callbacks */ /* This is a context that we pass to all callbacks */
typedef struct sslctxparm_st { typedef struct sslctxparm_st {
unsigned char * p12file ; unsigned char * p12file ;
const char * pst ; const char * pst ;
PKCS12 * p12 ; PKCS12 * p12 ;
EVP_PKEY * pkey ; EVP_PKEY * pkey ;
X509 * usercert ; X509 * usercert ;
STACK_OF(X509) * ca ; STACK_OF(X509) * ca ;
CURL * curl; CURL * curl;
BIO * errorbio; BIO * errorbio;
int accesstype ; int accesstype ;
int verbose; int verbose;
} sslctxparm; } sslctxparm;
@@ -134,33 +134,35 @@ typedef struct sslctxparm_st {
static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5) static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5)
{ {
char *tmp; char *tmp;
if(!ia5 || !ia5->length) return NULL; if(!ia5 || !ia5->length)
tmp = OPENSSL_malloc(ia5->length + 1); return NULL;
memcpy(tmp, ia5->data, ia5->length); tmp = OPENSSL_malloc(ia5->length + 1);
tmp[ia5->length] = 0; memcpy(tmp, ia5->data, ia5->length);
return tmp; tmp[ia5->length] = 0;
return tmp;
} }
/* A conveniance routine to get an access URI. */ /* A conveniance routine to get an access URI. */
static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) { static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) {
int i; int i;
STACK_OF(ACCESS_DESCRIPTION) * accessinfo ; STACK_OF(ACCESS_DESCRIPTION) * accessinfo ;
accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ; accessinfo = X509_get_ext_d2i(cert, extensiontype, NULL, NULL) ;
if (!sk_ACCESS_DESCRIPTION_num(accessinfo)) return NULL; if (!sk_ACCESS_DESCRIPTION_num(accessinfo))
for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) { return NULL;
ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i); for (i = 0; i < sk_ACCESS_DESCRIPTION_num(accessinfo); i++) {
if (OBJ_obj2nid(ad->method) == type) { ACCESS_DESCRIPTION * ad = sk_ACCESS_DESCRIPTION_value(accessinfo, i);
if (ad->location->type == GEN_URI) { if (OBJ_obj2nid(ad->method) == type) {
return i2s_ASN1_IA5STRING(ad->location->d.ia5); if (ad->location->type == GEN_URI) {
} return i2s_ASN1_IA5STRING(ad->location->d.ia5);
return NULL; }
} return NULL;
} }
return NULL; }
return NULL;
} }
/* This is an application verification call back, it does not /* This is an application verification call back, it does not
@@ -169,312 +171,336 @@ static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype)
the URL to be used in the POST. the URL to be used in the POST.
*/ */
static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg) { static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg)
sslctxparm * p = (sslctxparm *) arg; {
int ok; sslctxparm * p = (sslctxparm *) arg;
int ok;
if (p->verbose > 2) BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n"); if (p->verbose > 2)
if ((ok= X509_verify_cert(ctx)) && ctx->cert) { BIO_printf(p->errorbio,"entering ssl_app_verify_callback\n");
unsigned char * accessinfo ;
if (p->verbose > 1) X509_print_ex(p->errorbio,ctx->cert,0,0); if ((ok= X509_verify_cert(ctx)) && ctx->cert) {
if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_sinfo_access)) { unsigned char * accessinfo ;
if (p->verbose) BIO_printf(p->errorbio,"Setting URL from SIA to: %s\n",accessinfo); if (p->verbose > 1)
curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); X509_print_ex(p->errorbio,ctx->cert,0,0);
} else if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_info_access)) {
if (p->verbose) BIO_printf(p->errorbio,"Setting URL from AIA to: %s\n",accessinfo); if (accessinfo = my_get_ext(ctx->cert,p->accesstype ,NID_sinfo_access)) {
curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo); if (p->verbose)
} BIO_printf(p->errorbio,"Setting URL from SIA to: %s\n", accessinfo);
}
if (p->verbose > 2) BIO_printf(p->errorbio,"leaving ssl_app_verify_callback with %d\n",ok); curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo);
return(ok); }
else if (accessinfo = my_get_ext(ctx->cert,p->accesstype,
NID_info_access)) {
if (p->verbose)
BIO_printf(p->errorbio,"Setting URL from AIA to: %s\n", accessinfo);
curl_easy_setopt(p->curl, CURLOPT_URL,accessinfo);
}
}
if (p->verbose > 2)
BIO_printf(p->errorbio,"leaving ssl_app_verify_callback with %d\n", ok);
return(ok);
} }
/* This is an example of an curl SSL initialisation call back. The callback sets: /* This is an example of an curl SSL initialisation call back. The callback sets:
- a private key and certificate - a private key and certificate
- a trusted ca certificate - a trusted ca certificate
- a preferred cipherlist - a preferred cipherlist
- an application verification callback (the function above) - an application verification callback (the function above)
*/ */
static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) { static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) {
sslctxparm * p = (sslctxparm *) parm; sslctxparm * p = (sslctxparm *) parm;
SSL_CTX * ctx = (SSL_CTX *) sslctx ; SSL_CTX * ctx = (SSL_CTX *) sslctx ;
if (!SSL_CTX_use_certificate(ctx,p->usercert)) { if (!SSL_CTX_use_certificate(ctx,p->usercert)) {
BIO_printf(p->errorbio, "SSL_CTX_use_certificate problem\n"); goto err; BIO_printf(p->errorbio, "SSL_CTX_use_certificate problem\n"); goto err;
} }
if (!SSL_CTX_use_PrivateKey(ctx,p->pkey)) { if (!SSL_CTX_use_PrivateKey(ctx,p->pkey)) {
BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\n"); goto err; BIO_printf(p->errorbio, "SSL_CTX_use_PrivateKey\n"); goto err;
} }
if (!SSL_CTX_check_private_key(ctx)) { if (!SSL_CTX_check_private_key(ctx)) {
BIO_printf(p->errorbio, "SSL_CTX_check_private_key\n"); goto err; BIO_printf(p->errorbio, "SSL_CTX_check_private_key\n"); goto err;
} }
SSL_CTX_set_quiet_shutdown(ctx,1); SSL_CTX_set_quiet_shutdown(ctx,1);
SSL_CTX_set_cipher_list(ctx,"RC4-MD5"); SSL_CTX_set_cipher_list(ctx,"RC4-MD5");
SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY); SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY);
X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca,sk_X509_num(p->ca)-1)); X509_STORE_add_cert(ctx->cert_store,sk_X509_value(p->ca,
sk_X509_num(p->ca)-1));
SSL_CTX_set_verify_depth(ctx,2); SSL_CTX_set_verify_depth(ctx,2);
SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL);
SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm); SSL_CTX_set_cert_verify_callback(ctx, ssl_app_verify_callback, parm);
return CURLE_OK ; return CURLE_OK ;
err: err:
ERR_print_errors(p->errorbio); ERR_print_errors(p->errorbio);
return CURLE_SSL_CERTPROBLEM; return CURLE_SSL_CERTPROBLEM;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
BIO* in=NULL; BIO* in=NULL;
BIO* out=NULL; BIO* out=NULL;
char * outfile = NULL;
char * infile = NULL ;
int tabLength=100;
char *binaryptr;
char* mimetype;
char* mimetypeaccept=NULL;
char* contenttype;
char** pp;
unsigned char* hostporturl = NULL;
binaryptr=(char*)malloc(tabLength);
BIO * p12bio ;
char **args = argv + 1;
unsigned char * serverurl;
sslctxparm p;
char *response;
p.verbose = 0;
CURLcode res;
struct curl_slist * headers=NULL;
p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE);
curl_global_init(CURL_GLOBAL_DEFAULT);
/* we need some more for the P12 decoding */
OpenSSL_add_all_ciphers();
OpenSSL_add_all_digests();
ERR_load_crypto_strings();
char * outfile = NULL; int badarg=0;
char * infile = NULL ;
int tabLength=100; while (*args && *args[0] == '-') {
char *binaryptr; if (!strcmp (*args, "-in")) {
char* mimetype; if (args[1]) {
char* mimetypeaccept=NULL; infile=*(++args);
char* contenttype; } else badarg=1;
char** pp; } else if (!strcmp (*args, "-out")) {
unsigned char* hostporturl = NULL; if (args[1]) {
binaryptr=(char*)malloc(tabLength); outfile=*(++args);
BIO * p12bio ; } else badarg=1;
char **args = argv + 1; } else if (!strcmp (*args, "-p12")) {
unsigned char * serverurl; if (args[1]) {
sslctxparm p; p.p12file = *(++args);
char *response; } else badarg=1;
p.verbose = 0; } else if (strcmp(*args,"-envpass") == 0) {
if (args[1]) {
p.pst = getenv(*(++args));
} else badarg=1;
} else if (strcmp(*args,"-connect") == 0) {
if (args[1]) {
hostporturl = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-mimetype") == 0) {
if (args[1]) {
mimetype = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-acceptmime") == 0) {
if (args[1]) {
mimetypeaccept = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-accesstype") == 0) {
if (args[1]) {
if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1;
} else badarg=1;
} else if (strcmp(*args,"-verbose") == 0) {
p.verbose++;
} else badarg=1;
args++;
}
CURLcode res; if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1;
struct curl_slist * headers=NULL;
p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); if (badarg) {
for (pp=curlx_usage; (*pp != NULL); pp++)
curl_global_init(CURL_GLOBAL_DEFAULT); BIO_printf(p.errorbio,"%s\n",*pp);
BIO_printf(p.errorbio,"\n");
/* we need some more for the P12 decoding */ goto err;
}
OpenSSL_add_all_ciphers();
OpenSSL_add_all_digests();
ERR_load_crypto_strings();
int badarg=0;
while (*args && *args[0] == '-') {
if (!strcmp (*args, "-in")) {
if (args[1]) {
infile=*(++args);
} else badarg=1;
} else if (!strcmp (*args, "-out")) {
if (args[1]) {
outfile=*(++args);
} else badarg=1;
} else if (!strcmp (*args, "-p12")) {
if (args[1]) {
p.p12file = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-envpass") == 0) {
if (args[1]) {
p.pst = getenv(*(++args));
} else badarg=1;
} else if (strcmp(*args,"-connect") == 0) {
if (args[1]) {
hostporturl = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-mimetype") == 0) {
if (args[1]) {
mimetype = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-acceptmime") == 0) {
if (args[1]) {
mimetypeaccept = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-accesstype") == 0) {
if (args[1]) {
if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1;
} else badarg=1;
} else if (strcmp(*args,"-verbose") == 0) {
p.verbose++;
} else badarg=1;
args++;
}
if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1;
if (badarg) {
for (pp=curlx_usage; (*pp != NULL); pp++)
BIO_printf(p.errorbio,"%s\n",*pp);
BIO_printf(p.errorbio,"\n");
goto err;
}
/* set input */ /* set input */
if ((in=BIO_new(BIO_s_file())) == NULL) { if ((in=BIO_new(BIO_s_file())) == NULL) {
BIO_printf(p.errorbio, "Error setting input bio\n"); BIO_printf(p.errorbio, "Error setting input bio\n");
goto err; goto err;
} else if (infile == NULL) } else if (infile == NULL)
BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT); BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT);
else if (BIO_read_filename(in,infile) <= 0) { else if (BIO_read_filename(in,infile) <= 0) {
BIO_printf(p.errorbio, "Error opening input file %s\n", infile); BIO_printf(p.errorbio, "Error opening input file %s\n", infile);
BIO_free(in); BIO_free(in);
goto err; goto err;
} }
/* set output */ /* set output */
if ((out=BIO_new(BIO_s_file())) == NULL) { if ((out=BIO_new(BIO_s_file())) == NULL) {
BIO_printf(p.errorbio, "Error setting output bio.\n"); BIO_printf(p.errorbio, "Error setting output bio.\n");
goto err; goto err;
} else if (outfile == NULL) } else if (outfile == NULL)
BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT); BIO_set_fp(out,stdout,BIO_NOCLOSE|BIO_FP_TEXT);
else if (BIO_write_filename(out,outfile) <= 0) { else if (BIO_write_filename(out,outfile) <= 0) {
BIO_printf(p.errorbio, "Error opening output file %s\n", outfile); BIO_printf(p.errorbio, "Error opening output file %s\n", outfile);
BIO_free(out); BIO_free(out);
goto err; goto err;
} }
p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE); p.errorbio = BIO_new_fp (stderr, BIO_NOCLOSE);
if (!(p.curl = curl_easy_init())) { if (!(p.curl = curl_easy_init())) {
BIO_printf(p.errorbio, "Cannot init curl lib\n"); BIO_printf(p.errorbio, "Cannot init curl lib\n");
goto err; goto err;
} }
if (!(p12bio = BIO_new_file(p.p12file , "rb"))) { if (!(p12bio = BIO_new_file(p.p12file , "rb"))) {
BIO_printf(p.errorbio, "Error opening P12 file %s\n", p.p12file); goto err; BIO_printf(p.errorbio, "Error opening P12 file %s\n", p.p12file); goto err;
} }
if (!(p.p12 = d2i_PKCS12_bio (p12bio, NULL))) { if (!(p.p12 = d2i_PKCS12_bio (p12bio, NULL))) {
BIO_printf(p.errorbio, "Cannot decode P12 structure %s\n", p.p12file); goto err; BIO_printf(p.errorbio, "Cannot decode P12 structure %s\n", p.p12file); goto err;
} }
p.ca= NULL; p.ca= NULL;
if (!(PKCS12_parse (p.p12, p.pst, &(p.pkey), &(p.usercert), &(p.ca) ) )) { if (!(PKCS12_parse (p.p12, p.pst, &(p.pkey), &(p.usercert), &(p.ca) ) )) {
BIO_printf(p.errorbio,"Invalid P12 structure in %s\n", p.p12file); goto err; BIO_printf(p.errorbio,"Invalid P12 structure in %s\n", p.p12file); goto err;
} }
if (sk_X509_num(p.ca) <= 0) { if (sk_X509_num(p.ca) <= 0) {
BIO_printf(p.errorbio,"No trustworthy CA given.%s\n", p.p12file); goto err; BIO_printf(p.errorbio,"No trustworthy CA given.%s\n", p.p12file); goto err;
} }
if (p.verbose > 1) X509_print_ex(p.errorbio,p.usercert,0,0); if (p.verbose > 1)
X509_print_ex(p.errorbio,p.usercert,0,0);
/* determine URL to go */ /* determine URL to go */
if (hostporturl) { if (hostporturl) {
serverurl=(char*) malloc(9+strlen(hostporturl)); serverurl=(char*) malloc(9+strlen(hostporturl));
sprintf(serverurl,"https://%s",hostporturl); sprintf(serverurl,"https://%s",hostporturl);
} else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ }
if (!(serverurl = my_get_ext(p.usercert,p.accesstype,NID_info_access))) { else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */
BIO_printf(p.errorbio,"no service URL in user cert cherching in others certificats\n"); if (!(serverurl = my_get_ext(p.usercert,p.accesstype,NID_info_access))) {
int j=0; BIO_printf(p.errorbio,"no service URL in user cert "
int find=0; "cherching in others certificats\n");
for (j=0;j<sk_X509_num(p.ca);j++) { int j=0;
if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype,NID_info_access))) break; int find=0;
if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype,NID_sinfo_access))) break; for (j=0;j<sk_X509_num(p.ca);j++) {
} if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype,
} NID_info_access)))
} break;
if ((serverurl = my_get_ext(sk_X509_value(p.ca,j),p.accesstype,
NID_sinfo_access)))
break;
}
}
}
if (!serverurl) { if (!serverurl) {
BIO_printf(p.errorbio, "no service URL in certificats, check '-accesstype (AD_DVCS | ad_timestamping)' or use '-connect'\n"); goto err; BIO_printf(p.errorbio, "no service URL in certificats,"
} " check '-accesstype (AD_DVCS | ad_timestamping)'"
" or use '-connect'\n");
goto err;
}
if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); if (p.verbose)
curl_easy_setopt(p.curl, CURLOPT_URL, serverurl); BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl);
/* Now specify the POST binary data */ curl_easy_setopt(p.curl, CURLOPT_URL, serverurl);
curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); /* Now specify the POST binary data */
curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength);
/* pass our list of custom made headers */ curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr);
curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength);
contenttype=(char*) malloc(15+strlen(mimetype)); /* pass our list of custom made headers */
sprintf(contenttype,"Content-type: %s",mimetype);
headers = curl_slist_append(headers,contenttype);
curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers);
if (p.verbose) BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl); contenttype=(char*) malloc(15+strlen(mimetype));
sprintf(contenttype,"Content-type: %s",mimetype);
headers = curl_slist_append(headers,contenttype);
curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers);
{ if (p.verbose)
FILE *outfp; BIO_printf(p.errorbio, "Service URL: <%s>\n", serverurl);
BIO_get_fp(out,&outfp);
curl_easy_setopt(p.curl, CURLOPT_FILE,outfp);
}
res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ; {
FILE *outfp;
BIO_get_fp(out,&outfp);
curl_easy_setopt(p.curl, CURLOPT_FILE,outfp);
}
if (res != CURLE_OK) res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun) ;
BIO_printf(p.errorbio,"%d %s=%d %d\n", __LINE__, "CURLOPT_SSL_CTX_FUNCTION",CURLOPT_SSL_CTX_FUNCTION,res);
curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p); if (res != CURLE_OK)
BIO_printf(p.errorbio,"%d %s=%d %d\n", __LINE__, "CURLOPT_SSL_CTX_FUNCTION",CURLOPT_SSL_CTX_FUNCTION,res);
{ curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p);
int lu; int i=0;
while ((lu = BIO_read (in,&binaryptr[i],tabLength-i)) >0 ) {
i+=lu;
if (i== tabLength) {
tabLength+=100;
binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */
}
}
tabLength = i;
}
/* Now specify the POST binary data */
curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr); {
curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength); int lu; int i=0;
while ((lu = BIO_read (in,&binaryptr[i],tabLength-i)) >0 ) {
i+=lu;
if (i== tabLength) {
tabLength+=100;
binaryptr=(char*)realloc(binaryptr,tabLength); /* should be more careful */
}
}
tabLength = i;
}
/* Now specify the POST binary data */
curl_easy_setopt(p.curl, CURLOPT_POSTFIELDS, binaryptr);
curl_easy_setopt(p.curl, CURLOPT_POSTFIELDSIZE,tabLength);
/* Perform the request, res will get the return code */ /* Perform the request, res will get the return code */
BIO_printf(p.errorbio,"%d %s %d\n", __LINE__, "curl_easy_perform", res = curl_easy_perform(p.curl)); BIO_printf(p.errorbio,"%d %s %d\n", __LINE__, "curl_easy_perform",
{ res = curl_easy_perform(p.curl));
int result =curl_easy_getinfo(p.curl,CURLINFO_CONTENT_TYPE,&response); {
if( mimetypeaccept && p.verbose) int result =curl_easy_getinfo(p.curl,CURLINFO_CONTENT_TYPE,&response);
if(!strcmp(mimetypeaccept,response)) if( mimetypeaccept && p.verbose)
BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n",response); if(!strcmp(mimetypeaccept,response))
else BIO_printf(p.errorbio,"the response has a correct mimetype : %s\n",
BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable mime type, it is %s instead of %s\n",response,mimetypeaccept); response);
} else
BIO_printf(p.errorbio,"the reponse doesn\'t has an acceptable "
"mime type, it is %s instead of %s\n",
response,mimetypeaccept);
}
/*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/ /*** code d'erreur si accept mime ***, egalement code return HTTP != 200 ***/
/* free the header list*/ /* free the header list*/
curl_slist_free_all(headers); curl_slist_free_all(headers);
/* always cleanup */ /* always cleanup */
curl_easy_cleanup(p.curl); curl_easy_cleanup(p.curl);
BIO_free(in); BIO_free(in);
BIO_free(out); BIO_free(out);
return (EXIT_SUCCESS); return (EXIT_SUCCESS);
err: BIO_printf(p.errorbio,"error");
err: BIO_printf(p.errorbio,"error"); exit(1);
exit(1);
} }