diff options
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r-- | plugins/check_curl.c | 264 |
1 files changed, 167 insertions, 97 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c index 2ad373c0..c51914a9 100644 --- a/plugins/check_curl.c +++ b/plugins/check_curl.c | |||
@@ -37,6 +37,7 @@ const char *progname = "check_curl"; | |||
37 | const char *copyright = "2006-2019"; | 37 | const char *copyright = "2006-2019"; |
38 | const char *email = "devel@monitoring-plugins.org"; | 38 | const char *email = "devel@monitoring-plugins.org"; |
39 | 39 | ||
40 | #include <stdbool.h> | ||
40 | #include <ctype.h> | 41 | #include <ctype.h> |
41 | 42 | ||
42 | #include "common.h" | 43 | #include "common.h" |
@@ -54,6 +55,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
54 | #include "uriparser/Uri.h" | 55 | #include "uriparser/Uri.h" |
55 | 56 | ||
56 | #include <arpa/inet.h> | 57 | #include <arpa/inet.h> |
58 | #include <netinet/in.h> | ||
57 | 59 | ||
58 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | 60 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) |
59 | #include <openssl/opensslv.h> | 61 | #include <openssl/opensslv.h> |
@@ -131,14 +133,14 @@ regmatch_t pmatch[REGS]; | |||
131 | char regexp[MAX_RE_SIZE]; | 133 | char regexp[MAX_RE_SIZE]; |
132 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; | 134 | int cflags = REG_NOSUB | REG_EXTENDED | REG_NEWLINE; |
133 | int errcode; | 135 | int errcode; |
134 | int invert_regex = 0; | 136 | bool invert_regex = false; |
135 | 137 | ||
136 | char *server_address = NULL; | 138 | char *server_address = NULL; |
137 | char *host_name = NULL; | 139 | char *host_name = NULL; |
138 | char *server_url = 0; | 140 | char *server_url = 0; |
139 | char server_ip[DEFAULT_BUFFER_SIZE]; | 141 | char server_ip[DEFAULT_BUFFER_SIZE]; |
140 | struct curl_slist *server_ips = NULL; | 142 | struct curl_slist *server_ips = NULL; |
141 | int specify_port = FALSE; | 143 | bool specify_port = false; |
142 | unsigned short server_port = HTTP_PORT; | 144 | unsigned short server_port = HTTP_PORT; |
143 | unsigned short virtual_port = 0; | 145 | unsigned short virtual_port = 0; |
144 | int host_name_length; | 146 | int host_name_length; |
@@ -150,8 +152,8 @@ int days_till_exp_warn, days_till_exp_crit; | |||
150 | thresholds *thlds; | 152 | thresholds *thlds; |
151 | char user_agent[DEFAULT_BUFFER_SIZE]; | 153 | char user_agent[DEFAULT_BUFFER_SIZE]; |
152 | int verbose = 0; | 154 | int verbose = 0; |
153 | int show_extended_perfdata = FALSE; | 155 | bool show_extended_perfdata = false; |
154 | int show_body = FALSE; | 156 | bool show_body = false; |
155 | int min_page_len = 0; | 157 | int min_page_len = 0; |
156 | int max_page_len = 0; | 158 | int max_page_len = 0; |
157 | int redir_depth = 0; | 159 | int redir_depth = 0; |
@@ -160,10 +162,16 @@ char *http_method = NULL; | |||
160 | char *http_post_data = NULL; | 162 | char *http_post_data = NULL; |
161 | char *http_content_type = NULL; | 163 | char *http_content_type = NULL; |
162 | CURL *curl; | 164 | CURL *curl; |
165 | bool curl_global_initialized = false; | ||
166 | bool curl_easy_initialized = false; | ||
163 | struct curl_slist *header_list = NULL; | 167 | struct curl_slist *header_list = NULL; |
168 | bool body_buf_initialized = false; | ||
164 | curlhelp_write_curlbuf body_buf; | 169 | curlhelp_write_curlbuf body_buf; |
170 | bool header_buf_initialized = false; | ||
165 | curlhelp_write_curlbuf header_buf; | 171 | curlhelp_write_curlbuf header_buf; |
172 | bool status_line_initialized = false; | ||
166 | curlhelp_statusline status_line; | 173 | curlhelp_statusline status_line; |
174 | bool put_buf_initialized = false; | ||
167 | curlhelp_read_curlbuf put_buf; | 175 | curlhelp_read_curlbuf put_buf; |
168 | char http_header[DEFAULT_BUFFER_SIZE]; | 176 | char http_header[DEFAULT_BUFFER_SIZE]; |
169 | long code; | 177 | long code; |
@@ -173,7 +181,7 @@ double time_connect; | |||
173 | double time_appconnect; | 181 | double time_appconnect; |
174 | double time_headers; | 182 | double time_headers; |
175 | double time_firstbyte; | 183 | double time_firstbyte; |
176 | char errbuf[CURL_ERROR_SIZE+1]; | 184 | char errbuf[MAX_INPUT_BUFFER]; |
177 | CURLcode res; | 185 | CURLcode res; |
178 | char url[DEFAULT_BUFFER_SIZE]; | 186 | char url[DEFAULT_BUFFER_SIZE]; |
179 | char msg[DEFAULT_BUFFER_SIZE]; | 187 | char msg[DEFAULT_BUFFER_SIZE]; |
@@ -186,14 +194,14 @@ char user_auth[MAX_INPUT_BUFFER] = ""; | |||
186 | char proxy_auth[MAX_INPUT_BUFFER] = ""; | 194 | char proxy_auth[MAX_INPUT_BUFFER] = ""; |
187 | char **http_opt_headers; | 195 | char **http_opt_headers; |
188 | int http_opt_headers_count = 0; | 196 | int http_opt_headers_count = 0; |
189 | int display_html = FALSE; | 197 | bool display_html = false; |
190 | int onredirect = STATE_OK; | 198 | int onredirect = STATE_OK; |
191 | int followmethod = FOLLOW_HTTP_CURL; | 199 | int followmethod = FOLLOW_HTTP_CURL; |
192 | int followsticky = STICKY_NONE; | 200 | int followsticky = STICKY_NONE; |
193 | int use_ssl = FALSE; | 201 | bool use_ssl = false; |
194 | int use_sni = TRUE; | 202 | bool use_sni = true; |
195 | int check_cert = FALSE; | 203 | bool check_cert = false; |
196 | int continue_after_check_cert = FALSE; | 204 | bool continue_after_check_cert = false; |
197 | typedef union { | 205 | typedef union { |
198 | struct curl_slist* to_info; | 206 | struct curl_slist* to_info; |
199 | struct curl_certinfo* to_certinfo; | 207 | struct curl_certinfo* to_certinfo; |
@@ -203,19 +211,20 @@ int ssl_version = CURL_SSLVERSION_DEFAULT; | |||
203 | char *client_cert = NULL; | 211 | char *client_cert = NULL; |
204 | char *client_privkey = NULL; | 212 | char *client_privkey = NULL; |
205 | char *ca_cert = NULL; | 213 | char *ca_cert = NULL; |
206 | int verify_peer_and_host = FALSE; | 214 | bool verify_peer_and_host = false; |
207 | int is_openssl_callback = FALSE; | 215 | bool is_openssl_callback = false; |
208 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | 216 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) |
209 | X509 *cert = NULL; | 217 | X509 *cert = NULL; |
210 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ | 218 | #endif /* defined(HAVE_SSL) && defined(USE_OPENSSL) */ |
211 | int no_body = FALSE; | 219 | bool no_body = false; |
212 | int maximum_age = -1; | 220 | int maximum_age = -1; |
213 | int address_family = AF_UNSPEC; | 221 | int address_family = AF_UNSPEC; |
214 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; | 222 | curlhelp_ssl_library ssl_library = CURLHELP_SSL_LIBRARY_UNKNOWN; |
215 | int curl_http_version = CURL_HTTP_VERSION_NONE; | 223 | int curl_http_version = CURL_HTTP_VERSION_NONE; |
216 | int automatic_decompression = FALSE; | 224 | bool automatic_decompression = false; |
225 | char *cookie_jar_file = NULL; | ||
217 | 226 | ||
218 | int process_arguments (int, char**); | 227 | bool process_arguments (int, char**); |
219 | void handle_curl_option_return_code (CURLcode res, const char* option); | 228 | void handle_curl_option_return_code (CURLcode res, const char* option); |
220 | int check_http (void); | 229 | int check_http (void); |
221 | void redir (curlhelp_write_curlbuf*); | 230 | void redir (curlhelp_write_curlbuf*); |
@@ -269,10 +278,10 @@ main (int argc, char **argv) | |||
269 | progname, NP_VERSION, VERSION, curl_version()); | 278 | progname, NP_VERSION, VERSION, curl_version()); |
270 | 279 | ||
271 | /* parse arguments */ | 280 | /* parse arguments */ |
272 | if (process_arguments (argc, argv) == ERROR) | 281 | if (process_arguments (argc, argv) == false) |
273 | usage4 (_("Could not parse arguments")); | 282 | usage4 (_("Could not parse arguments")); |
274 | 283 | ||
275 | if (display_html == TRUE) | 284 | if (display_html) |
276 | printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", | 285 | printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", |
277 | use_ssl ? "https" : "http", | 286 | use_ssl ? "https" : "http", |
278 | host_name ? host_name : server_address, | 287 | host_name ? host_name : server_address, |
@@ -376,8 +385,11 @@ int | |||
376 | lookup_host (const char *host, char *buf, size_t buflen) | 385 | lookup_host (const char *host, char *buf, size_t buflen) |
377 | { | 386 | { |
378 | struct addrinfo hints, *res, *result; | 387 | struct addrinfo hints, *res, *result; |
388 | char addrstr[100]; | ||
389 | size_t addrstr_len; | ||
379 | int errcode; | 390 | int errcode; |
380 | void *ptr; | 391 | void *ptr; |
392 | size_t buflen_remaining = buflen - 1; | ||
381 | 393 | ||
382 | memset (&hints, 0, sizeof (hints)); | 394 | memset (&hints, 0, sizeof (hints)); |
383 | hints.ai_family = address_family; | 395 | hints.ai_family = address_family; |
@@ -387,31 +399,62 @@ lookup_host (const char *host, char *buf, size_t buflen) | |||
387 | errcode = getaddrinfo (host, NULL, &hints, &result); | 399 | errcode = getaddrinfo (host, NULL, &hints, &result); |
388 | if (errcode != 0) | 400 | if (errcode != 0) |
389 | return errcode; | 401 | return errcode; |
390 | 402 | ||
403 | strcpy(buf, ""); | ||
391 | res = result; | 404 | res = result; |
392 | 405 | ||
393 | while (res) { | 406 | while (res) { |
394 | inet_ntop (res->ai_family, res->ai_addr->sa_data, buf, buflen); | 407 | switch (res->ai_family) { |
395 | switch (res->ai_family) { | 408 | case AF_INET: |
396 | case AF_INET: | 409 | ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; |
397 | ptr = &((struct sockaddr_in *) res->ai_addr)->sin_addr; | 410 | break; |
398 | break; | 411 | case AF_INET6: |
399 | case AF_INET6: | 412 | ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; |
400 | ptr = &((struct sockaddr_in6 *) res->ai_addr)->sin6_addr; | 413 | break; |
401 | break; | ||
402 | } | 414 | } |
403 | inet_ntop (res->ai_family, ptr, buf, buflen); | 415 | |
404 | if (verbose >= 1) | 416 | inet_ntop (res->ai_family, ptr, addrstr, 100); |
417 | if (verbose >= 1) { | ||
405 | printf ("* getaddrinfo IPv%d address: %s\n", | 418 | printf ("* getaddrinfo IPv%d address: %s\n", |
406 | res->ai_family == PF_INET6 ? 6 : 4, buf); | 419 | res->ai_family == PF_INET6 ? 6 : 4, addrstr); |
420 | } | ||
421 | |||
422 | // Append all IPs to buf as a comma-separated string | ||
423 | addrstr_len = strlen(addrstr); | ||
424 | if (buflen_remaining > addrstr_len + 1) { | ||
425 | if (buf[0] != '\0') { | ||
426 | strncat(buf, ",", buflen_remaining); | ||
427 | buflen_remaining -= 1; | ||
428 | } | ||
429 | strncat(buf, addrstr, buflen_remaining); | ||
430 | buflen_remaining -= addrstr_len; | ||
431 | } | ||
432 | |||
407 | res = res->ai_next; | 433 | res = res->ai_next; |
408 | } | 434 | } |
409 | 435 | ||
410 | freeaddrinfo(result); | 436 | freeaddrinfo(result); |
411 | 437 | ||
412 | return 0; | 438 | return 0; |
413 | } | 439 | } |
414 | 440 | ||
441 | static void | ||
442 | cleanup (void) | ||
443 | { | ||
444 | if (status_line_initialized) curlhelp_free_statusline(&status_line); | ||
445 | status_line_initialized = false; | ||
446 | if (curl_easy_initialized) curl_easy_cleanup (curl); | ||
447 | curl_easy_initialized = false; | ||
448 | if (curl_global_initialized) curl_global_cleanup (); | ||
449 | curl_global_initialized = false; | ||
450 | if (body_buf_initialized) curlhelp_freewritebuffer (&body_buf); | ||
451 | body_buf_initialized = false; | ||
452 | if (header_buf_initialized) curlhelp_freewritebuffer (&header_buf); | ||
453 | header_buf_initialized = false; | ||
454 | if (put_buf_initialized) curlhelp_freereadbuffer (&put_buf); | ||
455 | put_buf_initialized = false; | ||
456 | } | ||
457 | |||
415 | int | 458 | int |
416 | check_http (void) | 459 | check_http (void) |
417 | { | 460 | { |
@@ -420,18 +463,24 @@ check_http (void) | |||
420 | int i; | 463 | int i; |
421 | char *force_host_header = NULL; | 464 | char *force_host_header = NULL; |
422 | struct curl_slist *host = NULL; | 465 | struct curl_slist *host = NULL; |
423 | char addrstr[100]; | 466 | char addrstr[DEFAULT_BUFFER_SIZE/2]; |
424 | char dnscache[DEFAULT_BUFFER_SIZE]; | 467 | char dnscache[DEFAULT_BUFFER_SIZE]; |
425 | 468 | ||
426 | /* initialize curl */ | 469 | /* initialize curl */ |
427 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) | 470 | if (curl_global_init (CURL_GLOBAL_DEFAULT) != CURLE_OK) |
428 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); | 471 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_global_init failed\n"); |
472 | curl_global_initialized = true; | ||
429 | 473 | ||
430 | if ((curl = curl_easy_init()) == NULL) | 474 | if ((curl = curl_easy_init()) == NULL) { |
431 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); | 475 | die (STATE_UNKNOWN, "HTTP UNKNOWN - curl_easy_init failed\n"); |
476 | } | ||
477 | curl_easy_initialized = true; | ||
432 | 478 | ||
479 | /* register cleanup function to shut down libcurl properly */ | ||
480 | atexit (cleanup); | ||
481 | |||
433 | if (verbose >= 1) | 482 | if (verbose >= 1) |
434 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, TRUE), "CURLOPT_VERBOSE"); | 483 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_VERBOSE, 1), "CURLOPT_VERBOSE"); |
435 | 484 | ||
436 | /* print everything on stdout like check_http would do */ | 485 | /* print everything on stdout like check_http would do */ |
437 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); | 486 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_STDERR, stdout), "CURLOPT_STDERR"); |
@@ -446,12 +495,14 @@ check_http (void) | |||
446 | /* initialize buffer for body of the answer */ | 495 | /* initialize buffer for body of the answer */ |
447 | if (curlhelp_initwritebuffer(&body_buf) < 0) | 496 | if (curlhelp_initwritebuffer(&body_buf) < 0) |
448 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); | 497 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for body\n"); |
498 | body_buf_initialized = true; | ||
449 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_WRITEFUNCTION"); | 499 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_WRITEFUNCTION"); |
450 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA"); | 500 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)&body_buf), "CURLOPT_WRITEDATA"); |
451 | 501 | ||
452 | /* initialize buffer for header of the answer */ | 502 | /* initialize buffer for header of the answer */ |
453 | if (curlhelp_initwritebuffer( &header_buf ) < 0) | 503 | if (curlhelp_initwritebuffer( &header_buf ) < 0) |
454 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" ); | 504 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating buffer for header\n" ); |
505 | header_buf_initialized = true; | ||
455 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_HEADERFUNCTION"); | 506 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_HEADERFUNCTION, (curl_write_callback)curlhelp_buffer_write_callback), "CURLOPT_HEADERFUNCTION"); |
456 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER"); | 507 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_WRITEHEADER, (void *)&header_buf), "CURLOPT_WRITEHEADER"); |
457 | 508 | ||
@@ -464,7 +515,7 @@ check_http (void) | |||
464 | 515 | ||
465 | // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy | 516 | // fill dns resolve cache to make curl connect to the given server_address instead of the host_name, only required for ssl, because we use the host_name later on to make SNI happy |
466 | if(use_ssl && host_name != NULL) { | 517 | if(use_ssl && host_name != NULL) { |
467 | if ( (res=lookup_host (server_address, addrstr, 100)) != 0) { | 518 | if ( (res=lookup_host (server_address, addrstr, DEFAULT_BUFFER_SIZE/2)) != 0) { |
468 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), | 519 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("Unable to lookup IP address for '%s': getaddrinfo returned %d - %s"), |
469 | server_address, res, gai_strerror (res)); | 520 | server_address, res, gai_strerror (res)); |
470 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); | 521 | die (STATE_CRITICAL, "HTTP CRITICAL - %s\n", msg); |
@@ -491,7 +542,7 @@ check_http (void) | |||
491 | /* compose URL: use the address we want to connect to, set Host: header later */ | 542 | /* compose URL: use the address we want to connect to, set Host: header later */ |
492 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", | 543 | snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", |
493 | use_ssl ? "https" : "http", | 544 | use_ssl ? "https" : "http", |
494 | use_ssl & host_name != NULL ? host_name : server_address, | 545 | ( use_ssl & ( host_name != NULL ) ) ? host_name : server_address, |
495 | server_port, | 546 | server_port, |
496 | server_url | 547 | server_url |
497 | ); | 548 | ); |
@@ -512,7 +563,7 @@ check_http (void) | |||
512 | 563 | ||
513 | /* disable body for HEAD request */ | 564 | /* disable body for HEAD request */ |
514 | if (http_method && !strcmp (http_method, "HEAD" )) { | 565 | if (http_method && !strcmp (http_method, "HEAD" )) { |
515 | no_body = TRUE; | 566 | no_body = true; |
516 | } | 567 | } |
517 | 568 | ||
518 | /* set HTTP protocol version */ | 569 | /* set HTTP protocol version */ |
@@ -609,7 +660,7 @@ check_http (void) | |||
609 | #ifdef USE_OPENSSL | 660 | #ifdef USE_OPENSSL |
610 | /* libcurl and monitoring plugins built with OpenSSL, good */ | 661 | /* libcurl and monitoring plugins built with OpenSSL, good */ |
611 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); | 662 | handle_curl_option_return_code (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, sslctxfun), "CURLOPT_SSL_CTX_FUNCTION"); |
612 | is_openssl_callback = TRUE; | 663 | is_openssl_callback = true; |
613 | #else /* USE_OPENSSL */ | 664 | #else /* USE_OPENSSL */ |
614 | #endif /* USE_OPENSSL */ | 665 | #endif /* USE_OPENSSL */ |
615 | /* libcurl is built with OpenSSL, monitoring plugins, so falling | 666 | /* libcurl is built with OpenSSL, monitoring plugins, so falling |
@@ -688,9 +739,11 @@ check_http (void) | |||
688 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS"); | 739 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_MAXREDIRS, max_depth+1), "CURLOPT_MAXREDIRS"); |
689 | 740 | ||
690 | /* for now allow only http and https (we are a http(s) check plugin in the end) */ | 741 | /* for now allow only http and https (we are a http(s) check plugin in the end) */ |
691 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) | 742 | #if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 85, 0) |
743 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS_STR, "http,https"), "CURLOPT_REDIR_PROTOCOLS_STR"); | ||
744 | #elif LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) | ||
692 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS"); | 745 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS), "CURLOPT_REDIRECT_PROTOCOLS"); |
693 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 19, 4) */ | 746 | #endif |
694 | 747 | ||
695 | /* TODO: handle the following aspects of redirection, make them | 748 | /* TODO: handle the following aspects of redirection, make them |
696 | * command line options too later: | 749 | * command line options too later: |
@@ -734,11 +787,19 @@ check_http (void) | |||
734 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS"); | 787 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http_post_data), "CURLOPT_POSTFIELDS"); |
735 | } else if (!strcmp(http_method, "PUT")) { | 788 | } else if (!strcmp(http_method, "PUT")) { |
736 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READFUNCTION, (curl_read_callback)curlhelp_buffer_read_callback), "CURLOPT_READFUNCTION"); | 789 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READFUNCTION, (curl_read_callback)curlhelp_buffer_read_callback), "CURLOPT_READFUNCTION"); |
737 | curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)); | 790 | if (curlhelp_initreadbuffer (&put_buf, http_post_data, strlen (http_post_data)) < 0) |
791 | die (STATE_UNKNOWN, "HTTP CRITICAL - out of memory allocating read buffer for PUT\n"); | ||
792 | put_buf_initialized = true; | ||
738 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA"); | 793 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_READDATA, (void *)&put_buf), "CURLOPT_READDATA"); |
739 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE"); | 794 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_INFILESIZE, (curl_off_t)strlen (http_post_data)), "CURLOPT_INFILESIZE"); |
740 | } | 795 | } |
741 | } | 796 | } |
797 | |||
798 | /* cookie handling */ | ||
799 | if (cookie_jar_file != NULL) { | ||
800 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEJAR, cookie_jar_file), "CURLOPT_COOKIEJAR"); | ||
801 | handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_COOKIEFILE, cookie_jar_file), "CURLOPT_COOKIEFILE"); | ||
802 | } | ||
742 | 803 | ||
743 | /* do the request */ | 804 | /* do the request */ |
744 | res = curl_easy_perform(curl); | 805 | res = curl_easy_perform(curl); |
@@ -749,6 +810,9 @@ check_http (void) | |||
749 | /* free header and server IP resolve lists, we don't need it anymore */ | 810 | /* free header and server IP resolve lists, we don't need it anymore */ |
750 | curl_slist_free_all (header_list); header_list = NULL; | 811 | curl_slist_free_all (header_list); header_list = NULL; |
751 | curl_slist_free_all (server_ips); server_ips = NULL; | 812 | curl_slist_free_all (server_ips); server_ips = NULL; |
813 | if (host) { | ||
814 | curl_slist_free_all (host); host = NULL; | ||
815 | } | ||
752 | 816 | ||
753 | /* Curl errors, result in critical Nagios state */ | 817 | /* Curl errors, result in critical Nagios state */ |
754 | if (res != CURLE_OK) { | 818 | if (res != CURLE_OK) { |
@@ -759,15 +823,15 @@ check_http (void) | |||
759 | 823 | ||
760 | /* certificate checks */ | 824 | /* certificate checks */ |
761 | #ifdef LIBCURL_FEATURE_SSL | 825 | #ifdef LIBCURL_FEATURE_SSL |
762 | if (use_ssl == TRUE) { | 826 | if (use_ssl) { |
763 | if (check_cert == TRUE) { | 827 | if (check_cert) { |
764 | if (is_openssl_callback) { | 828 | if (is_openssl_callback) { |
765 | #ifdef USE_OPENSSL | 829 | #ifdef USE_OPENSSL |
766 | /* check certificate with OpenSSL functions, curl has been built against OpenSSL | 830 | /* check certificate with OpenSSL functions, curl has been built against OpenSSL |
767 | * and we actually have OpenSSL in the monitoring tools | 831 | * and we actually have OpenSSL in the monitoring tools |
768 | */ | 832 | */ |
769 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | 833 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); |
770 | if (continue_after_check_cert == FALSE) { | 834 | if (!continue_after_check_cert) { |
771 | return result; | 835 | return result; |
772 | } | 836 | } |
773 | #else /* USE_OPENSSL */ | 837 | #else /* USE_OPENSSL */ |
@@ -809,7 +873,7 @@ GOT_FIRST_CERT: | |||
809 | } | 873 | } |
810 | BIO_free (cert_BIO); | 874 | BIO_free (cert_BIO); |
811 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); | 875 | result = np_net_ssl_check_certificate(cert, days_till_exp_warn, days_till_exp_crit); |
812 | if (continue_after_check_cert == FALSE) { | 876 | if (!continue_after_check_cert) { |
813 | return result; | 877 | return result; |
814 | } | 878 | } |
815 | #else /* USE_OPENSSL */ | 879 | #else /* USE_OPENSSL */ |
@@ -817,7 +881,7 @@ GOT_FIRST_CERT: | |||
817 | * so we use the libcurl CURLINFO data | 881 | * so we use the libcurl CURLINFO data |
818 | */ | 882 | */ |
819 | result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); | 883 | result = net_noopenssl_check_certificate(&cert_ptr, days_till_exp_warn, days_till_exp_crit); |
820 | if (continue_after_check_cert == FALSE) { | 884 | if (!continue_after_check_cert) { |
821 | return result; | 885 | return result; |
822 | } | 886 | } |
823 | #endif /* USE_OPENSSL */ | 887 | #endif /* USE_OPENSSL */ |
@@ -845,7 +909,7 @@ GOT_FIRST_CERT: | |||
845 | perfd_time(total_time), | 909 | perfd_time(total_time), |
846 | perfd_size(page_len), | 910 | perfd_size(page_len), |
847 | perfd_time_connect(time_connect), | 911 | perfd_time_connect(time_connect), |
848 | use_ssl == TRUE ? perfd_time_ssl (time_appconnect-time_connect) : "", | 912 | use_ssl ? perfd_time_ssl (time_appconnect-time_connect) : "", |
849 | perfd_time_headers(time_headers - time_appconnect), | 913 | perfd_time_headers(time_headers - time_appconnect), |
850 | perfd_time_firstbyte(time_firstbyte - time_headers), | 914 | perfd_time_firstbyte(time_firstbyte - time_headers), |
851 | perfd_time_transfer(total_time-time_firstbyte) | 915 | perfd_time_transfer(total_time-time_firstbyte) |
@@ -868,6 +932,7 @@ GOT_FIRST_CERT: | |||
868 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ | 932 | /* we cannot know the major/minor version here for sure as we cannot parse the first line */ |
869 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); | 933 | die (STATE_CRITICAL, "HTTP CRITICAL HTTP/x.x %ld unknown - %s", code, msg); |
870 | } | 934 | } |
935 | status_line_initialized = true; | ||
871 | 936 | ||
872 | /* get result code from cURL */ | 937 | /* get result code from cURL */ |
873 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); | 938 | handle_curl_option_return_code (curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &code), "CURLINFO_RESPONSE_CODE"); |
@@ -980,12 +1045,12 @@ GOT_FIRST_CERT: | |||
980 | 1045 | ||
981 | if (strlen (regexp)) { | 1046 | if (strlen (regexp)) { |
982 | errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0); | 1047 | errcode = regexec (&preg, body_buf.buf, REGS, pmatch, 0); |
983 | if ((errcode == 0 && invert_regex == 0) || (errcode == REG_NOMATCH && invert_regex == 1)) { | 1048 | if ((errcode == 0 && !invert_regex) || (errcode == REG_NOMATCH && invert_regex)) { |
984 | /* OK - No-op to avoid changing the logic around it */ | 1049 | /* OK - No-op to avoid changing the logic around it */ |
985 | result = max_state_alt(STATE_OK, result); | 1050 | result = max_state_alt(STATE_OK, result); |
986 | } | 1051 | } |
987 | else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { | 1052 | else if ((errcode == REG_NOMATCH && !invert_regex) || (errcode == 0 && invert_regex)) { |
988 | if (invert_regex == 0) | 1053 | if (!invert_regex) |
989 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); | 1054 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern not found, "), msg); |
990 | else | 1055 | else |
991 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); | 1056 | snprintf (msg, DEFAULT_BUFFER_SIZE, _("%spattern found, "), msg); |
@@ -1017,7 +1082,7 @@ GOT_FIRST_CERT: | |||
1017 | else | 1082 | else |
1018 | msg[strlen(msg)-3] = '\0'; | 1083 | msg[strlen(msg)-3] = '\0'; |
1019 | } | 1084 | } |
1020 | 1085 | ||
1021 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ | 1086 | /* TODO: separate _() msg and status code: die (result, "HTTP %s: %s\n", state_text(result), msg); */ |
1022 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", | 1087 | die (result, "HTTP %s: %s %d %s%s%s - %d bytes in %.3f second response time %s|%s\n%s%s", |
1023 | state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), | 1088 | state_text(result), string_statuscode (status_line.http_major, status_line.http_minor), |
@@ -1029,16 +1094,6 @@ GOT_FIRST_CERT: | |||
1029 | (show_body ? body_buf.buf : ""), | 1094 | (show_body ? body_buf.buf : ""), |
1030 | (show_body ? "\n" : "") ); | 1095 | (show_body ? "\n" : "") ); |
1031 | 1096 | ||
1032 | /* proper cleanup after die? */ | ||
1033 | curlhelp_free_statusline(&status_line); | ||
1034 | curl_easy_cleanup (curl); | ||
1035 | curl_global_cleanup (); | ||
1036 | curlhelp_freewritebuffer (&body_buf); | ||
1037 | curlhelp_freewritebuffer (&header_buf); | ||
1038 | if (!strcmp (http_method, "PUT")) { | ||
1039 | curlhelp_freereadbuffer (&put_buf); | ||
1040 | } | ||
1041 | |||
1042 | return result; | 1097 | return result; |
1043 | } | 1098 | } |
1044 | 1099 | ||
@@ -1134,7 +1189,10 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
1134 | } | 1189 | } |
1135 | } | 1190 | } |
1136 | 1191 | ||
1137 | use_ssl = !uri_strcmp (uri.scheme, "https"); | 1192 | if (!uri_strcmp (uri.scheme, "https")) |
1193 | use_ssl = true; | ||
1194 | else | ||
1195 | use_ssl = false; | ||
1138 | 1196 | ||
1139 | /* we do a sloppy test here only, because uriparser would have failed | 1197 | /* we do a sloppy test here only, because uriparser would have failed |
1140 | * above, if the port would be invalid, we just check for MAX_PORT | 1198 | * above, if the port would be invalid, we just check for MAX_PORT |
@@ -1209,6 +1267,7 @@ redir (curlhelp_write_curlbuf* header_buf) | |||
1209 | * attached to the URL in Location | 1267 | * attached to the URL in Location |
1210 | */ | 1268 | */ |
1211 | 1269 | ||
1270 | cleanup (); | ||
1212 | check_http (); | 1271 | check_http (); |
1213 | } | 1272 | } |
1214 | 1273 | ||
@@ -1221,7 +1280,7 @@ test_file (char *path) | |||
1221 | usage2 (_("file does not exist or is not readable"), path); | 1280 | usage2 (_("file does not exist or is not readable"), path); |
1222 | } | 1281 | } |
1223 | 1282 | ||
1224 | int | 1283 | bool |
1225 | process_arguments (int argc, char **argv) | 1284 | process_arguments (int argc, char **argv) |
1226 | { | 1285 | { |
1227 | char *p; | 1286 | char *p; |
@@ -1235,7 +1294,8 @@ process_arguments (int argc, char **argv) | |||
1235 | CONTINUE_AFTER_CHECK_CERT, | 1294 | CONTINUE_AFTER_CHECK_CERT, |
1236 | CA_CERT_OPTION, | 1295 | CA_CERT_OPTION, |
1237 | HTTP_VERSION_OPTION, | 1296 | HTTP_VERSION_OPTION, |
1238 | AUTOMATIC_DECOMPRESSION | 1297 | AUTOMATIC_DECOMPRESSION, |
1298 | COOKIE_JAR | ||
1239 | }; | 1299 | }; |
1240 | 1300 | ||
1241 | int option = 0; | 1301 | int option = 0; |
@@ -1281,11 +1341,12 @@ process_arguments (int argc, char **argv) | |||
1281 | {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, | 1341 | {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, |
1282 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, | 1342 | {"http-version", required_argument, 0, HTTP_VERSION_OPTION}, |
1283 | {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, | 1343 | {"enable-automatic-decompression", no_argument, 0, AUTOMATIC_DECOMPRESSION}, |
1344 | {"cookie-jar", required_argument, 0, COOKIE_JAR}, | ||
1284 | {0, 0, 0, 0} | 1345 | {0, 0, 0, 0} |
1285 | }; | 1346 | }; |
1286 | 1347 | ||
1287 | if (argc < 2) | 1348 | if (argc < 2) |
1288 | return ERROR; | 1349 | return false; |
1289 | 1350 | ||
1290 | /* support check_http compatible arguments */ | 1351 | /* support check_http compatible arguments */ |
1291 | for (c = 1; c < argc; c++) { | 1352 | for (c = 1; c < argc; c++) { |
@@ -1365,7 +1426,7 @@ process_arguments (int argc, char **argv) | |||
1365 | if( strtol(optarg, NULL, 10) > MAX_PORT) | 1426 | if( strtol(optarg, NULL, 10) > MAX_PORT) |
1366 | usage2 (_("Invalid port number, supplied port number is too big"), optarg); | 1427 | usage2 (_("Invalid port number, supplied port number is too big"), optarg); |
1367 | server_port = (unsigned short)strtol(optarg, NULL, 10); | 1428 | server_port = (unsigned short)strtol(optarg, NULL, 10); |
1368 | specify_port = TRUE; | 1429 | specify_port = true; |
1369 | } | 1430 | } |
1370 | break; | 1431 | break; |
1371 | case 'a': /* authorization info */ | 1432 | case 'a': /* authorization info */ |
@@ -1399,10 +1460,10 @@ process_arguments (int argc, char **argv) | |||
1399 | http_opt_headers[http_opt_headers_count - 1] = optarg; | 1460 | http_opt_headers[http_opt_headers_count - 1] = optarg; |
1400 | break; | 1461 | break; |
1401 | case 'L': /* show html link */ | 1462 | case 'L': /* show html link */ |
1402 | display_html = TRUE; | 1463 | display_html = true; |
1403 | break; | 1464 | break; |
1404 | case 'n': /* do not show html link */ | 1465 | case 'n': /* do not show html link */ |
1405 | display_html = FALSE; | 1466 | display_html = false; |
1406 | break; | 1467 | break; |
1407 | case 'C': /* Check SSL cert validity */ | 1468 | case 'C': /* Check SSL cert validity */ |
1408 | #ifdef LIBCURL_FEATURE_SSL | 1469 | #ifdef LIBCURL_FEATURE_SSL |
@@ -1423,12 +1484,12 @@ process_arguments (int argc, char **argv) | |||
1423 | usage2 (_("Invalid certificate expiration period"), optarg); | 1484 | usage2 (_("Invalid certificate expiration period"), optarg); |
1424 | days_till_exp_warn = atoi (optarg); | 1485 | days_till_exp_warn = atoi (optarg); |
1425 | } | 1486 | } |
1426 | check_cert = TRUE; | 1487 | check_cert = true; |
1427 | goto enable_ssl; | 1488 | goto enable_ssl; |
1428 | #endif | 1489 | #endif |
1429 | case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */ | 1490 | case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */ |
1430 | #ifdef HAVE_SSL | 1491 | #ifdef HAVE_SSL |
1431 | continue_after_check_cert = TRUE; | 1492 | continue_after_check_cert = true; |
1432 | break; | 1493 | break; |
1433 | #endif | 1494 | #endif |
1434 | case 'J': /* use client certificate */ | 1495 | case 'J': /* use client certificate */ |
@@ -1451,13 +1512,13 @@ process_arguments (int argc, char **argv) | |||
1451 | #endif | 1512 | #endif |
1452 | #ifdef LIBCURL_FEATURE_SSL | 1513 | #ifdef LIBCURL_FEATURE_SSL |
1453 | case 'D': /* verify peer certificate & host */ | 1514 | case 'D': /* verify peer certificate & host */ |
1454 | verify_peer_and_host = TRUE; | 1515 | verify_peer_and_host = true; |
1455 | break; | 1516 | break; |
1456 | #endif | 1517 | #endif |
1457 | case 'S': /* use SSL */ | 1518 | case 'S': /* use SSL */ |
1458 | #ifdef LIBCURL_FEATURE_SSL | 1519 | #ifdef LIBCURL_FEATURE_SSL |
1459 | enable_ssl: | 1520 | enable_ssl: |
1460 | use_ssl = TRUE; | 1521 | use_ssl = true; |
1461 | /* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default. | 1522 | /* ssl_version initialized to CURL_SSLVERSION_DEFAULT as a default. |
1462 | * Only set if it's non-zero. This helps when we include multiple | 1523 | * Only set if it's non-zero. This helps when we include multiple |
1463 | * parameters, like -S and -C combinations */ | 1524 | * parameters, like -S and -C combinations */ |
@@ -1531,15 +1592,15 @@ process_arguments (int argc, char **argv) | |||
1531 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */ | 1592 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 54, 0) */ |
1532 | if (verbose >= 2) | 1593 | if (verbose >= 2) |
1533 | printf(_("* Set SSL/TLS version to %d\n"), ssl_version); | 1594 | printf(_("* Set SSL/TLS version to %d\n"), ssl_version); |
1534 | if (specify_port == FALSE) | 1595 | if (!specify_port) |
1535 | server_port = HTTPS_PORT; | 1596 | server_port = HTTPS_PORT; |
1536 | break; | 1597 | break; |
1537 | #else /* LIBCURL_FEATURE_SSL */ | 1598 | #else /* LIBCURL_FEATURE_SSL */ |
1538 | /* -C -J and -K fall through to here without SSL */ | 1599 | /* -C -J and -K fall through to here without SSL */ |
1539 | usage4 (_("Invalid option - SSL is not available")); | 1600 | usage4 (_("Invalid option - SSL is not available")); |
1540 | break; | 1601 | break; |
1541 | case SNI_OPTION: /* --sni is parsed, but ignored, the default is TRUE with libcurl */ | 1602 | case SNI_OPTION: /* --sni is parsed, but ignored, the default is true with libcurl */ |
1542 | use_sni = TRUE; | 1603 | use_sni = true; |
1543 | break; | 1604 | break; |
1544 | #endif /* LIBCURL_FEATURE_SSL */ | 1605 | #endif /* LIBCURL_FEATURE_SSL */ |
1545 | case MAX_REDIRS_OPTION: | 1606 | case MAX_REDIRS_OPTION: |
@@ -1600,11 +1661,11 @@ process_arguments (int argc, char **argv) | |||
1600 | if (errcode != 0) { | 1661 | if (errcode != 0) { |
1601 | (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); | 1662 | (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); |
1602 | printf (_("Could Not Compile Regular Expression: %s"), errbuf); | 1663 | printf (_("Could Not Compile Regular Expression: %s"), errbuf); |
1603 | return ERROR; | 1664 | return false; |
1604 | } | 1665 | } |
1605 | break; | 1666 | break; |
1606 | case INVERT_REGEX: | 1667 | case INVERT_REGEX: |
1607 | invert_regex = 1; | 1668 | invert_regex = true; |
1608 | break; | 1669 | break; |
1609 | case '4': | 1670 | case '4': |
1610 | address_family = AF_INET; | 1671 | address_family = AF_INET; |
@@ -1639,7 +1700,7 @@ process_arguments (int argc, char **argv) | |||
1639 | break; | 1700 | break; |
1640 | } | 1701 | } |
1641 | case 'N': /* no-body */ | 1702 | case 'N': /* no-body */ |
1642 | no_body = TRUE; | 1703 | no_body = true; |
1643 | break; | 1704 | break; |
1644 | case 'M': /* max-age */ | 1705 | case 'M': /* max-age */ |
1645 | { | 1706 | { |
@@ -1662,10 +1723,10 @@ process_arguments (int argc, char **argv) | |||
1662 | } | 1723 | } |
1663 | break; | 1724 | break; |
1664 | case 'E': /* show extended perfdata */ | 1725 | case 'E': /* show extended perfdata */ |
1665 | show_extended_perfdata = TRUE; | 1726 | show_extended_perfdata = true; |
1666 | break; | 1727 | break; |
1667 | case 'B': /* print body content after status line */ | 1728 | case 'B': /* print body content after status line */ |
1668 | show_body = TRUE; | 1729 | show_body = true; |
1669 | break; | 1730 | break; |
1670 | case HTTP_VERSION_OPTION: | 1731 | case HTTP_VERSION_OPTION: |
1671 | curl_http_version = CURL_HTTP_VERSION_NONE; | 1732 | curl_http_version = CURL_HTTP_VERSION_NONE; |
@@ -1680,12 +1741,15 @@ process_arguments (int argc, char **argv) | |||
1680 | curl_http_version = CURL_HTTP_VERSION_NONE; | 1741 | curl_http_version = CURL_HTTP_VERSION_NONE; |
1681 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 33, 0) */ | 1742 | #endif /* LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 33, 0) */ |
1682 | } else { | 1743 | } else { |
1683 | fprintf (stderr, "unkown http-version parameter: %s\n", optarg); | 1744 | fprintf (stderr, "unknown http-version parameter: %s\n", optarg); |
1684 | exit (STATE_WARNING); | 1745 | exit (STATE_WARNING); |
1685 | } | 1746 | } |
1686 | break; | 1747 | break; |
1687 | case AUTOMATIC_DECOMPRESSION: | 1748 | case AUTOMATIC_DECOMPRESSION: |
1688 | automatic_decompression = TRUE; | 1749 | automatic_decompression = true; |
1750 | break; | ||
1751 | case COOKIE_JAR: | ||
1752 | cookie_jar_file = optarg; | ||
1689 | break; | 1753 | break; |
1690 | case '?': | 1754 | case '?': |
1691 | /* print short usage statement if args not parsable */ | 1755 | /* print short usage statement if args not parsable */ |
@@ -1726,52 +1790,52 @@ process_arguments (int argc, char **argv) | |||
1726 | virtual_port = server_port; | 1790 | virtual_port = server_port; |
1727 | else { | 1791 | else { |
1728 | if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT)) | 1792 | if ((use_ssl && server_port == HTTPS_PORT) || (!use_ssl && server_port == HTTP_PORT)) |
1729 | if(specify_port == FALSE) | 1793 | if(!specify_port) |
1730 | server_port = virtual_port; | 1794 | server_port = virtual_port; |
1731 | } | 1795 | } |
1732 | 1796 | ||
1733 | return TRUE; | 1797 | return true; |
1734 | } | 1798 | } |
1735 | 1799 | ||
1736 | char *perfd_time (double elapsed_time) | 1800 | char *perfd_time (double elapsed_time) |
1737 | { | 1801 | { |
1738 | return fperfdata ("time", elapsed_time, "s", | 1802 | return fperfdata ("time", elapsed_time, "s", |
1739 | thlds->warning?TRUE:FALSE, thlds->warning?thlds->warning->end:0, | 1803 | thlds->warning?true:false, thlds->warning?thlds->warning->end:0, |
1740 | thlds->critical?TRUE:FALSE, thlds->critical?thlds->critical->end:0, | 1804 | thlds->critical?true:false, thlds->critical?thlds->critical->end:0, |
1741 | TRUE, 0, TRUE, socket_timeout); | 1805 | true, 0, true, socket_timeout); |
1742 | } | 1806 | } |
1743 | 1807 | ||
1744 | char *perfd_time_connect (double elapsed_time_connect) | 1808 | char *perfd_time_connect (double elapsed_time_connect) |
1745 | { | 1809 | { |
1746 | return fperfdata ("time_connect", elapsed_time_connect, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1810 | return fperfdata ("time_connect", elapsed_time_connect, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1747 | } | 1811 | } |
1748 | 1812 | ||
1749 | char *perfd_time_ssl (double elapsed_time_ssl) | 1813 | char *perfd_time_ssl (double elapsed_time_ssl) |
1750 | { | 1814 | { |
1751 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1815 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1752 | } | 1816 | } |
1753 | 1817 | ||
1754 | char *perfd_time_headers (double elapsed_time_headers) | 1818 | char *perfd_time_headers (double elapsed_time_headers) |
1755 | { | 1819 | { |
1756 | return fperfdata ("time_headers", elapsed_time_headers, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1820 | return fperfdata ("time_headers", elapsed_time_headers, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1757 | } | 1821 | } |
1758 | 1822 | ||
1759 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) | 1823 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) |
1760 | { | 1824 | { |
1761 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1825 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1762 | } | 1826 | } |
1763 | 1827 | ||
1764 | char *perfd_time_transfer (double elapsed_time_transfer) | 1828 | char *perfd_time_transfer (double elapsed_time_transfer) |
1765 | { | 1829 | { |
1766 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", FALSE, 0, FALSE, 0, FALSE, 0, TRUE, socket_timeout); | 1830 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1767 | } | 1831 | } |
1768 | 1832 | ||
1769 | char *perfd_size (int page_len) | 1833 | char *perfd_size (int page_len) |
1770 | { | 1834 | { |
1771 | return perfdata ("size", page_len, "B", | 1835 | return perfdata ("size", page_len, "B", |
1772 | (min_page_len>0?TRUE:FALSE), min_page_len, | 1836 | (min_page_len>0?true:false), min_page_len, |
1773 | (min_page_len>0?TRUE:FALSE), 0, | 1837 | (min_page_len>0?true:false), 0, |
1774 | TRUE, 0, FALSE, 0); | 1838 | true, 0, false, 0); |
1775 | } | 1839 | } |
1776 | 1840 | ||
1777 | void | 1841 | void |
@@ -1906,6 +1970,8 @@ print_help (void) | |||
1906 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); | 1970 | printf (" %s\n", _("1.0 = HTTP/1.0, 1.1 = HTTP/1.1, 2.0 = HTTP/2 (HTTP/2 will fail without -S)")); |
1907 | printf (" %s\n", "--enable-automatic-decompression"); | 1971 | printf (" %s\n", "--enable-automatic-decompression"); |
1908 | printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); | 1972 | printf (" %s\n", _("Enable automatic decompression of body (CURLOPT_ACCEPT_ENCODING).")); |
1973 | printf (" %s\n", "---cookie-jar=FILE"); | ||
1974 | printf (" %s\n", _("Store cookies in the cookie jar and send them out when requested.")); | ||
1909 | printf ("\n"); | 1975 | printf ("\n"); |
1910 | 1976 | ||
1911 | printf (UT_WARN_CRIT); | 1977 | printf (UT_WARN_CRIT); |
@@ -1990,7 +2056,8 @@ print_usage (void) | |||
1990 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); | 2056 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
1991 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); | 2057 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); |
1992 | printf (" [-T <content-type>] [-j method]\n"); | 2058 | printf (" [-T <content-type>] [-j method]\n"); |
1993 | printf (" [--http-version=<version>]\n"); | 2059 | printf (" [--http-version=<version>] [--enable-automatic-decompression]\n"); |
2060 | printf (" [--cookie-jar=<cookie jar file>\n"); | ||
1994 | printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname); | 2061 | printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname); |
1995 | printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); | 2062 | printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); |
1996 | printf ("\n"); | 2063 | printf ("\n"); |
@@ -2024,9 +2091,12 @@ curlhelp_buffer_write_callback (void *buffer, size_t size, size_t nmemb, void *s | |||
2024 | curlhelp_write_curlbuf *buf = (curlhelp_write_curlbuf *)stream; | 2091 | curlhelp_write_curlbuf *buf = (curlhelp_write_curlbuf *)stream; |
2025 | 2092 | ||
2026 | while (buf->bufsize < buf->buflen + size * nmemb + 1) { | 2093 | while (buf->bufsize < buf->buflen + size * nmemb + 1) { |
2027 | buf->bufsize *= buf->bufsize * 2; | 2094 | buf->bufsize = buf->bufsize * 2; |
2028 | buf->buf = (char *)realloc (buf->buf, buf->bufsize); | 2095 | buf->buf = (char *)realloc (buf->buf, buf->bufsize); |
2029 | if (buf->buf == NULL) return -1; | 2096 | if (buf->buf == NULL) { |
2097 | fprintf(stderr, "malloc failed (%d) %s\n", errno, strerror(errno)); | ||
2098 | return -1; | ||
2099 | } | ||
2030 | } | 2100 | } |
2031 | 2101 | ||
2032 | memcpy (buf->buf + buf->buflen, buffer, size * nmemb); | 2102 | memcpy (buf->buf + buf->buflen, buffer, size * nmemb); |