aboutsummaryrefslogtreecommitdiff
path: root/plugins/check_curl.c
diff options
context:
space:
mode:
authorGravatar Andreas Baumann <mail@andreasbaumann.cc> 2019-09-07 15:31:15 +0200
committerGravatar Andreas Baumann <mail@andreasbaumann.cc> 2019-09-07 15:31:15 +0200
commit95ee6ace094109d156286ab61d3c76709e43d642 (patch)
tree8b9734e73623dec85e2637e2df574ebc304f5efe /plugins/check_curl.c
parentfe91deb40c6ca7732c3548c75c0671f580d1c81b (diff)
downloadmonitoring-plugins-95ee6ace094109d156286ab61d3c76709e43d642.tar.gz
improved curlhelp_parse_statusline to handle both HTTP/1.x and HTTP/2
Diffstat (limited to 'plugins/check_curl.c')
-rw-r--r--plugins/check_curl.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 8d8cb9f4..3a6f2af7 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -59,7 +59,7 @@ const char *email = "devel@monitoring-plugins.org";
#define DEFAULT_BUFFER_SIZE 2048
#define DEFAULT_SERVER_URL "/"
-#define HTTP_EXPECT "HTTP/1."
+#define HTTP_EXPECT "HTTP/"
#define DEFAULT_MAX_REDIRS 15
#define INET_ADDR_MAX_SIZE INET6_ADDRSTRLEN
enum {
@@ -1915,44 +1915,55 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line)
status_line->first_line[first_line_len] = '\0';
first_line_buf = strdup( status_line->first_line );
- /* protocol and version: "HTTP/x.x" SP */
+ /* protocol and version: "HTTP/x.x" SP or "HTTP/2" SP */
p = strtok(first_line_buf, "/");
if( p == NULL ) { free( first_line_buf ); return -1; }
if( strcmp( p, "HTTP" ) != 0 ) { free( first_line_buf ); return -1; }
- p = strtok( NULL, "." );
- if( p == NULL ) { free( first_line_buf ); return -1; }
- status_line->http_major = (int)strtol( p, &pp, 10 );
- if( *pp != '\0' ) { free( first_line_buf ); return -1; }
-
p = strtok( NULL, " " );
if( p == NULL ) { free( first_line_buf ); return -1; }
- status_line->http_minor = (int)strtol( p, &pp, 10 );
- if( *pp != '\0' ) { free( first_line_buf ); return -1; }
+ if( strchr( p, '.' ) != NULL ) {
+
+ /* HTTP 1.x case */
+ char *ppp;
+ ppp = strtok( p, "." );
+ status_line->http_major = (int)strtol( p, &pp, 10 );
+ if( *pp != '\0' ) { free( first_line_buf ); return -1; }
+ ppp = strtok( NULL, " " );
+ status_line->http_minor = (int)strtol( p, &pp, 10 );
+ if( *pp != '\0' ) { free( first_line_buf ); return -1; }
+ p += 4; /* 1.x SP */
+ } else {
+ /* HTTP 2 case */
+ status_line->http_major = (int)strtol( p, &pp, 10 );
+ status_line->http_minor = 0;
+ p += 2; /* 2 SP */
+ }
/* status code: "404" or "404.1", then SP */
- p = strtok( NULL, " ." );
+ p = strtok( p, " " );
if( p == NULL ) { free( first_line_buf ); return -1; }
if( strchr( p, '.' ) != NULL ) {
char *ppp;
ppp = strtok( p, "." );
status_line->http_code = (int)strtol( ppp, &pp, 10 );
if( *pp != '\0' ) { free( first_line_buf ); return -1; }
-
ppp = strtok( NULL, "" );
status_line->http_subcode = (int)strtol( ppp, &pp, 10 );
if( *pp != '\0' ) { free( first_line_buf ); return -1; }
+ p += 6; /* 400.1 SP */
} else {
status_line->http_code = (int)strtol( p, &pp, 10 );
status_line->http_subcode = -1;
if( *pp != '\0' ) { free( first_line_buf ); return -1; }
+ p += 4; /* 400 SP */
}
/* Human readable message: "Not Found" CRLF */
- p = strtok( NULL, "" );
+ p = strtok( p, "" );
if( p == NULL ) { status_line->msg = ""; return 0; }
status_line->msg = status_line->first_line + ( p - first_line_buf );
free( first_line_buf );