diff options
Diffstat (limited to 'plugins/check_curl.d/check_curl_helpers.h')
| -rw-r--r-- | plugins/check_curl.d/check_curl_helpers.h | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/plugins/check_curl.d/check_curl_helpers.h b/plugins/check_curl.d/check_curl_helpers.h new file mode 100644 index 00000000..87e45a9d --- /dev/null +++ b/plugins/check_curl.d/check_curl_helpers.h | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | #include "./config.h" | ||
| 2 | #include <curl/curl.h> | ||
| 3 | #include "../picohttpparser/picohttpparser.h" | ||
| 4 | #include "output.h" | ||
| 5 | |||
| 6 | #if defined(HAVE_SSL) && defined(USE_OPENSSL) | ||
| 7 | # include <openssl/opensslv.h> | ||
| 8 | #endif | ||
| 9 | |||
| 10 | /* for buffers for header and body */ | ||
| 11 | typedef struct { | ||
| 12 | size_t buflen; | ||
| 13 | size_t bufsize; | ||
| 14 | char *buf; | ||
| 15 | } curlhelp_write_curlbuf; | ||
| 16 | |||
| 17 | /* for buffering the data sent in PUT */ | ||
| 18 | typedef struct { | ||
| 19 | size_t buflen; | ||
| 20 | off_t pos; | ||
| 21 | char *buf; | ||
| 22 | } curlhelp_read_curlbuf; | ||
| 23 | |||
| 24 | /* for parsing the HTTP status line */ | ||
| 25 | typedef struct { | ||
| 26 | int http_major; /* major version of the protocol, always 1 (HTTP/0.9 | ||
| 27 | * never reached the big internet most likely) */ | ||
| 28 | int http_minor; /* minor version of the protocol, usually 0 or 1 */ | ||
| 29 | int http_code; /* HTTP return code as in RFC 2145 */ | ||
| 30 | int http_subcode; /* Microsoft IIS extension, HTTP subcodes, see | ||
| 31 | * http://support.microsoft.com/kb/318380/en-us */ | ||
| 32 | const char *msg; /* the human readable message */ | ||
| 33 | char *first_line; /* a copy of the first line */ | ||
| 34 | } curlhelp_statusline; | ||
| 35 | |||
| 36 | typedef struct { | ||
| 37 | bool curl_global_initialized; | ||
| 38 | bool curl_easy_initialized; | ||
| 39 | |||
| 40 | bool body_buf_initialized; | ||
| 41 | curlhelp_write_curlbuf *body_buf; | ||
| 42 | |||
| 43 | bool header_buf_initialized; | ||
| 44 | curlhelp_write_curlbuf *header_buf; | ||
| 45 | |||
| 46 | bool status_line_initialized; | ||
| 47 | curlhelp_statusline *status_line; | ||
| 48 | |||
| 49 | bool put_buf_initialized; | ||
| 50 | curlhelp_read_curlbuf *put_buf; | ||
| 51 | |||
| 52 | CURL *curl; | ||
| 53 | |||
| 54 | struct curl_slist *header_list; | ||
| 55 | struct curl_slist *host; | ||
| 56 | } check_curl_global_state; | ||
| 57 | |||
| 58 | /* to know the underlying SSL library used by libcurl */ | ||
| 59 | typedef enum curlhelp_ssl_library { | ||
| 60 | CURLHELP_SSL_LIBRARY_UNKNOWN, | ||
| 61 | CURLHELP_SSL_LIBRARY_OPENSSL, | ||
| 62 | CURLHELP_SSL_LIBRARY_LIBRESSL, | ||
| 63 | CURLHELP_SSL_LIBRARY_GNUTLS, | ||
| 64 | CURLHELP_SSL_LIBRARY_NSS | ||
| 65 | } curlhelp_ssl_library; | ||
| 66 | |||
| 67 | #define MAKE_LIBCURL_VERSION(major, minor, patch) ((major) * 0x10000 + (minor) * 0x100 + (patch)) | ||
| 68 | |||
| 69 | typedef struct { | ||
| 70 | int errorcode; | ||
| 71 | check_curl_global_state curl_state; | ||
| 72 | check_curl_working_state working_state; | ||
| 73 | } check_curl_configure_curl_wrapper; | ||
| 74 | |||
| 75 | check_curl_configure_curl_wrapper check_curl_configure_curl(check_curl_static_curl_config config, | ||
| 76 | check_curl_working_state working_state, | ||
| 77 | bool check_cert, | ||
| 78 | bool on_redirect_dependent, | ||
| 79 | int follow_method, int max_depth); | ||
| 80 | |||
| 81 | void handle_curl_option_return_code(CURLcode res, const char *option); | ||
| 82 | |||
| 83 | int curlhelp_initwritebuffer(curlhelp_write_curlbuf **buf); | ||
| 84 | size_t curlhelp_buffer_write_callback(void * /*buffer*/, size_t /*size*/, size_t /*nmemb*/, | ||
| 85 | void * /*stream*/); | ||
| 86 | void curlhelp_freewritebuffer(curlhelp_write_curlbuf * /*buf*/); | ||
| 87 | |||
| 88 | int curlhelp_initreadbuffer(curlhelp_read_curlbuf **buf, const char * /*data*/, size_t /*datalen*/); | ||
| 89 | size_t curlhelp_buffer_read_callback(void * /*buffer*/, size_t /*size*/, size_t /*nmemb*/, | ||
| 90 | void * /*stream*/); | ||
| 91 | void curlhelp_freereadbuffer(curlhelp_read_curlbuf * /*buf*/); | ||
| 92 | |||
| 93 | curlhelp_ssl_library curlhelp_get_ssl_library(void); | ||
| 94 | const char *curlhelp_get_ssl_library_string(curlhelp_ssl_library /*ssl_library*/); | ||
| 95 | |||
| 96 | typedef union { | ||
| 97 | struct curl_slist *to_info; | ||
| 98 | struct curl_certinfo *to_certinfo; | ||
| 99 | } cert_ptr_union; | ||
| 100 | int net_noopenssl_check_certificate(cert_ptr_union *, int, int); | ||
| 101 | |||
| 102 | int curlhelp_parse_statusline(const char * /*buf*/, curlhelp_statusline * /*status_line*/); | ||
| 103 | void curlhelp_free_statusline(curlhelp_statusline * /*status_line*/); | ||
| 104 | |||
| 105 | char *get_header_value(const struct phr_header *headers, size_t nof_headers, const char *header); | ||
| 106 | mp_subcheck check_document_dates(const curlhelp_write_curlbuf * /*header_buf*/, | ||
| 107 | int /*maximum_age*/); | ||
| 108 | size_t get_content_length(const curlhelp_write_curlbuf *header_buf, | ||
| 109 | const curlhelp_write_curlbuf *body_buf); | ||
| 110 | int lookup_host(const char *host, char *buf, size_t buflen, sa_family_t addr_family); | ||
| 111 | CURLcode sslctxfun(CURL *curl, SSL_CTX *sslctx, void *parm); | ||
| 112 | |||
| 113 | #define INET_ADDR_MAX_SIZE INET6_ADDRSTRLEN | ||
| 114 | const char *strrstr2(const char *haystack, const char *needle); | ||
| 115 | |||
| 116 | void cleanup(check_curl_global_state global_state); | ||
| 117 | |||
| 118 | bool expected_statuscode(const char *reply, const char *statuscodes); | ||
| 119 | char *string_statuscode(int major, int minor); | ||
| 120 | |||
| 121 | void test_file(char *path); | ||
| 122 | mp_subcheck check_curl_certificate_checks(CURL *curl, X509 *cert, int warn_days_till_exp, | ||
| 123 | int crit_days_till_exp); | ||
| 124 | char *fmt_url(check_curl_working_state workingState); | ||
