if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED &&
wsi->u.http.fd != LWS_INVALID_FILE) {
lwsl_debug("closing http file\n");
- lws_plat_file_close(&context->fops, wsi->u.http.fd);
+ lws_plat_file_close(wsi, wsi->u.http.fd);
wsi->u.http.fd = LWS_INVALID_FILE;
context->protocols[0].callback(context, wsi,
LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
#define lwsl_hexdump(a, b)
#endif
-
+struct lws;
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
/* api change list for user code to test against */
* @write: Write to file *amount is set on exit as amount written
*/
struct lws_plat_file_ops {
- lws_filefd_type (*open)(const char *filename, unsigned long *filelen,
- int flags);
- int (*close)(lws_filefd_type fd);
- unsigned long (*seek_cur)(lws_filefd_type fd, long offset_from_cur_pos);
- int (*read)(lws_filefd_type fd, unsigned long *amount,
+ lws_filefd_type (*open)(struct lws *wsi, const char *filename,
+ unsigned long *filelen, int flags);
+ int (*close)(struct lws *wsi, lws_filefd_type fd);
+ unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd,
+ long offset_from_cur_pos);
+ int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
unsigned char *buf, unsigned long len);
- int (*write)(lws_filefd_type fd, unsigned long *amount,
+ int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
unsigned char *buf, unsigned long len);
/* Add new things just above here ---^
lws_get_ctx(const struct lws *wsi);
/*
- * File Operations access helpers
+ * Wsi-associated File Operations access helpers
+ *
+ * Use these helper functions if you want to access a file from the perspective
+ * of a specific wsi, which is usually the case. If you just want contextless
+ * file access, use the fops callbacks directly with NULL wsi instead of these
+ * helpers.
*
- * usually the first argument will be lws_get_fops(context)
* If so, then it calls the platform handler or user overrides where present
* (as defined in info->fops)
*
*/
static inline lws_filefd_type
-lws_plat_file_open(struct lws_plat_file_ops *fops, const char *filename,
+lws_plat_file_open(struct lws *wsi, const char *filename,
unsigned long *filelen, int flags)
{
- return fops->open(filename, filelen, flags);
+ return lws_get_fops(lws_get_ctx(wsi))->open(wsi, filename,
+ filelen, flags);
}
static inline int
-lws_plat_file_close(struct lws_plat_file_ops *fops, lws_filefd_type fd)
+lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
{
- return fops->close(fd);
+ return lws_get_fops(lws_get_ctx(wsi))->close(wsi, fd);
}
static inline unsigned long
-lws_plat_file_seek_cur(struct lws_plat_file_ops *fops, lws_filefd_type fd,
- long offset_from_cur_pos)
+lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
{
- return fops->seek_cur(fd, offset_from_cur_pos);
+ return lws_get_fops(lws_get_ctx(wsi))->seek_cur(wsi, fd, offset);
}
static inline int
-lws_plat_file_read(struct lws_plat_file_ops *fops, lws_filefd_type fd,
- unsigned long *amount, unsigned char *buf, unsigned long len)
+lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
+ unsigned char *buf, unsigned long len)
{
- return fops->read(fd, amount, buf, len);
+ return lws_get_fops(lws_get_ctx(wsi))->read(wsi, fd, amount, buf, len);
}
static inline int
-lws_plat_file_write(struct lws_plat_file_ops *fops, lws_filefd_type fd,
- unsigned long *amount, unsigned char *buf, unsigned long len)
+lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
+ unsigned char *buf, unsigned long len)
{
- return fops->write(fd, amount, buf, len);
+ return lws_get_fops(lws_get_ctx(wsi))->write(wsi, fd, amount, buf, len);
}
/*
}
static lws_filefd_type
-_lws_plat_file_open(const char *filename, unsigned long *filelen, int flags)
+_lws_plat_file_open(struct lws *wsi, const char *filename,
+ unsigned long *filelen, int flags)
{
+ (void)wsi;
(void)filename;
(void)filelen;
(void)flags;
}
static int
-_lws_plat_file_close(lws_filefd_type fd)
+_lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
{
+ (void)wsi;
(void)fd;
return -1;
}
unsigned long
-_lws_plat_file_seek_cur(lws_filefd_type fd, long offset)
+_lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
{
+ (void)wsi
(void)fd;
(void)offset;
}
static int
-_lws_plat_file_read(lws_filefd_type fd, unsigned long *amount,
+_lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
unsigned char* buf, unsigned long* len)
{
+ (void)wsi;
(void)amount;
(void)fd;
(void)buf;
}
static int
-_lws_plat_file_write(lws_filefd_type fd, unsigned long *amount,
+_lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
unsigned char* buf, unsigned long len)
{
+ (void)wsi;
(void)amount;
(void)fd;
(void)buf;
}
static lws_filefd_type
-_lws_plat_file_open(const char *filename, unsigned long *filelen, int flags)
+_lws_plat_file_open(struct lws *wsi, const char *filename,
+ unsigned long *filelen, int flags)
{
struct stat stat_buf;
int ret = open(filename, flags, 0664);
}
static int
-_lws_plat_file_close(lws_filefd_type fd)
+_lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
{
return close(fd);
}
unsigned long
-_lws_plat_file_seek_cur(lws_filefd_type fd, long offset)
+_lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
{
return lseek(fd, offset, SEEK_CUR);
}
static int
-_lws_plat_file_read(lws_filefd_type fd, unsigned long *amount,
+_lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
unsigned char *buf, unsigned long len)
{
long n;
}
static int
-_lws_plat_file_write(lws_filefd_type fd, unsigned long *amount,
+_lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
unsigned char *buf, unsigned long len)
{
long n;
}
static lws_filefd_type
-_lws_plat_file_open(const char *filename, unsigned long *filelen, int flags)
+_lws_plat_file_open(struct lws *wsi, const char *filename,
+ unsigned long *filelen, int flags)
{
HANDLE ret;
WCHAR buf[MAX_PATH];
+ (void)wsi;
MultiByteToWideChar(CP_UTF8, 0, filename, -1, buf, ARRAY_SIZE(buf));
if ((flags & 7) == _O_RDONLY) {
ret = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ,
}
static int
-_lws_plat_file_close(lws_filefd_type fd)
+_lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
{
+ (void)wsi;
+
CloseHandle((HANDLE)fd);
return 0;
}
static unsigned long
-_lws_plat_file_seek_cur(lws_filefd_type fd, long offset)
+_lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
{
+ (void)wsi;
+
return SetFilePointer((HANDLE)fd, offset, NULL, FILE_CURRENT);
}
static int
-_lws_plat_file_read(lws_filefd_type fd, unsigned long *amount,
- unsigned char* buf, unsigned long len)
+_lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
+ unsigned char* buf, unsigned long len)
{
DWORD _amount;
+ (void *)wsi;
if (!ReadFile((HANDLE)fd, buf, (DWORD)len, &_amount, NULL)) {
*amount = 0;
}
static int
-_lws_plat_file_write(lws_filefd_type fd, unsigned long *amount,
+_lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
unsigned char* buf, unsigned long len)
{
- lwsl_err("%s: not implemented on this platform\n", __func__);
+ (void)wsi;
+ (void)fd;
+ (void)amount;
+ (void)buf;
+ (void)len;
+
+ lwsl_err("%s: not implemented yet on this platform\n", __func__);
return -1;
}
if (wsi->u.http.filepos == wsi->u.http.filelen)
goto all_sent;
- if (lws_plat_file_read(&context->fops, wsi->u.http.fd, &amount,
+ if (lws_plat_file_read(wsi, wsi->u.http.fd, &amount,
context->service_buffer,
sizeof(context->service_buffer)) < 0)
return -1; /* caller will close */
if (m != n)
/* adjust for what was not sent */
- if (lws_plat_file_seek_cur(&context->fops,
+ if (lws_plat_file_seek_cur(wsi,
wsi->u.http.fd,
m - n) ==
(unsigned long)-1)
wsi->state = WSI_STATE_HTTP;
/* we might be in keepalive, so close it off here */
- lws_plat_file_close(&context->fops, wsi->u.http.fd);
+ lws_plat_file_close(wsi, wsi->u.http.fd);
wsi->u.http.fd = LWS_INVALID_FILE;
if (wsi->protocol->callback)
LWS_SEND_BUFFER_PRE_PADDING;
int ret = 0;
- wsi->u.http.fd = lws_plat_file_open(&context->fops, file,
+ wsi->u.http.fd = lws_plat_file_open(wsi, file,
&wsi->u.http.filelen, O_RDONLY);
if (wsi->u.http.fd == LWS_INVALID_FILE) {
p = buffer + LWS_SEND_BUFFER_PRE_PADDING;
end = p + sizeof(buffer) - LWS_SEND_BUFFER_PRE_PADDING;
- pss->fd = lws_plat_file_open(lws_get_fops(context),
- leaf_path, &file_len,
+ pss->fd = lws_plat_file_open(wsi, leaf_path, &file_len,
LWS_O_RDONLY);
if (pss->fd == LWS_INVALID_FILE)
LWS_WRITE_HTTP_HEADERS);
if (n < 0) {
- lws_plat_file_close(lws_get_fops(context),
- pss->fd);
+ lws_plat_file_close(wsi, pss->fd);
return -1;
}
/*
/* he couldn't handle that much */
n = m;
- n = lws_plat_file_read(lws_get_fops(context), pss->fd,
+ n = lws_plat_file_read(wsi, pss->fd,
&amount, buffer +
LWS_SEND_BUFFER_PRE_PADDING, n);
/* problem reading, close conn */
*/
if (m != n)
/* partial write, adjust */
- if (lws_plat_file_seek_cur(lws_get_fops(context),
- pss->fd, m - n) ==
+ if (lws_plat_file_seek_cur(wsi, pss->fd, m - n) ==
(unsigned long)-1)
goto bail;
lws_callback_on_writable(context, wsi);
break;
}
- lws_plat_file_close(lws_get_fops(context), pss->fd);
+ lws_plat_file_close(wsi, pss->fd);
goto try_to_reuse;
bail:
- lws_plat_file_close(lws_get_fops(context), pss->fd);
+ lws_plat_file_close(wsi, pss->fd);
return -1;
/*
* compressed files without decompressing the whole archive)
*/
static lws_filefd_type
-test_server_fops_open(const char *filename, unsigned long *filelen, int flags)
+test_server_fops_open(struct lws *wsi, const char *filename,
+ unsigned long *filelen, int flags)
{
int n;
/* call through to original platform implementation */
- n = fops_plat.open(filename, filelen, flags);
+ n = fops_plat.open(wsi, filename, filelen, flags);
lwsl_notice("%s: opening %s, ret %d, len %lu\n", __func__, filename,
n, *filelen);