examples: adhere to curl code style

All plain C examples now (mostly) adhere to the curl code style. While
they are only examples, they had diverted so much and contained all
sorts of different mixed code styles by now. Having them use a unified
style helps users and readability. Also, as they get copy-and-pasted
widely by users, making sure they're clean and nice is a good idea.

573 checksrc warnings were addressed.
This commit is contained in:
Daniel Stenberg
2016-02-11 09:42:38 +01:00
parent 936d8f07df
commit 3a6563d668
54 changed files with 821 additions and 766 deletions

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -157,7 +157,8 @@ int main(void)
#else #else
sleep(L / 1000); sleep(L / 1000);
#endif #endif
} else { }
else {
T.tv_sec = L/1000; T.tv_sec = L/1000;
T.tv_usec = (L%1000)*1000; T.tv_usec = (L%1000)*1000;

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -77,43 +77,58 @@ int main(int argc, char *argv[])
"\rUsage: %s [-m=1|2|5|10|20|50|100] [-t] [-x] [url]\n", "\rUsage: %s [-m=1|2|5|10|20|50|100] [-t] [-x] [url]\n",
appname); appname);
exit(1); exit(1);
} else if (strncasecmp(*argv, "-V", 2) == 0) { }
else if(strncasecmp(*argv, "-V", 2) == 0) {
fprintf(stderr, "\r%s %s - %s\n", fprintf(stderr, "\r%s %s - %s\n",
appname, CHKSPEED_VERSION, curl_version()); appname, CHKSPEED_VERSION, curl_version());
exit(1); exit(1);
} else if (strncasecmp(*argv, "-A", 2) == 0) { }
else if(strncasecmp(*argv, "-A", 2) == 0) {
prtall = 1; prtall = 1;
} else if (strncasecmp(*argv, "-X", 2) == 0) { }
else if(strncasecmp(*argv, "-X", 2) == 0) {
prtsep = 1; prtsep = 1;
} else if (strncasecmp(*argv, "-T", 2) == 0) { }
else if(strncasecmp(*argv, "-T", 2) == 0) {
prttime = 1; prttime = 1;
} else if (strncasecmp(*argv, "-M=", 3) == 0) { }
else if(strncasecmp(*argv, "-M=", 3) == 0) {
long m = strtol((*argv)+3, NULL, 10); long m = strtol((*argv)+3, NULL, 10);
switch(m) { switch(m) {
case 1: url = URL_1M; case 1:
url = URL_1M;
break; break;
case 2: url = URL_2M; case 2:
url = URL_2M;
break; break;
case 5: url = URL_5M; case 5:
url = URL_5M;
break; break;
case 10: url = URL_10M; case 10:
url = URL_10M;
break; break;
case 20: url = URL_20M; case 20:
url = URL_20M;
break; break;
case 50: url = URL_50M; case 50:
url = URL_50M;
break; break;
case 100: url = URL_100M; case 100:
url = URL_100M;
break; break;
default: fprintf(stderr, "\r%s: invalid parameter %s\n", default:
fprintf(stderr, "\r%s: invalid parameter %s\n",
appname, *argv + 3); appname, *argv + 3);
exit(1); exit(1);
} }
} else { }
else {
fprintf(stderr, "\r%s: invalid or unknown option %s\n", fprintf(stderr, "\r%s: invalid or unknown option %s\n",
appname, *argv); appname, *argv);
exit(1); exit(1);
} }
} else { }
else {
url = *argv; url = *argv;
} }
} }
@@ -178,8 +193,8 @@ int main(int argc, char *argv[])
if((CURLE_OK == res) && (val>0)) if((CURLE_OK == res) && (val>0))
printf("Connect time: %0.3f sec.\n", val); printf("Connect time: %0.3f sec.\n", val);
} }
}
} else { else {
fprintf(stderr, "Error while fetching '%s' : %s\n", fprintf(stderr, "Error while fetching '%s' : %s\n",
url, curl_easy_strerror(res)); url, curl_easy_strerror(res));
} }

View File

