perlfunc.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <string.h>
00028 #include <stdio.h>
00029
00030 #include "../../mem/mem.h"
00031 #include "../../data_lump.h"
00032 #include "../../parser/parse_param.h"
00033 #include "../../parser/msg_parser.h"
00034 #include "../../dprint.h"
00035 #include "../../action.h"
00036 #include "../../config.h"
00037 #include "../../parser/parse_uri.h"
00038
00039 #include "perlfunc.h"
00040 #include "perl.h"
00041
00042
00043
00044
00045
00046 int perl_checkfnc(char *fnc) {
00047
00048 if (get_cv(fnc, 0)) {
00049 return 1;
00050 } else {
00051 return 0;
00052 }
00053 }
00054
00055
00056
00057
00058
00059 int perl_exec_simple(char* fnc, char* args[], int flags) {
00060
00061 if (perl_checkfnc(fnc)) {
00062 LM_DBG("running perl function \"%s\"", fnc);
00063
00064 call_argv(fnc, flags, args);
00065 } else {
00066 LM_ERR("unknown function '%s' called.\n", fnc);
00067 return -1;
00068 }
00069
00070 return 1;
00071 }
00072
00073 int perl_exec_simple1(struct sip_msg* _msg, char* fnc, char* str2) {
00074 char *args[] = { NULL };
00075
00076 return perl_exec_simple(fnc, args, G_DISCARD | G_NOARGS | G_EVAL);
00077 }
00078
00079 int perl_exec_simple2(struct sip_msg* _msg, char* fnc, char* param) {
00080 char *args[] = { param, NULL };
00081
00082 return perl_exec_simple(fnc, args, G_DISCARD | G_EVAL);
00083 }
00084
00085
00086
00087
00088 int perl_exec1(struct sip_msg* _msg, char* fnc, char *foobar) {
00089 return perl_exec2(_msg, fnc, NULL);
00090 }
00091
00092 int perl_exec2(struct sip_msg* _msg, char* fnc, char* mystr) {
00093 int retval;
00094 SV *m;
00095 str reason;
00096
00097 dSP;
00098
00099 if (!perl_checkfnc(fnc)) {
00100 LM_ERR("unknown perl function called.\n");
00101 reason.s = "Internal error";
00102 reason.len = sizeof("Internal error")-1;
00103 if (slb.send_reply(_msg, 500, &reason) == -1)
00104 {
00105 LM_ERR("failed to send reply\n");
00106 }
00107 return -1;
00108 }
00109
00110 switch ((_msg->first_line).type) {
00111 case SIP_REQUEST:
00112 if (parse_sip_msg_uri(_msg) < 0) {
00113 LM_ERR("failed to parse Request-URI\n");
00114
00115 reason.s = "Bad Request-URI";
00116 reason.len = sizeof("Bad Request-URI")-1;
00117 if (slb.send_reply(_msg, 400, &reason) == -1) {
00118 LM_ERR("failed to send reply\n");
00119 }
00120 return -1;
00121 }
00122 break;
00123 case SIP_REPLY:
00124 break;
00125 default:
00126 LM_ERR("invalid firstline");
00127 return -1;
00128 }
00129
00130 m = sv_newmortal();
00131 sv_setref_pv(m, "OpenSER::Message", (void *)_msg);
00132 SvREADONLY_on(SvRV(m));
00133
00134
00135 ENTER;
00136 SAVETMPS;
00137 PUSHMARK(SP);
00138 XPUSHs(m);
00139
00140 if (mystr)
00141 XPUSHs(sv_2mortal(newSVpv(mystr, strlen(mystr))));
00142
00143
00144 PUTBACK;
00145
00146 call_pv(fnc, G_EVAL|G_SCALAR);
00147 SPAGAIN;
00148
00149 retval = POPi;
00150
00151 PUTBACK;
00152 FREETMPS;
00153 LEAVE;
00154
00155 return retval;
00156 }