//===============================================
//		CNSmlProfileContentHandler::Charecters()
//		
//		
//===============================================	
TInt CNSmlProfileContentHandler::Charecters(TDesC& aBuf, TInt /*aStart*/, TInt /*aLength*/)
{	

	TInt aValue;
	if (iDSSettingInProgress)
	{
		
		if(iState == EProfileDisplayName)
		{
			if(aBuf.Length() > KNSmlMaxProfileNameLength)
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileDisplayName, KEmpty) ;
			}
			else
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileDisplayName, aBuf) ;
			}
			iState = EStateHandled;		
		}
		if(iState == EProfileServerURL)
		{
			if(aBuf.Length() > KDSMaxURLLength)
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileDisplayName, KEmpty) ;
			}
			else
			{
			SetServerURL(aBuf);
			}
			iState = EStateHandled;		
		}
		if(iState == EProfileIAPId)
		{
		
			if(aBuf.Length() > KAccessPointNameMaxLen)
			{
			_LIT(KDefaultValue ,"-1");
			aBuf = KDefaultValue;	
			}
			
			TInt iapId = AccessPointIdL(aBuf);
			iCustomProfileArray->At(iCounter)->SetIntValue( EDSProfileIAPId, iapId) ;
			iState = EStateHandled;		
		}
		if(iState == EProfileTransportId)
		{
			_LIT16(KHexCode,"0x");
			TBuf<64> tempBuf(aBuf);
			TInt temp = tempBuf.Find(KHexCode); 
			tempBuf.Delete(0, temp + 2);

			iLex = tempBuf;
			TInt64 aVal;
			User::LeaveIfError(iLex.Val(aVal ,EHex));
			if (aVal != KUidNSmlMediumTypeInternet.iUid && aVal != KUidNSmlMediumTypeBluetooth.iUid)
				{
				aVal = KUidNSmlMediumTypeInternet.iUid;	
				}
			iCustomProfileArray->At(iCounter)->SetIntValue( EDSProfileTransportId, aVal) ;
			iState = EStateHandled;		
		}
		
		if(iState == EProfileSyncServerUsername)
		{
			if(aBuf.Length() > KNSmlMaxUsernameLength)
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileDisplayName, KEmpty) ;
			}
			else
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileSyncServerUsername, aBuf) ;
			}
			iState = EStateHandled;	
		}
		if(iState == EProfileSyncServerPassword)
		{
			if(aBuf.Length() > KNSmlMaxPasswordLength)
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileDisplayName, KEmpty) ;
			}
			else
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileSyncServerPassword, aBuf) ;
			}
			iState = EStateHandled;	
		}
		if(iState == EProfileServerAlertedAction)
		{
			iLex = aBuf;
			User::LeaveIfError(iLex.Val(aValue));
			TInt typeId = ServerAlertType(aValue);
			
			if(aValue != ESmlEnableSync && aValue != ESmlConfirmSync && aValue != ESmlDisableSync)
				{
				aValue = ESmlEnableSync;
				}
			
			iCustomProfileArray->At(iCounter)->SetIntValue( EDSProfileServerAlertedAction, typeId) ;
			iState = EStateHandled;		
		}
	
		if(iState == EProfileHidden)
		{
			iLex = aBuf;
			User::LeaveIfError(iLex.Val(aValue));
			SetVisibility(aValue);
			iState = EStateHandled;		
		}
		
		if(iState == EProfileHttpAuthUsed)
		{
			iLex = aBuf;
			User::LeaveIfError(iLex.Val(aValue));
			if (aValue != 0 && aValue != 1)
			{
				aValue = 1;
			}
			iCustomProfileArray->At(iCounter)->SetIntValue( EDSProfileHttpAuthUsed, aValue) ;
			iState = EStateHandled;		
		}
		
		if(iState == EProfileHttpAuthUsername)
		{	
			if(iCustomProfileArray->At(iCounter)->IntValue(EDSProfileTransportId) 
											== KUidNSmlMediumTypeBluetooth.iUid 
				|| !iCustomProfileArray->At(iCounter)->IntValue(EDSProfileHttpAuthUsed))
				{
				iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileHttpAuthUsername, KEmpty) ;
				}
			else if (aBuf.Length() > KNSmlMaxHttpAuthUsernameLength)
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileDisplayName, KEmpty) ;
			}
			else
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileHttpAuthUsername, aBuf) ;
			}
			iState = EStateHandled;
		}
		
		if(iState == EProfileHttpAuthPassword)
		{	
			if(iCustomProfileArray->At(iCounter)->IntValue(EDSProfileTransportId) 
											== KUidNSmlMediumTypeBluetooth.iUid 
				|| !iCustomProfileArray->At(iCounter)->IntValue(EDSProfileHttpAuthUsed))
				{
				iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileHttpAuthPassword, KEmpty) ;
				}
			else if(aBuf.Length() > KNSmlMaxHttpAuthPasswordLength)
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileDisplayName, KEmpty) ;
			}
			else
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileHttpAuthPassword, aBuf) ;
			}
			iState = EStateHandled;	
		}
		
		if(iState == EProfileServerId)
		{
			if(aBuf.Length() > KNSmlMaxServerIdLength)
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileDisplayName, KEmpty) ;
			}
			else
			{
			iCustomProfileArray->At(iCounter)->SetStrValue( EDSProfileServerId, aBuf) ;						
			}
			iState = EStateHandled;	
		}
		if(iState == EProfileProtocolVersion)
		{
			iLex = aBuf;
			User::LeaveIfError(iLex.Val(aValue));
			
			if(aValue != ESmlVersion1_1_2 && aValue != ESmlVersion1_2)
				{
				aValue = ESmlVersion1_2;
				}
			iCustomProfileArray->At(iCounter)->SetIntValue( EDSProfileProtocolVersion, aValue) ;
			iState = EStateHandled;		
		}
		
		if(iState == ESyncType)
		{
			TInt syncType = SyncType (aBuf);
			iSyncTypeArray->AppendL(syncType);
			iState = EStateHandled;		
		}
		
		if(iState == EDefaultProfile)
        {
            if(aBuf.Compare(_L("true")) == 0)
                {
                aValue = 1;
                }
            else
                {
                aValue = 0;
                }
            iCustomProfileArray->At(iCounter)->SetIntValue( EDSProfileDefaultProfile, aValue );
            iState = EStateHandled;     
        }
	}
	else if (iDSContentInProgress)
	{
		if(iState == EProfileDisplayName)
		{
			if(aBuf.Length() > KNSmlMaxProfileNameLength)
			{
			iContentArray->At(iContentCounter)->SetStrValue( EXMLDSProfileName, KEmpty) ;
			iInvalidContent = ETrue;
			}
			else
			{
			iContentArray->At(iContentCounter)->SetStrValue( EXMLDSProfileName ,aBuf);
			}
			iState = EStateHandled;
		}
		if(iState == EProfileServerId)
		{	
			if(aBuf.Length() > KNSmlMaxServerIdLength || iInvalidContent)
			{
			iContentArray->At(iContentCounter)->SetStrValue( EXMLDSProfileName, KEmpty) ;
			iContentArray->At(iContentCounter)->SetStrValue( EXMLDSServerId, KEmpty) ;
			}
			else
			{
			iContentArray->At(iContentCounter)->SetStrValue( EXMLDSServerId ,aBuf);
			}
			iState = EStateHandled;
		}
		if(iState == EAdapterServerDataSource )
		{	
			if(aBuf.Length() > KDSMaxRemoteNameLength)
			{
			iContentArray->At(iContentCounter)->SetStrValue( EXMLDSServerDataSource, KEmpty) ;
			}
			else
			{
			iContentArray->At(iContentCounter)->SetStrValue( EXMLDSServerDataSource, aBuf);
			}
			iState = EStateHandled;
		}
		if(iState == EAdapterImplementationId )
		{	
			if(aBuf.Length() > KNSmlMaxAdapterIdLength)
			{
			iContentArray->At(iContentCounter)->SetStrValue( EXMLDSAdapaterId, KEmpty) ;
			}
			else
			{
			iContentArray->At(iContentCounter)->SetStrValue( EXMLDSAdapaterId, aBuf);
			}
			iState = EStateHandled;
		}
		

	}

	return 1;
}
bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite)
{
   AssertFatal( fromName != NULL && toName != NULL, "dPathCopy - NULL file name" );

   TempAlloc< TCHAR > from( dStrlen( fromName ) + 1 );
   TempAlloc< TCHAR > to( dStrlen( toName ) + 1 );

#ifdef UNICODE
   convertUTF8toUTF16( fromName, from, from.size );
   convertUTF8toUTF16( toName, to, to.size );
#else
   dStrcpy( from, fromName );
   dStrcpy( to, toName );
#endif

   backslash( from );
   backslash( to );

   // Copy File
   if (Platform::isFile(fromName))
      return CopyFile( from, to, nooverwrite );
   // Copy Path
   else if (Platform::isDirectory(fromName))
   {
      // If the destination path exists and we don't want to overwrite, return.
      if ((Platform::isDirectory(toName) || Platform::isFile(toName)) && nooverwrite)
         return false;

      Vector<StringTableEntry> directoryInfo;
      Platform::dumpDirectories(fromName, directoryInfo, -1);

      Vector<Platform::FileInfo> fileInfo;
      Platform::dumpPath(fromName, fileInfo);

      Platform::clearExcludedDirectories();

      TempAlloc< char > tempBuf( to.size * 3 + MAX_PATH * 3 );

      // Create all the directories.
      for (S32 i = 0; i < directoryInfo.size(); i++)
      {
         const char* fromDir = directoryInfo[i];

         char* toDir = tempBuf;
         Platform::makeFullPathName(fromDir + dStrlen(fromName) + (dStricmp(fromDir, fromName) ? 1 : 0), tempBuf, tempBuf.size, toName);
         if(*(toDir + dStrlen(toDir) - 1) != '/')
            dStrcat(toDir, "/");
         forwardslash(toDir);

         if (!Platform::createPath(toDir))
         {
            //TODO: New directory should be deleted here.
            return false;
         }
      }

      TempAlloc< char > tempBuf1( from.size * 3 + MAX_PATH * 3 );
#ifdef UNICODE
      TempAlloc< WCHAR > wtempBuf( tempBuf.size / 3 );
      TempAlloc< WCHAR > wtempBuf1( tempBuf1.size / 3 );
#endif

      for (S32 i = 0; i < fileInfo.size(); i++)
      {
         char* fromFile = tempBuf1;
         dSprintf( tempBuf1, tempBuf1.size, "%s/%s", fileInfo[i].pFullPath, fileInfo[i].pFileName);

         char* toFile = tempBuf;
         Platform::makeFullPathName(fileInfo[i].pFullPath + dStrlen(fromName) + (dStricmp(fileInfo[i].pFullPath, fromName) ? 1 : 0), tempBuf, tempBuf.size, toName);
         dStrcat(toFile, "/");
         dStrcat(toFile, fileInfo[i].pFileName);

         backslash(fromFile);
         backslash(toFile);
         
#ifdef UNICODE
         convertUTF8toUTF16( tempBuf, wtempBuf, wtempBuf.size );
         convertUTF8toUTF16( tempBuf1, wtempBuf1, wtempBuf1.size );
         WCHAR* f = wtempBuf1;
         WCHAR* t = wtempBuf;
#else
         char *f = (char*)fromFile;
         char *t = (char*)toFile;
#endif

         if (!::CopyFile(f, t, nooverwrite))
         {
            // New directory should be deleted here.
            return false;
         }

      }

      return true;
   }

   return false;
}
Beispiel #3
0
void parseFromStream(CharVector& buffer, int level, Chunk& parsedChunk)
{
	VectorBuffer<char> tempBuf(buffer);
	std::istream stream(&tempBuf);

	if (parsedChunk.id == "SURF")
	{
		std::string surfName = parseString0(stream);
		std::string parentName = parseString0(stream);

		addStringToContents(parsedChunk.contents, surfName);
		addStringToContents(parsedChunk.contents, parentName);
	}

	if (parsedChunk.id == "IMAP")
	{
		std::string ordinal = parseString0(stream);
		addStringToContents(parsedChunk.contents, ordinal);
	}

	while (!stream.eof())
	{
		// Read header
		Chunk chunk;

		char id[5];
		stream.read(id, 4);
		id[4] = '\0';

		chunk.id = id;

		if (stream.eof()) break;

		if (parsedChunk.id == "SURF" || parsedChunk.id == "BLOK" ||
			parsedChunk.id == "IMAP" || parsedChunk.id == "TMAP")
		{
			uint16_t size;
			stream.read((char*)&size, 2);
			size = reverse(size);
			chunk.size = size;
			chunk.chunkSizeBytes = 2;
		}
		else
		{
			uint32_t size;
			stream.read((char*)&size, 4);
			size = reverse(size);
			chunk.size = size;
			chunk.chunkSizeBytes = 4;
		}

		assert(!stream.fail());

		//std::string indent(level * 2, ' ');
		//std::cout << indent << id << " with size " << chunk.size << " bytes" << std::endl;

		// Check size restrictions
		assert(4 + chunk.chunkSizeBytes + chunk.size <= buffer.size());

		uint32_t dataSize = chunk.size;

		if (chunk.id == "FORM")
		{
			// LWO doesn't have the correct size?
			if (dataSize + 4 + 4 != buffer.size())
			{
				std::cout << "ERROR: FORM Size Value + 8 Bytes is not the same as the file size." << std::endl;
				assert(false);
			}

			// Read the LWO2 tag
			char lwo2[5];
			stream.read(lwo2, 4);
			lwo2[4] = '\0';

			assert(std::string(lwo2) == "LWO2");

			chunk.contents.push_back('L');
			chunk.contents.push_back('W');
			chunk.contents.push_back('O');
			chunk.contents.push_back('2');

			dataSize -= 4;
		}

		assert(!stream.fail());

		chunk.rawData.resize(dataSize);
		stream.read(&chunk.rawData.front(), dataSize);

#if 0
		if (chunk.id == "COLR")
		{
			uint32_t colr1Raw = *((uint32_t*)&chunk.rawData[0]);
			colr1Raw = reverse(colr1Raw);
			float colr1 = *((float*)&colr1Raw);
			std::cout << colr1;
		}
#endif

		assert(!stream.fail());

		// Fill bit if size is odd
		if (dataSize % 2 == 1)
		{
			char temp;
			stream.read(&temp, 1);
			assert(temp == '\0');
			assert(!stream.fail());
		}

		parsedChunk.subChunks.push_back(chunk);
	}

	// Try to parse the subchunks
	for (Chunk& chunk : parsedChunk.subChunks)
	{
		if (chunk.id == "FORM" || chunk.id == "SURF" || chunk.id == "BLOK" ||
			chunk.id == "IMAP" || chunk.id == "TMAP")
		{
			parseFromStream(chunk.rawData, level + 1, chunk);
		}
	}
}