兼容linux

This commit is contained in:
xx
2024-05-28 15:12:37 +08:00
parent b8b2ff12bf
commit bdbe5f34dd
34 changed files with 331 additions and 713 deletions

63
.gitattributes vendored
View File

@@ -1,63 +0,0 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

5
.gitignore vendored
View File

@@ -2,7 +2,4 @@
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################
/.vs
/session
/obj
/bin
/build

View File

@@ -19,7 +19,7 @@ namespace ylib::mssql
class prepare_statement;
struct mssql_conn_info
{
mssql_conn_info(){
mssql_conn_info() {
}
std::string odbcname;
std::string username;
@@ -68,19 +68,19 @@ namespace ylib::mssql
std::map<std::string, short> m_field_name_index;
};
class prepare_statement:public ylib::error_base{
class prepare_statement :public ylib::error_base {
public:
prepare_statement();
~prepare_statement();
void set_boolean(uint32 index,bool value);
void set_datetime(uint32 index,const std::string& value);
void set_double(uint32 index,double value);
void set_int32(uint32 index,int32 value);
void set_uint32(uint32 index,uint32 value);
void set_int64(uint32 index,int64 value);
void set_uint64(uint32 index,uint64 value);
void set_boolean(uint32 index, bool value);
void set_datetime(uint32 index, const std::string& value);
void set_double(uint32 index, double value);
void set_int32(uint32 index, int32 value);
void set_uint32(uint32 index, uint32 value);
void set_int64(uint32 index, int64 value);
void set_uint64(uint32 index, uint64 value);
void set_null(uint32 index);
void set_string(uint32 index,const std::string& value);
void set_string(uint32 index, const std::string& value);
void clear();
uint64 update();
ylib::mssql::result* query();
@@ -90,12 +90,12 @@ namespace ylib::mssql
ylib::mssql::result* m_result = nullptr;
void* m_handle = nullptr;
};
class conn :public ylib::example<ylib::mssql::mssql_conn_info>,public ylib::error_base
class conn :public ylib::example<ylib::mssql::mssql_conn_info>, public ylib::error_base
{
public:
conn();
~conn();
virtual EXAMPLE_START_RESULT start(const ylib::mssql::mssql_conn_info&info) override;
virtual EXAMPLE_START_RESULT start(const ylib::mssql::mssql_conn_info& info) override;
virtual void close() override;
@@ -110,14 +110,14 @@ namespace ylib::mssql
void rollback();
friend class ylib::mssql::pool;
private:
void *m_handle = nullptr;
void* m_handle = nullptr;
ylib::mssql::mssql_conn_info m_info;
class prepare_statement* m_ppst = nullptr;
int m_sw = 0;
};
class pool: public ylib::pool<ylib::mssql::conn, ylib::mssql::mssql_conn_info>
class pool : public ylib::pool<ylib::mssql::conn, ylib::mssql::mssql_conn_info>
{
public:
pool();

View File

@@ -17,14 +17,14 @@ namespace ylib::mysql
class result;
class conn;
class prepare_statement;
struct field{
struct field {
uint32 index = 0;
std::string name;
std::string type_name;
};
struct mysql_conn_info
{
mysql_conn_info(){
mysql_conn_info() {
port = 0;
}
std::string ipaddress;
@@ -81,21 +81,21 @@ namespace ylib::mysql
std::vector<ylib::mysql::field> m_fields;
};
class prepare_statement:public ylib::error_base{
class prepare_statement :public ylib::error_base {
public:
prepare_statement();
~prepare_statement();
void set_bigint(uint32 index,const std::string& value);
void set_boolean(uint32 index,bool value);
void set_datetime(uint32 index,const std::string& value);
void set_double(uint32 index,double value);
void set_int32(uint32 index,int32 value);
void set_uint32(uint32 index,uint32 value);
void set_int64(uint32 index,int64 value);
void set_uint64(uint32 index,uint64 value);
void set_bigint(uint32 index, const std::string& value);
void set_boolean(uint32 index, bool value);
void set_datetime(uint32 index, const std::string& value);
void set_double(uint32 index, double value);
void set_int32(uint32 index, int32 value);
void set_uint32(uint32 index, uint32 value);
void set_int64(uint32 index, int64 value);
void set_uint64(uint32 index, uint64 value);
void set_null(uint32 index);
void set_string(uint32 index,const std::string& value);
void set_blob(uint32 index,const ylib::buffer& value);
void set_string(uint32 index, const std::string& value);
void set_blob(uint32 index, const ylib::buffer& value);
void clear();
uint64 update();
ylib::mysql::result* query();
@@ -105,12 +105,12 @@ namespace ylib::mysql
ylib::mysql::result* m_result = nullptr;
void* m_handle = nullptr;
};
class conn :public ylib::example<ylib::mysql::mysql_conn_info>,public ylib::error_base
class conn :public ylib::example<ylib::mysql::mysql_conn_info>, public ylib::error_base
{
public:
conn();
~conn();
virtual EXAMPLE_START_RESULT start(const ylib::mysql::mysql_conn_info&info) override;
virtual EXAMPLE_START_RESULT start(const ylib::mysql::mysql_conn_info& info) override;
virtual void close() override;
@@ -130,7 +130,7 @@ namespace ylib::mysql
friend class ylib::mysql::pool;
private:
void *m_handle = nullptr;
void* m_handle = nullptr;
ylib::mysql::mysql_conn_info m_info;
class prepare_statement* m_ppst = nullptr;
// 事务状态 0=未开启 1=已开启 2=执行完毕
@@ -138,7 +138,7 @@ namespace ylib::mysql
};
class pool: public ylib::pool<ylib::mysql::conn, ylib::mysql::mysql_conn_info>
class pool : public ylib::pool<ylib::mysql::conn, ylib::mysql::mysql_conn_info>
{
public:
pool()

View File

@@ -21,7 +21,7 @@ namespace ylib
};
struct order_by {
std::string field;
sort sort;
ylib::sort sort;
};
struct keyvalue {
std::string name;
@@ -31,7 +31,7 @@ namespace ylib
/// <summary>
/// MYSQL SELECT 查询器
/// </summary>
class select:public ylib::error_base {
class select :public ylib::error_base {
public:
select(mysql::conn* conn);
~select();
@@ -51,11 +51,11 @@ namespace ylib
/// <summary>
/// 条件[A=B]
/// </summary>
select& where(const std::string& name,const std::string& expression,const std::any& value);
select& where(const std::string& name, const std::string& expression, const std::any& value);
/// <summary>
/// 条件[模糊查询]
/// </summary>
select& where_like(const std::string& name,const std::string& value);
select& where_like(const std::string& name, const std::string& value);
/// <summary>
/// 条件[自定义]
/// </summary>
@@ -63,7 +63,7 @@ namespace ylib
/// <summary>
/// LIMIT[页]
/// </summary>
select& page(uint32 page,uint32 count);
select& page(uint32 page, uint32 count);
/// <summary>
/// LIMIT
/// </summary>
@@ -96,7 +96,7 @@ namespace ylib
/// <param name="where"></param>
/// <param name="orderby"></param>
/// <param name="limit"></param>
void make_sql(std::string& field_name,std::string& where,std::string& orderby,std::string& limit,std::vector<std::any>& insert_values);
void make_sql(std::string& field_name, std::string& where, std::string& orderby, std::string& limit, std::vector<std::any>& insert_values);
private:
mysql::conn* m_conn = nullptr;
std::vector<ylib::where> m_wheres;
@@ -106,18 +106,6 @@ namespace ylib
order_by m_orderby;
};
#if 0
class Lselect :public ylib::select {
public:
Lselect(void* conn);
~Lselect();
void where_i32(const std::string& name, const std::string& expression,int32 value);
void where_i64(const std::string& name, const std::string& expression,int64 value);
void where_dob(const std::string& name, const std::string& expression,double value);
void where_str(const std::string& name, const std::string& expression, const std::string& value);
void where_expression(const std::string& expression);
};
#endif
/// <summary>
/// MYSQL UPDATE
/// </summary>
@@ -189,26 +177,6 @@ namespace ylib
order_by m_orderby;
};
#if 0
class Lupdate :public ylib::update {
public:
Lupdate(mysql::conn* conn);
~Lupdate();
void set_i32(const std::string& name, int32 value);
void set_i64(const std::string& name, int64 value);
void set_dob(const std::string& name, double value);
void set_str(const std::string& name, const std::string& value);
void where_i32(const std::string& name, const std::string& expression, int32 value);
void where_i64(const std::string& name, const std::string& expression, int64 value);
void where_dob(const std::string& name, const std::string& expression, double value);
void where_str(const std::string& name, const std::string& expression, const std::string& value);
void where_expression(const std::string& expression);
};
#endif
/// <summary>
/// MYSQL INSERT
/// </summary>
@@ -236,17 +204,6 @@ namespace ylib
std::string m_table_name;
std::vector<keyvalue> m_sets;
};
#if 0
class Linsert :public ylib::insert {
public:
Linsert(mysql::conn* conn);
~Linsert();
void i32(const std::string& name, int32 value);
void i64(const std::string& name, int64 value);
void dob(const std::string& name, double value);
void str(const std::string& name, const std::string& value);
};
#endif
/// <summary>
/// MYSQL DELETE
/// </summary>
@@ -304,16 +261,4 @@ namespace ylib
order_by m_orderby;
};
#if 0
class Ldelete :public ylib::delete_ {
public:
Ldelete(mysql::conn* conn);
~Ldelete();
void where_i32(const std::string& name, const std::string& expression, int32 value);
void where_i64(const std::string& name, const std::string& expression, int64 value);
void where_dob(const std::string& name, const std::string& expression, double value);
void where_str(const std::string& name, const std::string& expression, const std::string& value);
void where_expression(const std::string& expression);
};
#endif
}
}

View File

@@ -36,7 +36,7 @@ namespace ylib
// 请求类型
network::http::method method;
// 回调函数
std::function<void(network::http::request*, network::http::response*)> callback;
std::function<void(network::http::request*, network::http::response*,void *extra)> callback;
// 控制器。为控制器则启动下面两个属性
bool controller;
// 创建控制器类指针
@@ -49,6 +49,8 @@ namespace ylib
// LUA虚拟机初始化回调
std::function<void(sol::state& state)> lua_init_state;
#endif
// 附加数据
void* extra = nullptr;
};
/*************************************************************************
* class路由中专服务
@@ -94,9 +96,10 @@ namespace ylib
* 同一地址不允许订阅两次
******************************************************************/
void subscribe(
const std::string& path,
const std::string& path,
network::http::method method,
std::function<void(network::http::request*, network::http::response*)> callback
std::function<void(network::http::request*, network::http::response*, void*)> callback,
void* extra = nullptr
);
#define SUBSCRIBE(ROUTER,CONTROLLER,FUNCTION,PATH,METHOD) ROUTER->subscribe([]()->void*{return new CONTROLLER;},(ylib::network::http::HTTP_CTR_FUNCTION)&CONTROLLER::FUNCTION,PATH,METHOD)

Binary file not shown.

Binary file not shown.

138
CMakeLists.txt Normal file
View File

@@ -0,0 +1,138 @@
cmake_minimum_required(VERSION 3.5)
project("fastweb")
# 设置自定义配置类型
if(MSVC)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Build config types" FORCE)
endif()
# C++等级
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# 警告等级
# Recursively get all source files
file(GLOB_RECURSE SOURCE_FILES
"${PROJECT_SOURCE_DIR}/src/*.cpp"
)
file(GLOB_RECURSE HEADER_FILES
"${PROJECT_SOURCE_DIR}/src/*.h"
)
foreach(source IN LISTS SOURCE_FILES)
get_filename_component(source_path "${source}" PATH)
file(RELATIVE_PATH source_path_rel "${PROJECT_SOURCE_DIR}" "${source_path}")
string(REPLACE "/" "\\" source_path_rel_win "${source_path_rel}")
source_group(${source_path_rel_win} FILES "${source}")
endforeach()
foreach(header IN LISTS HEADER_FILES)
get_filename_component(header_path "${header}" PATH)
file(RELATIVE_PATH header_path_rel "${PROJECT_SOURCE_DIR}" "${header_path}")
string(REPLACE "/" "\\" header_path_rel_win "${header_path_rel}")
source_group(${header_path_rel_win} FILES "${header}")
endforeach()
include_directories(${PROJECT_SOURCE_DIR}/src)
if(MSVC)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Windows/Include)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/lua)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/soci/include)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/mysql/include/jdbc)
include_directories(${PROJECT_SOURCE_DIR}/3rdparty/ylib/include)
add_compile_options(/W3 /wd4819)
else()
include_directories(${PROJECT_SOURCE_DIR}/3rdparty)
include_directories(/usr/include/lua5.4/)
endif()
# Add the executable or library target
add_executable(${PROJECT_NAME} ${SOURCE_FILES} ${HEADER_FILES})
link_directories(/usr/lib/x86_64-linux-gnu)
link_directories(/usr/local/lib)
if(MSVC)
target_link_libraries(${PROJECT_NAME}
odbc32.lib
User32.lib
Advapi32.lib
IPHLPAPI.lib
WS2_32.lib
Shell32.lib
${PROJECT_SOURCE_DIR}/3rdparty/libcrypto_static.lib
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/mysqlcppconn.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/leveldb.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/libzip.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/lua.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/sqlite3.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/ylib.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Debug/zlib.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/libsoci_core_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/libsoci_empty_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/libsoci_odbc_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/soci_core_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/soci_empty_4_1.lib>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Debug/soci_odbc_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/mysqlcppconn.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/leveldb.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/libzip.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/lua.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/sqlite3.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/ylib.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/ylib/lib/Release/zlib.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/libsoci_core_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/libsoci_empty_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/libsoci_odbc_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/soci_core_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/soci_empty_4_1.lib>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/soci/lib/Release/soci_odbc_4_1.lib>
)
else()
target_link_libraries(${PROJECT_NAME}
hpsocket
ylib
leveldb
soci_core
soci_firebird
soci_mysql
soci_odbc
soci_postgresql
soci_sqlite3
crypto
lua5.4
mysqlcppconn
)
endif()
######################## 安装 ########################
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket_D.dll>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/libcrypto-3-x64.dll>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/libssl-3-x64.dll>
$<$<CONFIG:Debug>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Debug/mysqlcppconn-9-vs14.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/HP-Socket/Lib/HPSocket.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/libcrypto-3-x64.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/libssl-3-x64.dll>
$<$<CONFIG:Release>:${PROJECT_SOURCE_DIR}/3rdparty/mysql/lib/Release/mysqlcppconn-9-vs14.dll>
config.ini
DESTINATION bin)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/scripts DESTINATION bin)

