Esempio n. 1
0
int CHttpClient::ProcessURL(int iType, char *szURL, char *szPostData, char *szReferer)
{
	InitRequest(iType,szURL,szPostData,szReferer);

	Process();

	return m_iError;
}
Esempio n. 2
0
void HttpRequest::execute()
{
	_errorMessage.clear();

	if( _showDebugInfo )
	{
		Logger::update( "Download from " + _url, true );
	}

	InitRequest();

	_progress = 0;
	_status = IN_PROGRESS;

	// Check target file
	if (!_destFilename.toString().empty())
	{
		_destStream.open(_destFilename.toString().c_str(), std::ofstream::out|std::ofstream::binary);
	}

	CURLcode result = curl_easy_perform(_handle);

	if (!_destFilename.toString().empty())
	{
		_destStream.flush();
		_destStream.close();
	}

	if (_cancelFlag)
	{
		_status = ABORTED;
	}
	else
	{
		switch (result)
		{
		case CURLE_OK:
			_status = OK;
			_progress = 1.0;
			Logger::update( "  OK" );
			break;
		default:
			_status = FAILED;
			_errorMessage = curl_easy_strerror(result);
			Logger::warning( "  FAILED" );
			Logger::warning( "ERROR " + _errorMessage );
		};
	}

	curl_easy_cleanup(_handle);

	_handle = NULL;
}
Esempio n. 3
0
void HttpRequest::Perform()
{
	_errorMessage.clear();

	TraceLog::WriteLine(LOG_VERBOSE, "Initiating Download from " + _url);

	InitRequest();

	_progress = 0;
	_status = IN_PROGRESS;

	// Check target file
	if (!_destFilename.empty())
	{
		_destStream.open(_destFilename.c_str(), std::ofstream::out|std::ofstream::binary);
	}

	CURLcode result = curl_easy_perform(_handle);

	if (!_destFilename.empty())
	{
		_destStream.flush();
		_destStream.close();
	}

	if (_cancelFlag)
	{
		_status = ABORTED;
	}
	else
	{
		switch (result)
		{
		case CURLE_OK:
			_status = OK;
			_progress = 1.0;
			TraceLog::WriteLine(LOG_VERBOSE, "Download successful: " + _url);
			break;
		default:
			_status = FAILED;
			_errorMessage = curl_easy_strerror(result);
			TraceLog::WriteLine(LOG_VERBOSE, "Download failed: " + _errorMessage);
		};
	}

	curl_easy_cleanup(_handle);

	_handle = NULL;
}
Esempio n. 4
0
ALERROR CHexarcSession::ServerCommand (const CString &sMethod, const CString &sFunc, CJSONValue &Payload, CJSONValue *retResult)

//	ServerCommand
//
//	Sends a command to the server and gets back a result. We assume that we are
//	connected.
//
//	NOTE: We clobber the Payload.

	{
	//	Create the message

	CHTTPMessage Request;
	InitRequest(sMethod, sFunc, &Request);
	Request.SetBody(new CJSONMessage(Payload));

	//	Send

	return ServerCommand(Request, retResult);
	}
