From e6b2e9a7501b5d2e351a5e626fa13dfc3c113f1e Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Thu, 21 May 2009 21:13:09 +0000 Subject: Const-ify the world (or at least a good part of it) This patch adds 'const' tags to a number of Asterisk APIs where they are appropriate (where the API already demanded that the function argument not be modified, but the compiler was not informed of that fact). The list includes: - CLI command handlers - CLI command handler arguments - AGI command handlers - AGI command handler arguments - Dialplan application handler arguments - Speech engine API function arguments In addition, various file-scope and function-scope constant arrays got 'const' and/or 'static' qualifiers where they were missing. Review: https://reviewboard.asterisk.org/r/251/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@196072 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/abstract_jb.c | 19 ++++---- main/app.c | 6 +-- main/ast_expr2.fl | 4 +- main/asterisk.c | 4 +- main/astobj2.c | 8 +-- main/cdr.c | 8 +-- main/channel.c | 2 +- main/cli.c | 107 +++++++++++++++++++++------------------- main/dsp.c | 17 ++----- main/features.c | 37 +++++++------- main/frame.c | 6 +-- main/image.c | 6 +-- main/loader.c | 2 +- main/manager.c | 62 +++++++++++------------ main/pbx.c | 135 +++++++++++++++++++++++++-------------------------- main/taskprocessor.c | 8 +-- main/udptl.c | 2 +- main/ulaw.c | 2 +- main/utils.c | 8 +-- 19 files changed, 219 insertions(+), 224 deletions(-) (limited to 'main') diff --git a/main/abstract_jb.c b/main/abstract_jb.c index d7ff7354a..cda9a6dca 100644 --- a/main/abstract_jb.c +++ b/main/abstract_jb.c @@ -110,8 +110,7 @@ static void jb_force_resynch_adaptive(void *jb); static void jb_empty_and_reset_adaptive(void *jb); /* Available jb implementations */ -static struct ast_jb_impl avail_impl[] = -{ +static const struct ast_jb_impl avail_impl[] = { { .name = "fixed", .create = jb_create_fixed, @@ -150,13 +149,13 @@ enum { }; /* Translations between impl and abstract return codes */ -static int fixed_to_abstract_code[] = +static const int fixed_to_abstract_code[] = {JB_IMPL_OK, JB_IMPL_DROP, JB_IMPL_INTERP, JB_IMPL_NOFRAME}; -static int adaptive_to_abstract_code[] = +static const int adaptive_to_abstract_code[] = {JB_IMPL_OK, JB_IMPL_NOFRAME, JB_IMPL_NOFRAME, JB_IMPL_INTERP, JB_IMPL_DROP, JB_IMPL_OK}; /* JB_GET actions (used only for the frames log) */ -static char *jb_get_actions[] = {"Delivered", "Dropped", "Interpolated", "No"}; +static const char * const jb_get_actions[] = {"Delivered", "Dropped", "Interpolated", "No"}; /*! \brief Macros for the frame log files */ #define jb_framelog(...) do { \ @@ -181,7 +180,7 @@ static void jb_choose_impl(struct ast_channel *chan) { struct ast_jb *jb = &chan->jb; struct ast_jb_conf *jbconf = &jb->conf; - struct ast_jb_impl *test_impl; + const struct ast_jb_impl *test_impl; int i, avail_impl_count = ARRAY_LEN(avail_impl); jb->impl = &avail_impl[default_impl]; @@ -303,7 +302,7 @@ int ast_jb_get_when_to_wakeup(struct ast_channel *c0, struct ast_channel *c1, in int ast_jb_put(struct ast_channel *chan, struct ast_frame *f) { struct ast_jb *jb = &chan->jb; - struct ast_jb_impl *jbimpl = jb->impl; + const struct ast_jb_impl *jbimpl = jb->impl; void *jbobj = jb->jbobj; struct ast_frame *frr; long now = 0; @@ -385,7 +384,7 @@ void ast_jb_get_and_deliver(struct ast_channel *c0, struct ast_channel *c1) static void jb_get_and_deliver(struct ast_channel *chan) { struct ast_jb *jb = &chan->jb; - struct ast_jb_impl *jbimpl = jb->impl; + const struct ast_jb_impl *jbimpl = jb->impl; void *jbobj = jb->jbobj; struct ast_frame *f, finterp; long now; @@ -450,7 +449,7 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr) { struct ast_jb *jb = &chan->jb; struct ast_jb_conf *jbconf = &jb->conf; - struct ast_jb_impl *jbimpl = jb->impl; + const struct ast_jb_impl *jbimpl = jb->impl; void *jbobj; struct ast_channel *bridged; long now; @@ -534,7 +533,7 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr) void ast_jb_destroy(struct ast_channel *chan) { struct ast_jb *jb = &chan->jb; - struct ast_jb_impl *jbimpl = jb->impl; + const struct ast_jb_impl *jbimpl = jb->impl; void *jbobj = jb->jbobj; struct ast_frame *f; diff --git a/main/app.c b/main/app.c index 8e28b0c9a..72af3e085 100644 --- a/main/app.c +++ b/main/app.c @@ -180,7 +180,7 @@ enum ast_getdata_result ast_app_getdata(struct ast_channel *c, const char *promp /* The lock type used by ast_lock_path() / ast_unlock_path() */ static enum AST_LOCK_TYPE ast_lock_type = AST_LOCK_TYPE_LOCKFILE; -int ast_app_getdata_full(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd) +int ast_app_getdata_full(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd) { int res, to = 2000, fto = 6000; @@ -949,8 +949,8 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, return res; } -static char default_acceptdtmf[] = "#"; -static char default_canceldtmf[] = ""; +static const char default_acceptdtmf[] = "#"; +static const char default_canceldtmf[] = ""; int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence, const char *path, const char *acceptdtmf, const char *canceldtmf) { diff --git a/main/ast_expr2.fl b/main/ast_expr2.fl index 499706811..98d2ea5c4 100644 --- a/main/ast_expr2.fl +++ b/main/ast_expr2.fl @@ -313,7 +313,7 @@ void ast_expr_clear_extra_error_info(void) extra_error_message[0] = 0; } -static char *expr2_token_equivs1[] = +static const char * const expr2_token_equivs1[] = { "TOKEN", "TOK_COND", @@ -339,7 +339,7 @@ static char *expr2_token_equivs1[] = "TOK_LP" }; -static char *expr2_token_equivs2[] = +static const char * const expr2_token_equivs2[] = { "", "?", diff --git a/main/asterisk.c b/main/asterisk.c index 744ed2959..c45f6d8c8 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -765,7 +765,7 @@ int64_t ast_mark(int i, int startstop) static char *handle_show_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int i, min, max; - char *search = NULL; + const char *search = NULL; switch (cmd) { case CLI_INIT: e->command = "core show profile"; @@ -800,7 +800,7 @@ static char *handle_show_profile(struct ast_cli_entry *e, int cmd, struct ast_cl static char *handle_clear_profile(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int i, min, max; - char *search = NULL; + const char *search = NULL; switch (cmd) { case CLI_INIT: e->command = "core clear profile"; diff --git a/main/astobj2.c b/main/astobj2.c index 78c4cc00f..13e0c54b2 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -927,10 +927,10 @@ static void container_destruct_debug(void *_c) #ifdef AO2_DEBUG static int print_cb(void *obj, void *arg, int flag) { - int *fd = arg; + struct ast_cli_args *a = (struct ast_cli_args *) arg; char *s = (char *)obj; - ast_cli(*fd, "string <%s>\n", s); + ast_cli(a->fd, "string <%s>\n", s); return 0; } @@ -1017,7 +1017,7 @@ static char *handle_astobj2_test(struct ast_cli_entry *e, int cmd, struct ast_cl ao2_t_ref(obj, -1, "test"); } ast_cli(a->fd, "testing callbacks\n"); - ao2_t_callback(c1, 0, print_cb, &a->fd, "test callback"); + ao2_t_callback(c1, 0, print_cb, a, "test callback"); ast_cli(a->fd, "testing iterators, remove every second object\n"); { struct ao2_iterator ai; @@ -1038,7 +1038,7 @@ static char *handle_astobj2_test(struct ast_cli_entry *e, int cmd, struct ast_cl } } ast_cli(a->fd, "testing callbacks again\n"); - ao2_t_callback(c1, 0, print_cb, &a->fd, "test callback"); + ao2_t_callback(c1, 0, print_cb, a, "test callback"); ast_verbose("now you should see an error message:\n"); ao2_t_ref(&i, -1, ""); /* i is not a valid object so we print an error here */ diff --git a/main/cdr.c b/main/cdr.c index 65c4e3e01..169625fca 100644 --- a/main/cdr.c +++ b/main/cdr.c @@ -282,10 +282,10 @@ void ast_cdr_getvar(struct ast_cdr *cdr, const char *name, char **ret, char *wor } /* readonly cdr variables */ -static const char *cdr_readonly_vars[] = { "clid", "src", "dst", "dcontext", "channel", "dstchannel", - "lastapp", "lastdata", "start", "answer", "end", "duration", - "billsec", "disposition", "amaflags", "accountcode", "uniqueid", - "userfield", NULL }; +static const char * const cdr_readonly_vars[] = { "clid", "src", "dst", "dcontext", "channel", "dstchannel", + "lastapp", "lastdata", "start", "answer", "end", "duration", + "billsec", "disposition", "amaflags", "accountcode", "uniqueid", + "userfield", NULL }; /*! Set a CDR channel variable \note You can't set the CDR variables that belong to the actual CDR record, like "billsec". */ diff --git a/main/channel.c b/main/channel.c index 91bc8869c..969c0cfd6 100644 --- a/main/channel.c +++ b/main/channel.c @@ -3541,7 +3541,7 @@ int ast_senddigit_begin(struct ast_channel *chan, char digit) { /* Device does not support DTMF tones, lets fake * it by doing our own generation. */ - static const char* dtmf_tones[] = { + static const char * const dtmf_tones[] = { "941+1336", /* 0 */ "697+1209", /* 1 */ "697+1336", /* 2 */ diff --git a/main/cli.c b/main/cli.c index 8217e52d1..136d56a1e 100644 --- a/main/cli.c +++ b/main/cli.c @@ -365,13 +365,13 @@ static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_arg int atleast = 0; int fd = a->fd; int argc = a->argc; - char **argv = a->argv; - char *argv3 = a->argv ? S_OR(a->argv[3], "") : ""; + const char * const *argv = a->argv; + const char *argv3 = a->argv ? S_OR(a->argv[3], "") : ""; int *dst; char *what; struct debug_file_list *dfl; struct ast_debug_file *adf; - char *fn; + const char *fn; switch (cmd) { case CLI_INIT: @@ -387,7 +387,7 @@ static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_arg case CLI_GENERATE: if (a->pos == 3 || (a->pos == 4 && !strcasecmp(a->argv[3], "atleast"))) { - char *pos = a->pos == 3 ? argv3 : S_OR(a->argv[4], ""); + const char *pos = a->pos == 3 ? argv3 : S_OR(a->argv[4], ""); int numbermatch = (ast_strlen_zero(pos) || strchr("123456789", pos[0])) ? 0 : 21; if (a->n < 21 && numbermatch == 0) { return complete_number(pos, 0, 0x7fffffff, a->n); @@ -534,7 +534,7 @@ static char *handle_unload(struct ast_cli_entry *e, int cmd, struct ast_cli_args /* "module unload mod_1 [mod_2 .. mod_N]" */ int x; int force = AST_FORCE_SOFT; - char *s; + const char *s; switch (cmd) { case CLI_INIT: @@ -685,7 +685,7 @@ static char * handle_showuptime(struct ast_cli_entry *e, int cmd, struct ast_cli static char *handle_modlist(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - char *like; + const char *like; switch (cmd) { case CLI_INIT: @@ -787,8 +787,6 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar struct ast_channel *c = NULL; int numchans = 0, concise = 0, verbose = 0, count = 0; - int fd, argc; - char **argv; struct ast_channel_iterator *iter = NULL; switch (cmd) { @@ -808,16 +806,13 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar case CLI_GENERATE: return NULL; } - fd = a->fd; - argc = a->argc; - argv = a->argv; if (a->argc == e->args) { - if (!strcasecmp(argv[e->args-1],"concise")) + if (!strcasecmp(a->argv[e->args-1],"concise")) concise = 1; - else if (!strcasecmp(argv[e->args-1],"verbose")) + else if (!strcasecmp(a->argv[e->args-1],"verbose")) verbose = 1; - else if (!strcasecmp(argv[e->args-1],"count")) + else if (!strcasecmp(a->argv[e->args-1],"count")) count = 1; else return CLI_SHOWUSAGE; @@ -826,9 +821,9 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar if (!count) { if (!concise && !verbose) - ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)"); + ast_cli(a->fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)"); else if (verbose) - ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data", + ast_cli(a->fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data", "CallerID", "Duration", "Accountcode", "BridgedTo"); } @@ -857,7 +852,7 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar } } if (concise) { - ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), + ast_cli(a->fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), c->appl ? c->appl : "(None)", S_OR(c->data, ""), /* XXX different from verbose ? */ S_OR(c->cid.cid_num, ""), @@ -867,7 +862,7 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar bc ? bc->name : "(None)", c->uniqueid); } else if (verbose) { - ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), + ast_cli(a->fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), c->appl ? c->appl : "(None)", c->data ? S_OR(c->data, "(Empty)" ): "(None)", S_OR(c->cid.cid_num, ""), @@ -882,7 +877,7 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority); if (c->appl) snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, S_OR(c->data, "")); - ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata); + ast_cli(a->fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata); } } ast_channel_unlock(c); @@ -894,15 +889,15 @@ static char *handle_chanlist(struct ast_cli_entry *e, int cmd, struct ast_cli_ar if (!concise) { numchans = ast_active_channels(); - ast_cli(fd, "%d active channel%s\n", numchans, ESS(numchans)); + ast_cli(a->fd, "%d active channel%s\n", numchans, ESS(numchans)); if (option_maxcalls) - ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n", + ast_cli(a->fd, "%d of %d max active call%s (%5.2f%% of capacity)\n", ast_active_calls(), option_maxcalls, ESS(ast_active_calls()), ((double)ast_active_calls() / (double)option_maxcalls) * 100.0); else - ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls())); + ast_cli(a->fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls())); - ast_cli(fd, "%d call%s processed\n", ast_processed_calls(), ESS(ast_processed_calls())); + ast_cli(a->fd, "%d call%s processed\n", ast_processed_calls(), ESS(ast_processed_calls())); } return CLI_SUCCESS; @@ -1238,7 +1233,6 @@ static char *handle_core_set_debug_channel(struct ast_cli_entry *e, int cmd, str "Usage: core set debug channel [off]\n" " Enables/disables debugging on all or on a specific channel.\n"; return NULL; - case CLI_GENERATE: /* XXX remember to handle the optional "off" */ if (a->pos != e->args) @@ -1246,8 +1240,11 @@ static char *handle_core_set_debug_channel(struct ast_cli_entry *e, int cmd, str return a->n == 0 ? ast_strdup("all") : ast_complete_channels(a->line, a->word, a->pos, a->n - 1, e->args); } - /* 'core set debug channel {all|chan_id}' */ - if (a->argc == e->args + 2) { + if (cmd == (CLI_HANDLER + 1000)) { + /* called from handle_nodebugchan_deprecated */ + args.is_off = 1; + } else if (a->argc == e->args + 2) { + /* 'core set debug channel {all|chan_id}' */ if (!strcasecmp(a->argv[e->args + 1], "off")) args.is_off = 1; else @@ -1282,18 +1279,27 @@ static char *handle_core_set_debug_channel(struct ast_cli_entry *e, int cmd, str static char *handle_nodebugchan_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { char *res; - if (cmd == CLI_HANDLER) { - if (a->argc != e->args + 1) - return CLI_SHOWUSAGE; - /* pretend we have an extra "off" at the end. We can do this as the array - * is NULL terminated so we overwrite that entry. - */ - a->argv[e->args+1] = "off"; - a->argc++; - } - res = handle_core_set_debug_channel(e, cmd, a); - if (cmd == CLI_INIT) + + switch (cmd) { + case CLI_INIT: e->command = "no debug channel"; + return NULL; + case CLI_HANDLER: + /* exit out of switch statement */ + break; + default: + return NULL; + } + + if (a->argc != e->args + 1) + return CLI_SHOWUSAGE; + + /* add a 'magic' value to the CLI_HANDLER command so that + * handle_core_set_debug_channel() will act as if 'off' + * had been specified as part of the command + */ + res = handle_core_set_debug_channel(e, CLI_HANDLER + 1000, a); + return res; } @@ -1421,7 +1427,7 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar * helper function to generate CLI matches from a fixed set of values. * A NULL word is acceptable. */ -char *ast_cli_complete(const char *word, char *const choices[], int state) +char *ast_cli_complete(const char *word, const char * const choices[], int state) { int i, which = 0, len; len = ast_strlen_zero(word) ? 0 : strlen(word); @@ -1823,15 +1829,15 @@ static char *is_prefix(const char *word, const char *token, * 1 true only on complete, exact match. * */ -static struct ast_cli_entry *find_cli(char *const cmds[], int match_type) +static struct ast_cli_entry *find_cli(const char * const cmds[], int match_type) { int matchlen = -1; /* length of longest match so far */ struct ast_cli_entry *cand = NULL, *e=NULL; while ( (e = cli_next(e)) ) { /* word-by word regexp comparison */ - char * const *src = cmds; - char * const *dst = e->cmda; + const char * const *src = cmds; + const char * const *dst = e->cmda; int n = 0; for (;; dst++, src += n) { n = word_match(*src, *dst); @@ -1867,16 +1873,15 @@ static struct ast_cli_entry *find_cli(char *const cmds[], int match_type) return e ? e : cand; } -static char *find_best(char *argv[]) +static char *find_best(const char *argv[]) { static char cmdline[80]; int x; /* See how close we get, then print the candidate */ - char *myargv[AST_MAX_CMD_LEN]; - for (x=0;x@\n" @@ -2701,7 +2701,7 @@ static int action_mailboxstatus(struct mansession *s, const struct message *m) return 0; } -static char mandescr_mailboxcount[] = +static const char mandescr_mailboxcount[] = "Description: Checks a voicemail account for new messages.\n" "Variables: (Names marked with * are required)\n" " *Mailbox: Full mailbox ID @\n" @@ -2734,7 +2734,7 @@ static int action_mailboxcount(struct mansession *s, const struct message *m) return 0; } -static char mandescr_extensionstate[] = +static const char mandescr_extensionstate[] = "Description: Report the extension state for given extension.\n" " If the extension has a hint, will use devicestate to check\n" " the status of the device connected to the extension.\n" @@ -2770,7 +2770,7 @@ static int action_extensionstate(struct mansession *s, const struct message *m) return 0; } -static char mandescr_timeout[] = +static const char mandescr_timeout[] = "Description: Hangup a channel after a certain time.\n" "Variables: (Names marked with * are required)\n" " *Channel: Channel name to hangup\n" @@ -2839,7 +2839,7 @@ static int process_events(struct mansession *s) return ret; } -static char mandescr_userevent[] = +static const char mandescr_userevent[] = "Description: Send an event to manager sessions.\n" "Variables: (Names marked with * are required)\n" " *UserEvent: EventStringToSend\n" @@ -2864,7 +2864,7 @@ static int action_userevent(struct mansession *s, const struct message *m) return 0; } -static char mandescr_coresettings[] = +static const char mandescr_coresettings[] = "Description: Query for Core PBX settings.\n" "Variables: (Names marked with * are optional)\n" " *ActionID: ActionID of this transaction\n"; @@ -2911,7 +2911,7 @@ static int action_coresettings(struct mansession *s, const struct message *m) return 0; } -static char mandescr_corestatus[] = +static const char mandescr_corestatus[] = "Description: Query for Core PBX status.\n" "Variables: (Names marked with * are optional)\n" " *ActionID: ActionID of this transaction\n"; @@ -2950,7 +2950,7 @@ static int action_corestatus(struct mansession *s, const struct message *m) return 0; } -static char mandescr_reload[] = +static const char mandescr_reload[] = "Description: Send a reload event.\n" "Variables: (Names marked with * are optional)\n" " *ActionID: ActionID of this transaction\n" @@ -2970,7 +2970,7 @@ static int action_reload(struct mansession *s, const struct message *m) return 0; } -static char mandescr_coreshowchannels[] = +static const char mandescr_coreshowchannels[] = "Description: List currently defined channels and some information\n" " about them.\n" "Variables:\n" @@ -3052,7 +3052,7 @@ static int action_coreshowchannels(struct mansession *s, const struct message *m return 0; } -static char mandescr_modulecheck[] = +static const char mandescr_modulecheck[] = "Description: Checks if Asterisk module is loaded\n" "Variables: \n" " ActionID: Action ID for this transaction. Will be returned.\n" @@ -3105,7 +3105,7 @@ static int manager_modulecheck(struct mansession *s, const struct message *m) return 0; } -static char mandescr_moduleload[] = +static const char mandescr_moduleload[] = "Description: Loads, unloads or reloads an Asterisk module in a running system.\n" "Variables: \n" " ActionID: Action ID for this transaction. Will be returned.\n" @@ -3684,7 +3684,7 @@ enum output_format { FORMAT_XML, }; -static char *contenttype[] = { +static const char * const contenttype[] = { [FORMAT_RAW] = "plain", [FORMAT_HTML] = "html", [FORMAT_XML] = "xml", diff --git a/main/pbx.c b/main/pbx.c index 28c04802d..a24690278 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -855,7 +855,7 @@ struct ast_context { /*! \brief ast_app: A registered application */ struct ast_app { - int (*execute)(struct ast_channel *chan, void *data); + int (*execute)(struct ast_channel *chan, const char *data); AST_DECLARE_STRING_FIELDS( AST_STRING_FIELD(synopsis); /*!< Synopsis text for 'show applications' */ AST_STRING_FIELD(description); /*!< Description (help text) for 'show application <name>' */ @@ -919,33 +919,33 @@ struct pbx_exception { int priority; /*!< Priority associated with this exception */ }; -static int pbx_builtin_answer(struct ast_channel *, void *); -static int pbx_builtin_goto(struct ast_channel *, void *); -static int pbx_builtin_hangup(struct ast_channel *, void *); -static int pbx_builtin_background(struct ast_channel *, void *); -static int pbx_builtin_wait(struct ast_channel *, void *); -static int pbx_builtin_waitexten(struct ast_channel *, void *); -static int pbx_builtin_incomplete(struct ast_channel *, void *); -static int pbx_builtin_resetcdr(struct ast_channel *, void *); -static int pbx_builtin_setamaflags(struct ast_channel *, void *); -static int pbx_builtin_ringing(struct ast_channel *, void *); -static int pbx_builtin_proceeding(struct ast_channel *, void *); -static int pbx_builtin_progress(struct ast_channel *, void *); -static int pbx_builtin_congestion(struct ast_channel *, void *); -static int pbx_builtin_busy(struct ast_channel *, void *); -static int pbx_builtin_noop(struct ast_channel *, void *); -static int pbx_builtin_gotoif(struct ast_channel *, void *); -static int pbx_builtin_gotoiftime(struct ast_channel *, void *); -static int pbx_builtin_execiftime(struct ast_channel *, void *); -static int pbx_builtin_saynumber(struct ast_channel *, void *); -static int pbx_builtin_saydigits(struct ast_channel *, void *); -static int pbx_builtin_saycharacters(struct ast_channel *, void *); -static int pbx_builtin_sayphonetic(struct ast_channel *, void *); +static int pbx_builtin_answer(struct ast_channel *, const char *); +static int pbx_builtin_goto(struct ast_channel *, const char *); +static int pbx_builtin_hangup(struct ast_channel *, const char *); +static int pbx_builtin_background(struct ast_channel *, const char *); +static int pbx_builtin_wait(struct ast_channel *, const char *); +static int pbx_builtin_waitexten(struct ast_channel *, const char *); +static int pbx_builtin_incomplete(struct ast_channel *, const char *); +static int pbx_builtin_resetcdr(struct ast_channel *, const char *); +static int pbx_builtin_setamaflags(struct ast_channel *, const char *); +static int pbx_builtin_ringing(struct ast_channel *, const char *); +static int pbx_builtin_proceeding(struct ast_channel *, const char *); +static int pbx_builtin_progress(struct ast_channel *, const char *); +static int pbx_builtin_congestion(struct ast_channel *, const char *); +static int pbx_builtin_busy(struct ast_channel *, const char *); +static int pbx_builtin_noop(struct ast_channel *, const char *); +static int pbx_builtin_gotoif(struct ast_channel *, const char *); +static int pbx_builtin_gotoiftime(struct ast_channel *, const char *); +static int pbx_builtin_execiftime(struct ast_channel *, const char *); +static int pbx_builtin_saynumber(struct ast_channel *, const char *); +static int pbx_builtin_saydigits(struct ast_channel *, const char *); +static int pbx_builtin_saycharacters(struct ast_channel *, const char *); +static int pbx_builtin_sayphonetic(struct ast_channel *, const char *); static int matchcid(const char *cidpattern, const char *callerid); -int pbx_builtin_setvar(struct ast_channel *, void *); +int pbx_builtin_setvar(struct ast_channel *, const char *); void log_match_char_tree(struct match_char *node, char *prefix); /* for use anywhere */ -int pbx_builtin_setvar_multiple(struct ast_channel *, void *); -static int pbx_builtin_importvar(struct ast_channel *, void *); +int pbx_builtin_setvar_multiple(struct ast_channel *, const char *); +static int pbx_builtin_importvar(struct ast_channel *, const char *); static void set_ext_pri(struct ast_channel *c, const char *exten, int pri); static void new_find_extension(const char *str, struct scoreboard *score, struct match_char *tree, int length, int spec, const char *callerid, @@ -1083,7 +1083,7 @@ static AST_RWLIST_HEAD_STATIC(acf_root, ast_custom_function); /*! \brief Declaration of builtin applications */ static struct pbx_builtin { char name[AST_MAX_APP]; - int (*execute)(struct ast_channel *chan, void *data); + int (*execute)(struct ast_channel *chan, const char *data); } builtins[] = { /* These applications are built into the PBX core and do not @@ -1320,9 +1320,9 @@ int check_contexts(char *file, int line ) /* \note This function is special. It saves the stack so that no matter how many times it is called, it returns to the same place */ -int pbx_exec(struct ast_channel *c, /*!< Channel */ - struct ast_app *app, /*!< Application */ - void *data) /*!< Data for execution */ +int pbx_exec(struct ast_channel *c, /*!< Channel */ + struct ast_app *app, /*!< Application */ + const char *data) /*!< Data for execution */ { int res; struct ast_module_user *u = NULL; @@ -3040,9 +3040,8 @@ static struct ast_datastore_info exception_store_info = { .destroy = exception_store_free, }; -int pbx_builtin_raise_exception(struct ast_channel *chan, void *vreason) +int pbx_builtin_raise_exception(struct ast_channel *chan, const char *reason) { - const char *reason = vreason; struct ast_datastore *ds = ast_channel_datastore_find(chan, &exception_store_info, NULL); struct pbx_exception *exception = NULL; @@ -5332,7 +5331,7 @@ int ast_context_unlockmacro(const char *context) } /*! \brief Dynamically register a new dial plan application */ -int ast_register_application2(const char *app, int (*execute)(struct ast_channel *, void *), const char *synopsis, const char *description, void *mod) +int ast_register_application2(const char *app, int (*execute)(struct ast_channel *, const char *), const char *synopsis, const char *description, void *mod) { struct ast_app *tmp, *cur = NULL; char tmps[80]; @@ -5757,7 +5756,7 @@ static char *handle_show_applications(struct ast_cli_entry *e, int cmd, struct a int like = 0, describing = 0; int total_match = 0; /* Number of matches in like clause */ int total_apps = 0; /* Number of apps registered */ - static char* choices[] = { "like", "describing", NULL }; + static const char * const choices[] = { "like", "describing", NULL }; switch (cmd) { case CLI_INIT: @@ -6127,7 +6126,7 @@ static char *handle_show_dialplan(struct ast_cli_entry *e, int cmd, struct ast_c if (ast_strlen_zero(exten)) exten = NULL; } else { /* no '@' char, only context given */ - context = a->argv[2]; + context = ast_strdupa(a->argv[2]); } if (ast_strlen_zero(context)) context = NULL; @@ -6195,7 +6194,7 @@ static char *handle_debug_dialplan(struct ast_cli_entry *e, int cmd, struct ast_ if (ast_strlen_zero(exten)) exten = NULL; } else { /* no '@' char, only context given */ - context = a->argv[2]; + context = ast_strdupa(a->argv[2]); } if (ast_strlen_zero(context)) context = NULL; @@ -6417,7 +6416,7 @@ static int manager_show_dialplan(struct mansession *s, const struct message *m) return 0; } -static char mandescr_show_dialplan[] = +static const char mandescr_show_dialplan[] = "Description: Show dialplan contexts and extensions.\n" "Be aware that showing the full dialplan may take a lot of capacity\n" "Variables: \n" @@ -7025,7 +7024,7 @@ int ast_context_add_include(const char *context, const char *include, const char * return the index of the matching entry, starting from 1. * If names is not supplied, try numeric values. */ -static int lookup_name(const char *s, char *const names[], int max) +static int lookup_name(const char *s, const char * const names[], int max) { int i; @@ -7048,7 +7047,7 @@ static int lookup_name(const char *s, char *const names[], int max) /*! \brief helper function to return a range up to max (7, 12, 31 respectively). * names, if supplied, is an array of names that should be mapped to numbers. */ -static unsigned get_range(char *src, int max, char *const names[], const char *msg) +static unsigned get_range(char *src, int max, const char * const names[], const char *msg) { int start, end; /* start and ending position */ unsigned int mask = 0; @@ -7151,7 +7150,7 @@ static void get_timerange(struct ast_timing *i, char *times) return; } -static char *days[] = +static const char * const days[] = { "sun", "mon", @@ -7163,7 +7162,7 @@ static char *days[] = NULL, }; -static char *months[] = +static const char * const months[] = { "jan", "feb", @@ -8659,7 +8658,7 @@ void ast_context_destroy(struct ast_context *con, const char *registrar) ast_unlock_contexts(); } -static void wait_for_hangup(struct ast_channel *chan, void *data) +static void wait_for_hangup(struct ast_channel *chan, const void *data) { int res; struct ast_frame *f; @@ -8684,7 +8683,7 @@ static void wait_for_hangup(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_proceeding(struct ast_channel *chan, void *data) +static int pbx_builtin_proceeding(struct ast_channel *chan, const char *data) { ast_indicate(chan, AST_CONTROL_PROCEEDING); return 0; @@ -8693,7 +8692,7 @@ static int pbx_builtin_proceeding(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_progress(struct ast_channel *chan, void *data) +static int pbx_builtin_progress(struct ast_channel *chan, const char *data) { ast_indicate(chan, AST_CONTROL_PROGRESS); return 0; @@ -8702,7 +8701,7 @@ static int pbx_builtin_progress(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_ringing(struct ast_channel *chan, void *data) +static int pbx_builtin_ringing(struct ast_channel *chan, const char *data) { ast_indicate(chan, AST_CONTROL_RINGING); return 0; @@ -8711,7 +8710,7 @@ static int pbx_builtin_ringing(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_busy(struct ast_channel *chan, void *data) +static int pbx_builtin_busy(struct ast_channel *chan, const char *data) { ast_indicate(chan, AST_CONTROL_BUSY); /* Don't change state of an UP channel, just indicate @@ -8727,7 +8726,7 @@ static int pbx_builtin_busy(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_congestion(struct ast_channel *chan, void *data) +static int pbx_builtin_congestion(struct ast_channel *chan, const char *data) { ast_indicate(chan, AST_CONTROL_CONGESTION); /* Don't change state of an UP channel, just indicate @@ -8741,7 +8740,7 @@ static int pbx_builtin_congestion(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_answer(struct ast_channel *chan, void *data) +static int pbx_builtin_answer(struct ast_channel *chan, const char *data) { int delay = 0; int answer_cdr = 1; @@ -8773,9 +8772,9 @@ static int pbx_builtin_answer(struct ast_channel *chan, void *data) return __ast_answer(chan, delay, answer_cdr); } -static int pbx_builtin_incomplete(struct ast_channel *chan, void *data) +static int pbx_builtin_incomplete(struct ast_channel *chan, const char *data) { - char *options = data; + const char *options = data; int answer = 1; /* Some channels can receive DTMF in unanswered state; some cannot */ @@ -8803,7 +8802,7 @@ AST_APP_OPTIONS(resetcdr_opts, { /*! * \ingroup applications */ -static int pbx_builtin_resetcdr(struct ast_channel *chan, void *data) +static int pbx_builtin_resetcdr(struct ast_channel *chan, const char *data) { char *args; struct ast_flags flags = { 0 }; @@ -8821,7 +8820,7 @@ static int pbx_builtin_resetcdr(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_setamaflags(struct ast_channel *chan, void *data) +static int pbx_builtin_setamaflags(struct ast_channel *chan, const char *data) { /* Copy the AMA Flags as specified */ ast_cdr_setamaflags(chan, data ? data : ""); @@ -8831,7 +8830,7 @@ static int pbx_builtin_setamaflags(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_hangup(struct ast_channel *chan, void *data) +static int pbx_builtin_hangup(struct ast_channel *chan, const char *data) { if (!ast_strlen_zero(data)) { int cause; @@ -8861,7 +8860,7 @@ static int pbx_builtin_hangup(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_gotoiftime(struct ast_channel *chan, void *data) +static int pbx_builtin_gotoiftime(struct ast_channel *chan, const char *data) { char *s, *ts, *branch1, *branch2, *branch; struct ast_timing timing; @@ -8896,7 +8895,7 @@ static int pbx_builtin_gotoiftime(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_execiftime(struct ast_channel *chan, void *data) +static int pbx_builtin_execiftime(struct ast_channel *chan, const char *data) { char *s, *appname; struct ast_timing timing; @@ -8950,7 +8949,7 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_wait(struct ast_channel *chan, void *data) +static int pbx_builtin_wait(struct ast_channel *chan, const char *data) { double s; int ms; @@ -8966,7 +8965,7 @@ static int pbx_builtin_wait(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_waitexten(struct ast_channel *chan, void *data) +static int pbx_builtin_waitexten(struct ast_channel *chan, const char *data) { int ms, res; double s; @@ -9035,7 +9034,7 @@ static int pbx_builtin_waitexten(struct ast_channel *chan, void *data) /*! * \ingroup applications */ -static int pbx_builtin_background(struct ast_channel *chan, void *data) +static int pbx_builtin_background(struct ast_channel *chan, const char *data) { int res = 0; int mres = 0; @@ -9133,7 +9132,7 @@ done: /*! Goto * \ingroup applications */ -static int pbx_builtin_goto(struct ast_channel *chan, void *data) +static int pbx_builtin_goto(struct ast_channel *chan, const char *data) { int res = ast_parseable_goto(chan, data); if (!res) @@ -9302,7 +9301,7 @@ void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const ast_rwlock_unlock(&globalslock); } -int pbx_builtin_setvar(struct ast_channel *chan, void *data) +int pbx_builtin_setvar(struct ast_channel *chan, const char *data) { char *name, *value, *mydata; @@ -9325,7 +9324,7 @@ int pbx_builtin_setvar(struct ast_channel *chan, void *data) return(0); } -int pbx_builtin_setvar_multiple(struct ast_channel *chan, void *vdata) +int pbx_builtin_setvar_multiple(struct ast_channel *chan, const char *vdata) { char *data; int x; @@ -9361,7 +9360,7 @@ int pbx_builtin_setvar_multiple(struct ast_channel *chan, void *vdata) return 0; } -int pbx_builtin_importvar(struct ast_channel *chan, void *data) +int pbx_builtin_importvar(struct ast_channel *chan, const char *data) { char *name; char *value; @@ -9398,7 +9397,7 @@ int pbx_builtin_importvar(struct ast_channel *chan, void *data) return(0); } -static int pbx_builtin_noop(struct ast_channel *chan, void *data) +static int pbx_builtin_noop(struct ast_channel *chan, const char *data) { return 0; } @@ -9425,7 +9424,7 @@ int pbx_checkcondition(const char *condition) } } -static int pbx_builtin_gotoif(struct ast_channel *chan, void *data) +static int pbx_builtin_gotoif(struct ast_channel *chan, const char *data) { char *condition, *branch1, *branch2, *branch; char *stringp; @@ -9449,7 +9448,7 @@ static int pbx_builtin_gotoif(struct ast_channel *chan, void *data) return pbx_builtin_goto(chan, branch); } -static int pbx_builtin_saynumber(struct ast_channel *chan, void *data) +static int pbx_builtin_saynumber(struct ast_channel *chan, const char *data) { char tmp[256]; char *number = tmp; @@ -9477,7 +9476,7 @@ static int pbx_builtin_saynumber(struct ast_channel *chan, void *data) return 0; } -static int pbx_builtin_saydigits(struct ast_channel *chan, void *data) +static int pbx_builtin_saydigits(struct ast_channel *chan, const char *data) { int res = 0; @@ -9486,7 +9485,7 @@ static int pbx_builtin_saydigits(struct ast_channel *chan, void *data) return res; } -static int pbx_builtin_saycharacters(struct ast_channel *chan, void *data) +static int pbx_builtin_saycharacters(struct ast_channel *chan, const char *data) { int res = 0; @@ -9495,7 +9494,7 @@ static int pbx_builtin_saycharacters(struct ast_channel *chan, void *data) return res; } -static int pbx_builtin_sayphonetic(struct ast_channel *chan, void *data) +static int pbx_builtin_sayphonetic(struct ast_channel *chan, const char *data) { int res = 0; diff --git a/main/taskprocessor.c b/main/taskprocessor.c index 9aa86ce00..0de97e503 100644 --- a/main/taskprocessor.c +++ b/main/taskprocessor.c @@ -62,7 +62,7 @@ struct tps_taskprocessor_stats { /*! \brief A ast_taskprocessor structure is a singleton by name */ struct ast_taskprocessor { /*! \brief Friendly name of the taskprocessor */ - char *name; + const char *name; /*! \brief Thread poll condition */ ast_cond_t poll_cond; /*! \brief Taskprocessor thread */ @@ -189,7 +189,7 @@ static int tps_ping_handler(void *datap) static char *cli_tps_ping(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct timeval begin, end, delta; - char *name; + const char *name; struct timeval when; struct timespec ts; struct ast_taskprocessor *tps = NULL; @@ -366,7 +366,7 @@ static void tps_taskprocessor_destroy(void *tps) ast_free(t->stats); t->stats = NULL; } - ast_free(t->name); + ast_free((char *) t->name); } /* pop the front task and return it */ @@ -404,7 +404,7 @@ const char *ast_taskprocessor_name(struct ast_taskprocessor *tps) /* Provide a reference to a taskprocessor. Create the taskprocessor if necessary, but don't * create the taskprocessor if we were told via ast_tps_options to return a reference only * if it already exists */ -struct ast_taskprocessor *ast_taskprocessor_get(char *name, enum ast_tps_options create) +struct ast_taskprocessor *ast_taskprocessor_get(const char *name, enum ast_tps_options create) { struct ast_taskprocessor *p, tmp_tps = { .name = name, diff --git a/main/udptl.c b/main/udptl.c index 478ce8f5f..dfe89e126 100644 --- a/main/udptl.c +++ b/main/udptl.c @@ -1134,7 +1134,7 @@ static char *handle_cli_udptl_set_debug(struct ast_cli_entry *e, int cmd, struct if (strncasecmp(a->argv[3], "ip", 2)) return CLI_SHOWUSAGE; port = 0; - arg = a->argv[4]; + arg = ast_strdupa(a->argv[4]); p = strstr(arg, ":"); if (p) { *p = '\0'; diff --git a/main/ulaw.c b/main/ulaw.c index 18a118f60..0be633c4c 100644 --- a/main/ulaw.c +++ b/main/ulaw.c @@ -177,7 +177,7 @@ void ast_ulaw_init(void) #ifndef G711_NEW_ALGORITHM for (i = 0;i < 256;i++) { short mu,e,f,y; - static short etab[]={0,132,396,924,1980,4092,8316,16764}; + static const short etab[]={0,132,396,924,1980,4092,8316,16764}; mu = 255-i; e = (mu & 0x70)/16; diff --git a/main/utils.c b/main/utils.c index e724160f4..59a29ce5a 100644 --- a/main/utils.c +++ b/main/utils.c @@ -227,7 +227,7 @@ struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp) } /*! \brief Produce 32 char MD5 hash of value. */ -void ast_md5_hash(char *output, char *input) +void ast_md5_hash(char *output, const char *input) { struct MD5Context md5; unsigned char digest[16]; @@ -235,7 +235,7 @@ void ast_md5_hash(char *output, char *input) int x; MD5Init(&md5); - MD5Update(&md5, (unsigned char *)input, strlen(input)); + MD5Update(&md5, (const unsigned char *) input, strlen(input)); MD5Final(digest, &md5); ptr = output; for (x = 0; x < 16; x++) @@ -243,7 +243,7 @@ void ast_md5_hash(char *output, char *input) } /*! \brief Produce 40 char SHA1 hash of value. */ -void ast_sha1_hash(char *output, char *input) +void ast_sha1_hash(char *output, const char *input) { struct SHA1Context sha; char *ptr; @@ -1446,7 +1446,7 @@ char *ast_process_quotes_and_slashes(char *start, char find, char replace_with) return dataPut; } -void ast_join(char *s, size_t len, char * const w[]) +void ast_join(char *s, size_t len, const char * const w[]) { int x, ofs = 0; const char *src; -- cgit v1.2.3