[asterisk-commits] mmichelson: branch mmichelson/outbound_auth r383391 - in /team/mmichelson/out...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 19 14:29:44 CDT 2013
Author: mmichelson
Date: Tue Mar 19 14:29:42 2013
New Revision: 383391
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383391
Log:
Add a CLI method for sending OPTIONS requests.
This may seem unrelated to outbound auth, but it's a good way of
testing sending out-of-dialog requests to an endpoint.
The next step will be adding what is necessary to handle outbound
auth for out of dialog requests.
Modified:
team/mmichelson/outbound_auth/res/res_sip.c
team/mmichelson/outbound_auth/res/res_sip/sip_options.c
Modified: team/mmichelson/outbound_auth/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip.c?view=diff&rev=383391&r1=383390&r2=383391
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip.c Tue Mar 19 14:29:42 2013
@@ -490,28 +490,37 @@
contact = ast_sip_location_retrieve_contact_from_aor_list(endpoint->aors);
if (!contact || ast_strlen_zero(contact->uri)) {
+ ast_log(LOG_ERROR, "Unable to retrieve contact for endpoint %s\n",
+ ast_sorcery_object_get_id(endpoint));
return -1;
}
pj_cstr(&remote_uri, contact->uri);
if (sip_get_tpselector_from_endpoint(endpoint, &selector)) {
+ ast_log(LOG_ERROR, "Unable to retrieve PJSIP transport selector for endpoint %s\n",
+ ast_sorcery_object_get_id(endpoint));
return -1;
}
pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Outbound request", 256, 256);
if (!pool) {
+ ast_log(LOG_ERROR, "Unable to create PJLIB memory pool\n");
return -1;
}
if (sip_dialog_create_from(pool, &from, NULL, &remote_uri, &selector)) {
+ ast_log(LOG_ERROR, "Unable to create From header for %.*s request to endpoint %s\n",
+ (int) pj_strlen(&method->name), pj_strbuf(&method->name), ast_sorcery_object_get_id(endpoint));
pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
return -1;
}
if (pjsip_endpt_create_request(ast_sip_get_pjsip_endpoint(), method, &remote_uri,
&from, &remote_uri, &from, NULL, -1, NULL, &tdata) != PJ_SUCCESS) {
+ ast_log(LOG_ERROR, "Unable to create outbound %.*s request to endpoint %s\n",
+ (int) pj_strlen(&method->name), pj_strbuf(&method->name), ast_sorcery_object_get_id(endpoint));
pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
return -1;
}
@@ -522,6 +531,8 @@
pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
if (pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, NULL, NULL) != PJ_SUCCESS) {
+ ast_log(LOG_ERROR, "Error attempting to send outbound %.*s request to endpoint %s\n",
+ (int) pj_strlen(&method->name), pj_strbuf(&method->name), ast_sorcery_object_get_id(endpoint));
return -1;
}
Modified: team/mmichelson/outbound_auth/res/res_sip/sip_options.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip/sip_options.c?view=diff&rev=383391&r1=383390&r2=383391
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip/sip_options.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip/sip_options.c Tue Mar 19 14:29:42 2013
@@ -15,6 +15,7 @@
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/astobj2.h"
+#include "asterisk/cli.h"
#include "include/res_sip_private.h"
#define DEFAULT_LANGUAGE "en"
@@ -295,6 +296,46 @@
ao2_iterator_destroy(&it_endpoints);
}
+static char *send_options(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;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "sip send options";
+ e->usage =
+ "Usage: sip send options <endpoint>\n"
+ " Send a SIP OPTIONS request to the specified endpoint.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc != 4) {
+ return CLI_SHOWUSAGE;
+ }
+
+ endpoint_name = a->argv[3];
+
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name);
+ if (!endpoint) {
+ ast_log(LOG_ERROR, "Unable to retrieve endpoint %s\n", endpoint_name);
+ return CLI_FAILURE;
+ }
+
+ if (ast_sip_send_request("OPTIONS", NULL, NULL, endpoint)) {
+ ast_log(LOG_ERROR, "Unable to send OPTIONS request to endpoint %s\n", endpoint_name);
+ return CLI_FAILURE;
+ }
+
+ return CLI_SUCCESS;
+}
+
+static struct ast_cli_entry cli_options[] = {
+ AST_CLI_DEFINE(send_options, "Send an OPTIONS requst to an arbitrary SIP URI"),
+};
+
int ast_res_sip_init_options_handling(int reload)
{
const pj_str_t STR_OPTIONS = { "OPTIONS", 7 };
@@ -321,6 +362,8 @@
return -1;
}
+ ast_cli_register_multiple(cli_options, ARRAY_LEN(cli_options));
+
schedule_qualifies();
return 0;
More information about the asterisk-commits
mailing list