Beispiel #1
0
int Policy::nodeToByteString(int father, Node* node, ByteString& bytes){
  if(node == NULL){
    return 0;
  }

  //find a node
  this->nodeIndex += 1;
  int sonFather = this->nodeIndex;
  int size = 0;

  

  //append father position
  unsigned char buf[4];
  Utility::int2str(buf, father);
  bytes.append(buf, 4);
  size += 4;


 
  //length of bytes of node, -1 represents internal node, -2 represents leaf, >0 represents the real length of exLeaf
  int node_len = -1;
  if(node->getType() == LEAF){
    node_len = -2;
  ////  printf("leaf node");
  } else if (node->getType() == EXTENDED_LEAF){
    ExLeaf* tempNode = (ExLeaf*)node;
    node_len = tempNode->getLength();
   // printf("exLeaf node");
  }

  //append len info
  Utility::int2str(buf, node_len);
  bytes.append(buf, 4);
  size += 4;  

  //append node itself info
  size += node->toByteString(bytes);

//  printf("\tnode size: %d\n", size);
  
  //handle sons of node
  if(node->getSonNum() > 0){
    int i = 0;
    Node** sons = node->getSons();
    for(i = 0; i < node->getSonNum(); i++){
      size += nodeToByteString(sonFather, sons[i], bytes);
    }
  }

  
  return size;
}
Beispiel #2
0
int CipherText::toByteString(ByteString& bytes){
  int begin = bytes.getLength();
  unsigned char* buf = (unsigned char*)malloc(sizeof(unsigned char) * ELEMENT_LENGTH);
  element_to_bytes(buf, this->c1);
  bytes.append(buf, ELEMENT_LENGTH);
  element_to_bytes(buf, this->c0);
  bytes.append(buf, ELEMENT_LENGTH);
  free(buf);
  this->policy->toByteString(bytes);
  int end = bytes.getLength();
  return end - begin;
}
Beispiel #3
0
int Policy::toByteString(ByteString& bytes){
  this->nodeIndex = -1;
  unsigned char buf[4];
  Utility::int2str(buf, this->nodeNum);
  bytes.append(buf, 4);
  return 4 + nodeToByteString(-1, this->root, bytes);
}
Beispiel #4
0
/**
 * Send a RDM request to the widget
 */
bool RobeWidgetImpl::PackAndSendRDMRequest(uint8_t label,
                                           const RDMRequest *request) {
  ByteString frame;
  if (!RDMCommandSerializer::Pack(*request, &frame)) {
    return false;
  }
  frame.append(RDM_PADDING_BYTES, 0);
  return SendMessage(label, frame.data(), frame.size());
}
Beispiel #5
0
/**
 * Send a RDM Message
 */
