Browse Source

* Modules: enum

Moved modules_k/enum to modules and removed modules_s/enum.
Juha Heinanen 16 years ago
parent
commit
81198ed38e

+ 0 - 0
modules_k/enum/Makefile → modules/enum/Makefile


+ 0 - 0
modules_k/enum/README → modules/enum/README


+ 0 - 0
modules_k/enum/doc/enum.xml → modules/enum/doc/enum.xml


+ 0 - 0
modules_k/enum/doc/enum_admin.xml → modules/enum/doc/enum_admin.xml


+ 0 - 0
modules_k/enum/enum.c → modules/enum/enum.c


+ 0 - 0
modules_k/enum/enum.h → modules/enum/enum.h


+ 0 - 0
modules_k/enum/enum_mod.c → modules/enum/enum_mod.c


+ 0 - 0
modules_k/enum/enum_mod.h → modules/enum/enum_mod.h


+ 0 - 15
modules_s/enum/Makefile

@@ -1,15 +0,0 @@
-# Makefile v 1.0 2002/12/27
-#
-# Enum module makefile
-#
-# 
-# WARNING: do not run this directly, it should be run by the master Makefile
-
-include ../../Makefile.defs
-auto_gen=
-NAME=enum.so
-LIBS=
-
-DEFS+=-DSER_MOD_INTERFACE
-
-include ../../Makefile.modules

+ 0 - 159
modules_s/enum/README

@@ -1,159 +0,0 @@
-
-Enum Module
-
-Juha Heinanen
-
-   Copyright © 2002, 2003 Juha Heinanen
-     _________________________________________________________
-
-   Table of Contents
-   1. User's Guide
-
-        1.1. Overview
-        1.2. Dependencies
-        1.3. Exported Parameters
-
-              1.3.1. domain_suffix (string)
-              1.3.2. tel_uri_params (string)
-
-        1.4. Exported Functions
-
-              1.4.1. enum_query(),enum_query("suffix"),
-                      enum_query("suffix", "service")
-
-              1.4.2. is_from_user_e164()
-
-   2. Developer's Guide
-   3. Frequently Asked Questions
-
-   List of Examples
-   1-1. Setting domain_suffix module parameter
-   1-2. Setting tel_uri_params module parameter
-   1-3. enum_query usage
-   1-4. is_from_user_e164 usage
-     _________________________________________________________
-
-Chapter 1. User's Guide
-
-1.1. Overview
-
-   Enum module implements enum_query function that makes an enum
-   query based on the user part of the current Request-URI. The
-   function assumes that the user part consists of an
-   international phone number of the form +decimal-digits, where
-   the number of digits is at least 2 and at most 15. Out of this
-   number enum_query forms a domain name, where the digits are in
-   reverse order and separated by dots followed by domain suffix
-   that by default is "e164.arpa.". For example, if the user part
-   is +35831234567, the domain name will be
-   "7.6.5.4.3.2.1.3.8.5.3.e164.arpa.".
-
-   After forming the domain name, enum_query queries DNS for its
-   NAPTR records. From the possible response enum_query chooses
-   those records, whose flags field has string value "u", and
-   whose services field has string value "e2u+[service:]sip"
-   (case is ignored in both cases), and whose regexp field is of
-   the form !pattern!replacement!.
-
-   Then enum_query sorts the chosen NAPTR records based on their
-   <order, preference>. After sorting, enum_query replaces the
-   current Request URI by applying regexp of the most preferred
-   NAPTR record its user part and appends to the request new
-   branches by applying regexp of each remaining NAPTR record to
-   the user part of the current Request URI. If a new URI is a
-   tel URI, enum_query appends to it as tel URI parameters the
-   value of tel_uri_params module parameter. Finally, enum_query
-   associates a q value with each new URI based on the <order,
-   preference> of the corresponding NAPTR record.
-
-   Enum query returns 1 if the current Request URI was replaced
-   and -1 if not.
-
-   Enum module also implements is_from_user_e164 function that
-   checks if the user part of from URI is an E164 number.
-     _________________________________________________________
-
-1.2. Dependencies
-
-   The module depends on the following modules (in the other
-   words the listed modules must be loaded before this module):
-
-     * No dependencies.
-     _________________________________________________________
-
-1.3. Exported Parameters
-
-1.3.1. domain_suffix (string)
-
-   The domain suffix to be added to the domain name obtained from
-   the digits of an E164 number. Can be overridden by a parameter
-   to enum_query.
-
-   Default value is "e164.arpa."
-
-   Example 1-1. Setting domain_suffix module parameter
-modparam("enum", "domain_suffix", "e1234.arpa.")
-     _________________________________________________________
-
-1.3.2. tel_uri_params (string)
-
-   A string whose contents is appended to each new tel URI in the
-   request as tel URI parameters.
-
-   Note
-
-   Currently SER does not support tel URIs. This means that at
-   present tel_uri_params is appended as URI parameters to every
-   URI.
-
-   Default value is ""
-
-   Example 1-2. Setting tel_uri_params module parameter
-modparam("enum", "tel_uri_params", ";npdi")
-     _________________________________________________________
-
-1.4. Exported Functions
-
-1.4.1. enum_query(),enum_query("suffix"), enum_query("suffix",
-"service")
-
-   The function performs an enum query and rewrites the
-   Request-URI with the result of the query. See Section 1.1> for
-   more information.
-
-   Meaning of the parameters is as follows:
-
-     * suffix - Suffix to be appended to the domain name.
-     * service - Service string to be used in the service field.
-
-   Example 1-3. enum_query usage
-...
-enum_query("freenum.org.");
-...
-     _________________________________________________________
-
-1.4.2. is_from_user_e164()
-
-   Checks if the user part of from URI an E164 number of the form
-   +[0-9]{2,15}. Returns 1 if yes and -1 if not.
-
-   Example 1-4. is_from_user_e164 usage
-...
-if (is_from_user_e164()) {
-    ....
-};
-...
-     _________________________________________________________
-
-Chapter 2. Developer's Guide
-
-   To be done.
-     _________________________________________________________
-
-Chapter 3. Frequently Asked Questions
-
-   3.1. What is the meaning of life ?
-
-   3.1. What is the meaning of life ?
-
-   42

