]> git.kaiwu.me - klib.git/commitdiff
allow to feed change key/secret/id-file
authorHeng Li <lh3@me.com>
Thu, 21 Nov 2013 05:22:33 +0000 (00:22 -0500)
committerHeng Li <lh3@me.com>
Thu, 21 Nov 2013 05:22:33 +0000 (00:22 -0500)
kurl.c
kurl.h

diff --git a/kurl.c b/kurl.c
index 3a99cc7d0b5b1d7cee4b654a66b89e27cd5dc663..76e497eca74b7ad1df5ec6ed2222a8614e53699a 100644 (file)
--- a/kurl.c
+++ b/kurl.c
@@ -157,7 +157,11 @@ kurl_t *kurl_open(const char *url, kurl_opt_t *opt)
                if (strstr(url, "s3://") == url) {
                        s3aux_t a;
                        struct curl_slist *slist = 0;
-                       a = s3_parse(url, 0, 0, 0);
+                       a = s3_parse(url, (opt? opt->s3keyid : 0), (opt? opt->s3secretkey : 0), (opt? opt->s3key_fn : 0));
+                       if (a.url == 0 || a.date == 0 || a.auth == 0) {
+                               kurl_close(ku);
+                               return 0;
+                       }
                        ku->hdr = curl_slist_append(ku->hdr, a.date);
                        ku->hdr = curl_slist_append(ku->hdr, a.auth);
                        curl_easy_setopt(ku->curl, CURLOPT_URL, a.url);
@@ -168,8 +172,6 @@ kurl_t *kurl_open(const char *url, kurl_opt_t *opt)
                curl_easy_setopt(ku->curl, CURLOPT_VERBOSE, 0L);
                curl_easy_setopt(ku->curl, CURLOPT_NOSIGNAL, 1L);
                curl_easy_setopt(ku->curl, CURLOPT_WRITEFUNCTION, write_cb);
-               if (opt && opt->usrpwd)
-                       curl_easy_setopt(ku->curl, CURLOPT_USERPWD, opt->usrpwd);
        }
        ku->m_buf = KU_DEF_BUFLEN;
        if (!kurl_isfile(ku) && ku->m_buf < CURL_MAX_WRITE_SIZE * 2)
@@ -421,10 +423,10 @@ int main(int argc, char *argv[])
 //     s3_parse("s3://lh3test/44X.bam.bai", 0, 0, 0); return 0;
 
        memset(&opt, 0, sizeof(kurl_opt_t));
-       while ((c = getopt(argc, argv, "c:l:u:")) >= 0) {
+       while ((c = getopt(argc, argv, "c:l:a:")) >= 0) {
                if (c == 'c') start = strtol(optarg, &p, 0);
                else if (c == 'l') rest = strtol(optarg, &p, 0);
-               else if (c == 'u') opt.usrpwd = optarg;
+               else if (c == 'a') opt.s3key_fn = optarg;
        }
        if (optind == argc) {
                fprintf(stderr, "Usage: kurl [-c start] [-l length] <url>\n");
diff --git a/kurl.h b/kurl.h
index a4a6487a382fa5a15f8077d93c972bcf4b5ddd3c..f07f64118a88f1327621c96c139dd0bb4fb2bdab 100644 (file)
--- a/kurl.h
+++ b/kurl.h
@@ -6,13 +6,15 @@
 #define KURL_NULL       1
 #define KURL_INV_WHENCE 2
 #define KURL_SEEK_OUT   3
-#define KURL_NO_MEM     4
+#define KURL_NO_AUTH    4
 
 struct kurl_t;
 typedef struct kurl_t kurl_t;
 
 typedef struct {
-       const char *usrpwd;
+       const char *s3keyid;
+       const char *s3secretkey;
+       const char *s3key_fn;
 } kurl_opt_t;
 
 #ifdef __cplusplus