Module: kamailio Branch: master Commit: 4643c51032b8d28c1dede12792c1e1737fdb60e8 URL: https://github.com/kamailio/kamailio/commit/4643c51032b8d28c1dede12792c1e173...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2017-11-03T09:07:55+01:00
evapi: allow setting max number of clients via param
- reported by GH #1290
---
Modified: src/modules/evapi/evapi_dispatch.c Modified: src/modules/evapi/evapi_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/4643c51032b8d28c1dede12792c1e173... Patch: https://github.com/kamailio/kamailio/commit/4643c51032b8d28c1dede12792c1e173...
---
diff --git a/src/modules/evapi/evapi_dispatch.c b/src/modules/evapi/evapi_dispatch.c index 93eef3c445..e5b11b18cf 100644 --- a/src/modules/evapi/evapi_dispatch.c +++ b/src/modules/evapi/evapi_dispatch.c @@ -47,6 +47,7 @@ static int _evapi_netstring_format = 1;
extern str _evapi_event_callback; extern int _evapi_dispatcher_pid; +extern int _evapi_max_clients;
#define EVAPI_IPADDR_SIZE 64 #define EVAPI_TAG_SIZE 64 @@ -75,9 +76,10 @@ typedef struct _evapi_msg { int unicast; } evapi_msg_t;
-#define EVAPI_MAX_CLIENTS 8 +#define EVAPI_MAX_CLIENTS _evapi_max_clients + /* last one used for error handling, not a real connected client */ -static evapi_client_t _evapi_clients[EVAPI_MAX_CLIENTS+1]; +static evapi_client_t *_evapi_clients = NULL;
typedef struct _evapi_evroutes { int con_new; @@ -176,7 +178,7 @@ int evapi_run_cfg_route(evapi_env_t *evenv, int rt, str *rtname) */ int evapi_close_connection(int cidx) { - if(cidx<0 || cidx>=EVAPI_MAX_CLIENTS) + if(cidx<0 || cidx>=EVAPI_MAX_CLIENTS || _evapi_clients==NULL) return -1; if(_evapi_clients[cidx].connected==1 && _evapi_clients[cidx].sock >= 0) { @@ -212,7 +214,7 @@ int evapi_set_tag(sip_msg_t* msg, str* stag) { evapi_env_t *evenv;
- if(msg==NULL || stag==NULL) + if(msg==NULL || stag==NULL || _evapi_clients==NULL) return -1;
evenv = evapi_get_msg_env(msg); @@ -280,6 +282,10 @@ int evapi_dispatch_notify(evapi_msg_t *emsg) int n; int wlen;
+ if(_evapi_clients==NULL) { + return 0; + } + n = 0; for(i=0; i<EVAPI_MAX_CLIENTS; i++) { if(_evapi_clients[i].connected==1 && _evapi_clients[i].sock>=0) { @@ -319,7 +325,11 @@ void evapi_recv_client(struct ev_loop *loop, struct ev_io *watcher, int revents) char *efp;
if(EV_ERROR & revents) { - perror("received invalid event\n"); + LM_ERR("received invalid event (%d)\n", revents); + return; + } + if(_evapi_clients==NULL) { + LM_ERR("no client structures\n"); return; }
@@ -479,6 +489,10 @@ void evapi_accept_client(struct ev_loop *loop, struct ev_io *watcher, int revent int i; evapi_env_t evenv;
+ if(_evapi_clients==NULL) { + LM_ERR("no client structures\n"); + return; + } evapi_client = (struct ev_io*) malloc (sizeof(struct ev_io)); if(evapi_client==NULL) { LM_ERR("no more memory\n"); @@ -601,6 +615,12 @@ int evapi_run_dispatcher(char *laddr, int lport)
LM_DBG("starting dispatcher processing\n");
+ _evapi_clients = (evapi_client_t*)malloc(sizeof(evapi_client_t) + * (EVAPI_MAX_CLIENTS+1)); + if(_evapi_clients==NULL) { + LM_ERR("failed to allocate client structures\n"); + exit(-1); + } memset(_evapi_clients, 0, sizeof(evapi_client_t) * EVAPI_MAX_CLIENTS); for(i=0; i<EVAPI_MAX_CLIENTS; i++) { _evapi_clients[i].sock = -1; @@ -872,6 +892,9 @@ int pv_get_evapi(sip_msg_t *msg, pv_param_t *param, pv_value_t *res) if(param==NULL || res==NULL) return -1;
+ if(_evapi_clients==NULL) { + return pv_get_null(msg, param, res); + } evenv = evapi_get_msg_env(msg);
if(evenv==NULL || evenv->conidx<0 || evenv->conidx>=EVAPI_MAX_CLIENTS) diff --git a/src/modules/evapi/evapi_mod.c b/src/modules/evapi/evapi_mod.c index e5eac596ae..7673cb262e 100644 --- a/src/modules/evapi/evapi_mod.c +++ b/src/modules/evapi/evapi_mod.c @@ -53,6 +53,7 @@ static int _evapi_netstring_format_param = 1;
str _evapi_event_callback = STR_NULL; int _evapi_dispatcher_pid = -1; +int _evapi_max_clients = 8;
static tm_api_t tmb;
@@ -98,6 +99,7 @@ static param_export_t params[]={ {"bind_addr", PARAM_STRING, &_evapi_bind_param}, {"netstring_format", INT_PARAM, &_evapi_netstring_format_param}, {"event_callback", PARAM_STR, &_evapi_event_callback}, + {"max_clients", PARAM_INT, &_evapi_max_clients}, {0, 0, 0} };