+ 0 - 29
modules_s/enum/doc/Makefile

@@ -1,29 +0,0 @@
-#
-# The list of documents to build (without extensions)
-#
-DOCUMENTS = enum
-
-#
-# The root directory containing Makefile.doc
-#
-ROOT_DIR=../../..
-
-#
-# Validate docbook documents before generating output
-# (may be slow)
-#
-#VALIDATE=1
-
-#
-# You can override the stylesheet used to generate
-# xhtml documents here
-#
-#XHTML_XSL=$(ROOT_DIR)/doc/stylesheets/xhtml.xsl
-
-#
-# You can override the stylesheet used to generate
-# plain text documents here
-#
-#TXT_XSL=$(XHTML_XSL)
-
-include $(ROOT_DIR)/Makefile.doc

+ 0 - 95
modules_s/enum/doc/enum.xml

@@ -1,95 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 
-   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
-
-<section id="enum" xmlns:xi="http://www.w3.org/2001/XInclude">
-    <sectioninfo>
-	<authorgroup>
-	    <author>
-		<firstname>Juha</firstname>
-		<surname>Heinanen</surname>
-		<email>[email protected]</email>
-	    </author>
-	</authorgroup>
-
-	<copyright>
-	    <year>2002</year>
-	    <year>2003</year>
-	    <holder>Juha Heinanen</holder>
-	</copyright>
-
-	<revhistory>
-	    <revision>
-		<revnumber>$Revision$</revnumber>
-		<date>$Date$</date>
-	    </revision>
-	</revhistory>
-    </sectioninfo>
-
-    <title>ENUM Module</title>
-
-    <section id="enum_overview">
-	<title>Overview</title>
-	<para>
-	    Enum module implements enum_query function that makes an enum query
-	    based on the user part of the current Request-URI. The function
-	    assumes that the user part consists of an international phone
-	    number of the form +decimal-digits, where the number of digits is
-	    at least 2 and at most 15. Out of this number
-	    <function>enum_query</function> forms a domain name, where the
-	    digits are in reverse order and separated by dots followed by
-	    domain suffix that by default is "e164.arpa.". For example, if the
-	    user part is +35831234567, the domain name will be
-	    "7.6.5.4.3.2.1.3.8.5.3.e164.arpa.".
-	</para>
-	<para>
-	    After forming the domain name, <function>enum_query</function>
-	    queries DNS for its NAPTR records. From the possible response
-	    <function>enum_query</function> chooses those records, whose flags
-	    field has string value "u", and whose services field has string
-	    value "e2u+[service:]sip" or
-	    "e2u+type[:subtype][+type[:subtype]...]" (case is ignored in both
-	    cases), and whose regexp field is of the form
-	    !pattern!replacement!.
-	</para>
-	<para>
-	    Then <function>enum_query</function> sorts the chosen NAPTR records
-	    based on their &lt;order, preference&gt;.  After sorting,
-	    <function>enum_query</function> replaces the current Request URI by
-	    applying regexp of the most preferred NAPTR record its user part
-	    and appends to the request new branches by applying regexp of each
-	    remaining NAPTR record to the user part of the current Request
-	    URI. If a new URI is a tel URI, <function>enum_query</function>
-	    appends to it as tel URI parameters the value of tel_uri_params
-	    module parameter. Finally, <function>enum_query</function>
-	    associates a q value with each new URI based on the &lt;order,
-	    preference&gt; of the corresponding NAPTR record.
-	</para>
-	<para>
-	    When using <function>enum_query</function> without any parameters,
-	    it searches for NAPTRs with service type "e2u+sip" in the default
-	    enum tree. When using <function>enum_query</function> with a single
-	    parameter, this parameter will be used as enum tree. When using
-	    <function>enum_query</function> with two
-	    parameters, the functionality depends on the first letter in the
-	    second parameter. When the first letter is not a '+' sign, the
-	    second parameter will be used to search for NAPTRs with service
-	    type "e2u+parameter:sip". When the second parameter starts with a
-	    '+' sign, the ENUM lookup also supports compound NAPTRs (e.g.
-	    "e2u+voice:sip+video:sip") and searching for multiple service types
-	    within one lookup.  Multiple service types must be separeted by a
-	    '+' sign.
-	</para>
-	<para>
-	    Enum query returns 1 if the current Request URI was replaced and -1 if not.
-	</para>
-	<para>
-	    Enum module also implements is_from_user_e164 function that checks if the user part of
-	    from URI is an E164 number.
-	</para>
-    </section>
-
-    <xi:include href="params.xml"/>
-    <xi:include href="functions.xml"/>
-
-</section>

