Skip to content

Commit

Permalink
http_client: new param netinterface to set curl network interface
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Jan 17, 2020
1 parent 02bff60 commit b384a99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/modules/http_client/functions.c
Expand Up @@ -57,6 +57,7 @@ typedef struct
char *failovercon;
char *useragent;
char *hdrs;
char *netinterface;
unsigned int authmethod;
unsigned int http_proxy_port;
unsigned int tlsversion;
Expand Down Expand Up @@ -249,7 +250,9 @@ static int curL_query_url(struct sip_msg *_m, const char *_url, str *_dst,
if(params->http_follow_redirect) {
LM_DBG("Following redirects for this request! \n");
}

if(params->netinterface != NULL) {
res |= curl_easy_setopt(curl, CURLOPT_INTERFACE, params->netinterface);
}

res |= curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_function);
res |= curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)(&stream));
Expand Down Expand Up @@ -576,6 +579,7 @@ int curl_con_query_url_f(struct sip_msg *_m, const str *connection,
query_params.keep_connections = conn->keep_connections;
query_params.oneline = 0;
query_params.maxdatasize = maxdatasize;
query_params.netinterface = default_netinterface;
query_params.http_proxy_port = conn->http_proxy_port;
if(conn->failover.s) {
failovercon = as_asciiz(&conn->failover);
Expand Down Expand Up @@ -654,6 +658,7 @@ int http_client_query(
query_params.http_follow_redirect = default_http_follow_redirect;
query_params.oneline = default_query_result;
query_params.maxdatasize = default_query_maxdatasize;
query_params.netinterface = default_netinterface;
if(default_useragent.s != NULL && default_useragent.len > 0) {
query_params.useragent = default_useragent.s;
}
Expand Down
3 changes: 3 additions & 0 deletions src/modules/http_client/http_client.c
Expand Up @@ -100,6 +100,8 @@ unsigned int default_authmethod =
CURLAUTH_BASIC
| CURLAUTH_DIGEST; /*!< authentication method - Basic, Digest or both */

char *default_netintrface = 0; /*!< local network interface */

/*!< Default http query result mode
* - 0: return full result
* - 1: return first line only */
Expand Down Expand Up @@ -204,6 +206,7 @@ static param_export_t params[] = {
{"keep_connections", PARAM_INT, &default_keep_connections },
{"query_result", PARAM_INT, &default_query_result },
{"query_maxdatasize", PARAM_INT, &default_query_maxdatasize },
{"netinterface", PARAM_STRING, &default_netinterface },
{0, 0, 0}
};

Expand Down
2 changes: 2 additions & 0 deletions src/modules/http_client/http_client.h
Expand Up @@ -69,6 +69,8 @@ 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 char *default_netinterface;

/* Curl stream object */
typedef struct
{
Expand Down

0 comments on commit b384a99

Please sign in to comment.