X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=route.c;h=925bfe86e3334f2a7d0a3ed6ff40db20f80d7a49;hp=c57de227657f4c33edf5a07aea58903f65265ea9;hb=refs%2Fheads%2Fbackup2;hpb=f6aea744f84e702b3469393f007b9e1bf25f6737 diff --git a/route.c b/route.c index c57de22..925bfe8 100644 --- a/route.c +++ b/route.c @@ -94,6 +94,14 @@ struct cond_defs cond_defs[] = { "remote=","Matches if remote application is running."}, { "notremote", MATCH_NOTREMOTE,COND_TYPE_STRING, "notremote=","Matches if remote application is not running."}, + { "pots-flash", MATCH_POTS_FLASH,COND_TYPE_NULL, + "pots-flash","When using POTS: Matches if call was invoked by flash/earth button."}, + { "pots-cw", MATCH_POTS_CW, COND_TYPE_NULL, + "pots-cw","When using POTS: Matches if a call is waiting."}, + { "pots-calls", MATCH_POTS_CALLS,COND_TYPE_INTEGER, + "pots-calls=","When using POTS: Matches if given number of calls are held."}, + { "pots-last", MATCH_POTS_LAST,COND_TYPE_INTEGER, + "pots-last=","When using POTS: Matches if given call number (1=oldest) was the last active call."}, { NULL, 0, 0, NULL} }; @@ -245,6 +253,9 @@ struct param_defs param_defs[] = { { PARAM_KEYPAD, "keypad", PARAM_TYPE_NULL, "keypad", "Use 'keypad facility' for dialing, instead of 'called number'."}, + { PARAM_POTS_CALL, + "pots-call", PARAM_TYPE_INTEGER, + "pots-call=", "Select call number. The oldest call is number 1."}, { 0, NULL, 0, NULL, NULL} }; @@ -380,6 +391,30 @@ struct action_defs action_defs[] = { "efi", &EndpointAppPBX::action_init_efi, NULL, NULL, PARAM_PROCEEDING | PARAM_ALERTING | PARAM_CONNECT, "Elektronische Fernsprecher Identifikation - announces caller ID."}, + { ACTION_POTS_RETRIEVE, + "pots-retrieve", &EndpointAppPBX::action_init_pots_retrieve, NULL, NULL, + PARAM_POTS_CALL, + "When using POTS: Select call on hold to retrieve."}, + { ACTION_POTS_RELEASE, + "pots-release", &EndpointAppPBX::action_init_pots_release, NULL, NULL, + PARAM_POTS_CALL, + "When using POTS: Select call on hold to release."}, + { ACTION_POTS_REJECT, + "pots-reject", &EndpointAppPBX::action_init_pots_reject, NULL, NULL, + 0, + "When using POTS: Reject incomming waiting call."}, + { ACTION_POTS_ANSWER, + "pots-answer", &EndpointAppPBX::action_init_pots_answer, NULL, NULL, + 0, + "When using POTS: Answer incomming waiting call."}, + { ACTION_POTS_3PTY, + "pots-3pty", &EndpointAppPBX::action_init_pots_3pty, NULL, NULL, + 0, + "When using POTS: Invoke 3PTY call of two calls on hold"}, + { ACTION_POTS_TRANSFER, + "pots-transfer", &EndpointAppPBX::action_init_pots_transfer, NULL, NULL, + 0, + "When using POTS: Interconnect two calls on hold"}, { -1, NULL, NULL, NULL, NULL, 0, NULL} }; @@ -983,7 +1018,7 @@ struct route_ruleset *ruleset_parse(void) while(*p!=':' && *p!='\0') { /* read item text */ i = 0; - while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9')) { + while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9') || *p == '-') { if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */ key[i++] = *p++; if (i == sizeof(key)) i--; /* limit */ @@ -1216,19 +1251,25 @@ struct route_ruleset *ruleset_parse(void) /* parse service value */ case COND_TYPE_CAPABILITY: - if (!strncasecmp("speech", p, 6)) + if (!strncasecmp("speech", p, 6)) { cond->integer_value = INFO_BC_SPEECH; - else if (!strncasecmp("audio", p, 5)) + p += 6; + } else if (!strncasecmp("audio", p, 5)) { cond->integer_value = INFO_BC_AUDIO; - else if (!strncasecmp("video", p, 5)) + p += 5; + } else if (!strncasecmp("video", p, 5)) { cond->integer_value = INFO_BC_VIDEO; - else if (!strncasecmp("digital-restricted", p, 18)) + p += 5; + } else if (!strncasecmp("digital-restricted", p, 18)) { cond->integer_value = INFO_BC_DATARESTRICTED; - else if (!strncasecmp("digital-unrestricted", p, 20)) + p += 18; + } else if (!strncasecmp("digital-unrestricted", p, 20)) { cond->integer_value = INFO_BC_DATAUNRESTRICTED; - else if (!strncasecmp("digital-unrestricted-tones", p, 26)) + p += 20; + } else if (!strncasecmp("digital-unrestricted-tones", p, 26)) { cond->integer_value = INFO_BC_DATAUNRESTRICTED_TONES; - else { + p += 26; + } else { SPRINT(failure, "Given service type is invalid or misspelled."); goto parse_error; } @@ -1237,11 +1278,13 @@ struct route_ruleset *ruleset_parse(void) /* parse bmode value */ case COND_TYPE_BMODE: - if (!strncasecmp("transparent", p, 11)) + if (!strncasecmp("transparent", p, 11)) { cond->integer_value = INFO_BMODE_CIRCUIT; - else if (!strncasecmp("hdlc", p, 4)) + p += 11; + } else if (!strncasecmp("hdlc", p, 4)) { cond->integer_value = INFO_BMODE_PACKET; - else { + p += 4; + } else { SPRINT(failure, "Given bchannel mode is invalid or misspelled."); goto parse_error; } @@ -1250,35 +1293,49 @@ struct route_ruleset *ruleset_parse(void) /* parse service value */ case COND_TYPE_HLC: - if (!strncasecmp("telephony", p, 9)) + if (!strncasecmp("telephony", p, 9)) { cond->integer_value = INFO_HLC_TELEPHONY; - else if (!strncasecmp("faxg2g3", p, 7)) + p += 9; + } else if (!strncasecmp("faxg2g3", p, 7)) { cond->integer_value = INFO_HLC_FAXG2G3; - else if (!strncasecmp("faxg4", p, 5)) + p += 7; + } else if (!strncasecmp("faxg4", p, 5)) { cond->integer_value = INFO_HLC_FAXG4; - else if (!strncasecmp("teletex1", p, 8)) + p += 5; + } else if (!strncasecmp("teletex1", p, 8)) { cond->integer_value = INFO_HLC_TELETEX1; - else if (!strncasecmp("teletex2", p, 8)) + p += 8; + } else if (!strncasecmp("teletex2", p, 8)) { cond->integer_value = INFO_HLC_TELETEX2; - else if (!strncasecmp("teletex3", p, 8)) + p += 8; + } else if (!strncasecmp("teletex3", p, 8)) { cond->integer_value = INFO_HLC_TELETEX3; - else if (!strncasecmp("videotex1", p, 9)) + p += 8; + } else if (!strncasecmp("videotex1", p, 9)) { cond->integer_value = INFO_HLC_VIDEOTEX1; - else if (!strncasecmp("videotex2", p, 9)) + p += 9; + } else if (!strncasecmp("videotex2", p, 9)) { cond->integer_value = INFO_HLC_VIDEOTEX2; - else if (!strncasecmp("telex", p, 5)) + p += 9; + } else if (!strncasecmp("telex", p, 5)) { cond->integer_value = INFO_HLC_TELEX; - else if (!strncasecmp("mhs", p, 3)) + p += 5; + } else if (!strncasecmp("mhs", p, 3)) { cond->integer_value = INFO_HLC_MHS; - else if (!strncasecmp("osi", p, 3)) + p += 3; + } else if (!strncasecmp("osi", p, 3)) { cond->integer_value = INFO_HLC_OSI; - else if (!strncasecmp("maintenance", p, 11)) + p += 3; + } else if (!strncasecmp("maintenance", p, 11)) { cond->integer_value = INFO_HLC_MAINTENANCE; - else if (!strncasecmp("management", p, 10)) + p += 11; + } else if (!strncasecmp("management", p, 10)) { cond->integer_value = INFO_HLC_MANAGEMENT; - else if (!strncasecmp("audiovisual", p, 11)) + p += 10; + } else if (!strncasecmp("audiovisual", p, 11)) { cond->integer_value = INFO_HLC_AUDIOVISUAL; - else { + p += 11; + } else { SPRINT(failure, "Given HLC type is invalid or misspelled."); goto parse_error; } @@ -1405,11 +1462,15 @@ struct route_ruleset *ruleset_parse(void) while(*p != 0) { /* read param text */ i = 0; - while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9')) { + while((*p>='a' && *p<='z') || (*p>='A' && *p<='Z') || (*p>='0' && *p<='9') || *p == '-') { if (*p>='A' && *p<='Z') *p = *p-'A'+'a'; /* lower case */ key[i++] = *p++; if (i == sizeof(key)) i--; /* limit */ } + if (*p == ':') { + p++; + goto nextaction; + } key[i] = 0; if (key[0] == '\0') { SPRINT(failure, "Expecting parameter name."); @@ -1894,9 +1955,12 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) struct timeval current_time; #ifdef WITH_MISDN struct mISDNport *mISDNport; - int avail, - any; + int avail; int jj; + class Port *port; + class Pfxs *ourfxs, *fxs; + int fxs_count; + int fxs_age; #endif struct admin_list *admin; time_t now; @@ -1947,7 +2011,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) if (!e_callerinfo.interface[0]) break; string = e_callerinfo.interface; - goto match_string_prefix; + goto match_string; case MATCH_CALLERID: string = callerid; @@ -2185,7 +2249,6 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) case MATCH_BUSY: case MATCH_IDLE: #ifdef WITH_MISDN - any = 0; mISDNport = mISDNport_first; while(mISDNport) { if (mISDNport->ifport) @@ -2215,6 +2278,86 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) istrue = 1; break; +#ifdef WITH_MISDN + case MATCH_POTS_FLASH: + if (e_dialinginfo.flash) + istrue = 1; + break; + + case MATCH_POTS_CW: + port = find_port_id(ea_endpoint->ep_portlist->port_id); + if (!port) + break; + if ((port->p_type & PORT_CLASS_POTS_MASK) != PORT_CLASS_POTS_FXS) + break; + ourfxs = (class Pfxs *)port; + port = port_first; + while(port) { + if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS) { + fxs = (class Pfxs *)port; + if (fxs->p_m_mISDNport == ourfxs->p_m_mISDNport && fxs != ourfxs) { + if (fxs->p_state == PORT_STATE_OUT_ALERTING) { + istrue = 1; + break; + } + } + } + port = port->next; + } + break; + + case MATCH_POTS_CALLS: + port = find_port_id(ea_endpoint->ep_portlist->port_id); + if (!port) + break; + if ((port->p_type & PORT_CLASS_POTS_MASK) != PORT_CLASS_POTS_FXS) + break; + ourfxs = (class Pfxs *)port; + integer = 0; + port = port_first; + while(port) { + if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS) { + fxs = (class Pfxs *)port; + if (fxs->p_m_mISDNport == ourfxs->p_m_mISDNport && fxs != ourfxs) { + if (fxs->p_state == PORT_STATE_CONNECT) { + integer++; + } + } + } + port = port->next; + } + goto match_integer; + + case MATCH_POTS_LAST: + port = find_port_id(ea_endpoint->ep_portlist->port_id); + if (!port) + break; + if ((port->p_type & PORT_CLASS_POTS_MASK) != PORT_CLASS_POTS_FXS) + break; + ourfxs = (class Pfxs *)port; + /* integer gets the call number that has been the least active call on hold */ + fxs_age = -1; + fxs_count = 0; + integer = 0; + port = port_first; + while(port) { + if ((port->p_type & PORT_CLASS_POTS_MASK) == PORT_CLASS_POTS_FXS) { + fxs = (class Pfxs *)port; + if (fxs->p_m_mISDNport == ourfxs->p_m_mISDNport && fxs != ourfxs) { + if (fxs->p_state == PORT_STATE_CONNECT) { + fxs_count++; + if (fxs->p_m_fxs_age > fxs_age) { + fxs_age = fxs->p_m_fxs_age; + integer = fxs_count; + } + } + } + } + port = port->next; + } + goto match_integer; +#endif + default: PERROR("Software error: MATCH_* %d not parsed in function '%s'", cond->match, __FUNCTION__); break; @@ -2249,7 +2392,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) /* we must have greater or equal length to values */ if ((unsigned long)strlen(string) < comp_len) { /* special case for unfinished dialing */ - if (cond->match == MATCH_DIALING) { + if (cond->match == MATCH_DIALING && !e_dialinginfo.sending_complete) { couldbetrue = 1; /* could match */ comp_len = strlen(string); } else { @@ -2323,7 +2466,8 @@ 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 sending complete, we use future match now, since waiting does not make sense anymore */ + if (timeout>now_ll && match==1 && !e_dialinginfo.sending_complete) { /* 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;