示例#1
0
Qedo_Components::Deployment::ComponentInstallation_ptr
AssemblyImpl::getComponentInstallation(std::string host)
throw( Components::CreateFailure )
{
	Qedo_Components::Deployment::ComponentInstallation_var componentInstallation;
	CORBA::Object_var obj;

	//
	// get ComponentInstallation for destination
	//
	obj = resolveName(COMPONENT_INSTALLATION_CONTEXT + host);
	if ( CORBA::is_nil(obj))
	{
		DEBUG_OUT2("..... no Object for ", host);
		throw Components::CreateFailure();
	}
    
	componentInstallation = Qedo_Components::Deployment::ComponentInstallation::_narrow(obj.in());
	if ( CORBA::is_nil(componentInstallation.in()))
	{
		DEBUG_OUT2("..... no ComponentInstallation for ", host);
		throw Components::CreateFailure();
	}

	return componentInstallation._retn();
}
std::vector<ServerList_st>& cSrvParams::serverList()
{
	if ( serverList_.empty() ) // Empty? Try to load
	{
		setGroup("LoginServer");
		bool bKeepLooping = true;
		unsigned int i = 1;
		do
		{
			QString tmp = getString(QString("Shard %1").arg(i++), "").simplifyWhiteSpace();
			bKeepLooping = ( tmp != "" );
			if ( bKeepLooping ) // valid data.
			{
				QStringList strList = QStringList::split("=", tmp);
				if ( strList.size() == 2 )
				{
					ServerList_st server;
					server.sServer = strList[0];
					QStringList strList2 = QStringList::split(",", strList[1].stripWhiteSpace());
					server.sIP = strList2[0]; // Save this for later
					server.ip = resolveName(strList2[0]);
					bool ok = false;
					server.uiPort = strList2[1].toUShort(&ok);
					if ( !ok )
						server.uiPort = 2593; // Unspecified defaults to 2593
					serverList_.push_back(server);
				}
			}
		} while ( bKeepLooping );
	}
	return serverList_;
}
int main(int argc, char** argv)
{
	char dle_etx[] = "\x10\03";
	int sock;								//socket descrriptor
	struct sockaddr_in echoServerAddr;		//echo server address
	unsigned short echoServerPort;			//echo server port
	char* serverIP;							//server ip address (dotted quad)
	char echoBuffer[RCVBUFSIZE];			//buffer for echo string
	unsigned int echoStringLen;				//length of string to echo
	int bytesRecieved, totalBytesRecieved;	//bytes read in single recv and total bytes read
	int messagesSent, messages;

	if(argc < 3 || argc > 7){				//test for correct arguments
		fprintf(stderr, "Usage: %s <Server IP> <string 1> [string 2] [string 3] [string 4] [string 5]\n", argv[0]);
		exit(1);
	}
	messages = argc - 2;
	serverIP = argv[1];

	echoServerPort = PORT;

	//create a reliable stream socket using TCP
	if((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
		dieWithError("socket() failed");
	}

	//construct server address structure
	memset(&echoServerAddr, 0, sizeof(echoServerAddr));		//zero out structure
	echoServerAddr.sin_family = AF_INET;					//internet address family
	echoServerAddr.sin_addr.s_addr = resolveName(serverIP);	//server ip address
	echoServerAddr.sin_port = htons(echoServerPort);		//server port

	//establish connection to the echo server
	if(connect(sock, (struct sockaddr*)&echoServerAddr, sizeof(echoServerAddr)) < 0){
		dieWithError("connect() failed");
	}

	//TODO: echo all messages and dle etx
	messagesSent = 0;
	do {
		//printf("sending %s\n",argv[2+messagesSent] );
		sendMessage(sock, argv[2+messagesSent]);
		messagesSent++;
	} while(messagesSent < messages);

	sendMessage(sock, dle_etx);

	close(sock);	//close socket
	exit(0);

}
示例#4
0
Components::Deployment::ComponentServer_ptr
AssemblyImpl::createComponentServer (std::string dest)
throw( Components::CreateFailure )
{
	DEBUG_OUT2("..... create new component server on ", dest);

    //
	// get server activator for destination
	//
	Components::Deployment::ServerActivator_var serverActivator;
    Components::Deployment::ComponentServer_var component_server;

	CORBA::Object_var obj = resolveName(SERVER_ACTIVATOR_CONTEXT + dest);
    if ( CORBA::is_nil(obj))
    {
        DEBUG_OUT2(".......... no ServerActivator found for ", dest);
        throw Components::CreateFailure();
    }

    serverActivator = Components::Deployment::ServerActivator::_narrow(obj.in());
    if ( CORBA::is_nil(serverActivator.in()))
    {
        DEBUG_OUT(".......... ServerActivator is NIL ");
        throw Components::CreateFailure();
    }

	//
	// create new Component Server
	//
	try
	{
		Components::ConfigValues_var config = new Components::ConfigValues();
        component_server = serverActivator->create_component_server(config);
	}
	catch ( CORBA::SystemException& )
	{
		std::cerr << ".......... CORBA system exception during create_component_server()" << std::endl;
		std::cerr << ".......... is ServerActivator running?" << std::endl;
		throw Components::CreateFailure();
	}
	if (CORBA::is_nil(component_server))
	{
		std::cerr << ".......... Component Server is NIL" << std::endl;
		throw Components::CreateFailure();
	}

    return component_server._retn();
}
void
DeploymentClient::initialize()
throw (CannotInitialize)
{
    // get NameService
    if (! initNameService(orb_))
    {
        throw CannotInitialize();
    }

	// get an AssemblyFactory
	char hostname[256];
	gethostname(hostname, 256);
	CORBA::Object_var obj = resolveName(std::string("Qedo/AssemblyFactory/") + hostname);
	assemblyFactory_ = Components::Deployment::AssemblyFactory::_narrow( obj.in() );
    assert( !CORBA::is_nil( assemblyFactory_.in() ) );
}
示例#6
0
文件: www.c 项目: theand/sgcs-archive
//소켓 연결 후 리소스 요청
void connectToWWW(char *hostname)
{
	struct sockaddr_in www_addr;
	char request[150];
	char *resource_path;

    if ( strstr(hostname, "http://") == NULL) {
		printf("Site Address must start with 'http://'\n");
		exit(1);
    } else {
		//도메인 추출
		hostname = strtok(hostname+6, "/");
		//path 추출
		resource_path = strtok(NULL, "");
		//printf("hostname = '%s'\n", hostname);
		//printf("resource_path = '%s'\n", resource_path);
    }

	//REQUEST 파라메터 세팅
    sprintf(request, "GET /");
    if (resource_path)
		strcat(request, resource_path);
    strcat(request, "\r\n\0");

    //printf("\n[%s/%s]", hostname, resource_path);

	//소켓 연결
    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
		DieWithError("socket() failed");

    bzero((char *) &www_addr, sizeof(www_addr));
    www_addr.sin_family = AF_INET;
    www_addr.sin_addr.s_addr = resolveName(hostname);
    www_addr.sin_port = htons(HTTP_PORT);

    if (connect(sockfd, (struct sockaddr *) &www_addr, sizeof(www_addr)) < 0) 
		DieWithError("connect() failed");
    //puts("connect() success");
    //printf("REQUEST : %s\n", request);
	//REQUEST 전송
    write(sockfd, request, strlen(request));
}
示例#7
0
MGEhud::hud_id MGEhud::load(const char *name, const char *texture)
{
    hud_id hud = resolveName(name);

    if(hud == MGEhud::invalid_hud_id)
    {
        hud = elements_free.back();
        elements_free.pop_back();
        element_names[name] = hud;
    }

    Element *e = &elements[hud];
    e->enabled = false;
    e->x = e->y = 0;
    e->xscale = e->yscale = 1.0;
    e->texture = 0;
    e->effect = 0;
    e->effectFilename.clear();

    setTexture(hud, texture);
    return hud;
}
示例#8
0
CORBA::Object_ptr
AssemblyImpl::getRef (ReferenceData data)
throw(Components::CreateFailure)
{
    CORBA::Object_var obj;

	switch(data.kind)
	{
	case COMPONENTID:
		obj = getInstance(data.name);
		break;
	case HOMEID:
		obj = getInstance(data.name);
		break;
	case NAMING:
		obj = resolveName(data.name);
        if ( CORBA::is_nil(obj))
        {
			throw Components::CreateFailure();
        }
		break;
	case OBJECTREF:
		// todo
		break;
	case TRADER:
		// todo
		break;
	case FINDER:
		// todo
		break;
	default:
		break;
	}

	return obj._retn();
}
void
ComponentDeployment::init()
throw (DeploymentFailure)
{
	int dummy = 0;
	CORBA::ORB_var orb = CORBA::ORB_init (dummy, 0);

    //
	// get NameService
	//
    if (! initNameService(orb))
    {
        throw DeploymentFailure();
    }

	//
	// try to get a local AssemblyFactory
	//
	char hostname[256];
	gethostname(hostname, 256);
	CORBA::Object_var obj = resolveName(std::string("Qedo/AssemblyFactory/") + hostname);
	assemblyFactory_ = Components::Deployment::AssemblyFactory::_narrow( obj.in() );
    if( !CORBA::is_nil( assemblyFactory_.in() ) && 
		!assemblyFactory_->_non_existent() )
	{
		std::cerr << "..... take assembly factory on " << hostname << std::endl;
		return;
	}

	//
	// try to get another one
	//
	std::cerr << "..... no local assembly factory, try to get another one" << std::endl;

	obj = resolveName(std::string("Qedo/AssemblyFactory"));
	CosNaming::NamingContext_var ctx = CosNaming::NamingContext::_narrow( obj.in() );
	if( !CORBA::is_nil( ctx.in() ) )
	{
		CosNaming::BindingList_var list;
		CosNaming::BindingIterator_var iter;
		try
		{
			ctx->list(10, list.out(), iter.out());
		}
		catch (...)
		{
		}

		for(CORBA::ULong i = 0; i < list->length(); i++)
		{
			try
			{
				obj = ctx->resolve(list[i].binding_name);
			}
			catch (...)
			{
				continue;
			}
			assemblyFactory_ = Components::Deployment::AssemblyFactory::_narrow( obj.in() );
			if( !CORBA::is_nil( assemblyFactory_.in() ) &&
				!assemblyFactory_->_non_existent() )
			{
				std::cerr << "..... take assembly factory on " << list[i].binding_name[0].id << std::endl;
				return;
			}
		}
	}

	//
	// use our own assembly
	//
	// todo


	std::cerr << "!!!!! no assembly factory found" << std::endl;
	throw DeploymentFailure();
}
void 
ORBInitializerImpl::post_init (PortableInterceptor::ORBInitInfo_ptr info)
{
    //
	// First resolve the Name Service
	//
    CORBA::Object_var obj;

	try
    {
        obj = info->resolve_initial_references("NameService");
    }
    catch (const CORBA::ORB::InvalidName&)
    {
		std::cerr << "ORBInitializerImpl: Can't resolve NameService" << std::endl;
		return;
    }

    if (CORBA::is_nil(obj.in()))
    {
		std::cerr << "ORBInitializerImpl: NameService is a nil object reference" << std::endl;
		return;
    }

	try
	{
		nameService_ = CosNaming::NamingContext::_narrow(obj.in());
	}
	catch (const CORBA::Exception&)
	{
		std::cerr << "ORBInitializerImpl: NameService is not running" << std::endl;
		return;
	}

    if (CORBA::is_nil(nameService_.in()))
    {
		std::cerr << "ORBInitializerImpl: NameService is not a NamingContext object reference" << std::endl;
		return;
    }

    //
	// Resolve the HomeFinder
	//
	Qedo_Components::HomeFinder_var home_finder;
	obj = resolveName("Qedo/HomeFinder");

	if (CORBA::is_nil(obj.in()))
    {
		std::cerr << "ORBInitializerImpl: HomeFinder not found" << std::endl;
		return;
    }

    try
    {
        home_finder = Qedo_Components::HomeFinder::_narrow(obj);
    }
    catch (CORBA::SystemException&)
    {
        std::cerr << "ORBInitializerImpl: HomeFinder is not running" << std::endl;
		return;
    }

	if (CORBA::is_nil(home_finder.in()))
    {
		std::cerr << "ORBInitializerImpl: HomeFinder is not running" << std::endl;
		return;
    }

	//
	// register HomeFinder
	//
	info->register_initial_reference ("ComponentHomeFinder", home_finder);

	//
	// Allocate a slot id to communicate data towards our components
	//
	slot_id_ = info->allocate_slot_id();
}
示例#11
0
bool XMPP::sendMessage(string myMessage, string receiver)
{

  Log log(LOGFILE, dbData);

  struct sockaddr_in address;
  if((xmppSock = socket(AF_INET, SOCK_STREAM,0)) > 0)
  {

    // Socket created.
    address.sin_family = AF_INET;
    address.sin_port = htons(xmppData.xmppPort);
    address.sin_addr.s_addr = resolveName((char*) xmppData.xmppServer.c_str());
    if(connect(xmppSock,(struct sockaddr *) &address, sizeof(address)) == 0)
    {
      // Connected to server.

      ConversationDebug debug(dbData, "xmpp", xmppData.xmppServer);
      p_debug = &debug;

      stringstream message;
      stringstream reply;

      // Build message for stream initialization.
      message << "<stream:stream to='"
        << xmppData.xmppServer
        << "' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>" << endl;

      // Send stream initialization.
      if(!sendSocket(message.str()))
      {
        close(xmppSock);
        return 0;
      }

      // Clear message.
      message.str("");

      // Build message for iq request.
      message << "<iq type='get' to='"
        << xmppData.xmppServer
        << "' id='auth1'><query xmlns='jabber:iq:auth'/></iq>" << endl;

      // Send iq request.
      if(!sendSocket(message.str()))
      {
        close(xmppSock);
        return 0;
      }

      // Read reply.
      if(!readSocket())
      {
        close(xmppSock);
        return 0;
      }

      // See if an error occured.
      reply << buffer;
      if(reply.str().find("<stream:error>", 0) != string::npos)
      {

        // There was an error. Abort.
        stringstream error;
        error << "Could not send XMPP message to \""
          << receiver
          << "\" - Server reply: \""
          << getErrorReplyMessage(reply.str(), XMPP_STREAM_ERROR) << "\"";
        log.putLog(1, "011", error.str());
        close(xmppSock);
        return 0;
      }

      // Clear reply.
      reply.str("");

      // Clear message.
      message.str("");

      // Build login message.
      message << "<iq type='set' id='auth2'><query xmlns='jabber:iq:auth'><username>"
        << xmppData.xmppUser
        << "</username><password>"
        << xmppData.xmppPass
        << "</password><resource>"
        << xmppData.xmppResource
        << "</resource></query></iq>"
        << endl;

      // Send login message.
      if(!sendSocket(message.str()))
      {
        close(xmppSock);
        return 0;
      }

      // Read reply.
      if(!readSocket())
      {
        close(xmppSock);
        return 0;
      }

      // See if an error occured.
      reply << buffer;

      if(reply.str().find("<error", 0) != string::npos)
      {
        // There was an error. Abort.
        stringstream error;
        error << "Could not send XMPP message to \""
          << receiver
          << "\" - Server reply: \""
          << getErrorReplyMessage(reply.str(), XMPP_GENERAL_ERROR) << "\"";
        log.putLog(1, "012", error.str());
        close(xmppSock);
        return 0;
      }
      // Clear reply.
      reply.str("");

      // Clear message.
      message.str("");

      // Build the message to send alarm message to user.
      message << "<message to='"
        << receiver
        << "' from='"
        << xmppData.xmppUser
        << "@"
        << xmppData.xmppServer
        << "' type='chat' xml:lang='en'><body>"
        << myMessage
        << "</body></message>"
        << endl;

      if(!sendSocket(message.str()))
      {
        close(xmppSock);
        return 0;
      }

      if(!readSocket())
      {
        close(xmppSock);
        return 0;
      }

      // See if an error occurred.
      reply << buffer;

      if(reply.str().find("<error", 0) != string::npos)
      {
        // There was an error. Abort.
        stringstream error;
        error << "Could not send XMPP message to \""
          << receiver
          << "\" - Server reply: \""
          << getErrorReplyMessage(reply.str(), XMPP_GENERAL_ERROR) << "\"";
        log.putLog(1, "013", error.str());
        close(xmppSock);
        return 0;
      }

      // Close this session.
      sendSocket("</stream>");

      close(xmppSock);
      return 1;
    }
    else
    {
      // Could not connect to server.
      close(xmppSock);
      stringstream error;
      error << "Could not XMPP connect to \""
        << xmppData.xmppServer
        << "\"";
      log.putLog(1, "014", error.str());
      return 0;
    }
    log.putLog(1, "015", "Could not bind to socket for XMPP messaging.");
    close(xmppSock);
  }
  close(xmppSock);

  return 1;
}
示例#12
0
HKEY KeyService::getKeyByAnyName(std::string name)
{
  return getkeyByName(resolveName(name));
}
示例#13
0
int main(int argc, char *argv[])
{
    int sock;
    struct sockaddr_in fingerServAddr;
    const unsigned short servPort = 79;
    char *servIP;
    char *userName;

    char fingerBuffer[RCVBUFSIZE];
    unsigned int userNameLen;
    int bytesRcvd, totalBytesRcvd;

	int count=0;
	char *SEPARATOR = "@";
	char *param;
	char *word;

	//파라메터 형식을 체크
    if ((argc !=2 )) {
		fprintf(stderr, "Usage: %s username@hostname\n", argv[0]);
		exit(1);
    }

	//userName과 servIP를 분석해서 얻어온다
	param = estrdup(argv[1]);
	for(word = strtok(param, SEPARATOR); word!= NULL; word=strtok(NULL, SEPARATOR) ){
		if( count==0 )
			userName = estrdup(word);
		else if(count==1)
			servIP = estrdup(word);
		else
			DieWithError("Illegal input");
		count++; 
	}

	//소켓 생성
    if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0)
		DieWithError("socket() failed");

	//핑거 서버 포트 79로 주소 정보 입력
    memset(&fingerServAddr, 0, sizeof(fingerServAddr));
    fingerServAddr.sin_family = AF_INET;
    fingerServAddr.sin_addr.s_addr = resolveName(servIP);//Internet Address이건 호스트 네임이건 알아서 변환해서 넣음.
    fingerServAddr.sin_port = htons(servPort);

	//핑거 서버에 소켓 연결
    if (connect(sock, (struct sockaddr *) &fingerServAddr, sizeof(fingerServAddr)) < 0)
		DieWithError("connect() failed");

	//핑거 쿼리 - userName과 new line
    userNameLen = strlen(userName);
    if (send(sock, userName, userNameLen, 0) != userNameLen)
		DieWithError("send() sent a different number of bytes than expected");
    if (send(sock, "\n", 1, 0) != 1)
		DieWithError("send() sent a different number of bytes than expected");

	//핑거 결과 받아옴
    memset(fingerBuffer, 0, sizeof(fingerBuffer));
    totalBytesRcvd = 0;
    do {
		if ((bytesRcvd = recv(sock, fingerBuffer, RCVBUFSIZE-1, 0)) < 0)
			DieWithError("recv() failed or connection closed prematurely");
		totalBytesRcvd += bytesRcvd;
		fingerBuffer[bytesRcvd] = '\0';
		printf("%s", fingerBuffer);
    } while (bytesRcvd != 0 );

	//소켓 종료
    close(sock);

    return 0;
}
std::vector<ServerList_st>& cConfig::serverList()
{
	static unsigned int lastIpCheck = 0;
	static bool dynamicIP = false;
	if ( serverList_.empty() || ( dynamicIP && lastIpCheck <= Server::instance()->time() ) ) // Empty? Try to load
	{
		serverList_.clear();

		bool bKeepLooping = true;
		unsigned int i = 1;
		do
		{
			QString tmp = getString( "LoginServer", QString( "Shard %1" ).arg( i++ ), QString::null, false ).simplifyWhiteSpace();
			bKeepLooping = !tmp.isEmpty();
			if ( bKeepLooping ) // valid data.
			{
				QStringList strList = QStringList::split( "=", tmp );
				if ( strList.size() == 2 )
				{
					ServerList_st server;
					server.sServer = strList[0];
					QStringList strList2 = QStringList::split( ",", strList[1].stripWhiteSpace() );
					QHostAddress host;
					host.setAddress( strList2[0] );
					server.sIP = strList2[0];
					server.ip = resolveName( server.sIP );

					bool ok = false;
					server.uiPort = strList2[1].toUShort( &ok );
					if ( !ok )
						server.uiPort = 2593; // Unspecified defaults to 2593

					// This code will retrieve the first
					// valid Internet IP it finds
					// and replace a 0.0.0.0 with it
					if ( ( ( server.ip == 0 ) && ( lastIpCheck <= Server::instance()->time() ) ) )
					{
						dynamicIP = true;
						hostent* hostinfo;
						char name[256];

						// We check for a new IP max. every 30 minutes
						// So we have a max. of 30 minutes downtime
						lastIpCheck = Server::instance()->time() + ( MY_CLOCKS_PER_SEC * 30 * 60 );

						// WSA Is needed for this :/
						if ( !gethostname( name, sizeof( name ) ) )
						{
							hostinfo = gethostbyname( name );

							if ( hostinfo )
							{
								Q_UINT32 i = 0;

								while ( hostinfo->h_addr_list[i] )
								{
									// Check if it's an INTERNET ADDRESS
									char* hIp = inet_ntoa( *( struct in_addr* ) hostinfo->h_addr_list[i++] );
									host.setAddress( hIp );
									Q_UINT32 ip = host.ip4Addr();
									Q_UINT8 part1 = ( ip & 0xFF000000 ) >> 24;
									Q_UINT8 part2 = ( ip & 0x00FF0000 ) >> 16;

									if ( ( part1 == 127 ) || 	//this one is class A too.
										( part1 == 10 ) || ( ( part1 == 192 ) && ( part2 == 168 ) ) || ( ( part1 == 172 ) && ( part2 >= 16 ) && ( part2 <= 31 ) ) || ( ( part1 == 169 ) && ( part2 == 254 ) ) // DHCP Space Stuff
									   )
									{
										continue;
									}

									// We are now certain that it's a valid INET ip
									server.ip = ip;
									break;
								}
							}
						}

						// Fall back to localhost
						if ( !server.ip )
						{
							server.ip = 0x7F000001;
							server.sIP = "127.0.0.1";
						}
					}
					serverList_.push_back( server );
				}
示例#15
0
int main(int argc, char **argv)
{

	int servSock;
	int clientSock;
	struct sockaddr_in servAddr;
	struct sockaddr_in clientAddr;
	unsigned short servPort;
	unsigned int clientLen;
	char *servIP;
	char fileBuffer[FILEBUFSIZE];
	
	if(argc < 2)
	{
		handleError("Usage: ./a.out < mode > < addl. parameters >\n");
	}
//CLIENT MODE
	if(atoi(argv[1]) == 0)
	{
		if(argc != 5)
		{
			handleError("Usage: ./a.out <0> <serverName> <serverPort> <fileToTransfer>\n");
		}

		FILE *transferMe = fopen(argv[4],"r");
		if(transferMe == NULL) { handleError("Failed to open specified file!"); }
		
		servIP = argv[2];
		servPort = atoi(argv[3]);
		
		if((clientSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) 
		{
			handleError("socket creation failed");
		}

		memset(&servAddr, 0, sizeof(servAddr));
		servAddr.sin_family = AF_INET;
		servAddr.sin_addr.s_addr = resolveName(servIP);
		servAddr.sin_port = htons(servPort);

		if(connect(clientSock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
		{
			handleError("connection failed");
		}

		printf("\nTransferring");
		int bytesRead;
		while(!feof(transferMe))
		{
			bytesRead = fread(fileBuffer, 1, FILEBUFSIZE, transferMe);
			send(clientSock, fileBuffer, bytesRead, 0);
			printf(".");

		}

		printf("\nFile transfer complete!\n");

	}
//SERVER MODE
	else if(atoi(argv[1]) == 1)
	{
		char fileIndex[10]; // this holds the current file index in string form
		if(argc != 4)
		{
			handleError("Usage: ./a.out <1> <serverPort> <fileToCreate>\n");
		}

		servPort = atoi(argv[2]);

		FILE *fileToWrite;
		char *fileBaseName = argv[3];
		char fileNameBuffer[64];
		
		signal(SIGINT,exit_with_stats);

		if((servSock= socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)  
		{
			handleError("socket creation failed");
		}

		memset(&servAddr, 0, sizeof(servAddr));
		servAddr.sin_family = AF_INET;
		servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
		servAddr.sin_port = htons(servPort);
		
		if(bind(servSock, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
		{
			handleError("binding socket failed");
		}

		if(listen(servSock, MAXPENDING) < 0)
		{
			handleError("listen() failed");
		}

		while(1)
		{

			clientLen = sizeof(clientAddr);
			
			if((clientSock = accept(servSock, (struct sockaddr *) &clientAddr, &clientLen)) < 0)
			{
				handleError("accept() failed");
			}
			strcpy(fileNameBuffer,fileBaseName);
			sprintf(fileIndex, "%d",filesTransferred);
			strcat(fileNameBuffer,fileIndex);
			fileToWrite = fopen(fileNameBuffer,"w");
			transferFile(fileBuffer, fileToWrite, clientSock);
			fclose(fileToWrite);
		}
	}

	else { handleError("Unrecognized mode, bailing out!"); }

	return 0;

}
示例#16
0
Components::CCMHome_ptr
AssemblyImpl::instantiateHome 
(Components::Deployment::Container_ptr container, HomeInstanceData data)
throw(Components::CreateFailure)
{
    Components::CCMHome_var home;

	// extension, existing home can be referenced
	if(data.file.length())
	{
		//
		// create home
		//
		DEBUG_OUT2( "AssemblyImpl: create new home ", data.id );
		try
		{
			Components::ConfigValues_var config = new Components::ConfigValues();
			home = container->install_home(data.impl_id.c_str(), "", config);
		}
		catch (Components::Deployment::UnknownImplId&)
		{
			NORMAL_ERR2( "AssemblyImpl: unknown impl id during install_home() for ", data.id );
			throw Components::CreateFailure();
		}
		catch (Components::Deployment::ImplEntryPointNotFound&)
		{
			NORMAL_ERR2( "AssemblyImpl: entry point not found during install_home() for ", data.id );
			throw Components::CreateFailure();
		}
		catch (Components::Deployment::InstallationFailure&)
		{
			NORMAL_ERR2( "AssemblyImpl: installation failure during install_home() for ", data.id );
			throw Components::CreateFailure();
		}
		catch (Components::Deployment::InvalidConfiguration&)
		{
			NORMAL_ERR2( "AssemblyImpl: invalid configuration during install_home() for ", data.id );
			throw Components::CreateFailure();
		}
		catch (CORBA::SystemException&)
		{
			NORMAL_ERR2( "AssemblyImpl: CORBA system exception during install_home() for ", data.id );
			throw Components::CreateFailure();
		}

		if (CORBA::is_nil(home))
		{
			NORMAL_ERR2( "AssemblyImpl: Component Home is NIL for ", data.id );
			throw Components::CreateFailure();
		}

		//
		// register created home
		//
		homeMap_[data.id] = Components::CCMHome::_duplicate(home);
	}
	else
    {
		//
		// extension, use referenced home
		//
		DEBUG_OUT2( "AssemblyImpl: resolve home ", data.impl_id );
        home = Components::CCMHome::_narrow( resolveName(data.impl_id) );
	}

	//
	// registerwithhomefinder
	//
	// todo

	//
	// registerwithnaming
	//
	if (data.naming.length())
    {
		DEBUG_OUT2( "AssemblyImpl: register home with naming ", data.naming );
        registerName( data.naming, home, true );
    }

	//
	// registerwithtrader
	//
	// todo

    return home._retn();
}
示例#17
0
bool LocalDomainUriFilter::exists(const QString& host) const
{
    QHostInfo hostInfo = resolveName (host, 1500);
    return (hostInfo.error() == QHostInfo::NoError);
}
std::vector<ServerList_st>& cSrvParams::serverList()
{
	// We need a way to get this stuff for linux too
#ifndef __unix__
	static UINT32 lastIpCheck = 0;
	static UINT32 inetIp = 0;
#endif

	if ( serverList_.empty() ) // Empty? Try to load
	{
		setGroup("LoginServer");
		bool bKeepLooping = true;
		unsigned int i = 1;
		do
		{
			QString tmp = getString(QString("Shard %1").arg(i++), "").simplifyWhiteSpace();
			bKeepLooping = ( tmp != "" );
			if ( bKeepLooping ) // valid data.
			{
				QStringList strList = QStringList::split("=", tmp);
				if ( strList.size() == 2 )
				{
					ServerList_st server;
					server.sServer = strList[0];
					QStringList strList2 = QStringList::split(",", strList[1].stripWhiteSpace());
					QHostAddress host;
					host.setAddress( strList2[0] );
					server.sIP = strList2[0];
					server.ip = resolveName( server.sIP );

					bool ok = false;
					server.uiPort = strList2[1].toUShort(&ok);
					if ( !ok )
						server.uiPort = 2593; // Unspecified defaults to 2593

					// This code will retrieve the first
					// valid Internet IP it finds
					// and replace a 0.0.0.0 with it
#ifndef __unix__
					if( ( server.ip == 0 ) && ( lastIpCheck <= uiCurrentTime ) )
					{
						hostent *hostinfo;
						char name[256];

						// We check for a new IP max. every 30 minutes
						// So we have a max. of 30 minutes downtime
						lastIpCheck = uiCurrentTime + (MY_CLOCKS_PER_SEC*30*60);

						// WSA Is needed for this :/
						if( !gethostname( name, sizeof( name ) ) )
						{
							hostinfo = gethostbyname( name );

							if( hostinfo )
							{
								UINT32 i = 0;
								while( hostinfo->h_addr_list[i] )
								{
									// Check if it's an INTERNET ADDRESS
									char *hIp = inet_ntoa( *(struct in_addr *)hostinfo->h_addr_list[i++] );
									host.setAddress( hIp );
									UINT32 ip = host.ip4Addr();
									UINT8 part1 = ( ip & 0xFF000000 ) >> 24;
									UINT8 part2 = ( ip & 0x00FF0000 ) >> 16;

									if	( 
										( part1 == 127 ) || //this one is class A too.
										( part1 == 10 ) || 
										( ( part1 == 192 ) && ( part2 == 168 ) ) || 
										( ( part1 == 172 ) && ( part2 == 16 ) ) 
										)
										continue;

									// We are now certain that it's a valid INET ip
									server.ip = ip;
									inetIp = ip;
								}
							}
						}
						else if( inetIp )
							server.sIP = inetIp;
					}