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
* you should have received as part of this distribution. The terms
@ -157,7 +157,8 @@ int main(void)
#else
sleep(L / 1000);
#endif
} else {
}
else {
T.tv_sec = L/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
* 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
* 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
* 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",
appname);
exit(1);
} else if (strncasecmp(*argv, "-V", 2) == 0) {
}
else if(strncasecmp(*argv, "-V", 2) == 0) {
fprintf(stderr, "\r%s %s - %s\n",
appname, CHKSPEED_VERSION, curl_version());
exit(1);
} else if (strncasecmp(*argv, "-A", 2) == 0) {
}
else if(strncasecmp(*argv, "-A", 2) == 0) {
prtall = 1;
} else if (strncasecmp(*argv, "-X", 2) == 0) {
}
else if(strncasecmp(*argv, "-X", 2) == 0) {
prtsep = 1;
} else if (strncasecmp(*argv, "-T", 2) == 0) {
}
else if(strncasecmp(*argv, "-T", 2) == 0) {
prttime = 1;
} else if (strncasecmp(*argv, "-M=", 3) == 0) {
}
else if(strncasecmp(*argv, "-M=", 3) == 0) {
long m = strtol((*argv)+3, NULL, 10);
switch(m) {
case 1: url = URL_1M;
case 1:
url = URL_1M;
break;
case 2: url = URL_2M;
case 2:
url = URL_2M;
break;
case 5: url = URL_5M;
case 5:
url = URL_5M;
break;
case 10: url = URL_10M;
case 10:
url = URL_10M;
break;
case 20: url = URL_20M;
case 20:
url = URL_20M;
break;
case 50: url = URL_50M;
case 50:
url = URL_50M;
break;
case 100: url = URL_100M;
case 100:
url = URL_100M;
break;
default: fprintf(stderr, "\r%s: invalid parameter %s\n",
default:
fprintf(stderr, "\r%s: invalid parameter %s\n",
appname, *argv + 3);
exit(1);
}
} else {
}
else {
fprintf(stderr, "\r%s: invalid or unknown option %s\n",
appname, *argv);
exit(1);
}
} else {
}
else {
url = *argv;
}
}
@ -178,8 +193,8 @@ int main(int argc, char *argv[])
if((CURLE_OK == res) && (val>0))
printf("Connect time: %0.3f sec.\n", val);
}
} else {
}
else {
fprintf(stderr, "Error while fetching '%s' : %s\n",
url, curl_easy_strerror(res));
}

View File

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

View File

