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