core: allow event_route blocks to run ONEVENT_ROUTE|REQUEST_ROUTE functions
[sip-router] / src / core / sr_module.c
index 1ab32a5..fe54537 100644 (file)
@@ -665,7 +665,21 @@ skip:
        return -1;
 }
 
-
+/**
+ * test if command flags are compatible with route block flags (type)
+ * - decide if the command is allowed to run within a specific route block
+ * - return: 1 if allowed; 0 if not allowed
+ */
+static inline int sr_cmd_flags_match(int cflags, int rflags)
+{
+       if((cflags & rflags) == rflags) {
+               return 1;
+       }
+       if((rflags==EVENT_ROUTE) && (cflags & EVENT_ROUTE)) {
+               return 1;
+       }
+       return 0;
+}
 
 /* searches the module list for function name in module mod and returns
  *  a pointer to the "name" function record union or 0 if not found
@@ -688,16 +702,16 @@ sr31_cmd_export_t* find_mod_export_record(char* mod, char* name,
                                if((strcmp(name, cmd->name) == 0) &&
                                        ((cmd->param_no == param_no) ||
                                        (cmd->param_no==VAR_PARAM_NO)) &&
-                                       ((cmd->flags & flags) == flags)
+                                       (sr_cmd_flags_match(cmd->flags, flags)==1)
                                ){
-                                       LM_DBG("find_export_record: found <%s> in module %s [%s]\n",
+                                       LM_DBG("found export of <%s> in module %s [%s]\n",
                                                name, t->exports.name, t->path);
                                        *mod_if_ver=t->orig_mod_interface_ver;
                                        return cmd;
                                }
                        }
        }
-       LM_DBG("find_export_record: <%s> not found \n", name);
+       LM_DBG("export of <%s> not found (flags %d)\n", name, flags);
        return 0;
 }
 
@@ -1723,6 +1737,7 @@ int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param)
                case FPARAM_UNSPEC:
                case FPARAM_STRING:
                case FPARAM_STR:
+                       LM_ERR("Unsupported param type for int value: %d\n", param->type);
                        return -1;
                case FPARAM_AVP:
                        avp = search_first_avp(param->v.avp.flags, param->v.avp.name,
@@ -1759,6 +1774,10 @@ int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param)
                        }
                        break;
                case FPARAM_PVE:
+                       LM_ERR("Unsupported param type for int value: %d\n", param->type);
+                       return -1;
+               default:
+                       LM_ERR("Unexpected param type: %d\n", param->type);
                        return -1;
        }
        return 0;