]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
- Removed alternative contexts / extensions
authorGeovani Ricardo Wiedenhoft <grw@geovani.(none)>
Mon, 25 Oct 2010 14:07:31 +0000 (12:07 -0200)
committerGeovani Ricardo Wiedenhoft <grw@geovani.(none)>
Mon, 25 Oct 2010 14:07:31 +0000 (12:07 -0200)
- New struct for matchs
- On calls originated from an FXS branch, the Endpoint searches for a valid extension (digits sent) after the DTMF '#' or after the timeout (option fxs-digit-timeout). That search is done in the context defined in section <fxs-options>, or if no context configured, the search is done in context defined in context-fxs.
- Added "dialplan" configuration: Name of the dialplan module in use
(default XML)
- Group context enabled. If set, the search for a valid extension is done only in that context.
- Updated documentation

21 files changed:
src/mod/endpoints/mod_khomp/Install/files/khomp.conf.xml
src/mod/endpoints/mod_khomp/docs/Manual.html
src/mod/endpoints/mod_khomp/docs/Manual.pdf
src/mod/endpoints/mod_khomp/docs/README.pdf
src/mod/endpoints/mod_khomp/docs/README_en.pdf
src/mod/endpoints/mod_khomp/docs/User_Guide.html
src/mod/endpoints/mod_khomp/docs/User_Guide.pdf
src/mod/endpoints/mod_khomp/include/khomp_pvt.h
src/mod/endpoints/mod_khomp/include/khomp_pvt_fxo.h
src/mod/endpoints/mod_khomp/include/khomp_pvt_gsm.h
src/mod/endpoints/mod_khomp/include/khomp_pvt_kxe1.h
src/mod/endpoints/mod_khomp/include/khomp_pvt_passive.h
src/mod/endpoints/mod_khomp/include/revision.h
src/mod/endpoints/mod_khomp/include/utils.h
src/mod/endpoints/mod_khomp/src/applications.cpp
src/mod/endpoints/mod_khomp/src/khomp_pvt.cpp
src/mod/endpoints/mod_khomp/src/khomp_pvt_fxo.cpp
src/mod/endpoints/mod_khomp/src/khomp_pvt_gsm.cpp
src/mod/endpoints/mod_khomp/src/khomp_pvt_kxe1.cpp
src/mod/endpoints/mod_khomp/src/khomp_pvt_passive.cpp
src/mod/endpoints/mod_khomp/src/utils.cpp

index 7255fb85559e9da682263f312f355b099745e9b9..ec02ca7ba644cd89df0f0971b15640d955e2948c 100644 (file)
 <channels>
 <!-- Section for main configurations about channels. -->
 
+<!--
+Name of the dialplan module in use.
+(default = XML)
+
+<param name="dialplan" value="XML"/>
+-->
+
 <!--
 Enable/disable generalized echo cancellation in the channel, for calls
 passing inside FreeSWITCH (disabled for bridged calls).
@@ -114,15 +121,6 @@ accepted, and described in the bottom of this file.
 <param name="context-fxs" value="khomp-DD-CC"/>
 -->
 
-<!--
-Defines the "alternative" context for calls on FXS channels, which will be
-checked if the main context does not match for a call. Some wildcards are
-accepted, and described in the bottom of this file.
-(default = khomp-DD)
-
-<param name="context-fxs-alt" value="khomp-DD"/>
--->
-
 <!--
 Defines the incoming context for calls on FXO channels. Some wildcards are
 accepted, and described in the bottom of this file.
@@ -131,15 +129,6 @@ accepted, and described in the bottom of this file.
 <param name="context-fxo" value="khomp-DD-CC"/>
 -->
 
-<!--
-Defines the "alternative" context for calls on FXO channels, which will be
-checked if the main context does not match for a call. Some wildcards are
-accepted, and described in the bottom of this file.
-(default = khomp-DD)
-
-<param name="context-fxo-alt" value="khomp-DD"/>
--->
-
 <!--
 Defines the incoming context for calls on GSM channels. Some wildcards are
 accepted, and described in the bottom of this file.
@@ -148,15 +137,6 @@ accepted, and described in the bottom of this file.
 <param name="context-gsm-call" value="khomp-DD-CC"/>
 -->
 
-<!--
-Defines the "alternative" context for calls on GSM channels, which will be
-checked if the main context does not match for a call. Some wildcards are
-accepted, and described in the bottom of this file.
-(default = khomp-DD)
-
-<param name="context-gsm-call-alt" value="khomp-DD"/>
--->
-
 <!--
 Defines the incoming context for messages on GSM channels. Some wildcards are
 accepted, and described in the bottom of this file.
index fc63f0d8f1fbf6463d59bbfb0fc8de4e48c12147..d0699551f61581d2dbd319aa93b20612b4f59117 100644 (file)
 </p>
 <pre><b>Sintaxe:</b> &lt;param name="..." value="..."/&gt;
 </pre>
-<ul><li><b>auto-fax-adjustment</b>: Ativa ("yes") ou desativa ("no") o ajuste automático do canal (desabilitar o cancelador de eco e a supressão DTMF) ao detectar tom de FAX; 
+<ul><li><b>dialplan</b>: Nome do módulo de <i>dialplan</i> em uso.
+</li><li><b>auto-fax-adjustment</b>: Ativa ("yes") ou desativa ("no") o ajuste automático do canal (desabilitar o cancelador de eco e a supressão DTMF) ao detectar tom de FAX; 
 </li><li><b>auto-gain-control</b>: Ativa ("yes") ou desativa ("no") a ativação do controle automático de ganho (AGC) pelo Endpoint; 
 </li><li><b>context-digital</b>: Contexto de entrada para ligações em placas digitais (o padrão é "khomp-DD-LL", onde "DD" será substituído, no momento da ligação, pelo número do dispositivo, "LL" pelo número do link, "CCC" pelo número do canal e "SSSS" pelo número serial do dispositivo); 
 </li><li><b>context-fxo</b>: Contexto de entrada para placas FXO (o padrão é "khomp-DD-CC", onde "DD" será substituído, no momento da ligação, pelo número do dispositivo, "CC" pelo número do canal, e "SSSS" pelo número serial do dispositivo); 
-</li><li><b>context-fxo-alt</b>: Contexto de entrada alternativo para placas FXO (o padrão é vazio, no entanto quando definido, segue a mesma regra de substituição da opção <b>context-fxo</b>); 
 </li><li><b>context-fxs</b>: Contexto de entrada para placas FXS (o padrão é "khomp-DD-CC", onde "DD" será substituído, no momento da ligação, pelo número do dispositivo, "CC" pelo número do canal, e "SSSS" pelo número serial do dispositivo); 
-</li><li><b>context-fxs-alt</b>: Contexto de entrada alternativo para placas FXS (o padrão é vazio, no entanto quando definido, segue a mesma regra de substituição da opção <b>context-fxs</b>); 
 </li><li><b>context-gsm-call</b> (ou "context-gsm"): Contexto de entrada para ligações GSM (o padrão é "khomp-DD-CC", onde "DD" será substituído no momento da ligação pelo número do dispositivo, "CC" pelo número do canal, e "SSSS" pelo número serial do dispositivo); 
-</li><li><b>context-gsm-call-alt</b> (ou "context-gsm-alt"): Contexto de entrada alternativo para ligações GSM (o padrão é vazio, no entanto quando definido, segue a mesma regra de substituição da opção <b>context-gsm-call</b>); 
 </li><li><b>context-gsm-sms</b>: Contexto de entrada para SMSs (o padrão é "khomp-sms-DD-CC", onde "DD" será substituído pelo número de dispositivo, "CC" pelo número do canal, e "SSSS" pelo número serial do dispositivo);
 </li><li><b>context-pr</b>: Contexto de entrada para ligações em placas KPR (o padrão é "khomp-DD-CC", onde "DD" será substituído, no momento da ligação, pelo número do dispositivo, "CC" pelo número do canal); 
 </li><li><b>disconnect-delay</b>: Define o tempo em milissegundos para realizar o processamento de um evento de desconexão, para ignorar situações onde outros equipamentos realizam o duplo atendimento para derrubar chamadas a cobrar;