View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,69 +0,0 @@
# Fast Web (快速网站开发框架)
## 简介
Fast Web 是使用 C++ 和 Lua 开发的网站框架以快速开发、部署简单为理念核心部分由C++实现Lua 脚本语言处理业务逻辑,
Fast Web 旨在简化复杂的部署和环境配置,使开发者能够迅速启动并运行他们的网站。
QQ群153076832
## 特性
- **LUA脚本**通过Lua脚本实现业务逻辑开发编写及维护更加容易
- **易于部署**:只需一个可执行文件
- **灵活易用**适合各类个人博客、API接口到复杂的企业级项目
## 示例
URL: http://127.0.0.1:8888/scripts/index.lua?key=123456
#### 拦截器
```lua
function access()
if request:pstring("key") == "123456" then
return true
end
response:send("密钥不正确,已被拦截器拦截.")
return false
end
```
#### 业务代码
```lua
-- 通用入口函数
function access()
-- MYSQL执行SELECT查询map表
local result = mysql:select():table("map"):query()
-- 构建回复数据
local data = result:table()
-- 返回JSON数据
json(data)
end
```
## 部署
目前仅支持Windows部署Linux将在下个版本支持
```bash
# 克隆仓库
git clone https://github.com/Liuccysdgg/fastweb.git
# 进入项目目录
cd fastweb
# 编译项目 (确保你的机器上安装了VS2022集成开发环境)
# 运行 fastweb.sln 编译
```
三方库均仅提供x64二进制发布版本,如需更新或修改请自行根据下方链接下载编译
## 🙇致谢
如果没有社区已有的优秀软件帮助fastweb就不可能构建出来
https://github.com/Liuccysdgg/ylib 跨平台快速开发库
https://github.com/ldcsaa/HP-Socket HPSocket高性能网络库
https://github.com/ThePhD/sol2 C++ 与 Lua 的绑定
https://github.com/lua/lua 脚本解释器

