[svn-commits] kmoore: branch kmoore/pjsip_path_support r403156 - in /team/kmoore/pjsip_path...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Nov 25 21:38:54 CST 2013


Author: kmoore
Date: Mon Nov 25 21:38:53 2013
New Revision: 403156

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403156
Log:
Update supplement hooks to support the case required by qualify support

Modified:
    team/kmoore/pjsip_path_support/channels/chan_pjsip.c
    team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h
    team/kmoore/pjsip_path_support/res/res_pjsip.c
    team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_options.c
    team/kmoore/pjsip_path_support/res/res_pjsip_messaging.c
    team/kmoore/pjsip_path_support/res/res_pjsip_mwi.c
    team/kmoore/pjsip_path_support/res/res_pjsip_notify.c

Modified: team/kmoore/pjsip_path_support/channels/chan_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/channels/chan_pjsip.c?view=diff&rev=403156&r1=403155&r2=403156
==============================================================================
--- team/kmoore/pjsip_path_support/channels/chan_pjsip.c (original)
+++ team/kmoore/pjsip_path_support/channels/chan_pjsip.c Mon Nov 25 21:38:53 2013
@@ -1819,7 +1819,7 @@
 
 	ast_sip_create_request("MESSAGE", data->session->inv_session->dlg, data->session->endpoint, NULL, &tdata);
 	ast_sip_add_body(tdata, &body);
-	ast_sip_send_request(tdata, data->session->inv_session->dlg, data->session->endpoint);
+	ast_sip_send_request(tdata, data->session->inv_session->dlg, data->session->endpoint, NULL, NULL);
 
 	return 0;
 }

Modified: team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h?view=diff&rev=403156&r1=403155&r2=403156
==============================================================================
--- team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h (original)
+++ team/kmoore/pjsip_path_support/include/asterisk/res_pjsip.h Mon Nov 25 21:38:53 2013
@@ -1253,10 +1253,15 @@
  * \param tdata The request to send
  * \param dlg Optional. If specified, the dialog on which the request should be sent
  * \param endpoint Optional. If specified, the request is sent out-of-dialog to the endpoint.
+ * \param token Data to be passed to the callback upon receipt of response
+ * \param callback Callback to be called upon receipt of response
+ *
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint);
+int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg,
+	struct ast_sip_endpoint *endpoint, void *token,
+	void (*callback)(void *token, pjsip_event *e));
 
 /*!
  * \brief Send a response to an out of dialog request

Modified: team/kmoore/pjsip_path_support/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip.c?view=diff&rev=403156&r1=403155&r2=403156
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip.c Mon Nov 25 21:38:53 2013
@@ -1641,33 +1641,67 @@
 	return pj_stristr(&method, message_method) ? PJ_TRUE : PJ_FALSE;
 }
 
+struct send_request_data {
+	struct ast_sip_endpoint *endpoint;
+	void *token;
+	void (*callback)(void *token, pjsip_event *e);
+};
+
+static void send_request_data_destroy(void *obj)
+{
+	struct send_request_data *req_data = obj;
+	ao2_cleanup(req_data->endpoint);
+}
+
+static struct send_request_data *send_request_data_alloc(struct ast_sip_endpoint *endpoint,
+	void *token, void (*callback)(void *token, pjsip_event *e))
+{
+	struct send_request_data *req_data = ao2_alloc(sizeof(*req_data), send_request_data_destroy);
+
+	if (!req_data) {
+		return NULL;
+	}
+
+	req_data->endpoint = ao2_bump(endpoint);
+	req_data->token = token;
+	req_data->callback = callback;
+
+	return req_data;
+}
+
 static void send_request_cb(void *token, pjsip_event *e)
 {
-	RAII_VAR(struct ast_sip_endpoint *, endpoint, token, ao2_cleanup);
+	RAII_VAR(struct send_request_data *, req_data, token, ao2_cleanup);
 	pjsip_transaction *tsx = e->body.tsx_state.tsx;
 	pjsip_rx_data *challenge = e->body.tsx_state.src.rdata;
 	pjsip_tx_data *tdata;
 	struct ast_sip_supplement *supplement;
 
-	if (tsx->status_code == 401 || tsx->status_code == 407) {
-		if (!ast_sip_create_request_with_auth(&endpoint->outbound_auths, challenge, tsx, &tdata)) {
-			pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, NULL, NULL);
-		}
-		return;
-	}
-
 	AST_RWLIST_RDLOCK(&supplements);
 	AST_LIST_TRAVERSE(&supplements, supplement, next) {
 		if (supplement->incoming_response && does_method_match(&challenge->msg_info.cseq->method.name, supplement->method)) {
-			supplement->incoming_response(endpoint, challenge);
+			supplement->incoming_response(req_data->endpoint, challenge);
 		}
 	}
 	AST_RWLIST_UNLOCK(&supplements);
-}
-
-static int send_out_of_dialog_request(pjsip_tx_data *tdata, struct ast_sip_endpoint *endpoint)
+
+	if (tsx->status_code == 401 || tsx->status_code == 407) {
+		if (!ast_sip_create_request_with_auth(&req_data->endpoint->outbound_auths, challenge, tsx, &tdata)) {
+			pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, req_data->token, req_data->callback);
+		}
+		return;
+	}
+
+	if (req_data->callback) {
+		req_data->callback(req_data->token, e);
+	}
+}
+
+static int send_out_of_dialog_request(pjsip_tx_data *tdata, struct ast_sip_endpoint *endpoint,
+	void *token, void (*callback)(void *token, pjsip_event *e))
 {
 	struct ast_sip_supplement *supplement;
+	RAII_VAR(struct send_request_data *, req_data, send_request_data_alloc(endpoint, token, callback), ao2_cleanup);
 
 	AST_RWLIST_RDLOCK(&supplements);
 	AST_LIST_TRAVERSE(&supplements, supplement, next) {
@@ -1677,27 +1711,29 @@
 	}
 	AST_RWLIST_UNLOCK(&supplements);
 
-	ao2_ref(endpoint, +1);
-	if (pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, endpoint, send_request_cb) != PJ_SUCCESS) {
+	ao2_ref(req_data, +1);
+	if (pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata, -1, req_data, send_request_cb) != PJ_SUCCESS) {
 		ast_log(LOG_ERROR, "Error attempting to send outbound %.*s request to endpoint %s\n",
 				(int) pj_strlen(&tdata->msg->line.req.method.name),
 				pj_strbuf(&tdata->msg->line.req.method.name),
 				ast_sorcery_object_get_id(endpoint));
-		ao2_ref(endpoint, -1);
+		ao2_ref(req_data, -1);
 		return -1;
 	}
 
 	return 0;
 }
 
-int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint)
+int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg,
+	struct ast_sip_endpoint *endpoint, void *token,
+	void (*callback)(void *token, pjsip_event *e))
 {
 	ast_assert(tdata->msg->type == PJSIP_REQUEST_MSG);
 
 	if (dlg) {
 		return send_in_dialog_request(tdata, dlg);
 	} else {
-		return send_out_of_dialog_request(tdata, endpoint);
+		return send_out_of_dialog_request(tdata, endpoint, token, callback);
 	}
 }
 

Modified: team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_options.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_options.c?view=diff&rev=403156&r1=403155&r2=403156
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_options.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip/pjsip_options.c Mon Nov 25 21:38:53 2013
@@ -34,7 +34,7 @@
 #define DEFAULT_ENCODING "text/plain"
 #define QUALIFIED_BUCKETS 211
 
-static int qualify_contact(struct ast_sip_contact *contact);
+static int qualify_contact(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact);
 
 /*!
  * \internal
@@ -186,7 +186,7 @@
  * \internal
  * \brief Find endpoints associated with the given contact.
  */
