[asterisk-commits] kharwell: branch kharwell/stasis-http-conf r384283 - in /team/kharwell/stasis...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 28 12:18:03 CDT 2013


Author: kharwell
Date: Thu Mar 28 12:17:58 2013
New Revision: 384283

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384283
Log:
Resolved conflicts and fixed a few issues found during initial review.  Also added function shortcuts
for all the dump functions.

Multiple revisions 383776,383780,383783,383983,384107,384236

........
  r383776 | dlee | 2013-03-25 15:47:33 -0500 (Mon, 25 Mar 2013) | 2 lines
  
  Merged revisions 383323-383772 from http://svn.asterisk.org/svn/asterisk/team/dlee/stasis-app
........
  r383780 | dlee | 2013-03-25 16:02:13 -0500 (Mon, 25 Mar 2013) | 5 lines
  
  Missed a res_json dep
  ........
  
  Merged revisions 383779 from http://svn.asterisk.org/svn/asterisk/team/dlee/stasis-app
........
  r383783 | dlee | 2013-03-25 16:16:49 -0500 (Mon, 25 Mar 2013) | 5 lines
  
  Replaced functions lost in the merge from trunk
  ........
  
  Merged revisions 383781 from http://svn.asterisk.org/svn/asterisk/team/dlee/stasis-app
........
  r383983 | dlee | 2013-03-27 09:56:45 -0500 (Wed, 27 Mar 2013) | 1 line
  
  Fixed null derefernce in tests
........
  r384107 | dlee | 2013-03-27 13:30:11 -0500 (Wed, 27 Mar 2013) | 1 line
  
  Apparently, swagger prefers int to number.
........
  r384236 | dlee | 2013-03-27 22:50:10 -0500 (Wed, 27 Mar 2013) | 5 lines
  
  Merged revisions 383799-384219 from http://svn.asterisk.org/svn/asterisk/trunk
  ........
  
  Merged revisions 384235 from http://svn.asterisk.org/svn/asterisk/team/dlee/stasis-app
........

Merged revisions 383776,383780,383783,383983,384107,384236 from http://svn.asterisk.org/svn/asterisk/team/dlee/stasis-http

Added:
    team/kharwell/stasis-http-conf/main/json.c
      - copied, changed from r384236, team/dlee/stasis-http/main/json.c
    team/kharwell/stasis-http-conf/main/manager_channels.c
      - copied unchanged from r384236, team/dlee/stasis-http/main/manager_channels.c
Removed:
    team/kharwell/stasis-http-conf/res/res_json.c
    team/kharwell/stasis-http-conf/res/res_json.exports.in
Modified:
    team/kharwell/stasis-http-conf/   (props changed)
    team/kharwell/stasis-http-conf/CHANGES
    team/kharwell/stasis-http-conf/apps/app_meetme.c
    team/kharwell/stasis-http-conf/apps/app_mixmonitor.c
    team/kharwell/stasis-http-conf/apps/app_stasis.c
    team/kharwell/stasis-http-conf/apps/app_userevent.c
    team/kharwell/stasis-http-conf/channels/chan_dahdi.c
    team/kharwell/stasis-http-conf/channels/chan_iax2.c
    team/kharwell/stasis-http-conf/channels/chan_mgcp.c
    team/kharwell/stasis-http-conf/channels/chan_sip.c
    team/kharwell/stasis-http-conf/channels/chan_skinny.c
    team/kharwell/stasis-http-conf/channels/chan_unistim.c
    team/kharwell/stasis-http-conf/channels/sig_pri.c
    team/kharwell/stasis-http-conf/channels/sip/include/sip.h
    team/kharwell/stasis-http-conf/channels/sip/security_events.c
    team/kharwell/stasis-http-conf/codecs/Makefile
    team/kharwell/stasis-http-conf/cog/stasis_cog.py
    team/kharwell/stasis-http-conf/configure
    team/kharwell/stasis-http-conf/configure.ac
    team/kharwell/stasis-http-conf/contrib/scripts/install_prereq
    team/kharwell/stasis-http-conf/funcs/func_curl.c
    team/kharwell/stasis-http-conf/include/asterisk/app.h
    team/kharwell/stasis-http-conf/include/asterisk/astobj2.h
    team/kharwell/stasis-http-conf/include/asterisk/autoconfig.h.in
    team/kharwell/stasis-http-conf/include/asterisk/channel.h
    team/kharwell/stasis-http-conf/include/asterisk/json.h
    team/kharwell/stasis-http-conf/include/asterisk/manager.h
    team/kharwell/stasis-http-conf/include/asterisk/sorcery.h
    team/kharwell/stasis-http-conf/include/asterisk/stasis.h
    team/kharwell/stasis-http-conf/main/Makefile
    team/kharwell/stasis-http-conf/main/app.c
    team/kharwell/stasis-http-conf/main/asterisk.c
    team/kharwell/stasis-http-conf/main/cdr.c
    team/kharwell/stasis-http-conf/main/channel.c
    team/kharwell/stasis-http-conf/main/channel_internal_api.c
    team/kharwell/stasis-http-conf/main/format_pref.c
    team/kharwell/stasis-http-conf/main/http.c
    team/kharwell/stasis-http-conf/main/manager.c
    team/kharwell/stasis-http-conf/main/pbx.c
    team/kharwell/stasis-http-conf/main/sorcery.c
    team/kharwell/stasis-http-conf/main/stasis.c
    team/kharwell/stasis-http-conf/main/stasis_message_router.c
    team/kharwell/stasis-http-conf/pbx/pbx_realtime.c
    team/kharwell/stasis-http-conf/res/res_config_curl.c
    team/kharwell/stasis-http-conf/res/res_format_attr_h264.c
    team/kharwell/stasis-http-conf/res/res_jabber.c
    team/kharwell/stasis-http-conf/res/res_rtp_asterisk.c
    team/kharwell/stasis-http-conf/res/res_sorcery_memory.c
    team/kharwell/stasis-http-conf/res/res_stasis_http.c
    team/kharwell/stasis-http-conf/res/res_stasis_http.make
    team/kharwell/stasis-http-conf/res/res_stasis_websocket.c
    team/kharwell/stasis-http-conf/res/res_xmpp.c
    team/kharwell/stasis-http-conf/rest-api/bridges.json
    team/kharwell/stasis-http-conf/rest-api/channels.json
    team/kharwell/stasis-http-conf/tests/test_json.c
    team/kharwell/stasis-http-conf/tests/test_sorcery.c
    team/kharwell/stasis-http-conf/tests/test_stasis_http.c

