// removes the first occurance of pzMatch from the list
// or every occurance if bRemoveAllOccurances = 1
// if bMatchCase = 1 only ExAcT Case Matches are removed
// returns number of items removed.
__int64 GStringList::Remove(const char *pzMatch, int bMatchCase, int bRemoveAllOccurances)
{
	GString *p = (GString *)First();
	__int64 nItemsRemoved = 0;
	while(p)
	{
		if (bMatchCase)
		{
			if (p->Compare(pzMatch) == 0)
			{
				nItemsRemoved++;
				RemoveCurrent();
				delete p;
				if (!bRemoveAllOccurances)
					break;
			}
		}
		else
		{
			if (p->CompareNoCase(pzMatch) == 0)
			{
				nItemsRemoved++;
				RemoveCurrent();
				delete p;
				if (!bRemoveAllOccurances)
					break;
			}
		}
		p = (GString *)Next();
	}
	return nItemsRemoved;
}
// returns -1 if not found otherwise the Index
__int64 GStringList::Find(const char *pzFindWhat, int bMatchCase/* = 1*/)
{
	GString *p = (GString *)First();
	__int64 nIndex = -1;
	while(p)
	{
		nIndex++;
		if (bMatchCase)
		{
			if (p->Compare(pzFindWhat) == 0)
			{
				return nIndex;
			}
		}
		else
		{
			if (p->CompareNoCase(pzFindWhat) == 0)
			{
				return nIndex;
			}
		}
		p = (GString *)Next();
	}
	return -1; // not found
}
Beispiel #3
0
void ModifyStartupFile(GString &strStartupKey,GString &strServerPassword,GString &strRoot,GString &strPort)
{
	///////////////////////////////////////////////////////////////////
	// load the following values fron the startup file:
	//////////////////////////////////////////////////////////////////
	GString strCurrentPassword;
	GString strCurrentRoot;
	GString strCurrentPort;
	
	GString strThisEXEName(GetThisEXEName());
	GString strStartupData;
	if (strStartupKey.Length())
	{
		// look for a file in the root of the file system (c:\)
		// with the same name as this .exe
		GString strFile("c:\\");
		strFile += strThisEXEName;


		// load the crypted disk file into clear text memory
		char *pDest;
		int nDestLen;
		GString strErrorOut;
		if (FileDecryptToMemory(strStartupKey, strFile, &pDest, &nDestLen, strErrorOut))
		{
			// parse into the profile data structures
			pDest[7 + nDestLen] = 0; // null terminate it
			strStartupData.write(&pDest[7], nDestLen + 1); // and cap the GString 
		}
		else
		{
			// if the file was not in the root of the file system
			// see if there is an environment setting directing
			// this server to look for the file in another location
			// The variable name is dynamic, matching this .exe name
			// and the environment variable value must be a fully
			// qualified path and file name to the startup file.
			if (getenv(strThisEXEName))
			{
				if (FileDecryptToMemory(strStartupKey, getenv(strThisEXEName), &pDest, &nDestLen, strErrorOut))
				{
					// parse into the profile data structures
					strStartupData.write(&pDest[7], nDestLen-7);
				}
			}
		}

		// parse stored settings in startup file to startup variables
		if (strStartupData.Length())
		{
			GStringList lstOptions("&&",strStartupData);
			GStringIterator it(&lstOptions);
			
			if (it()) strCurrentPassword = it++;
			if (it()) strCurrentRoot = it++;
			if (it()) strCurrentPort = it++;
		}
	}
	//////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////


	// new values over write the old ones
	if (strServerPassword.Length())
		strCurrentPassword = strServerPassword;

	if (strPort.Length())
		strCurrentPort = strPort;

	if (strRoot.Length() && strRoot.CompareNoCase("none") != 0)
		strCurrentRoot = strRoot;
	else if (strRoot.CompareNoCase("none") == 0)
	{
		strCurrentRoot = "";
	}
	


	// use root of file system to store the startup file 
	// unless specified otherwise by environment setting
	GString strOutFile("c:\\");
	strOutFile += strThisEXEName;
	if (getenv(strThisEXEName))
	{
		strOutFile += getenv(strThisEXEName);
	}
	
	
	// create the new startup file
	GString strTempFile;
	strTempFile << strServerPassword << "&&" << strRoot << "&&" << strPort;
	strTempFile.ToFile("tempfile");
	GString strErrorOut;
	unlink(strOutFile);
	FileEncrypt(strStartupKey, "tempfile", strOutFile, strErrorOut);
	unlink("tempfile");
}
int UpdateExistingObject(JNIEnv *env, DynamicXMLObject *pJavaObjectDO,	 DynamicXMLObject * pToApplyDO, DynamicXMLObject *pDXOOwner)
{
    jboolean isCopy;
	jfieldID fid;

	GString strJavaOID;
	GString strNewOID;

	GStringIterator itKeyParts( pJavaObjectDO->GetKeyPartsList() );
	while(itKeyParts())
	{
		bool bHasOidDefined = true;
		NativeMemberDescriptor *pMD = pJavaObjectDO->FindMemberDescriptor(itKeyParts++);

		PortableCast pc;
		pc.mbrJobject = (jobject)pJavaObjectDO->getUserLanguageObject();
		if (pc.mbrInt > 0)
		{
			jclass clazz = env->GetObjectClass(pc.mbrJobject);
			if (pMD->Source == 1) // Element
				strNewOID += pToApplyDO->GetMember(pMD->strTag);
			else if (pMD->Source == 2) // Attribute
				strNewOID += pToApplyDO->FindAttribute(pMD->strTag);


			switch(pMD->DataType)
			{
	/*long*/	case 0:
				fid = env->GetFieldID(clazz, (const char *)pMD->strName, "J");
				strJavaOID += env->GetLongField(pc.mbrJobject, fid);
				break;
	/*double*/	case 1:
				fid = env->GetFieldID(clazz, (const char *)pMD->strName, "D");
				strJavaOID << env->GetDoubleField(pc.mbrJobject, fid);
				break;

	/*short*/	case 2:
				fid = env->GetFieldID(clazz, (const char *)pMD->strName, "S");
				strJavaOID << env->GetShortField(pc.mbrJobject, fid);
				break;
	/*byte*/	case 3:
				fid = env->GetFieldID(clazz, (const char *)pMD->strName, "B");
				strJavaOID << env->GetByteField(pc.mbrJobject, fid);
				break;
	/*String*/	case 4:
				fid = env->GetFieldID(clazz, (const char *)pMD->strName, "Ljava/lang/String;");
				strJavaOID += (char*) env->GetStringUTFChars( (jstring)env->GetObjectField(pc.mbrJobject,fid), &isCopy);
				break;

	/*int*/		case 5:
				fid = env->GetFieldID(clazz, (const char *)pMD->strName, "I");
				strJavaOID << env->GetIntField(pc.mbrJobject, fid);
				break;

	/*boolean*/	case 6:
				fid = env->GetFieldID(clazz, (const char *)pMD->strName, "Z");
				strJavaOID << env->GetBooleanField(pc.mbrJobject, fid);
				break;
			}
			if (strJavaOID.CompareNoCase(strNewOID) == 0)
			{
				pJavaObjectDO->ClearPreviousMembers(pToApplyDO);
				ExchangeMembers(env,"in",pJavaObjectDO,pc.mbrJobject,pDXOOwner);
				return 1;	// Updated
			}
		}
		else
		{
			// attempted to retrieve an OID from a Root object.  Rare usage but
			// there could be some case where this needs to be done.  
		}
	}
	return 0;// Not Updated
}