Skip to content

Commit

Permalink
http_client: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 66d99f2 commit b6fd0ee
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 77 deletions.
4 changes: 2 additions & 2 deletions src/modules/http_client/curl_api.h
Expand Up @@ -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);

Expand Down
32 changes: 15 additions & 17 deletions src/modules/http_client/curlcon.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
}

Expand All @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -818,37 +816,37 @@ 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;
}

/* 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);
LM_ERR("no pkg memory available\n");
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;
Expand Down
12 changes: 6 additions & 6 deletions src/modules/http_client/functions.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions src/modules/http_client/functions.h
Expand Up @@ -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);
Expand Down
72 changes: 36 additions & 36 deletions src/modules/http_client/http_client.c
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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};
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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};
Expand Down

0 comments on commit b6fd0ee

Please sign in to comment.