+ 0 - 83
modules_s/enum/doc/functions.xml

@@ -1,83 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 
-   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
-
-<section id="enum.functions" xmlns:xi="http://www.w3.org/2001/XInclude">
-    <sectioninfo>
-	<revhistory>
-	    <revision>
-		<revnumber>$Revision$</revnumber>
-		<date>$Date$</date>
-	    </revision>
-	</revhistory>
-    </sectioninfo>
-
-    <title>Functions</title>
-
-    <section id="enum_query"> 
-	<title><function>enum_query(),enum_query("suffix"), enum_query("suffix","service")</function></title>
-	    <para>
-	    The function performs an enum query and rewrites the Request-URI
-	    with the result of the query. See <xref linkend="enum_overview"/>
-	    for more information.
-	</para>
-	<para>Meaning of the parameters is as follows:</para>
-	<itemizedlist>
-	    <listitem>
-		<para>
-		    <emphasis>suffix</emphasis> - Suffix to be appended to the domain name.
-		</para>
-	    </listitem>
-	    <listitem>
-		<para>
-		    <emphasis>service</emphasis> - Service string to be used in
-		    the service field.
-		</para>
-	    </listitem>
-	</itemizedlist>
-	<example>
-	    <title><function>enum_query</function> usage</title>
-	    <programlisting>
-...
-# search for "e2u+sip" in freenum.org 
-enum_query("freenum.org.");
-...
-# search for "e2u+sip" in default tree (configured as parameter)
-enum_query();
-...
-# search for "e2u+voice:sip" in e164.arpa
-enum_query("e164.arpa.","voice");
-...
-# search for service type "sip" or "voice:sip" or "video:sip"
-# note the '+' sign in front of the second parameter
-enum_query("e164.arpa.","+sip+voice:sip+video:sip");
-...
-# quering for service sip and voice:sip
-enum_query("e164.arpa.");
-enum_query("e164.arpa.","voice");
-# or use instead
-enum_query("e164.arpa.","+sip+voice:sip");
-...
-</programlisting>
-	</example>
-    </section>
-    
-    <section id="is_from_user_e164">
-	<title><function>is_from_user_e164()</function></title>
-	<para>
-	    Checks if the user part of from <abbrev>URI</abbrev> an <abbrev>E164</abbrev> number
-	    of the form +[0-9]{2,15}. Returns 1 if yes and -1 if not.
-	</para>
-	<example>
-	    <title><function>is_from_user_e164</function> usage</title>
-	    <programlisting>
-...
-if (is_from_user_e164()) {
-    ....
-};
-...
-	    </programlisting>
-	</example>
-    </section>
-
-</section>

+ 0 - 58
modules_s/enum/doc/params.xml

