gsm improvements
[lcr.git] / route.c
diff --git a/route.c b/route.c
index 8f1e3bb..da59e98 100644 (file)
--- a/route.c
+++ b/route.c
@@ -26,6 +26,8 @@ struct cond_defs cond_defs[] = {
          "interface=<interface>[,...]", "Matches if call is received from given interface(s). NOT PORTS!"},
        { "callerid",   MATCH_CALLERID, COND_TYPE_STRING,
          "callerid=<digits>[-<digits>][,...]", "Matches if caller ID matches or begins with the given (range(s) of) prefixes(s)."},
+       { "callerid2",  MATCH_CALLERID2,COND_TYPE_STRING,
+         "callerid2=<digits>[-<digits>][,...]", "Matches the second caller ID (network provided)."},
        { "extension",  MATCH_EXTENSION,COND_TYPE_STRING,
          "extension=<digits>[-<digits>][,...]", "Matches if caller calls from given (range(s) of) extension(s)."},
        { "dialing",    MATCH_DIALING,  COND_TYPE_STRING,
@@ -90,7 +92,7 @@ struct cond_defs cond_defs[] = {
          "notbusy=<extension>[,...]","Matches if any of the given extension is not busy."},
        { "remote",     MATCH_REMOTE,   COND_TYPE_STRING,
          "remote=<application name>","Matches if remote application is running."},
-       { "notremote",  MATCH_NOTREMOTE,COND_TYPE_NULL,
+       { "notremote",  MATCH_NOTREMOTE,COND_TYPE_STRING,
          "notremote=<application name>","Matches if remote application is not running."},
        { NULL, 0, 0, NULL}
 };
@@ -232,11 +234,14 @@ struct param_defs param_defs[] = {
          "application",PARAM_TYPE_STRING,
          "application=<name>", "Name of remote application to make call to."},
        { PARAM_CONTEXT,
-         "exten",      PARAM_TYPE_STRING,
-         "exten=<extension>", "Give context parameter to the remote application."},
+         "context",    PARAM_TYPE_STRING,
+         "context=<context>", "Give context parameter to the remote application."},
        { PARAM_EXTEN,
          "exten",      PARAM_TYPE_STRING,
          "exten=<extension>", "Give exten parameter to the remote application. (overrides dialed number)"},
+       { PARAM_ON,
+         "on", PARAM_TYPE_STRING,
+         "on=[init|hangup]", "Defines if the action is executed on call init or on hangup."},
        { 0, NULL, 0, NULL, NULL}
 };
 