@@ -50,9 +50,9 @@ void *my_thread(void *ptr)
gchar *url = ptr; gchar *url = ptr;
curl = curl_easy_init(); curl = curl_easy_init();
if(curl) if(curl) {
{ const char *filename = "test.curl";
outfile = fopen("test.curl", "w"); outfile = fopen(filename, "wb");
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);

View File

@@ -101,13 +101,18 @@
static const char *curlx_usage[]={ static const 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.openevidence.org", " -connect arg - URL of the server for the connection ex:"
" -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query", " www.openevidence.org",
" -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none", " -mimetype arg - MIME type for data in ex : application/timestamp-query"
" -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping", " or application/dvcs -default application/timestamp-query",
" -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",
NULL NULL
}; };
@@ -155,9 +160,9 @@ static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5)
} }
/* 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,
static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) { 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);
@@ -211,11 +216,12 @@ static int ssl_app_verify_callback(X509_STORE_CTX *ctx, void *arg)
} }
if(p->verbose > 2) if(p->verbose > 2)
BIO_printf(p->errorbio, "leaving ssl_app_verify_callback with %d\n", ok); BIO_printf(p->errorbio, "leaving ssl_app_verify_callback with %d\n", ok);
return(ok);
return ok;
} }
/* This is an example of an curl SSL initialisation call back. The callback sets: /* The SSL initialisation callback. 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
@@ -228,21 +234,25 @@ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * 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(SSL_CTX_get_cert_store(ctx), sk_X509_value(p->ca, sk_X509_num(p->ca)-1)); X509_STORE_add_cert(SSL_CTX_get_cert_store(ctx),
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);
@@ -302,42 +312,70 @@ int main(int argc, char **argv) {
if(!strcmp (*args, "-in")) { if(!strcmp (*args, "-in")) {
if(args[1]) { if(args[1]) {
infile=*(++args); infile=*(++args);
} else badarg=1; }
} else if (!strcmp (*args, "-out")) { else
badarg=1;
}
else if(!strcmp (*args, "-out")) {
if(args[1]) { if(args[1]) {
outfile=*(++args); outfile=*(++args);
} else badarg=1; }
} else if (!strcmp (*args, "-p12")) { else
badarg=1;
}
else if(!strcmp (*args, "-p12")) {
if(args[1]) { if(args[1]) {
p.p12file = *(++args); p.p12file = *(++args);
} else badarg=1; }
} else if (strcmp(*args,"-envpass") == 0) { else
badarg=1;
}
else if(strcmp(*args, "-envpass") == 0) {
if(args[1]) { if(args[1]) {
p.pst = getenv(*(++args)); p.pst = getenv(*(++args));
} else badarg=1; }
} else if (strcmp(*args,"-connect") == 0) { else
badarg=1;
}
else if(strcmp(*args, "-connect") == 0) {
if(args[1]) { if(args[1]) {
hostporturl = *(++args); hostporturl = *(++args);
} else badarg=1; }
} else if (strcmp(*args,"-mimetype") == 0) { else
badarg=1;
}
else if(strcmp(*args, "-mimetype") == 0) {
if(args[1]) { if(args[1]) {
mimetype = *(++args); mimetype = *(++args);
} else badarg=1; }
} else if (strcmp(*args,"-acceptmime") == 0) { else
badarg=1;
}
else if(strcmp(*args, "-acceptmime") == 0) {
if(args[1]) { if(args[1]) {
mimetypeaccept = *(++args); mimetypeaccept = *(++args);
} else badarg=1; }
} else if (strcmp(*args,"-accesstype") == 0) { else
badarg=1;
}
else if(strcmp(*args, "-accesstype") == 0) {
if(args[1]) { if(args[1]) {
if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1; if((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args, 0))) == 0)
} else badarg=1; badarg=1;
} else if (strcmp(*args,"-verbose") == 0) { }
else
badarg=1;
}
else if(strcmp(*args, "-verbose") == 0) {
p.verbose++; p.verbose++;
} else badarg=1; }
else
badarg=1;
args++; args++;
} }
if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1; if(mimetype==NULL || mimetypeaccept == NULL)
badarg = 1;
if(badarg) { if(badarg) {
for(pp=curlx_usage; (*pp != NULL); pp++) for(pp=curlx_usage; (*pp != NULL); pp++)
@@ -353,7 +391,8 @@ int main(int argc, char **argv) {
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);
@@ -366,7 +405,8 @@ int main(int argc, char **argv) {
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);
@@ -385,19 +425,23 @@ int main(int argc, char **argv) {
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) if(p.verbose > 1)
@@ -406,10 +450,12 @@ int main(int argc, char **argv) {
/* determine URL to go */ /* determine URL to go */
if(hostporturl) { if(hostporturl) {
serverurl = malloc(9+strlen(hostporturl)); size_t len = strlen(hostporturl) + 9;
sprintf(serverurl,"https://%s",hostporturl); serverurl = malloc(len);
snprintf(serverurl, len, "https://%s", hostporturl);
} }
else if (p.accesstype != 0) { /* see whether we can find an AIA or SIA for a given access type */ 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))) { if(!(serverurl = my_get_ext(p.usercert, p.accesstype, NID_info_access))) {
int j=0; int j=0;
BIO_printf(p.errorbio, "no service URL in user cert " BIO_printf(p.errorbio, "no service URL in user cert "
@@ -445,7 +491,7 @@ int main(int argc, char **argv) {
/* pass our list of custom made headers */ /* pass our list of custom made headers */
contenttype = malloc(15+strlen(mimetype)); contenttype = malloc(15+strlen(mimetype));
sprintf(contenttype,"Content-type: %s",mimetype); snprintf(contenttype, 15+strlen(mimetype), "Content-type: %s", mimetype);
headers = curl_slist_append(headers, contenttype); headers = curl_slist_append(headers, contenttype);
curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(p.curl, CURLOPT_HTTPHEADER, headers);
@@ -461,7 +507,8 @@ int main(int argc, char **argv) {
res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun); res = curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun);
if(res != CURLE_OK) if(res != CURLE_OK)
BIO_printf(p.errorbio,"%d %s=%d %d\n", __LINE__, "CURLOPT_SSL_CTX_FUNCTION",CURLOPT_SSL_CTX_FUNCTION,res); 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); curl_easy_setopt(p.curl, CURLOPT_SSL_CTX_DATA, &p);

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -119,12 +119,12 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g)
{ {
DPRINT("%s %li\n", __PRETTY_FUNCTION__, timeout_ms); DPRINT("%s %li\n", __PRETTY_FUNCTION__, timeout_ms);
ev_timer_stop(g->loop, &g->timer_event); ev_timer_stop(g->loop, &g->timer_event);
if (timeout_ms > 0) if(timeout_ms > 0) {
{
double t = timeout_ms / 1000; double t = timeout_ms / 1000;
ev_timer_init(&g->timer_event, timer_cb, t, 0.); ev_timer_init(&g->timer_event, timer_cb, t, 0.);
ev_timer_start(g->loop, &g->timer_event); ev_timer_start(g->loop, &g->timer_event);
}else }
else
timer_cb(g->loop, &g->timer_event, 0); timer_cb(g->loop, &g->timer_event, 0);
return 0; return 0;
} }
@@ -132,20 +132,32 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, GlobalInfo *g)
/* Die if we get a bad CURLMcode somewhere */ /* Die if we get a bad CURLMcode somewhere */
static void mcode_or_die(const char *where, CURLMcode code) static void mcode_or_die(const char *where, CURLMcode code)
{ {
if ( CURLM_OK != code ) if(CURLM_OK != code) {
{
const char *s; const char *s;
switch ( code ) switch (code) {
{ case CURLM_BAD_HANDLE:
case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break; s="CURLM_BAD_HANDLE";
case CURLM_BAD_EASY_HANDLE: s="CURLM_BAD_EASY_HANDLE"; break;
case CURLM_OUT_OF_MEMORY: s="CURLM_OUT_OF_MEMORY"; break;
case CURLM_INTERNAL_ERROR: s="CURLM_INTERNAL_ERROR"; break;
case CURLM_UNKNOWN_OPTION: s="CURLM_UNKNOWN_OPTION"; break;
case CURLM_LAST: s="CURLM_LAST"; break;
default: s="CURLM_unknown";
break; break;
case CURLM_BAD_SOCKET: s="CURLM_BAD_SOCKET"; case CURLM_BAD_EASY_HANDLE:
s="CURLM_BAD_EASY_HANDLE";
break;
case CURLM_OUT_OF_MEMORY:
s="CURLM_OUT_OF_MEMORY";
break;
case CURLM_INTERNAL_ERROR:
s="CURLM_INTERNAL_ERROR";
break;
case CURLM_UNKNOWN_OPTION:
s="CURLM_UNKNOWN_OPTION";
break;
case CURLM_LAST:
s="CURLM_LAST";
break;
default:
s="CURLM_unknown";
break;
case CURLM_BAD_SOCKET:
s="CURLM_BAD_SOCKET";
fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s);
/* ignore this error */ /* ignore this error */
return; return;
@@ -197,8 +209,7 @@ static void event_cb(EV_P_ struct ev_io *w, int revents)
rc = curl_multi_socket_action(g->multi, w->fd, action, &g->still_running); rc = curl_multi_socket_action(g->multi, w->fd, action, &g->still_running);
mcode_or_die("event_cb: curl_multi_socket_action", rc); mcode_or_die("event_cb: curl_multi_socket_action", rc);
check_multi_info(g); check_multi_info(g);
if ( g->still_running <= 0 ) if(g->still_running <= 0) {
{
fprintf(MSG_OUT, "last transfer done, kill timeout\n"); fprintf(MSG_OUT, "last transfer done, kill timeout\n");
ev_timer_stop(g->loop, &g->timer_event); ev_timer_stop(g->loop, &g->timer_event);
} }
@@ -212,7 +223,8 @@ static void timer_cb(EV_P_ struct ev_timer *w, int revents)
GlobalInfo *g = (GlobalInfo *)w->data; GlobalInfo *g = (GlobalInfo *)w->data;
CURLMcode rc; CURLMcode rc;
rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &g->still_running); rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0,
&g->still_running);
mcode_or_die("timer_cb: curl_multi_socket_action", rc); mcode_or_die("timer_cb: curl_multi_socket_action", rc);
check_multi_info(g); check_multi_info(g);
} }
@@ -221,8 +233,7 @@ static void timer_cb(EV_P_ struct ev_timer *w, int revents)
static void remsock(SockInfo *f, GlobalInfo *g) static void remsock(SockInfo *f, GlobalInfo *g)
{ {
printf("%s \n", __PRETTY_FUNCTION__); printf("%s \n", __PRETTY_FUNCTION__);
if ( f ) if(f) {
{
if(f->evset) if(f->evset)
ev_io_stop(g->loop, &f->ev); ev_io_stop(g->loop, &f->ev);
free(f); free(f);
@@ -273,18 +284,16 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
fprintf(MSG_OUT, fprintf(MSG_OUT,
"socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]);
if ( what == CURL_POLL_REMOVE ) if(what == CURL_POLL_REMOVE) {
{
fprintf(MSG_OUT, "\n"); fprintf(MSG_OUT, "\n");
remsock(fdp, g); remsock(fdp, g);
} else }
{ else {
if ( !fdp ) if(!fdp) {
{
fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]); fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]);
addsock(s, e, what, g); addsock(s, e, what, g);
} else }
{ else {
fprintf(MSG_OUT, fprintf(MSG_OUT,
"Changing action from %s to %s\n", "Changing action from %s to %s\n",
whatstr[fdp->action], whatstr[what]); whatstr[fdp->action], whatstr[what]);
@@ -330,8 +339,7 @@ static void new_conn(char *url, GlobalInfo *g )
conn->error[0]='\0'; conn->error[0]='\0';
conn->easy = curl_easy_init(); conn->easy = curl_easy_init();
if ( !conn->easy ) if(!conn->easy) {
{
fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n"); fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n");
exit(2); exit(2);
} }
@@ -366,15 +374,15 @@ static void fifo_cb(EV_P_ struct ev_io *w, int revents)
int n=0; int n=0;
GlobalInfo *g = (GlobalInfo *)w->data; GlobalInfo *g = (GlobalInfo *)w->data;
do do {
{
s[0]='\0'; s[0]='\0';
rv=fscanf(g->input, "%1023s%n", s, &n); rv=fscanf(g->input, "%1023s%n", s, &n);
s[n]='\0'; s[n]='\0';
if ( n && s[0] ) if(n && s[0]) {
{
new_conn(s, g); /* if we read a URL, go get it! */ new_conn(s, g); /* if we read a URL, go get it! */
} else break; }
else
break;
} while(rv != EOF); } while(rv != EOF);
} }
@@ -386,24 +394,20 @@ static int init_fifo (GlobalInfo *g)
curl_socket_t sockfd; curl_socket_t sockfd;
fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo); fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo);
if ( lstat (fifo, &st) == 0 ) if(lstat (fifo, &st) == 0) {
{ if((st.st_mode & S_IFMT) == S_IFREG) {
if ( (st.st_mode & S_IFMT) == S_IFREG )
{
errno = EEXIST; errno = EEXIST;
perror("lstat"); perror("lstat");
exit (1); exit (1);
} }
} }
unlink(fifo); unlink(fifo);
if ( mkfifo (fifo, 0600) == -1 ) if(mkfifo (fifo, 0600) == -1) {
{
perror("mkfifo"); perror("mkfifo");
exit (1); exit (1);
} }
sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0); sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0);
if ( sockfd == -1 ) if(sockfd == -1) {
{
perror("open"); perror("open");
exit (1); exit (1);
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms

View File

@@ -165,8 +165,7 @@ static int fill_buffer(URL_FILE *file, size_t want)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }
@@ -447,6 +446,10 @@ void url_rewind(URL_FILE *file)
} }
} }
#define FGETSFILE "fgets.test"
#define FREADFILE "fread.test"
#define REWINDFILE "rewind.test"
/* Small main program to retrive from a url using fgets and fread saving the /* Small main program to retrive from a url using fgets and fread saving the
* output to two test files (note the fgets method will corrupt binary files if * output to two test files (note the fgets method will corrupt binary files if
* they contain 0 chars */ * they contain 0 chars */
@@ -465,7 +468,7 @@ int main(int argc, char *argv[])
url=argv[1];/* use passed url */ url=argv[1];/* use passed url */
/* copy from url line by line with fgets */ /* copy from url line by line with fgets */
outf=fopen("fgets.test","w+"); outf=fopen(FGETSFILE, "wb+");
if(!outf) { if(!outf) {
perror("couldn't open fgets output file\n"); perror("couldn't open fgets output file\n");
return 1; return 1;
@@ -489,7 +492,7 @@ int main(int argc, char *argv[])
/* Copy from url with fread */ /* Copy from url with fread */
outf=fopen("fread.test","w+"); outf=fopen(FREADFILE, "wb+");
if(!outf) { if(!outf) {
perror("couldn't open fread output file\n"); perror("couldn't open fread output file\n");
return 1; return 1;
@@ -513,7 +516,7 @@ int main(int argc, char *argv[])
/* Test rewind */ /* Test rewind */
outf=fopen("rewind.test","w+"); outf=fopen(REWINDFILE, "wb+");
if(!outf) { if(!outf) {
perror("couldn't open fread output file\n"); perror("couldn't open fread output file\n");
return 1; return 1;
@@ -536,11 +539,9 @@ int main(int argc, char *argv[])
nread = url_fread(buffer, 1, sizeof(buffer), handle); nread = url_fread(buffer, 1, sizeof(buffer), handle);
fwrite(buffer, 1, nread, outf); fwrite(buffer, 1, nread, outf);
url_fclose(handle); url_fclose(handle);
fclose(outf); fclose(outf);
return 0;/* all done */ return 0;/* all done */
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -119,7 +119,7 @@ static long file_is_coming(struct curl_fileinfo *finfo,
return CURL_CHUNK_BGN_FUNC_SKIP; return CURL_CHUNK_BGN_FUNC_SKIP;
} }
data->output = fopen(finfo->filename, "w"); data->output = fopen(finfo->filename, "wb");
if(!data->output) { if(!data->output) {
return CURL_CHUNK_BGN_FUNC_FAIL; return CURL_CHUNK_BGN_FUNC_FAIL;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -63,7 +63,7 @@ int main(void)
* You better replace the URL with one that works! * You better replace the URL with one that works!
*/ */
curl_easy_setopt(curl, CURLOPT_URL, curl_easy_setopt(curl, CURLOPT_URL,
"ftp://ftp.example.com/pub/www/utilities/curl/curl-7.9.2.tar.gz"); "ftp://ftp.example.com/curl/curl-7.9.2.tar.gz");
/* Define our callback to get called when there's data to be written */ /* Define our callback to get called when there's data to be written */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
/* Set a pointer to our struct to pass to the callback */ /* Set a pointer to our struct to pass to the callback */

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -71,10 +71,12 @@ int main(void)
time_t file_time = (time_t)filetime; time_t file_time = (time_t)filetime;
printf("filetime %s: %s", filename, ctime(&file_time)); printf("filetime %s: %s", filename, ctime(&file_time));
} }
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &filesize); res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
&filesize);
if((CURLE_OK == res) && (filesize>0.0)) if((CURLE_OK == res) && (filesize>0.0))
printf("filesize %s: %0.0f bytes\n", filename, filesize); printf("filesize %s: %0.0f bytes\n", filename, filesize);
} else { }
else {
/* we failed */ /* we failed */
fprintf(stderr, "curl told us %d\n", res); fprintf(stderr, "curl told us %d\n", res);
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -35,6 +35,9 @@ write_response(void *ptr, size_t size, size_t nmemb, void *data)
return fwrite(ptr, size, nmemb, writehere); return fwrite(ptr, size, nmemb, writehere);
} }
#define FTPBODY "ftp-list"
#define FTPHEADERS "ftp-responses"
int main(void) int main(void)
{ {
CURL *curl; CURL *curl;
@@ -43,10 +46,10 @@ int main(void)
FILE *respfile; FILE *respfile;
/* local file name to store the file as */ /* local file name to store the file as */
ftpfile = fopen("ftp-list", "wb"); /* b is binary, needed on win32 */ ftpfile = fopen(FTPBODY, "wb"); /* b is binary, needed on win32 */
/* local file name to store the FTP server's response lines in */ /* local file name to store the FTP server's response lines in */
respfile = fopen("ftp-responses", "wb"); /* b is binary, needed on win32 */ respfile = fopen(FTPHEADERS, "wb"); /* b is binary, needed on win32 */
curl = curl_easy_init(); curl = curl_easy_init();
if(curl) { if(curl) {

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -36,7 +36,8 @@
/* The MinGW headers are missing a few Win32 function definitions, /* The MinGW headers are missing a few Win32 function definitions,
you shouldn't need this if you use VC++ */ you shouldn't need this if you use VC++ */
#if defined(__MINGW32__) && !defined(__MINGW64__) #if defined(__MINGW32__) && !defined(__MINGW64__)
int __cdecl _snscanf(const char * input, size_t length, const char * format, ...); int __cdecl _snscanf(const char * input, size_t length,
const char * format, ...);
#endif #endif
@@ -85,7 +86,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath,
int c; int c;
f = fopen(localpath, "rb"); f = fopen(localpath, "rb");
if (f == NULL) { if(!f) {
perror(NULL); perror(NULL);
return 0; return 0;
} }
@@ -105,7 +106,8 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath,
curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc); curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, readfunc);
curl_easy_setopt(curlhandle, CURLOPT_READDATA, f); curl_easy_setopt(curlhandle, CURLOPT_READDATA, f);
curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-"); /* disable passive mode */ /* disable passive mode */
curl_easy_setopt(curlhandle, CURLOPT_FTPPORT, "-");
curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); curl_easy_setopt(curlhandle, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1L);
@@ -161,7 +163,8 @@ int main(int c, char **argv)
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
curlhandle = curl_easy_init(); curlhandle = curl_easy_init();
upload(curlhandle, "ftp://user:pass@example.com/path/file", "C:\\file", 0, 3); upload(curlhandle, "ftp://user:pass@example.com/path/file", "C:\\file",
0, 3);
curl_easy_cleanup(curlhandle); curl_easy_cleanup(curlhandle);
curl_global_cleanup(); curl_global_cleanup();

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -54,7 +54,6 @@ callback.
*/ */
#include <glib.h> #include <glib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
@@ -64,13 +63,10 @@ callback.
#include <errno.h> #include <errno.h>
#include <curl/curl.h> #include <curl/curl.h>
#define MSG_OUT g_print /* Change to "g_error" to write to stderr */ #define MSG_OUT g_print /* Change to "g_error" to write to stderr */
#define SHOW_VERBOSE 0 /* Set to non-zero for libcurl messages */ #define SHOW_VERBOSE 0 /* Set to non-zero for libcurl messages */
#define SHOW_PROGRESS 0 /* Set to non-zero to enable progress callback */ #define SHOW_PROGRESS 0 /* Set to non-zero to enable progress callback */
/* Global information, common to all connections */ /* Global information, common to all connections */
typedef struct _GlobalInfo { typedef struct _GlobalInfo {
CURLM *multi; CURLM *multi;
@@ -78,8 +74,6 @@ typedef struct _GlobalInfo {
int still_running; int still_running;
} GlobalInfo; } GlobalInfo;
/* Information associated with a specific easy handle */ /* Information associated with a specific easy handle */
typedef struct _ConnInfo { typedef struct _ConnInfo {
CURL *easy; CURL *easy;
@@ -88,7 +82,6 @@ typedef struct _ConnInfo {
char error[CURL_ERROR_SIZE]; char error[CURL_ERROR_SIZE];
} ConnInfo; } ConnInfo;
/* Information associated with a specific socket */ /* Information associated with a specific socket */
typedef struct _SockInfo { typedef struct _SockInfo {
curl_socket_t sockfd; curl_socket_t sockfd;
@@ -100,9 +93,6 @@ typedef struct _SockInfo {
GlobalInfo *global; GlobalInfo *global;
} SockInfo; } SockInfo;
/* Die if we get a bad CURLMcode somewhere */ /* Die if we get a bad CURLMcode somewhere */
static void mcode_or_die(const char *where, CURLMcode code) { static void mcode_or_die(const char *where, CURLMcode code) {
if(CURLM_OK != code) { if(CURLM_OK != code) {
@@ -122,8 +112,6 @@ static void mcode_or_die(const char *where, CURLMcode code) {
} }
} }
/* Check for completed transfers, and remove their easy handles */ /* Check for completed transfers, and remove their easy handles */
static void check_multi_info(GlobalInfo *g) static void check_multi_info(GlobalInfo *g)
{ {
@@ -150,8 +138,6 @@ static void check_multi_info(GlobalInfo *g)
} }
} }
/* Called by glib when our timeout expires */ /* Called by glib when our timeout expires */
static gboolean timer_cb(gpointer data) static gboolean timer_cb(gpointer data)
{ {
@@ -165,8 +151,6 @@ static gboolean timer_cb(gpointer data)
return FALSE; return FALSE;
} }
/* Update the event timer after curl_multi library calls */ /* Update the event timer after curl_multi library calls */
static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp)
{ {
@@ -182,9 +166,6 @@ static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp)
return 0; return 0;
} }
/* Called by glib when we get action on a multi socket */ /* Called by glib when we get action on a multi socket */
static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data)
{ {
@@ -202,25 +183,28 @@ static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data)
check_multi_info(g); check_multi_info(g);
if(g->still_running) { if(g->still_running) {
return TRUE; return TRUE;
} else { }
else {
MSG_OUT("last transfer done, kill timeout\n"); MSG_OUT("last transfer done, kill timeout\n");
if (g->timer_event) { g_source_remove(g->timer_event); } if(g->timer_event) {
g_source_remove(g->timer_event);
}
return FALSE; return FALSE;
} }
} }
/* Clean up the SockInfo structure */ /* Clean up the SockInfo structure */
static void remsock(SockInfo *f) static void remsock(SockInfo *f)
{ {
if (!f) { return; } if(!f) {
if (f->ev) { g_source_remove(f->ev); } return;
}
if(f->ev) {
g_source_remove(f->ev);
}
g_free(f); g_free(f);
} }
/* Assign information to a SockInfo structure */ /* Assign information to a SockInfo structure */
static void setsock(SockInfo*f, curl_socket_t s, CURL*e, int act, GlobalInfo*g) static void setsock(SockInfo*f, curl_socket_t s, CURL*e, int act, GlobalInfo*g)
{ {
@@ -230,12 +214,11 @@ static void setsock(SockInfo*f, curl_socket_t s, CURL*e, int act, GlobalInfo*g)
f->sockfd = s; f->sockfd = s;
f->action = act; f->action = act;
f->easy = e; f->easy = e;
if (f->ev) { g_source_remove(f->ev); } if(f->ev) {
f->ev=g_io_add_watch(f->ch, kind, event_cb,g); g_source_remove(f->ev);
}
f->ev=g_io_add_watch(f->ch, kind, event_cb, g);
} }
/* Initialize a new SockInfo structure */ /* Initialize a new SockInfo structure */
static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g) static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g)
@@ -248,8 +231,6 @@ static void addsock(curl_socket_t s, CURL *easy, int action, GlobalInfo *g)
curl_multi_assign(g->multi, s, fdp); curl_multi_assign(g->multi, s, fdp);
} }
/* CURLMOPT_SOCKETFUNCTION */ /* CURLMOPT_SOCKETFUNCTION */
static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
{ {
@@ -261,7 +242,8 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
if(what == CURL_POLL_REMOVE) { if(what == CURL_POLL_REMOVE) {
MSG_OUT("\n"); MSG_OUT("\n");
remsock(fdp); remsock(fdp);
} else { }
else {
if(!fdp) { if(!fdp) {
MSG_OUT("Adding data: %s%s\n", MSG_OUT("Adding data: %s%s\n",
what&CURL_POLL_IN?"READ":"", what&CURL_POLL_IN?"READ":"",
@@ -277,8 +259,6 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp)
return 0; return 0;
} }
/* CURLOPT_WRITEFUNCTION */ /* CURLOPT_WRITEFUNCTION */
static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data)
{ {
@@ -289,18 +269,15 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data)
return realsize; return realsize;
} }
/* CURLOPT_PROGRESSFUNCTION */ /* CURLOPT_PROGRESSFUNCTION */
static int prog_cb (void *p, double dltotal, double dlnow, double ult, double uln) static int prog_cb (void *p, double dltotal, double dlnow, double ult,
double uln)
{ {
ConnInfo *conn = (ConnInfo *)p; ConnInfo *conn = (ConnInfo *)p;
MSG_OUT("Progress: %s (%g/%g)\n", conn->url, dlnow, dltotal); MSG_OUT("Progress: %s (%g/%g)\n", conn->url, dlnow, dltotal);
return 0; return 0;
} }
/* Create a new easy handle, and add it to the global curl_multi */ /* Create a new easy handle, and add it to the global curl_multi */
static void new_conn(char *url, GlobalInfo *g ) static void new_conn(char *url, GlobalInfo *g )
{ {
@@ -308,9 +285,7 @@ static void new_conn(char *url, GlobalInfo *g )
CURLMcode rc; CURLMcode rc;
conn = g_malloc0(sizeof(ConnInfo)); conn = g_malloc0(sizeof(ConnInfo));
conn->error[0]='\0'; conn->error[0]='\0';
conn->easy = curl_easy_init(); conn->easy = curl_easy_init();
if(!conn->easy) { if(!conn->easy) {
MSG_OUT("curl_easy_init() failed, exiting!\n"); MSG_OUT("curl_easy_init() failed, exiting!\n");
@@ -340,7 +315,6 @@ static void new_conn(char *url, GlobalInfo *g )
that the necessary socket_action() call will be called by this app */ that the necessary socket_action() call will be called by this app */
} }
/* This gets called by glib whenever data is received from the fifo */ /* This gets called by glib whenever data is received from the fifo */
static gboolean fifo_cb (GIOChannel *ch, GIOCondition condition, gpointer data) static gboolean fifo_cb (GIOChannel *ch, GIOCondition condition, gpointer data)
{ {
@@ -353,10 +327,13 @@ static gboolean fifo_cb (GIOChannel *ch, GIOCondition condition, gpointer data)
GError *err=NULL; GError *err=NULL;
rv = g_io_channel_read_line(ch, &buf, &len, &tp, &err); rv = g_io_channel_read_line(ch, &buf, &len, &tp, &err);
if(buf) { if(buf) {
if (tp) { buf[tp]='\0'; } if(tp) {
buf[tp]='\0';
}
new_conn(buf, (GlobalInfo*)data); new_conn(buf, (GlobalInfo*)data);
g_free(buf); g_free(buf);
} else { }
else {
buf = g_malloc(BUF_SIZE+1); buf = g_malloc(BUF_SIZE+1);
while(TRUE) { while(TRUE) {
buf[BUF_SIZE]='\0'; buf[BUF_SIZE]='\0';
@@ -367,10 +344,12 @@ static gboolean fifo_cb (GIOChannel *ch, GIOCondition condition, gpointer data)
tmp=all; tmp=all;
all=g_strdup_printf("%s%s", tmp, buf); all=g_strdup_printf("%s%s", tmp, buf);
g_free(tmp); g_free(tmp);
} else { }
else {
all = g_strdup(buf); all = g_strdup(buf);
} }
} else { }
else {
break; break;
} }
} }
@@ -389,9 +368,6 @@ static gboolean fifo_cb (GIOChannel *ch, GIOCondition condition, gpointer data)
return TRUE; return TRUE;
} }
int init_fifo(void) int init_fifo(void)
{ {
struct stat st; struct stat st;
@@ -421,12 +397,8 @@ int init_fifo(void)
MSG_OUT("Now, pipe some URL's into > %s\n", fifo); MSG_OUT("Now, pipe some URL's into > %s\n", fifo);
return socket; return socket;
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
GlobalInfo *g; GlobalInfo *g;

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -362,7 +362,9 @@ static void fifo_cb(int fd, short event, void *arg)
s[n]='\0'; s[n]='\0';
if(n && s[0] ) { if(n && s[0] ) {
new_conn(s, arg); /* if we read a URL, go get it! */ new_conn(s, arg); /* if we read a URL, go get it! */
} else break; }
else
break;
} while(rv != EOF); } while(rv != EOF);
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 2012 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2012 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -38,18 +38,16 @@ uint write_cb(char *in, uint size, uint nmemb, TidyBuffer *out)
uint r; uint r;
r = size * nmemb; r = size * nmemb;
tidyBufAppend( out, in, r ); tidyBufAppend( out, in, r );
return(r); return r;
} }
/* Traverse the document tree */ /* Traverse the document tree */
void dumpNode(TidyDoc doc, TidyNode tnod, int indent ) void dumpNode(TidyDoc doc, TidyNode tnod, int indent )
{ {
TidyNode child; TidyNode child;
for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) for(child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) {
{
ctmbstr name = tidyNodeGetName( child ); ctmbstr name = tidyNodeGetName( child );
if ( name ) if(name) {
{
/* if it has a name, then it's an HTML tag ... */ /* if it has a name, then it's an HTML tag ... */
TidyAttr attr; TidyAttr attr;
printf( "%*.*s%s ", indent, indent, "<", name); printf( "%*.*s%s ", indent, indent, "<", name);
@@ -119,11 +117,11 @@ int main(int argc, char **argv )
tidyBufFree(&docbuf); tidyBufFree(&docbuf);
tidyBufFree(&tidy_errbuf); tidyBufFree(&tidy_errbuf);
tidyRelease(tdoc); tidyRelease(tdoc);
return(err); return err;
} }
else else
printf( "usage: %s <url>\n", argv[0] ); printf( "usage: %s <url>\n", argv[0] );
return(0); return 0;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -149,7 +149,7 @@ static void setup(CURL *hnd, int num)
FILE *out; FILE *out;
char filename[128]; char filename[128];
sprintf(filename, "dl-%d", num); snprintf(filename, 128, "dl-%d", num);
out = fopen(filename, "wb"); out = fopen(filename, "wb");
@@ -244,8 +244,7 @@ int main(int argc, char **argv)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -123,9 +123,11 @@ int my_trace(CURL *handle, curl_infotype type,
return 0; return 0;
} }
#define OUTPUTFILE "dl"
static void setup(CURL *hnd) static void setup(CURL *hnd)
{ {
FILE *out = fopen("dl", "wb"); FILE *out = fopen(OUTPUTFILE, "wb");
/* write to this file */ /* write to this file */
curl_easy_setopt(hnd, CURLOPT_WRITEDATA, out); curl_easy_setopt(hnd, CURLOPT_WRITEDATA, out);
@@ -167,7 +169,7 @@ static int server_push_callback(CURL *parent,
(void)parent; /* we have no use for this */ (void)parent; /* we have no use for this */
sprintf(filename, "push%u", count++); snprintf(filename, 128, "push%u", count++);
/* here's a new stream, save it in a new file for each new push */ /* here's a new stream, save it in a new file for each new push */
out = fopen(filename, "wb"); out = fopen(filename, "wb");

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -187,10 +187,10 @@ static void setup(CURL *hnd, int num, const char *upload)
struct stat file_info; struct stat file_info;
curl_off_t uploadsize; curl_off_t uploadsize;
sprintf(filename, "dl-%d", num); snprintf(filename, 128, "dl-%d", num);
out = fopen(filename, "wb"); out = fopen(filename, "wb");
sprintf(url, "https://localhost:8443/upload-%d", num); snprintf(url, 256, "https://localhost:8443/upload-%d", num);
/* get the file size of the local file */ /* get the file size of the local file */
stat(upload, &file_info); stat(upload, &file_info);
@@ -308,8 +308,7 @@ int main(int argc, char **argv)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -44,7 +44,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n", "To: " TO "\r\n",
"From: " FROM "(Example User)\r\n", "From: " FROM "(Example User)\r\n",
"Cc: " CC "(Another example User)\r\n", "Cc: " CC "(Another example User)\r\n",
"Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", "Message-ID: "
"<dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n",
"Subject: IMAP example message\r\n", "Subject: IMAP example message\r\n",
"\r\n", /* empty line to divide headers from body, see RFC5322 */ "\r\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\r\n", "The body of the message starts here.\r\n",

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -46,7 +46,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
/* This will fetch message 1 from the user's inbox */ /* This will fetch message 1 from the user's inbox */
curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/INBOX/;UID=1"); curl_easy_setopt(curl, CURLOPT_URL,
"imap://imap.example.com/INBOX/;UID=1");
/* Perform the fetch */ /* Perform the fetch */
res = curl_easy_perform(curl); res = curl_easy_perform(curl);

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -120,8 +120,7 @@ int main(void)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -48,7 +48,8 @@ int main(void)
/* This will fetch message 1 from the user's inbox. Note the use of /* This will fetch message 1 from the user's inbox. Note the use of
* imaps:// rather than imap:// to request a SSL based connection. */ * imaps:// rather than imap:// to request a SSL based connection. */
curl_easy_setopt(curl, CURLOPT_URL, "imaps://imap.example.com/INBOX/;UID=1"); curl_easy_setopt(curl, CURLOPT_URL,
"imaps://imap.example.com/INBOX/;UID=1");
/* If you want to connect to a site who isn't using a certificate that is /* If you want to connect to a site who isn't using a certificate that is
* signed by one of the certs in the CA bundle you have, you can skip the * signed by one of the certs in the CA bundle you have, you can skip the

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -47,7 +47,8 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret"); curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
/* This will fetch message 1 from the user's inbox */ /* This will fetch message 1 from the user's inbox */
curl_easy_setopt(curl, CURLOPT_URL, "imap://imap.example.com/INBOX/;UID=1"); curl_easy_setopt(curl, CURLOPT_URL,
"imap://imap.example.com/INBOX/;UID=1");
/* In this example, we'll start with a plain text connection, and upgrade /* In this example, we'll start with a plain text connection, and upgrade
* to Transport Layer Security (TLS) using the STARTTLS command. Be careful * to Transport Layer Security (TLS) using the STARTTLS command. Be careful
@@ -61,12 +62,13 @@ int main(void)
* CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to 0 (false). * CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to 0 (false).
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
*
* That is, in general, a bad idea. It is still better than sending your * That is, in general, a bad idea. It is still better than sending your
* authentication details in plain text though. * authentication details in plain text though. Instead, you should get
* Instead, you should get the issuer certificate (or the host certificate * the issuer certificate (or the host certificate if the certificate is
* if the certificate is self-signed) and add it to the set of certificates * self-signed) and add it to the set of certificates that are known to
* that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See * libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See docs/SSLCERTS
* docs/SSLCERTS for more information. */ * for more information. */
curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem"); curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");
/* Since the traffic will be encrypted, it is very useful to turn on debug /* Since the traffic will be encrypted, it is very useful to turn on debug

View File

@@ -106,8 +106,7 @@ int main(void)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -179,8 +179,7 @@ int main(void)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -95,8 +95,7 @@ int main(void)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -115,8 +115,7 @@ int main(void)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -77,8 +77,7 @@ int main(void)
/* wait for activity, timeout or "nothing" */ /* wait for activity, timeout or "nothing" */
mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds); mc = curl_multi_wait(multi_handle, NULL, 0, 1000, &numfds);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_wait() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_wait() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -84,9 +84,9 @@ void add_download(const char *url, int num)
FILE *file; FILE *file;
CURL *handle; CURL *handle;
sprintf(filename, "%d.download", num); snprintf(filename, 50, "%d.download", num);
file = fopen(filename, "w"); file = fopen(filename, "wb");
if(!file) { if(!file) {
fprintf(stderr, "Error opening %s\n", filename); fprintf(stderr, "Error opening %s\n", filename);
return; return;

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -42,7 +42,8 @@
#define THREAD_ID pthread_self( ) #define THREAD_ID pthread_self( )
void handle_error(const char *file, int lineno, const char *msg){ void handle_error(const char *file, int lineno, const char *msg)
{
fprintf(stderr, "** %s:%d %s\n", file, lineno, msg); fprintf(stderr, "** %s:%d %s\n", file, lineno, msg);
ERR_print_errors_fp(stderr); ERR_print_errors_fp(stderr);
/* exit(-1); */ /* exit(-1); */
@@ -51,7 +52,6 @@ void handle_error(const char *file, int lineno, const char *msg){
/* This array will store all of the mutexes available to OpenSSL. */ /* This array will store all of the mutexes available to OpenSSL. */
static MUTEX_TYPE *mutex_buf= NULL; static MUTEX_TYPE *mutex_buf= NULL;
static void locking_function(int mode, int n, const char * file, int line) static void locking_function(int mode, int n, const char * file, int line)
{ {
if(mode & CRYPTO_LOCK) if(mode & CRYPTO_LOCK)

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -120,8 +120,7 @@ int main(void)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -61,12 +61,13 @@ int main(void)
* CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to 0 (false). * CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST options to 0 (false).
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
*
* That is, in general, a bad idea. It is still better than sending your * That is, in general, a bad idea. It is still better than sending your
* authentication details in plain text though. * authentication details in plain text though. Instead, you should get
* Instead, you should get the issuer certificate (or the host certificate * the issuer certificate (or the host certificate if the certificate is
* if the certificate is self-signed) and add it to the set of certificates * self-signed) and add it to the set of certificates that are known to
* that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See * libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See docs/SSLCERTS
* docs/SSLCERTS for more information. */ * for more information. */
curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem"); curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");
/* Since the traffic will be encrypted, it is very useful to turn on debug /* Since the traffic will be encrypted, it is very useful to turn on debug

View File

@@ -87,7 +87,7 @@ static void rtsp_describe(CURL *curl, const char *uri,
const char *sdp_filename) const char *sdp_filename)
{ {
CURLcode res = CURLE_OK; CURLcode res = CURLE_OK;
FILE *sdp_fp = fopen(sdp_filename, "wt"); FILE *sdp_fp = fopen(sdp_filename, "wb");
printf("\nRTSP: DESCRIBE %s\n", uri); printf("\nRTSP: DESCRIBE %s\n", uri);
if(sdp_fp == NULL) { if(sdp_fp == NULL) {
fprintf(stderr, "Could not open '%s' for writing\n", sdp_filename); fprintf(stderr, "Could not open '%s' for writing\n", sdp_filename);
@@ -141,14 +141,15 @@ static void rtsp_teardown(CURL *curl, const char *uri)
/* convert url into an sdp filename */ /* convert url into an sdp filename */
static void get_sdp_filename(const char *url, char *sdp_filename) static void get_sdp_filename(const char *url, char *sdp_filename,
size_t namelen)
{ {
const char *s = strrchr(url, '/'); const char *s = strrchr(url, '/');
strcpy(sdp_filename, "video.sdp"); strcpy(sdp_filename, "video.sdp");
if(s != NULL) { if(s != NULL) {
s++; s++;
if(s[0] != '\0') { if(s[0] != '\0') {
sprintf(sdp_filename, "%s.sdp", s); snprintf(sdp_filename, namelen, "%s.sdp", s);
} }
} }
} }
@@ -160,7 +161,7 @@ static void get_media_control_attribute(const char *sdp_filename,
{ {
int max_len = 256; int max_len = 256;
char *s = malloc(max_len); char *s = malloc(max_len);
FILE *sdp_fp = fopen(sdp_filename, "rt"); FILE *sdp_fp = fopen(sdp_filename, "rb");
control[0] = '\0'; control[0] = '\0';
if(sdp_fp != NULL) { if(sdp_fp != NULL) {
while(fgets(s, max_len - 2, sdp_fp) != NULL) { while(fgets(s, max_len - 2, sdp_fp) != NULL) {
@@ -178,7 +179,8 @@ int main(int argc, char * const argv[])
#if 1 #if 1
const char *transport = "RTP/AVP;unicast;client_port=1234-1235"; /* UDP */ const char *transport = "RTP/AVP;unicast;client_port=1234-1235"; /* UDP */
#else #else
const char *transport = "RTP/AVP/TCP;unicast;client_port=1234-1235"; /* TCP */ /* TCP */
const char *transport = "RTP/AVP/TCP;unicast;client_port=1234-1235";
#endif #endif
const char *range = "0.000-"; const char *range = "0.000-";
int rc = EXIT_SUCCESS; int rc = EXIT_SUCCESS;
@@ -196,22 +198,25 @@ int main(int argc, char * const argv[])
} }
if(base_name == NULL) { if(base_name == NULL) {
base_name = argv[0]; base_name = argv[0];
} else { }
else {
base_name++; base_name++;
} }
printf("Usage: %s url [transport]\n", base_name); printf("Usage: %s url [transport]\n", base_name);
printf(" url of video server\n"); printf(" url of video server\n");
printf(" transport (optional) specifier for media stream protocol\n"); printf(" transport (optional) specifier for media stream"
" protocol\n");
printf(" default transport: %s\n", transport); printf(" default transport: %s\n", transport);
printf("Example: %s rtsp://192.168.0.2/media/video1\n\n", base_name); printf("Example: %s rtsp://192.168.0.2/media/video1\n\n", base_name);
rc = EXIT_FAILURE; rc = EXIT_FAILURE;
} else { }
else {
const char *url = argv[1]; const char *url = argv[1];
char *uri = malloc(strlen(url) + 32); char *uri = malloc(strlen(url) + 32);
char *sdp_filename = malloc(strlen(url) + 32); char *sdp_filename = malloc(strlen(url) + 32);
char *control = malloc(strlen(url) + 32); char *control = malloc(strlen(url) + 32);
CURLcode res; CURLcode res;
get_sdp_filename(url, sdp_filename); get_sdp_filename(url, sdp_filename, strlen(url) + 32);
if(argc == 3) { if(argc == 3) {
transport = argv[2]; transport = argv[2];
} }
@@ -232,7 +237,7 @@ int main(int argc, char * const argv[])
my_curl_easy_setopt(curl, CURLOPT_URL, url); my_curl_easy_setopt(curl, CURLOPT_URL, url);
/* request server options */ /* request server options */
sprintf(uri, "%s", url); snprintf(uri, strlen(url) + 32, "%s", url);
rtsp_options(curl, uri); rtsp_options(curl, uri);
/* request session description and write response to sdp file */ /* request session description and write response to sdp file */
@@ -242,11 +247,11 @@ int main(int argc, char * const argv[])
get_media_control_attribute(sdp_filename, control); get_media_control_attribute(sdp_filename, control);
/* setup media stream */ /* setup media stream */
sprintf(uri, "%s/%s", url, control); snprintf(uri, strlen(url) + 32, "%s/%s", url, control);
rtsp_setup(curl, uri, transport); rtsp_setup(curl, uri, transport);
/* start playing media stream */ /* start playing media stream */
sprintf(uri, "%s/", url); snprintf(uri, strlen(url) + 32, "%s/", url);
rtsp_play(curl, uri, range); rtsp_play(curl, uri, range);
printf("Playing video, press any key to stop ..."); printf("Playing video, press any key to stop ...");
_getch(); _getch();
@@ -258,11 +263,13 @@ int main(int argc, char * const argv[])
/* cleanup */ /* cleanup */
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
curl = NULL; curl = NULL;
} else { }
else {
fprintf(stderr, "curl_easy_init() failed\n"); fprintf(stderr, "curl_easy_init() failed\n");
} }
curl_global_cleanup(); curl_global_cleanup();
} else { }
else {
fprintf(stderr, "curl_global_init(%s) failed: %d\n", fprintf(stderr, "curl_global_init(%s) failed: %d\n",
"CURL_GLOBAL_ALL", res); "CURL_GLOBAL_ALL", res);
} }

View File

@@ -50,9 +50,10 @@ CURLcode my_conv_from_ascii_to_ebcdic(char *buffer, size_t length)
tempptrin = tempptrout = buffer; tempptrin = tempptrout = buffer;
rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes); rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes);
if(rc == PLATFORM_CONV_OK) { if(rc == PLATFORM_CONV_OK) {
return(CURLE_OK); return CURLE_OK;
} else { }
return(CURLE_CONV_FAILED); else {
return CURLE_CONV_FAILED;
} }
} }
@@ -64,9 +65,10 @@ CURLcode my_conv_from_ebcdic_to_ascii(char *buffer, size_t length)
tempptrin = tempptrout = buffer; tempptrin = tempptrout = buffer;
rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes); rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes);
if(rc == PLATFORM_CONV_OK) { if(rc == PLATFORM_CONV_OK) {
return(CURLE_OK); return CURLE_OK;
} else { }
return(CURLE_CONV_FAILED); else {
return CURLE_CONV_FAILED;
} }
} }
@@ -78,9 +80,10 @@ CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length)
tempptrin = tempptrout = buffer; tempptrin = tempptrout = buffer;
rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes); rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes);
if(rc == PLATFORM_CONV_OK) { if(rc == PLATFORM_CONV_OK) {
return(CURLE_OK); return CURLE_OK;
} else { }
return(CURLE_CONV_FAILED); else {
return CURLE_CONV_FAILED;
} }
} }