View File

@@ -1,5 +1,5 @@
[variable]
base=D:/project/fastweb
base=${current_dir}
[scripts]
; 应用目录(可执行脚本)
; 考虑安全性,请勿放置于网站静态文件目录

View File

@@ -1,31 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34723.18
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fastweb", "fastweb.vcxproj", "{30FF78DA-6DB2-4600-9DB1-8D581D3B38BA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{30FF78DA-6DB2-4600-9DB1-8D581D3B38BA}.Debug|x64.ActiveCfg = Debug|x64
{30FF78DA-6DB2-4600-9DB1-8D581D3B38BA}.Debug|x64.Build.0 = Debug|x64
{30FF78DA-6DB2-4600-9DB1-8D581D3B38BA}.Debug|x86.ActiveCfg = Debug|Win32
{30FF78DA-6DB2-4600-9DB1-8D581D3B38BA}.Debug|x86.Build.0 = Debug|Win32
{30FF78DA-6DB2-4600-9DB1-8D581D3B38BA}.Release|x64.ActiveCfg = Release|x64
{30FF78DA-6DB2-4600-9DB1-8D581D3B38BA}.Release|x64.Build.0 = Release|x64
{30FF78DA-6DB2-4600-9DB1-8D581D3B38BA}.Release|x86.ActiveCfg = Release|Win32
{30FF78DA-6DB2-4600-9DB1-8D581D3B38BA}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3C07C2E6-C40B-4D78-900B-E25ADE05A28C}
EndGlobalSection
EndGlobal

