X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fsendfile.c;h=b3797aaca88027cbd3776707b10a2dafc2807f18;hb=600a1ce79471493f8cad5fcf118dc9797331d5aa;hp=ce422e25cb5e046910da797cd143081650181faa;hpb=0e57e1f5abb9605fe119fce941de12792a82c2a8;p=ashd.git diff --git a/src/sendfile.c b/src/sendfile.c index ce422e2..b3797aa 100644 --- a/src/sendfile.c +++ b/src/sendfile.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #ifdef HAVE_CONFIG_H #include @@ -100,7 +102,7 @@ static const char *getmimetype(char *file, struct stat *sb) if((ret = attrmimetype(file)) != NULL) return(ret); if(cookie == NULL) { - cookie = magic_open(MAGIC_MIME_TYPE); + cookie = magic_open(MAGIC_MIME_TYPE | MAGIC_SYMLINK); magic_load(cookie, NULL); } if((ret = magic_file(cookie, file)) != NULL) @@ -108,6 +110,15 @@ static const char *getmimetype(char *file, struct stat *sb) return("application/octet-stream"); } +/* XXX: This could be made far better and check for other attributes + * and stuff, but not now. */ +static const char *ckctype(const char *ctype) +{ + if(!strncmp(ctype, "text/", 5) && (strchr(ctype, ';') == NULL)) + return(sprintf2("%s; charset=%s", ctype, nl_langinfo(CODESET))); + return(ctype); +} + static void checkcache(char *file, struct stat *sb) { char *hdr; @@ -136,6 +147,7 @@ int main(int argc, char **argv) int fd; const char *contype; + setlocale(LC_ALL, ""); contype = NULL; while((c = getopt(argc, argv, "c:")) >= 0) { switch(c) { @@ -167,6 +179,7 @@ int main(int argc, char **argv) } if(contype == NULL) contype = getmimetype(file, &sb); + contype = ckctype(contype); checkcache(file, &sb);