]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
christmas presence
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 14 Dec 2007 02:09:22 +0000 (02:09 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 14 Dec 2007 02:09:22 +0000 (02:09 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6783 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_voicemail/mod_voicemail.c
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

index 3cc0985ee207c5ad262c7511806d2ad1bd688f4d..e66f0ae2fc739cb1a6f3caca92c6f0af92c17ed0 100644 (file)
@@ -2178,7 +2178,7 @@ static void  message_query_handler(switch_event_t *event)
             id = strdup(account);
         }
         assert(id);
-
+            
         if ((domain = strchr(id, '@'))) {
             *domain++ = '\0';
             for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
index 01c6383a524765c5c933785e180f19da5b46dc09..3f8316bcabfe795646fc72b3db5c6bd28bc785b4 100644 (file)
@@ -295,6 +295,7 @@ void event_handler(switch_event_t *event)
                char *exp_str = switch_event_get_header(event, "orig-expires");
                char *rpid = switch_event_get_header(event, "orig-rpid");
                char *call_id = switch_event_get_header(event, "orig-call-id");
+               char *user_agent = switch_event_get_header(event, "user-agent");
                long expires = (long) time(NULL) + atol(exp_str);
                char *profile_name = switch_event_get_header(event, "orig-profile-name");
                sofia_profile_t *profile = NULL;
@@ -317,8 +318,8 @@ void event_handler(switch_event_t *event)
                sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
                switch_safe_free(sql);
                
-               sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','Regestered', '%q', %ld)",
-                                                        call_id, from_user, from_host, contact_str, rpid, expires);
+               sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','Regestered', '%q', %ld, '%q')",
+                                                        call_id, from_user, from_host, contact_str, rpid, expires, user_agent);
 
                if (sql) {
                        sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
@@ -396,6 +397,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
                                   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW("SUBSCRIBE")),
                                   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ENABLEMESSAGE(1)),
                                   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence")),
+                                  TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("dialog")),
                                   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("presence.winfo")),
                                   TAG_IF((profile->pflags & PFLAG_PRESENCE), NUTAG_ALLOW_EVENTS("message-summary")),
                                   SIPTAG_SUPPORTED_STR("100rel, precondition, timer"), SIPTAG_USER_AGENT_STR(profile->user_agent), TAG_END());
index 8c34aca8180b824ff0e4a04fa2cdc191cf16c7f5..9223928d1efcce04742052f2abbbd0cfe4d9fe5d 100644 (file)
@@ -1694,7 +1694,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
                "   contact         VARCHAR(1024),\n" 
                "   status          VARCHAR(255),\n" 
                "   rpid            VARCHAR(255),\n" 
-               "   expires         INTEGER" 
+               "   expires         INTEGER,\n"
+               "   user_agent      VARCHAR(255)\n"
                ");\n";
 
        char sub_sql[] =
@@ -1709,7 +1710,9 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
                "   call_id         VARCHAR(255),\n" 
                "   full_from       VARCHAR(255),\n" 
                "   full_via        VARCHAR(255),\n" 
-               "   expires         INTEGER" 
+               "   expires         INTEGER,\n"
+               "   user_agent      VARCHAR(255),\n"
+               "   accept          VARCHAR(255)\n" 
                ");\n";
 
 
@@ -1731,12 +1734,12 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
 
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
                        
-               if (switch_odbc_handle_exec(profile->master_odbc, "select sip_user from sip_registrations", NULL) != SWITCH_ODBC_SUCCESS) {
+               if (switch_odbc_handle_exec(profile->master_odbc, "select sip_user,user_agent from sip_registrations", NULL) != SWITCH_ODBC_SUCCESS) {
                        switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_registrations", NULL);
                        switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
                }
 
-               if (switch_odbc_handle_exec(profile->master_odbc, "delete from sip_subscriptions where sip_user != ''", NULL) != SWITCH_ODBC_SUCCESS) {
+               if (switch_odbc_handle_exec(profile->master_odbc, "delete from sip_subscriptions where sip_user != '' or accept != ''", 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);
                }
@@ -1753,8 +1756,8 @@ int sofia_glue_init_sql(sofia_profile_t *profile)
                        return 0;
                }
 
-               switch_core_db_test_reactive(profile->master_db, "select sip_user from sip_registrations", "DROP TABLE sip_registrations", reg_sql);
-               switch_core_db_test_reactive(profile->master_db, "delete * from sip_subscriptions where sip_user != ''", "DROP TABLE sip_subscriptions", sub_sql);
+               switch_core_db_test_reactive(profile->master_db, "select sip_user,user_agent from sip_registrations", "DROP TABLE sip_registrations", reg_sql);
+               switch_core_db_test_reactive(profile->master_db, "delete from sip_subscriptions where sip_user != '' or accept != ''", "DROP TABLE sip_subscriptions", sub_sql);
                switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", "DROP TABLE sip_authentication", auth_sql);
 
        }
index 4e9e9cd5b5e701933d23c272c310984dbd0be24f..3ac6eb1bc40081bf71ac848efe65875fc38cba4d 100644 (file)
@@ -532,9 +532,9 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
        sofia_profile_t *profile = (sofia_profile_t *) pArg;
        char *pl;
        char *id, *note;