View File

@@ -44,12 +44,10 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
FD_SET(sockfd, &errfd); /* always check for error */ FD_SET(sockfd, &errfd); /* always check for error */
if(for_recv) if(for_recv) {
{
FD_SET(sockfd, &infd); FD_SET(sockfd, &infd);
} }
else else {
{
FD_SET(sockfd, &outfd); FD_SET(sockfd, &outfd);
} }
@@ -84,8 +82,7 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if(CURLE_OK != res) if(CURLE_OK != res) {
{
printf("Error: %s\n", strerror(res)); printf("Error: %s\n", strerror(res));
return 1; return 1;
} }
@@ -96,8 +93,7 @@ int main(void)
*/ */
res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr); res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);
if(CURLE_OK != res) if(CURLE_OK != res) {
{
printf("Error: %s\n", curl_easy_strerror(res)); printf("Error: %s\n", curl_easy_strerror(res));
return 1; return 1;
} }
@@ -105,8 +101,7 @@ int main(void)
sockfd = sockextr; sockfd = sockextr;
/* wait for the socket to become ready for sending */ /* wait for the socket to become ready for sending */
if(!wait_on_socket(sockfd, 0, 60000L)) if(!wait_on_socket(sockfd, 0, 60000L)) {
{
printf("Error: timeout.\n"); printf("Error: timeout.\n");
return 1; return 1;
} }
@@ -116,16 +111,14 @@ int main(void)
* to see if all the request has been sent */ * to see if all the request has been sent */
res = curl_easy_send(curl, request, strlen(request), &iolen); res = curl_easy_send(curl, request, strlen(request), &iolen);
if(CURLE_OK != res) if(CURLE_OK != res) {
{
printf("Error: %s\n", curl_easy_strerror(res)); printf("Error: %s\n", curl_easy_strerror(res));
return 1; return 1;
} }
puts("Reading response."); puts("Reading response.");
/* read the response */ /* read the response */
for(;;) for(;;) {
{
char buf[1024]; char buf[1024];
wait_on_socket(sockfd, 1, 60000L); wait_on_socket(sockfd, 1, 60000L);

View File

@@ -55,6 +55,7 @@ int main(void)
static const char *pCertFile = "testcert.pem"; static const char *pCertFile = "testcert.pem";
static const char *pCACertFile="cacert.pem"; static const char *pCACertFile="cacert.pem";
static const char *pHeaderFile = "dumpit"
const char *pKeyName; const char *pKeyName;
const char *pKeyType; const char *pKeyType;
@@ -71,7 +72,7 @@ int main(void)
pEngine = NULL; pEngine = NULL;
#endif #endif
headerfile = fopen("dumpit", "w"); headerfile = fopen(pHeaderFile, "wb");
curl_global_init(CURL_GLOBAL_DEFAULT); curl_global_init(CURL_GLOBAL_DEFAULT);
@@ -81,17 +82,16 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://your.favourite.ssl.site"); curl_easy_setopt(curl, CURLOPT_URL, "HTTPS://your.favourite.ssl.site");
curl_easy_setopt(curl, CURLOPT_HEADERDATA, headerfile); curl_easy_setopt(curl, CURLOPT_HEADERDATA, headerfile);
for(i = 0; i < 1; i++) /* single-iteration loop, just to break out from */ do { /* dummy loop, just to break out from */
{ if(pEngine) {
if (pEngine) /* use crypto engine */ /* use crypto engine */
{ if(curl_easy_setopt(curl, CURLOPT_SSLENGINE, pEngine) != CURLE_OK) {
if (curl_easy_setopt(curl, CURLOPT_SSLENGINE,pEngine) != CURLE_OK) /* load the crypto engine */
{ /* load the crypto engine */
fprintf(stderr, "can't set crypto engine\n"); fprintf(stderr, "can't set crypto engine\n");
break; break;
} }
if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT,1L) != CURLE_OK) if(curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) != CURLE_OK) {
{ /* set the crypto engine as default */ /* set the crypto engine as default */
/* only needed for the first time you load /* only needed for the first time you load
a engine in a curl object... */ a engine in a curl object... */
fprintf(stderr, "can't set crypto engine as default\n"); fprintf(stderr, "can't set crypto engine as default\n");
@@ -134,7 +134,7 @@ int main(void)
} }
/* always cleanup */ /* always cleanup */
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} } while(0);
curl_global_cleanup(); curl_global_cleanup();

View File

@@ -74,8 +74,7 @@ void *pull_one_url(void *NaN)
/* Stop threads from entering unless j is incremented */ /* Stop threads from entering unless j is incremented */
pthread_mutex_lock(&lock); pthread_mutex_lock(&lock);
while ( j < num_urls ) while(j < num_urls) {
{
printf("j = %d\n", j); printf("j = %d\n", j);
http = http =
@@ -85,11 +84,9 @@ void *pull_one_url(void *NaN)
printf( "http %s", http ); printf( "http %s", http );
curl = curl_easy_init(); curl = curl_easy_init();
if(curl) if(curl) {
{
outfile = fopen(urls[j], "w"); outfile = fopen(urls[j], "wb");
/* printf("fopen\n"); */
/* Set the URL and transfer type */ /* Set the URL and transfer type */
curl_easy_setopt(curl, CURLOPT_URL, http); curl_easy_setopt(curl, CURLOPT_URL, http);
@@ -228,4 +225,3 @@ int main(int argc, char **argv)
return 0; return 0;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -45,7 +45,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n", "To: " TO "\r\n",
"From: " FROM "(Example User)\r\n", "From: " FROM "(Example User)\r\n",
"Cc: " CC "(Another example User)\r\n", "Cc: " CC "(Another example User)\r\n",
"Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
"rfcpedant.example.org>\r\n",
"Subject: SMTP example message\r\n", "Subject: SMTP example message\r\n",
"\r\n", /* empty line to divide headers from body, see RFC5322 */ "\r\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\r\n", "The body of the message starts here.\r\n",
@@ -95,11 +96,12 @@ int main(void)
/* This is the URL for your mailserver */ /* This is the URL for your mailserver */
curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
/* Note that this option isn't strictly required, omitting it will result in /* Note that this option isn't strictly required, omitting it will result
* libcurl sending the MAIL FROM command with empty sender data. All * in libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be directed * autoresponses should have an empty reverse-path, and should be directed
* to the address in the reverse-path which triggered them. Otherwise, they * to the address in the reverse-path which triggered them. Otherwise,
* could cause an endless loop. See RFC 5321 Section 4.5.5 for more details. * they could cause an endless loop. See RFC 5321 Section 4.5.5 for more
* details.
*/ */
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM); curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
@@ -128,13 +130,13 @@ int main(void)
/* Free the list of recipients */ /* Free the list of recipients */
curl_slist_free_all(recipients); curl_slist_free_all(recipients);
/* curl won't send the QUIT command until you call cleanup, so you should be /* curl won't send the QUIT command until you call cleanup, so you should
* able to re-use this connection for additional messages (setting * be able to re-use this connection for additional messages (setting
* CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling * CURLOPT_MAIL_FROM and CURLOPT_MAIL_RCPT as required, and calling
* curl_easy_perform() again. It may not be a good idea to keep the * curl_easy_perform() again. It may not be a good idea to keep the
* connection open for a very long time though (more than a few minutes may * connection open for a very long time though (more than a few minutes
* result in the server timing out the connection), and you do want to clean * may result in the server timing out the connection), and you do want to
* up in the end. * clean up in the end.
*/ */
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -46,7 +46,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n", "To: " TO "\r\n",
"From: " FROM "(Example User)\r\n", "From: " FROM "(Example User)\r\n",
"Cc: " CC "(Another example User)\r\n", "Cc: " CC "(Another example User)\r\n",
"Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
"rfcpedant.example.org>\r\n",
"Subject: SMTP multi example message\r\n", "Subject: SMTP multi example message\r\n",
"\r\n", /* empty line to divide headers from body, see RFC5322 */ "\r\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\r\n", "The body of the message starts here.\r\n",
@@ -186,8 +187,7 @@ int main(void)
/* get file descriptors from the transfers */ /* get file descriptors from the transfers */
mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd); mc = curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK) if(mc != CURLM_OK) {
{
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break; break;
} }

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -46,7 +46,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n", "To: " TO "\r\n",
"From: " FROM "(Example User)\r\n", "From: " FROM "(Example User)\r\n",
"Cc: " CC "(Another example User)\r\n", "Cc: " CC "(Another example User)\r\n",
"Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
"rfcpedant.example.org>\r\n",
"Subject: SMTP SSL example message\r\n", "Subject: SMTP SSL example message\r\n",
"\r\n", /* empty line to divide headers from body, see RFC5322 */ "\r\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\r\n", "The body of the message starts here.\r\n",
@@ -121,11 +122,12 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif #endif
/* Note that this option isn't strictly required, omitting it will result in /* Note that this option isn't strictly required, omitting it will result
* libcurl sending the MAIL FROM command with empty sender data. All * in libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be directed * autoresponses should have an empty reverse-path, and should be directed
* to the address in the reverse-path which triggered them. Otherwise, they * to the address in the reverse-path which triggered them. Otherwise,
* could cause an endless loop. See RFC 5321 Section 4.5.5 for more details. * they could cause an endless loop. See RFC 5321 Section 4.5.5 for more
* details.
*/ */
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM); curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -46,7 +46,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n", "To: " TO "\r\n",
"From: " FROM "(Example User)\r\n", "From: " FROM "(Example User)\r\n",
"Cc: " CC "(Another example User)\r\n", "Cc: " CC "(Another example User)\r\n",
"Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>\r\n", "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
"rfcpedant.example.org>\r\n",
"Subject: SMTP TLS example message\r\n", "Subject: SMTP TLS example message\r\n",
"\r\n", /* empty line to divide headers from body, see RFC5322 */ "\r\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\r\n", "The body of the message starts here.\r\n",
@@ -116,18 +117,19 @@ int main(void)
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); * curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
* That is, in general, a bad idea. It is still better than sending your * That is, in general, a bad idea. It is still better than sending your
* authentication details in plain text though. * authentication details in plain text though. Instead, you should get
* Instead, you should get the issuer certificate (or the host certificate * the issuer certificate (or the host certificate if the certificate is
* if the certificate is self-signed) and add it to the set of certificates * self-signed) and add it to the set of certificates that are known to
* that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See * libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See docs/SSLCERTS
* docs/SSLCERTS for more information. */ * for more information. */
curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem"); curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");
/* Note that this option isn't strictly required, omitting it will result in /* Note that this option isn't strictly required, omitting it will result
* libcurl sending the MAIL FROM command with empty sender data. All * in libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be directed * autoresponses should have an empty reverse-path, and should be directed
* to the address in the reverse-path which triggered them. Otherwise, they * to the address in the reverse-path which triggered them. Otherwise,
* could cause an endless loop. See RFC 5321 Section 4.5.5 for more details. * they could cause an endless loop. See RFC 5321 Section 4.5.5 for more
* details.
*/ */
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM); curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);

