ReactOS 0.4.16-dev-340-g0540c21
fs.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * This file is part of the lwIP TCP/IP stack.
28 *
29 * Author: Adam Dunkels <adam@sics.se>
30 *
31 */
32
34#include "lwip/def.h"
35#include "lwip/apps/fs.h"
36#include <string.h>
37
38
39#include HTTPD_FSDATA_FILE
40
41/*-----------------------------------------------------------------------------------*/
43fs_open(struct fs_file *file, const char *name)
44{
45 const struct fsdata_file *f;
46
47 if ((file == NULL) || (name == NULL)) {
48 return ERR_ARG;
49 }
50
51#if LWIP_HTTPD_CUSTOM_FILES
52 if (fs_open_custom(file, name)) {
53 file->flags |= FS_FILE_FLAGS_CUSTOM;
54 return ERR_OK;
55 }
56#endif /* LWIP_HTTPD_CUSTOM_FILES */
57
58 for (f = FS_ROOT; f != NULL; f = f->next) {
59 if (!strcmp(name, (const char *)f->name)) {
60 file->data = (const char *)f->data;
61 file->len = f->len;
62 file->index = f->len;
63 file->flags = f->flags;
65 file->chksum_count = f->chksum_count;
66 file->chksum = f->chksum;
67#endif /* HTTPD_PRECALCULATED_CHECKSUM */
69 file->pextension = NULL;
70#endif /* LWIP_HTTPD_FILE_EXTENSION */
72 file->state = fs_state_init(file, name);
73#endif /* #if LWIP_HTTPD_FILE_STATE */
74 return ERR_OK;
75 }
76 }
77 /* file not found */
78 return ERR_VAL;
79}
80
81/*-----------------------------------------------------------------------------------*/
82void
84{
85#if LWIP_HTTPD_CUSTOM_FILES
86 if ((file->flags & FS_FILE_FLAGS_CUSTOM) != 0) {
87 fs_close_custom(file);
88 }
89#endif /* LWIP_HTTPD_CUSTOM_FILES */
90#if LWIP_HTTPD_FILE_STATE
91 fs_state_free(file, file->state);
92#endif /* #if LWIP_HTTPD_FILE_STATE */
94}
95/*-----------------------------------------------------------------------------------*/
96#if LWIP_HTTPD_DYNAMIC_FILE_READ
97#if LWIP_HTTPD_FS_ASYNC_READ
98int
99fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg)
100#else /* LWIP_HTTPD_FS_ASYNC_READ */
101int
102fs_read(struct fs_file *file, char *buffer, int count)
103#endif /* LWIP_HTTPD_FS_ASYNC_READ */
104{
105 int read;
106 if (file->index == file->len) {
107 return FS_READ_EOF;
108 }
109#if LWIP_HTTPD_FS_ASYNC_READ
110 LWIP_UNUSED_ARG(callback_fn);
111 LWIP_UNUSED_ARG(callback_arg);
112#endif /* LWIP_HTTPD_FS_ASYNC_READ */
113#if LWIP_HTTPD_CUSTOM_FILES
114 if ((file->flags & FS_FILE_FLAGS_CUSTOM) != 0) {
115#if LWIP_HTTPD_FS_ASYNC_READ
116 return fs_read_async_custom(file, buffer, count, callback_fn, callback_arg);
117#else /* LWIP_HTTPD_FS_ASYNC_READ */
118 return fs_read_custom(file, buffer, count);
119#endif /* LWIP_HTTPD_FS_ASYNC_READ */
120 }
121#endif /* LWIP_HTTPD_CUSTOM_FILES */
122
123 read = file->len - file->index;
124 if (read > count) {
125 read = count;
126 }
127
128 MEMCPY(buffer, (file->data + file->index), read);
129 file->index += read;
130
131 return (read);
132}
133#endif /* LWIP_HTTPD_DYNAMIC_FILE_READ */
134/*-----------------------------------------------------------------------------------*/
135#if LWIP_HTTPD_FS_ASYNC_READ
136int
137fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg)
138{
139 if (file != NULL) {
140#if LWIP_HTTPD_FS_ASYNC_READ
141#if LWIP_HTTPD_CUSTOM_FILES
142 if (!fs_canread_custom(file)) {
143 if (fs_wait_read_custom(file, callback_fn, callback_arg)) {
144 return 0;
145 }
146 }
147#else /* LWIP_HTTPD_CUSTOM_FILES */
148 LWIP_UNUSED_ARG(callback_fn);
149 LWIP_UNUSED_ARG(callback_arg);
150#endif /* LWIP_HTTPD_CUSTOM_FILES */
151#endif /* LWIP_HTTPD_FS_ASYNC_READ */
152 }
153 return 1;
154}
155#endif /* LWIP_HTTPD_FS_ASYNC_READ */
156/*-----------------------------------------------------------------------------------*/
157int
159{
160 return file->len - file->index;
161}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define read
Definition: acwin.h:96
#define NULL
Definition: types.h:112
int fs_bytes_left(struct fs_file *file)
Definition: fs.c:158
err_t fs_open(struct fs_file *file, const char *name)
Definition: fs.c:43
void fs_close(struct fs_file *file)
Definition: fs.c:83
#define FS_READ_EOF
Definition: fs.h:42
#define FS_FILE_FLAGS_CUSTOM
Definition: fs.h:57
#define FS_ROOT
Definition: fsdata.c:335
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
GLfloat f
Definition: glext.h:7540
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
#define HTTPD_PRECALCULATED_CHECKSUM
Definition: httpd_opts.h:392
#define LWIP_HTTPD_FILE_EXTENSION
Definition: httpd_opts.h:385
#define LWIP_HTTPD_FILE_STATE
Definition: httpd_opts.h:375
s8_t err_t
Definition: err.h:96
@ ERR_OK
Definition: err.h:55
@ ERR_VAL
Definition: err.h:67
@ ERR_ARG
Definition: err.h:88
#define f
Definition: ke_i.h:83
#define MEMCPY(DST, SRC, BYTES)
Definition: macros.h:231
void fs_read(off_t pos, int size, void *data)
Definition: io.c:282
struct define * next
Definition: compiler.c:65
Definition: fci.c:127
Definition: fs.h:66
Definition: name.c:39
WCHAR * name
Definition: name.c:42