]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
presence crap
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 24 Oct 2007 23:20:47 +0000 (23:20 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 24 Oct 2007 23:20:47 +0000 (23:20 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6048 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_conference/mod_conference.c
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c
src/switch_utils.c

index 0f8c15221e87e2a351ab58554f44a0f2b8bba1cd..b8215a84ff44585ea403c7d736c58b1bda5a7a42 100644 (file)
@@ -4424,6 +4424,7 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
        } else {
                switch_copy_string(name, to, sizeof(name));
        }
+       
 
        if (!(conference = (conference_obj_t *) switch_core_hash_find(globals.conference_hash, name))) {
                ci->chat_send(CONF_CHAT_PROTO, to, hint && strchr(hint, '/') ? hint : from, "", "Conference not active.", NULL);
@@ -4433,18 +4434,21 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
        SWITCH_STANDARD_STREAM(stream);
 
        if (body != NULL && (lbuf = strdup(body))) {
-               int argc;
-               char *argv[25];
-
-               memset(argv, 0, sizeof(argv));
-               argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+               //int argc;
+               //char *argv[25];
 
+               //memset(argv, 0, sizeof(argv));
+               //argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+               
                /* try to find a command to execute */
-               if (argc) {
+               //if (argc) {
                        /* special case list */
-                       if (strcasecmp(argv[0], "list") == 0) {
-                               conference_list_pretty(conference, &stream);
-                               /* provide help */
+               if (switch_stristr("list", lbuf)) {
+                       conference_list_pretty(conference, &stream);
+                       /* provide help */
+               }
+                       else {
+                               return SWITCH_STATUS_SUCCESS;
                        }
 #if 0
                        else {
@@ -4456,12 +4460,11 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subjec
                                }
                        }
 #endif
-               } else {
-                       stream.write_function(&stream, "No parameters specified.\nTry 'help'\n");
-               }
+               //} else {
+               //stream.write_function(&stream, "No parameters specified.\nTry 'help'\n");
+               //}
        }
        switch_safe_free(lbuf);
-
        ci->chat_send(CONF_CHAT_PROTO, to, from, "", stream.data, NULL);
        switch_safe_free(stream.data);
 
index 740907f026d7b72702e0338e97edab1262193eb6..a0952fb02a57e340db6d7565743daff12cdef039 100644 (file)
@@ -1710,7 +1710,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_sofia_shutdown)
 {
        int sanity = 0;
        
-       sofia_presence_cancel();
+       //sofia_presence_cancel();
 
        switch_mutex_lock(mod_sofia_globals.mutex);
        if (mod_sofia_globals.running == 1) {
index 1a0fa2ca8ba46a386f3faa5f11ff2e3d80a8f2db..6a0c273d59864c839c1bcf36dbc99c838c1ba04f 100644 (file)
@@ -248,7 +248,7 @@ struct sofia_profile {
        switch_mutex_t *gateway_mutex;
        sofia_gateway_t *gateways;
        su_home_t *home;
-       switch_hash_t *profile_hash;
+       switch_hash_t *sub_hash;
        switch_hash_t *chat_hash;
        switch_core_db_t *master_db;
        switch_thread_rwlock_t *rwlock;
index 43d15e3b9cf3c3725586869894dc9c0e3c4322a1..044921b1125dfb819bb9c5bbe7e39fc37d54a35a 100644 (file)
@@ -42,12 +42,24 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
                                                                         char const *phrase,
                                                                         nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
 
+void sofia_handle_sip_r_notify(switch_core_session_t *session, int status,
+                                                          char const *phrase,
+                                                          nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
+{
+#if 0
+       if (status > 299) {
+               nua_handle_destroy(nh);
+               switch_core_hash_delete(profile->sub_hash, sip->sip_call_id->i_id);
+       }
+#endif
+}
+
 void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
                                                           char const *phrase,
                                                           nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
 {
        switch_channel_t *channel = NULL;
-
+       
        if (sip && sip->sip_event) {
                char *type = (char *)sip->sip_event->o_type;
                
@@ -177,7 +189,6 @@ void sofia_event_callback(nua_event_t event,
        case nua_i_bye:
        case nua_r_unsubscribe:
        case nua_r_publish:
-       case nua_r_notify:
        case nua_i_cancel:
        case nua_i_error:
        case nua_i_active:
@@ -185,6 +196,9 @@ void sofia_event_callback(nua_event_t event,
        case nua_i_terminated:
        case nua_r_set_params:
                break;
+       case nua_r_notify:
+               sofia_handle_sip_r_notify(session, status, phrase, nua, profile, nh, sofia_private, sip, tags);
+               break;
        case nua_i_notify:
                sofia_handle_sip_i_notify(session, status, phrase, nua, profile, nh, sofia_private, sip, tags);
                break;
@@ -462,6 +476,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
 
        sofia_glue_del_profile(profile);
        switch_core_hash_destroy(&profile->chat_hash);
+       switch_core_hash_destroy(&profile->sub_hash);
 
        switch_thread_rwlock_unlock(profile->rwlock);
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write unlock %s\n", profile->name);
@@ -789,6 +804,7 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                
                                profile->dbname = switch_core_strdup(profile->pool, url);
                                switch_core_hash_init(&profile->chat_hash, profile->pool);
+                               switch_core_hash_init(&profile->sub_hash, profile->pool);
                                switch_thread_rwlock_create(&profile->rwlock, profile->pool);
                                switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool);
                                profile->dtmf_duration = 100;
index c923025b77d59625d11e3ea786862f83f4a1ea14..a2a82611ad3637c38b318c2d488ba8b4e51b4e7b 100644 (file)
@@ -1684,7 +1684,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
                        switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
                }
 
-               if (switch_odbc_handle_exec(profile->master_odbc, "select contact from sip_subscriptions", NULL) != SWITCH_ODBC_SUCCESS) {
+               if (switch_odbc_handle_exec(profile->master_odbc, "delete from sip_subscriptions", NULL) != SWITCH_ODBC_SUCCESS) {
                        switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_subscriptions", NULL);
                        switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
                }
@@ -1700,7 +1700,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
                }
 
                switch_core_db_test_reactive(profile->master_db, "select call_id from sip_registrations", "DROP TABLE sip_registrations", reg_sql);
-               switch_core_db_test_reactive(profile->master_db, "select contact from sip_subscriptions", "DROP TABLE sip_subscriptions", sub_sql);
+               switch_core_db_test_reactive(profile->master_db, "delete from sip_subscriptions", "DROP TABLE sip_subscriptions", sub_sql);
                switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", "DROP TABLE sip_authentication", auth_sql);
 
 #ifdef SWITCH_HAVE_ODBC
index bd91c07d502b0c5af40f1e44e1547ffacb1bf60b..7d6f28e028234106d8143eed66eb91b3230b59dc 100644 (file)
@@ -114,7 +114,7 @@ void sofia_presence_cancel(void)
        switch_hash_index_t *hi;
        void *val;
 
-       if ((sql = switch_mprintf("select 0,'unavailable','unavailable',* from sip_subscriptions where event='presence'"))) {
+       if ((sql = switch_mprintf("select *,-1,'unavailable','unavailable' from sip_subscriptions where event='presence'"))) {
                switch_mutex_lock(mod_sofia_globals.hash_mutex);
                for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
                        switch_hash_this(hi, NULL, NULL, &val);
@@ -153,12 +153,12 @@ void sofia_presence_establish_presence(sofia_profile_t *profile)
 
 char *sofia_presence_translate_rpid(char *in, char *ext)
 {
-       char *r = NULL;
+       char *r = in;
 
-       if (in && (strstr(in, "null") || strstr(in, "NULL"))) {
+       if (in && (switch_stristr(in, "null"))) {
                in = NULL;
        }
-
+       
        if (!in) {
                in = ext;
        }
@@ -167,14 +167,10 @@ char *sofia_presence_translate_rpid(char *in, char *ext)
                return NULL;
        }
 
-       if (!strcasecmp(in, "dnd")) {
+       if (!strcasecmp(in, "dnd") || !strcasecmp(in, "idle")) {
                r = "busy";
        }
 
-       if (ext && !strcasecmp(ext, "away")) {
-               r = "idle";
-       }
-
        return r;
 }
 
@@ -245,6 +241,7 @@ void sofia_presence_mwi_event_handler(switch_event_t *event)
        }
 }
 
+
 void sofia_presence_event_handler(switch_event_t *event)
 {
        sofia_profile_t *profile = NULL;
@@ -293,11 +290,11 @@ void sofia_presence_event_handler(switch_event_t *event)
        if (event->event_id == SWITCH_EVENT_ROSTER) {
 
                if (from) {
-                       sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where event='presence' and full_from like '%%%q%%'", status, rpid, from);
+                       sql = switch_mprintf("select *,1,'%q','%q' from sip_subscriptions where event='presence' and full_from like '%%%q%%'", status, rpid, from);
                } else {
-                       sql = switch_mprintf("select 1,'%q','%q',* from sip_subscriptions where event='presence'", status, rpid);
+                       sql = switch_mprintf("select *,1,'%q','%q' from sip_subscriptions where event='presence'", status, rpid);
                }
-               
+
                assert(sql != NULL);
                switch_mutex_lock(mod_sofia_globals.hash_mutex);
                for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
@@ -388,13 +385,13 @@ void sofia_presence_event_handler(switch_event_t *event)
        case SWITCH_EVENT_PRESENCE_IN:
                sql =
                        switch_mprintf
-                       ("select 1,'%q','%q',* from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'",
+                       ("select *,1,'%q','%q' from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'",
                         status, rpid, proto, event_type, euser, host);
                break;
        case SWITCH_EVENT_PRESENCE_OUT:
                sql =
                        switch_mprintf
-                       ("select 0,'%q','%q',* from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'",
+                       ("select *,0,'%q','%q' from sip_subscriptions where proto='%q' and event='%q' and sub_to_user='%q' and sub_to_host='%q'",
                         status, rpid, proto, event_type, euser, host);
                break;
        default:
@@ -486,34 +483,82 @@ static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char
        return 0;
 }
 
+static char *translate_rpid(char *in)
+{
+       char *r = in;
+       
+       if (in && (strstr(in, "null") || strstr(in, "NULL"))) {
+               in = NULL;
+       }
+
+       if (!in || !strcasecmp(in, "unknown")) {
+               r = "online";
+               goto end;
+       }
+
+       if (!strcasecmp(in, "busy")) {
+               r = in;
+               goto end;
+       }
+
+       if (!strcasecmp(in, "unavailable")) {
+               r = "away";
+               goto end;
+       }
+
+       if (!strcasecmp(in, "idle")) {
+               r = "busy";
+       }
+
+ end:
+       return r;
+}
+
+
 static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
        sofia_profile_t *profile = (sofia_profile_t *) pArg;
        char *pl;
        char *id, *note;
-       uint32_t in = atoi(argv[0]);
-       char *status = argv[1];
-       char *rpid = argv[2];
-       char *proto = argv[3];
-       char *user = argv[4];
-       char *host = argv[5];
-       char *sub_to_user = argv[6];
-       char *sub_to_host = argv[7];
-       char *event = argv[8];
-       char *contact = argv[9];
-       char *callid = argv[10];
-       char *full_from = argv[11];
-       char *full_via = argv[12];
+       uint32_t in = atoi(argv[11]);
+       char *status = argv[12];
+       char *rpid = argv[13];
+
+       char *proto = argv[0];
+       char *user = argv[1];
+       char *host = argv[2];
+       char *sub_to_user = argv[3];
+       char *sub_to_host = argv[4];
+       char *event = argv[5];
+       char *contact = argv[6];
+       char *call_id = argv[7];
+       //char *full_from = argv[8];
+       //char *full_via = argv[9];
+       //char *expires = argv[10];
+
        nua_handle_t *nh;
        char *to;
        char *open;
        char *tmp;
-       char *prpid = "onthephone";
+       char *prpid;
+       int done = 0;
+
+       if (!(nh = (nua_handle_t *) switch_core_hash_find(profile->sub_hash, call_id))) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
+               return 0;
+       }
 
        if (!rpid) {
                rpid = "unknown";
        }
 
+       prpid = translate_rpid(rpid);
+
+       if (in < 0) {
+               done = 1;
+               in = 0;
+       } 
+
        if (in) {
                note = switch_mprintf("<dm:note>%s</dm:note>", status);
                open = "open";
@@ -542,7 +587,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
                                                "<presentity uri=\"%s;method=SUBSCRIBE\"/>\r\n"
                                                "<atom id=\"1002\">\r\n"
                                                "<address uri=\"%s\" priority=\"0.800000\">\r\n"
-                                               "<status status=\"inuse\">\r\n"
+                                               "<status status=\"%s\">\r\n"
                                                "<note>%s</note>\r\n"
                                                "</status>\r\n"
                                                "<msnsubstatus substatus=\"%s\"/>\r\n"
@@ -554,28 +599,26 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
                                                "</status>\r\n"
                                                "</tuple>\r\n"
                                                "<dm:person id='p06360c4a'>\r\n"
-                                               "<rpid:activities>\r\n" "<rpid:%s/>\r\n" "</rpid:activities>%s</dm:person>\r\n" "</presence>", id, 
-                                               id, profile->url, status, prpid,
+                                               "<rpid:activities>\r\n" "<rpid:%s/>\r\n" 
+                                               "</rpid:activities>%s</dm:person>\r\n" 
+                                               "</presence>", id, 
+                                               id, profile->url, open, status, prpid,
                                                open, rpid, note);
 
 
        tmp = contact;
        contact = sofia_glue_get_url_from_contact(tmp, 0);
 
-       nh = nua_handle(profile->nua, NULL, TAG_END());
-
-
        nua_notify(nh,
-                          NUTAG_NEWSUB(1),
-                          NUTAG_URL(contact),
-                          SIPTAG_TO_STR(full_from),
-                          SIPTAG_FROM_STR(id),
-                          SIPTAG_CONTACT_STR(profile->url),
-                          SIPTAG_CALL_ID_STR(callid),
-                          SIPTAG_VIA_STR(full_via),
                           SIPTAG_SUBSCRIPTION_STATE_STR("active;expires=3600"),
                           SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/pidf+xml"), SIPTAG_PAYLOAD_STR(pl), TAG_END());
 
+
+
+       if (done) {
+               switch_core_hash_delete(profile->sub_hash, call_id);
+       }
+
        switch_safe_free(id);
        switch_safe_free(note);
        switch_safe_free(pl);
@@ -594,8 +637,8 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
        char *event = argv[5];
        char *contact = argv[6];
        char *call_id = argv[7];
-       char *full_from = argv[8];
-       char *full_via = argv[9];
+       //char *full_from = argv[8];
+       //char *full_via = argv[9];
        char *expires = argv[10];
        char *body = argv[11];
        char *exp;
@@ -609,8 +652,10 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
                return 0;
        }
        
-       nh = nua_handle(profile->nua, NULL, TAG_END());
-       assert(nh != NULL);
+       if (!(nh = (nua_handle_t *) switch_core_hash_find(profile->sub_hash, call_id))) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
+               return 0;
+       }
 
        id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
        expire_sec = (int)(expire_sec - time(NULL));
@@ -623,15 +668,6 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
        contact = sofia_glue_get_url_from_contact(tmp, 0);
 
        nua_notify(nh,
-                          NUTAG_WITH_THIS(profile->nua),
-                          NUTAG_NEWSUB(1),
-                          NUTAG_URL(contact),
-                          SIPTAG_TO_STR(full_from),
-                          SIPTAG_FROM_STR(id),
-                          //SIPTAG_CONTACT_STR(profile->url),
-                          SIPTAG_CONTACT_STR(id),
-                          SIPTAG_CALL_ID_STR(call_id),
-                          SIPTAG_VIA_STR(full_via),
                           SIPTAG_SUBSCRIPTION_STATE_STR(exp),
                           SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
 
@@ -663,13 +699,18 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                char *proto = "sip";
                char *d_user = NULL;
                char *contact_str = "";
-               char *call_id = NULL;
+               const char *call_id = NULL;
                char *to_str = NULL;
                char *full_from = NULL;
                char *full_via = NULL;
                char *sstr;
                const char *display = "\"user\"";
                switch_event_t *sevent;
+               int sub_state;
+
+               tl_gets(tags,
+                               NUTAG_SUBSTATE_REF(sub_state), TAG_END());
+
 
                if (contact) {
                        char *port = (char *) contact->m_url->url_port;
@@ -708,8 +749,15 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                        to_host = (char *) to->a_url->url_host;
                }
 
+               if (sip && sip->sip_from) {
+                       from_user = (char *) sip->sip_from->a_url->url_user;
+                       from_host = (char *) sip->sip_from->a_url->url_host;
+               } else {
+                       from_user = "n/a";
+                       from_host = "n/a";
+               }
 
-               if (strstr(to_user, "ext+") || strstr(to_user, "user+") || strstr(to_user, "conf+")) {
+               if (strstr(to_user, "ext+") || strstr(to_user, "user+")) {
                        char proto[80];
                        char *p;
 
@@ -717,15 +765,25 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                        if ((p = strchr(proto, '+'))) {
                                *p = '\0';
                        }
-
+                       
                        if (switch_event_create(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
-                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "proto", proto);
                                switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", profile->name);
                                switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "from", "%s@%s", to_user, to_host);
-                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "rpid", "unknown");
+                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "rpid", "active");
                                switch_event_add_header(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(sevent, SWITCH_STACK_BOTTOM, "proto", SOFIA_CHAT_PROTO);
+                               switch_event_add_header(sevent, SWITCH_STACK_BOTTOM, "login", "%s", 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_fire(&sevent);
+                       }
                }
 
                if (strchr(to_user, '+')) {
@@ -746,7 +804,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                        }
                }
 
-               call_id = sip_header_as_string(profile->home, (void *) sip->sip_call_id);
+               call_id = sip->sip_call_id->i_id; //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
                event = sip_header_as_string(profile->home, (void *) sip->sip_event);
                full_from = sip_header_as_string(profile->home, (void *) sip->sip_from);
                full_via = sip_header_as_string(profile->home, (void *) sip->sip_via);
@@ -754,13 +812,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                exp_raw = (sip->sip_expires ? sip->sip_expires->ex_delta : 3600);
                exp = (long) time(NULL) + exp_raw;
 
-               if (sip && sip->sip_from) {
-                       from_user = (char *) sip->sip_from->a_url->url_user;
-                       from_host = (char *) sip->sip_from->a_url->url_host;
-               } else {
-                       from_user = "n/a";
-                       from_host = "n/a";
-               }
+               
 
                switch_mutex_lock(profile->ireg_mutex);
 
@@ -776,16 +828,24 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                assert(sql != NULL);
                sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
                free(sql);
-               sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
-                                                        proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp);
-               
-               assert(sql != NULL);
-               sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
-               free(sql);
-
-               switch_mutex_unlock(profile->ireg_mutex);
 
-               sstr = switch_mprintf("active;expires=%ld", exp_raw);
+               if (sub_state == nua_substate_terminated) {
+                       sstr = switch_mprintf("terminated");
+                       switch_core_hash_delete(profile->sub_hash, call_id);
+               } else {
+                       sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)",
+                                                                proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp);
+                       
+                       assert(sql != NULL);
+                       sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
+                       free(sql);
+
+
+                       switch_mutex_unlock(profile->ireg_mutex);
+                       sstr = switch_mprintf("active;expires=%ld", exp_raw);
+                       switch_core_hash_insert(profile->sub_hash, call_id, nh);
+                       
+               }
 
                nua_respond(nh, SIP_202_ACCEPTED,
                                        NUTAG_WITH_THIS(nua),
@@ -795,8 +855,8 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                                        SIPTAG_CONTACT_STR(contact_str),
                                        TAG_END());
 
-
-
+               
+               
 
                switch_safe_free(sstr);
 
@@ -815,9 +875,13 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                if (event) {
                        su_free(profile->home, event);
                }
-               if (call_id) {
-                       su_free(profile->home, call_id);
-               }
+
+               /*
+                 if (call_id) {
+                 su_free(profile->home, call_id);
+                 }
+               */
+
                if (full_from) {
                        su_free(profile->home, full_from);
                }
index f702c4a0670f0d6aed7bd9baab21c27eb44a1d2b..09e2122ebbc6ded558baf0d2ac5dacc63bdfaeaf 100644 (file)
@@ -344,7 +344,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
        char *register_gateway = NULL;
        int network_port;
        int cd = 0;
-       char *call_id = NULL;
+       const char *call_id = NULL;
 
        /* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
        assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
@@ -475,7 +475,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
                return 0;
        }
 
-       call_id = sip_header_as_string(profile->home, (void *) sip->sip_call_id);
+       call_id = sip->sip_call_id->i_id; //sip_header_as_string(profile->home, (void *) sip->sip_call_id);
        assert(call_id);
 
        
@@ -582,9 +582,11 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
        }
 
        
+       /*
        if (call_id) {
                su_free(profile->home, call_id);
        }
+       */
 
        if (regtype == REG_REGISTER) {
                char *new_contact = NULL;
index 8a27a71cc8c97d7601f1717a201b8fad9b0e6ccd..e7fccce4c257b3a1737b7c76ad473176148d2e65 100644 (file)
@@ -199,22 +199,21 @@ SWITCH_DECLARE(switch_bool_t) switch_simple_email(char *to, char *from, char *he
 
 SWITCH_DECLARE(const char *) switch_stristr(const char *str, const char *instr)
 {
-    switch_size_t score = strlen(str), x = 0;
-    const char *a = str, *b = instr, *p = NULL;
-
-    while(*a && *b) {
-        if (tolower(*b) == tolower(*a)) {
-            if (++x == score) {
-                return b - x + 1;
-            }
-            a++;
-        } else {
-            a = str;
-            p = b+1;
+       switch_size_t score = strlen(str), x = 0;
+       const char *a = str, *b = instr, *p = NULL;
+       while(*a && *b) {
+               if (tolower(*b) == tolower(*a)) {
+                       if (++x == score) {
+                               return b - x + 1;
+                       }
+                       a++;
+               } else {
+                       a = str;
+                       p = b+1;
                        x = 0;
-        }
-        b++;
-    }
+               }
+               b++;
+       }
        return NULL;
 }