]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
tweak parking bug
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 11 Apr 2008 19:41:24 +0000 (19:41 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 11 Apr 2008 19:41:24 +0000 (19:41 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8089 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_fifo/mod_fifo.c
src/mod/endpoints/mod_sofia/sofia_presence.c

index ee7ff1510c2cd3be5427f1f4d76012456de33a80..a3185af1f9dab44dde66b59f019d9fd6ecca94c7 100644 (file)
@@ -329,9 +329,7 @@ static void pres_event_handler(switch_event_t *event)
         node = create_node(node_name, 0);
     }
 
-    switch_mutex_lock(node->mutex);
     send_presence(node);
-    switch_mutex_unlock(node->mutex);
 
     switch_mutex_unlock(globals.mutex);
 
@@ -498,8 +496,9 @@ SWITCH_STANDARD_APP(fifo_function)
 
         switch_mutex_lock(node->mutex);
         node->caller_count++;
-        send_presence(node);
+
         switch_core_hash_insert(node->caller_hash, uuid, session);
+               
 
         if ((pri = switch_channel_get_variable(channel, "fifo_priority"))) {
                        p = atoi(pri);
@@ -545,6 +544,8 @@ SWITCH_STANDARD_APP(fifo_function)
                        cd.next = switch_timestamp(NULL) + cd.freq;
                }
 
+        send_presence(node);
+
                while(switch_channel_ready(channel)) {
                        switch_input_args_t args = { 0 };
                        char buf[25] = "";
@@ -566,7 +567,9 @@ SWITCH_STANDARD_APP(fifo_function)
                        if ((serviced_uuid = switch_channel_get_variable(channel, "fifo_serviced_uuid"))) {
                                break;
                        }
-                       
+
+                       switch_core_session_flush_private_events(session);
+
                        if (moh) {
                                switch_ivr_play_file(session, NULL, moh, &args);
                        } else {
@@ -592,6 +595,7 @@ SWITCH_STANDARD_APP(fifo_function)
                        }
                }
                
+               switch_core_session_flush_private_events(session);
 
                if (switch_channel_ready(channel)) {
             if (announce) {
@@ -621,9 +625,10 @@ SWITCH_STANDARD_APP(fifo_function)
             switch_mutex_lock(node->mutex);
                        node_remove_uuid(node, uuid);
             node->caller_count--;
-            send_presence(node);
             switch_core_hash_delete(node->caller_hash, uuid);
             switch_mutex_unlock(node->mutex);
+            send_presence(node);
+                       
         }
         
                if (cd.do_orbit && cd.orbit_exten) {
@@ -847,6 +852,7 @@ SWITCH_STANDARD_APP(fifo_function)
                                
                                switch_channel_set_variable(other_channel, "fifo_serviced_by", my_id);
                                switch_channel_set_variable(other_channel, "fifo_serviced_uuid", switch_core_session_get_uuid(session));
+
                                switch_channel_set_flag(other_channel, CF_BREAK);
 
                                while (switch_channel_ready(channel) && switch_channel_ready(other_channel) && switch_channel_test_flag(other_channel, CF_TAGGED)) {
@@ -883,9 +889,9 @@ SWITCH_STANDARD_APP(fifo_function)
                 switch_channel_set_variable(other_channel, "fifo_status", "TALKING");
                 switch_channel_set_variable(other_channel, "fifo_timestamp", date);
                 switch_channel_set_variable(other_channel, "fifo_target", switch_core_session_get_uuid(session));
-                switch_mutex_lock(node->mutex);
+
                 send_presence(node);
-                switch_mutex_unlock(node->mutex);
+
 
                                if (record_template) {
                                        expanded = switch_channel_expand_variables(other_channel, record_template);
@@ -912,10 +918,12 @@ SWITCH_STANDARD_APP(fifo_function)
                 
                 switch_mutex_lock(node->mutex);
                 node->caller_count--;
-                send_presence(node);
                 switch_core_hash_delete(node->caller_hash, uuid);
                 switch_mutex_unlock(node->mutex);
+                send_presence(node);
                 switch_core_session_rwunlock(other_session);
+
+
                 if (!do_wait) {
                     done = 1;
                 }
index edd62b6e3187bad2b75c92ac15e742e777af754b..14744b70458f12789c34f7b6aeb31dd3b529ca6f 100644 (file)
@@ -46,6 +46,7 @@ struct presence_helper {
        sofia_profile_t *profile;
        switch_event_t *event;
        switch_stream_handle_t stream;
+       char last_uuid[512];
 };
 
 switch_status_t sofia_presence_chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint)
@@ -472,6 +473,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                        if (!switch_strlen_zero((char *)helper.stream.data)) {
                                char *this = (char *)helper.stream.data;
                                char *next = NULL;
+                               char *last = NULL;
                                
                                do {
                                        if ((next = strchr(this, ';'))) {
@@ -481,8 +483,9 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                                }
                                        }
 
-                                       if (!switch_strlen_zero(this)) {
+                                       if (!switch_strlen_zero(this) && (!last || strcmp(last, this))) {
                                                sofia_glue_execute_sql(profile, &this, SWITCH_FALSE);
+                                               last = this;
                                        }
                                        this = next;
                                } while (this);
@@ -934,8 +937,10 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
                        ct = "application/dialog-info+xml";
                }
                
-               if (!switch_strlen_zero(astate) && !switch_strlen_zero(uuid) && helper && helper->stream.data) {
-                       helper->stream.write_function(&helper->stream, "update sip_dialogs set state='%s' where uuid='%s';\n", astate, uuid);
+               if (!switch_strlen_zero(astate) && !switch_strlen_zero(uuid) && helper && helper->stream.data && strcmp(helper->last_uuid, uuid)) {
+                       helper->stream.write_function(&helper->stream, "update sip_dialogs set state='%s' where uuid='%s';", astate, uuid);
+                       
+                       switch_copy_string(helper->last_uuid, uuid, sizeof(helper->last_uuid));
                }