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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 4 18:34:32 CDT 2013


Author: mmichelson
Date: Thu Apr  4 18:34:29 2013
New Revision: 384806

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384806
Log:
Queue a connected line update on initial call.

This makes it so that the caller can see who he is connected to if the
callee has configured caller ID.


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=384806&r1=384805&r2=384806
==============================================================================
--- team/mmichelson/caller_id/res/res_sip/sip_configuration.c (original)
+++ team/mmichelson/caller_id/res/res_sip/sip_configuration.c Thu Apr  4 18:34:29 2013
@@ -233,6 +233,18 @@
 		}
 		endpoint->id.number.valid = 1;
 	}
+	return 0;
+}
+
+static int caller_id_privacy_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+	struct ast_sip_endpoint *endpoint = obj;
+	int callingpres = ast_parse_caller_presentation(var->value);
+	if (callingpres == -1 && sscanf(var->value, "%d", &callingpres) != 1) {
+		return -1;
+	}
+	endpoint->id.number.presentation = callingpres;
+	endpoint->id.name.presentation = callingpres;
 	return 0;
 }
 
@@ -302,6 +314,7 @@
 	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);
+	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "callerid_privacy", "", caller_id_privacy_handler, NULL, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "trust_external_id", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, trust_external_id));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_pai", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, send_pai));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_rpid", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, send_rpid));

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=384806&r1=384805&r2=384806
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Thu Apr  4 18:34:29 2013
@@ -157,37 +157,81 @@
 	return 0;
 }
 
+static int should_queue_connected_line_update(struct ast_sip_session *session, struct ast_party_id *id)
+{
+	/* Invalid number means no update */
+	if (!id->number.valid) {
+		return 0;
+	}
+
+	/* If the session has never communicated an update or if the
+	 * new ID has a different number than the session, then we
+	 * should queue an update
+	 */
+	if (ast_strlen_zero(session->id.number.str) ||
+			strcmp(session->id.number.str, id->number.str)) {
+		return 1;
+	}
+
+	/* By making it to this point, it means the number is not enough
+	 * to determine if an update should be sent. Now we look at
+	 * the name
+	 */
+
+	/* If the number couldn't warrant an update and the name is
+	 * invalid, then no update
+	 */
+	if (!id->name.valid) {
+		return 0;
+	}
+
+	/* If the name has changed or we don't have a name set for the
+	 * session, then we should send an update
+	 */
+	if (ast_strlen_zero(session->id.name.str) ||
+			strcmp(session->id.name.str, id->name.str)) {
+		return 1;
+	}
+
+	/* Neither the name nor the number have changed. No update */
+	return 0;
+}
+
+static void queue_connected_line_update(struct ast_sip_session *session, struct ast_party_id *id)
+{
+	struct ast_party_connected_line connected;
+	struct ast_set_party_connected_line update_connected;
+	ast_party_connected_line_init(&connected);
+	ast_party_id_copy(&connected.id, id);
+
+	memset(&update_connected, 0, sizeof(update_connected));
+	update_connected.id.number = 1;
+	update_connected.id.name = 1;
+
+	ast_set_party_id_all(&update_connected.priv);
+	connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
+	ast_party_id_copy(&session->id, &connected.id);
+	ast_channel_queue_connected_line_update(session->channel, &connected, &update_connected);
+
+	ast_party_connected_line_free(&connected);
+}
+
 static void update_incoming_connected_line(struct ast_sip_session *session, pjsip_rx_data *rdata)
 {
-	struct ast_party_connected_line connected;
-
+	struct ast_party_id id;
 	if (!session->endpoint->trust_external_id) {
 		return;
 	}
 
-	ast_party_connected_line_init(&connected);
-
-	if (get_id_from_pai(rdata, &connected.id) && get_id_from_rpid(rdata, &connected.id)) {
-		return;
-	}
-	if ((connected.id.number.valid &&
-			(ast_strlen_zero(session->id.number.str) ||
-			 strcmp(session->id.number.str, connected.id.number.str))) ||
-		(connected.id.name.valid &&
-			(ast_strlen_zero(session->id.name.str) ||
-		 	strcmp(session->id.name.str, connected.id.name.str)))) {
-		struct ast_set_party_connected_line update_connected;
-		memset(&update_connected, 0, sizeof(update_connected));
-		update_connected.id.number = 1;
-		update_connected.id.name = 1;
-
-		ast_set_party_id_all(&update_connected.priv);
-		connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
-		ast_party_id_copy(&session->id, &connected.id);
-		ast_channel_queue_connected_line_update(session->channel, &connected, &update_connected);
-	}
-
-	ast_party_connected_line_free(&connected);
+	ast_party_id_init(&id);
+	if (get_id_from_pai(rdata, &id) && get_id_from_rpid(rdata, &id)) {
+		return;
+	}
+	if (should_queue_connected_line_update(session, &id)) {
+		queue_connected_line_update(session, &id);
+	}
+
+	ast_party_id_free(&id);
 }
 
 static int caller_id_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
@@ -336,6 +380,9 @@
 		modify_id_header(tdata->pool, from, &ast_channel_connected(session->channel)->id);
 		modify_id_header(dlg->pool, dlg->local.info,
 				&ast_channel_connected(session->channel)->id);
+		if (should_queue_connected_line_update(session, &session->endpoint->id)) {
+			queue_connected_line_update(session, &session->endpoint->id);
+		}
 	}
 	if (session->endpoint->send_pai) {
 		add_pai_header(tdata, &ast_channel_connected(session->channel)->id);




More information about the asterisk-commits mailing list