@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 
-   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
-
-<section id="enum.parameters" xmlns:xi="http://www.w3.org/2001/XInclude">
-    <sectioninfo>
-	<revhistory>
-	    <revision>
-		<revnumber>$Revision$</revnumber>
-		<date>$Date$</date>
-	    </revision>
-	</revhistory>
-    </sectioninfo>
-
-    <title>Parameters</title>
-
-    <section id="domain_suffix">
-	<title><varname>domain_suffix</varname> (string)</title>
-	<para>
-	    The domain suffix to be added to the domain name obtained from the
-	    digits of an <acronym>E164</acronym> number. Can be overridden by a
-	    parameter to enum_query.
-	</para>
-	<para>
-	    Default value is "e164.arpa.".
-	</para>
-	<example>
-	    <title>Setting domain_suffix module parameter</title>
-	    <programlisting>
-modparam("enum", "domain_suffix", "e1234.arpa.")
-	    </programlisting>
-	</example>
-    </section>
-
-    <section id="tel_uri_params">
-	<title><varname>tel_uri_params</varname> (string)</title>
-	<para>
-	    A string whose contents is appended to each new tel URI in the
-	    request as tel URI parameters.
-	</para>
-	<note>
-	    <para>
-		Currently SER does not support tel URIs. This means that at
-		present tel_uri_params is appended as URI parameters to every
-		URI.
-	    </para>
-	</note>
-	<para>
-	    Default value is "".
-	</para>
-	<example>
-	    <title>Setting tel_uri_params module parameter</title>
-	    <programlisting>
-modparam("enum", "tel_uri_params", ";npdi")
-	    </programlisting>
-	</example>
-    </section>
-</section>

+ 0 - 476
modules_s/enum/enum.c

