From c11b26e1f75b643997787b76f5181731058a28f9 Mon Sep 17 00:00:00 2001 From: kaa Date: Sun, 19 Nov 2023 00:56:10 -0800 Subject: Basis for directory listing and file download. --- canup.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'canup.c') diff --git a/canup.c b/canup.c index f7bfa2d..ffb5ba1 100644 --- a/canup.c +++ b/canup.c @@ -1,4 +1,4 @@ -#define _BSD_SOURCE +#define _BSD_SOURCE /* Needed for popen(3) on Linux. */ #include #include #include @@ -6,10 +6,7 @@ #include #include "config.h" -#define MAXPATH 1024 -#define MAXCMD 4096 - -char *upload_key; +char *url = "https://sdccd.instructure.com/api/v1/users/self/files"; char * json_match(char *JSON, char *key) @@ -51,9 +48,9 @@ int upfile(char *name, char *rdir) { printf("%s/%s\n", rdir, name); - char *cmd = calloc(MAXCMD, sizeof(char)); + char *cmd = calloc(cmdsize, sizeof(char)); char *dir = strip_fn(name); - snprintf(cmd, MAXCMD, "curl -s '%s' -F 'name=%s'" + snprintf(cmd, cmdsize, "curl -s '%s' -F 'name=%s'" " -F 'parent_folder_path=%s/%s'" " -H 'Authorization: Bearer %s'", url, name, rdir, dir, upload_key); @@ -83,7 +80,7 @@ upfile(char *name, char *rdir) return -1; } - snprintf(cmd, MAXCMD, "curl -s '%s' -F 'key=%s'" + snprintf(cmd, cmdsize, "curl -s '%s' -F 'key=%s'" " -F 'content_type=%s' -F 'file=@%s'", upload_url, filename, content_type, name); /* Throw away output; assume that, if auth is successful, @@ -103,7 +100,7 @@ updir(DIR *dirp, char *rdir, char *dir) { DIR *nestdirp; struct dirent *dp; - char *name = calloc(MAXPATH, sizeof(char)); + char *name = calloc(pathsize, sizeof(char)); while ((dp = readdir(dirp)) != NULL) { if (strcmp(".", dp->d_name) == 0 || strcmp("..", dp->d_name) == 0) @@ -141,9 +138,9 @@ main(int argc, char **argv) return -1; } char *rdir; - rdir = calloc(MAXPATH, sizeof(char)); + rdir = calloc(pathsize, sizeof(char)); char *local; - local = calloc(MAXPATH, sizeof(char)); + local = calloc(pathsize, sizeof(char)); local[0] = '.'; int i; for (i = 1; i < argc; ++i) { -- cgit v1.2.3