Merge branch 'master' of ssh://schlaile@git.misdn.org/var/git/lcr
[lcr.git] / route.c
diff --git a/route.c b/route.c
index e8bf896..29381c2 100644 (file)
--- a/route.c
+++ b/route.c
@@ -9,10 +9,6 @@
 **                                                                           **
 \*****************************************************************************/ 
 
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
 #include "main.h"
 
 
@@ -94,7 +90,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}
 };
@@ -123,7 +119,7 @@ struct param_defs param_defs[] = {
          "capability=speech|audio|video|digital-restricted|digital-unrestricted|digital-unrestricted-tones", "Alter the service type of the call."},
        { PARAM_BMODE,
          "bmode",      PARAM_TYPE_BMODE,
-         "capability=transparent|hdlc", "Alter the bchannel mode of the call. Use hdlc for data calls."},
+         "bmode=transparent|hdlc", "Alter the bchannel mode of the call. Use hdlc for data calls."},
        { PARAM_INFO1,
          "infolayer1", PARAM_TYPE_INTEGER,
          "infolayer1=<value>", "Alter the layer 1 information of a call. Use 3 for ALAW or 2 for uLAW."},
@@ -220,6 +216,9 @@ struct param_defs param_defs[] = {
        { PARAM_ROOM,
          "room",       PARAM_TYPE_INTEGER,
          "room=<digits>", "Conference room number, must be greater 0, as in real life."},
+       { PARAM_JINGLE,
+         "jingle",     PARAM_TYPE_NULL,
+         "jingle", "Conference members will hear a jingle if a member joins."},
        { PARAM_TIMEOUT,
          "timeout",    PARAM_TYPE_INTEGER,
          "timeout=<seconds>", "Timeout before continue with next action."},
@@ -231,7 +230,13 @@ struct param_defs param_defs[] = {
          "strip", "Remove digits that were required to match this rule."},
        { PARAM_APPLICATION,
          "application",PARAM_TYPE_STRING,
-         "application", "Name of remote application to make call to."},
+         "application=<name>", "Name of remote application to make call to."},
+       { PARAM_CONTEXT,
+         "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)"},
        { 0, NULL, 0, NULL, NULL}
 };
 