void RobeWidgetImpl::SendRDMRequest(RDMRequest *request_ptr,
                                    ola::rdm::RDMCallback *on_complete) {
  auto_ptr<RDMRequest> request(request_ptr);
  if (m_rdm_request_callback) {
    OLA_FATAL << "Previous request hasn't completed yet, dropping request";
    RunRDMCallback(on_complete, ola::rdm::RDM_FAILED_TO_SEND);
    return;
  }

  // prepare the buffer for the RDM data, we don't need to include the start
  // code. We need to include 4 bytes at the end, these bytes can be any value.
  ByteString data;

  unsigned int this_transaction_number = m_transaction_number++;
  unsigned int port_id = 1;

  request->SetSourceUID(m_uid);
  request->SetTransactionNumber(this_transaction_number);
  request->SetPortId(port_id);

  if (!RDMCommandSerializer::Pack(*request, &data)) {
    OLA_WARN << "Failed to pack message, dropping request";
    RunRDMCallback(on_complete, ola::rdm::RDM_FAILED_TO_SEND);
    return;
  }

  // Append the extra padding bytes, which can be set to any value.
  data.append(RDM_PADDING_BYTES, 0);

  OLA_DEBUG << "Sending RDM command. CC: "
            << strings::ToHex(request->CommandClass()) << ", PID "
            << strings::ToHex(request->ParamId()) << ", TN: "
            << this_transaction_number;

  m_rdm_request_callback = on_complete;
  m_pending_request.reset(request.release());

  const uint8_t label = m_pending_request->IsDUB() ?
      RDM_DISCOVERY : RDM_REQUEST;
  bool sent_ok = SendMessage(label, data.data(), data.size());

  if (!sent_ok) {
    m_rdm_request_callback = NULL;
    m_pending_request.reset();
    RunRDMCallback(on_complete, ola::rdm::RDM_FAILED_TO_SEND);
  }
}
Beispiel #6
0
static bool ReadInterfaces()
{
	ByteString buffer;
	if (FileSystem::FileExists(INTERFACE_VERSION_FILE))
	{
		FileSystem::ReadFile(INTERFACE_VERSION_FILE, buffer);
	}
	else
	{
		std::string data = WebIO("Redacted").Get(hString::va("https://momo5502.com/SteamAPI/?app=%d", Global::Steam_AppID));

		buffer.append(data.begin(), data.end());
		FileSystem::WriteFile(INTERFACE_VERSION_FILE, buffer, false);
	}

	Json::Reader reader;
	Json::Value root;

	if (reader.parse(std::string(buffer.begin(), buffer.end()), root) && root.type() == Json::objectValue)
	{
		PARSEINTERFACE(root, _SteamApps,                "Apps",                INTERFACE_STEAMAPPS001)
		PARSEINTERFACE(root, _SteamClient,              "Client",              INTERFACE_STEAMCLIENT001)
		PARSEINTERFACE(root, _SteamContentServer,       "ContentServer",       INTERFACE_STEAMCONTENTSERVER001)
//		PARSEINTERFACE(root, _SteamController,          "Controller",          INTERFACE_STEAMCONTROLLER001)
		PARSEINTERFACE(root, _SteamFriends,             "Friends",             INTERFACE_STEAMFRIENDS001)
		PARSEINTERFACE(root, _SteamGameServer,          "GameServer",          INTERFACE_STEAMGAMESERVER001)
		PARSEINTERFACE(root, _SteamGameServerStats,     "GameServerStats",     INTERFACE_STEAMGAMESERVER001)
		PARSEINTERFACE(root, _SteamHTTP,                "HTTP",                INTERFACE_STEAMHTTP001)
		PARSEINTERFACE(root, _SteamMasterServerUpdater, "MasterServerUpdater", INTERFACE_STEAMMASTERUPDATER001)
		PARSEINTERFACE(root, _SteamMatchMaking,         "MatchMaking",         INTERFACE_STEAMMATCHMAKING001)
		PARSEINTERFACE(root, _SteamMatchMakingServers,  "MatchMakingServers",  INTERFACE_STEAMMATCHMAKINGSERVERS001)
		PARSEINTERFACE(root, _SteamMusic,               "Music",               INTERFACE_STEAMMUSIC001)
//		PARSEINTERFACE(root, _SteamMusicRemote,         "MusicRemote",         INTERFACE_STEAMMUSICREMOTE001)
		PARSEINTERFACE(root, _SteamNetworking,          "Networking",          INTERFACE_STEAMNETWORKING001)
		PARSEINTERFACE(root, _SteamRemoteStorage,       "RemoteStorage",       INTERFACE_STEAMREMOTESTORAGE001)
		PARSEINTERFACE(root, _SteamScreenshots,         "Screenshots",         INTERFACE_STEAMSCREENSHOTS001)
		PARSEINTERFACE(root, _SteamUnifiedMessages,     "UnifiedMessages",     INTERFACE_STEAMUNIFIEDMESSAGES001)
		PARSEINTERFACE(root, _SteamUser,                "User",                INTERFACE_STEAMUSER001)
		PARSEINTERFACE(root, _SteamUserStats,           "UserStats",           INTERFACE_STEAMUSERSTATS001)
		PARSEINTERFACE(root, _SteamUtils,               "Utils",               INTERFACE_STEAMUTILS001)
		PARSEINTERFACE(root, _SteamUGC,                 "UGC",                 INTERFACE_STEAMUGC001)

		return true;
	}
Beispiel #7
0
bool FileSystem::ReadFile(const char *Filename, ByteString &DataBuffer)
{
	// Waste of time.
	if (!FileExists(Filename))
		return false;

	bool Result = false;
	uint32_t ReadSize = GetFileSize(Filename);
	uint8_t *ReadBuffer = new uint8_t[ReadSize];
	SecureZeroMemory(ReadBuffer, ReadSize);

	// Read the file.
	Result = ReadFile(Filename, ReadBuffer, ReadSize);

	// Append the data.
	DataBuffer.append(ReadBuffer, ReadSize);

	// Clear the buffer.
	SecureZeroMemory(ReadBuffer, ReadSize);
	delete[] ReadBuffer;

	return Result;
}