diff options
Diffstat (limited to 'fb-helper.c')
-rw-r--r-- | fb-helper.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/fb-helper.c b/fb-helper.c index c8e4256..6e2a7fb 100644 --- a/fb-helper.c +++ b/fb-helper.c @@ -51,6 +51,7 @@ struct options { int debug; char *url; char *file; + char *apikeyfile; }; /* load the contents of file fn into data */ @@ -222,6 +223,7 @@ void display_help() printf(" -h This help\n"); printf(" -u <url> URL of pastebin or URL to download\n"); printf(" -f <file> File to upload to URL\n"); + printf(" -a <file> Path to API key file\n"); } int main(int argc, char *argv[]) @@ -251,7 +253,8 @@ int main(int argc, char *argv[]) struct options options = { .debug = 0, .file = NULL, - .url = NULL + .url = NULL, + .apikeyfile = NULL }; if (argc == 1) { @@ -259,7 +262,7 @@ int main(int argc, char *argv[]) exit(0); } - while ((opt = getopt(argc, argv, "Du:f:m:h")) != -1) { + while ((opt = getopt(argc, argv, "Du:f:m:a:h")) != -1) { switch (opt) { case 'D': options.debug = 1; break; @@ -267,6 +270,8 @@ int main(int argc, char *argv[]) case 'f': options.file = optarg; break; + case 'a': options.apikeyfile = optarg; break; + case 'h': display_help(); exit(0); @@ -296,6 +301,18 @@ int main(int argc, char *argv[]) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); } + if (options.apikeyfile) { + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "apikey", + CURLFORM_FILECONTENT, options.apikeyfile, + CURLFORM_END); + } else { + /* use .netrc settings for authentication if available */ + curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); + } + + /* if we have a file to upload, add it as a POST request */ if (options.file) { struct stat statbuf; @@ -358,9 +375,6 @@ int main(int argc, char *argv[]) curl_easy_setopt(curl, CURLOPT_URL, options.url); curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent); - /* use .netrc settings for authentication if available */ - curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); - /* bail if the upload stalls for 30 seconds */ curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1L); curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 30L); |