[asterisk-commits] dvossel: branch dvossel/sip_callback_issue r214359 - /team/dvossel/sip_callba...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Aug 27 11:10:48 CDT 2009
Author: dvossel
Date: Thu Aug 27 11:10:44 2009
New Revision: 214359
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214359
Log:
new parse_uri stuff
Modified:
team/dvossel/sip_callback_issue/channels/chan_sip.c
Modified: team/dvossel/sip_callback_issue/channels/chan_sip.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/dvossel/sip_callback_issue/channels/chan_sip.c?view=diff&rev=214359&r1=214358&r2=214359
==============================================================================
--- team/dvossel/sip_callback_issue/channels/chan_sip.c (original)
+++ team/dvossel/sip_callback_issue/channels/chan_sip.c Thu Aug 27 11:10:44 2009
@@ -4278,7 +4278,7 @@
* \endverbatim
*
*/
-static int parse_uri(char *uri, char *scheme,
+static int parse_uri_helper(char *uri, char *scheme,
char **ret_name, char **pass, char **domain, char **port, char **options, char **transport)
{
char *name = NULL;
@@ -4349,6 +4349,18 @@
*options = uri ? uri : "";
return error;
+}
+
+static int parse_uri(char *uri, char **ret_name, char **pass, char **domain, char **port, char **options, char **transport)
+{
+ char *uri2 = ast_strdupa(uri);
+ int res = 0;
+ if ((res = parse_uri_helper(uri, "sip:", ret_name, pass, domain, port, options, transport))) {
+ memcpy(uri, uri2, sizeof(*uri)); /* restore original and try again */
+ res = parse_uri_helper(uri, "sips:", ret_name, pass, domain, port, options, transport);
+ }
+
+ return res;
}
/*! \brief Send message with Access-URL header, if this is an HTML URL only! */
@@ -12181,42 +12193,33 @@
{
struct hostent *hp;
struct ast_hostent ahp;
- int port;
- char *host, *pt;
+ int port = STANDARD_SIP_PORT;
+ char *host, *pt, *transport;
char contact_buf[256];
- char contact2_buf[256];
- char *contact, *contact2;
+ char *contact;
int use_tls = FALSE;
/* Work on a copy */
ast_copy_string(contact_buf, fullcontact, sizeof(contact_buf));
- ast_copy_string(contact2_buf, fullcontact, sizeof(contact2_buf));
contact = contact_buf;
- contact2 = contact2_buf;
-
- /* We have only the part in <brackets> here so we just need to parse a SIP URI.*/
-
- /*! \brief This code is wrong, it assumes that the contact we receive will use the
- same transport as the request. It's not a valid assumption. The contact for
- a udp connection can be a SIPS uri, or request ;transport=tcp
- \todo Fix this buggy code. It doesn't even parse transport!!!!
-
- Note: The outbound proxy could be using UDP between the proxy and Asterisk.
- We still need to be able to send to the remote agent through the proxy.
- */
- if (tcp) {
- if (!parse_uri(contact, "sips:", &contact, NULL, &host, &pt, NULL, NULL)) {
+
+ /*
+ * We have only the part in <brackets> here so we just need to parse a SIP URI.
+ *
+ * Note: The outbound proxy could be using UDP between the proxy and Asterisk.
+ * We still need to be able to send to the remote agent through the proxy.
+ */
+
+ if (!parse_uri(contact, &contact, NULL, &host, &pt, NULL, &transport)) {
+ if (((get_transport_str2enum(transport) == SIP_TRANSPORT_TLS)) ||
+ !(strncasecmp(fullcontact, "sips", 4))) {
use_tls = TRUE;
+ port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_TLS_PORT;
} else {
- if (parse_uri(contact2, "sip:", &contact, NULL, &host, &pt, NULL, NULL))
- ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", contact);
- }
- port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_TLS_PORT;
- /*! \todo XXX why are we setting TLS port if there's no port given? parse_uri needs to return the transport. */
+ port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
+ }
} else {
- if (parse_uri(contact, "sip:", &contact, NULL, &host, &pt, NULL, NULL))
- ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", contact);
- port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
+ ast_log(LOG_WARNING, "Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact);
}
/* XXX This could block for a long time XXX */
@@ -12258,7 +12261,7 @@
char data[SIPBUFSIZE];
const char *expires = get_header(req, "Expires");
int expire = atoi(expires);
- char *curi, *host, *pt, *curi2, *transport;
+ char *curi, *host, *pt, *transport;
int port;
int transport_type;
const char *useragent;
@@ -12288,7 +12291,6 @@
if (strchr(contact, '<') == NULL) /* No <, check for ; and strip it */
strsep(&curi, ";"); /* This is Header options, not URI options */
curi = get_in_brackets(contact);
- curi2 = ast_strdupa(curi);
/* if they did not specify Contact: or Expires:, they are querying
what we currently have stored as their contact address, so return
@@ -12329,16 +12331,8 @@
ast_string_field_build(pvt, our_contact, "<%s>", curi);
/* Make sure it's a SIP URL */
- if (pvt->socket.type == SIP_TRANSPORT_TLS) {
- if (parse_uri(curi, "sips:", &curi, NULL, &host, &pt, NULL, &transport)) {
- if (parse_uri(curi2, "sip:", &curi, NULL, &host, &pt, NULL, &transport))
- ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:) trying to use anyway\n");
- }
- port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_TLS_PORT;
- } else {
- if (parse_uri(curi, "sip:", &curi, NULL, &host, &pt, NULL, &transport))
- ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:) trying to use anyway\n");
- port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
+ if (parse_uri(curi, &curi, NULL, &host, &pt, NULL, &transport)) {
+ ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:) trying to use anyway\n");
}
/* handle the transport type specified in Contact header. */
@@ -12348,8 +12342,11 @@
* same transport used by the pvt struct for the Register dialog. */
if (ast_strlen_zero(pt)) {
port = (transport_type == SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT;
+ } else {
+ port = atoi(pt);
}
} else {
+ port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
transport_type = pvt->socket.type;
}
@@ -14260,7 +14257,7 @@
char from[256];
char *dummy; /* dummy return value for parse_uri */
char *domain; /* dummy return value for parse_uri */
- char *of, *of2;
+ char *of;
enum check_auth_result res;
char calleridname[50];
char *uri2 = ast_strdupa(uri);
@@ -14293,19 +14290,9 @@
/* save the URI part of the From header */
ast_string_field_set(p, from, of);
- of2 = ast_strdupa(of);
-
/* ignore all fields but name */
- /*! \todo Samme logical error as in many places above. Need a generic function for this.
- */
- if (p->socket.type == SIP_TRANSPORT_TLS) {
- if (parse_uri(of, "sips:", &of, &dummy, &domain, &dummy, &dummy, NULL)) {
- if (parse_uri(of2, "sip:", &of, &dummy, &domain, &dummy, &dummy, NULL))
- ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
- }
- } else {
- if (parse_uri(of, "sip:", &of, &dummy, &domain, &dummy, &dummy, NULL))
- ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
+ if (parse_uri(of, &of, &dummy, &domain, &dummy, &dummy, NULL)) {
+ ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
}
if (ast_strlen_zero(of)) {
More information about the asterisk-commits
mailing list