libwebsockets
Lightweight C library for HTML5 websockets
lws-vfs.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010-2018 Andy Green <andy@warmcat.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation:
9  * version 2.1 of the License.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  *
21  * included from libwebsockets.h
22  */
23 
40 
47 #if defined(LWS_WITH_ESP32)
48 /* sdk preprocessor defs? compiler issue? gets confused with member names */
49 #define LWS_FOP_OPEN _open
50 #define LWS_FOP_CLOSE _close
51 #define LWS_FOP_SEEK_CUR _seek_cur
52 #define LWS_FOP_READ _read
53 #define LWS_FOP_WRITE _write
54 #else
55 #define LWS_FOP_OPEN open
56 #define LWS_FOP_CLOSE close
57 #define LWS_FOP_SEEK_CUR seek_cur
58 #define LWS_FOP_READ read
59 #define LWS_FOP_WRITE write
60 #endif
61 
62 #define LWS_FOP_FLAGS_MASK ((1 << 23) - 1)
63 #define LWS_FOP_FLAG_COMPR_ACCEPTABLE_GZIP (1 << 24)
64 #define LWS_FOP_FLAG_COMPR_IS_GZIP (1 << 25)
65 #define LWS_FOP_FLAG_MOD_TIME_VALID (1 << 26)
66 #define LWS_FOP_FLAG_VIRTUAL (1 << 27)
67 
68 struct lws_plat_file_ops;
69 
70 struct lws_fop_fd {
71  lws_filefd_type fd;
73  const struct lws_plat_file_ops *fops;
77  lws_filepos_t pos;
79  lws_filepos_t len;
81  lws_fop_flags_t flags;
83  uint32_t mod_time;
86 };
87 typedef struct lws_fop_fd *lws_fop_fd_t;
88 
90  const char *sig; /* NULL or vfs signature, eg, ".zip/" */
91  uint8_t len; /* length of above string */
92 };
93 
96  const char *filename, const char *vpath,
97  lws_fop_flags_t *flags);
107  int (*LWS_FOP_CLOSE)(lws_fop_fd_t *fop_fd);
109  lws_fileofs_t (*LWS_FOP_SEEK_CUR)(lws_fop_fd_t fop_fd,
110  lws_fileofs_t offset_from_cur_pos);
112  int (*LWS_FOP_READ)(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
113  uint8_t *buf, lws_filepos_t len);
115  int (*LWS_FOP_WRITE)(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
116  uint8_t *buf, lws_filepos_t len);
119  struct lws_fops_index fi[3];
122  const struct lws_plat_file_ops *next;
125  /* Add new things just above here ---^
126  * This is part of the ABI, don't needlessly break compatibility */
127 };
128 
134 LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
135 lws_get_fops(struct lws_context *context);
136 LWS_VISIBLE LWS_EXTERN void
137 lws_set_fops(struct lws_context *context, const struct lws_plat_file_ops *fops);
143 LWS_VISIBLE LWS_EXTERN lws_filepos_t LWS_WARN_UNUSED_RESULT
144 lws_vfs_tell(lws_fop_fd_t fop_fd);
150 LWS_VISIBLE LWS_EXTERN lws_filepos_t LWS_WARN_UNUSED_RESULT
151 lws_vfs_get_length(lws_fop_fd_t fop_fd);
157 LWS_VISIBLE LWS_EXTERN uint32_t LWS_WARN_UNUSED_RESULT
158 lws_vfs_get_mod_time(lws_fop_fd_t fop_fd);
165 LWS_VISIBLE LWS_EXTERN lws_fileofs_t
166 lws_vfs_file_seek_set(lws_fop_fd_t fop_fd, lws_fileofs_t offset);
173 LWS_VISIBLE LWS_EXTERN lws_fileofs_t
174 lws_vfs_file_seek_end(lws_fop_fd_t fop_fd, lws_fileofs_t offset);
175 
176 extern struct lws_plat_file_ops fops_zip;
177 
192 LWS_VISIBLE LWS_EXTERN lws_fop_fd_t LWS_WARN_UNUSED_RESULT
193 lws_vfs_file_open(const struct lws_plat_file_ops *fops, const char *vfs_path,
194  lws_fop_flags_t *flags);
195 
201 static LWS_INLINE int
202 lws_vfs_file_close(lws_fop_fd_t *fop_fd)
203 {
204  if (*fop_fd && (*fop_fd)->fops)
205  return (*fop_fd)->fops->LWS_FOP_CLOSE(fop_fd);
206 
207  return 0;
208 }
209 
217 static LWS_INLINE lws_fileofs_t
218 lws_vfs_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset)
219 {
220  return fop_fd->fops->LWS_FOP_SEEK_CUR(fop_fd, offset);
221 }
230 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
231 lws_vfs_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
232  uint8_t *buf, lws_filepos_t len)
233 {
234  return fop_fd->fops->LWS_FOP_READ(fop_fd, amount, buf, len);
235 }
244 static LWS_INLINE int LWS_WARN_UNUSED_RESULT
245 lws_vfs_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
246  uint8_t *buf, lws_filepos_t len)
247 {
248  return fop_fd->fops->LWS_FOP_WRITE(fop_fd, amount, buf, len);
249 }
250 
251 /* these are the platform file operations implementations... they can
252  * be called directly and used in fops arrays
253  */
254 
255 LWS_VISIBLE LWS_EXTERN lws_fop_fd_t
256 _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
257  const char *vpath, lws_fop_flags_t *flags);
258 LWS_VISIBLE LWS_EXTERN int
259 _lws_plat_file_close(lws_fop_fd_t *fop_fd);
260 LWS_VISIBLE LWS_EXTERN lws_fileofs_t
261 _lws_plat_file_seek_cur(lws_fop_fd_t fop_fd, lws_fileofs_t offset);
262 LWS_VISIBLE LWS_EXTERN int
263 _lws_plat_file_read(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
264  uint8_t *buf, lws_filepos_t len);
265 LWS_VISIBLE LWS_EXTERN int
266 _lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
267  uint8_t *buf, lws_filepos_t len);
268 
269 LWS_VISIBLE LWS_EXTERN int
270 lws_alloc_vfs_file(struct lws_context *context, const char *filename,
271  uint8_t **buf, lws_filepos_t *amount);
lws_plat_file_ops::LWS_FOP_READ
int(* LWS_FOP_READ)(lws_fop_fd_t fop_fd, lws_filepos_t *amount, uint8_t *buf, lws_filepos_t len)
Definition: lws-vfs.h:112
lws_plat_file_ops::fi
struct lws_fops_index fi[3]
Definition: lws-vfs.h:119
lws_fop_fd::filesystem_priv
void * filesystem_priv
Definition: lws-vfs.h:75
lws_fop_fd::pos
lws_filepos_t pos
Definition: lws-vfs.h:77
lws_plat_file_ops::LWS_FOP_OPEN
lws_fop_fd_t(* LWS_FOP_OPEN)(const struct lws_plat_file_ops *fops, const char *filename, const char *vpath, lws_fop_flags_t *flags)
Definition: lws-vfs.h:95
lws_fop_fd::fd
lws_filefd_type fd
Definition: lws-vfs.h:71
lws_fops_index
Definition: lws-vfs.h:89
lws_fop_fd::mod_time
uint32_t mod_time
Definition: lws-vfs.h:83
lws_plat_file_ops::next
const struct lws_plat_file_ops * next
Definition: lws-vfs.h:122
lws_fop_fd
Definition: lws-vfs.h:70
lws_plat_file_ops
Definition: lws-vfs.h:94
lws_fop_fd::len
lws_filepos_t len
Definition: lws-vfs.h:79
lws_fop_fd::fops
const struct lws_plat_file_ops * fops
Definition: lws-vfs.h:73
lws_plat_file_ops::LWS_FOP_SEEK_CUR
lws_fileofs_t(* LWS_FOP_SEEK_CUR)(lws_fop_fd_t fop_fd, lws_fileofs_t offset_from_cur_pos)
Definition: lws-vfs.h:109
lws_plat_file_ops::LWS_FOP_WRITE
int(* LWS_FOP_WRITE)(lws_fop_fd_t fop_fd, lws_filepos_t *amount, uint8_t *buf, lws_filepos_t len)
Definition: lws-vfs.h:115
lws_fop_fd::flags
lws_fop_flags_t flags
Definition: lws-vfs.h:81
lws_plat_file_ops::LWS_FOP_CLOSE
int(* LWS_FOP_CLOSE)(lws_fop_fd_t *fop_fd)
Definition: lws-vfs.h:107