Beispiel #1
0
QBox_Error QBox_Client_CallWithBinary(
	QBox_Client* self, QBox_Json** ret, const char* url, FILE* body, QBox_Int64 bodyLen)
{
	CURL* curl;
	struct curl_slist* headers;
	QBox_Error err;

	QBox_Client_initcall(self, url);

	curl = (CURL*)self->curl;
	curl_easy_setopt(curl, CURLOPT_INFILESIZE, bodyLen);
	curl_easy_setopt(curl, CURLOPT_READFUNCTION, fread);
	curl_easy_setopt(curl, CURLOPT_READDATA, body);
	curl_easy_setopt(curl, CURLOPT_POST, 1);

	char ctxLength[64];
	QBox_snprintf(ctxLength, 64, "Content-Length: %lld", bodyLen);
	headers = curl_slist_append(NULL, ctxLength);
	headers = curl_slist_append(headers, "Content-Type: application/octet-stream");

	err = self->vptr->Auth(self->auth, &headers, url, NULL, 0);
	if (err.code != 200) {
		return err;
	}

	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

	err = QBox_callex(curl, &self->b, &self->root, QBox_False);

	curl_slist_free_all(headers);

	*ret = self->root;
	return err;
}
Beispiel #2
0
QBox_Error QBox_call(CURL* curl, int bufSize, QBox_Json** ret, QBox_Bool simpleError)
{
	QBox_Error err;
	QBox_Buffer resp;
	QBox_Buffer_Init(&resp, bufSize);

	err = QBox_callex(curl, &resp, ret, simpleError);

	QBox_Buffer_Cleanup(&resp);
	return err;
}
Beispiel #3
0
QBox_Error QBox_Client_CallNoRet(QBox_Client* self, const char* url)
{
	QBox_Error err;
	QBox_Header* headers = NULL;
	CURL* curl = (CURL*)self->curl;

	QBox_Client_initcall(self, url);

	err = self->vptr->Auth(self->auth, &headers, url, NULL, 0);
	if (err.code != 200) {
		return err;
	}

	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

	return QBox_callex((CURL*)self->curl, &self->b, &self->root, QBox_False);
}
Beispiel #4
0
Datei: io.c Projekt: hzgnpu/c-sdk
static QBox_Error QBox_Io_call(
	QBox_Client* self, QBox_Io_PutRet* ret, struct curl_httppost* formpost, char* action)
{
	QBox_Error err;

	CURL* curl = QBox_Client_reset(self);
	char* url = QBox_String_Concat2(QBOX_UP_HOST, "/upload");
	struct curl_slist* headers = curl_slist_append(NULL, "Expect:");

	curl_easy_setopt(curl, CURLOPT_URL, url);
	curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

	err = QBox_callex(curl, &self->b, &self->root, QBox_False, &self->respHeader);
	if (err.code == 200 && ret != NULL) {
		ret->hash = QBox_Json_GetString(self->root, "hash", NULL);
	}

	curl_formfree(formpost);
	free(action);
	free(url);

	return err;
}