Source

h323ac / h323ac.cxx

/***************************************************************************
    h323ac.cpp
    
    Copyright (c) 2002-2003  Vladimir Toncar

    The contents of this file are subject to the Mozilla Public License
    Version 1.1 (the "License"); you may not use this file except in
    compliance with the License. You may obtain a copy of the License at
    http://www.mozilla.org/MPL/

    Software distributed under the License is distributed on an "AS IS"
    basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
    See the License for the specific language governing rights and
    limitations under the License.

    The Original Code is oh323tut.

    The Initial Developer of the Original Code is Vladimir Toncar.
    All Rights Reserved.

    Contributor: Peter Nixon <codemonkey@peternixon.net>

 ***************************************************************************/


#include "h323ac.h"
#include "pconf.h"
#include "ep.h"

#ifndef WIN32
#include <signal.h>
#endif





// ***********************************************************************

PCREATE_PROCESS(OH323Tut) 

OH323Tut::OH323Tut(): 
	PProcess("Peter Nixon", "H323 Auto Caller", OH323TUT_VER_MAJOR, OH323TUT_VER_MINOR,
			OH323TUT_VER_STATUS, OH323TUT_VER_BUILD)
{}


// **********************************************************************

OH323Tut::~OH323Tut()
{} // Nothing to do now

// ***********************************************************************

void OH323Tut::printHelp() 
{
	PError << "Available options:\n"
	  "-f <file> --file <file>        the name of the sound file\n"
	  "-c <number> --call <number>    the number to call\n"
	  "-g <addr> --gatekeeper <addr>  the IP address or DNS name of the gatekeeper\n"
	  "-G <id> --gatekeeper-id <id>   gatekeeper identifier\n"
	  "-h --help                      print this message and exit\n"
	  "-n --no-gatekeeper             do not register with gatekeeper\n"
#if PTRACING
	  "-o <file> --output <file>      send trace output to <file>\n"
	  "-t --trace                     enable trace, use multiple times for more detail\n"
#endif
	  "-p <port> --port <port>        TCP port to listen at\n"
	  "-u <user> --user <user>        user name or number (can be used multiple times)\n"
	  "-F --fast-disable              Disable fast start\n"
	  "-T --h245tunneldisable         Disable H245 tunnelling.\n";
} 


// ***********************************************************************

void OH323Tut::Main() 
{
	PConfigArgs args(GetArguments()); 

	args.Parse( 
			"f-file:"
			"c-call:"
			"g-gatekeeper:"
			"G-gatekeeper-id:"
			"h-help."
			"n-no-gatekeeper."
                        "F-fast-disable."      
                        "T-h245tunneldisable." 
#if PTRACING
			"o-output:"
			"t-trace."
#endif
			"p-port:"
			"u-user:"
		);

	if (!args.HasOption('f') || !args.HasOption('c') || args.HasOption('h')) 
	{
		printHelp();
		return;
	} 

#if PTRACING 
  PTrace::Initialise(args.GetOptionCount('t'),
		args.HasOption('o') ? (const char *)args.GetOptionString('o') : NULL,
		PTrace::Blocks | PTrace::Timestamp | PTrace::Thread | PTrace::FileAndLine);
#endif 

	progConf.gkMode = ProgConf::RegisterWithGatekeeper; 
	progConf.fastStart = !args.HasOption('F');
	progConf.h245Tunnell = !args.HasOption('T');

	if (args.HasOption('n')) 
		progConf.gkMode = ProgConf::NoGatekeeper;

	if (args.HasOption('g'))
	{
		progConf.gkAddr = args.GetOptionString('g');
		progConf.gkMode = ProgConf::RegisterWithGatekeeper;
	}

	if (args.HasOption('G'))
	{
		progConf.gkId = args.GetOptionString('G');
		progConf.gkMode = ProgConf::RegisterWithGatekeeper;
	} 

	progConf.fileName = args.GetOptionString('f'); 
	progConf.callingNumber = args.GetOptionString('c'); 

	if (args.HasOption('p')) 
		progConf.port = (unsigned short)args.GetOptionString('p').AsUnsigned();

	if (progConf.port == 0) 
		progConf.port = DEFAULT_PORT;

	if (args.HasOption('u')) 
		progConf.userAliases = args.GetOptionString('u').Lines(); 

	// Allocate and initialise H.323 endpoint
	MyEndPoint endpoint(progConf, terminationSync); 

	if (endpoint.Init()) 
	{
		PTRACE(1, "H323 Auto Caller running");
		terminationSync.Wait(); 
	}

	PTRACE(1, "H323 Auto Caller shutting down...");
} 


//////////////////////////////////////////////////////////////////////
ProgConf::ProgConf()
{
  port = DEFAULT_PORT;
  fastStart = TRUE;
  h245Tunnell = TRUE;

}
// ***********************************************************************