View File

@@ -157,7 +157,6 @@ size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb,
&SYSTime.wHour, &SYSTime.wMinute, &SYSTime.wSecond); &SYSTime.wHour, &SYSTime.wMinute, &SYSTime.wSecond);
if(RetVal == 7) { if(RetVal == 7) {
SYSTime.wMilliseconds = 500; /* adjust to midpoint, 0.5 sec */ SYSTime.wMilliseconds = 500; /* adjust to midpoint, 0.5 sec */
for(i=0; i<12; i++) { for(i=0; i<12; i++) {
if(strcmp(MthStr[i], TmpStr2) == 0) { if(strcmp(MthStr[i], TmpStr2) == 0) {

View File

@@ -64,7 +64,7 @@ static unsigned long thread_id(void)
unsigned long ret; unsigned long ret;
ret=(unsigned long)pthread_self(); ret=(unsigned long)pthread_self();
return(ret); return ret;
} }
static void init_locks(void) static void init_locks(void)

View File

@@ -184,9 +184,9 @@ int main(void)
rv = curl_easy_setopt(ch, CURLOPT_HEADER, 0L); rv = curl_easy_setopt(ch, CURLOPT_HEADER, 0L);
rv = curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L); rv = curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L);
rv = curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L); rv = curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L);
rv = curl_easy_setopt(ch,CURLOPT_WRITEFUNCTION, *writefunction); rv = curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, writefunction);
rv = curl_easy_setopt(ch, CURLOPT_WRITEDATA, stdout); rv = curl_easy_setopt(ch, CURLOPT_WRITEDATA, stdout);
rv = curl_easy_setopt(ch,CURLOPT_HEADERFUNCTION, *writefunction); rv = curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, writefunction);
rv = curl_easy_setopt(ch, CURLOPT_HEADERDATA, stderr); rv = curl_easy_setopt(ch, CURLOPT_HEADERDATA, stderr);
rv = curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM"); rv = curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM");