@@ -324,7 +329,7 @@ struct action_defs action_defs[] = {
 //       "Caller calls the timer."},
        { ACTION_GOTO,
          "goto",       NULL, &EndpointAppPBX::action_dialing_goto, NULL,
-         PARAM_CONNECT | PARAM_RULESET | PARAM_STRIP | PARAM_SAMPLE,
+         PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT | PARAM_RULESET | PARAM_STRIP | PARAM_SAMPLE,
          "Jump to given ruleset and optionally play sample. Dialed digits are not flushed."},
        { ACTION_MENU,
          "menu",       NULL, &EndpointAppPBX::action_dialing_menu, NULL,
@@ -345,8 +350,8 @@ struct action_defs action_defs[] = {
          NULL},
 //       "The call forward is set within the telephone network of the external line."},
        { ACTION_EXECUTE,
-         "execute",    NULL, NULL, &EndpointAppPBX::action_hangup_execute,
-         PARAM_CONNECT | PARAM_EXECUTE | PARAM_PARAM,
+         "execute",    &EndpointAppPBX::action_init_execute, NULL, &EndpointAppPBX::action_hangup_execute,
+         PARAM_CONNECT | PARAM_EXECUTE | PARAM_PARAM | PARAM_ON,
          "Executes the given script file. The file must terminate quickly, because it will halt the PBX."},
        { ACTION_FILE,
          "file",       NULL, NULL, &EndpointAppPBX::action_hangup_file,
@@ -751,7 +756,7 @@ void ruleset_debug(struct route_ruleset *ruleset_start)
 /*
  * parse ruleset
  */
-static char *read_string(char *p, char *key, int key_size, char *special)
+static char *read_string(char *p, char *key, int key_size, const char *special)
 {
        key[0] = 0;
 
@@ -875,7 +880,7 @@ struct route_ruleset *ruleset_parse(void)
                j<<=1;
        }
 
-        SPRINT(filename[0], "%s/routing.conf", INSTALL_DATA);
+        SPRINT(filename[0], "%s/routing.conf", CONFIG_DATA);
 
         if (!(fp[0]=fopen(filename[0],"r")))
         {
@@ -943,7 +948,7 @@ struct route_ruleset *ruleset_parse(void)
                        if (key[0] == '/')
                                SCPY(filename[nesting+1], key);
                        else
-                               SPRINT(filename[nesting+1], "%s/%s", INSTALL_DATA, key);
+                               SPRINT(filename[nesting+1], "%s/%s", CONFIG_DATA, key);
                        if (!(fp[nesting+1]=fopen(filename[nesting+1],"r")))
                        {
                                PERROR("Cannot open %s\n", filename[nesting+1]);
@@ -1682,6 +1687,7 @@ struct route_ruleset *ruleset_parse(void)
                                case PARAM_TYPE_DESTIN:
                                case PARAM_TYPE_TYPE:
                                case PARAM_TYPE_YESNO:
+                               case PARAM_TYPE_ON:
                                key[0] = '\0';
                                if (*p==',' || *p==' ' || *p=='\0')
                                {
@@ -1720,6 +1726,22 @@ struct route_ruleset *ruleset_parse(void)
                                        SPRINT(failure, "Caller ID type '%s' unknown.", key);
                                        goto parse_error;
                                }
+                               if (param_defs[index].type == PARAM_TYPE_ON)
+                               {
+                                       param->value_type = VALUE_TYPE_INTEGER;
+                                       if (!strcasecmp(key, "init"))
+                                       {
+                                               param->integer_value = INFO_ON_INIT;
+                                               break;
+                                       }
+                                       if (!strcasecmp(key, "hangup"))
+                                       {
+                                               param->integer_value = INFO_ON_HANGUP;
+                                               break;
+                                       }
+                                       SPRINT(failure, "Execute on '%s' unknown.", key);
+                                       goto parse_error;
+                               }
                                if (param_defs[index].type == PARAM_TYPE_CAPABILITY)
                                {
                                        param->value_type = VALUE_TYPE_INTEGER;
@@ -1922,7 +1944,7 @@ struct route_ruleset *ruleset_parse(void)
 /*
  * return ruleset by name
  */
-struct route_ruleset *getrulesetbyname(char *name)
+struct route_ruleset *getrulesetbyname(const char *name)
 {
        struct route_ruleset *ruleset = ruleset_first;
 
@@ -1956,7 +1978,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
        struct route_action     *action = NULL;
        unsigned long           comp_len;
        int                     j, jj;
-       char                    callerid[64],   redirid[64];
+       char                    callerid[64], callerid2[64], redirid[64];
        int                     integer;
        char                    *string;
        FILE                    *tfp;
@@ -1969,6 +1991,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
        e_match_to_action = NULL;
 
        SCPY(callerid, numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international));
+       SCPY(callerid2, numberrize_callerinfo(e_callerinfo.id2, e_callerinfo.ntype2, options.national, options.international));
        SCPY(redirid, numberrize_callerinfo(e_redirinfo.id, e_redirinfo.ntype, options.national, options.international));
        
        PDEBUG(DEBUG_ROUTE, "parsing ruleset '%s'\n", ruleset->name);
@@ -1999,7 +2022,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
 
                                case MATCH_PORT:
                                if (ea_endpoint->ep_portlist)
-                               if ((ea_endpoint->ep_portlist->port_type & PORT_CLASS_mISDN_MASK) != PORT_CLASS_mISDN_DSS1)
+                               if ((ea_endpoint->ep_portlist->port_type & PORT_CLASS_MASK) != PORT_CLASS_mISDN)
                                        break;
                                integer = e_callerinfo.isdn_port;
                                goto match_integer;
@@ -2014,6 +2037,10 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
                                string = callerid;
                                goto match_string_prefix;
 
+                               case MATCH_CALLERID2:
+                               string = callerid2;
+                               goto match_string_prefix;
+
                                case MATCH_EXTENSION:
                                string = e_ext.name;
                                goto match_string;
@@ -2063,12 +2090,12 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
                                break;
 
                                case MATCH_REDIRECTED:
-                               if (e_redirinfo.present != INFO_PRESENT_NULL)
+                               if (e_redirinfo.ntype != INFO_NTYPE_NOTPRESENT)
                                        istrue = 1;
                                break;
 
                                case MATCH_DIRECT:
-                               if (e_redirinfo.present == INFO_PRESENT_NULL)
+                               if (e_redirinfo.ntype == INFO_NTYPE_NOTPRESENT)
                                        istrue = 1;
                                break;
 
@@ -2147,7 +2174,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
                                        if (mISDNport->ifport)
                                        if (strlen(mISDNport->ifport->interface->name) == comp_len)
                                        if (!strncasecmp(mISDNport->ifport->interface->name, cond->string_value, comp_len)) 
-                                       if (!mISDNport->l2hold || mISDNport->l2link)
+                                       if (!mISDNport->l2hold || mISDNport->l2link>0)
                                        {
                                                j = 0;
                                                jj = mISDNport->b_num;
@@ -2179,7 +2206,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
                                {
                                        if (mISDNport->ifport)
                                        if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value)) 
-                                       if (!mISDNport->l2hold || mISDNport->l2link)
+                                       if (!mISDNport->l2hold || mISDNport->l2link>0)
                                                break;
                                        mISDNport = mISDNport->next;
                                }
@@ -2193,7 +2220,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
                                {
                                        if (mISDNport->ifport)
                                        if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value)) 
-                                       if (!mISDNport->l2hold || mISDNport->l2link)
+                                       if (!mISDNport->l2hold || mISDNport->l2link>0)
                                                break;
                                        
                                        mISDNport = mISDNport->next;