]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update pidf relates presence code
authorBrian West <brian@freeswitch.org>
Wed, 28 Jul 2010 03:08:47 +0000 (22:08 -0500)
committerBrian West <brian@freeswitch.org>
Wed, 28 Jul 2010 03:08:58 +0000 (22:08 -0500)
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index 347bd2a53511fa581e778cffbe98f568ebe07e37..1ea4bebdd36ab63b4e40593f9910c33237aa8efc 100644 (file)
@@ -55,6 +55,7 @@ static void sync_sla(sofia_profile_t *profile, const char *to_user, const char *
 struct resub_helper {
        sofia_profile_t *profile;
        switch_event_t *event;
+       int rowcount;
 };
 
 struct presence_helper {
@@ -549,7 +550,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                                                         "(sip_registrations.sip_host='%q' or sip_registrations.presence_hosts like '%%%q%%')",
                                                                         probe_host, probe_euser, probe_host, probe_host);
                                switch_assert(sql);
-
+                               
 
                                if (mod_sofia_globals.debug_presence > 0) {
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s START_PRESENCE_PROBE_SQL\n", profile->name);
@@ -565,6 +566,18 @@ static void actual_sofia_presence_event_handler(switch_event_t *event)
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s END_PRESENCE_PROBE_SQL\n\n", profile->name);
                                }
 
+                               if (!h.rowcount) {
+                                       switch_event_t *sevent;
+                                       if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+                                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+                                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
+                                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", probe_euser, probe_host);
+                                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "status", "Unregistered");
+                                               switch_event_fire(&sevent);
+                                       }                                       
+                               }
+
+
                                sofia_glue_release_profile(profile);
                                switch_safe_free(sql);
                        }
@@ -953,6 +966,7 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
                switch_event_fire(&event);
        }
 
+       h->rowcount++;
        return 0;
 }
 
@@ -1018,11 +1032,17 @@ static char *gen_pidf(char *user_agent, char *id, char *url, char *open, char *r
        } else {
                *ct = "application/pidf+xml";
 
-               if (!strncasecmp(status, "Registered(", 11)) {
+               if (!strncasecmp(status, "Registered", 10)) {
                        prpid = NULL;
                        status = "Available";
                }
 
+
+               if (!strcasecmp(status, "Unregistered")) {
+                       prpid = NULL;
+                       open = "closed";
+               }
+               
                if (prpid) {
                        ret = switch_mprintf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> \n"
                                                                 "<presence xmlns='urn:ietf:params:xml:ns:pidf' \n"
@@ -1346,8 +1366,6 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
                                open = "closed";
                        }
 
-                       printf("WTF %s\n%s\n", ct, content);
-
                        if (content) {
                                pl = strdup(content);
                        } else {
@@ -1363,8 +1381,6 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
                        open = "closed";
                }
 
-               printf("WTF2 %s\n%s\n", ct, content);
-
                if (content) {
                        pl = strdup(content);
                } else {
@@ -1897,36 +1913,6 @@ void sofia_presence_handle_sip_i_subscribe(int status,
 
                switch_snprintf(exp_delta_str, sizeof(exp_delta_str), "%ld", exp_delta);
 
-               if (to_user && (strstr(to_user, "ext+") || strstr(to_user, "user+"))) {
-                       char protocol[80];
-                       char *p;
-
-                       switch_copy_string(protocol, to_user, sizeof(protocol));
-                       if ((p = strchr(protocol, '+'))) {
-                               *p = '\0';
-                       }
-
-                       if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
-                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
-                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
-                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
-                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "rpid", "active");
-                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
-                               switch_event_fire(&sevent);
-                       }
-
-               } else {
-                       if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
-                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
-                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
-                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
-                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, to_host);
-                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event);
-                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
-                               switch_event_fire(&sevent);
-                       }
-               }
-
                if (to_user && strchr(to_user, '+')) {
                        char *h;
                        if ((proto = (d_user = strdup(to_user)))) {
@@ -2174,19 +2160,42 @@ void sofia_presence_handle_sip_i_subscribe(int status,
 
                                switch_safe_free(sql);
                        }
-               } else {
-                       if ((sql = switch_mprintf("select proto,sip_user,'%q',sub_to_user,sub_to_host,event,contact,call_id,full_from,"
-                                                                         "full_via,expires,user_agent,accept,profile_name,network_ip"
-                                                                         " from sip_subscriptions where expires > -1 and event='%s' and sip_user='%q' "
-                                                                         "and (sip_host='%q' or presence_hosts like '%%%q%%')", to_host, event, to_user, to_host, to_host))) {
-                               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_presence_sub_callback, profile);
-
-                               switch_safe_free(sql);
-                       }                       
                }
 
          end:
 
+               if (to_user && (strstr(to_user, "ext+") || strstr(to_user, "user+"))) {
+                       char protocol[80];
+                       char *p;
+
+                       switch_copy_string(protocol, to_user, sizeof(protocol));
+                       if ((p = strchr(protocol, '+'))) {
+                               *p = '\0';
+                       }
+
+                       if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
+                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
+                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
+                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "rpid", "active");
+                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "status", "Click To Call");
+                               switch_event_fire(&sevent);
+                       }
+
+               } else {
+                       if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
+                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", from_user, from_host);
+                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, to_host);
+                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto-specific-event-name", event);
+                               switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "expires", exp_delta_str);
+                               switch_event_fire(&sevent);
+                       }
+               }
+
+
+
                if (event) {
                        su_free(profile->home, event);
                }
index 32f22081b317191dfea7526b0e259ab7e51fa41e..2e1b1273a02058db3dc872fedb1d4ce8aaeab9c5 100644 (file)
@@ -1124,7 +1124,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                        sql = switch_mprintf("delete from sip_registrations where sip_user='%q' and sip_host='%q'", to_user, reg_host);
                }
                switch_mutex_lock(profile->ireg_mutex);
-               sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+               sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
 
                switch_find_local_ip(guess_ip4, sizeof(guess_ip4), NULL, AF_INET);
                sql = switch_mprintf("insert into sip_registrations "
@@ -1138,7 +1138,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                                         mwi_user, mwi_host, guess_ip4, mod_sofia_globals.hostname);
                                                         
                if (sql) {
-                       sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
+                       sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
                }
 
                switch_mutex_unlock(profile->ireg_mutex);
@@ -1204,7 +1204,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
 
        } else {
 
-               if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
+               if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "rpid", rpid);
                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "login", profile->url);
@@ -1287,6 +1287,17 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                                        switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "VM-Call-ID", call_id);
                                }
                        }
+
+
+                       if (switch_event_create(&s_event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "login", profile->name);
+                               switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, reg_host);
+                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "rpid", "closed");
+                               switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "status", "Registered");
+                               switch_event_fire(&s_event);
+                       }                                       
+
                } else {
                        if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_UNREGISTER) == SWITCH_STATUS_SUCCESS) {
                                switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "profile-name", profile->name);