@@ -215,8 +213,8 @@ de entrada no link 1 (segundo link) da placa 0.
 <br />
 </p>
 <a name="Contextos_de_entrada_em_canais_FXS.2FFXO.2FGSM" id="Contextos_de_entrada_em_canais_FXS.2FFXO.2FGSM"></a><h3> <span class="mw-headline"> Contextos de entrada em canais FXS/FXO/GSM </span></h3>
-<p>Da mesma forma que no contexto de placas E1, as ligações de entrada são encaminhadas pelo <i>Endpoint</i> para o FreeSWITCH. Entretanto, estas sinalizações possuem dois contextos pré-definidos, buscados com uma ordem de preferência.
-</p><p>O primeiro contexto é pré-definido da seguinte forma, conforme o arquivo <b>khomp.conf.xml</b>:
+<p>Da mesma forma que no contexto de placas E1, as ligações de entrada são encaminhadas pelo <i>Endpoint</i> para o FreeSWITCH. 
+</p><p>O contexto é pré-definido da seguinte forma, conforme o arquivo <b>khomp.conf.xml</b>:
 </p>
 <pre>&lt;param name="context-gsm" value="khomp-DD-CC"/&gt;&nbsp;;placas GSM
 </pre>
@@ -224,27 +222,14 @@ de entrada no link 1 (segundo link) da placa 0.
 </pre>
 <pre>&lt;param name="context-fxo" value="khomp-DD-CC"/&gt;&nbsp;; placas FXO
 </pre>
-<p>Enquanto o segundo contexto possui o seguinte formato padrão:
-</p>
-<pre>&lt;param name="context-gsm-alt" value="khomp-DD"/&gt;&nbsp;; placas GSM
-</pre>
-<pre>&lt;param name="context-fxs-alt" value="khomp-DD"/&gt;&nbsp;; placas FXS
-</pre>
-<pre>&lt;param name="context-fxo-alt" value="khomp-DD"/&gt;&nbsp;; placas FXO
-</pre>
-<p>Nestes casos, <b>DD</b> é o número dispositivo (com dois dígitos), e <b>CC</b> é o número do canal da placa. Pode-se utilizar também <b>SSSS</b>, que representa o número serial da placa. 
+<p><br />
+Nestes casos, <b>DD</b> é o número dispositivo (com dois dígitos), e <b>CC</b> é o número do canal da placa. Pode-se utilizar também <b>SSSS</b>, que representa o número serial da placa. 
 </p>
 <ul><li> <b>IMPORTANTE</b>: No caso da placa <b>KGSM</b>, as ligações entrantes são <b>sempre</b> encaminhadas para o <i>extension</i> <b>"s"</b> por padrão, visto que o protocolo GSM não identifica o número de destino nas ligações entrantes, apenas o número de origem - quando não omitido.
 </li></ul>
 <a name="Prioridade_de_contextos_na_placa_FXS" id="Prioridade_de_contextos_na_placa_FXS"></a><h4> <span class="mw-headline"> Prioridade de contextos na placa FXS </span></h4>
-<p>Em ligações originadas a partir de um ramal FXS, o Endpoint driver procura uma extensão válida dos dígitos discados em três contextos diferentes. A prioridade dos contextos é a seguinte:
-</p>
-<ol><li> Contexto específico do ramal, definido na seção <b>&lt;fxs-options&gt;</b> do arquivo de configuração do <b>khomp.conf.xml</b>;
-</li><li> Contexto definido na opção <b>context-fxs</b>;
-</li><li> Contexto definido na opção <b>context-fxs-alt</b>.
-</li></ol>
-<p>Caso durante a discagem, nenhuma extensão válida puder ser encontrada, a extensão <b>i</b> é procurada nos contextos em ordem de prioridade, e por fim no contexto <b>default</b>. Caso ocorra um <i>timeout</i> durante a discagem (configurável pela opção <b>fxs-digit-timeout</b>, no arquivo <b>khomp.conf.xml</b>) durante a discagem, o mesmo comportamento será aplicado - no entanto, a busca se dará inicialmente pelo número já discado até o <i>timeout</i> e, se não encontrado, a busca nos contextos será repetida para a extensão "t".
-<br />
+<p>Em ligações originadas a partir de um ramal FXS, o Endpoint driver procura uma extensão válida (dos dígitos discados) após o dígito <b>#</b> ou após o timeout (configurável pela opção <b>fxs-digit-timeout</b>, no arquivo <b>khomp.conf.xml</b>). Essa busca é realizada no contexto específico do ramal (definido na seção <b>&lt;fxs-options&gt;</b> do arquivo de configuração <b>khomp.conf.xml</b>), caso não seja configurado, a busca é realizada no contexto definido na opção <b>context-fxs</b>;
+</p><p><br />
 </p>
 <a name="Contextos_de_mensagens_SMS_.28apenas_GSM.29" id="Contextos_de_mensagens_SMS_.28apenas_GSM.29"></a><h3> <span class="mw-headline"> Contextos de mensagens SMS (apenas GSM) </span></h3>
 <p>Mensagens SMS são recebidas pelo <i>Endpoint</i> da Khomp e encaminhadas para o FreeSWITCH como uma ligação normal, mas sem áudio, que possui algumas variáveis ajustadas com informações recebidas na mensagem - para maiores informações sobre estas variáveis, consulte a documentação das variáveis do <i>Endpoint</i>. Este contexto também pode ser alterado, de mesma forma que o contextos acima.
@@ -270,7 +255,10 @@ de entrada no link 1 (segundo link) da placa 0.
 </pre>
 <p>Neste caso, <b>DD</b> é o número do dispositivo (com dois dígitos), e <b>CC</b> é o número do canal da placa.
 <br />
-</p><p><br />
+</p>
+<a name="Contextos_por_grupo_de_chamada" id="Contextos_por_grupo_de_chamada"></a><h3> <span class="mw-headline">Contextos por grupo de chamada </span></h3>
+<p>A seção <b>groups</b>, no arquivo de configuração <b>khomp.conf.xml</b>, pode ser utilizado para definir contextos específicos para determinados grupos de canais.
+</p><p>Esta seção é detalhada na seção <b>Configuração do Endpoint</b>.
 <br />
 </p>
 <a name="Utiliza.C3.A7.C3.A3o_do_application_bridge" id="Utiliza.C3.A7.C3.A3o_do_application_bridge"></a><h3> <span class="mw-headline">Utilização do <i>application</i> bridge </span></h3>
index ea29f716ec2b8f62651ae66bc396e97f1a5c13fc..665be58ee3b76614e2d787029c423f543781d6b7 100644 (file)
Binary files a/src/mod/endpoints/mod_khomp/docs/Manual.pdf and b/src/mod/endpoints/mod_khomp/docs/Manual.pdf differ
index 698ab83daecc34a1f5dad2bca780d38c4e4fa680..a65cc28d66f1f2de6288c4a62ef0ccd1a7bfd068 100644 (file)
Binary files a/src/mod/endpoints/mod_khomp/docs/README.pdf and b/src/mod/endpoints/mod_khomp/docs/README.pdf differ
index e36d6f1191102c4616d6382b6ca5a021c8aa9638..2864e403fca13bb436047954a77a8c7b3464d9ea 100644 (file)
Binary files a/src/mod/endpoints/mod_khomp/docs/README_en.pdf and b/src/mod/endpoints/mod_khomp/docs/README_en.pdf differ
index 1a276b9e373d39e2ff6ce50e5d934ac5da64acc3..ceb520b0d2176107c1e0418e4e401c4b4fd84887 100644 (file)
@@ -30,17 +30,14 @@ If you need to set advanced parameters of the board and/or signaling, the progra
 </p>
 <pre><b>Sintaxe:</b> &lt;param name="..." value="..."/&gt;
 </pre>
