Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
lwip_fs.c
00001 /* 00002 * Copyright (c) 2001-2003 Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 3. The name of the author may not be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00017 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00019 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00020 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00023 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00024 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00025 * OF SUCH DAMAGE. 00026 * 00027 * This file is part of the lwIP TCP/IP stack. 00028 * 00029 * Author: Adam Dunkels <adam@sics.se> 00030 * 00031 */ 00032 00033 #include "lwip/apps/httpd_opts.h" 00034 #include "lwip/def.h" 00035 #include "lwip/apps/fs.h" 00036 #include <string.h> 00037 00038 00039 #include HTTPD_FSDATA_FILE 00040 00041 /*-----------------------------------------------------------------------------------*/ 00042 00043 #if LWIP_HTTPD_CUSTOM_FILES 00044 int fs_open_custom(struct fs_file *file, const char *name); 00045 void fs_close_custom(struct fs_file *file); 00046 #if LWIP_HTTPD_FS_ASYNC_READ 00047 u8_t fs_canread_custom(struct fs_file *file); 00048 u8_t fs_wait_read_custom(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg); 00049 int fs_read_async_custom(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg); 00050 #else /* LWIP_HTTPD_FS_ASYNC_READ */ 00051 int fs_read_custom(struct fs_file *file, char *buffer, int count); 00052 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00053 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00054 00055 /*-----------------------------------------------------------------------------------*/ 00056 err_t 00057 fs_open(struct fs_file *file, const char *name) 00058 { 00059 const struct fsdata_file *f; 00060 00061 if ((file == NULL) || (name == NULL)) { 00062 return ERR_ARG; 00063 } 00064 00065 #if LWIP_HTTPD_CUSTOM_FILES 00066 if (fs_open_custom(file, name)) { 00067 file->is_custom_file = 1; 00068 return ERR_OK; 00069 } 00070 file->is_custom_file = 0; 00071 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00072 00073 for (f = FS_ROOT; f != NULL; f = f->next) { 00074 if (!strcmp(name, (const char *)f->name)) { 00075 file->data = (const char *)f->data; 00076 file->len = f->len; 00077 file->index = f->len; 00078 file->pextension = NULL; 00079 file->flags = f->flags; 00080 #if HTTPD_PRECALCULATED_CHECKSUM 00081 file->chksum_count = f->chksum_count; 00082 file->chksum = f->chksum; 00083 #endif /* HTTPD_PRECALCULATED_CHECKSUM */ 00084 #if LWIP_HTTPD_FILE_STATE 00085 file->state = fs_state_init(file, name); 00086 #endif /* #if LWIP_HTTPD_FILE_STATE */ 00087 return ERR_OK; 00088 } 00089 } 00090 /* file not found */ 00091 return ERR_VAL; 00092 } 00093 00094 /*-----------------------------------------------------------------------------------*/ 00095 void 00096 fs_close(struct fs_file *file) 00097 { 00098 #if LWIP_HTTPD_CUSTOM_FILES 00099 if (file->is_custom_file) { 00100 fs_close_custom(file); 00101 } 00102 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00103 #if LWIP_HTTPD_FILE_STATE 00104 fs_state_free(file, file->state); 00105 #endif /* #if LWIP_HTTPD_FILE_STATE */ 00106 LWIP_UNUSED_ARG(file); 00107 } 00108 /*-----------------------------------------------------------------------------------*/ 00109 #if LWIP_HTTPD_DYNAMIC_FILE_READ 00110 #if LWIP_HTTPD_FS_ASYNC_READ 00111 int 00112 fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg) 00113 #else /* LWIP_HTTPD_FS_ASYNC_READ */ 00114 int 00115 fs_read(struct fs_file *file, char *buffer, int count) 00116 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00117 { 00118 int read; 00119 if (file->index == file->len) { 00120 return FS_READ_EOF; 00121 } 00122 #if LWIP_HTTPD_FS_ASYNC_READ 00123 LWIP_UNUSED_ARG(callback_fn); 00124 LWIP_UNUSED_ARG(callback_arg); 00125 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00126 #if LWIP_HTTPD_CUSTOM_FILES 00127 if (file->is_custom_file) { 00128 #if LWIP_HTTPD_FS_ASYNC_READ 00129 return fs_read_async_custom(file, buffer, count, callback_fn, callback_arg); 00130 #else /* LWIP_HTTPD_FS_ASYNC_READ */ 00131 return fs_read_custom(file, buffer, count); 00132 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00133 } 00134 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00135 00136 read = file->len - file->index; 00137 if (read > count) { 00138 read = count; 00139 } 00140 00141 MEMCPY(buffer, (file->data + file->index), read); 00142 file->index += read; 00143 00144 return (read); 00145 } 00146 #endif /* LWIP_HTTPD_DYNAMIC_FILE_READ */ 00147 /*-----------------------------------------------------------------------------------*/ 00148 #if LWIP_HTTPD_FS_ASYNC_READ 00149 int 00150 fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg) 00151 { 00152 if (file != NULL) { 00153 #if LWIP_HTTPD_FS_ASYNC_READ 00154 #if LWIP_HTTPD_CUSTOM_FILES 00155 if (!fs_canread_custom(file)) { 00156 if (fs_wait_read_custom(file, callback_fn, callback_arg)) { 00157 return 0; 00158 } 00159 } 00160 #else /* LWIP_HTTPD_CUSTOM_FILES */ 00161 LWIP_UNUSED_ARG(callback_fn); 00162 LWIP_UNUSED_ARG(callback_arg); 00163 #endif /* LWIP_HTTPD_CUSTOM_FILES */ 00164 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00165 } 00166 return 1; 00167 } 00168 #endif /* LWIP_HTTPD_FS_ASYNC_READ */ 00169 /*-----------------------------------------------------------------------------------*/ 00170 int 00171 fs_bytes_left(struct fs_file *file) 00172 { 00173 return file->len - file->index; 00174 }
Generated on Tue Jul 12 2022 13:54:28 by
1.7.2