"Fossies" - the Fresh Open Source Software Archive

Member "bayonne-1.2.16/modules/switch/generic.cpp" (11 Dec 2002, 2661 Bytes) of package /linux/misc/old/bayonne-1.2.16.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "generic.cpp" see the Fossies "Dox" file reference documentation.

    1 // Copyright (C) 2000 Open Source Telecom Corporation.
    2 //
    3 // This program is free software; you can redistribute it and/or modify
    4 // it under the terms of the GNU General Public License as published by
    5 // the Free Software Foundation; either version 2 of the License, or
    6 // (at your option) any later version.
    7 //
    8 // This program is distributed in the hope that it will be useful,
    9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
   10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11 // GNU General Public License for more details.
   12 //
   13 // You should have received a copy of the GNU General Public License
   14 // along with this program; if not, write to the Free Software
   15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   16 //
   17 // The generic switch integration module supports setting and clearing of
   18 // message waiting status by dialing extension numbers directly through 
   19 // the bayonne server.  Many PBX's have the ability to set and clear mwi
   20 // status by such dialing codes.  A mwi.mod PBX integration script is also
   21 // used with entries for common pbx vendors.
   22 
   23 #include <server.h>
   24 #include <cc++/serial.h>
   25 
   26 #ifdef  CCXX_NAMESPACES
   27 namespace ost {
   28 using namespace std;
   29 #endif
   30 
   31 class MWI : public Module, public Keydata
   32 {
   33 public:
   34     MWI();
   35 
   36 private:
   37     modtype_t getType(void)
   38         {return MODULE_SWITCH;};
   39 
   40     char *getName(void)
   41         {return "mwi";};
   42 
   43     char *dispatch(Trunk *trunk);
   44 
   45 } mwi;
   46 
   47 MWI::MWI() : Module(), Keydata("/bayonne/switch")
   48 {
   49     static Keydata::Define keys[] = {
   50         {"protocol", "none"},
   51         {"group", "*"},
   52         {"timeout", "30s"},
   53         {NULL, NULL}};
   54 
   55     load(keys);
   56     driver->addModule(this);
   57 }
   58 
   59 char* MWI::dispatch(Trunk *trunk)
   60 {
   61     TrunkGroup *grp = getGroup(getLast("group"));
   62     const char *mem = trunk->getMember();
   63     const char *swi = getLast("protocol");
   64     const char *value;
   65     char *argv[8];
   66     char name[65];
   67     char extensions[256];
   68     int len = 0;
   69 
   70     if(!stricmp(swi, "none"))
   71         return NULL;
   72 
   73     if(!grp)
   74         return "mwi-invalid-group";
   75 
   76     if(!mem)
   77         mem = "mwi.mode=on";
   78     else
   79         mem = "mwi.mode=off";
   80 
   81     extensions[0] = 0;
   82     snprintf(name, sizeof(name), "mwi::%s", swi);
   83 
   84     while(NULL != (value = trunk->getValue(NULL)))
   85     {
   86         if(!len)
   87         {
   88             sprintf(extensions, "mwi.extensions=%s", value);
   89             len = strlen(extensions);
   90             continue;
   91         }
   92         extensions[len++] = ',';
   93         if(len + strlen(value) >= sizeof(extensions))
   94             break;
   95         strcpy(extensions + len, value);
   96         len += strlen(value);
   97     }
   98     if(!extensions[0])
   99         return NULL;
  100 
  101     argv[0] = name;
  102     argv[1] = extensions;
  103     argv[2] = (char *)mem;
  104     argv[3] = NULL;
  105 
  106     request(grp, argv, getSecTimeout(getLast("timeout")), "mwi");   
  107     
  108     return NULL;            
  109 }
  110 
  111 #ifdef  CCXX_NAMESPACES
  112 };
  113 #endif