]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
keep presence up to date
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 27 Apr 2009 17:31:34 +0000 (17:31 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 27 Apr 2009 17:31:34 +0000 (17:31 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13166 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_dptools/mod_dptools.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/switch_core_state_machine.c

index cd145333c82d15a60e46c0b46568418d63b772ec..4b11e7fdbd6c06257595e9ad5597ab08a543ef34 100644 (file)
@@ -1114,7 +1114,7 @@ SWITCH_STANDARD_API(presence_api_function)
                        goto error;
                }
 
-               if (argc != need) {
+               if (argc < need) {
                        goto error;
                }
 
@@ -1122,12 +1122,19 @@ SWITCH_STANDARD_API(presence_api_function)
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", "dp");
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", __FILE__);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "from", argv[1]);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", argv[2]);
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", argv[3]);
                        if (type == SWITCH_EVENT_PRESENCE_IN) {
-                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", argv[2]);
-                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", argv[3]);
+                               if (!strncasecmp(argv[3], "cs_", 3) || switch_stristr("hangup", argv[3])) {
+                                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-state", "CS_HANGUP");
+                                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "CS_HANGUP");
+                               }
+                       } else {
+                               switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "status", "CS_HANGUP");
                        }
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event_type", "presence");
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "alt_event_type", "dialog");
+                       switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_count", "%d", 0);
                        switch_event_fire(&event);
                }
                stream->write_function(stream, "Event Sent");
index ac49eccc99ac7d9f3e24981295bcc3ce2074c47c..92414688b99c4097b121852bbaf1baa18829f8b9 100644 (file)
@@ -634,11 +634,15 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                                                  event->event_id == SWITCH_EVENT_PRESENCE_IN ? "IN" : "OUT", profile->name);
                        }
 
-                       if (mod_sofia_globals.debug_presence > 1) {
+                       if (mod_sofia_globals.debug_presence) {
                                char *buf;
                                switch_event_serialize(event, &buf, SWITCH_FALSE);
                                switch_assert(buf);
-                               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DUMP PRESENCE SQL:\n%s\nEVENT DUMP:\n%s\n", sql, buf);
+                               if (mod_sofia_globals.debug_presence > 1) {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DUMP PRESENCE SQL:\n%s\nEVENT DUMP:\n%s\n", sql, buf);
+                               } else {
+                                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "EVENT DUMP:\n%s\n", buf);
+                               }
                                free(buf);
                        }
 
@@ -946,16 +950,18 @@ static char *translate_rpid(char *in)
 
 static char *gen_pidf(char *user_agent, char *id, char *url, char *open, char *rpid, char *prpid, char *status, const char **ct)
 {
+       char *ret = NULL;
+
        if (switch_stristr("polycom", user_agent)) {
                *ct = "application/xpidf+xml";
-
+               
                /* of course!, lets make a big deal over dashes. Now the stupidity is complete. */
 
                if (!strcmp(prpid, "on-the-phone")) {
                        prpid = "onthephone";
                }
 
-               return switch_mprintf(
+               ret = switch_mprintf(
                                                          "<?xml version=\"1.0\"?>\n"
                                                          "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"
                                                          "<presence>\n"
@@ -973,7 +979,7 @@ static char *gen_pidf(char *user_agent, char *id, char *url, char *open, char *r
                                                          );
        } else {
                *ct = "application/pidf+xml";
-               return switch_mprintf(
+               ret = switch_mprintf(
                                                          "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n"
                                                          "<presence xmlns='urn:ietf:params:xml:ns:pidf' \n"
                                                          "xmlns:dm='urn:ietf:params:xml:ns:pidf:data-model' \n"
@@ -993,6 +999,9 @@ static char *gen_pidf(char *user_agent, char *id, char *url, char *open, char *r
                                                          " </dm:person>\n"
                                                          "</presence>", id, open, prpid, status);
        }
+
+
+       return ret;
 }
 
 static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames)
@@ -1305,6 +1314,12 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
                }
        }
 
+       if (mod_sofia_globals.debug_presence > 0 && pl) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "send payload:\n%s\n", pl);
+       }
+
+
+
        nua_notify(nh, 
                           TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
                           SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
index 05ba48101cdfafbe90a7692fa15327f36038948c..603e3fd6b5e0f5795a0ccb82ce590620386ee64d 100644 (file)
@@ -443,7 +443,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
                                        
                                        switch_channel_set_variable(session->channel, "hangup_cause", switch_channel_cause2str(cause));
                                        switch_channel_set_variable_printf(session->channel, "hangup_cause_q850", "%d", cause_q850);
-                                       switch_channel_presence(session->channel, "unavailable", switch_channel_cause2str(cause), NULL);
+                                       switch_channel_presence(session->channel, "unknown", switch_channel_cause2str(cause), NULL);
                                        
                                        switch_channel_set_timestamps(session->channel);