[Serdev] ENUM enhancements

Klaus Darilion klaus.mailinglists at pernau.at
Tue Jun 21 07:49:47 UTC 2005


Hi Juha!

My code works, but it was not that easy as I thought (probably due to my 
weak C skills). I could not find any function that searches a character 
in a string without terminating \0. Thus I copied the str into a \0 
terminated string first. Also it bloated up the code.

Below you see the modified sip_match function. I guess, the code is not 
very nice, thus I ask for help how I could improve this code:

syntax: enum_query("e164.arpa.","sip+voice:sip+video:sip")

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 {

     int lastuser = 0; /* if this is the last requested service */
     char *posuser;    /* points to the service within
                          the e2u+service+service string*
     char naptrserv[MAX_DNS_STRING+1], userserv[MAX_DNS_STRING];

     /* make strings from str */
     strncpy(naptrserv, naptr->services, naptr->services_len);
     naptrserv[naptr->services_len] = '\0';
     strncpy(userserv, service->s, service->len);
     userserv[service->len] = '\0';

     /* check if NAPTR starts with e2u+*/
     if (strncasecmp(naptr->services, "e2u+", 4) != 0) {
       return 0;
     }
     /* parsing the requested services from the end
        to the begin of the string */
     while(!lastuser) {
       if ( (posuser = strrchr (userserv, '+'))) {
         *posuser = '\0';
         if (strcasecmp(naptrserv+4, posuser+1) == 0) return 1;
       } else {
         lastuser = 1;
         if (strcasecmp(naptrserv+4, userserv) == 0) return 1;
       }
     }
     /* no matching service found */
     return 0;
   }
}


regards,
klaus



Juha Heinanen wrote:
> Klaus Darilion writes:
> 
>  > I think every string comparison is negligible compared to a second DNS 
>  > lookup.
> 
> that is true, but i don't want to take any performance penalty for those
> who use the simple, ietf recommended service field e2u+sip.  also, in
> order to make debugging of the code simple, the extra logic that is
> needed for more complicated options should be separate from the simple
> case, not mixed up in it.
> 
> -- juha
> 
> 




More information about the Serdev mailing list