mirror of
https://github.com/moparisthebest/curl
synced 2024-12-24 09:08:49 -05:00
examples: reduce variable scopes
Closes https://github.com/curl/curl/pull/3919
This commit is contained in:
parent
918987a844
commit
10b7067eb7
@ -85,7 +85,6 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
|
|||||||
|
|
||||||
BIO *cbio = BIO_new_mem_buf(mypem, sizeof(mypem));
|
BIO *cbio = BIO_new_mem_buf(mypem, sizeof(mypem));
|
||||||
X509_STORE *cts = SSL_CTX_get_cert_store((SSL_CTX *)sslctx);
|
X509_STORE *cts = SSL_CTX_get_cert_store((SSL_CTX *)sslctx);
|
||||||
X509_INFO *itmp;
|
|
||||||
int i;
|
int i;
|
||||||
STACK_OF(X509_INFO) *inf;
|
STACK_OF(X509_INFO) *inf;
|
||||||
(void)curl;
|
(void)curl;
|
||||||
@ -103,7 +102,7 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < sk_X509_INFO_num(inf); i++) {
|
for(i = 0; i < sk_X509_INFO_num(inf); i++) {
|
||||||
itmp = sk_X509_INFO_value(inf, i);
|
X509_INFO *itmp = sk_X509_INFO_value(inf, i);
|
||||||
if(itmp->x509) {
|
if(itmp->x509) {
|
||||||
X509_STORE_add_cert(cts, itmp->x509);
|
X509_STORE_add_cert(cts, itmp->x509);
|
||||||
}
|
}
|
||||||
|
@ -45,13 +45,12 @@ int my_progress_func(GtkWidget *bar,
|
|||||||
void *my_thread(void *ptr)
|
void *my_thread(void *ptr)
|
||||||
{
|
{
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
FILE *outfile;
|
|
||||||
gchar *url = ptr;
|
|
||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if(curl) {
|
if(curl) {
|
||||||
|
gchar *url = ptr;
|
||||||
const char *filename = "test.curl";
|
const char *filename = "test.curl";
|
||||||
outfile = fopen(filename, "wb");
|
FILE *outfile = fopen(filename, "wb");
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile);
|
||||||
|
@ -472,8 +472,6 @@ void SignalHandler(int signo)
|
|||||||
int main(int argc _Unused, char **argv _Unused)
|
int main(int argc _Unused, char **argv _Unused)
|
||||||
{
|
{
|
||||||
GlobalInfo g;
|
GlobalInfo g;
|
||||||
int err;
|
|
||||||
int idx;
|
|
||||||
struct itimerspec its;
|
struct itimerspec its;
|
||||||
struct epoll_event ev;
|
struct epoll_event ev;
|
||||||
struct epoll_event events[10];
|
struct epoll_event events[10];
|
||||||
@ -518,8 +516,9 @@ int main(int argc _Unused, char **argv _Unused)
|
|||||||
fprintf(MSG_OUT, "Entering wait loop\n");
|
fprintf(MSG_OUT, "Entering wait loop\n");
|
||||||
fflush(MSG_OUT);
|
fflush(MSG_OUT);
|
||||||
while(!g_should_exit_) {
|
while(!g_should_exit_) {
|
||||||
err = epoll_wait(g.epfd, events, sizeof(events)/sizeof(struct epoll_event),
|
int idx;
|
||||||
10000);
|
int err = epoll_wait(g.epfd, events,
|
||||||
|
sizeof(events)/sizeof(struct epoll_event), 10000);
|
||||||
if(err == -1) {
|
if(err == -1) {
|
||||||
if(errno == EINTR) {
|
if(errno == EINTR) {
|
||||||
fprintf(MSG_OUT, "note: wait interrupted\n");
|
fprintf(MSG_OUT, "note: wait interrupted\n");
|
||||||
|
@ -74,13 +74,14 @@ void dumpNode(TidyDoc doc, TidyNode tnod, int indent)
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
if(argc == 2) {
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
char curl_errbuf[CURL_ERROR_SIZE];
|
char curl_errbuf[CURL_ERROR_SIZE];
|
||||||
TidyDoc tdoc;
|
TidyDoc tdoc;
|
||||||
TidyBuffer docbuf = {0};
|
TidyBuffer docbuf = {0};
|
||||||
TidyBuffer tidy_errbuf = {0};
|
TidyBuffer tidy_errbuf = {0};
|
||||||
int err;
|
int err;
|
||||||
if(argc == 2) {
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
||||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
|
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
|
||||||
|
@ -85,14 +85,15 @@ int main(void)
|
|||||||
{
|
{
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res = CURLE_OK;
|
CURLcode res = CURLE_OK;
|
||||||
|
|
||||||
|
curl = curl_easy_init();
|
||||||
|
if(curl) {
|
||||||
const char **p;
|
const char **p;
|
||||||
long infilesize;
|
long infilesize;
|
||||||
struct upload_status upload_ctx;
|
struct upload_status upload_ctx;
|
||||||
|
|
||||||
upload_ctx.lines_read = 0;
|
upload_ctx.lines_read = 0;
|
||||||
|
|
||||||
curl = curl_easy_init();
|
|
||||||
if(curl) {
|
|
||||||
/* Set username and password */
|
/* Set username and password */
|
||||||
curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
|
curl_easy_setopt(curl, CURLOPT_USERNAME, "user");
|
||||||
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
|
curl_easy_setopt(curl, CURLOPT_PASSWORD, "secret");
|
||||||
|
@ -147,11 +147,11 @@ int main(void)
|
|||||||
/* See how the transfers went */
|
/* See how the transfers went */
|
||||||
while((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
|
while((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
|
||||||
if(msg->msg == CURLMSG_DONE) {
|
if(msg->msg == CURLMSG_DONE) {
|
||||||
int idx, found = 0;
|
int idx;
|
||||||
|
|
||||||
/* Find out which handle this message is about */
|
/* Find out which handle this message is about */
|
||||||
for(idx = 0; idx<HANDLECOUNT; idx++) {
|
for(idx = 0; idx<HANDLECOUNT; idx++) {
|
||||||
found = (msg->easy_handle == handles[idx]);
|
int found = (msg->easy_handle == handles[idx]);
|
||||||
if(found)
|
if(found)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -59,12 +59,9 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
|
||||||
/* Minimalistic http request */
|
/* Minimalistic http request */
|
||||||
const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n";
|
const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n";
|
||||||
size_t request_len = strlen(request);
|
size_t request_len = strlen(request);
|
||||||
curl_socket_t sockfd;
|
|
||||||
size_t nsent_total = 0;
|
|
||||||
|
|
||||||
/* A general note of caution here: if you're using curl_easy_recv() or
|
/* A general note of caution here: if you're using curl_easy_recv() or
|
||||||
curl_easy_send() to implement HTTP or _any_ other protocol libcurl
|
curl_easy_send() to implement HTTP or _any_ other protocol libcurl
|
||||||
@ -76,6 +73,10 @@ int main(void)
|
|||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if(curl) {
|
if(curl) {
|
||||||
|
CURLcode res;
|
||||||
|
curl_socket_t sockfd;
|
||||||
|
size_t nsent_total = 0;
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
|
||||||
/* Do not do the transfer - only connect to host */
|
/* Do not do the transfer - only connect to host */
|
||||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
|
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
|
||||||
|
@ -46,8 +46,6 @@ static void my_unlock(CURL *handle, curl_lock_data data, void *useptr)
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
CURL *curl;
|
|
||||||
CURLcode res;
|
|
||||||
CURLSH *share;
|
CURLSH *share;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -61,8 +59,10 @@ int main(void)
|
|||||||
still reuse connections since the pool is in the shared object! */
|
still reuse connections since the pool is in the shared object! */
|
||||||
|
|
||||||
for(i = 0; i < 3; i++) {
|
for(i = 0; i < 3; i++) {
|
||||||
curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
if(curl) {
|
if(curl) {
|
||||||
|
CURLcode res;
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, "https://curl.haxx.se/");
|
curl_easy_setopt(curl, CURLOPT_URL, "https://curl.haxx.se/");
|
||||||
|
|
||||||
/* use the share object */
|
/* use the share object */
|
||||||
|
@ -67,13 +67,12 @@ size_t write_file(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
|||||||
/* https://weather.com/weather/today/l/46214?cc=*&dayf=5&unit=i */
|
/* https://weather.com/weather/today/l/46214?cc=*&dayf=5&unit=i */
|
||||||
void *pull_one_url(void *NaN)
|
void *pull_one_url(void *NaN)
|
||||||
{
|
{
|
||||||
CURL *curl;
|
|
||||||
gchar *http;
|
|
||||||
FILE *outfile;
|
|
||||||
|
|
||||||
/* Stop threads from entering unless j is incremented */
|
/* Stop threads from entering unless j is incremented */
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
while(j < num_urls) {
|
while(j < num_urls) {
|
||||||
|
CURL *curl;
|
||||||
|
gchar *http;
|
||||||
|
|
||||||
printf("j = %d\n", j);
|
printf("j = %d\n", j);
|
||||||
|
|
||||||
http =
|
http =
|
||||||
@ -85,7 +84,7 @@ void *pull_one_url(void *NaN)
|
|||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if(curl) {
|
if(curl) {
|
||||||
|
|
||||||
outfile = fopen(urls[j], "wb");
|
FILE *outfile = fopen(urls[j], "wb");
|
||||||
|
|
||||||
/* Set the URL and transfer type */
|
/* Set the URL and transfer type */
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, http);
|
curl_easy_setopt(curl, CURLOPT_URL, http);
|
||||||
|
@ -70,6 +70,9 @@ int main(void)
|
|||||||
{
|
{
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res = CURLE_OK;
|
CURLcode res = CURLE_OK;
|
||||||
|
|
||||||
|
curl = curl_easy_init();
|
||||||
|
if(curl) {
|
||||||
struct curl_slist *headers = NULL;
|
struct curl_slist *headers = NULL;
|
||||||
struct curl_slist *recipients = NULL;
|
struct curl_slist *recipients = NULL;
|
||||||
struct curl_slist *slist = NULL;
|
struct curl_slist *slist = NULL;
|
||||||
@ -78,8 +81,6 @@ int main(void)
|
|||||||
curl_mimepart *part;
|
curl_mimepart *part;
|
||||||
const char **cpp;
|
const char **cpp;
|
||||||
|
|
||||||
curl = curl_easy_init();
|
|
||||||
if(curl) {
|
|
||||||
/* This is the URL for your mailserver */
|
/* This is the URL for your mailserver */
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
|
curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
|
||||||
|
|
||||||
|
@ -257,25 +257,15 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
conf_t conf[1];
|
conf_t conf[1];
|
||||||
int OptionIndex;
|
|
||||||
struct tm *lt;
|
|
||||||
struct tm *gmt;
|
|
||||||
time_t tt;
|
|
||||||
time_t tt_local;
|
|
||||||
time_t tt_gmt;
|
|
||||||
double tzonediffFloat;
|
|
||||||
int tzonediffWord;
|
|
||||||
char timeBuf[61];
|
|
||||||
char tzoneBuf[16];
|
|
||||||
int RetValue;
|
int RetValue;
|
||||||
|
|
||||||
OptionIndex = 0;
|
|
||||||
ShowAllHeader = 0; /* Do not show HTTP Header */
|
ShowAllHeader = 0; /* Do not show HTTP Header */
|
||||||
AutoSyncTime = 0; /* Do not synchronise computer clock */
|
AutoSyncTime = 0; /* Do not synchronise computer clock */
|
||||||
RetValue = 0; /* Successful Exit */
|
RetValue = 0; /* Successful Exit */
|
||||||
conf_init(conf);
|
conf_init(conf);
|
||||||
|
|
||||||
if(argc > 1) {
|
if(argc > 1) {
|
||||||
|
int OptionIndex = 0;
|
||||||
while(OptionIndex < argc) {
|
while(OptionIndex < argc) {
|
||||||
if(strncmp(argv[OptionIndex], "--server=", 9) == 0)
|
if(strncmp(argv[OptionIndex], "--server=", 9) == 0)
|
||||||
snprintf(conf->timeserver, MAX_STRING, "%s", &argv[OptionIndex][9]);
|
snprintf(conf->timeserver, MAX_STRING, "%s", &argv[OptionIndex][9]);
|
||||||
@ -308,6 +298,16 @@ int main(int argc, char *argv[])
|
|||||||
curl_global_init(CURL_GLOBAL_ALL);
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
if(curl) {
|
if(curl) {
|
||||||
|
struct tm *lt;
|
||||||
|
struct tm *gmt;
|
||||||
|
time_t tt;
|
||||||
|
time_t tt_local;
|
||||||
|
time_t tt_gmt;
|
||||||
|
double tzonediffFloat;
|
||||||
|
int tzonediffWord;
|
||||||
|
char timeBuf[61];
|
||||||
|
char tzoneBuf[16];
|
||||||
|
|
||||||
SyncTime_CURL_Init(curl, conf->http_proxy, conf->proxy_user);
|
SyncTime_CURL_Init(curl, conf->http_proxy, conf->proxy_user);
|
||||||
|
|
||||||
/* Calculating time diff between GMT and localtime */
|
/* Calculating time diff between GMT and localtime */
|
||||||
|
Loading…
Reference in New Issue
Block a user