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