Propchange: team/kharwell/stasis-http-conf/
------------------------------------------------------------------------------
Binary property 'branch-11-merged' - no diff available.

Propchange: team/kharwell/stasis-http-conf/
------------------------------------------------------------------------------
--- stasis-http-conf-integrated (original)
+++ stasis-http-conf-integrated Thu Mar 28 12:17:58 2013
@@ -1,1 +1,1 @@
-/team/dlee/stasis-http:1-383519
+/team/dlee/stasis-http:1-384262

Propchange: team/kharwell/stasis-http-conf/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Mar 28 12:17:58 2013
@@ -1,1 +1,1 @@
-/team/dlee/stasis-app:1-383317 /trunk:1-383057
+/team/dlee/stasis-app:1-384235 /trunk:1-384219

Modified: team/kharwell/stasis-http-conf/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/CHANGES?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/CHANGES (original)
+++ team/kharwell/stasis-http-conf/CHANGES Thu Mar 28 12:17:58 2013
@@ -40,6 +40,18 @@
    stopped, restarted, reversed, or skipped forward. When initiated by other
    mechanisms (such as the Playback application), the audio can be stopped,
    reversed, or skipped forward.
+
+ * Channel related events now contain a snapshot of channel state, adding new
+   fields to many of these events.
+
+ * The AMI event 'Newexten' field 'Extension' is deprecated, and may be removed
+   in a future release. Please use the common 'Exten' field instead.
+
+ * The AMI event 'UserEvent' from app_userevent now contains the channel state
+   fields. The channel state fields will come before the body fields.
+
+ * The deprecated use of | (pipe) as a separator in the channelvars setting in
+   manager.conf has been removed.
 
 Channel Drivers
 ------------------

Modified: team/kharwell/stasis-http-conf/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/apps/app_meetme.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/apps/app_meetme.c (original)
+++ team/kharwell/stasis-http-conf/apps/app_meetme.c Thu Mar 28 12:17:58 2013
@@ -5926,7 +5926,16 @@
 			ringing_trunk = sla_choose_ringing_trunk(ringing_station->station, &s_trunk_ref, 1);
 			ast_mutex_unlock(&sla.lock);
 			if (!ringing_trunk) {
+				/* This case happens in a bit of a race condition.  If two stations answer
+				 * the outbound call at the same time, the first one will get connected to
+				 * the trunk.  When the second one gets here, it will not see any trunks
+				 * ringing so we have no idea what to conect it to.  So, we just hang up
+				 * on it. */
 				ast_debug(1, "Found no ringing trunk for station '%s' to answer!\n", ringing_station->station->name);
+				ast_dial_join(ringing_station->station->dial);
+				ast_dial_destroy(ringing_station->station->dial);
+				ringing_station->station->dial = NULL;
+				ast_free(ringing_station);
 				break;
 			}
 			/* Track the channel that answered this trunk */

Modified: team/kharwell/stasis-http-conf/apps/app_mixmonitor.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/apps/app_mixmonitor.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/apps/app_mixmonitor.c (original)
+++ team/kharwell/stasis-http-conf/apps/app_mixmonitor.c Thu Mar 28 12:17:58 2013
@@ -1042,7 +1042,7 @@
 	return 0;
 }
 
-static int stop_mixmonitor_exec(struct ast_channel *chan, const char *data)
+static int stop_mixmonitor_full(struct ast_channel *chan, const char *data)
 {
 	struct ast_datastore *datastore = NULL;
 	char *parse = "";
@@ -1093,6 +1093,12 @@
 	}
 	ast_channel_unlock(chan);
 
+	return 0;
+}
+
+static int stop_mixmonitor_exec(struct ast_channel *chan, const char *data)
+{
+	stop_mixmonitor_full(chan, data);
 	return 0;
 }
 
@@ -1315,7 +1321,7 @@
 		return AMI_SUCCESS;
 	}
 