Esempio n. 5
0
bool CIVConnection::GetYield (LPCTSTR szIndex, double & rdYield )
{
	InitRequest();
	
	ASSERT (szIndex);
	CString strURL;
	if(-1 == m_opts.m_strURL.Find(_T("http")))
	{
		strURL  = _T("http://");
		strURL += m_opts.m_strURL;
	}
	else
		strURL = m_opts.m_strURL;


	m_strRequest = strURL + _T("/ivanalyzer.asp?sid=%s&si=2&idx=");
	m_strRequest += szIndex;

	if (! RequestData() )
		return false;
	
	rdYield = 0;

	LPCTSTR szKey = _T("Yield");
	LPCTSTR szToken = _tcsstr_nocase (m_strResult, szKey);
	if (szToken)
	{
		szToken += _tcslen (szKey) ;
		
#ifndef _UNICODE
		std::istringstream is;	
#else
		std::wistringstream is;
#endif
		is.str ( szToken);
		is >> rdYield;
	}

	return true;
}
Esempio n. 6
0
zx_status_t IntelHDADevice::Probe() {
    zx_status_t res = ZirconDevice::Connect();
    if (res != ZX_OK)
        return res;

    ihda_get_ids_req_t req;
    ihda_get_ids_resp_t resp;

    InitRequest(&req, IHDA_CMD_GET_IDS);
    res = CallDevice(req, &resp);
    if (res != ZX_OK)
        return res;

    vid_       = resp.vid;
    did_       = resp.did;
    ihda_vmaj_ = resp.ihda_vmaj;
    ihda_vmin_ = resp.ihda_vmin;
    rev_id_    = resp.rev_id;
    step_id_   = resp.step_id;

    return ZX_OK;
}
Esempio n. 7
0
bool CIVConnection::GetHIVola (LPCTSTR szSymbol, const dte_vec & dtes, hist_ranges_map & ranges)
{
	InitRequest();
	
	ASSERT (szSymbol);
	
	CString strURL;
	if(-1 == m_opts.m_strURL.Find(_T("http")))
	{
		strURL  = _T("http://");
		strURL += m_opts.m_strURL;
	}
	else
		strURL = m_opts.m_strURL;

	
	m_strRequest = strURL + _T("/ivanalyzer.asp?sid=%s&si=1&S=");
	m_strRequest += szSymbol;

	CString strDates;
	for (dte_vec::const_iterator it = dtes.begin() ; it != dtes.end(); it++ )
	{
		CString strFmt;
		strFmt.Format (_T("&D=%d"), *it );
		strDates += strFmt;
	}
	
	m_strRequest += strDates;

	if (! RequestData() )
		return false;

	ranges.clear();
	DATE dtCurrent = (long) (DATE)  COleDateTime::GetCurrentTime();
	
	LPTSTR szResult = m_strResult.GetBuffer (0);
	
	LPCTSTR szDelimit = _T("\r");
	char* szContext = NULL;
	LPTSTR szToken = _tcstok_s (szResult, szDelimit, &szContext);
	while (szToken)
	{
		LPCTSTR szKey = _T("HiVola");
		LPCTSTR szStart =  _tcsstr_nocase (szToken, szKey);

		if (szStart)
		{
			szStart += _tcslen (szKey);
			
			CHistRangeData hrData;
			long nDte = 0;
#ifndef _UNICODE
			char chSep;
			std::istringstream is;	
#else
			wchar_t chSep;		
			std::wistringstream is;
#endif
			is.str ( szStart);
			is 
				>> nDte >> chSep 
				>> hrData.m_dStrike	>> chSep  
				>> hrData.m_dHistVolaHigh >> chSep
				>> hrData.m_dHistVolaLow >> chSep
				>> hrData.m_bATM;


			long dtExp = static_cast<long>(dtCurrent) + nDte;
			ranges.insert ( std::make_pair (dtExp, hrData)  );
		}
		szToken = _tcstok_s (NULL, szDelimit, &szContext);

	}

	m_strResult.ReleaseBuffer();

	return true;
}
Esempio n. 8
0
bool CHexarcSession::Connect (CString *retsError)