-<ul><li><b>auto-fax-adjustment</b>: Enable ("yes") or disables ("no") the automatic adjustment of the channel (disable the echo canceller and the suppression DTMF) tone to detect FAX (local option)&nbsp;;
+<ul><li><b>dialplan</b>: Name of the dialplan module in use.
+</li><li><b>auto-fax-adjustment</b>: Enable ("yes") or disables ("no") the automatic adjustment of the channel (disable the echo canceller and the suppression DTMF) tone to detect FAX (local option)&nbsp;;
 </li><li><b>auto-gain-control</b>:Enable ("yes") or disables ("no") the activation of the automatic gain control (AGC) by the Endpoint (local option);
 </li><li><b>context-digital</b>: Context for incoming connections on digital boards (the default is "khomp-DD-LL", where "DD" will be replaced at the time of connection by the device number, "LL" by the number of the link, "CCC" by channel number and "SSSS" for the device serial number);
 </li><li><b>context-fxo</b>: Context for incoming connections on FXO cards (the default is "khomp-CC-DD", where "DD" will be replaced at the time of connection by the device number, "CC" by channel number, and "SSSS" by the device serial number);
-</li><li><b>context-fxo-alt</b>: Alternative input context for FXO cards (the default is empty - when set, follows the same substitution rules for <b>context-fxo</b>);
 </li><li><b>context-fxs</b>: Context for incoming connections on FXS cards (the default is "khomp-CC-DD", where "DD" will be replaced at the time of connection by the device number, "CC" by channel number, and "SSSS" by the device serial number); 
-</li><li><b>context-fxs-alt</b>: Alternative input context for FXS cards (the default is empty - when set, follows the same substitution rules for context-fxs); number); 
 </li><li><b>context-gsm-call</b> (or <b>context-gsm</b>): Context of entry for GSM boards (the default is "khomp-CC-DD", where "DD" will be replaced at the time of connection by the device number, "CC" by channel number, and "SSSS" by the device serial number);
-</li><li><b>context-gsm-alt-call</b> (or <b>context-gsm-alt</b>): Alternative input context for GSM (the default is zero - when set, follows the same substitution rules for <b>context-gsm-call</b>);
 </li><li><b>context-gsm-sms</b>: Context for incoming SMSs (the default is "khomp-sms-CC-DD", where "DD" will be replaced by the number of device, "CC" by channel number and "SSSS" by the device's serial number);
-</li><li><b>context-gsm-wait</b>: Context used for pre-processing of incoming GSM calls that are on waiting state - to disable this feature, use <b>none</b> (the default is "khomp-wait-CC-DD", where "DD" will be replaced by the number of device, "CC" by channel number and "SSSS" by the device's serial number);
 </li><li><b>context-pr</b>: Context for incoming connections on boards KPR (default is "khomp-CC-DD", where "DD" will be replaced at the time of connection by the device number, "CC "by channel number);
 </li><li><b>disconnect-delay</b>: Sets the time in milliseconds to perform processing a disconnect event, to ignore situations where other equipment performing the double service to overthrow collect calls (local option);
 </li><li><b>echo-canceller</b> (former 'echocanceller): Active ("yes") or disables ("no") echo cancellation automatic Endpoint (local option);
@@ -223,8 +220,8 @@ that come from the link 1 (second link) of the board 0.
 </li><li> The incoming calls on the link <b>1</b> of the board <b>0</b> for the number <b>1111</b> will be redirected to the first link of the first board (b0L0) calling number <b>2345</b>.
 </li></ol>
 <a name="Contexts_of_FXS.2FFXO.2FGSM_channels" id="Contexts_of_FXS.2FFXO.2FGSM_channels"></a><h3> <span class="mw-headline"> Contexts of FXS/FXO/GSM channels </span></h3>
-<p>Just as in the context of E1 cards, inbound links are forwarded to the Endpoint FreeSwitch. However, these signals have two pre-defined contexts, sought with a preference order.
-</p><p>The first context is pre-defined as follows, according to the file <b>khomp.conf.xml</b>:
+<p>Just as in the context of E1 cards, inbound links are forwarded to the Endpoint FreeSwitch. 
+</p><p>The context is pre-defined as follows, according to the file <b>khomp.conf.xml</b>:
 </p>
 <pre>&lt;param name="context-gsm" value="khomp-DD-CC"/&gt;&nbsp;;placas GSM
 </pre>
@@ -232,26 +229,12 @@ that come from the link 1 (second link) of the board 0.
 </pre>
 <pre>&lt;param name="context-fxo" value="khomp-DD-CC"/&gt;&nbsp;; placas FXO
 </pre>
-<p>There is also an alternative context, which has the following default value:
-</p>
-<pre>&lt;param name="context-gsm-alt" value="khomp-DD"/&gt;&nbsp;; placas GSM
-</pre>
-<pre>&lt;param name="context-fxs-alt" value="khomp-DD"/&gt;&nbsp;; placas FXS
-</pre>
-<pre>&lt;param name="context-fxo-alt" value="khomp-DD"/&gt;&nbsp;; placas FXO
-</pre>
 <p>For these options, <b>DD</b> is the device number (two digits), and <b>CC</b> is the channel number (also two digits). There is also the <b>SSSS</b> format, which represents the serial number board.
 </p>
 <ul><li><b>NOTE</b>: In the <b>KGSM</b> board, incoming calls are <b>always</b> redirected to the <b>"s"</b> extension, since the GSM protocol does not identify the target number, only the originator - if not omitted.
 </li></ul>
 <a name="Priority_settings_on_the_FXS_branches" id="Priority_settings_on_the_FXS_branches"></a><h4> <span class="mw-headline"> Priority settings on the FXS branches </span></h4>
-<p>On calls originated from an FXS branch, the Endpoint searches for a valid extension in three different contexts. The priority of contexts is as follows:
-</p>
-<ol><li> Branch-specific extension, defined in section <b>&lt;fxs-options&gt;</b> of file <b>khomp.conf.xml</b>;
-</li><li> Context defined in <b>context-fxs</b>;
-</li><li> Context defined in <b>context-fxs-alt</b>.
-</li></ol>
-<p>If no valid extension can be found, the extension <b>i</b> is searched in the contexts above, and also in the <b>default</b> context. If the dialing timeout is reached (option <b>fxs-digit-timeout</b>), the search will consider all digits dialed until the timeout; if no extension is found, it will search extension "t"; if nothing is found again, then extension "i" will be searched; if no extension is found, "fast-busy" cadence will be played.
+<p>On calls originated from an FXS branch, the Endpoint searches for a valid extension (digits sent) after the DTMF <b>#</b> or after the <i>timeout</i> (option <b>fxs-digit-timeout</b>). That search is done in the context defined in section <b>&lt;fxs-options&gt;</b>, or if no context configured, the search is done in context defined in <b>context-fxs</b>.
 <br />
 </p>
 <a name="Contexts_for_SMS_messages_.28GSM_only.29" id="Contexts_for_SMS_messages_.28GSM_only.29"></a><h3> <span class="mw-headline"> Contexts for SMS messages (GSM only) </span></h3>
@@ -278,6 +261,10 @@ that come from the link 1 (second link) of the board 0.
 </pre>
 <p>In this case, <b>DD</b> is the device number (two digits), and<b>CC</b> is the channel number (also two digits). The name and format of this context can also be changed through the "context-pr" in the configuration file.
 <br />
+</p>
+<a name="Groups_contexts" id="Groups_contexts"></a><h3> <span class="mw-headline"> Groups contexts </span></h3>
+<p>The section <b>groups</b>, in the configuration file <b>khomp.conf.xml</b>, can be used to define specific settings for certain groups of channels.
+</p><p>This section is detailed in the section <b>Endpoint Configuration</b>.
 <br />
 </p>
 <a name="Using_the_bridge_application" id="Using_the_bridge_application"></a><h3> <span class="mw-headline"> Using the <i>bridge</i> application </span></h3>
index 2f8c874a2417c21e7ece4e95cc903dd662c358fc..fd8027ba2b29bcfae0670899279dfec11473750a 100644 (file)
Binary files a/src/mod/endpoints/mod_khomp/docs/User_Guide.pdf and b/src/mod/endpoints/mod_khomp/docs/User_Guide.pdf differ
index 5037492b9b96f3fd053ddfcffb047dcc1946c25c..bed6e1e08ee9524e4cb3063b7e3121ce6df7b12d 100644 (file)
@@ -85,10 +85,6 @@ struct Board
 /******************************** Channel *************************************/
 struct KhompPvt
 {
-    // TODO: Here for while, put in right struct, when is ready
-    typedef std::vector<std::string> ContextListType;
-    typedef std::vector<std::string> ExtenListType;
-
     typedef SimpleNonBlockLock<25,100>      ChanLockType;
 
     typedef enum
@@ -994,29 +990,26 @@ public:
 
     virtual int getActiveChannel(bool invalid_as_not_found);
 
-    MatchType matchExtension(std::string &, std::string &, std::string &, bool match_only = false);
-
-    MatchType findExtension(std::string &, std::string &, ContextListType &, std::string &, std::string &, 
-                            bool default_ctx = true, bool default_ext = true);
-
     /* Let's validate the contexts */
-    virtual bool validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_string = "")
+    virtual bool validContexts(MatchExtension::ContextListType & contexts, 
+                               std::string extra_string = "")
     {
         DBG(FUNC,PVT_FMT(_target,"c"));
 
         if(!_group_context.empty())
         {
-            contexts.push_back(_group_context);
+            contexts.insert(contexts.begin(), _group_context);
+            //contexts.push_back(_group_context);
         }
     
-        for (Board::KhompPvt::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++) 
+        for (MatchExtension::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++) 
             replaceTemplate((*i),  "DD", _target.device);
 
         BEGIN_CONTEXT  
         {    
             K3L_DEVICE_CONFIG & dev_cfg = Globals::k3lapi.device_config(_target.device);
 
-            for (Board::KhompPvt::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++) 
+            for (MatchExtension::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++) 
                 replaceTemplate((*i), "SSSS", atoi(dev_cfg.SerialNumber));
         }    
         END_CONTEXT
index 87eaa298b9e98b4ae5fe67c12451f677c46d0851..130c3b311ea3df57151ac5c42644b181930e39ca 100644 (file)
@@ -241,7 +241,8 @@ struct KhompPvtFXO: public KhompPvt
     void setAnswerInfo(int answer_info);
     bool indicateBusyUnlocked(int cause, bool sent_signaling = false);
     void reportFailToReceive(int fail_code);
-    bool validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context = "");
+    bool validContexts(MatchExtension::ContextListType & contexts, 
+                       std::string extra_context = "");
   
     bool isOK(void); 
 
index 31ca1a0be5977e7718b6e188c2ea9b53520ec1ee..d31dba51cca602a90593b3c0f3bd942cdc8a57cc 100644 (file)
@@ -262,7 +262,8 @@ struct KhompPvtGSM: public KhompPvt
         _sms->statistics()->clear();
     }
 
-    bool validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context = "");
+    bool validContexts(MatchExtension::ContextListType & contexts, 
+                       std::string extra_context = "");
         
     SMS * _sms;
 
index c87dd23276dc44761068e3862084b7d054f990e7..85b1af0e174277d1df9a892ca4b667b8c71ccc22 100644 (file)
@@ -191,7 +191,8 @@ struct KhompPvtE1: public KhompPvt
     bool setupConnection();
     bool indicateBusyUnlocked(int cause, bool sent_signaling = false);
     void setAnswerInfo(int answer_info);
-    bool validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context = "");
+    bool validContexts(MatchExtension::ContextListType & contexts, 
+                       std::string extra_context = "");
     bool isOK(void); 
 
     bool isPhysicalFree() 
