summaryrefslogtreecommitdiffstats
path: root/plugins/check_http.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r--plugins/check_http.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 5da5750..be18ce7 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -196,7 +196,7 @@ int server_port = HTTP_PORT;
196char server_port_text[6] = ""; 196char server_port_text[6] = "";
197char server_type[6] = "http"; 197char server_type[6] = "http";
198/*@null@*/ char *server_address = NULL; 198/*@null@*/ char *server_address = NULL;
199/*@null@*/ char *host_name = NULL; 199char *host_name = "";
200/*@null@*/ char *server_url = NULL; 200/*@null@*/ char *server_url = NULL;
201int server_url_length = 0; 201int server_url_length = 0;
202int server_expect_yn = 0; 202int server_expect_yn = 0;
@@ -401,7 +401,7 @@ process_arguments (int argc, char **argv)
401 break; 401 break;
402 /* Note: H, I, and u must be malloc'd or will fail on redirects */ 402 /* Note: H, I, and u must be malloc'd or will fail on redirects */
403 case 'H': /* Host Name (virtual host) */ 403 case 'H': /* Host Name (virtual host) */
404 host_name = strscpy (host_name, optarg); 404 asprintf (&host_name, "%s", optarg);
405 break; 405 break;
406 case 'I': /* Server IP-address */ 406 case 'I': /* Server IP-address */
407 server_address = strscpy (server_address, optarg); 407 server_address = strscpy (server_address, optarg);
@@ -464,19 +464,21 @@ process_arguments (int argc, char **argv)
464 464
465 c = optind; 465 c = optind;
466 466
467 if (server_address == NULL && host_name == NULL) { server_address = strscpy (NULL, argv[c]); 467 if (server_address == NULL) {
468 host_name = strscpy (NULL, argv[c++]); 468 if (c < argc) {
469 server_address = strscpy (NULL, argv[c++]);
470 }
471 else if (strcmp (host_name ,"") == 0) {
472 usage ("check_http: you must specify a server address\n");
473 }
469 } 474 }
470 475
471 if (server_address == NULL && host_name == NULL) 476 if (strcmp (host_name ,"") == 0 && c < argc)
472 usage ("check_http: you must specify a host name\n"); 477 asprintf (&host_name, "%s", argv[c++]);
473 478
474 if (server_address == NULL) 479 if (server_address == NULL)
475 server_address = strscpy (NULL, host_name); 480 server_address = strscpy (NULL, host_name);
476 481
477 if (host_name == NULL)
478 host_name = strscpy (NULL, server_address);
479
480 if (http_method == NULL) 482 if (http_method == NULL)
481 http_method = strscpy (http_method, "GET"); 483 http_method = strscpy (http_method, "GET");
482 484
@@ -631,8 +633,6 @@ check_http (void)
631 terminate (STATE_CRITICAL, "Unable to open TCP socket"); 633 terminate (STATE_CRITICAL, "Unable to open TCP socket");
632 asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url); 634 asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url);
633 send (sd, buf, strlen (buf), 0); 635 send (sd, buf, strlen (buf), 0);
634
635
636 636
637 /* optionally send the host header info */ 637 /* optionally send the host header info */
638 if (strcmp (host_name, "")) { 638 if (strcmp (host_name, "")) {
@@ -664,7 +664,7 @@ check_http (void)
664 send (sd, http_post_data, strlen (http_post_data), 0); 664 send (sd, http_post_data, strlen (http_post_data), 0);
665 } 665 }
666 else { 666 else {
667 /* send a newline so the server knows we're done with the request */ 667 /* or just a newline so the server knows we're done with the request */
668 asprintf (&buf, "\r\n"); 668 asprintf (&buf, "\r\n");
669 send (sd, buf, strlen (buf), 0); 669 send (sd, buf, strlen (buf), 0);
670 } 670 }