example: fix formatting nits
No binary (build failed)
—
(log yok)
| @@ -81,7 +81,7 @@ static const char *urls[] = { | |
| }; | |
| #define MAX_PARALLEL 10 /* number of simultaneous transfers */ | |
| - | #define NUM_URLS sizeof(urls)/sizeof(char *) |
| + | #define NUM_URLS (sizeof(urls) / sizeof(char *)) |
| static size_t write_cb(char *data, size_t n, size_t l, void *userp) | |
| { | |
| @@ -65,9 +65,9 @@ | |
| /* seek callback function */ | |
| static int my_seek(void *userp, curl_off_t offset, int origin) | |
| { | |
| - | FILE *fp = (FILE *) userp; |
| + | FILE *fp = (FILE *)userp; |
| - | if(fseek(fp, (long) offset, origin) == -1) |
| + | if(fseek(fp, (long)offset, origin) == -1) |
| /* could not seek */ | |
| return CURL_SEEKFUNC_CANTSEEK; | |
| @@ -128,13 +128,13 @@ int main(int argc, char **argv) | |
| curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb); | |
| /* which file to upload */ | |
| - | curl_easy_setopt(curl, CURLOPT_READDATA, (void *) fp); |
| + | curl_easy_setopt(curl, CURLOPT_READDATA, (void *)fp); |
| /* set the seek function */ | |
| curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, my_seek); | |
| /* pass the file descriptor to the seek callback as well */ | |
| - | curl_easy_setopt(curl, CURLOPT_SEEKDATA, (void *) fp); |
| + | curl_easy_setopt(curl, CURLOPT_SEEKDATA, (void *)fp); |
| /* enable "uploading" (which means PUT when doing HTTP) */ | |
| curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); | |
| @@ -31,7 +31,11 @@ | |
| #ifdef __AMIGA__ | |
| #include <stdio.h> | |
| - | int main(void) { printf("Platform not supported.\n"); return 1; } |
| + | int main(void) |
| + | { |
| + | printf("Platform not supported.\n"); |
| + | return 1; |
| + | } |
| #else | |
| #ifdef _MSC_VER | |
| @@ -29,7 +29,7 @@ | |
| #include <curl/curl.h> | |
| - | static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) |
| + | static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) |
| { | |
| (void)stream; | |
| (void)ptr; | |
| @@ -74,10 +74,8 @@ int main(void) | |
| for(slist = certinfo->certinfo[i]; slist; slist = slist->next) | |
| printf("%s\n", slist->data); | |
| - | |
| } | |
| } | |
| - | |
| } | |
| curl_easy_cleanup(curl); | |
| @@ -71,8 +71,7 @@ static int print_cookies(CURL *curl) | |
| return 0; | |
| } | |
| - | int |
| - | main(void) |
| + | int main(void) |
| { | |
| CURL *curl; | |
| CURLcode res; | |
| @@ -65,7 +65,7 @@ struct memory { | |
| static size_t write_cb(void *contents, size_t sz, size_t nmemb, void *ctx) | |
| { | |
| size_t realsize = sz * nmemb; | |
| - | struct memory *mem = (struct memory*) ctx; |
| + | struct memory *mem = (struct memory *)ctx; |
| char *ptr = realloc(mem->buf, mem->size + realsize); | |
| if(!ptr) { | |
| /* out of memory */ | |
| @@ -109,7 +109,7 @@ static CURL *make_handle(const char *url) | |
| curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT_MS, 2000L); | |
| /* skip files larger than a gigabyte */ | |
| curl_easy_setopt(curl, CURLOPT_MAXFILESIZE_LARGE, | |
| - | (curl_off_t)1024*1024*1024); |
| + | (curl_off_t)1024 * 1024 * 1024); |
| curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); | |
| curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); | |
| curl_easy_setopt(curl, CURLOPT_USERAGENT, "mini crawler"); | |
| @@ -121,8 +121,7 @@ static CURL *make_handle(const char *url) | |
| } | |
| /* HREF finder implemented in libxml2 but could be any HTML parser */ | |
| - | static size_t follow_links(CURLM *multi, struct memory *mem, |
| - | const char *url) |
| + | static size_t follow_links(CURLM *multi, struct memory *mem, const char *url) |
| { | |
| int opts = HTML_PARSE_NOBLANKS | HTML_PARSE_NOERROR | \ | |
| HTML_PARSE_NOWARNING | HTML_PARSE_NONET; | |
| @@ -135,7 +134,7 @@ static size_t follow_links(CURLM *multi, struct memory *mem, | |
| xmlXPathObjectPtr result; | |
| if(!doc) | |
| return 0; | |
| - | xpath = (xmlChar*) "//a/@href"; |
| + | xpath = (xmlChar *)"//a/@href"; |
| context = xmlXPathNewContext(doc); | |
| result = xmlXPathEvalExpression(xpath, context); | |
| xmlXPathFreeContext(context); | |
| @@ -155,10 +154,10 @@ static size_t follow_links(CURLM *multi, struct memory *mem, | |
| char *link; | |
| if(follow_relative_links) { | |
| xmlChar *orig = href; | |
| - | href = xmlBuildURI(href, (xmlChar *) url); |
| + | href = xmlBuildURI(href, (xmlChar *)url); |
| xmlFree(orig); | |
| } | |
| - | link = (char *) href; |
| + | link = (char *)href; |
| if(!link || strlen(link) < 20) | |
| continue; | |
| if(!strncmp(link, "http://", 7) || !strncmp(link, "https://", 8)) { | |
| @@ -240,7 +239,7 @@ int main(void) | |
| } | |
| } | |
| else { | |
| - | printf("[%d] HTTP %d: %s\n", complete, (int) res_status, url); |
| + | printf("[%d] HTTP %d: %s\n", complete, (int)res_status, url); |
| } | |
| } | |
| else { | |
| @@ -58,7 +58,6 @@ This is purely a demo app, all retrieved data is simply discarded by the write | |
| callback. | |
| */ | |
| - | |
| #include <errno.h> | |
| #include <fcntl.h> | |
| #include <signal.h> | |
| @@ -77,7 +76,6 @@ callback. | |
| #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ | |
| - | |
| /* Global information, common to all connections */ | |
| struct GlobalInfo { | |
| int epfd; /* epoll filedescriptor */ | |
| @@ -105,23 +103,35 @@ struct SockInfo { | |
| struct GlobalInfo *global; | |
| }; | |
| - | #define mycase(code) \ |
| - | case code: s = __STRING(code) |
| - | |
| /* Die if we get a bad CURLMcode somewhere */ | |
| static void mcode_or_die(const char *where, CURLMcode code) | |
| { | |
| if(CURLM_OK != code) { | |
| const char *s; | |
| switch(code) { | |
| - | mycase(CURLM_BAD_HANDLE); break; |
| - | mycase(CURLM_BAD_EASY_HANDLE); break; |
| - | mycase(CURLM_OUT_OF_MEMORY); break; |
| - | mycase(CURLM_INTERNAL_ERROR); break; |
| - | mycase(CURLM_UNKNOWN_OPTION); break; |
| - | mycase(CURLM_LAST); break; |
| - | default: s = "CURLM_unknown"; break; |
| - | mycase(CURLM_BAD_SOCKET); |
| + | 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"; |
| + | break; |
| + | case CURLM_BAD_SOCKET: |
| + | s = "CURLM_BAD_SOCKET"; |
| fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); | |
| /* ignore this error */ | |
| return; | |
| @@ -161,7 +171,7 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, struct GlobalInfo *g) | |
| memset(&its, 0, sizeof(its)); | |
| } | |
| - | timerfd_settime(g->tfd, /* flags= */0, &its, NULL); |
| + | timerfd_settime(g->tfd, /* flags= */ 0, &its, NULL); |
| return 0; | |
| } | |
| @@ -281,7 +291,7 @@ static void setsock(struct SockInfo *f, curl_socket_t s, CURL *e, int act, | |
| static void addsock(curl_socket_t s, CURL *curl, int action, | |
| struct GlobalInfo *g) | |
| { | |
| - | struct SockInfo *fdp = (struct SockInfo*)calloc(1, sizeof(struct SockInfo)); |
| + | struct SockInfo *fdp = (struct SockInfo *)calloc(1, sizeof(struct SockInfo)); |
| fdp->global = g; | |
| setsock(fdp, s, curl, action, g); | |
| @@ -291,12 +301,11 @@ static void addsock(curl_socket_t s, CURL *curl, int action, | |
| /* CURLMOPT_SOCKETFUNCTION */ | |
| static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| { | |
| - | struct GlobalInfo *g = (struct GlobalInfo*) cbp; |
| - | struct SockInfo *fdp = (struct SockInfo*) sockp; |
| - | const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; |
| + | struct GlobalInfo *g = (struct GlobalInfo *)cbp; |
| + | struct SockInfo *fdp = (struct SockInfo *)sockp; |
| + | const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; |
| - | fprintf(MSG_OUT, |
| - | "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); |
| + | fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); |
| if(what == CURL_POLL_REMOVE) { | |
| fprintf(MSG_OUT, "\n"); | |
| remsock(fdp, g); | |
| @@ -307,8 +316,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| addsock(s, e, what, g); | |
| } | |
| else { | |
| - | fprintf(MSG_OUT, |
| - | "Changing action from %s to %s\n", |
| + | fprintf(MSG_OUT, "Changing action from %s to %s\n", |
| whatstr[fdp->action], whatstr[what]); | |
| setsock(fdp, s, e, what, g); | |
| } | |
| @@ -342,7 +350,7 @@ static void new_conn(const char *url, struct GlobalInfo *g) | |
| struct ConnInfo *conn; | |
| CURLMcode rc; | |
| - | conn = (struct ConnInfo*)calloc(1, sizeof(*conn)); |
| + | conn = (struct ConnInfo *)calloc(1, sizeof(*conn)); |
| conn->error[0] = '\0'; | |
| conn->curl = curl_easy_init(); | |
| @@ -364,8 +372,8 @@ static void new_conn(const char *url, struct GlobalInfo *g) | |
| curl_easy_setopt(conn->curl, CURLOPT_FOLLOWLOCATION, 1L); | |
| curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_TIME, 3L); | |
| curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_LIMIT, 10L); | |
| - | fprintf(MSG_OUT, |
| - | "Adding easy %p to multi %p (%s)\n", conn->curl, g->multi, url); |
| + | fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", |
| + | conn->curl, g->multi, url); |
| rc = curl_multi_add_handle(g->multi, conn->curl); | |
| mcode_or_die("new_conn: curl_multi_add_handle", rc); | |
| @@ -381,9 +389,9 @@ static void fifo_cb(struct GlobalInfo *g, int revents) | |
| int n = 0; | |
| do { | |
| - | s[0]='\0'; |
| + | s[0] = '\0'; |
| rv = fscanf(g->input, "%1023s%n", s, &n); | |
| - | s[n]='\0'; |
| + | s[n] = '\0'; |
| if(n && s[0]) { | |
| new_conn(s, g); /* if we read a URL, go get it! */ | |
| } | |
| @@ -437,7 +445,6 @@ static void clean_fifo(struct GlobalInfo *g) | |
| unlink(fifo); | |
| } | |
| - | |
| int g_should_exit_ = 0; | |
| void sigint_handler(int signo) | |
| @@ -506,7 +513,7 @@ int main(int argc, char **argv) | |
| while(!g_should_exit_) { | |
| int idx; | |
| int err = epoll_wait(g.epfd, events, | |
| - | sizeof(events)/sizeof(struct epoll_event), 10000); |
| + | sizeof(events) / sizeof(struct epoll_event), 10000); |
| if(err == -1) { | |
| /* !checksrc! disable ERRNOVAR 1 */ | |
| if(errno == EINTR) { | |
| @@ -61,7 +61,6 @@ This is purely a demo app, all retrieved data is simply discarded by the write | |
| callback. | |
| */ | |
| - | |
| #include <errno.h> | |
| #include <fcntl.h> | |
| #include <stdio.h> | |
| @@ -79,7 +78,6 @@ callback. | |
| #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ | |
| - | |
| /* Global information, common to all connections */ | |
| struct GlobalInfo { | |
| struct ev_loop *loop; | |
| @@ -119,7 +117,7 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, struct GlobalInfo *g) | |
| ev_timer_stop(g->loop, &g->timer_event); | |
| if(timeout_ms >= 0) { | |
| /* -1 means delete, other values are timeout times in milliseconds */ | |
| - | double t = timeout_ms / 1000; |
| + | double t = timeout_ms / 1000; |
| ev_timer_init(&g->timer_event, timer_cb, t, 0.); | |
| ev_timer_start(g->loop, &g->timer_event); | |
| } | |
| @@ -196,7 +194,7 @@ static void event_cb(EV_P_ struct ev_io *w, int revents) | |
| int action; | |
| printf("%s w %p revents %i\n", __PRETTY_FUNCTION__, (void *)w, revents); | |
| - | g = (struct GlobalInfo*) w->data; |
| + | g = (struct GlobalInfo *)w->data; |
| action = ((revents & EV_READ) ? CURL_POLL_IN : 0) | | |
| ((revents & EV_WRITE) ? CURL_POLL_OUT : 0); | |
| @@ -270,15 +268,14 @@ static void addsock(curl_socket_t s, CURL *curl, int action, | |
| /* CURLMOPT_SOCKETFUNCTION */ | |
| static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| { | |
| - | struct GlobalInfo *g = (struct GlobalInfo*) cbp; |
| - | struct SockInfo *fdp = (struct SockInfo*) sockp; |
| - | const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE"}; |
| + | struct GlobalInfo *g = (struct GlobalInfo *)cbp; |
| + | struct SockInfo *fdp = (struct SockInfo *)sockp; |
| + | const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; |
| printf("%s e %p s %i what %i cbp %p sockp %p\n", | |
| __PRETTY_FUNCTION__, e, s, what, cbp, sockp); | |
| - | fprintf(MSG_OUT, |
| - | "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); |
| + | fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); |
| if(what == CURL_POLL_REMOVE) { | |
| fprintf(MSG_OUT, "\n"); | |
| remsock(fdp, g); | |
| @@ -289,8 +286,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| addsock(s, e, what, g); | |
| } | |
| else { | |
| - | fprintf(MSG_OUT, |
| - | "Changing action from %s to %s\n", |
| + | fprintf(MSG_OUT, "Changing action from %s to %s\n", |
| whatstr[fdp->action], whatstr[what]); | |
| setsock(fdp, s, e, what, g); | |
| } | |
| @@ -302,7 +298,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) | |
| { | |
| size_t realsize = size * nmemb; | |
| - | struct ConnInfo *conn = (struct ConnInfo*) data; |
| + | struct ConnInfo *conn = (struct ConnInfo *)data; |
| (void)ptr; | |
| (void)conn; | |
| return realsize; | |
| @@ -316,8 +312,9 @@ static int xferinfo_cb(void *p, curl_off_t dltotal, curl_off_t dlnow, | |
| (void)ult; | |
| (void)uln; | |
| - | fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T |
| - | "/%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); |
| + | fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T "/" |
| + | "%" CURL_FORMAT_CURL_OFF_T ")\n", |
| + | conn->url, dlnow, dltotal); |
| return 0; | |
| } | |
| @@ -328,7 +325,7 @@ static void new_conn(const char *url, struct GlobalInfo *g) | |
| CURLMcode rc; | |
| conn = calloc(1, sizeof(*conn)); | |
| - | conn->error[0]='\0'; |
| + | conn->error[0] = '\0'; |
| conn->curl = curl_easy_init(); | |
| if(!conn->curl) { | |
| @@ -349,8 +346,8 @@ static void new_conn(const char *url, struct GlobalInfo *g) | |
| curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_TIME, 3L); | |
| curl_easy_setopt(conn->curl, CURLOPT_LOW_SPEED_LIMIT, 10L); | |
| - | fprintf(MSG_OUT, |
| - | "Adding easy %p to multi %p (%s)\n", conn->curl, g->multi, url); |
| + | fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", |
| + | conn->curl, g->multi, url); |
| rc = curl_multi_add_handle(g->multi, conn->curl); | |
| mcode_or_die("new_conn: curl_multi_add_handle", rc); | |
| @@ -369,9 +366,9 @@ static void fifo_cb(EV_P_ struct ev_io *w, int revents) | |
| (void)revents; | |
| do { | |
| - | s[0]='\0'; |
| + | s[0] = '\0'; |
| rv = fscanf(g->input, "%1023s%n", s, &n); | |
| - | s[n]='\0'; |
| + | s[n] = '\0'; |
| if(n && s[0]) { | |
| new_conn(s, g); /* if we read a URL, go get it! */ | |
| } | |
| @@ -124,7 +124,7 @@ int main(void) | |
| memset(&servaddr, 0, sizeof(servaddr)); | |
| servaddr.sin_family = AF_INET; | |
| - | servaddr.sin_port = htons(PORTNUM); |
| + | servaddr.sin_port = htons(PORTNUM); |
| servaddr.sin_addr.s_addr = inet_addr(IPADDR); | |
| if(INADDR_NONE == servaddr.sin_addr.s_addr) { | |
| @@ -132,8 +132,7 @@ int main(void) | |
| return 2; | |
| } | |
| - | if(connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) == |
| - | -1) { |
| + | if(connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) == -1) { |
| close(sockfd); | |
| printf("client error: connect: %s\n", strerror(errno)); | |
| return 1; | |
| @@ -85,8 +85,7 @@ static long file_is_downloaded(void *input) | |
| return CURL_CHUNK_END_FUNC_OK; | |
| } | |
| - | static size_t write_cb(char *buff, size_t size, size_t nmemb, |
| - | void *cb_data) |
| + | static size_t write_cb(char *buff, size_t size, size_t nmemb, void *cb_data) |
| { | |
| struct callback_data *data = cb_data; | |
| size_t written = 0; | |
| @@ -104,7 +103,7 @@ int main(int argc, char **argv) | |
| CURL *curl; | |
| /* help data */ | |
| - | struct callback_data data = { 0 }; |
| + | struct callback_data data = {0}; |
| /* global initialization */ | |
| CURLcode res = curl_global_init(CURL_GLOBAL_ALL); | |
| @@ -52,7 +52,6 @@ static size_t write_cb(void *buffer, size_t size, size_t nmemb, void *stream) | |
| return fwrite(buffer, size, nmemb, out->stream); | |
| } | |
| - | |
| int main(void) | |
| { | |
| CURL *curl; | |
| @@ -90,7 +90,7 @@ int main(void) | |
| curl_easy_cleanup(curl); | |
| } | |
| - | fclose(ftpfile); /* close the local file */ |
| + | fclose(ftpfile); /* close the local file */ |
| fclose(respfile); /* close the response file */ | |
| curl_global_cleanup(); | |
| @@ -30,7 +30,7 @@ | |
| #include <curl/curl.h> | |
| - | static const char data[]= |
| + | static const char data[] = |
| "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " | |
| "___ rhoncus odio id venenatis volutpat. Vestibulum dapibus " | |
| "bibendum ullamcorper. Maecenas finibus elit augue, vel " | |
| @@ -64,7 +64,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) | |
| return copylen; | |
| } | |
| - | return 0; /* no more data left to deliver */ |
| + | return 0; /* no more data left to deliver */ |
| } | |
| int main(void) | |
| @@ -37,8 +37,7 @@ struct MemoryStruct { | |
| size_t size; | |
| }; | |
| - | static size_t write_cb(void *contents, size_t size, size_t nmemb, |
| - | void *userp) |
| + | static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp) |
| { | |
| size_t realsize = size * nmemb; | |
| struct MemoryStruct *mem = (struct MemoryStruct *)userp; | |
| @@ -69,8 +68,8 @@ int main(void) | |
| if(res) | |
| return (int)res; | |
| - | chunk.memory = malloc(1); /* grown as needed by the realloc above */ |
| - | chunk.size = 0; /* no data at this point */ |
| + | chunk.memory = malloc(1); /* grown as needed by the realloc above */ |
| + | chunk.size = 0; /* no data at this point */ |
| /* init the curl session */ | |
| curl = curl_easy_init(); | |
| @@ -54,8 +54,7 @@ int main(void) | |
| curl_easy_strerror(res)); | |
| else { | |
| res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); | |
| - | if((res == CURLE_OK) && |
| - | ((response_code / 100) != 3)) { |
| + | if((res == CURLE_OK) && ((response_code / 100) != 3)) { |
| /* a redirect implies a 3xx response code */ | |
| fprintf(stderr, "Not a redirect.\n"); | |
| } | |
| @@ -171,8 +171,8 @@ static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) | |
| { | |
| struct timeval timeout; | |
| struct GlobalInfo *g = (struct GlobalInfo *)userp; | |
| - | timeout.tv_sec = timeout_ms/1000; |
| - | timeout.tv_usec = (timeout_ms%1000)*1000; |
| + | timeout.tv_sec = timeout_ms / 1000; |
| + | timeout.tv_usec = (timeout_ms % 1000) * 1000; |
| MSG_OUT("*** update_timeout_cb %ld => %ld:%ld ***\n", | |
| timeout_ms, timeout.tv_sec, timeout.tv_usec); | |
| @@ -191,7 +191,7 @@ static int update_timeout_cb(CURLM *multi, long timeout_ms, void *userp) | |
| /* Called by glib when we get action on a multi socket */ | |
| static gboolean event_cb(GIOChannel *ch, GIOCondition condition, gpointer data) | |
| { | |
| - | struct GlobalInfo *g = (struct GlobalInfo*) data; |
| + | struct GlobalInfo *g = (struct GlobalInfo *)data; |
| CURLMcode rc; | |
| int fd = g_io_channel_unix_get_fd(ch); | |
| @@ -259,9 +259,9 @@ static void addsock(curl_socket_t s, CURL *curl, int action, | |
| /* CURLMOPT_SOCKETFUNCTION */ | |
| static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| { | |
| - | struct GlobalInfo *g = (struct GlobalInfo*) cbp; |
| - | struct SockInfo *fdp = (struct SockInfo*) sockp; |
| - | static const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; |
| + | struct GlobalInfo *g = (struct GlobalInfo *)cbp; |
| + | struct SockInfo *fdp = (struct SockInfo *)sockp; |
| + | static const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; |
| MSG_OUT("socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); | |
| if(what == CURL_POLL_REMOVE) { | |
| @@ -276,8 +276,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| addsock(s, e, what, g); | |
| } | |
| else { | |
| - | MSG_OUT( |
| - | "Changing action from %d to %d\n", fdp->action, what); |
| + | MSG_OUT("Changing action from %d to %d\n", fdp->action, what); |
| setsock(fdp, s, e, what, g); | |
| } | |
| } | |
| @@ -288,7 +287,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *data) | |
| { | |
| size_t realsize = size * nmemb; | |
| - | struct ConnInfo *conn = (struct ConnInfo*) data; |
| + | struct ConnInfo *conn = (struct ConnInfo *)data; |
| (void)ptr; | |
| (void)conn; | |
| return realsize; | |
| @@ -302,8 +301,8 @@ static int xferinfo_cb(void *p, curl_off_t dltotal, curl_off_t dlnow, | |
| (void)ult; | |
| (void)uln; | |
| - | fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T |
| - | "/%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); |
| + | fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T "/" |
| + | "%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); |
| return 0; | |
| } | |
| @@ -357,18 +356,18 @@ static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data) | |
| rv = g_io_channel_read_line(ch, &buf, &len, &tp, &err); | |
| if(buf) { | |
| if(tp) { | |
| - | buf[tp]='\0'; |
| + | buf[tp] = '\0'; |
| } | |
| - | new_conn(buf, (struct GlobalInfo*)data); |
| + | new_conn(buf, (struct GlobalInfo *)data); |
| g_free(buf); | |
| } | |
| else { | |
| buf = g_malloc(BUF_SIZE + 1); | |
| while(TRUE) { | |
| - | buf[BUF_SIZE]='\0'; |
| + | buf[BUF_SIZE] = '\0'; |
| g_io_channel_read_chars(ch, buf, BUF_SIZE, &len, &err); | |
| if(len) { | |
| - | buf[len]='\0'; |
| + | buf[len] = '\0'; |
| if(all) { | |
| tmp = all; | |
| all = g_strdup_printf("%s%s", tmp, buf); | |
| @@ -383,7 +382,7 @@ static gboolean fifo_cb(GIOChannel *ch, GIOCondition condition, gpointer data) | |
| } | |
| } | |
| if(all) { | |
| - | new_conn(all, (struct GlobalInfo*)data); |
| + | new_conn(all, (struct GlobalInfo *)data); |
| g_free(all); | |
| } | |
| g_free(buf); | |
| @@ -76,7 +76,6 @@ int main(void) | |
| printf(" %s: %s (%u)\n", h->name, h->value, (unsigned int)h->amount); | |
| prev = h; | |
| } while(h); | |
| - | |
| } | |
| /* always cleanup */ | |
| curl_easy_cleanup(curl); | |
| @@ -77,7 +77,6 @@ callback. | |
| #define MSG_OUT stdout /* Send info to stdout, change to stderr if you want */ | |
| - | |
| /* Global information, common to all connections */ | |
| struct GlobalInfo { | |
| struct event_base *evbase; | |
| @@ -107,23 +106,35 @@ struct SockInfo { | |
| struct GlobalInfo *global; | |
| }; | |
| - | #define mycase(code) \ |
| - | case code: s = __STRING(code) |
| - | |
| /* Die if we get a bad CURLMcode somewhere */ | |
| static void mcode_or_die(const char *where, CURLMcode code) | |
| { | |
| if(CURLM_OK != code) { | |
| const char *s; | |
| switch(code) { | |
| - | mycase(CURLM_BAD_HANDLE); break; |
| - | mycase(CURLM_BAD_EASY_HANDLE); break; |
| - | mycase(CURLM_OUT_OF_MEMORY); break; |
| - | mycase(CURLM_INTERNAL_ERROR); break; |
| - | mycase(CURLM_UNKNOWN_OPTION); break; |
| - | mycase(CURLM_LAST); break; |
| - | default: s = "CURLM_unknown"; break; |
| - | mycase(CURLM_BAD_SOCKET); |
| + | 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"; |
| + | break; |
| + | case CURLM_BAD_SOCKET: |
| + | s = "CURLM_BAD_SOCKET"; |
| fprintf(MSG_OUT, "ERROR: %s returns %s\n", where, s); | |
| /* ignore this error */ | |
| return; | |
| @@ -139,8 +150,8 @@ static int multi_timer_cb(CURLM *multi, long timeout_ms, struct GlobalInfo *g) | |
| struct timeval timeout; | |
| (void)multi; | |
| - | timeout.tv_sec = timeout_ms/1000; |
| - | timeout.tv_usec = (timeout_ms%1000)*1000; |
| + | timeout.tv_sec = timeout_ms / 1000; |
| + | timeout.tv_usec = (timeout_ms % 1000) * 1000; |
| fprintf(MSG_OUT, "multi_timer_cb: Setting timeout to %ld ms\n", timeout_ms); | |
| /* | |
| @@ -185,7 +196,7 @@ static void check_multi_info(struct GlobalInfo *g) | |
| /* Called by libevent when we get action on a multi socket */ | |
| static void event_cb(int fd, short kind, void *userp) | |
| { | |
| - | struct GlobalInfo *g = (struct GlobalInfo*) userp; |
| + | struct GlobalInfo *g = (struct GlobalInfo *)userp; |
| CURLMcode rc; | |
| int action = | |
| @@ -261,12 +272,11 @@ static void addsock(curl_socket_t s, CURL *curl, int action, | |
| /* CURLMOPT_SOCKETFUNCTION */ | |
| static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| { | |
| - | struct GlobalInfo *g = (struct GlobalInfo*) cbp; |
| - | struct SockInfo *fdp = (struct SockInfo*) sockp; |
| - | const char *whatstr[]={ "none", "IN", "OUT", "INOUT", "REMOVE" }; |
| + | struct GlobalInfo *g = (struct GlobalInfo *)cbp; |
| + | struct SockInfo *fdp = (struct SockInfo *)sockp; |
| + | const char *whatstr[] = {"none", "IN", "OUT", "INOUT", "REMOVE"}; |
| - | fprintf(MSG_OUT, |
| - | "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); |
| + | fprintf(MSG_OUT, "socket callback: s=%d e=%p what=%s ", s, e, whatstr[what]); |
| if(what == CURL_POLL_REMOVE) { | |
| fprintf(MSG_OUT, "\n"); | |
| remsock(fdp); | |
| @@ -277,8 +287,7 @@ static int sock_cb(CURL *e, curl_socket_t s, int what, void *cbp, void *sockp) | |
| addsock(s, e, what, g); | |
| } | |
| else { | |
| - | fprintf(MSG_OUT, |
| - | "Changing action from %s to %s\n", |
| + | fprintf(MSG_OUT, "Changing action from %s to %s\n", |
| whatstr[fdp->action], whatstr[what]); | |
| setsock(fdp, s, e, what, g); | |
| } | |
| @@ -302,8 +311,8 @@ static int xferinfo_cb(void *p, curl_off_t dltotal, curl_off_t dlnow, | |
| (void)ult; | |
| (void)uln; | |
| - | fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T |
| - | "/%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); |
| + | fprintf(MSG_OUT, "Progress: %s (%" CURL_FORMAT_CURL_OFF_T "/" |
| + | "%" CURL_FORMAT_CURL_OFF_T ")\n", conn->url, dlnow, dltotal); |
| return 0; | |
| } | |
| @@ -333,8 +342,8 @@ static void new_conn(const char *url, struct GlobalInfo *g) | |
| curl_easy_setopt(conn->curl, CURLOPT_XFERINFOFUNCTION, xferinfo_cb); | |
| curl_easy_setopt(conn->curl, CURLOPT_PROGRESSDATA, conn); | |
| curl_easy_setopt(conn->curl, CURLOPT_FOLLOWLOCATION, 1L); | |
| - | fprintf(MSG_OUT, |
| - | "Adding easy %p to multi %p (%s)\n", conn->curl, g->multi, url); |
| + | fprintf(MSG_OUT, "Adding easy %p to multi %p (%s)\n", |
| + | conn->curl, g->multi, url); |
| rc = curl_multi_add_handle(g->multi, conn->curl); | |
| mcode_or_die("new_conn: curl_multi_add_handle", rc); | |
| @@ -353,9 +362,9 @@ static void fifo_cb(int fd, short event, void *arg) | |
| (void)event; | |
| do { | |
| - | s[0]='\0'; |
| + | s[0] = '\0'; |
| rv = fscanf(g->input, "%1023s%n", s, &n); | |
| - | s[n]='\0'; |
| + | s[n] = '\0'; |
| if(n && s[0]) { | |
| if(!strcmp(s, "stop")) { | |
| g->stopped = 1; | |
| @@ -386,7 +395,7 @@ static int init_fifo(struct GlobalInfo *g) | |
| } | |
| } | |
| unlink(fifo); | |
| - | if(mkfifo (fifo, 0600) == -1) { |
| + | if(mkfifo(fifo, 0600) == -1) { |
| perror("mkfifo"); | |
| return 1; | |
| } | |
| @@ -398,7 +407,7 @@ static int init_fifo(struct GlobalInfo *g) | |
| g->input = fdopen(sockfd, "r"); | |
| fprintf(MSG_OUT, "Now, pipe some URL's into > %s\n", fifo); | |
| - | event_assign(&g->fifo_event, g->evbase, sockfd, EV_READ|EV_PERSIST, |
| + | event_assign(&g->fifo_event, g->evbase, sockfd, EV_READ | EV_PERSIST, |
| fifo_cb, g); | |
| event_add(&g->fifo_event, NULL); | |
| return 0; | |
| @@ -406,9 +415,9 @@ static int init_fifo(struct GlobalInfo *g) | |
| static void clean_fifo(struct GlobalInfo *g) | |
| { | |
| - | event_del(&g->fifo_event); |
| - | fclose(g->input); |
| - | unlink(fifo); |
| + | event_del(&g->fifo_event); |
| + | fclose(g->input); |
| + | unlink(fifo); |
| } | |
| int main(int argc, char **argv) | |
| @@ -53,8 +53,7 @@ struct state { | |
| /* "read" is from the point of the library, it wants data from us. One domain | |
| entry per invoke. */ | |
| - | static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, |
| - | void *userp) |
| + | static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, void *userp) |
| { | |
| const char *host; | |
| const char *expire; | |
| @@ -48,14 +48,14 @@ static uint write_cb(char *in, uint size, uint nmemb, TidyBuffer *out) | |
| static 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 it has a name, then it is an HTML tag ... */ | |
| TidyAttr attr; | |
| printf("%*.*s%s ", indent, indent, "<", name); | |
| /* walk the attribute list */ | |
| - | for(attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr) ) { |
| + | for(attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr)) { |
| printf("%s", tidyAttrName(attr)); | |
| tidyAttrValue(attr) ? printf("=\"%s\" ", | |
| tidyAttrValue(attr)) : printf(" "); | |
| @@ -55,9 +55,8 @@ | |
| // libxml callback context structure | |
| // | |
| - | struct Context |
| - | { |
| - | Context(): addTitle(false) { } |
| + | struct Context { |
| + | Context() : addTitle(false) {} |
| bool addTitle; | |
| std::string title; | |
| @@ -79,7 +78,7 @@ static size_t writer(char *data, size_t size, size_t nmemb, | |
| if(writerData == NULL) | |
| return 0; | |
| - | writerData->append(data, size*nmemb); |
| + | writerData->append(data, size * nmemb); |
| return size * nmemb; | |
| } | |
| @@ -115,7 +115,6 @@ static int server_push_callback(CURL *parent, | |
| return CURL_PUSH_OK; | |
| } | |
| - | |
| /* | |
| * Download a file over HTTP/2, take care of server push. | |
| */ | |
| @@ -30,7 +30,7 @@ | |
| #include <curl/curl.h> | |
| - | static const char olivertwist[]= |
| + | static const char olivertwist[] = |
| "Among other public buildings in a certain town, which for many reasons " | |
| "it will be prudent to refrain from mentioning, and to which I will assign " | |
| "no fictitious name, there is one anciently common to most towns, great or " | |
| @@ -77,7 +77,7 @@ int main(int argc, char **argv) | |
| { | |
| CURL *curl; | |
| CURLcode res; | |
| - | FILE * hd_src; |
| + | FILE *hd_src; |
| struct stat file_info; | |
| char *file; | |
| @@ -64,7 +64,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) | |
| const char *data; | |
| size_t room = size * nmemb; | |
| - | if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { |
| + | if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { |
| return 0; | |
| } | |
| @@ -95,7 +95,7 @@ int main(void) | |
| if(curl) { | |
| size_t filesize; | |
| long infilesize = LONG_MAX; | |
| - | struct upload_status upload_ctx = { 0 }; |
| + | struct upload_status upload_ctx = {0}; |
| /* Set username and password */ | |
| curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); | |
| @@ -51,7 +51,7 @@ int main(void) | |
| curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret"); | |
| /* This fetches message 1 from the user's inbox. Note the use of | |
| - | * imaps:// rather than imap:// to request an SSL based connection. */ |
| + | * imaps:// rather than imap:// to request an SSL based connection. */ |
| curl_easy_setopt(curl, CURLOPT_URL, | |
| "imaps://imap.example.com/INBOX/;UID=1"); | |
| @@ -236,7 +236,7 @@ int main(void) | |
| curl_global_trace("all"); | |
| #endif | |
| - | for(i = 0; i < sizeof(transfer)/sizeof(transfer[0]); ++i) { |
| + | for(i = 0; i < sizeof(transfer) / sizeof(transfer[0]); ++i) { |
| int failed = 0; | |
| struct transfer *t = &transfer[i]; | |
| @@ -66,7 +66,7 @@ int main(void) | |
| int still_running = 1; /* keep number of running handles */ | |
| - | CURLMsg *msg; /* for picking up messages with the transfer status */ |
| + | CURLMsg *msg; /* for picking up messages with the transfer status */ |
| int msgs_left; /* how many messages are left */ | |
| /* add the individual transfers */ | |
| @@ -47,7 +47,7 @@ static struct curl_context *create_curl_context(curl_socket_t sockfd) | |
| { | |
| struct curl_context *context; | |
| - | context = (struct curl_context *) malloc(sizeof(*context)); |
| + | context = (struct curl_context *)malloc(sizeof(*context)); |
| context->sockfd = sockfd; | |
| @@ -134,10 +134,9 @@ static void curl_perform(int fd, short event, void *arg) | |
| if(event & EV_WRITE) | |
| flags |= CURL_CSELECT_OUT; | |
| - | context = (struct curl_context *) arg; |
| + | context = (struct curl_context *)arg; |
| - | curl_multi_socket_action(multi, context->sockfd, flags, |
| - | &running_handles); |
| + | curl_multi_socket_action(multi, context->sockfd, flags, &running_handles); |
| check_multi_info(); | |
| } | |
| @@ -148,8 +147,7 @@ static void on_timeout(evutil_socket_t fd, short events, void *arg) | |
| (void)fd; | |
| (void)events; | |
| (void)arg; | |
| - | curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, |
| - | &running_handles); |
| + | curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0, &running_handles); |
| check_multi_info(); | |
| } | |
| @@ -186,9 +184,9 @@ static int handle_socket(CURL *curl, curl_socket_t s, int action, void *userp, | |
| case CURL_POLL_OUT: | |
| case CURL_POLL_INOUT: | |
| curl_context = socketp ? | |
| - | (struct curl_context *) socketp : create_curl_context(s); |
| + | (struct curl_context *)socketp : create_curl_context(s); |
| - | curl_multi_assign(multi, s, (void *) curl_context); |
| + | curl_multi_assign(multi, s, (void *)curl_context); |
| if(action != CURL_POLL_IN) | |
| events |= EV_WRITE; | |
| @@ -205,8 +203,8 @@ static int handle_socket(CURL *curl, curl_socket_t s, int action, void *userp, | |
| break; | |
| case CURL_POLL_REMOVE: | |
| if(socketp) { | |
| - | event_del(((struct curl_context*) socketp)->event); |
| - | destroy_curl_context((struct curl_context*) socketp); |
| + | event_del(((struct curl_context *)socketp)->event); |
| + | destroy_curl_context((struct curl_context *)socketp); |
| curl_multi_assign(multi, s, NULL); | |
| } | |
| break; | |
| @@ -72,7 +72,7 @@ int main(void) | |
| int still_running = 0; /* keep number of running handles */ | |
| - | CURLMsg *msg; /* for picking up messages with the transfer status */ |
| + | CURLMsg *msg; /* for picking up messages with the transfer status */ |
| int msgs_left; /* how many messages are left */ | |
| /* add the individual transfers */ | |
| @@ -85,7 +85,7 @@ int main(void) | |
| while(still_running) { | |
| struct timeval timeout; | |
| - | int rc; /* select() return code */ |
| + | int rc; /* select() return code */ |
| CURLMcode mc; /* curl_multi_fdset() return code */ | |
| fd_set fdread; | |
| @@ -155,7 +155,7 @@ int main(void) | |
| case -1: | |
| /* select error */ | |
| break; | |
| - | case 0: /* timeout */ |
| + | case 0: /* timeout */ |
| default: /* action */ | |
| curl_multi_perform(multi, &still_running); | |
| break; | |
| @@ -60,7 +60,7 @@ static struct curl_context *create_curl_context(curl_socket_t sockfd, | |
| { | |
| struct curl_context *context; | |
| - | context = (struct curl_context *) malloc(sizeof(*context)); |
| + | context = (struct curl_context *)malloc(sizeof(*context)); |
| context->sockfd = sockfd; | |
| context->uv = uv; | |
| @@ -73,13 +73,13 @@ static struct curl_context *create_curl_context(curl_socket_t sockfd, | |
| static void curl_close_cb(uv_handle_t *handle) | |
| { | |
| - | struct curl_context *context = (struct curl_context *) handle->data; |
| + | struct curl_context *context = (struct curl_context *)handle->data; |
| free(context); | |
| } | |
| static void destroy_curl_context(struct curl_context *context) | |
| { | |
| - | uv_close((uv_handle_t *) &context->poll_handle, curl_close_cb); |
| + | uv_close((uv_handle_t *)&context->poll_handle, curl_close_cb); |
| } | |
| static void add_download(const char *url, int num, CURLM *multi) | |
| @@ -145,7 +145,7 @@ static void on_uv_socket(uv_poll_t *req, int status, int events) | |
| { | |
| int running_handles; | |
| int flags = 0; | |
| - | struct curl_context *context = (struct curl_context *) req->data; |
| + | struct curl_context *context = (struct curl_context *)req->data; |
| (void)status; | |
| if(events & UV_READABLE) | |
| flags |= CURL_CSELECT_IN; | |
| @@ -202,9 +202,9 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, | |
| case CURL_POLL_OUT: | |
| case CURL_POLL_INOUT: | |
| curl_context = socketp ? | |
| - | (struct curl_context *) socketp : create_curl_context(s, uv); |
| + | (struct curl_context *)socketp : create_curl_context(s, uv); |
| - | curl_multi_assign(uv->multi, s, (void *) curl_context); |
| + | curl_multi_assign(uv->multi, s, (void *)curl_context); |
| if(action != CURL_POLL_IN) | |
| events |= UV_WRITABLE; | |
| @@ -215,8 +215,8 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, | |
| break; | |
| case CURL_POLL_REMOVE: | |
| if(socketp) { | |
| - | uv_poll_stop(&((struct curl_context*)socketp)->poll_handle); |
| - | destroy_curl_context((struct curl_context*) socketp); |
| + | uv_poll_stop(&((struct curl_context *)socketp)->poll_handle); |
| + | destroy_curl_context((struct curl_context *)socketp); |
| curl_multi_assign(uv->multi, s, NULL); | |
| } | |
| break; | |
| @@ -230,7 +230,7 @@ static int cb_socket(CURL *curl, curl_socket_t s, int action, | |
| int main(int argc, char **argv) | |
| { | |
| CURLcode res; | |
| - | struct datauv uv = { 0 }; |
| + | struct datauv uv = {0}; |
| int running_handles; | |
| if(argc <= 1) | |
| @@ -56,7 +56,6 @@ struct targ { | |
| const char *url; | |
| }; | |
| - | |
| static void *pull_one_url(void *p) | |
| { | |
| CURL *curl; | |
| @@ -72,7 +71,6 @@ static void *pull_one_url(void *p) | |
| return NULL; | |
| } | |
| - | |
| /* | |
| int pthread_create(pthread_t *new_thread_ID, | |
| const pthread_attr_t *attr, | |
| @@ -40,8 +40,7 @@ int main(void) | |
| curl = curl_easy_init(); | |
| if(curl) { | |
| curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); | |
| - | curl_easy_setopt(curl, CURLOPT_NETRC_FILE, |
| - | "/home/daniel/s3cr3ts.txt"); |
| + | curl_easy_setopt(curl, CURLOPT_NETRC_FILE, "/home/daniel/s3cr3ts.txt"); |
| curl_easy_setopt(curl, CURLOPT_URL, "https://curl.se/"); | |
| res = curl_easy_perform(curl); | |
| @@ -47,7 +47,7 @@ struct WriteThis { | |
| static size_t read_cb(char *dest, size_t size, size_t nmemb, void *userp) | |
| { | |
| struct WriteThis *wt = (struct WriteThis *)userp; | |
| - | size_t buffer_size = size*nmemb; |
| + | size_t buffer_size = size * nmemb; |
| if(wt->sizeleft) { | |
| /* copy as much as possible from the source to the destination */ | |
| @@ -36,8 +36,7 @@ struct MemoryStruct { | |
| size_t size; | |
| }; | |
| - | static size_t write_cb(void *contents, size_t size, size_t nmemb, |
| - | void *userp) |
| + | static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp) |
| { | |
| size_t realsize = size * nmemb; | |
| struct MemoryStruct *mem = (struct MemoryStruct *)userp; | |
| @@ -104,7 +103,7 @@ int main(void) | |
| * | |
| * Do something nice with it! | |
| */ | |
| - | printf("%s\n",chunk.memory); |
| + | printf("%s\n", chunk.memory); |
| } | |
| /* always cleanup */ | |
| @@ -50,8 +50,7 @@ struct FtpFile { | |
| FILE *stream; | |
| }; | |
| - | static size_t write_cb(void *buffer, size_t size, size_t nmemb, |
| - | void *stream) |
| + | static size_t write_cb(void *buffer, size_t size, size_t nmemb, void *stream) |
| { | |
| struct FtpFile *out = (struct FtpFile *)stream; | |
| if(!out->stream) { | |
| @@ -63,7 +62,6 @@ static size_t write_cb(void *buffer, size_t size, size_t nmemb, | |
| return fwrite(buffer, size, nmemb, out->stream); | |
| } | |
| - | |
| int main(void) | |
| { | |
| CURL *curl; | |
| @@ -83,7 +83,6 @@ static curl_off_t sftpGetRemoteFileSize(const char *i_remoteFile) | |
| return remoteFileSizeByte; | |
| } | |
| - | |
| static int sftpResumeUpload(CURL *curl, const char *remotepath, | |
| const char *localpath) | |
| { | |
| @@ -29,8 +29,8 @@ | |
| #include <curl/curl.h> | |
| - | static void my_lock(CURL *curl, curl_lock_data data, |
| - | curl_lock_access laccess, void *useptr) |
| + | static void my_lock(CURL *curl, curl_lock_data data, curl_lock_access laccess, |
| + | void *useptr) |
| { | |
| (void)curl; | |
| (void)data; | |
| @@ -68,11 +68,11 @@ int main(void) | |
| const char *pKeyType; | |
| #ifdef USE_ENGINE | |
| - | pKeyName = "rsa_test"; |
| - | pKeyType = "ENG"; |
| + | pKeyName = "rsa_test"; |
| + | pKeyType = "ENG"; |
| #else | |
| - | pKeyName = "testkey.pem"; |
| - | pKeyType = "PEM"; |
| + | pKeyName = "testkey.pem"; |
| + | pKeyType = "PEM"; |
| #endif | |
| res = curl_global_init(CURL_GLOBAL_ALL); | |
| @@ -108,11 +108,10 @@ static void *pull_one_url(void *NaN) | |
| return NULL; | |
| } | |
| - | |
| static gboolean pulse_bar(gpointer data) | |
| { | |
| gdk_threads_enter(); | |
| - | gtk_progress_bar_pulse(GTK_PROGRESS_BAR (data)); |
| + | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(data)); |
| gdk_threads_leave(); | |
| /* Return true so the function is called again; returning false removes this | |
| @@ -127,7 +126,7 @@ static void *create_thread(void *progress_bar) | |
| int i; | |
| /* Make sure I do not create more threads than urls. */ | |
| - | for(i = 0; i < NUMT && i < num_urls ; i++) { |
| + | for(i = 0; i < NUMT && i < num_urls; i++) { |
| int error = pthread_create(&tid[i], | |
| NULL, /* default attributes please */ | |
| pull_one_url, | |
| @@ -196,7 +195,7 @@ int main(int argc, char **argv) | |
| /* Progress bar */ | |
| progress_bar = gtk_progress_bar_new(); | |
| - | gtk_progress_bar_pulse(GTK_PROGRESS_BAR (progress_bar)); |
| + | gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); |
| /* Make uniform pulsing */ | |
| gint pulse_ref = g_timeout_add(300, pulse_bar, progress_bar); | |
| g_object_set_data(G_OBJECT(progress_bar), "pulse_id", | |
| @@ -206,7 +205,7 @@ int main(int argc, char **argv) | |
| gtk_widget_show_all(top_window); | |
| printf("gtk_widget_show_all\n"); | |
| - | g_signal_connect(G_OBJECT (top_window), "delete-event", |
| + | g_signal_connect(G_OBJECT(top_window), "delete-event", |
| G_CALLBACK(cb_delete), NULL); | |
| if(!g_thread_create(&create_thread, progress_bar, FALSE, NULL) != 0) | |
| @@ -73,7 +73,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) | |
| size_t room = size * nmemb; | |
| size_t len; | |
| - | if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { |
| + | if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { |
| return 0; | |
| } | |
| @@ -99,7 +99,7 @@ int main(void) | |
| curl = curl_easy_init(); | |
| if(curl) { | |
| struct curl_slist *recipients = NULL; | |
| - | struct upload_status upload_ctx = { 0 }; |
| + | struct upload_status upload_ctx = {0}; |
| /* This is the URL for your mailserver. In this example we connect to the | |
| smtp-submission port as we require an authenticated connection. */ | |
| @@ -70,7 +70,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) | |
| size_t room = size * nmemb; | |
| size_t len; | |
| - | if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { |
| + | if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { |
| return 0; | |
| } | |
| @@ -96,7 +96,7 @@ int main(void) | |
| curl = curl_easy_init(); | |
| if(curl) { | |
| struct curl_slist *recipients = NULL; | |
| - | struct upload_status upload_ctx = { 0 }; |
| + | struct upload_status upload_ctx = {0}; |
| /* This is the URL for your mailserver */ | |
| curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); | |
| @@ -63,7 +63,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) | |
| size_t room = size * nmemb; | |
| size_t len; | |
| - | if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { |
| + | if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { |
| return 0; | |
| } | |
| @@ -94,7 +94,7 @@ int main(void) | |
| if(multi) { | |
| int still_running = 1; | |
| struct curl_slist *recipients = NULL; | |
| - | struct upload_status upload_ctx = { 0 }; |
| + | struct upload_status upload_ctx = {0}; |
| /* This is the URL for your mailserver */ | |
| curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com"); | |
| @@ -67,7 +67,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) | |
| size_t room = size * nmemb; | |
| size_t len; | |
| - | if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { |
| + | if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { |
| return 0; | |
| } | |
| @@ -93,7 +93,7 @@ int main(void) | |
| curl = curl_easy_init(); | |
| if(curl) { | |
| struct curl_slist *recipients = NULL; | |
| - | struct upload_status upload_ctx = { 0 }; |
| + | struct upload_status upload_ctx = {0}; |
| /* Set username and password */ | |
| curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); | |
| @@ -67,7 +67,7 @@ static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp) | |
| size_t room = size * nmemb; | |
| size_t len; | |
| - | if((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) { |
| + | if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) { |
| return 0; | |
| } | |
| @@ -93,7 +93,7 @@ int main(void) | |
| curl = curl_easy_init(); | |
| if(curl) { | |
| struct curl_slist *recipients = NULL; | |
| - | struct upload_status upload_ctx = { 0 }; |
| + | struct upload_status upload_ctx = {0}; |
| /* Set username and password */ | |
| curl_easy_setopt(curl, CURLOPT_USERNAME, "user"); | |
| @@ -38,7 +38,7 @@ | |
| * SSL backend has to be configured). | |
| * | |
| * **** This example only works with libcurl 7.56.0 and later! **** | |
| - | */ |
| + | */ |
| int main(int argc, char **argv) | |
| { | |
| @@ -66,7 +66,11 @@ | |
| #include <stdio.h> | |
| #ifndef _WIN32 | |
| - | int main(void) { printf("Platform not supported.\n"); return 1; } |
| + | int main(void) |
| + | { |
| + | printf("Platform not supported.\n"); |
| + | return 1; |
| + | } |
| #else | |
| #if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ | |
| @@ -79,7 +83,11 @@ int main(void) { printf("Platform not supported.\n"); return 1; } | |
| #endif | |
| #ifdef CURL_WINDOWS_UWP | |
| - | int main(void) { printf("Platform not supported.\n"); return 1; } |
| + | int main(void) |
| + | { |
| + | printf("Platform not supported.\n"); |
| + | return 1; |
| + | } |
| #else | |
| #include <time.h> | |
| @@ -123,8 +131,7 @@ static SYSTEMTIME LOCALTime; | |
| #define HTTP_COMMAND_HEAD 0 | |
| #define HTTP_COMMAND_GET 1 | |
| - | static size_t write_cb(void *ptr, size_t size, size_t nmemb, |
| - | void *stream) |
| + | static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream) |
| { | |
| fwrite(ptr, size, nmemb, stream); | |
| return nmemb * size; | |
| @@ -280,7 +287,7 @@ int main(int argc, char *argv[]) | |
| snprintf(conf->http_proxy, MAX_STRING, "%s", &argv[OptionIndex][8]); | |
| if((strcmp(argv[OptionIndex], "--help") == 0) || | |
| - | (strcmp(argv[OptionIndex], "/?") == 0)) { |
| + | (strcmp(argv[OptionIndex], "/?") == 0)) { |
| showUsage(); | |
| return 0; | |
| } | |
| @@ -317,9 +324,9 @@ int main(int argc, char *argv[]) | |
| gmt = gmtime(&tt); | |
| tt_gmt = mktime(gmt); | |
| tzonediffFloat = difftime(tt_local, tt_gmt); | |
| - | tzonediffWord = (int)(tzonediffFloat/3600.0); |
| + | tzonediffWord = (int)(tzonediffFloat / 3600.0); |
| - | if(tzonediffWord == (int)(tzonediffFloat/3600.0)) |
| + | if(tzonediffWord == (int)(tzonediffFloat / 3600.0)) |
| snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'00'", tzonediffWord); | |
| else | |
| snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'30'", tzonediffWord); | |
| @@ -329,9 +336,8 @@ int main(int argc, char *argv[]) | |
| GetLocalTime(&LOCALTime); | |
| snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", | |
| DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, | |
| - | MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, |
| - | LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, |
| - | LOCALTime.wMilliseconds); |
| + | MthStr[LOCALTime.wMonth - 1], LOCALTime.wYear, LOCALTime.wHour, |
| + | LOCALTime.wMinute, LOCALTime.wSecond, LOCALTime.wMilliseconds); |
| fprintf(stderr, "Fetch: %s\n\n", conf->timeserver); | |
| fprintf(stderr, "Before HTTP. Date: %s%s\n\n", timeBuf, tzoneBuf); | |
| @@ -343,9 +349,8 @@ int main(int argc, char *argv[]) | |
| GetLocalTime(&LOCALTime); | |
| snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", | |
| DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, | |
| - | MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, |
| - | LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, |
| - | LOCALTime.wMilliseconds); |
| + | MthStr[LOCALTime.wMonth - 1], LOCALTime.wYear, LOCALTime.wHour, |
| + | LOCALTime.wMinute, LOCALTime.wSecond, LOCALTime.wMilliseconds); |
| fprintf(stderr, "\nAfter HTTP. Date: %s%s\n", timeBuf, tzoneBuf); | |
| if(AutoSyncTime == 3) { | |
| @@ -359,7 +364,7 @@ int main(int argc, char *argv[]) | |
| GetLocalTime(&LOCALTime); | |
| snprintf(timeBuf, 60, "%s, %02d %s %04d %02d:%02d:%02d.%03d, ", | |
| DayStr[LOCALTime.wDayOfWeek], LOCALTime.wDay, | |
| - | MthStr[LOCALTime.wMonth-1], LOCALTime.wYear, |
| + | MthStr[LOCALTime.wMonth - 1], LOCALTime.wYear, |
| LOCALTime.wHour, LOCALTime.wMinute, LOCALTime.wSecond, | |
| LOCALTime.wMilliseconds); | |
| fprintf(stderr, "\nNew System's Date: %s%s\n", timeBuf, tzoneBuf); | |
| @@ -46,7 +46,7 @@ | |
| #define NUMT 4 | |
| /* List of URLs to fetch.*/ | |
| - | static const char * const urls[]= { |
| + | static const char * const urls[] = { |
| "https://www.example.com/", | |
| "https://www2.example.com/", | |
| "https://www3.example.com/", | |
| @@ -114,7 +114,7 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer) | |
| } | |
| /* tell SSL to use the X509 certificate */ | |
| - | ret = SSL_CTX_use_certificate((SSL_CTX*)sslctx, cert); |
| + | ret = SSL_CTX_use_certificate((SSL_CTX *)sslctx, cert); |
| if(ret != 1) { | |
| printf("Use certificate failed\n"); | |
| } | |
| @@ -132,7 +132,7 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *pointer) | |
| } | |
| /* tell SSL to use the RSA key from memory */ | |
| - | ret = SSL_CTX_use_RSAPrivateKey((SSL_CTX*)sslctx, rsa); |
| + | ret = SSL_CTX_use_RSAPrivateKey((SSL_CTX *)sslctx, rsa); |
| if(ret != 1) { | |
| printf("Use Key failed\n"); | |
| } | |
| @@ -55,7 +55,7 @@ struct ParserStruct { | |
| 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->depth++; | |
| @@ -70,7 +70,7 @@ static void startElement(void *userData, const XML_Char *name, | |
| static void characterDataHandler(void *userData, const XML_Char *s, int len) | |
| { | |
| - | struct ParserStruct *state = (struct ParserStruct *) userData; |
| + | struct ParserStruct *state = (struct ParserStruct *)userData; |
| struct MemoryStruct *mem = &state->characters; | |
| char *ptr = realloc(mem->memory, mem->size + (unsigned long)len + 1); | |
| @@ -89,7 +89,7 @@ static void characterDataHandler(void *userData, const XML_Char *s, int len) | |
| static void endElement(void *userData, const XML_Char *name) | |
| { | |
| - | struct ParserStruct *state = (struct ParserStruct *) userData; |
| + | struct ParserStruct *state = (struct ParserStruct *)userData; |
| state->depth--; | |
| printf("%5lu %10lu %s\n", state->depth, state->characters.size, name); | |
| @@ -98,9 +98,9 @@ static void endElement(void *userData, const XML_Char *name) | |
| static size_t write_cb(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; | |
| - | struct ParserStruct *state = (struct ParserStruct *) XML_GetUserData(parser); |
| + | struct ParserStruct *state = (struct ParserStruct *)XML_GetUserData(parser); |
| /* Only parse if we are not already in a failure state. */ | |
| if(state->ok && XML_Parse(parser, contents, (int)real_size, 0) == 0) { | |