@@ -1,476 +0,0 @@
-/*
- * $Id$
- *
- * Enum and E164 related functions
- *
- * Copyright (C) 2002-2003 Juha Heinanen
- *
- * This file is part of ser, a free SIP server.
- *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-#include "enum.h"
-#include "../../parser/parse_uri.h"
-#include "../../parser/parse_from.h"
-#include "../../ut.h"
-#include "../../resolve.h"
-#include "../../mem/mem.h"
-#include "../../dset.h"
-#include "../../qvalue.h"
-#include "../../sr_module.h"
-#include "enum_mod.h"
-#include "regexp.h"
-
-
-/* return the length of the string until c, if not found returns n */
-static inline int findchr(char* p, int c, unsigned int size)
-{
-  int len=0;
-
-  for(;len<size;p++){
-    if (*p==(unsigned char)c) {
-      return len;
-    }
-    len++;   
-  }
-  return len;
-}
-
-/* Checks if NAPTR record has flag u and its services field
- * e2u+[service:]sip or
- * e2u+service[+service[+service[+...]]]
- */
-static inline int sip_match( struct naptr_rdata* naptr, str* service)
-{
-  if (service->len == 0) {
-    return (naptr->flags_len == 1) &&
-      ((naptr->flags[0] == 'u') || (naptr->flags[0] == 'U')) &&
-      (naptr->services_len == 7) &&
-      ((strncasecmp(naptr->services, "e2u+sip", 7) == 0) ||
-       (strncasecmp(naptr->services, "sip+e2u", 7) == 0));
-  } else if (service->s[0] != '+') {
-    return (naptr->flags_len == 1) &&
-      ((naptr->flags[0] == 'u') || (naptr->flags[0] == 'U')) &&
-      (naptr->services_len == service->len + 8) &&
-      (strncasecmp(naptr->services, "e2u+", 4) == 0) &&
-      (strncasecmp(naptr->services + 4, service->s, service->len) == 0) &&
-      (strncasecmp(naptr->services + 4 + service->len, ":sip", 4) == 0);
-  } else { /* handle compound NAPTRs and multiple services */
-    str bakservice, baknaptr; /* we bakup the str */
-    int naptrlen, len;        /* length of the extracted service */
-
-    /* RFC 3761, NAPTR service field must start with E2U+ */
-    if (strncasecmp(naptr->services, "e2u+", 4) != 0) {
-      return 0;
-    }
-    baknaptr.s   = naptr->services + 4; /* leading 'e2u+' */
-    baknaptr.len = naptr->services_len - 4;
-    for (;;) { /* iterate over services in NAPTR */
-      bakservice.s   = service->s + 1; /* leading '+' */
-      bakservice.len = service->len - 1;
-      naptrlen = findchr(baknaptr.s,'+',baknaptr.len);
-
-      for (;;) { /* iterate over services in enum_query */
-        len = findchr(bakservice.s,'+',bakservice.len);
-        if ((naptrlen == len ) && !strncasecmp(baknaptr.s , bakservice.s, len)) {
-          return 1;
-        }
-        if ( (bakservice.len -= len+1) > 0) {
-          bakservice.s += len+1;
-          continue;
-        }
-        break;
-      }
-      if ( (baknaptr.len -= naptrlen+1) > 0) {
-        baknaptr.s += naptrlen+1;
-        continue;
-      }
-      break;
-    }
-    /* no matching service found */
-    return 0;
-  }    
-}
-
-
-static int test_e164(str* user)
-{
-    int i;
-    char c;
-
-    if ((user->len > 2) && (user->len < 17) && ((user->s)[0] == '+')) {
-	for (i = 1; i <= user->len; i++) {
-	    c = (user->s)[i];
-	    if (c < '0' && c > '9') return -1;
-	}
-	return 1;
-    }
-    return -1;
-}
-
-
-/*
- * Check if from user is an e164 number
- */
-int is_e164(struct sip_msg* msg, char* p1, char* p2)
-{
-    str user;
-
-    if (get_str_fparam(&user, msg, (fparam_t*)p1) < 0) {
-	ERR("Error while obtaining username to be checked\n");
-	return -1;
-    }
-    return test_e164(&user);
-}
-
-
-/* Parse NAPTR regexp field of the form !pattern!replacement! and return its
- * components in pattern and replacement parameters.  Regexp field starts at
- * address first and is len characters long.
- */
-static inline int parse_naptr_regexp(char* first, int len, str* pattern,
-										str* replacement)
-{
-	char *second, *third;
-
-	if (len > 0) {
-		if (*first == '!') {
-			second = (char *)memchr((void *)(first + 1), '!', len - 1);
-			if (second) {
-				len = len - (second - first + 1);
-				if (len > 0) {
-					third = memchr(second + 1, '!', len);
-					if (third) {
-						pattern->len = second - first - 1;
-						pattern->s = first + 1;
-						replacement->len = third - second - 1;
-						replacement->s = second + 1;
-						return 1;
-					} else {
-						LOG(L_ERR, "parse_regexp(): third ! missing from regexp\n");
-						return -1;
-					}
-				} else {
-					LOG(L_ERR, "parse_regexp(): third ! missing from regexp\n");
-					return -2;
-				}
-			} else {
-				LOG(L_ERR, "parse_regexp(): second ! missing from regexp\n");
-				return -3;
-			}
-		} else {
-			LOG(L_ERR, "parse_regexp(): first ! missing from regexp\n");
-			return -4;
-		}
-	} else {
-		LOG(L_ERR, "parse_regexp(): regexp missing\n");
-		return -5;
-	}
-}
-
-
-/* 
- * Add parameter to URI.
- */
-int add_uri_param(str *uri, str *param, str *new_uri)
-{
-	struct sip_uri puri;
-	char *at;
-
-	if (parse_uri(uri->s, uri->len, &puri) < 0) {
-		return 0;
-	}
-
-	/* if current uri has no headers, pad param to the end of uri */
-	if (puri.headers.len == 0) {
-		memcpy(uri->s + uri->len, param->s, param->len);
-		uri->len = uri->len + param->len;
-		new_uri->len = 0;
-		return 1;
-	}
-
-	/* otherwise take the long path and create new_uri */
-	at = new_uri->s;
-	memcpy(at, "sip:", 4);
-	at = at + 4;
-	if (puri.user.len) {
-		memcpy(at, puri.user.s, puri.user.len);
-		at = at + puri.user.len;
-		if (puri.passwd.len) {
-			*at = ':';
-			at = at + 1;
-			memcpy(at, puri.passwd.s, puri.passwd.len);
-			at = at + puri.passwd.len;
-		};
-		*at = '@';
-		at = at + 1;
-	}
-	memcpy(at, puri.host.s, puri.host.len);
-	at = at + puri.host.len;
-	if (puri.port.len) {
-		*at = ':';
-		at = at + 1;
-		memcpy(at, puri.port.s, puri.port.len);
-		at = at + puri.port.len;
-	}
-	if (puri.params.len) {
-		*at = ';';
-		at = at + 1;
-		memcpy(at, puri.params.s, puri.params.len);
-		at = at + puri.params.len;
-	}
-	memcpy(at, param->s, param->len);
-	at = at + param->len;
-	*at = '?';
-	at = at + 1;
-	memcpy(at, puri.headers.s, puri.headers.len);
-	at = at + puri.headers.len;
-	new_uri->len = at - new_uri->s;
-	return 1;
-}
-
-/*
- * Tests if one result record is "greater" that the other.  Non-NAPTR records
- * greater that NAPTR record.  An invalid NAPTR record is greater than a 
- * valid one.  Valid NAPTR records are compared based on their
- * (order,preference).
- */
-static inline int naptr_greater(struct rdata* a, struct rdata* b)
-{
-	struct naptr_rdata *na, *nb;
-
-	if (a->type != T_NAPTR) return 1;
-	if (b->type != T_NAPTR) return 0;
-
-	na = (struct naptr_rdata*)a->rdata;
-	if (na == 0) return 1;
-
-	nb = (struct naptr_rdata*)b->rdata;
-	if (nb == 0) return 0;
-	
-	return (((na->order) << 16) + na->pref) >
-		(((nb->order) << 16) + nb->pref);
-}
-	
-	
-/*
- * Bubble sorts result record list according to naptr (order,preference).
- */
-static inline void naptr_sort(struct rdata** head)
-{
-	struct rdata *p, *q, *r, *s, *temp, *start;
-
-        /* r precedes p and s points to the node up to which comparisons
-         are to be made */ 
-
-	s = NULL;
-	start = *head;
-	while ( s != start -> next ) { 
-		r = p = start ; 
-		q = p -> next ;
-		while ( p != s ) { 
-			if ( naptr_greater(p, q) ) { 
-				if ( p == start ) { 
-					temp = q -> next ; 
-					q -> next = p ; 
-					p -> next = temp ;
-					start = q ; 
-					r = q ; 
-				} else {
-					temp = q -> next ; 
-					q -> next = p ; 
-					p -> next = temp ;
-					r -> next = q ; 
-					r = q ; 
-				} 
-			} else {
-				r = p ; 
-				p = p -> next ; 
-			} 
-			q = p -> next ; 
-			if ( q == s ) s = p ; 
-		}
-	}
-	*head = start;
-}	
-
-	
-/*
- * See documentation in README file.
- */
-
-int enum_query(struct sip_msg* msg, char* p1, char* p2)
-{
-	char *user_s;
-	int user_len, i, j, first;
-	char name[MAX_DOMAIN_SIZE];
-	char uri[MAX_URI_SIZE];
-	char new_uri[MAX_URI_SIZE];
-	unsigned int priority, curr_prio;
-	qvalue_t q;
-
-	struct rdata* head;
-	struct rdata* l;
-	struct naptr_rdata* naptr;
-
-	str pattern, replacement, result, new_result;
-
-	char string[17];
-
-	str suffix, service;
-
-	if (p1) {
-	    if (get_str_fparam(&suffix, msg, (fparam_t*)p1) < 0) {
-		ERR("Unable to get suffix value\n");
-		return -1;
-	    }
-	} else {
-	    suffix = domain_suffix;
-	}
-
-	if (p2) {
-	    if (get_str_fparam(&service, msg, (fparam_t*)p2) < 0) {
-		ERR("Unable to get service value\n");
-		return -1;
-	    }
-	} else {
-	    service = default_service;
-	}
-	
-	if (parse_sip_msg_uri(msg) < 0) {
-		LOG(L_ERR, "enum_query(): uri parsing failed\n");
-		return -1;
-	}
-
-	if (test_e164(&(msg->parsed_uri.user)) == -1) {
-		LOG(L_ERR, "enum_query(): uri user is not an E164 number\n");
-		return -1;
-	}
-
-	user_s = msg->parsed_uri.user.s;
-	user_len = msg->parsed_uri.user.len;
-
-	memcpy(&(string[0]), user_s, user_len);
-	string[user_len] = (char)0;
-
-	j = 0;
-	for (i = user_len - 1; i > 0; i--) {
-		name[j] = user_s[i];
-		name[j + 1] = '.';
-		j = j + 2;
-	}
-
-	memcpy(name + j, suffix.s, suffix.len + 1);
-
-	head = get_record(name, T_NAPTR, RES_ONLY_TYPE);
-
-	if (head == 0) {
-		DBG("enum_query(): No NAPTR record found for %s.\n", name);
-		return -1;
-	}
-
-	naptr_sort(&head);
-
-	q = MAX_Q - 10;
-	curr_prio = 0;
-	first = 1;
-
-	for (l = head; l; l = l->next) {
-
-		if (l->type != T_NAPTR) continue; /*should never happen*/
-		naptr = (struct naptr_rdata*)l->rdata;
-		if (naptr == 0) {
-			LOG(L_CRIT, "enum_query: BUG: null rdata\n");
-			continue;
-		}
-
-		DBG("enum_query(): order %u, pref %u, flen %u, flags '%.*s', slen %u, "
-		    "services '%.*s', rlen %u, regexp '%.*s'\n", naptr->order, naptr->pref,
-		    naptr->flags_len, (int)(naptr->flags_len), ZSW(naptr->flags),
-		    naptr->services_len,
-		    (int)(naptr->services_len), ZSW(naptr->services), naptr->regexp_len,
-		    (int)(naptr->regexp_len), ZSW(naptr->regexp));
-
-		if (sip_match(naptr, &service) == 0) continue;
-
-		if (parse_naptr_regexp(&(naptr->regexp[0]), naptr->regexp_len,
-				       &pattern, &replacement) < 0) {
-			LOG(L_ERR, "enum_query(): parsing of NAPTR regexp failed\n");
-			continue;
-		}
-		result.s = &(uri[0]);
-		result.len = MAX_URI_SIZE;
-		/* Avoid making copies of pattern and replacement */
-		pattern.s[pattern.len] = (char)0;
-		replacement.s[replacement.len] = (char)0;
-		if (reg_replace(pattern.s, replacement.s, &(string[0]),
-				&result) < 0) {
-			pattern.s[pattern.len] = '!';
-			replacement.s[replacement.len] = '!';
-			LOG(L_ERR, "enum_query(): regexp replace failed\n");
-			continue;
-		}
-		DBG("enum_query(): resulted in replacement: '%.*s'\n",
-		    result.len, ZSW(result.s));
-		pattern.s[pattern.len] = '!';
-		replacement.s[replacement.len] = '!';
-		
-		if (tel_uri_params.len > 0) {
-			if (result.len + tel_uri_params.len > MAX_URI_SIZE - 1) {
-				LOG(L_ERR, "ERROR: enum_query(): URI is too long\n");
-				continue;
-			}
-			new_result.s = &(new_uri[0]);
-			new_result.len = MAX_URI_SIZE;
-			if (add_uri_param(&result, &tel_uri_params, &new_result) == 0) {
-				LOG(L_ERR, "ERROR: enum_query(): Parsing of URI failed\n");
-				continue;
-			}
-			if (new_result.len > 0) {
-				result = new_result;
-			}
-		}
-
-		if (first) {
-			if (rewrite_uri(msg, &result) == -1) {
-				goto done;
-			}
-			set_ruri_q(q);
-			first = 0;
-			curr_prio = ((naptr->order) << 16) + naptr->pref;
-		} else {
-			priority = ((naptr->order) << 16) + naptr->pref;
-			if (priority > curr_prio) {
-				q = q - 10;
-				curr_prio = priority;
-			}
-			if (append_branch(msg, result.s, result.len, 0, 0, q, 0) == -1) {
-				goto done;
-			}
-		}
-	}
-
-done:
-	free_rdata_list(head);
-	return first ? -1 : 1;
-}

