diff options
author | kaa <kaa@disroot.org> | 2023-11-19 00:56:10 -0800 |
---|---|---|
committer | kaa <kaa@disroot.org> | 2023-11-19 00:56:10 -0800 |
commit | c11b26e1f75b643997787b76f5181731058a28f9 (patch) | |
tree | d186d74acbe892e17b323a884e49868ed25532fd /canls.c | |
parent | 5a30f14c78f7f82c41680b983bea4ce2fa938226 (diff) |
Basis for directory listing and file download.
Diffstat (limited to 'canls.c')
-rw-r--r-- | canls.c | 55 |
1 files changed, 55 insertions, 0 deletions
@@ -0,0 +1,55 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +enum { + bufsize = 16, +}; + +typedef char byte; + +struct listing { + long id, folder_id, size; + char *uuid, *filename, *upload_status, *content_type, *url; + char *created_at, *updated_at, *unlock_at, *lock_at, thumbnail_url; + char *modified_at, *mime_class, *media_entry_id, *category; + byte locked, hidden, hidden_for_user, locked_for_user; +}; + +typedef struct listing Listing; + +int +main() +{ + FILE* infile = fopen("dump", "r"); + if (infile == NULL) { + fprintf(stderr, "No dump provided. Run dump.sh.\n"); + } + + char buf[bufsize]; + char *contents = NULL; + int read, size = 0; + while ((read = fread(buf, 1, bufsize, infile)) > 0) { + size += read; + contents = realloc(contents, size); + memmove(&contents[size-read], buf, read); + } + + int i, j = 0; + char ch; + Listing *l = calloc(1, sizeof(Listing)); + int l_size = sizeof(Listing); + for (i = 0; i < size; i++) { + ch = contents[i]; + switch (ch) { + case '\n': + j++; + l_size += sizeof(Listing); + l = realloc(l, l_size); + break; + default: + } + } + printf("%d\n", l_size); + return 0; +} |