mirror of
https://github.com/TurboGit/hubicfuse.git
synced 2026-08-02 02:42:00 +02:00
Implement mime-type recognition.
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@ @XML_CFLAGS@ @CURL_CFLAGS@ @FUSE_CFLAGS@ @OPENSSL_CFLAGS@ @JSON_CFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@ @XML_LIBS@ @CURL_LIBS@ @FUSE_LIBS@ @OPENSSL_LIBS@ @JSON_LIBS@
|
||||
LIBS = @LIBS@ @XML_LIBS@ @CURL_LIBS@ @FUSE_LIBS@ @OPENSSL_LIBS@ @JSON_LIBS@ -lmagic
|
||||
INSTALL = @INSTALL@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
prefix = @prefix@
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <magic.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
@@ -23,6 +24,7 @@
|
||||
#include "config.h"
|
||||
#include <fuse.h>
|
||||
|
||||
|
||||
#define RHEL5_LIBCURL_VERSION 462597
|
||||
#define RHEL5_CERTIFICATE_FILE "/etc/pki/tls/certs/ca-bundle.crt"
|
||||
|
||||
@@ -512,11 +514,43 @@ void cloudfs_init()
|
||||
}
|
||||
}
|
||||
|
||||
int file_exists(const char *fname)
|
||||
{
|
||||
FILE *file;
|
||||
if ( file = fopen( fname, "r" ) )
|
||||
{
|
||||
fclose( file );
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * get_mimetype ( const char *filename )
|
||||
{
|
||||
const char *mime;
|
||||
|
||||
if( file_exists( filename ) == 1 )
|
||||
{
|
||||
magic_t magic;
|
||||
|
||||
magic = magic_open( MAGIC_MIME_TYPE );
|
||||
magic_load( magic, NULL );
|
||||
magic_compile( magic, NULL );
|
||||
mime = magic_file( magic, filename );
|
||||
magic_close( magic );
|
||||
return mime;
|
||||
}
|
||||
const char *error = "application/octet-stream";
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
int cloudfs_object_read_fp(const char *path, FILE *fp)
|
||||
{
|
||||
|
||||
long flen;
|
||||
fflush(fp);
|
||||
const char *filemimetype = get_mimetype( path );
|
||||
|
||||
// determine the size of the file and segment if it is above the threshhold
|
||||
fseek(fp, 0, SEEK_END);
|
||||
@@ -574,6 +608,7 @@ int cloudfs_object_read_fp(const char *path, FILE *fp)
|
||||
add_header(&headers, "x-object-manifest", manifest);
|
||||
add_header(&headers, "x-object-meta-mtime", meta_mtime);
|
||||
add_header(&headers, "Content-Length", "0");
|
||||
add_header(&headers, "Content-Type", filemimetype);
|
||||
|
||||
int response = send_request_size("PUT", encoded, NULL, NULL, headers, 0, 0);
|
||||
curl_slist_free_all(headers);
|
||||
|
||||
@@ -58,6 +58,9 @@ long segment_above;
|
||||
char *override_storage_url;
|
||||
char *public_container;
|
||||
|
||||
int file_exists(const char *fname);
|
||||
const char * get_mimetype ( const char *filename );
|
||||
|
||||
int cloudfs_object_read_fp(const char *path, FILE *fp);
|
||||
int cloudfs_object_write_fp(const char *path, FILE *fp);
|
||||
int cloudfs_list_directory(const char *path, dir_entry **);
|
||||
|
||||
Reference in New Issue
Block a user