+ 0 - 54
modules_s/enum/enum.h

@@ -1,54 +0,0 @@
-/*
- * $Id$
- *
- * Header file for Enum and E164 related functions
- *
- * Copyright (C) 2002-2003 Juha Heinanen
- *
- * This file is part of ser, a free SIP server.
- *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-
-#ifndef ENUM_H
-#define ENUM_H
-
-
-#include "../../parser/msg_parser.h"
-
-
-#define MAX_DOMAIN_SIZE 256
-		
-
-/*
- * Check if from user is an e164 number
- */
-int is_e164(struct sip_msg* msg, char* p1, char* p2);
-
-
-/*
- * Make enum query and if query succeeds, replace current uri with the
- * result of the query
- */
-int enum_query(struct sip_msg* msg, char* p1, char* p2);
-
-
-#endif /* ENUM_H */

+ 0 - 87
modules_s/enum/enum_mod.c

@@ -1,87 +0,0 @@
-/*
- * $Id$
- *
- * Enum module
- *
- * Copyright (C) 2002-2003 Juha Heinanen
- *
- * This file is part of ser, a free SIP server.
- *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * History:
- * -------
- * 2003-03-11: New module interface (janakj)
- * 2003-03-16: flags export parameter added (janakj)
- * 2003-12-15: added suffix parameter to enum_query (jh)
- */
-
-
-#include "enum_mod.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include "../../sr_module.h"
-#include "../../error.h"
-#include "enum.h"
-
-MODULE_VERSION
-
-str domain_suffix = STR_STATIC_INIT("e164.arpa.");
-str tel_uri_params = STR_STATIC_INIT("");
-str default_service = STR_NULL;
-
-
-/*
- * Exported functions
- */
-static cmd_export_t cmds[] = {
-	{"enum_query", enum_query, 0, 0,                REQUEST_ROUTE},
-	{"enum_query", enum_query, 1, fixup_var_str_1,  REQUEST_ROUTE},
-	{"enum_query", enum_query, 2, fixup_var_str_12, REQUEST_ROUTE},
-	{"is_e164",    is_e164,    1, fixup_var_str_1,  REQUEST_ROUTE},
-	{0, 0, 0, 0, 0}
-};
-
-
-/*
- * Exported parameters
- */
-static param_export_t params[] = {
-        {"domain_suffix",   PARAM_STR, &domain_suffix },
-        {"tel_uri_params",  PARAM_STR, &tel_uri_params},
-	{"default_service", PARAM_STR, &default_service},
-	{0, 0, 0}
-};
-
-
-/*
- * Module parameter variables
- */
-struct module_exports exports = {
-	"enum",
-	cmds,     /* Exported functions */
-	0,        /* RPC method */
-	params,   /* Exported parameters */
-	0,        /* module initialization function */
-	0,        /* response function*/
-	0,        /* destroy function */
-	0,        /* oncancel function */
-	0         /* per-child init function */
-};