View File

@@ -1,202 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\core\bytecodemanager.cpp" />
<ClCompile Include="src\core\config.cpp" />
<ClCompile Include="src\core\fastweb.cpp" />
<ClCompile Include="src\core\global.cpp" />
<ClCompile Include="src\core\main.cpp" />
<ClCompile Include="src\core\statemanager.cpp" />
<ClCompile Include="src\module\codec.cpp" />
<ClCompile Include="src\module\globalfuns.cpp" />
<ClCompile Include="src\module\http\httpclient.cpp" />
<ClCompile Include="src\module\http\request.cpp" />
<ClCompile Include="src\module\http\response.cpp" />
<ClCompile Include="src\module\http\session.cpp" />
<ClCompile Include="src\module\localstorage.cpp" />
<ClCompile Include="src\module\mssql.cpp" />
<ClCompile Include="src\module\mutex.cpp" />
<ClCompile Include="src\module\mysql.cpp" />
<ClCompile Include="src\module\time.cpp" />
<ClCompile Include="src\utils\logutils.cpp" />
<ClCompile Include="src\utils\luautils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\core\bytecodemanager.h" />
<ClInclude Include="src\core\config.h" />
<ClInclude Include="src\core\define.h" />
<ClInclude Include="src\core\fastweb.h" />
<ClInclude Include="src\core\global.h" />
<ClInclude Include="src\core\statemanager.h" />
<ClInclude Include="src\core\structs.h" />
<ClInclude Include="src\module\codec.h" />
<ClInclude Include="src\module\globalfuns.h" />
<ClInclude Include="src\module\http\httpclient.h" />
<ClInclude Include="src\module\http\request.h" />
<ClInclude Include="src\module\http\response.h" />
<ClInclude Include="src\module\http\session.h" />
<ClInclude Include="src\module\imodule.h" />
<ClInclude Include="src\module\localstorage.h" />
<ClInclude Include="src\module\mssql.h" />
<ClInclude Include="src\module\mutex.h" />
<ClInclude Include="src\module\mysql.h" />
<ClInclude Include="src\module\time.h" />
<ClInclude Include="src\utils\logutils.h" />
<ClInclude Include="src\utils\luautils.h" />
</ItemGroup>
<ItemGroup>
<None Include=".gitignore" />
<None Include="config.ini" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<Text Include="LICENSE.txt" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{30ff78da-6db2-4600-9db1-8d581d3b38ba}</ProjectGuid>
<RootNamespace>fastweb</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutDir>$(SolutionDir)bin\debug</OutDir>
<IntDir>$(SolutionDir)obj\debug</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>$(SolutionDir)bin\release</OutDir>
<IntDir>$(SolutionDir)obj\release</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)3rdparty\soci\include;$(SolutionDir)src;$(SolutionDir)3rdparty;$(SolutionDir)3rdparty\lua;D:\lib\ylib\include;$(SolutionDir)3rdparty\HP-Socket\include</AdditionalIncludeDirectories>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libsoci_core_4_1.lib;libsoci_empty_4_1.lib;libsoci_odbc_4_1.lib;soci_core_4_1.lib;soci_empty_4_1.lib;soci_odbc_4_1.lib;odbc32.lib;User32.lib;Advapi32.lib;IPHLPAPI.lib;WS2_32.lib;Shell32.lib;leveldb.lib;libzip.lib;lua.lib;sqlite3.lib;D:\lib\ylib_vs_build\lib\Debug\ylib.lib;zlib.lib;mysqlcppconn.lib;HPSocket_D.lib;libcrypto_static.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)3rdparty\ylib\lib\$(Configuration);$(SolutionDir)3rdparty\mysql\lib\$(Configuration);$(SolutionDir)3rdparty\HP-Socket\lib;$(SolutionDir)3rdparty;$(SolutionDir)3rdparty\soci\lib\$(Configuration)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)3rdparty\soci\include;$(SolutionDir)src;$(SolutionDir)3rdparty;$(SolutionDir)3rdparty\lua;D:\lib\ylib\include;$(SolutionDir)3rdparty\HP-Socket\include</AdditionalIncludeDirectories>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libsoci_core_4_1.lib;libsoci_empty_4_1.lib;libsoci_odbc_4_1.lib;soci_core_4_1.lib;soci_empty_4_1.lib;soci_odbc_4_1.lib;odbc32.lib;User32.lib;Advapi32.lib;IPHLPAPI.lib;WS2_32.lib;Shell32.lib;leveldb.lib;libzip.lib;lua.lib;sqlite3.lib;ylib.lib;zlib.lib;mysqlcppconn.lib;HPSocket.lib;libcrypto_static.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)3rdparty\ylib\lib\$(Configuration);$(SolutionDir)3rdparty\mysql\lib\$(Configuration);$(SolutionDir)3rdparty\HP-Socket\lib;$(SolutionDir)3rdparty;$(SolutionDir)3rdparty\soci\lib\$(Configuration)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -1,152 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="src">
<UniqueIdentifier>{edadfc2f-873d-4876-be12-0f0a346c671a}</UniqueIdentifier>
</Filter>
<Filter Include="src\core">
<UniqueIdentifier>{a7a813c2-1819-4d9e-97b1-553df4fc20f3}</UniqueIdentifier>
</Filter>
<Filter Include="src\module">
<UniqueIdentifier>{feb78a4c-cec1-4b7c-850b-6d1451e57962}</UniqueIdentifier>
</Filter>
<Filter Include="src\utils">
<UniqueIdentifier>{2b04f1f8-4027-4d87-a828-f18f2b918b8f}</UniqueIdentifier>
</Filter>
<Filter Include="src\module\http">
<UniqueIdentifier>{a6112717-e5e3-426e-9132-03cd4315deb0}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\core\main.cpp">
<Filter>src\core</Filter>
</ClCompile>
<ClCompile Include="src\core\fastweb.cpp">
<Filter>src\core</Filter>
</ClCompile>
<ClCompile Include="src\core\statemanager.cpp">
<Filter>src\core</Filter>
</ClCompile>
<ClCompile Include="src\core\config.cpp">
<Filter>src\core</Filter>
</ClCompile>
<ClCompile Include="src\utils\logutils.cpp">
<Filter>src\utils</Filter>
</ClCompile>
<ClCompile Include="src\module\mysql.cpp">
<Filter>src\module</Filter>
</ClCompile>
<ClCompile Include="src\module\http\session.cpp">
<Filter>src\module\http</Filter>
</ClCompile>
<ClCompile Include="src\module\http\request.cpp">
<Filter>src\module\http</Filter>
</ClCompile>
<ClCompile Include="src\module\http\response.cpp">
<Filter>src\module\http</Filter>
</ClCompile>
<ClCompile Include="src\core\bytecodemanager.cpp">
<Filter>src\core</Filter>
</ClCompile>
<ClCompile Include="src\utils\luautils.cpp">
<Filter>src\utils</Filter>
</ClCompile>
<ClCompile Include="src\core\global.cpp">
<Filter>src\core</Filter>
</ClCompile>
<ClCompile Include="src\module\localstorage.cpp">
<Filter>src\module</Filter>
</ClCompile>
<ClCompile Include="src\module\globalfuns.cpp">
<Filter>src\module</Filter>
</ClCompile>
<ClCompile Include="src\module\mutex.cpp">
<Filter>src\module</Filter>
</ClCompile>
<ClCompile Include="src\module\codec.cpp">
<Filter>src\module</Filter>
</ClCompile>
<ClCompile Include="src\module\mssql.cpp">
<Filter>src\module</Filter>
</ClCompile>
<ClCompile Include="src\module\time.cpp">
<Filter>src\module</Filter>
</ClCompile>
<ClCompile Include="src\module\http\httpclient.cpp">
<Filter>src\module\http</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\core\fastweb.h">
<Filter>src\core</Filter>
</ClInclude>
<ClInclude Include="src\core\statemanager.h">
<Filter>src\core</Filter>
</ClInclude>
<ClInclude Include="src\core\structs.h">
<Filter>src\core</Filter>
</ClInclude>
<ClInclude Include="src\core\define.h">
<Filter>src\core</Filter>
</ClInclude>
<ClInclude Include="src\core\config.h">
<Filter>src\core</Filter>
</ClInclude>
<ClInclude Include="src\utils\logutils.h">
<Filter>src\utils</Filter>
</ClInclude>
<ClInclude Include="src\module\mysql.h">
<Filter>src\module</Filter>
</ClInclude>
<ClInclude Include="src\module\http\session.h">
<Filter>src\module\http</Filter>
</ClInclude>
<ClInclude Include="src\module\http\request.h">
<Filter>src\module\http</Filter>
</ClInclude>
<ClInclude Include="src\module\http\response.h">
<Filter>src\module\http</Filter>
</ClInclude>
<ClInclude Include="src\core\bytecodemanager.h">
<Filter>src\core</Filter>
</ClInclude>
<ClInclude Include="src\utils\luautils.h">
<Filter>src\utils</Filter>
</ClInclude>
<ClInclude Include="src\core\global.h">
<Filter>src\core</Filter>
</ClInclude>
<ClInclude Include="src\module\imodule.h">
<Filter>src\module</Filter>
</ClInclude>
<ClInclude Include="src\module\localstorage.h">
<Filter>src\module</Filter>
</ClInclude>
<ClInclude Include="src\module\globalfuns.h">
<Filter>src\module</Filter>
</ClInclude>
<ClInclude Include="src\module\mutex.h">
<Filter>src\module</Filter>
</ClInclude>
<ClInclude Include="src\module\codec.h">
<Filter>src\module</Filter>
</ClInclude>
<ClInclude Include="src\module\mssql.h">
<Filter>src\module</Filter>
</ClInclude>
<ClInclude Include="src\module\time.h">
<Filter>src\module</Filter>
</ClInclude>
<ClInclude Include="src\module\http\httpclient.h">
<Filter>src\module\http</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="config.ini" />
<None Include="README.md" />
<None Include=".gitignore" />
</ItemGroup>
<ItemGroup>
<Text Include="LICENSE.txt" />
</ItemGroup>
</Project>

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@@ -1,10 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FastWeb快速开发框架</title>
</head>
<body>
<h1>FastWeb快速开发框架</h1>
</body>
</html>

