[Serusers] URI Pattern Matching

Martin Hoffmann hn at nvnc.de
Thu Feb 22 09:35:53 CET 2007


Kristian Larsson wrote:
> On Thu, Feb 22, 2007 at 12:45:53AM +0000, Jon Farmer wrote:
> > Hi
> > 
> > I am trying to find a way to detect if the Invite URI starts with a *.
> Perhaps I'm not really enlightened in the realms
> of URIs, but can a URI really contain a * ?
> I was under the impression that the only allowed
> characters were [A-z0-9-.] plus @ as a separator
> of username and domain.

Thankfully, this is IETF land and we can easily check:

SIP-URI          =  "sip:" [ userinfo ] hostport
                    uri-parameters [ headers ]
userinfo         =  ( user / telephone-subscriber ) [ ":" password ] "@"
user             =  1*( unreserved / escaped / user-unreserved )
unreserved       =  alphanum / mark
alphanum         =  ALPHA / DIGIT
mark             =  "-" / "_" / "." / "!" / "~" / "*" / "'"
                     / "(" / ")"
escaped          =  "%" HEXDIG HEXDIG		     
user-unreserved  =  "&" / "=" / "+" / "$" / "," / ";" / "?" / "/"

They userinfo part of a URI may actually contain quite a lot
non-alphanumerical characters. Well, pretty much everything, really.

> > How do I match this as ser normally sees * as a wildcard.
> I believe SER uses regular expression type of
> matching and thus * is not really a wildcard, but
> rather "0 or more instances of the previous
> character". Anyway to match a request-URI starting
> with '*' you simply do
> if (uri =~ /^\*/) { #blaha }

Almost, but the scheme is part of the URI, so it would be

   if (uri =~ "^sip:\*") { ; }

Regards,
Martin



More information about the sr-users mailing list