-	res = stop_mixmonitor_exec(c, mixmonitor_id);
+	res = stop_mixmonitor_full(c, mixmonitor_id);
 
 	if (res) {
 		astman_send_error(s, m, "Could not stop monitoring channel");

Modified: team/kharwell/stasis-http-conf/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/apps/app_stasis.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/apps/app_stasis.c (original)
+++ team/kharwell/stasis-http-conf/apps/app_stasis.c Thu Mar 28 12:17:58 2013
@@ -24,7 +24,6 @@
  */
 
 /*** MODULEINFO
-	<depend>res_json</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -103,7 +102,7 @@
 	return __app_controls;
 }
 
-struct stasis_app {
+struct app {
 	/*! Callback function for this application. */
 	stasis_app_cb handler;
 	/*! Opaque data to hand to callback function. */
@@ -112,11 +111,10 @@
 	char name[];
 };
 
-/*! Constructor for \ref stasis_app. */
-static struct stasis_app *app_create(const char *name, stasis_app_cb handler,
-				     void *data)
-{
-	struct stasis_app *app;
+/*! Constructor for \ref app. */
+static struct app *app_create(const char *name, stasis_app_cb handler, void *data)
+{
+	struct app *app;
 	size_t size;
 
 	ast_assert(name != NULL);
@@ -139,7 +137,7 @@
 /*! AO2 hash function for \ref stasis_app */
 static int app_hash(const void *obj, const int flags)
 {
-	const struct stasis_app *app = obj;
+	const struct app *app = obj;
 	const char *name = flags & OBJ_KEY ? obj : app->name;
 
 	return ast_str_hash(name);
@@ -148,8 +146,8 @@
 /*! AO2 comparison function for \ref stasis_app */
 static int app_compare(void *lhs, void *rhs, int flags)
 {
-	const struct stasis_app *lhs_app = lhs;
-	const struct stasis_app *rhs_app = rhs;
+	const struct app *lhs_app = lhs;
+	const struct app *rhs_app = rhs;
 	const char *rhs_name = flags & OBJ_KEY ? rhs : rhs_app->name;
 
 	if (strcmp(lhs_app->name, rhs_name) == 0) {
@@ -164,7 +162,7 @@
  * \param app App to send the message to.
  * \param message Message to send.
  */
-static void app_send(struct stasis_app *app, struct ast_json *message)
+static void app_send(struct app *app, struct ast_json *message)
 {
 	app->handler(app->data, app->name, message);
 }
@@ -404,8 +402,7 @@
 	return ast_json_ref(message);
 }
 
-static int send_start_msg(struct stasis_app *app, struct ast_channel *chan,
-			  int argc, char *argv[])
+static int send_start_msg(struct app *app, struct ast_channel *chan, int argc, char *argv[])
 {
 	RAII_VAR(struct ast_json *, msg_info, NULL, ast_json_unref);
 	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
@@ -451,7 +448,7 @@
 	return 0;
 }
 
-static int send_end_msg(struct stasis_app *app, struct ast_channel *chan)
+static int send_end_msg(struct app *app, struct ast_channel *chan)
 {
 	RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
 	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
@@ -464,25 +461,29 @@
 		return -1;
 	}
 	msg = stasis_app_event_create("stasis-end", snapshot, NULL);
+	if (!msg) {
+		return -1;
+	}
 
 	app_send(app, msg);
 	return 0;
 }
 
 static void sub_handler(void *data, struct stasis_subscription *sub,
-			struct stasis_topic *topic, struct stasis_message *msg)
-{
-	struct stasis_app *app = data;
-	if (ast_channel_snapshot() == stasis_message_type(msg)) {
-		RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
-		struct ast_channel_snapshot *snapshot =
-			stasis_message_data(msg);
-
-		json = stasis_app_event_create("channel-state-change", snapshot,
-					       NULL);
-		app_send(app, json);
-	}
-	if (stasis_subscription_final_message(sub, msg)) {
+			struct stasis_topic *topic, struct stasis_message *message)
+{
+	struct app *app = data;
+	if (ast_channel_snapshot() == stasis_message_type(message)) {
+		RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
+		struct ast_channel_snapshot *snapshot =	stasis_message_data(message);
+
+		msg = stasis_app_event_create("channel-state-change", snapshot, NULL);
+		if (!msg) {
+			return;
+		}
+		app_send(app, msg);
+	}
+	if (stasis_subscription_final_message(sub, message)) {
 		ao2_cleanup(data);
 	}
 }
@@ -529,7 +530,7 @@
 static int app_stasis_exec(struct ast_channel *chan, const char *data)
 {
 	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
-	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
+	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_app_control *, control, NULL, control_unlink);
 	RAII_VAR(struct stasis_subscription *, subscription, NULL,
 		 stasis_unsubscribe);
@@ -652,7 +653,7 @@
 int stasis_app_send(const char *app_name, struct ast_json *message)
 {
 	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
-	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
+	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
 
 	app = ao2_find(apps, app_name, OBJ_KEY);
 
@@ -672,7 +673,7 @@
 int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data)
 {
 	RAII_VAR(struct ao2_container *, apps, apps_registry(), ao2_cleanup);
-	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
+	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
 
 	SCOPED_LOCK(apps_lock, apps, ao2_lock, ao2_unlock);
 
@@ -747,5 +748,4 @@
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS,
 		"Stasis dialplan application",
 		.load = load_module,
-		.unload = unload_module,
-		.nonoptreq = "res_json");
+		.unload = unload_module);

Modified: team/kharwell/stasis-http-conf/apps/app_userevent.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/apps/app_userevent.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/apps/app_userevent.c (original)
+++ team/kharwell/stasis-http-conf/apps/app_userevent.c Thu Mar 28 12:17:58 2013
@@ -33,6 +33,7 @@
 #include "asterisk/module.h"
 #include "asterisk/manager.h"
 #include "asterisk/app.h"
+#include "asterisk/json.h"
 
 /*** DOCUMENTATION
 	<application name="UserEvent" language="en_US">
@@ -68,11 +69,12 @@
 		AST_APP_ARG(eventname);
 		AST_APP_ARG(extra)[100];
 	);
-	struct ast_str *body = ast_str_create(16);
+	RAII_VAR(struct ast_str *, body, ast_str_create(16), ast_free);
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
-		ast_free(body);
 		return -1;
 	}
 
@@ -89,24 +91,21 @@
 		ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
 	}
 
-	/*** DOCUMENTATION
-	<managerEventInstance>
-		<synopsis>A user defined event raised from the dialplan.</synopsis>
-		<parameter name="UserEvent">
-			<para>The event name, as specified in the dialplan.</para>
-		</parameter>
-		<see-also>
-			<ref type="application">UserEvent</ref>
-		</see-also>
-	</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_USER, "UserEvent",
-			"UserEvent: %s\r\n"
-			"Uniqueid: %s\r\n"
-			"%s",
-			args.eventname, ast_channel_uniqueid(chan), ast_str_buffer(body));
+	blob = ast_json_pack("{s: s, s: s, s: s}",
+			     "type", "userevent",
+			     "eventname", args.eventname,
+			     "body", ast_str_buffer(body));
+	if (!blob) {
+		ast_log(LOG_WARNING, "Unable to create message buffer\n");
+		return -1;
+	}
 
-	ast_free(body);
+	msg = ast_channel_blob_create(chan, blob);
+	if (!msg) {
+		return -1;
+	}
+
+	stasis_publish(ast_channel_topic(chan), msg);
 
 	return 0;
 }

Modified: team/kharwell/stasis-http-conf/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/channels/chan_dahdi.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/channels/chan_dahdi.c (original)
+++ team/kharwell/stasis-http-conf/channels/chan_dahdi.c Thu Mar 28 12:17:58 2013
@@ -5414,7 +5414,7 @@
 	}
 
 	ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
-	mwi_message = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
+	mwi_message = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
 
 	if (mwi_message) {
 		struct stasis_mwi_state *mwi_state = stasis_message_data(mwi_message);

Modified: team/kharwell/stasis-http-conf/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/channels/chan_iax2.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/channels/chan_iax2.c (original)
+++ team/kharwell/stasis-http-conf/channels/chan_iax2.c Thu Mar 28 12:17:58 2013
@@ -8755,7 +8755,7 @@
 			}
 
 			ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
-			msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
+			msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
 
 			if (msg) {
 				struct stasis_mwi_state *mwi_state = stasis_message_data(msg);

Modified: team/kharwell/stasis-http-conf/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/channels/chan_mgcp.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/channels/chan_mgcp.c (original)
+++ team/kharwell/stasis-http-conf/channels/chan_mgcp.c Thu Mar 28 12:17:58 2013
@@ -507,7 +507,7 @@
 
 	ast_str_set(&uniqueid, 0, "%s@%s", mbox, cntx);
 
-	msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
+	msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
 
 	if (msg) {
 		struct stasis_mwi_state *mwi_state = stasis_message_data(msg);

Modified: team/kharwell/stasis-http-conf/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/channels/chan_sip.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/channels/chan_sip.c (original)
+++ team/kharwell/stasis-http-conf/channels/chan_sip.c Thu Mar 28 12:17:58 2013
@@ -1009,6 +1009,11 @@
 static struct ao2_container *peers;
 static struct ao2_container *peers_by_ip;
 
+/*! \brief  A bogus peer, to be used when authentication should fail */
+static struct sip_peer *bogus_peer;
+/*! \brief  We can recognise the bogus peer by this invalid MD5 hash */
+#define BOGUS_PEER_MD5SECRET "intentionally_invalid_md5_string"
+
 /*! \brief  The register list: Other SIP proxies we register with and receive calls from */
 static struct ast_register_list {
 	ASTOBJ_CONTAINER_COMPONENTS(struct sip_registry);
@@ -1157,7 +1162,7 @@
 static int transmit_response_with_auth(struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *rand, enum xmittype reliable, const char *header, int stale);
 static int transmit_provisional_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, int with_sdp);
 static int transmit_response_with_allow(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
-static void transmit_fake_auth_response(struct sip_pvt *p, int sipmethod, struct sip_request *req, enum xmittype reliable);
+static void transmit_fake_auth_response(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable);
 static int transmit_request(struct sip_pvt *p, int sipmethod, uint32_t seqno, enum xmittype reliable, int newbranch);
 static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, uint32_t seqno, enum xmittype reliable, int newbranch);
 static int transmit_publish(struct sip_epa_entry *epa_entry, enum sip_publish_type publish_type, const char * const explicit_uri);
@@ -16131,7 +16136,9 @@
 		ast_verb(3, "Registered SIP '%s' at %s\n", peer->name,
 			ast_sockaddr_stringify(&peer->addr));
 	}
+	sip_pvt_unlock(pvt);
 	sip_poke_peer(peer, 0);
+	sip_pvt_lock(pvt);
 	register_peer_exten(peer, 1);
 
 	/* Save User agent */
@@ -16477,6 +16484,7 @@
 	char a1_hash[256];
 	char resp_hash[256]="";
 	char *c;
+	int is_bogus_peer = 0;
 	int  wrongnonce = FALSE;
 	int  good_response;
 	const char *usednonce = p->nonce;
@@ -16548,8 +16556,14 @@
 
 	sip_digest_parser(c, keys);
 
+	/* We cannot rely on the bogus_peer having a bad md5 value. Someone could
+	 * use it to construct valid auth. */
+	if (md5secret && strcmp(md5secret, BOGUS_PEER_MD5SECRET) == 0) {
+		is_bogus_peer = 1;
+	}
+
 	/* Verify that digest username matches  the username we auth as */
-	if (strcmp(username, keys[K_USER].s)) {
+	if (strcmp(username, keys[K_USER].s) && !is_bogus_peer) {
 		ast_log(LOG_WARNING, "username mismatch, have <%s>, digest has <%s>\n",
 			username, keys[K_USER].s);
 		/* Oops, we're trying something here */
@@ -16588,7 +16602,8 @@
 	}
 
 	good_response = keys[K_RESP].s &&
-			!strncasecmp(keys[K_RESP].s, resp_hash, strlen(resp_hash));
+			!strncasecmp(keys[K_RESP].s, resp_hash, strlen(resp_hash)) &&
+			!is_bogus_peer; /* lastly, check that the peer isn't the fake peer */
 	if (wrongnonce) {
 		if (good_response) {
 			if (sipdebug)
@@ -16653,7 +16668,7 @@
 		ao2_cleanup(peer);
 		return;
 	}
-	if (stasis_mwi_state_message() == stasis_message_type(msg)) {
+	if (stasis_mwi_state_type() == stasis_message_type(msg)) {
 		sip_send_mwi_to_peer(peer, 0);
 	}
 }
@@ -16819,13 +16834,13 @@
 /*! \brief Send a fake 401 Unauthorized response when the administrator
   wants to hide the names of local devices  from fishers
  */
-static void transmit_fake_auth_response(struct sip_pvt *p, int sipmethod, struct sip_request *req, enum xmittype reliable)
+static void transmit_fake_auth_response(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable)
 {
 	/* We have to emulate EXACTLY what we'd get with a good peer
 	 * and a bad password, or else we leak information. */
-	const char *response = "407 Proxy Authentication Required";
-	const char *reqheader = "Proxy-Authorization";
-	const char *respheader = "Proxy-Authenticate";
+	const char *response = "401 Unauthorized";
+	const char *reqheader = "Authorization";
+	const char *respheader = "WWW-Authenticate";
 	const char *authtoken;
 	struct ast_str *buf;
 	char *c;
@@ -16840,36 +16855,31 @@
 		[K_LAST] = { NULL, NULL}
 	};
 
-	if (sipmethod == SIP_REGISTER || sipmethod == SIP_SUBSCRIBE) {
-		response = "401 Unauthorized";
-		reqheader = "Authorization";
-		respheader = "WWW-Authenticate";
-	}
 	authtoken = sip_get_header(req, reqheader);
 	if (req->ignore && !ast_strlen_zero(p->nonce) && ast_strlen_zero(authtoken)) {
 		/* This is a retransmitted invite/register/etc, don't reconstruct authentication
 		 * information */
-		transmit_response_with_auth(p, response, req, p->nonce, 0, respheader, 0);
+		transmit_response_with_auth(p, response, req, p->nonce, reliable, respheader, 0);
 		/* Schedule auto destroy in 32 seconds (according to RFC 3261) */
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 		return;
 	} else if (ast_strlen_zero(p->nonce) || ast_strlen_zero(authtoken)) {
 		/* We have no auth, so issue challenge and request authentication */
 		build_nonce(p, 1);
-		transmit_response_with_auth(p, response, req, p->nonce, 0, respheader, 0);
+		transmit_response_with_auth(p, response, req, p->nonce, reliable, respheader, 0);
 		/* Schedule auto destroy in 32 seconds */
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 		return;
 	}
 
 	if (!(buf = ast_str_thread_get(&check_auth_buf, CHECK_AUTH_BUF_INITLEN))) {
-		transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq);
+		__transmit_response(p, "403 Forbidden", &p->initreq, reliable);
 		return;
 	}
 
 	/* Make a copy of the response and parse it */
 	if (ast_str_set(&buf, 0, "%s", authtoken) == AST_DYNSTR_BUILD_FAILED) {
-		transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq);
+		__transmit_response(p, "403 Forbidden", &p->initreq, reliable);
 		return;
 	}
 
@@ -16907,7 +16917,7 @@
 		/* Schedule auto destroy in 32 seconds */
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 	} else {
-		transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq);
+		__transmit_response(p, "403 Forbidden", &p->initreq, reliable);
 	}
 }
 
