[asterisk-commits] mmichelson: branch mmichelson/caller_id r384585 - in /team/mmichelson/caller_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 2 13:39:33 CDT 2013


Author: mmichelson
Date: Tue Apr  2 13:39:29 2013
New Revision: 384585

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384585
Log:
Implement a callerid option for endpoints.


Modified:
    team/mmichelson/caller_id/res/res_sip/sip_configuration.c
    team/mmichelson/caller_id/res/res_sip_caller_id.c

Modified: team/mmichelson/caller_id/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/caller_id/res/res_sip/sip_configuration.c?view=diff&rev=384585&r1=384584&r2=384585
==============================================================================
--- team/mmichelson/caller_id/res/res_sip/sip_configuration.c (original)
+++ team/mmichelson/caller_id/res/res_sip/sip_configuration.c Tue Apr  2 13:39:29 2013
@@ -16,6 +16,7 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/utils.h"
 #include "asterisk/sorcery.h"
+#include "asterisk/callerid.h"
 
 static struct ast_sorcery *sip_sorcery;
 
@@ -208,6 +209,30 @@
 		return -1;
 	}
 
+	return 0;
+}
+
+static int caller_id_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+	struct ast_sip_endpoint *endpoint = obj;
+	char cid_name[80] = { '\0' };
+	char cid_num[80] = { '\0' };
+
+	ast_callerid_split(var->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
+	if (!ast_strlen_zero(cid_name)) {
+		endpoint->id.name.str = ast_strdup(cid_name);
+		if (!endpoint->id.name.str) {
+			return -1;
+		}
+		endpoint->id.name.valid = 1;
+	}
+	if (!ast_strlen_zero(cid_num)) {
+		endpoint->id.number.str = ast_strdup(cid_num);
+		if (!endpoint->id.number.str) {
+			return -1;
+		}
+		endpoint->id.number.valid = 1;
+	}
 	return 0;
 }
 
@@ -276,6 +301,7 @@
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_method", "invite", direct_media_method_handler, NULL, 0, 0);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_glare_mitigation", "none", direct_media_glare_mitigation_handler, NULL, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "disable_direct_media_on_nat", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, disable_direct_media_on_nat));
+	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "callerid", "", caller_id_handler, NULL, 0, 0);
 
 	if (ast_sip_initialize_sorcery_transport(sip_sorcery)) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");
@@ -327,6 +353,7 @@
 		ast_format_cap_destroy(endpoint->codecs);
 	}
 	destroy_endpoint_auths(endpoint);
+	ast_party_id_free(&endpoint->id);
 }
 
 void *ast_sip_endpoint_alloc(const char *name)
@@ -343,6 +370,7 @@
 		ao2_cleanup(endpoint);
 		return NULL;
 	}
+	ast_party_id_init(&endpoint->id);
 	return endpoint;
 }
 

Modified: team/mmichelson/caller_id/res/res_sip_caller_id.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/caller_id/res/res_sip_caller_id.c?view=diff&rev=384585&r1=384584&r2=384585
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Tue Apr  2 13:39:29 2013
@@ -136,7 +136,12 @@
 	if (session->inv_session->state < PJSIP_INV_STATE_CONFIRMED) {
 		/* Initial inbound INVITE. Set the session ID directly */
 		if (get_id_from_pai(rdata, &session->id)) {
-			get_id_from_from(rdata, &session->id);
+			if (session->endpoint->id.number.valid) {
+				/* Prefer configured caller-ID over From header. */
+				ast_party_id_copy(&session->id, &session->endpoint->id);
+			} else {
+				get_id_from_from(rdata, &session->id);
+			}
 		}
 	} else {
 		/* Reinvite. Check for changes to the ID and queue a connected line




More information about the asterisk-commits mailing list