Skip to content

Commit

Permalink
#1264: removed httpGetSync() method
Browse files Browse the repository at this point in the history
  • Loading branch information
nesbox committed Dec 7, 2020
1 parent b196c3d commit 53eee4b
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 127 deletions.
4 changes: 2 additions & 2 deletions src/studio/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static void netDirRequest(const char* path, ListCallback callback, void* data)
sprintf(request, "/api?fn=dir&path=%s", path);

s32 size = 0;
void* buffer = getSystem()->httpGetSync(request, &size);
void* buffer = NULL;//getSystem()->httpGetSync(request, &size);

NetDirData netDirData = {callback, data};
onDirResponse(buffer, size, &netDirData);
Expand Down Expand Up @@ -892,7 +892,7 @@ void* fsLoadFileByHash(FileSystem* fs, const char* hash, s32* size)

char path[TICNAME_MAX] = {0};
sprintf(path, "/cart/%s/cart.tic", hash);
void* data = getSystem()->httpGetSync(path, size);
void* data = NULL;//getSystem()->httpGetSync(path, size);

if(data)
fsSaveRootFile(fs, cachePath, data, *size, false);
Expand Down
60 changes: 30 additions & 30 deletions src/studio/screens/surf.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,29 +398,29 @@ static void resetMenu(Surf* surf)
surf->menu.anim = 0;
}

static void* requestCover(Surf* surf, const char* hash, s32* size)
{
char cachePath[TICNAME_MAX] = {0};
sprintf(cachePath, TIC_CACHE "%s.gif", hash);
// static void* requestCover(Surf* surf, const char* hash, s32* size)
// {
// char cachePath[TICNAME_MAX] = {0};
// sprintf(cachePath, TIC_CACHE "%s.gif", hash);

{
void* data = fsLoadRootFile(surf->fs, cachePath, size);
// {
// void* data = fsLoadRootFile(surf->fs, cachePath, size);

if(data)
return data;
}
// if(data)
// return data;
// }

char path[TICNAME_MAX] = {0};
sprintf(path, "/cart/%s/cover.gif", hash);
void* data = getSystem()->httpGetSync(path, size);
// char path[TICNAME_MAX] = {0};
// sprintf(path, "/cart/%s/cover.gif", hash);
// void* data = getSystem()->httpGetSync(path, size);

if(data)
{
fsSaveRootFile(surf->fs, cachePath, data, *size, false);
}
// if(data)
// {
// fsSaveRootFile(surf->fs, cachePath, data, *size, false);
// }

return data;
}
// return data;
// }

static void updateMenuItemCover(Surf* surf, const u8* cover, s32 size)
{
Expand Down Expand Up @@ -525,18 +525,18 @@ static void loadCover(Surf* surf)
free(data);
}
}
else if(item->hash && !item->cover)
{
s32 size = 0;

u8* cover = requestCover(surf, item->hash, &size);

if(cover)
{
updateMenuItemCover(surf, cover, size);
free(cover);
}
}
// else if(item->hash && !item->cover)
// {
// s32 size = 0;

// u8* cover = requestCover(surf, item->hash, &size);

// if(cover)
// {
// updateMenuItemCover(surf, cover, size);
// free(cover);
// }
// }
}

static void initMenu(Surf* surf)
Expand Down
1 change: 0 additions & 1 deletion src/studio/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ typedef struct
u64 (*getPerformanceCounter)();
u64 (*getPerformanceFrequency)();

void* (*httpGetSync)(const char* url, s32* size);
void (*httpGet)(const char* url, HttpGetCallback callback, void* userdata);

void (*goFullscreen)();
Expand Down
9 changes: 0 additions & 9 deletions src/system/baremetalpi/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ static u64 getPerformanceFrequency()
return HZ;
}

static void* httpGetSync(const char* url, s32* size)
{
return NULL;
}

static void httpGet(const char* url, HttpGetCallback callback, void* calldata)
{

Expand Down Expand Up @@ -173,12 +168,8 @@ static System systemInterface =
.getPerformanceCounter = getPerformanceCounter,
.getPerformanceFrequency = getPerformanceFrequency,

.httpGetSync = httpGetSync,
.httpGet = httpGet,

//.fileDialogLoad = NULL, //file_dialog_load,
//.fileDialogSave = NULL, //file_dialog_save,

.goFullscreen = agoFullscreen,
.showMessageBox = showMessageBox,
.setWindowTitle = setWindowTitle,
Expand Down
10 changes: 0 additions & 10 deletions src/system/n3ds/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,6 @@ static u64 getPerformanceFrequency()
return SYSCLOCK_ARM11;
}

static void* httpGetSync(const char* url, s32* size)
{
#ifdef ENABLE_HTTPC
return n3ds_net_get_sync(&platform.httpc, url, size);
#else
return NULL;
#endif
}

