Esempio n. 1
0
int main(int argc, char*argv[]){
	refresh(START);

	char *rawFile,*csvfile,*sysDate;
	const char url[] = "http://codapi.zappos.biz/menus";
	float budgetVal;
	
	
	sysDate = (char*)malloc(sizeof(char)*20);
		memset(sysDate,'\0',20);

	budgetVal = validator(argc, argv);	//check the validity of the input arguments
	rawFile = readURL(url);				//Read the content from the website and get the name of the file 
	
	parseFile(rawFile);					//Performs parsing of the JSON data on the file name stored in rawFile
	
	sysDate = systemDate();				//Find the system date and save it in sysDate variable. 
	
	//Debugging statements
	//strcpy(sysDate,"2015-05-11");	
	
	returnBestList(sysDate,directoryExam());	//Use the sysdate to find the appropriate files and then perform operations.
	
	purgeFiles(directoryExam());				//Maintenance :) 
	deleteFile(rawFile);

	refresh(STOP);

	return 0;
}
Esempio n. 2
0
// Set URL
bool SoffidEssoManager::SaveURLServer (const char* url)
{
	URL_COMPONENTS urlComp;		// Initialize the URL_COMPONENTS structure.

	// Set required component lengths to non-zero so that they are cracked.
	ZeroMemory(&urlComp, sizeof(urlComp));
	urlComp.dwStructSize = sizeof(urlComp);
	WCHAR szScheme[15];
	urlComp.lpszScheme = szScheme;
	urlComp.dwSchemeLength = 14;
	WCHAR szHostName[256];
	urlComp.lpszHostName = szHostName;
	urlComp.dwHostNameLength = 255;
	WCHAR szPath[5096];
	urlComp.lpszUrlPath = szPath;
	urlComp.dwUrlPathLength = 4095;

	int strLen = mbstowcs(NULL, url, strlen(url) + 1);
	wchar_t* wUrl = (wchar_t*) malloc(strLen * sizeof(wchar_t));
	mbstowcs(wUrl, url, strlen(url) + 1);

	// Use WinHttpOpen to obtain a session handle.
	HINTERNET hSession = WinHttpOpen(SoffidEssoManager::DEF_CON_AGENT.c_str(),
			WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME,
			WINHTTP_NO_PROXY_BYPASS, 0);

	// Specify an HTTP server.
	if (hSession)
	{
		if (!WinHttpCrackUrl(wUrl, wcslen(wUrl), 0, &urlComp))
		{
			MessageBox(NULL, Utils::LoadResourcesString(8).c_str(),
					Utils::LoadResourcesString(1001).c_str(),
					MB_OK | MB_ICONEXCLAMATION);
			return false;
		}
		WinHttpSetStatusCallback(hSession, asyncCallback,
				WINHTTP_CALLBACK_FLAG_SECURE_FAILURE, 0);
	}
	else
		return false;

	// Obtener la lista de host
	size_t size;
	if (debug)
		log("Connecting to https://%ls:%d/cert\n", szHostName, urlComp.nPort);

	LPCSTR cert = readURL(hSession, szHostName, urlComp.nPort, L"/cert", true, &size);

	// Check error obtain certificate
	if (cert == NULL)
	{
		log("Error getting certificate");
		return FALSE;
	}

	std::string fileName = getMazingerDir();
	fileName += SoffidEssoManager::DEF_CERTIFICATE_NAME;

	FILE *f = fopen(fileName.c_str(), "wb");

	if (f == NULL)
	{
		log("Error generating file %s", fileName.c_str());
		return FALSE;
	}

	else
	{
		fwrite(cert, size, 1, f);
		fclose(f);
	}

	// Write certificate
	SeyconCommon::writeProperty("CertificateFile", fileName.c_str());

	// Write ESSO Server
	SeyconCommon::writeProperty("SSOServer", MZNC_wstrtostr(szHostName).c_str());

	char szPort[100];
	sprintf(szPort, "%d", urlComp.nPort);

	// Write server prot
	SeyconCommon::writeProperty("seycon.https.port", szPort);

	return true;
}