diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..de29c4c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "files.associations": { + "assert.h": "c", + "wn_utils.h": "c", + "webnet.h": "c", + "wn_module.h": "c" + } +} \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..ce21783 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +SRC_DIR += src module samples + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/README.md b/README.md old mode 100644 new mode 100755 index b45a8bf..7eba612 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ WebNet 软件包使用需要文件系统和Lwip协议栈的支持。 webnet.c 文件中注意以下定义,注意其他操作系统lwip协议栈的大小设置 ``` -#ifdef ADD_RTTHREAD_FETURES +#ifdef ADD_RTTHREAD_FETURES #if defined(RT_USING_LWIP) && (RT_LWIP_TCPTHREAD_STACKSIZE < 1408) #error The lwIP tcpip thread stack size(RT_LWIP_TCPTHREAD_STACKSIZE) must more than 1408 #endif @@ -98,3 +98,10 @@ webnet.c 文件中注意以下定义,注意其他操作系统lwip协议栈的 ``` webnet文件夹为该分支的一个前端页面文件版本 + + +for xizi: +1.需要同时打开SD卡和USB功能,同时使用SD卡作为文件系统,需要开启SEMC功能 +单独使用SD卡会导致卡在网络配置界面,单独使用USB卡会导致从U盘读取数据到内存的时候,数据发生错误(一部分数据没写入,呈现出来的就是全0) +2.注意使用的时候,需要修改read,close,open等系统调用的地方,因为默认使用的是lwip中的read,close和open +3.需要单独开启netdev模块 diff --git a/inc/webnet.h b/inc/webnet.h old mode 100644 new mode 100755 index e85be7c..b71974d --- a/inc/webnet.h +++ b/inc/webnet.h @@ -23,33 +23,58 @@ * Change Logs: * Date Author Notes * 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #ifndef __WEBNET_H__ #define __WEBNET_H__ #include +#include #ifdef __cplusplus extern "C" { #endif #ifndef wn_malloc -#define wn_malloc malloc +#define wn_malloc PrivMalloc #endif #ifndef wn_free -#define wn_free free +#define wn_free PrivFree #endif #ifndef wn_realloc -#define wn_realloc realloc +#define wn_realloc PrivRealloc #endif #ifndef wn_strdup -#define wn_strdup strdup +#define wn_strdup strdup #endif +#ifndef wn_read +#define wn_read PrivRead +#endif + +#ifndef wn_open +#define wn_open PrivOpen +#endif + +#ifndef wn_close +#define wn_close PrivClose +#endif + +// #define WEBNET_USING_LOG +// #define WEBNET_USING_AUTH +// #define WEBNET_USING_CGI +// #define WEBNET_USING_ASP +// #define WEBNET_USING_SSI +// #define WEBNET_USING_INDEX +// #define WEBNET_USING_ALIAS +// #define WEBNET_USING_UPLOAD +// #define WEBNET_CACHE_LEVEL 0 +// #define WEBNET_USING_SAMPLES + #ifndef WEBNET_USING_RANGE #define WEBNET_USING_RANGE #endif diff --git a/inc/wn_module.h b/inc/wn_module.h old mode 100644 new mode 100755 index d161f04..20fd57e --- a/inc/wn_module.h +++ b/inc/wn_module.h @@ -22,7 +22,8 @@ * * Change Logs: * Date Author Notes - * 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread + * 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #ifndef __WN_MODULE_H__ diff --git a/inc/wn_request.h b/inc/wn_request.h old mode 100644 new mode 100755 index 7819840..9da6d80 --- a/inc/wn_request.h +++ b/inc/wn_request.h @@ -19,13 +19,14 @@ * Change Logs: * Date Author Notes * 2022-05-10 chunyexixiaoyu the version the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #ifndef __WN_REQUEST_H__ #define __WN_REQUEST_H__ #include -#include #include +#include #ifdef __cplusplus extern "C" { @@ -124,6 +125,7 @@ int webnet_request_parse_post(struct webnet_request* request, char* buffer, int void webnet_request_parse(struct webnet_request* request, char* buffer, int length); bool webnet_request_has_query(struct webnet_request* request, char* name); + const char* webnet_request_get_query(struct webnet_request* request, char* name); #ifdef __cplusplus diff --git a/inc/wn_session.h b/inc/wn_session.h old mode 100644 new mode 100755 index 2c8da9b..4b3b2f4 --- a/inc/wn_session.h +++ b/inc/wn_session.h @@ -18,7 +18,8 @@ * * Change Logs: * Date Author Notes - * 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread + * 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #ifndef __WN_SESSION_H__ @@ -27,11 +28,16 @@ #include #include +#ifdef BSP_USING_LWIP +#include +#include +#endif + #ifdef __cplusplus extern "C" { #endif -#define WEBNET_SESSION_BUFSZ (4 * 1024) +#define WEBNET_SESSION_BUFSZ (8 * 1024) /* close session */ #define WEBNET_EVENT_CLOSE (1 << 5) @@ -68,7 +74,7 @@ struct webnet_session struct webnet_request* request; /* session buffer */ - uint16 buffer_length; + uint32 buffer_length; uint16 buffer_offset; uint8 buffer[WEBNET_SESSION_BUFSZ]; diff --git a/inc/wn_utils.h b/inc/wn_utils.h old mode 100644 new mode 100755 index 449afe6..541671b --- a/inc/wn_utils.h +++ b/inc/wn_utils.h @@ -19,6 +19,7 @@ * Change Logs: * Date Author Notes * 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #ifndef __WN_UTILS_H__ diff --git a/module/Makefile b/module/Makefile new file mode 100644 index 0000000..943ecaf --- /dev/null +++ b/module/Makefile @@ -0,0 +1,11 @@ +SRC_FILES += wn_module_alias.c \ + wn_module_asp.c \ + wn_module_auth.c \ + wn_module_cgi.c \ + wn_module_dav.c \ + wn_module_index.c \ + wn_module_log.c \ + wn_module_ssi.c \ + wn_module_upload.c + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/module/wn_module_alias.c b/module/wn_module_alias.c old mode 100644 new mode 100755 index cc46fec..d9551ee --- a/module/wn_module_alias.c +++ b/module/wn_module_alias.c @@ -18,11 +18,15 @@ * * Change Logs: * Date Author Notes - * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ +#include +#include #include #include +#include #include #ifdef WEBNET_USING_ALIAS diff --git a/module/wn_module_asp.c b/module/wn_module_asp.c old mode 100644 new mode 100755 index e6fe745..63c9576 --- a/module/wn_module_asp.c +++ b/module/wn_module_asp.c @@ -19,12 +19,15 @@ * Change Logs: * Date Author Notes * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ -#include +#include #include +#include #include #include +#include #include #ifdef WEBNET_USING_ASP @@ -111,15 +114,12 @@ static void _default_asp_handler(struct webnet_session* session, const char* nam } else if (strncmp(name, "TICK", 4) == 0) { - int32 tick; + int32 tick; int32 hour, min, second; - #ifdef ADD_RTTHREAD_FETURES - tick = rt_tick_get()/RT_TICK_PER_SECOND; - #endif + tick = PrivGetTickTime(); second = tick % 60; min = (tick/60) % 60; hour = tick / (60 * 60); - webnet_session_printf(session, "%02d:%02d:%02d", hour, min, second); } } @@ -137,6 +137,7 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd) /* allocate read buffer */ buffer = (char*) wn_malloc (length); + memset(buffer,0,length); if (buffer == NULL) { session->request->result_code = 500; @@ -146,7 +147,8 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd) /* write page header */ webnet_session_set_header(session, "text/html", 200, "OK", -1); /* read file to buffer */ - if (read(fd, buffer, (uint32)length) != length) /* read failed */ + + if (wn_read(fd, buffer, (uint32)length) != length) /* read failed */ { wn_free(buffer); session->request->result_code = 500; @@ -180,7 +182,9 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd) webnet_session_write(session, (const uint8*)offset, asp_begin - offset); offset = asp_begin + 2; - while ((*offset == ' ') || (*offset == '\t')) offset ++; + while ((*offset == ' ') || (*offset == '\t')){ + offset++; + } /* extrace asp variable */ for (index = 0; index < _webnet_asp_vars_count; index ++) @@ -217,7 +221,7 @@ int webnet_module_asp(struct webnet_session* session, int event) if (event == WEBNET_EVENT_URI_POST) { - int fd; + int fd=-1; /* check whether a asp file */ if ((strstr(request->path, ".asp") != NULL) || @@ -225,11 +229,11 @@ int webnet_module_asp(struct webnet_session* session, int event) { /* try to open this file */ - fd = open(request->path, O_RDONLY, 0); + fd = wn_open(request->path, O_RDONLY, 0); if ( fd >= 0) { _webnet_asp_dofile(session, fd); - close(fd); + wn_close(fd); return WEBNET_MODULE_FINISHED; } else @@ -248,14 +252,16 @@ int webnet_module_asp(struct webnet_session* session, int event) if (asp_filename != NULL) { snprintf(asp_filename, WEBNET_PATH_MAX, "%s/index.asp", request->path); - fd = open(asp_filename, O_RDONLY, 0); + struct stat file_stat; + if (stat(asp_filename, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) { + fd = wn_open(asp_filename, O_RDONLY, 0); - if (fd >= 0) - { - wn_free(asp_filename); - _webnet_asp_dofile(session, fd); - close(fd); - return WEBNET_MODULE_FINISHED; + if (fd >= 0) { + wn_free(asp_filename); + _webnet_asp_dofile(session, fd); + wn_close(fd); + return WEBNET_MODULE_FINISHED; + } } } wn_free(asp_filename); diff --git a/module/wn_module_auth.c b/module/wn_module_auth.c old mode 100644 new mode 100755 index 0eb9a97..73ef8b9 --- a/module/wn_module_auth.c +++ b/module/wn_module_auth.c @@ -19,11 +19,14 @@ * Change Logs: * Date Author Notes * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ +#include #include #include #include +#include #include #ifdef WEBNET_USING_AUTH @@ -77,7 +80,10 @@ void webnet_auth_set(const char* path, const char* username_password) _auth_items[_auth_items_count - 1].path = wn_strdup(path); _auth_items[_auth_items_count - 1].username_password = str_base64_encode(username_password); } + +#ifdef ADD_RTTHREAD_FETURES RTM_EXPORT(webnet_auth_set); +#endif /** * Authorization module handler diff --git a/module/wn_module_cgi.c b/module/wn_module_cgi.c old mode 100644 new mode 100755 index 419211d..9976d78 --- a/module/wn_module_cgi.c +++ b/module/wn_module_cgi.c @@ -18,13 +18,16 @@ * * Change Logs: * Date Author Notes - * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #include #include +#include #include #include +#include #include #ifdef WEBNET_USING_CGI @@ -42,13 +45,13 @@ static uint32 _cgi_count = 0; void webnet_cgi_set_root(const char* root) { - if (strlen(root) > CGI_ROOT_PATH_MAX) - { + int root_len = strlen(root); + if (root_len > CGI_ROOT_PATH_MAX) { assert(0); return; } - strncpy(_cgi_root, root, strlen(root)); + strncpy(_cgi_root, root, root_len); if (_cgi_root[strlen(_cgi_root)] != '/') { _cgi_root[strlen(_cgi_root) + 1] = '/'; diff --git a/module/wn_module_dav.c b/module/wn_module_dav.c old mode 100644 new mode 100755 index 3e90736..3e25fd6 --- a/module/wn_module_dav.c +++ b/module/wn_module_dav.c @@ -18,13 +18,17 @@ * * Change Logs: * Date Author Notes - * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #include + #include #include #include #include + + #ifdef WEBNET_USING_DAV struct webnet_module_put_entry @@ -100,10 +104,10 @@ int webnet_module_dav(struct webnet_session* session, int event) printf("PROPFIND %s depth: %s", session->request->path, session->request->depth?session->request->depth:"null"); - fd = open(session->request->path, O_RDONLY, 0); + fd = wn_open(session->request->path, O_RDONLY, 0); if (fd >= 0) { - close(fd); + wn_close(fd); exit_file = 1; } dir = opendir(session->request->path); @@ -276,9 +280,23 @@ static void print_propfind_element(struct webnet_session *session, const char *u time_t t = file_stat->st_mtime; + #ifdef ADD_RTTHREAD_FETURES PrivTaskenterCritical(); + #endif + + #ifdef ADD_XIZI_FEATURES + long lock; + lock = CriticalAreaLock(); + #endif //ADD_XIZI_FEATURES + strftime(ctime_str, sizeof(ctime_str), "%a, %d %b %Y %H:%M:%S GMT", localtime(&t)); + #ifdef ADD_RTTHREAD_FETURES PrivTaskexitCritical(); + #endif + + #ifdef ADD_XIZI_FEATURES + CriticalAreaUnLock(lock); + #endif //ADD_XIZI_FEATURES //printf("strftime: %s\n", ctime_str); webnet_session_printf(session, @@ -296,7 +314,7 @@ static int put_open (struct webnet_session* session) goto _exit; } - fd = open(session->request->path, O_WRONLY | O_CREAT | O_TRUNC, 0); + fd = wn_open(session->request->path, O_WRONLY | O_CREAT | O_TRUNC, 0); if(fd < 0) { session->session_phase = WEB_PHASE_CLOSE; @@ -319,7 +337,7 @@ static int put_close(struct webnet_session* session) fd = (int)webnet_put_get_userdata(session); if (fd < 0) return 0; - close(fd); + wn_close(fd); return 0; } diff --git a/module/wn_module_index.c b/module/wn_module_index.c old mode 100644 new mode 100755 index 1732cf1..bcac702 --- a/module/wn_module_index.c +++ b/module/wn_module_index.c @@ -18,9 +18,12 @@ * * Change Logs: * Date Author Notes - * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #include + +#include #include #include #include diff --git a/module/wn_module_log.c b/module/wn_module_log.c old mode 100644 new mode 100755 index 3ce0ab9..c3737c2 --- a/module/wn_module_log.c +++ b/module/wn_module_log.c @@ -18,13 +18,16 @@ * * Change Logs: * Date Author Notes - * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #include + #include #include #include + #ifdef WEBNET_USING_LOG int webnet_module_log(struct webnet_session* session, int event) @@ -42,7 +45,7 @@ int webnet_module_log(struct webnet_session* session, int event) if (event == WEBNET_EVENT_INIT) { - printf("server initialize success."); + printf("server initialize success.\n"); } else if (event == WEBNET_EVENT_URI_PHYSICAL) { @@ -75,7 +78,7 @@ int webnet_module_log(struct webnet_session* session, int event) default: break; } - printf(" request: %s", request->path); + printf(" request: %s\n", request->path); for (index = 0; index < request->query_counter; index ++) { printf(" query[%d]: %s => %s", index, @@ -87,7 +90,7 @@ int webnet_module_log(struct webnet_session* session, int event) { printf("event post uri physical url: %s", request->path); - printf("mime type: %s", mime_get_type(request->path)); + printf("mime type: %s\n", mime_get_type(request->path)); } else if (event == WEBNET_EVENT_RSP_HEADER) { diff --git a/module/wn_module_ssi.c b/module/wn_module_ssi.c old mode 100644 new mode 100755 index e0e688a..9c99007 --- a/module/wn_module_ssi.c +++ b/module/wn_module_ssi.c @@ -19,11 +19,15 @@ * Change Logs: * Date Author Notes * 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread + * 2022-09-07 zhaoyun the version transplanted for XiZi */ #include + +#include #include -#include #include +#include + #if defined(WEBNET_USING_SSI) #define SSI_INCLUDE_STRING " diff --git a/webnet/css/layout.css b/webnet/css/layout.css old mode 100644 new mode 100755 diff --git a/webnet/deviceinfo.asp b/webnet/deviceinfo.asp old mode 100644 new mode 100755 index 3acb30b..beb607b --- a/webnet/deviceinfo.asp +++ b/webnet/deviceinfo.asp @@ -3,12 +3,13 @@ + - + xidatong web server set page @@ -144,4 +145,4 @@ - + \ No newline at end of file diff --git a/webnet/favicon.ico b/webnet/favicon.ico new file mode 100755 index 0000000..382b603 Binary files /dev/null and b/webnet/favicon.ico differ diff --git a/webnet/index_origin.html b/webnet/index_origin.html old mode 100644 new mode 100755 diff --git a/webnet/js/Chart.bundle.min.js b/webnet/js/Chart.bundle.min.js old mode 100644 new mode 100755 diff --git a/webnet/logo/logo.png b/webnet/logo/logo.png old mode 100644 new mode 100755 diff --git a/webnet/mqtt.html b/webnet/mqtt.html old mode 100644 new mode 100755 index 74e75b5..6774be6 --- a/webnet/mqtt.html +++ b/webnet/mqtt.html @@ -2,6 +2,7 @@ + diff --git a/webnet/netsetting.html b/webnet/netsetting.html old mode 100644 new mode 100755 index e31d263..c552169 --- a/webnet/netsetting.html +++ b/webnet/netsetting.html @@ -2,6 +2,7 @@ xidatong web server set page + diff --git a/webnet/privateProtocol.html b/webnet/privateProtocol.html old mode 100644 new mode 100755 index cec550a..076c807 --- a/webnet/privateProtocol.html +++ b/webnet/privateProtocol.html @@ -2,6 +2,7 @@ + diff --git a/webnet/systemModify.html b/webnet/systemModify.html old mode 100644 new mode 100755 index fa673d5..5201a4a --- a/webnet/systemModify.html +++ b/webnet/systemModify.html @@ -2,6 +2,7 @@ + diff --git a/webnet/tcp.html b/webnet/tcp.html old mode 100644 new mode 100755 index 7e791c0..bb18337 --- a/webnet/tcp.html +++ b/webnet/tcp.html @@ -3,11 +3,12 @@ + - + xidatong web server set page