@@ -17017,7 +17027,7 @@
 	if (!AST_LIST_EMPTY(&domain_list)) {
 		if (!check_sip_domain(domain, NULL, 0)) {
 			if (sip_cfg.alwaysauthreject) {
-				transmit_fake_auth_response(p, SIP_REGISTER, &p->initreq, XMIT_UNRELIABLE);
+				transmit_fake_auth_response(p, &p->initreq, XMIT_UNRELIABLE);
 			} else {
 				transmit_response(p, "404 Not found (unknown domain)", &p->initreq);
 			}
@@ -17043,6 +17053,13 @@
 		}
 	}
 	peer = sip_find_peer(name, NULL, TRUE, FINDPEERS, FALSE, 0);
+
+	/* If we don't want username disclosure, use the bogus_peer when a user
+	 * is not found. */
+	if (!peer && sip_cfg.alwaysauthreject && sip_cfg.autocreatepeer == AUTOPEERS_DISABLED) {
+		peer = bogus_peer;
+		sip_ref_peer(peer, "register_verify: ref the bogus_peer");
+	}
 
 	if (!(peer && ast_apply_acl(peer->acl, addr, "SIP Peer ACL: "))) {
 		/* Peer fails ACL check */
@@ -17135,7 +17152,7 @@
 			switch (parse_register_contact(p, peer, req)) {
 			case PARSE_REGISTER_DENIED:
 				ast_log(LOG_WARNING, "Registration denied because of contact ACL\n");
-				transmit_response_with_date(p, "403 Forbidden (ACL)", req);
+				transmit_response_with_date(p, "403 Forbidden", req);
 				res = 0;
 				break;
 			case PARSE_REGISTER_FAILED:
@@ -17163,9 +17180,9 @@
 	}
 	if (!res) {
 		if (send_mwi) {
-			ao2_unlock(p);
+			sip_pvt_unlock(p);
 			sip_send_mwi_to_peer(peer, 0);
-			ao2_lock(p);
+			sip_pvt_lock(p);
 		} else {
 			update_peer_lastmsgssent(peer, -1, 0);
 		}
@@ -17175,7 +17192,7 @@
 		switch (res) {
 		case AUTH_SECRET_FAILED:
 			/* Wrong password in authentication. Go away, don't try again until you fixed it */
-			transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq);
+			transmit_response(p, "403 Forbidden", &p->initreq);
 			if (global_authfailureevents) {
 				const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
 				const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
@@ -17198,7 +17215,7 @@
 		case AUTH_PEER_NOT_DYNAMIC:
 		case AUTH_ACL_FAILED:
 			if (sip_cfg.alwaysauthreject) {
-				transmit_fake_auth_response(p, SIP_REGISTER, &p->initreq, XMIT_UNRELIABLE);
+				transmit_fake_auth_response(p, &p->initreq, XMIT_UNRELIABLE);
 				if (global_authfailureevents) {
 					const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
 					const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
@@ -18237,7 +18254,19 @@
 			ast_verbose("No matching peer for '%s' from '%s'\n",
 				of, ast_sockaddr_stringify(&p->recv));
 		}
-		return AUTH_DONT_KNOW;
+
+		/* If you don't mind, we can return 404s for devices that do
+		 * not exist: username disclosure. If we allow guests, there
+		 * is no way around that. */
+		if (sip_cfg.allowguest || !sip_cfg.alwaysauthreject) {
+			return AUTH_DONT_KNOW;
+		}
+
+		/* If you do mind, we use a peer that will never authenticate.
+		 * This ensures that we follow the same code path as regular
+		 * auth: less chance for username disclosure. */
+		peer = bogus_peer;
+		sip_ref_peer(peer, "sip_ref_peer: check_peer_ok: must ref bogus_peer so unreffing it does not fail");
 	}
 
 	/*  build_peer, called through sip_find_peer, is not able to check the
@@ -18260,9 +18289,10 @@
 		sip_unref_peer(peer, "sip_unref_peer: check_peer_ok: from sip_find_peer call, early return of AUTH_ACL_FAILED");
 		return AUTH_ACL_FAILED;
 	}
-	if (debug)
+	if (debug && peer != bogus_peer) {
 		ast_verbose("Found peer '%s' for '%s' from %s\n",
 			peer->name, of, ast_sockaddr_stringify(&p->recv));
+	}
 
 	/* XXX what about p->prefs = peer->prefs; ? */
 	/* Set Frame packetization */
@@ -18545,8 +18575,6 @@
 		} else {
 			res = AUTH_RTP_FAILED;
 		}
-	} else if (sip_cfg.alwaysauthreject) {
-		res = AUTH_FAKE_AUTH; /* reject with fake authorization request */
 	} else {
 		res = AUTH_SECRET_FAILED; /* we don't want any guests, authentication will fail */
 	}
@@ -18681,13 +18709,8 @@
 			return;
 		}
 		if (res < 0) { /* Something failed in authentication */
-			if (res == AUTH_FAKE_AUTH) {
-				ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", sip_get_header(req, "From"));
-				transmit_fake_auth_response(p, SIP_MESSAGE, req, XMIT_UNRELIABLE);
-			} else {
-				ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", sip_get_header(req, "From"));
-				transmit_response(p, "403 Forbidden", req);
-			}
+			ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", sip_get_header(req, "From"));
+			transmit_response(p, "403 Forbidden", req);
 			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 			return;
 		}
