Exemple #1
0
LPSTR MakeRequest(HANDLE hUser, LPSTR reqUrl, LPSTR reqParamsFormat, LPSTR p1, LPSTR p2)
{
	ptrA encodedP1(mir_urlEncode(p1)), encodedP2(mir_urlEncode(p2));
	size_t size = mir_strlen(reqParamsFormat) + 1 + mir_strlen(encodedP1) + mir_strlen(encodedP2);
	LPSTR reqParams = (LPSTR)alloca(size);
	mir_snprintf(reqParams, size, reqParamsFormat, encodedP1, encodedP2);
	return HttpPost(hUser, reqUrl, reqParams);
}
static char *GetNetworkIdApi()
{
	HttpResult *httpRes = NULL;
	JsonEl *json = NULL;
	char *jsonTxt = NULL;
	char *networkId = NULL;

	CString params = ApiParamsNetworkGet(g_pref_token);
	const char *paramsTxt = TStrToStr(params);
	const char *apiHost = GetApiHost();
	bool apiHostIsHttps = IsApiHostHttps();
	httpRes = HttpPost(apiHost, API_URL, paramsTxt, apiHostIsHttps);
	free((void*)paramsTxt);
	if (!httpRes || !httpRes->IsValid())
		goto Exit;

	DWORD dataSize;
	jsonTxt = (char *)httpRes->data.getData(&dataSize);
	if (!jsonTxt)
		goto Exit;

	// we log the server's json response if there was an error, but ignore
	// the error otherwise
	json = ParseJsonToDoc(jsonTxt);
	if (!json)
		goto Exit;
	WebApiStatus status = GetApiStatus(json);
	if (WebApiStatusSuccess != status) {
		slog("GetNetworkIdApi() bad api status. json: ");
		slognl(jsonTxt);
		goto Exit;
	}

	JsonEl *resp = GetMapElByName(json, "response");
	if (!resp)
		goto Exit;

	JsonEl *networkIdEl = GetMapElByName(resp, "network_id");
	if (!networkIdEl)
		goto Exit;

	networkId = JsonElAsStringVal(networkIdEl);
	if (!networkId)
		goto Exit;
	networkId = strdup(networkId);

Exit:
	JsonElFree(json);
	delete httpRes;
	return networkId;
}
static BOOL SubmitExpiredTypoExceptions(StringTimeNode *expired)
{
	HttpResult *httpRes = NULL;
	JsonEl *json = NULL;
	char *jsonTxt = NULL;
	BOOL res = TRUE;

	if (!expired)
		return FALSE;

	char *networkId = GetNetworkId();
	if (!networkId)
		return FALSE;

	char *toDelete = GetNamesAsCommaSeparatedString(expired);
	if (!toDelete)
		return FALSE;
	slogfmt("Removing expired typo exceptions: %s\n", toDelete);
	CString params = ApiParamsNetworkTypoExceptionsRemove(g_pref_token, networkId, toDelete);
	const char *paramsTxt = TStrToStr(params);
	const char *apiHost = GetApiHost();
	bool apiHostIsHttps = IsApiHostHttps();
	httpRes = HttpPost(apiHost, API_URL, paramsTxt, apiHostIsHttps);
	free((void*)paramsTxt);
	if (!httpRes || !httpRes->IsValid())
		goto Error;

	DWORD dataSize;
	jsonTxt = (char *)httpRes->data.getData(&dataSize);
	if (!jsonTxt)
		goto Error;

	// we log the server's json response if there was an error, but ignore
	// the error otherwise
	json = ParseJsonToDoc(jsonTxt);
	if (!json)
		goto Exit;
	WebApiStatus status = GetApiStatus(json);
	if (WebApiStatusSuccess != status) {
		slog("SubmitExpiredTypoExceptions() bad api status. json: ");
		slognl(jsonTxt);
	}

Exit:
	JsonElFree(json);
	delete httpRes;
	return res;
Error:
	res = FALSE;
	goto Exit;
}
Exemple #4
0
static void SendCrashInfo(char *s)
{
    lf("SendCrashInfo(): started");
    if (str::IsEmpty(s)) {
        plog("SendCrashInfo(): s is empty");
        return;
    }

    char *boundary = "0xKhTmLbOuNdArY";
    str::Str<char> headers(256, gCrashHandlerAllocator);
    headers.AppendFmt("Content-Type: multipart/form-data; boundary=%s", boundary);

    str::Str<char> data(2048, gCrashHandlerAllocator);
    data.AppendFmt("--%s\r\n", boundary);
    data.Append("Content-Disposition: form-data; name=\"file\"; filename=\"test.bin\"\r\n\r\n");
    data.Append(s);
    data.Append("\r\n");
    data.AppendFmt("\r\n--%s--\r\n", boundary);

    HttpPost(CRASH_SUBMIT_SERVER, CRASH_SUBMIT_URL, &headers, &data);
}
Exemple #5
0
LPSTR MakeRequest(HANDLE hUser, LPSTR reqUrl, LPSTR reqParamsFormat, LPSTR p1, LPSTR p2)
{
    LPSTR encodedP1 = url_encode(p1);
    __try {
        LPSTR encodedP2 = url_encode(p2);
        __try {
            LPSTR reqParams = (LPSTR)malloc(lstrlenA(reqParamsFormat) + 1 + lstrlenA(encodedP1) + lstrlenA(encodedP2));
            __try {
                sprintf(reqParams, reqParamsFormat, encodedP1, encodedP2);
                return HttpPost(hUser, reqUrl, reqParams);
            }
            __finally {
                free(reqParams);
            }
        }
        __finally {
            free(encodedP2);
        }
    }
    __finally {
        free(encodedP1);
    }
}