mirror of
https://github.com/logos-storage/easylibstorage.git
synced 2026-02-10 11:43:07 +00:00
132 lines
3.5 KiB
C
132 lines
3.5 KiB
C
#include "libstorage.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define FAKE_CID "zDvZRwzmAbCdEfGhIjKlMnOpQrStUvWxYz0123456789ABCD"
|
|
|
|
// A fake context to return from storage_new.
|
|
static int fake_ctx_data = 42;
|
|
bool exists = false;
|
|
|
|
void libstorageNimMain(void) {
|
|
// no-op
|
|
}
|
|
|
|
void *storage_new(const char *configJson, StorageCallback callback, void *userData) {
|
|
if (callback) {
|
|
callback(RET_OK, "ok", 2, userData);
|
|
}
|
|
return &fake_ctx_data;
|
|
}
|
|
|
|
int storage_start(void *ctx, StorageCallback callback, void *userData) {
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
if (callback) {
|
|
callback(RET_OK, "started", 7, userData);
|
|
}
|
|
return RET_OK;
|
|
}
|
|
|
|
int storage_stop(void *ctx, StorageCallback callback, void *userData) {
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
if (callback) {
|
|
callback(RET_OK, "stopped", 7, userData);
|
|
}
|
|
return RET_OK;
|
|
}
|
|
|
|
int storage_close(void *ctx, StorageCallback callback, void *userData) {
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
if (callback) {
|
|
callback(RET_OK, "closed", 6, userData);
|
|
}
|
|
return RET_OK;
|
|
}
|
|
|
|
int storage_destroy(void *ctx) {
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
return RET_OK;
|
|
}
|
|
|
|
int storage_upload_init(void *ctx, const char *filepath, size_t chunkSize, StorageCallback callback, void *userData) {
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
// Return a fake session ID
|
|
const char *session_id = "mock-session-123";
|
|
if (callback) {
|
|
callback(RET_OK, session_id, strlen(session_id), userData);
|
|
}
|
|
return RET_OK;
|
|
}
|
|
|
|
int storage_upload_file(void *ctx, const char *sessionId, StorageCallback callback, void *userData) {
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
// Fire a progress callback first, then final OK with CID
|
|
if (callback) {
|
|
callback(RET_PROGRESS, "chunk", 5, userData);
|
|
const char *cid = FAKE_CID;
|
|
callback(RET_OK, cid, strlen(cid), userData);
|
|
exists = true;
|
|
}
|
|
return RET_OK;
|
|
}
|
|
|
|
int storage_delete(void *ctx, const char *cid, StorageCallback callback, void *userData) {
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
|
|
if (callback) {
|
|
if (strcmp(cid, FAKE_CID) == 0 && exists) {
|
|
callback(RET_OK, "", 0, userData);
|
|
exists = false;
|
|
} else {
|
|
callback(RET_ERR, "Failed", 6, userData);
|
|
}
|
|
}
|
|
|
|
return RET_OK;
|
|
}
|
|
|
|
int storage_download_init(void *ctx, const char *cid, size_t chunkSize, bool local, StorageCallback callback,
|
|
void *userData) {
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
if (callback) {
|
|
callback(RET_OK, "init", 4, userData);
|
|
}
|
|
return RET_OK;
|
|
}
|
|
|
|
int storage_download_stream(void *ctx, const char *cid, size_t chunkSize, bool local, const char *filepath,
|
|
StorageCallback callback, void *userData) {
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
if (callback) {
|
|
callback(RET_PROGRESS, "data", 4, userData);
|
|
callback(RET_OK, "done", 4, userData);
|
|
}
|
|
return RET_OK;
|
|
}
|
|
|
|
int storage_spr(void *ctx, StorageCallback callback, void *userData) {
|
|
const char *resp = "spr:"
|
|
"CiUIAhIhAjWYLRhJho1LoZbaxILgJVTrHptSiejsvLKAqlumo4c4EgIDARpJCicAJQgCEiECNZgtGEmGjUuhltrEguAlVOs"
|
|
"em1KJ6Oy8soCqW6ajhzgQsdDzywYaCwoJBLtZShSRAh-"
|
|
"aGgsKCQS7WUoUkQIfmipHMEUCIQChjWYvEJE4bE55vtwyAuFvHoGqvpRouXasY7CaIg6nCQIgeCxTWoFmSCNEgMYinM7HuG"
|
|
"oCKfoRkcC1pAycNnk-z3A";
|
|
if (!ctx)
|
|
return RET_ERR;
|
|
|
|
if (callback) {
|
|
callback(RET_OK, resp, strlen(resp), userData);
|
|
}
|
|
|
|
return RET_OK;
|
|
}
|