@@ -24845,13 +24868,8 @@
 			return 0;
 		}
 		if (res < 0) { /* Something failed in authentication */
-			if (res == AUTH_FAKE_AUTH) {
-				ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", sip_get_header(req, "From"));
-				transmit_fake_auth_response(p, SIP_OPTIONS, req, XMIT_UNRELIABLE);
-			} else {
-				ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", sip_get_header(req, "From"));
-				transmit_response(p, "403 Forbidden", req);
-			}
+			ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", sip_get_header(req, "From"));
+			transmit_response(p, "403 Forbidden", req);
 			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 			return 0;
 		}
@@ -25496,13 +25514,8 @@
 			goto request_invite_cleanup;
 		}
 		if (res < 0) { /* Something failed in authentication */
-			if (res == AUTH_FAKE_AUTH) {
-				ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", sip_get_header(req, "From"));
-				transmit_fake_auth_response(p, SIP_INVITE, req, XMIT_RELIABLE);
-			} else {
-				ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", sip_get_header(req, "From"));
-				transmit_response_reliable(p, "403 Forbidden", req);
-			}
+			ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", sip_get_header(req, "From"));
+			transmit_response_reliable(p, "403 Forbidden", req);
 			p->invitestate = INV_COMPLETED;
 			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 			goto request_invite_cleanup;
@@ -25670,7 +25683,7 @@
 
 	/* Session-Timers */
 	if ((p->sipoptions & SIP_OPT_TIMER)) {
-		enum st_refresher_param st_ref_param;
+		enum st_refresher_param st_ref_param = SESSION_TIMER_REFRESHER_PARAM_UNKNOWN;
 
 		/* The UAC has requested session-timers for this session. Negotiate
 		the session refresh interval and who will be the refresher */
@@ -27545,18 +27558,13 @@
 		return -1;
 	}
 
-	auth_result = check_user(p, req, SIP_PUBLISH, uri, XMIT_RELIABLE, addr);
+	auth_result = check_user(p, req, SIP_PUBLISH, uri, XMIT_UNRELIABLE, addr);
 	if (auth_result == AUTH_CHALLENGE_SENT) {
 		p->lastinvite = seqno;
 		return 0;
 	} else if (auth_result < 0) {
-		if (auth_result == AUTH_FAKE_AUTH) {
-			ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", sip_get_header(req, "From"));
-			transmit_fake_auth_response(p, SIP_INVITE, req, XMIT_RELIABLE);
-		} else {
-			ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", sip_get_header(req, "From"));
-			transmit_response_reliable(p, "403 Forbidden", req);
-		}
+		ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", sip_get_header(req, "From"));
+		transmit_response(p, "403 Forbidden", req);
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 		ast_string_field_set(p, theirtag, NULL);
 		return 0;
@@ -27768,19 +27776,14 @@
 	 * use if !req->ignore, because then we'll end up sending
 	 * a 200 OK if someone retransmits without sending auth */
 	if (p->subscribed == NONE || resubscribe) {
-		res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, addr, &authpeer);
+		res = check_user_full(p, req, SIP_SUBSCRIBE, e, XMIT_UNRELIABLE, addr, &authpeer);
 
 		/* if an authentication response was sent, we are done here */
 		if (res == AUTH_CHALLENGE_SENT)	/* authpeer = NULL here */
 			return 0;
 		if (res != AUTH_SUCCESSFUL) {
-			if (res == AUTH_FAKE_AUTH) {
-				ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", sip_get_header(req, "From"));
-				transmit_fake_auth_response(p, SIP_SUBSCRIBE, req, XMIT_UNRELIABLE);
-			} else {
-				ast_log(LOG_NOTICE, "Failed to authenticate device %s for SUBSCRIBE\n", sip_get_header(req, "From"));
-				transmit_response_reliable(p, "403 Forbidden", req);
-			}
+			ast_log(LOG_NOTICE, "Failed to authenticate device %s for SUBSCRIBE\n", sip_get_header(req, "From"));
+			transmit_response(p, "403 Forbidden", req);
 
 			pvt_set_needdestroy(p, "authentication failed");
 			return 0;
@@ -28846,7 +28849,7 @@
 		ast_str_reset(uniqueid);
 		ast_str_set(&uniqueid, 0, "%s@%s", mailbox->mailbox, S_OR(mailbox->context, "default"));
 
-		msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_message(), ast_str_buffer(uniqueid));
+		msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), ast_str_buffer(uniqueid));
 		if (!msg) {
 			continue;
 		}
