};
#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)
{
/* 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;
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);
#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
#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;
for(slist = certinfo->certinfo[i]; slist; slist = slist->next)
printf("%s\n", slist->data);
-
}
}
-
}
curl_easy_cleanup(curl);
return 0;
}
-int
-main(void)
+int main(void)
{
CURL *curl;
CURLcode res;
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 */
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");
}
/* 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;
xmlXPathObjectPtr result;
if(!doc)
return 0;
- xpath = (xmlChar*) "//a/@href";
+ xpath = (xmlChar *)"//a/@href";
context = xmlXPathNewContext(doc);
result = xmlXPathEvalExpression(xpath, context);
xmlXPathFreeContext(context);
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)) {
}
}
else {
- printf("[%d] HTTP %d: %s\n", complete, (int) res_status, url);
+ printf("[%d] HTTP %d: %s\n", complete, (int)res_status, url);
}
}
else {
callback.
*/
-
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#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 */
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;
memset(&its, 0, sizeof(its));
}
- timerfd_settime(g->tfd, /* flags= */0, &its, NULL);
+ timerfd_settime(g->tfd, /* flags= */ 0, &its, NULL);
return 0;
}
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);
/* 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);
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);
}
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();
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);
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! */
}
unlink(fifo);
}
-
int g_should_exit_ = 0;
void sigint_handler(int signo)
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) {
callback.
*/
-
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#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;
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);
}
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);
/* 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);
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);
}
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;
(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;
}
CURLMcode rc;
conn = calloc(1, sizeof(*conn));
- conn->error[0]='\0';
+ conn->error[0] = '\0';
conn->curl = curl_easy_init();
if(!conn->curl) {
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);
(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! */
}
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) {
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;
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;
CURL *curl;
/* help data */
- struct callback_data data = { 0 };
+ struct callback_data data = {0};
/* global initialization */
CURLcode res = curl_global_init(CURL_GLOBAL_ALL);
return fwrite(buffer, size, nmemb, out->stream);
}
-
int main(void)
{
CURL *curl;
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();
#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 "
return copylen;
}
- return 0; /* no more data left to deliver */
+ return 0; /* no more data left to deliver */
}
int main(void)
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;
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();
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");
}
{
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);
/* 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);
/* 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) {
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);
}
}
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;
(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;
}
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);
}
}
if(all) {
- new_conn(all, (struct GlobalInfo*)data);
+ new_conn(all, (struct GlobalInfo *)data);
g_free(all);
}
g_free(buf);
printf(" %s: %s (%u)\n", h->name, h->value, (unsigned int)h->amount);
prev = h;
} while(h);
-
}
/* always cleanup */
curl_easy_cleanup(curl);
#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;
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;
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);
/*
/* 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 =
/* 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);
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);
}
(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;
}
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);
(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;
}
}
unlink(fifo);
- if(mkfifo (fifo, 0600) == -1) {
+ if(mkfifo(fifo, 0600) == -1) {
perror("mkfifo");
return 1;
}
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;
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)
/* "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;
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(" ");
// libxml callback context structure
//
-struct Context
-{
- Context(): addTitle(false) { }
+struct Context {
+ Context() : addTitle(false) {}
bool addTitle;
std::string title;
if(writerData == NULL)
return 0;
- writerData->append(data, size*nmemb);
+ writerData->append(data, size * nmemb);
return size * nmemb;
}
return CURL_PUSH_OK;
}
-
/*
* Download a file over HTTP/2, take care of server push.
*/
#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 "
{
CURL *curl;
CURLcode res;
- FILE * hd_src;
+ FILE *hd_src;
struct stat file_info;
char *file;
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;
}
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");
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");
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];
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 */
{
struct curl_context *context;
- context = (struct curl_context *) malloc(sizeof(*context));
+ context = (struct curl_context *)malloc(sizeof(*context));
context->sockfd = sockfd;
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();
}
(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();
}
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;
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;
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 */
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;
case -1:
/* select error */
break;
- case 0: /* timeout */
+ case 0: /* timeout */
default: /* action */
curl_multi_perform(multi, &still_running);
break;
{
struct curl_context *context;
- context = (struct curl_context *) malloc(sizeof(*context));
+ context = (struct curl_context *)malloc(sizeof(*context));
context->sockfd = sockfd;
context->uv = uv;
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)
{
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;
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;
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;
int main(int argc, char **argv)
{
CURLcode res;
- struct datauv uv = { 0 };
+ struct datauv uv = {0};
int running_handles;
if(argc <= 1)
const char *url;
};
-
static void *pull_one_url(void *p)
{
CURL *curl;
return NULL;
}
-
/*
int pthread_create(pthread_t *new_thread_ID,
const pthread_attr_t *attr,
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);
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 */
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;
*
* Do something nice with it!
*/
- printf("%s\n",chunk.memory);
+ printf("%s\n", chunk.memory);
}
/* always cleanup */
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) {
return fwrite(buffer, size, nmemb, out->stream);
}
-
int main(void)
{
CURL *curl;
return remoteFileSizeByte;
}
-
static int sftpResumeUpload(CURL *curl, const char *remotepath,
const char *localpath)
{
#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;
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);
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
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,
/* 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",
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)
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;
}
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. */
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;
}
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");
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;
}
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");
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;
}
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");
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;
}
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");
* SSL backend has to be configured).
*
* **** This example only works with libcurl 7.56.0 and later! ****
-*/
+ */
int main(int argc, char **argv)
{
#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)) || \
#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>
#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;
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;
}
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);
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);
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) {
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);
#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/",
}
/* 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");
}
}
/* 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");
}
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++;
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);
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);
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) {