]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
This set of changes is to make some callerID handling thread-safe.
authorRussell Bryant <russell@russellbryant.com>
Thu, 29 Nov 2007 00:20:34 +0000 (00:20 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 29 Nov 2007 00:20:34 +0000 (00:20 +0000)
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/branches/1.4@90145 65c4cc65-6c06-0410-ace0-fbb531ad65f3

funcs/func_callerid.c
include/asterisk/channel.h
main/channel.c

index be3026325b127caa9aec705232be200fc432856e..9809f4d085b360d836e1e87022cfc96dedeaa93a 100644 (file)
@@ -64,6 +64,8 @@ static int callerid_read(struct ast_channel *chan, 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, ""),
@@ -92,6 +94,8 @@ static int callerid_read(struct ast_channel *chan, char *cmd, char *data,
                } else {
                        ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
                }
+
+               ast_channel_unlock(chan);
        }
 
        return 0;
@@ -107,8 +111,8 @@ static int callerid_write(struct ast_channel *chan, char *cmd, char *data,
                char name[256];
                char num[256];
 
-               if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num)))
-                       ast_set_callerid(chan, num, name, num);
+       if (!ast_callerid_split(value, name, sizeof(name), num, sizeof(num)))
+               ast_set_callerid(chan, num, name, num);
        } else if (!strncasecmp("name", data, 4)) {
                ast_set_callerid(chan, NULL, value, NULL);
        } else if (!strncasecmp("num", data, 3) ||
@@ -117,15 +121,17 @@ static int callerid_write(struct ast_channel *chan, char *cmd, char *data,
        } else if (!strncasecmp("ani", data, 3)) {
                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)
                        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)
                        free(chan->cid.cid_rdnis);
                chan->cid.cid_rdnis = ast_strdup(value);
+               ast_channel_unlock(chan);
        } else {
                ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
        }
index 5a704199e338aff3bfe8bea5199c678f8e055240..a05975a5658758b0ba54ef143136387556a39f50 100644 (file)
@@ -1109,6 +1109,9 @@ int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen,
 /*! Deactive an active generator */
 void ast_deactivate_generator(struct ast_channel *chan);
 
+/*!
+ * \note The channel does not need to be locked before calling this function.
+ */
 void ast_set_callerid(struct ast_channel *chan, const char *cidnum, const char *cidname, const char *ani);
 
 
index ce9f2ce7489b2102d60917681cf820f63f2f9e66..3c4af0f93f86d448abf0589ad22e8c14031f7006 100644 (file)
@@ -3874,6 +3874,8 @@ int ast_do_masquerade(struct ast_channel *original)
 
 void ast_set_callerid(struct ast_channel *chan, const char *callerid, const char *calleridname, const char *ani)
 {
+       ast_channel_lock(chan);
+
        if (callerid) {
                if (chan->cid.cid_num)
                        free(chan->cid.cid_num);
@@ -3904,6 +3906,8 @@ void ast_set_callerid(struct ast_channel *chan, const char *callerid, 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)