X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=route.c;h=5b42f5842e050dad72f440cd6e0ae9131b5ef048;hp=f72d6b0b929135604d8e9394cd5723b552723949;hb=9f9b721735aa20e3362b7f6c451830b90f012c28;hpb=0f5c2eabde69c66e8793171c878652184f9de5d8 diff --git a/route.c b/route.c index f72d6b0..5b42f58 100644 --- a/route.c +++ b/route.c @@ -1882,14 +1882,12 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) istrue, couldbetrue, condition, - dialing_required, - avail, - any; + dialing_required; struct route_rule *rule = ruleset->rule_first; struct route_cond *cond; struct route_action *action = NULL; unsigned long comp_len; - int j, jj; + int j; char isdn_port[10]; char *argv[11]; /* check also number of args below */ char callerid[64], callerid2[64], redirid[64]; @@ -1898,10 +1896,16 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) FILE *tfp; long long timeout, now_ll = 0, match_timeout = 0; struct timeval current_time; +#ifdef WITH_MISDN struct mISDNport *mISDNport; + int avail, + any; + int jj; +#endif struct admin_list *admin; time_t now; struct tm *now_tm; + int pid, status; /* reset timeout action */ e_match_to_action = NULL; @@ -1934,11 +1938,14 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) break; case MATCH_PORT: +#ifdef WITH_MISDN if (ea_endpoint->ep_portlist) if ((ea_endpoint->ep_portlist->port_type & PORT_CLASS_MASK) != PORT_CLASS_mISDN) break; integer = e_callerinfo.isdn_port; goto match_integer; +#endif + break; case MATCH_INTERFACE: if (!e_callerinfo.interface[0]) @@ -2071,9 +2078,11 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) case MATCH_EXECUTE: j = 0; +#if 0 argv[j++] = (char *)"/bin/sh"; argv[j++] = (char *)"-c"; argv[j++] = cond->string_value; +#endif argv[j++] = cond->string_value; argv[j++] = e_extdialing; argv[j++] = (char *)numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international); @@ -2083,8 +2092,18 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) argv[j++] = isdn_port; argv[j++] = e_callerinfo.imsi; argv[j++] = NULL; /* check also number of args above */ - if (execve("/bin/sh", argv, environ) == 0) - istrue = 1; + switch ((pid = fork())) { + case 0: + execve(cond->string_value, argv, environ); + perror("execve"); + exit(1); + case -1: + break; + default: + waitpid(pid, &status, 0); + if (0 == WEXITSTATUS(status)) + istrue = 1; + } break; case MATCH_DEFAULT: @@ -2103,6 +2122,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) case MATCH_FREE: case MATCH_NOTFREE: +#ifdef WITH_MISDN if (!(comp_len = (unsigned long)strchr(cond->string_value, ':'))) break; comp_len = comp_len-(unsigned long)cond->string_value; @@ -2131,10 +2151,12 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) if (avail < atoi(cond->string_value + comp_len + 1)) istrue = 1; } +#endif break; case MATCH_DOWN: +#ifdef WITH_MISDN mISDNport = mISDNport_first; while(mISDNport) { if (mISDNport->ifport) @@ -2145,9 +2167,11 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) } if (!mISDNport) /* all down */ istrue = 1; +#endif break; case MATCH_UP: +#ifdef WITH_MISDN mISDNport = mISDNport_first; while(mISDNport) { if (mISDNport->ifport) @@ -2159,10 +2183,12 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) } if (mISDNport) /* one link at least */ istrue = 1; +#endif break; case MATCH_BUSY: case MATCH_IDLE: +#ifdef WITH_MISDN any = 0; mISDNport = mISDNport_first; while(mISDNport) { @@ -2176,6 +2202,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) istrue = 1; if (!mISDNport && cond->match==MATCH_IDLE) istrue = 1; +#endif break; case MATCH_REMOTE: @@ -2300,12 +2327,13 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) cond = cond->next; } - if (timeout>now_ll && match==1) /* the matching rule with timeout in the future */ - if (match_timeout == 0 || timeout < match_timeout) { /* first timeout or lower */ - /* set timeout in the furture */ - match_timeout = timeout; - e_match_to_action = rule->action_first; - e_match_to_extdialing = e_dialinginfo.id + dialing_required; + if (timeout>now_ll && match==1) { /* the matching rule with timeout in the future */ + if (match_timeout == 0 || timeout < match_timeout) { /* first timeout or lower */ + /* set timeout in the furture */ + match_timeout = timeout; + e_match_to_action = rule->action_first; + e_match_to_extdialing = e_dialinginfo.id + dialing_required; + } match = 0; /* matches in the future */ } if (match == 1) { @@ -2325,7 +2353,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) if (match_timeout == 0) unsched_timer(&e_match_timeout); /* no timeout */ else { - schedule_timer(&e_match_timeout, match_timeout / 1000000, match_timeout % 1000000); + schedule_timer(&e_match_timeout, (match_timeout-now_ll) / 1000000, (match_timeout-now_ll) % 1000000); } return(action); }