Exemple #1
0
CPLString VSIOSSHandleHelper::GetSignedURL(CSLConstList papszOptions)
{
    GIntBig nStartDate = static_cast<GIntBig>(time(nullptr));
    const char* pszStartDate = CSLFetchNameValue(papszOptions, "START_DATE");
    if( pszStartDate )
    {
        int nYear, nMonth, nDay, nHour, nMin, nSec;
        if( sscanf(pszStartDate, "%04d%02d%02dT%02d%02d%02dZ",
                   &nYear, &nMonth, &nDay, &nHour, &nMin, &nSec) == 6 )
        {
            struct tm brokendowntime;
            brokendowntime.tm_year = nYear - 1900;
            brokendowntime.tm_mon = nMonth - 1;
            brokendowntime.tm_mday = nDay;
            brokendowntime.tm_hour = nHour;
            brokendowntime.tm_min = nMin;
            brokendowntime.tm_sec = nSec;
            nStartDate = CPLYMDHMSToUnixTime(&brokendowntime);
        }
    }
    GIntBig nExpiresIn = nStartDate + atoi(
        CSLFetchNameValueDef(papszOptions, "EXPIRATION_DELAY", "3600"));
    CPLString osExpires(CSLFetchNameValueDef(papszOptions, "EXPIRES",
                                    CPLSPrintf(CPL_FRMT_GIB, nExpiresIn)));

    CPLString osVerb(CSLFetchNameValueDef(papszOptions, "VERB", "GET"));

    CPLString osCanonicalizedResource( m_osBucket.empty() ? CPLString("/") :
        "/" + m_osBucket +  "/" + m_osObjectKey );

    CPLString osStringToSign;
    osStringToSign += osVerb + "\n";
    osStringToSign += "\n";
    osStringToSign += "\n";
    osStringToSign += osExpires + "\n";
    // osStringToSign += ; // osCanonicalizedHeaders;
    osStringToSign += osCanonicalizedResource;
#ifdef DEBUG_VERBOSE
    CPLDebug("OSS", "osStringToSign = %s", osStringToSign.c_str());
#endif

    CPLString osSignature(GetSignature(osStringToSign, m_osSecretAccessKey));

    ResetQueryParameters();
    //  Note: https://www.alibabacloud.com/help/doc-detail/31952.htm?spm=a3c0i.o32002en.b99.294.6d70a0fc7cRJfJ is wrong on the name of the OSSAccessKeyId parameter !
    AddQueryParameter("OSSAccessKeyId", m_osAccessKeyId);
    AddQueryParameter("Expires", osExpires);
    AddQueryParameter("Signature", osSignature);
    return m_osURL;
}
AnalyticsBinding::AnalyticsBinding() :
	KEventObject("Network.Analytics"),
	running(true),
	curlHandle(0),
	startCallback(0)
{
	SharedApplication app(Host::GetInstance()->GetApplication());
	this->url = app->GetStreamURL("https") + "/app-track";

	AddQueryParameter(baseData, "mid", PlatformUtils::GetMachineId(), true);
	AddQueryParameter(baseData, "guid", app->getGUID());
	AddQueryParameter(baseData, "app_name", app->getName());
	AddQueryParameter(baseData, "app_id", app->getId());
	AddQueryParameter(baseData, "app_version", app->getVersion());
	AddQueryParameter(baseData, "sid", DataUtils::GenerateUUID());
	AddQueryParameter(baseData, "mac_addr", PlatformUtils::GetFirstMACAddress());
	AddQueryParameter(baseData, "osver", Poco::Environment::osVersion().c_str());
	AddQueryParameter(baseData, "platform", OS_NAME);
	AddQueryParameter(baseData, "version", PRODUCT_VERSION);
	AddQueryParameter(baseData, "os", Poco::Environment::osName().c_str());
	AddQueryParameter(baseData, "ostype", OS_TYPE);
	AddQueryParameter(baseData, "osarch", Poco::Environment::osArchitecture().c_str());
	AddQueryParameter(baseData, "oscpu", 
		Poco::NumberFormatter::format(PlatformUtils::GetProcessorCount()));
	AddQueryParameter(baseData, "un", PlatformUtils::GetUsername());
	AddQueryParameter(baseData, "ip", NetworkBinding::GetFirstIPAddress());
	AddQueryParameter(baseData, "ver", SPEC_VERSION);

	// The 'tz' property is the amount of minutes to add to local time to get
	// UTC time. According to: http://pocoproject.org/docs/Poco.Timezone.html
	// local time = UTC + utcOffset() + dst().
	AddQueryParameter(baseData, "tz", Poco::NumberFormatter::format(
		-(Poco::Timezone::utcOffset() + Poco::Timezone::dst()) / 60));

	this->SetMethod("_sendEvent", &AnalyticsBinding::_SendEvent);

	// When curl_easy_perform is called with an HTTPS address on Windows,
	// it seems to block the UI thread until the request initializes. This
	// causes a multi-second lag before the first page display. The most
	// important thing is to show the page as soon as possible, so we defer
	// starting the Analytics thread until the first page has loaded.
	// TODO: Figure out what is causing the blocking behavior in curl_easy_perform.
	this->startCallback = StaticBoundMethod::FromMethod(
		this, &AnalyticsBinding::_StartAnalyticsThread);
	GlobalObject::GetInstance()->AddEventListener(
		Event::PAGE_LOADED, this->startCallback);
}