X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fsendfile.c;h=601661b0656ad650ec56ea08111d36f5f729ea36;hb=0328ac04990bf22e635930aa37abb8c2128a17f1;hp=4ec25a60eaf2df89b041b6d8cad4998efc767884;hpb=8f728a255f0e887b2a4f6eb814a061c124381aa2;p=ashd.git diff --git a/src/sendfile.c b/src/sendfile.c index 4ec25a6..601661b 100644 --- a/src/sendfile.c +++ b/src/sendfile.c @@ -34,6 +34,10 @@ #include #include +#ifdef HAVE_XATTR +#include +#endif + static magic_t cookie = NULL; static void passdata(int in, int out) @@ -66,10 +70,40 @@ static int strrcmp(char *str, char *end) return(strcmp(str + strlen(str) - strlen(end), end)); } +static char *attrmimetype(char *file) +{ +#ifdef HAVE_XATTR + static char buf[1024]; + int i; + ssize_t sz; + + if((sz = getxattr(file, "user.ash-mime-type", buf, sizeof(buf) - 1)) > 0) + goto found; + if((sz = getxattr(file, "user.mime-type", buf, sizeof(buf) - 1)) > 0) + goto found; + if((sz = getxattr(file, "user.mime_type", buf, sizeof(buf) - 1)) > 0) + goto found; + if((sz = getxattr(file, "user.Content-Type", buf, sizeof(buf) - 1)) > 0) + goto found; + return(NULL); +found: + for(i = 0; i < sz; i++) { + if((buf[sz] < 32) || (buf[sz] >= 128)) + return(NULL); + } + buf[sz] = 0; + return(buf); +#else + return(NULL); +#endif +} + static const char *getmimetype(char *file, struct stat *sb) { const char *ret; + if((ret = attrmimetype(file)) != NULL) + return(ret); if(cookie == NULL) { cookie = magic_open(MAGIC_MIME_TYPE); magic_load(cookie, NULL);