Exemplo n.º 1
0
LONG CSerialWnd::Open (LPCTSTR lpszDevice, HWND hwndDest, UINT nComMsg, LPARAM lParam, DWORD dwInQueue, DWORD dwOutQueue)
{
    // Call the base class first
    long lLastError = CSerialEx::Open(lpszDevice,dwInQueue,dwOutQueue);
    if (lLastError != ERROR_SUCCESS)
        return lLastError;

    // Save the window handle, notification message and user message
    m_hwndDest = hwndDest;
    m_nComMsg  = nComMsg?nComMsg:mg_nDefaultComMsg;
    m_lParam   = lParam;

    // Start the listener thread
    lLastError = StartListener();
    if (lLastError != ERROR_SUCCESS)
    {
        // Close the serial port
        Close();

        // Return the error-code
        m_lLastError = lLastError;
        return m_lLastError;
    }

    // Return the error
    m_lLastError = ERROR_SUCCESS;
    return m_lLastError;
}
void
SharedPortEndpoint::SocketCheck()
{
	if( !m_listening || m_full_name.IsEmpty() || !m_is_file_socket) {
		return;
	}

	priv_state orig_priv = set_condor_priv();

	int rc = utime(m_full_name.Value(), NULL);

	int utime_errno = errno;
	set_priv(orig_priv);

	if( rc < 0 ) {
		dprintf(D_ALWAYS,"SharedPortEndpoint: failed to touch %s: %s\n",
				m_full_name.Value(), strerror(utime_errno));

		if( utime_errno == ENOENT ) {
			dprintf(D_ALWAYS,"SharedPortEndpoint: attempting to recreate vanished socket!\n");
			StopListener();
			if( !StartListener() ) {
				EXCEPT("SharedPortEndpoint: failed to recreate socket");
			}
		}
	}
}
void
SharedPortEndpoint::InitAndReconfig()
{
	std::string socket_dir;
#if USE_ABSTRACT_DOMAIN_SOCKET
	m_is_file_socket = false;
#endif
	if (!GetDaemonSocketDir(socket_dir)) {
		m_is_file_socket = true;
		if (!GetAltDaemonSocketDir(socket_dir)) {
			EXCEPT("Unable to determine an appropriate DAEMON_SOCKET_DIR to use.");
		}
	}

	if( !m_listening ) {
		m_socket_dir = socket_dir;
	}
	else if( m_socket_dir != socket_dir ) {
		dprintf(D_ALWAYS,"SharedPortEndpoint: DAEMON_SOCKET_DIR changed from %s to %s, so restarting.\n",
				m_socket_dir.Value(), socket_dir.c_str());
		StopListener();
		m_socket_dir = socket_dir;
		StartListener();
	}
	m_max_accepts = param_integer("SHARED_ENDPOINT_MAX_ACCEPTS_PER_CYCLE",
						param_integer("MAX_ACCEPTS_PER_CYCLE", 8));
}
char *
SharedPortEndpoint::deserialize(char *inherit_buf)
{
	char *ptr;
	ptr = strchr(inherit_buf,'*');
	ASSERT( ptr );
	m_full_name.formatstr("%.*s",(int)(ptr-inherit_buf),inherit_buf);
	inherit_buf = ptr+1;

	m_local_id = condor_basename( m_full_name.Value() );
	char *socket_dir = condor_dirname( m_full_name.Value() );
	m_socket_dir = socket_dir;
	free( socket_dir );
#ifdef WIN32
	/*
	Deserializing requires getting the handles out of the buffer and getting the pid pipe name
	stored.  Registering the pipe is handled by StartListener().
	*/
	sscanf_s(inherit_buf, "%d", (int*)&pipe_end);

	//m_pipe_out = daemonCore->Inherit_Pipe_Handle(out_pipe, false, true, true, 4096);
#else
	inherit_buf = m_listener_sock.serialize(inherit_buf);
#endif
	m_listening = true;

	ASSERT( StartListener() );

	return inherit_buf;
}
Exemplo n.º 5
0
const char *
SharedPortEndpoint::deserialize(const char *inherit_buf)
{
	YourStringDeserializer in(inherit_buf);
	if ( ! in.deserialize_string(m_full_name, "*") || ! in.deserialize_sep("*") ) {
		EXCEPT("Failed to parse serialized shared-port information at offset %d: '%s'", (int)in.offset(), inherit_buf);
	}

	m_local_id = condor_basename(m_full_name.c_str());
	auto_free_ptr socket_dir(condor_dirname(m_full_name.c_str()));
	m_socket_dir = socket_dir.ptr();
#ifdef WIN32
	/*
	Deserializing requires getting the handles out of the buffer and getting the pid pipe name
	stored.  Registering the pipe is handled by StartListener().
	*/
	in.deserialize_int((LONG_PTR*)&pipe_end);
	in.deserialize_sep("*"); // note: terminator is missing from HTCondor prior to 8.5.7 so it is optional here...
	inherit_buf = in.next_pos();
#else
	inherit_buf = m_listener_sock.serialize(in.next_pos());
#endif
	m_listening = true;

	ASSERT( StartListener() );

	return inherit_buf;
}
Exemplo n.º 6
0
//---------------------------------------------------------------------------
int TCustomMsgServer::Start() 
{
    int Result = 0;
    if (Status != SrvRunning)
    {
        Result = StartListener();
        if (Result != 0)
        {
            DoEvent(0, evcListenerCannotStart, Result, 0, 0, 0, 0);
            Status = SrvError;
        }
        else
        {
            DoEvent(0, evcServerStarted, SockListener->ClientHandle, LocalPort, 0, 0, 0);
            Status = SrvRunning;
        };
    };
    FLastError = Result;
    return Result;
}
Exemplo n.º 7
0
LONG CSerialEx::Open (LPCTSTR lpszDevice, DWORD dwInQueue, DWORD dwOutQueue, bool fStartListener)
{
	// Call the base class first
	long lLastError = CSerial::Open(lpszDevice,dwInQueue,dwOutQueue,SERIAL_DEFAULT_OVERLAPPED);
	if (lLastError != ERROR_SUCCESS)
		return lLastError;

#ifndef SERIAL_NO_OVERLAPPED
	// Create an event that is used for the workerthread. The globally
	// used event is used by the main-thread and cannot be reused
	// for this thread.
	m_hevtOverlappedWorkerThread = ::CreateEvent(0,true,false,0);
	if (m_hevtOverlappedWorkerThread == 0)
	{
		// Obtain the error information
		m_lLastError = ::GetLastError();
		_RPTF0(_CRT_WARN,"CSerialEx::Open - Unable to create event\n");

		// Close the serial port again
		CSerial::Close();

		// Return the error
		return m_lLastError;
	}
#endif


	// Start the listener thread (only on request)
	if (fStartListener)
	{
		lLastError = StartListener();
		if (lLastError != ERROR_SUCCESS)
			return lLastError;
	}

	// Return the error
	return m_lLastError;
}
Exemplo n.º 8
0
bool EndPoint::init()
{
	PTRACE( 1, "Initializing endpoint" );

#ifdef ENTERPRISE
	if( !ldapQueried ) {
		PError << "LDAP was not queried successfuly." << endl;
		return false;
	}

	if( ldapAliases.IsEmpty() ) {
		PError << "Aliases were not fetched from LDAP." << endl;
		return false;
	}

	SetLocalUserName( ldapAliases[0] );
	for (int i = 1; i < ldapAliases.GetSize(); i++)
		AddAliasName( ldapAliases[i]);
	if( ldapAttrs.HasKey("h323IdentitydialedDigits") )
		AddAliasName( ldapAttrs.GetString("h323IdentitydialedDigits") );
#else

	if( args.HasOption('u')) {
		PStringArray aliases = args.GetOptionString('u').Lines();
		SetLocalUserName(aliases[0]);
		for (int i = 1; i < aliases.GetSize(); i++)
			AddAliasName(aliases[i]);
	}
	else {
		QStringList userAliases = ancaConf->readListEntry( USER_ALIASES );
		SetLocalUserName( userAliases[ 0 ].latin1() );
		for ( unsigned i = 1; i < userAliases.size(); i++ )
			AddAliasName( userAliases[ i ].latin1() );
	}
#endif

	bool disableFastStart = !ancaConf->readBoolEntry( FAST_START, FAST_START_DEFAULT );
	bool disableTunneling = !ancaConf->readBoolEntry( H245_TUNNELING, H245_TUNNELING_DEFAULT );
	bool disableH245InSetup = !ancaConf->readBoolEntry( H245_IN_SETUP, H245_IN_SETUP_DEFAULT );
	if( args.HasOption("fast-disable") )
		disableFastStart = true;
	if( args.HasOption("h245tunneldisable") )
		disableTunneling = true;
	if( args.HasOption("disable-h245-in-setup") )
		disableH245InSetup = true;

	DisableFastStart( disableFastStart );
	DisableH245Tunneling( disableTunneling );
	DisableH245inSetup( disableH245InSetup );


	// Codecs
	AudioPlugin *audioPlugin = (AudioPlugin*)pluginFactory->getPlugin(Plugin::Audio);
	if( audioPlugin ) {
		audioPlugin->addCapabilities();
	}

	VideoInPlugin *videoPlugin = (VideoInPlugin*)pluginFactory->getPlugin(Plugin::VideoIn);
	if( videoPlugin ) {
		videoPlugin->addCapabilities();
	}

	AddAllUserInputCapabilities( 0, 1 );

	PTRACE( 1, "Capabilities:\n" << setprecision( 2 ) << capabilities );

	ancaInfo->set( ADDRESS, ( const char * ) (GetLocalUserName() + "@" + PIPSocket::GetHostName()) );

	// Initialise the security info
	if( args.HasOption("password") ) {
		SetGatekeeperPassword( args.GetOptionString("password") );
		PTRACE( 1, "Enabling H.235 security access to gatekeeper." );
	}

	// Do not start H323 Listener
	if( args.HasOption("no-listenport") ) return true;

	// Start H323 Listener
	PIPSocket::Address addr = INADDR_ANY;
	WORD port = ancaConf->readIntEntry( PORT, PORT_DEFAULT );
	if (args.HasOption("listenport"))
		port = (WORD)args.GetOptionString("listenport").AsInteger();

	listener = new H323ListenerTCP( *this, addr, port );
	if ( listener == NULL || !StartListener( listener ) ) {
		PTRACE(1, "Unable to start H323 Listener at port " << port );
		if ( listener != NULL )
			delete listener;
		return false;
	}
	PTRACE( 1, "TCP listener started at port " << port );

	return true;
}
Exemplo n.º 9
0
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;
}
Exemplo n.º 10
0
void CINSTALLSYS::StartDriver()
{
	StartListener();
}