Skip to content

Commit

Permalink
Make *_export_t const for all modules (part II of e470daa).
Browse files Browse the repository at this point in the history
This includes:

 o cmd_export_t [];
 o param_export_t [];
 o stat_export_t [];
 o dep_export_t [];
 o acmd_export_t [];
 o trans_export_t [];
 o mi_export_t [];
 o pv_export_t [];
 o proc_export_t [];
 o evi_export_t [].

The only exception is modules that provide param to alter number of
children via module parameter (mi_datagram & sipcapture).
  • Loading branch information
sobomax committed Feb 14, 2023
1 parent fa652e8 commit 6bb21b7
Show file tree
Hide file tree
Showing 209 changed files with 668 additions and 669 deletions.
12 changes: 6 additions & 6 deletions action.c
Expand Up @@ -623,7 +623,7 @@ int do_action(struct action* a, struct sip_msg* msg)
struct timeval start;
int end_time;
const cmd_export_t *cmd = NULL;
acmd_export_t *acmd;
const acmd_export_t *acmd;
void* cmdp[MAX_CMD_PARAMS];
pv_value_t tmp_vals[MAX_CMD_PARAMS];
pv_value_t *route_p;
Expand Down Expand Up @@ -1026,7 +1026,7 @@ int do_action(struct action* a, struct sip_msg* msg)
break;
case CMD_T:
if (a->elem[0].type != CMD_ST ||
((cmd = (const cmd_export_t*)a->elem[0].u.data) == NULL)) {
((cmd = (const cmd_export_t*)a->elem[0].u.data_const) == NULL)) {
LM_ALERT("BUG in module call\n");
break;
}
Expand Down Expand Up @@ -1057,7 +1057,7 @@ int do_action(struct action* a, struct sip_msg* msg)
* second param - a NUMBER_ST pointing to resume route
* third param - an optional NUMBER_ST with a timeout */
aitem = (struct action *)(a->elem[0].u.data);
acmd = (acmd_export_t *)aitem->elem[0].u.data;
acmd = (const acmd_export_t *)aitem->elem[0].u.data_const;

