4 * Perl module for OpenSER
6 * Copyright (C) 2006 Collax GmbH
7 * (Bastian Friedrich <bastian.friedrich@collax.com>)
9 * This file is part of openser, a free SIP server.
11 * openser is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version
16 * openser is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 /* perl.h defines union semun */
35 # undef _SEM_SEMUN_UNDEFINED
38 #include "../../sr_module.h"
39 #include "../../parser/msg_parser.h"
40 #include "../../parser/parse_uri.h"
41 #include "../../usr_avp.h"
42 #include "../../action.h"
43 #include "../../flags.h"
44 #include "../../pvar.h"
45 #include "../../dset.h"
46 #include "../../mem/mem.h"
47 #include "../../route_struct.h"
48 #include "../../qvalue.h"
49 #include "../../dprint.h"
51 extern int unsafemodfnc;
69 XS_URI_USER_PARAM_VAL,
75 /* These members are no strings:
76 unsigned short port_no;
77 unsigned short proto; / * from transport * /
78 uri_type type; / * uri scheme */
82 * Return the sip_msg struct referred to by perl reference sv
84 struct sip_msg * sv2msg(SV *sv) {
89 m = INT2PTR(struct sip_msg*, SvIV(sv));
93 return NULL; /* In case of error above... */
96 struct sip_uri * sv2uri(SV *sv) {
101 u = INT2PTR(struct sip_uri*, SvIV(sv));
105 return NULL; /* In case of error above... */
108 struct action * sv2action(SV *sv) {
113 a = INT2PTR(struct action*, SvIV(sv));
117 return NULL; /* In case of error above... */
121 * We have a private function for two reasons:
122 * a) Return SIP_INVALID even if type was sth different
126 inline static int getType(struct sip_msg *msg) {
129 if (!msg) return SIP_INVALID;
131 switch ((msg->first_line).type) {
132 case SIP_REQUEST: t = SIP_REQUEST; break;
133 case SIP_REPLY: t = SIP_REPLY; break;
139 SV *getStringFromURI(SV *self, enum xs_uri_members what) {
140 struct sip_uri *myuri = sv2uri(self);
144 LM_ERR("Invalid URI reference\n");
149 case XS_URI_USER: ret = &(myuri->user);
151 case XS_URI_HOST: ret = &(myuri->host);
153 case XS_URI_PASSWD: ret = &(myuri->passwd);
155 case XS_URI_PORT: ret = &(myuri->port);
157 case XS_URI_PARAMS: ret = &(myuri->params);
159 case XS_URI_HEADERS: ret = &(myuri->headers);
161 case XS_URI_TRANSPORT: ret = &(myuri->transport);
163 case XS_URI_TTL: ret = &(myuri->ttl);
165 case XS_URI_USER_PARAM: ret = &(myuri->user_param);
167 case XS_URI_MADDR: ret = &(myuri->maddr);
169 case XS_URI_METHOD: ret = &(myuri->method);
171 case XS_URI_LR: ret = &(myuri->lr);
173 case XS_URI_R2: ret = &(myuri->r2);
175 case XS_URI_TRANSPORT_VAL: ret = &(myuri->transport_val);
177 case XS_URI_TTL_VAL: ret = &(myuri->ttl_val);
179 case XS_URI_USER_PARAM_VAL: ret = &(myuri->user_param_val);
181 case XS_URI_MADDR_VAL: ret = &(myuri->maddr_val);
183 case XS_URI_METHOD_VAL: ret = &(myuri->method_val);
185 case XS_URI_LR_VAL: ret = &(myuri->lr_val);
187 case XS_URI_R2_VAL: ret = &(myuri->r2_val);
190 default: LM_INFO("Unknown URI element"
191 " requested: %d\n", what);
196 if ((ret) && (ret->len)) {
197 return sv_2mortal(newSVpv(ret->s, ret->len));
206 * Calls an exported function. Parameters are copied and fixup'd.
209 * -1 - Function not available (or other error).
210 * 1 - Function was called. Its return value is returned via the retval
214 int moduleFunc(struct sip_msg *m, char *func,
215 char *param1, char *param2,
218 union cmd_export_u* exp_func_struct;
223 struct run_act_ctx ra_ctx;
226 LM_ERR("moduleFunc called with null function name. Error.");
230 if ((!param1) && param2) {
231 LM_ERR("moduleFunc called with parameter 1 UNSET and"
232 " parameter 2 SET. Error.");
238 argv[0] = (char *)pkg_malloc(strlen(param1)+1);
239 strcpy(argv[0], param1);
246 argv[1] = (char *)pkg_malloc(strlen(param2)+1);
247 strcpy(argv[1], param2);
253 exp_func_struct = find_export_record(func, argc, 0, &mod_ver);
254 if (!exp_func_struct || mod_ver < 1) {
255 LM_ERR("function '%s' called, but not available.", func);
257 if (argv[0]) pkg_free(argv[0]);
258 if (argv[1]) pkg_free(argv[1]);
262 act = mk_action(MODULE_T, 4 /* number of (type, value) pairs */,
263 MODEXP_ST, exp_func_struct, /* function */
264 NUMBER_ST, 2, /* parameter number */
265 STRING_ST, argv[0], /* param. 1 */
266 STRING_ST, argv[1] /* param. 2 */
271 LM_ERR("action structure could not be created. Error.");
272 if (argv[0]) pkg_free(argv[0]);
273 if (argv[1]) pkg_free(argv[1]);
278 if (exp_func_struct->v1.fixup) {
280 LM_ERR("Module function '%s' is unsafe. Call is refused.\n", func);
281 if (argv[0]) pkg_free(argv[0]);
282 if (argv[1]) pkg_free(argv[1]);
288 *retval = exp_func_struct->v1.fixup(&(act->val[2].u.data), 2);
290 LM_ERR("Error in fixup (2)\n");
293 act->val[2].type = MODFIXUP_ST;
296 *retval = exp_func_struct->v1.fixup(&(act->val[1].u.data), 1);
298 LM_ERR("Error in fixup (1)\n");
301 act->val[1].type = MODFIXUP_ST;
304 *retval = exp_func_struct->v1.fixup(0, 0);
306 LM_ERR("Error in fixup (0)\n");
312 init_run_actions_ctx(&ra_ctx);
313 *retval = do_action(&ra_ctx, act, m);
315 if ((act->val[2].type == MODFIXUP_ST) && (act->val[2].u.data)) {
316 /* pkg_free(act->elem[2].u.data); */
317 LM_WARN("moduleFunction: A fixup function was called. "
318 "This currently creates a memory leak.\n");
321 if ((act->val[1].type == MODFIXUP_ST) && (act->val[1].u.data)) {
322 /* pkg_free(act->elem[1].u.data); */
323 LM_WARN("moduleFunction: A fixup function was called. "
324 "This currently creates a memory leak.\n");
327 if (argv[0]) pkg_free(argv[0]);
328 if (argv[1]) pkg_free(argv[1]);
337 * Rewrite Request-URI
339 static inline int rewrite_ruri(struct sip_msg* _m, char* _s)
342 struct run_act_ctx ra_ctx;
344 act.type = SET_URI_T;
345 act.val[0].type = STRING_ST;
346 act.val[0].u.string = _s;
349 init_run_actions_ctx(&ra_ctx);
350 if (do_action(&ra_ctx, &act, _m) < 0)
352 LM_ERR("rewrite_ruri: Error in do_action\n");
360 * Compile a string with pseudo variables substituted by their values.
361 * A string buffer is allocated. Deallocate afterwards!
363 char *pv_sprintf(struct sip_msg *m, char *fmt) {
367 char *out = (char *)pkg_malloc(buf_size);
371 LM_ERR("pv_sprintf: Memory exhausted!\n");
375 s.s = fmt; s.len = strlen(s.s);
376 if(pv_parse_format(&s, &model) < 0) {
377 LM_ERR("pv_sprintf: ERROR: wrong format[%s]!\n",
382 if(pv_printf(m, model, out, &buf_size) < 0) {
388 pv_elem_free_all(model);
395 * Convert an SV to an int_str struct. Needed in AVP package.
396 * - val: SV to convert.
397 * - is: pointer to resulting int_str
398 * - flags: pointer to flags to set
399 * - strflag: flag mask to be or-applied for string match
402 inline int sv2int_str(SV *val, int_str *is,
403 unsigned short *flags, unsigned short strflag) {
408 LM_ERR("AVP:sv2int_str: Invalid value "
409 "(not a scalar).\n");
413 if (SvIOK(val)) { /* numerical name */
417 } else if (SvPOK(val)) {
424 LM_ERR("AVP:sv2int_str: Invalid value "
425 "(neither string nor integer).\n");
430 /* ************************************************************************ */
431 /* Object methods begin here */
435 This module provides access to a limited number of OpenSER core functions.
436 As the most interesting functions deal with SIP messages, they are located
437 in the OpenSER::Message class below.
441 MODULE = OpenSER PACKAGE = OpenSER
443 =head2 log(level,message)
445 Logs the message with OpenSER's logging facility. The logging level
446 is one of the following:
456 Please note that this method is I<NOT> automatically exported, as it collides
457 with the perl function log (which calculates the logarithm). Either explicitly
458 import the function (via C<use OpenSER qw ( log );>), or call it with its full
461 OpenSER::log(L_INFO, "foobar");
473 case L_ALERT: LM_ALERT("%s", log); break;
474 case L_CRIT: LM_CRIT("%s", log); break;
475 case L_ERR: LM_ERR("%s", log); break;
476 case L_WARN: LM_WARN("%s", log); break;
477 case L_NOTICE: LM_NOTICE("%s", log); break;
478 case L_INFO: LM_INFO("%s", log); break;
479 default: LM_DBG("%s", log); break;
485 MODULE = OpenSER PACKAGE = OpenSER::Message
489 =head1 OpenSER::Message
491 This package provides access functions for an OpenSER C<sip_msg> structure and
492 its sub-components. Through its means it is possible to fully configure
493 alternative routing decisions.
499 Returns one of the constants SIP_REQUEST, SIP_REPLY, SIP_INVALID stating the
500 type of the current message.
508 struct sip_msg *msg = sv2msg(self);
511 RETVAL = getType(msg);
519 Returns the status code of the current Reply message. This function is invalid
528 struct sip_msg *msg = sv2msg(self);
533 LM_ERR("Invalid message reference\n");
534 ST(0) = &PL_sv_undef;
536 if (getType(msg) != SIP_REPLY) {
537 LM_ERR("getStatus: Status not available in"
538 " non-reply messages.");
539 ST(0) = &PL_sv_undef;
541 ret = &((msg->first_line).u.reply.status);
542 ST(0) = sv_2mortal(newSVpv(ret->s, ret->len));
549 Returns the reason of the current Reply message. This function is invalid
558 struct sip_msg *msg = sv2msg(self);
563 LM_ERR("Invalid message reference\n");
564 ST(0) = &PL_sv_undef;
566 if (getType(msg) != SIP_REPLY) {
567 LM_ERR("getReason: Reason not available in"
568 " non-reply messages.");
569 ST(0) = &PL_sv_undef;
571 ret = &((msg->first_line).u.reply.reason);
572 ST(0) = sv_2mortal(newSVpv(ret->s, ret->len));
579 Returns the version string of the current SIP message.
587 struct sip_msg *msg = sv2msg(self);
592 LM_ERR("Invalid message reference\n");
593 ST(0) = &PL_sv_undef;
595 if (getType(msg) == SIP_REQUEST) {
596 ret = &((msg->first_line).u.request.version);
597 } else { /* SIP_REPLY */
598 ret = &((msg->first_line).u.reply.version);
600 ST(0) = sv_2mortal(newSVpv(ret->s, ret->len));
606 This function returns the recipient URI of the present SIP message:
608 C<< my $ruri = $m->getRURI(); >>
610 getRURI returns a string. See L</"getParsedRURI()"> below how to receive a
613 This function is valid in request messages only.
621 struct sip_msg *msg = sv2msg(self);
626 LM_ERR("Invalid message reference\n");
627 ST(0) = &PL_sv_undef;
629 if (getType(msg) != SIP_REQUEST) {
630 LM_ERR("Not a request message - "
631 "no RURI available.\n");
632 ST(0) = &PL_sv_undef;
634 ret = &((msg->first_line).u.request.uri);
635 ST(0) = sv_2mortal(newSVpv(ret->s, ret->len));
642 Returns the current method, such as C<INVITE>, C<REGISTER>, C<ACK> and so on.
644 C<< my $method = $m->getMethod(); >>
646 This function is valid in request messages only.
654 struct sip_msg *msg = sv2msg(self);
659 LM_ERR("Invalid message reference\n");
660 ST(0) = &PL_sv_undef;
662 if (getType(msg) != SIP_REQUEST) {
663 LM_ERR("Not a request message - "
664 "no method available.\n");
665 ST(0) = &PL_sv_undef;
667 ret = &((msg->first_line).u.request.method);
668 ST(0) = sv_2mortal(newSVpv(ret->s, ret->len));
673 =head2 getFullHeader()
675 Returns the full message header as present in the current message.
676 You might use this header to further work with it with your
677 favorite MIME package.
679 C<< my $hdr = $m->getFullHeader(); >>
687 struct sip_msg *msg = sv2msg(self);
693 LM_ERR("Invalid message reference\n");
694 ST(0) = &PL_sv_undef;
696 if (getType(msg) == SIP_INVALID) {
697 LM_ERR("getFullHeader: Invalid message type.\n");
698 ST(0) = &PL_sv_undef;
700 parse_headers(msg, ~0, 0);
701 if (getType(msg) == SIP_REQUEST) {
702 firsttoken = (msg->first_line).u.request.method.s;
703 } else { /* SIP_REPLY */
704 firsttoken = (msg->first_line).u.reply.version.s;
707 if (msg->eoh == NULL)
710 headerlen = ((long)(msg->eoh))
711 -((long)(firsttoken));
715 sv_2mortal(newSVpv(firsttoken, headerlen));
717 ST(0) = &PL_sv_undef;
725 Returns the message body.
733 struct sip_msg *msg = sv2msg(self);
737 LM_ERR("Invalid message reference\n");
738 ST(0) = &PL_sv_undef;
740 parse_headers(msg, ~0, 0);
741 ST(0) = sv_2mortal(newSVpv(get_body(msg), 0));
747 Returns the whole message including headers and body.
755 struct sip_msg *msg = sv2msg(self);
759 LM_ERR("Invalid message reference\n");
760 ST(0) = &PL_sv_undef;
762 ST(0) = sv_2mortal(newSVpv(msg->buf, 0));
766 =head2 getHeader(name)
768 Returns the body of the first message header with this name.
770 C<< print $m->getHeader("To"); >>
772 B<C<< "John" <sip:john@doe.example> >>>
777 getHeader(self, name)
781 struct sip_msg *msg = sv2msg(self);
783 struct hdr_field *hf;
785 int namelen = strlen(name);
788 LM_DBG("searching '%s'\n", name);
791 LM_ERR("Invalid message reference\n");
793 parse_headers(msg, ~0, 0);
794 for (hf = msg->headers; hf; hf = hf->next) {
795 if (namelen == hf->name.len) {
796 if (strncmp(name, hf->name.s, namelen) == 0) {
797 /* Found the right header. */
800 XPUSHs(sv_2mortal(newSVpv(body->s,
807 XPUSHs(&PL_sv_undef);
812 =head2 getHeaderNames()
814 Returns an array of all header names. Duplicates possible!
822 struct sip_msg *msg = sv2msg(self);
823 struct hdr_field *hf = NULL;
828 LM_ERR("Invalid message reference\n");
830 parse_headers(msg, ~0, 0);
831 for (hf = msg->headers; hf; hf = hf->next) {
833 XPUSHs(sv_2mortal(newSVpv(hf->name.s, hf->name.len)));
837 XPUSHs(&PL_sv_undef);
841 =head2 moduleFunction(func,string1,string2)
843 Search for an arbitrary function in module exports and call it with the
844 parameters self, string1, string2.
846 C<string1> and/or C<string2> may be omitted.
848 As this function provides access to the functions that are exported to the
849 OpenSER configuration file, it is autoloaded for unknown functions. Instead of
852 $m->moduleFunction("sl_send_reply", "500", "Internal Error");
853 $m->moduleFunction("xlog", "L_INFO", "foo");
855 you may as well write
857 $m->sl_send_reply("500", "Internal Error");
858 $m->xlog("L_INFO", "foo");
862 In OpenSER 1.2, only a limited subset of module functions is available. This
863 restriction will be removed in a later version.
865 Here is a list of functions that are expected to be working (not claiming
869 * consume_credentials
874 * cpl_process_register
875 * cpl_process_register_norpl
885 * enum_query (without parameters)
886 * enum_fquery (without parameters)
887 * is_from_user_enum (without parameters)
888 * i_enum_query (without parameters)
890 * jab_* (all functions from the jabber module)
891 * load_gws (without parameters)
893 * from_gw (without parameters)
894 * to_gw (without parameters)
899 * decode_contact_header
916 * prepareallosproutes
917 * checkcallingtranslation
920 * mangle_message_cpim
921 * add_path (without parameters)
922 * add_path_received (without parameters)
924 * allow_routing (without parameters)
943 * has_body (without parameters)
947 * t_relay (without parameters)
959 * radius_does_uri_exist
960 * ul_* (All functions exported by the usrloc module for user access)
967 moduleFunction (self, func, string1 = NULL, string2 = NULL)
973 struct sip_msg *msg = sv2msg(self);
974 int retval; /* Return value of called function */
975 int ret; /* Return value of moduleFunc - < 0 for "non existing function" and other errors */
978 LM_DBG("Calling exported func '%s', Param1 is '%s',"
979 " Param2 is '%s'\n", func, string1, string2);
981 ret = moduleFunc(msg, func, string1, string2, &retval);
983 LM_ERR("calling module function '%s' failed."
984 " Missing loadmodule?\n", func);
993 =head2 log(level,message) (deprecated type)
995 Logs the message with OpenSER's logging facility. The logging level
996 is one of the following:
1006 The logging function should be accessed via the OpenSER module variant. This
1007 one, located in OpenSER::Message, is deprecated.
1012 log(self, level, log)
1020 case L_ALERT: LM_ALERT("%s", log); break;
1021 case L_CRIT: LM_CRIT("%s", log); break;
1022 case L_ERR: LM_ERR("%s", log); break;
1023 case L_WARN: LM_WARN("%s", log); break;
1024 case L_NOTICE: LM_NOTICE("%s", log); break;
1025 case L_INFO: LM_INFO("%s", log); break;
1026 default: LM_DBG("%s", log); break;
1031 =head2 rewrite_ruri(newruri)
1033 Sets a new destination (recipient) URI. Useful for rerouting the
1034 current message/call.
1036 if ($m->getRURI() =~ m/\@somedomain.net/) {
1037 $m->rewrite_ruri("sip:dispatcher\@organization.net");
1043 rewrite_ruri(self, newruri)
1047 struct sip_msg *msg = sv2msg(self);
1051 LM_ERR("Invalid message reference\n");
1054 if (getType(msg) != SIP_REQUEST) {
1055 LM_ERR("Not a Request. RURI rewrite unavailable.\n");
1058 LM_DBG("New R-URI is [%s]\n", newruri);
1059 RETVAL = rewrite_ruri(msg, newruri);
1067 =head2 setFlag(flag)
1069 Sets a message flag. The constants as known from the C API may be used,
1070 when Constants.pm is included.
1079 struct sip_msg *msg = sv2msg(self);
1083 LM_ERR("Invalid message reference\n");
1086 RETVAL = setflag(msg, flag);
1092 =head2 resetFlag(flag)
1094 Resets a message flag.
1099 resetFlag(self, flag)
1103 struct sip_msg *msg = sv2msg(self);
1107 LM_ERR("Invalid message reference\n");
1110 RETVAL = resetflag(msg, flag);
1115 =head2 isFlagSet(flag)
1117 Returns whether a message flag is set or not.
1122 isFlagSet(self, flag)
1126 struct sip_msg *msg = sv2msg(self);
1130 LM_ERR("Invalid message reference\n");
1133 RETVAL = isflagset(msg, flag) == 1 ? 1 : 0;
1139 =head2 pseudoVar(string)
1141 Returns a new string where all pseudo variables are substituted by their values.
1142 Can be used to receive the values of single variables, too.
1144 B<Please remember that you need to escape the '$' sign in perl strings!>
1149 pseudoVar(self, varstring)
1153 struct sip_msg *msg = sv2msg(self);
1157 LM_ERR("Invalid message reference\n");
1158 ST(0) = &PL_sv_undef;
1160 ret = pv_sprintf(msg, varstring);
1162 ST(0) = sv_2mortal(newSVpv(ret, strlen(ret)));
1165 ST(0) = &PL_sv_undef;
1171 =head2 append_branch(branch,qval)
1173 Append a branch to current message.
1178 append_branch(self, branch = NULL, qval = NULL)
1183 struct sip_msg *msg = sv2msg(self);
1184 qvalue_t q = Q_UNSPECIFIED;
1189 LM_ERR("Invalid message reference\n");
1193 if (str2q(&q, qval, strlen(qval)) < 0) {
1194 LM_ERR("append_branch: Bad q value.");
1195 } else { /* branch and qval set */
1197 b.len = strlen(branch);
1200 if (branch) { /* branch set, qval unset */
1202 b.len = strlen(branch);
1206 RETVAL = km_append_branch(msg, (b.s!=0)?&b:0, 0, 0, q, 0, 0);
1213 =head2 getParsedRURI()
1215 Returns the current destination URI as an OpenSER::URI object.
1223 struct sip_msg *msg = sv2msg(self);
1224 struct sip_uri *uri;
1229 LM_ERR("Invalid message reference\n");
1232 parse_sip_msg_uri(msg);
1233 parse_headers(msg, ~0, 0);
1235 uri = &(msg->parsed_uri);
1236 ret = sv_newmortal();
1237 sv_setref_pv(ret, "OpenSER::URI", (void *)uri);
1238 SvREADONLY_on(SvRV(ret));
1245 MODULE = OpenSER PACKAGE = OpenSER::URI
1249 This package provides functions for access to sip_uri structures.
1258 Returns the user part of this URI.
1266 ST(0) = getStringFromURI(self, XS_URI_USER);
1271 Returns the host part of this URI.
1279 ST(0) = getStringFromURI(self, XS_URI_HOST);
1284 Returns the passwd part of this URI.
1292 ST(0) = getStringFromURI(self, XS_URI_PASSWD);
1297 Returns the port part of this URI.
1305 ST(0) = getStringFromURI(self, XS_URI_PORT);
1310 Returns the params part of this URI.
1318 ST(0) = getStringFromURI(self, XS_URI_PARAMS);
1323 Returns the headers part of this URI.
1331 ST(0) = getStringFromURI(self, XS_URI_HEADERS);
1336 Returns the transport part of this URI.
1344 ST(0) = getStringFromURI(self, XS_URI_TRANSPORT);
1349 Returns the ttl part of this URI.
1357 ST(0) = getStringFromURI(self, XS_URI_TTL);
1362 Returns the user_param part of this URI.
1370 ST(0) = getStringFromURI(self, XS_URI_USER_PARAM);
1376 Returns the maddr part of this URI.
1384 ST(0) = getStringFromURI(self, XS_URI_MADDR);
1388 Returns the method part of this URI.
1396 ST(0) = getStringFromURI(self, XS_URI_METHOD);
1401 Returns the lr part of this URI.
1409 ST(0) = getStringFromURI(self, XS_URI_LR);
1414 Returns the r2 part of this URI.
1422 ST(0) = getStringFromURI(self, XS_URI_R2);
1425 =head2 transport_val()
1427 Returns the transport_val part of this URI.
1435 ST(0) = getStringFromURI(self, XS_URI_TRANSPORT_VAL);
1440 Returns the ttl_val part of this URI.
1448 ST(0) = getStringFromURI(self, XS_URI_TTL_VAL);
1451 =head2 user_param_val()
1453 Returns the user_param_val part of this URI.
1458 user_param_val(self)
1461 ST(0) = getStringFromURI(self, XS_URI_USER_PARAM_VAL);
1466 Returns the maddr_val part of this URI.
1474 ST(0) = getStringFromURI(self, XS_URI_MADDR_VAL);
1479 Returns the method_val part of this URI.
1487 ST(0) = getStringFromURI(self, XS_URI_METHOD_VAL);
1492 Returns the lr_val part of this URI.
1500 ST(0) = getStringFromURI(self, XS_URI_LR_VAL);
1505 Returns the r2_val part of this URI.
1513 ST(0) = getStringFromURI(self, XS_URI_R2_VAL);
1519 This package provides access functions for OpenSER's AVPs.
1520 These variables can be created, evaluated, modified and removed through this
1523 Please note that these functions do NOT support the notation used
1524 in the configuration file, but directly work on strings or numbers. See
1525 documentation of add method below.
1530 MODULE = OpenSER PACKAGE = OpenSER::AVP
1532 =head2 add(name,val)
1536 Add an OpenSER AVP to its environment. name and val may both be integers or
1537 strings; this function will try to guess what is correct. Please note that
1539 OpenSER::AVP::add("10", "10")
1541 is something different than
1543 OpenSER::AVP::add(10, 10)
1545 due to this evaluation: The first will create _string_ AVPs with the name
1546 10, while the latter will create a numerical AVP.
1548 You can modify/overwrite AVPs with this function.
1559 unsigned short flags = 0;
1564 if (SvOK(p_name) && SvOK(p_val)) {
1565 if (!sv2int_str(p_name, &name, &flags, AVP_NAME_STR)) {
1567 } else if (!sv2int_str(p_val, &val, &flags, AVP_VAL_STR)) {
1572 RETVAL = add_avp(flags, name, val);
1585 my $numavp = OpenSER::AVP::get(5);
1586 my $stravp = OpenSER::AVP::get("foo");
1594 struct usr_avp *first_avp;
1597 unsigned short flags = 0;
1598 SV *ret = &PL_sv_undef;
1604 if (!sv2int_str(p_name, &name, &flags, AVP_NAME_STR)) {
1605 LM_ERR("AVP:get: Invalid name.");
1609 LM_ERR("AVP:get: Invalid name.");
1614 first_avp = search_first_avp(flags, name, &val, NULL);
1616 if (first_avp != NULL) { /* found correct AVP */
1617 if (is_avp_str_val(first_avp)) {
1618 ret = sv_2mortal(newSVpv(val.s.s, val.s.len));
1620 ret = sv_2mortal(newSViv(val.n));
1623 /* Empty AVP requested. */
1632 =head2 destroy(name)
1636 OpenSER::AVP::destroy(5);
1637 OpenSER::AVP::destroy("foo");
1645 struct usr_avp *first_avp;
1648 unsigned short flags = 0;
1649 SV *ret = &PL_sv_undef;
1655 if (!sv2int_str(p_name, &name, &flags, AVP_NAME_STR)) {
1657 LM_ERR("AVP:destroy: Invalid name.");
1661 LM_ERR("VP:destroy: Invalid name.");
1665 first_avp = search_first_avp(flags, name, &val, NULL);
1667 if (first_avp != NULL) { /* found correct AVP */
1668 destroy_avp(first_avp);
1671 /* Empty AVP requested. */