[asterisk-commits] rizzo: trunk r45977 - /trunk/channels/chan_sip.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon Oct 23 08:45:37 MST 2006
Author: rizzo
Date: Mon Oct 23 10:45:36 2006
New Revision: 45977
URL: http://svn.digium.com/view/asterisk?rev=45977&view=rev
Log:
+ make sure parse_uri never returns NULL pointers - this
simplifies its usage.
+ add another client for parse_uri, in handling Contact: strings
(on passing, document the content of the "fullcontact" field);
+ in register_verify(), mark with XXX what i believe is another
misinterpretation on the URI format when '@' is missing.
No code changed here, so no fixes applied.
Modified:
trunk/channels/chan_sip.c
Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=45977&r1=45976&r2=45977&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Mon Oct 23 10:45:36 2006
@@ -912,6 +912,7 @@
AST_STRING_FIELD(cid_name); /*!< Caller*ID name */
AST_STRING_FIELD(via); /*!< Via: header */
AST_STRING_FIELD(fullcontact); /*!< The Contact: that the UA registers with us */
+ /* we only store the part in <brackets> in this field. */
AST_STRING_FIELD(our_contact); /*!< Our contact header */
AST_STRING_FIELD(rpid); /*!< Our RPID header */
AST_STRING_FIELD(rpid_from); /*!< Our RPID From header */
@@ -2242,7 +2243,7 @@
* name:pass and domain:port.
* It is safe to call with ret_name, pass, domain, port
* pointing all to the same place.
- *
+ * Init pointers to empty string so we never get NULL dereferencing.
* Overwrites the string.
* return 0 on success, other values on error.
*/
@@ -2254,9 +2255,9 @@
/* init field as required */
if (*pass)
- *pass = NULL;
+ *pass = "";
if (*port)
- *port = NULL;
+ *port = "";
name = strsep(&uri, ";"); /* remove options */
if (scheme) {
int l = strlen(scheme);
@@ -2275,12 +2276,12 @@
/* store the result in a temp. variable to avoid it being
* overwritten if arguments point to the same place.
*/
- char *c, *dom = NULL;
+ char *c, *dom = "";
if ((c = strchr(name, '@')) == NULL) {
/* domain-only URI, according to the SIP RFC. */
dom = name;
- name = NULL;
+ name = "";
} else {
*c++ = '\0';
dom = c;
@@ -2289,7 +2290,7 @@
*c++ = '\0';
*port = c;
}
- if (name && pass && (c = strchr(name, ':'))) { /* user:password */
+ if (pass && (c = strchr(name, ':'))) { /* user:password */
*c++ = '\0';
*pass = c;
}
@@ -2298,7 +2299,7 @@
if (ret_name) /* same as for domain, store the result only at the end */
*ret_name = name;
if (options)
- *options = uri;
+ *options = uri ? uri : "";
return error;
}
@@ -7590,7 +7591,7 @@
struct hostent *hp;
struct ast_hostent ahp;
int port;
- char *c, *host, *pt;
+ char *host, *pt;
char *contact;
@@ -7604,32 +7605,12 @@
/* Work on a copy */
contact = ast_strdupa(pvt->fullcontact);
-
- /* XXX this code is repeated all over */
- /* Make sure it's a SIP URL */
- if (strncasecmp(contact, "sip:", 4)) {
+ /* We have only the part in <brackets> here so we just need to parse a SIP URI.*/
+
+ if (parse_uri(contact, "sip:", &contact, NULL, &host, &pt, NULL))
ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", contact);
- } else
- contact += 4;
-
- /* Ditch arguments */
- /* XXX this code is replicated also shortly below */
- contact = strsep(&contact, ";"); /* trim ; and beyond */
-
- /* Grab host */
- host = strchr(contact, '@');
- if (!host) { /* No username part */
- host = contact;
- c = NULL;
- } else {
- *host++ = '\0';
- }
- pt = strchr(host, ':');
- if (pt) {
- *pt++ = '\0';
- port = atoi(pt);
- } else
- port = STANDARD_SIP_PORT;
+ port = !ast_strlen_zero(pt) ? atoi(pt) : STANDARD_SIP_PORT;
+ ast_verbose("--- set_address_from_contact host '%s'\n", host);
/* XXX This could block for a long time XXX */
/* We should only do this if it's a name, not an IP */
@@ -8193,6 +8174,9 @@
ast_log(LOG_NOTICE, "Invalid to address: '%s' from %s (missing sip:) trying to use anyway...\n", c, ast_inet_ntoa(sin->sin_addr));
}
+ /* XXX here too we interpret a missing @domain as a name-only
+ * URI, whereas the RFC says this is a domain-only uri.
+ */
/* Strip off the domain name */
if ((c = strchr(name, '@'))) {
*c++ = '\0';
@@ -9233,7 +9217,7 @@
if (parse_uri(of, "sip:", &of, &dummy, &domain, &dummy, &dummy)) {
ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n");
}
- if (of == NULL) {
+ if (ast_strlen_zero(of)) {
/* XXX note: the original code considered a missing @host
* as a username-only URI. The SIP RFC (19.1.1) says that
* this is wrong, and it should be considered as a domain-only URI.
More information about the asterisk-commits
mailing list