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 /canup.c | |
parent | 5a30f14c78f7f82c41680b983bea4ce2fa938226 (diff) |
Basis for directory listing and file download.
Diffstat (limited to 'canup.c')
-rw-r--r-- | canup.c | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -1,4 +1,4 @@ -#define _BSD_SOURCE +#define _BSD_SOURCE /* Needed for popen(3) on Linux. */ #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -6,10 +6,7 @@ #include <unistd.h> #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) { |