@@ -29611,6 +29614,9 @@
 \note	This is done with 60 seconds between each ping,
 	unless forced by cli or manager. If peer is unreachable,
 	we check every 10th second by default.
+\note Do *not* hold a pvt lock while calling this function.
+	This function calls sip_alloc, which can cause a deadlock
+	if another sip_pvt is held.
 */
 static int sip_poke_peer(struct sip_peer *peer, int force)
 {
@@ -33310,6 +33316,7 @@
 /*! \brief Force reload of module from cli */
 static char *sip_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
+	static struct sip_peer *tmp_peer, *new_peer;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -33331,6 +33338,18 @@
 	}
 	ast_mutex_unlock(&sip_reload_lock);
 	restart_monitor();
+
+	tmp_peer = bogus_peer;
+	/* Create new bogus peer possibly with new global settings. */
+	if ((new_peer = temp_peer("(bogus_peer)"))) {
+		ast_string_field_set(new_peer, md5secret, BOGUS_PEER_MD5SECRET);
+		ast_clear_flag(&new_peer->flags[0], SIP_INSECURE);
+		bogus_peer = new_peer;
+		ao2_t_ref(tmp_peer, -1, "unref the old bogus_peer during reload");
+	} else {
+		ast_log(LOG_ERROR, "Could not update the fake authentication peer.\n");
+		/* You probably have bigger (memory?) issues to worry about though.. */
+	}
 
 	return CLI_SUCCESS;
 }