//	Connect
//
//	Connect to the server (if not already connected)

	{
	//	Already connected?

	if (m_Session.IsConnected())
		return true;

	//	Need host and root URL

	if (m_sHost.IsBlank() || m_sRootURL.IsBlank())
		{
		*retsError = ERR_NO_SERVER_DEFINED;
		return false;
		}

	//	Connect to host

	EInetsErrors iError = m_Session.Connect(m_sHost, m_sPort);
	if (iError != inetsOK)
		{
		switch (iError)
			{
			case inetsDNSError:
				*retsError = strPatternSubst(ERR_DNS_ERROR, GetHostspec());
				kernelDebugLogMessage(*retsError);
				return false;

			case inetsCannotConnect:
				*retsError = strPatternSubst(ERR_CONNECT_ERROR, GetHostspec());
				kernelDebugLogMessage(*retsError);
				return false;

			default:
				*retsError = strPatternSubst(ERR_INTERNAL, GetHostspec());
				kernelDebugLogMessage(*retsError);
				return false;
			}
		}

	//	Compose a connect payload

	CJSONValue Payload(CJSONValue::typeObject);
	Payload.InsertHandoff(FIELD_CLIENT_ID, CJSONValue(m_sClientID));
	Payload.InsertHandoff(FIELD_CLIENT_VERSION, CJSONValue(GetClientVersion()));
	Payload.InsertHandoff(FIELD_PROTOCOL_VERSION, CJSONValue(TRANS_SERVICE_VERSION));
	if (!m_sUsername.IsBlank())
		Payload.InsertHandoff(FIELD_USERNAME, CJSONValue(m_sUsername));

	//	Now issue the connect command

	CHTTPMessage Request;
	InitRequest(METHOD_POST, FUNC_CONNECT_CLIENT, &Request);
	Request.SetBody(new CJSONMessage(Payload));

	//	Send the request and wait for response

	CHTTPMessage Response;
	if (iError = m_Session.Send(Request, &Response))
		{
		m_Session.Disconnect();
		*retsError = strPatternSubst(ERR_REQUEST_FAILED, GetHostspec());
		kernelDebugLogMessage(*retsError);
		return false;
		}

	//	If we got a 301 redirect then we try the whole thing again

	if (Response.GetStatusCode() == 301)
		{
		m_Session.Disconnect();

		//	LATER: Set up the new host and recurse
		//	LATER: Keep track of recursion count, in case of ping-pong redirects
		*retsError = CONSTLIT("LATER: Redirect");
		kernelDebugLogMessage(*retsError);
		return false;
		}

	//	If we get an error, return

	else if (Response.GetStatusCode() != 200)
		{
		m_Session.Disconnect();
		*retsError = strPatternSubst(ERR_FROM_SERVER, GetHostspec(), Response.GetStatusMsg());
		kernelDebugLogMessage(*retsError);
		return false;
		}

	//	Get the JSON response

	CJSONValue ResponseData;
	if (!GetJSONResponse(Response, &ResponseData, retsError))
		{
		m_Session.Disconnect();
		*retsError = strPatternSubst(ERR_INVALID_JSON, GetHostspec(), *retsError);
		return false;
		}

	//	If this is an error, then return it

	if (CHexarc::IsError(ResponseData, NULL, retsError))
		{
		m_Session.Disconnect();
		kernelDebugLogMessage(*retsError);
		return false;
		}

	//	LATER: Process return value (challenge)

	//	Done

	return true;
	}
Esempio n. 9
0
bool ServerCommand (CHTTPClientSession &Session, const CString &sMethod, const CString &sFunc, CJSONValue &Payload, CJSONValue *retResult)

//	ServerCommand
//
//	Sends a command to the server and gets back a result. We assume that we are
//	connected.
//
//	NOTE: We clobber the Payload.

	{
	EInetsErrors iError;

	if (!Session.IsConnected())
		{
		*retResult = CJSONValue(CONSTLIT("Not connected."));
		return false;
		}

	//	Now issue the connect command

	CHTTPMessage Request;
	InitRequest(Session.GetHost(), sMethod, sFunc, &Request);
	Request.SetBody(new CJSONMessage(Payload));

	//	Send the request and wait for response

	CHTTPMessage Response;
	if (iError = Session.Send(Request, &Response))
		{
		*retResult = CJSONValue(CONSTLIT("Unable to send."));
		return false;
		}

	//	If we get an error, return

	if (Response.GetStatusCode() != 200)
		{
		*retResult = CJSONValue(Response.GetStatusMsg());
		return false;
		}

	//	Get the JSON response

	CString sError;
	if (!GetJSONResponse(Response, retResult, &sError))
		{
		*retResult = CJSONValue(strPatternSubst(CONSTLIT("Unable to parse response: %s"), sError));
		return false;
		}

	//	See if it is a server error code

	CString sErrorCode;
	CString sErrorDesc;
	if (CHexarc::IsError(*retResult, &sErrorCode, &sErrorDesc))
		{
		*retResult = CJSONValue(sErrorDesc);
		return false;
		}

	//	Done

	return true;
	}
