bool Manager::Init(PArgList &args) { std::cout << __func__ << std::endl; // Parse various command line arguments args.Parse( "u-user:"******"c-password:"******"l-localaddress:" "o-opallog:" "p-listenport:" "P-protocol:" "R-register:" "x-execute:" "f-file:" "g-gatekeeper:" "w-gateway:" "h-help:" ); if (args.HasOption('h')) { print_help(); return false; } // enable opal logging if requested. if (args.HasOption('o')) PTrace::Initialise(5, args.GetOptionString('o')); if (!args.HasOption('P')) { std::cerr << "please define a protocol to use!" << std::endl; return false; } if (args.HasOption('p')) { TPState::Instance().SetListenPort( args.GetOptionString('p').AsInteger()); } if (args.HasOption('l')) { TPState::Instance().SetLocalAddress(args.GetOptionString('l')); } string protocol = stringify(args.GetOptionString('P')); if (!protocol.compare("sip")) { cout << "initialising SIP endpoint..." << endl; sipep = new SIPEndPoint(*this); sipep->SetRetryTimeouts(10000, 30000); sipep->SetSendUserInputMode(OpalConnection::SendUserInputAsRFC2833); // AddRouteEntry("pc:.* = sip:<da>"); // AddRouteEntry("sip:.* = pc:<db>"); AddRouteEntry("local:.* = sip:<da>"); AddRouteEntry("sip:.* = local:<db>"); if (args.HasOption('u')) { sipep->SetDefaultLocalPartyName(args.GetOptionString('u')); } if (args.HasOption('c')) { SIPRegister::Params param; param.m_registrarAddress = args.GetOptionString('w'); param.m_addressOfRecord = args.GetOptionString('u'); param.m_password = args.GetOptionString('c'); param.m_realm = args.GetOptionString('g'); PString *aor = new PString(""); //sipep->SetProxy(args.GetOptionString('w')); if (!StartListener()) { return false; } if (!sipep->Register(param, *aor)) { cout << "Could not register to " << param.m_registrarAddress << endl; return false; } else { cout << "registered as " << aor->GetPointer(aor->GetSize()) << endl; } } TPState::Instance().SetProtocol(TPState::SIP); } else if (!protocol.compare("h323")) { cout << "initialising H.323 endpoint..." << endl; h323ep = new H323EndPoint(*this); AddRouteEntry("pc:.* = h323:<da>"); AddRouteEntry("h323:.* = pc:<da>"); if (args.HasOption('u')) { h323ep->SetDefaultLocalPartyName(args.GetOptionString('u')); } TPState::Instance().SetProtocol(TPState::H323); } else if (!protocol.compare("rtp")) { cout << "initialising RTP endpoint..." << endl; TPState::Instance().SetProtocol(TPState::RTP); } else { std::cerr << "invalid protocol" << std::endl; return false; } if (args.HasOption('w')) { std::string val = args.GetOptionString('w'); TPState::Instance().SetGateway(val); } SetAudioJitterDelay(20, 1000); DisableDetectInBandDTMF(true); localep = new LocalEndPoint(*this); TPState::Instance().SetManager(this); return true; }
bool Resources::Open(PString & argv0, PString & application) { if(!PHYSFS_init(argv0.GetPointer())) { PError << "failure while initialising physfs: " << PHYSFS_getLastError() << endl; return PFalse; } else { PTRACE(5, "successful initialize physfs"); } const char* basedir = PHYSFS_getBaseDir(); const char* userdir = PHYSFS_getUserDir(); const char* dirsep = PHYSFS_getDirSeparator(); char* writedir = new char[strlen(userdir) + application.GetLength() + 2]; sprintf(writedir, "%s.%s", userdir, application.GetPointer()); PTRACE(5, "physfs base directory: " << basedir); PTRACE(5, "physfs user directory: " << userdir); PTRACE(5, "physfs write directory: " << writedir); if(!PHYSFS_setWriteDir(writedir)) { // try to create the directory... char* mkdir = new char[application.GetLength()+2]; sprintf(mkdir, ".%s", application.GetPointer()); if(!PHYSFS_setWriteDir(userdir) || ! PHYSFS_mkdir(mkdir)) { delete[] writedir; delete[] mkdir; PError << "failed creating configuration directory: '" << writedir << "': " << PHYSFS_getLastError() << endl; return PFalse; } delete[] mkdir; if (!PHYSFS_setWriteDir(writedir)) { PError << "couldn't set configuration directory to '" << writedir << "': " << PHYSFS_getLastError() << endl; return PFalse; } } PHYSFS_addToSearchPath(writedir, 0); PHYSFS_addToSearchPath(basedir, 1); delete[] writedir; /* Root out archives, and add them to search path... */ if (resourceExt != NULL) { char **rc = PHYSFS_enumerateFiles("/"); char **i; size_t extlen = strlen(resourceExt); char *ext; for (i = rc; *i != NULL; i++) { size_t l = strlen(*i); if ((l > extlen) && ((*i)[l - extlen - 1] == '.')) { ext = (*i) + (l - extlen); if (strcasecmp(ext, resourceExt) == 0) { PTRACE(5, "Add resource '" << *i << "' to search path"); const char *d = PHYSFS_getRealDir(*i); char* str = new char[strlen(d) + strlen(dirsep) + l + 1]; sprintf(str, "%s%s%s", d, dirsep, *i); addToSearchPath(str, 1); delete[] str; }; }; }; PHYSFS_freeList(rc); } return PTrue; }