1 /******************************************************************************* 2 3 KHOMP generic endpoint/channel library. 4 Copyright (C) 2007-2010 Khomp Ind. & Com. 5 6 The contents of this file are subject to the Mozilla Public License 7 Version 1.1 (the "License"); you may not use this file except in compliance 8 with the License. You may obtain a copy of the License at 9 http://www.mozilla.org/MPL/ 10 11 Software distributed under the License is distributed on an "AS IS" basis, 12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 13 the specific language governing rights and limitations under the License. 14 15 Alternatively, the contents of this file may be used under the terms of the 16 "GNU Lesser General Public License 2.1" license (the “LGPL" License), in which 17 case the provisions of "LGPL License" are applicable instead of those above. 18 19 If you wish to allow use of your version of this file only under the terms of 20 the LGPL License and not to allow others to use your version of this file 21 under the MPL, indicate your decision by deleting the provisions above and 22 replace them with the notice and other provisions required by the LGPL 23 License. If you do not delete the provisions above, a recipient may use your 24 version of this file under either the MPL or the LGPL License. 25 26 The LGPL header follows below: 27 28 This library is free software; you can redistribute it and/or 29 modify it under the terms of the GNU Lesser General Public 30 License as published by the Free Software Foundation; either 31 version 2.1 of the License, or (at your option) any later version. 32 33 This library is distributed in the hope that it will be useful, 34 but WITHOUT ANY WARRANTY; without even the implied warranty of 35 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 36 Lesser General Public License for more details. 37 38 You should have received a copy of the GNU Lesser General Public License 39 along with this library; if not, write to the Free Software Foundation, 40 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 41 42 *******************************************************************************/ 43 44 #ifndef _CLI_H_ 45 #define _CLI_H_ 46 47 #include "globals.h" 48 #include "logger.h" 49 50 struct Command 51 { 52 /* print in client the usage */ printUsageCommand53 void printUsage(switch_stream_handle_t *stream) 54 { 55 if(stream) 56 { 57 printBrief(stream); 58 K::Logger::Logg2(C_CLI,stream, 59 "------------------------------ Description --------------------------------"); 60 K::Logger::Logg2(C_CLI,stream, 61 "---------------------------------------------------------------------------"); 62 K::Logger::Logg2(C_CLI,stream,(char*) usage.c_str()); 63 K::Logger::Logg2(C_CLI,stream, 64 "---------------------------------------------------------------------------"); 65 } 66 else 67 { 68 LOG(ERROR,FMT("Invalid stream for commmand: %s") % complete_name); 69 } 70 } 71 72 /* print in client the brief */ printBriefCommand73 void printBrief(switch_stream_handle_t *stream) 74 { 75 if(stream) 76 { 77 K::Logger::Logg2(C_CLI,stream, 78 "---------------------------------------------------------------------------"); 79 K::Logger::Logg2(C_CLI,stream, 80 "-------------------------------- Brief ------------------------------------"); 81 K::Logger::Logg2(C_CLI,stream, 82 "---------------------------------------------------------------------------"); 83 K::Logger::Logg2(C_CLI,stream,(char*) brief.c_str()); 84 K::Logger::Logg2(C_CLI,stream, 85 "---------------------------------------------------------------------------"); 86 } 87 else 88 { 89 LOG(ERROR,FMT("Invalid stream for commmand: %s") % complete_name); 90 } 91 } 92 93 /* pure virtual */ 94 virtual bool execute(int argc, char *argv[]) = 0; 95 96 std::string complete_name; /* specify the command in console */ 97 std::vector<std::string> options; /* extra options for command */ 98 std::string brief; /* brief of the command, a path */ 99 std::string usage; /* usage of the command, a help */ 100 }; 101 102 struct CommandXMLOutput : public Command 103 { createRootCommandXMLOutput104 void createRoot(const char *name) 105 { 106 root = switch_xml_new(name); 107 } 108 insertXMLCommandXMLOutput109 void insertXML(switch_xml_t xml) 110 { 111 switch_xml_insert(xml,root,0); 112 } 113 clearRootCommandXMLOutput114 void clearRoot() 115 { 116 if(root) 117 { 118 switch_xml_free(root); 119 root = NULL; 120 } 121 } 122 printXMLOutputCommandXMLOutput123 void printXMLOutput(switch_stream_handle_t *stream) 124 { 125 K::Logger::Logg2(C_CLI,stream,switch_xml_toxml(root,SWITCH_FALSE)); 126 } 127 CommandXMLOutputCommandXMLOutput128 CommandXMLOutput() : root(NULL) {}; 129 130 switch_xml_t root; /* for commands that ouput as xml */ 131 }; 132 133 struct Cli 134 { 135 /* Useful definitions --------------------------------------------------- */ 136 typedef switch_status_t (APIFunc)(const char*, switch_core_session_t*, switch_stream_handle_t*); 137 typedef std::vector<Command*> Commands; 138 139 /* Define the output types form commands */ 140 typedef enum 141 { 142 VERBOSE = 1, 143 CONCISE, 144 DETAILED, 145 XML 146 } OutputType; 147 148 /* register our commands, but you must create the command function */ 149 static void registerCommands(APIFunc func,switch_loadable_module_interface_t **mod_int); 150 151 /* delete the commands */ unregisterCommandsCli152 static void unregisterCommands() 153 { 154 switch_console_set_complete("del khomp"); 155 } 156 157 /* stream is very useful */ setStreamCli158 static void setStream(switch_stream_handle_t *s) 159 { 160 if(!s) 161 { 162 LOG(ERROR,"Invalid stream passed"); 163 return; 164 } 165 166 stream = s; 167 } 168 169 /* gets the khomp usage */ printKhompUsageCli170 static void printKhompUsage() 171 { 172 if(stream) 173 { 174 K::Logger::Logg2(C_CLI,stream,(char*) _khomp_usage.c_str()); 175 } 176 else 177 { 178 LOG(ERROR,"Invalid stream for command: printKhompUsage"); 179 } 180 } 181 182 /* is responsible for parse and execute all commands */ 183 static bool parseCommands(int argc, char *argv[]); 184 185 /* The Commands --------------------------------------------------------- */ 186 187 /* khomp summary */ 188 static struct _KhompSummary : public CommandXMLOutput 189 { 190 _KhompSummary(bool on_cli_term = true): CommandXMLOutputCli::_KhompSummary191 CommandXMLOutput(), 192 _on_cli_term(on_cli_term), 193 xdevs(NULL) 194 { 195 complete_name = "summary"; 196 197 options.push_back("verbose"); 198 options.push_back("concise"); 199 options.push_back("xml"); 200 201 brief = "Print system info."; 202 usage = \ 203 "Prints detailed info about the system like API version and \n" \ 204 "boards characteristics like DSPs version.\n\n" \ 205 "Usage: khomp summary [concise|verbose|xml]"; 206 207 _commands.push_back(this); 208 }; 209 210 bool execute(int argc, char *argv[]); 211 bool _on_cli_term; /* indicates if message is sent to fs_cli */ 212 switch_xml_t xdevs; /* support xml needed to help the interation */ 213 } KhompSummary; 214 215 /* khomp show calls */ 216 static struct _KhompShowCalls : public Command 217 { _KhompShowCallsCli::_KhompShowCalls218 _KhompShowCalls() 219 { 220 complete_name = "show calls"; 221 brief = \ 222 "Show each Khomp channel which have more than one call state associated."; 223 224 usage = \ 225 "Show each Khomp channel which have more than one call state associated.\n\n" \ 226 "Usage: khomp show calls [<board> [<channel>]]"; 227 228 _commands.push_back(this); 229 }; 230 231 bool execute(int argc, char *argv[]); 232 233 /* support function for _KhompShowCalls */ 234 void showCalls(unsigned int device, unsigned int object, std::string &buffer); 235 } KhompShowCalls; 236 237 /* khomp channels disconnect */ 238 static struct _KhompChannelsDisconnect : public Command 239 { _KhompChannelsDisconnectCli::_KhompChannelsDisconnect240 _KhompChannelsDisconnect() 241 { 242 complete_name = "channels disconnect"; 243 brief = "Disconnect a(ll) channel(s)."; 244 usage = \ 245 "Disconnects channels in boards, or specific board/channel if parameter \n" \ 246 "is supplied.\n\n" \ 247 "Usage: khomp channels disconnect {all | <board> all | <board> <channel>}\n" \ 248 "\tboard -- Number of the board (start from 0).\n" \ 249 "\tchannel -- Number of the channel (start from 0).\n" \ 250 "e.g. khomp channels disconnect all - Disconnect all channels of all boards.\n"\ 251 "e.g. khomp channels disconnect 0 5 - Disconnect channel 5 of board 0."; 252 _commands.push_back(this); 253 }; 254 255 bool execute(int argc, char *argv[]); 256 257 /* support function for _KhompChannelsDisconnect */ 258 bool forceDisconnect(unsigned int device, unsigned int channel); 259 } KhompChannelsDisconnect; 260 261 /* khomp channels unblock */ 262 static struct _KhompChannelsUnblock : public Command 263 { _KhompChannelsUnblockCli::_KhompChannelsUnblock264 _KhompChannelsUnblock() 265 { 266 complete_name = "channels unblock"; 267 brief = "Unblock a(ll) channel(s)."; 268 269 usage = \ 270 "The board will request to the PBX or network where it is connected to \n" \ 271 "unblock the channel if its blocked.\n\n" \ 272 "Usage: khomp channels unblock {all | <board> all | <board> <channel>}\n" \ 273 "\tboard -- Number of the board (start from 0).\n" \ 274 "\tchannel -- Number of the channel (start from 0).\n" \ 275 "e.g. khomp channels unblock all - Unblock all channels of all boards.\n" \ 276 "e.g. khomp channels unblock 0 all - Unblock all channels of board 0.\n" \ 277 "e.g. khomp channels unblock 1 20 - Unblock channel 20 of board 1."; 278 279 _commands.push_back(this); 280 }; 281 282 bool execute(int argc, char *argv[]); 283 } KhompChannelsUnblock; 284 285 /* khomp show statistics */ 286 static struct _KhompShowStatistics : public CommandXMLOutput 287 { _KhompShowStatisticsCli::_KhompShowStatistics288 _KhompShowStatistics() : CommandXMLOutput(), xdevs(NULL) 289 { 290 complete_name = "show statistics"; 291 292 options.push_back("verbose"); 293 options.push_back("detailed"); 294 options.push_back("xml"); 295 296 brief = "Shows statistics of the channels."; 297 298 usage = \ 299 "Shows statistics of the channels, like number of calls incoming \n" \ 300 "and outgoing, status, status time.\n\n" \ 301 "Usage: khomp show statistics [{{verbose|xml} [<board> [<channel>]]} | \n" \ 302 " {detailed <board> <channel>}]\n" \ 303 "\tboard -- Number of the board (start from 0).\n" \ 304 "\tchannel -- Number of the channel (start from 0).\n" \ 305 "e.g. khomp channels statistics - Shows general statistics \n" \ 306 " of all boards.\n" \ 307 "e.g. khomp channels statistics 0 - Shows general statistics \n" \ 308 " of board 0.\n" \ 309 "e.g. khomp channels statistics verbose - Shows general statistics \n" \ 310 " of all boards.\n" \ 311 "e.g. khomp channels statistics verbose 0 - Shows general statistics \n" \ 312 " of board 0.\n" \ 313 "e.g. khomp channels statistics detailed 0 2 - Shows detailed statistics \n" \ 314 " of channel 2 on board 0."; 315 316 _commands.push_back(this); 317 }; 318 319 bool execute(int argc, char *argv[]); 320 321 /* support functions */ 322 void cliStatistics(unsigned int device, OutputType output_type); 323 void cliDetailedStatistics(unsigned int device, unsigned int channel, OutputType output_type); 324 switch_xml_t xdevs; /* support xml needed to help the interation */ 325 326 } KhompShowStatistics; 327 328 /* khomp show channels */ 329 static struct _KhompShowChannels: public CommandXMLOutput 330 { _KhompShowChannelsCli::_KhompShowChannels331 _KhompShowChannels() : CommandXMLOutput(), xdev(NULL) 332 { 333 complete_name = "show channels"; 334 335 options.push_back("verbose"); 336 options.push_back("concise"); 337 options.push_back("xml"); 338 339 brief = "Show all channels status."; 340 usage = \ 341 "List the status of each channel, both on asterisk point of view and on \n" \ 342 "khomp API point of view.\n\n" \ 343 "Usage: \n" \ 344 "khomp show channels [{<board> [<channel>]} | \n" \ 345 "{{concise|verbose|xml} [<board> [<channel>]]}]\n" \ 346 "\tboard -- Number of the board (start from 0).\n" \ 347 "e.g. khomp show channels - List status of all channels of all boards.\n" \ 348 "e.g. khomp show channels concise 0 - List status of all channels of \n" \ 349 " board 0 in a concise way.\n" \ 350 "e.g. khomp show channels xml 0 - List status of all channels of \n" \ 351 " board 0 in a xml structure."; 352 353 _commands.push_back(this); 354 }; 355 356 /* support function for _KhompShowChannels */ 357 void showChannel(unsigned int device, unsigned int channel, OutputType output_type = Cli::VERBOSE); 358 void showChannels(unsigned int device, OutputType output_type = Cli::VERBOSE); 359 360 bool execute(int argc, char *argv[]); 361 switch_xml_t xdev; /* support xml needed to help the interation */ 362 363 } KhompShowChannels; 364 365 /* khomp show links */ 366 static struct _KhompShowLinks: public CommandXMLOutput 367 { _KhompShowLinksCli::_KhompShowLinks368 _KhompShowLinks() : CommandXMLOutput(), xdev(NULL) 369 { 370 complete_name = "show links"; 371 372 options.push_back("verbose"); 373 options.push_back("concise"); 374 options.push_back("xml"); 375 options.push_back("errors"); 376 options.push_back("errors verbose"); 377 options.push_back("errors concise"); 378 options.push_back("errors xml"); 379 380 brief = "Show E1 link(s) status/errors counters in a concise \n" \ 381 "way or not."; 382 383 usage = \ 384 "Prints information about the signaling, syncronization and general \n" \ 385 "status/the error counters of each link on the board. It prints in \n" \ 386 "a concise way for parsing facilities.\n\n" \ 387 "Usage: \n" \ 388 "khomp show links [[errors] [{<board>} | {{concise|verbose|xml} [<board>]}]]\n"\ 389 "e.g. khomp show links - Show all links of all boards.\n" \ 390 "e.g. khomp show links xml - Show all links of all boards in xml.\n" \ 391 "e.g. khomp show links errors - Show error counters of all links of \n" \ 392 " all boards.\n" \ 393 "e.g. khomp show links errors 0 - Show error counters of all links of \n" \ 394 " board 0."; 395 396 _commands.push_back(this); 397 }; 398 399 /* support function for _KhompShowLinks */ 400 void showLinks(unsigned int device, OutputType output_type = Cli::VERBOSE); 401 void showErrors(unsigned int device, OutputType output_type = Cli::VERBOSE); 402 std::string getLinkStatus(int dev, int obj, Verbose::Presentation fmt); 403 404 bool execute(int argc, char *argv[]); 405 switch_xml_t xdev; /* support xml needed to help the interation */ 406 } KhompShowLinks; 407 408 /* khomp clear links */ 409 static struct _KhompClearLinks: public Command 410 { _KhompClearLinksCli::_KhompClearLinks411 _KhompClearLinks() 412 { 413 complete_name = "clear links"; 414 415 brief = "Clear the error counters of the links."; 416 417 usage = \ 418 "Clear the error counters of the links.\n\n" \ 419 "Usage: khomp clear links [<board> [<link>]]\n" \ 420 "\tboard -- Number of the board (start from 0).\n" \ 421 "\tlink -- Number of the link (start from 0).\n" \ 422 "e.g. khomp clear links 0 -- Clear error counters of all links of board 0."; 423 424 _commands.push_back(this); 425 }; 426 427 /* support function for _KhompClearLinks */ 428 void clearLink(unsigned int device, unsigned int link); 429 430 bool execute(int argc, char *argv[]); 431 } KhompClearLinks; 432 433 /* khomp clear statistics */ 434 static struct _KhompClearStatistics: public Command 435 { _KhompClearStatisticsCli::_KhompClearStatistics436 _KhompClearStatistics() 437 { 438 complete_name = "clear statistics"; 439 440 brief = "Clear statistics of the channels."; 441 442 usage = \ 443 "Clear statistics of the channels, like number of calls incoming \n" \ 444 "and outgoing, status, status time.\n\n" \ 445 "Usage: khomp clear statistics [<board> [<channel>]]\n" \ 446 "\tboard -- Number of the board (start from 0).\n" \ 447 "\tchannel -- Number of the channel (start from 0).\n" \ 448 "e.g. khomp clear statistics 0 -- Clear statistics of board 0."; 449 _commands.push_back(this); 450 }; 451 452 bool execute(int argc, char *argv[]); 453 } KhompClearStatistics; 454 455 456 /* khomp reset links */ 457 static struct _KhompResetLinks: public Command 458 { _KhompResetLinksCli::_KhompResetLinks459 _KhompResetLinks() 460 { 461 complete_name = "reset links"; 462 463 brief = "Reset the specified link."; 464 465 usage = \ 466 "Reset the specified link.\n\n" \ 467 "Usage: khomp reset links [<board> [<link>]]\n" \ 468 "\tboard -- Number of the board (start from 0).\n" \ 469 "\tlink -- Number of the link (start from 0).\n" \ 470 "e.g. khomp reset links 0 1 -- Reset link 1 of board 0."; 471 472 _commands.push_back(this); 473 }; 474 475 /* support function for _KhompResetLinks */ 476 void resetLink(unsigned int device, unsigned int link); 477 478 bool execute(int argc, char *argv[]); 479 } KhompResetLinks; 480 481 /* khomp sms */ 482 static struct _KhompSMS : public Command 483 { _KhompSMSCli::_KhompSMS484 _KhompSMS() 485 { 486 complete_name = "sms"; 487 brief = "Send an SMS message using a Khomp KGSM board."; 488 489 usage = \ 490 "Send an SMS message using a Khomp KGSM board.\n\n" \ 491 "Usage: khomp sms <device> <destination> <message..>\n" \ 492 "\tdevice -- Device to use (same string used in Dial for \n" \ 493 "\t channel allocation).\n" \ 494 "\tdestination -- Phone number of the destination.\n" \ 495 "\tmessage -- Message to send.\n" \ 496 "e.g. khomp sms b0 99887766 Oi, tudo bem?"; 497 498 _commands.push_back(this); 499 }; 500 501 bool execute(int argc, char *argv[]); 502 } KhompSMS; 503 504 /* khomp log console */ 505 static struct _KhompLogConsole : public Command 506 { _KhompLogConsoleCli::_KhompLogConsole507 _KhompLogConsole() 508 { 509 complete_name = "log console"; 510 511 options.push_back("errors"); 512 options.push_back("warnings"); 513 options.push_back("messages"); 514 options.push_back("events"); 515 options.push_back("commands"); 516 options.push_back("audio"); 517 options.push_back("modem"); 518 options.push_back("link"); 519 options.push_back("cas"); 520 options.push_back("standard"); 521 options.push_back("all"); 522 options.push_back("no"); 523 options.push_back("just"); 524 525 brief = "Enables/disables showing console messages for the channel."; 526 usage = \ 527 "Enables/disables showing channel messages, where <options> can be:\n" \ 528 "\terrors -- Error messages, when something goes really \n" \ 529 "\t wrong. Enabled by default.\n" \ 530 "\twarnings -- Warnings, used when something might not be \n" \ 531 "\t going as expected. Enabled by default.\n" \ 532 "\tmessages -- Generic messages, used to indicate some \n" \ 533 "\t information. Enabled by default.\n" \ 534 "\tevents -- Show received K3L events as console \n" \ 535 "\t messages. Disabled by default.\n" \ 536 "\tcommands -- Show sent K3L commands as console \n" \ 537 "\t messages. Disabled by default.\n" \ 538 "\taudio -- Enable messages for K3L audio events. \n" \ 539 "\t Disabled by default (very verbose!).\n" \ 540 "\tmodem -- Enable messages for data received from \n" \ 541 "\t KGSM modems. Disabled by default.\n" \ 542 "\tlink -- Enable logging of link status changes. \n" \ 543 "\t Enabled by default.\n" \ 544 "\tcas -- Enable logging of MFCs and line state \n" \ 545 "\t changes in KPR board. Disabled by default.\n" \ 546 "\tstandard -- Special identifier, enable default \n" \ 547 "\t console messages.\n" \ 548 "\tall -- Special identifier, enable ALL console \n" \ 549 "\t messages (should not be used naively).\n\n" \ 550 "Usage: khomp log console <options>\n" \ 551 "e.g. khomp log console standard"; 552 553 _commands.push_back(this); 554 } 555 556 bool execute(int argc, char *argv[]); 557 } KhompLogConsole; 558 559 /* khomp log disk */ 560 static struct _KhompLogDisk : public Command 561 { _KhompLogDiskCli::_KhompLogDisk562 _KhompLogDisk() 563 { 564 complete_name = "log disk"; 565 566 options.push_back("errors"); 567 options.push_back("warnings"); 568 options.push_back("messages"); 569 options.push_back("events"); 570 options.push_back("commands"); 571 options.push_back("audio"); 572 options.push_back("modem"); 573 options.push_back("link"); 574 options.push_back("cas"); 575 options.push_back("functions"); 576 options.push_back("threads"); 577 options.push_back("locks"); 578 options.push_back("streams"); 579 options.push_back("standard"); 580 options.push_back("debugging"); 581 options.push_back("all"); 582 options.push_back("no"); 583 options.push_back("just"); 584 585 brief = "Enables/disables logging to file messages for the channel."; 586 usage = \ 587 "Enables/disables the logging of channel messages to disk, where <options> \n" \ 588 "can be:\n" \ 589 "\terrors -- Error messages, when something goes really \n" \ 590 "\t wrong. Enabled by default.\n" \ 591 "\twarnings -- Warnings, used when something might not be \n" \ 592 "\t going as expected. Enabled by default.\n" \ 593 "\tmessages -- Generic messages, used to indicate some \n" \ 594 "\t information. Enabled by default.\n" \ 595 "\tevents -- Record received K3L events as log messages. \n" \ 596 "\t Disabled by default.\n" \ 597 "\tcommands -- Record sent K3L commands as log messages. \n" \ 598 "\t Disabled by default.\n" \ 599 "\taudio -- Enable messages for K3L audio events. \n" \ 600 "\t Disabled by default (very verbose!).\n" \ 601 "\tmodem -- Enable messages for data received from \n" \ 602 "\t KGSM modems. Disabled by default.\n" \ 603 "\tlink -- Enable logging of link status changes. \n" \ 604 "\t Enabled by default.\n" \ 605 "\tcas -- Enable logging of MFCs and line state \n" \ 606 "\t changes in KPR board. Disabled by default.\n" \ 607 "\tfunctions -- Enable debugging for functions. Disabled \n" \ 608 "\t by default (should not be used naively!).\n" \ 609 "\tthreads -- Enable debugging for threads. Disabled by \n" \ 610 "\t default (should not be used naively!).\n" \ 611 "\tlocks -- Enable debugging for locks. Disabled by \n" \ 612 "\t default (should not be used naively!).\n" \ 613 "\tstreams -- Enable debugging for streams. Disabled by \n" \ 614 "\t default (should not be used naively!).\n" \ 615 "\tstandard -- Special identifier, enable default messages.\n" \ 616 "\tdebugging -- Special identifier, enable debugging messages \n" \ 617 "\t (should not be used naively).\n" \ 618 "\tall -- Special identifier, enable ALL disk \n" \ 619 "\t messages (DO NOT USE THIS!).\n\n" \ 620 "Usage: khomp log disk <options>\n" \ 621 "e.g. khomp log disk <options>"; 622 623 _commands.push_back(this); 624 } 625 626 bool execute(int argc, char *argv[]); 627 } KhompLogDisk; 628 629 /* khomp log trace k3l */ 630 static struct _KhompLogTraceK3L : public Command 631 { _KhompLogTraceK3LCli::_KhompLogTraceK3L632 _KhompLogTraceK3L() 633 { 634 complete_name = "log trace k3l"; 635 636 options.push_back("on"); 637 options.push_back("off"); 638 639 brief = "Set K3L tracing (debug) option."; 640 641 usage = \ 642 "Sets the low-level log for K3L API. Should not be set for long time \n" \ 643 "periods.\n\n" \ 644 "Usage: khomp log trace k3l {on|off}\n" \ 645 "e.g. khomp log trace k3l on"; 646 647 _commands.push_back(this); 648 } 649 650 bool execute(int argc, char *argv[]); 651 } KhompLogTraceK3L; 652 653 /* khomp log trace ISDN */ 654 static struct _KhompLogTraceISDN : public Command 655 { _KhompLogTraceISDNCli::_KhompLogTraceISDN656 _KhompLogTraceISDN() 657 { 658 complete_name = "log trace isdn"; 659 660 options.push_back("q931"); 661 options.push_back("lapd"); 662 options.push_back("system"); 663 options.push_back("off"); 664 665 brief = "Set ISDN signaling trace."; 666 667 usage = \ 668 "Sets the low-level log for ISDN signalling. Should not be set for \n" \ 669 "long time periods.\n\n" \ 670 "Usage: khomp log trace isdn <what>[,<what2>[,..]]\n" \ 671 "\twhat -- \"q931\", \"lapd\", \"system\" or \"off\" \n" \ 672 "\t (comma-separated values).\n" \ 673 "e.g. khomp log trace isdn q931,system"; 674 675 _commands.push_back(this); 676 } 677 678 bool execute(int argc, char *argv[]); 679 } KhompLogTraceISDN; 680 681 /* khomp log trace R2 */ 682 static struct _KhompLogTraceR2 : public Command 683 { _KhompLogTraceR2Cli::_KhompLogTraceR2684 _KhompLogTraceR2() 685 { 686 complete_name = "log trace r2"; 687 688 options.push_back("on"); 689 options.push_back("off"); 690 691 brief = "Set R2 signaling trace."; 692 693 usage = \ 694 "Sets the low-level log monitor for R2 digital signalling. Should not \n" \ 695 "be set for long time periods.\n\n" \ 696 "Usage: khomp log trace r2 {on|off}\n" \ 697 "e.g. khomp log trace r2 on"; 698 699 _commands.push_back(this); 700 } 701 702 bool execute(int argc, char *argv[]); 703 } KhompLogTraceR2; 704 705 /* khomp get */ 706 static struct _KhompGet : public Command 707 { _KhompGetCli::_KhompGet708 _KhompGet() 709 { 710 complete_name = "get"; 711 712 options.push_back("dialplan"); 713 options.push_back("echo-canceller"); 714 options.push_back("auto-gain-control"); 715 options.push_back("out-of-band-dtmfs"); 716 options.push_back("suppression-delay"); 717 options.push_back("auto-fax-adjustment"); 718 options.push_back("fax-adjustment-timeout"); 719 options.push_back("pulse-forwarding"); 720 options.push_back("r2-strict-behaviour"); 721 options.push_back("r2-preconnect-wait"); 722 options.push_back("context-digital"); 723 options.push_back("context-fxs"); 724 options.push_back("context-fxo"); 725 options.push_back("context-gsm-call"); 726 options.push_back("context-gsm-sms"); 727 options.push_back("context-pr"); 728 options.push_back("log-to-console"); 729 options.push_back("log-to-disk"); 730 options.push_back("trace"); 731 options.push_back("output-volume"); 732 options.push_back("input-volume"); 733 options.push_back("fxs-global-orig"); 734 options.push_back("fxs-co-dialtone"); 735 options.push_back("fxs-bina"); 736 options.push_back("fxs-sharp-dial"); 737 options.push_back("disconnect-delay"); 738 options.push_back("delay-ringback-co"); 739 options.push_back("delay-ringback-pbx"); 740 options.push_back("ignore-letter-dtmfs"); 741 options.push_back("fxo-send-pre-audio"); 742 options.push_back("fxo-busy-disconnection"); 743 options.push_back("fxs-digit-timeout"); 744 options.push_back("drop-collect-call"); 745 options.push_back("kommuter-activation"); 746 options.push_back("kommuter-timeout"); 747 options.push_back("user-transfer-digits"); 748 options.push_back("flash-to-digits"); 749 options.push_back("accountcode"); 750 options.push_back("audio-packet-length"); 751 752 brief = "Get configuration options in the Khomp channel."; 753 754 usage = \ 755 "Usage: khomp get <option>\n" \ 756 "<option> -- Shown below, with a short description each.\n\n" \ 757 "Option Description\n" \ 758 "dialplan Gets the Name of the dialplan module in use.\n" \ 759 "echo-canceller Gets the echo cancellation procedures if they are \n" \ 760 " avaliable.\n" \ 761 "auto-gain-control Gets the AGC procedures if they are avaliable.\n" \ 762 "out-of-band-dtmfs Gets DTMFs to be sent out-of-band (using ast_frames) \n" \ 763 " instead of in-band (audio).\n" \ 764 "suppression-delay Enable/disable the internal buffer for DTMF \n" \ 765 " suppression.\n" \ 766 "auto-fax-adjustment Gets the automatic adjustment for FAX (mainly, \n" \ 767 " disables the echo canceller).\n" \ 768 //"fax-adjustment-timeout" 769 "pulse-forwarding Gets the forwarding of detected pulses as DTMF tones.\n" \ 770 "r2-strict-behaviour Gets the R2 protocol behavior while answering lines.\n" \ 771 "r2-preconnect-wait Gets the R2 protocol delay to pre-connect after \n" \ 772 " sending ringback signal.\n" \ 773 "context-digital Context (may be a template) for receiving digital \n" \ 774 " (E1) calls.\n" \ 775 "context-fxs Context (may be a template) for receiving FXS calls.\n" \ 776 "context-fxo Context (may be a template) for receiving FXO calls.\n" \ 777 "context-gsm-call Context (may be a template) for receiving GSM calls.\n" \ 778 "context-gsm-sms Context (may be a template) for receiving GSM \n" \ 779 " messages.\n" \ 780 "context-pr Context (may be a template) for receiving calls on \n" \ 781 " Passive Record boards.\n" \ 782 "log-to-console Gets the logging of messages to console.\n" \ 783 "log-to-disk Gets the logging of messages to disk.\n" \ 784 "trace Gets the low level tracing.\n" \ 785 "output-volume Gets the volume multiplier to be applied by the \n" \ 786 " board over the output audio.\n" \ 787 "input-volume Gets the volume multiplier to be applied by the \n" \ 788 " board over the input audio.\n\n" \ 789 "FOR ALL COMMANDS, CHECK THE DOCUMENTATION."; 790 791 _commands.push_back(this); 792 }; 793 794 bool execute(int argc, char *argv[]); 795 } KhompGet; 796 797 /* khomp set */ 798 static struct _KhompSet : public Command 799 { _KhompSetCli::_KhompSet800 _KhompSet() 801 { 802 complete_name = "set"; 803 804 options.push_back("dialplan"); 805 options.push_back("echo-canceller"); 806 options.push_back("auto-gain-control"); 807 options.push_back("out-of-band-dtmfs"); 808 options.push_back("suppression-delay"); 809 options.push_back("auto-fax-adjustment"); 810 options.push_back("fax-adjustment-timeout"); 811 options.push_back("pulse-forwarding"); 812 options.push_back("r2-strict-behaviour"); 813 options.push_back("r2-preconnect-wait"); 814 options.push_back("context-digital"); 815 options.push_back("context-fxs"); 816 options.push_back("context-fxo"); 817 options.push_back("context-gsm-call"); 818 options.push_back("context-gsm-sms"); 819 options.push_back("context-pr"); 820 options.push_back("log-to-console"); 821 options.push_back("log-to-disk"); 822 options.push_back("trace"); 823 options.push_back("output-volume"); 824 options.push_back("input-volume"); 825 options.push_back("fxs-global-orig"); 826 options.push_back("fxs-co-dialtone"); 827 options.push_back("fxs-bina"); 828 options.push_back("fxs-sharp-dial"); 829 options.push_back("disconnect-delay"); 830 options.push_back("delay-ringback-co"); 831 options.push_back("delay-ringback-pbx"); 832 options.push_back("ignore-letter-dtmfs"); 833 options.push_back("fxo-send-pre-audio"); 834 options.push_back("fxo-busy-disconnection"); 835 options.push_back("fxs-digit-timeout"); 836 options.push_back("drop-collect-call"); 837 options.push_back("kommuter-activation"); 838 options.push_back("kommuter-timeout"); 839 options.push_back("user-transfer-digits"); 840 options.push_back("flash-to-digits"); 841 options.push_back("accountcode"); 842 options.push_back("audio-packet-length"); 843 844 brief = "Ajust configuration options in the Khomp channel."; 845 846 usage = \ 847 "Usage: khomp set <option> <value>\n" \ 848 "\t<option> -- Shown below, with a short description each.\n" \ 849 "\t<value> -- Depends on the option. Check the documentation for \n" \ 850 "\t more info.\n\n" \ 851 "Option Description\n" \ 852 "dialplan Sets the Name of the dialplan module in use.\n" \ 853 "echo-canceller Sets the echo cancellation procedures if they are \n" \ 854 " avaliable.\n" \ 855 "auto-gain-control Sets the AGC procedures if they are avaliable.\n" \ 856 "out-of-band-dtmfs Sets DTMFs to be sent out-of-band (using ast_frames) \n" \ 857 " instead of in-band (audio).\n" \ 858 "suppression-delay Enable/disable the internal buffer for DTMF \n" \ 859 " suppression.\n" \ 860 "auto-fax-adjustment Sets the automatic adjustment for FAX (mainly, \n" \ 861 " disables the echo canceller).\n" \ 862 "pulse-forwarding Sets the forwarding of detected pulses as DTMF tones.\n" \ 863 "r2-strict-behaviour Sets the R2 protocol behavior while answering lines.\n" \ 864 "r2-preconnect-wait Sets the R2 protocol delay to pre-connect after \n" \ 865 " sending ringback signal.\n" \ 866 "context-digital Context (may be a template) for receiving digital \n" \ 867 " (E1) calls.\n" \ 868 "context-fxs Context (may be a template) for receiving FXS calls.\n" \ 869 "context-fxo Context (may be a template) for receiving FXO calls.\n" \ 870 "context-gsm-call Context (may be a template) for receiving GSM calls.\n" \ 871 "context-gsm-sms Context (may be a template) for receiving GSM \n" \ 872 " messages.\n" \ 873 "context-pr Context (may be a template) for receiving calls on \n" \ 874 " Passive Record boards.\n" \ 875 "log-to-console Sets the logging of messages to console.\n" \ 876 "log-to-disk Sets the logging of messages to disk.\n" \ 877 "trace Sets the low level tracing.\n" \ 878 "output-volume Sets the volume multiplier to be applied by the \n" \ 879 " board over the output audio.\n" \ 880 "input-volume Sets the volume multiplier to be applied by the \n" \ 881 " board over the input audio.\n\n" \ 882 "FOR ALL COMMANDS, CHECK THE DOCUMENTATION."; 883 884 _commands.push_back(this); 885 }; 886 887 bool execute(int argc, char *argv[]); 888 } KhompSet; 889 890 /* khomp log rotate */ 891 static struct _KhompLogRotate : public Command 892 { _KhompLogRotateCli::_KhompLogRotate893 _KhompLogRotate() 894 { 895 complete_name = "log rotate"; 896 brief = "Rotate the files where the messages are being logged."; 897 898 usage = \ 899 "Rotate the files where the messages are being logged.\n\n" \ 900 "Usage: khomp log rotate"; 901 902 _commands.push_back(this); 903 } 904 905 bool execute(int argc, char *argv[]); 906 } KhompLogRotate; 907 908 /* khomp log status */ 909 static struct _KhompLogStatus : public Command 910 { _KhompLogStatusCli::_KhompLogStatus911 _KhompLogStatus() 912 { 913 complete_name = "log status"; 914 brief = "Show the status of the messages."; 915 916 usage = \ 917 "Show the status of the message system (enabled/disabled messages).\n\n" \ 918 "Usage: khomp log status"; 919 920 _commands.push_back(this); 921 } 922 923 bool execute(int argc, char *argv[]); 924 } KhompLogStatus; 925 926 /* khomp revision */ 927 static struct _KhompRevision : public Command 928 { _KhompRevisionCli::_KhompRevision929 _KhompRevision() 930 { 931 complete_name = "revision"; 932 brief = "Show revision number."; 933 934 usage = \ 935 "Show the internal revision number for this channel.\n\n" \ 936 "Usage: khomp revision"; 937 938 _commands.push_back(this); 939 } 940 941 bool execute(int argc, char *argv[]); 942 } KhompRevision; 943 944 /* khomp dump config */ 945 static struct _KhompDumpConfig : public Command 946 { _KhompDumpConfigCli::_KhompDumpConfig947 _KhompDumpConfig() 948 { 949 complete_name = "dump config"; 950 brief = "Dump configuration values on screen."; 951 952 usage = \ 953 "\nUsage: khomp dump config\n\n" \ 954 "Dump configuration values loaded on memory.\n "; 955 956 _commands.push_back(this); 957 } 958 959 /* just to hide unavaible options */ removeUnavaibleCli::_KhompDumpConfig960 bool removeUnavaible(const std::string &s) 961 { 962 if(s == "atxfer" || s == "blindxfer" || s == "callgroup" || 963 s == "mohclass" || s == "native-bridge" || s == "recording" || 964 s == "record-prefix" || s == "transferdigittimeout" || 965 s == "pickupgroup" || s == "has-ctbus" || 966 s == "user-transfer-digits") 967 return true; 968 return false; 969 } 970 971 bool execute(int argc, char *argv[]); 972 } KhompDumpConfig; 973 974 /* khomp send command */ 975 static struct _KhompSendCommand : public Command 976 { _KhompSendCommandCli::_KhompSendCommand977 _KhompSendCommand() 978 { 979 complete_name = "send command"; 980 brief = "Send an K3L API command directly to the board."; 981 982 usage = \ 983 "Send an K3L API command directly to the board.\n" \ 984 "WARNING: This command is for debugging only - just use if you know \n" \ 985 "what you are doing!\n\n" \ 986 "Usage: khomp send command <board> <channel> <command> [argument]\n" \ 987 "\tboard -- Number of the board (start from 0).\n" \ 988 "\tchannel -- Number of the channel (start from 0).\n" \ 989 "\tcommand -- Number of API command (should be consulted in separate docs).\n"\ 990 "\targument -- Optimal string to use as parameter for the command.\n" \ 991 "e.g. khomp send command 0 1 4 123456 - Send DTMFs 123456 throught \n" \ 992 " channel 1 on board 0."; 993 994 _commands.push_back(this); 995 }; 996 997 bool execute(int argc, char *argv[]); 998 } KhompSendCommand; 999 1000 /* khomp send raw */ 1001 static struct _KhompSendRawCommand : public Command 1002 { _KhompSendRawCommandCli::_KhompSendRawCommand1003 _KhompSendRawCommand() 1004 { 1005 complete_name = "send raw command"; 1006 brief = "Send an command directly to a DSP at the board."; 1007 1008 usage = \ 1009 "Send an command directly to some DSP at the board.\n" \ 1010 "WARNING: This command is for debugging only - just use if you know \n" \ 1011 "what you are doing!\n\n" \ 1012 "Usage: khomp send raw command <board> <dsp> <c0> <c1> [...]\n" \ 1013 "\tboard -- Number of the board (start from 0).\n" \ 1014 "\tchannel -- Number of the channel (start from 0).\n" \ 1015 "\tdsp -- Number of the DSP.\n" \ 1016 "\tc0, c1, ... -- Hexadecimal numbers for the command.\n" \ 1017 "e.g. khomp send raw command 0 1 0x4a 0x00 0x00 - Disables the internal \n" \ 1018 " audio delay on board 0."; 1019 1020 _commands.push_back(this); 1021 }; 1022 1023 bool execute(int argc, char *argv[]); 1024 } KhompSendRawCommand; 1025 1026 /* khomp select sim */ 1027 static struct _KhompSelectSim : public Command 1028 { _KhompSelectSimCli::_KhompSelectSim1029 _KhompSelectSim() 1030 { 1031 complete_name = "select sim"; 1032 1033 brief = "Select SIM card, available to Khomp KGSM boards."; 1034 1035 usage = \ 1036 "Select SIM card, available to Khomp KGSM boards.\n\n" \ 1037 "Usage: khomp select sim <board> <channel> <sim_card>\n" \ 1038 "\tboard -- Number of the board (start from 0).\n" \ 1039 "\tchannel -- Number of the channel (start from 0), identifies \n" \ 1040 "\t the modem inside the board.\n" \ 1041 "\tsim_card -- Number for the SIM card to select.\n" \ 1042 "e.g. khomp select sim 0 0 2"; 1043 1044 _commands.push_back(this); 1045 }; 1046 1047 bool execute(int argc, char *argv[]); 1048 } KhompSelectSim; 1049 1050 /* khomp kommuter */ 1051 static struct _KhompKommuterOnOff : public Command 1052 { _KhompKommuterOnOffCli::_KhompKommuterOnOff1053 _KhompKommuterOnOff() 1054 { 1055 complete_name = "kommuter"; 1056 1057 options.push_back("on"); 1058 options.push_back("off"); 1059 1060 brief = "Activate and deactives the Kommuter devices."; 1061 1062 usage = \ 1063 "Manually activates or deactivates all kommuters connected to this machine.\n" \ 1064 "This command will only be sent if kommuter-activation variable in \n" \ 1065 "khomp.conf is set to manual. All kommuter devices will be configure with \n" \ 1066 "the timeout defined in kommuter-timeout.\n\n" \ 1067 "Usage: khomp kommuter {on|off}\n" \ 1068 "\ton -- Turn ON kommuter devices on this machine.\n" \ 1069 "\toff -- Turn OFF kommuter devices on this machine."; 1070 1071 _commands.push_back(this); 1072 }; 1073 1074 bool execute(int argc, char *argv[]); 1075 } KhompKommuterOnOff; 1076 1077 /* khomp kommuter count */ 1078 static struct _KhompKommuterCount : public Command 1079 { _KhompKommuterCountCli::_KhompKommuterCount1080 _KhompKommuterCount() 1081 { 1082 complete_name = "kommuter count"; 1083 1084 brief = "Prints the number of Kommuter devices."; 1085 1086 usage = \ 1087 "Prints the number of Kommuter devices connected to this machine.\n\n" \ 1088 "Usage: khomp kommuter count"; 1089 1090 _commands.push_back(this); 1091 }; 1092 1093 bool execute(int argc, char *argv[]); 1094 } KhompKommuterCount; 1095 1096 protected: 1097 static switch_stream_handle_t* stream; 1098 static switch_loadable_module_interface_t **module_interface; 1099 static Commands _commands; 1100 static std::string _khomp_usage; 1101 }; 1102 1103 /******************************************************************************/ 1104 /******************************* Command Tree ********************************* 1105 1106 This tree is a overview for all commands in our module, 1107 when a command is added, deleted or modified, please, update our tree. 1108 1109 + khomp 1110 | 1111 + ---- channels 1112 | | 1113 - + ---- disconnect 1114 | | 1115 - + ---- unblock 1116 | 1117 + ---- show 1118 | | 1119 - + ---- calls 1120 | | 1121 - + ---- channels 1122 | | | 1123 - - + ---- verbose 1124 | | | 1125 - - + ---- concise 1126 | | 1127 - + ---- statistics 1128 | | | 1129 - - + ---- detailed 1130 | | | 1131 - - + ---- verbose 1132 | | 1133 - + ---- links 1134 | | 1135 - + ---- errors 1136 | | 1137 - + ---- verbose 1138 | | 1139 - + ---- concise 1140 | 1141 + ---- reset 1142 | | 1143 - + ---- links 1144 | 1145 + ---- clear 1146 | | 1147 - + ---- links 1148 | | 1149 - + ---- errors 1150 | | 1151 - + ---- statistics 1152 | 1153 + ---- log 1154 | | 1155 - + ---- console 1156 | | | 1157 - - + ---- errors 1158 | | | 1159 - - + ---- warnings 1160 | | | 1161 - - + ---- messages 1162 | | | 1163 - - + ---- events 1164 | | | 1165 - - + ---- commands 1166 | | | 1167 - - + ---- audio 1168 | | | 1169 - - + ---- link 1170 | | | 1171 - - + ---- cas 1172 | | | 1173 - - + ---- standard 1174 | | | 1175 - - + ---- all 1176 | | 1177 - + ---- disk 1178 | | | 1179 - - + ---- errors 1180 | | | 1181 - - + ---- warnings 1182 | | | 1183 - - + ---- messages 1184 | | | 1185 - - + ---- events 1186 | | | 1187 - - + ---- commands 1188 | | | 1189 - - + ---- audio 1190 | | | 1191 - - + ---- modem 1192 | | | 1193 - - + ---- link 1194 | | | 1195 - - + ---- cas 1196 | | | 1197 - - + ---- functions 1198 | | | 1199 - - + ---- threads 1200 | | | 1201 - - + ---- locks 1202 | | | 1203 - - + ---- streams 1204 | | | 1205 - - + ---- standard 1206 | | | 1207 - - + ---- debugging 1208 | | | 1209 - - + ---- all 1210 | | 1211 - + ---- rotate 1212 | | 1213 - + ---- status 1214 | | 1215 - + ---- trace 1216 | | 1217 - + ---- isdn 1218 | | | 1219 - - + ---- q931 1220 | | | 1221 - - + ---- lapd 1222 | | | 1223 - - + ---- system 1224 | | | 1225 - - + ---- off 1226 | | 1227 - + ---- k3l 1228 | | | 1229 - - + ---- on 1230 | | | 1231 - - + ---- off 1232 | | 1233 - + ---- r2 1234 | | 1235 - + ---- on 1236 | | 1237 - + ---- off 1238 | 1239 + ---- send 1240 | | 1241 - + ---- command 1242 | | 1243 - + ---- raw 1244 | 1245 + ---- get 1246 | 1247 + ---- set 1248 | 1249 + ---- select 1250 | | 1251 - + ---- sim 1252 | 1253 + ---- sms 1254 | 1255 + ---- summary 1256 | | 1257 - + ---- concise 1258 | | 1259 - + ---- verbose 1260 | 1261 + ---- revision 1262 | 1263 + ---- kommuter 1264 | 1265 + ---- on 1266 | 1267 + ---- off 1268 1269 ******************************************************************************/ 1270 /******************************************************************************/ 1271 1272 #endif 1273 1274