ECONFIG ReadConfigOptions()

in src/configuration/AxisConfiguration.cpp [222:330]


ECONFIG	ReadConfigOptions( int iParamCount, char * pParamArray[], char ** ppsDefaultParamList, char cSlash)
{
	ECONFIG		eConfig = eEmpty;
	OPTIONLIST	sOptions[] = {{eHTTPTransport,		"TH"},
							  {eHTTPChannel,		"C"},
							  {eHTTPSSLChannel,		"CS"},
							  {eXMLParser,			"X"},
							  {eSMTPTransport,		"TS"},
							  {eClientLog,			"CL"},
							  {eClientWSDD,			"CW"},
							  {eServerLog,			"SL"},
							  {eRootDirectory,		"A"},
							  {eOffsetToLibs,		"O"},
							  {eServerWSDD,			"SW"},
							  {eSSLOptions,			"SO"},
							  {eProgressInfo,		"PI"},
							  {eAxisConfigDir,		"ACD"},
							  {eBackup,				"B"},
							  {eQueryMissingFiles,	"QMF"},
							  {eMerge,				"M"}};

	ppsDefaultParamList[eMerge] = (char *) malloc( strlen( "off "));
	ppsDefaultParamList[eProgressInfo] = (char *) malloc( strlen( "normal "));
	ppsDefaultParamList[eBackup] = (char *) malloc( strlen( "true "));
	ppsDefaultParamList[eQueryMissingFiles] = (char *) malloc( strlen( "on "));

	strcpy( ppsDefaultParamList[eMerge], "off");
	strcpy( ppsDefaultParamList[eProgressInfo], "normal");
	strcpy( ppsDefaultParamList[eBackup], "true");
	strcpy( ppsDefaultParamList[eQueryMissingFiles], "on");

	for( int iCount = 0; iCount < iParamCount; iCount++)
	{
		if( StringCompare( pParamArray[iCount], "Client"))
		{
			eConfig = (ECONFIG)((int) eConfig | eClient);
		}
		else if( StringCompare( pParamArray[iCount], "Server"))
		{
			eConfig = (ECONFIG)((int) eConfig | eServer);
		}
		else if( StringCompare( pParamArray[iCount], "Both"))
		{
			eConfig = (ECONFIG)((int) eConfig | eClientAndServer);
		}

		if( *pParamArray[iCount] == '-')
		{
			bool	bOptionFound = false;
			int		iIndex = 0;

			do
			{
				if( !(bOptionFound = StringCompare( (pParamArray[iCount] + 1), sOptions[iIndex].pszOption)))
				{
					iIndex++;
				}
			} while( iIndex < (eConfigMax - 1) && !bOptionFound);

			if( bOptionFound)
			{
				if( ppsDefaultParamList[sOptions[iIndex].eConfType] != NULL)
				{
					free( (void *) ppsDefaultParamList[sOptions[iIndex].eConfType]);
				}

				iCount++;

				if( iCount < iParamCount)
				{
					if( ppsDefaultParamList[eOffsetToLibs] != NULL &&
						ppsDefaultParamList[eRootDirectory] != NULL &&
						!(sOptions[iIndex].eConfType == eClientLog || 
						  sOptions[iIndex].eConfType == eServerLog ||
						  sOptions[iIndex].eConfType == eBackup ||
						  sOptions[iIndex].eConfType == eMerge ||
						  sOptions[iIndex].eConfType == eQueryMissingFiles ||
						  sOptions[iIndex].eConfType == eSSLOptions) &&
						strchr( pParamArray[iCount], cSlash) == NULL)
					{
						std::string	sLocation;

						sLocation = ppsDefaultParamList[eRootDirectory];
						sLocation += cSlash;
						sLocation += ppsDefaultParamList[eOffsetToLibs];
						sLocation += cSlash;
						sLocation += pParamArray[iCount];

						ppsDefaultParamList[sOptions[iIndex].eConfType] = (char *) malloc( sLocation.length() + 1);

						strcpy( ppsDefaultParamList[sOptions[iIndex].eConfType], sLocation.c_str());
					}
					else
					{
						ppsDefaultParamList[sOptions[iIndex].eConfType] = (char *) malloc( strlen( pParamArray[iCount]) + 1);

						strcpy( ppsDefaultParamList[sOptions[iIndex].eConfType], pParamArray[iCount]);
					}
				}
			}
			else
			{
				cout << "Option: " << pParamArray[iCount] << " has been ignored." << endl;
			}
		}
	}

	return eConfig;
}