[OpenSIPS-Users] How to best check a request's method?

Michael Renzmann mrenzmann at otaku42.de
Thu Nov 15 09:17:43 CET 2012


Hi.

For the records and just in case anyone stumbles across my post in the
archives (feel free to ignore it otherwise):

> Let's assume that I want to check whether the current request uses a given
> method. The following statements would work for that:
>
>  1. if (method == INVITE) { ... }
>  2. if (method == "INVITE") { ... }
>  3. if (is_method("INVITE")) { ... }

No one answered so far, so it appears to me this is more or less a
personal decision thing rather than a real performance issue. :-)

I for me decided to go with is_method(). It's widely used in the demo
configuration.

Plus: it offers more flexibility when it comes to expanding an existing
test. Say, if you wanted to expand the statements given as example above
to also test for SUBSCRIBE requests, for 1 or 2 you would end up with
something like:

  if ((method == INVITE) || (method == SUBSCRIBE)) { ... }

while with 3 it would be:

  if (is_method("INVITE|SUBSCRIBE")) { ... }

The latter appears to be more intuitive and easier to read, at least for me.

Bye, Mike



More information about the Users mailing list