[asterisk-commits] qwell: branch qwell/fun_with_transports r384988 - in /team/qwell/fun_with_tra...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 8 13:08:34 CDT 2013
Author: qwell
Date: Mon Apr 8 13:08:30 2013
New Revision: 384988
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384988
Log:
Allow for storage (and retrieval) of transport, on an AOR contact.
Modified:
team/qwell/fun_with_transports/include/asterisk/res_sip.h
team/qwell/fun_with_transports/res/res_sip.c
team/qwell/fun_with_transports/res/res_sip/location.c
team/qwell/fun_with_transports/res/res_sip_outbound_registration.c
team/qwell/fun_with_transports/res/res_sip_registrar.c
team/qwell/fun_with_transports/res/res_sip_session.c
Modified: team/qwell/fun_with_transports/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/include/asterisk/res_sip.h?view=diff&rev=384988&r1=384987&r2=384988
==============================================================================
--- team/qwell/fun_with_transports/include/asterisk/res_sip.h (original)
+++ team/qwell/fun_with_transports/include/asterisk/res_sip.h Mon Apr 8 13:08:30 2013
@@ -148,6 +148,8 @@
);
/*! Absolute time that this contact is no longer valid after */
struct timeval expiration_time;
+ /*! Transport to use for all messages (some transport types require this) */
+ pjsip_transport *transport;
};
/*!
@@ -543,7 +545,7 @@
* \retval -1 failure
* \retval 0 success
*/
-int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time);
+int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, pjsip_transport *transport);
/*!
* \brief Update a contact
@@ -751,7 +753,7 @@
* \retval non-NULL success
* \retval NULL failure
*/
- pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, const char *aor_name, const char *request_user);
+ pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, const char *aor_name, const char *request_user, pjsip_transport *transport);
/*!
* \brief General purpose method for sending a SIP request
Modified: team/qwell/fun_with_transports/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip.c?view=diff&rev=384988&r1=384987&r2=384988
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip.c (original)
+++ team/qwell/fun_with_transports/res/res_sip.c Mon Apr 8 13:08:30 2013
@@ -255,7 +255,7 @@
return 0;
}
-pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, const char *uri, const char *request_user)
+pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, const char *uri, const char *request_user, pjsip_transport *request_transport)
{
RAII_VAR(struct ast_uuid *, uuid, ast_uuid_generate(), ast_free_ptr);
char uuid_str[AST_UUID_STR_LEN];
@@ -275,7 +275,11 @@
return NULL;
}
- if (!ast_strlen_zero(transport_name)) {
+ if (request_transport) {
+ /* Force a transport, if we're provided one. */
+ selector.type = PJSIP_TPSELECTOR_TRANSPORT;
+ selector.u.transport = request_transport;
+ } else if (!ast_strlen_zero(transport_name)) {
RAII_VAR(struct ast_sip_transport *, transport, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_name), ao2_cleanup);
if (!transport || !transport->state) {
@@ -283,10 +287,10 @@
return NULL;
}
- if (transport->type == AST_SIP_TRANSPORT_UDP) {
+ if (transport->state->transport) {
selector.type = PJSIP_TPSELECTOR_TRANSPORT;
selector.u.transport = transport->state->transport;
- } else if (transport->type == AST_SIP_TRANSPORT_TCP || transport->type == AST_SIP_TRANSPORT_TLS) {
+ } else if (transport->state->factory) {
selector.type = PJSIP_TPSELECTOR_LISTENER;
selector.u.listener = transport->state->factory;
} else {
Modified: team/qwell/fun_with_transports/res/res_sip/location.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip/location.c?view=diff&rev=384988&r1=384987&r2=384988
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip/location.c (original)
+++ team/qwell/fun_with_transports/res/res_sip/location.c Mon Apr 8 13:08:30 2013
@@ -121,7 +121,7 @@
return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "contact", contact_name);
}
-int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time)
+int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, pjsip_transport *transport)
{
char name[AST_UUID_STR_LEN];
RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
@@ -134,6 +134,7 @@
ast_string_field_set(contact, uri, uri);
contact->expiration_time = expiration_time;
+ contact->transport = transport;
return ast_sorcery_create(ast_sip_get_sorcery(), contact);
}
Modified: team/qwell/fun_with_transports/res/res_sip_outbound_registration.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip_outbound_registration.c?view=diff&rev=384988&r1=384987&r2=384988
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip_outbound_registration.c (original)
+++ team/qwell/fun_with_transports/res/res_sip_outbound_registration.c Mon Apr 8 13:08:30 2013
@@ -466,10 +466,10 @@
return -1;
}
- if (transport->type == AST_SIP_TRANSPORT_UDP) {
+ if (transport->state->transport) {
selector.type = PJSIP_TPSELECTOR_TRANSPORT;
selector.u.transport = transport->state->transport;
- } else if (transport->type == AST_SIP_TRANSPORT_TCP || transport->type == AST_SIP_TRANSPORT_TLS) {
+ } else if (transport->state->factory) {
selector.type = PJSIP_TPSELECTOR_LISTENER;
selector.u.listener = transport->state->factory;
} else {
Modified: team/qwell/fun_with_transports/res/res_sip_registrar.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip_registrar.c?view=diff&rev=384988&r1=384987&r2=384988
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip_registrar.c (original)
+++ team/qwell/fun_with_transports/res/res_sip_registrar.c Mon Apr 8 13:08:30 2013
@@ -190,6 +190,7 @@
struct registrar_contact_details details = { 0, };
pjsip_tx_data *tdata;
pjsip_response_addr addr;
+ pjsip_transport *transport = NULL;
if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_register_method) || !endpoint) {
return PJ_FALSE;
@@ -204,6 +205,10 @@
if (!PJSIP_URI_SCHEME_IS_SIP(rdata->msg_info.to->uri) && !PJSIP_URI_SCHEME_IS_SIPS(rdata->msg_info.to->uri)) {
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 416, NULL, NULL, NULL);
return PJ_TRUE;
+ }
+
+ if (!strcasecmp(rdata->tp_info.transport->type_name, "WS") || !strcasecmp(rdata->tp_info.transport->type_name, "WSS")) {
+ transport = rdata->tp_info.transport;
}
uri = pjsip_uri_get_uri(rdata->msg_info.to->uri);
@@ -298,13 +303,14 @@
continue;
}
- ast_sip_location_add_contact(aor, contact_uri, ast_tvadd(ast_tvnow(), ast_samp2tv(expiration, 1)));
+ ast_sip_location_add_contact(aor, contact_uri, ast_tvadd(ast_tvnow(), ast_samp2tv(expiration, 1)), transport);
ast_verb(3, "Added contact '%s' to AOR '%s' with expiration of %d seconds\n",
contact_uri, aor_name, expiration);
} else if (expiration) {
RAII_VAR(struct ast_sip_contact *, updated, ast_sorcery_copy(ast_sip_get_sorcery(), contact), ao2_cleanup);
updated->expiration_time = ast_tvadd(ast_tvnow(), ast_samp2tv(expiration, 1));
+ updated->transport = transport;
ast_sip_location_update_contact(updated);
ast_verb(3, "Refreshed contact '%s' on AOR '%s' with new expiration of %d seconds\n",
Modified: team/qwell/fun_with_transports/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip_session.c?view=diff&rev=384988&r1=384987&r2=384988
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip_session.c (original)
+++ team/qwell/fun_with_transports/res/res_sip_session.c Mon Apr 8 13:08:30 2013
@@ -953,16 +953,27 @@
return CMP_MATCH | CMP_STOP;
}
+static int contact_find_by_uri(void *obj, void *args, int flags)
+{
+ struct ast_sip_contact *contact = obj;
+ const char *uri = args;
+
+ if (!strcmp(contact->uri, uri)) {
+ return CMP_MATCH | CMP_STOP;
+ }
+ return 0;
+}
+
struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *location, const char *request_user)
{
char *aor_name, *rest;
const char *uri = NULL;
- RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
pjsip_timer_setting timer;
pjsip_dialog *dlg;
struct pjsip_inv_session *inv_session;
RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
pjmedia_sdp_session *offer;
+ pjsip_transport *request_transport = NULL;
/* If no location has been provided use the AOR list from the endpoint itself */
if (ast_strlen_zero(location)) {
@@ -979,17 +990,42 @@
while ((aor_name = strsep(&rest, ","))) {
RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
/* If a valid contact is available use its URI for dialing */
if (aor && (contacts = ast_sip_location_retrieve_aor_contacts(aor)) &&
(contact = ao2_callback(contacts, OBJ_NOLOCK, contact_find_first, NULL))) {
uri = contact->uri;
+ request_transport = contact->transport;
break;
}
}
- /* If no URI was found using the provided AORs then use the location as provided as a last resort */
+ /* Couldn't find an AOR. Try matching a contact in the AOR list on the endpoint. */
+ if (ast_strlen_zero(uri)) {
+ rest = ast_strdupa(endpoint->aors);
+ while ((aor_name = strsep(&rest, ","))) {
+ RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
+ RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
+
+ if (aor && (contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
+ char *contact_name;
+ char *contact_names = ast_strdupa(location);
+
+ while ((contact_name = strsep(&contact_names, ","))) {
+ if ((contact = ao2_callback(contacts, OBJ_NOLOCK, contact_find_by_uri, contact_name))) {
+ uri = contact->uri;
+ request_transport = contact->transport;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ /* If no URI was found using the provided AORs and contacts then use the location as provided as a last resort */
if (ast_strlen_zero(uri)) {
uri = location;
}
@@ -999,7 +1035,7 @@
return NULL;
}
- if (!(dlg = ast_sip_create_dialog(endpoint, uri, request_user))) {
+ if (!(dlg = ast_sip_create_dialog(endpoint, uri, request_user, request_transport))) {
return NULL;
} else if (pjsip_inv_create_uac(dlg, NULL, endpoint->extensions, &inv_session) != PJ_SUCCESS) {
pjsip_dlg_terminate(dlg);
More information about the asterisk-commits
mailing list