diff --git a/src/modules/http_client/curl_api.h b/src/modules/http_client/curl_api.h index 3090a29dd91..8272836cd25 100644 --- a/src/modules/http_client/curl_api.h +++ b/src/modules/http_client/curl_api.h @@ -39,8 +39,8 @@ typedef int (*httpcapi_httpconnect_f)(struct sip_msg *msg, const char *contenttype, const str *_post); typedef int (*httpcapi_httpquery_f)( struct sip_msg *_m, char *_url, str *_dst, char *_post, char *_hdrs); -typedef int (*httpcapi_httpquery_c_f)( - struct sip_msg *_m, char *_url, str *_dst, char *_post, char *_ctype, char *_hdrs); +typedef int (*httpcapi_httpquery_c_f)(struct sip_msg *_m, char *_url, str *_dst, + char *_post, char *_ctype, char *_hdrs); typedef int (*httpcapi_curlcon_exists_f)(str *_name); typedef char *(*httpcapi_res_content_type_f)(const str *_name); diff --git a/src/modules/http_client/curlcon.c b/src/modules/http_client/curlcon.c index c70af3ecd8d..96ea474e19c 100644 --- a/src/modules/http_client/curlcon.c +++ b/src/modules/http_client/curlcon.c @@ -94,9 +94,9 @@ static cfg_option_t tls_versions[] = { static cfg_option_t http_client_options[] = { {"url", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 0 */ - {"username", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 1 */ - {"password", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 2 */ - {"failover", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 3 */ + {"username", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 1 */ + {"password", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 2 */ + {"failover", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 3 */ {"useragent", .f = cfg_parse_str_opt, .flags = CFG_STR_PKGMEM}, /* 4 */ {"verify_peer", .f = cfg_parse_bool_opt}, /* 5 */ {"verify_host", .f = cfg_parse_bool_opt}, /* 6 */ @@ -138,8 +138,7 @@ int http_connection_exists(str *name) return 1; } - LM_DBG("no success in looking for httpcon: [%.*s]\n", - name->len, name->s); + LM_DBG("no success in looking for httpcon: [%.*s]\n", name->len, name->s); return 0; } @@ -151,8 +150,7 @@ curl_con_t *curl_get_connection(str *name) unsigned int conid; conid = core_case_hash(name, 0, 0); - LM_DBG("looking for httpcon: [%.*s] ID %u\n", name->len, - name->s, conid); + LM_DBG("looking for httpcon: [%.*s] ID %u\n", name->len, name->s, conid); cc = _curl_con_root; while(cc) { @@ -162,8 +160,8 @@ curl_con_t *curl_get_connection(str *name) } cc = cc->next; } - LM_DBG("no success in looking for httpcon: [%.*s] (list: %p)\n", - name->len, name->s, _curl_con_root); + LM_DBG("no success in looking for httpcon: [%.*s] (list: %p)\n", name->len, + name->s, _curl_con_root); return NULL; } @@ -818,8 +816,8 @@ curl_con_t *curl_init_con(str *name) } /* Connection structures are shared by all children processes */ - cc = (curl_con_t *)shm_malloc(sizeof(curl_con_t) - + (name->len + 1)*sizeof(char)); + cc = (curl_con_t *)shm_malloc( + sizeof(curl_con_t) + (name->len + 1) * sizeof(char)); if(cc == NULL) { LM_ERR("no shm memory\n"); return NULL; @@ -827,8 +825,8 @@ curl_con_t *curl_init_con(str *name) /* Each structure is allocated in package memory so each process can write into it without any locks or such stuff */ - ccp = (curl_con_pkg_t *)pkg_malloc(sizeof(curl_con_pkg_t) - + (name->len + 1)*sizeof(char)); + ccp = (curl_con_pkg_t *)pkg_malloc( + sizeof(curl_con_pkg_t) + (name->len + 1) * sizeof(char)); if(ccp == NULL) { /* We failed to allocate ccp, so let's free cc and quit */ shm_free(cc); @@ -836,19 +834,19 @@ curl_con_t *curl_init_con(str *name) return NULL; } - memset(cc, 0, sizeof(curl_con_t) + (name->len + 1)*sizeof(char)); + memset(cc, 0, sizeof(curl_con_t) + (name->len + 1) * sizeof(char)); cc->next = _curl_con_root; cc->conid = conid; - cc->name.s = (char*)cc + sizeof(curl_con_t); + cc->name.s = (char *)cc + sizeof(curl_con_t); memcpy(cc->name.s, name->s, name->len); cc->name.len = name->len; _curl_con_root = cc; /* Put the new ccp first in line */ - memset(ccp, 0, sizeof(curl_con_pkg_t) + (name->len + 1)*sizeof(char)); + memset(ccp, 0, sizeof(curl_con_pkg_t) + (name->len + 1) * sizeof(char)); ccp->next = _curl_con_pkg_root; ccp->conid = conid; - ccp->name.s = (char*)ccp + sizeof(curl_con_pkg_t); + ccp->name.s = (char *)ccp + sizeof(curl_con_pkg_t); memcpy(ccp->name.s, name->s, name->len); ccp->name.len = name->len; _curl_con_pkg_root = ccp; diff --git a/src/modules/http_client/functions.c b/src/modules/http_client/functions.c index 8a2b9938538..e85d87d6938 100644 --- a/src/modules/http_client/functions.c +++ b/src/modules/http_client/functions.c @@ -262,7 +262,7 @@ static int curL_request_url(struct sip_msg *_m, const char *_met, } res |= curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function); - res |= curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)(&stream)); + res |= curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)(&stream)); if(params->useragent) res |= curl_easy_setopt(curl, CURLOPT_USERAGENT, params->useragent); @@ -642,7 +642,7 @@ int curl_con_query_url(struct sip_msg *_m, const str *connection, * Similar to http_client_request but supports setting a content type attribute. */ int http_client_request_c(sip_msg_t *_m, char *_url, str *_dst, char *_body, - char* _ctype, char *_hdrs, char *_met) + char *_ctype, char *_hdrs, char *_met) { int res; curl_query_t query_params; @@ -698,8 +698,8 @@ int http_client_request_c(sip_msg_t *_m, char *_url, str *_dst, char *_body, * to pvar. * This is the same http_query as used to be in the utils module. */ -int http_client_request( - sip_msg_t *_m, char *_url, str *_dst, char *_body, char *_hdrs, char *_met) +int http_client_request(sip_msg_t *_m, char *_url, str *_dst, char *_body, + char *_hdrs, char *_met) { return http_client_request_c(_m, _url, _dst, _body, NULL, _hdrs, _met); } @@ -720,8 +720,8 @@ int http_client_query( * to pvar. * This is the same http_query as used to be in the utils module. */ -int http_client_query_c( - struct sip_msg *_m, char *_url, str *_dst, char *_post, char *_ctype, char *_hdrs) +int http_client_query_c(struct sip_msg *_m, char *_url, str *_dst, char *_post, + char *_ctype, char *_hdrs) { return http_client_request_c(_m, _url, _dst, _post, _ctype, _hdrs, 0); } diff --git a/src/modules/http_client/functions.h b/src/modules/http_client/functions.h index 78663d0c1af..b5cf18f3a12 100644 --- a/src/modules/http_client/functions.h +++ b/src/modules/http_client/functions.h @@ -58,22 +58,22 @@ int http_client_query( * Performs http_client_query and saves possible result * (first body line of reply) to pvar. */ -int http_client_query_c( - struct sip_msg *_m, char *_url, str *_dst, char *_post, char *_ctype, char *_hdrs); +int http_client_query_c(struct sip_msg *_m, char *_url, str *_dst, char *_post, + char *_ctype, char *_hdrs); /* * Performs http request and saves possible result * (first body line of reply) to pvar. */ -int http_client_request( - sip_msg_t *_m, char *_url, str *_dst, char *_body, char *_hdrs, char *_met); +int http_client_request(sip_msg_t *_m, char *_url, str *_dst, char *_body, + char *_hdrs, char *_met); /* * Performs http request and saves possible result * (first body line of reply) to pvar. */ -int http_client_request_c( - sip_msg_t *_m, char *_url, str *_dst, char *_body, char *_ctype, char *_hdrs, char *_met); +int http_client_request_c(sip_msg_t *_m, char *_url, str *_dst, char *_body, + char *_ctype, char *_hdrs, char *_met); char *http_get_content_type(const str *connection); diff --git a/src/modules/http_client/http_client.c b/src/modules/http_client/http_client.c index 01c7067ae6f..b45a6081c25 100644 --- a/src/modules/http_client/http_client.c +++ b/src/modules/http_client/http_client.c @@ -84,11 +84,11 @@ str default_tls_clientcert = str default_tls_clientkey = STR_NULL; /*!< File name: Key in PEM format that belongs to client cert */ str default_cipher_suite_list = STR_NULL; /*!< List of allowed cipher suites */ -unsigned int default_tls_version = 0; /*!< 0 = Use libcurl default */ +unsigned int default_tls_version = 0; /*!< 0 = Use libcurl default */ unsigned int default_tls_verify_peer = 1; /*!< 0 = Do not verify TLS server cert. 1 = Verify TLS cert (default) */ unsigned int default_tls_verify_host = - 2; /*!< 0 = Do not verify TLS server CN/SAN 2 = Verify TLS server CN/SAN (default) */ + 2; /*!< 0 = Do not verify TLS server CN/SAN 2 = Verify TLS server CN/SAN (default) */ str default_http_proxy = STR_NULL; /*!< Default HTTP proxy to use */ unsigned int default_http_proxy_port = 0; /*!< Default HTTP proxy port to use */ unsigned int default_http_follow_redirect = @@ -245,7 +245,7 @@ struct module_exports exports = { counter_handle_t connections; /* Number of connection definitions */ counter_handle_t connok; /* Successful Connection attempts */ -counter_handle_t connfail; /* Failed Connection attempts */ +counter_handle_t connfail; /* Failed Connection attempts */ static int init_shmlock(void) @@ -606,8 +606,8 @@ static int fixup_free_curl_connect(void **param, int param_no) /* * Wrapper for Curl_connect (GET) */ -static int ki_curl_connect_helper(sip_msg_t *_m, str *con, str *url, - pv_spec_t *dst) +static int ki_curl_connect_helper( + sip_msg_t *_m, str *con, str *url, pv_spec_t *dst) { str result = {NULL, 0}; pv_value_t val; @@ -637,11 +637,11 @@ static int ki_curl_connect(sip_msg_t *_m, str *con, str *url, str *dpv) pv_spec_t *dst; dst = pv_cache_get(dpv); - if(dst==NULL) { + if(dst == NULL) { LM_ERR("failed to get pv spec for: %.*s\n", dpv->len, dpv->s); return -1; } - if(dst->setf==NULL) { + if(dst->setf == NULL) { LM_ERR("target pv is not writable: %.*s\n", dpv->len, dpv->s); return -1; } @@ -705,17 +705,17 @@ static int ki_curl_connect_post_helper(sip_msg_t *_m, str *con, str *url, /* * Kemi wrapper for Curl_connect (POST) */ -static int ki_curl_connect_post(sip_msg_t *_m, str *con, str *url, - str *ctype, str *data, str *dpv) +static int ki_curl_connect_post( + sip_msg_t *_m, str *con, str *url, str *ctype, str *data, str *dpv) { pv_spec_t *dst; dst = pv_cache_get(dpv); - if(dst==NULL) { + if(dst == NULL) { LM_ERR("failed to get pv spec for: %.*s\n", dpv->len, dpv->s); return -1; } - if(dst->setf==NULL) { + if(dst->setf == NULL) { LM_ERR("target pv is not writable: %.*s\n", dpv->len, dpv->s); return -1; } @@ -735,7 +735,7 @@ static int w_curl_connect_post_raw(struct sip_msg *_m, char *_con, char *_url, str data = {NULL, 0}; pv_spec_t *dst; - if(_con == NULL || _url == NULL || _ctype==NULL || _data == NULL + if(_con == NULL || _url == NULL || _ctype == NULL || _data == NULL || _result == NULL) { LM_ERR("http_connect: Invalid parameters\n"); return -1; @@ -773,7 +773,7 @@ static int w_curl_connect_post(struct sip_msg *_m, char *_con, char *_url, str data = {NULL, 0}; pv_spec_t *dst; - if(_con == NULL || _url == NULL || _ctype==NULL || _data == NULL + if(_con == NULL || _url == NULL || _ctype == NULL || _data == NULL || _result == NULL) { LM_ERR("http_connect: Invalid parameters\n"); return -1; @@ -890,20 +890,20 @@ static int fixup_free_http_query_post_hdr(void **param, int param_no) /*! * helper for HTTP-Query function */ -static int ki_http_query_helper(sip_msg_t *_m, str *url, str *post, str *hdrs, - pv_spec_t *dst) +static int ki_http_query_helper( + sip_msg_t *_m, str *url, str *post, str *hdrs, pv_spec_t *dst) { int ret = 0; str result = {NULL, 0}; pv_value_t val; - if(url==NULL || url->s==NULL) { + if(url == NULL || url->s == NULL) { LM_ERR("invalid url parameter\n"); return -1; } ret = http_client_query(_m, url->s, &result, - (post && post->s && post->len>0)?post->s:NULL, - (hdrs && hdrs->s && hdrs->len>0)?hdrs->s:NULL); + (post && post->s && post->len > 0) ? post->s : NULL, + (hdrs && hdrs->s && hdrs->len > 0) ? hdrs->s : NULL); val.rs = result; val.flags = PV_VAL_STR; @@ -919,17 +919,17 @@ static int ki_http_query_helper(sip_msg_t *_m, str *url, str *post, str *hdrs, return (ret == 0) ? -1 : ret; } -static int ki_http_query_post_hdrs(sip_msg_t *_m, str *url, str *post, str *hdrs, - str *dpv) +static int ki_http_query_post_hdrs( + sip_msg_t *_m, str *url, str *post, str *hdrs, str *dpv) { pv_spec_t *dst; dst = pv_cache_get(dpv); - if(dst==NULL) { + if(dst == NULL) { LM_ERR("failed to get pv spec for: %.*s\n", dpv->len, dpv->s); return -1; } - if(dst->setf==NULL) { + if(dst->setf == NULL) { LM_ERR("target pv is not writable: %.*s\n", dpv->len, dpv->s); return -1; } @@ -950,8 +950,8 @@ static int ki_http_query(sip_msg_t *_m, str *url, str *dpv) /*! * Wrapper for HTTP-Query function for cfg script */ -static int w_http_query_script(sip_msg_t *_m, char *_url, char *_post, - char *_hdrs, char *_result) +static int w_http_query_script( + sip_msg_t *_m, char *_url, char *_post, char *_hdrs, char *_result) { str url = {NULL, 0}; str post = {NULL, 0}; @@ -1012,21 +1012,21 @@ static int w_http_query_post_hdr( /*! * helper for HTTP-Query function */ -static int ki_http_request_helper(sip_msg_t *_m, str *met, str *url, str *body, - str *hdrs, pv_spec_t *dst) +static int ki_http_request_helper( + sip_msg_t *_m, str *met, str *url, str *body, str *hdrs, pv_spec_t *dst) { int ret = 0; str result = {NULL, 0}; pv_value_t val; - if(url==NULL || url->s==NULL) { + if(url == NULL || url->s == NULL) { LM_ERR("invalid url parameter\n"); return -1; } ret = http_client_request(_m, url->s, &result, - (body && body->s && body->len>0)?body->s:NULL, - (hdrs && hdrs->s && hdrs->len>0)?hdrs->s:NULL, - (met && met->s && met->len>0)?met->s:NULL); + (body && body->s && body->len > 0) ? body->s : NULL, + (hdrs && hdrs->s && hdrs->len > 0) ? hdrs->s : NULL, + (met && met->s && met->len > 0) ? met->s : NULL); val.rs = result; val.flags = PV_VAL_STR; @@ -1045,18 +1045,18 @@ static int ki_http_request_helper(sip_msg_t *_m, str *met, str *url, str *body, /*! * KEMI function to perform GET with headers and body */ -static int ki_http_get_hdrs(sip_msg_t *_m, str *url, str *body, - str *hdrs, str *dpv) +static int ki_http_get_hdrs( + sip_msg_t *_m, str *url, str *body, str *hdrs, str *dpv) { str met = str_init("GET"); pv_spec_t *dst; dst = pv_cache_get(dpv); - if(dst==NULL) { + if(dst == NULL) { LM_ERR("failed to get pv spec for: %.*s\n", dpv->len, dpv->s); return -1; } - if(dst->setf==NULL) { + if(dst->setf == NULL) { LM_ERR("target pv is not writable: %.*s\n", dpv->len, dpv->s); return -1; } @@ -1067,8 +1067,8 @@ static int ki_http_get_hdrs(sip_msg_t *_m, str *url, str *body, /*! * Wrapper for HTTP-Query function for cfg script */ -static int w_http_get_script(sip_msg_t *_m, char *_url, char *_body, - char *_hdrs, char *_result) +static int w_http_get_script( + sip_msg_t *_m, char *_url, char *_body, char *_hdrs, char *_result) { str met = str_init("GET"); str url = {NULL, 0}; diff --git a/src/modules/http_client/http_client.h b/src/modules/http_client/http_client.h index 44dd331771e..1c1e9df0c64 100644 --- a/src/modules/http_client/http_client.h +++ b/src/modules/http_client/http_client.h @@ -46,13 +46,13 @@ extern str default_tls_clientcert; /*!< File name: Default client certificate to use for curl TLS connection */ extern str default_tls_clientkey; /*!< File name: Key in PEM format that belongs to client cert */ -extern str default_cipher_suite_list; /*!< List of allowed cipher suites */ +extern str default_cipher_suite_list; /*!< List of allowed cipher suites */ extern unsigned int default_tls_version; /*!< 0 = Use libcurl default */ extern unsigned int default_tls_verify_peer; /*!< 0 = Do not verify TLS server cert. 1 = Verify TLS cert (default) */ extern unsigned int default_tls_verify_host; /*!< 0 = Do not verify TLS server CN/SAN. 2 = Verify TLS server CN/SAN (default) */ -extern str default_http_proxy; /*!< Default HTTP proxy to use */ +extern str default_http_proxy; /*!< Default HTTP proxy to use */ extern unsigned int default_http_proxy_port; /*!< Default HTTP proxy port to use */ extern unsigned int @@ -65,11 +65,12 @@ extern unsigned int extern unsigned int default_keep_connections; /*!< Keep http connections open for reuse */ extern unsigned int default_query_result; /*!< Default query result mode */ -extern unsigned int default_query_maxdatasize; /*!< Default query result maximum download size */ +extern unsigned int + default_query_maxdatasize; /*!< Default query result maximum download size */ extern counter_handle_t connections; /* Number of connection definitions */ extern counter_handle_t connok; /* Successful Connection attempts */ -extern counter_handle_t connfail; /* Failed Connection attempts */ +extern counter_handle_t connfail; /* Failed Connection attempts */ extern char *default_netinterface; @@ -86,7 +87,7 @@ enum connection_status { AVAILABLE = 0, /*!< Available */ NOTREACHABLE, /*!< Failure */ - DISABLED, /*!< Disabled by action (RPC etc) */ + DISABLED, /*!< Disabled by action (RPC etc) */ /* DELETED */ /*!< Should be deleted by pkg process, not listed */ }; @@ -106,7 +107,7 @@ typedef struct _curl_con str failover; /*!< Another connection to use if this one fails */ char *useragent; /*!< Useragent to use for this connection */ char *cacert; /*!< File name of CA cert to use */ - char *clientcert; /*!< File name of CA client cert */ + char *clientcert; /*!< File name of CA client cert */ char *clientkey; /*!< File name of CA client key */ char *ciphersuites; /*!< List of allowed cipher suites */ unsigned int tlsversion; /*!< SSL/TLS version to use */ @@ -116,8 +117,8 @@ typedef struct _curl_con unsigned int keep_connections; /*!< TRUE to keep curl connections open */ unsigned int port; /*!< The port to connect to */ int timeout; /*!< Timeout for this connection */ - unsigned int maxdatasize; /*!< Maximum data download on GET or POST */ - curl_res_stream_t *stream; /*!< Curl stream */ + unsigned int maxdatasize; /*!< Maximum data download on GET or POST */ + curl_res_stream_t *stream; /*!< Curl stream */ char *http_proxy; /*!< HTTP proxy for this connection */ unsigned int http_proxy_port; /*!< HTTP proxy port for this connection */ struct _curl_con *next; /*!< next connection */ @@ -127,7 +128,7 @@ typedef struct _curl_con /*! Per-process copy of connection object -stored in pkg memory */ typedef struct _curl_con_pkg { - str name; /*!< Connection name */ + str name; /*!< Connection name */ unsigned int conid; /*!< Connection hash ID */ char redirecturl [512]; /*!< Last redirect URL - to use for $curlredirect(curlcon) pv */ @@ -135,7 +136,7 @@ typedef struct _curl_con_pkg char result_content_type[512]; /*!< Response content-type */ CURL *curl; /*!< Curl connection handle */ double querytime; /*!< Seconds used for last request */ - double connecttime; /*!< Seconds used for connecting last request inc TLS setup - see + double connecttime; /*!< Seconds used for connecting last request inc TLS setup - see https://curl.haxx.se/libcurl/c/CURLINFO_APPCONNECT_TIME.html */ /* Potential candidates: Last TLS fingerprint used