#define INDEV stdin #define OUTDEV stdout #define DEFAULT_BUF_SIZE 1024 #define RESERVED 5 #include #include #include #include #include "SHSSDK.h" #include "SHCSDK.h" // ¾Æ·¡´Â °³ÅëÁ¤º¸ Àü´Þ½Ã Àü´ÞµÈ ³»¿ëÀÔ´Ï´Ù. // ´Ü, cert ÆÄÀÏÀº »ùÇüҽº¿Í ÇÔ²² Àü´ÞµË´Ï´Ù. #define ID "wjthinkbig" #define PWD "wjthinkbig1@" #define FILE_PATH "./wjthinkbig295.cert" #define AUTHSTR "wjthinkbig" #define SERVICE "wjthinkbig" /* Callback Funtion */ int CallbackProc(void *param, long long int result) { // progress printf("File Transfer : %lld\n", result); // 1 : Stop // 0 : Continue return 1; } int main(void) { char service[DEFAULT_BUF_SIZE + RESERVED]; char path[DEFAULT_BUF_SIZE + RESERVED]; char service_host[DEFAULT_BUF_SIZE + RESERVED]; char auth_string[DEFAULT_BUF_SIZE + RESERVED]; char *auth_key, *auth_file; char *__service_host = NULL; char *__auth_string = NULL; HSHSDK hsdk; HSHFILELIST hsdf; int i; PSHFILE_STRUCT pshf; strcpy(service, SERVICE); if (service && !strcmp(service, SERVICE)) { auth_key = AUTHSTR; auth_file = FILE_PATH; } else { fprintf(OUTDEV, "There isn't the service ID\n"); return -1; } ///////////////////////// SSDK //////////////////////////////////////////////////////////////////// // !!! Áß¿ä !!! // SSDK °¡ End User¿¡°Ô ¹èÆ÷°¡µÇ¸é ¾ÈµË´Ï´Ù. // ±× ÀÌÀ¯´Â º¸¾È»ó Ãë¾àÁ¡ÀÌ ¹ß»ý Çϱ⶧¹®ÀÔ´Ï´Ù. // ÇØ´ç ¼Ò½º´Â »ùÇÿëÀÏ »ÓÀ̸ç, SSDK´Â ÀÎÁõ¼­¹ö¸¦ ¸¶·ÃÇÏ¿© ÇØ´ç ¼­¹ö¿¡¼­ // »ý¼ºÇØ Àü´Þ µÉ ¼ö ÀÖµµ·Ï Á¦À۵Ǿî¾ß ÇÕ´Ï´Ù. /* SSDK : get service host */ __service_host = (char *)sh_get_service_host(ID, PWD, service); if (!__service_host) { fprintf(OUTDEV, "Cannot get the service host.\n"); goto ERR_EXIT; } /* SSDK : get auth string */ __auth_string = (char *)sh_get_auth_string(ID, PWD, service, auth_key, auth_file, time(0)+100000); if (!__auth_string) { fprintf(OUTDEV, "Cannot get the auth string.\n"); goto ERR_EXIT; } ///////////////////////// SSDK //////////////////////////////////////////////////////////////////// sprintf(service_host, "%s", __service_host); sprintf(auth_string, "%s", __auth_string); /* CSDK : init */ fprintf(stderr, "service_host!!! %s\n", service_host); hsdk = sh_init(service_host, auth_string, CallbackProc, NULL); if (hsdk == NULL) { fprintf(OUTDEV, "Failed to initiate the SDK.\n"); goto ERR_EXIT; } path[0] = '\0'; /* TODO : listing base uri copy to path */ strcpy(path, "/"); /* CSDK : get list */ hsdf = sh_get_filelist(hsdk, path, 1); if (hsdf == NULL) { fprintf(OUTDEV, "Failed to retrieve the file list.\n"); goto ERR_EXIT; } for (i = 0; i< sh_get_filelist_count(hsdk, hsdf); i++) { pshf = sh_get_file(hsdk, hsdf, i); if (pshf->attr == SHFILEATTR_FOLDER) { fprintf(OUTDEV, "Folder Name : %s\n", pshf->path); } else { fprintf(OUTDEV, "file Name : %s(%lld byte)\n", pshf->path, pshf->size); } } sh_free_filelist(hsdk, hsdf); /* Upload Test */ if (!sh_upload(hsdk, "./test.txt", "/test.txt", SHWRITEPOLICY_OVERWRITE, -1, NULL)) { printf("sh_upload ERROR 1: %d, %s\n", sh_get_error_number(hsdk), sh_get_error_message(hsdk)); goto ERR_EXIT; } else { printf("sh_upload SUCCESS\n"); } /* Dowload Test */ if (!sh_download(hsdk, "/test.txt", "./test.txt", SHWRITEPOLICY_OVERWRITE, -1, NULL)) { printf("sh_download ERROR : %d, %s\n", sh_get_error_number(hsdk), sh_get_error_message(hsdk)); goto ERR_EXIT; } else { printf("sh_download SUCCESS\n"); } /* CSDK : get list */ hsdf = sh_get_filelist(hsdk, path, 1); if (hsdf == NULL) { fprintf(OUTDEV, "Failed to retrieve the file list.\n"); goto ERR_EXIT; } for (i = 0; i< sh_get_filelist_count(hsdk, hsdf); i++) { pshf = sh_get_file(hsdk, hsdf, i); if (pshf->attr == SHFILEATTR_FOLDER) { fprintf(OUTDEV, "Folder Name : %s\n", pshf->path); } else { fprintf(OUTDEV, "file Name : %s(%lld byte)\n", pshf->path, pshf->size); } } sh_free_filelist(hsdk, hsdf); /* File delete test */ if (sh_delete(hsdk, "/test.txt") == 0) { printf("sh_delete ERROR : %d, %s\n", sh_get_error_number(hsdk), sh_get_error_message(hsdk)); goto ERR_EXIT; } else { printf("sh_delete SUCCESS\n"); } /* CSDK : get list */ hsdf = sh_get_filelist(hsdk, path, 1); if (hsdf == NULL) { fprintf(OUTDEV, "Failed to retrieve the file list.\n"); goto ERR_EXIT; } for (i = 0; i< sh_get_filelist_count(hsdk, hsdf); i++) { pshf = sh_get_file(hsdk, hsdf, i); if (pshf->attr == SHFILEATTR_FOLDER) { fprintf(OUTDEV, "Folder Name : %s\n", pshf->path); } else { fprintf(OUTDEV, "file Name : %s(%lld byte)\n", pshf->path, pshf->size); } } sh_free_filelist(hsdk, hsdf); sh_free(hsdk); ERR_EXIT: if(__service_host) sh_mem_free(__service_host); if(__auth_string) sh_mem_free(__auth_string); return 0; }