opensips/enum-isn.diff

Mon, 18 Jan 2010 19:59:51 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Mon, 18 Jan 2010 19:59:51 +0100
changeset 13
b63f281afe6b
permissions
-rw-r--r--

Introduce ISN formatting and lookup logic into the ENUM module.
A detailed description of these changes is provided in enum-isn.txt.

     1 Index: modules/enum/enum_mod.h
     2 diff -Nau modules/enum/enum_mod.h.orig modules/enum/enum_mod.h
     3 --- modules/enum/enum_mod.h.orig	2010-01-18 15:54:52.842465412 +0100
     4 +++ modules/enum/enum_mod.h	2010-01-18 15:55:20.812190874 +0100
     5 @@ -41,5 +41,7 @@
     6  extern str i_branchlabel;    /* the label branching off the infrastructure tree */
     7  extern str i_bl_alg;         /* how to know where to branch off */
     9 +extern str isnsuffix;        /* str version of isn_suffix */
    10 +
    12  #endif /* ENUM_MOD_H */
    13 Index: modules/enum/enum_mod.c
    14 diff -Nau modules/enum/enum_mod.c.orig modules/enum/enum_mod.c
    15 --- modules/enum/enum_mod.c.orig	2010-01-18 15:52:57.316263519 +0100
    16 +++ modules/enum/enum_mod.c	2010-01-18 15:52:42.844229824 +0100
    17 @@ -55,6 +55,8 @@
    18  char* i_enum_suffix = "e164.arpa.";
    19  char* bl_algorithm = "cc";
    21 +char* isn_suffix = "freenum.org.";
    22 +
    24  /*
    25   * Internal module variables
    26 @@ -67,6 +69,8 @@
    27  str i_branchlabel;
    28  str i_bl_alg;
    30 +str isnsuffix;
    31 +
    33  /*
    34   * Exported functions
    35 @@ -94,6 +98,11 @@
    36  	 REQUEST_ROUTE},
    37  	{"i_enum_query", (cmd_function)i_enum_query_2, 2, fixup_str_str, 0,
    38  	 REQUEST_ROUTE},
    39 +	{"isn_query", (cmd_function)isn_query_0, 0, 0, 0, REQUEST_ROUTE},
    40 +	{"isn_query", (cmd_function)isn_query_1, 1, fixup_str_null,
    41 +	 fixup_free_str_null, REQUEST_ROUTE},
    42 +	{"isn_query", (cmd_function)isn_query_2, 2, fixup_str_str, 
    43 +	 fixup_free_str_str, REQUEST_ROUTE},
    44  	{0, 0, 0, 0, 0, 0}
    45  };
    47 @@ -107,6 +116,7 @@
    48  	{"branchlabel", STR_PARAM, &branchlabel},
    49  	{"i_enum_suffix", STR_PARAM, &i_enum_suffix},
    50  	{"bl_algorithm", STR_PARAM, &bl_algorithm},
    51 +	{"isn_suffix", STR_PARAM, &isn_suffix},
    52  	{0, 0, 0}
    53  };
    55 @@ -152,6 +162,9 @@
    56  	i_bl_alg.s = bl_algorithm;
    57  	i_bl_alg.len = strlen(bl_algorithm);
    59 +	isnsuffix.s = isn_suffix;
    60 +	isnsuffix.len = strlen(isn_suffix.s);
    61 +
    62  	return 0;
    63  }
    65 Index: modules/enum/enum.h
    66 diff -Nau modules/enum/enum.h.orig modules/enum/enum.h
    67 --- modules/enum/enum.h.orig	2010-01-18 15:54:40.361624448 +0100
    68 +++ modules/enum/enum.h	2010-01-18 15:54:43.090330399 +0100
    69 @@ -66,5 +66,13 @@
    70  int i_enum_query_1(struct sip_msg* _msg, char* _suffix, char* _str2);
    71  int i_enum_query_2(struct sip_msg* _msg, char* _suffix, char* _service);
    73 +/*
    74 + * Make ISN query and if query succeeds, replace current uri with the
    75 + * result of the query
    76 + */
    77 +int isn_query_0(struct sip_msg* _msg, char* _str1, char* _str2);
    78 +int isn_query_1(struct sip_msg* _msg, char* _suffix, char* _str2);
    79 +int isn_query_2(struct sip_msg* _msg, char* _suffix, char* _service);
    80 +
    82  #endif /* ENUM_H */
    83 Index: modules/enum/enum.c
    84 diff -Nau modules/enum/enum.c.orig modules/enum/enum.c
    85 --- modules/enum/enum.c.orig	2010-01-18 15:57:10.995902181 +0100
    86 +++ modules/enum/enum.c	2010-01-18 15:46:19.642209178 +0100
    87 @@ -736,6 +736,84 @@
    88  }
    91 +/*
    92 + * Call isn_query_2 with module parameter suffix and default service.
    93 + */
    94 +int isn_query_0(struct sip_msg* _msg, char* _str1, char* _str2)
    95 +{
    96 +	return isn_query_2(_msg, (char *)(&isnsuffix), (char *)(&service));
    97 +}
    98 +
    99 +
   100 +/*
   101 + * Call isn_query_2 with given suffix and default service.
   102 + */
   103 +int isn_query_1(struct sip_msg* _msg, char* _suffix, char* _str2)
   104 +{
   105 +	return isn_query_2(_msg, _suffix, (char *)(&service));
   106 +}
   107 +
   108 +
   109 +/*
   110 + * See documentation in README file.
   111 + */
   112 +int isn_query_2(struct sip_msg* _msg, char* _suffix, char* _service)
   113 +{
   114 +	char *user_s = NULL;
   115 +	int user_len, i, j;
   116 +	char name[MAX_DOMAIN_SIZE] = {0};
   117 +	char string[17] = {0};
   118 +	char szItad[17] = {0};
   119 +	size_t nItlen = 0;
   120 +
   121 +	str *suffix, *service;
   122 +
   123 +	suffix = (str*)_suffix;
   124 +	service = (str*)_service;
   125 +
   126 +	if (parse_sip_msg_uri(_msg) < 0) {
   127 +		LM_ERR("Parsing of R-URI failed\n");
   128 +		return -1;
   129 +	}
   130 +
   131 +	user_s = _msg->parsed_uri.user.s;
   132 +	user_len = _msg->parsed_uri.user.len;
   133 +
   134 +	memcpy(&(string[0]), user_s, user_len);
   135 +	string[user_len] = (char)0;
   136 +
   137 +	/* Do primitive test for correct ISN format, */
   138 +	/* and set szItad to the ISN ITAD (RFC 3872/2871). */
   139 +	/* Correct ISN format guessed from freenum.org and IANA */
   140 +	/* doc http://www.iana.org/assignments/trip-parameters/ */
   141 +	{
   142 +		char *pAster = strchr(string, '*');
   143 +		if (pAster && (nItlen = strspn(pAster + sizeof(char), "0123456789")))
   144 +			strncpy(szItad, pAster + sizeof(char), nItlen);
   145 +		else {
   146 +			LM_ERR("R-URI user does not contain a valid ISN\n");
   147 +			return -1;
   148 +		}
   149 +	}
   150 +
   151 +	/* Ammend the original ENUM E.164 string logic to process */
   152 +	/* ISN numbers instead, which include a nonreversed ITAD. */
   153 +	i = user_len - nItlen - sizeof(char); /* Ex: *1212 */
   154 +	j = 0;
   155 +	while (i--) {
   156 +		name[j] = user_s[i];
   157 +		name[j + 1] = '.';
   158 +		j = j + 2;
   159 +	}
   160 +
   161 +	strcat(name + j, szItad);  /* Copy the unreversed ITAD, */
   162 +	name[j + nItlen] = '.';    /* and append a trailing dot. */
   163 +	memcpy(name + j + nItlen + sizeof(char), suffix->s, suffix->len + 1);
   164 +
   165 +	return do_query(_msg, string, name, service);
   166 +}
   167 +
   168 +
   169  /*********** INFRASTRUCTURE ENUM ***************/
   171  /*
   172 Index: modules/enum/README
   173 diff -Nau modules/enum/README.orig modules/enum/README
   174 --- modules/enum/README.orig	2010-01-18 17:59:52.034172367 +0100
   175 +++ modules/enum/README	2010-01-18 18:01:30.730633377 +0100
   176 @@ -10,8 +10,8 @@
   178     Copyright © 2002, 2003 Juha Heinanen
   179     Revision History
   180 -   Revision $Revision: 5906 $ $Date: 2009-07-21 10:45:05 +0300
   181 -                              (Tue, 21 Jul 2009) $
   182 +   Revision $Revision: 5907 $ $Date: 2010-01-18 10:45:05 +0100
   183 +                              (Mon, 18 Jan 2010) $
   184       __________________________________________________________
   186     Table of Contents
   187 @@ -25,28 +25,32 @@
   188                1.3.1. domain_suffix (string)
   189                1.3.2. tel_uri_params (string)
   190                1.3.3. i_enum_suffix (string)
   191 -              1.3.4. branchlabel (string)
   192 -              1.3.5. bl_algorithm (string)
   193 +              1.3.4. isn_suffix (string)
   194 +              1.3.5. branchlabel (string)
   195 +              1.3.6. bl_algorithm (string)
   197          1.4. Exported Functions
   199                1.4.1. enum_query(["suffix"[,"service"]])
   200                1.4.2. enum_pv_query("pvar"[,"suffix"[,"service"]])
   201                1.4.3. i_enum_query(["suffix"[,"service"]])
   202 -              1.4.4. is_from_user_enum()
   203 +              1.4.4. isn_query(["suffix"[,"service"]])
   204 +              1.4.5. is_from_user_enum()
   206     List of Examples
   208     1.1. Setting domain_suffix module parameter
   209     1.2. Setting tel_uri_params module parameter
   210     1.3. Setting i_enum_suffix module parameter
   211 -   1.4. Setting brachlabel module parameter
   212 -   1.5. Zone file example
   213 +   1.4. Setting isn_query usage module parameter
   214 +   1.5. Setting branchlabel module parameter
   215     1.6. Zone file example
   216 -   1.7. Setting the bl_algorithm module parameter
   217 -   1.8. enum_query usage
   218 -   1.9. enum_pv_query usage
   219 -   1.10. is_from_user_enum usage
   220 +   1.7. Zone file example
   221 +   1.8. Setting the bl_algorithm module parameter
   222 +   1.9. enum_query usage
   223 +   1.10. enum_pv_query usage
   224 +   1.11. isn_query usage
   225 +   1.12. is_from_user_enum usage
   227  Chapter 1. Admin Guide
   229 @@ -113,6 +117,22 @@
   230     function does an enum lookup on the from user and returns true
   231     if found, false otherwise.
   233 +   In addition to standard ENUM, support for ISN (ITAD Subscriber
   234 +   Numbers) is provided as well. To allow ISN lookups to resolve,
   235 +   a different formatting algorithm is expected by the DNS server.
   236 +   Whereas a ENUM NAPTR record expects a DNS query of the form
   237 +   9.8.7.6.5.4.3.2.1.<suffix>, ISN method expects a DNS query of
   238 +   the form 6.5.1212.<suffix>. That is, a valid ISN number includes
   239 +   a prefix of '56' in the example. The rest of the number is a
   240 +   ITAD (Internet Telephony Administrative Domain) as defined
   241 +   in RFCs 3872 and 2871, and as allocated by the IANA in
   242 +   http://www.iana.org/assignments/trip-parameters. The ITAD is
   243 +   left intact and not refersed as ENUM requires. To learn more
   244 +   about ISN please refer to documents at www.freenum.org.
   245 +
   246 +   To complete a ISN lookup on the user part of the Request-URI,
   247 +   isn_query() is used instead of enum_query().
   248 +
   249  1.2. Dependencies
   251     The module depends on the following modules (in the other words
   252 @@ -158,17 +178,27 @@
   253     Example 1.3. Setting i_enum_suffix module parameter
   254  modparam("enum", "i_enum_suffix", "e1234.arpa.")
   256 -1.3.4. branchlabel (string)
   257 +1.3.4. isn_suffix (string)
   258 +
   259 +   The domain suffix to be used for isn_query() lookups. Can be
   260 +   overridden by a parameter to isn_query.
   261 +
   262 +   Default value is "freenum.org."
   263 +
   264 +   Example 1.4. Setting isn_suffix module parameter
   265 +modparam("enum", "isn_suffix", "freenum.org.")
   266 +
   267 +1.3.5. branchlabel (string)
   269     This parameter determines which label i_enum_query() will use
   270     to branch off to the infrastructure ENUM tree.
   272     Default value is ""i""
   274 -   Example 1.4. Setting brachlabel module parameter
   275 +   Example 1.5. Setting branchlabel module parameter
   276  modparam("enum", "branchlabel", "i")
   278 -1.3.5. bl_algorithm (string)
   279 +1.3.6. bl_algorithm (string)
   281     This parameter determines which algorithm i_enum_query() will
   282     use to select the position in the DNS tree where the
   283 @@ -182,7 +212,7 @@
   284     [branchlabel].[reverse-country-code].[i_enum_suffix] to
   285     indicate after how many digits the label should in inserted.
   287 -   Example 1.5. Zone file example
   288 +   Example 1.6. Zone file example
   289  i.1.e164.arpa.                     IN TXT   "4"
   290  9.9.9.8.7.6.5.i.4.3.2.1.e164.arpa. IN NAPTR "NAPTR content for  +1 234 5
   291  678 999"
   292 @@ -196,7 +226,7 @@
   293     allocated yet. This version of the code uses 65300. See
   294     resolve.h.
   296 -   Example 1.6. Zone file example
   297 +   Example 1.7. Zone file example
   298  i.1.e164.arpa.     TYPE65300  \# 14 (
   299                                04    ; position
   300                                01 69 ; separator
   301 @@ -208,7 +238,7 @@
   303     Default value is "cc"
   305 -   Example 1.7. Setting the bl_algorithm module parameter
   306 +   Example 1.8. Setting the bl_algorithm module parameter
   307  modparam("enum", "bl_algorithm", "txt")
   309  1.4. Exported Functions
   310 @@ -225,7 +255,7 @@
   312     This function can be used from REQUEST_ROUTE.
   314 -   Example 1.8. enum_query usage
   315 +   Example 1.9. enum_query usage
   316  ...
   317  # search for "e2u+sip" in freenum.org
   318  enum_query("freenum.org.");
   319 @@ -262,7 +292,7 @@
   321     This function can be used from REQUEST_ROUTE.
   323 -   Example 1.9. enum_pv_query usage
   324 +   Example 1.10. enum_pv_query usage
   325  ...
   326  # search for "e2u+sip" in freenum.org
   327  enum_pv_query("$avp(i:100)", "freenum.org.");
   328 @@ -296,14 +326,42 @@
   329     ftp://ftp.rfc-editor.org/in-notes/internet-drafts/draft-haberle
   330     r-carrier-enum-01.txt for the rationale behind this function.
   332 -1.4.4. is_from_user_enum()
   333 +1.4.4.  isn_query(["suffix"[,"service"]])
   334 +
   335 +   The function performs a ISN query and rewrites the
   336 +   Request-URI with the result of the query. See Section 1.1,
   337 +   "Overview" for more information.
   338 +
   339 +   Meaning of the parameters is as follows:
   340 +     * suffix - Suffix to be appended to the domain name.
   341 +     * service - Service string to be used in the service field.
   342 +
   343 +   This function can be used from REQUEST_ROUTE.
   344 +
   345 +   See ftp://www.ietf.org/rfc/rfc3872.txt and
   346 +   ftp://www.ietf.org/rfc/rfc2871.txt for information
   347 +   regarding the ITAD part of the ISN string.
   348 +
   349 +   Example 1.11. isn_query usage
   350 +...
   351 +# search for "e2u+sip" in freenum.org
   352 +isn_query("freenum.org.");
   353 +...
   354 +# search for "e2u+sip" in default tree (configured as parameter)
   355 +enum_query();
   356 +...
   357 +# search for "e2u+voice:sip" in freenum.org
   358 +enum_query("freenum.org.","voice");
   359 +...
   360 +
   361 +1.4.5. is_from_user_enum()
   363     Checks if the user part of from URI is found in an enum lookup.
   364     Returns 1 if yes and -1 if not.
   366     This function can be used from REQUEST_ROUTE.
   368 -   Example 1.10. is_from_user_enum usage
   369 +   Example 1.12. is_from_user_enum usage
   370  ...
   371  if (is_from_user_enum()) {
   372          ....
   373 Index: modules/enum/doc/enum.xml
   374 diff -Nau modules/enum/doc/enum.xml.orig modules/enum/doc/enum.xml
   375 --- modules/enum/doc/enum.xml.orig	2009-10-16 02:31:52.000000000 +0200
   376 +++ modules/enum/doc/enum.xml	2010-01-18 18:01:15.954172402 +0100
   377 @@ -33,8 +33,8 @@
   378  	</copyright>
   379  	<revhistory>
   380  	    <revision>
   381 -		<revnumber>$Revision: 5901 $</revnumber>
   382 -		<date>$Date: 2009-07-21 10:45:05 +0300 (Tue, 21 Jul 2009) $</date>
   383 +		<revnumber>$Revision: 5907 $</revnumber>
   384 +		<date>$Date: 2010-01-18 10:45:05 +0100 (Mon, 18 Jan 2010) $</date>
   385  	    </revision>
   386  	</revhistory>
   387      </bookinfo>
   388 Index: modules/enum/doc/enum_admin.xml
   389 diff -Nau modules/enum/doc/enum_admin.xml.orig modules/enum/doc/enum_admin.xml
   390 --- modules/enum/doc/enum_admin.xml.orig	2010-01-18 12:33:30.053644000 +0100
   391 +++ modules/enum/doc/enum_admin.xml	2010-01-18 18:14:59.583157910 +0100
   392 @@ -75,6 +75,24 @@
   393  		and -1 if not.
   394  	</para>
   395  	<para>
   396 +		In addition to standard ENUM, support for ISN (ITAD Subscriber
   397 +		Numbers) is provided as well. To allow ISN lookups to resolve,
   398 +		a different formatting algorithm is expected by the DNS server.
   399 +		Whereas a ENUM NAPTR record expects a DNS query of the form
   400 +		9.8.7.6.5.4.3.2.1.<suffix>, ISN method expects a DNS query of
   401 +		the form 6.5.1212.<suffix>. That is, a valid ISN number includes
   402 +		a prefix of '56' in the example. The rest of the number is a
   403 +		ITAD (Internet Telephony Administrative Domain) as defined
   404 +		in RFCs 3872 and 2871, and as allocated by the IANA in
   405 +		http://www.iana.org/assignments/trip-parameters. The ITAD is
   406 +		left intact and not refersed as ENUM requires. To learn more
   407 +		about ISN please refer to documents at www.freenum.org.
   408 +	</para>
   409 +	<para>
   410 +		To complete a ISN lookup on the user part of the Request-URI,
   411 +		isn_query() is used instead of enum_query().
   412 +	</para>
   413 +	<para>
   414  		Enum module also implements is_from_user_enum function.
   415  		This function does an enum lookup on the from user and
   416  		returns true if found, false otherwise.
   417 @@ -153,6 +171,22 @@
   418                  </example>
   419          </section>
   420          <section>
   421 +                <title><varname>isn_suffix</varname> (string)</title>
   422 +                <para>
   423 +                The domain suffix to be used for isn_query() lookups. Can
   424 +                be overridden by a parameter to isn_query.
   425 +                </para>
   426 +                <para>
   427 +                Default value is <quote>freenum.org.</quote>
   428 +                </para>
   429 +                <example>
   430 +                <title>Setting isn_suffix module parameter</title>
   431 +                <programlisting format="linespecific">
   432 +modparam("enum", "isn_suffix", "freenum.org.")
   433 +</programlisting>
   434 +                </example>
   435 +        </section>
   436 +        <section>
   437                  <title><varname>branchlabel</varname> (string)</title>
   438                  <para>
   439                  This parameter determines which label i_enum_query() will use
   440 @@ -162,7 +196,7 @@
   441                  Default value is <quote>"i"</quote>
   442                  </para>
   443                  <example>
   444 -                <title>Setting brachlabel module parameter</title>
   445 +                <title>Setting branchlabel module parameter</title>
   446                  <programlisting format="linespecific">
   447  modparam("enum", "branchlabel", "i")
   448  </programlisting>
   449 @@ -353,6 +387,53 @@
   450          </section>
   452  	<section>
   453 +		<title>
   454 +		<function moreinfo="none">isn_query(["suffix"[,"service"]])</function>
   455 +		</title>
   456 +		<para>
   457 +		The function performs a ISN query and rewrites the Request-URI with 
   458 +		the result of the query. See <xref linkend="sec-overview"/> for more 
   459 +		information.
   460 +		</para>
   461 +		<para>Meaning of the parameters is as follows:</para>
   462 +		<itemizedlist>
   463 +		<listitem>
   464 +			<para><emphasis>suffix</emphasis> - Suffix to be appended to the 
   465 +			domain name.
   466 +			</para>
   467 +		</listitem>
   468 +		<listitem>
   469 +			<para><emphasis>service</emphasis> - Service string to be used in 
   470 +			the service field.
   471 +			</para>
   472 +		</listitem>
   473 +		</itemizedlist>
   474 +		<para>
   475 +			This function can be used from REQUEST_ROUTE.
   476 +		</para>
   477 +		<para>
   478 +			See ftp://www.ietf.org/rfc/rfc3872.txt and
   479 +			ftp://www.ietf.org/rfc/rfc2871.txt for information
   480 +			regarding the ITAD part of the ISN string.
   481 +		</para>
   482 +		<example>
   483 +		<title><function moreinfo="none">isn_query</function> usage</title>
   484 +		<programlisting format="linespecific">
   485 +...
   486 +# search for "e2u+sip" in freenum.org 
   487 +isn_query("freenum.org.");
   488 +...
   489 +# search for "e2u+sip" in default tree (configured as parameter)
   490 +isn_query();
   491 +...
   492 +# search for "e2u+voice:sip" in freenum.org
   493 +isn_query("freenum.org.","voice");
   494 +...
   495 +</programlisting>
   496 +		</example>
   497 +	</section>
   498 +
   499 +	<section>
   500  		<title><function moreinfo="none">is_from_user_enum()</function></title>
   501  		<para>
   502  		Checks if the user part of from <abbrev>URI</abbrev>

mercurial