View File

@@ -1,17 +1,10 @@
require "website"
-- 通用入口函数
route = {"/",GET}
function access()
-- MYSQL执行SELECT查询map表
--local result = mysql:select():table("map"):query()
-- 构建回复数据
--local data = result:table()
local data = {
name = "Fast Web 快速网站开发框架"
}
-- 返回JSON数据
json(data)
reply(200,"OK",data)
end

View File

@@ -1,19 +1,6 @@
require "website"
-- MYSQL数据库池
function initMysql()
local pool = mysql_pool.new()
if pool:start("127.0.0.1","test","123456","test","utf8mb4",3306,10) == false then
print("start mysql pool failed")
return false
end
global_regist("mysql",pool:self())
return true
end
print("init fast web success!")
if initMysql() == false then
return false
end
return true

View File

@@ -1,9 +1,7 @@
function access()
if request:pstring("key") == "123456" then
return true
require "website"
function access()
if param("key") == nil or param("key") ~= "123465" then
print("is not found key")
end
response:send("密钥不正确,已被拦截器拦截.")
return false
return true
end

View File

@@ -1,8 +1,23 @@
local dkjson = require 'dkjson'
function json(data)
response:header("Content-Type","application/json")
response:send(dkjson.encode(data))
end
function session()
return request:session(request:token())
end
function param(name)
return request:param(name,false)
end
function param_throw(name)
return request:param(name,true)
end
function reply(code,msg,data)
local data ={
code =code,
msg = msg,
data = data
}
json(data)
end