@@ -931,7 +932,8 @@ struct KhompPvtFXS: public KhompPvt
     bool alloc();
     bool indicateBusyUnlocked(int cause, bool sent_signaling = false);
     void reportFailToReceive(int fail_code);
-    bool validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context = "");
+    bool validContexts(MatchExtension::ContextListType & contexts, 
+                       std::string extra_context = "");
     bool isOK(void);
 
     bool startTransfer();
index 55b0659b806b6ddcea8419c92f61bd88ab203ae4..a0a6df0aaf7febd2cfe49cbefc3d361b47c81be6 100644 (file)
@@ -126,7 +126,8 @@ struct KhompPvtPassive: public KhompPvt
         return ret;
     }
     
-    bool validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context = "");
+    bool validContexts(MatchExtension::ContextListType & contexts, 
+                       std::string extra_context = "");
 
 /*
     virtual bool cleanup(CleanupType type = CLN_HARD)
index 4665cda0abf93ccdc1184e0ba684042caf4b6f76..bbb7f6b61b270199e7681d584969ecb5d8081e6b 100644 (file)
@@ -1 +1 @@
-#define MOD_KHOMP_VERSION "1.0 - (rev: 5796)"
+#define MOD_KHOMP_VERSION "1.0 - (rev: 5823)"
index 34e9b2653e07aa5a559ec5012870ede27fbec918..0c71a74188d52db1e6678e53960461bdbd668631 100644 (file)
@@ -601,109 +601,30 @@ static std::string timeToString (time_t time_value)
 }
 /******************************************************************************/
 /******************************* Match functions ******************************/