@@ -34559,6 +34578,17 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
+	/* Initialize bogus peer. Can be done first after reload_config() */
+	if (!(bogus_peer = temp_peer("(bogus_peer)"))) {
+		ast_log(LOG_ERROR, "Unable to create bogus_peer for authentication\n");
+		io_context_destroy(io);
+		ast_sched_context_destroy(sched);
+		return AST_MODULE_LOAD_FAILURE;
+	}
+	/* Make sure the auth will always fail. */
+	ast_string_field_set(bogus_peer, md5secret, BOGUS_PEER_MD5SECRET);
+	ast_clear_flag(&bogus_peer->flags[0], SIP_INSECURE);
+
 	/* Prepare the version that does not require DTMF BEGIN frames.
 	 * We need to use tricks such as memcpy and casts because the variable
 	 * has const fields.
@@ -34574,6 +34604,7 @@
 	/* Make sure we can register our sip channel type */
 	if (ast_channel_register(&sip_tech)) {
 		ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n");
+		ao2_t_ref(bogus_peer, -1, "unref the bogus_peer");
 		io_context_destroy(io);
 		ast_sched_context_destroy(sched);
 		return AST_MODULE_LOAD_FAILURE;
@@ -34836,6 +34867,8 @@
 		ast_debug(2, "TCP/TLS thread container did not become empty :(\n");
 	}
 
