[asterisk-commits] mjordan: branch mjordan/12-messaging r418444 - in /team/mjordan/12-messaging:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jul 12 21:46:31 CDT 2014


Author: mjordan
Date: Sat Jul 12 21:46:22 2014
New Revision: 418444

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=418444
Log:
cleanup res_pjsip_messaging; fix crashes

Modified:
    team/mjordan/12-messaging/include/asterisk/json.h
    team/mjordan/12-messaging/include/asterisk/message.h
    team/mjordan/12-messaging/main/json.c
    team/mjordan/12-messaging/main/message.c
    team/mjordan/12-messaging/res/ari/resource_endpoints.c
    team/mjordan/12-messaging/res/res_ari.c
    team/mjordan/12-messaging/res/res_pjsip_messaging.c
    team/mjordan/12-messaging/res/res_xmpp.c
    team/mjordan/12-messaging/res/stasis/app.c

Modified: team/mjordan/12-messaging/include/asterisk/json.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/include/asterisk/json.h?view=diff&rev=418444&r1=418443&r2=418444
==============================================================================
--- team/mjordan/12-messaging/include/asterisk/json.h (original)
+++ team/mjordan/12-messaging/include/asterisk/json.h Sat Jul 12 21:46:22 2014
@@ -1010,6 +1010,25 @@
  */
 struct ast_json *ast_json_party_id(struct ast_party_id *party);
 
+/*!
+ * \brief Convert a \c ast_json list of key/value pair tuples into a \c ast_variable list
+ * \since 12.5.0
+ *
+ * \param json_variables The JSON blob containing the variable
+ * \param variables An out reference to the variables to populate.
+ *        The pointer to the variables should be NULL when calling this.
+ *
+ * \code
+ * struct ast_json *json_variables = ast_json_pack("[ { s: s } ]", "foo", "bar");
+ * struct ast_variable *variables = NULL;
+ * int res;
+ *
+ * res = ast_json_to_ast_variables(json_variables, &variables);
+ * \endcode
+ *
+ * \retval 0 success
+ * \retval -1 error
+ */
 int ast_json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables);
 
 /*!@}*/

Modified: team/mjordan/12-messaging/include/asterisk/message.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/include/asterisk/message.h?view=diff&rev=418444&r1=418443&r2=418444
==============================================================================
--- team/mjordan/12-messaging/include/asterisk/message.h (original)
+++ team/mjordan/12-messaging/include/asterisk/message.h Sat Jul 12 21:46:22 2014
@@ -243,7 +243,7 @@
  */
 int __attribute__((format(printf, 2, 3)))
 		ast_msg_set_endpoint(struct ast_msg *msg, const char *fmt, ...);
-	
+
 /*!
  * \brief Set a variable on the message going to the dialplan.
  * \note Setting a variable that already exists overwrites the existing variable value

Modified: team/mjordan/12-messaging/main/json.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/main/json.c?view=diff&rev=418444&r1=418443&r2=418444
==============================================================================
--- team/mjordan/12-messaging/main/json.c (original)
+++ team/mjordan/12-messaging/main/json.c Sat Jul 12 21:46:22 2014
@@ -893,12 +893,12 @@
 		struct ast_variable *new_var;
 
 		new_var = ast_variable_new(ast_json_object_iter_key(it_json_var),
-								   ast_json_string_get(ast_json_object_iter_value(it_json_var)),
-								   "");
+		                           ast_json_string_get(ast_json_object_iter_value(it_json_var)),
+		                           "");
 		if (!new_var) {
 			ast_variables_destroy(*variables);
 			*variables = NULL;
-			return 1;
+			return -1;
 		}
 
 		ast_variable_list_append(variables, new_var);

Modified: team/mjordan/12-messaging/main/message.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/main/message.c?view=diff&rev=418444&r1=418443&r2=418444
==============================================================================
--- team/mjordan/12-messaging/main/message.c (original)
+++ team/mjordan/12-messaging/main/message.c Sat Jul 12 21:46:22 2014
@@ -209,19 +209,25 @@
 
 /*!
  * \brief A message.
- *
- * \todo Consider whether stringfields would be an appropriate optimization here.
  */
 struct ast_msg {
 	AST_DECLARE_STRING_FIELDS(
+		/*! Where the message is going */
 		AST_STRING_FIELD(to);
+		/*! Where we "say" the message came from */
 		AST_STRING_FIELD(from);
+		/*! The text to send */
 		AST_STRING_FIELD(body);
+		/*! The dialplan context for the message */
 		AST_STRING_FIELD(context);
+		/*! The dialplan extension for the message */
 		AST_STRING_FIELD(exten);
+		/*! An endpoint associated with this message */
 		AST_STRING_FIELD(endpoint);
+		/*! The technology of the endpoint associated with this message */
 		AST_STRING_FIELD(tech);
 	);
+	/*! Technology/dialplan specific variables associated with the message */
 	struct ao2_container *vars;
 };
 
@@ -1503,7 +1509,7 @@
 	}
 
 	ast_rwlock_init(&msg_handlers_lock);