View File

@@ -14,6 +14,8 @@ bool config::open(const std::string& ini_filepath)
return false;
}
std::string src_content = ylib::file::read(temp_filepath);
src_content = strutils::replace(src_content, "${current_dir}", strutils::replace(system::current_dir(),'\\','/'));
ylib::file::write(temp_filepath,src_content);
if (m_ini.open(temp_filepath))
{
auto vars = extractVariableNames(ylib::file::read(temp_filepath));

View File

@@ -75,7 +75,66 @@ bool fastweb::start()
{
auto map = service_bytecode.map();
for_iter(iter, map)
router->subscribe(sConfig->scripts.app_mapping_dir + iter->first, ALL, &fastweb::subscribe_service);
{
auto state = sStateMgr->get_state();
std::string route_pattern;
network::http::method method = network::http::ALL;
try
{
auto result = state->script_file(iter->second->filepath);
if (result.valid()) {
auto router = (*state)["route"];
auto type = router.get_type();
if (router.is<sol::table>())
{
sol::optional<std::string> route_pattern_param = router[1];
sol::optional<int> method_param = router[2];
if (route_pattern_param && route_pattern_param->empty() == false)
route_pattern = *route_pattern_param;
if (method_param)
method = (network::http::method)*method_param;
}
}
}
catch (const std::exception& e)
{
LOG_ERROR(e.what());
}
if (route_pattern.empty())
route_pattern = sConfig->scripts.app_mapping_dir + iter->first;
// OutPutLog
{
std::string log;
log = "[subscribe] lua: " + iter->first + "\t pattern: " + route_pattern + "\t method: ";
switch (method)
{
case ylib::network::http::GET:
log.append("GET");
break;
case ylib::network::http::POST:
log.append("POST");
break;
case ylib::network::http::PUT:
log.append("PUT");
break;
case ylib::network::http::DEL:
log.append("DEL");
break;
case ylib::network::http::HEAD:
log.append("HEAD");
break;
case ylib::network::http::ALL:
log.append("ALL");
break;
default:
break;
}
LOG_INFO(log);
}
router->subscribe(route_pattern, method, &fastweb::subscribe_service,new std::string(iter->first));
}
}
// 加入拦截器
@@ -132,11 +191,7 @@ bool fastweb::initialization_script()
try
{
state->set_function("global_regist", module::global_regist);
auto result = state->script_file(script_filepath);
if (!result.valid()) {
sol::error err = result;
throw ylib::exception(err.what());
@@ -155,10 +210,12 @@ bool fastweb::initialization_script()
return m_lastErrorDesc == "";
}
void fastweb::subscribe_service(network::http::request* request, network::http::response* response)
void fastweb::subscribe_service(network::http::request* request, network::http::response* response,void *extra)
{
std::string lua_name = *(std::string*)extra;
// 文件原路径(非绝对路径)
std::string lua_name = strutils::right(request->filepath(), request->filepath().length() - sConfig->scripts.app_mapping_dir.length());
//std::string lua_name = strutils::right(request->filepath(), request->filepath().length() - sConfig->scripts.app_mapping_dir.length());
auto lua = sStateMgr->get_state();

View File

@@ -34,7 +34,7 @@ private:
/// </summary>
/// <param name="request"></param>
/// <param name="response"></param>
static void subscribe_service(network::http::request* request, network::http::response* response);
static void subscribe_service(network::http::request* request, network::http::response* response, void* extra);
/// <summary>
/// 拦截器回调
/// </summary>

View File

@@ -9,7 +9,7 @@ int main()
std::cout << "=========== [fastweb engine] ============" << std::endl;
if(sConfig->open(system::current_dir() + "\\config.ini") == false)
if(sConfig->open(system::current_dir() + "/config.ini") == false)
{
LOG_ERROR("open config failed,"+sConfig->last_error());
return -1;
@@ -25,4 +25,4 @@ int main()
while (true)
std::cin.get();
return 0;
}
}

View File

@@ -13,7 +13,9 @@
#include "module/http/session.h"
#include "module/http/httpclient.h"
#include "module/mysql.h"
#ifdef _WIN32
#include "module/mssql.h"
#endif
#include "module/localstorage.h"
#include "module/globalfuns.h"
#include "module/mutex.h"
@@ -70,7 +72,9 @@ sol::state* state_manager::create_state()
module::session::regist(*lua);
module::httpclient::regist(*lua);
module::mysql_regist(*lua);
#ifdef _WIN32
module::mssql::regist(*lua);
#endif
module::regist_globalfuns(*lua);
module::local_storage::regist(lua);
module::mutex::regist(lua);

View File

@@ -10,12 +10,12 @@ std::string module::codec::url_en(const std::string& value)
return ylib::codec::url::en(value);
}
std::string module::codec::gbk_to_utf8(const std::string& value)
std::string module::codec::to_utf8(const std::string& value)
{
return ylib::codec::to_utf8(value);
}
std::string module::codec::utf8_to_gbk(const std::string& value)
std::string module::codec::to_gbk(const std::string& value)
{
return ylib::codec::to_gbk(value);
}
@@ -30,8 +30,8 @@ void module::codec::regist(sol::state* lua)
lua->new_usertype<module::codec>("codec",
"url_de", &module::codec::url_de,
"url_en", &module::codec::url_en,
"gbk_to_utf8", &module::codec::gbk_to_utf8,
"utf8_to_gbk", &module::codec::utf8_to_gbk,
"to_utf8", &module::codec::to_utf8,
"to_gbk", &module::codec::to_gbk,
"md5", &module::codec::md5
);
}

