예제 #1
0
RakNet::RakString RakString::FormatForPUTOrPost(const char* type, const char* uri, const char* contentType, const char* body, const char* extraHeaders)
{
	RakString out;
	RakString host;
	RakString remotePath;
	RakNet::RakString header;
	RakString uriRs;
	uriRs = uri;
	uriRs.SplitURI(header, host, remotePath);

	if (host.IsEmpty() || remotePath.IsEmpty())
		return out;

//	RakString bodyEncoded = body;
//	bodyEncoded.URLEncode();

	if (extraHeaders!=0 && extraHeaders[0])
	{
		out.Set("%s %s HTTP/1.1\r\n"
			"%s\r\n"
			"Host: %s\r\n"
			"Content-Type: %s\r\n"
			"Content-Length: %u\r\n"
			"\r\n"
			"%s",
			type,
			remotePath.C_String(),
			extraHeaders,
			host.C_String(),
			contentType,
			//bodyEncoded.GetLength(),
			//bodyEncoded.C_String());
			strlen(body),
			body);
	}
	else
	{
		out.Set("%s %s HTTP/1.1\r\n"
			"Host: %s\r\n"
			"Content-Type: %s\r\n"
			"Content-Length: %u\r\n"
			"\r\n"
			"%s",
			type,
			remotePath.C_String(),
			host.C_String(),
			contentType,
			//bodyEncoded.GetLength(),
			//bodyEncoded.C_String());
			strlen(body),
			body);
	}

	return out;
}
예제 #2
0
PluginReceiveResult FT_Node_Plugin::OnReceive(Packet *packet){

	if (resultHandler){
		RakString strLog;
		strLog.Set ( "FT_Node_Plugin::OnReceive :%d",  packet->data[0]);
		resultHandler->ReceiveLog(strLog);
	}

	if (packet->data[0] == ID_SERVER_LOGIN) {
		FT_MessageTypesNode  typeNode = (FT_MessageTypesNode)packet->data[1];

		if (resultHandler){
			RakString str;
			str.Set("FT_Node_Plugin::OnReceive data[0]: %d, data[1]: %d, typeNode: %d",packet->data[0],packet->data[1], typeNode );
			resultHandler->ReceiveLog(str);
		}

		UINT i = 0;
		for (; i < _Handlers.Size(); i++)
		{
			FT_Node_Process* handler = _Handlers[i];
			if (resultHandler){
				RakString str;
				str.Set("FT_Node_Plugin::OnReceive _Handler[%d].NodeType = %d", i, handler->GetNodeType() );
				resultHandler->ReceiveLog(str);
			}
			if (handler && handler->GetNodeType() == typeNode){
				BitStream bsIn(packet->data, packet->length, false);

				bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
				bsIn.IgnoreBytes(sizeof(RakNet::MessageID));

				FT_Session session;
				// session.Serialize(false, &bsIn);

				// FT_UnitData unitData;
				// unitData.Serialize(false, &bsIn);

				if (!session.IsOutTime()){
					handler->OnProcess(session, &bsIn, packet->systemAddress);
				}
				else{
					handler->OnOutTime(session);
				}
				return RR_STOP_PROCESSING;
			}
		}
	}

	return RR_CONTINUE_PROCESSING;
}
예제 #3
0
RakString RakString::FormatForPOST(RakString &uri, RakString &contentType, unsigned int port, RakString &body)
{
	RakString out;
	RakString host;
	RakString remotePath;
	RakNet::RakString header;

	uri.SplitURI(header, host, remotePath);
	if (host.IsEmpty() || remotePath.IsEmpty())
		return out;
	
	out.Set("POST %s HTTP/1.0\r\n"
		"Host: %s:%i\r\n"
		"Content-Type: %s\r\n"
		"Content-Length: %u\r\n"
		"\r\n"
		"%s",
		remotePath.C_String(),
		host.C_String(),
		port,
		contentType.C_String(),
		body.GetLength(),
		body.C_String());

	return out;
}
예제 #4
0
RakString RakString::FormatForDELETE(const char* uri, const char* extraHeaders)
{
	RakString out;
	RakString host;
	RakString remotePath;
	RakNet::RakString header;
	RakNet::RakString uriRs;
	uriRs = uri;

	uriRs.SplitURI(header, host, remotePath);
	if (host.IsEmpty() || remotePath.IsEmpty())
		return out;

	if (extraHeaders && extraHeaders[0])
	{
		out.Set("DELETE %s HTTP/1.1\r\n"
			"%s\r\n"
			"Content-Length: 0\r\n"
			"Host: %s\r\n"
			"Connection: close\r\n"
			"\r\n",
			remotePath.C_String(),
			extraHeaders,
			host.C_String());
	}
	else
	{
		out.Set("DELETE %s HTTP/1.1\r\n"
			"Content-Length: 0\r\n"
			"Host: %s\r\n"
			"Connection: close\r\n"
			"\r\n",
			remotePath.C_String(),
			host.C_String());
	}

	return out;
}
예제 #5
0
RakString RakString::FormatForGET(RakString &uri, unsigned int port)
{
	RakString out;
	RakString host;
	RakString remotePath;
	RakNet::RakString header;

	uri.SplitURI(header, host, remotePath);
	if (host.IsEmpty() || remotePath.IsEmpty())
		return out;

	out.Set("GET %s HTTP/1.0\r\n"
		"Host: %s:%i\r\n"
		"\r\n",
		remotePath.C_String(),
		host.C_String(),
		port);

	return out;
}
예제 #6
0
void HTTPConnection::Update(void)
{
    SystemAddress sa;
    sa = tcp->HasCompletedConnectionAttempt();
    while (sa!=UNASSIGNED_SYSTEM_ADDRESS)
    {
//		printf("Connected\n");
        connectionState=CS_CONNECTED;
        server=sa;
        sa = tcp->HasCompletedConnectionAttempt();
    }

    sa = tcp->HasFailedConnectionAttempt();
    while (sa!=UNASSIGNED_SYSTEM_ADDRESS)
    {
        //printf("Failed connected\n");
        CloseConnection();
        sa = tcp->HasFailedConnectionAttempt();
    }

    sa = tcp->HasLostConnection();
    while (sa!=UNASSIGNED_SYSTEM_ADDRESS)
    {
        //printf("Lost connection\n");
        CloseConnection();
        sa = tcp->HasLostConnection();
    }


    switch (connectionState)
    {
    case CS_NONE:
    {
        if (outgoingCommand.IsEmpty())
            return;

        //printf("Connecting\n");
        server = tcp->Connect(host, port, false);
        connectionState = CS_CONNECTING;
    }
    break;
    case CS_DISCONNECTING:
    {
        if (tcp->ReceiveHasPackets()==false)
        {
            if (incomingData.IsEmpty()==false)
            {
                results.Push(incomingData, _FILE_AND_LINE_ );
            }
            incomingData.Clear();
            tcp->CloseConnection(server);
            connectionState=CS_NONE;
        }
    }
    break;
    case CS_CONNECTING:
    {
    }
    break;
    case CS_CONNECTED:
    {
        //printf("Connected\n");
        if (outgoingCommand.IsEmpty())
        {
            //printf("Closed connection (nothing to do)\n");
            CloseConnection();
            return;
        }

#if OPEN_SSL_CLIENT_SUPPORT==1
        tcp->StartSSLClient(server);
#endif

        //printf("Sending request\n");
        currentProcessingCommand = outgoingCommand.Pop();
        RakString request;
        if (currentProcessingCommand.isPost)
        {
            request.Set("POST %s HTTP/1.0\r\n"
                        "Host: %s:%i\r\n"
                        "Content-Type: %s\r\n"
                        "Content-Length: %u\r\n"
                        "\r\n"
                        "%s",
                        currentProcessingCommand.remotePath.C_String(),
                        host.C_String(),
                        port,
                        currentProcessingCommand.contentType.C_String(),
                        (unsigned) currentProcessingCommand.data.GetLength(),
                        currentProcessingCommand.data.C_String());
        }
        else
        {
            // request.Set("GET %s\r\n", host.C_String());
            // http://www.jenkinssoftware.com/forum/index.php?topic=4601.0;topicseen
            request.Set("GET %s HTTP/1.0\r\n"
                        "Host: %s:%i\r\n"
                        "\r\n",
                        currentProcessingCommand.remotePath.C_String(),
                        host.C_String(),
                        port);
        }

        //	printf(request.C_String());
        //		request.URLEncode();
        tcp->Send(request.C_String(), (unsigned int) request.GetLength(), server,false);
        connectionState=CS_PROCESSING;
    }
    break;
    case CS_PROCESSING:
    {
    }
    }

//	if (connectionState==CS_PROCESSING && currentProcessingCommand.data.IsEmpty()==false)
//		outgoingCommand.PushAtHead(currentProcessingCommand);
}
예제 #7
0
void Rackspace2::AddOperation(RakNet::RakString URL, OpType opType, json_t *data, bool setAuthToken)
{
	if (tcp==0)
	{
		tcp = RakNet::OP_NEW<TCPInterface>();

		if (tcp->Start(0, 0, 8)==false)
		{
			if (eventCallback)
				eventCallback->OnTCPFailure();
		}

		httpConnection2 = RakNet::OP_NEW<HTTPConnection2>();

		tcp->AttachPlugin(httpConnection2);
	}

	RakString authURLHeader, authURLDomain, authURLPath;
	URL.SplitURI(authURLHeader,authURLDomain,authURLPath);
	char *jsonStr = "";
	if (data)
		jsonStr = json_dumps(data, 0);
	RakString requestStr;
	RakString extraBody;
	if (setAuthToken)
	{
		RakAssert(X_Auth_Token[0]);
		// Test expired token
		//strcpy(X_Auth_Token, "fd6ad67c-fbd3-4b35-94e2-059b6090998e");
		extraBody.Set("Accept: application/json\r\nX-Auth-Token: %s", X_Auth_Token);

		__addOpLast_URL = URL;
		__addOpLast_isPost = opType;
		__addOpLast_dataAsStr = jsonStr;
	}
	else
	{
		extraBody = "Accept: application/json";
	}

	if (opType==OT_POST)
		requestStr = RakString::FormatForPOST(URL, "application/json", jsonStr, extraBody);
	else if (opType==OT_GET)
		requestStr = RakString::FormatForGET(URL, extraBody);
	else  if (opType==OT_DELETE)
		requestStr = RakString::FormatForDELETE(URL, extraBody);
	else
		requestStr = RakString::FormatForPUT(URL, "application/json", jsonStr, extraBody);

	bool b = httpConnection2->TransmitRequest(requestStr,authURLDomain, 443, true);
	if (!b)
	{
		if (eventCallback)
			eventCallback->OnTransmissionFailed(httpConnection2, requestStr, authURLDomain);
	}
	if (data)
	{
		free(jsonStr);
		json_decref(data);
	}
}