-	if (AST_VECTOR_INIT(&msg_handlers, 8)) {
+	if (AST_VECTOR_INIT(&msg_handlers, 4)) {
 		return -1;
 	}
 

Modified: team/mjordan/12-messaging/res/ari/resource_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/res/ari/resource_endpoints.c?view=diff&rev=418444&r1=418443&r2=418444
==============================================================================
--- team/mjordan/12-messaging/res/ari/resource_endpoints.c (original)
+++ team/mjordan/12-messaging/res/ari/resource_endpoints.c Sat Jul 12 21:46:22 2014
@@ -99,7 +99,7 @@
 	if (!tech_endpoint) {
 		ast_ari_response_error(response, 404, "Not Found",
 				       "No Endpoints found - invalid tech %s", args->tech);
-		return;		
+		return;
 	}
 	ao2_ref(tech_endpoint, -1);
 
@@ -278,7 +278,3 @@
 
 	send_message(msg_to, args->from, args->body, variables, response);
 }
-
-
-
-

Modified: team/mjordan/12-messaging/res/res_ari.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/res/res_ari.c?view=diff&rev=418444&r1=418443&r2=418444
==============================================================================
--- team/mjordan/12-messaging/res/res_ari.c (original)
+++ team/mjordan/12-messaging/res/res_ari.c Sat Jul 12 21:46:22 2014
@@ -532,7 +532,6 @@
 
 	if (method < 0 || method >= AST_HTTP_MAX_METHOD) {
 		add_allow_header(handler, response);
-		ast_log(LOG_NOTICE, "@@@@ WTF!\n");
 		ast_ari_response_error(
 			response, 405, "Method Not Allowed",
 			"Invalid method");
@@ -551,7 +550,6 @@
 
 	callback = handler->callbacks[method];
 	if (callback == NULL) {
-		ast_log(LOG_NOTICE, "@@@@ BAH!\n");
 		add_allow_header(handler, response);
 		ast_ari_response_error(
 			response, 405, "Method Not Allowed",

Modified: team/mjordan/12-messaging/res/res_pjsip_messaging.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/res/res_pjsip_messaging.c?view=diff&rev=418444&r1=418443&r2=418444
==============================================================================
--- team/mjordan/12-messaging/res/res_pjsip_messaging.c (original)
+++ team/mjordan/12-messaging/res/res_pjsip_messaging.c Sat Jul 12 21:46:22 2014
@@ -464,7 +464,7 @@
 		return PJSIP_SC_INTERNAL_SERVER_ERROR;
 	}
 	buf[size] = '\0';
-	res |= ast_msg_set_from(msg, "%s", sip_to_pjsip(buf, ++size, sizeof(buf) - 1));
+	res |= ast_msg_set_from(msg, "%s", buf);
 
 	field = pj_sockaddr_print(&rdata->pkt_info.src_addr, buf, sizeof(buf) - 1, 1);
 	res |= ast_msg_set_var(msg, "PJSIP_RECVADDR", field);
@@ -520,15 +520,9 @@
 		return NULL;
 	}
 
-	if (!(from = strchr(from, ':'))) {
-		ao2_ref(mdata, -1);
-		return NULL;
-	}
-
-	/* if there is another sip in the uri then we are good,
-	   otherwise it needs a sip: in front */
+	/* Make sure we start with sip: */
 	mdata->to = ast_begins_with(to, "sip:") ? ast_strdup(++to) : ast_strdup(to - 3);
-	mdata->from = ast_begins_with(from, "from:") ? ast_strdup(++from) : ast_strdup(from - 3);
+	mdata->from = ast_strdup(from);
 
 	/* sometimes from can still contain the tag at this point, so remove it */
 	if ((tag = strchr(mdata->from, ';'))) {

Modified: team/mjordan/12-messaging/res/res_xmpp.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/res/res_xmpp.c?view=diff&rev=418444&r1=418443&r2=418444
==============================================================================
--- team/mjordan/12-messaging/res/res_xmpp.c (original)
+++ team/mjordan/12-messaging/res/res_xmpp.c Sat Jul 12 21:46:22 2014
@@ -3188,9 +3188,11 @@
 			res |= ast_msg_set_body(msg, "%s", message->message);
 			res |= ast_msg_set_context(msg, "%s", cfg->context);
 			res |= ast_msg_set_tech(msg, "%s", "XMPP");
-			res |= ast_msg_set_endpoint(msg, "%s%s%s", client->name,
-				buddy ? "/" : "",
-				buddy ? buddy->id : "");
+			res |= ast_msg_set_endpoint(msg, "%s", client->name);
+
+			if (buddy) {
+				res |= ast_msg_set_var(msg, "XMPP_BUDDY", buddy->id);
+			}
 
 			ao2_cleanup(buddy);
 

Modified: team/mjordan/12-messaging/res/stasis/app.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-messaging/res/stasis/app.c?view=diff&rev=418444&r1=418443&r2=418444
==============================================================================
--- team/mjordan/12-messaging/res/stasis/app.c (original)
+++ team/mjordan/12-messaging/res/stasis/app.c Sat Jul 12 21:46:22 2014
@@ -512,7 +512,7 @@
 		"endpoint", json_endpoint);
 }
 
-static int message_received_handler(const char *endpoint, enum messaging_direction direction, struct ast_json *json_msg, void *pvt)
+static int message_received_handler(const char *endpoint_id, struct ast_json *json_msg, void *pvt)
 {
 	RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
 	struct ast_json *json_endpoint;
@@ -520,7 +520,7 @@
 	char *tech;
 	char *resource;
 
-	tech = ast_strdupa(endpoint);
+	tech = ast_strdupa(endpoint_id);
 	resource = strchr(tech, '/');
 	if (resource) {
 		resource[0] = '\0';




More information about the asterisk-commits mailing list