View File

@@ -21,8 +21,8 @@ namespace module
/// GBK转UTF8
/// </summary>
/// <returns></returns>
static std::string gbk_to_utf8(const std::string& value);
static std::string utf8_to_gbk(const std::string& value);
static std::string to_utf8(const std::string& value);
static std::string to_gbk(const std::string& value);
/// <summary>
/// MD5校验
/// </summary>

View File

@@ -57,6 +57,11 @@ void module::request::regist(sol::state& state)
"body_param", &module::request::body_param,
"url_param", &module::request::url_param
);
state["GET"] = (int)network::http::GET;
state["POST"] = (int)network::http::POST;
state["DEL"] = (int)network::http::DEL;
state["HEAD"] = (int)network::http::HEAD;
state["PUT"] = (int)network::http::PUT;
}

View File

@@ -1,4 +1,5 @@
#include "mssql.h"
#ifdef _WIN32
#include "mssql.h"
#include "soci/odbc/soci-odbc.h"
module::mssql::mssql(const std::string& connstring)
{
@@ -42,9 +43,10 @@ void module::mssql::query(const std::string& sql)
m_rows = (m_session->prepare << sql);
//m_iter = m_rows.begin();
}
uint64 module::mssql::update(const std::string& sql)
int64 module::mssql::update(const std::string& sql)
{
soci::statement st = (m_session->prepare << sql);
soci::statement st = m_session->prepare << sql;
st.execute();
return st.get_affected_rows();
}
bool module::mssql::next()
@@ -74,3 +76,4 @@ void module::mssql::regist(sol::state& lua)
"update", &module::mssql::update
);
}
#endif

