[asterisk-commits] file: branch file/pjsip-outbound-publish r420046 - /team/file/pjsip-outbound-...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 5 10:28:46 CDT 2014
Author: file
Date: Tue Aug 5 10:28:41 2014
New Revision: 420046
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=420046
Log:
Only allow authentication attempts go on for so long.
Modified:
team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c
Modified: team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c?view=diff&rev=420046&r1=420045&r2=420046
==============================================================================
--- team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c (original)
+++ team/file/pjsip-outbound-publish/res/res_pjsip_outbound_publish.c Tue Aug 5 10:28:41 2014
@@ -84,6 +84,9 @@
<configOption name="event" default="">
<synopsis>Event type of the PUBLISH.</synopsis>
</configOption>
+ <configOption name="max_auth_attempts" default="5">
+ <synopsis>Maximum number of authentication attempts before stopping the publication.</synopsis>
+ </configOption>
<configOption name="type">
<synopsis>Must be of type 'outbound-publish'.</synopsis>
</configOption>
@@ -110,12 +113,18 @@
pj_timer_entry timer;
/*! \brief Publisher datastores set up by handlers */
struct ao2_container *datastores;
+ /*! \brief The number of auth attempts done */
+ unsigned int auth_attempts;
/*! \brief Queue of outgoing publish messages to send*/
AST_LIST_HEAD_NOLOCK(, sip_outbound_publish_message) queue;
/*! \brief The message currently being sent */
struct sip_outbound_publish_message *sending;
/*! \brief Publish client has been fully started and event type informed */
unsigned int started;
+};
+
+/*! \brief Configuration information for publish client */
+struct sip_outbound_publish_configuration {
};
/*! \brief Outbound publish information */
@@ -137,6 +146,8 @@
);
/*! \brief Requested expiration time */
unsigned int expiration;
+ /*! \brief Maximum number of auth attempts before stopping the publish client */
+ unsigned int max_auth_attempts;
/*! \brief Configured authentication credentials */
struct ast_sip_auth_vector outbound_auths;
/*! \brief Outbound publish state */
@@ -575,7 +586,9 @@
pj_str_t event, server_uri, to_uri, from_uri;
pj_status_t status;
- if (!publish->state->client &&
+ if (publish->state->client) {
+ return 0;
+ } else if (!publish->state->client &&
pjsip_publishc_create(ast_sip_get_pjsip_endpoint(), &opt, publish, sip_outbound_publish_callback,
&publish->state->client) != PJ_SUCCESS) {
return -1;
@@ -653,17 +666,30 @@
static void sip_outbound_publish_callback(struct pjsip_publishc_cbparam *param)
{
struct ast_sip_outbound_publish *publish = param->token;
+ SCOPED_AO2LOCK(lock, publish->state);
if (param->code == 401 || param->code == 407) {
pjsip_tx_data *tdata;
if (!ast_sip_create_request_with_auth(&publish->outbound_auths,
param->rdata, pjsip_rdata_get_tsx(param->rdata), &tdata)) {
pjsip_publishc_send(publish->state->client, tdata);
- return;
- }
- }
-
- ao2_lock(publish->state);
+ }
+ publish->state->auth_attempts++;
+
+ if (publish->state->auth_attempts == publish->max_auth_attempts) {
+ pjsip_publishc_destroy(publish->state->client);
+ publish->state->client = NULL;
+
+ ast_log(LOG_ERROR, "Reached maximum number of PUBLISH authentication attempts on '%s'\n",
+ ast_sorcery_object_get_id(publish));
+
+ goto end;
+ }
+
+ return;
+ }
+
+ publish->state->auth_attempts = 0;
if (param->code == 412) {
pjsip_publishc_destroy(publish->state->client);
@@ -715,7 +741,6 @@
ao2_ref(publish->state, -1);
}
}
- ao2_unlock(publish->state);
}
#define DATASTORE_BUCKETS 53
@@ -822,9 +847,9 @@
if (can_reuse_publish(existing, applied)) {
applied->state = existing->state;
ao2_ref(applied->state, +1);
- return 0;
- }
- applied->state = sip_outbound_publish_state_alloc();
+ } else {
+ applied->state = sip_outbound_publish_state_alloc();
+ }
}
if (!applied->state) {
@@ -857,6 +882,7 @@
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "to_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, to_uri));
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, outbound_proxy));
ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "expiration", "3600", OPT_UINT_T, 0, FLDSET(struct ast_sip_outbound_publish, expiration));
+ ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "max_auth_attempts", "5", OPT_UINT_T, 0, FLDSET(struct ast_sip_outbound_publish, max_auth_attempts));
ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "outbound-publish", "outbound_auth", "", outbound_auth_handler, NULL, NULL, 0, 0);
ast_sorcery_reload_object(ast_sip_get_sorcery(), "outbound-publish");
More information about the asterisk-commits
mailing list