Fit webnet to edu-arm32 and xidatong-arm32 #3
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"assert.h": "c",
|
||||
"wn_utils.h": "c",
|
||||
"webnet.h": "c",
|
||||
"wn_module.h": "c"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
SRC_DIR += src module samples
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -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模块
|
||||
|
|
|
|||
|
|
@ -23,33 +23,58 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
|
||||
#ifndef __WEBNET_H__
|
||||
#define __WEBNET_H__
|
||||
|
||||
#include <transform.h>
|
||||
#include <xs_klist.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef wn_malloc
|
||||
#define wn_malloc malloc
|
||||
#define wn_malloc PrivMalloc
|
||||
#endif
|
||||
|
||||
#ifndef wn_free
|
||||
#define wn_free free
|
||||
#define wn_free PrivFree
|
||||
#endif
|
||||
|
||||
#ifndef wn_realloc
|
||||
#define wn_realloc realloc
|
||||
#define wn_realloc PrivRealloc
|
||||
#endif
|
||||
|
||||
#ifndef wn_strdup
|
||||
#define wn_strdup strdup
|
||||
#define wn_strdup strdup
|
||||
#endif
|
||||
|
||||
#ifndef wn_read
|
||||
#define wn_read PrivRead
|
||||
#endif
|
||||
|
||||
#ifndef wn_open
|
||||
#define wn_open PrivOpen
|
||||
#endif
|
||||
|
||||
#ifndef wn_close
|
||||
#define wn_close PrivClose
|
||||
#endif
|
||||
|
||||
// #define WEBNET_USING_LOG
|
||||
// #define WEBNET_USING_AUTH
|
||||
// #define WEBNET_USING_CGI
|
||||
// #define WEBNET_USING_ASP
|
||||
// #define WEBNET_USING_SSI
|
||||
// #define WEBNET_USING_INDEX
|
||||
// #define WEBNET_USING_ALIAS
|
||||
// #define WEBNET_USING_UPLOAD
|
||||
// #define WEBNET_CACHE_LEVEL 0
|
||||
// #define WEBNET_USING_SAMPLES
|
||||
|
||||
#ifndef WEBNET_USING_RANGE
|
||||
#define WEBNET_USING_RANGE
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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__
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-10 chunyexixiaoyu the version the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
|
||||
#ifndef __WN_REQUEST_H__
|
||||
#define __WN_REQUEST_H__
|
||||
#include <transform.h>
|
||||
#include <rtthread.h>
|
||||
#include <wn_session.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -124,6 +125,7 @@ int webnet_request_parse_post(struct webnet_request* request, char* buffer, int
|
|||
void webnet_request_parse(struct webnet_request* request, char* buffer, int length);
|
||||
|
||||
bool webnet_request_has_query(struct webnet_request* request, char* name);
|
||||
|
||||
const char* webnet_request_get_query(struct webnet_request* request, char* name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-05-10 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
|
||||
#ifndef __WN_SESSION_H__
|
||||
|
|
@ -27,11 +28,16 @@
|
|||
#include <sys/select.h>
|
||||
#include <wn_request.h>
|
||||
|
||||
#ifdef BSP_USING_LWIP
|
||||
#include <sys_arch.h>
|
||||
#include <sockets.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WEBNET_SESSION_BUFSZ (4 * 1024)
|
||||
#define WEBNET_SESSION_BUFSZ (8 * 1024)
|
||||
|
||||
/* close session */
|
||||
#define WEBNET_EVENT_CLOSE (1 << 5)
|
||||
|
|
@ -68,7 +74,7 @@ struct webnet_session
|
|||
struct webnet_request* request;
|
||||
|
||||
/* session buffer */
|
||||
uint16 buffer_length;
|
||||
uint32 buffer_length;
|
||||
uint16 buffer_offset;
|
||||
uint8 buffer[WEBNET_SESSION_BUFSZ];
|
||||
|
||||
|
|
|
|||
|
|
@ -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__
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -18,11 +18,15 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <transform.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_request.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
#ifdef WEBNET_USING_ALIAS
|
||||
|
|
|
|||
|
|
@ -19,12 +19,15 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
|
||||
#include<transform.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_request.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
#ifdef WEBNET_USING_ASP
|
||||
|
|
@ -111,15 +114,12 @@ static void _default_asp_handler(struct webnet_session* session, const char* nam
|
|||
}
|
||||
else if (strncmp(name, "TICK", 4) == 0)
|
||||
{
|
||||
int32 tick;
|
||||
int32 tick;
|
||||
int32 hour, min, second;
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
tick = rt_tick_get()/RT_TICK_PER_SECOND;
|
||||
#endif
|
||||
tick = PrivGetTickTime();
|
||||
second = tick % 60;
|
||||
min = (tick/60) % 60;
|
||||
hour = tick / (60 * 60);
|
||||
|
||||
webnet_session_printf(session, "%02d:%02d:%02d", hour, min, second);
|
||||
}
|
||||
}
|
||||
|
|
@ -137,6 +137,7 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd)
|
|||
|
||||
/* allocate read buffer */
|
||||
buffer = (char*) wn_malloc (length);
|
||||
memset(buffer,0,length);
|
||||
if (buffer == NULL)
|
||||
{
|
||||
session->request->result_code = 500;
|
||||
|
|
@ -146,7 +147,8 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd)
|
|||
/* write page header */
|
||||
webnet_session_set_header(session, "text/html", 200, "OK", -1);
|
||||
/* read file to buffer */
|
||||
if (read(fd, buffer, (uint32)length) != length) /* read failed */
|
||||
|
||||
if (wn_read(fd, buffer, (uint32)length) != length) /* read failed */
|
||||
{
|
||||
wn_free(buffer);
|
||||
session->request->result_code = 500;
|
||||
|
|
@ -180,7 +182,9 @@ static void _webnet_asp_dofile(struct webnet_session* session, int fd)
|
|||
webnet_session_write(session, (const uint8*)offset, asp_begin - offset);
|
||||
|
||||
offset = asp_begin + 2;
|
||||
while ((*offset == ' ') || (*offset == '\t')) offset ++;
|
||||
while ((*offset == ' ') || (*offset == '\t')){
|
||||
offset++;
|
||||
}
|
||||
|
||||
/* extrace asp variable */
|
||||
for (index = 0; index < _webnet_asp_vars_count; index ++)
|
||||
|
|
@ -217,7 +221,7 @@ int webnet_module_asp(struct webnet_session* session, int event)
|
|||
|
||||
if (event == WEBNET_EVENT_URI_POST)
|
||||
{
|
||||
int fd;
|
||||
int fd=-1;
|
||||
|
||||
/* check whether a asp file */
|
||||
if ((strstr(request->path, ".asp") != NULL) ||
|
||||
|
|
@ -225,11 +229,11 @@ int webnet_module_asp(struct webnet_session* session, int event)
|
|||
{
|
||||
/* try to open this file */
|
||||
|
||||
fd = open(request->path, O_RDONLY, 0);
|
||||
fd = wn_open(request->path, O_RDONLY, 0);
|
||||
if ( fd >= 0)
|
||||
{
|
||||
_webnet_asp_dofile(session, fd);
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
return WEBNET_MODULE_FINISHED;
|
||||
}
|
||||
else
|
||||
|
|
@ -248,14 +252,16 @@ int webnet_module_asp(struct webnet_session* session, int event)
|
|||
if (asp_filename != NULL)
|
||||
{
|
||||
snprintf(asp_filename, WEBNET_PATH_MAX, "%s/index.asp", request->path);
|
||||
fd = open(asp_filename, O_RDONLY, 0);
|
||||
struct stat file_stat;
|
||||
if (stat(asp_filename, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) {
|
||||
fd = wn_open(asp_filename, O_RDONLY, 0);
|
||||
|
||||
if (fd >= 0)
|
||||
{
|
||||
wn_free(asp_filename);
|
||||
_webnet_asp_dofile(session, fd);
|
||||
close(fd);
|
||||
return WEBNET_MODULE_FINISHED;
|
||||
if (fd >= 0) {
|
||||
wn_free(asp_filename);
|
||||
_webnet_asp_dofile(session, fd);
|
||||
wn_close(fd);
|
||||
return WEBNET_MODULE_FINISHED;
|
||||
}
|
||||
}
|
||||
}
|
||||
wn_free(asp_filename);
|
||||
|
|
|
|||
|
|
@ -19,11 +19,14 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_request.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
#ifdef WEBNET_USING_AUTH
|
||||
|
|
@ -77,7 +80,10 @@ void webnet_auth_set(const char* path, const char* username_password)
|
|||
_auth_items[_auth_items_count - 1].path = wn_strdup(path);
|
||||
_auth_items[_auth_items_count - 1].username_password = str_base64_encode(username_password);
|
||||
}
|
||||
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
RTM_EXPORT(webnet_auth_set);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Authorization module handler
|
||||
|
|
|
|||
|
|
@ -18,13 +18,16 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_request.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
#ifdef WEBNET_USING_CGI
|
||||
|
|
@ -42,13 +45,13 @@ static uint32 _cgi_count = 0;
|
|||
|
||||
void webnet_cgi_set_root(const char* root)
|
||||
{
|
||||
if (strlen(root) > CGI_ROOT_PATH_MAX)
|
||||
{
|
||||
int root_len = strlen(root);
|
||||
if (root_len > CGI_ROOT_PATH_MAX) {
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
|
||||
strncpy(_cgi_root, root, strlen(root));
|
||||
strncpy(_cgi_root, root, root_len);
|
||||
if (_cgi_root[strlen(_cgi_root)] != '/')
|
||||
{
|
||||
_cgi_root[strlen(_cgi_root) + 1] = '/';
|
||||
|
|
|
|||
|
|
@ -18,13 +18,17 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
#include <transform.h>
|
||||
|
||||
#include <webnet.h>
|
||||
#include <wn_session.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
|
||||
#ifdef WEBNET_USING_DAV
|
||||
|
||||
struct webnet_module_put_entry
|
||||
|
|
@ -100,10 +104,10 @@ int webnet_module_dav(struct webnet_session* session, int event)
|
|||
printf("PROPFIND %s depth: %s", session->request->path,
|
||||
session->request->depth?session->request->depth:"null");
|
||||
|
||||
fd = open(session->request->path, O_RDONLY, 0);
|
||||
fd = wn_open(session->request->path, O_RDONLY, 0);
|
||||
if (fd >= 0)
|
||||
{
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
exit_file = 1;
|
||||
}
|
||||
dir = opendir(session->request->path);
|
||||
|
|
@ -276,9 +280,23 @@ static void print_propfind_element(struct webnet_session *session, const char *u
|
|||
|
||||
time_t t = file_stat->st_mtime;
|
||||
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
PrivTaskenterCritical();
|
||||
#endif
|
||||
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
long lock;
|
||||
lock = CriticalAreaLock();
|
||||
#endif //ADD_XIZI_FEATURES
|
||||
|
||||
strftime(ctime_str, sizeof(ctime_str), "%a, %d %b %Y %H:%M:%S GMT", localtime(&t));
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
PrivTaskexitCritical();
|
||||
#endif
|
||||
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
CriticalAreaUnLock(lock);
|
||||
#endif //ADD_XIZI_FEATURES
|
||||
//printf("strftime: %s\n", ctime_str);
|
||||
|
||||
webnet_session_printf(session,
|
||||
|
|
@ -296,7 +314,7 @@ static int put_open (struct webnet_session* session)
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
fd = open(session->request->path, O_WRONLY | O_CREAT | O_TRUNC, 0);
|
||||
fd = wn_open(session->request->path, O_WRONLY | O_CREAT | O_TRUNC, 0);
|
||||
if(fd < 0)
|
||||
{
|
||||
session->session_phase = WEB_PHASE_CLOSE;
|
||||
|
|
@ -319,7 +337,7 @@ static int put_close(struct webnet_session* session)
|
|||
fd = (int)webnet_put_get_userdata(session);
|
||||
if (fd < 0) return 0;
|
||||
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,12 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
#include <transform.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_utils.h>
|
||||
|
|
|
|||
|
|
@ -18,13 +18,16 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
#include <transform.h>
|
||||
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
|
||||
#ifdef WEBNET_USING_LOG
|
||||
|
||||
int webnet_module_log(struct webnet_session* session, int event)
|
||||
|
|
@ -42,7 +45,7 @@ int webnet_module_log(struct webnet_session* session, int event)
|
|||
|
||||
if (event == WEBNET_EVENT_INIT)
|
||||
{
|
||||
printf("server initialize success.");
|
||||
printf("server initialize success.\n");
|
||||
}
|
||||
else if (event == WEBNET_EVENT_URI_PHYSICAL)
|
||||
{
|
||||
|
|
@ -75,7 +78,7 @@ int webnet_module_log(struct webnet_session* session, int event)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
printf(" request: %s", request->path);
|
||||
printf(" request: %s\n", request->path);
|
||||
for (index = 0; index < request->query_counter; index ++)
|
||||
{
|
||||
printf(" query[%d]: %s => %s", index,
|
||||
|
|
@ -87,7 +90,7 @@ int webnet_module_log(struct webnet_session* session, int event)
|
|||
{
|
||||
|
||||
printf("event post uri physical url: %s", request->path);
|
||||
printf("mime type: %s", mime_get_type(request->path));
|
||||
printf("mime type: %s\n", mime_get_type(request->path));
|
||||
}
|
||||
else if (event == WEBNET_EVENT_RSP_HEADER)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -19,11 +19,15 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
#include <transform.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_session.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_session.h>
|
||||
|
||||
#if defined(WEBNET_USING_SSI)
|
||||
|
||||
#define SSI_INCLUDE_STRING "<!--#include "
|
||||
|
|
@ -39,7 +43,7 @@ static void _webnet_ssi_sendfile(struct webnet_session* session, const char* fil
|
|||
int file_length;
|
||||
unsigned long size, readbytes;
|
||||
|
||||
fd = open(filename, O_RDONLY, 0);
|
||||
fd = wn_open(filename, O_RDONLY, 0);
|
||||
if (fd < 0) return; /* open file failed */
|
||||
|
||||
/* get file size */
|
||||
|
|
@ -48,7 +52,7 @@ static void _webnet_ssi_sendfile(struct webnet_session* session, const char* fil
|
|||
lseek(fd, 0, SEEK_SET);
|
||||
if (file_length <= 0)
|
||||
{
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
return ;
|
||||
}
|
||||
while (file_length)
|
||||
|
|
@ -58,7 +62,7 @@ static void _webnet_ssi_sendfile(struct webnet_session* session, const char* fil
|
|||
else
|
||||
size = file_length;
|
||||
|
||||
readbytes = read(fd, session->buffer, size);
|
||||
readbytes = wn_read(fd, session->buffer, size);
|
||||
if (readbytes <= 0)
|
||||
/* no more data */
|
||||
break;
|
||||
|
|
@ -70,7 +74,7 @@ static void _webnet_ssi_sendfile(struct webnet_session* session, const char* fil
|
|||
}
|
||||
|
||||
/* close file */
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
}
|
||||
|
||||
static void _webnet_ssi_dofile(struct webnet_session* session, int fd)
|
||||
|
|
@ -102,14 +106,14 @@ static void _webnet_ssi_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, length) != length) /* read failed */
|
||||
if (wn_read(fd, buffer, length) != length) /* read failed */
|
||||
{
|
||||
session->request->result_code = 500;
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
goto __exit;
|
||||
}
|
||||
/* close file */
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
|
||||
offset = buffer;
|
||||
end = buffer + length;
|
||||
|
|
@ -207,11 +211,11 @@ int webnet_module_ssi(struct webnet_session* session, int event)
|
|||
if (strstr(request->path, ssi_extension[index]) != NULL)
|
||||
{
|
||||
/* try to open this file */
|
||||
fd = open(request->path, O_RDONLY, 0);
|
||||
fd = wn_open(request->path, O_RDONLY, 0);
|
||||
if ( fd >= 0)
|
||||
{
|
||||
_webnet_ssi_dofile(session, fd);
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
return WEBNET_MODULE_FINISHED;
|
||||
}
|
||||
else
|
||||
|
|
@ -233,13 +237,13 @@ int webnet_module_ssi(struct webnet_session* session, int event)
|
|||
if (ssi_filename != NULL)
|
||||
{
|
||||
snprintf(ssi_filename, WEBNET_PATH_MAX, "%s/index.shtm", request->path);
|
||||
fd = open(ssi_filename, O_RDONLY, 0);
|
||||
fd = wn_open(ssi_filename, O_RDONLY, 0);
|
||||
|
||||
if (fd >= 0)
|
||||
{
|
||||
wn_free(ssi_filename);
|
||||
_webnet_ssi_dofile(session, fd);
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
return WEBNET_MODULE_FINISHED;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,11 @@
|
|||
* 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 <transform.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_utils.h>
|
||||
|
|
@ -155,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;
|
||||
|
|
@ -174,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)
|
||||
{
|
||||
|
|
@ -748,7 +750,7 @@ int webnet_upload_file_close(struct webnet_session* session)
|
|||
fd = upload_session->user_data;
|
||||
if (fd >= 0)
|
||||
{
|
||||
return close(fd);
|
||||
return wn_close(fd);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
SRC_FILES += deviceinfoasp.c \
|
||||
wn_sample_upload.c \
|
||||
uploaddata.c \
|
||||
netsetting.c \
|
||||
wn_sample.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
|
@ -1,4 +1,22 @@
|
|||
#include "deviceinfoasp.h"
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
extern void HwCpuReset();//reset machine
|
||||
#endif //ADD_XIZI_FEATURES
|
||||
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
deviceinfo xidatong_deviceinfo =
|
||||
{
|
||||
DEVICE_NUM_DEFUALT,
|
||||
DEVICE_NAME_DEFUALT,
|
||||
DEVICE_TYPE_DEFUALT,
|
||||
DEVICE_SERIAL_DEFUALT,
|
||||
XIZI_OS_KERNEL,
|
||||
SYSTEM_VERSION,
|
||||
WEB_VERSION
|
||||
};
|
||||
#endif //ADD_XIZI_FEATURES
|
||||
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
deviceinfo xidatong_deviceinfo =
|
||||
{
|
||||
DEVICE_NUM_DEFUALT,
|
||||
|
|
@ -9,6 +27,7 @@ deviceinfo xidatong_deviceinfo =
|
|||
SYSTEM_VERSION,
|
||||
WEB_VERSION
|
||||
};
|
||||
#endif
|
||||
|
||||
void deviceinfo_default()
|
||||
{
|
||||
|
|
@ -80,10 +99,13 @@ 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));
|
||||
#elif defined ADD_XIZI_FETURES
|
||||
#endif
|
||||
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
HwCpuReset();
|
||||
#endif //ADD_XIZI_FEATURES
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,13 @@
|
|||
#ifndef _DEVICEINFO_H
|
||||
#define _DEVICEINFO_H
|
||||
|
||||
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_request.h>
|
||||
#include <wn_utils.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#define RT_THREAD_KERNEL "rt-thread kenel"
|
||||
#define NUTTX_OS_KERNEL "nuttx kenel"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#include "netsetting.h"
|
||||
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
#include <netdev.h>
|
||||
#include <netdev_ipaddr.h>
|
||||
#endif // ADD_XIZI_FEATURES
|
||||
|
||||
static mqttsetting mqttweb;
|
||||
static local_tcpip local_tcpipweb;
|
||||
|
|
@ -36,7 +40,7 @@ void private_prtweb_default()
|
|||
|
||||
char *json_create_mqtt_data(void)
|
||||
{
|
||||
char *json_data = RT_NULL;
|
||||
char *json_data = NULL;
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
|
||||
cJSON_AddItemToObject(root, "pub_topic", cJSON_CreateString(mqttweb.topic));
|
||||
|
|
@ -93,27 +97,42 @@ void cgi_mqtt_save_data(struct webnet_session *session)
|
|||
|
||||
static void device_get_tcpip_parameter()
|
||||
{
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
struct netdev *netdev_device = netdev_get_by_name("e0");
|
||||
/*
|
||||
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));
|
||||
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]));
|
||||
#elif defined ADD_XIZI_FETURES
|
||||
#endif
|
||||
char dev_name[3] = "hd\0";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//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));
|
||||
//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]));
|
||||
|
||||
printf("ip address: %s\n", local_tcpipweb.local_ipaddr);
|
||||
printf("netmask address: %s\n", local_tcpipweb.netmask_addr);
|
||||
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_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_FEATURES
|
||||
|
||||
char *json_create_tcpip_data(void)
|
||||
{
|
||||
char *json_data = RT_NULL;
|
||||
char *json_data = NULL;
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "local_ipaddr", cJSON_CreateString(local_tcpipweb.local_ipaddr));
|
||||
cJSON_AddItemToObject(root, "netmask_addr", cJSON_CreateString(local_tcpipweb.netmask_addr));
|
||||
|
|
@ -140,12 +159,21 @@ void cgi_tcpip_save_data(struct webnet_session *session)
|
|||
cgi_head();
|
||||
ip_addr_t addr;
|
||||
const char *response = "{\"code\":0}";
|
||||
|
||||
const char *local_ipaddr = webnet_request_get_query(request, "local_ipaddr");
|
||||
const char *netmask_addr = webnet_request_get_query(request, "netmask_addr");
|
||||
const char *gateway_addr = webnet_request_get_query(request, "gateway_addr");
|
||||
const char *dns_server0 = webnet_request_get_query(request, "dns_server0");
|
||||
const char *dns_server1 = webnet_request_get_query(request, "dns_server1");
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
|
||||
|
||||
printf("ip address: %s\n", local_ipaddr);
|
||||
printf("netmask address: %s\n", netmask_addr);
|
||||
printf("gw address: %s\n", gateway_addr);
|
||||
printf("dns0 address: %s\n", dns_server0);
|
||||
printf("dns1 address: %s\n", dns_server1);
|
||||
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
struct netdev *netdev_device = netdev_get_by_name("e0");
|
||||
inet_aton(local_ipaddr, &addr);
|
||||
netdev_set_ipaddr(netdev_device, &addr);
|
||||
|
|
@ -157,15 +185,23 @@ void cgi_tcpip_save_data(struct webnet_session *session)
|
|||
netdev_set_dns_server(netdev_device,0, &addr);
|
||||
inet_aton(dns_server1, &addr);
|
||||
netdev_set_dns_server(netdev_device,0, &addr);
|
||||
#elif defined ADD_XIZI_FETURES
|
||||
#endif
|
||||
#endif //ADD_RTTHREAD_FETURES
|
||||
/*configuration*/
|
||||
memset((char*)(&local_tcpipweb),0,sizeof(local_tcpipweb));
|
||||
|
||||
strcpy(local_tcpipweb.local_ipaddr,local_ipaddr);
|
||||
strcpy(local_tcpipweb.netmask_addr,netmask_addr);
|
||||
strcpy(local_tcpipweb.gateway_addr,gateway_addr);
|
||||
strcpy(local_tcpipweb.dns_server0,dns_server0);
|
||||
strcpy(local_tcpipweb.dns_server1,dns_server1);
|
||||
|
||||
|
||||
printf("ip address: %s\n", local_tcpipweb.local_ipaddr);
|
||||
printf("netmask address: %s\n", local_tcpipweb.netmask_addr);
|
||||
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);
|
||||
|
||||
webnet_session_printf(session, response);
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +209,7 @@ void cgi_tcpip_save_data(struct webnet_session *session)
|
|||
|
||||
char *json_create_private_prt_data()
|
||||
{
|
||||
char *json_data = RT_NULL;
|
||||
char *json_data = NULL;
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "server_addr", cJSON_CreateString(private_prtweb.server_addr));
|
||||
cJSON_AddItemToObject(root, "server_port", cJSON_CreateString(private_prtweb.server_port));
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
#ifndef _NETSETTING_H
|
||||
#define _NETSETTING_H
|
||||
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include<cJSON.h>
|
||||
#include<transform.h>
|
||||
#include <wn_request.h>
|
||||
#include <wn_utils.h>
|
||||
#include <cJSON.h>
|
||||
#include <transform.h>
|
||||
|
||||
#define cgi_head() \
|
||||
; \
|
||||
|
|
|
|||
|
|
@ -1,105 +1,118 @@
|
|||
#include "uploaddata.h"
|
||||
#include <mqueue.h>
|
||||
#include <transform.h>
|
||||
|
||||
char msg[] = "/mq_upload_web";
|
||||
sensor_msg eg_temperature;
|
||||
sensor_msg web_show;
|
||||
|
||||
static mqd_t mq_web;
|
||||
void upload_receive_web_msg_thread()
|
||||
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);
|
||||
while (1) {
|
||||
nbytes = mq_receive(mq_web, (char*)(&eg_temperature), sizeof(eg_temperature), NULL);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
printf("mq_receive error: %d \n",nbytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("=============mq_receive success:==============\n");
|
||||
printf("mq_receive error: %d \n", nbytes);
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
break;
|
||||
#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 = 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
|
||||
prio.sched_priority = 8;
|
||||
#endif // ADD_RTTHREAD_FETURES
|
||||
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
prio.sched_priority = 25;
|
||||
#endif // ADD_XIZI_FEATURES
|
||||
|
||||
size_t stack_size = 1024 * 11;
|
||||
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);
|
||||
}
|
||||
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 (0 == result)
|
||||
{
|
||||
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);
|
||||
}
|
||||
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
|
||||
char *json_create_datashow_data()
|
||||
{
|
||||
char *json_data = RT_NULL;
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
|
||||
#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();
|
||||
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));
|
||||
|
|
@ -107,7 +120,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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef _UPLOADDATA_
|
||||
#define _UPLOADDATA_
|
||||
#include "netsetting.h"
|
||||
#include<transform.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[32]; //sensor name
|
||||
|
|
|
|||
|
|
@ -18,11 +18,16 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-05-09 chunyexixiaoyu the version transplanted from rt-thread
|
||||
* 2022-09-07 zhaoyun the version transplanted for XiZi
|
||||
*/
|
||||
#include <transform.h>
|
||||
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_request.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
#include "deviceinfoasp.h"
|
||||
#include "netsetting.h"
|
||||
#include "uploaddata.h"
|
||||
|
|
@ -71,11 +76,17 @@ void webnet_start(void)
|
|||
#endif
|
||||
private_prtweb_default();
|
||||
mqttweb_default();
|
||||
uploaddata_init();
|
||||
// uploaddata_init();
|
||||
webnet_init();
|
||||
|
||||
|
||||
|
||||
}
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(webnet_start, wenbet test);
|
||||
#endif
|
||||
#endif //ADD_RTTHREAD_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_FEATURES
|
||||
|
|
|
|||
|
|
@ -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 <transform.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
|
||||
#include <wn_request.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef WEBNET_USING_UPLOAD
|
||||
|
||||
/**
|
||||
|
|
@ -92,7 +99,7 @@ static int upload_open(struct webnet_session *session)
|
|||
|
||||
printf("save to: %s\r\n", file_path);
|
||||
|
||||
fd = open(file_path, O_WRONLY | O_CREAT, 0);
|
||||
fd = wn_open(file_path, O_WRONLY | O_CREAT, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
webnet_session_close(session);
|
||||
|
|
@ -116,7 +123,7 @@ static int upload_close(struct webnet_session* session)
|
|||
fd = (int)webnet_upload_get_userdata(session);
|
||||
if (fd < 0) return 0;
|
||||
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
printf("Upload FileSize: %d\n", file_size);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version from rt-thread
|
||||
* 2022-05-09 chunyexixiaoyu the version from rt-thread
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -26,23 +26,18 @@
|
|||
#include <stdint.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
|
||||
#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.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <sys.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +60,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;
|
||||
|
|
@ -88,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)
|
||||
{
|
||||
|
|
@ -128,7 +124,7 @@ static void webnet_thread(void *parameter)
|
|||
/* use temporary fd set in select */
|
||||
tempfds = readset;
|
||||
tempwrtfds = writeset;
|
||||
/* Wait for data or a new connection */
|
||||
|
||||
sock_fd = select(maxfdp1, &tempfds, &tempwrtfds, 0, 0);
|
||||
if (sock_fd == 0)
|
||||
{
|
||||
|
|
@ -175,28 +171,29 @@ __exit:
|
|||
int webnet_init(void)
|
||||
{
|
||||
int result = 0;
|
||||
#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;
|
||||
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);
|
||||
|
||||
if (0 == result)
|
||||
{
|
||||
init_ok = TRUE;
|
||||
init_ok = true;
|
||||
printf("XiUOS webnet initialize success.");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("XiUOS webnet initialize failed.");
|
||||
printf("XiUOS webnet initialize failed\n.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ static const struct webnet_mime_entry mime_tables[] =
|
|||
{ "png", "image/png" },
|
||||
{ "jpeg", "image/jpeg" },
|
||||
{ "jpg", "image/jpeg" },
|
||||
{ "ico", "image/x-icon" },
|
||||
{ "svg", "image/svg+xml" },
|
||||
{ "avi", "video/x-msvideo" },
|
||||
{ "mp3", "audio/mpeg" },
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@
|
|||
* 2022-05-09 chunyexixiaoyu the version from rt-thread
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <transform.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
|
||||
#include <xs_kdbg.h>
|
||||
|
||||
static int _webnet_module_system_init(struct webnet_session *session, int event)
|
||||
{
|
||||
|
|
@ -107,21 +107,22 @@ 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 = read(fd, session->buffer, length);
|
||||
readbytes = wn_read(fd, session->buffer, length);
|
||||
if (readbytes <= 0) /* end of file */
|
||||
goto __exit;
|
||||
|
||||
if (webnet_session_write(session, session->buffer, readbytes) == 0)
|
||||
goto __exit;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
__exit:
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
session->user_data = 0;
|
||||
session->session_event_mask = 0; /* clean event */
|
||||
/* destroy session */
|
||||
|
|
@ -142,7 +143,7 @@ int webnet_module_system_dofile(struct webnet_session *session)
|
|||
int fd = -1; /* file descriptor */
|
||||
struct stat file_stat;
|
||||
const char *mimetype;
|
||||
unsigned long file_length;
|
||||
unsigned long file_length;
|
||||
struct webnet_request *request;
|
||||
|
||||
#if WEBNET_CACHE_LEVEL > 0
|
||||
|
|
@ -172,11 +173,23 @@ int webnet_module_system_dofile(struct webnet_session *session)
|
|||
wn_free(path_gz);
|
||||
}
|
||||
|
||||
if (stat_result == 0)
|
||||
{
|
||||
if (stat_result == 0) {
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
long lock;
|
||||
lock = CriticalAreaLock();
|
||||
#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
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
PrivTaskexitCritical();
|
||||
#endif // ADD_RTTHREAD_FETURES
|
||||
|
||||
ctime_str[strlen(ctime_str) - 1] = '\0'; /* clear the end \n */
|
||||
|
||||
|
|
@ -191,21 +204,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)
|
||||
{
|
||||
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
|
||||
|
||||
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
|
||||
PrivTaskexitCritical();
|
||||
#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 */
|
||||
|
|
@ -231,22 +256,21 @@ int webnet_module_system_dofile(struct webnet_session *session)
|
|||
if (path_gz != NULL)
|
||||
{
|
||||
sprintf(path_gz, "%s.gz", request->path);
|
||||
fd = open(path_gz, O_RDONLY, 0);
|
||||
fd = wn_open(path_gz, O_RDONLY, 0);
|
||||
wn_free(path_gz);
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
/* .gz not exist, use raw. */
|
||||
request->support_gzip = FALSE;
|
||||
request->support_gzip = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* .gz not exist, use raw. */
|
||||
#endif /* WEBNET_USING_GZIP */
|
||||
if (fd < 0 && stat(request->path, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode))
|
||||
{
|
||||
fd = open(request->path, O_RDONLY, 0);
|
||||
if (fd < 0 && stat(request->path, &file_stat) >= 0 && !S_ISDIR(file_stat.st_mode)) {
|
||||
fd = wn_open(request->path, O_RDONLY, 0);
|
||||
}
|
||||
|
||||
if (fd < 0)
|
||||
|
|
@ -386,7 +410,7 @@ int webnet_module_system_dofile(struct webnet_session *session)
|
|||
|
||||
if (file_length <= 0)
|
||||
{
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
return WEBNET_MODULE_FINISHED;
|
||||
}
|
||||
|
||||
|
|
@ -405,7 +429,7 @@ int webnet_module_system_dofile(struct webnet_session *session)
|
|||
_error_exit:
|
||||
if (fd >= 0)
|
||||
{
|
||||
close(fd);
|
||||
wn_close(fd);
|
||||
}
|
||||
|
||||
return WEBNET_MODULE_FINISHED;
|
||||
|
|
@ -491,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
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -24,11 +24,13 @@
|
|||
#include <transform.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <webnet.h>
|
||||
#include <wn_request.h>
|
||||
#include <wn_utils.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define POST_BUFSZ_MAX (8 * 1024)
|
||||
|
||||
/**
|
||||
|
|
@ -108,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)
|
||||
{
|
||||
|
|
@ -141,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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -154,10 +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);
|
||||
|
|
@ -315,8 +316,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);
|
||||
rt_memset(request->query, 0, request->content_length + 1);
|
||||
request->query = (char*) wn_malloc(request->content_length + 1);
|
||||
memset(request->query, 0, request->content_length + 1);
|
||||
request->query_offset = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -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 */
|
||||
|
|
@ -495,7 +496,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;
|
||||
|
||||
rt_memcpy(&request->query[request->query_offset], buffer, length);
|
||||
memcpy(&request->query[request->query_offset], buffer, length);
|
||||
request->query_offset += length;
|
||||
|
||||
if (request->query_offset == request->content_length)
|
||||
|
|
@ -678,8 +679,10 @@ void webnet_request_parse(struct webnet_request* request, char* buffer, int leng
|
|||
{
|
||||
/* end of http request */
|
||||
request->result_code = 200;
|
||||
session->buffer_offset = (rt_uint16_t)(length -
|
||||
|
||||
session->buffer_offset = (uint16_t)(length -
|
||||
((uint32)request->query - (uint32)buffer));
|
||||
|
||||
/* move the buffer to the session */
|
||||
if (session->buffer_offset > 0)
|
||||
{
|
||||
|
|
@ -687,7 +690,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.
|
||||
*/
|
||||
rt_memcpy(session->buffer, request->query, session->buffer_offset);
|
||||
memcpy(session->buffer, request->query, session->buffer_offset);
|
||||
}
|
||||
request->query = NULL;
|
||||
return;
|
||||
|
|
@ -715,7 +718,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;
|
||||
rt_memcpy(read_ptr, request->query, read_length);
|
||||
memcpy(read_ptr, request->query, read_length);
|
||||
}
|
||||
request->query = read_ptr;
|
||||
|
||||
|
|
@ -865,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 */
|
||||
|
|
@ -906,8 +909,8 @@ struct webnet_request* webnet_request_create()
|
|||
request = (struct webnet_request*) wn_malloc (sizeof(struct webnet_request));
|
||||
if (request != NULL)
|
||||
{
|
||||
rt_memset(request, 0, sizeof(struct webnet_request));
|
||||
request->field_copied = FALSE;
|
||||
memset(request, 0, sizeof(struct webnet_request));
|
||||
request->field_copied = false;
|
||||
}
|
||||
|
||||
return request;
|
||||
|
|
@ -917,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);
|
||||
|
|
|
|||
|
|
@ -18,17 +18,23 @@
|
|||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-05-09 chunyexixiaoyu the version from rt-thread
|
||||
* 2022-05-09 chunyexixiaoyu the version from rt-thread
|
||||
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
#include <xs_kdbg.h>
|
||||
|
||||
#include <webnet.h>
|
||||
#include <wn_module.h>
|
||||
#include <wn_utils.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
#include <finsh.h>
|
||||
#endif //ADD_RTTHREAD_FETURES
|
||||
|
||||
static struct webnet_session *_session_list = 0;
|
||||
|
||||
|
|
@ -124,8 +130,9 @@ void webnet_session_close(struct webnet_session *session)
|
|||
closesocket(session->socket);
|
||||
|
||||
/* Free webnet_session */
|
||||
if (_session_list == session)
|
||||
if (_session_list == session){
|
||||
_session_list = session->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (iter = _session_list; iter; iter = iter->next)
|
||||
|
|
@ -182,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;
|
||||
|
|
@ -458,7 +466,7 @@ static void _webnet_session_badrequest(struct webnet_session *session, int code)
|
|||
title = "Method Not Allowed";
|
||||
break;
|
||||
case 500:
|
||||
title = "Internal Server Error";
|
||||
title = "Internal Server Error\n";
|
||||
break;
|
||||
case 501:
|
||||
title = "Not Implemented";
|
||||
|
|
@ -518,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))
|
||||
{
|
||||
|
|
@ -546,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 = NULL;
|
||||
session->user_data = 0; // change from NULL
|
||||
|
||||
request->session = session;
|
||||
request->result_code = 200; /* set the default result code to 200 */
|
||||
|
|
@ -603,10 +613,12 @@ 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));
|
||||
}
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
|
||||
|
||||
|
||||
|
||||
static void list_webnet(void)
|
||||
{
|
||||
|
|
@ -614,29 +626,47 @@ static void list_webnet(void)
|
|||
char client_ip_str[16]; /* ###.###.###.### */
|
||||
uint32 num = 0;
|
||||
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
x_base lock = CriticalAreaLock();
|
||||
#endif // ADD_XIZI_FEATURES
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
PrivTaskenterCritical();
|
||||
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");
|
||||
}
|
||||
printf("Total Session Number: %d\n", num);
|
||||
#ifdef ADD_XIZI_FEATURES
|
||||
CriticalAreaUnLock(lock);
|
||||
#endif // ADD_XIZI_FEATURES
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
PrivTaskexitCritical();
|
||||
#endif // ADD_RTTHREAD_FETURES
|
||||
}
|
||||
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
#endif /* RT_USING_FINSH */
|
||||
FINSH_FUNCTION_EXPORT(list_webnet, list webnet session);
|
||||
#ifdef FINSH_USING_MSH
|
||||
MSH_CMD_EXPORT(list_webnet, list webnet session);
|
||||
#endif
|
||||
#endif /* RT_USING_FINSH */
|
||||
#endif
|
||||
#endif //FINSH_USING_MSH
|
||||
#endif //ADD_RTTHREAD_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_FEATURES
|
||||
|
|
|
|||
|
|
@ -23,12 +23,11 @@
|
|||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include <webnet.h>
|
||||
#include <wn_utils.h>
|
||||
#include <transform.h>
|
||||
|
||||
rt_inline int tohex(char c)
|
||||
inline int tohex(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="favicon.ico" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="favicon.ico">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
<meta name="description" content="xidatong webnet" />
|
||||
<meta name="author" content="gong" />
|
||||
<!-- <link rel="icon" href="../../favicon.ico" /> -->
|
||||
|
||||
|
||||
<title>xidatong web server set page</title>
|
||||
|
||||
|
|
@ -144,4 +145,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 206 KiB After Width: | Height: | Size: 206 KiB |
|
|
@ -2,6 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="favicon.ico" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>xidatong web server set page </title>
|
||||
<link rel="icon" href="favicon.ico" />
|
||||
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="favicon.ico" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="favicon.ico" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta http-equiv="Cache-Control" content="max-age=7200" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
|
||||
<meta name="description" content="xidatong webnet" />
|
||||
<meta name="author" content="gong" />
|
||||
<!-- <link rel="icon" href="../../favicon.ico" /> -->
|
||||
<link rel="icon" href="favicon.ico" />
|
||||
|
||||
<title>xidatong web server set page</title>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue