summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2019-09-07 13:31:15 (GMT)
committerAndreas Baumann <mail@andreasbaumann.cc>2019-09-07 13:31:15 (GMT)
commit95ee6ace094109d156286ab61d3c76709e43d642 (patch)
tree8b9734e73623dec85e2637e2df574ebc304f5efe /plugins
parentfe91deb40c6ca7732c3548c75c0671f580d1c81b (diff)
downloadmonitoring-plugins-95ee6ace094109d156286ab61d3c76709e43d642.tar.gz
improved curlhelp_parse_statusline to handle both HTTP/1.x and HTTP/2
Diffstat (limited to 'plugins')
-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 8d8cb9f..3a6f2af 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -59,7 +59,7 @@ const char *email = "devel@monitoring-plugins.org";
59 59
60#define DEFAULT_BUFFER_SIZE 2048 60#define DEFAULT_BUFFER_SIZE 2048
61#define DEFAULT_SERVER_URL "/" 61#define DEFAULT_SERVER_URL "/"
62#define HTTP_EXPECT "HTTP/1." 62#define HTTP_EXPECT "HTTP/"
63#define DEFAULT_MAX_REDIRS 15 63#define DEFAULT_MAX_REDIRS 15
64#define INET_ADDR_MAX_SIZE INET6_ADDRSTRLEN 64#define INET_ADDR_MAX_SIZE INET6_ADDRSTRLEN
65enum { 65enum {
@@ -1915,44 +1915,55 @@ curlhelp_parse_statusline (const char *buf, curlhelp_statusline *status_line)
1915 status_line->first_line[first_line_len] = '\0'; 1915 status_line->first_line[first_line_len] = '\0';
1916 first_line_buf = strdup( status_line->first_line ); 1916 first_line_buf = strdup( status_line->first_line );
1917 1917
1918 /* protocol and version: "HTTP/x.x" SP */ 1918 /* protocol and version: "HTTP/x.x" SP or "HTTP/2" SP */
1919 1919
1920 p = strtok(first_line_buf, "/"); 1920 p = strtok(first_line_buf, "/");
1921 if( p == NULL ) { free( first_line_buf ); return -1; } 1921 if( p == NULL ) { free( first_line_buf ); return -1; }
1922 if( strcmp( p, "HTTP" ) != 0 ) { free( first_line_buf ); return -1; } 1922 if( strcmp( p, "HTTP" ) != 0 ) { free( first_line_buf ); return -1; }
1923 1923
1924 p = strtok( NULL, "." );
1925 if( p == NULL ) { free( first_line_buf ); return -1; }
1926 status_line->http_major = (int)strtol( p, &pp, 10 );
1927 if( *pp != '\0' ) { free( first_line_buf ); return -1; }
1928
1929 p = strtok( NULL, " " ); 1924 p = strtok( NULL, " " );
1930 if( p == NULL ) { free( first_line_buf ); return -1; } 1925 if( p == NULL ) { free( first_line_buf ); return -1; }
1931 status_line->http_minor = (int)strtol( p, &pp, 10 ); 1926 if( strchr( p, '.' ) != NULL ) {
1932 if( *pp != '\0' ) { free( first_line_buf ); return -1; } 1927
1928 /* HTTP 1.x case */
1929 char *ppp;
1930 ppp = strtok( p, "." );
1931 status_line->http_major = (int)strtol( p, &pp, 10 );
1932 if( *pp != '\0' ) { free( first_line_buf ); return -1; }
1933 ppp = strtok( NULL, " " );
1934 status_line->http_minor = (int)strtol( p, &pp, 10 );
1935 if( *pp != '\0' ) { free( first_line_buf ); return -1; }
1936 p += 4; /* 1.x SP */
1937 } else {
1938 /* HTTP 2 case */
1939 status_line->http_major = (int)strtol( p, &pp, 10 );
1940 status_line->http_minor = 0;
1941 p += 2; /* 2 SP */
1942 }
1933 1943
1934 /* status code: "404" or "404.1", then SP */ 1944 /* status code: "404" or "404.1", then SP */
1935 1945
1936 p = strtok( NULL, " ." ); 1946 p = strtok( p, " " );
1937 if( p == NULL ) { free( first_line_buf ); return -1; } 1947 if( p == NULL ) { free( first_line_buf ); return -1; }
1938 if( strchr( p, '.' ) != NULL ) { 1948 if( strchr( p, '.' ) != NULL ) {
1939 char *ppp; 1949 char *ppp;
1940 ppp = strtok( p, "." ); 1950 ppp = strtok( p, "." );
1941 status_line->http_code = (int)strtol( ppp, &pp, 10 ); 1951 status_line->http_code = (int)strtol( ppp, &pp, 10 );
1942 if( *pp != '\0' ) { free( first_line_buf ); return -1; } 1952 if( *pp != '\0' ) { free( first_line_buf ); return -1; }
1943
1944 ppp = strtok( NULL, "" ); 1953 ppp = strtok( NULL, "" );
1945 status_line->http_subcode = (int)strtol( ppp, &pp, 10 ); 1954 status_line->http_subcode = (int)strtol( ppp, &pp, 10 );
1946 if( *pp != '\0' ) { free( first_line_buf ); return -1; } 1955 if( *pp != '\0' ) { free( first_line_buf ); return -1; }
1956 p += 6; /* 400.1 SP */
1947 } else { 1957 } else {
1948 status_line->http_code = (int)strtol( p, &pp, 10 ); 1958 status_line->http_code = (int)strtol( p, &pp, 10 );
1949 status_line->http_subcode = -1; 1959 status_line->http_subcode = -1;
1950 if( *pp != '\0' ) { free( first_line_buf ); return -1; } 1960 if( *pp != '\0' ) { free( first_line_buf ); return -1; }
1961 p += 4; /* 400 SP */
1951 } 1962 }
1952 1963
1953 /* Human readable message: "Not Found" CRLF */ 1964 /* Human readable message: "Not Found" CRLF */
1954 1965
1955 p = strtok( NULL, "" ); 1966 p = strtok( p, "" );
1956 if( p == NULL ) { status_line->msg = ""; return 0; } 1967 if( p == NULL ) { status_line->msg = ""; return 0; }
1957 status_line->msg = status_line->first_line + ( p - first_line_buf ); 1968 status_line->msg = status_line->first_line + ( p - first_line_buf );
1958 free( first_line_buf ); 1969 free( first_line_buf );