@@ -250,7 +255,7 @@ struct action_defs action_defs[] = {
          "Same as 'extern'"},
        { ACTION_REMOTE,
          "remote",     &EndpointAppPBX::action_init_remote, &EndpointAppPBX::action_dialing_remote, &EndpointAppPBX::action_hangup_call,
-         PARAM_CONNECT | PARAM_APPLICATION | PARAM_TIMEOUT,
+         PARAM_CONNECT | PARAM_APPLICATION | PARAM_CONTEXT | PARAM_EXTEN | PARAM_TIMEOUT,
          "Call is routed to Remote application, like Asterisk."},
        { ACTION_VBOX_RECORD,
          "vbox-record",&EndpointAppPBX::action_init_call, &EndpointAppPBX::action_dialing_vbox_record, &EndpointAppPBX::action_hangup_call,
@@ -258,7 +263,7 @@ struct action_defs action_defs[] = {
          "Caller is routed to the voice box of given extension."},
        { ACTION_PARTYLINE,
          "partyline",&EndpointAppPBX::action_init_partyline, NULL, &EndpointAppPBX::action_hangup_call,
-         PARAM_ROOM,
+         PARAM_ROOM | PARAM_JINGLE,
          "Caller is participating the conference with the given room number."},
        { ACTION_LOGIN,
          "login",      NULL, &EndpointAppPBX::action_dialing_login, NULL,
@@ -283,7 +288,7 @@ struct action_defs action_defs[] = {
        { ACTION_REPLY,
          "reply",      &EndpointAppPBX::action_init_redial_reply, &EndpointAppPBX::action_dialing_reply, NULL,
          PARAM_CONNECT | PARAM_SELECT,
-         "Caller replies. (last incomming call(s))"},
+         "Caller replies. (last incoming call(s))"},
        { ACTION_POWERDIAL,
          "powerdial",  NULL, &EndpointAppPBX::action_dialing_powerdial, NULL,
          PARAM_CONNECT | PARAM_DELAY | PARAM_LIMIT | PARAM_TIMEOUT,
@@ -329,11 +334,6 @@ struct action_defs action_defs[] = {
          "disconnect", NULL, &EndpointAppPBX::action_dialing_disconnect, NULL,
          PARAM_CONNECT | PARAM_CAUSE | PARAM_LOCATION | PARAM_SAMPLE | PARAM_DISPLAY,
          "Caller gets disconnected optionally with given cause and given sample and given display text."},
-       { ACTION_HELP,
-         "help",       NULL, &EndpointAppPBX::action_dialing_help, NULL,
-         PARAM_CONNECT | PARAM_TIMEOUT,
-         NULL},
-//       "Caller will be able to select from current rules that would match. (using * and #)"},
        { ACTION_DEFLECT,
          "deflect",    NULL, &EndpointAppPBX::action_dialing_deflect, NULL,
          PARAM_DEST,
@@ -751,7 +751,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;
 
@@ -848,6 +848,7 @@ struct route_ruleset *ruleset_parse(void)
        struct route_param      *param;
        struct route_param      **param_pointer = NULL;
        char                    failure[256];
+       unsigned long long      allowed_params;
 
        /* check the integrity of IDs for ACTION_* and PARAM_* */
        i = 0;
@@ -874,7 +875,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")))
         {
@@ -942,7 +943,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]);
@@ -973,7 +974,7 @@ struct route_ruleset *ruleset_parse(void)
 
                        /* reading ruleset name text */
                        i = 0;
-                       while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9'))
+                       while(*p>' ' && *p<127 && *p!=']')
                        {
                                if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */
                                key[i++] = *p++;
@@ -1461,6 +1462,7 @@ struct route_ruleset *ruleset_parse(void)
                        SPRINT(failure, "Unknown action name '%s'.", key);
                        goto parse_error;
                }
+               allowed_params = action_defs[index].params;
 
                /* alloc memory for action */
                action = (struct route_action *)MALLOC(sizeof(struct route_action));
@@ -1510,6 +1512,13 @@ struct route_ruleset *ruleset_parse(void)
                                goto parse_error;
                        }
 
+                       /* check if item is allowed for the action */
+                       if (!(param_defs[index].id & allowed_params))
+                       {
+                               SPRINT(failure, "Param name '%s' exists, but not for this action.", key);
+                               goto parse_error;
+                       }
+
                        /* params without values must not have any parameter */
                        if (param_defs[index].type == PARAM_TYPE_NULL)
                        {
@@ -1913,7 +1922,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;
 
@@ -1959,8 +1968,8 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
        e_match_timeout = 0; /* no timeout */
        e_match_to_action = NULL;
 
-       SCPY(callerid, numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype));
-       SCPY(redirid, numberrize_callerinfo(e_redirinfo.id, e_redirinfo.ntype));
+       SCPY(callerid, numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, 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);
        while(rule)
@@ -2138,7 +2147,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->ptp || mISDNport->l2link)
+                                       if (!mISDNport->l2hold || mISDNport->l2link>0)
                                        {
                                                j = 0;
                                                jj = mISDNport->b_num;
@@ -2170,7 +2179,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
                                {
                                        if (mISDNport->ifport)
                                        if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value)) 
-                                       if (!mISDNport->ptp || mISDNport->l2link) /* break if one is up */
+                                       if (!mISDNport->l2hold || mISDNport->l2link>0)
                                                break;
                                        mISDNport = mISDNport->next;
                                }
@@ -2184,7 +2193,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset)
                                {
                                        if (mISDNport->ifport)
                                        if (!strcasecmp(mISDNport->ifport->interface->name, cond->string_value)) 
-                                       if (!mISDNport->ptp || mISDNport->l2link) /* break if one is up */
+                                       if (!mISDNport->l2hold || mISDNport->l2link>0)
                                                break;
                                        
                                        mISDNport = mISDNport->next;