make the 'name' and 'value' fields in ast_variable const char *

This prevents modifying the strings in the stored variables, 
and catched a few instances where this was actually done.

Given the differences between trunk and 1.4 (and the fact that this
is effectively an API change) it is better to fix 1.4 independently.
These are

chan_sip.c::sip_register()
chan_skinny.c:: near line 2847
config.c:: near line 1774
logger.c::make_components()
res_adsi.c:: near line 1049

I may have missed some instances for modules that do not build here.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89268 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Luigi Rizzo 18 years ago
parent d3414c7552
commit 7f8ecd2cd3

@ -277,8 +277,8 @@ static char *convert(const char *lastname)
* '1' for selected entry from directory
* '*' for skipped entry from directory
*/
static int play_mailbox_owner(struct ast_channel *chan, char *context,
char *dialcontext, char *ext, char *name, int readext,
static int play_mailbox_owner(struct ast_channel *chan, const char *context,
const char *dialcontext, const char *ext, const char *name, int readext,
int fromappvm)
{
int res = 0;

@ -458,7 +458,7 @@ static double global_volgain; /*!< Volume gain for voicmemail via e-mail */
#define DEFAULT_CHARSET "ISO-8859-1"
/* Forward declarations */
static char *message_template_parse_filebody(char *filename);
static char *message_template_parse_filebody(const char *filename);
static char *message_template_parse_emailbody(const char *body);
static int create_vmaccount(char *name, struct ast_variable *var, int realtime);
static struct minivm_account *find_user_realtime(const char *domain, const char *username);
@ -2182,7 +2182,7 @@ static void timezone_destroy_list(void)
}
/*! \brief Add time zone to memory list */
static int timezone_add(char *zonename, char *config)
static int timezone_add(const char *zonename, const char *config)
{
struct minivm_zone *newzone;
@ -2220,7 +2220,7 @@ static int timezone_add(char *zonename, char *config)
}
/*! \brief Read message template from file */
static char *message_template_parse_filebody(char *filename) {
static char *message_template_parse_filebody(const char *filename) {
char buf[BUFSIZ * 6];
char readbuf[BUFSIZ];
char filenamebuf[BUFSIZ];

@ -325,7 +325,7 @@ static int say_datetime(struct ast_channel *chan, time_t t, const char *ints, co
/*
* remap the 'say' functions to use those in this file
*/
static int say_init_mode(char *mode) {
static int say_init_mode(const char *mode) {
if (!strcmp(mode, say_new)) {
if (say_cfg == NULL) {
ast_log(LOG_ERROR, "There is no say.conf file to use new mode\n");

@ -1242,7 +1242,8 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
struct member *m;
struct ao2_iterator mem_iter;
char *interface = NULL;
char *tmp, *tmp_name;
const char *tmp_name;
char *tmp;
char tmpbuf[64]; /* Must be longer than the longest queue param name. */
/* Static queues override realtime. */
@ -1300,7 +1301,7 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
if ((tmp = strchr(v->name, '_'))) {
ast_copy_string(tmpbuf, v->name, sizeof(tmpbuf));
tmp_name = tmpbuf;
tmp = tmp_name;
tmp = tmpbuf;
while ((tmp = strchr(tmp, '_')))
*tmp++ = '-';
} else
@ -2664,7 +2665,7 @@ static void send_agent_complete(const struct queue_ent *qe, const char *queuenam
const struct ast_channel *peer, const struct member *member, time_t callstart,
char *vars, size_t vars_len, enum agent_complete_reason rsn)
{
const char *reason;
const char *reason = NULL; /* silence dumb compilers */
if (!qe->parent->eventwhencalled)
return;

@ -1652,7 +1652,7 @@ static void copy_file(char *frompath, char *topath)
{
char frompath2[PATH_MAX], topath2[PATH_MAX];
struct ast_variable *tmp,*var = NULL;
char *origmailbox = NULL, *context = NULL, *macrocontext = NULL, *exten = NULL, *priority = NULL, *callerchan = NULL, *callerid = NULL, *origdate = NULL, *origtime = NULL, *category = NULL, *duration = NULL;
const char *origmailbox = NULL, *context = NULL, *macrocontext = NULL, *exten = NULL, *priority = NULL, *callerchan = NULL, *callerid = NULL, *origdate = NULL, *origtime = NULL, *category = NULL, *duration = NULL;
ast_filecopy(frompath, topath, NULL);
snprintf(frompath2, sizeof(frompath2), "%s.txt", frompath);
snprintf(topath2, sizeof(topath2), "%s.txt", topath);
@ -7400,7 +7400,7 @@ static int vm_exec(struct ast_channel *chan, void *data)
return res;
}
static struct ast_vm_user *find_or_create(char *context, char *mbox)
static struct ast_vm_user *find_or_create(const char *context, const char *mbox)
{
struct ast_vm_user *vmu;
@ -7425,7 +7425,7 @@ static struct ast_vm_user *find_or_create(char *context, char *mbox)
return vmu;
}
static int append_mailbox(char *context, char *mbox, char *data)
static int append_mailbox(const char *context, const char *mbox, const char *data)
{
/* Assumes lock is already held */
char *tmp;

@ -267,7 +267,7 @@ static const struct ast_channel_tech agent_tech = {
* @return The just created agent.
* \sa agent_pvt, agents.
*/
static struct agent_pvt *add_agent(char *agent, int pending)
static struct agent_pvt *add_agent(const char *agent, int pending)
{
char *parse;
AST_DECLARE_APP_ARGS(args,

@ -6287,7 +6287,7 @@ static int iax2_append_register(const char *hostname, const char *username,
return 0;
}
static int iax2_register(char *value, int lineno)
static int iax2_register(const char *value, int lineno)
{
char copy[256];
char *username, *hostname, *secret;
@ -9592,7 +9592,7 @@ static int start_network_thread(void)
return 0;
}
static struct iax2_context *build_context(char *context)
static struct iax2_context *build_context(const char *context)
{
struct iax2_context *con;
@ -9602,7 +9602,7 @@ static struct iax2_context *build_context(char *context)
return con;
}
static int get_auth_methods(char *value)
static int get_auth_methods(const char *value)
{
int methods = 0;
if (strstr(value, "rsa"))

@ -212,7 +212,7 @@ END_CONFIG
* Likely we will come up with a better way of doing config file parsing.
*/
#define M_START(var, val) \
char *__s = var; char *__val = val;
const char *__s = var; const char *__val = val;
#define M_END(x) x;
#define M_F(tag, f) if (!strcasecmp((__s), tag)) { f; } else
#define M_BOOL(tag, dst) M_F(tag, (dst) = ast_true(__val) )
@ -1413,7 +1413,7 @@ static char *console_active(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
/*!
* \brief store the boost factor
*/
static void store_boost(struct chan_oss_pvt *o, char *s)
static void store_boost(struct chan_oss_pvt *o, const char *s)
{
double boost = 0;
if (sscanf(s, "%lf", &boost) != 1) {
@ -1472,7 +1472,7 @@ static struct ast_cli_entry cli_oss[] = {
* invalid or dangerous values (the string is used as argument for
* system("mixer %s")
*/
static void store_mixer(struct chan_oss_pvt *o, char *s)
static void store_mixer(struct chan_oss_pvt *o, const char *s)
{
int i;
@ -1491,7 +1491,7 @@ static void store_mixer(struct chan_oss_pvt *o, char *s)
/*!
* store the callerid components
*/
static void store_callerid(struct chan_oss_pvt *o, char *s)
static void store_callerid(struct chan_oss_pvt *o, const char *s)
{
ast_callerid_split(s, o->cid_name, sizeof(o->cid_name), o->cid_num, sizeof(o->cid_num));
}

@ -1572,7 +1572,7 @@ static int add_sip_domain(const char *domain, const enum domain_mode mode, const
static void clear_sip_domains(void);
/*--- SIP realm authentication */
static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno);
static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, const char *configuration, int lineno);
static int clear_realm_authentication(struct sip_auth *authlist); /* Clear realm authentication list (at reload) */
static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, const char *realm);
@ -1686,7 +1686,7 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli
/*--- Internal UA client handling (outbound registrations) */
static void ast_sip_ouraddrfor(struct in_addr *them, struct sockaddr_in *us);
static void sip_registry_destroy(struct sip_registry *reg);
static int sip_register(char *value, int lineno);
static int sip_register(const char *value, int lineno);
static const char *regstate2str(enum sipregistrystate regstate) attribute_const;
static int sip_reregister(const void *data);
static int __sip_do_register(struct sip_registry *r);
@ -5248,7 +5248,7 @@ static struct sip_pvt *find_call(struct sip_request *req, struct sockaddr_in *si
}
/*! \brief Parse register=> line in sip.conf and add to registry */
static int sip_register(char *value, int lineno)
static int sip_register(const char *value, int lineno)
{
struct sip_registry *reg;
int portnum = 0;
@ -12545,8 +12545,11 @@ static char *sip_notify(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a
initreqprep(&req, p, SIP_NOTIFY);
for (var = varlist; var; var = var->next)
add_header(&req, var->name, ast_unescape_semicolon(var->value));
for (var = varlist; var; var = var->next) {
char buf[512];
ast_copy_string(buf, var->value, sizeof(buf));
add_header(&req, var->name, ast_unescape_semicolon(buf));
}
/* Recalculate our side, and recalculate Call ID */
ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip);
@ -17236,7 +17239,7 @@ static void clear_sip_domains(void)
/*! \brief Add realm authentication in list */
static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno)
static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, const char *configuration, int lineno)
{
char authcopy[256];
char *username=NULL, *realm=NULL, *secret=NULL, *md5secret=NULL;

@ -2847,8 +2847,10 @@ static struct skinny_device *build_device(const char *cat, struct ast_variable *
if (!(sd = ast_calloc(1, sizeof(*sd)))) {
return NULL;
} else {
char *stringp, *exten, *context, *label;
stringp = v->value;
char buf[256];
char *stringp = buf, *exten, *context, *label;
ast_copy_string(buf, v->value, sizeof(buf));
exten = strsep(&stringp, ",");
if ((context = strchr(exten, '@'))) {
*context++ = '\0';

@ -193,7 +193,7 @@ void ast_jb_destroy(struct ast_channel *chan);
*
* \return zero if the property was set to the configuration, -1 if not.
*/
int ast_jb_read_conf(struct ast_jb_conf *conf, char *varname, char *value);
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value);
/*!

@ -56,7 +56,7 @@ struct ast_ha {
void ast_free_ha(struct ast_ha *ha);
/*! \brief Append ACL entry to host access list. */
struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path, int *error);
struct ast_ha *ast_append_ha(const char *sense, const char *stuff, struct ast_ha *path, int *error);
/*! \brief Check IP address with host access list */
int ast_apply_ha(struct ast_ha *ha, struct sockaddr_in *sin);

@ -50,16 +50,18 @@ enum {
/*! \brief Structure for variables, used for configurations and for channel variables
*/
struct ast_variable {
char *name;
char *value;
const char *name;
const char *value;
struct ast_variable *next;
char *file;
int lineno;
int object; /*!< 0 for variable, 1 for object */
int blanklines; /*!< Number of blanklines following entry */
struct ast_comment *precomments;
struct ast_comment *sameline;
struct ast_comment *trailing; /*!< the last object in the list will get assigned any trailing comments when EOF is hit */
struct ast_variable *next;
char stuff[0];
};

@ -562,10 +562,10 @@ static long get_now(struct ast_jb *jb, struct timeval *tv)
}
int ast_jb_read_conf(struct ast_jb_conf *conf, char *varname, char *value)
int ast_jb_read_conf(struct ast_jb_conf *conf, const char *varname, const char *value)
{
int prefixlen = sizeof(AST_JB_CONF_PREFIX) - 1;
char *name;
const char *name;
int tmp;
if (strncasecmp(AST_JB_CONF_PREFIX, varname, prefixlen))

@ -120,7 +120,7 @@ struct ast_ha *ast_duplicate_ha_list(struct ast_ha *original)
return ret; /* Return start of list */
}
struct ast_ha *ast_append_ha(char *sense, char *stuff, struct ast_ha *path, int *error)
struct ast_ha *ast_append_ha(const char *sense, const char *stuff, struct ast_ha *path, int *error)
{
struct ast_ha *ha;
char *nm;

@ -259,14 +259,16 @@ struct ast_variable *ast_variable_new(const char *name, const char *value, const
{
struct ast_variable *variable;
int name_len = strlen(name) + 1;
if ((variable = ast_calloc(1, name_len + strlen(value) + 1 + strlen(filename) + 1 + sizeof(*variable)))) {
variable->name = variable->stuff;
variable->value = variable->stuff + name_len;
variable->file = variable->stuff + name_len + strlen(value) + 1;
strcpy(variable->name,name);
strcpy(variable->value,value);
strcpy(variable->file,filename);
int val_len = strlen(value) + 1;
int fn_len = strlen(filename) + 1;
if ((variable = ast_calloc(1, name_len + val_len + fn_len + sizeof(*variable)))) {
char *dst = variable->stuff; /* writable space starts here */
variable->name = strcpy(dst, name);
dst += name_len;
variable->value = strcpy(dst, value);
dst += fn_len;
variable->file = strcpy(dst, value);
}
return variable;
}
@ -1721,7 +1723,7 @@ static void clear_config_maps(void)
ast_mutex_unlock(&config_lock);
}
static int append_mapping(char *name, char *driver, char *database, char *table)
static int append_mapping(const char *name, const char *driver, const char *database, const char *table)
{
struct ast_config_map *map;
int length;
@ -1772,7 +1774,9 @@ int read_config_maps(void)
}
for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
stringp = v->value;
char buf[512];
ast_copy_string(buf, v->value, sizeof(buf));
stringp = buf;
driver = strsep(&stringp, ",");
if ((tmp = strchr(stringp, '\"')))

@ -594,7 +594,7 @@ int ast_get_txt(struct ast_channel *chan, const char *number, char *dst, int dst
}
/*! \brief Add enum tree to linked list */
static struct enum_search *enum_newtoplev(char *s)
static struct enum_search *enum_newtoplev(const char *s)
{
struct enum_search *tmp;

@ -174,11 +174,11 @@ AST_THREADSTORAGE(verbose_buf);
AST_THREADSTORAGE(log_buf);
#define LOG_BUF_INIT_SIZE 256
static int make_components(char *s, int lineno)
static int make_components(const char *s, int lineno)
{
char *w;
int res = 0;
char *stringp = s;
char *stringp = ast_strdupa(s);
while ((w = strsep(&stringp, ","))) {
w = ast_skip_blanks(w);
@ -204,7 +204,7 @@ static int make_components(char *s, int lineno)
return res;
}
static struct logchannel *make_logchannel(char *channel, char *components, int lineno)
static struct logchannel *make_logchannel(const char *channel, const char *components, int lineno)
{
struct logchannel *chan;
char *facility;

@ -2973,9 +2973,9 @@ static void xml_copy_escape(struct ast_str **out, const char *src, int mode)
static void xml_translate(struct ast_str **out, char *in, struct ast_variable *vars, enum output_format format)
{
struct ast_variable *v;
char *dest = NULL;
const char *dest = NULL;
char *var, *val;
char *objtype = NULL;
const char *objtype = NULL;
int in_data = 0; /* parsing data */
int inobj = 0;
int xml = (format == FORMAT_XML);

@ -88,7 +88,7 @@ char *dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid)
return os;
}
int dundi_str_to_eid(dundi_eid *eid, char *s)
int dundi_str_to_eid(dundi_eid *eid, const char *s)
{
unsigned int eid_int[6];
int x;
@ -100,7 +100,7 @@ int dundi_str_to_eid(dundi_eid *eid, char *s)
return 0;
}
int dundi_str_short_to_eid(dundi_eid *eid, char *s)
int dundi_str_short_to_eid(dundi_eid *eid, const char *s)
{
unsigned int eid_int[6];
int x;

@ -79,8 +79,8 @@ extern int dundi_ie_append(struct dundi_ie_data *ied, unsigned char ie);
extern int dundi_parse_ies(struct dundi_ies *ies, unsigned char *data, int datalen);
extern char *dundi_eid_to_str(char *s, int maxlen, dundi_eid *eid);
extern char *dundi_eid_to_str_short(char *s, int maxlen, dundi_eid *eid);
extern int dundi_str_to_eid(dundi_eid *eid, char *s);
extern int dundi_str_short_to_eid(dundi_eid *eid, char *s);
extern int dundi_str_to_eid(dundi_eid *eid, const char *s);
extern int dundi_str_short_to_eid(dundi_eid *eid, const char *s);
extern int dundi_eid_zero(dundi_eid *eid);
extern int dundi_eid_cmp(dundi_eid *eid1, dundi_eid *eid2);
extern char *dundi_flags2str(char *s, int maxlen, int flags);

@ -4219,7 +4219,7 @@ static void prune_mappings(void)
AST_LIST_UNLOCK(&peers);
}
static void append_permission(struct permissionlist *permlist, char *s, int allow)
static void append_permission(struct permissionlist *permlist, const char *s, int allow)
{
struct permission *perm;
@ -4234,7 +4234,7 @@ static void append_permission(struct permissionlist *permlist, char *s, int allo
#define MAX_OPTS 128
static void build_mapping(char *name, char *value)
static void build_mapping(const char *name, const char *value)
{
char *t, *fields[MAX_OPTS];
struct dundi_mapping *map;

@ -70,7 +70,8 @@ static int maxretries = DEFAULT_ADSI_MAX_RETRIES;
static char intro[ADSI_MAX_INTRO][20];
static int aligns[ADSI_MAX_INTRO];
static char speeddial[ADSI_MAX_SPEED_DIAL][3][20];
#define SPEEDDIAL_MAX_LEN 20
static char speeddial[ADSI_MAX_SPEED_DIAL][3][SPEEDDIAL_MAX_LEN];
static int alignment = 0;
@ -988,7 +989,7 @@ static int _ast_adsi_unload_session(struct ast_channel *chan)
return 0;
}
static int str2align(char *s)
static int str2align(const char *s)
{
if (!strncasecmp(s, "l", 1))
return ADSI_JUST_LEFT;
@ -1048,7 +1049,9 @@ static void adsi_load(void)
x = 0;
for (v = ast_variable_browse(conf, "speeddial"); v; v = v->next) {
char *stringp = v->value;
char buf[3 * SPEEDDIAL_MAX_LEN];
char *stringp = buf;
ast_copy_string(buf, v->value, sizeof(buf));
name = strsep(&stringp, ",");
sname = strsep(&stringp, ",");
if (!sname)

Loading…
Cancel
Save