[asterisk-commits] kharwell: branch kharwell/pimp_sip_state r388073 - in /team/kharwell/pimp_sip...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 8 16:28:40 CDT 2013


Author: kharwell
Date: Wed May  8 16:28:38 2013
New Revision: 388073

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388073
Log:
hopefully mostly done...going up for review

Modified:
    team/kharwell/pimp_sip_state/res/res_sip_exten_state.c
    team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c

Modified: team/kharwell/pimp_sip_state/res/res_sip_exten_state.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/res/res_sip_exten_state.c?view=diff&rev=388073&r1=388072&r2=388073
==============================================================================
--- team/kharwell/pimp_sip_state/res/res_sip_exten_state.c (original)
+++ team/kharwell/pimp_sip_state/res/res_sip_exten_state.c Wed May  8 16:28:38 2013
@@ -140,6 +140,8 @@
  * a notify data creator is quickly accessible.
  */
 struct state_sub {
+	/*! Watcher id when registering for extension state changes */
+	int id;
 	/*! The SIP subscription */
 	struct ast_sip_subscription *sip_sub;
 	/*! The notify data creator */
@@ -229,7 +231,7 @@
 static void create_send_notify(struct state_sub *ssub, const char *reason,
 			       struct ast_exten_state *data)
 {
-	RAII_VAR(struct ast_str *, body_text, ast_str_create(512), ast_free_ptr);
+	RAII_VAR(struct ast_str *, body_text, ast_str_create(1024), ast_free_ptr);
 	pj_str_t reason_str;
 	const pj_str_t *reason_str_ptr = NULL;
 	pjsip_tx_data *tdata;
@@ -243,9 +245,8 @@
 	}
 
 	ast_copy_string(type, ssub->provider->accept,
-			body.subtype - ssub->provider->accept);
+			++body.subtype - ssub->provider->accept);
 	body.type = type;
-	++body.subtype;	
 
 	if (!ssub->provider->create_body) {
 		ast_log(LOG_WARNING, "Body handler not specified for provider\n");
@@ -298,9 +299,9 @@
 	};
 
 	if ((sdata.exten_state = ast_extension_state_extended(
-		     NULL, ssub->context, ssub->exten, &info))) {
-
-		ast_log(LOG_WARNING, "Unable to get device info for extension %s\n",
+		     NULL, ssub->context, ssub->exten, &info)) < 0) {
+
+		ast_log(LOG_WARNING, "Unable to get device hint/info for extension %s\n",
 			ssub->exten);
 		return;
 	}
@@ -317,10 +318,15 @@
 static int serialized_notify(void *userdata)
 {
 	struct serialized_userdata *udata = userdata;
-	create_send_notify(udata->ssub, NULL, udata->sdata);
+
+	create_send_notify(udata->ssub, udata->ssub->state == PJSIP_EVSUB_STATE_TERMINATED ?
+			   "noresource" : NULL, udata->sdata);
 
 	ao2_ref(udata->ssub, -1);
-	ao2_ref(udata->sdata->device_state, -1);
+	if (udata->sdata->device_state) {
+		ao2_ref(udata->sdata->device_state, -1);
+	}
+
 	ast_free(udata->sdata);
 	return 0;
 }
@@ -344,9 +350,12 @@
 	sdata->exten_state = info->exten_state;
 	sdata->presence_state = info->presence_state;
 	sdata->device_state = info->device_state_info;
-	ao2_ref(sdata->device_state, +1);
+	if (sdata->device_state) {
+		ao2_ref(sdata->device_state, +1);
+	}
+	udata->sdata = sdata;
+
 	udata->ssub->state = PJSIP_EVSUB_STATE_ACTIVE;
-
 	if ((info->exten_state == AST_EXTENSION_DEACTIVATED) ||
 	    (info->exten_state == AST_EXTENSION_REMOVED)) {
 		udata->ssub->state = PJSIP_EVSUB_STATE_TERMINATED;
@@ -354,10 +363,8 @@
 			 == AST_EXTENSION_REMOVED ? "removed" : "deactivated");
 	}
 
-	ast_log(LOG_VERBOSE, "state_changed: context=%s, exten=%s\n",context, exten);
-
 	ast_sip_push_task(ast_sip_subscription_get_serializer(udata->ssub->sip_sub),
-			  serialized_notify, sdata);
+			  serialized_notify, udata);
 	return 0;
 }
 
@@ -403,6 +410,7 @@
 	struct state_sub *ssub = from_datastore(sub);
 
 	if (ssub) {
+		ast_extension_state_del(ssub->id, state_changed);
 		ao2_cleanup(ssub);
 	}
 }
@@ -414,8 +422,6 @@
 	pjsip_sip_uri *sip_uri = pjsip_uri_get_uri(uri);
 	struct state_sub *ssub;
 
