[Freeswitch-svn] [commit] r6783 - in freeswitch/trunk/src/mod: applications/mod_voicemail endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Thu Dec 13 21:09:22 EST 2007


Author: anthm
Date: Thu Dec 13 21:09:22 2007
New Revision: 6783

Modified:
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c

Log:
christmas presence

Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	Thu Dec 13 21:09:22 2007
@@ -2178,7 +2178,7 @@
             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)) {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Thu Dec 13 21:09:22 2007
@@ -295,6 +295,7 @@
 		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 @@
 		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 @@
 				   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());

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	Thu Dec 13 21:09:22 2007
@@ -1694,7 +1694,8 @@
 		"   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 @@
 		"   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 @@
 
 		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 @@
 			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);
 
 	}

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	Thu Dec 13 21:09:22 2007
@@ -532,9 +532,9 @@
 	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 @@
 	//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 @@
 		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 @@
 			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 @@
 					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 @@
 		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);

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	Thu Dec 13 21:09:22 2007
@@ -176,12 +176,13 @@
 
 	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 @@
 #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 @@
 
 	
 	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 @@
 		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 @@
 			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());
 		}



More information about the Freeswitch-svn mailing list