@ -101,13 +101,18 @@
static const char *curlx_usage[]={
"usage: curlx args\n",
" -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",
" -in arg - input file (request)- default stdin",
" -connect arg - URL of the server for the connection ex: www.openevidence.org",
" -mimetype arg - MIME type for data in ex : application/timestamp-query or application/dvcs -default application/timestamp-query",
" -acceptmime arg - MIME type acceptable for the response ex : application/timestamp-response or application/dvcs -default none",
" -accesstype arg - an Object identifier in an AIA/SIA method, e.g. AD_DVCS or ad_timestamping",
" -connect arg - URL of the server for the connection ex:"
" www.openevidence.org",
" -mimetype arg - MIME type for data in ex : application/timestamp-query"
" or application/dvcs -default application/timestamp-query",
" -acceptmime arg - MIME type acceptable for the response ex : "
"application/timestamp-response or application/dvcs -default none",
" -accesstype arg - an Object identifier in an AIA/SIA method, e.g."
" AD_DVCS or ad_timestamping",
NULL
};
@ -155,9 +160,9 @@ static char *i2s_ASN1_IA5STRING( ASN1_IA5STRING *ia5)
}
/* A conveniance routine to get an access URI. */
static unsigned char *my_get_ext(X509 * cert, const int type, int extensiontype) {
static unsigned char *my_get_ext(X509 * cert, const int type,
int extensiontype)
{
int i;
STACK_OF(ACCESS_DESCRIPTION) * accessinfo;
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)
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 trusted ca certificate
- a preferred cipherlist
@ -228,21 +234,25 @@ static CURLcode sslctxfun(CURL * curl, void * sslctx, void * parm) {
SSL_CTX * ctx = (SSL_CTX *) sslctx;
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)) {
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)) {
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_cipher_list(ctx, "RC4-MD5");
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);
@ -302,42 +312,70 @@ int main(int argc, char **argv) {
if(!strcmp (*args, "-in")) {
if(args[1]) {
infile=*(++args);
} else badarg=1;
} else if (!strcmp (*args, "-out")) {
}
else
badarg=1;
}
else if(!strcmp (*args, "-out")) {
if(args[1]) {
outfile=*(++args);
} else badarg=1;
} else if (!strcmp (*args, "-p12")) {
}
else
badarg=1;
}
else if(!strcmp (*args, "-p12")) {
if(args[1]) {
p.p12file = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-envpass") == 0) {
}
else
badarg=1;
}
else if(strcmp(*args, "-envpass") == 0) {
if(args[1]) {
p.pst = getenv(*(++args));
} else badarg=1;
} else if (strcmp(*args,"-connect") == 0) {
}
else
badarg=1;
}
else if(strcmp(*args, "-connect") == 0) {
if(args[1]) {
hostporturl = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-mimetype") == 0) {
}
else
badarg=1;
}
else if(strcmp(*args, "-mimetype") == 0) {
if(args[1]) {
mimetype = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-acceptmime") == 0) {
}
else
badarg=1;
}
else if(strcmp(*args, "-acceptmime") == 0) {
if(args[1]) {
mimetypeaccept = *(++args);
} else badarg=1;
} else if (strcmp(*args,"-accesstype") == 0) {
}
else
badarg=1;
}
else if(strcmp(*args, "-accesstype") == 0) {
if(args[1]) {
if ((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args,0))) == 0) badarg=1;
} else badarg=1;
} else if (strcmp(*args,"-verbose") == 0) {
if((p.accesstype = OBJ_obj2nid(OBJ_txt2obj(*++args, 0))) == 0)
badarg=1;
}
else
badarg=1;
}
else if(strcmp(*args, "-verbose") == 0) {
p.verbose++;
} else badarg=1;
}
else
badarg=1;
args++;
}
if (mimetype==NULL || mimetypeaccept == NULL) badarg = 1;
if(mimetype==NULL || mimetypeaccept == NULL)
badarg = 1;
if(badarg) {
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) {
BIO_printf(p.errorbio, "Error setting input bio\n");
goto err;
} else if (infile == NULL)
}
else if(infile == NULL)
BIO_set_fp(in, stdin, BIO_NOCLOSE|BIO_FP_TEXT);
else if(BIO_read_filename(in, infile) <= 0) {
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) {
BIO_printf(p.errorbio, "Error setting output bio.\n");
goto err;
} else if (outfile == NULL)
}
else if(outfile == NULL)
BIO_set_fp(out, stdout, BIO_NOCLOSE|BIO_FP_TEXT);
else if(BIO_write_filename(out, outfile) <= 0) {
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"))) {
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))) {
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;
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) {
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)
@ -406,10 +450,12 @@ int main(int argc, char **argv) {
/* determine URL to go */
if(hostporturl) {
serverurl = malloc(9+strlen(hostporturl));
sprintf(serverurl,"https://%s",hostporturl);
size_t len = strlen(hostporturl) + 9;
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))) {
int j=0;
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 */
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);
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);
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);

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
* 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
* 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);
ev_timer_stop(g->loop, &g->timer_event);
if (timeout_ms > 0)
{
if(timeout_ms > 0) {
double t = timeout_ms / 1000;
ev_timer_init(&g->timer_event, timer_cb, t, 0.);
ev_timer_start(g->loop, &g->timer_event);
}else
}
else
timer_cb(g->loop, &g->timer_event, 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 */
static void mcode_or_die(const char *where, CURLMcode code)
{
if ( CURLM_OK != code )
{
if(CURLM_OK != code) {
const char *s;
switch ( code )
{
case CURLM_BAD_HANDLE: s="CURLM_BAD_HANDLE"; break;
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";
switch (code) {
case CURLM_BAD_HANDLE:
s="CURLM_BAD_HANDLE";
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);
/* ignore this error */
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);
mcode_or_die("event_cb: curl_multi_socket_action", rc);
check_multi_info(g);
if ( g->still_running <= 0 )
{
if(g->still_running <= 0) {
fprintf(MSG_OUT, "last transfer done, kill timeout\n");
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;
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);
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)
{
printf("%s \n", __PRETTY_FUNCTION__);
if ( f )
{
if(f) {
if(f->evset)
ev_io_stop(g->loop, &f->ev);
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,
"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");
remsock(fdp, g);
} else
{
if ( !fdp )
{
}
else {
if(!fdp) {
fprintf(MSG_OUT, "Adding data: %s\n", whatstr[what]);
addsock(s, e, what, g);
} else
{
}
else {
fprintf(MSG_OUT,
"Changing action from %s to %s\n",
whatstr[fdp->action], whatstr[what]);
@ -330,8 +339,7 @@ static void new_conn(char *url, GlobalInfo *g )
conn->error[0]='\0';
conn->easy = curl_easy_init();
if ( !conn->easy )
{
if(!conn->easy) {
fprintf(MSG_OUT, "curl_easy_init() failed, exiting!\n");
exit(2);
}
@ -366,15 +374,15 @@ static void fifo_cb(EV_P_ struct ev_io *w, int revents)
int n=0;
GlobalInfo *g = (GlobalInfo *)w->data;
do
{
do {
s[0]='\0';
rv=fscanf(g->input, "%1023s%n", s, &n);
s[n]='\0';
if ( n && s[0] )
{
if(n && s[0]) {
new_conn(s, g); /* if we read a URL, go get it! */
} else break;
}
else
break;
} while(rv != EOF);
}
@ -386,24 +394,20 @@ static int init_fifo (GlobalInfo *g)
curl_socket_t sockfd;
fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo);
if ( lstat (fifo, &st) == 0 )
{
if ( (st.st_mode & S_IFMT) == S_IFREG )
{
if(lstat (fifo, &st) == 0) {
if((st.st_mode & S_IFMT) == S_IFREG) {
errno = EEXIST;
perror("lstat");
exit (1);
}
}
unlink(fifo);
if ( mkfifo (fifo, 0600) == -1 )
{
if(mkfifo (fifo, 0600) == -1) {
perror("mkfifo");
exit (1);
}
sockfd = open(fifo, O_RDWR | O_NONBLOCK, 0);
if ( sockfd == -1 )
{
if(sockfd == -1) {
perror("open");
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
* 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 */
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);
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
* output to two test files (note the fgets method will corrupt binary files if
* they contain 0 chars */
@ -465,7 +468,7 @@ int main(int argc, char *argv[])
url=argv[1];/* use passed url */
/* copy from url line by line with fgets */
outf=fopen("fgets.test","w+");
outf=fopen(FGETSFILE, "wb+");
if(!outf) {
perror("couldn't open fgets output file\n");
return 1;
@ -489,7 +492,7 @@ int main(int argc, char *argv[])
/* Copy from url with fread */
outf=fopen("fread.test","w+");
outf=fopen(FREADFILE, "wb+");
if(!outf) {
perror("couldn't open fread output file\n");
return 1;
@ -513,7 +516,7 @@ int main(int argc, char *argv[])
/* Test rewind */
outf=fopen("rewind.test","w+");
outf=fopen(REWINDFILE, "wb+");
if(!outf) {
perror("couldn't open fread output file\n");
return 1;
@ -536,11 +539,9 @@ int main(int argc, char *argv[])
nread = url_fread(buffer, 1, sizeof(buffer), handle);
fwrite(buffer, 1, nread, outf);
url_fclose(handle);
fclose(outf);
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
* 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;
}
data->output = fopen(finfo->filename, "w");
data->output = fopen(finfo->filename, "wb");
if(!data->output) {
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
* 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!
*/
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 */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
/* 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
* 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;
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))
printf("filesize %s: %0.0f bytes\n", filename, filesize);
} else {
}
else {
/* we failed */
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
* 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);
}
#define FTPBODY "ftp-list"
#define FTPHEADERS "ftp-responses"
int main(void)
{
CURL *curl;
@ -43,10 +46,10 @@ int main(void)
FILE *respfile;
/* 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 */
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();
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
* 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
* 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,
you shouldn't need this if you use VC++ */
#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
@ -85,7 +86,7 @@ int upload(CURL *curlhandle, const char * remotepath, const char * localpath,
int c;
f = fopen(localpath, "rb");
if (f == NULL) {
if(!f) {
perror(NULL);
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_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_VERBOSE, 1L);
@ -161,7 +163,8 @@ int main(int c, char **argv)
curl_global_init(CURL_GLOBAL_ALL);
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_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
* you should have received as part of this distribution. The terms
@ -54,7 +54,6 @@ callback.
*/
#include <glib.h>
#include <sys/stat.h>
#include <unistd.h>
@ -64,13 +63,10 @@ callback.
#include <errno.h>
#include <curl/curl.h>
#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_PROGRESS 0 /* Set to non-zero to enable progress callback */
/* Global information, common to all connections */
typedef struct _GlobalInfo {
CURLM *multi;
@ -78,8 +74,6 @@ typedef struct _GlobalInfo {
int still_running;
} GlobalInfo;
/* Information associated with a specific easy handle */
typedef struct _ConnInfo {
CURL *easy;
@ -88,7 +82,6 @@ typedef struct _ConnInfo {
char error[CURL_ERROR_SIZE];
} ConnInfo;
/* Information associated with a specific socket */
typedef struct _SockInfo {
curl_socket_t sockfd;
@ -100,9 +93,6 @@ typedef struct _SockInfo {
GlobalInfo *global;
} SockInfo;
/* Die if we get a bad CURLMcode somewhere */
static void mcode_or_die(const char *where, CURLMcode 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 */
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 */
static gboolean timer_cb(gpointer data)
{
@ -165,8 +151,6 @@ static gboolean timer_cb(gpointer data)
return FALSE;
}
/* Update the event timer after curl_multi library calls */
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;
}
/* Called by glib when we get action on a multi socket */
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);
if(g->still_running) {
return TRUE;
} else {
}
else {
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;
}
}
/* Clean up the SockInfo structure */
static void remsock(SockInfo *f)
{
if (!f) { return; }
if (f->ev) { g_source_remove(f->ev); }
if(!f) {
return;
}
if(f->ev) {
g_source_remove(f->ev);
}
g_free(f);
}
/* Assign information to a SockInfo structure */
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->action = act;
f->easy = e;
if (f->ev) { g_source_remove(f->ev); }
f->ev=g_io_add_watch(f->ch, kind, event_cb,g);
if(f->ev) {
g_source_remove(f->ev);
}
f->ev=g_io_add_watch(f->ch, kind, event_cb, g);
}
/* Initialize a new SockInfo structure */
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);
}
/* CURLMOPT_SOCKETFUNCTION */
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) {
MSG_OUT("\n");
remsock(fdp);
} else {
}
else {
if(!fdp) {
MSG_OUT("Adding data: %s%s\n",
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;
}
/* CURLOPT_WRITEFUNCTION */
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;
}
/* 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;
MSG_OUT("Progress: %s (%g/%g)\n", conn->url, dlnow, dltotal);
return 0;
}
/* Create a new easy handle, and add it to the global curl_multi */
static void new_conn(char *url, GlobalInfo *g )
{
@ -308,9 +285,7 @@ static void new_conn(char *url, GlobalInfo *g )
CURLMcode rc;
conn = g_malloc0(sizeof(ConnInfo));
conn->error[0]='\0';
conn->easy = curl_easy_init();
if(!conn->easy) {
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 */
}
/* This gets called by glib whenever data is received from the fifo */
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;
rv = g_io_channel_read_line(ch, &buf, &len, &tp, &err);
if(buf) {
if (tp) { buf[tp]='\0'; }
if(tp) {
buf[tp]='\0';
}
new_conn(buf, (GlobalInfo*)data);
g_free(buf);
} else {
}
else {
buf = g_malloc(BUF_SIZE+1);
while(TRUE) {
buf[BUF_SIZE]='\0';
@ -367,10 +344,12 @@ static gboolean fifo_cb (GIOChannel *ch, GIOCondition condition, gpointer data)
tmp=all;
all=g_strdup_printf("%s%s", tmp, buf);
g_free(tmp);
} else {
}
else {
all = g_strdup(buf);
}
} else {
}
else {
break;
}
}
@ -389,9 +368,6 @@ static gboolean fifo_cb (GIOChannel *ch, GIOCondition condition, gpointer data)
return TRUE;
}
int init_fifo(void)
{
struct stat st;
@ -421,12 +397,8 @@ int init_fifo(void)
MSG_OUT("Now, pipe some URL's into > %s\n", fifo);
return socket;
}
int main(int argc, char **argv)
{
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
* 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';
if(n && s[0] ) {
new_conn(s, arg); /* if we read a URL, go get it! */
} else break;
}
else
break;
} 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
* 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
* 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;
r = size * nmemb;
tidyBufAppend( out, in, r );
return(r);
return r;
}
/* Traverse the document tree */
void dumpNode(TidyDoc doc, TidyNode tnod, int indent )
{
TidyNode child;
for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) )
{
for(child = tidyGetChild(tnod); child; child = tidyGetNext(child) ) {
ctmbstr name = tidyNodeGetName( child );
if ( name )
{
if(name) {
/* if it has a name, then it's an HTML tag ... */
TidyAttr attr;
printf( "%*.*s%s ", indent, indent, "<", name);
@ -119,11 +117,11 @@ int main(int argc, char **argv )
tidyBufFree(&docbuf);
tidyBufFree(&tidy_errbuf);
tidyRelease(tdoc);
return(err);
return err;
}
else
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
* you should have received as part of this distribution. The terms
@ -149,7 +149,7 @@ static void setup(CURL *hnd, int num)
FILE *out;
char filename[128];
sprintf(filename, "dl-%d", num);
snprintf(filename, 128, "dl-%d", num);
out = fopen(filename, "wb");
@ -244,8 +244,7 @@ int main(int argc, char **argv)
/* get file descriptors from the transfers */
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);
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
* 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;
}
#define OUTPUTFILE "dl"
static void setup(CURL *hnd)
{
FILE *out = fopen("dl", "wb");
FILE *out = fopen(OUTPUTFILE, "wb");
/* write to this file */
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 */
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 */
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
* 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;
curl_off_t uploadsize;
sprintf(filename, "dl-%d", num);
snprintf(filename, 128, "dl-%d", num);
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 */
stat(upload, &file_info);
@ -308,8 +308,7 @@ int main(int argc, char **argv)
/* get file descriptors from the transfers */
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);
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
* 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
* you should have received as part of this distribution. The terms
@ -44,7 +44,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n",
"From: " FROM "(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",
"\r\n", /* empty line to divide headers from body, see RFC5322 */
"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
* 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");
/* 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 */
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
* you should have received as part of this distribution. The terms
@ -120,8 +120,7 @@ int main(void)
/* get file descriptors from the transfers */
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);
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
* 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
* 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
* 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
* 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");
/* 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
* 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).
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
*
* That is, in general, a bad idea. It is still better than sending your
* authentication details in plain text though.
* Instead, you should get the issuer certificate (or the host certificate
* if the certificate is self-signed) and add it to the set of certificates
* that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See
* docs/SSLCERTS for more information. */
* authentication details in plain text though. Instead, you should get
* the issuer certificate (or the host certificate if the certificate is
* self-signed) and add it to the set of certificates that are known to
* libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See docs/SSLCERTS
* for more information. */
curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");
/* 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 */
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);
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
* you should have received as part of this distribution. The terms
@ -179,8 +179,7 @@ int main(void)
/* get file descriptors from the transfers */
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);
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
* you should have received as part of this distribution. The terms
@ -95,8 +95,7 @@ int main(void)
/* get file descriptors from the transfers */
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);
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
* you should have received as part of this distribution. The terms
@ -115,8 +115,7 @@ int main(void)
/* get file descriptors from the transfers */
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);
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
* you should have received as part of this distribution. The terms
@ -77,8 +77,7 @@ int main(void)
/* wait for activity, timeout or "nothing" */
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);
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
* 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;
CURL *handle;
sprintf(filename, "%d.download", num);
snprintf(filename, 50, "%d.download", num);
file = fopen(filename, "w");
file = fopen(filename, "wb");
if(!file) {
fprintf(stderr, "Error opening %s\n", filename);
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
* you should have received as part of this distribution. The terms
@ -42,7 +42,8 @@
#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);
ERR_print_errors_fp(stderr);
/* 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. */
static MUTEX_TYPE *mutex_buf= NULL;
static void locking_function(int mode, int n, const char * file, int line)
{
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
* you should have received as part of this distribution. The terms
@ -120,8 +120,7 @@ int main(void)
/* get file descriptors from the transfers */
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);
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
* 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).
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
* curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
*
* That is, in general, a bad idea. It is still better than sending your
* authentication details in plain text though.
* Instead, you should get the issuer certificate (or the host certificate
* if the certificate is self-signed) and add it to the set of certificates
* that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See
* docs/SSLCERTS for more information. */
* authentication details in plain text though. Instead, you should get
* the issuer certificate (or the host certificate if the certificate is
* self-signed) and add it to the set of certificates that are known to
* libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See docs/SSLCERTS
* for more information. */
curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");
/* 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)
{
CURLcode res = CURLE_OK;
FILE *sdp_fp = fopen(sdp_filename, "wt");
FILE *sdp_fp = fopen(sdp_filename, "wb");
printf("\nRTSP: DESCRIBE %s\n", uri);
if(sdp_fp == NULL) {
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 */
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, '/');
strcpy(sdp_filename, "video.sdp");
if(s != NULL) {
s++;
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;
char *s = malloc(max_len);
FILE *sdp_fp = fopen(sdp_filename, "rt");
FILE *sdp_fp = fopen(sdp_filename, "rb");
control[0] = '\0';
if(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
const char *transport = "RTP/AVP;unicast;client_port=1234-1235"; /* UDP */
#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
const char *range = "0.000-";
int rc = EXIT_SUCCESS;
@ -196,22 +198,25 @@ int main(int argc, char * const argv[])
}
if(base_name == NULL) {
base_name = argv[0];
} else {
}
else {
base_name++;
}
printf("Usage: %s url [transport]\n", base_name);
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("Example: %s rtsp://192.168.0.2/media/video1\n\n", base_name);
rc = EXIT_FAILURE;
} else {
}
else {
const char *url = argv[1];
char *uri = malloc(strlen(url) + 32);
char *sdp_filename = malloc(strlen(url) + 32);
char *control = malloc(strlen(url) + 32);
CURLcode res;
get_sdp_filename(url, sdp_filename);
get_sdp_filename(url, sdp_filename, strlen(url) + 32);
if(argc == 3) {
transport = argv[2];
}
@ -232,7 +237,7 @@ int main(int argc, char * const argv[])
my_curl_easy_setopt(curl, CURLOPT_URL, url);
/* request server options */
sprintf(uri, "%s", url);
snprintf(uri, strlen(url) + 32, "%s", url);
rtsp_options(curl, uri);
/* 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);
/* setup media stream */
sprintf(uri, "%s/%s", url, control);
snprintf(uri, strlen(url) + 32, "%s/%s", url, control);
rtsp_setup(curl, uri, transport);
/* start playing media stream */
sprintf(uri, "%s/", url);
snprintf(uri, strlen(url) + 32, "%s/", url);
rtsp_play(curl, uri, range);
printf("Playing video, press any key to stop ...");
_getch();
@ -258,11 +263,13 @@ int main(int argc, char * const argv[])
/* cleanup */
curl_easy_cleanup(curl);
curl = NULL;
} else {
}
else {
fprintf(stderr, "curl_easy_init() failed\n");
}
curl_global_cleanup();
} else {
}
else {
fprintf(stderr, "curl_global_init(%s) failed: %d\n",
"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;
rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes);
if(rc == PLATFORM_CONV_OK) {
return(CURLE_OK);
} else {
return(CURLE_CONV_FAILED);
return CURLE_OK;
}
else {
return CURLE_CONV_FAILED;
}
}
@ -64,9 +65,10 @@ CURLcode my_conv_from_ebcdic_to_ascii(char *buffer, size_t length)
tempptrin = tempptrout = buffer;
rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes);
if(rc == PLATFORM_CONV_OK) {
return(CURLE_OK);
} else {
return(CURLE_CONV_FAILED);
return CURLE_OK;
}
else {
return CURLE_CONV_FAILED;
}
}
@ -78,9 +80,10 @@ CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length)
tempptrin = tempptrout = buffer;
rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes);
if(rc == PLATFORM_CONV_OK) {
return(CURLE_OK);
} else {
return(CURLE_CONV_FAILED);
return CURLE_OK;
}
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 */
if(for_recv)
{
if(for_recv) {
FD_SET(sockfd, &infd);
}
else
{
else {
FD_SET(sockfd, &outfd);
}
@ -84,8 +82,7 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
res = curl_easy_perform(curl);
if(CURLE_OK != res)
{
if(CURLE_OK != res) {
printf("Error: %s\n", strerror(res));
return 1;
}
@ -96,8 +93,7 @@ int main(void)
*/
res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);
if(CURLE_OK != res)
{
if(CURLE_OK != res) {
printf("Error: %s\n", curl_easy_strerror(res));
return 1;
}
@ -105,8 +101,7 @@ int main(void)
sockfd = sockextr;
/* 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");
return 1;
}
@ -116,16 +111,14 @@ int main(void)
* to see if all the request has been sent */
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));
return 1;
}
puts("Reading response.");
/* read the response */
for(;;)
{
for(;;) {
char buf[1024];
wait_on_socket(sockfd, 1, 60000L);

View File

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

View File

@ -74,8 +74,7 @@ void *pull_one_url(void *NaN)
/* Stop threads from entering unless j is incremented */
pthread_mutex_lock(&lock);
while ( j < num_urls )
{
while(j < num_urls) {
printf("j = %d\n", j);
http =
@ -85,11 +84,9 @@ void *pull_one_url(void *NaN)
printf( "http %s", http );
curl = curl_easy_init();
if(curl)
{
if(curl) {
outfile = fopen(urls[j], "w");
/* printf("fopen\n"); */
outfile = fopen(urls[j], "wb");
/* Set the URL and transfer type */
curl_easy_setopt(curl, CURLOPT_URL, http);
@ -228,4 +225,3 @@ int main(int argc, char **argv)
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
* you should have received as part of this distribution. The terms
@ -45,7 +45,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n",
"From: " FROM "(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",
"\r\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\r\n",
@ -95,11 +96,12 @@ int main(void)
/* This is the URL for your mailserver */
curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
/* Note that this option isn't strictly required, omitting it will result in
* libcurl sending the MAIL FROM command with empty sender data. All
/* Note that this option isn't strictly required, omitting it will result
* in libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be directed
* to the address in the reverse-path which triggered them. Otherwise, they
* could cause an endless loop. See RFC 5321 Section 4.5.5 for more details.
* to the address in the reverse-path which triggered them. Otherwise,
* they could cause an endless loop. See RFC 5321 Section 4.5.5 for more
* details.
*/
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
@ -128,13 +130,13 @@ int main(void)
/* Free the list of recipients */
curl_slist_free_all(recipients);
/* curl won't send the QUIT command until you call cleanup, so you should be
* able to re-use this connection for additional messages (setting
/* curl won't send the QUIT command until you call cleanup, so you should
* be able to re-use this connection for additional messages (setting
* 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
* connection open for a very long time though (more than a few minutes may
* result in the server timing out the connection), and you do want to clean
* up in the end.
* connection open for a very long time though (more than a few minutes
* may result in the server timing out the connection), and you do want to
* clean up in the end.
*/
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
* you should have received as part of this distribution. The terms
@ -46,7 +46,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n",
"From: " FROM "(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",
"\r\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\r\n",
@ -186,8 +187,7 @@ int main(void)
/* get file descriptors from the transfers */
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);
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
* you should have received as part of this distribution. The terms
@ -46,7 +46,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n",
"From: " FROM "(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",
"\r\n", /* empty line to divide headers from body, see RFC5322 */
"The body of the message starts here.\r\n",
@ -121,11 +122,12 @@ int main(void)
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
#endif
/* Note that this option isn't strictly required, omitting it will result in
* libcurl sending the MAIL FROM command with empty sender data. All
/* Note that this option isn't strictly required, omitting it will result
* in libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be directed
* to the address in the reverse-path which triggered them. Otherwise, they
* could cause an endless loop. See RFC 5321 Section 4.5.5 for more details.
* to the address in the reverse-path which triggered them. Otherwise,
* they could cause an endless loop. See RFC 5321 Section 4.5.5 for more
* details.
*/
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
* you should have received as part of this distribution. The terms
@ -46,7 +46,8 @@ static const char *payload_text[] = {
"To: " TO "\r\n",
"From: " FROM "(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",
"\r\n", /* empty line to divide headers from body, see RFC5322 */
"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_VERIFYHOST, 0L);
* That is, in general, a bad idea. It is still better than sending your
* authentication details in plain text though.
* Instead, you should get the issuer certificate (or the host certificate
* if the certificate is self-signed) and add it to the set of certificates
* that are known to libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See
* docs/SSLCERTS for more information. */
* authentication details in plain text though. Instead, you should get
* the issuer certificate (or the host certificate if the certificate is
* self-signed) and add it to the set of certificates that are known to
* libcurl using CURLOPT_CAINFO and/or CURLOPT_CAPATH. See docs/SSLCERTS
* for more information. */
curl_easy_setopt(curl, CURLOPT_CAINFO, "/path/to/certificate.pem");
/* Note that this option isn't strictly required, omitting it will result in
* libcurl sending the MAIL FROM command with empty sender data. All
/* Note that this option isn't strictly required, omitting it will result
* in libcurl sending the MAIL FROM command with empty sender data. All
* autoresponses should have an empty reverse-path, and should be directed
* to the address in the reverse-path which triggered them. Otherwise, they
* could cause an endless loop. See RFC 5321 Section 4.5.5 for more details.
* to the address in the reverse-path which triggered them. Otherwise,
* they could cause an endless loop. See RFC 5321 Section 4.5.5 for more
* details.
*/
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);
if(RetVal == 7) {
SYSTime.wMilliseconds = 500; /* adjust to midpoint, 0.5 sec */
for(i=0; i<12; i++) {
if(strcmp(MthStr[i], TmpStr2) == 0) {

View File

@ -64,7 +64,7 @@ static unsigned long thread_id(void)
unsigned long ret;
ret=(unsigned long)pthread_self();
return(ret);
return ret;
}
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_NOPROGRESS, 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_HEADERFUNCTION, *writefunction);
rv = curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, writefunction);
rv = curl_easy_setopt(ch, CURLOPT_HEADERDATA, stderr);
rv = curl_easy_setopt(ch, CURLOPT_SSLCERTTYPE, "PEM");

View File

@ -51,7 +51,8 @@ struct ParserStruct {
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;
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);
}
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;
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. */
if(state->ok && XML_Parse(parser, contents, real_size, 0) == 0) {
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));
state->ok = 0;
}
@ -126,7 +129,8 @@ int main(void)
/* Initialize a libcurl handle. */
curl_global_init(CURL_GLOBAL_ALL ^ CURL_GLOBAL_SSL);
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_WRITEDATA, (void *)parser);