View File

@@ -1,4 +1,5 @@
#pragma once
#ifdef _WIN32
#include "sol/sol.hpp"
#include "imodule.h"
#include "soci/soci.h"
@@ -35,7 +36,7 @@ namespace module
bool next();
uint64 update(const std::string& sql);
int64 update(const std::string& sql);
/// <summary>
/// 注册
/// </summary>
@@ -52,3 +53,4 @@ namespace module
}
#endif

View File

@@ -9,10 +9,16 @@ uint64 module::time::now_sec()
return ylib::time::now_sec();
}
std::string module::time::now_time(const std::string& format)
{
return ylib::time::now_time(format);
}
void module::time::regist(sol::state* lua)
{
lua->new_usertype<module::time>("time",
"now_msec", &module::time::now_msec,
"now_sec", &module::time::now_sec
"now_sec", &module::time::now_sec,
"now_time", &module::time::now_time
);
}

View File

@@ -9,12 +9,9 @@ namespace module
/// </summary>
class time:public module::imodule {
public:
/// <summary>
/// URL解码
/// </summary>
static uint64 now_msec();
static uint64 now_sec();
static std::string now_time(const std::string& format);
static void regist(sol::state* lua);
};

View File

@@ -3,7 +3,9 @@
#include "util/time.h"
#include "util/codec.h"
#include "util/file.h"
#ifdef _WIN32
#include <Windows.h>
#endif
#define DEBUG_INFO 0
void print(const std::string& type,const std::string& msg,const std::string& filepath, const std::string& func, int line,int color) {
@@ -23,7 +25,11 @@ void print(const std::string& type,const std::string& msg,const std::string& fil
}
void LogUtils::success(const std::string& msg, const std::string& filepath, const std::string& func, int line)
{
::print("[SUCC ] ", msg, filepath, func, line, ylib::ConsoleTextColor::GREEN | FOREGROUND_INTENSITY);
::print("[SUCC ] ", msg, filepath, func, line, ylib::ConsoleTextColor::GREEN
#ifdef _WIN32
|FOREGROUND_INTENSITY
#endif
);
}
void LogUtils::info(const std::string& msg, const std::string& filepath, const std::string& func, int line)
@@ -35,7 +41,11 @@ void LogUtils::info(const std::string& msg, const std::string& filepath, const s
void LogUtils::error(const std::string& msg, const std::string& filepath, const std::string& func, int line)
{
//#ifdef _DEBUG
::print("[ERROR] ", msg, filepath, func, line, ylib::ConsoleTextColor::RED | FOREGROUND_INTENSITY);
::print("[ERROR] ", msg, filepath, func, line, ylib::ConsoleTextColor::RED
#ifdef _WIN32
| FOREGROUND_INTENSITY
#endif
);
//#else
//#endif
@@ -43,10 +53,18 @@ void LogUtils::error(const std::string& msg, const std::string& filepath, const
void LogUtils::warn(const std::string& msg, const std::string& filepath, const std::string& func, int line)
{
::print("[WARN ] ", msg, filepath, func, line, ylib::ConsoleTextColor::YELLOW | FOREGROUND_INTENSITY);
::print("[WARN ] ", msg, filepath, func, line, ylib::ConsoleTextColor::YELLOW
#ifdef _WIN32
| FOREGROUND_INTENSITY
#endif
);
}
void LogUtils::debug(const std::string& msg, const std::string& filepath, const std::string& func,int line)
{
::print("[DEBUG] ", msg, filepath, func, line, ylib::ConsoleTextColor::BLUE | FOREGROUND_INTENSITY);
::print("[DEBUG] ", msg, filepath, func, line, ylib::ConsoleTextColor::BLUE
#ifdef _WIN32
| FOREGROUND_INTENSITY
#endif
);
}