View File

@@ -51,7 +51,8 @@ struct ParserStruct {
struct MemoryStruct characters; struct MemoryStruct characters;
}; };
static void startElement(void *userData, const XML_Char *name, const XML_Char **atts) static void startElement(void *userData, const XML_Char *name,
const XML_Char **atts)
{ {
struct ParserStruct *state = (struct ParserStruct *) userData; struct ParserStruct *state = (struct ParserStruct *) userData;
state->tags++; state->tags++;
@@ -89,7 +90,8 @@ static void endElement(void *userData, const XML_Char *name)
printf("%5lu %10lu %s\n", state->depth, state->characters.size, name); printf("%5lu %10lu %s\n", state->depth, state->characters.size, name);
} }
static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb, void *userp) static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb,
void *userp)
{ {
XML_Parser parser = (XML_Parser) userp; XML_Parser parser = (XML_Parser) userp;
size_t real_size = length * nmemb; size_t real_size = length * nmemb;
@@ -98,7 +100,8 @@ static size_t parseStreamCallback(void *contents, size_t length, size_t nmemb, v
/* Only parse if we're not already in a failure state. */ /* Only parse if we're not already in a failure state. */
if(state->ok && XML_Parse(parser, contents, real_size, 0) == 0) { if(state->ok && XML_Parse(parser, contents, real_size, 0) == 0) {
int error_code = XML_GetErrorCode(parser); int error_code = XML_GetErrorCode(parser);
fprintf(stderr, "Parsing response buffer of length %lu failed with error code %d (%s).\n", fprintf(stderr, "Parsing response buffer of length %lu failed"
" with error code %d (%s).\n",
real_size, error_code, XML_ErrorString(error_code)); real_size, error_code, XML_ErrorString(error_code));
state->ok = 0; state->ok = 0;
} }
@@ -126,7 +129,8 @@ int main(void)
/* Initialize a libcurl handle. */ /* Initialize a libcurl handle. */
curl_global_init(CURL_GLOBAL_ALL ^ CURL_GLOBAL_SSL); curl_global_init(CURL_GLOBAL_ALL ^ CURL_GLOBAL_SSL);
curl_handle = curl_easy_init(); curl_handle = curl_easy_init();
curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.w3schools.com/xml/simple.xml"); curl_easy_setopt(curl_handle, CURLOPT_URL,
"http://www.w3schools.com/xml/simple.xml");
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, parseStreamCallback); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, parseStreamCallback);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)parser); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)parser);