Example #1
0
void FuzzyCom::parseMessage() {
  int messageLength;

  /*if (!isValidHeader()) {
    setResponse("Header mismatch");
    return;
  }
  messageLength = buffer[4];
  if (messageLength < 5 || messageLength > 255) {
    sprintf(response, "Message length invalid (%d)", messageLength);
    return;
  }


  if (strlen(buffer) + 1 != messageLength) {
    sprintf(response, "Message length mismatch (%d != %d)", messageLength, strlen(buffer) + 1);
    return;
  }

  strcpy(bufcopy, buffer + 5);
  */
  char bufcopy[255];
  strcpy(bufcopy, buffer);

  char *tokens[10];
  char *token;
  int total = 0;
  token = strtok(bufcopy, " \n");
  while (token != NULL) {
    tokens[total] = token;
    total++;
    token = strtok(NULL, " \n");
  }

  if (strcmp(tokens[0], "set") == 0) {
    parseSet(tokens, total);
  } else if (strcmp(tokens[0], "get") == 0) {
    parseGet(tokens, total);
  } else if (strcmp(tokens[0], "log") == 0) {
    parseLog(tokens, total);
  } else {
    setResponse("Command unknown");
  }
}
Example #2
0
void WsAccount::fromXml( IMAccountList& imAccountList, const std::string& xml )
{
	bool result = true;

	TiXmlDocument doc;

	doc.Parse(xml.c_str());

	TiXmlHandle docHandle(&doc);
	TiXmlNode*  syncNode = NULL;
	
	syncNode = findSyncNode( docHandle );

	QueryResult::EnumMethod eMethod = _queryResult.getEnumMethod();

	if (syncNode) 
	{
		assert( eMethod != QueryResult::EnumMethod_None );

		std::string nodeData;
		nodeData << *syncNode;

		switch( eMethod )
		{
		case QueryResult::EnumMethod_GetUserNetwork:
			parseGet( syncNode, imAccountList );
			break;

		case QueryResult::EnumMethod_SaveUserNetwork:
			parseSet( syncNode, imAccountList );
			break;

		case QueryResult::EnumMethod_RemoveUserNetwork:
			parseRemove( syncNode, _userNetworkId, _bDeleted );
			break;

		default:
			assert(false);		//New method?
		}

		//Results
		QueryResultXMLSerializer resultSerializer( _queryResult );

		//Query node may or may not exist, depending on timestamp.
		TiXmlNode* queryNode = syncNode->FirstChild( "QUERY" );

		if ( queryNode )
		{
			resultSerializer.unserializeQuery( queryNode );
		}

		//Response - We should get this:
		//				1) if no update required due to timestamp. value == 0
		//				2) on all gets.  value = 1
		TiXmlNode* responseNode = syncNode->FirstChild( "response" );

		if ( responseNode )
		{
			resultSerializer.unserializeResponse( responseNode );
		}

		//Status - success or failure of overall action
		TiXmlNode* statusNode = syncNode->FirstChild( "status" );

		if ( statusNode )
		{
			resultSerializer.unserializeStatus( statusNode );
		}
	}
	else
	{
		assert(false);		//Did not find node.  Did XML change?
	}
}