From 53a5f2284963bd60a912f332d379c6c7fc3e06f3 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Thu, 29 Nov 2007 00:28:10 +0000 Subject: [PATCH] Merged revisions 90145 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r90145 | russell | 2007-11-28 18:20:34 -0600 (Wed, 28 Nov 2007) | 5 lines This set of changes is to make some callerID handling thread-safe. The ast_set_callerid() function needed to lock the channel. Also, the handlers for the CALLERID() dialplan function needed to lock the channel when reading or writing callerid values directly on the channel structure. ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@90146 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- funcs/func_callerid.c | 10 ++++++++-- include/asterisk/channel.h | 6 +++++- main/channel.c | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/funcs/func_callerid.c b/funcs/func_callerid.c index e53097f3b4..9dfe0d8c7c 100644 --- a/funcs/func_callerid.c +++ b/funcs/func_callerid.c @@ -72,6 +72,8 @@ static int callerid_read(struct ast_channel *chan, const char *cmd, char *data, ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); } } else { + ast_channel_lock(chan); + if (!strncasecmp("all", data, 3)) { snprintf(buf, len, "\"%s\" <%s>", S_OR(chan->cid.cid_name, ""), @@ -105,6 +107,8 @@ static int callerid_read(struct ast_channel *chan, const char *cmd, char *data, } else { ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); } + + ast_channel_unlock(chan); } return 0; @@ -133,15 +137,17 @@ static int callerid_write(struct ast_channel *chan, const char *cmd, char *data, } else ast_set_callerid(chan, NULL, NULL, value); } else if (!strncasecmp("dnid", data, 4)) { - /* do we need to lock chan here? */ + ast_channel_lock(chan); if (chan->cid.cid_dnid) ast_free(chan->cid.cid_dnid); chan->cid.cid_dnid = ast_strdup(value); + ast_channel_unlock(chan); } else if (!strncasecmp("rdnis", data, 5)) { - /* do we need to lock chan here? */ + ast_channel_lock(chan); if (chan->cid.cid_rdnis) ast_free(chan->cid.cid_rdnis); chan->cid.cid_rdnis = ast_strdup(value); + ast_channel_unlock(chan); } else if (!strncasecmp("pres", data, 4)) { int i; char *s, *val; diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index ad4e735b88..4bf33d7bd1 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -1309,7 +1309,11 @@ int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, /*! Deactivate an active generator */ void ast_deactivate_generator(struct ast_channel *chan); -/*! Set caller ID number, name and ANI */ +/*! + * \brief Set caller ID number, name and ANI + * + * \note The channel does not need to be locked before calling this function. + */ void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani); /*! Set the file descriptor on the channel */ diff --git a/main/channel.c b/main/channel.c index 0dd937c1e2..219485939e 100644 --- a/main/channel.c +++ b/main/channel.c @@ -3758,6 +3758,8 @@ int ast_do_masquerade(struct ast_channel *original) void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani) { + ast_channel_lock(chan); + if (cid_num) { if (chan->cid.cid_num) ast_free(chan->cid.cid_num); @@ -3788,6 +3790,8 @@ void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char chan->cid.cid_pres, ast_describe_caller_presentation(chan->cid.cid_pres) ); + + ast_channel_unlock(chan); } int ast_setstate(struct ast_channel *chan, enum ast_channel_state state)