if (async_script_start_f==NULL || a->elem[0].type!=ACTIONS_ST ||
a->elem[1].type!=NUMBER_ST || aitem->type!=AMODULE_T) {
Expand Down Expand Up @@ -1090,7 +1090,7 @@ int do_action(struct action* a, struct sip_msg* msg)
/* first param - an ACTIONS_ST containing an ACMD_ST
* second param - an optional NUMBER_ST pointing to an end route */
aitem = (struct action *)(a->elem[0].u.data);
acmd = (acmd_export_t *)aitem->elem[0].u.data;
acmd = (const acmd_export_t *)aitem->elem[0].u.data_const;

if (async_script_start_f==NULL || a->elem[0].type!=ACTIONS_ST ||
a->elem[1].type!=NUMBER_ST || aitem->type!=AMODULE_T) {
Expand Down Expand Up @@ -1228,8 +1228,8 @@ static int for_each_handler(struct sip_msg *msg, struct action *a)
* @msg - mandatory, sip message
* @line - line in script
*/
void __script_trace(char *class, char *action, struct sip_msg *msg,
char *file, int line)
void __script_trace(const char *class, const char *action, struct sip_msg *msg,
const char *file, int line)
{
str val;

Expand Down
4 changes: 2 additions & 2 deletions action.h
Expand Up @@ -72,8 +72,8 @@ void run_error_route(struct sip_msg* msg, int force_reset);
__script_trace(class, action, msg, file, line); \
} while (0)

void __script_trace(char *class, char *action, struct sip_msg *msg,
char *file, int line);
void __script_trace(const char *class, const char *action, struct sip_msg *msg,
const char *file, int line);

typedef int (*param_getf_t)(struct sip_msg*, pv_param_t*, pv_value_t*, void *, void *);

Expand Down
2 changes: 1 addition & 1 deletion async.c
Expand Up @@ -294,7 +294,7 @@ int async_script_launch(struct sip_msg *msg, struct action* a,

async_status = ASYNC_NO_IO; /*assume defauly status "no IO done" */

return_code = ((acmd_export_t*)(a->elem[0].u.data))->function(msg,
return_code = ((const acmd_export_t*)(a->elem[0].u.data_const))->function(msg,
(async_ctx*)ctx,
params[0], params[1], params[2],
params[3], params[4], params[5],
Expand Down
2 changes: 1 addition & 1 deletion blacklists.c
Expand Up @@ -62,7 +62,7 @@ static mi_response_t *mi_del_blacklist_rule(const mi_params_t *params,
struct mi_handler *async_hdl);


static mi_export_t mi_bl_cmds[] = {
static const mi_export_t mi_bl_cmds[] = {
{ "list_blacklists", "lists all the defined (static or learned) blacklists", 0, 0, {
{mi_print_blacklists, {0}},
{mi_print_blacklists, {"name", 0}},
Expand Down
4 changes: 2 additions & 2 deletions cachedb/example/example_cachedb.c
Expand Up @@ -56,13 +56,13 @@ cachedb_funcs cdbf;
/* Actual connection to the Cache/DB back-end */
cachedb_con *con;

static cmd_export_t cmds[]=
static const cmd_export_t cmds[]=
{
{"process_msg", (cmd_function)process_msg, 0, 0, 0, REQUEST_ROUTE},
{0,0,0,0,0,0}
};

static param_export_t params[]={
static const param_export_t params[]={
{ "cachedb_url", STR_PARAM, &cachedb_url.s},
{0,0,0}
};
Expand Down
25 changes: 12 additions & 13 deletions cfg.y
Expand Up @@ -132,7 +132,6 @@ static void yyerror(char* s);
static void yyerrorf(char* fmt, ...);
static char* tmp;
static int i_tmp, rc;
static void* cmd_tmp;
static struct socket_id* lst_tmp;
static int rt; /* Type of route block for find_export */
static str s_tmp;
Expand Down Expand Up @@ -2148,31 +2147,31 @@ route_param: STRING {
;

async_func: ID LPAREN RPAREN {
cmd_tmp=(void*)find_mod_acmd_export_t($1);
if (cmd_tmp==0){
const acmd_export_t* acmd_tmp=find_mod_acmd_export_t($1);
if (acmd_tmp==0){
yyerrorf("unknown async command <%s>, "
"missing loadmodule?", $1);
$$=0;
}else{
if (check_acmd_call_params(cmd_tmp,elems,0)<0) {
if (check_acmd_call_params(acmd_tmp,elems,0)<0) {
yyerrorf("too few parameters "
"for command <%s>\n", $1);
$$=0;
} else {
elems[0].type = ACMD_ST;
elems[0].u.data = cmd_tmp;
elems[0].u.data_const = acmd_tmp;
mk_action_($$, AMODULE_T, 1, elems);
}
}
}
| ID LPAREN func_param RPAREN {
cmd_tmp=(void*)find_mod_acmd_export_t($1);
if (cmd_tmp==0){
const acmd_export_t* acmd_tmp=find_mod_acmd_export_t($1);
if (acmd_tmp==0){
yyerrorf("unknown async command <%s>, "
"missing loadmodule?", $1);
$$=0;
}else{
rc = check_acmd_call_params(cmd_tmp,elems,$3);
rc = check_acmd_call_params(acmd_tmp,elems,$3);
switch (rc) {
case -1:
yyerrorf("too few parameters "
Expand All @@ -2191,7 +2190,7 @@ async_func: ID LPAREN RPAREN {
break;
default:
elems[0].type = ACMD_ST;
elems[0].u.data = cmd_tmp;
elems[0].u.data_const = acmd_tmp;
mk_action_($$, AMODULE_T, $3+1, elems);
}
}
Expand Down Expand Up @@ -2272,7 +2271,7 @@ cmd: ASSERT LPAREN exp COMMA STRING RPAREN {
| ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route"
"argument"); }
| ID LPAREN RPAREN {
cmd_tmp=(void*)find_cmd_export_t($1, rt);
const cmd_export_t* cmd_tmp=find_cmd_export_t($1, rt);
if (cmd_tmp==0){
if (find_cmd_export_t($1, 0)) {
yyerrorf("Command <%s> cannot be "
Expand All @@ -2289,13 +2288,13 @@ cmd: ASSERT LPAREN exp COMMA STRING RPAREN {
$$=0;
} else {
elems[0].type = CMD_ST;
elems[0].u.data = cmd_tmp;
elems[0].u.data_const = cmd_tmp;
mk_action_($$, CMD_T, 1, elems);
}
}
}
| ID LPAREN func_param RPAREN {
cmd_tmp=(void*)find_cmd_export_t($1, rt);
const cmd_export_t* cmd_tmp=find_cmd_export_t($1, rt);
if (cmd_tmp==0){
if (find_cmd_export_t($1, 0)) {
yyerrorf("Command <%s> cannot be "
Expand Down Expand Up @@ -2325,7 +2324,7 @@ cmd: ASSERT LPAREN exp COMMA STRING RPAREN {
break;
default:
elems[0].type = CMD_ST;
elems[0].u.data = cmd_tmp;
elems[0].u.data_const = cmd_tmp;
mk_action_($$, CMD_T, $3+1, elems);
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmds.c
Expand Up @@ -63,9 +63,9 @@ int check_cmd_call_params(const cmd_export_t *cmd, action_elem_t *elems, int no_
}

/* simillar function to check_cmd_call_params but for async cmds */
int check_acmd_call_params(acmd_export_t *acmd, action_elem_t *elems, int no_params)
int check_acmd_call_params(const acmd_export_t *acmd, action_elem_t *elems, int no_params)
{
struct cmd_param *param;
const struct cmd_param *param;
int n=0, m=0, i;

for (param=acmd->params; param->flags; param++, n++)
Expand Down
6 changes: 3 additions & 3 deletions cmds.h
Expand Up @@ -56,7 +56,7 @@ struct cmd_param {
};

struct cmd_export_ {
char* name; /* null terminated command name */
const char* name; /* null terminated command name */
cmd_function function; /* pointer to the corresponding function */
struct cmd_param
params[MAX_CMD_PARAMS+1]; /* array of parameters */
Expand All @@ -65,7 +65,7 @@ struct cmd_export_ {


struct acmd_export_ {
char* name; /* null terminated command name */
const char* name; /* null terminated command name */
acmd_function function; /* pointer to the corresponding function */
struct cmd_param
params[MAX_CMD_PARAMS+1]; /* array of parameters */
Expand All @@ -76,7 +76,7 @@ typedef struct acmd_export_ acmd_export_t;

const cmd_export_t* find_cmd_export_t(const char* name, int flags);
int check_cmd_call_params(const cmd_export_t *cmd, action_elem_t *elems, int no_params);
int check_acmd_call_params(acmd_export_t *acmd, action_elem_t *elems, int no_params);
int check_acmd_call_params(const acmd_export_t *acmd, action_elem_t *elems, int no_params);

const cmd_export_t* find_core_cmd_export_t(const char* name, int flags);
const cmd_export_t* find_mod_cmd_export_t(const char* name, int flags);
Expand Down
4 changes: 2 additions & 2 deletions core_stats.c
Expand Up @@ -59,7 +59,7 @@ stat_var* bad_msg_hdr;
stat_var* slow_msgs;


stat_export_t core_stats[] = {
const stat_export_t core_stats[] = {
{"rcv_requests" , 0, &rcv_reqs },
{"rcv_replies" , 0, &rcv_rpls },
{"fwd_requests" , 0, &fwd_reqs },
Expand Down Expand Up @@ -94,7 +94,7 @@ static unsigned long net_get_wb_tls(unsigned short foo)
return get_total_bytes_waiting(PROTO_TLS);
}

stat_export_t net_stats[] = {
const stat_export_t net_stats[] = {
{"waiting_udp" , STAT_IS_FUNC, (stat_var**)net_get_wb_udp },
{"waiting_tcp" , STAT_IS_FUNC, (stat_var**)net_get_wb_tcp },
{"waiting_tls" , STAT_IS_FUNC, (stat_var**)net_get_wb_tls },
Expand Down
4 changes: 2 additions & 2 deletions evi/event_interface.c
Expand Up @@ -309,7 +309,7 @@ int evi_event_subscribe(str event_name,
{
evi_subs_t *subscriber = NULL;
evi_event_p event;
evi_export_t *trans_mod = NULL;
const evi_export_t *trans_mod = NULL;
evi_reply_sock *sock;

event = evi_get_event(&event_name);
Expand Down Expand Up @@ -648,7 +648,7 @@ static int evi_print_event(mi_item_t *ev_obj, evi_event_t *ev, evi_subs_p subs)

static evi_subs_p evi_get_subscriber(evi_event_p event, str sock_str)
{
evi_export_t * trans_mod;
const evi_export_t * trans_mod;
evi_subs_p subscriber = NULL;
evi_reply_sock * sock;

Expand Down
4 changes: 2 additions & 2 deletions evi/event_interface.h
Expand Up @@ -35,7 +35,7 @@
#define DEFAULT_EXPIRE 3600

typedef struct evi_subscriber {
evi_export_t* trans_mod; /* transport module */
const evi_export_t* trans_mod; /* transport module */
evi_reply_sock* reply_sock; /* reply socket */
struct evi_subscriber *next; /* next subscriber */
} evi_subs_t, *evi_subs_p;
Expand Down Expand Up @@ -70,7 +70,7 @@ mi_response_t *w_mi_raise_event(const mi_params_t *params,
struct mi_handler *async_hdl);

/* returns the transport export */
evi_export_t* get_trans_mod(str* tran);
const evi_export_t* get_trans_mod(str* tran);

/* returns the transport modules number */
int get_trans_mod_no(void);
Expand Down
4 changes: 2 additions & 2 deletions evi/evi_transport.c
Expand Up @@ -36,7 +36,7 @@ static int evi_trans_mods_size = 0;

/* functions used by the transport modules */

int register_event_mod(evi_export_t *ev)
int register_event_mod(const evi_export_t *ev)
{
evi_trans_t *trans_mod;

Expand Down Expand Up @@ -108,7 +108,7 @@ int get_trans_mod_no(void)
}

/* Returns the transport export */
evi_export_t* get_trans_mod(str* tran)
const evi_export_t* get_trans_mod(str* tran)
{
str t;
char *p;
Expand Down
4 changes: 2 additions & 2 deletions evi/evi_transport.h
Expand Up @@ -97,7 +97,7 @@ typedef struct evi_export_ {

/* transport list */
typedef struct evi_trans_ {
evi_export_t *module;
const evi_export_t *module;
struct evi_trans_ *next;
} evi_trans_t;

Expand All @@ -110,7 +110,7 @@ typedef struct evi_trans_ {
* Returns:
* - 0 if successful or negative on error
*/
int register_event_mod(evi_export_t *ev);
int register_event_mod(const evi_export_t *ev);

/*
* Used to build the payload of an event
Expand Down
2 changes: 1 addition & 1 deletion mi/mi_core.c
Expand Up @@ -764,7 +764,7 @@ static mi_response_t *w_reload_routes(const mi_params_t *params,



static mi_export_t mi_core_cmds[] = {
static const mi_export_t mi_core_cmds[] = {
{ "uptime", "prints various time information about OpenSIPS - "
"when it started to run, for how long it runs", 0, init_mi_uptime, {
{mi_uptime, {0}},
Expand Down
4 changes: 2 additions & 2 deletions mod_fix.c
Expand Up @@ -79,10 +79,10 @@ static inline gparam_p alloc_gp(void)
return gp;
}

int check_cmd(struct cmd_param *params, action_elem_t *elems)
int check_cmd(const struct cmd_param *params, action_elem_t *elems)
{
int i;
struct cmd_param *param;
const struct cmd_param *param;
pv_elem_t *pve;

for (param=params, i=1; param->flags; param++, i++) {
Expand Down
2 changes: 1 addition & 1 deletion mod_fix.h
Expand Up @@ -45,7 +45,7 @@ typedef struct _gparam

struct cmd_param;

int check_cmd(struct cmd_param *params, action_elem_t *elems);
int check_cmd(const struct cmd_param *params, action_elem_t *elems);
int fix_cmd(const struct cmd_param *params, action_elem_t *elems);
int get_cmd_fixups(struct sip_msg* msg, const struct cmd_param *params,
action_elem_t *elems, void **cmdp, pv_value_t *tmp_val);
Expand Down
10 changes: 5 additions & 5 deletions modules/aaa_diameter/aaa_diameter.c
Expand Up @@ -44,7 +44,7 @@ str dm_realm = str_init("diameter.test");
str dm_peer_identity = str_init("server"); /* a.k.a. server.diameter.test */
int dm_answer_timeout = 2000; /* ms */

static cmd_export_t cmds[]= {
static const cmd_export_t cmds[]= {
{"dm_send_request", (cmd_function)dm_send_request, {
{CMD_PARAM_INT,0,0},
{CMD_PARAM_INT,0,0},
Expand All @@ -56,12 +56,12 @@ static cmd_export_t cmds[]= {
{0,0,{{0,0,0}},0}
};

static proc_export_t procs[] = {
static const proc_export_t procs[] = {
{ "diameter-peer", NULL, NULL, diameter_peer_loop, 1, 0 },
{ 0, 0, 0, 0, 0, 0 },
};

static param_export_t params[] =
static const param_export_t params[] =
{
{ "fd_log_level", INT_PARAM, &fd_log_level },
{ "realm", STR_PARAM, &dm_realm.s },
Expand All @@ -70,15 +70,15 @@ static param_export_t params[] =
{ NULL, 0, NULL },
};

static mi_export_t mi_cmds[] = {
static const mi_export_t mi_cmds[] = {
{ "fd_log_level", 0, 0, 0, {
{NULL, {"log_level", 0}},
{EMPTY_MI_RECIPE}}
},
{EMPTY_MI_EXPORT}
};

static dep_export_t deps = {
static const dep_export_t deps = {
{ /* OpenSIPS module dependencies */
{ MOD_TYPE_NULL, NULL, 0 },
},
Expand Down

0 comments on commit 6bb21b7

Please sign in to comment.