MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / fix_expr

Function fix_expr

route.c:1228–1301  ·  view source on GitHub ↗

! \brief traverses an expression tree and compiles the REs where necessary) * \return 0 for ok, <0 if errors */

Source from the content-addressed store, hash-verified

1226 * \return 0 for ok, <0 if errors
1227 */
1228static int fix_expr(struct expr* exp)
1229{
1230 regex_t* re;
1231 int ret;
1232
1233 ret=E_BUG;
1234 if (exp==0){
1235 LM_CRIT("null pointer\n");
1236 return E_BUG;
1237 }
1238 if (exp->type==EXP_T){
1239 switch(exp->op){
1240 case AND_OP:
1241 case OR_OP:
1242 if ((ret=fix_expr(exp->left.v.expr))!=0)
1243 return ret;
1244 ret=fix_expr(exp->right.v.expr);
1245 break;
1246 case NOT_OP:
1247 case EVAL_OP:
1248 ret=fix_expr(exp->left.v.expr);
1249 break;
1250 default:
1251 LM_CRIT("unknown op %d\n", exp->op);
1252 }
1253 }else if (exp->type==ELEM_T){
1254 if (exp->op==MATCH_OP || exp->op==NOTMATCH_OP){
1255 if (exp->right.type==STR_ST){
1256 re=(regex_t*)pkg_malloc(sizeof(regex_t));
1257 if (re==0){
1258 LM_CRIT("out of pkg memory\n");
1259 return E_OUT_OF_MEM;
1260 }
1261 if (regcomp(re, (char*) exp->right.v.data,
1262 REG_EXTENDED|REG_NOSUB|REG_ICASE) ){
1263 LM_CRIT("bad re \"%s\"\n", (char*) exp->right.v.data);
1264 pkg_free(re);
1265 return E_BAD_RE;
1266 }
1267 /* replace the string with the re */
1268 pkg_free(exp->right.v.data);
1269 exp->right.v.data=re;
1270 exp->right.type=RE_ST;
1271 }else if (exp->right.type!=RE_ST
1272 && exp->right.type!=SCRIPTVAR_ST){
1273 LM_CRIT("invalid type for match\n");
1274 return E_BUG;
1275 }
1276 }
1277 if (exp->left.type==ACTION_O){
1278 ret=fix_actions((struct action*)exp->right.v.data);
1279 if (ret!=0){
1280 LM_CRIT("fix_actions error\n");
1281 return ret;
1282 }
1283 }
1284 if (exp->left.type==EXPR_O){
1285 ret=fix_expr(exp->left.v.expr);

Callers 1

fix_actionsFunction · 0.85

Calls 1

fix_actionsFunction · 0.85

Tested by

no test coverage detected