-       uint32_t in = atoi(argv[11]);
-       char *status = argv[12];
-       char *rpid = argv[13];
+       uint32_t in = atoi(argv[13]);
+       char *status = argv[14];
+       char *rpid = argv[15];
 
        char *proto = argv[0];
        char *user = argv[1];
@@ -640,7 +640,7 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
        //char *full_from = argv[8];
        //char *full_via = argv[9];
        char *expires = argv[10];
-       char *body = argv[11];
+       char *body = argv[13];
        char *exp;
        sofia_profile_t *profile = NULL;
        char *id = NULL;
@@ -738,6 +738,8 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                char *to_str = NULL;
                char *full_from = NULL;
                char *full_via = NULL;
+               char *full_agent = NULL;
+               char *full_accept = NULL;
                char *sstr;
                const char *display = "\"user\"";
                switch_event_t *sevent;
@@ -866,8 +868,11 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                        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);
+                       full_agent = sip_header_as_string(profile->home, (void *) sip->sip_user_agent);
+                       full_accept = sip_header_as_string(profile->home, (void *) sip->sip_accept);
+                       sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld,'%q','%q')",
+                                                                proto, from_user, from_host, to_user, to_host, event, 
+                                                                contact_str, call_id, full_from, full_via, exp, full_agent, full_accept);
                        
                        switch_assert(sql != NULL);
                        sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
@@ -886,7 +891,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                                        SIPTAG_CONTACT_STR(contact_str),
                                        TAG_END());
 
-               nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("text/html"),
+               nua_notify(nh, SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/octet-stream"),
                                   SIPTAG_PAYLOAD_STR("Come to ClueCon http://www.cluecon.com\n\n"),
                                   TAG_END());
 
@@ -914,6 +919,12 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                if (full_via) {
                        su_free(profile->home, full_via);
                }
+               if (full_agent) {
+                       su_free(profile->home, full_agent);
+               }
+               if (full_accept) {
+                       su_free(profile->home, full_accept);
+               }
 
                switch_safe_free(d_user);
                switch_safe_free(to_str);
index 9157eef6d2e35f32731eb48a1fad7537fa6c7192..f560bb14b34a47996cba5ce939838c6a2d6927fe 100644 (file)
@@ -176,12 +176,13 @@ int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames
 
        if (argc >= 3) {
                if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_EXPIRE) == SWITCH_STATUS_SUCCESS) {
-                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile-name", "%s", argv[0]);
-                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "call-id", "%s", argv[1]);
-                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "user", "%s", argv[2]);
-                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "host", "%s", argv[3]);
-                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s", argv[4]);
-                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%s", argv[5]);
+                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile-name", "%s", argv[6]);
+                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "call-id", "%s", argv[0]);
+                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "user", "%s", argv[1]);
+                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "host", "%s", argv[2]);
+                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s", argv[3]);
+                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%s", argv[4]);
+                       switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "user-agent", "%s", argv[5]);
                        switch_event_fire(&s_event);
                }
        }
@@ -210,9 +211,9 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
 #endif
 
        if (now) {
-               switch_snprintf(sql, sizeof(sql), "select '%s',* from sip_registrations where expires > 0 and expires <= %ld", profile->name, (long) now);
+               switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where expires > 0 and expires <= %ld", profile->name, (long) now);
        } else {
-               switch_snprintf(sql, sizeof(sql), "select '%s',* from sip_registrations where expires > 0", profile->name);
+               switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where expires > 0", profile->name);
        }
 
        switch_mutex_lock(profile->ireg_mutex);
@@ -477,6 +478,11 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
 
        
        if (exptime) {
+               const char *agent = "dunno";
+
+               if (sip->sip_user_agent) {
+                       agent = sip->sip_user_agent->g_string;
+               }
 
                if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
                        sql = switch_mprintf("delete from sip_registrations where call_id='%q'", call_id);
@@ -487,8 +493,9 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
                sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL);
                switch_safe_free(sql);
                
-               sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','%q', '%q', %ld)", call_id,
-                                                        to_user, to_host, contact_str, cd ? "Registered(NATHACK)" : "Registered", rpid, (long) time(NULL) + (long) exptime * 2);
+               sql = switch_mprintf("insert into sip_registrations values ('%q', '%q','%q','%q','%q', '%q', %ld, '%q')", call_id,
+                                                        to_user, to_host, contact_str, cd ? "Registered(NATHACK)" : "Registered", 
+                                                        rpid, (long) time(NULL) + (long) exptime * 2, agent);
 
                
                if (sql) {
@@ -591,6 +598,10 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han
                        new_contact = switch_mprintf("%s;expires=%ld", contact_str, (long)exptime);
                        nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END());
                        switch_safe_free(new_contact);
+                       if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
+                               switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", to_user, to_host);
+                               switch_event_fire(&event);
+                       }
                } else {
                        nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(contact), NUTAG_WITH_THIS(nua), TAG_END());
                }