/*
- Copyright (C) 2010-2011 jeanfi@gmail.com
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301 USA
-*/
+ * Copyright (C) 2010-2011 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
#include <locale.h>
#include <libintl.h>
#define _(str) gettext(str)
}
#if MHD_VERSION >= 0x00090200
-static int
+static ssize_t
file_reader(void *cls, uint64_t pos, char *buf, size_t max)
#else
static int
unsigned int *rp_code,
const char *fpath)
{
- if (is_file(fpath)) {
- FILE *file = fopen(fpath, "rb");
+ struct stat st;
+ int ret;
+ FILE *file;
- if (file) {
- struct stat buf;
+ ret = stat(fpath, &st);
+
+ if (!ret && (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))) {
+ file = fopen(fpath, "rb");
- stat(fpath, &buf);
+ if (file) {
*rp_code = MHD_HTTP_OK;
- if (!buf.st_size) {
+ if (!st.st_size) {
fclose(file);
return MHD_create_response_from_data
(0, NULL, MHD_NO, MHD_NO);
}
return MHD_create_response_from_callback
- (buf.st_size,
+ (st.st_size,
32 * 1024,
&file_reader,
file,
(MHD_ContentReaderFreeCallback)&fclose);
+ } else {
+ log_printf(LOG_ERR, "Failed to open: %s\n", fpath);
}
}