From 167170c3c315e2e184de1427733411a8559343ea Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Fri, 23 Mar 2012 15:06:31 -0700 Subject: [PATCH 1/3] Add support for MIME types / Content-Type headers via GIO. Add editor modelines. --- Makefile.in | 4 +-- README | 4 +++ cloudfsapi.c | 40 +++++++++++++++++++++++++ cloudfuse.c | 41 ++++++++++++++++++++++++- config.h.in | 3 ++ configure | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++-- configure.in | 1 + 7 files changed, 172 insertions(+), 5 deletions(-) diff --git a/Makefile.in b/Makefile.in index 3159c7f..0ed5835 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,9 +2,9 @@ .SUFFIXES: .c .o CC = @CC@ -CFLAGS = @CFLAGS@ @XML_CFLAGS@ @CURL_CFLAGS@ @FUSE_CFLAGS@ @OPENSSL_CFLAGS@ +CFLAGS = @CFLAGS@ @XML_CFLAGS@ @CURL_CFLAGS@ @FUSE_CFLAGS@ @OPENSSL_CFLAGS@ @GIO_CFLAGS@ LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ @XML_LIBS@ @CURL_LIBS@ @FUSE_LIBS@ @OPENSSL_LIBS@ +LIBS = @LIBS@ @XML_LIBS@ @CURL_LIBS@ @FUSE_LIBS@ @OPENSSL_LIBS@ @GIO_LIBS@ INSTALL = @INSTALL@ MKDIR_P = @MKDIR_P@ prefix = @prefix@ diff --git a/README b/README index bc2bf04..c389f38 100644 --- a/README +++ b/README @@ -21,6 +21,10 @@ BUILDING: apt-get install build-essential libcurl4-openssl-dev libxml2-dev \ libssl-dev libfuse-dev + For MIME (Content-type header) support you need GIO. On Debian and + Ubuntu it comes with GLib: + apt-get install libglib2.0-dev + Cloudfuse is built and installed like any other autoconf configured code. Normally, ./configure diff --git a/cloudfsapi.c b/cloudfsapi.c index ba14035..e71cc91 100644 --- a/cloudfsapi.c +++ b/cloudfsapi.c @@ -16,6 +16,11 @@ #include "cloudfsapi.h" #include "config.h" +#ifdef HAVE_GIO +#include +#include +#endif + #define REQUEST_RETRIES 4 static char storage_url[MAX_URL_SIZE]; @@ -143,10 +148,21 @@ static int send_request(char *method, const char *path, FILE *fp, xmlParserCtxtP } else if (!strcasecmp(method, "PUT") && fp) { +#ifdef HAVE_GIO + gchar *guess_type; + gboolean guess_uncertain; +#endif rewind(fp); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_size(fileno(fp))); curl_easy_setopt(curl, CURLOPT_READDATA, fp); +#ifdef HAVE_GIO + guess_type = g_content_type_guess(path, NULL, 0, &guess_uncertain); + if (! guess_uncertain) { + add_header(&headers, "Content-Type", guess_type); + } + g_free(guess_type); +#endif } else if (!strcasecmp(method, "GET")) { @@ -338,8 +354,20 @@ int copy_object(const char *src, const char *dst) { char *dst_encoded = curl_escape(dst, 0); curl_slist *headers = NULL; +#ifdef HAVE_GIO + gchar *guess_type; + gboolean guess_uncertain; +#endif + add_header(&headers, "X-Copy-From", src); add_header(&headers, "Content-Length", "0"); +#ifdef HAVE_GIO + guess_type = g_content_type_guess(dst, NULL, 0, &guess_uncertain); + if (! guess_uncertain) { + add_header(&headers, "Content-Type", guess_type); + } + g_free(guess_type); +#endif int response = send_request("PUT", dst_encoded, NULL, NULL, headers); curl_free(dst_encoded); curl_slist_free_all(headers); @@ -453,3 +481,15 @@ void debugf(char *fmt, ...) } } +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 2 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=2 tabstop=8 expandtab: + * :indentSize=2:tabSize=8:noTabs=true: + */ diff --git a/cloudfuse.c b/cloudfuse.c index bf7e195..eeb0577 100644 --- a/cloudfuse.c +++ b/cloudfuse.c @@ -17,6 +17,11 @@ #include "cloudfsapi.h" #include "config.h" +#ifdef HAVE_GIO +#include +#include +#endif + #define OPTION_SIZE 1024 @@ -95,6 +100,11 @@ static void update_dir_cache(const char *path, off_t size, int isdir) dir_cache *cw; dir_entry *de; char dir[MAX_PATH_SIZE]; +#ifdef HAVE_GIO + gchar *guess_type; + gboolean guess_uncertain; +#endif + dir_for(path, dir); for (cw = dcache; cw; cw = cw->next) { @@ -114,7 +124,21 @@ static void update_dir_cache(const char *path, off_t size, int isdir) de->isdir = isdir; de->name = strdup(&path[strlen(cw->path)+1]); de->full_name = strdup(path); - de->content_type = strdup(isdir ? "application/directory" : "application/octet-stream"); + if (isdir) { + de->content_type = strdup("application/directory"); + } else { +#ifdef HAVE_GIO + guess_type = g_content_type_guess(de->name, NULL, 0, &guess_uncertain); + if (! guess_uncertain) { + de->content_type = strdup(guess_type); + } else { +#endif + de->content_type = "application/octet-stream"; + } +#ifdef HAVE_GIO + g_free(guess_type); + } +#endif de->last_modified = time(NULL); de->next = cw->entries; cw->entries = de; @@ -462,6 +486,9 @@ int main(int argc, char **argv) } cache_timeout = atoi(options.cache_timeout); +#ifdef HAVE_GIO + g_type_init(); +#endif if (!*options.username || !*options.api_key) { @@ -516,3 +543,15 @@ int main(int argc, char **argv) return fuse_main(args.argc, args.argv, &cfs_oper, &options); } +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 2 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=2 tabstop=8 expandtab: + * :indentSize=2:tabSize=8:noTabs=true: + */ diff --git a/config.h.in b/config.h.in index 05a3799..d7e4b35 100644 --- a/config.h.in +++ b/config.h.in @@ -52,6 +52,9 @@ /* Openssl headers were found */ #undef HAVE_OPENSSL +/* GIO headers were found */ +#undef HAVE_GIO + /* Define to 1 if you have the header file. */ #undef HAVE_PTHREAD_H diff --git a/configure b/configure index 3691c78..507d033 100755 --- a/configure +++ b/configure @@ -610,6 +610,8 @@ ALLOCA EGREP GREP CPP +GIO_LIBS +GIO_CFLAGS OPENSSL_LIBS OPENSSL_CFLAGS FUSE_LIBS @@ -693,8 +695,9 @@ FUSE_CFLAGS FUSE_LIBS OPENSSL_CFLAGS OPENSSL_LIBS -CPP -CPPFLAGS' +GIO_CFLAGS +GIO_LIBS +CPP' # Initialize some variables set by options. @@ -1325,6 +1328,8 @@ Some influential environment variables: C compiler flags for OPENSSL, overriding pkg-config OPENSSL_LIBS linker flags for OPENSSL, overriding pkg-config + GIO_CFLAGS C compiler flags for GIO, overriding pkg-config + GIO_LIBS linker flags for GIO, overriding pkg-config CPP C preprocessor Use these variables to override the choices made by `configure' or to help @@ -3618,6 +3623,81 @@ $as_echo "yes" >&6; } fi +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GIO" >&5 +$as_echo_n "checking for GIO... " >&6; } + +if test -n "$GIO_CFLAGS"; then + pkg_cv_GIO_CFLAGS="$GIO_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gio-2.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gio-2.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GIO_CFLAGS=`$PKG_CONFIG --cflags "gio-2.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$GIO_LIBS"; then + pkg_cv_GIO_LIBS="$GIO_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gio-2.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gio-2.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GIO_LIBS=`$PKG_CONFIG --libs "gio-2.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + GIO_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "gio-2.0" 2>&1` + else + GIO_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "gio-2.0" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$GIO_PKG_ERRORS" >&5 + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'Unable to find GIO. MIME type support disabled.'" >&5 +$as_echo "$as_me: WARNING: 'Unable to find GIO. MIME type support disabled.'" >&2;} +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'Unable to find GIO. MIME type support disabled.'" >&5 +$as_echo "$as_me: WARNING: 'Unable to find GIO. MIME type support disabled.'" >&2;} +else + GIO_CFLAGS=$pkg_cv_GIO_CFLAGS + GIO_LIBS=$pkg_cv_GIO_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define HAVE_GIO /**/" >>confdefs.h + +fi + # Checks for header files. ac_ext=c diff --git a/configure.in b/configure.in index 1289317..a72b1d4 100644 --- a/configure.in +++ b/configure.in @@ -18,6 +18,7 @@ PKG_CHECK_MODULES(XML, libxml-2.0, , AC_MSG_ERROR('Unable to find libxml2. Pleas PKG_CHECK_MODULES(CURL, libcurl, , AC_MSG_ERROR('Unable to find libcurl. Please make sure library and header files are installed.')) PKG_CHECK_MODULES(FUSE, fuse, , AC_MSG_ERROR('Unable to find libfuse. Please make sure library and header files are installed.')) PKG_CHECK_MODULES(OPENSSL, openssl, , []) +PKG_CHECK_MODULES(GIO, gio-2.0, AC_DEFINE([HAVE_GIO], [], [GIO package was found]), AC_MSG_WARN('Unable to find GIO. MIME type support disabled.')) # Checks for header files. AC_FUNC_ALLOCA From f93a14e7571fae101c0905c52b4f6f0efde496ec Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Fri, 23 Mar 2012 15:06:31 -0700 Subject: [PATCH 2/3] Add support for MIME types / Content-Type headers via GIO. Add editor modelines. --- Makefile.in | 4 +-- README | 4 +++ cloudfsapi.c | 40 +++++++++++++++++++++++++ cloudfuse.c | 41 ++++++++++++++++++++++++- config.h.in | 3 ++ configure | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++-- configure.in | 1 + 7 files changed, 172 insertions(+), 5 deletions(-) diff --git a/Makefile.in b/Makefile.in index 3159c7f..0ed5835 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,9 +2,9 @@ .SUFFIXES: .c .o CC = @CC@ -CFLAGS = @CFLAGS@ @XML_CFLAGS@ @CURL_CFLAGS@ @FUSE_CFLAGS@ @OPENSSL_CFLAGS@ +CFLAGS = @CFLAGS@ @XML_CFLAGS@ @CURL_CFLAGS@ @FUSE_CFLAGS@ @OPENSSL_CFLAGS@ @GIO_CFLAGS@ LDFLAGS = @LDFLAGS@ -LIBS = @LIBS@ @XML_LIBS@ @CURL_LIBS@ @FUSE_LIBS@ @OPENSSL_LIBS@ +LIBS = @LIBS@ @XML_LIBS@ @CURL_LIBS@ @FUSE_LIBS@ @OPENSSL_LIBS@ @GIO_LIBS@ INSTALL = @INSTALL@ MKDIR_P = @MKDIR_P@ prefix = @prefix@ diff --git a/README b/README index bc2bf04..c389f38 100644 --- a/README +++ b/README @@ -21,6 +21,10 @@ BUILDING: apt-get install build-essential libcurl4-openssl-dev libxml2-dev \ libssl-dev libfuse-dev + For MIME (Content-type header) support you need GIO. On Debian and + Ubuntu it comes with GLib: + apt-get install libglib2.0-dev + Cloudfuse is built and installed like any other autoconf configured code. Normally, ./configure diff --git a/cloudfsapi.c b/cloudfsapi.c index ba14035..e71cc91 100644 --- a/cloudfsapi.c +++ b/cloudfsapi.c @@ -16,6 +16,11 @@ #include "cloudfsapi.h" #include "config.h" +#ifdef HAVE_GIO +#include +#include +#endif + #define REQUEST_RETRIES 4 static char storage_url[MAX_URL_SIZE]; @@ -143,10 +148,21 @@ static int send_request(char *method, const char *path, FILE *fp, xmlParserCtxtP } else if (!strcasecmp(method, "PUT") && fp) { +#ifdef HAVE_GIO + gchar *guess_type; + gboolean guess_uncertain; +#endif rewind(fp); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_size(fileno(fp))); curl_easy_setopt(curl, CURLOPT_READDATA, fp); +#ifdef HAVE_GIO + guess_type = g_content_type_guess(path, NULL, 0, &guess_uncertain); + if (! guess_uncertain) { + add_header(&headers, "Content-Type", guess_type); + } + g_free(guess_type); +#endif } else if (!strcasecmp(method, "GET")) { @@ -338,8 +354,20 @@ int copy_object(const char *src, const char *dst) { char *dst_encoded = curl_escape(dst, 0); curl_slist *headers = NULL; +#ifdef HAVE_GIO + gchar *guess_type; + gboolean guess_uncertain; +#endif + add_header(&headers, "X-Copy-From", src); add_header(&headers, "Content-Length", "0"); +#ifdef HAVE_GIO + guess_type = g_content_type_guess(dst, NULL, 0, &guess_uncertain); + if (! guess_uncertain) { + add_header(&headers, "Content-Type", guess_type); + } + g_free(guess_type); +#endif int response = send_request("PUT", dst_encoded, NULL, NULL, headers); curl_free(dst_encoded); curl_slist_free_all(headers); @@ -453,3 +481,15 @@ void debugf(char *fmt, ...) } } +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 2 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=2 tabstop=8 expandtab: + * :indentSize=2:tabSize=8:noTabs=true: + */ diff --git a/cloudfuse.c b/cloudfuse.c index bf7e195..eeb0577 100644 --- a/cloudfuse.c +++ b/cloudfuse.c @@ -17,6 +17,11 @@ #include "cloudfsapi.h" #include "config.h" +#ifdef HAVE_GIO +#include +#include +#endif + #define OPTION_SIZE 1024 @@ -95,6 +100,11 @@ static void update_dir_cache(const char *path, off_t size, int isdir) dir_cache *cw; dir_entry *de; char dir[MAX_PATH_SIZE]; +#ifdef HAVE_GIO + gchar *guess_type; + gboolean guess_uncertain; +#endif + dir_for(path, dir); for (cw = dcache; cw; cw = cw->next) { @@ -114,7 +124,21 @@ static void update_dir_cache(const char *path, off_t size, int isdir) de->isdir = isdir; de->name = strdup(&path[strlen(cw->path)+1]); de->full_name = strdup(path); - de->content_type = strdup(isdir ? "application/directory" : "application/octet-stream"); + if (isdir) { + de->content_type = strdup("application/directory"); + } else { +#ifdef HAVE_GIO + guess_type = g_content_type_guess(de->name, NULL, 0, &guess_uncertain); + if (! guess_uncertain) { + de->content_type = strdup(guess_type); + } else { +#endif + de->content_type = "application/octet-stream"; + } +#ifdef HAVE_GIO + g_free(guess_type); + } +#endif de->last_modified = time(NULL); de->next = cw->entries; cw->entries = de; @@ -462,6 +486,9 @@ int main(int argc, char **argv) } cache_timeout = atoi(options.cache_timeout); +#ifdef HAVE_GIO + g_type_init(); +#endif if (!*options.username || !*options.api_key) { @@ -516,3 +543,15 @@ int main(int argc, char **argv) return fuse_main(args.argc, args.argv, &cfs_oper, &options); } +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 2 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=2 tabstop=8 expandtab: + * :indentSize=2:tabSize=8:noTabs=true: + */ diff --git a/config.h.in b/config.h.in index 05a3799..d7e4b35 100644 --- a/config.h.in +++ b/config.h.in @@ -52,6 +52,9 @@ /* Openssl headers were found */ #undef HAVE_OPENSSL +/* GIO headers were found */ +#undef HAVE_GIO + /* Define to 1 if you have the header file. */ #undef HAVE_PTHREAD_H diff --git a/configure b/configure index 3691c78..507d033 100755 --- a/configure +++ b/configure @@ -610,6 +610,8 @@ ALLOCA EGREP GREP CPP +GIO_LIBS +GIO_CFLAGS OPENSSL_LIBS OPENSSL_CFLAGS FUSE_LIBS @@ -693,8 +695,9 @@ FUSE_CFLAGS FUSE_LIBS OPENSSL_CFLAGS OPENSSL_LIBS -CPP -CPPFLAGS' +GIO_CFLAGS +GIO_LIBS +CPP' # Initialize some variables set by options. @@ -1325,6 +1328,8 @@ Some influential environment variables: C compiler flags for OPENSSL, overriding pkg-config OPENSSL_LIBS linker flags for OPENSSL, overriding pkg-config + GIO_CFLAGS C compiler flags for GIO, overriding pkg-config + GIO_LIBS linker flags for GIO, overriding pkg-config CPP C preprocessor Use these variables to override the choices made by `configure' or to help @@ -3618,6 +3623,81 @@ $as_echo "yes" >&6; } fi +pkg_failed=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GIO" >&5 +$as_echo_n "checking for GIO... " >&6; } + +if test -n "$GIO_CFLAGS"; then + pkg_cv_GIO_CFLAGS="$GIO_CFLAGS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gio-2.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gio-2.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GIO_CFLAGS=`$PKG_CONFIG --cflags "gio-2.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi +if test -n "$GIO_LIBS"; then + pkg_cv_GIO_LIBS="$GIO_LIBS" + elif test -n "$PKG_CONFIG"; then + if test -n "$PKG_CONFIG" && \ + { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"gio-2.0\""; } >&5 + ($PKG_CONFIG --exists --print-errors "gio-2.0") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; then + pkg_cv_GIO_LIBS=`$PKG_CONFIG --libs "gio-2.0" 2>/dev/null` + test "x$?" != "x0" && pkg_failed=yes +else + pkg_failed=yes +fi + else + pkg_failed=untried +fi + + + +if test $pkg_failed = yes; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then + _pkg_short_errors_supported=yes +else + _pkg_short_errors_supported=no +fi + if test $_pkg_short_errors_supported = yes; then + GIO_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "gio-2.0" 2>&1` + else + GIO_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "gio-2.0" 2>&1` + fi + # Put the nasty error message in config.log where it belongs + echo "$GIO_PKG_ERRORS" >&5 + + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'Unable to find GIO. MIME type support disabled.'" >&5 +$as_echo "$as_me: WARNING: 'Unable to find GIO. MIME type support disabled.'" >&2;} +elif test $pkg_failed = untried; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'Unable to find GIO. MIME type support disabled.'" >&5 +$as_echo "$as_me: WARNING: 'Unable to find GIO. MIME type support disabled.'" >&2;} +else + GIO_CFLAGS=$pkg_cv_GIO_CFLAGS + GIO_LIBS=$pkg_cv_GIO_LIBS + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define HAVE_GIO /**/" >>confdefs.h + +fi + # Checks for header files. ac_ext=c diff --git a/configure.in b/configure.in index 1289317..a72b1d4 100644 --- a/configure.in +++ b/configure.in @@ -18,6 +18,7 @@ PKG_CHECK_MODULES(XML, libxml-2.0, , AC_MSG_ERROR('Unable to find libxml2. Pleas PKG_CHECK_MODULES(CURL, libcurl, , AC_MSG_ERROR('Unable to find libcurl. Please make sure library and header files are installed.')) PKG_CHECK_MODULES(FUSE, fuse, , AC_MSG_ERROR('Unable to find libfuse. Please make sure library and header files are installed.')) PKG_CHECK_MODULES(OPENSSL, openssl, , []) +PKG_CHECK_MODULES(GIO, gio-2.0, AC_DEFINE([HAVE_GIO], [], [GIO package was found]), AC_MSG_WARN('Unable to find GIO. MIME type support disabled.')) # Checks for header files. AC_FUNC_ALLOCA From 185f1bcf6e761ba15b181cfbbbb0f1114b85786b Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Fri, 23 Mar 2012 17:16:56 -0700 Subject: [PATCH 3/3] Add back a missing strdup (crash bug). Add missing strdup which would result in a bad free. Be more careful about variable initial initialization and checking. --- cloudfsapi.c | 22 ++++++++++++---------- cloudfuse.c | 6 +++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cloudfsapi.c b/cloudfsapi.c index e71cc91..c82a798 100644 --- a/cloudfsapi.c +++ b/cloudfsapi.c @@ -149,8 +149,8 @@ static int send_request(char *method, const char *path, FILE *fp, xmlParserCtxtP else if (!strcasecmp(method, "PUT") && fp) { #ifdef HAVE_GIO - gchar *guess_type; - gboolean guess_uncertain; + gchar *guess_type = NULL; + gboolean guess_uncertain = TRUE; #endif rewind(fp); curl_easy_setopt(curl, CURLOPT_UPLOAD, 1); @@ -158,7 +158,7 @@ static int send_request(char *method, const char *path, FILE *fp, xmlParserCtxtP curl_easy_setopt(curl, CURLOPT_READDATA, fp); #ifdef HAVE_GIO guess_type = g_content_type_guess(path, NULL, 0, &guess_uncertain); - if (! guess_uncertain) { + if (! guess_uncertain && guess_type) { add_header(&headers, "Content-Type", guess_type); } g_free(guess_type); @@ -355,18 +355,20 @@ int copy_object(const char *src, const char *dst) char *dst_encoded = curl_escape(dst, 0); curl_slist *headers = NULL; #ifdef HAVE_GIO - gchar *guess_type; - gboolean guess_uncertain; + gchar *guess_type = NULL; + gboolean guess_uncertain = TRUE; #endif add_header(&headers, "X-Copy-From", src); add_header(&headers, "Content-Length", "0"); #ifdef HAVE_GIO - guess_type = g_content_type_guess(dst, NULL, 0, &guess_uncertain); - if (! guess_uncertain) { - add_header(&headers, "Content-Type", guess_type); + if (dst) { + guess_type = g_content_type_guess(dst, NULL, 0, &guess_uncertain); + if (! guess_uncertain && guess_type) { + add_header(&headers, "Content-Type", guess_type); + } + g_free(guess_type); } - g_free(guess_type); #endif int response = send_request("PUT", dst_encoded, NULL, NULL, headers); curl_free(dst_encoded); @@ -423,7 +425,7 @@ int cloudfs_connect(char *username, char *password, char *authurl, int use_snet) use_snet = reconnect_args.use_snet; } - + pthread_mutex_lock(&pool_mut); debugf("Authenticating..."); storage_token[0] = storage_url[0] = '\0'; diff --git a/cloudfuse.c b/cloudfuse.c index eeb0577..b0bed2b 100644 --- a/cloudfuse.c +++ b/cloudfuse.c @@ -129,11 +129,11 @@ static void update_dir_cache(const char *path, off_t size, int isdir) } else { #ifdef HAVE_GIO guess_type = g_content_type_guess(de->name, NULL, 0, &guess_uncertain); - if (! guess_uncertain) { + if (! guess_uncertain && guess_type) { de->content_type = strdup(guess_type); } else { #endif - de->content_type = "application/octet-stream"; + de->content_type = strdup("application/octet-stream"); } #ifdef HAVE_GIO g_free(guess_type); @@ -473,7 +473,7 @@ int main(int argc, char **argv) char settings_filename[MAX_PATH_SIZE] = ""; FILE *settings; struct fuse_args args = FUSE_ARGS_INIT(argc, argv); - + fuse_opt_parse(&args, &options, NULL, parse_option); snprintf(settings_filename, sizeof(settings_filename), "%s/.cloudfuse", get_home_dir());