[Freeswitch-svn] [commit] r5035 - in freeswitch/trunk/src: . include mod/applications/mod_conference mod/applications/mod_enum mod/dialplans/mod_dialplan_xml mod/endpoints/mod_sofia
Freeswitch SVN
anthm at freeswitch.org
Sat Apr 28 17:48:03 EDT 2007
Author: anthm
Date: Sat Apr 28 17:48:03 2007
New Revision: 5035
Modified:
freeswitch/trunk/src/include/switch_channel.h
freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c
freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
freeswitch/trunk/src/switch_channel.c
freeswitch/trunk/src/switch_ivr.c
freeswitch/trunk/src/switch_ivr_originate.c
Log:
add locking to vars
Modified: freeswitch/trunk/src/include/switch_channel.h
==============================================================================
--- freeswitch/trunk/src/include/switch_channel.h (original)
+++ freeswitch/trunk/src/include/switch_channel.h Sat Apr 28 17:48:03 2007
@@ -228,6 +228,7 @@
* @remark Use switch_hash_next and switch_hash_this with this function to iterate all the channel variables
*/
SWITCH_DECLARE(switch_hash_index_t *) switch_channel_variable_first(switch_channel_t *channel, switch_memory_pool_t *pool);
+SWITCH_DECLARE(void) switch_channel_variable_last(switch_channel_t *channel);
/*!
\brief Assign a caller extension to a given channel
Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c Sat Apr 28 17:48:03 2007
@@ -1025,10 +1025,6 @@
if (member->energy_level > 3000) {
member->energy_level = 3000;
}
- switch_mutex_unlock(member->flag_mutex);
-
- snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
- conference_member_say(member, msg, 0);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -1040,6 +1036,12 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->energy_level);
switch_event_fire(&event);
}
+ switch_mutex_unlock(member->flag_mutex);
+
+ snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
+ conference_member_say(member, msg, 0);
+
+
}
}
@@ -1051,10 +1053,6 @@
switch_mutex_lock(member->flag_mutex);
member->energy_level = member->conference->energy_level;
- switch_mutex_unlock(member->flag_mutex);
-
- snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
- conference_member_say(member, msg, 0);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -1066,6 +1064,11 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->energy_level);
switch_event_fire(&event);
}
+ switch_mutex_unlock(member->flag_mutex);
+
+ snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
+ conference_member_say(member, msg, 0);
+
}
}
@@ -1080,10 +1083,6 @@
if (member->energy_level < 0) {
member->energy_level = 0;
}
- switch_mutex_unlock(member->flag_mutex);
-
- snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
- conference_member_say(member, msg, 0);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -1095,6 +1094,13 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->energy_level);
switch_event_fire(&event);
}
+ switch_mutex_unlock(member->flag_mutex);
+
+ snprintf(msg, sizeof(msg), "Energy level %d", member->energy_level);
+ conference_member_say(member, msg, 0);
+
+
+
}
}
@@ -1107,10 +1113,7 @@
switch_mutex_lock(member->flag_mutex);
member->volume_out_level++;
switch_normalize_volume(member->volume_out_level);
- switch_mutex_unlock(member->flag_mutex);
- snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
- conference_member_say(member, msg, 0);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -1122,6 +1125,12 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_out_level);
switch_event_fire(&event);
}
+ switch_mutex_unlock(member->flag_mutex);
+
+
+ snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
+ conference_member_say(member, msg, 0);
+
}
}
@@ -1133,10 +1142,7 @@
switch_mutex_lock(member->flag_mutex);
member->volume_out_level = 0;
- switch_mutex_unlock(member->flag_mutex);
- snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
- conference_member_say(member, msg, 0);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -1148,6 +1154,13 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_out_level);
switch_event_fire(&event);
}
+ switch_mutex_unlock(member->flag_mutex);
+
+
+ snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
+ conference_member_say(member, msg, 0);
+
+
}
}
@@ -1160,10 +1173,6 @@
switch_mutex_lock(member->flag_mutex);
member->volume_out_level--;
switch_normalize_volume(member->volume_out_level);
- switch_mutex_unlock(member->flag_mutex);
-
- snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
- conference_member_say(member, msg, 0);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -1175,6 +1184,12 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_out_level);
switch_event_fire(&event);
}
+ switch_mutex_unlock(member->flag_mutex);
+
+ snprintf(msg, sizeof(msg), "Volume level %d", member->volume_out_level);
+ conference_member_say(member, msg, 0);
+
+
}
}
@@ -1187,10 +1202,7 @@
switch_mutex_lock(member->flag_mutex);
member->volume_in_level++;
switch_normalize_volume(member->volume_in_level);
- switch_mutex_unlock(member->flag_mutex);
- snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
- conference_member_say(member, msg, 0);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -1202,6 +1214,14 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_in_level);
switch_event_fire(&event);
}
+ switch_mutex_unlock(member->flag_mutex);
+
+
+ snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
+ conference_member_say(member, msg, 0);
+
+
+
}
}
@@ -1213,10 +1233,6 @@
switch_mutex_lock(member->flag_mutex);
member->volume_in_level = 0;
- switch_mutex_unlock(member->flag_mutex);
-
- snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
- conference_member_say(member, msg, 0);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -1228,6 +1244,13 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_in_level);
switch_event_fire(&event);
}
+ switch_mutex_unlock(member->flag_mutex);
+
+ snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
+ conference_member_say(member, msg, 0);
+
+
+
}
}
@@ -1240,10 +1263,7 @@
switch_mutex_lock(member->flag_mutex);
member->volume_in_level--;
switch_normalize_volume(member->volume_in_level);
- switch_mutex_unlock(member->flag_mutex);
- snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
- conference_member_say(member, msg, 0);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) {
switch_channel_t *channel = switch_core_session_get_channel(member->session);
@@ -1255,6 +1275,13 @@
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "New-Level", "%d", member->volume_in_level);
switch_event_fire(&event);
}
+ switch_mutex_unlock(member->flag_mutex);
+
+
+ snprintf(msg, sizeof(msg), "Gain level %d", member->volume_in_level);
+ conference_member_say(member, msg, 0);
+
+
}
}
Modified: freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_enum/mod_enum.c Sat Apr 28 17:48:03 2007
@@ -591,11 +591,14 @@
void *vval;
const void *vvar;
- for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
- switch_hash_this(hi, &vvar, NULL, &vval);
- if (vvar && !strncmp(vvar, "enum_", 5)) {
- switch_channel_set_variable(channel, (char *) vvar, NULL);
+ if ((hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)))) {
+ for (; hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &vvar, NULL, &vval);
+ if (vvar && !strncmp(vvar, "enum_", 5)) {
+ switch_channel_set_variable(channel, (char *) vvar, NULL);
+ }
}
+ switch_channel_variable_last(channel);
}
for (rtp = globals.route_order; rtp; rtp = rtp->next) {
Modified: freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
==============================================================================
--- freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c (original)
+++ freeswitch/trunk/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c Sat Apr 28 17:48:03 2007
@@ -251,28 +251,30 @@
stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
}
+ if ((hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)))) {
+ for (; hi; hi = switch_hash_next(hi)) {
+ void *val;
+ const void *var;
+ switch_hash_this(hi, &var, NULL, &val);
+
+ new_len = (strlen((char *) var) * 3) + 1;
+ if (encode_len < new_len) {
+ char *tmp;
+
+ encode_len = new_len;
+
+ if (!(tmp = realloc(encode_buf, encode_len))) {
+ goto done;
+ }
- for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
- void *val;
- const void *var;
- switch_hash_this(hi, &var, NULL, &val);
-
- new_len = (strlen((char *) var) * 3) + 1;
- if (encode_len < new_len) {
- char *tmp;
-
- encode_len = new_len;
-
- if (!(tmp = realloc(encode_buf, encode_len))) {
- goto done;
+ encode_buf = tmp;
}
- encode_buf = tmp;
- }
-
- switch_url_encode((char *) val, encode_buf, encode_len - 1);
- stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
+ switch_url_encode((char *) val, encode_buf, encode_len - 1);
+ stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
+ }
+ switch_channel_variable_last(channel);
}
e = (char *) stream.data + (strlen((char *) stream.data) - 1);
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Sat Apr 28 17:48:03 2007
@@ -570,17 +570,20 @@
SWITCH_STANDARD_STREAM(stream);
- for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(tech_pvt->session)); hi; hi = switch_hash_next(hi)) {
- switch_hash_this(hi, &vvar, NULL, &vval);
- if (vvar && vval) {
- const char *name = vvar;
- char *value = (char *) vval;
-
- if (!strncasecmp(name, SOFIA_SIP_HEADER_PREFIX, strlen(SOFIA_SIP_HEADER_PREFIX))) {
- const char *hname = name + strlen(SOFIA_SIP_HEADER_PREFIX);
- stream.write_function(&stream, "%s: %s\r\n", hname, value);
+ if ((hi = switch_channel_variable_first(channel, switch_core_session_get_pool(tech_pvt->session)))) {
+ for (; hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &vvar, NULL, &vval);
+ if (vvar && vval) {
+ const char *name = vvar;
+ char *value = (char *) vval;
+
+ if (!strncasecmp(name, SOFIA_SIP_HEADER_PREFIX, strlen(SOFIA_SIP_HEADER_PREFIX))) {
+ const char *hname = name + strlen(SOFIA_SIP_HEADER_PREFIX);
+ stream.write_function(&stream, "%s: %s\r\n", hname, value);
+ }
}
}
+ switch_channel_variable_last(channel);
}
if (stream.data) {
Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c (original)
+++ freeswitch/trunk/src/switch_channel.c Sat Apr 28 17:48:03 2007
@@ -115,6 +115,7 @@
switch_hash_t *variables;
switch_hash_t *private_hash;
switch_call_cause_t hangup_cause;
+ int vi;
};
@@ -306,6 +307,7 @@
char *v = NULL;
assert(channel != NULL);
+ switch_mutex_lock(channel->profile_mutex);
if (!(v = switch_core_hash_find(channel->variables, varname))) {
if (!channel->caller_profile || !(v = switch_caller_get_field_by_name(channel->caller_profile, varname))) {
if (!strcmp(varname, "base_dir")) {
@@ -314,27 +316,50 @@
v = switch_core_get_variable(varname);
}
}
+ switch_mutex_unlock(channel->profile_mutex);
return v;
}
+SWITCH_DECLARE(void) switch_channel_variable_last(switch_channel_t *channel)
+{
+ assert(channel != NULL);
+ if (channel->vi) {
+ switch_mutex_unlock(channel->profile_mutex);
+ }
+}
+
SWITCH_DECLARE(switch_hash_index_t *) switch_channel_variable_first(switch_channel_t *channel, switch_memory_pool_t *pool)
{
+ switch_hash_index_t *hi;
+
assert(channel != NULL);
- return switch_hash_first(pool, channel->variables);
+
+ if ((hi = switch_hash_first(pool, channel->variables))) {
+ switch_mutex_lock(channel->profile_mutex);
+ channel->vi = 1;
+ }
+
+ return hi;
}
SWITCH_DECLARE(switch_status_t) switch_channel_set_private(switch_channel_t *channel, char *key, void *private_info)
{
assert(channel != NULL);
+ switch_mutex_lock(channel->profile_mutex);
switch_core_hash_insert_dup(channel->private_hash, switch_core_session_strdup(channel->session, key), private_info);
+ switch_mutex_unlock(channel->profile_mutex);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(void *) switch_channel_get_private(switch_channel_t *channel, char *key)
{
assert(channel != NULL);
- return switch_core_hash_find(channel->private_hash, key);
+ void *val;
+ switch_mutex_lock(channel->profile_mutex);
+ val = switch_core_hash_find(channel->private_hash, key);
+ switch_mutex_unlock(channel->profile_mutex);
+ return val;
}
SWITCH_DECLARE(switch_status_t) switch_channel_set_name(switch_channel_t *channel, char *name)
@@ -361,12 +386,14 @@
assert(channel != NULL);
if (varname) {
+ switch_mutex_lock(channel->profile_mutex);
switch_core_hash_delete(channel->variables, varname);
if (!switch_strlen_zero(value)) {
switch_core_hash_insert_dup(channel->variables, varname, switch_core_session_strdup(channel->session, value));
} else {
switch_core_hash_delete(channel->variables, varname);
}
+ switch_mutex_unlock(channel->profile_mutex);
return SWITCH_STATUS_SUCCESS;
}
@@ -378,12 +405,14 @@
assert(channel != NULL);
if (varname) {
+ switch_mutex_lock(channel->profile_mutex);
switch_core_hash_delete(channel->variables, varname);
if (!switch_strlen_zero(value)) {
switch_core_hash_insert_dup(channel->variables, varname, value);
} else {
switch_core_hash_delete(channel->variables, varname);
}
+ switch_mutex_unlock(channel->profile_mutex);
return SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c (original)
+++ freeswitch/trunk/src/switch_ivr.c Sat Apr 28 17:48:03 2007
@@ -900,11 +900,14 @@
void *vval;
const void *vvar;
- for (hi = switch_channel_variable_first(chana, switch_core_session_get_pool(sessa)); hi; hi = switch_hash_next(hi)) {
- switch_hash_this(hi, &vvar, NULL, &vval);
- if (vvar && vval && (!prefix || (var && !strncmp((char *) vvar, var, strlen(var))))) {
- switch_channel_set_variable(chanb, (char *) vvar, (char *) vval);
+ if ((hi = switch_channel_variable_first(chana, switch_core_session_get_pool(sessa)))) {
+ for (; hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &vvar, NULL, &vval);
+ if (vvar && vval && (!prefix || (var && !strncmp((char *) vvar, var, strlen(var))))) {
+ switch_channel_set_variable(chanb, (char *) vvar, (char *) vval);
+ }
}
+ switch_channel_variable_last(chana);
}
}
@@ -1260,20 +1263,23 @@
}
}
- for (hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
- switch_hash_this(hi, &vvar, NULL, &vval);
- if (vvar && vval) {
- if ((variable = switch_xml_add_child_d(variables, (char *) vvar, v_off++))) {
- char *data;
- char *value = (char *) vval;
- switch_size_t dlen = strlen(value) * 3;
-
- if ((data = switch_core_session_alloc(session, dlen))) {
- switch_url_encode(value, data, dlen);
- switch_xml_set_txt_d(variable, data);
+ if (((hi = switch_channel_variable_first(channel, switch_core_session_get_pool(session))))) {
+ for (; hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &vvar, NULL, &vval);
+ if (vvar && vval) {
+ if ((variable = switch_xml_add_child_d(variables, (char *) vvar, v_off++))) {
+ char *data;
+ char *value = (char *) vval;
+ switch_size_t dlen = strlen(value) * 3;
+
+ if ((data = switch_core_session_alloc(session, dlen))) {
+ switch_url_encode(value, data, dlen);
+ switch_xml_set_txt_d(variable, data);
+ }
}
}
}
+ switch_channel_variable_last(channel);
}
caller_profile = switch_channel_get_caller_profile(channel);
Modified: freeswitch/trunk/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_originate.c (original)
+++ freeswitch/trunk/src/switch_ivr_originate.c Sat Apr 28 17:48:03 2007
@@ -323,11 +323,14 @@
assert(caller_channel != NULL);
/* Copy all the channel variables into the event */
- for (hi = switch_channel_variable_first(caller_channel, switch_core_session_get_pool(session)); hi; hi = switch_hash_next(hi)) {
- switch_hash_this(hi, &vvar, NULL, &vval);
- if (vvar && vval) {
- switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, (void *) vvar, "%s", (char *) vval);
+ if ((hi = switch_channel_variable_first(caller_channel, switch_core_session_get_pool(session)))) {
+ for (; hi; hi = switch_hash_next(hi)) {
+ switch_hash_this(hi, &vvar, NULL, &vval);
+ if (vvar && vval) {
+ switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, (void *) vvar, "%s", (char *) vval);
+ }
}
+ switch_channel_variable_last(caller_channel);
}
}
More information about the Freeswitch-svn
mailing list