-typedef enum
-{
-    MATCH_NONE,
-    MATCH_EXACT,
-    MATCH_MORE
-}
-MatchType;
-
-static bool canMatch(std::string & context, std::string & exten, std::string & caller_id, bool match_more = false)
+struct MatchExtension
 {
-    switch_xml_t xml = NULL;
-    switch_xml_t xcontext = NULL;
-    switch_regex_t *re;
-    int ovector[30];
-    
-    if (switch_xml_locate("dialplan","context","name",context.c_str(),&xml,&xcontext, NULL,SWITCH_FALSE) == SWITCH_STATUS_SUCCESS)
-    {
-        switch_xml_t xexten = NULL;
-        
-        if(!(xexten = switch_xml_child(xcontext,"extension")))
-        {
-            DBG(FUNC,"extension cannot match, returning");
-
-            if(xml)
-                switch_xml_free(xml); 
-
-            return false;
-        }
+    typedef std::vector<std::string> ContextListType;
+    typedef std::vector<std::string> ExtenListType;
 
-        while(xexten)
-        {
-            switch_xml_t xcond = NULL;
-
-            for (xcond = switch_xml_child(xexten, "condition"); xcond; xcond = xcond->next)
-            {
-                std::string expression;
-
-                if (switch_xml_child(xcond, "condition")) 
-                { 
-                    LOG(ERROR,"Nested conditions are not allowed");
-                }  
-
-                switch_xml_t xexpression = switch_xml_child(xcond, "expression");
-
-                if ((xexpression = switch_xml_child(xcond, "expression"))) 
-                {
-                    expression = switch_str_nil(xexpression->txt);
-                }
-                else 
-                {
-                    expression =  switch_xml_attr_soft(xcond, "expression");
-                }  
-
-                if(expression.empty() || expression == "^(.*)$")
-                {
-                    /** 
-                    * We're not gonna take it
-                    * No, we ain't gonna take it
-                    * We're not gonna take it anymore
-                    **/
-                    continue;
-                }
-          
-                int pm = -1; 
-                switch_status_t is_match = SWITCH_STATUS_FALSE;
-                is_match =  switch_regex_match_partial(exten.c_str(),expression.c_str(),&pm);
-                
-                if(is_match == SWITCH_STATUS_SUCCESS)
-                {
-                    if(match_more)
-                    {
-                        if(pm == 1)
-                        {
-                            switch_xml_free(xml);
-                            return true;
-                        }
-                    }
-                    else
-                    {
-                        switch_xml_free(xml);
-                        return true;
-                    }
-                }
-                else
-                {
-                    // not match
-                }
-            }            
-
-            xexten = xexten->next;
-        }
-    }
-    else
+    typedef enum
     {
-        DBG(FUNC,"context cannot match, returning");
+        MATCH_NONE,
+        MATCH_EXACT,
+        MATCH_MORE
     }
+    MatchType;
 
-    if(xml)
-        switch_xml_free(xml); 
+    static bool canMatch(std::string & context, std::string & exten, 
+                std::string & caller_id, bool match_more = false);
 
-    return false;
-}
+    static MatchType matchExtension(std::string &, std::string &, 
+                std::string &, bool match_only = false);
 
+    static MatchType findExtension(std::string &, std::string &, 
+                ContextListType &, std::string &, std::string &,
+                bool default_ctx = true, bool default_ext = true);
+
+};
 /******************************************************************************/
 /************************** Thread helper functions ***************************/
 typedef int (HandlerType)(void *);