-static struct ao2_container *find_endpoints(struct ast_sip_contact *contact)
+static struct ao2_iterator *find_endpoints(struct ast_sip_contact *contact)
 {
 	RAII_VAR(struct ao2_container *, endpoints,
 		 ast_sip_get_endpoints(), ao2_cleanup);
@@ -201,43 +201,15 @@
 static void qualify_contact_cb(void *token, pjsip_event *e)
 {
 	RAII_VAR(struct ast_sip_contact *, contact, token, ao2_cleanup);
-	RAII_VAR(struct ao2_container *, endpoints, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
-
-	pjsip_transaction *tsx = e->body.tsx_state.tsx;
-	pjsip_rx_data *challenge = e->body.tsx_state.src.rdata;
-	pjsip_tx_data *tdata;
 
 	switch(e->body.tsx_state.type) {
 	case PJSIP_EVENT_TRANSPORT_ERROR:
 	case PJSIP_EVENT_TIMER:
 		update_contact_status(contact, UNAVAILABLE);
-		return;
+		break;
 	default:
+		update_contact_status(contact, AVAILABLE);
 		break;
-	}
-
-	if (!contact->authenticate_qualify || (tsx->status_code != 401 &&
-					       tsx->status_code != 407)) {
-		update_contact_status(contact, AVAILABLE);
-		return;
-	}
-
-	/* try to find endpoints that are associated with the contact */
-	if (!(endpoints = find_endpoints(contact))) {
-		ast_log(LOG_ERROR, "No endpoints found for contact %s, cannot authenticate",
-			contact->uri);
-		return;
-	}
-
-	/* find "first" endpoint in order to authenticate - actually any
-	   endpoint should do that matched on the contact */
-	endpoint = ao2_callback(endpoints, 0, NULL, NULL);
-
-	if (!ast_sip_create_request_with_auth(&endpoint->outbound_auths,
-					      challenge, tsx, &tdata)) {
-		pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(), tdata,
-					 -1, NULL, NULL);
 	}
 }
 
@@ -248,9 +220,23 @@
  * \detail Sends a SIP OPTIONS request to the given contact in order to make
  *         sure that contact is available.
  */
-static int qualify_contact(struct ast_sip_contact *contact)
+static int qualify_contact(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact)
 {
 	pjsip_tx_data *tdata;
+	RAII_VAR(struct ast_sip_endpoint *, endpoint_local, ao2_bump(endpoint), ao2_cleanup);
+
+
+	if (!endpoint_local) {
+		struct ao2_iterator *endpoint_iterator = find_endpoints(contact);
+
+		/* try to find endpoints that are associated with the contact */
+		if (endpoint_iterator) {
+			/* find "first" endpoint in order to authenticate - actually any
+			   endpoint should do that matched on the contact */
+			endpoint_local = ao2_iterator_next(endpoint_iterator);
+			ao2_iterator_destroy(endpoint_iterator);
+		}
+	}
 
 	if (ast_sip_create_request("OPTIONS", NULL, NULL, contact->uri, &tdata)) {
 		ast_log(LOG_ERROR, "Unable to create request to qualify contact %s\n",
@@ -261,12 +247,12 @@
 	init_start_time(contact);
 
 	ao2_ref(contact, +1);
-	if (pjsip_endpt_send_request(ast_sip_get_pjsip_endpoint(),
-				     tdata, -1, contact, qualify_contact_cb) != PJ_SUCCESS) {
+	if (ast_sip_send_request(tdata, NULL, endpoint_local, contact,
+		qualify_contact_cb) != PJ_SUCCESS) {
 		pjsip_tx_data_dec_ref(tdata);
 		ast_log(LOG_ERROR, "Unable to send request to qualify contact %s\n",
 			contact->uri);
-		ao2_ref(contact, -1);
+		ao2_cleanup(contact);
 		return -1;
 	}
 
@@ -331,7 +317,7 @@
 static int qualify_contact_task(void *obj)
 {
 	RAII_VAR(struct ast_sip_contact *, contact, obj, ao2_cleanup);
-	return qualify_contact(contact);
+	return qualify_contact(NULL, contact);
 }
 
 /*!
@@ -578,12 +564,13 @@
  * \internal
  * \brief Send qualify request to the given contact.
  */
-static int cli_on_contact(void *obj, void *arg, int flags)
+static int cli_on_contact(void *obj, void *arg, void *data, int flags)
 {
 	struct ast_sip_contact *contact = obj;
+	struct ast_sip_endpoint *endpoint = data;
 	int *cli_fd = arg;
 	ast_cli(*cli_fd, " contact %s\n", contact->uri);
-	qualify_contact(contact);
+	qualify_contact(endpoint, contact);
 	return 0;
 }
 
@@ -647,7 +634,7 @@
 		}
 
 		ast_cli(cli_fd, "Sending qualify to endpoint %s\n", endpoint_name);
-		ao2_callback(contacts, OBJ_NODATA, cli_on_contact, &cli_fd);
+		ao2_callback_data(contacts, OBJ_NODATA, cli_on_contact, &cli_fd, endpoint);
 	}
 	return 0;
 }

Modified: team/kmoore/pjsip_path_support/res/res_pjsip_messaging.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip_messaging.c?view=diff&rev=403156&r1=403155&r2=403156
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip_messaging.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip_messaging.c Mon Nov 25 21:38:53 2013
@@ -522,7 +522,7 @@
 
 	update_from(tdata, mdata->from);
 	vars_to_headers(mdata->msg, tdata);
-	if (ast_sip_send_request(tdata, NULL, endpoint)) {
+	if (ast_sip_send_request(tdata, NULL, endpoint, NULL, NULL)) {
 		ast_log(LOG_ERROR, "SIP MESSAGE - Could not send request\n");
 		return -1;
 	}

Modified: team/kmoore/pjsip_path_support/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip_mwi.c?view=diff&rev=403156&r1=403155&r2=403156
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip_mwi.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip_mwi.c Mon Nov 25 21:38:53 2013
@@ -308,7 +308,7 @@
 	pjsip_msg_add_hdr(tdata->msg, pjsip_hdr_shallow_clone(tdata->pool, allow_events));
 	msg_body = pjsip_msg_body_create(tdata->pool, &mwi_type->type, &mwi_type->subtype, body_text);
 	tdata->msg->body = msg_body;
-	ast_sip_send_request(tdata, NULL, endpoint);
+	ast_sip_send_request(tdata, NULL, endpoint, NULL, NULL);
 
 	return 0;
 }

Modified: team/kmoore/pjsip_path_support/res/res_pjsip_notify.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/pjsip_path_support/res/res_pjsip_notify.c?view=diff&rev=403156&r1=403155&r2=403156
==============================================================================
--- team/kmoore/pjsip_path_support/res/res_pjsip_notify.c (original)
+++ team/kmoore/pjsip_path_support/res/res_pjsip_notify.c Mon Nov 25 21:38:53 2013
@@ -479,7 +479,7 @@
 	ast_sip_add_header(tdata, "Subscription-State", "terminated");
 	data->build_notify(tdata, data->info);
 
-	if (ast_sip_send_request(tdata, NULL, data->endpoint)) {
+	if (ast_sip_send_request(tdata, NULL, data->endpoint, NULL, NULL)) {
 		ast_log(LOG_ERROR, "SIP NOTIFY - Unable to send request for "
 			"contact %s\n",	contact->uri);
 		return -1;




More information about the svn-commits mailing list