[Nagiosplug-checkins] CVS: nagiosplug/plugins check_http.c,1.20,1.21

Karl DeBisschop kdebisschop at users.sourceforge.net
Fri Feb 7 21:33:02 CET 2003


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1:/tmp/cvs-serv12969/plugins

Modified Files:
	check_http.c 
Log Message:
submit request with one send

Index: check_http.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_http.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -r1.20 -r1.21
*** check_http.c	5 Feb 2003 05:57:27 -0000	1.20
--- check_http.c	8 Feb 2003 05:32:40 -0000	1.21
***************
*** 161,166 ****
  
  #ifdef HAVE_REGEX_H
! #define REGS 2
! #define MAX_RE_SIZE 256
  #include <regex.h>
  regex_t preg;
--- 161,168 ----
  
  #ifdef HAVE_REGEX_H
! enum {
! 	REGS = 2,
! 	MAX_RE_SIZE = 256
! };
  #include <regex.h>
  regex_t preg;
***************
*** 179,183 ****
  #define server_port_check(use_ssl) (use_ssl ? HTTPS_PORT : HTTP_PORT)
  
- #define MAX_IPV4_HOSTLENGTH 64
  #define HDR_LOCATION "%*[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]: "
  #define URI_HTTP "%[HTPShtps]://"
--- 181,184 ----
***************
*** 186,191 ****
  #define URI_PATH "%[/a-zA-Z0-9._-=@,]"
  
! #define HTTP_PORT 80
! #define HTTPS_PORT 443
  #define HTTP_EXPECT "HTTP/1."
  #define HTTP_URL "/"
--- 187,196 ----
  #define URI_PATH "%[/a-zA-Z0-9._-=@,]"
  
! enum {
! 	MAX_IPV4_HOSTLENGTH = 64,
! 	HTTP_PORT = 80,
! 	HTTPS_PORT = 443
! };
! 
  #define HTTP_EXPECT "HTTP/1."
  #define HTTP_URL "/"
***************
*** 550,555 ****
  	if (use_ssl == TRUE) {
  
! 		if (connect_SSL () != OK)
  			terminate (STATE_CRITICAL, "Unable to open TCP socket");
  
  		if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
--- 555,561 ----
  	if (use_ssl == TRUE) {
  
! 		if (connect_SSL () != OK) {
  			terminate (STATE_CRITICAL, "Unable to open TCP socket");
+ 		}
  
  		if ((server_cert = SSL_get_peer_certificate (ssl)) != NULL) {
***************
*** 561,628 ****
  		}
  
- 		asprintf (&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;
- 		}
- 
- 		/* optionally send the host header info (not clear if it's usable) */
- 		if (strcmp (host_name, "")) {
- 			asprintf (&buf, "Host: %s\r\n", host_name);
- 			if (SSL_write (ssl, buf, strlen (buf)) == -1) {
- 				ERR_print_errors_fp (stderr);
- 				return STATE_CRITICAL;
- 			}
- 		}
- 
- 		/* send user agent */
- 		asprintf (&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;
- 		}
- 
- 		/* optionally send the authentication info */
- 		if (strcmp (user_auth, "")) {
- 			auth = base64 (user_auth, strlen (user_auth));
- 			asprintf (&buf, "Authorization: Basic %s\r\n", auth);
- 			if (SSL_write (ssl, buf, strlen (buf)) == -1) {
- 				ERR_print_errors_fp (stderr);
- 				return STATE_CRITICAL;
- 			}
- 		}
- 
- 		/* either send http POST data */
- 		if (strlen (http_post_data)) {
- 			asprintf (&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;
- 			}
- 			asprintf (&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;
- 			}
- 			if (SSL_write (ssl, http_post_data, strlen (http_post_data)) == -1) {
- 				ERR_print_errors_fp (stderr);
- 				return STATE_CRITICAL;
- 			}
- 			asprintf (&buf, CRLF);
- 			if (SSL_write (ssl, buf, strlen (buf)) == -1) {
- 				ERR_print_errors_fp (stderr);
- 				return STATE_CRITICAL;
- 			}
- 		}
- 		else {
- 			/* or just a newline so the server knows we're done with the request */
- 			asprintf (&buf, "\r\n");
- 			if (SSL_write (ssl, buf, strlen (buf)) == -1) {
- 				ERR_print_errors_fp (stderr);
- 				return STATE_CRITICAL;
- 			}
- 		}
- 
  	}
  	else {
--- 567,570 ----
***************
*** 630,670 ****
  		if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
  			terminate (STATE_CRITICAL, "Unable to open TCP socket");
! 		asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url);
! 		send (sd, buf, strlen (buf), 0);
  
! 		/* optionally send the host header info */
! 		if (strcmp (host_name, "")) {
! 			asprintf (&buf, "Host: %s\r\n", host_name);
! 			send (sd, buf, strlen (buf), 0);
! 		}
  
! 		/* send user agent */
! 		asprintf (&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));
! 			asprintf (&buf, "Authorization: Basic %s\r\n", auth);
! 			send (sd, buf, strlen (buf), 0);
! 		}
  
! 		/* either send http POST data */
! 		/* written by Chris Henesy <lurker at shadowtech.org> */
! 		if (strlen (http_post_data)) {
! 			asprintf (&buf, "Content-Type: application/x-www-form-urlencoded\r\n");
! 			send (sd, buf, strlen (buf), 0);
! 			asprintf (&buf, "Content-Length: %i\r\n\r\n", strlen (http_post_data));
! 			send (sd, buf, strlen (buf), 0);
! 			send (sd, http_post_data, strlen (http_post_data), 0);
! 			send (sd, CRLF, strlen (CRLF), 0);
! 		}
! 		else {
! 			/* or just a newline so the server knows we're done with the request */
! 			asprintf (&buf, "\r\n");
! 			send (sd, buf, strlen (buf), 0);
  		}
  #ifdef HAVE_SSL
  	}
--- 572,616 ----
  		if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
  			terminate (STATE_CRITICAL, "Unable to open TCP socket");
! #ifdef HAVE_SSL
! 	}
! #endif
  
! 	asprintf (&buf, "%s %s HTTP/1.0\r\n", http_method, server_url);
  
! 	/* optionally send the host header info (not clear if it's usable) */
! 	if (strcmp (host_name, ""))
! 		asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
! 
! 	/* send user agent */
! 	asprintf (&buf, "%sUser-Agent: check_http/%s (nagios-plugins %s)\r\n",
! 	          buf, clean_revstring (REVISION), PACKAGE_VERSION);
! 
! 	/* optionally send the authentication info */
! 	if (strcmp (user_auth, "")) {
! 		auth = base64 (user_auth, strlen (user_auth));
! 		asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth);
! 	}
  
! 	/* either send http POST data */
! 	if (strlen (http_post_data)) {
! 		asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
! 		asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, strlen (http_post_data));
! 		asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF);
! 	}
! 	else {
! 		/* or just a newline so the server knows we're done with the request */
! 		asprintf (&buf, "%s%s", buf, CRLF);
! 	}
  
! #ifdef HAVE_SSL
! 	if (use_ssl == TRUE) {
! 		if (SSL_write (ssl, buf, strlen (buf)) == -1) {
! 			ERR_print_errors_fp (stderr);
! 			return STATE_CRITICAL;
  		}
+ 	}
+ 	else {
+ #endif
+ 		send (sd, buf, strlen (buf), 0);
  #ifdef HAVE_SSL
  	}





More information about the Commits mailing list