Ejemplo n.º 1
0
void testIoPut()
{
	Qiniu_Error err;
	Qiniu_Client client;
	Qiniu_RS_PutPolicy putPolicy;
	Qiniu_RS_GetPolicy getPolicy;
	char* uptoken;
	char* dntoken;

	Qiniu_Client_InitMacAuth(&client, 1024, NULL);

	Qiniu_Zero(putPolicy);
	putPolicy.scope = bucket;
	uptoken = Qiniu_RS_PutPolicy_Token(&putPolicy, NULL);

	Qiniu_RS_Delete(&client, bucket, key);
	clientIoPutFile(uptoken);

	Qiniu_RS_Delete(&client, bucket, key);
	clientIoPutBuffer(uptoken);

	free(uptoken);

	Qiniu_Zero(getPolicy);
	getPolicy.scope = "*/*";
	dntoken = Qiniu_RS_GetPolicy_Token(&getPolicy, NULL);

	clientIoGet(dntoken);

	free(dntoken);

	Qiniu_Client_Cleanup(&client);
}
Ejemplo n.º 2
0
int main(int argc, char **argv) {
    Qiniu_Global_Init(-1);

    Qiniu_Client client;

    char *accessKey = getenv("QINIU_ACCESS_KEY");
    char *secretKey = getenv("QINIU_SECRET_KEY");
    char *bucket = getenv("QINIU_TEST_BUCKET");
    char *key = "qiniu.png";
    int fileType = 1;

    Qiniu_Mac mac;
    mac.accessKey = accessKey;
    mac.secretKey = secretKey;

    //init
    Qiniu_Client_InitMacAuth(&client, 1024, &mac);
    Qiniu_Error error = Qiniu_RS_ChangeType(&client, bucket, key, fileType);
    if (error.code != 200) {
        printf("change file type %s:%s error.\n", bucket, key);
        debug_log(&client, error);
    } else {
        printf("change file type %s:%s success.\n\n", bucket, key);
    }

    Qiniu_Client_Cleanup(&client);
}
Ejemplo n.º 3
0
static void clientIoPutBuffer(const char* uptoken)
{
	Qiniu_Error err;
	Qiniu_Client client;
	Qiniu_Rio_PutExtra extra;
	Qiniu_Rio_PutRet putRet;
	Qiniu_Seq seq;
	Qiniu_ReaderAt in;
	Qiniu_Int64 fsize = testFsize;

	Qiniu_Client_InitNoAuth(&client, 1024);

	Qiniu_Zero(extra);
	extra.bucket = bucket;
	extra.notify = notify;
	extra.notifyErr = notifyErr;
	extra.chunkSize = 1024;

	in = Qiniu_SeqReaderAt(&seq, fsize, 10, '0', 0);

	err = Qiniu_Rio_Put(&client, &putRet, uptoken, key, in, fsize, &extra);

	printf("\n%s", Qiniu_Buffer_CStr(&client.respHeader));
	printf("hash: %s\n", putRet.hash);

	CU_ASSERT(err.code == 200);
	CU_ASSERT_STRING_EQUAL(putRet.hash, "FoErrxvY99fW7npWmVii0RncWKme");

	Qiniu_Client_Cleanup(&client);
}
Ejemplo n.º 4
0
void testResumableIoPut(void)
{
	Qiniu_Client client;
	Qiniu_RS_PutPolicy putPolicy;
	Qiniu_RS_GetPolicy getPolicy;
	char* uptoken;
	char* dnBaseUrl;
	char* dnRequest;

	Qiniu_Client_InitMacAuth(&client, 1024, NULL);

	Qiniu_Zero(putPolicy);
	putPolicy.scope = bucket;
	uptoken = Qiniu_RS_PutPolicy_Token(&putPolicy, NULL);

	Qiniu_RS_Delete(&client, bucket, key);
	clientIoPutFile(uptoken);

	Qiniu_RS_Delete(&client, bucket, key);
	clientIoPutBuffer(uptoken);

	Qiniu_Free(uptoken);

	Qiniu_Zero(getPolicy);
	dnBaseUrl = Qiniu_RS_MakeBaseUrl(domain, key);
	dnRequest = Qiniu_RS_GetPolicy_MakeRequest(&getPolicy, dnBaseUrl, NULL);

	clientIoGet(dnRequest);

	Qiniu_Free(dnRequest);
	Qiniu_Free(dnBaseUrl);

	Qiniu_Client_Cleanup(&client);
}
Ejemplo n.º 5
0
int main(int argc, char **argv) {
    Qiniu_Client client;
    Qiniu_CDN_RefreshRet ret;
    Qiniu_Error error;
    char **p;
    int i;

    char *accessKey = getenv("QINIU_ACCESS_KEY");
    char *secretKey = getenv("QINIU_SECRET_KEY");

    Qiniu_Mac mac;
    mac.accessKey = accessKey;
    mac.secretKey = secretKey;


    //urls to refresh
    char *urls[] = {
            "http://csdk.qiniudn.com/qiniu1.png",
            "http://csdk.qiniudn.com/qiniu2.png",
            "http://csdk.qiniudn.com/qiniu3.png"
    };

    //init
    Qiniu_Zero(ret);
    Qiniu_Client_InitMacAuth(&client, 1024, &mac);
    error = Qiniu_CDN_RefreshUrls(&client, &ret, urls, 3);
    if (error.code != 200) {
        printf("refresh urls error.\n");
        debug_log(&client, error);
    } else {
        printf("refresh urls success.\n");
        printf("Code: %d\n", ret.code);
        printf("Error: %s\n", ret.error);
        printf("RequestId: %s\n", ret.requestId);

        p = ret.invalidUrls;
        for (i = 0; i < ret.invalidUrlsCount; i++) {
            printf("InvalidUrl: %s\n", *p);
            ++p;
        }

        p = ret.invalidDirs;
        for (i = 0; i < ret.invalidDirsCount; i++) {
            printf("InvalidDir: %s\n", *p);
            ++p;
        }

        printf("UrlQuotaDay: %d\n", ret.urlQuotaDay);
        printf("UrlSurplusDay: %d\n", ret.urlSurplusDay);
        printf("DirQuotaDay: %d\n", ret.dirQuotaDay);
        printf("DirSurplusDay: %d\n", ret.dirSurplusDay);

        Qiniu_Free_CDNRefreshRet(&ret);
    }
    Qiniu_Client_Cleanup(&client);
}
Ejemplo n.º 6
0
void up_chunk_upload() {
    Qiniu_Global_Init(-1);
    Qiniu_Rio_PutRet putRet;
    Qiniu_Client client;
    Qiniu_RS_PutPolicy putPolicy;
    Qiniu_Rio_PutExtra putExtra;

    char *accessKey = getenv("QINIU_ACCESS_KEY");
    char *secretKey = getenv("QINIU_SECRET_KEY");
    char *bucket = getenv("QINIU_TEST_BUCKET");
	char *key = "2017/08/12/upload.mp4";
	char *localFile = "E:\\Data\\upload.mp4";

    Qiniu_Mac mac;
    mac.accessKey = accessKey;
    mac.secretKey = secretKey;

    Qiniu_Zero(putPolicy);
    Qiniu_Zero(putExtra);

    putPolicy.scope = bucket;
    char *uptoken = Qiniu_RS_PutPolicy_Token(&putPolicy, &mac);

    //设置机房域名
    //Qiniu_Use_Zone_Beimei(Qiniu_False);
    //Qiniu_Use_Zone_Huabei(Qiniu_True);
    Qiniu_Use_Zone_Huadong(Qiniu_False);
    //Qiniu_Use_Zone_Huanan(Qiniu_True);

    //put extra
    //putExtra.upHost="http://nbxs-gate-up.qiniu.com";
    putExtra.mimeType="video/x-mp4";

    //init
    Qiniu_Client_InitMacAuth(&client, 1024, &mac);
    Qiniu_Error error = Qiniu_Rio_PutFile(&client, &putRet, uptoken, key, localFile, &putExtra);
    if (error.code != 200) {
        printf("upload file %s:%s error.\n", bucket, key);
        debug_log(&client, error);
    } else {
        /*200, 正确返回了, 你可以通过statRet变量查询一些关于这个文件的信息*/
        printf("upload file %s:%s success.\n\n", bucket, key);
        printf("key:\t%s\n", putRet.key);
        printf("hash:\t%s\n", putRet.hash);
    }

    Qiniu_Free(uptoken);
    Qiniu_Client_Cleanup(&client);
}
Ejemplo n.º 7
0
static void clientIoPutFile(const char* uptoken)
{
	Qiniu_Error err;
	Qiniu_Client client;
	Qiniu_Io_PutExtra extra;
	Qiniu_Io_PutRet putRet;

	Qiniu_Client_InitNoAuth(&client, 1024);

	Qiniu_Zero(extra);
	extra.bucket = bucket;

	err = Qiniu_Io_PutFile(&client, &putRet, uptoken, key, __FILE__, &extra);
	CU_ASSERT(err.code == 200);

	printf("\n%s\n", Qiniu_Buffer_CStr(&client.respHeader));
	printf("hash: %s\n", putRet.hash);

	Qiniu_Client_Cleanup(&client);
}
Ejemplo n.º 8
0
int main(int argc, char **argv) {
    Qiniu_RS_StatRet statRet;
    Qiniu_Client client;

    char *accessKey = getenv("QINIU_ACCESS_KEY");
    char *secretKey = getenv("QINIU_SECRET_KEY");
    char *bucket = getenv("QINIU_TEST_BUCKET");

    if (str_empty(accessKey) || str_empty(accessKey) || str_empty(bucket)) {
        printf("please fill `test-env.sh` and then run `source test-env.sh` first\n");
        return -1;
    }

    char *key = "qiniu.png";

    Qiniu_Mac mac;
    mac.accessKey = accessKey;
    mac.secretKey = secretKey;

    Qiniu_Use_Zone_Huadong(Qiniu_True);
    //init
    Qiniu_Client_InitMacAuth(&client, 1024, &mac);
    Qiniu_Error error = Qiniu_RS_Stat(&client, &statRet, bucket, key);
    if (error.code != 200) {
        printf("stat file %s:%s error.\n", bucket, key);
        debug_log(&client, error);
    } else {
        /*200, 正确返回了, 你可以通过statRet变量查询一些关于这个文件的信息*/
        printf("stat file \t%s:%s success.\n\n", bucket, key);
        printf("file hash: \t%s\n", statRet.hash);
        printf("file size: \t%lld\n", statRet.fsize);
        printf("file put time: \t%lld\n", statRet.putTime);
        printf("file mime type: \t%s\n", statRet.mimeType);
        printf("file type: \t%lld\n", statRet.type);
    }

    Qiniu_Client_Cleanup(&client);
}
Ejemplo n.º 9
0
static void clientIoPutBuffer(const char* uptoken)
{
	const char text[] = "Hello, world!";

	Qiniu_Error err;
	Qiniu_Client client;
	Qiniu_Io_PutExtra extra;
	Qiniu_Io_PutRet putRet;

	Qiniu_Client_InitNoAuth(&client, 1024);

	Qiniu_Zero(extra);
	extra.bucket = bucket;

	err = Qiniu_Io_PutBuffer(&client, &putRet, uptoken, key, text, sizeof(text)-1, &extra);

	printf("\n%s", Qiniu_Buffer_CStr(&client.respHeader));
	printf("hash: %s\n", putRet.hash);

	CU_ASSERT(err.code == 200);
	CU_ASSERT_STRING_EQUAL(putRet.hash, "FpQ6cC0G80WZruH42o759ylgMdaZ");

	Qiniu_Client_Cleanup(&client);
}
Ejemplo n.º 10
0
int main(int argc, char * argv[])
{
	Qiniu_Client client;
	Qiniu_Mac    mac;

	char * bucketName = "test";
	char * file_path = "./local.txt";

	mac.accessKey = "Hw_2_emX0FV5fe26brBCemk3Yhdzd5l86UwfI9_n";
	mac.secretKey = "V09N6hmt3Z4vieC7Ps3g6HAyQ136cGSmAj7UtjWv";

	Qiniu_Servend_Init(-1);
	Qiniu_Client_InitNoAuth(&client, 1024);

#if 0 //upload
	Qiniu_RS_PutPolicy putPolicy;
	Qiniu_Zero(putPolicy);
	putPolicy.scope = "test";
	char * uploadtoken = Qiniu_RS_PutPolicy_Token(&putPolicy, &mac);
	
	Qiniu_Io_PutRet putRet;
	Qiniu_Error error = Qiniu_Io_PutFile(&client, &putRet, uploadtoken, "local.txt", "./local.txt", NULL);
	if (error.code != 200) 
	{
		printf("!200 ERROR\n");
	}
	else
    	{
		printf("200  OK\n");
    	}

    	Qiniu_Free(uploadtoken);
#endif

#if 1 //download
	Qiniu_RS_GetPolicy getPolicy;
	Qiniu_Zero(getPolicy);

	//char* domain = Qiniu_String_Concat2("heenbo-test", "o9mmpvxgk.bkt.clouddn.com");
	char* domain = Qiniu_String_Concat2("", "o9mmpvxgk.bkt.clouddn.com");
	printf("domain:%s\n", domain);

	char * baseUrl = Qiniu_RS_MakeBaseUrl(domain, "a.txt");
	printf("baseUrl: %s\n", baseUrl);

	char * url = Qiniu_RS_GetPolicy_MakeRequest(&getPolicy, baseUrl, &mac);
	printf("url:%s\n", url);
	
	Qiniu_Free(baseUrl);
	Qiniu_Free(url);
	Qiniu_Free(domain);





#endif

	Qiniu_Client_Cleanup(&client);
	Qiniu_Servend_Cleanup();

	return 0;
}
Ejemplo n.º 11
0
int main()
{
	char AccessKey[256]={0};
	char ScreteKey[256]={0};
	char Space[64]={0};
	char Path[256]={0};

	time_t deadline;

	ReadUploadInfo("./Information.ini", AccessKey, ScreteKey, Space, Path);
	std::vector<FileInfo> fi;
	ScanAllFile(Path,fi);

	Qiniu_Client client;
	QINIU_ACCESS_KEY=(const char *)AccessKey;
	QINIU_SECRET_KEY=(const char *)ScreteKey;

	Qiniu_Servend_Init(-1);
	Qiniu_Client_InitMacAuth(&client, 1024, NULL);

	printf("\n\nStart Uploading...\n");
	for(std::vector<FileInfo>::const_iterator it = fi.begin(); it < fi.end(); ++it)
	{

		char hash[29]="";
		memcpy(hash,it->Hash,28);
		bool ft=repeatcheck(&client, Space, it->FileLocalInfo,hash);
		if (ft) continue;

		char *output;
		char encodedPutPolicy[256]={0};
		time_t deadline;
		time(&deadline);
		deadline=deadline+7200;

		unsigned char hmac_sha1code[256]={0};
		unsigned int hmac_sha1code_length;
		char encodesign[512]={0};

		char scope[256]="";

		cJSON *fmt;
		fmt=cJSON_CreateObject();
		sprintf_s(scope,256,"%s:%s",Space,it->FileLocalInfo);
		cJSON_AddStringToObject(fmt,"scope",scope);
		cJSON_AddNumberToObject(fmt,"deadline",deadline);

		output=cJSON_Print(fmt);
		printf("%s\n",output);

		//Get Code 3£ºencodedPutPolicy
		size_t destlength=urlsafe_b64_encode(output,strlen(output),encodedPutPolicy,256);

		printf("encodedPutPolicy=%s\n",encodedPutPolicy);
		//Get Code 2£ºencodesign
		unsigned char *sign = HMAC(EVP_sha1(),ScreteKey,strlen(ScreteKey), 
									(const unsigned char *)encodedPutPolicy,destlength,
									(unsigned char *) hmac_sha1code,
									&hmac_sha1code_length);

		destlength=urlsafe_b64_encode(hmac_sha1code,strlen((const char *)hmac_sha1code),encodesign,256);

		char UpLoadToken[1024];
		sprintf_s(UpLoadToken,"%s:%s:%s",AccessKey,encodesign,encodedPutPolicy);
		
		char *LocalHashCode=upload(&client, UpLoadToken, it->FileLocalInfo, it->FileGlobalInfo);
		//if (LocalHashCode == NULL)
		//{
		//	int uploadflag=resumable_upload(&client, UpLoadToken, 
		//					it->FileLocalInfo, it->FileGlobalInfo,Space);
		//}
		free(output);

	}
	printf("\n\nStop Uploading...\n");
	Qiniu_Client_Cleanup(&client);
	Qiniu_Servend_Cleanup();
}
Ejemplo n.º 12
0
int main(int argc, char **argv) {
    Qiniu_Client client;
    Qiniu_CDN_FluxRet ret;
    Qiniu_Error error;
    int i, j;

    char *accessKey = getenv("QINIU_ACCESS_KEY");
    char *secretKey = getenv("QINIU_SECRET_KEY");

    Qiniu_Mac mac;
    mac.accessKey = accessKey;
    mac.secretKey = secretKey;


    //urls to refresh
    char *domains[] = {
            "csdk.qiniudn.com",
            "javasdk.qiniudn.com"
    };
    int domainsCount = 2;
    char *startDate = "2017-08-01";
    char *endDate = "2017-08-09";
    char *g = "day";

    //init
    Qiniu_Zero(ret);
    Qiniu_Client_InitMacAuth(&client, 1024, &mac);
    error = Qiniu_CDN_GetFluxData(&client, &ret, startDate, endDate, g, domains, domainsCount);
    if (error.code != 200) {
        printf("get domain flux error.\n");
        debug_log(&client, error);
    } else {
        printf("get domain flux success.\n\n");
        printf("Code: %d\n", ret.code);
        printf("Error: %s\n", ret.error);
        printf("Domains: %d\n", ret.domainsCount);

        printf("-----------\n");

        for (i = 0; i < ret.timeCount; i++) {
            printf("%s\t", ret.time[i]);
        }
        printf("\n");

        //data
        for (i = 0; i < ret.domainsCount; i++) {
            printf("Domain:%s\n", domains[i]);
            Qiniu_CDN_FluxData fluxData = ret.data[i];
            if (fluxData.chinaCount == 0) {
                printf("China: no flux data\n");
            } else {
                printf("China: flux data\n");
                for (j = 0; j < fluxData.chinaCount; j++) {
                    printf("%lld\t", fluxData.china[j]);
                }
                printf("\n");
            }

            if (fluxData.overseaCount == 0) {
                printf("Oversea: no flux data\n");
            } else {
                printf("Oversea: flux data\n");
                for (j = 0; j < fluxData.overseaCount; j++) {
                    printf("%lld\t", fluxData.oversea[j]);
                }
                printf("\n");
            }
            printf("-----------\n");
        }


        Qiniu_Free_CDNFluxRet(&ret);
    }
    Qiniu_Client_Cleanup(&client);
}