| 1 | /*************************************************************************** | 
| 2 | oh323tut.cpp | 
| 3 | |
| 4 | Copyright (c) 2002-2003 Vladimir Toncar | 
| 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 | 
| 8 | compliance 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" | 
| 12 | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. | 
| 13 | See the License for the specific language governing rights and | 
| 14 | limitations under the License. | 
| 15 | |
| 16 | The Original Code is oh323tut. | 
| 17 | |
| 18 | The Initial Developer of the Original Code is Vladimir Toncar. | 
| 19 | All Rights Reserved. | 
| 20 | |
| 21 | Contributor(s): ______________________________________. | 
| 22 | |
| 23 | ***************************************************************************/ | 
| 24 | |
| 25 | |
| 26 | #include "oh323tut.h" | 
| 27 | #include "pconf.h" | 
| 28 | #include "ep.h" | 
| 29 | |
| 30 | #ifndef WIN32 | 
| 31 | #include <signal.h> | 
| 32 | #endif | 
| 33 | |
| 34 | // *********************************************************************** | 
| 35 | |
| 36 | static PSyncPoint terminationSync; | 
| 37 | |
| 38 | #ifndef WIN32 | 
| 39 | void signalHandler(int sig) | 
| 40 | { | 
| 41 | switch(sig) | 
| 42 | { | 
| 43 | case SIGINT: | 
| 44 | case SIGTERM: | 
| 45 | terminationSync.Signal(); | 
| 46 | break; | 
| 47 | default: | 
| 48 | break; | 
| 49 | } | 
| 50 | } | 
| 51 | #endif | 
| 52 | |
| 53 | |
| 54 | // *********************************************************************** | 
| 55 | |
| 56 | PCREATE_PROCESS(OH323Tut) | 
| 57 | |
| 58 | OH323Tut::OH323Tut(): | 
| 59 | PProcess("vt", "oh323tut", OH323TUT_VER_MAJOR, OH323TUT_VER_MINOR, | 
| 60 | OH323TUT_VER_STATUS, OH323TUT_VER_BUILD) | 
| 61 | {} | 
| 62 | |
| 63 | |
| 64 | // ********************************************************************** | 
| 65 | |
| 66 | OH323Tut::~OH323Tut() | 
| 67 | {} // Nothing to do now | 
| 68 | |
| 69 | // *********************************************************************** | 
| 70 | |
| 71 | void OH323Tut::printHelp() | 
| 72 | { | 
| 73 | PError << "Available options:\n" | 
| 74 | "-f <file> --file <file> the name of the sound file\n" | 
| 75 | "-g <addr> --gatekeeper <addr> the IP address or DNS name of the gatekeeper\n" | 
| 76 | "-G <id> --gatekeeper-id <id> gatekeeper identifier\n" | 
| 77 | "-h --help print this message and exit\n" | 
| 78 | "-n --no-gatekeeper do not register with gatekeeper\n" | 
| 79 | #if PTRACING | 
| 80 | "-o <file> --output <file> send trace output to <file>\n" | 
| 81 | #endif | 
| 82 | "-p <port> --port <port> TCP port to listen at\n" | 
| 83 | #if PTRACING | 
| 84 | "-t --trace enable trace, use multiple times for more detail\n" | 
| 85 | #endif | 
| 86 | "-u <user> --user <user> user name or number (can be used multiple times)\n"; | 
| 87 | } | 
| 88 | |
| 89 | |
| 90 | // *********************************************************************** | 
| 91 | |
| 92 | void OH323Tut::Main() | 
| 93 | { | 
| 94 | #ifndef WIN32 | 
| 95 | signal(SIGINT, signalHandler); | 
| 96 | signal(SIGTERM, signalHandler); | 
| 97 | #endif | 
| 98 | PConfigArgs args(GetArguments()); | 
| 99 | |
| 100 | args.Parse( | 
| 101 | "f-file:" | 
| 102 | "g-gatekeeper:" | 
| 103 | "G-gatekeeper-id:" | 
| 104 | "h-help." | 
| 105 | "n-no-gatekeeper." | 
| 106 | #if PTRACING | 
| 107 | "o-output:" | 
| 108 | #endif | 
| 109 | "p-port:" | 
| 110 | #if PTRACING | 
| 111 | "t-trace." | 
| 112 | #endif | 
| 113 | "u-user:" | 
| 114 | ); | 
| 115 | |
| 116 | if (!args.HasOption('f') || args.HasOption('h')) | 
| 117 | { | 
| 118 | printHelp(); | 
| 119 | return; | 
| 120 | } | 
| 121 | |
| 122 | #if PTRACING | 
| 123 | PTrace::Initialise(args.GetOptionCount('t'), | 
| 124 | args.HasOption('o') ? (const char *)args.GetOptionString('o') : NULL, | 
| 125 | PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine); | 
| 126 | #endif | 
| 127 | |
| 128 | ProgConf progConf; | 
| 129 | |
| 130 | progConf.gkMode = ProgConf::RegisterWithGatekeeper; | 
| 131 | |
| 132 | if (args.HasOption('n')) | 
| 133 | progConf.gkMode = ProgConf::NoGatekeeper; | 
| 134 | |
| 135 | if (args.HasOption('g')) | 
| 136 | { | 
| 137 | progConf.gkAddr = args.GetOptionString('g'); | 
| 138 | progConf.gkMode = ProgConf::RegisterWithGatekeeper; | 
| 139 | } | 
| 140 | |
| 141 | if (args.HasOption('G')) | 
| 142 | { | 
| 143 | progConf.gkId = args.GetOptionString('G'); | 
| 144 | progConf.gkMode = ProgConf::RegisterWithGatekeeper; | 
| 145 | } | 
| 146 | |
| 147 | progConf.fileName = args.GetOptionString('f'); | 
| 148 | |
| 149 | if (args.HasOption('p')) | 
| 150 | progConf.port = args.GetOptionString('p').AsUnsigned(); | 
| 151 | |
| 152 | if (progConf.port == 0) | 
| 153 | progConf.port = DEFAULT_PORT; | 
| 154 | |
| 155 | if (args.HasOption('u')) | 
| 156 | progConf.userAliases = args.GetOptionString('u').Lines(); | 
| 157 | |
| 158 | // Allocate and initialise H.323 endpoint | 
| 159 | MyEndPoint endpoint(progConf); | 
| 160 | |
| 161 | if (endpoint.Init()) | 
| 162 | { | 
| 163 | PTRACE(1, "oh323tut running"); | 
| 164 | terminationSync.Wait(); | 
| 165 | } | 
| 166 | |
| 167 | PTRACE(1, "oh323tut shutting down..."); | 
| 168 | } | 
| 169 | |
| 170 | |
| 171 | // *********************************************************************** | 
| 172 | |
| 173 |