Esempio n. 10
0
bool Connect (const CString &sHostspec, CHTTPClientSession &Session)
	{
	CString sHost;
	CString sPort;
	urlParseHostspec(sHostspec, &sHost, &sPort);

	EInetsErrors iError = Session.Connect(sHost, sPort);
	if (iError != inetsOK)
		{
		switch (iError)
			{
			case inetsDNSError:
				printf("Unable to resolve IP address for: %s\n", sHost.GetASCIIZPointer());
				return false;

			case inetsCannotConnect:
				printf("Unable to connect to: %s\n", sHostspec.GetASCIIZPointer());
				return false;

			default:
				printf("Unknown error connecting to: %s\n", sHostspec.GetASCIIZPointer());
				return false;
			}
		}

	//	Use a constant clientID (representing TransData)

	BYTE ClientIDBytes[4] = { 0, 1, 0, 1 };
	CIntegerIP ClientID(4, ClientIDBytes);
	CString sClientID = ClientID.AsBase64();

	//	Compose a connect payload

	CJSONValue Payload(CJSONValue::typeObject);
	Payload.InsertHandoff(FIELD_CLIENT_ID, CJSONValue(sClientID));
	Payload.InsertHandoff(FIELD_CLIENT_VERSION, CJSONValue(CLIENT_TYPE));
	Payload.InsertHandoff(FIELD_PROTOCOL_VERSION, CJSONValue(TRANS_SERVICE_VERSION));

	//	Now issue the connect command

	CHTTPMessage Request;
	InitRequest(sHost, METHOD_POST, FUNC_CONNECT, &Request);
	Request.SetBody(new CJSONMessage(Payload));

	//	Send the request and wait for response

	CHTTPMessage Response;
	if (iError = Session.Send(Request, &Response))
		{
		Session.Disconnect();
		printf("Unable to send to: %s\n", sHostspec.GetASCIIZPointer());
		return false;
		}

	//	If we got a 301 redirect then we try the whole thing again

	if (Response.GetStatusCode() == 301)
		{
		Session.Disconnect();

		//	LATER: Set up the new host and recurse
		//	LATER: Keep track of recursion count, in case of ping-pong redirects
		printf("REDIRECT\n");
		return false;
		}

	//	If we get an error, return

	else if (Response.GetStatusCode() != 200)
		{
		Session.Disconnect();
		printf("[%d] %s\n", Response.GetStatusCode(), Response.GetStatusMsg().GetASCIIZPointer());
		return false;
		}

	//	Get the JSON response

	CString sError;
	CJSONValue ResponseData;
	if (!GetJSONResponse(Response, &ResponseData, &sError))
		{
		Session.Disconnect();
		printf("Unable to parse JSON reply: %s\n", sError.GetASCIIZPointer());
		return false;
		}

	//	Done

	printf("Connected to %s\n", sHostspec.GetASCIIZPointer());
	return true;
	}
Esempio n. 11
0
//---------------------------------------------------------------------------
int TTrdItf_GTJA::GetStkAccount(char *LogType, char *Logid, char *ZJ, char *SH, char *SZ)//获得主股东账号
{
	char szFunid[] = "410301";

	if(InitRequest(szFunid, true) != 0)
		return -1;

	KCBPCLI_SetValue(FHandle, "inputtype", LogType);//登录类型	inputtype	char(1)	Y	见备注
	KCBPCLI_SetValue(FHandle, "inputid", Logid);//登录标识	inputid	char(64)	Y	见备注

	int nReturnCode = ExecuteRequest(szFunid);
	if( nReturnCode != 0 && nReturnCode != 100 ) //nReturnCode = 0 全部返回了,=100表示还有数据
	{
		return nReturnCode;
	}
	char szTmpbuf[20];
	if( KCBPCLI_SQLMoreResults(FHandle) == 0 )
	{

		try
		{
			bool bFlag[2] = {false, false};
			while( !KCBPCLI_RsFetchRow(FHandle) )
			{
				if( KCBPCLI_RsGetColByName( FHandle, "market", szTmpbuf ) == 0)
				{
					if(lstrcmpi(szTmpbuf, "1") == 0 && !bFlag[0])
					{
						bFlag[0] = true;
						if( KCBPCLI_RsGetColByName( FHandle, "secuid", SH) != 0)
							return -1;
					}
					else if(lstrcmpi(szTmpbuf,this->FGTJASet.bencrypt==true ? "2":"0") == 0 && !bFlag[1])
					{
						bFlag[1] = true;
						if( KCBPCLI_RsGetColByName( FHandle, "secuid", SZ) != 0)
							return -1;
					}
				}
				else
					return -1;

				if(KCBPCLI_RsGetColByName( FHandle, "fundid", ZJ ) != 0)
					return -1;

				if(KCBPCLI_RsGetColByName( FHandle, "custid", FCustid ) != 0)
					return -1;

				if(KCBPCLI_RsGetColByName( FHandle, "bankcode", FBankCode ) != 0)
					return -1;

				//ODS('M',PLUGINNAME,"银行代码:%s", FBankCode);

				if(bFlag[0] && bFlag[1])
					break;
			}
		}
		__finally
		{
			KCBPCLI_SQLCloseCursor(FHandle);
		}
	}
	else
		return -1;