[asterisk-commits] kharwell: branch kharwell/pimp_sip_state r387285 - /team/kharwell/pimp_sip_st...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 1 18:04:18 CDT 2013


Author: kharwell
Date: Wed May  1 18:04:16 2013
New Revision: 387285

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=387285
Log:
changed exten_state accept array to single accept value. also fleshed out some of the send_notify function - no compile

Modified:
    team/kharwell/pimp_sip_state/res/res_sip_exten_state.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=387285&r1=387284&r2=387285
==============================================================================
--- 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  1 18:04:16 2013
@@ -46,8 +46,15 @@
 	const char *name;
 	/*! The name of the event this notifier registers for */
 	const char *event_name;
-	/*! The types of body this notifier accepts */
-	const char *accept[AST_SIP_MAX_ACCEPT];
+	/*! The type of body this notifier accepts */
+	const char *accept;
+
+	/*!
+	 * \brief Called before sending the notify request.
+	 *
+	 * Allows the notifier to set data on the outgoing request.
+	 */
+	void (*set_tdata)(pjsip_tx_data *tdata);
 };
 
 AST_RWLIST_HEAD_STATIC(notifiers, exten_state_notifer);
@@ -74,15 +81,13 @@
 	AST_RWLIST_TRAVERSE_SAFE_END;
 }
 
-static int has_accept(const char accept[], const char *value);
-
 static struct exten_state_notifier *notifier_by_accept(const char *accept)
 {
 	struct exten_state_notifier *res = NULL;
 	struct exten_state_notifier *i;
 	SCOPED_LOCK(lock, &notifiers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
 	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&notifers, i, next) {
-		if (i->accept, accept) {
+		if (!strcmp(i->accept, accept)) {
 			res = i;
 			break;
 		}
@@ -225,12 +230,17 @@
 
 static void send_notify(struct state_sub *sub, pjsip_evsub_state state, const char *reason)
 {
-	const pj_str_t *reason_str_ptr = NULL;
-
-	static pjsip_media_type mwi_type = {
-		.type = { "application", 11 },
-		.subtype = { "simple-message-summary", 22 },
-	};
+	pjsip_media_type body_type;
+	char type[50];
+	char *subtype;
+
+	ast_copy_string(type, sub->notifier->accept, sizeof(type));
+	if ((subtype = strchr(type, '/'))) {
+		*subtype++ = '\0';
+		body_type.subtype = pj_str_t(subtype);
+	}
+
+	body_type.type = pj_str_t(type);
 
 	RAII_VAR(struct ast_str *, body, ast_str_create(64), ast_free_ptr);
 	pjsip_tx_data *tdata;
@@ -251,6 +261,10 @@
 			       NULL, reason ? pj_str(reason) : NULL, &tdata) != PJ_SUCCESS) {
 		ast_log(LOG_WARNING, "Unable to create NOTIFY request to %s.\n", sub->id);
 		return;
+	}
+
+	if (sub->notifier->set_data) {
+		sub->notifier->set_data(tdata);
 	}
 
 	if (ast_sip_subscription_send_request(sub->sip_sub, tdata) != PJ_SUCCESS) {
@@ -340,7 +354,7 @@
 
 	pjsip_evsub_accept(ast_sip_subscription_get_evsub(sub->sip_sub),
 			   rdata, 200, NULL);
-	send_mwi_notify(sub, PJSIP_EVSUB_STATE_ACTIVE, NULL);
+	send_notify(sub, PJSIP_EVSUB_STATE_ACTIVE, NULL);
 
 	return sub->sip_sub;
 }
@@ -396,23 +410,26 @@
 
 /*!
  * \internal
- * \brief Assign items from 'src' to 'dest' if 'dest' does not
- *        already contain the item.
- */
-static void assign_accept(char* dest[], const char* src[])
-{
-	int i = 0, j;
+ * \brief Add given accept to 'dest' if 'dest' does not already contain
+ *        the accept type.
+ */
+static void add_accept(char* dest[], const char* accept)
+{
+	int i = 0;
+
+	if (has_accept(dest, accept)) {
+		return;
+	}
 
 	/* find the first empty element in the array */
 	while (dest[i]) ++i;
 
-	/* for every item in src, if it is not already in dest
-	   then add it to it */
-	for (j = 0; j < sizeof(src) && i < sizeof(dest); ++j) {
-		if (!has_accept(dest, src[j])) {
-			dest[i++] = src[j];
-		}
-	}
+	if (i == sizeof(dest)) {
+		ast_log(LOG_WARNING, "Subcription handler's accept values full\n");
+		return;
+	}
+
+	dest[i] = accept;
 }
 
 /*!
@@ -420,10 +437,10 @@
  * \brief Create a subscription handler.
  *
  * Creates a subscription handler that can be registered with the pub/sub
- * framework for the given event_name and accept values.
+ * framework for the given event_name and accept value.
  */
 static struct ast_sip_subscription_handler *create_sub_handler(const char *event_name,
-							       const char accept[])
+							       const char *accept)
 {
 	struct ast_sip_subscription_handler *handler = 
 		ao2_alloc(sizeof(*handler), NULL);
@@ -433,7 +450,7 @@
 	}
 
 	handler->event_name = event_name;
-	assign_accept(handler->accept, accept);
+	add_accept(handler->accept, accept);
 
 	handler->subscription_shutdown = subscription_shutdown;
 	handler->new_subscribe = new_subscribe;
@@ -459,9 +476,9 @@
  *
  * For every registered notifier create, or re-use, a subscription handler
  * based upon the event_name. If a handler does not exist for a particular
- * event_name one will be created adding all accept values from a notifier.
- * If a handler already exists for an event_name then any extra accept
- * values that have not been assigned to that handler will be.
+ * event_name one will be created adding the accept value from a notifier.
+ * If a handler already exists for an event_name then if the accept value
+ * has not been added to that handler it will be.
  */
 static void create_sub_handlers()
 {
@@ -474,7 +491,7 @@
 		if (handler) {
 			/* if handler exists just assign those accept values to
 			   it from the notifier that have not already been set */
-			assign_accept(handler->accept, i->accept);
+			add_accept(handler->accept, i->accept);
 			continue;
 		}
 




More information about the asterisk-commits mailing list