Rename FS API functions to avoid conflicts

This commit is contained in:
Sergey Lyubka committed 2022-02-08 13:36:04 +00:00
1 parent 49d5aff8f9
commit 8cd4699dbc
7 files changed
+77 -67

No files matched your search

+13 -13
View File
@@ -385,8 +385,8 @@ static void static_cb(struct mg_connection *c, int ev, void *ev_data,
size_t n, max = 2 * MG_IO_SIZE;
if (c->send.size < max) mg_iobuf_resize(&c->send, max);
if (c->send.len >= c->send.size) return; // Rate limit
n = fd->fs->read(fd->fd, c->send.buf + c->send.len,
c->send.size - c->send.len);
n = fd->fs->rd(fd->fd, c->send.buf + c->send.len,
c->send.size - c->send.len);
if (n > 0) c->send.len += n;
if (c->send.len < c->send.size) restore_http_cb(c);
} else if (ev == MG_EV_CLOSE) {
@@ -482,7 +482,7 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm,
time_t mtime = 0;
struct mg_str *inm = NULL;
if (fd == NULL || fs->stat(path, &size, &mtime) == 0) {
if (fd == NULL || fs->st(path, &size, &mtime) == 0) {
LOG(LL_DEBUG, ("404 [%s] %p", path, (void *) fd));
mg_http_reply(c, 404, "", "%s", "Not found\n");
mg_fs_close(fd);
@@ -515,7 +515,7 @@ void mg_http_serve_file(struct mg_connection *c, struct mg_http_message *hm,
"Content-Range: bytes " MG_INT64_FMT "-" MG_INT64_FMT
"/" MG_INT64_FMT "\r\n",
r1, r1 + cl - 1, (int64_t) size);
fs->seek(fd->fd, (size_t) r1);
fs->sk(fd->fd, (size_t) r1);
}
}
@@ -552,7 +552,7 @@ static void printdirentry(const char *name, void *userdata) {
// LOG(LL_DEBUG, ("[%s] [%s]", d->dir, name));
if (snprintf(path, sizeof(path), "%s%c%s", d->dir, '/', name) < 0) {
LOG(LL_ERROR, ("%s truncated", name));
} else if ((flags = fs->stat(path, &size, &t)) == 0) {
} else if ((flags = fs->st(path, &size, &t)) == 0) {
LOG(LL_ERROR, ("%lu stat(%s): %d", d->c->id, path, errno));
} else {
const char *slash = flags & MG_FS_DIR ? "/" : "";
@@ -631,7 +631,7 @@ static void listdir(struct mg_connection *c, struct mg_http_message *hm,
(int) uri.len, uri.ptr, sort_js_code, sort_js_code2, (int) uri.len,
uri.ptr);
fs->list(dir, printdirentry, &d);
fs->ls(dir, printdirentry, &d);
mg_printf(c,
"</tbody><tfoot><tr><td colspan=\"3\"><hr></td></tr></tfoot>"
"</table><address>Mongoose v.%s</address></body></html>\n",
@@ -662,7 +662,7 @@ static void remove_double_dots(char *s) {
*p = '\0';
}
// Resolve requested file into `path` and return its fs->stat() result
// Resolve requested file into `path` and return its fs->st() result
static int uri_to_path2(struct mg_connection *c, struct mg_http_message *hm,
struct mg_fs *fs, struct mg_str url, struct mg_str dir,
char *path, size_t path_size) {
@@ -671,7 +671,7 @@ static int uri_to_path2(struct mg_connection *c, struct mg_http_message *hm,
size_t n = (size_t) snprintf(path, path_size, "%.*s", (int) dir.len, dir.ptr);
if (n > path_size) n = path_size;
path[path_size - 1] = '\0';
if ((fs->stat(path, NULL, NULL) & MG_FS_DIR) == 0) {
if ((fs->st(path, NULL, NULL) & MG_FS_DIR) == 0) {
mg_http_reply(c, 400, "", "Invalid web root [%.*s]\n", (int) dir.len,
dir.ptr);
} else {
@@ -684,7 +684,7 @@ static int uri_to_path2(struct mg_connection *c, struct mg_http_message *hm,
LOG(LL_VERBOSE_DEBUG,
("%lu %.*s -> %s", c->id, (int) hm->uri.len, hm->uri.ptr, path));
while (n > 0 && path[n - 1] == '/') path[--n] = 0; // Trim trailing slashes
flags = fs->stat(path, NULL, NULL); // Does it exist?
flags = fs->st(path, NULL, NULL); // Does it exist?
if (flags == 0) {
mg_http_reply(c, 404, "", "Not found\n"); // Does not exist, doh
} else if ((flags & MG_FS_DIR) && hm->uri.len > 0 &&
@@ -698,9 +698,9 @@ static int uri_to_path2(struct mg_connection *c, struct mg_http_message *hm,
flags = 0;
} else if (flags & MG_FS_DIR) {
if (((snprintf(path + n, path_size - n, "/" MG_HTTP_INDEX) > 0 &&
(tmp = fs->stat(path, NULL, NULL)) != 0) ||
(tmp = fs->st(path, NULL, NULL)) != 0) ||
(snprintf(path + n, path_size - n, "/index.shtml") > 0 &&
(tmp = fs->stat(path, NULL, NULL)) != 0))) {
(tmp = fs->st(path, NULL, NULL)) != 0))) {
flags = tmp;
} else {
path[n] = '\0'; // Remove appended index file name
@@ -900,12 +900,12 @@ int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
snprintf(path, sizeof(path), "%s%c%s", dir, MG_DIRSEP, name);
remove_double_dots(path);
LOG(LL_DEBUG, ("%d bytes @ %ld [%s]", (int) hm->body.len, oft, path));
if (oft == 0) fs->remove(path);
if (oft == 0) fs->rm(path);
if ((fd = mg_fs_open(fs, path, MG_FS_WRITE)) == NULL) {
mg_http_reply(c, 400, "", "open(%s): %d", path, errno);
return -2;
} else {
int written = (int) fs->write(fd->fd, hm->body.ptr, hm->body.len);
int written = (int) fs->wr(fd->fd, hm->body.ptr, hm->body.len);
mg_fs_close(fd);
mg_http_reply(c, 200, "", "%d", written);
return (int) hm->body.len;