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