From 64e1a0fae7692f5ff5b78dace34131523c8575fd Mon Sep 17 00:00:00 2001 From: zhaoyun1215 <58766762@qq.com> Date: Fri, 9 Sep 2022 01:58:11 -0700 Subject: [PATCH 1/8] can be runned in xizi kernel --- Makefile | 3 ++ README.md | 9 +++- inc/webnet.h | 1 + inc/wn_module.h | 3 +- inc/wn_request.h | 24 +++++++++ inc/wn_session.h | 10 +++- inc/wn_utils.h | 1 + module/wn_module_alias.c | 8 ++- module/wn_module_asp.c | 23 +++++++-- module/wn_module_auth.c | 11 ++++ module/wn_module_cgi.c | 9 +++- module/wn_module_dav.c | 23 ++++++++- module/wn_module_index.c | 8 ++- module/wn_module_log.c | 14 ++++-- module/wn_module_ssi.c | 7 +++ module/wn_module_upload.c | 20 ++++++++ samples/deviceinfoasp.c | 26 +++++++++- samples/deviceinfoasp.h | 5 ++ samples/netsetting.c | 71 +++++++++++++++++++------- samples/netsetting.h | 7 ++- samples/uploaddata.c | 41 ++++++++++++--- samples/uploaddata.h | 2 + samples/wn_sample.c | 17 +++++-- samples/wn_sample_upload.c | 9 +++- src/webnet.c | 51 +++++++++++++++++-- src/wn_mimetype.c | 1 + src/wn_module.c | 50 +++++++++++++++++- src/wn_request.c | 92 ++++++++++++++++++++++++++++++++-- src/wn_session.c | 55 ++++++++++++++++---- src/wn_utils.c | 10 +++- webnet/chart.html | 1 + webnet/css/layout.css | 0 webnet/deviceinfo.asp | 5 +- webnet/favicon.ico | Bin 0 -> 9662 bytes webnet/index_origin.html | 0 webnet/js/Chart.bundle.min.js | 0 webnet/logo/logo.png | Bin webnet/mqtt.html | 1 + webnet/netsetting.html | 1 + webnet/privateProtocol.html | 1 + webnet/systemModify.html | 1 + webnet/tcp.html | 3 +- 42 files changed, 556 insertions(+), 68 deletions(-) create mode 100755 Makefile mode change 100644 => 100755 README.md mode change 100644 => 100755 inc/webnet.h mode change 100644 => 100755 inc/wn_module.h mode change 100644 => 100755 inc/wn_request.h mode change 100644 => 100755 inc/wn_session.h mode change 100644 => 100755 inc/wn_utils.h mode change 100644 => 100755 module/wn_module_alias.c mode change 100644 => 100755 module/wn_module_asp.c mode change 100644 => 100755 module/wn_module_auth.c mode change 100644 => 100755 module/wn_module_cgi.c mode change 100644 => 100755 module/wn_module_dav.c mode change 100644 => 100755 module/wn_module_index.c mode change 100644 => 100755 module/wn_module_log.c mode change 100644 => 100755 module/wn_module_ssi.c mode change 100644 => 100755 module/wn_module_upload.c mode change 100644 => 100755 samples/deviceinfoasp.c mode change 100644 => 100755 samples/deviceinfoasp.h mode change 100644 => 100755 samples/netsetting.c mode change 100644 => 100755 samples/netsetting.h mode change 100644 => 100755 samples/uploaddata.c mode change 100644 => 100755 samples/uploaddata.h mode change 100644 => 100755 samples/wn_sample.c mode change 100644 => 100755 samples/wn_sample_upload.c mode change 100644 => 100755 src/webnet.c mode change 100644 => 100755 src/wn_mimetype.c mode change 100644 => 100755 src/wn_module.c mode change 100644 => 100755 src/wn_request.c mode change 100644 => 100755 src/wn_session.c mode change 100644 => 100755 src/wn_utils.c mode change 100644 => 100755 webnet/chart.html mode change 100644 => 100755 webnet/css/layout.css mode change 100644 => 100755 webnet/deviceinfo.asp create mode 100755 webnet/favicon.ico mode change 100644 => 100755 webnet/index_origin.html mode change 100644 => 100755 webnet/js/Chart.bundle.min.js mode change 100644 => 100755 webnet/logo/logo.png mode change 100644 => 100755 webnet/mqtt.html mode change 100644 => 100755 webnet/netsetting.html mode change 100644 => 100755 webnet/privateProtocol.html mode change 100644 => 100755 webnet/systemModify.html mode change 100644 => 100755 webnet/tcp.html diff --git a/Makefile b/Makefile new file mode 100755 index 0000000..916e473 --- /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..e33e005 --- a/inc/webnet.h +++ b/inc/webnet.h @@ -23,6 +23,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 __WEBNET_H__ 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..c8c1516 --- a/inc/wn_request.h +++ b/inc/wn_request.h @@ -19,14 +19,23 @@ * 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 +#ifdef ADD_RTTHREAD_FETURES #include +#endif #include + +#ifdef ADD_XIZI_FETURES +#include +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -77,7 +86,12 @@ struct webnet_request char* modified; #endif /* WEBNET_CACHE_LEVEL */ #ifdef WEBNET_USING_GZIP + #ifdef ADD_RTTHREAD_FETURES bool support_gzip; + #endif + #ifdef ADD_XIZI_FETURES + _Bool support_gzip; + #endif #endif /* WEBNET_USING_GZIP */ char* user_agent; @@ -111,7 +125,12 @@ struct webnet_request enum webnet_connection connection; /* whether the string filed is copied */ + #ifdef ADD_RTTHREAD_FETURES bool field_copied; + #endif + #ifdef ADD_XIZI_FETURES + _Bool field_copied; + #endif }; struct webnet_request* webnet_request_create(void); @@ -123,7 +142,12 @@ int webnet_request_parse_post(struct webnet_request* request, char* buffer, int void webnet_request_parse(struct webnet_request* request, char* buffer, int length); +#ifdef ADD_RTTHREAD_FETURES bool webnet_request_has_query(struct webnet_request* request, char* name); +#endif +#ifdef ADD_XIZI_FETURES +_Bool webnet_request_has_query(struct webnet_request* request, char* name); +#endif 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..68971df --- 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,6 +28,13 @@ #include #include +#ifdef ADD_XIZI_FETURES +#include +#include "sys_arch.h" +#include +#include "lwip/sys.h" +#endif + #ifdef __cplusplus extern "C" { #endif 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/wn_module_alias.c b/module/wn_module_alias.c old mode 100644 new mode 100755 index cc46fec..f3d6039 --- a/module/wn_module_alias.c +++ b/module/wn_module_alias.c @@ -18,13 +18,19 @@ * * 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 ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_ALIAS struct webnet_alias_item diff --git a/module/wn_module_asp.c b/module/wn_module_asp.c old mode 100644 new mode 100755 index e6fe745..75abf54 --- a/module/wn_module_asp.c +++ b/module/wn_module_asp.c @@ -19,14 +19,22 @@ * 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 ADD_XIZI_FETURES +#include +#include // for "open,read,close",if not will use the command from lwip +#endif + #ifdef WEBNET_USING_ASP struct webnet_asp_variable @@ -111,11 +119,14 @@ static void _default_asp_handler(struct webnet_session* session, const char* nam } else if (strncmp(name, "TICK", 4) == 0) { - int32 tick; + int32 tick; //这里定义的tick是多少秒的意思,并不是正常意义上的tick(个人感觉定义为:sum_time更好) int32 hour, min, second; #ifdef ADD_RTTHREAD_FETURES tick = rt_tick_get()/RT_TICK_PER_SECOND; #endif + #ifdef ADD_XIZI_FETURES + tick = CurrentTicksGain() / TICK_PER_SECOND; + #endif second = tick % 60; min = (tick/60) % 60; hour = tick / (60 * 60); @@ -137,6 +148,9 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd) /* allocate read buffer */ buffer = (char*) wn_malloc (length); + #ifdef ADD_XIZI_FETURES + memset(buffer,0,length); + #endif if (buffer == NULL) { session->request->result_code = 500; @@ -180,7 +194,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 +233,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) || @@ -236,6 +252,7 @@ int webnet_module_asp(struct webnet_session* session, int event) { /* no this file */ request->result_code = 404; + close(fd);//zhaoyun add return WEBNET_MODULE_FINISHED; } } diff --git a/module/wn_module_auth.c b/module/wn_module_auth.c old mode 100644 new mode 100755 index 0eb9a97..54b2a14 --- a/module/wn_module_auth.c +++ b/module/wn_module_auth.c @@ -19,13 +19,21 @@ * 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 +#ifdef ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_AUTH struct webnet_auth_item { @@ -77,7 +85,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..cd58daa --- a/module/wn_module_cgi.c +++ b/module/wn_module_cgi.c @@ -18,15 +18,22 @@ * * 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 ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_CGI #define CGI_ROOT_PATH_MAX 64 diff --git a/module/wn_module_dav.c b/module/wn_module_dav.c old mode 100644 new mode 100755 index 3e90736..0a940da --- a/module/wn_module_dav.c +++ b/module/wn_module_dav.c @@ -18,13 +18,20 @@ * * 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 ADD_XIZI_FETURES +#include +#endif #ifdef WEBNET_USING_DAV struct webnet_module_put_entry @@ -276,9 +283,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_FETURES + long lock; + lock = CriticalAreaLock(); + #endif + 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_FETURES + CriticalAreaUnLock(lock); + #endif //printf("strftime: %s\n", ctime_str); webnet_session_printf(session, diff --git a/module/wn_module_index.c b/module/wn_module_index.c old mode 100644 new mode 100755 index 1732cf1..de83d9e --- a/module/wn_module_index.c +++ b/module/wn_module_index.c @@ -18,13 +18,19 @@ * * 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 ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_INDEX int webnet_module_dirindex(struct webnet_session* session, int event) diff --git a/module/wn_module_log.c b/module/wn_module_log.c old mode 100644 new mode 100755 index 3ce0ab9..c6de21c --- a/module/wn_module_log.c +++ b/module/wn_module_log.c @@ -18,13 +18,19 @@ * * 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 ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_LOG int webnet_module_log(struct webnet_session* session, int event) @@ -42,7 +48,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 +81,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 +93,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..b8c5ef2 --- a/module/wn_module_ssi.c +++ b/module/wn_module_ssi.c @@ -19,11 +19,18 @@ * 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 + +#ifdef ADD_XIZI_FETURES +#include +#endif + #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 0000000000000000000000000000000000000000..382b603750cf897b0f0b687d15a0e086c9f46f07 GIT binary patch literal 9662 zcmeI2dr(!^6~+%pjcttSm`+U76!V8xxmZoxB(xQ!QDZbdqM%6PgNLI5dC22}NK8Ny zjiOCyXb`JTP2!7G-U=1sh*Eh9Mz9(OYl>)1h|@9J;8nTb>bLK`haM4#V`!Q`?s0y1 z?Q_oFYkzC)*I`CYbK$=yp3wOFxVC4wrai1_+DO7jS`bmsZPzeOd+2^U_6N>iX9k=Z zaAv@n0cQrB8E|I6nE_`8zS#_*d9H?*S$*26)2-P4-22u; zYlfgawbNgB1=Sz%Am@m5QW*dH`smRU*-twW2RCV_JM_D=ZcAr^J{J2&rUOB2dY{WSBW7L0x_kF9s(5y+G*;C3_p2LY4!SQ8+>ZOA6P(i_bL3Ypy zP5W^t)D7Fc202qwBYnfj?;&N1Mgc<{HL?X z&d9~ij5K_($jU2o~HhP z8e)Lt#U{!w?mZvveM;(fT*PT=Zmy#K2JX3sseiYibgLjgU9clXkjb^bVWA+EXGzjb z+5nMM?#=5~3SM6>hzq=h^;J*(v|VyDQtVEz#1E9xfg0g5<{9 zV0@Xe0+!6wCaj6rfaJwXWl!`4$)_K+*6e-Vjs6O1zrQE_Dkl0;sBZ$LS@#W=bBJNT zj1|VR&RS}Au^!FoZ>`E7Y%SY790%U+c5tcbosC)IRVo^s5-+h}F=Cib0P@*)wD~xnn46!aX$NL)wXO|Ixo; zg3qM*DBt(0zmnP?=uN+242H0uDq_^Empk}8n%KsxYXHhW>H7VkV)(lHtLbBq^55H~ z>!J-H*NLuMw<@lONw;p4fAW9RuS6+rM4f5HMAxnC4H8JY&An=S&-z7F+Ys^wNhWnf zjhjv@%d5$&%BsG4x^#WC&yg!ck3pT$Dz2WI-mCu5w})wN)KyM&y}jBV1vp+Pjl}q! zsm^9~M)#O|)s+1!e2DS;Uuo%W{`a|lrNyDui?)sIChCk#qw)>Q!t~Ogf$YEXkyA5Q$e`v05n!#RS zQy1PV+mF`reN9vTEWB5?L$mvX_L|KfG}x@@)&*_@RQIdlMx)8=4qM@{RStW}VgE<@ F`41%L + 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 fd01360..62bccf7 --- 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 -- 2.34.1 From 0ec3efb66fc471b838842f43b8cbfc24755276e5 Mon Sep 17 00:00:00 2001 From: zhaoyun1215 <58766762@qq.com> Date: Wed, 14 Sep 2022 05:13:19 -0700 Subject: [PATCH 2/8] for webnet and netdev --- README.md | 9 +++- inc/webnet.h | 14 ++++++ inc/wn_module.h | 3 +- inc/wn_request.h | 24 +++++++++ inc/wn_session.h | 10 +++- inc/wn_utils.h | 1 + module/wn_module_alias.c | 8 ++- module/wn_module_asp.c | 38 ++++++++++---- module/wn_module_auth.c | 11 ++++ module/wn_module_cgi.c | 9 +++- module/wn_module_dav.c | 31 ++++++++++-- module/wn_module_index.c | 8 ++- module/wn_module_log.c | 14 ++++-- module/wn_module_ssi.c | 29 +++++++---- module/wn_module_upload.c | 22 +++++++- samples/deviceinfoasp.c | 26 +++++++++- samples/deviceinfoasp.h | 5 ++ samples/netsetting.c | 71 +++++++++++++++++++------- samples/netsetting.h | 7 ++- samples/uploaddata.c | 47 +++++++++++++---- samples/uploaddata.h | 2 + samples/wn_sample.c | 17 +++++-- samples/wn_sample_upload.c | 13 +++-- src/webnet.c | 65 ++++++++++++++++++++---- src/wn_mimetype.c | 1 + src/wn_module.c | 62 ++++++++++++++++++++--- src/wn_request.c | 92 ++++++++++++++++++++++++++++++++-- src/wn_session.c | 55 ++++++++++++++++---- src/wn_utils.c | 10 +++- webnet/chart.html | 1 + webnet/css/layout.css | 0 webnet/deviceinfo.asp | 5 +- webnet/index_origin.html | 0 webnet/js/Chart.bundle.min.js | 0 webnet/logo/logo.png | Bin webnet/mqtt.html | 1 + webnet/netsetting.html | 1 + webnet/privateProtocol.html | 1 + webnet/systemModify.html | 1 + webnet/tcp.html | 3 +- 40 files changed, 611 insertions(+), 106 deletions(-) mode change 100644 => 100755 README.md mode change 100644 => 100755 inc/webnet.h mode change 100644 => 100755 inc/wn_module.h mode change 100644 => 100755 inc/wn_request.h mode change 100644 => 100755 inc/wn_session.h mode change 100644 => 100755 inc/wn_utils.h mode change 100644 => 100755 module/wn_module_alias.c mode change 100644 => 100755 module/wn_module_asp.c mode change 100644 => 100755 module/wn_module_auth.c mode change 100644 => 100755 module/wn_module_cgi.c mode change 100644 => 100755 module/wn_module_dav.c mode change 100644 => 100755 module/wn_module_index.c mode change 100644 => 100755 module/wn_module_log.c mode change 100644 => 100755 module/wn_module_ssi.c mode change 100644 => 100755 module/wn_module_upload.c mode change 100644 => 100755 samples/deviceinfoasp.c mode change 100644 => 100755 samples/deviceinfoasp.h mode change 100644 => 100755 samples/netsetting.c mode change 100644 => 100755 samples/netsetting.h mode change 100644 => 100755 samples/uploaddata.c mode change 100644 => 100755 samples/uploaddata.h mode change 100644 => 100755 samples/wn_sample.c mode change 100644 => 100755 samples/wn_sample_upload.c mode change 100644 => 100755 src/webnet.c mode change 100644 => 100755 src/wn_mimetype.c mode change 100644 => 100755 src/wn_module.c mode change 100644 => 100755 src/wn_request.c mode change 100644 => 100755 src/wn_session.c mode change 100644 => 100755 src/wn_utils.c mode change 100644 => 100755 webnet/chart.html mode change 100644 => 100755 webnet/css/layout.css mode change 100644 => 100755 webnet/deviceinfo.asp mode change 100644 => 100755 webnet/index_origin.html mode change 100644 => 100755 webnet/js/Chart.bundle.min.js mode change 100644 => 100755 webnet/logo/logo.png mode change 100644 => 100755 webnet/mqtt.html mode change 100644 => 100755 webnet/netsetting.html mode change 100644 => 100755 webnet/privateProtocol.html mode change 100644 => 100755 webnet/systemModify.html mode change 100644 => 100755 webnet/tcp.html 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..ab48205 --- a/inc/webnet.h +++ b/inc/webnet.h @@ -23,6 +23,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 __WEBNET_H__ @@ -50,6 +51,19 @@ extern "C" { #define wn_strdup strdup #endif +#ifndef wn_read +#define wn_read PrivRead +#endif + +#ifndef wn_open +#define wn_open open +#endif + +#ifndef wn_close +#define wn_close close +#endif + + #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..c8c1516 --- a/inc/wn_request.h +++ b/inc/wn_request.h @@ -19,14 +19,23 @@ * 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 +#ifdef ADD_RTTHREAD_FETURES #include +#endif #include + +#ifdef ADD_XIZI_FETURES +#include +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -77,7 +86,12 @@ struct webnet_request char* modified; #endif /* WEBNET_CACHE_LEVEL */ #ifdef WEBNET_USING_GZIP + #ifdef ADD_RTTHREAD_FETURES bool support_gzip; + #endif + #ifdef ADD_XIZI_FETURES + _Bool support_gzip; + #endif #endif /* WEBNET_USING_GZIP */ char* user_agent; @@ -111,7 +125,12 @@ struct webnet_request enum webnet_connection connection; /* whether the string filed is copied */ + #ifdef ADD_RTTHREAD_FETURES bool field_copied; + #endif + #ifdef ADD_XIZI_FETURES + _Bool field_copied; + #endif }; struct webnet_request* webnet_request_create(void); @@ -123,7 +142,12 @@ int webnet_request_parse_post(struct webnet_request* request, char* buffer, int void webnet_request_parse(struct webnet_request* request, char* buffer, int length); +#ifdef ADD_RTTHREAD_FETURES bool webnet_request_has_query(struct webnet_request* request, char* name); +#endif +#ifdef ADD_XIZI_FETURES +_Bool webnet_request_has_query(struct webnet_request* request, char* name); +#endif 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..68971df --- 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,6 +28,13 @@ #include #include +#ifdef ADD_XIZI_FETURES +#include +#include "sys_arch.h" +#include +#include "lwip/sys.h" +#endif + #ifdef __cplusplus extern "C" { #endif 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/wn_module_alias.c b/module/wn_module_alias.c old mode 100644 new mode 100755 index cc46fec..1227174 --- a/module/wn_module_alias.c +++ b/module/wn_module_alias.c @@ -18,13 +18,19 @@ * * 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 ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_ALIAS struct webnet_alias_item diff --git a/module/wn_module_asp.c b/module/wn_module_asp.c old mode 100644 new mode 100755 index e6fe745..d4cb846 --- a/module/wn_module_asp.c +++ b/module/wn_module_asp.c @@ -19,14 +19,22 @@ * 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 ADD_XIZI_FETURES +#include +//#include // for "open,read,close",if not will use the command from lwip +#endif + #ifdef WEBNET_USING_ASP struct webnet_asp_variable @@ -111,11 +119,14 @@ static void _default_asp_handler(struct webnet_session* session, const char* nam } else if (strncmp(name, "TICK", 4) == 0) { - int32 tick; + int32 tick; //这里定义的tick是多少秒的意思,并不是正常意义上的tick(个人感觉定义为:sum_time更好) int32 hour, min, second; #ifdef ADD_RTTHREAD_FETURES tick = rt_tick_get()/RT_TICK_PER_SECOND; #endif + #ifdef ADD_XIZI_FETURES + tick = CurrentTicksGain() / TICK_PER_SECOND; + #endif second = tick % 60; min = (tick/60) % 60; hour = tick / (60 * 60); @@ -134,9 +145,12 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd) /* get file length */ length = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); - + printf("length:%d\n",length); //needed to delete /* allocate read buffer */ buffer = (char*) wn_malloc (length); + #ifdef ADD_XIZI_FETURES + memset(buffer,0,length); + #endif if (buffer == NULL) { session->request->result_code = 500; @@ -146,7 +160,10 @@ 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 */ + + int read_length=wn_read(fd, buffer, (uint32)length); + printf("read_length:%d\n",read_length); //needed to delete + if (read_length != length) /* read failed */ { wn_free(buffer); session->request->result_code = 500; @@ -180,7 +197,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 +236,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,17 +244,18 @@ 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 { /* no this file */ request->result_code = 404; + wn_close(fd);//zhaoyun add return WEBNET_MODULE_FINISHED; } } @@ -248,13 +268,13 @@ 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); + fd = wn_open(asp_filename, O_RDONLY, 0); if (fd >= 0) { wn_free(asp_filename); _webnet_asp_dofile(session, fd); - close(fd); + wn_close(fd); return WEBNET_MODULE_FINISHED; } } diff --git a/module/wn_module_auth.c b/module/wn_module_auth.c old mode 100644 new mode 100755 index 0eb9a97..54b2a14 --- a/module/wn_module_auth.c +++ b/module/wn_module_auth.c @@ -19,13 +19,21 @@ * 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 +#ifdef ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_AUTH struct webnet_auth_item { @@ -77,7 +85,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..cd58daa --- a/module/wn_module_cgi.c +++ b/module/wn_module_cgi.c @@ -18,15 +18,22 @@ * * 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 ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_CGI #define CGI_ROOT_PATH_MAX 64 diff --git a/module/wn_module_dav.c b/module/wn_module_dav.c old mode 100644 new mode 100755 index 3e90736..4f148cd --- a/module/wn_module_dav.c +++ b/module/wn_module_dav.c @@ -18,13 +18,20 @@ * * 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 ADD_XIZI_FETURES +#include +#endif #ifdef WEBNET_USING_DAV struct webnet_module_put_entry @@ -100,10 +107,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 +283,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_FETURES + long lock; + lock = CriticalAreaLock(); + #endif + 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_FETURES + CriticalAreaUnLock(lock); + #endif //printf("strftime: %s\n", ctime_str); webnet_session_printf(session, @@ -296,7 +317,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 +340,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..de83d9e --- a/module/wn_module_index.c +++ b/module/wn_module_index.c @@ -18,13 +18,19 @@ * * 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 ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_INDEX int webnet_module_dirindex(struct webnet_session* session, int event) diff --git a/module/wn_module_log.c b/module/wn_module_log.c old mode 100644 new mode 100755 index 3ce0ab9..c6de21c --- a/module/wn_module_log.c +++ b/module/wn_module_log.c @@ -18,13 +18,19 @@ * * 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 ADD_XIZI_FETURES +#include +#endif + #ifdef WEBNET_USING_LOG int webnet_module_log(struct webnet_session* session, int event) @@ -42,7 +48,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 +81,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 +93,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..9d4ecfe --- a/module/wn_module_ssi.c +++ b/module/wn_module_ssi.c @@ -19,11 +19,18 @@ * 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 + +#ifdef ADD_XIZI_FETURES +#include +#endif + #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/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 fd01360..62bccf7 --- 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 -- 2.34.1 From 1dff04fd3880640400f9fb8472706e428be2f137 Mon Sep 17 00:00:00 2001 From: zhaoyun1215 <58766762@qq.com> Date: Wed, 14 Sep 2022 05:22:14 -0700 Subject: [PATCH 3/8] for webnet and netdev --- .vscode/settings.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .vscode/settings.json 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 -- 2.34.1 From 135c842fb84deb8dfbbf2bb86d70508986d21aa1 Mon Sep 17 00:00:00 2001 From: zhaoyun1215 <58766762@qq.com> Date: Wed, 14 Sep 2022 20:28:45 -0700 Subject: [PATCH 4/8] change for posix --- inc/wn_request.h | 25 +---------- inc/wn_session.h | 7 ---- module/wn_module_alias.c | 6 +-- module/wn_module_asp.c | 35 ++++++---------- module/wn_module_auth.c | 5 --- module/wn_module_cgi.c | 4 -- module/wn_module_dav.c | 7 +--- module/wn_module_index.c | 3 -- module/wn_module_log.c | 3 -- module/wn_module_ssi.c | 3 -- module/wn_module_upload.c | 20 +-------- samples/deviceinfoasp.c | 8 ++-- samples/netsetting.c | 9 +--- samples/uploaddata.c | 25 +++++------ src/webnet.c | 58 +++----------------------- src/wn_module.c | 27 ++---------- src/wn_request.c | 88 ++------------------------------------- src/wn_session.c | 9 ---- src/wn_utils.c | 11 +---- 19 files changed, 46 insertions(+), 307 deletions(-) diff --git a/inc/wn_request.h b/inc/wn_request.h index c8c1516..0129393 100755 --- a/inc/wn_request.h +++ b/inc/wn_request.h @@ -25,17 +25,8 @@ #ifndef __WN_REQUEST_H__ #define __WN_REQUEST_H__ #include -#ifdef ADD_RTTHREAD_FETURES -#include -#endif #include - -#ifdef ADD_XIZI_FETURES -#include -#include -#endif - #ifdef __cplusplus extern "C" { #endif @@ -86,12 +77,7 @@ struct webnet_request char* modified; #endif /* WEBNET_CACHE_LEVEL */ #ifdef WEBNET_USING_GZIP - #ifdef ADD_RTTHREAD_FETURES bool support_gzip; - #endif - #ifdef ADD_XIZI_FETURES - _Bool support_gzip; - #endif #endif /* WEBNET_USING_GZIP */ char* user_agent; @@ -125,12 +111,7 @@ struct webnet_request enum webnet_connection connection; /* whether the string filed is copied */ - #ifdef ADD_RTTHREAD_FETURES bool field_copied; - #endif - #ifdef ADD_XIZI_FETURES - _Bool field_copied; - #endif }; struct webnet_request* webnet_request_create(void); @@ -142,12 +123,8 @@ int webnet_request_parse_post(struct webnet_request* request, char* buffer, int void webnet_request_parse(struct webnet_request* request, char* buffer, int length); -#ifdef ADD_RTTHREAD_FETURES bool webnet_request_has_query(struct webnet_request* request, char* name); -#endif -#ifdef ADD_XIZI_FETURES -_Bool webnet_request_has_query(struct webnet_request* request, char* name); -#endif + 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 index 68971df..37d5f61 100755 --- a/inc/wn_session.h +++ b/inc/wn_session.h @@ -28,13 +28,6 @@ #include #include -#ifdef ADD_XIZI_FETURES -#include -#include "sys_arch.h" -#include -#include "lwip/sys.h" -#endif - #ifdef __cplusplus extern "C" { #endif diff --git a/module/wn_module_alias.c b/module/wn_module_alias.c index f3d6039..741e2cd 100755 --- a/module/wn_module_alias.c +++ b/module/wn_module_alias.c @@ -18,7 +18,7 @@ * * 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 */ @@ -26,10 +26,8 @@ #include #include #include +#include -#ifdef ADD_XIZI_FETURES -#include -#endif #ifdef WEBNET_USING_ALIAS diff --git a/module/wn_module_asp.c b/module/wn_module_asp.c index 75abf54..557b875 100755 --- a/module/wn_module_asp.c +++ b/module/wn_module_asp.c @@ -22,19 +22,13 @@ * 2022-09-07 zhaoyun the version transplanted for XiZi */ -#include +#include #include #include #include #include #include - -#ifdef ADD_XIZI_FETURES -#include -#include // for "open,read,close",if not will use the command from lwip -#endif - #ifdef WEBNET_USING_ASP struct webnet_asp_variable @@ -119,18 +113,12 @@ static void _default_asp_handler(struct webnet_session* session, const char* nam } else if (strncmp(name, "TICK", 4) == 0) { - int32 tick; //这里定义的tick是多少秒的意思,并不是正常意义上的tick(个人感觉定义为:sum_time更好) + int32 tick; int32 hour, min, second; - #ifdef ADD_RTTHREAD_FETURES - tick = rt_tick_get()/RT_TICK_PER_SECOND; - #endif - #ifdef ADD_XIZI_FETURES - tick = CurrentTicksGain() / TICK_PER_SECOND; - #endif + tick = GetTick(); second = tick % 60; min = (tick/60) % 60; hour = tick / (60 * 60); - webnet_session_printf(session, "%02d:%02d:%02d", hour, min, second); } } @@ -148,9 +136,7 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd) /* allocate read buffer */ buffer = (char*) wn_malloc (length); - #ifdef ADD_XIZI_FETURES memset(buffer,0,length); - #endif if (buffer == NULL) { session->request->result_code = 500; @@ -160,7 +146,10 @@ 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 */ + + int read_length=wn_read(fd, buffer, (uint32)length); + printf("read_lenth:%d\n",read_length);//needed to delete + if (read_length != length) /* read failed */ { wn_free(buffer); session->request->result_code = 500; @@ -241,18 +230,18 @@ 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 { /* no this file */ request->result_code = 404; - close(fd);//zhaoyun add + wn_close(fd);//zhaoyun add return WEBNET_MODULE_FINISHED; } } @@ -265,13 +254,13 @@ 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); + fd = wn_open(asp_filename, O_RDONLY, 0); if (fd >= 0) { wn_free(asp_filename); _webnet_asp_dofile(session, fd); - close(fd); + wn_close(fd); return WEBNET_MODULE_FINISHED; } } diff --git a/module/wn_module_auth.c b/module/wn_module_auth.c index 54b2a14..7cf6c78 100755 --- a/module/wn_module_auth.c +++ b/module/wn_module_auth.c @@ -23,16 +23,11 @@ */ #include - - #include #include #include #include -#ifdef ADD_XIZI_FETURES -#include -#endif #ifdef WEBNET_USING_AUTH struct webnet_auth_item diff --git a/module/wn_module_cgi.c b/module/wn_module_cgi.c index cd58daa..bd27c0e 100755 --- a/module/wn_module_cgi.c +++ b/module/wn_module_cgi.c @@ -30,10 +30,6 @@ #include -#ifdef ADD_XIZI_FETURES -#include -#endif - #ifdef WEBNET_USING_CGI #define CGI_ROOT_PATH_MAX 64 diff --git a/module/wn_module_dav.c b/module/wn_module_dav.c index 4f148cd..27dad76 100755 --- a/module/wn_module_dav.c +++ b/module/wn_module_dav.c @@ -29,9 +29,6 @@ #include -#ifdef ADD_XIZI_FETURES -#include -#endif #ifdef WEBNET_USING_DAV struct webnet_module_put_entry @@ -290,7 +287,7 @@ static void print_propfind_element(struct webnet_session *session, const char *u #ifdef ADD_XIZI_FETURES long lock; lock = CriticalAreaLock(); - #endif + #endif //ADD_XIZI_FETURES strftime(ctime_str, sizeof(ctime_str), "%a, %d %b %Y %H:%M:%S GMT", localtime(&t)); #ifdef ADD_RTTHREAD_FETURES @@ -299,7 +296,7 @@ static void print_propfind_element(struct webnet_session *session, const char *u #ifdef ADD_XIZI_FETURES CriticalAreaUnLock(lock); - #endif + #endif //ADD_XIZI_FETURES //printf("strftime: %s\n", ctime_str); webnet_session_printf(session, diff --git a/module/wn_module_index.c b/module/wn_module_index.c index de83d9e..c4498c8 100755 --- a/module/wn_module_index.c +++ b/module/wn_module_index.c @@ -27,9 +27,6 @@ #include #include -#ifdef ADD_XIZI_FETURES -#include -#endif #ifdef WEBNET_USING_INDEX diff --git a/module/wn_module_log.c b/module/wn_module_log.c index c6de21c..c3737c2 100755 --- a/module/wn_module_log.c +++ b/module/wn_module_log.c @@ -27,9 +27,6 @@ #include #include -#ifdef ADD_XIZI_FETURES -#include -#endif #ifdef WEBNET_USING_LOG diff --git a/module/wn_module_ssi.c b/module/wn_module_ssi.c index 9d4ecfe..63fad19 100755 --- a/module/wn_module_ssi.c +++ b/module/wn_module_ssi.c @@ -27,9 +27,6 @@ #include #include -#ifdef ADD_XIZI_FETURES -#include -#endif #if defined(WEBNET_USING_SSI) diff --git a/module/wn_module_upload.c b/module/wn_module_upload.c index c156a14..5d2d34e 100755 --- a/module/wn_module_upload.c +++ b/module/wn_module_upload.c @@ -28,10 +28,6 @@ #include -#ifdef ADD_XIZI_FETURES -#include -#endif - #if defined(WEBNET_USING_UPLOAD) #define MULTIPART_FORM_DATA_STRING "multipart/form-data" @@ -162,7 +158,7 @@ static char* memstrs(const char* str, uint32 length, int num, ...) return ptr; } -#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) + static void* memrchr(const void *s, int c, uint32 n) { register const char* t=s; @@ -181,7 +177,6 @@ static void* memrchr(const void *s, int c, uint32 n) } return (void*)last; /* man, what an utterly b0rken prototype */ } -#endif static char* _webnet_module_upload_parse_header(struct webnet_session* session, char* buffer, uint32 length) { @@ -338,19 +333,6 @@ static char* _webnet_module_upload_parse_header(struct webnet_session* session, return ptr; } -#ifdef ADD_XIZI_FETURES -void* memrchr(const void* ptr, int ch, size_t pos) -{ - char* end = (char*)ptr + pos - 1; - while (end != ptr) - { - if (*end == ch) - return end; - end--; - } - return (*end == ch) ? (end) : (NULL); -} -#endif static char* _next_possible_boundary(struct webnet_session* session, char* buffer, uint32 length) { diff --git a/samples/deviceinfoasp.c b/samples/deviceinfoasp.c index d4e152f..98dacbb 100755 --- a/samples/deviceinfoasp.c +++ b/samples/deviceinfoasp.c @@ -1,9 +1,7 @@ #include "deviceinfoasp.h" #ifdef ADD_XIZI_FETURES -#include -#include extern void HwCpuReset();//reset machine -#endif +#endif //ADD_XIZI_FETURES #ifdef ADD_XIZI_FETURES deviceinfo xidatong_deviceinfo = @@ -16,7 +14,7 @@ deviceinfo xidatong_deviceinfo = SYSTEM_VERSION, WEB_VERSION }; -#endif +#endif //ADD_XIZI_FETURES #ifdef ADD_RTTHREAD_FETURES deviceinfo xidatong_deviceinfo = @@ -107,7 +105,7 @@ void cgi_device_reboot(struct webnet_session* session) #ifdef ADD_XIZI_FETURES HwCpuReset(); - #endif + #endif //ADD_XIZI_FETURES } diff --git a/samples/netsetting.c b/samples/netsetting.c index c74ab9c..67c8534 100755 --- a/samples/netsetting.c +++ b/samples/netsetting.c @@ -3,14 +3,9 @@ #ifdef ADD_XIZI_FETURES -#include -#include // for "open,read,close",if not will use the command from lwip -#include "sys_arch.h" -#include -#include "lwip/sys.h" #include #include -#endif +#endif //ADD_XIZI_FETURES static mqttsetting mqttweb; static local_tcpip local_tcpipweb; @@ -129,7 +124,7 @@ static void device_get_tcpip_parameter() #ifdef ADD_XIZI_FETURES SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), device_get_tcpip_parameter,device_get_tcpip_parameter, device_get_tcpip_parameter); -#endif +#endif //ADD_XIZI_FETURES char *json_create_tcpip_data(void) { diff --git a/samples/uploaddata.c b/samples/uploaddata.c index d3feb79..fbc752c 100755 --- a/samples/uploaddata.c +++ b/samples/uploaddata.c @@ -1,17 +1,12 @@ #include "uploaddata.h" - -#ifdef ADD_XIZI_FETURES #include -#include -#include -#endif //ADD_XIZI_FETURES char msg[] = "/mq_upload_web"; sensor_msg eg_temperature; sensor_msg web_show; static mqd_t mq_web=-1; -void upload_receive_web_msg_thread() +void *upload_receive_web_msg_thread() { int nbytes = 0; while(1) @@ -56,27 +51,27 @@ int uploaddata_init() printf("mq_open success: %d \n",mq_web); } - - #ifdef ADD_RTTHREAD_FETURES pthread_t tid = 0; pthread_attr_t attr; struct sched_param prio; + + #ifdef ADD_RTTHREAD_FETURES prio.sched_priority = 8; + #endif //ADD_RTTHREAD_FETURES + + #ifdef ADD_XIZI_FETURES + prio.sched_priority = 25; + #endif //ADD_XIZI_FETURES + size_t stack_size = 1024 * 11; pthread_attr_init(&attr); pthread_attr_setschedparam(&attr, &prio); pthread_attr_setstacksize(&attr, stack_size); result = pthread_create(&tid, &attr,upload_receive_web_msg_thread, NULL); - #endif //ADD_RTTHREAD_FETURES - - #ifdef ADD_XIZI_FETURES - result = sys_thread_new("upload_receive_web_msg_thread", upload_receive_web_msg_thread, NULL, WEBNET_THREAD_STACKSIZE, 25); - #endif //ADD_XIZI_FETURES - if (result>=0) { printf("thread_detect_entry successfully!\n"); - } + } else { printf("thread_detect_entry failed! error code is %d.\n", result); diff --git a/src/webnet.c b/src/webnet.c index aeec69b..cfcb68f 100755 --- a/src/webnet.c +++ b/src/webnet.c @@ -27,43 +27,15 @@ #include #include -#ifdef ADD_XIZI_FETURES -#include "sys_arch.h" -#include -#include "lwip/sys.h" -#include -#endif // ADD_XIZI_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 -#endif -/* -other os kernel need to notice the point about lwip thread stack. -*/ - static uint8 webnet_port = WEBNET_PORT; static char webnet_root[64] = WEBNET_ROOT; -#ifdef ADD_XIZI_FETURES -static _Bool init_ok = 0; -#endif // ADD_XIZI_FETURES -#ifdef ADD_RTTHREAD_FETURES + static bool init_ok = FALSE; -#endif //ADD_RTTHREAD_FETURES void webnet_set_port(int port) { - #ifdef ADD_XIZI_FETURES - assert(init_ok == 0); - #endif // ADD_XIZI_FETURES - - #ifdef ADD_RTTHREAD_FETURES assert(init_ok == FALSE); - #endif //ADD_RTTHREAD_FETURES webnet_port = port; } @@ -86,7 +58,7 @@ const char* webnet_get_root(void) /** * webnet thread entry */ -static void webnet_thread(void *parameter) +static void *webnet_thread(void *parameter) { int listenfd = -1; fd_set readset, tempfds; @@ -151,7 +123,7 @@ static void webnet_thread(void *parameter) tempwrtfds = writeset; /* Wait for data or a new connection */ #ifdef ADD_XIZI_FETURES - sys_msleep(1); + sys_msleep(100); #endif // ADD_XIZI_FETURES sock_fd = select(maxfdp1, &tempfds, &tempwrtfds, 0, 0); if (sock_fd == 0) @@ -203,42 +175,22 @@ int webnet_init(void) lwip_config_net(lwip_ipaddr, lwip_netmask, lwip_gwaddr); #endif // ADD_XIZI_FETURES - #ifdef ADD_RTTHREAD_FETURES pthread_t tid; pthread_attr_t attr; struct sched_param prio; prio.sched_priority = WEBNET_PRIORITY; size_t stack_size = WEBNET_THREAD_STACKSIZE; + pthread_attr_init(&attr); pthread_attr_setschedparam(&attr, &prio); pthread_attr_setstacksize(&attr, stack_size); - if (init_ok == TRUE) - { - printf("XiUOS webnet package is already initialized."); - return 0; - } result = pthread_create(&tid, &attr, webnet_thread, NULL); - #endif //ADD_RTTHREAD_FETURES - - #ifdef ADD_XIZI_FETURES - result = sys_thread_new("webnet_init", webnet_thread, NULL, WEBNET_THREAD_STACKSIZE, WEBNET_PRIORITY); - #endif // ADD_XIZI_FETURES - - #ifdef ADD_XIZI_FETURES - if (result>=0) - { - init_ok = 1; - printf("XiUOS webnet initialize success\n."); - } - #endif // ADD_XIZI_FETURES - - #ifdef ADD_RTTHREAD_FETURES + if (0 == result) { init_ok = TRUE; printf("XiUOS webnet initialize success."); } - #endif //ADD_RTTHREAD_FETURES else { printf("XiUOS webnet initialize failed\n."); diff --git a/src/wn_module.c b/src/wn_module.c index a2eefe0..fbc2d7c 100755 --- a/src/wn_module.c +++ b/src/wn_module.c @@ -27,12 +27,6 @@ #include -#ifdef ADD_XIZI_FETURES -#include -#include -#include -#endif // ADD_XIZI_FETURES - static int _webnet_module_system_init(struct webnet_session *session, int event) { #ifdef WEBNET_USING_LOG @@ -147,13 +141,7 @@ int webnet_module_system_dofile(struct webnet_session *session) int fd = -1; /* file descriptor */ struct stat file_stat; const char *mimetype; - - #ifdef ADD_XIZI_FETURES - size_t file_length; - #endif // ADD_XIZI_FETURES - #ifdef ADD_RTTHREAD_FETURES - unsigned long file_length; - #endif //ADD_RTTHREAD_FETURES + unsigned long file_length; struct webnet_request *request; #if WEBNET_CACHE_LEVEL > 0 @@ -185,13 +173,10 @@ int webnet_module_system_dofile(struct webnet_session *session) if (stat_result == 0) { - //PrivTaskenterCritical(); #ifdef ADD_XIZI_FETURES long lock; - int lock = CriticalAreaLock(); - #endif // ADD_XIZI_FETURES - - + lock = CriticalAreaLock(); + #endif // ADD_XIZI_FETURES #ifdef ADD_RTTHREAD_FETURES PrivTaskenterCritical(); @@ -279,13 +264,7 @@ int webnet_module_system_dofile(struct webnet_session *session) if (fd < 0) { /* .gz not exist, use raw. */ - #ifdef ADD_XIZI_FETURES - request->support_gzip = 0;//0 ->false - #endif // ADD_XIZI_FETURES - - #ifdef ADD_RTTHREAD_FETURES request->support_gzip = FALSE; - #endif //ADD_RTTHREAD_FETURES } } } diff --git a/src/wn_request.c b/src/wn_request.c index 8c26d41..08294e0 100755 --- a/src/wn_request.c +++ b/src/wn_request.c @@ -29,11 +29,6 @@ #include #include -#ifdef ADD_XIZI_FETURES -#include -#include -#include -#endif // ADD_XIZI_FETURES #define POST_BUFSZ_MAX (8 * 1024) @@ -147,42 +142,22 @@ static void _webnet_request_copy_str(struct webnet_request* request) #ifdef WEBNET_USING_RANGE if (request->Range) request->Range = wn_strdup(request->Range); #endif /* WEBNET_USING_RANGE */ - - #ifdef ADD_XIZI_FETURES - request->field_copied = 1;//true - #endif // ADD_XIZI_FETURES - - #ifdef ADD_RTTHREAD_FETURES request->field_copied = TRUE; - #endif //ADD_RTTHREAD_FETURES } /** * to check whether a query on the http request. */ -_Bool webnet_request_has_query(struct webnet_request* request, char* name) +bool webnet_request_has_query(struct webnet_request* request, char* name) { uint32 index; for (index = 0; index < request->query_counter; index ++) { if (strncmp(request->query_items[index].name, name, strlen(name)) == 0) - - #ifdef ADD_XIZI_FETURES - return 1;//true - #endif // ADD_XIZI_FETURES - - #ifdef ADD_RTTHREAD_FETURES return TRUE; - #endif //ADD_RTTHREAD_FETURES } - #ifdef ADD_XIZI_FETURES - return 0;//true - #endif // ADD_XIZI_FETURES - - #ifdef ADD_RTTHREAD_FETURES - return FALSE; - #endif //ADD_RTTHREAD_FETURES + return FALSE; } #ifdef ADD_RTTHREAD_FETURES RTM_EXPORT(webnet_request_has_query); @@ -340,14 +315,8 @@ int webnet_request_parse_header(struct webnet_request *request, char* buffer, in if(request->query != NULL) { wn_free(request->query); } - request->query = (char*) wn_malloc(request->content_length + 1); - - #ifdef ADD_XIZI_FETURES + request->query = (char*) wn_malloc(request->content_length + 1); memset(request->query, 0, request->content_length + 1); - #endif // ADD_XIZI_FETURES - #ifdef ADD_RTTHREAD_FETURES - rt_memset(request->query, 0, request->content_length + 1); - #endif //ADD_RTTHREAD_FETURES request->query_offset = 0; } } @@ -492,13 +461,7 @@ int webnet_request_parse_header(struct webnet_request *request, char* buffer, in if( (gzip != NULL)) { - - #ifdef ADD_XIZI_FETURES - request->support_gzip = 1;//1->true - #endif // ADD_XIZI_FETURES - #ifdef ADD_RTTHREAD_FETURES request->support_gzip = TRUE; - #endif //ADD_RTTHREAD_FETURES } } #endif /* WEBNET_USING_GZIP */ @@ -532,13 +495,7 @@ int webnet_request_parse_post(struct webnet_request* request, char* buffer, int if (request->query_offset + length > request->content_length) length = request->content_length - request->query_offset; - - #ifdef ADD_XIZI_FETURES memcpy(&request->query[request->query_offset], buffer, length); - #endif // ADD_XIZI_FETURES - #ifdef ADD_RTTHREAD_FETURES - rt_memcpy(&request->query[request->query_offset], buffer, length); - #endif //ADD_RTTHREAD_FETURES request->query_offset += length; if (request->query_offset == request->content_length) @@ -722,16 +679,9 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng /* end of http request */ request->result_code = 200; - - #ifdef ADD_XIZI_FETURES session->buffer_offset = (uint16_t)(length - ((uint32)request->query - (uint32)buffer)); - #endif // ADD_XIZI_FETURES - #ifdef ADD_RTTHREAD_FETURES - session->buffer_offset = (rt_uint16_t)(length - - ((uint32)request->query - (uint32)buffer)); - #endif //ADD_RTTHREAD_FETURES /* move the buffer to the session */ if (session->buffer_offset > 0) { @@ -739,14 +689,7 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng * NOTIC: the rest of buffer must not be great than session buffer * Therefore, the size of read buffer can equal to the size of session buffer. */ - #ifdef ADD_XIZI_FETURES - memcpy(session->buffer, request->query, session->buffer_offset); - #endif // ADD_XIZI_FETURES - - #ifdef ADD_RTTHREAD_FETURES - rt_memcpy(session->buffer, request->query, session->buffer_offset); - #endif //ADD_RTTHREAD_FETURES - + memcpy(session->buffer, request->query, session->buffer_offset); } request->query = NULL; return; @@ -774,14 +717,7 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng if (read_length > 0) { if (read_length > request->content_length) read_length = request->content_length; - - #ifdef ADD_XIZI_FETURES memcpy(read_ptr, request->query, read_length); - #endif // ADD_XIZI_FETURES - #ifdef ADD_RTTHREAD_FETURES - rt_memcpy(read_ptr, request->query, read_length); - #endif //ADD_RTTHREAD_FETURES - } request->query = read_ptr; @@ -931,14 +867,7 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng if( (gzip != NULL) && (end != NULL) && (gzip < end) ) { - #ifdef ADD_XIZI_FETURES - request->support_gzip = 1;//1->true - #endif // ADD_XIZI_FETURES - - #ifdef ADD_RTTHREAD_FETURES request->support_gzip = TRUE; - #endif //ADD_RTTHREAD_FETURES - } } #endif /* WEBNET_USING_GZIP */ @@ -979,17 +908,8 @@ struct webnet_request* webnet_request_create() request = (struct webnet_request*) wn_malloc (sizeof(struct webnet_request)); if (request != NULL) { - #ifdef ADD_XIZI_FETURES memset(request, 0, sizeof(struct webnet_request)); - request->field_copied = 0;//false - #endif // ADD_XIZI_FETURES - - #ifdef ADD_RTTHREAD_FETURES - rt_memset(request, 0, sizeof(struct webnet_request)); request->field_copied = FALSE; - #endif //ADD_RTTHREAD_FETURES - - } return request; diff --git a/src/wn_session.c b/src/wn_session.c index 24e18f3..7d88e5f 100755 --- a/src/wn_session.c +++ b/src/wn_session.c @@ -30,15 +30,6 @@ #include #include - #ifdef ADD_XIZI_FETURES - #include -#include "sys_arch.h" -#include -#include "lwip/sys.h" -#include -//#include -#endif // ADD_XIZI_FETURES - #ifdef ADD_RTTHREAD_FETURES #include #endif //ADD_RTTHREAD_FETURES diff --git a/src/wn_utils.c b/src/wn_utils.c index 8af4294..9741460 100755 --- a/src/wn_utils.c +++ b/src/wn_utils.c @@ -23,18 +23,9 @@ */ #include - - -#ifdef ADD_XIZI_FETURES -#include -#endif // ADD_XIZI_FETURES - -#ifdef ADD_RTTHREAD_FETURES -#include -#endif //ADD_RTTHREAD_FETURES - #include #include +#include inline int tohex(char c) { -- 2.34.1 From 42a888a7e739a27f5301dae4d69470c7521e0887 Mon Sep 17 00:00:00 2001 From: zhaoyun1215 <58766762@qq.com> Date: Thu, 15 Sep 2022 19:08:51 -0700 Subject: [PATCH 5/8] change for posix --- module/wn_module_asp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/wn_module_asp.c b/module/wn_module_asp.c index 557b875..0368e03 100755 --- a/module/wn_module_asp.c +++ b/module/wn_module_asp.c @@ -115,7 +115,7 @@ static void _default_asp_handler(struct webnet_session* session, const char* nam { int32 tick; int32 hour, min, second; - tick = GetTick(); + tick = PriGetTick(); second = tick % 60; min = (tick/60) % 60; hour = tick / (60 * 60); -- 2.34.1 From c7af2a767cdbd7987e62770d2cf144c8e5ca4efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=82=E7=85=9C=E6=B4=8B?= <1163589503@qq.com> Date: Thu, 27 Jul 2023 15:06:16 +0800 Subject: [PATCH 6/8] 23/07/27 1.Add netdev module and for edu-arm32, fit Lwip to it; 2.Fit Webnet to edu-arm32; --- Makefile | 2 +- inc/webnet.h | 8 +++ inc/wn_request.h | 1 + inc/wn_session.h | 5 ++ module/Makefile | 11 ++++ module/wn_module_dav.c | 8 +-- samples/Makefile | 7 +++ samples/deviceinfoasp.c | 12 ++-- samples/deviceinfoasp.h | 1 + samples/netsetting.c | 23 +++++--- samples/uploaddata.c | 123 ++++++++++++++++++++-------------------- samples/wn_sample.c | 4 +- src/Makefile | 3 + src/webnet.c | 18 +++--- src/wn_module.c | 18 +++--- src/wn_request.c | 17 +++--- src/wn_session.c | 16 +++--- 17 files changed, 158 insertions(+), 119 deletions(-) create mode 100644 module/Makefile create mode 100644 samples/Makefile create mode 100644 src/Makefile diff --git a/Makefile b/Makefile index 916e473..ce21783 100755 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ -SRC_DIR := src module samples +SRC_DIR += src module samples include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/inc/webnet.h b/inc/webnet.h index ab48205..63fb56b 100755 --- a/inc/webnet.h +++ b/inc/webnet.h @@ -85,6 +85,14 @@ extern "C" { #define WEBNET_PATH_MAX 256 /* maxiaml path length in webnet */ #define WEBNET_SERVER "Server: webnet "WEBNET_VERSION"\r\n" +// #ifndef FALSE +// #define FALSE 0 +// #endif + +// #ifndef TRUE +// #define TRUE 1 +// #endif + /* Pre-declaration */ struct webnet_session; /* webnet query item definitions */ diff --git a/inc/wn_request.h b/inc/wn_request.h index 0129393..9da6d80 100755 --- a/inc/wn_request.h +++ b/inc/wn_request.h @@ -26,6 +26,7 @@ #define __WN_REQUEST_H__ #include #include +#include #ifdef __cplusplus extern "C" { diff --git a/inc/wn_session.h b/inc/wn_session.h index 37d5f61..d7527c9 100755 --- a/inc/wn_session.h +++ b/inc/wn_session.h @@ -28,6 +28,11 @@ #include #include +#ifdef BSP_USING_LWIP +#include +#include +#endif + #ifdef __cplusplus extern "C" { #endif 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_dav.c b/module/wn_module_dav.c index 27dad76..3e25fd6 100755 --- a/module/wn_module_dav.c +++ b/module/wn_module_dav.c @@ -284,19 +284,19 @@ static void print_propfind_element(struct webnet_session *session, const char *u PrivTaskenterCritical(); #endif - #ifdef ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES long lock; lock = CriticalAreaLock(); - #endif //ADD_XIZI_FETURES + #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_FETURES + #ifdef ADD_XIZI_FEATURES CriticalAreaUnLock(lock); - #endif //ADD_XIZI_FETURES + #endif //ADD_XIZI_FEATURES //printf("strftime: %s\n", ctime_str); webnet_session_printf(session, diff --git a/samples/Makefile b/samples/Makefile new file mode 100644 index 0000000..596791a --- /dev/null +++ b/samples/Makefile @@ -0,0 +1,7 @@ +SRC_FILES += deviceinfoasp.c \ + wn_sample_upload.c \ + uploaddata.c \ + netsetting.c \ + wn_sample.c + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/samples/deviceinfoasp.c b/samples/deviceinfoasp.c index 98dacbb..d05c6c7 100755 --- a/samples/deviceinfoasp.c +++ b/samples/deviceinfoasp.c @@ -1,9 +1,9 @@ #include "deviceinfoasp.h" -#ifdef ADD_XIZI_FETURES +#ifdef ADD_XIZI_FEATURES extern void HwCpuReset();//reset machine -#endif //ADD_XIZI_FETURES +#endif //ADD_XIZI_FEATURES -#ifdef ADD_XIZI_FETURES +#ifdef ADD_XIZI_FEATURES deviceinfo xidatong_deviceinfo = { DEVICE_NUM_DEFUALT, @@ -14,7 +14,7 @@ deviceinfo xidatong_deviceinfo = SYSTEM_VERSION, WEB_VERSION }; -#endif //ADD_XIZI_FETURES +#endif //ADD_XIZI_FEATURES #ifdef ADD_RTTHREAD_FETURES deviceinfo xidatong_deviceinfo = @@ -103,9 +103,9 @@ void cgi_device_reboot(struct webnet_session* session) msh_exec(order_sh,rt_strlen(order_sh)); #endif - #ifdef ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES HwCpuReset(); - #endif //ADD_XIZI_FETURES + #endif //ADD_XIZI_FEATURES } diff --git a/samples/deviceinfoasp.h b/samples/deviceinfoasp.h index bf015bb..5e890f3 100755 --- a/samples/deviceinfoasp.h +++ b/samples/deviceinfoasp.h @@ -6,6 +6,7 @@ #include #include #include +#include #define RT_THREAD_KERNEL "rt-thread kenel" diff --git a/samples/netsetting.c b/samples/netsetting.c index 67c8534..7396bfc 100755 --- a/samples/netsetting.c +++ b/samples/netsetting.c @@ -1,11 +1,9 @@ #include "netsetting.h" - - -#ifdef ADD_XIZI_FETURES +#ifdef ADD_XIZI_FEATURES #include #include -#endif //ADD_XIZI_FETURES +#endif // ADD_XIZI_FEATURES static mqttsetting mqttweb; static local_tcpip local_tcpipweb; @@ -99,8 +97,14 @@ void cgi_mqtt_save_data(struct webnet_session *session) static void device_get_tcpip_parameter() { - struct netdev *netdev_device = netdev_get_by_name("e0"); - + char dev_name[2] = "en"; + + struct netdev* netdev_device = netdev_get_by_name(dev_name); + if (netdev_device == NULL) { + SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Not found netdev by name %s\n", __func__, dev_name)); + netdev_device = NETDEV_DEFAULT; + } + //printf("ip address: %s\n", inet_ntoa(netdev_device->ip_addr)); //printf("netmask address: %s\n", inet_ntoa(netdev_device->netmask)); //printf("gw address: %s\n", inet_ntoa(netdev_device->gw)); @@ -112,6 +116,7 @@ static void device_get_tcpip_parameter() strcpy(local_tcpipweb.gateway_addr,inet_ntoa(netdev_device->gw)); strcpy(local_tcpipweb.dns_server0,inet_ntoa(netdev_device->dns_servers[0])); strcpy(local_tcpipweb.dns_server1,inet_ntoa(netdev_device->dns_servers[1])); + SYS_KDEBUG_LOG(NETDEV_DEBUG, NETDEV_DEBUG_PRINT_IP_INFO(netdev_device->ip_addr, netdev_device->netmask, netdev_device->gw)); printf("ip address: %s\n", local_tcpipweb.local_ipaddr); @@ -119,12 +124,12 @@ static void device_get_tcpip_parameter() printf("gw address: %s\n", local_tcpipweb.gateway_addr); printf("dns0 address: %s\n", local_tcpipweb.dns_server0); printf("dns1 address: %s\n", local_tcpipweb.dns_server1); -} +} -#ifdef ADD_XIZI_FETURES +#ifdef ADD_XIZI_FEATURES SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), device_get_tcpip_parameter,device_get_tcpip_parameter, device_get_tcpip_parameter); -#endif //ADD_XIZI_FETURES +#endif // ADD_XIZI_FEATURES char *json_create_tcpip_data(void) { diff --git a/samples/uploaddata.c b/samples/uploaddata.c index fbc752c..a7aef45 100755 --- a/samples/uploaddata.c +++ b/samples/uploaddata.c @@ -1,125 +1,122 @@ #include "uploaddata.h" -#include +#include +#include char msg[] = "/mq_upload_web"; sensor_msg eg_temperature; sensor_msg web_show; -static mqd_t mq_web=-1; +static mqd_t mq_web = -1; void *upload_receive_web_msg_thread() { int nbytes = 0; while(1) { - nbytes = PrivMqueueReceive(mq_web,(char*)(&eg_temperature), sizeof(eg_temperature), NULL); + // printf("[%s] sizeof buffer: %d\n", __func__, sizeof(eg_temperature)); + nbytes = mq_receive(mq_web, (char*)(&eg_temperature), sizeof(eg_temperature), NULL); if (nbytes < 0) { - printf("mq_receive error: %d \n",nbytes); - #ifdef ADD_XIZI_FETURES + printf("mq_receive error: %d \n", nbytes); +#ifdef ADD_XIZI_FEATURES break; - #endif //ADD_XIZI_FETURES - } - else - { - printf("=============mq_receive success:==============\n"); +#endif // ADD_XIZI_FEATURES + } else { + printf("=============mq_receive success:==============\n"); printf(" \ name:%s\n \ brand %s\n \ unit %s\n \ - value %s\n", \ - eg_temperature.name,eg_temperature.brand,eg_temperature.unit,eg_temperature.value); - memcpy(&web_show,&eg_temperature,sizeof(web_show)); - } + value %s\n", + eg_temperature.name, eg_temperature.brand, eg_temperature.unit, eg_temperature.value); + memcpy(&web_show, &eg_temperature, sizeof(web_show)); + } } } + int uploaddata_init() { struct mq_attr webmq_attr; int result = 0; webmq_attr.mq_flags = 0; - webmq_attr.mq_maxmsg = 20; - webmq_attr.mq_msgsize = 512; - webmq_attr.mq_curmsgs = 0; - mq_web = PrivMqueueCreate("/mq_web", O_RDONLY|O_CREAT,0666,&webmq_attr); - if (mq_web < 0) - { - printf("mq_open error: %d \n",mq_web); - }else - { - printf("mq_open success: %d \n",mq_web); - } + + webmq_attr.mq_maxmsg = 20; + webmq_attr.mq_msgsize = 512; + webmq_attr.mq_curmsgs = 0; + + mq_web = mq_open("/mq_web", O_RDONLY | O_CREAT, 0666, &webmq_attr); + if (mq_web < 0) { + printf("mq_open error: %d \n", mq_web); + } else { + printf("mq_open success: %d \n", mq_web); + } pthread_t tid = 0; pthread_attr_t attr; struct sched_param prio; - #ifdef ADD_RTTHREAD_FETURES +#ifdef ADD_RTTHREAD_FETURES prio.sched_priority = 8; - #endif //ADD_RTTHREAD_FETURES +#endif // ADD_RTTHREAD_FETURES - #ifdef ADD_XIZI_FETURES +#ifdef ADD_XIZI_FEATURES prio.sched_priority = 25; - #endif //ADD_XIZI_FETURES +#endif // ADD_XIZI_FEATURES size_t stack_size = 1024 * 11; pthread_attr_init(&attr); - pthread_attr_setschedparam(&attr, &prio); + pthread_attr_setschedparam(&attr, &prio); pthread_attr_setstacksize(&attr, stack_size); - result = pthread_create(&tid, &attr,upload_receive_web_msg_thread, NULL); - if (result>=0) - { - printf("thread_detect_entry successfully!\n"); - } - else - { - printf("thread_detect_entry failed! error code is %d.\n", result); + result = pthread_create(&tid, &attr, upload_receive_web_msg_thread, NULL); + if (result >= 0) { + printf("thread_detect_entry successfully!\n"); + } else { + printf("thread_detect_entry failed! error code is %d.\n", result); } /***********demo sensor set parameters***************/ - strcpy(eg_temperature.name,"temperature"); - strcpy(eg_temperature.brand,"hs300x"); - strcpy(eg_temperature.unit,"°C"); + strcpy(eg_temperature.name, "temperature"); + strcpy(eg_temperature.brand, "hs300x"); + strcpy(eg_temperature.unit, "°C"); } - void upload_send_web_msg() { static int seed_t = 20; float temp = 25; float tem_decimals = 0; - int nbytes = 0; - memset((char*)eg_temperature.value,0,sizeof(eg_temperature.value)); + int nbytes = 0; + memset((char*)eg_temperature.value, 0, sizeof(eg_temperature.value)); srand(seed_t); - tem_decimals = ((float)(rand() % 100))/100.0; + tem_decimals = ((float)(rand() % 100)) / 100.0; temp = temp + tem_decimals; - sprintf(eg_temperature.value,"%f",temp); - printf("rand generate temperature %s \n\r",eg_temperature.value); + sprintf(eg_temperature.value, "%f", temp); + printf("rand generate temperature %s \n\r", eg_temperature.value); - nbytes = PrivMqueueSend(mq_web, (char *)(&eg_temperature), sizeof(eg_temperature), 0); - if (nbytes < 0) - { - printf("mq_send error: %d \n",nbytes); - } - else - { - printf("mq_send success: times%d \n",seed_t); - } + // printf("[%s] sizeof buffer: %d\n", __func__, sizeof(eg_temperature)); + nbytes = mq_send(mq_web, (char*)(&eg_temperature), sizeof(eg_temperature), 0); + if (nbytes < 0) { + printf("mq_send error: %d \n", nbytes); + } else { + printf("mq_send success: times%d \n", seed_t); + } seed_t++; } #ifdef ADD_RTTHREAD_FETURES MSH_CMD_EXPORT(upload_send_web_msg, upload_send_web_msg); #endif -#ifdef ADD_XIZI_FETURES -SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), +#ifdef ADD_XIZI_FEATURES + SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), upload_send_web_msg, upload_send_web_msg, upload_send_web_msg); + SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), + uploaddata_init, uploaddata_init, uploaddata_init); #endif -char *json_create_datashow_data() -{ - char *json_data = NULL; - cJSON *root = cJSON_CreateObject(); + char* json_create_datashow_data() + { + char* json_data = NULL; + cJSON* root = cJSON_CreateObject(); cJSON_AddItemToObject(root, "name", cJSON_CreateString(web_show.name)); cJSON_AddItemToObject(root, "brand", cJSON_CreateString(web_show.brand)); cJSON_AddItemToObject(root, "unit", cJSON_CreateString(web_show.unit)); @@ -127,7 +124,7 @@ char *json_create_datashow_data() json_data = cJSON_PrintUnformatted(root); cJSON_Delete(root); return json_data; -} + } void cgi_dateshow_get_data(struct webnet_session *session) { diff --git a/samples/wn_sample.c b/samples/wn_sample.c index 83d3383..c7df963 100755 --- a/samples/wn_sample.c +++ b/samples/wn_sample.c @@ -86,7 +86,7 @@ MSH_CMD_EXPORT(webnet_start, wenbet test); #endif //ADD_RTTHREAD_FETURES -#ifdef ADD_XIZI_FETURES +#ifdef ADD_XIZI_FEATURES SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), webnet_start, webnet_start, wenbet test); -#endif //ADD_XIZI_FETURES +#endif //ADD_XIZI_FEATURES diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..a9a2636 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,3 @@ +SRC_FILES += webnet.c wn_mimetype.c wn_module.c wn_request.c wn_session.c wn_utils.c + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/src/webnet.c b/src/webnet.c index cfcb68f..da327f3 100755 --- a/src/webnet.c +++ b/src/webnet.c @@ -26,16 +26,18 @@ #include #include #include +#include +#include static uint8 webnet_port = WEBNET_PORT; static char webnet_root[64] = WEBNET_ROOT; -static bool init_ok = FALSE; +static bool init_ok = false; void webnet_set_port(int port) { - assert(init_ok == FALSE); + assert(init_ok == false); webnet_port = port; } @@ -122,9 +124,9 @@ static void *webnet_thread(void *parameter) tempfds = readset; tempwrtfds = writeset; /* Wait for data or a new connection */ - #ifdef ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES sys_msleep(100); - #endif // ADD_XIZI_FETURES + #endif // ADD_XIZI_FEATURES sock_fd = select(maxfdp1, &tempfds, &tempwrtfds, 0, 0); if (sock_fd == 0) { @@ -171,9 +173,9 @@ __exit: int webnet_init(void) { int result = 0; - #ifdef ADD_XIZI_FETURES - lwip_config_net(lwip_ipaddr, lwip_netmask, lwip_gwaddr); - #endif // ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES + lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr); + #endif // ADD_XIZI_FEATURES pthread_t tid; pthread_attr_t attr; @@ -188,7 +190,7 @@ int webnet_init(void) if (0 == result) { - init_ok = TRUE; + init_ok = true; printf("XiUOS webnet initialize success."); } else diff --git a/src/wn_module.c b/src/wn_module.c index fbc2d7c..a13cb60 100755 --- a/src/wn_module.c +++ b/src/wn_module.c @@ -25,7 +25,7 @@ #include #include #include - +#include static int _webnet_module_system_init(struct webnet_session *session, int event) { @@ -173,18 +173,18 @@ int webnet_module_system_dofile(struct webnet_session *session) if (stat_result == 0) { - #ifdef ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES long lock; lock = CriticalAreaLock(); - #endif // ADD_XIZI_FETURES + #endif // ADD_XIZI_FEATURES #ifdef ADD_RTTHREAD_FETURES PrivTaskenterCritical(); #endif //ADD_RTTHREAD_FETURES strcpy(ctime_str, ctime((time_t *)&file_stat.st_mtime)); - #ifdef ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES CriticalAreaUnLock(lock); - #endif // ADD_XIZI_FETURES + #endif // ADD_XIZI_FEATURES #ifdef ADD_RTTHREAD_FETURES PrivTaskexitCritical(); @@ -211,10 +211,10 @@ int webnet_module_system_dofile(struct webnet_session *session) if (stat_result == 0) { - #ifdef ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES long lock; lock = CriticalAreaLock(); - #endif // ADD_XIZI_FETURES + #endif // ADD_XIZI_FEATURES @@ -226,9 +226,9 @@ int webnet_module_system_dofile(struct webnet_session *session) strftime(gmtime_str,sizeof(ctime_str),"%a, %d %b %Y %H:%M:%S GMT",info); strcpy(ctime_str, ctime((time_t *)&file_stat.st_mtime)); - #ifdef ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES CriticalAreaUnLock(lock); - #endif // ADD_XIZI_FETURES + #endif // ADD_XIZI_FEATURES #ifdef ADD_RTTHREAD_FETURES PrivTaskexitCritical(); diff --git a/src/wn_request.c b/src/wn_request.c index 08294e0..ab8e02e 100755 --- a/src/wn_request.c +++ b/src/wn_request.c @@ -29,6 +29,7 @@ #include #include +#include #define POST_BUFSZ_MAX (8 * 1024) @@ -109,7 +110,7 @@ static void _webnet_request_parse_query(struct webnet_request* request) } /** - * copy string from request and the field_copied set to TRUE + * copy string from request and the field_copied set to true */ static void _webnet_request_copy_str(struct webnet_request* request) { @@ -142,7 +143,7 @@ static void _webnet_request_copy_str(struct webnet_request* request) #ifdef WEBNET_USING_RANGE if (request->Range) request->Range = wn_strdup(request->Range); #endif /* WEBNET_USING_RANGE */ - request->field_copied = TRUE; + request->field_copied = true; } /** @@ -155,9 +156,9 @@ bool webnet_request_has_query(struct webnet_request* request, char* name) for (index = 0; index < request->query_counter; index ++) { if (strncmp(request->query_items[index].name, name, strlen(name)) == 0) - return TRUE; + return true; } - return FALSE; + return false; } #ifdef ADD_RTTHREAD_FETURES RTM_EXPORT(webnet_request_has_query); @@ -461,7 +462,7 @@ int webnet_request_parse_header(struct webnet_request *request, char* buffer, in if( (gzip != NULL)) { - request->support_gzip = TRUE; + request->support_gzip = true; } } #endif /* WEBNET_USING_GZIP */ @@ -867,7 +868,7 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng if( (gzip != NULL) && (end != NULL) && (gzip < end) ) { - request->support_gzip = TRUE; + request->support_gzip = true; } } #endif /* WEBNET_USING_GZIP */ @@ -909,7 +910,7 @@ struct webnet_request* webnet_request_create() if (request != NULL) { memset(request, 0, sizeof(struct webnet_request)); - request->field_copied = FALSE; + request->field_copied = false; } return request; @@ -919,7 +920,7 @@ void webnet_request_destory(struct webnet_request* request) { if (request != NULL) { - // if (request->field_copied == TRUE) + // if (request->field_copied == true) { if (request->path != NULL) wn_free(request->path); if (request->host != NULL) wn_free(request->host); diff --git a/src/wn_session.c b/src/wn_session.c index 7d88e5f..9ac5226 100755 --- a/src/wn_session.c +++ b/src/wn_session.c @@ -29,6 +29,7 @@ #include #include #include +#include #ifdef ADD_RTTHREAD_FETURES #include @@ -125,9 +126,6 @@ void webnet_session_close(struct webnet_session *session) /* Either an error or tcp connection closed on other * end. Close here */ - #ifdef ADD_XIZI_FETURES - //sys_msleep(1); - #endif // ADD_XIZI_FETURES closesocket(session->socket); /* Free webnet_session */ @@ -622,10 +620,10 @@ static void list_webnet(void) char client_ip_str[16]; /* ###.###.###.### */ uint32 num = 0; - #ifdef ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES long lock; lock = CriticalAreaLock(); - #endif // ADD_XIZI_FETURES + #endif // ADD_XIZI_FEATURES #ifdef ADD_RTTHREAD_FETURES PrivTaskenterCritical(); #endif //ADD_RTTHREAD_FETURES @@ -646,9 +644,9 @@ static void list_webnet(void) printf("\r\n"); } - #ifdef ADD_XIZI_FETURES + #ifdef ADD_XIZI_FEATURES CriticalAreaUnLock(lock); - #endif // ADD_XIZI_FETURES + #endif // ADD_XIZI_FEATURES #ifdef ADD_RTTHREAD_FETURES PrivTaskexitCritical(); #endif //ADD_RTTHREAD_FETURES @@ -664,7 +662,7 @@ MSH_CMD_EXPORT(list_webnet, list webnet session); #endif //FINSH_USING_MSH #endif //ADD_RTTHREAD_FETURES -#ifdef ADD_XIZI_FETURES +#ifdef ADD_XIZI_FEATURES SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0), list_webnet, list_webnet, list_webnet); -#endif //ADD_XIZI_FETURES +#endif //ADD_XIZI_FEATURES -- 2.34.1 From 2056a6d5876ac607052522b82134ee25071419f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=82=E7=85=9C=E6=B4=8B?= <1163589503@qq.com> Date: Mon, 31 Jul 2023 10:38:16 +0800 Subject: [PATCH 7/8] 23/07/31 Fit Webnet to edu-arm32 --- inc/webnet.h | 18 +++++++----- inc/wn_session.h | 4 +-- module/wn_module_asp.c | 26 ++++++++-------- module/wn_module_cgi.c | 8 ++--- module/wn_module_upload.c | 2 +- samples/netsetting.c | 17 +++++------ samples/uploaddata.c | 6 +--- samples/wn_sample.c | 2 +- src/webnet.c | 5 +--- src/wn_module.c | 62 ++++++++++++++++++--------------------- 10 files changed, 71 insertions(+), 79 deletions(-) diff --git a/inc/webnet.h b/inc/webnet.h index 63fb56b..21b6d55 100755 --- a/inc/webnet.h +++ b/inc/webnet.h @@ -30,39 +30,43 @@ #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 +#define wn_read PrivRead #endif #ifndef wn_open -#define wn_open open +#define wn_open PrivOpen #endif #ifndef wn_close -#define wn_close close +#define wn_close PrivClose #endif +#define WEBNET_USING_CGI +#define WEBNET_USING_ASP +#define WEBNET_USING_UPLOAD #ifndef WEBNET_USING_RANGE #define WEBNET_USING_RANGE diff --git a/inc/wn_session.h b/inc/wn_session.h index d7527c9..b88d4dd 100755 --- a/inc/wn_session.h +++ b/inc/wn_session.h @@ -37,7 +37,7 @@ extern "C" { #endif -#define WEBNET_SESSION_BUFSZ (4 * 1024) +#define WEBNET_SESSION_BUFSZ (32 * 1024) /* close session */ #define WEBNET_EVENT_CLOSE (1 << 5) @@ -74,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/module/wn_module_asp.c b/module/wn_module_asp.c index 0368e03..63c9576 100755 --- a/module/wn_module_asp.c +++ b/module/wn_module_asp.c @@ -22,8 +22,9 @@ * 2022-09-07 zhaoyun the version transplanted for XiZi */ -#include +#include #include +#include #include #include #include @@ -115,7 +116,7 @@ static void _default_asp_handler(struct webnet_session* session, const char* nam { int32 tick; int32 hour, min, second; - tick = PriGetTick(); + tick = PrivGetTickTime(); second = tick % 60; min = (tick/60) % 60; hour = tick / (60 * 60); @@ -147,9 +148,7 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd) webnet_session_set_header(session, "text/html", 200, "OK", -1); /* read file to buffer */ - int read_length=wn_read(fd, buffer, (uint32)length); - printf("read_lenth:%d\n",read_length);//needed to delete - if (read_length != length) /* read failed */ + if (wn_read(fd, buffer, (uint32)length) != length) /* read failed */ { wn_free(buffer); session->request->result_code = 500; @@ -241,7 +240,6 @@ int webnet_module_asp(struct webnet_session* session, int event) { /* no this file */ request->result_code = 404; - wn_close(fd);//zhaoyun add return WEBNET_MODULE_FINISHED; } } @@ -254,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 = wn_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); - wn_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_cgi.c b/module/wn_module_cgi.c index bd27c0e..9976d78 100755 --- a/module/wn_module_cgi.c +++ b/module/wn_module_cgi.c @@ -24,12 +24,12 @@ #include #include +#include #include #include #include #include - #ifdef WEBNET_USING_CGI #define CGI_ROOT_PATH_MAX 64 @@ -45,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_upload.c b/module/wn_module_upload.c index 5d2d34e..fad48f4 100755 --- a/module/wn_module_upload.c +++ b/module/wn_module_upload.c @@ -23,11 +23,11 @@ */ #include +#include #include #include #include - #if defined(WEBNET_USING_UPLOAD) #define MULTIPART_FORM_DATA_STRING "multipart/form-data" diff --git a/samples/netsetting.c b/samples/netsetting.c index 7396bfc..bb3de03 100755 --- a/samples/netsetting.c +++ b/samples/netsetting.c @@ -97,9 +97,10 @@ void cgi_mqtt_save_data(struct webnet_session *session) static void device_get_tcpip_parameter() { - char dev_name[2] = "en"; + char dev_name[3] = "hd\0"; - struct netdev* netdev_device = netdev_get_by_name(dev_name); + struct netdev* netdev_device = NULL; + netdev_device = netdev_get_by_name(dev_name); if (netdev_device == NULL) { SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Not found netdev by name %s\n", __func__, dev_name)); netdev_device = NETDEV_DEFAULT; @@ -111,13 +112,11 @@ static void device_get_tcpip_parameter() //printf("dns0 address: %s\n", inet_ntoa(netdev_device->dns_servers[0])); //printf("dns1 address: %s\n", inet_ntoa(netdev_device->dns_servers[1])); - strcpy(local_tcpipweb.local_ipaddr,inet_ntoa(netdev_device->ip_addr)); - strcpy(local_tcpipweb.netmask_addr,inet_ntoa(netdev_device->netmask)); - strcpy(local_tcpipweb.gateway_addr,inet_ntoa(netdev_device->gw)); - strcpy(local_tcpipweb.dns_server0,inet_ntoa(netdev_device->dns_servers[0])); - strcpy(local_tcpipweb.dns_server1,inet_ntoa(netdev_device->dns_servers[1])); - SYS_KDEBUG_LOG(NETDEV_DEBUG, NETDEV_DEBUG_PRINT_IP_INFO(netdev_device->ip_addr, netdev_device->netmask, netdev_device->gw)); - + strcpy(local_tcpipweb.local_ipaddr, inet_ntoa(netdev_device->ip_addr)); + strcpy(local_tcpipweb.netmask_addr, inet_ntoa(netdev_device->netmask)); + strcpy(local_tcpipweb.gateway_addr, inet_ntoa(netdev_device->gw)); + strcpy(local_tcpipweb.dns_server0, inet_ntoa(netdev_device->dns_servers[0])); + strcpy(local_tcpipweb.dns_server1, inet_ntoa(netdev_device->dns_servers[1])); printf("ip address: %s\n", local_tcpipweb.local_ipaddr); printf("netmask address: %s\n", local_tcpipweb.netmask_addr); diff --git a/samples/uploaddata.c b/samples/uploaddata.c index a7aef45..1dd2fa0 100755 --- a/samples/uploaddata.c +++ b/samples/uploaddata.c @@ -10,9 +10,7 @@ static mqd_t mq_web = -1; void *upload_receive_web_msg_thread() { int nbytes = 0; - while(1) - { - // printf("[%s] sizeof buffer: %d\n", __func__, sizeof(eg_temperature)); + while (1) { nbytes = mq_receive(mq_web, (char*)(&eg_temperature), sizeof(eg_temperature), NULL); if (nbytes < 0) { @@ -31,7 +29,6 @@ void *upload_receive_web_msg_thread() memcpy(&web_show, &eg_temperature, sizeof(web_show)); } } - } int uploaddata_init() @@ -93,7 +90,6 @@ void upload_send_web_msg() sprintf(eg_temperature.value, "%f", temp); printf("rand generate temperature %s \n\r", eg_temperature.value); - // printf("[%s] sizeof buffer: %d\n", __func__, sizeof(eg_temperature)); nbytes = mq_send(mq_web, (char*)(&eg_temperature), sizeof(eg_temperature), 0); if (nbytes < 0) { printf("mq_send error: %d \n", nbytes); diff --git a/samples/wn_sample.c b/samples/wn_sample.c index c7df963..0b7cd0a 100755 --- a/samples/wn_sample.c +++ b/samples/wn_sample.c @@ -76,7 +76,7 @@ void webnet_start(void) #endif private_prtweb_default(); mqttweb_default(); - uploaddata_init(); + // uploaddata_init(); webnet_init(); diff --git a/src/webnet.c b/src/webnet.c index da327f3..67df036 100755 --- a/src/webnet.c +++ b/src/webnet.c @@ -123,10 +123,7 @@ static void *webnet_thread(void *parameter) /* use temporary fd set in select */ tempfds = readset; tempwrtfds = writeset; - /* Wait for data or a new connection */ - #ifdef ADD_XIZI_FEATURES - sys_msleep(100); - #endif // ADD_XIZI_FEATURES + sock_fd = select(maxfdp1, &tempfds, &tempwrtfds, 0, 0); if (sock_fd == 0) { diff --git a/src/wn_module.c b/src/wn_module.c index a13cb60..08b8060 100755 --- a/src/wn_module.c +++ b/src/wn_module.c @@ -171,24 +171,23 @@ int webnet_module_system_dofile(struct webnet_session *session) wn_free(path_gz); } - if (stat_result == 0) - { - #ifdef ADD_XIZI_FEATURES + if (stat_result == 0) { +#ifdef ADD_XIZI_FEATURES long lock; lock = CriticalAreaLock(); - #endif // ADD_XIZI_FEATURES - - #ifdef ADD_RTTHREAD_FETURES +#endif // ADD_XIZI_FEATURES +#ifdef ADD_RTTHREAD_FETURES PrivTaskenterCritical(); - #endif //ADD_RTTHREAD_FETURES - strcpy(ctime_str, ctime((time_t *)&file_stat.st_mtime)); - #ifdef ADD_XIZI_FEATURES - CriticalAreaUnLock(lock); - #endif // ADD_XIZI_FEATURES +#endif // ADD_RTTHREAD_FETURES - #ifdef ADD_RTTHREAD_FETURES + strcpy(ctime_str, ctime((time_t *)&file_stat.st_mtime)); + +#ifdef ADD_XIZI_FEATURES + CriticalAreaUnLock(lock); +#endif // ADD_XIZI_FEATURES +#ifdef ADD_RTTHREAD_FETURES PrivTaskexitCritical(); - #endif //ADD_RTTHREAD_FETURES +#endif // ADD_RTTHREAD_FETURES ctime_str[strlen(ctime_str) - 1] = '\0'; /* clear the end \n */ @@ -203,36 +202,33 @@ int webnet_module_system_dofile(struct webnet_session *session) /* .gz not exist, use raw. */ #endif /* WEBNET_USING_GZIP */ + /* get Last-Modified. */ if (stat_result != 0) { struct stat file_stat; stat_result = stat(request->path, &file_stat); - if (stat_result == 0) - { - #ifdef ADD_XIZI_FEATURES - long lock; - lock = CriticalAreaLock(); - #endif // ADD_XIZI_FEATURES - - - - #ifdef ADD_RTTHREAD_FETURES + if (stat_result == 0) { +#ifdef ADD_XIZI_FEATURES + x_base lock = CriticalAreaLock(); +#endif // ADD_XIZI_FEATURES +#ifdef ADD_RTTHREAD_FETURES PrivTaskenterCritical(); - #endif //ADD_RTTHREAD_FETURES +#endif // ADD_RTTHREAD_FETURES + info = localtime((time_t *)&file_stat.st_mtime); memset(gmtime_str,0,32); strftime(gmtime_str,sizeof(ctime_str),"%a, %d %b %Y %H:%M:%S GMT",info); strcpy(ctime_str, ctime((time_t *)&file_stat.st_mtime)); - #ifdef ADD_XIZI_FEATURES - CriticalAreaUnLock(lock); - #endif // ADD_XIZI_FEATURES - #ifdef ADD_RTTHREAD_FETURES +#ifdef ADD_XIZI_FEATURES + CriticalAreaUnLock(lock); +#endif // ADD_XIZI_FEATURES +#ifdef ADD_RTTHREAD_FETURES PrivTaskexitCritical(); - #endif //ADD_RTTHREAD_FETURES +#endif // ADD_RTTHREAD_FETURES ctime_str[strlen(ctime_str) - 1] = '\0'; /* clear the end \n */ gmtime_str[strlen(gmtime_str)] = '\0'; /* clear the end \n */ @@ -264,7 +260,7 @@ int webnet_module_system_dofile(struct webnet_session *session) if (fd < 0) { /* .gz not exist, use raw. */ - request->support_gzip = FALSE; + request->support_gzip = false; } } } @@ -273,6 +269,7 @@ int webnet_module_system_dofile(struct webnet_session *session) #endif /* WEBNET_USING_GZIP */ if (fd < 0 && stat(request->path, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) { + SYS_KDEBUG_LOG(FILESYS_DEBUG, ("[%s] FileSys reuqest path: %s\n", __func__, request->path)); fd = wn_open(request->path, O_RDONLY, 0); } @@ -518,12 +515,11 @@ int webnet_module_handle_event(struct webnet_session *session, int event) } /* default index file */ -static const char *default_files[] = -{ +static const char* default_files[] = { "", "deviceinfo.asp", "/index.html", - "/index.htm", + // "/index.htm", NULL }; -- 2.34.1 From 23ef71e8ccc72aa6f2c789423ed674cb13f22dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=82=E7=85=9C=E6=B4=8B?= <1163589503@qq.com> Date: Wed, 2 Aug 2023 17:43:56 +0800 Subject: [PATCH 8/8] 23/08/02 Fit webnet to edu-arm32. --- inc/webnet.h | 21 +++++++++--------- inc/wn_session.h | 2 +- module/wn_module_alias.c | 4 ++-- module/wn_module_auth.c | 2 +- module/wn_module_index.c | 2 +- module/wn_module_ssi.c | 4 ++-- samples/deviceinfoasp.c | 2 +- src/webnet.c | 5 +++-- src/wn_module.c | 12 +++++------ src/wn_session.c | 46 ++++++++++++++++++++++------------------ 10 files changed, 52 insertions(+), 48 deletions(-) diff --git a/inc/webnet.h b/inc/webnet.h index 21b6d55..b71974d 100755 --- a/inc/webnet.h +++ b/inc/webnet.h @@ -64,9 +64,16 @@ extern "C" { #define wn_close PrivClose #endif -#define WEBNET_USING_CGI -#define WEBNET_USING_ASP -#define WEBNET_USING_UPLOAD +// #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 @@ -89,14 +96,6 @@ extern "C" { #define WEBNET_PATH_MAX 256 /* maxiaml path length in webnet */ #define WEBNET_SERVER "Server: webnet "WEBNET_VERSION"\r\n" -// #ifndef FALSE -// #define FALSE 0 -// #endif - -// #ifndef TRUE -// #define TRUE 1 -// #endif - /* Pre-declaration */ struct webnet_session; /* webnet query item definitions */ diff --git a/inc/wn_session.h b/inc/wn_session.h index b88d4dd..4b3b2f4 100755 --- a/inc/wn_session.h +++ b/inc/wn_session.h @@ -37,7 +37,7 @@ extern "C" { #endif -#define WEBNET_SESSION_BUFSZ (32 * 1024) +#define WEBNET_SESSION_BUFSZ (8 * 1024) /* close session */ #define WEBNET_EVENT_CLOSE (1 << 5) diff --git a/module/wn_module_alias.c b/module/wn_module_alias.c index 741e2cd..d9551ee 100755 --- a/module/wn_module_alias.c +++ b/module/wn_module_alias.c @@ -22,12 +22,12 @@ * 2022-09-07 zhaoyun the version transplanted for XiZi */ +#include +#include #include #include #include #include -#include - #ifdef WEBNET_USING_ALIAS diff --git a/module/wn_module_auth.c b/module/wn_module_auth.c index 7cf6c78..73ef8b9 100755 --- a/module/wn_module_auth.c +++ b/module/wn_module_auth.c @@ -22,13 +22,13 @@ * 2022-09-07 zhaoyun the version transplanted for XiZi */ +#include #include #include #include #include #include - #ifdef WEBNET_USING_AUTH struct webnet_auth_item { diff --git a/module/wn_module_index.c b/module/wn_module_index.c index c4498c8..bcac702 100755 --- a/module/wn_module_index.c +++ b/module/wn_module_index.c @@ -23,11 +23,11 @@ */ #include +#include #include #include #include - #ifdef WEBNET_USING_INDEX int webnet_module_dirindex(struct webnet_session* session, int event) diff --git a/module/wn_module_ssi.c b/module/wn_module_ssi.c index 63fad19..9c99007 100755 --- a/module/wn_module_ssi.c +++ b/module/wn_module_ssi.c @@ -23,10 +23,10 @@ */ #include +#include #include -#include #include - +#include #if defined(WEBNET_USING_SSI) diff --git a/samples/deviceinfoasp.c b/samples/deviceinfoasp.c index d05c6c7..559e21d 100755 --- a/samples/deviceinfoasp.c +++ b/samples/deviceinfoasp.c @@ -99,7 +99,7 @@ void cgi_device_reboot(struct webnet_session* session) webnet_session_printf(session, response); #ifdef ADD_RTTHREAD_FETURES extern int msh_exec(char *cmd, rt_size_t length); - printf("reboot !!!!! \n\r"); + printf("reboot !!!!! \n\r"); msh_exec(order_sh,rt_strlen(order_sh)); #endif diff --git a/src/webnet.c b/src/webnet.c index 67df036..ea2653d 100755 --- a/src/webnet.c +++ b/src/webnet.c @@ -83,11 +83,12 @@ static void *webnet_thread(void *parameter) webnet_saddr.sin_port = htons(webnet_port); /* webnet server port */ /* Set receive timeout for accept() */ - if(setsockopt(listenfd, SOL_SOCKET, SO_RCVTIMEO, (void*)&rcv_to, sizeof(rcv_to)) == -1) - { + + if (setsockopt(listenfd, SOL_SOCKET, SO_RCVTIMEO, (void*)&rcv_to, sizeof(rcv_to)) == -1) { printf("Set SO_RCVTIMEO failed, errno=%d\n", errno); goto __exit; } + int flag = 1; if (bind(listenfd, (struct sockaddr *) &webnet_saddr, sizeof(webnet_saddr)) == -1) { diff --git a/src/wn_module.c b/src/wn_module.c index 08b8060..f0db0b9 100755 --- a/src/wn_module.c +++ b/src/wn_module.c @@ -21,11 +21,12 @@ * 2022-05-09 chunyexixiaoyu the version from rt-thread */ +#include #include #include #include #include -#include +#include static int _webnet_module_system_init(struct webnet_session *session, int event) { @@ -106,8 +107,8 @@ static void _webnet_dofile_handle(struct webnet_session *session, int event) { length = WEBNET_SESSION_BUFSZ; } - lseek(fd, session->request->pos_start, SEEK_SET); - session->request->pos_start += length; + lseek(fd, session->request->pos_start, SEEK_SET); + session->request->pos_start += length; } #endif readbytes = wn_read(fd, session->buffer, length); @@ -116,6 +117,7 @@ static void _webnet_dofile_handle(struct webnet_session *session, int event) if (webnet_session_write(session, session->buffer, readbytes) == 0) goto __exit; + return; } @@ -267,9 +269,7 @@ int webnet_module_system_dofile(struct webnet_session *session) /* .gz not exist, use raw. */ #endif /* WEBNET_USING_GZIP */ - if (fd < 0 && stat(request->path, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) - { - SYS_KDEBUG_LOG(FILESYS_DEBUG, ("[%s] FileSys reuqest path: %s\n", __func__, request->path)); + if (fd < 0 && stat(request->path, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) { fd = wn_open(request->path, O_RDONLY, 0); } diff --git a/src/wn_session.c b/src/wn_session.c index 9ac5226..d6022f2 100755 --- a/src/wn_session.c +++ b/src/wn_session.c @@ -18,13 +18,14 @@ * * Change Logs: * Date Author Notes - * 2022-05-09 chunyexixiaoyu the version from rt-thread + * 2022-05-09 chunyexixiaoyu the version from rt-thread */ -#include #include #include #include +#include +#include #include #include @@ -188,6 +189,7 @@ RTM_EXPORT(webnet_session_printf); int webnet_session_write(struct webnet_session *session, const uint8* data, uint32 size) { /* send data directly */ + MdelayKTask(10); send(session->socket, data, size, 0); return size; @@ -524,12 +526,14 @@ void webnet_sessions_set_err_callback(void (*callback)(struct webnet_session *se void webnet_sessions_handle_fds(fd_set *readset, fd_set *writeset) { struct webnet_session *session, *next_session; + int num_sess = 0; /* Go through list of connected session and process data */ for (session = _session_list; session; session = next_session) { /* get next session firstly if this session is closed */ next_session = session->next; + num_sess++; if (FD_ISSET(session->socket, readset)) { @@ -552,7 +556,7 @@ void webnet_sessions_handle_fds(fd_set *readset, fd_set *writeset) session->session_phase = WEB_PHASE_METHOD; /* set the default session ops */ session->session_ops = &_default_session_ops; - session->user_data = 0;//change from NULL + session->user_data = 0; // change from NULL request->session = session; request->result_code = 200; /* set the default result code to 200 */ @@ -609,6 +613,8 @@ void webnet_sessions_handle_fds(fd_set *readset, fd_set *writeset) } } } + + SYS_KDEBUG_LOG(WEBNET_DEBUG, ("[%s] %d sessions in total\n", __func__, num_sess)); } @@ -620,36 +626,34 @@ static void list_webnet(void) char client_ip_str[16]; /* ###.###.###.### */ uint32 num = 0; - #ifdef ADD_XIZI_FEATURES - long lock; - lock = CriticalAreaLock(); - #endif // ADD_XIZI_FEATURES - #ifdef ADD_RTTHREAD_FETURES +#ifdef ADD_XIZI_FEATURES + x_base lock = CriticalAreaLock(); +#endif // ADD_XIZI_FEATURES +#ifdef ADD_RTTHREAD_FETURES PrivTaskenterCritical(); - #endif //ADD_RTTHREAD_FETURES - for (session = _session_list; session != NULL; session = session->next) - { +#endif // ADD_RTTHREAD_FETURES + for (session = _session_list; session != NULL; session = session->next) { strcpy(client_ip_str, - inet_ntoa(*((struct in_addr*)&(session->cliaddr.sin_addr)))); + inet_ntoa(*((struct in_addr*)&(session->cliaddr.sin_addr)))); printf("#%u client %s:%u \n", - num++, - client_ip_str, - ntohs(session->cliaddr.sin_port)); + num++, + client_ip_str, + ntohs(session->cliaddr.sin_port)); - if (session->request != NULL) - { + if (session->request != NULL) { printf("path: %s\n", session->request->path); } printf("\r\n"); } - #ifdef ADD_XIZI_FEATURES + printf("Total Session Number: %d\n", num); +#ifdef ADD_XIZI_FEATURES CriticalAreaUnLock(lock); - #endif // ADD_XIZI_FEATURES - #ifdef ADD_RTTHREAD_FETURES +#endif // ADD_XIZI_FEATURES +#ifdef ADD_RTTHREAD_FETURES PrivTaskexitCritical(); - #endif //ADD_RTTHREAD_FETURES +#endif // ADD_RTTHREAD_FETURES } #ifdef ADD_RTTHREAD_FETURES -- 2.34.1