+	ao2_t_ref(bogus_peer, -1, "unref the bogus_peer");
+
 	ao2_t_ref(peers, -1, "unref the peers table");
 	ao2_t_ref(peers_by_ip, -1, "unref the peers_by_ip table");
 	ao2_t_ref(dialogs, -1, "unref the dialogs table");

Modified: team/kharwell/stasis-http-conf/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/channels/chan_skinny.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/channels/chan_skinny.c (original)
+++ team/kharwell/stasis-http-conf/channels/chan_skinny.c Thu Mar 28 12:17:58 2013
@@ -3518,7 +3518,7 @@
 		return;
 	}
 
-	if (msg && stasis_mwi_state_message() == stasis_message_type(msg)) {
+	if (msg && stasis_mwi_state_type() == stasis_message_type(msg)) {
 		struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
 		l->newmsgs = mwi_state->new_msgs;
 	}
@@ -6254,12 +6254,14 @@
 	struct ast_channel *c;
 	int event;
 	int instance;
+#ifdef AST_DEVMODE
 	int callreference;
-	/*int res = 0;*/
+	/* This is only used in AST_DEVMODE, as an argument to SKINNY_DEBUG */
+	callreference = letohl(req->data.stimulus.callreference);
+#endif
 
 	event = letohl(req->data.stimulus.stimulus);
 	instance = letohl(req->data.stimulus.stimulusInstance);
-	callreference = letohl(req->data.stimulus.callreference);
 
 	/*  Note that this call should be using the passed in instance and callreference */
 	sub = find_subchannel_by_instance_reference(d, d->lastlineinstance, d->lastcallreference);
@@ -7111,13 +7113,6 @@
 	case SOFTKEY_ENDCALL:
 		SKINNY_DEBUG(DEBUG_PACKET, 3, "Received SOFTKEY_ENDCALL from %s, inst %d, callref %d\n",
 			d->name, instance, callreference);
-
-		if (l->transfer && sub && sub->xferor && ast_channel_state(sub->owner) >= AST_STATE_RING) {
-			/* We're allowed to transfer, we have two active calls and
-			    we made at least one of the calls.  Let's try and transfer */
-			handle_transfer_button(sub);
-			return 0;
-		}
 
 		ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, "Skinny/%s", l->name);
 
@@ -8571,6 +8566,9 @@
 		   We do not want to free the line here, that
 		   will happen below. */
 		while ((l = AST_LIST_REMOVE_HEAD(&d->lines, list))) {
+			if (l->mwi_event_sub) {
+				l->mwi_event_sub = stasis_unsubscribe(l->mwi_event_sub);
+			}
 		}
 		/* Delete all speeddials for this device */
 		while ((sd = AST_LIST_REMOVE_HEAD(&d->speeddials, list))) {

Modified: team/kharwell/stasis-http-conf/channels/chan_unistim.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/stasis-http-conf/channels/chan_unistim.c?view=diff&rev=384283&r1=384282&r2=384283
==============================================================================
--- team/kharwell/stasis-http-conf/channels/chan_unistim.c (original)

[... 2975 lines stripped ...]



More information about the asterisk-commits mailing list