[asterisk-commits] mmichelson: trunk r400683 - in /trunk: ./ res/res_pjsip/pjsip_options.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 8 10:44:49 CDT 2013


Author: mmichelson
Date: Tue Oct  8 10:44:47 2013
New Revision: 400683

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=400683
Log:
Push CLI qualify into the threadpool.

If you run Asterisk in the background and then connect to
it through a separate console, the thread that runs CLI commands
is not registered with PJLIB. Thus PJLIB does not like it when
you attempt to send OPTIONS requests from that thread. So now
we push the task into the threadpool, which we know to be registered
with PJLIB.

Thanks to Antti Yrjola for reporting this.
........

Merged revisions 400680 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/res/res_pjsip/pjsip_options.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/res/res_pjsip/pjsip_options.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/pjsip_options.c?view=diff&rev=400683&r1=400682&r2=400683
==============================================================================
--- trunk/res/res_pjsip/pjsip_options.c (original)
+++ trunk/res/res_pjsip/pjsip_options.c Tue Oct  8 10:44:47 2013
@@ -581,25 +581,58 @@
 static int cli_on_contact(void *obj, void *arg, int flags)
 {
 	struct ast_sip_contact *contact = obj;
-	struct ast_cli_args *a = arg;
-	ast_cli(a->fd, " contact %s\n", contact->uri);
+	int *cli_fd = arg;
+	ast_cli(*cli_fd, " contact %s\n", contact->uri);
 	qualify_contact(contact);
 	return 0;
 }
 
 /*!
+ * \brief Data pushed to threadpool to qualify endpoints from the CLI
+ */
+struct qualify_data {
+	/*! Endpoint that is being qualified */
+	struct ast_sip_endpoint *endpoint;
+	/*! CLI File descriptor for printing messages */
+	int cli_fd;
+};
+
+static struct qualify_data *qualify_data_alloc(struct ast_sip_endpoint *endpoint, int cli_fd)
+{
+	struct qualify_data *qual_data;
+
+	qual_data = ast_malloc(sizeof(*qual_data));
+	if (!qual_data) {
+		return NULL;
+	}
+
+	qual_data->endpoint = ao2_bump(endpoint);
+	qual_data->cli_fd = cli_fd;
+	return qual_data;
+}
+
+static void qualify_data_destroy(struct qualify_data *qual_data)
+{
+	ao2_cleanup(qual_data->endpoint);
+	ast_free(qual_data);
+}
+
+/*!
  * \internal
  * \brief For an endpoint iterate over and qualify all aors/contacts
  */
-static void cli_qualify_contacts(struct ast_cli_args *a, const char *endpoint_name,
-				 struct ast_sip_endpoint *endpoint)
+static int cli_qualify_contacts(void *data)
 {
 	char *aor_name, *aors;
+	RAII_VAR(struct qualify_data *, qual_data, data, qualify_data_destroy);
+	struct ast_sip_endpoint *endpoint = qual_data->endpoint;
+	int cli_fd = qual_data->cli_fd;
+	const char *endpoint_name = ast_sorcery_object_get_id(endpoint);
 
 	if (ast_strlen_zero(endpoint->aors)) {
-		ast_cli(a->fd, "Endpoint %s has no AoR's configured\n",
+		ast_cli(cli_fd, "Endpoint %s has no AoR's configured\n",
 			endpoint_name);
-		return;
+		return 0;
 	}
 
 	aors = ast_strdupa(endpoint->aors);
@@ -613,15 +646,17 @@
 			continue;
 		}
 
-		ast_cli(a->fd, "Sending qualify to endpoint %s\n", endpoint_name);
-		ao2_callback(contacts, OBJ_NODATA, cli_on_contact, a);
-	}
+		ast_cli(cli_fd, "Sending qualify to endpoint %s\n", endpoint_name);
+		ao2_callback(contacts, OBJ_NODATA, cli_on_contact, &cli_fd);
+	}
+	return 0;
 }
 
 static char *cli_qualify(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
 	const char *endpoint_name;
+	struct qualify_data *qual_data;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -646,8 +681,15 @@
 		return CLI_FAILURE;
 	}
 
-	/* send a qualify for all contacts registered with the endpoint */
-	cli_qualify_contacts(a, endpoint_name, endpoint);
+	qual_data = qualify_data_alloc(endpoint, a->fd);
+	if (!qual_data) {
+		return CLI_FAILURE;
+	}
+
+	if (ast_sip_push_task(NULL, cli_qualify_contacts, qual_data)) {
+		qualify_data_destroy(qual_data);
+		return CLI_FAILURE;
+	}
 
 	return CLI_SUCCESS;
 }




More information about the asterisk-commits mailing list