static void httpGet(const char* url, HttpGetCallback callback, void* calldata)
{
#ifdef ENABLE_HTTPC
Expand Down Expand Up @@ -499,7 +490,6 @@ static System systemInterface =
.getPerformanceCounter = getPerformanceCounter,
.getPerformanceFrequency = getPerformanceFrequency,

.httpGetSync = httpGetSync,
.httpGet = httpGet,

.goFullscreen = goFullscreen,
Expand Down
14 changes: 0 additions & 14 deletions src/system/n3ds/net_httpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,3 @@ void n3ds_net_get(tic_n3ds_net *net, const char *url, HttpGetCallback callback,
svcGetThreadPriority(&priority, CUR_THREAD_HANDLE);
threadCreate((ThreadFunc) n3ds_net_get_thread, ctx, 16 * 1024, priority - 1, -1, true);
}

void* n3ds_net_get_sync(tic_n3ds_net *net, const char *url, s32 *size) {
net_ctx ctx;
memset(&ctx, 0, sizeof(net_ctx));

n3ds_net_apply_url(&ctx, url);
ctx.net = net;
n3ds_net_execute(&ctx, true);

if (size != NULL) {
*size = ctx.size;
}
return ctx.buffer;
}
1 change: 0 additions & 1 deletion src/system/n3ds/net_httpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ typedef struct {
void n3ds_net_init(tic_n3ds_net *net, LightLock *tick_lock);
void n3ds_net_free(tic_n3ds_net *net);
void n3ds_net_get(tic_n3ds_net *net, const char *url, HttpGetCallback callback, void *calldata);
void* n3ds_net_get_sync(tic_n3ds_net *net, const char *url, s32 *size);
47 changes: 0 additions & 47 deletions src/system/net/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ struct Net
{
const char* host;
CURLM* multi;
struct Curl_easy* sync;
};

static size_t writeCallbackSync(void *contents, size_t size, size_t nmemb, void *userp)
Expand Down Expand Up @@ -232,47 +231,6 @@ void netGet(Net* net, const char* path, HttpGetCallback callback, void* calldata
#endif
}

void* netGetSync(Net* net, const char* path, s32* size)
{
#ifdef DISABLE_NETWORKING

return NULL;

#else
#if defined(__EMSCRIPTEN__)

return NULL;

#else

CurlData data = {NULL, 0};

if(net->sync)
{
char url[URL_SIZE];
strcpy(url, net->host);
strcat(url, path);

curl_easy_setopt(net->sync, CURLOPT_URL, url);
curl_easy_setopt(net->sync, CURLOPT_WRITEDATA, &data);

if(curl_easy_perform(net->sync) == CURLE_OK)
{
long httpCode = 0;
curl_easy_getinfo(net->sync, CURLINFO_RESPONSE_CODE, &httpCode);
if(httpCode != 200) return NULL;
}
else return NULL;
}

*size = data.size;

return data.buffer;

#endif
#endif
}

void netTick(Net *net)
{
#if !defined(__EMSCRIPTEN__)
Expand Down Expand Up @@ -357,12 +315,9 @@ Net* createNet(const char* host)
{
*net = (Net)
{
.sync = curl_easy_init(),
.multi = curl_multi_init(),
.host = host,
};

curl_easy_setopt(net->sync, CURLOPT_WRITEFUNCTION, writeCallbackSync);
}

#endif
Expand All @@ -373,8 +328,6 @@ Net* createNet(const char* host)
void closeNet(Net* net)
{
#if !defined(__EMSCRIPTEN__)
if(net->sync)
curl_easy_cleanup(net->sync);

if(net->multi)
curl_multi_cleanup(net->multi);
Expand Down
1 change: 0 additions & 1 deletion src/system/net/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
typedef struct Net Net;

Net* createNet(const char* host);
void* netGetSync(Net* net, const char* path, s32* size);
void netGet(Net* net, const char* url, HttpGetCallback callback, void* calldata);
void closeNet(Net* net);
void netTick(Net *net);
6 changes: 0 additions & 6 deletions src/system/sdl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,11 +1329,6 @@ static void openSystemPath(const char* path) {}

#endif

static void* httpGetSync(const char* url, s32* size)
{
return netGetSync(platform.net, url, size);
}

static void httpGet(const char* url, HttpGetCallback callback, void* calldata)
{
netGet(platform.net, url, callback, calldata);
Expand Down Expand Up @@ -1414,7 +1409,6 @@ static System systemInterface =
.getPerformanceCounter = getPerformanceCounter,
.getPerformanceFrequency = getPerformanceFrequency,

.httpGetSync = httpGetSync,
.httpGet = httpGet,

.goFullscreen = goFullscreen,
Expand Down
6 changes: 0 additions & 6 deletions src/system/sokol/sokol.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ static u64 getPerformanceFrequency()
return 1000000000;
}

static void* httpGetSync(const char* url, s32* size)
{
return netGetSync(platform.net, url, size);
}

static void httpGet(const char* url, HttpGetCallback callback, void* calldata)
{
return netGet(platform.net, url, callback, calldata);
Expand Down Expand Up @@ -151,7 +146,6 @@ static System systemInterface =
.getPerformanceCounter = getPerformanceCounter,
.getPerformanceFrequency = getPerformanceFrequency,

.httpGetSync = httpGetSync,
.httpGet = httpGet,

.goFullscreen = goFullscreen,
Expand Down

0 comments on commit 53eee4b

Please sign in to comment.