Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef __HTPP_CURL_INCLUDE__ 7 : #define __HTPP_CURL_INCLUDE__ 8 : 9 : #if __cplusplus > 199711L 10 : #define NOEXCEPT noexcept 11 : #else 12 : #define NOEXCEPT 13 : #endif 14 : 15 : #include <curl/curl.h> 16 : 17 : #define set_curl_option(handle, option, parameter) \ 18 : do { \ 19 : curl_easy_setopt(handle, option, parameter); \ 20 : } while (0) 21 : 22 : /* Global information, common to all connections */ 23 : typedef struct _GlobalInfo 24 : { 25 : CURLM *multi; 26 : int still_running; 27 : HttpClient *client; 28 : } GlobalInfo; 29 : 30 : /* Information associated with a specific easy handle */ 31 : typedef struct _ConnInfo 32 : { 33 : CURL *easy; 34 : char *url; 35 : char *post; 36 : uint32_t post_len; 37 : struct curl_slist *headers; 38 : GlobalInfo *global; 39 : char error[CURL_ERROR_SIZE + 1]; 40 : HttpConnection *connection; 41 : } ConnInfo; 42 : 43 : typedef struct _SockInfo 44 : { 45 : int action; 46 : ConnInfo *conn_info; 47 : } SockInfo; 48 : 49 : class CurlErrorCategory : public boost::system::error_category 50 : { 51 : public: 52 0 : virtual const char *name() const NOEXCEPT { return "http_curl"; } 53 0 : virtual std::string message( int ev ) const { 54 0 : return curl_easy_strerror((CURLcode)ev); 55 : } 56 : }; 57 : extern const CurlErrorCategory curl_error_category; 58 : 59 : int http_get(ConnInfo *conn, GlobalInfo *g); 60 : void set_url(ConnInfo *conn, const char *url); 61 : int curl_init(HttpClient *); 62 : ConnInfo *new_conn(HttpConnection *connection, GlobalInfo *g, 63 : bool header, bool short_timeout, bool reuse); 64 : void del_conn(HttpConnection *connection, GlobalInfo *g); 65 : void del_curl_handle(ConnInfo *curl_handle, GlobalInfo *g); 66 : void set_header_options(ConnInfo *conn, const char *options); 67 : void set_ssl_options(ConnInfo *conn, const char *client_cert, 68 : const char *client_cert_type, const char *client_key, 69 : const char *ca_cert); 70 : void set_post_string(ConnInfo *conn, const char *post, uint32_t len); 71 : void set_put_string(ConnInfo *conn, const char *put, uint32_t len); 72 : int http_head(ConnInfo *conn, GlobalInfo *g); 73 : int http_put(ConnInfo *conn, GlobalInfo *g); 74 : int http_post(ConnInfo *conn, GlobalInfo *g); 75 : int http_delete(ConnInfo *conn, GlobalInfo *g); 76 : bool timer_cb(GlobalInfo *g); 77 : 78 : #endif /* __HTPP_CURL_INCLUDE__ */