[Nagiosplug-checkins] CVS: nagiosplug/plugins check_http.c,1.4,1.5
Karl DeBisschop
kdebisschop at users.sourceforge.net
Wed Sep 25 00:59:02 CEST 2002
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv18758
Modified Files:
check_http.c
Log Message:
incorporate comments from Russell Scibetti
Index: check_http.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_http.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** check_http.c 24 Sep 2002 05:16:12 -0000 1.4
--- check_http.c 25 Sep 2002 07:58:08 -0000 1.5
***************
*** 178,182 ****
#define HTTP_URL "/"
! char timestamp[10] = "";
int specify_port = FALSE;
int server_port = HTTP_PORT;
--- 178,182 ----
#define HTTP_URL "/"
! char timestamp[17] = "";
int specify_port = FALSE;
int server_port = HTTP_PORT;
***************
*** 435,439 ****
errcode = regcomp (&preg, regexp, cflags);
if (errcode != 0) {
! regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
printf ("Could Not Compile Regular Expression: %s", errbuf);
return ERROR;
--- 435,439 ----
errcode = regcomp (&preg, regexp, cflags);
if (errcode != 0) {
! (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
printf ("Could Not Compile Regular Expression: %s", errbuf);
return ERROR;
***************
*** 531,535 ****
--- 531,538 ----
size_t pagesize = 0;
char *full_page = NULL;
+ char *buf = NULL;
char *pos = NULL;
+ char *x = NULL;
+ char *orig_url = NULL;
/* try to connect to the host at the given port number */
***************
*** 550,555 ****
}
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "%s %s HTTP/1.0\r\n", http_method, server_url);
! if (SSL_write (ssl, buffer, strlen (buffer)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
--- 553,558 ----
}
! buf = ssprintf (buf, "%s %s HTTP/1.0\r\n", http_method, server_url);
! if (SSL_write (ssl, buf, strlen (buf)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
***************
*** 558,563 ****
/* optionally send the host header info (not clear if it's usable) */
if (strcmp (host_name, "")) {
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "Host: %s\r\n", host_name);
! if (SSL_write (ssl, buffer, strlen (buffer)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
--- 561,566 ----
/* optionally send the host header info (not clear if it's usable) */
if (strcmp (host_name, "")) {
! buf = ssprintf (buf, "Host: %s\r\n", host_name);
! if (SSL_write (ssl, buf, strlen (buf)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
***************
*** 566,572 ****
/* send user agent */
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "User-Agent: check_http/%s (nagios-plugins %s)\r\n",
clean_revstring (REVISION), PACKAGE_VERSION);
! if (SSL_write (ssl, buffer, strlen (buffer)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
--- 569,575 ----
/* send user agent */
! buf = ssprintf (buf, "User-Agent: check_http/%s (nagios-plugins %s)\r\n",
clean_revstring (REVISION), PACKAGE_VERSION);
! if (SSL_write (ssl, buf, strlen (buf)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
***************
*** 576,581 ****
if (strcmp (user_auth, "")) {
auth = base64 (user_auth, strlen (user_auth));
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "Authorization: Basic %s\r\n", auth);
! if (SSL_write (ssl, buffer, strlen (buffer)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
--- 579,584 ----
if (strcmp (user_auth, "")) {
auth = base64 (user_auth, strlen (user_auth));
! buf = ssprintf (buf, "Authorization: Basic %s\r\n", auth);
! if (SSL_write (ssl, buf, strlen (buf)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
***************
*** 585,595 ****
/* optionally send http POST data */
if (http_post_data) {
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "Content-Type: application/x-www-form-urlencoded\r\n");
! if (SSL_write (ssl, buffer, strlen (buffer)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
}
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "Content-Length: %i\r\n\r\n", strlen (http_post_data));
! if (SSL_write (ssl, buffer, strlen (buffer)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
--- 588,598 ----
/* optionally send http POST data */
if (http_post_data) {
! buf = ssprintf (buf, "Content-Type: application/x-www-form-urlencoded\r\n");
! if (SSL_write (ssl, buf, strlen (buf)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
}
! buf = ssprintf (buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data));
! if (SSL_write (ssl, buf, strlen (buf)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
***************
*** 603,608 ****
/* send a newline so the server knows we're done with the request */
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "\r\n\r\n");
! if (SSL_write (ssl, buffer, strlen (buffer)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
--- 606,611 ----
/* send a newline so the server knows we're done with the request */
! buf = ssprintf (buf, "\r\n\r\n");
! if (SSL_write (ssl, buf, strlen (buf)) == -1) {
ERR_print_errors_fp (stderr);
return STATE_CRITICAL;
***************
*** 616,621 ****
terminate (STATE_CRITICAL, msg);
}
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "%s %s HTTP/1.0\r\n", http_method, server_url);
! send (sd, buffer, strlen (buffer), 0);
--- 619,624 ----
terminate (STATE_CRITICAL, msg);
}
! buf = ssprintf (buf, "%s %s HTTP/1.0\r\n", http_method, server_url);
! send (sd, buf, strlen (buf), 0);
***************
*** 623,641 ****
/* optionally send the host header info */
if (strcmp (host_name, "")) {
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "Host: %s\r\n", host_name);
! send (sd, buffer, strlen (buffer), 0);
}
/* send user agent */
! snprintf (buffer, MAX_INPUT_BUFFER - 1,
"User-Agent: check_http/%s (nagios-plugins %s)\r\n",
clean_revstring (REVISION), PACKAGE_VERSION);
! send (sd, buffer, strlen (buffer), 0);
/* optionally send the authentication info */
if (strcmp (user_auth, "")) {
auth = base64 (user_auth, strlen (user_auth));
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "Authorization: Basic %s\r\n", auth);
! send (sd, buffer, strlen (buffer), 0);
}
--- 626,644 ----
/* optionally send the host header info */
if (strcmp (host_name, "")) {
! buf = ssprintf (buf, "Host: %s\r\n", host_name);
! send (sd, buf, strlen (buf), 0);
}
/* send user agent */
! buf = ssprintf (buf,
"User-Agent: check_http/%s (nagios-plugins %s)\r\n",
clean_revstring (REVISION), PACKAGE_VERSION);
! send (sd, buf, strlen (buf), 0);
/* optionally send the authentication info */
if (strcmp (user_auth, "")) {
auth = base64 (user_auth, strlen (user_auth));
! buf = ssprintf (buf, "Authorization: Basic %s\r\n", auth);
! send (sd, buf, strlen (buf), 0);
}
***************
*** 643,650 ****
/* written by Chris Henesy <lurker at shadowtech.org> */
if (http_post_data) {
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "Content-Type: application/x-www-form-urlencoded\r\n");
! send (sd, buffer, strlen (buffer), 0);
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "Content-Length: %i\r\n\r\n", strlen (http_post_data));
! send (sd, buffer, strlen (buffer), 0);
http_post_data = strscat (http_post_data, "\r\n");
send (sd, http_post_data, strlen (http_post_data), 0);
--- 646,653 ----
/* written by Chris Henesy <lurker at shadowtech.org> */
if (http_post_data) {
! buf = ssprintf (buf, "Content-Type: application/x-www-form-urlencoded\r\n");
! send (sd, buf, strlen (buf), 0);
! buf = ssprintf (buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data));
! send (sd, buf, strlen (buf), 0);
http_post_data = strscat (http_post_data, "\r\n");
send (sd, http_post_data, strlen (http_post_data), 0);
***************
*** 652,657 ****
/* send a newline so the server knows we're done with the request */
! snprintf (buffer, MAX_INPUT_BUFFER - 1, "\r\n\r\n");
! send (sd, buffer, strlen (buffer), 0);
#ifdef HAVE_SSL
}
--- 655,660 ----
/* send a newline so the server knows we're done with the request */
! buf = ssprintf (buf, "\r\n\r\n");
! send (sd, buf, strlen (buf), 0);
#ifdef HAVE_SSL
}
***************
*** 760,764 ****
strstr (status_line, "304")) {
if (onredirect == STATE_DEPENDENT) {
!
pos = header;
while (pos) {
--- 763,768 ----
strstr (status_line, "304")) {
if (onredirect == STATE_DEPENDENT) {
!
! orig_url = strscpy(NULL, server_url);
pos = header;
while (pos) {
***************
*** 767,776 ****
terminate (STATE_UNKNOWN,
"HTTP UNKNOWN: could not allocate server_address");
! if (strspn (pos, "\r\n") > server_url_length) {
! server_url = realloc (server_url, strspn (pos, "\r\n"));
if (server_url == NULL)
terminate (STATE_UNKNOWN,
! "HTTP UNKNOWN: could not allocate server_url");
! server_url_length = strspn (pos, "\r\n");
}
if (sscanf (pos, HDR_LOCATION URI_HTTP URI_HOST URI_PORT URI_PATH, server_type, server_address, server_port_text, server_url) == 4) {
--- 771,780 ----
terminate (STATE_UNKNOWN,
"HTTP UNKNOWN: could not allocate server_address");
! if (strcspn (pos, "\r\n") > server_url_length) {
! server_url = realloc (server_url, strcspn (pos, "\r\n"));
if (server_url == NULL)
terminate (STATE_UNKNOWN,
! "HTTP UNKNOWN: could not allocate server_url");
! server_url_length = strcspn (pos, "\r\n");
}
if (sscanf (pos, HDR_LOCATION URI_HTTP URI_HOST URI_PORT URI_PATH, server_type, server_address, server_port_text, server_url) == 4) {
***************
*** 800,806 ****
check_http ();
}
! else if (sscanf (pos, HDR_LOCATION URI_PATH, server_url) == 1) {
check_http ();
! }
pos += (size_t) strcspn (pos, "\r\n");
pos += (size_t) strspn (pos, "\r\n");
--- 804,814 ----
check_http ();
}
! else if (sscanf (pos, HDR_LOCATION URI_PATH, server_url) == 1) {
! if ((server_url[0] != '/') && (x = strrchr(orig_url, '/'))) {
! *x = '\0';
! server_url = ssprintf (server_url, "%s/%s", orig_url, server_url);
! }
check_http ();
! }
pos += (size_t) strcspn (pos, "\r\n");
pos += (size_t) strspn (pos, "\r\n");
***************
*** 946,951 ****
struct tm stamp;
int days_left;
- /* int result = STATE_OK; */
- /* char timestamp[14]; */
--- 954,957 ----
***************
*** 992,996 ****
days_left = (mktime (&stamp) - time (NULL)) / 86400;
snprintf
! (timestamp, MAX_INPUT_BUFFER - 1, "%02d/%02d/%04d %02d:%02d",
stamp.tm_mon + 1,
stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
--- 998,1002 ----
days_left = (mktime (&stamp) - time (NULL)) / 86400;
snprintf
! (timestamp, 16, "%02d/%02d/%04d %02d:%02d",
stamp.tm_mon + 1,
stamp.tm_mday, stamp.tm_year + 1900, stamp.tm_hour, stamp.tm_min);
More information about the Commits
mailing list