+ 0 - 42
modules_s/enum/enum_mod.h

@@ -1,42 +0,0 @@
-/*
- * $Id$
- *
- * Enum module headers
- *
- * Copyright (C) 2002-2003 Juha Heinanen
- *
- * This file is part of ser, a free SIP server.
- *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-
-#ifndef ENUM_MOD_H
-#define ENUM_MOD_H
-
-
-#include "../../str.h"
-
-extern str domain_suffix;
-extern str tel_uri_params;
-extern str default_service;
-
-
-#endif /* ENUM_MOD_H */

+ 0 - 123
modules_s/enum/regexp.c

@@ -1,123 +0,0 @@
-/*
- * $Id$
- *
- * Regular expression functions
- *
- * Copyright (C) 2003 Juha Heinanen
- *
- * This file is part of ser, a free SIP server.
- *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-#include <sys/types.h>
-#include <string.h>
-#include <regex.h>
-#include <ctype.h>
-#include "regexp.h"
-#include "../../dprint.h"
-
-/* Replace in replacement tokens \d with substrings of string pointed by
- * pmatch.
- */
-int replace(regmatch_t* pmatch, char* string, char* replacement, str* result)
-{
-	int len, i, j, digit, size;
-
-	len = strlen(replacement);
-	j = 0;
-
-	for (i = 0; i < len; i++) {
-		if (replacement[i] == '\\') {
-			if (i < len - 1) {
-				if (isdigit((unsigned char)replacement[i+1])) {
-					digit = replacement[i+1] - '0';
-					if (pmatch[digit].rm_so != -1) {
-						size = pmatch[digit].rm_eo - pmatch[digit].rm_so;
-						if (j + size < result->len) {
-							memcpy(&(result->s[j]), string+pmatch[digit].rm_so, size);
-							j = j + size;
-						} else {
-							return -1;
-						}
-					} else {
-						return -2;
-					}
-					i = i + 1;
-					continue;
-				} else {
-					i = i + 1;
-				}
-			} else {
-				return -3;
-			}
-		}
-		if (j + 1 < result->len) {
-			result->s[j] = replacement[i];
-			j = j + 1;
-		} else {
-			return -4;
-		}
-	}
-	result->len = j;
-	return 1;
-}
-
-
-/* Match pattern against string and store result in pmatch */
-int reg_match(char *pattern, char *string, regmatch_t *pmatch)
-{
-	regex_t preg;
-
-	if (regcomp(&preg, pattern, REG_EXTENDED | REG_NEWLINE)) {
-		return -1;
-	}
-	if (preg.re_nsub > MAX_MATCH) {
-		regfree(&preg);
-		return -2;
-	}
-	if (regexec(&preg, string, MAX_MATCH, pmatch, 0)) {
-		regfree(&preg);
-		return -3;
-	}
-	regfree(&preg);
-	return 0;
-}
-
-
-/* Match pattern against string and, if match succeeds, and replace string
- * with replacement substituting tokens \d with matched substrings.
- */
-int reg_replace(char *pattern, char *replacement, char *string, str *result)
-{
-	regmatch_t pmatch[MAX_MATCH];
-
-	DBG("reg_replace(): pattern: '%s', replacement: '%s', string: '%s'\n",
-	    pattern, replacement, string);
-
-	if (reg_match(pattern, string, &(pmatch[0]))) {
-		return -1;
-	}
-
-	return replace(&pmatch[0], string, replacement, result);
-
-}

+ 0 - 41
modules_s/enum/regexp.h

@@ -1,41 +0,0 @@
-/*
- * $Id$
- *
- * Regular expression definitions
- *
- * Copyright (C) 2003 Juha Heinanen
- *
- * This file is part of ser, a free SIP server.
- *
- * ser is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version
- *
- * For a license to use the ser software under conditions
- * other than those described here, or to purchase support for this
- * software, please contact iptel.org by e-mail at the following addresses:
- *    [email protected]
- *
- * ser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-
-#ifndef REGEXP_H
-#define REGEXP_H
-
-#include "../../str.h"
-
-#define MAX_MATCH 6
-
-extern int reg_replace(char *pattern, char *replacement, char *string, str *result);
-
-#endif