-	ast_log(LOG_VERBOSE, "new_subscribe:\n");
-
 	if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri)) {
 		ast_log(LOG_WARNING, "Attempt to SUBSCRIBE to a non-SIP URI\n");
 		return NULL;
@@ -428,7 +434,8 @@
 	ssub->context = endpoint->context;
 	ast_copy_pj_str(ssub->exten, &sip_uri->user, sizeof(ssub->exten));
 
-	if (ast_extension_state_add(ssub->context, ssub->exten, state_changed, ssub) < 0) {
+	if ((ssub->id = ast_extension_state_add(ssub->context, ssub->exten,
+						state_changed, ssub)) < 0) {
 		ast_log(LOG_WARNING, "Unable to subscribe extension %s\n",
 			ssub->exten);
 		ao2_cleanup(ssub);
@@ -485,23 +492,6 @@
 	ast_log(LOG_NOTICE, "Subscription has been terminated\n");
 	ssub->state = PJSIP_EVSUB_STATE_TERMINATED;
 	send_notify(ssub, NULL);
-}
-
-static void notify_response(struct ast_sip_subscription *sub, pjsip_rx_data *rdata)
-{
-	/* nothing to do? */
-}
-
-static void notify_request(struct ast_sip_subscription *sub, pjsip_rx_data *rdata,
-			   struct ast_sip_subscription_response_data *response_data)
-{
-	/* nothing to do? */
-}
-
-static int refresh_subscription(struct ast_sip_subscription *sub)
-{
-	/* nothing to do? */
-	return 0;
 }
 
 /*!
@@ -569,9 +559,6 @@
 	handler->resubscribe = resubscribe;
 	handler->subscription_timeout = subscription_timeout;
 	handler->subscription_terminated = subscription_terminated;
-	handler->notify_response = notify_response;
-	handler->notify_request = notify_request;
-	handler->refresh_subscription = refresh_subscription;
 
 	return handler;
 }

Modified: team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c?view=diff&rev=388073&r1=388072&r2=388073
==============================================================================
--- team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c (original)
+++ team/kharwell/pimp_sip_state/res/res_sip_providers/res_sip_pidf.c Wed May  8 16:28:38 2013
@@ -23,6 +23,7 @@
 	<depend>res_sip_exten_state</depend>
 	<support_level>core</support_level>
  ***/
+
 #include "asterisk.h"
 #include "asterisk/pbx.h"
 #include "asterisk/res_sip_exten_state.h"
@@ -38,12 +39,6 @@
 			       char **pidfnote, int *local_state)
 {
 	switch (state) {
-	/* case (AST_EXTENSION_RINGING | AST_EXTENSION_INUSE): */
-	/* 	statestring = (sip_cfg.notifyringing) ? "early" : "confirmed"; */
-	/* 	local_state = NOTIFY_INUSE; */
-	/* 	pidfstate = "busy"; */
-	/* 	pidfnote = "Ringing"; */
-	/* 	break; */
 	case AST_EXTENSION_RINGING:
 		*statestring = "early";
 		*local_state = NOTIFY_INUSE;
@@ -111,29 +106,11 @@
 	ast_str_append(body_text, 0, "<note>%s</note>\n", pidfnote);
 	ast_str_append(body_text, 0, "<tuple id=\"%s\">\n", data->exten); /* Tuple start */
 	ast_str_append(body_text, 0, "<contact priority=\"1\">%s</contact>\n", remote);
-	if (pidfstate[0] == 'b') /* Busy? Still open ... */
+	if (pidfstate[0] == 'b') { /* Busy? Still open ... */
 		ast_str_append(body_text, 0, "<status><basic>open</basic></status>\n");
-	else
+	} else {
 		ast_str_append(body_text, 0, "<status><basic>%s</basic></status>\n", (local_state != NOTIFY_CLOSED) ? "open" : "closed");
-
-	/* if (allow_notify_user_presence(p) && (data->presence_state != AST_PRESENCE_INVALID) */
-	/*     && (data->presence_state != AST_PRESENCE_NOT_SET)) { */
-	/* 	ast_str_append(body_text, 0, "</tuple>\n"); */
-	/* 	ast_str_append(body_text, 0, "<tuple id=\"digium-presence\">\n"); */
-	/* 	ast_str_append(body_text, 0, "<status>\n"); */
-	/* 	ast_str_append(body_text, 0, "<digium_presence type=\"%s\" subtype=\"%s\">%s</digium_presence>\n", */
-	/* 		       ast_presence_state2str(data->presence_state), */
-	/* 		       S_OR(data->presence_subtype, ""), */
-	/* 		       S_OR(data->presence_message, "")); */
-	/* 	ast_str_append(body_text, 0, "</status>\n"); */
-	/* 	ast_test_suite_event_notify("DIGIUM_PRESENCE_SENT", */
-	/* 				    "PresenceState: %s\r\n" */
-	/* 				    "Subtype: %s\r\n" */
-	/* 				    "Message: %s", */
-	/* 				    ast_presence_state2str(data->presence_state), */
-	/* 				    S_OR(data->presence_subtype, ""), */
-	/* 				    S_OR(data->presence_message, "")); */
-	/* } */
+	}
 	ast_str_append(body_text, 0, "</tuple>\n</presence>\n");
 }
 




More information about the asterisk-commits mailing list