index 3826431695db3c322600e4341c3bcf73a3b0bd14..d4a50e0adbfc41eec334778e34231c1cd837e866 100644 (file)
@@ -382,26 +382,27 @@ bool Fax::addFaxFile(const char * filename, bool last)
 bool SMS::justAlloc(unsigned int count)
 {
     /* incoming contexts */
-    Board::KhompPvt::ContextListType contexts;
+    MatchExtension::ContextListType contexts;
 
     contexts.push_back(Opt::_context_gsm_sms);
 
     /* temporary variables */
     std::string context;
-    std::string exten;
+    std::string exten("s");
 
     K3L_DEVICE_CONFIG & dev_cfg = Globals::k3lapi.device_config(_pvt->_target.device);
 
-    for (Board::KhompPvt::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++)
+    for (MatchExtension::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++)
     {
         replaceTemplate((*i), "DD", _pvt->_target.device);
         replaceTemplate((*i), "CC", _pvt->_target.object);
         replaceTemplate((*i), "SSSS", atoi(dev_cfg.SerialNumber));
     }
 
-    switch(_pvt->findExtension(exten, context, contexts, _got_sms._type, _got_sms._from, false, true))
+    //switch(_pvt->findExtension(exten, context, contexts, _got_sms._type, _got_sms._from, false, true))
+    switch(MatchExtension::findExtension(exten, context, contexts, exten, _got_sms._from, false, true))
     {
-    case MATCH_NONE:
+    case MatchExtension::MATCH_NONE:
         if( _got_sms._type != "broadcast")
         {
             LOG(WARNING, PVT_FMT(_pvt->target(), "unable to find context/exten for incoming SMS (s/%s), processing disabled for this channel.")
@@ -437,7 +438,7 @@ bool SMS::justAlloc(unsigned int count)
 
         switch_caller_profile_t *caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
                 "Khomp_SMS",                       //username
-                "XML",                             //dialplan
+                Opt::_dialplan.c_str(),            //dialplan
                 NULL,                              //caller_id_name
                 _got_sms._from.c_str(),            //caller_id_number
                 NULL,                              //network_addr
index 3d1235e61d7db6c267863f29ca2f7316268493d5..225312be541c0c0a28461eb63bd130645b33ede2 100644 (file)
@@ -592,7 +592,7 @@ switch_status_t Board::KhompPvt::justStart(switch_caller_profile_t *profile)
 
             if(call()->_incoming_context.empty())
             {
-                Board::KhompPvt::ContextListType contexts;
+                MatchExtension::ContextListType contexts;
                 std::string context("default");
 
                 if(!validContexts(contexts))
@@ -603,16 +603,16 @@ switch_status_t Board::KhompPvt::justStart(switch_caller_profile_t *profile)
                     return SWITCH_STATUS_FALSE;
                 }
 
-                switch(findExtension(exten, context, contexts, _call->_dest_addr, _call->_orig_addr)) 
+                switch(MatchExtension::findExtension(exten, context, contexts, _call->_dest_addr, _call->_orig_addr)) 
                 {
-                    case MATCH_NONE:
+                    case MatchExtension::MATCH_NONE:
                         destroy();
                         owner(NULL);
                         LOG(ERROR, PVT_FMT(_target, "r (unable to find exten/context on incoming call %s/%s)")
                                 % _call->_dest_addr % (contexts.size() >= 1 ? contexts[0] : "default"));
                         return SWITCH_STATUS_FALSE; 
                     default:
-                        DBG(FUNC, PVT_FMT(_target, "our: context '%s', exten '%s'") % context % exten);
+                        DBG(FUNC, PVT_FMT(_target, "our: dialplan '%s', context '%s', exten '%s'") % Opt::_dialplan % context % exten);
                         break;
                 }
 
@@ -621,12 +621,12 @@ switch_status_t Board::KhompPvt::justStart(switch_caller_profile_t *profile)
             else
             {
                 exten = call()->_dest_addr;
-                DBG(FUNC, PVT_FMT(target(), "already found our: context '%s', exten '%s'") % call()->_incoming_context % exten);
+                DBG(FUNC, PVT_FMT(target(), "already found our: dialplan '%s', context '%s', exten '%s'") % Opt::_dialplan % call()->_incoming_context % exten);
             }
             
             _caller_profile = switch_caller_profile_new(switch_core_session_get_pool(_session),
                     "Khomp",                           //username
-                    "XML",                             //dialplan
+                    Opt::_dialplan.c_str(),            //dialplan
                     NULL,                              //caller_id_name
                     _call->_orig_addr.c_str(),         //caller_id_number
                     NULL,                              //network_addr
@@ -1421,91 +1421,6 @@ int Board::KhompPvt::getActiveChannel(bool invalid_as_not_found)
     return 0;
 }
 
-MatchType Board::KhompPvt::matchExtension(std::string & context, std::string & exten,
-                                                           std::string & callerid, bool match_only)
-{
-    if(!canMatch(context,exten,callerid))
-    {
-        DBG(FUNC, "context/extension cannot match");
-        return MATCH_NONE;
-    }
-
-    if(match_only)
-    {
-        DBG(FUNC, "for now we want know if it matches...");
-        return MATCH_MORE;
-    }
-
-    if(!canMatch(context,exten,callerid,true))
-    {
-        DBG(FUNC, "it match exact!");
-        return MATCH_EXACT;
-    }
-
-    return MATCH_MORE;
-}
-
-MatchType Board::KhompPvt::findExtension(std::string & ref_extension, 
-                                         std::string & ref_context,
-                                         ContextListType & contexts,
-                                         std::string & extension,
-                                         std::string & caller_id,
-                                         bool default_ctx,
-                                         bool default_ext)
-{
-    Board::KhompPvt::ExtenListType extens;
-
-    if(!extension.empty())
-    {
-        extens.push_back(extension);
-    }
-
-    if(default_ext)
-    {
-        if (extension != "s")
-        {
-            extens.push_back("s");
-        }
-
-        extens.push_back("i");
-    }
-
-    if(default_ctx)
-    {
-        contexts.push_back("default");
-    }
-
-    for(Board::KhompPvt::ContextListType::iterator itc = contexts.begin(); itc != contexts.end(); itc++)
-    {
-        for(Board::KhompPvt::ExtenListType::iterator ite = extens.begin(); ite != extens.end(); ite++)
-        {
-            DBG(FUNC, FMT("trying context '%s' with exten '%s'...") % *itc % *ite);
-
-            MatchType m = matchExtension(*itc, *ite, caller_id, false);
-
-            switch (m)
-            {    
-                case MATCH_NONE:
-                    continue;
-
-                case MATCH_MORE:
-                case MATCH_EXACT:
-                {    
-                    ref_context = *itc;
-                    ref_extension = *ite;
-
-                    DBG(FUNC, ".... can match context/extension (some way)!");
-
-                    return m;
-                }    
-            } 
-        }
-    }
-
-    DBG(FUNC, D("... no context/extension found!"));
-    return MATCH_NONE;
-}
-
 bool Board::KhompPvt::setCollectCall()
 {
     DBG(FUNC, PVT_FMT(target(), "c"));
index 1383f5cf5fe1c573f16a612398a694ea3089fdc9..f45638b3b4d1368e14f06fe8e6fdc1de755c8f2f 100644 (file)
@@ -734,14 +734,15 @@ void BoardFXO::KhompPvtFXO::reportFailToReceive(int fail_code)
 
 }
 
-bool BoardFXO::KhompPvtFXO::validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context)
+bool BoardFXO::KhompPvtFXO::validContexts(
+        MatchExtension::ContextListType & contexts, std::string extra_context)
 {
     DBG(FUNC,PVT_FMT(_target,"(FXO) c"));
 
     contexts.push_back(Opt::_context_fxo);
     contexts.push_back(Opt::_context2_fxo);
 
-    for (Board::KhompPvt::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++)
+    for (MatchExtension::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++)
     {
         replaceTemplate((*i), "CC", _target.object);
     }
index 2f24c60af56eb488fe3ea1f21729580e08c0e3e1..1095c5a29664b815e2e51309cdde7cc7745eef5c 100644 (file)
@@ -511,7 +511,8 @@ int BoardGSM::KhompPvtGSM::callFailFromCause(int cause)
     return k3l_fail;
 }
 
-bool BoardGSM::KhompPvtGSM::validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context)
+bool BoardGSM::KhompPvtGSM::validContexts(
+        MatchExtension::ContextListType & contexts, std::string extra_context)
 {
     DBG(FUNC,PVT_FMT(_target,"(GSM) c"));
 
@@ -540,20 +541,12 @@ bool BoardGSM::KhompPvtGSM::validContexts(Board::KhompPvt::ContextListType & con
             context += extra_context;
             contexts.push_back(_group_context);
         }    
-
-        if (!Opt::_context2_gsm_call.empty())
-        {    
-            std::string context(Opt::_context2_gsm_call);
-            context += "-"; 
-            context += extra_context;
-            contexts.push_back(_group_context);
-        }    
     }  
 
     contexts.push_back(Opt::_context_gsm_call);
     contexts.push_back(Opt::_context2_gsm_call);
 
-    for (Board::KhompPvt::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++) 
+    for (MatchExtension::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++) 
         replaceTemplate((*i), "CC", _target.object);
 
     bool ret = Board::KhompPvt::validContexts(contexts,extra_context);
index 4dec540d09b0af07cecb5713f19c3de3e09c896e..b5acfd18e6c94a9594e0d5087a6ed3794b5212c2 100644 (file)
@@ -818,13 +818,14 @@ bool BoardE1::KhompPvtE1::application(ApplicationType type, switch_core_session_
     return true;
 }
 
-bool BoardE1::KhompPvtE1::validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context)
+bool BoardE1::KhompPvtE1::validContexts(
+        MatchExtension::ContextListType & contexts, std::string extra_context)
 {
     DBG(FUNC,PVT_FMT(_target, "(E1) c"));
 
     contexts.push_back(Opt::_context_digital);
 
-    for (Board::KhompPvt::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++) 
+    for (MatchExtension::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++) 
     {    
         replaceTemplate((*i), "LL", ((_target.object)/30));
         replaceTemplate((*i), "CCC", _target.object);
@@ -1903,19 +1904,19 @@ bool BoardE1::KhompPvtR2::onNumberDetected(K3L_EVENT *e)
         DBG(FUNC, PVT_FMT(_target, "incoming exten %s") % callR2()->_incoming_exten);
 
         /* begin context adjusting + processing */
-        Board::KhompPvt::ContextListType contexts;
+        MatchExtension::ContextListType contexts;
 
         validContexts(contexts);
 
         /* temporary */
-        std::string tmp_exten("s");
-        std::string tmp_context("default");
+        std::string tmp_exten;
+        std::string tmp_context;
         std::string tmp_orig("");
 
-        switch (findExtension(tmp_exten, tmp_context, contexts, callR2()->_incoming_exten,tmp_orig, false, false))
+        switch (MatchExtension::findExtension(tmp_exten, tmp_context, contexts, callR2()->_incoming_exten,tmp_orig, false, false))
         {    
-            case MATCH_EXACT:
-            case MATCH_NONE:
+            case MatchExtension::MATCH_EXACT:
+            case MatchExtension::MATCH_NONE:
                 call()->_flags.set(Kflags::NUMBER_DIAL_FINISHD);
 
                 DBG(FUNC,FMT("incoming exten matched: %s") % callR2()->_incoming_exten);
@@ -1924,7 +1925,7 @@ bool BoardE1::KhompPvtR2::onNumberDetected(K3L_EVENT *e)
                 command(KHOMP_LOG,CM_END_OF_NUMBER);
                 break;
 
-            case MATCH_MORE:
+            case MatchExtension::MATCH_MORE:
                 DBG(FUNC, "didn't match exact extension, waiting...");
                 // cannot say anything exact about the number, do nothing...
                 break;
@@ -2396,18 +2397,19 @@ void BoardE1::KhompPvtFXS::transferTimer(KhompPvt * pvt)
         }
 
         /* begin context adjusting + processing */
-        ContextListType contexts;
+        MatchExtension::ContextListType contexts;
 
         pvt_fxs->validContexts(contexts);
 
-        std::string tmp_exten("s");
-        std::string tmp_context("default");
+        std::string tmp_exten;
+        std::string tmp_context;
 
-        switch (pvt_fxs->findExtension(tmp_exten, tmp_context, contexts, pvt_fxs->callFXS()->_flash_transfer, pvt_fxs->call()->_orig_addr, false, false))
+        switch (MatchExtension::findExtension(tmp_exten, tmp_context, contexts, pvt_fxs->callFXS()->_flash_transfer, pvt_fxs->call()->_orig_addr, false, false))
         {
-            case MATCH_EXACT:
-            case MATCH_MORE:
+            case MatchExtension::MATCH_EXACT:
+            case MatchExtension::MATCH_MORE:
             {
+                pvt_fxs->callFXS()->_flash_transfer = tmp_exten;
                 DBG(FUNC,FMT("incoming exten matched: %s") % pvt_fxs->callFXS()->_flash_transfer);
 
                 if(!pvt_fxs->transfer(tmp_context))
@@ -2419,7 +2421,7 @@ void BoardE1::KhompPvtFXS::transferTimer(KhompPvt * pvt)
 
                 break;
             }
-            case MATCH_NONE:
+            case MatchExtension::MATCH_NONE:
             {
                 DBG(FUNC, PVT_FMT(pvt_fxs->target(), "match none!"));
                 
@@ -2702,7 +2704,7 @@ bool BoardE1::KhompPvtFXS::transfer(std::string & context, bool blind)
         if(blind)
         {
             DBG(FUNC, PVT_FMT(_target, "Blind Transfer"));
-            switch_ivr_session_transfer(peer_session, number.c_str(), "XML", context.c_str());
+            switch_ivr_session_transfer(peer_session, number.c_str(), Opt::_dialplan.c_str(), context.c_str());
         }
         else
         {
@@ -2741,7 +2743,7 @@ bool BoardE1::KhompPvtFXS::transfer(std::string & context, bool blind)
             switch_channel_set_variable(channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE, "true");
             switch_core_event_hook_add_state_change(session(), xferHook);
 
-            switch_ivr_session_transfer(session(), number.c_str(), "XML", context.c_str());
+            switch_ivr_session_transfer(session(), number.c_str(), Opt::_dialplan.c_str(), context.c_str());
 
             DBG(FUNC, PVT_FMT(target(), "Generating ring"));
             call()->_indication = INDICA_RING;
@@ -2819,16 +2821,17 @@ bool BoardE1::KhompPvtFXS::onDtmfDetected(K3L_EVENT *e)
             callFXS()->_incoming_exten += e->AddInfo;
 
             /* begin context adjusting + processing */
-            ContextListType contexts;
+            MatchExtension::ContextListType contexts;
 
             validContexts(contexts);
 
-            std::string tmp_exten("s");
-            std::string tmp_context("default");
+            std::string tmp_exten;
+            std::string tmp_context;
 
-            switch (findExtension(tmp_exten, tmp_context, contexts, callFXS()->_incoming_exten, call()->_orig_addr, false, false))
+            switch (MatchExtension::findExtension(tmp_exten, tmp_context, contexts, callFXS()->_incoming_exten, call()->_orig_addr, false, false))
             {
-                case MATCH_EXACT:
+                case MatchExtension::MATCH_EXACT:
+                    callFXS()->_incoming_exten = tmp_exten;
                     DBG(FUNC,FMT("incoming exten matched: %s") % callFXS()->_incoming_exten);
                     Board::board(_target.device)->_timers.del(callFXS()->_idx_dial);
                     call()->_dest_addr = callFXS()->_incoming_exten;
@@ -2837,7 +2840,7 @@ bool BoardE1::KhompPvtFXS::onDtmfDetected(K3L_EVENT *e)
                     alloc();
                     break;
 
-                case MATCH_MORE:
+                case MatchExtension::MATCH_MORE:
                     DBG(FUNC, PVT_FMT(target(), "match more..."));
 
                     /* can match, will match more, and it's an external call? */
@@ -2851,23 +2854,23 @@ bool BoardE1::KhompPvtFXS::onDtmfDetected(K3L_EVENT *e)
                     }
 
                     break;
-                case MATCH_NONE:
+                case MatchExtension::MATCH_NONE:
                     DBG(FUNC, PVT_FMT(target(), "match none!"));
 
                     std::string invalid = "i";
                     
                     Board::board(_target.device)->_timers.del(callFXS()->_idx_dial);
 
-                    switch (findExtension(tmp_exten, tmp_context, contexts, invalid, call()->_orig_addr, true, false))
+                    switch (MatchExtension::findExtension(tmp_exten, tmp_context, contexts, invalid, call()->_orig_addr, true, false))
                     {
-                        case MATCH_EXACT:
+                        case MatchExtension::MATCH_EXACT:
                             // this dialing is invalid, and we can handle it...
                             call()->_dest_addr = invalid;
                             call()->_incoming_context = tmp_context;
                             alloc();
                             break;
-                        case MATCH_MORE:
-                        case MATCH_NONE:
+                        case MatchExtension::MATCH_MORE:
+                        case MatchExtension::MATCH_NONE:
                             callFXS()->_flags.set(Kflags::FXS_DIAL_FINISHD);
                             startCadence(PLAY_FASTBUSY);
                             break;
@@ -2896,17 +2899,18 @@ bool BoardE1::KhompPvtFXS::onDtmfDetected(K3L_EVENT *e)
             callFXS()->_flash_transfer += e->AddInfo;
     
             /* begin context adjusting + processing */
-            ContextListType contexts;
+            MatchExtension::ContextListType contexts;
 
             validContexts(contexts);
 
-            std::string tmp_exten("s");
-            std::string tmp_context("default");
+            std::string tmp_exten;
+            std::string tmp_context;
             
-            switch (findExtension(tmp_exten, tmp_context, contexts, callFXS()->_flash_transfer, call()->_orig_addr, false, false))
+            switch (MatchExtension::findExtension(tmp_exten, tmp_context, contexts, callFXS()->_flash_transfer, call()->_orig_addr, false, false))
             {
-                case MATCH_EXACT:
+                case MatchExtension::MATCH_EXACT:
                 {
+                    callFXS()->_flash_transfer = tmp_exten;
                     DBG(FUNC,FMT("incoming exten matched: %s") % callFXS()->_flash_transfer);
 
                     if(!transfer(tmp_context))
@@ -2918,7 +2922,7 @@ bool BoardE1::KhompPvtFXS::onDtmfDetected(K3L_EVENT *e)
 
                     break;
                 }
-                case MATCH_MORE:
+                case MatchExtension::MATCH_MORE:
                     DBG(FUNC, PVT_FMT(target(), "match more..."));
 
                     /* can match, will match more, and it's an external call? */
@@ -2932,7 +2936,7 @@ bool BoardE1::KhompPvtFXS::onDtmfDetected(K3L_EVENT *e)
                     }
 
                     break;
-                case MATCH_NONE:
+                case MatchExtension::MATCH_NONE:
                 {
                     DBG(FUNC, PVT_FMT(target(), "match none!"));
 
@@ -3379,7 +3383,8 @@ void BoardE1::KhompPvtFXS::reportFailToReceive(int fail_code)
     }
 }
 
-bool BoardE1::KhompPvtFXS::validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context)
+bool BoardE1::KhompPvtFXS::validContexts(
+        MatchExtension::ContextListType & contexts, std::string extra_context)
 {
     DBG(FUNC,PVT_FMT(_target, "(FXS) c"));
     
@@ -3389,7 +3394,7 @@ bool BoardE1::KhompPvtFXS::validContexts(Board::KhompPvt::ContextListType & cont
     contexts.push_back(Opt::_context_fxs);
     contexts.push_back(Opt::_context2_fxs);
 
-    for (Board::KhompPvt::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++)
+    for (MatchExtension::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++)
     {
         replaceTemplate((*i), "CC", _target.object);
     }
index 01c1610dec8814957e994362df901ff45f52d332..28ccb99cfbe186fed6e45efcbafa5de9b663af29 100644 (file)
 #include "lock.h"
 #include "logger.h"
 
-bool BoardPassive::KhompPvtPassive::validContexts(Board::KhompPvt::ContextListType & contexts, std::string extra_context)
+bool BoardPassive::KhompPvtPassive::validContexts(
+        MatchExtension::ContextListType & contexts, std::string extra_context)
 {
     DBG(FUNC,PVT_FMT(_target,"(Passive) c"));
 
     contexts.push_back(Opt::_context_pr);
 
-    for (Board::KhompPvt::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++)
+    for (MatchExtension::ContextListType::iterator i = contexts.begin(); i != contexts.end(); i++)
     {
         replaceTemplate((*i), "CC", _target.object);
     }
@@ -89,16 +90,16 @@ bool BoardPassive::KhompPvtHI::onSeizureStart(K3L_EVENT *e)
         }
 
         /* begin context adjusting + processing */
-        ContextListType contexts;
+        MatchExtension::ContextListType contexts;
 
         validContexts(contexts);
 
         std::string tmp_exten;
         std::string tmp_context;
 
-        switch (findExtension(tmp_exten, tmp_context, contexts, call()->_dest_addr, call()->_orig_addr, false))
+        switch (MatchExtension::findExtension(tmp_exten, tmp_context, contexts, call()->_dest_addr, call()->_orig_addr, false))
         {
-        case MATCH_NONE:
+        case MatchExtension::MATCH_NONE:
             destroy();
             owner(NULL);
             LOG(WARNING, PVT_FMT(_target, "(HI) r (unable to find exten/context on incoming call %s/%s)")
@@ -111,6 +112,7 @@ bool BoardPassive::KhompPvtHI::onSeizureStart(K3L_EVENT *e)
         }
 
         call()->_incoming_context = tmp_context;
+        _call->_dest_addr = tmp_exten;
 
         startListen();
 
@@ -209,16 +211,16 @@ bool BoardPassive::KhompPvtKPR::onNewCall(K3L_EVENT *e)
         }
 
         /* begin context adjusting + processing */
-        ContextListType contexts;
+        MatchExtension::ContextListType contexts;
 
         validContexts(contexts);
 
         std::string tmp_exten;
         std::string tmp_context;
 
-        switch (findExtension(tmp_exten, tmp_context, contexts, call()->_dest_addr, call()->_orig_addr, false))
+        switch (MatchExtension::findExtension(tmp_exten, tmp_context, contexts, call()->_dest_addr, call()->_orig_addr, false))
         {
-            case MATCH_NONE:
+            case MatchExtension::MATCH_NONE:
                 destroy();
                 owner(NULL);
                 LOG(WARNING, PVT_FMT(_target, "(KPR) r (unable to find exten/context on incoming call %s/%s)")
index 9044e602778adb2b6d8ab4a4807a109b6ae2789c..a0e68563225b949276b6a78d9091a649d543f304 100644 (file)
@@ -236,6 +236,214 @@ const char * answerInfoToString(int answer_info)
 
     return NULL;
 }
+/******************************* Match functions ******************************/
+bool MatchExtension::canMatch(std::string & context, std::string & exten, 
+                              std::string & caller_id, bool match_more)
+{
+    if(!match_more)
+    {
+        return true;
+    }
+
+    size_t finished = exten.find('#');
+
+    if(finished != std::string::npos)
+    {
+        exten.erase(finished);
+        DBG(FUNC, FMT("match exact!!! exten=%s") % exten);
+        return false;
+    }
+
+    return true;
+
+/*
+    switch_xml_t xml = NULL;
+    switch_xml_t xcontext = NULL;
+    switch_regex_t *re;
+    int ovector[30];
+
+    if (switch_xml_locate("dialplan","context","name",context.c_str(),&xml,&xcontext, NULL,SWITCH_FALSE) == SWITCH_STATUS_SUCCESS)
+    {
+        switch_xml_t xexten = NULL;
+
+        if(!(xexten = switch_xml_child(xcontext,"extension")))
+        {
+            DBG(FUNC,"extension cannot match, returning");
+
+            if(xml)
+                switch_xml_free(xml); 
+
+            return false;
+        }
+
+        while(xexten)
+        {
+            switch_xml_t xcond = NULL;
+
+            for (xcond = switch_xml_child(xexten, "condition"); xcond; xcond = xcond->next)
+            {
+                std::string expression;
+
+                if (switch_xml_child(xcond, "condition")) 
+                { 
+                    LOG(ERROR,"Nested conditions are not allowed");
+                }  
+
+                switch_xml_t xexpression = switch_xml_child(xcond, "expression");
+
+                if ((xexpression = switch_xml_child(xcond, "expression"))) 
+                {
+                    expression = switch_str_nil(xexpression->txt);
+                }
+                else 
+                {
+                    expression =  switch_xml_attr_soft(xcond, "expression");
+                }  
+
+                if(expression.empty() || expression == "^(.*)$")
+                {                    
+                    //We're not gonna take it
+                    //No, we ain't gonna take it
+                    // We're not gonna take it anymore
+                    //
+                    continue;
+                }
+
+                int pm = -1; 
+                switch_status_t is_match = SWITCH_STATUS_FALSE;
+                is_match =  switch_regex_match_partial(exten.c_str(),expression.c_str(),&pm);
+
+                if(is_match == SWITCH_STATUS_SUCCESS)
+                {
+                    if(match_more)
+                    {
+                        if(pm == 1)
+                        {
+                            switch_xml_free(xml);
+                            return true;
+                        }
+                    }
+                    else
+                    {
+                        switch_xml_free(xml);
+                        return true;
+                    }
+                }
+                else
+                {
+                    // not match
+                }
+            }            
+
+            xexten = xexten->next;
+        }
+    }
+    else
+    {
+        DBG(FUNC,"context cannot match, returning");
+    }
+
+    if(xml)
+        switch_xml_free(xml); 
+
+    return false;
+*/
+}
+
+
+MatchExtension::MatchType MatchExtension::matchExtension(
+                                        std::string & context, 
+                                        std::string & exten,
+                                        std::string & callerid, 
+                                        bool match_only)
+{
+    if(!canMatch(context,exten,callerid))
+    {
+        DBG(FUNC, "context/extension cannot match");
+        return MATCH_NONE;
+    }
+
+    if(match_only)
+    {
+        DBG(FUNC, "for now we want know if it matches...");
+        return MATCH_MORE;
+    }
+
+    if(!canMatch(context,exten,callerid,true))
+    {
+        DBG(FUNC, "it match exact!");
+        return MATCH_EXACT;
+    }
+
+    return MATCH_MORE;
+}
+
+MatchExtension::MatchType MatchExtension::findExtension(
+                                        std::string & ref_extension,
+                                        std::string & ref_context,
+                                        ContextListType & contexts,
+                                        std::string & extension,
+                                        std::string & caller_id,
+                                        bool default_ctx,
+                                        bool default_ext)
+{
+    ExtenListType extens;
+
+    if(!extension.empty())
+    {
+        extens.push_back(extension);
+    }
+
+    if(default_ext)
+    {
+        if (extension != "s")
+        {
+            extens.push_back("s");
+        }
+
+        extens.push_back("i");
+    }
+
+    if(default_ctx)
+    {
+        contexts.push_back("default");
+    }
+
+    for(ContextListType::iterator itc = contexts.begin(); itc != contexts.end(); itc++)
+    {
+        for(ExtenListType::iterator ite = extens.begin(); ite != extens.end(); ite++)
+        {
+            DBG(FUNC, FMT("trying context '%s' with exten '%s'...") % *itc % *ite);
+            ref_context   = *itc;
+            ref_extension = *ite;
+
+            MatchType m = matchExtension(ref_context, ref_extension, caller_id, false);
+
+            switch (m)
+            {
+                case MATCH_NONE:
+                    continue;
+
+                case MATCH_MORE:
+                case MATCH_EXACT:
+                {
+                    //ref_context = *itc;
+                    //ref_extension = *ite;
+
+                    DBG(FUNC, ".... can match context/extension (some way)!");
+
+                    return m;
+                }
+            }
+        }
+    }
+            
+    ref_context.clear();
+    ref_extension.clear();
+
+    DBG(FUNC, D("... no context/extension found!"));
+    return MATCH_NONE;
+}
 
 /******************************** Kommuter ************************************/
 bool Kommuter::stop()