Skip to content

Commit

Permalink
curl init cleanup, pass through s3 interface
Browse files Browse the repository at this point in the history
  • Loading branch information
benlemasurier committed Feb 2, 2012
1 parent 73e7ac2 commit 546000e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
13 changes: 8 additions & 5 deletions src/curl.c
Expand Up @@ -1967,7 +1967,7 @@ stormfs_curl_put(const char *path, GList *headers)
return result; return result;
} }


int static int
stormfs_curl_set_auth(const char *access_key, const char *secret_key) stormfs_curl_set_auth(const char *access_key, const char *secret_key)
{ {
curl.access_key = access_key; curl.access_key = access_key;
Expand All @@ -1976,7 +1976,7 @@ stormfs_curl_set_auth(const char *access_key, const char *secret_key)
return 0; return 0;
} }


int static int
stormfs_curl_verify_ssl(int verify) stormfs_curl_verify_ssl(int verify)
{ {
if(verify == 0) if(verify == 0)
Expand Down Expand Up @@ -2025,13 +2025,16 @@ share_init()
} }


int int
stormfs_curl_init(const char *bucket, const char *url) stormfs_curl_init(struct stormfs *stormfs)
{ {
CURLcode result; CURLcode result;
curl.url = url; curl.url = stormfs->virtual_url;
curl.bucket = bucket; curl.bucket = stormfs->bucket;
curl.verify_ssl = 1; curl.verify_ssl = 1;


stormfs_curl_set_auth(stormfs->access_key, stormfs->secret_key);
stormfs_curl_verify_ssl(stormfs->verify_ssl);

if((result = curl_global_init(CURL_GLOBAL_ALL)) != CURLE_OK) if((result = curl_global_init(CURL_GLOBAL_ALL)) != CURLE_OK)
return -1; return -1;
if(share_init() != 0) if(share_init() != 0)
Expand Down
4 changes: 1 addition & 3 deletions src/curl.h
Expand Up @@ -53,13 +53,11 @@ int stormfs_curl_get(const char *path, char **data);
int stormfs_curl_get_file(const char *path, FILE *f); int stormfs_curl_get_file(const char *path, FILE *f);
int stormfs_curl_head(const char *path, GList **meta); int stormfs_curl_head(const char *path, GList **meta);
int stormfs_curl_head_multi(const char *path, GList *files); int stormfs_curl_head_multi(const char *path, GList *files);
int stormfs_curl_init(const char *bucket, const char *url); int stormfs_curl_init(struct stormfs *stormfs);
int stormfs_curl_list_bucket(const char *path, char **xml); int stormfs_curl_list_bucket(const char *path, char **xml);
int stormfs_curl_put(const char *path, GList *headers); int stormfs_curl_put(const char *path, GList *headers);
int stormfs_curl_rename(const char *from, const char *to); int stormfs_curl_rename(const char *from, const char *to);
int stormfs_curl_set_auth(const char *access_key, const char *secret_key);
int stormfs_curl_upload(const char *path, GList *headers, int fd); int stormfs_curl_upload(const char *path, GList *headers, int fd);
int stormfs_curl_verify_ssl(int verify);
int copy_multipart(const char *from, const char *to, GList *headers, off_t size); int copy_multipart(const char *from, const char *to, GList *headers, off_t size);


#endif // stormfs_curl_H #endif // stormfs_curl_H
Expand Down
11 changes: 11 additions & 0 deletions src/s3.c
Expand Up @@ -76,6 +76,12 @@ xml_to_files(const char *path, char *xml)
return files; return files;
} }


void
s3_destroy(void)
{
stormfs_curl_destroy();
}

int int
s3_getattr(const char *path, struct stat *st) s3_getattr(const char *path, struct stat *st)
{ {
Expand Down Expand Up @@ -173,6 +179,11 @@ s3_init(struct stormfs *stormfs)
{ {
s3.stormfs = stormfs; s3.stormfs = stormfs;


if(stormfs_curl_init(stormfs) != 0) {
fprintf(stderr, "%s: unable to initialize libcurl\n", stormfs->progname);
exit(EXIT_FAILURE);
}

return 0; return 0;
} }


Expand Down
1 change: 1 addition & 0 deletions src/s3.h
Expand Up @@ -11,6 +11,7 @@
#ifndef s3_H #ifndef s3_H
#define s3_H #define s3_H


void s3_destroy(void);
int s3_getattr(const char *path, struct stat *st); int s3_getattr(const char *path, struct stat *st);
int s3_getattr_multi(const char *path, GList *files); int s3_getattr_multi(const char *path, GList *files);
int s3_chmod(const char *path, struct stat *st); int s3_chmod(const char *path, struct stat *st);
Expand Down
10 changes: 1 addition & 9 deletions src/stormfs.c
Expand Up @@ -1382,14 +1382,6 @@ stormfs_init(struct fuse_conn_info *conn)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }


if(stormfs_curl_init(stormfs.bucket, stormfs.virtual_url) != 0) {
fprintf(stderr, "%s: unable to initialize libcurl\n", stormfs.progname);
exit(EXIT_FAILURE);
}

stormfs_curl_set_auth(stormfs.access_key, stormfs.secret_key);
stormfs_curl_verify_ssl(stormfs.verify_ssl);

if(cache_init() != 0) { if(cache_init() != 0) {
fprintf(stderr, "%s: unable to initialize cache\n", stormfs.progname); fprintf(stderr, "%s: unable to initialize cache\n", stormfs.progname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
Expand All @@ -1402,7 +1394,7 @@ static void
stormfs_destroy(void *data) stormfs_destroy(void *data)
{ {
cache_destroy(); cache_destroy();
stormfs_curl_destroy(); s3_destroy();
free(stormfs.bucket); free(stormfs.bucket);
free(stormfs.mountpoint); free(stormfs.mountpoint);
free(stormfs.access_key); free(stormfs.access_key);
Expand Down

0 comments on commit 546000e

Please sign in to comment.