Beispiel #1
0
static Qiniu_Error Qiniu_Io_call(
	Qiniu_Client* self, Qiniu_Io_PutRet* ret, struct curl_httppost* formpost)
{
	Qiniu_Error err;

	CURL* curl = Qiniu_Client_reset(self);
	struct curl_slist* headers = curl_slist_append(NULL, "Expect:");

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

	err = Qiniu_callex(curl, &self->b, &self->root, Qiniu_False, &self->respHeader);
	if (err.code == 200 && ret != NULL) {
		ret->hash = Qiniu_Json_GetString(self->root, "hash", NULL);
		ret->key = Qiniu_Json_GetString(self->root, "key", NULL);
	}

	curl_formfree(formpost);
	/*
	 * Bug No.(4718) Wang Xiaotao 2013\10\17 17:46:07
	 * Change for : free  variable 'headers'
	 * Reason     : memory leak!
	 */
	curl_slist_free_all(headers);
	return err;
}
Beispiel #2
0
Qiniu_Error Qiniu_Client_Call(Qiniu_Client* self, Qiniu_Json** ret, const char* url)
{
	Qiniu_Error err;
	Qiniu_Header* headers = NULL;
	CURL* curl = Qiniu_Client_initcall(self, url);

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

	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);


	err = Qiniu_callex(curl, &self->b, &self->root, Qiniu_False, &self->respHeader);
	/*
	 * Bug No.(4601) Wang Xiaotao 2013\10\12 17:09:02
	 * Change for : free  var headers 'variable'
	 * Reason     : memory leak!
	 */
    curl_slist_free_all(headers);
	*ret = self->root;
	return err;
}
Beispiel #3
0
static Qiniu_Error Qiniu_Client_callWithBody(
	Qiniu_Client* self, Qiniu_Json** ret, const char* url,
	const char* body, Qiniu_Int64 bodyLen, const char* mimeType)
{
	int retCode = 0;
	Qiniu_Error err;
	const char* ctxType;
	char ctxLength[64];
	Qiniu_Header* headers = NULL;
	CURL* curl = (CURL*)self->curl;

	// Bind the NIC for sending packets.
	if (self->boundNic != NULL) {
		retCode = curl_easy_setopt(curl, CURLOPT_INTERFACE, self->boundNic);
		if (retCode == CURLE_INTERFACE_FAILED) {
			err.code = 9994;
			err.message = "Can not bind the given NIC";
			return err;
		}
	}

	curl_easy_setopt(curl, CURLOPT_POST, 1);

	if (mimeType == NULL) {
		ctxType = "Content-Type: application/octet-stream";
	} else {
		ctxType = Qiniu_String_Concat2("Content-Type: ", mimeType);
	}

	Qiniu_snprintf(ctxLength, 64, "Content-Length: %lld", bodyLen);
	headers = curl_slist_append(NULL, ctxLength);
	headers = curl_slist_append(headers, ctxType);

	if (self->auth.itbl != NULL) {
		if (body == NULL) {
			err = self->auth.itbl->Auth(self->auth.self, &headers, url, NULL, 0);
		} else {
			err = self->auth.itbl->Auth(self->auth.self, &headers, url, body, (size_t)bodyLen);
		}

		if (err.code != 200) {
			return err;
		}
	}

	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

	err = Qiniu_callex(curl, &self->b, &self->root, Qiniu_False, &self->respHeader);

	curl_slist_free_all(headers);
	if (mimeType != NULL) {
		free((void*)ctxType);
	}

	*ret = self->root;
	return err;
}