add mail builder class and sample; optimize http module; add some json samples for test

This commit is contained in:
ubuntu14 2015-09-27 05:59:21 -07:00
parent a631725ba5
commit b319c8742a
137 changed files with 4596 additions and 471 deletions

View File

@ -575,6 +575,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mail_build", "lib_acl_cpp\s
{FE724EF7-3763-4E78-BDF5-BCBC075719FD} = {FE724EF7-3763-4E78-BDF5-BCBC075719FD}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "http_servlet2", "lib_acl_cpp\samples\http_servlet2\http_servlet2_vc2012.vcxproj", "{685428CA-8DD4-489F-AC7F-0F5B70191D0F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
@ -2784,6 +2786,31 @@ Global
{DBC43D27-7731-409D-A931-26D141A5FC6B}.Template|Win32.Build.0 = DebugDll|Win32
{DBC43D27-7731-409D-A931-26D141A5FC6B}.Template|x64.ActiveCfg = DebugDll|x64
{DBC43D27-7731-409D-A931-26D141A5FC6B}.Template|x64.Build.0 = DebugDll|x64
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Debug|Win32.ActiveCfg = Debug|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Debug|Win32.Build.0 = Debug|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Debug|x64.ActiveCfg = Debug|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.DebugDll|Mixed Platforms.ActiveCfg = DebugDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.DebugDll|Mixed Platforms.Build.0 = DebugDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.DebugDll|Win32.ActiveCfg = DebugDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.DebugDll|Win32.Build.0 = DebugDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.DebugDll|x64.ActiveCfg = DebugDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Release|Mixed Platforms.Build.0 = Release|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Release|Win32.ActiveCfg = Release|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Release|Win32.Build.0 = Release|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Release|x64.ActiveCfg = Release|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Releasedll|Mixed Platforms.ActiveCfg = ReleaseDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Releasedll|Mixed Platforms.Build.0 = ReleaseDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Releasedll|Win32.ActiveCfg = ReleaseDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Releasedll|Win32.Build.0 = ReleaseDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Releasedll|x64.ActiveCfg = ReleaseDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Template|Mixed Platforms.ActiveCfg = DebugDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Template|Mixed Platforms.Build.0 = DebugDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Template|Win32.ActiveCfg = DebugDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Template|Win32.Build.0 = DebugDll|Win32
{685428CA-8DD4-489F-AC7F-0F5B70191D0F}.Template|x64.ActiveCfg = DebugDll|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -2828,6 +2855,7 @@ Global
{467619C7-C100-47B9-9A3B-7246A542EDC9} = {F1ABE59F-D95A-4CD5-92A2-6A1622E63BAB}
{A28B19ED-291C-47C8-BDD5-10BB038C371E} = {F1ABE59F-D95A-4CD5-92A2-6A1622E63BAB}
{2C2212C1-01D2-4C8E-AB15-F7E31C7C134B} = {F1ABE59F-D95A-4CD5-92A2-6A1622E63BAB}
{685428CA-8DD4-489F-AC7F-0F5B70191D0F} = {F1ABE59F-D95A-4CD5-92A2-6A1622E63BAB}
{19CB30E5-2672-4A8B-96FB-9C42970CCF69} = {B1A07893-DA8C-43D8-A2F1-0940837C482F}
{5DC79C83-9DE8-46B3-A172-8A4E3371878B} = {B1A07893-DA8C-43D8-A2F1-0940837C482F}
{503AFD46-DF2F-4D2B-8584-60AD2007D2BE} = {B1A07893-DA8C-43D8-A2F1-0940837C482F}

View File

@ -99,4 +99,5 @@ RM:
clean:
rm -f $(PROG)
rm -f $(OBJ)
rebuild rb: clean all
###########################################################

View File

@ -1,7 +1,8 @@
#include "stdafx.h"
#include "http_servlet.h"
http_servlet::http_servlet(void)
http_servlet::http_servlet(acl::socket_stream* stream, acl::session* session)
: acl::HttpServlet(stream, session)
{
}
@ -11,7 +12,7 @@ http_servlet::~http_servlet(void)
}
bool http_servlet::doUnknown(acl::HttpServletRequest&,
bool http_servlet::doError(acl::HttpServletRequest&,
acl::HttpServletResponse& res)
{
res.setStatus(400);
@ -19,8 +20,25 @@ bool http_servlet::doUnknown(acl::HttpServletRequest&,
// 发送 http 响应头
if (res.sendHeader() == false)
return false;
// 发送 http 响应体
acl::string buf("<root error='unkown request method' />\r\n");
acl::string buf;
buf.format("<root error='some error happened!' />\r\n");
(void) res.getOutputStream().write(buf);
return false;
}
bool http_servlet::doOther(acl::HttpServletRequest&,
acl::HttpServletResponse& res, const char* method)
{
res.setStatus(400);
res.setContentType("text/html; charset=$<CHARSET>");
// ·¢ËÍ http ÏìӦͷ
if (res.sendHeader() == false)
return false;
// ·¢ËÍ http ÏìÓ¦Ìå
acl::string buf;
buf.format("<root error='unkown request method %s' />\r\n", method);
(void) res.getOutputStream().write(buf);
return false;
}

View File

@ -3,12 +3,14 @@
class http_servlet : public acl::HttpServlet
{
public:
http_servlet();
http_servlet(acl::socket_stream* stream, acl::session* session);
~http_servlet();
protected:
virtual bool doUnknown(acl::HttpServletRequest&,
virtual bool doError(acl::HttpServletRequest&,
acl::HttpServletResponse& res);
virtual bool doOther(acl::HttpServletRequest&,
acl::HttpServletResponse& res, const char* method);
virtual bool doGet(acl::HttpServletRequest& req,
acl::HttpServletResponse& res);
virtual bool doPost(acl::HttpServletRequest& req,

View File

@ -51,13 +51,13 @@ void master_service::on_accept(acl::socket_stream* conn)
conn->set_rw_timeout(10);
acl::memcache_session session("127.0.0.1:11211");
http_servlet servlet;
http_servlet servlet(conn, &session);
// charset: big5, gb2312, gb18030, gbk, utf-8
servlet.setLocalCharset("utf-8");
while (true)
{
if (servlet.doRun(session, conn) == false)
if (servlet.doRun() == false)
break;
}
@ -74,7 +74,8 @@ void master_service::proc_on_exit()
void master_service::do_cgi()
{
http_servlet servlet;
acl::memcache_session session("127.0.0.1:11211");
http_servlet servlet(NULL, &session);
servlet.setLocalCharset("utf-8");
servlet.doRun("127.0.0.1:11211", NULL);
servlet.doRun();
}

View File

@ -40,8 +40,7 @@ acl::master_int64_tbl var_conf_int64_tab[] = {
master_service::master_service()
{
session_ = NULL;
cluster_ = NULL;
redis_ = NULL;
}
master_service::~master_service()
@ -54,10 +53,7 @@ bool master_service::thread_on_read(acl::socket_stream* conn)
if (servlet == NULL)
logger_fatal("servlet null!");
if (var_cfg_use_redis_session)
return servlet->doRun(*session_, conn);
else
return servlet->doRun("127.0.0.1:11211", conn);
return servlet->doRun();
}
bool master_service::thread_on_accept(acl::socket_stream* conn)
@ -66,7 +62,13 @@ bool master_service::thread_on_accept(acl::socket_stream* conn)
conn->sock_handle());
conn->set_rw_timeout(var_cfg_rw_timeout);
http_servlet* servlet = new http_servlet();
acl::session* session;
if (var_cfg_use_redis_session)
session = new acl::redis_session(*redis_, var_cfg_max_threads);
else
session = new acl::memcache_session("127.0.0.1:11211");
http_servlet* servlet = new http_servlet(conn, session);
conn->set_ctx(servlet);
return true;
@ -85,8 +87,9 @@ void master_service::thread_on_close(acl::socket_stream* conn)
conn->sock_handle());
http_servlet* servlet = (http_servlet*) conn->get_ctx();
if (servlet)
delete servlet;
acl::session* session = &servlet->getSession();
delete session;
delete servlet;
}
void master_service::thread_on_init()
@ -100,18 +103,14 @@ void master_service::thread_on_exit()
void master_service::proc_on_init()
{
// create redis cluster for session cluster
cluster_ = new acl::redis_client_cluster(var_cfg_conn_timeout,
redis_ = new acl::redis_client_cluster(var_cfg_conn_timeout,
var_cfg_rw_timeout);
cluster_->init(NULL, var_cfg_redis_addrs, var_cfg_max_threads);
// create session cluster
session_ = new acl::redis_session(*cluster_, var_cfg_max_threads);
redis_->init(NULL, var_cfg_redis_addrs, var_cfg_max_threads);
}
void master_service::proc_on_exit()
{
delete session_;
delete cluster_;
delete redis_;
}
bool master_service::proc_exit_timer(size_t nclients, size_t nthreads)

View File

@ -95,7 +95,5 @@ protected:
private:
// redis 集群对象
acl::redis_client_cluster* cluster_;
// 管理 session 的集群对象
acl::session* session_;
acl::redis_client_cluster* redis_;
};

View File

@ -1,7 +1,9 @@
#include "stdafx.h"
#include "http_servlet.h"
http_servlet::http_servlet(const char* filepath)
http_servlet::http_servlet(const char* filepath, acl::socket_stream* conn,
acl::session* session)
: acl::HttpServlet(conn, session)
{
if (filepath && *filepath)
filepath_ = filepath;

View File

@ -3,7 +3,8 @@
class http_servlet : public acl::HttpServlet
{
public:
http_servlet(const char* filepath);
http_servlet(const char* filepath, acl::socket_stream* conn,
acl::session* session);
~http_servlet();
protected:

View File

@ -49,7 +49,7 @@ bool master_service::thread_on_read(acl::socket_stream* conn)
if (servlet == NULL)
logger_fatal("servlet null!");
return servlet->doRun("127.0.0.1:11211", conn);
return servlet->doRun();
}
bool master_service::thread_on_accept(acl::socket_stream* conn)
@ -58,7 +58,9 @@ bool master_service::thread_on_accept(acl::socket_stream* conn)
conn->sock_handle());
conn->set_rw_timeout(5);
http_servlet* servlet = new http_servlet(var_cfg_filepath);
acl::session* session = new acl::memcache_session("127.0.0.1");
http_servlet* servlet = new http_servlet(var_cfg_filepath,
conn, session);
conn->set_ctx(servlet);
return true;
@ -77,8 +79,9 @@ void master_service::thread_on_close(acl::socket_stream* conn)
conn->sock_handle());
http_servlet* servlet = (http_servlet*) conn->get_ctx();
if (servlet)
delete servlet;
acl::session* session = &servlet->getSession();
delete session;
delete servlet;
}
void master_service::thread_on_init()

Binary file not shown.

BIN
doc/redis_cluster.vsd Normal file

Binary file not shown.

View File

@ -31,7 +31,7 @@
#include <string.h>
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(MINGW)
#include <basetsd.h>
typedef UINT32 uint32_t;
#else

View File

@ -32,7 +32,7 @@
#include "config.h"
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(MINGW)
#include <basetsd.h>
#if (_MSC_VER <= 1200)
typedef signed short int16_t;

View File

@ -31,7 +31,7 @@
#include <string.h>
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(MINGW)
#include <basetsd.h>
typedef UINT32 uint32_t;
#else

View File

@ -31,7 +31,7 @@
#include <string.h>
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(MINGW)
#include <basetsd.h>
typedef UINT32 uint32_t;
#else

View File

@ -31,7 +31,7 @@
#include <string.h>
#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(MINGW)
#include <basetsd.h>
typedef UINT32 uint32_t;
#else

View File

@ -31,7 +31,7 @@
#include <string.h>
#if defined(_MSC_VER) || defined(__WATCOMC__)
#if defined(_MSC_VER) || defined(__WATCOMC__) || defined(MINGW)
#define UL64(x) x##ui64
typedef unsigned __int64 uint64_t;
#else

View File

@ -1,6 +1,14 @@
修改历史列表:
------------------------------------------------------------------------
497) 2015.9.23
497.1) feature: json 解析器支持最外层为数组类型同时完全支持bool, number, null 类型的数据
496) 2015.9.22
496.1) feature: json 解析器增加支持判断是否解析完毕的功能
------------------------------------------------------------------------
495) 2015.8.13
495.1) feature: acl_msg.c 文件中,即可以将日志信息记入文件中,同时又可以输出
至屏幕

View File

@ -23,17 +23,20 @@ struct ACL_JSON_NODE {
#define ACL_JSON_T_A_STRING (1 << 0)
#define ACL_JSON_T_A_NUMBER (1 << 1)
#define ACL_JSON_T_A_BOOL (1 << 2)
#define ACL_JSON_T_NUMBER (1 << 3)
#define ACL_JSON_T_OBJ (1 << 4)
#define ACL_JSON_T_ARRAY (1 << 5)
#define ACL_JSON_T_A_NULL (1 << 3)
#define ACL_JSON_T_STRING (1 << 4)
#define ACL_JSON_T_NUMBER (1 << 5)
#define ACL_JSON_T_BOOL (1 << 6)
#define ACL_JSON_T_NULL (1 << 7)
#define ACL_JSON_T_TEXT (1 << 8)
#define ACL_JSON_T_ARRAY (1 << 8)
#define ACL_JSON_T_OBJ (1 << 9)
#define ACL_JSON_T_TEXT (1 << 10)
#define ACL_JSON_T_LEAF ACL_JSON_T_TEXT
#define ACL_JSON_T_MEMBER (1 << 9)
#define ACL_JSON_T_PAIR (1 << 10)
#define ACL_JSON_T_ELEMENT (1 << 11)
#define ACL_JSON_T_MEMBER (1 << 11)
#define ACL_JSON_T_PAIR (1 << 12)
#define ACL_JSON_T_ELEMENT (1 << 13)
ACL_JSON_NODE *parent; /**< 父结点 */
ACL_RING children; /**< 子结点集合 */
@ -211,9 +214,18 @@ ACL_API void acl_json_reset(ACL_JSON *json);
* json , json
* @param json {ACL_JSON*} json
* @param data {const char*} '\0' , json ;
* json , ,
* json , , ;
* NULL NULL
* @return {const char*}
*/
ACL_API void acl_json_update(ACL_JSON *json, const char *data);
ACL_API const char* acl_json_update(ACL_JSON *json, const char *data);
/**
* JSON
* @param json {ACL_JSON*} json
* @return {int} 0
*/
ACL_API int acl_json_finish(ACL_JSON *json);
/*------------------------- in acl_json_util.c ----------------------------*/

View File

@ -0,0 +1,3 @@
base_path = ../../..
include ../../Makefile_cpp.in
PROG = json

View File

@ -0,0 +1,230 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="json"
ProjectGUID="{8021ECD9-04CB-463B-B287-1FB0F5486D91}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="DebugDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;ACL_DLL"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="ReleaseDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;ACL_DLL"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Ô´Îļþ"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\main.cpp">
</File>
</Filter>
<Filter
Name="Í·Îļþ"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
</Filter>
<Filter
Name="×ÊÔ´Îļþ"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="DebugDll|Win32">
<Configuration>DebugDll</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="ReleaseDll|Win32">
<Configuration>ReleaseDll</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{8021ECD9-04CB-463B-B287-1FB0F5486D91}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">true</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">false</LinkIncremental>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\lib_acl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(OutDir)json.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)json.pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\..\..\..\lib_acl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(OutDir)json.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\..\..\lib_acl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;ACL_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(OutDir)json.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)json.pdb</ProgramDatabaseFile>
<SubSystem>Console</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>..\..\..\..\lib_acl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;ACL_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Link>
<OutputFile>$(OutDir)json.exe</OutputFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\lib_acl\lib_acl_vc2010.vcxproj">
<Project>{b40213c2-507c-4c7f-a6e1-b850c9bdc27b}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,56 @@
#include "lib_acl.h"
#define STR acl_vstring_str
static const char* default_data = \
"{ 'menu name': {\r\n"
" 'id:file': 'file',\r\n"
" 'value{': 'File',\r\n"
" 'popup{}': {\r\n"
" 'menuitem1}': [\r\n"
" {'value': 'New', 'onclick': 'CreateNewDoc()'},\r\n"
" {'value': 'Open', 'onclick': 'OpenDoc()'},\r\n"
" {'value': 'Close', 'onclick': 'CloseDoc()'}\r\n"
" ],\r\n"
" 'menuname[]': 'hello world',\r\n"
" 'inner': { 'value' : 'new ', 'value' : 'open' },\r\n"
" 'menuitem2': [\r\n"
" {'value': 'New', 'onclick': 'CreateNewDoc()'},\r\n"
" {'value': 'Open', 'onclick': 'OpenDoc()'},\r\n"
" {'value': 'Close', 'onclick': 'CloseDoc()'},\r\n"
" {{'value': 'Help', 'onclick': 'Help()'}}"
" ]\r\n"
" }\r\n"
" }\r\n,"
" 'help': 'hello world!',\r\n"
" 'menuitem2': [\r\n"
" {'value': 'New', 'onclick': 'CreateNewDoc()'},\r\n"
" {'value': 'Open', 'onclick': 'OpenDoc()'},\r\n"
" {'value': 'Close', 'onclick': 'CloseDoc()'},\r\n"
" [{'value': 'Save', 'onclick': 'SaveDoc()'}]"
" ]\r\n"
"}\r\n"
"{ 'hello world' }\r\n";
static void test_json(void)
{
ACL_JSON *json = acl_json_alloc();
const char* ptr = default_data;
ptr = acl_json_update(json, ptr);
printf("finish: %s, left char: %s\r\n",
acl_json_finish(json) ? "yes" : "no", ptr);
acl_json_free(json);
}
int main(void)
{
test_json();
#ifdef WIN32
getchar();
#endif
return (0);
}

View File

@ -0,0 +1,3 @@
#!/bin/sh
valgrind --tool=memcheck --leak-check=yes -v ./json

View File

@ -213,7 +213,7 @@ static ACL_JSON_NODE *json_iter_next(ACL_ITER *it, ACL_JSON *json)
node = (struct ACL_JSON_NODE*) it->data;
/* 先遍历当前结点的子结点 */
/* 先遍历当前节点的子节点 */
ring_ptr = acl_ring_succ(&node->children);
if (ring_ptr != &node->children) {
@ -223,7 +223,7 @@ static ACL_JSON_NODE *json_iter_next(ACL_ITER *it, ACL_JSON *json)
return (it->ptr);
}
/* 当前结点的子结点遍历完毕,再遍历当前结点的兄弟结点 */
/* 当前节点的子节点遍历完毕,再遍历当前节点的兄弟节点 */
parent = acl_json_node_parent(node);
ring_ptr = acl_ring_succ(&node->node);
@ -234,7 +234,7 @@ static ACL_JSON_NODE *json_iter_next(ACL_ITER *it, ACL_JSON *json)
return (it->ptr);
}
/* 当前结点的兄弟结点遍历完毕,最后遍历当前结点的父结点的兄弟结点 */
/* 当前节点的兄弟节点遍历完毕,最后遍历当前节点的父节点的兄弟节点 */
do {
if (parent == json->root)
@ -253,7 +253,7 @@ static ACL_JSON_NODE *json_iter_next(ACL_ITER *it, ACL_JSON *json)
}
} while (ring_ptr != &json->root->children);
/* 遍历完所有点 */
/* 遍历完所有点 */
it->ptr = it->data = NULL;
return (NULL);
@ -287,7 +287,7 @@ static ACL_JSON_NODE *json_iter_prev(ACL_ITER *it, ACL_JSON *json)
node = (struct ACL_JSON_NODE*) it->data;
/* 先遍历当前结点的子结点 */
/* 先遍历当前节点的子节点 */
ring_ptr = acl_ring_pred(&node->children);
if (ring_ptr != &node->children) {
@ -297,7 +297,7 @@ static ACL_JSON_NODE *json_iter_prev(ACL_ITER *it, ACL_JSON *json)
return (it->ptr);
}
/* 当前结点的子结点遍历完毕,再遍历当前结点的兄弟结点 */
/* 当前节点的子节点遍历完毕,再遍历当前节点的兄弟节点 */
parent = acl_json_node_parent(node);
ring_ptr = acl_ring_pred(&node->node);
@ -308,7 +308,7 @@ static ACL_JSON_NODE *json_iter_prev(ACL_ITER *it, ACL_JSON *json)
return (it->ptr);
}
/* 当前结点的兄弟结点遍历完毕,最后遍历当前结点的父结点的兄弟结点 */
/* 当前节点的兄弟节点遍历完毕,最后遍历当前节点的父节点的兄弟节点 */
do {
if (parent == json->root)
@ -326,7 +326,7 @@ static ACL_JSON_NODE *json_iter_prev(ACL_ITER *it, ACL_JSON *json)
}
} while (ring_ptr != &json->root->children);
/* 遍历完所有点 */
/* 遍历完所有点 */
it->ptr = it->data = NULL;
return (NULL);
@ -340,7 +340,7 @@ ACL_JSON *acl_json_alloc()
json->dbuf = acl_dbuf_pool_create(81920);
json->root = acl_json_node_alloc(json);
/* 将根结点作为当前结点 */
/* 将根节点作为当前节点 */
json->curr_node = json->root;
/* 设置状态机的状态 */
#if 0
@ -392,7 +392,7 @@ ACL_JSON *acl_json_create(ACL_JSON_NODE *node)
json = (ACL_JSON*) acl_mycalloc(1, sizeof(ACL_JSON));
json->dbuf = acl_dbuf_pool_create(81920);
/* 如果传入的结点为 root 结点,则直接赋值创建 root 即可 */
/* 如果传入的节点为 root 节点,则直接赋值创建 root 即可 */
if (node == root) {
json->root = acl_json_node_duplicate(json, node);
} else {
@ -401,7 +401,7 @@ ACL_JSON *acl_json_create(ACL_JSON_NODE *node)
acl_json_node_add_child(json->root, first);
}
/* 将根结点作为当前结点 */
/* 将根节点作为当前节点 */
json->curr_node = json->root;
/* 设置状态机的状态 */
#if 0

View File

@ -1,7 +1,9 @@
#include "StdAfx.h"
#include <stdio.h>
#include <string.h>
#ifndef ACL_PREPARE_COMPILE
#include "stdlib/acl_define.h"
#include "stdlib/acl_stringops.h"
#include "json/acl_json.h"
#endif
@ -17,22 +19,33 @@
static const char *json_root(ACL_JSON *json, const char *data)
{
SKIP_WHILE(*data != '{', data);
SKIP_WHILE(*data != '{' && *data != '[', data);
if (*data == 0)
return NULL;
return data;
if (*data == '{') {
json->root->left_ch = '{';
json->root->right_ch = '}';
json->status = ACL_JSON_S_MEMBER;
json->root->type = ACL_JSON_T_OBJ;
}
else
{
json->root->left_ch = '[';
json->root->right_ch = ']';
json->status = ACL_JSON_S_ELEMENT;
json->root->type = ACL_JSON_T_ARRAY;
}
data++;
json->root->left_ch = '{';
json->root->right_ch = '}';
json->status = ACL_JSON_S_MEMBER;
json->curr_node = json->root;
json->root->type = ACL_JSON_T_OBJ;
json->depth = json->depth;
return data;
}
/* 分析结点对象值,必须找到 '{' 或 '[' */
/* 分析点对象值,必须找到 '{' 或 '[' */
static const char *json_obj(ACL_JSON *json, const char *data)
{
@ -40,9 +53,9 @@ static const char *json_obj(ACL_JSON *json, const char *data)
SKIP_SPACE(data);
if (*data == 0)
return NULL;
return data;
/* 创建对象 '{}' 子点 */
/* 创建对象 '{}' 子点 */
obj = acl_json_node_alloc(json);
obj->type = ACL_JSON_T_OBJ;
@ -50,7 +63,7 @@ static const char *json_obj(ACL_JSON *json, const char *data)
if (obj->depth > json->depth)
json->depth = obj->depth;
/* 根据 json 点对象前缀的不同,记录不同的对象后缀 */
/* 根据 json 点对象前缀的不同,记录不同的对象后缀 */
obj->left_ch = '{';
obj->right_ch = '}';
@ -67,7 +80,7 @@ static const char *json_obj(ACL_JSON *json, const char *data)
static const char *json_member(ACL_JSON *json, const char *data)
{
/* 创建上面所建对象点的成员对象 */
/* 创建上面所建对象点的成员对象 */
ACL_JSON_NODE *member = acl_json_node_alloc(json);
member->type = ACL_JSON_T_MEMBER;
@ -77,14 +90,14 @@ static const char *json_member(ACL_JSON *json, const char *data)
acl_json_node_add_child(json->curr_node, member);
/* 将该成员对象置为当前 JSON 分析点 */
/* 将该成员对象置为当前 JSON 分析点 */
json->curr_node = member;
json->status = ACL_JSON_S_PAIR;
return data;
}
/* 解析结点的标签名称,结点允许没有标签名;叶结点没有 { } [ ] 分隔符 */
/* 解析节点的标签名称,节点允许没有标签名;叶节点没有 { } [ ] 分隔符 */
static const char *json_pair(ACL_JSON *json, const char *data)
{
@ -92,27 +105,26 @@ static const char *json_pair(ACL_JSON *json, const char *data)
SKIP_SPACE(data);
if (*data == 0)
return NULL;
return data;
acl_assert(parent);
/* 如果当前字符为父结点的右分隔符,则表示父结点结束 */
/* 如果当前字符为父节点的右分隔符,则表示父节点结束 */
if (*data == parent->right_ch) {
data++; /* 去掉父结点的右分隔符 */
data++; /* 去掉父节点的右分隔符 */
if (parent == json->root) {
/* 如果根点分析结束则整个 json 分析完毕 */
/* 如果根点分析结束则整个 json 分析完毕 */
json->finish = 1;
return NULL;
return data;
}
/* 弹出父点 */
/* 弹出父点 */
json->curr_node = parent;
/* 查询父结点的下一个兄弟结点 */
/* 查询父节点的下一个兄弟节点 */
json->status = ACL_JSON_S_NEXT;
return data;
}
/* 为 '{' 或 '[' 时说明遇到了当前结点的子结点 */
/* 为 '{' 或 '[' 时说明遇到了当前节点的子节点 */
if (*data == '{') {
data++;
json->status = ACL_JSON_S_OBJ;
@ -134,7 +146,7 @@ static const char *json_pair(ACL_JSON *json, const char *data)
return data;
}
/* 解析结点的标签名称,结点允许没有标签名;叶结点没有 { } [ ] 分隔符 */
/* 解析节点的标签名称,节点允许没有标签名;叶节点没有 { } [ ] 分隔符 */
static const char *json_tag(ACL_JSON *json, const char *data)
{
@ -177,7 +189,7 @@ static const char *json_tag(ACL_JSON *json, const char *data)
acl_assert(parent);
/* 数组对象的子点允许为单独的字符串或对象 */
/* 数组对象的子点允许为单独的字符串或对象 */
if (parent->left_ch == '[')
json->status = ACL_JSON_S_NEXT;
@ -185,6 +197,10 @@ static const char *json_tag(ACL_JSON *json, const char *data)
else
json->status = ACL_JSON_S_COLON;
/* 当在分析标签名结束后,需要把 quote 赋 0
* quote ,
* 0
*/
node->quote = 0;
node->part_word = 0;
data++;
@ -257,7 +273,7 @@ static const char *json_colon(ACL_JSON *json, const char *data)
{
SKIP_SPACE(data);
if (*data == 0)
return NULL;
return data;
if (*data != ':') {
data++;
@ -267,7 +283,7 @@ static const char *json_colon(ACL_JSON *json, const char *data)
data++;
/* 下一步分析标签名所对应的标签值,有可能为字符串,
*
*
*/
json->status = ACL_JSON_S_VALUE;
@ -280,7 +296,7 @@ static const char *json_array(ACL_JSON *json, const char *data)
SKIP_SPACE(data);
if (*data == 0)
return NULL;
return data;
/* 创建数组对象 */
array = acl_json_node_alloc(json);
@ -309,7 +325,7 @@ static const char *json_element(ACL_JSON *json, const char *data)
SKIP_SPACE(data);
if (*data == 0)
return NULL;
return data;
if (*data == '{') {
data++;
@ -329,22 +345,22 @@ static const char *json_element(ACL_JSON *json, const char *data)
acl_json_node_add_child(json->curr_node, element);
/* 将该数组成员对象置为当前 JSON 分析点 */
/* 将该数组成员对象置为当前 JSON 分析点 */
json->curr_node = element;
json->status = ACL_JSON_S_VALUE;
return data;
}
/* 分析标签值,该值有可能是纯文本(即该结点为叶结点),也有可能是一个子结点 */
/* 分析标签值,该值有可能是纯文本(即该节点为叶节点),也有可能是一个子节点 */
static const char *json_value(ACL_JSON *json, const char *data)
{
SKIP_SPACE(data);
if (*data == 0)
return NULL;
return data;
/* 为 '{' 或 '[' 时说明遇到了当前结点的子结点 */
/* 为 '{' 或 '[' 时说明遇到了当前节点的子节点 */
if (*data == '{') {
data++;
json->status = ACL_JSON_S_OBJ;
@ -356,7 +372,7 @@ static const char *json_value(ACL_JSON *json, const char *data)
/* 兼容一下有些数据格式为 "xxx: ," 的方式 */
else if (*data == ',' || *data == ';') {
data++;
/* 切换至查询该结点的兄弟结点的过程 */
/* 切换至查询该节点的兄弟节点的过程 */
json->status = ACL_JSON_S_NEXT;
}
@ -365,7 +381,8 @@ static const char *json_value(ACL_JSON *json, const char *data)
else if (IS_QUOTE(*data)) { /* && json->curr_node->quote == 0) { */
json->curr_node->quote = *data++;
json->status = ACL_JSON_S_STRING;
} else
}
else
json->status = ACL_JSON_S_STRING;
json->curr_node->type = ACL_JSON_T_LEAF;
@ -383,10 +400,10 @@ static const char *json_string(ACL_JSON *json, const char *data)
/* 先过滤开头没用的空格 */
SKIP_SPACE(data);
if (*data == 0)
return NULL;
return data;
}
/* 说明本结点是叶结点 */
/* 说明本节点是叶节点 */
while ((ch = *data) != 0) {
/* 如果开始有引号,则需要以该引号作为结尾符 */
@ -420,9 +437,12 @@ static const char *json_string(ACL_JSON *json, const char *data)
} else
node->backslash = 1;
} else if (ch == node->quote) {
node->quote = 0;
/* 对节点的值,必须保留该 quote 值,以便于区分
* bool, null, number, string
* node->quote = 0;
*/
/* 切换至查询该结点的兄弟结点的过程 */
/* 切换至查询该节点的兄弟节点的过程 */
json->status = ACL_JSON_S_STREND;
node->part_word = 0;
data++;
@ -459,7 +479,7 @@ static const char *json_string(ACL_JSON *json, const char *data)
} else if (IS_SPACE(ch) || ch == ',' || ch == ';'
|| ch == '}' || ch == ']')
{
/* 切换至查询该结点的兄弟结点的过程 */
/* 切换至查询该节点的兄弟节点的过程 */
json->status = ACL_JSON_S_STREND;
break;
}
@ -487,11 +507,46 @@ static const char *json_string(ACL_JSON *json, const char *data)
static const char *json_strend(ACL_JSON *json, const char *data)
{
ACL_JSON_NODE *node = json->curr_node;
ACL_JSON_NODE *parent;
SKIP_SPACE(data);
if (*data == 0)
return NULL;
return data;
#define EQ(x, y) !strcasecmp((x), ((y)))
if (node->parent && node->parent->type == ACL_JSON_T_ARRAY)
{
if (EQ(STR(node->text), "null"))
node->type = ACL_JSON_T_A_NULL;
else if (EQ(STR(node->text), "true")
|| EQ(STR(node->text), "false"))
{
node->type = ACL_JSON_T_A_BOOL;
}
else if (acl_alldig(STR(node->text)))
node->type = ACL_JSON_T_A_NUMBER;
else
node->type = ACL_JSON_T_A_STRING;
}
else if (node->quote == 0)
{
if (EQ(STR(node->text), "null"))
node->type = ACL_JSON_T_NULL;
else if (EQ(STR(node->text), "true")
|| EQ(STR(node->text), "false"))
{
node->type = ACL_JSON_T_BOOL;
}
else if (acl_alldig(STR(node->text)))
node->type = ACL_JSON_T_NUMBER;
else
node->type = ACL_JSON_T_STRING;
}
else
node->type = ACL_JSON_T_STRING;
if (*data == ',' || *data == ';') {
json->status = ACL_JSON_S_NEXT;
@ -504,18 +559,18 @@ static const char *json_strend(ACL_JSON *json, const char *data)
return data;
}
data++;
if (parent == json->root) {
json->finish = 1;
return NULL;
return data;
}
data++;
json->curr_node = parent;
json->status = ACL_JSON_S_NEXT;
return data;
}
/* 尝试分析本结点的下一个兄弟结点,必须能找到分隔符 ',' 或 ';' */
/* 尝试分析本节点的下一个兄弟节点,必须能找到分隔符 ',' 或 ';' */
static const char *json_brother(ACL_JSON *json, const char *data)
{
@ -523,14 +578,14 @@ static const char *json_brother(ACL_JSON *json, const char *data)
if (json->curr_node == json->root) {
json->finish = 1;
return NULL;
return data;
}
SKIP_SPACE(data);
if (*data == 0)
return NULL;
return data;
/* 如果到达根点的结束符,则 json 解析过程完毕 */
/* 如果到达根点的结束符,则 json 解析过程完毕 */
parent = acl_json_node_parent(json->curr_node);
acl_assert(parent);
@ -550,14 +605,13 @@ static const char *json_brother(ACL_JSON *json, const char *data)
if (*data == parent->right_ch) {
data++;
if (parent == json->root) {
json->finish = 1;
return NULL;
return data;
}
json->curr_node = parent;
/* 查询父结点的下一个兄弟结点 */
/* 查询父节点的下一个兄弟节点 */
json->status = ACL_JSON_S_NEXT;
return data;
}
@ -590,7 +644,7 @@ static struct JSON_STATUS_MACHINE status_tab[] = {
{ ACL_JSON_S_ARRAY, json_array }, /* json array node */
{ ACL_JSON_S_ELEMENT, json_element },
{ ACL_JSON_S_PAIR, json_pair }, /* json pair node */
{ ACL_JSON_S_NEXT, json_brother }, /* json brother node */
{ ACL_JSON_S_NEXT, json_brother }, /* json brother node */
{ ACL_JSON_S_TAG, json_tag }, /* json tag name */
{ ACL_JSON_S_VALUE, json_value }, /* json node's value */
{ ACL_JSON_S_COLON, json_colon }, /* json tag's ':' */
@ -598,17 +652,26 @@ static struct JSON_STATUS_MACHINE status_tab[] = {
{ ACL_JSON_S_STREND, json_strend },
};
void acl_json_update(ACL_JSON *json, const char *data)
const char* acl_json_update(ACL_JSON *json, const char *data)
{
const char *ptr = data;
if (data == NULL)
return "";
/* 检查是否已经解析完毕 */
if (json->finish)
return;
return ptr;
/* json 解析器状态机循环处理过程 */
while (ptr && *ptr) {
while (*ptr && !json->finish)
ptr = status_tab[json->status].callback(json, ptr);
}
return ptr;
}
int acl_json_finish(ACL_JSON *json)
{
return json->finish;
}

View File

@ -271,13 +271,16 @@ void acl_json_building(ACL_JSON *json, size_t length,
ACL_VSTRING_ADDCH(buf, node->left_ch);
}
/* 当点有标签名时 */
/* 当点有标签名时 */
else if (LEN(node->ltag) > 0) {
json_escape_append(buf, STR(node->ltag));
ACL_VSTRING_ADDCH(buf, ':');
ACL_VSTRING_ADDCH(buf, ' ');
switch (node->type) {
case ACL_JSON_T_NULL:
acl_vstring_strcat(buf, "null");
break;
case ACL_JSON_T_BOOL:
case ACL_JSON_T_NUMBER:
acl_vstring_strcat(buf, STR(node->text));
@ -288,11 +291,14 @@ void acl_json_building(ACL_JSON *json, size_t length,
}
}
/* 当点为数组的成员时 */
/* 当点为数组的成员时 */
else if (LEN(node->text) > 0 && node->parent
&& node->parent->left_ch != 0)
{
switch (node->type) {
case ACL_JSON_T_A_NULL:
acl_vstring_strcat(buf, "null");
break;
case ACL_JSON_T_A_BOOL:
case ACL_JSON_T_A_NUMBER:
acl_vstring_strcat(buf, STR(node->text));
@ -303,16 +309,16 @@ void acl_json_building(ACL_JSON *json, size_t length,
}
}
/* 当点为没有标签名的容器(为 '{}' 或 '[]')时 */
/* 当点为没有标签名的容器(为 '{}' 或 '[]')时 */
else if (node->left_ch != 0) {
ACL_VSTRING_ADDCH(buf, node->left_ch);
}
/*
*
*
*
*
*/
/* 当本结点有子结点或虽为叶结点,但该结点的下一个兄弟结
/* 当本节点有子节点或虽为叶节点,但该节点的下一个兄弟节
*
*/
if (acl_ring_size(&node->children) > 0)
@ -326,9 +332,9 @@ void acl_json_building(ACL_JSON *json, size_t length,
if (node->right_ch > 0)
ACL_VSTRING_ADDCH(buf, node->right_ch);
/* 当本结点为叶结点且后面没有兄弟结点时,需要一级一级回溯
*
*
/* 当本节点为叶节点且后面没有兄弟节点时,需要一级一级回溯
*
*
*/
while (acl_json_node_next(node) == NULL) {
if (node->parent == json->root)
@ -390,13 +396,16 @@ ACL_VSTRING *acl_json_build(ACL_JSON *json, ACL_VSTRING *buf)
ACL_VSTRING_ADDCH(buf, node->left_ch);
}
/* 当点有标签名时 */
/* 当点有标签名时 */
else if (LEN(node->ltag) > 0) {
json_escape_append(buf, STR(node->ltag));
ACL_VSTRING_ADDCH(buf, ':');
ACL_VSTRING_ADDCH(buf, ' ');
switch (node->type) {
case ACL_JSON_T_NULL:
acl_vstring_strcat(buf, "null");
break;
case ACL_JSON_T_BOOL:
case ACL_JSON_T_NUMBER:
acl_vstring_strcat(buf, STR(node->text));
@ -407,11 +416,17 @@ ACL_VSTRING *acl_json_build(ACL_JSON *json, ACL_VSTRING *buf)
}
}
/* 当点为数组的成员时 */
/* 当点为数组的成员时 */
else if (LEN(node->text) > 0 && node->parent
&& node->parent->left_ch != 0)
/* 应该依据父节点类型来确定当前节点是否为数组节点
* && node->parent->left_ch != 0)
*/
&& node->parent->type == ACL_JSON_T_ARRAY)
{
switch (node->type) {
case ACL_JSON_T_A_NULL:
acl_vstring_strcat(buf, "null");
break;
case ACL_JSON_T_A_BOOL:
case ACL_JSON_T_A_NUMBER:
acl_vstring_strcat(buf, STR(node->text));
@ -422,16 +437,16 @@ ACL_VSTRING *acl_json_build(ACL_JSON *json, ACL_VSTRING *buf)
}
}
/* 当点为没有标签名的容器(为 '{}' 或 '[]')时 */
/* 当点为没有标签名的容器(为 '{}' 或 '[]')时 */
else if (node->left_ch != 0) {
ACL_VSTRING_ADDCH(buf, node->left_ch);
}
/*
*
*
*
*
*/
/* 当本结点有子结点或虽为叶结点,但该结点的下一个兄弟结
/* 当本节点有子节点或虽为叶节点,但该节点的下一个兄弟节
*
*/
if (acl_ring_size(&node->children) > 0)
@ -445,9 +460,9 @@ ACL_VSTRING *acl_json_build(ACL_JSON *json, ACL_VSTRING *buf)
if (node->right_ch > 0)
ACL_VSTRING_ADDCH(buf, node->right_ch);
/* 当本结点为叶结点且后面没有兄弟结点时,需要一级一级回溯
*
*
/* 当本节点为叶节点且后面没有兄弟节点时,需要一级一级回溯
*
*
*/
while (acl_json_node_next(node) == NULL) {
if (node->parent == json->root)

View File

@ -76,7 +76,7 @@ static void vstring_extend(ACL_VBUF *bp, int incr)
static int vstring_buf_get_ready(ACL_VBUF *buf acl_unused)
{
acl_msg_panic("vstring_buf_get: write-only buffer");
return (0);
return 0;
}
/* vstring_buf_put_ready - vbuf callback for write buffer full condition */
@ -84,7 +84,7 @@ static int vstring_buf_get_ready(ACL_VBUF *buf acl_unused)
static int vstring_buf_put_ready(ACL_VBUF *bp)
{
vstring_extend(bp, 0);
return (0);
return 0;
}
/* vstring_buf_space - vbuf callback to reserve space */
@ -97,7 +97,7 @@ static int vstring_buf_space(ACL_VBUF *bp, int len)
acl_msg_panic("vstring_buf_space: bad length %d", len);
if ((need = len - bp->cnt) > 0)
vstring_extend(bp, need);
return (0);
return 0;
}
void acl_vstring_init(ACL_VSTRING *vp, size_t len)
@ -137,7 +137,7 @@ void acl_vstring_free_buf(ACL_VSTRING *vp)
ACL_VSTRING *acl_vstring_alloc(size_t len)
{
return (acl_vstring_slice_alloc(NULL, len));
return acl_vstring_slice_alloc(NULL, len);
}
ACL_VSTRING *acl_vstring_slice_alloc(ACL_SLICE_POOL *slice, size_t len)
@ -169,7 +169,7 @@ ACL_VSTRING *acl_vstring_slice_alloc(ACL_SLICE_POOL *slice, size_t len)
vp->vbuf.space = vstring_buf_space;
vp->vbuf.ctx = vp;
vp->maxlen = 0;
return (vp);
return vp;
}
ACL_VSTRING *acl_vstring_dbuf_alloc(ACL_DBUF_POOL *dbuf, size_t len)
@ -199,7 +199,7 @@ ACL_VSTRING *acl_vstring_dbuf_alloc(ACL_DBUF_POOL *dbuf, size_t len)
vp->vbuf.space = vstring_buf_space;
vp->vbuf.ctx = vp;
vp->maxlen = 0;
return (vp);
return vp;
}
/* acl_vstring_free - destroy variable-length string */
@ -249,7 +249,7 @@ ACL_VSTRING *acl_vstring_truncate(ACL_VSTRING *vp, size_t len)
ACL_VSTRING_AT_OFFSET(vp, (int) len);
ACL_VSTRING_TERMINATE(vp);
}
return (vp);
return vp;
}
/* acl_vstring_strcpy - copy string */
@ -263,7 +263,7 @@ ACL_VSTRING *acl_vstring_strcpy(ACL_VSTRING *vp, const char *src)
src++;
}
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_strncpy - copy string of limited length */
@ -277,7 +277,7 @@ ACL_VSTRING *acl_vstring_strncpy(ACL_VSTRING *vp, const char *src, size_t len)
src++;
}
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_strcat - append string */
@ -289,7 +289,7 @@ ACL_VSTRING *acl_vstring_strcat(ACL_VSTRING *vp, const char *src)
src++;
}
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_strncat - append string of limited length */
@ -301,7 +301,7 @@ ACL_VSTRING *acl_vstring_strncat(ACL_VSTRING *vp, const char *src, size_t len)
src++;
}
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_memcpy - copy buffer of limited length */
@ -310,17 +310,22 @@ ACL_VSTRING *acl_vstring_memcpy(ACL_VSTRING *vp, const char *src, size_t len)
{
ACL_VSTRING_RESET(vp);
ACL_VSTRING_SPACE(vp, (int) len);
memcpy(acl_vstring_str(vp), src, len);
ACL_VSTRING_AT_OFFSET(vp, (int) len);
if (len > 0) {
ACL_VSTRING_SPACE(vp, (int) len);
memcpy(acl_vstring_str(vp), src, len);
ACL_VSTRING_AT_OFFSET(vp, (int) len);
}
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_memmove - move buffer of limited length */
ACL_VSTRING *acl_vstring_memmove(ACL_VSTRING *vp, const char *src, size_t len)
{
if (len == 0)
return vp;
if (src >= acl_vstring_str(vp)
&& (src + len <= acl_vstring_str(vp) + ACL_VSTRING_SIZE(vp)))
{
@ -328,7 +333,7 @@ ACL_VSTRING *acl_vstring_memmove(ACL_VSTRING *vp, const char *src, size_t len)
memmove(acl_vstring_str(vp), src, len);
ACL_VSTRING_AT_OFFSET(vp, (int) len);
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
} else {
/* 说明不是同一内存区间的数据移动 */
char *ptr = acl_mymalloc(len);
@ -340,7 +345,7 @@ ACL_VSTRING *acl_vstring_memmove(ACL_VSTRING *vp, const char *src, size_t len)
ACL_VSTRING_AT_OFFSET(vp, (int) len);
ACL_VSTRING_TERMINATE(vp);
vp->maxlen = 0;
return (vp);
return vp;
}
}
@ -348,12 +353,14 @@ ACL_VSTRING *acl_vstring_memmove(ACL_VSTRING *vp, const char *src, size_t len)
ACL_VSTRING *acl_vstring_memcat(ACL_VSTRING *vp, const char *src, size_t len)
{
ACL_VSTRING_SPACE(vp, (int) len);
memcpy(acl_vstring_end(vp), src, len);
len += ACL_VSTRING_LEN(vp);
ACL_VSTRING_AT_OFFSET(vp, (int) len);
if (len > 0) {
ACL_VSTRING_SPACE(vp, (int) len);
memcpy(acl_vstring_end(vp), src, len);
len += ACL_VSTRING_LEN(vp);
ACL_VSTRING_AT_OFFSET(vp, (int) len);
}
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_memchr - locate byte in buffer */
@ -367,7 +374,7 @@ char *acl_vstring_memchr(ACL_VSTRING *vp, int ch)
if (*cp == ch)
return ((char *) cp);
}
return (NULL);
return NULL;
}
/* acl_vstring_strstr - locate byte in buffer */
@ -378,7 +385,7 @@ char *acl_vstring_strstr(ACL_VSTRING *vp, const char *needle)
const unsigned char *np = 0;
if (vp == NULL || needle == NULL || *needle == 0)
return (NULL);
return NULL;
for (cp = (unsigned char *) acl_vstring_str(vp);
cp < (unsigned char *) acl_vstring_end(vp); cp++) {
@ -397,7 +404,7 @@ char *acl_vstring_strstr(ACL_VSTRING *vp, const char *needle)
}
}
return (NULL);
return NULL;
}
/* acl_vstring_strcasestr - locate byte in buffer */
@ -409,7 +416,7 @@ char *acl_vstring_strcasestr(ACL_VSTRING *vp, const char *needle)
const unsigned char *np = 0;
if (vp == NULL || needle == NULL || *needle == 0)
return (NULL);
return NULL;
for (cp = (unsigned char *) acl_vstring_str(vp);
cp < (unsigned char *) acl_vstring_end(vp); cp++) {
@ -428,7 +435,7 @@ char *acl_vstring_strcasestr(ACL_VSTRING *vp, const char *needle)
}
}
return (NULL);
return NULL;
}
/* acl_vstring_rstrstr - locate byte in buffer */
@ -439,7 +446,7 @@ char *acl_vstring_rstrstr(ACL_VSTRING *vp, const char *needle)
const unsigned char *np = 0, *needle_end;
if (vp == NULL || needle == NULL || *needle == 0)
return (NULL);
return NULL;
needle_end = (const unsigned char *) needle + strlen(needle) - 1;
@ -459,7 +466,7 @@ char *acl_vstring_rstrstr(ACL_VSTRING *vp, const char *needle)
}
}
return (NULL);
return NULL;
}
/* acl_vstring_rstrcasestr - locate byte in buffer */
@ -471,7 +478,7 @@ char *acl_vstring_rstrcasestr(ACL_VSTRING *vp, const char *needle)
const unsigned char *np = 0, *needle_end;
if (vp == NULL || needle == NULL || *needle == 0)
return (NULL);
return NULL;
needle_end = (const unsigned char *) needle + strlen(needle) - 1;
@ -487,11 +494,11 @@ char *acl_vstring_rstrcasestr(ACL_VSTRING *vp, const char *needle)
if (!np && *cp == cm[*needle_end]) {
np = needle_end - 1;
if (np < (const unsigned char *) needle)
return ((char *) cp);
return (char *) cp;
}
}
return (NULL);
return NULL;
}
/* acl_vstring_insert - insert text into string */
@ -520,7 +527,7 @@ ACL_VSTRING *acl_vstring_insert(ACL_VSTRING *vp, size_t start,
memcpy(acl_vstring_str(vp) + start, buf, len);
ACL_VSTRING_AT_OFFSET(vp, (int) new_len);
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_prepend - prepend text to string */
@ -538,7 +545,7 @@ ACL_VSTRING *acl_vstring_prepend(ACL_VSTRING *vp, const char *buf, size_t len)
memcpy(acl_vstring_str(vp), buf, len);
ACL_VSTRING_AT_OFFSET(vp, new_len);
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_export - VSTRING to bare string */
@ -550,7 +557,7 @@ char *acl_vstring_export(ACL_VSTRING *vp)
cp = (char *) vp->vbuf.data;
vp->vbuf.data = 0;
acl_myfree(vp);
return (cp);
return cp;
}
/* acl_vstring_import - bare string to vstring */
@ -567,7 +574,7 @@ ACL_VSTRING *acl_vstring_import(char *str)
vp->vbuf.len = len + 1;
ACL_VSTRING_AT_OFFSET(vp, len);
vp->maxlen = 0;
return (vp);
return vp;
}
void acl_vstring_glue(ACL_VSTRING *vp, void *buf, size_t len)
@ -607,7 +614,7 @@ ACL_VSTRING *acl_vstring_sprintf(ACL_VSTRING *vp, const char *format,...)
va_start(ap, format);
vp = acl_vstring_vsprintf(vp, format, ap);
va_end(ap);
return (vp);
return vp;
}
/* acl_vstring_vsprintf - format string, vsprintf-like interface */
@ -617,7 +624,7 @@ ACL_VSTRING *acl_vstring_vsprintf(ACL_VSTRING *vp, const char *format, va_list a
ACL_VSTRING_RESET(vp);
acl_vbuf_print(&vp->vbuf, format, ap);
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_sprintf_append - append formatted string */
@ -629,7 +636,7 @@ ACL_VSTRING *acl_vstring_sprintf_append(ACL_VSTRING *vp, const char *format,...)
va_start(ap, format);
vp = acl_vstring_vsprintf_append(vp, format, ap);
va_end(ap);
return (vp);
return vp;
}
/* acl_vstring_vsprintf_append - append format string, vsprintf-like interface */
@ -638,7 +645,7 @@ ACL_VSTRING *acl_vstring_vsprintf_append(ACL_VSTRING *vp, const char *format, va
{
acl_vbuf_print(&vp->vbuf, format, ap);
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
/* acl_vstring_sprintf_prepend - format + prepend string, vsprintf-like interface */
@ -663,7 +670,7 @@ ACL_VSTRING *acl_vstring_sprintf_prepend(ACL_VSTRING *vp, const char *format,...
memmove(acl_vstring_str(vp), acl_vstring_str(vp) + old_len, result_len);
ACL_VSTRING_AT_OFFSET(vp, result_len);
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
const ACL_VSTRING *acl_buffer_gets_nonl(ACL_VSTRING *vp, const char **src, size_t dlen)
@ -673,8 +680,8 @@ const ACL_VSTRING *acl_buffer_gets_nonl(ACL_VSTRING *vp, const char **src, size_
if (dlen <= 0) {
acl_msg_warn("%s(%d): dlen(%d) invalid",
myname, __LINE__, (int) dlen);
return (NULL);
myname, __LINE__, (int) dlen);
return NULL;
}
ptr = memchr(pbegin, '\n', dlen);
@ -682,7 +689,7 @@ const ACL_VSTRING *acl_buffer_gets_nonl(ACL_VSTRING *vp, const char **src, size_
acl_vstring_memcat(vp, pbegin, dlen);
ACL_VSTRING_TERMINATE(vp);
*src += dlen; /* 移动 *src 指针位置 */
return (NULL);
return NULL;
}
*src = ptr + 1; /* 移动 *src 指针位置 */
pend = ptr;
@ -696,11 +703,11 @@ const ACL_VSTRING *acl_buffer_gets_nonl(ACL_VSTRING *vp, const char **src, size_
if (pend < pbegin) {
/* 说明 data 中只包括 \r, \n */
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
acl_vstring_memcat(vp, pbegin, pend - pbegin + 1);
ACL_VSTRING_TERMINATE(vp);
return (vp);
return vp;
}
const ACL_VSTRING *acl_buffer_gets(ACL_VSTRING *vp, const char **src, size_t dlen)
@ -711,7 +718,7 @@ const ACL_VSTRING *acl_buffer_gets(ACL_VSTRING *vp, const char **src, size_t dle
if (dlen <= 0) {
acl_msg_warn("%s(%d): dlen(%d) invalid",
myname, __LINE__, (int) dlen);
return (NULL);
return NULL;
}
ptr = memchr(*src, '\n', dlen);
@ -719,11 +726,11 @@ const ACL_VSTRING *acl_buffer_gets(ACL_VSTRING *vp, const char **src, size_t dle
acl_vstring_memcat(vp, *src, dlen);
ACL_VSTRING_TERMINATE(vp);
*src += dlen;
return (NULL);
return NULL;
}
acl_vstring_memcat(vp, *src, ptr - *src + 1);
ACL_VSTRING_TERMINATE(vp);
*src = ptr + 1; /* 修改 *src 指针位置 */
return (vp);
return vp;
}

View File

@ -401,15 +401,45 @@ const char *acl_i64toa(acl_int64 value, char *buf, size_t size)
#elif defined(ACL_UNIX)
# ifdef MINGW
static long long atoll(const char *s)
{
long long num = 0;
int neg = 0;
while (isspace(*s))
s++;
if (*s == '-') {
neg = 1;
s++;
}
while (isdigit(*s)) {
num = 10*num + (*s - '0');
s++;
}
if (neg)
num = -num;
return num;
}
# endif
acl_uint64 acl_atoui64(const char *str)
{
#if 1
return (acl_uint64) atoll(str);
#else
return (acl_uint64) strtoull(str, NULL, 10);
#endif
}
acl_int64 acl_atoi64(const char *str)
{
#if 1
return (acl_int64) atoll(str);
#if 0
#else
return (acl_int64) strtoull(str, NULL, 10);
#endif
}

View File

@ -299,7 +299,7 @@ static ACL_XML_NODE *xml_iter_next(ACL_ITER *it, ACL_XML *xml)
node = (struct ACL_XML_NODE*) it->data;
/* 先遍历当前结点的子结点 */
/* 先遍历当前节点的子节点 */
ring_ptr = acl_ring_succ(&node->children);
if (ring_ptr != &node->children) {
@ -309,7 +309,7 @@ static ACL_XML_NODE *xml_iter_next(ACL_ITER *it, ACL_XML *xml)
return (it->ptr);
}
/* 当前结点的子结点遍历完毕,再遍历当前结点的兄弟结点 */
/* 当前节点的子节点遍历完毕,再遍历当前节点的兄弟节点 */
parent = acl_xml_node_parent(node);
ring_ptr = acl_ring_succ(&node->node);
@ -320,7 +320,7 @@ static ACL_XML_NODE *xml_iter_next(ACL_ITER *it, ACL_XML *xml)
return (it->ptr);
}
/* 当前结点的兄弟结点遍历完毕,最后遍历当前结点的父结点的兄弟结点 */
/* 当前节点的兄弟节点遍历完毕,最后遍历当前节点的父节点的兄弟节点 */
do {
if (parent == xml->root)
@ -338,7 +338,7 @@ static ACL_XML_NODE *xml_iter_next(ACL_ITER *it, ACL_XML *xml)
}
} while (ring_ptr != &xml->root->children);
/* 遍历完所有点 */
/* 遍历完所有点 */
it->ptr = it->data = NULL;
return (NULL);
@ -372,7 +372,7 @@ static ACL_XML_NODE *xml_iter_prev(ACL_ITER *it, ACL_XML *xml)
node = (struct ACL_XML_NODE*) it->data;
/* 先遍历当前结点的子结点 */
/* 先遍历当前节点的子节点 */
ring_ptr = acl_ring_pred(&node->children);
if (ring_ptr != &node->children) {
@ -382,7 +382,7 @@ static ACL_XML_NODE *xml_iter_prev(ACL_ITER *it, ACL_XML *xml)
return (it->ptr);
}
/* 当前结点的子结点遍历完毕,再遍历当前结点的兄弟结点 */
/* 当前节点的子节点遍历完毕,再遍历当前节点的兄弟节点 */
parent = acl_xml_node_parent(node);
ring_ptr = acl_ring_pred(&node->node);
@ -393,7 +393,7 @@ static ACL_XML_NODE *xml_iter_prev(ACL_ITER *it, ACL_XML *xml)
return (it->ptr);
}
/* 当前结点的兄弟结点遍历完毕,最后遍历当前结点的父结点的兄弟结点 */
/* 当前节点的兄弟节点遍历完毕,最后遍历当前节点的父节点的兄弟节点 */
do {
if (parent == xml->root)
@ -411,7 +411,7 @@ static ACL_XML_NODE *xml_iter_prev(ACL_ITER *it, ACL_XML *xml)
}
} while (ring_ptr != &xml->root->children);
/* 遍历完所有点 */
/* 遍历完所有点 */
it->ptr = it->data = NULL;
return (NULL);
@ -520,7 +520,7 @@ void acl_xml_reset(ACL_XML *xml)
(void) acl_xml_node_delete(node);
}
/* 因为根结点是一个虚结点,所以不需要释放,其会在调用
/* 因为根节点是一个虚节点,所以不需要释放,其会在调用
* acl_xml_free ʱ±»ÊÍ·Å
*/
acl_ring_detach(&xml->root->node);
@ -539,18 +539,18 @@ int acl_xml_is_closure(ACL_XML *xml)
ACL_RING *ring_ptr;
ACL_XML_NODE *node;
/* 获得 xml->root 结点的最后一个一级子结点 */
/* 获得 xml->root 节点的最后一个一级子节点 */
ring_ptr = acl_ring_succ(&xml->root->children);
if (ring_ptr == &xml->root->children) {
/* 说明没有真实子点 */
/* 说明没有真实子点 */
return (0);
}
node = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);
if ((node->flag & ACL_XML_F_SELF_CL)) {
/* 说明该结点是自闭合结点 */
/* 说明该节点是自闭合节点 */
return (1);
}
@ -558,7 +558,7 @@ int acl_xml_is_closure(ACL_XML *xml)
return (1);
}
/* 说明最后一个一级子点还未处理完毕 */
/* 说明最后一个一级子点还未处理完毕 */
return (0);
}
@ -567,23 +567,23 @@ int acl_xml_is_complete(ACL_XML *xml, const char *tag)
ACL_RING *ring_ptr;
ACL_XML_NODE *node;
/* 获得 xml->root 结点的最后一个一级子结点 */
/* 获得 xml->root 节点的最后一个一级子节点 */
ring_ptr = acl_ring_succ(&xml->root->children);
if (ring_ptr == &xml->root->children) {
/* 说明没有真实子点 */
/* 说明没有真实子点 */
return (0);
}
node = acl_ring_to_appl(ring_ptr, ACL_XML_NODE, node);
if ((node->flag & ACL_XML_F_SELF_CL)) {
/* 说明该结点是自闭合结点 */
/* 说明该节点是自闭合节点 */
return (1);
}
if (node->status != ACL_XML_S_RGT) {
/* 说明最后一个一级子点还未处理完毕 */
/* 说明最后一个一级子点还未处理完毕 */
return (0);
}
@ -591,6 +591,6 @@ int acl_xml_is_complete(ACL_XML *xml, const char *tag)
return (1);
}
/* 说明 xml 中的最后一个点与所给标签不匹配 */
/* 说明 xml 中的最后一个点与所给标签不匹配 */
return (0);
}

View File

@ -522,12 +522,12 @@ static const char *xml_parse_attr_val(ACL_XML *xml, const char *data)
if (acl_htable_find(xml->id_table, ptr) == NULL) {
acl_htable_enter(xml->id_table, ptr, attr);
/* 只有当该属性被加入哈希表后才会赋于点的 id */
/* 只有当该属性被加入哈希表后才会赋于点的 id */
xml->curr_node->id = attr->value;
}
}
/* 必须将该点的当前属性对象置空,以便于继续解析时
/* 必须将该点的当前属性对象置空,以便于继续解析时
*
*/
xml->curr_node->curr_attr = NULL;
@ -561,8 +561,8 @@ static const char *xml_parse_text(ACL_XML *xml, const char *data)
return (data);
if ((xml->curr_node->flag & ACL_XML_F_SELF_CL)) {
/* 如果该标签是自关闭类型,则应使父点直接跳至右边 '/' 处理位置,
* 使 '>'
/* 如果该标签是自关闭类型,则应使父点直接跳至右边 '/' 处理位置,
* 使 '>'
*/
ACL_XML_NODE *parent = acl_xml_node_parent(xml->curr_node);
if (parent != xml->root)
@ -596,12 +596,12 @@ static const char *xml_parse_right_lt(ACL_XML *xml, const char *data)
return (data);
}
/* 说明遇到了当前结点的子结点 */
/* 说明遇到了当前节点的子节点 */
/* 重新设置当前点状态,以便于其可以找到 "</" */
/* 重新设置当前点状态,以便于其可以找到 "</" */
xml->curr_node->status = ACL_XML_S_TXT;
/* 创建新的子结点,并将其加入至当前结点的子结点集合中 */
/* 创建新的子节点,并将其加入至当前节点的子节点集合中 */
node = acl_xml_node_alloc(xml);
acl_xml_node_add_child(xml->curr_node, node);
@ -622,8 +622,8 @@ static const char *xml_parse_right_gt(ACL_XML *xml, const char *data)
return (data);
}
/* 因为该父结点其实为叶结点,所以需要更新附属于该伪父结点的
*
/* 因为该父节点其实为叶节点,所以需要更新附属于该伪父节点的
*
*/
static void update_children_depth(ACL_XML_NODE *parent)
{
@ -637,7 +637,7 @@ static void update_children_depth(ACL_XML_NODE *parent)
}
}
/* 查找与右标签相同的父点 */
/* 查找与右标签相同的父点 */
static int search_match_node(ACL_XML *xml)
{
ACL_XML_NODE *parent, *node;
@ -717,7 +717,7 @@ static const char *xml_parse_right_tag(ACL_XML *xml, const char *data)
if ((xml->flag & ACL_XML_FLAG_IGNORE_SLASH))
ret = search_match_node(xml);
if (ret == 0) {
/* 如果点标签名与开始标签名不匹配,
/* 如果点标签名与开始标签名不匹配,
*
*/
acl_vstring_strcat(curr_node->text,
@ -725,7 +725,7 @@ static const char *xml_parse_right_tag(ACL_XML *xml, const char *data)
ACL_VSTRING_RESET(curr_node->rtag);
ACL_VSTRING_TERMINATE(curr_node->rtag);
/* 重新设置当前点状态,以便于其可以找到 "</" */
/* 重新设置当前点状态,以便于其可以找到 "</" */
curr_node->status = ACL_XML_S_TXT;
}
}

View File

@ -1,6 +1,24 @@
修改历史列表:
------------------------------------------------------------------------
359) 2015.9.25
359.1) feature: http 模块中的 HttpServlet 类增加了 doOther 虚接口,从而可以
支持其它未知的 HTTP 请求方法
359.2) feature: smtp 模块下组装邮件的功能完善
359.3) samples/mime/mail_builder: 示例功能完善
358) 2015.9.22
358.1) feature: json 解析器增加支持判断是否解析完毕的功能
357) 2015.9.21
357.1) bugfix严重: 连接池基础类 connect_pool 中的方法 check_idle 当参数
exclusive 为 false 时会造成提前解锁; 该 BUG 影响所有该类的子类。
357.2) safety: string 类中的宏 MCP 增加了安全性检测
356) 2015.9.18
356.1) feature: connect_pool/connect_manager 连接池及连接池管理类允许设置
无连接数上限
355) 2015.9.9
355.1) feature: smtp_client 类已经可以非常方便地发送邮件
355.2) samples/smtp_client: 测试邮件发送过程

View File

@ -30,7 +30,7 @@ public:
* IP:PORT:COUNT,IP:PORT:COUNT,IP:PORT;IP:PORT ...
* 127.0.0.1:7777:50;192.168.1.1:7777:10;127.0.0.1:7778
* @param default_count {size_t} addr_list
* COUNT 便
* COUNT 便 0
* default_addr addr_list
*/
void init(const char* default_addr, const char* addr_list,
@ -39,7 +39,8 @@ public:
/**
*
* @param addr {const char*} (ip:port)
* @param count {size_t}
* @param count {size_t} , 0
*
* @return {connect_pool&}
*/
connect_pool& set(const char* addr, size_t count);
@ -163,7 +164,7 @@ protected:
/**
*
* @param addr {const char*} ip:port
* @param count {size_t}
* @param count {size_t} 0
* @param idx {size_t} ( 0 )
* @return {connect_pool*}
*/

View File

@ -21,10 +21,11 @@ public:
/**
*
* @param addr {const char*} ip:port(domain:port)
* @param count {size_t}
* @param max {size_t} 0
*
* @param idx {size_t} ( 0 )
*/
connect_pool(const char* addr, size_t count, size_t idx = 0);
connect_pool(const char* addr, size_t max, size_t idx = 0);
/**
*
@ -102,7 +103,7 @@ public:
}
/**
*
* 0
* @return {size_t}
*/
size_t get_max() const

View File

@ -45,7 +45,7 @@ protected:
/**
* connect_manager
* @param addr {const char*} ip:port
* @param count {size_t}
* @param count {size_t} 0
* @param idx {size_t} ( 0 )
* @return {connect_pool*}
*/

View File

@ -21,7 +21,7 @@ protected:
/**
* connect_manager
* @param addr {const char*} ip:port
* @param count {size_t}
* @param count {size_t} 0
* @param idx {size_t} ( 0 )
* @return {connect_pool*}
*/

View File

@ -16,9 +16,40 @@ class HttpServletResponse;
class ACL_CPP_API HttpServlet
{
public:
HttpServlet(void);
/**
*
* @param stream {socket_stream*} acl_master
* apache CGI
* NULL
* 便 acl_master
* @param session {session*} HttpServlet session
*/
HttpServlet(socket_stream* stream, session* session);
/**
*
* @param stream {socket_stream*} acl_master
* apache CGI
* NULL
* 便 acl_master
* @param memcache_addr {const char*}
*/
HttpServlet(socket_stream* stream,
const char* memcache_addr = "127.0.0.1:11211");
HttpServlet();
virtual ~HttpServlet(void) = 0;
session& getSession() const
{
return *session_;
}
socket_stream* getStream() const
{
return stream_;
}
/**
* HTTP
* doRun
@ -54,6 +85,12 @@ public:
*/
HttpServlet& setParseBodyLimit(int length);
/**
* HttpServlet HTTP doXXX
* @return {bool}
*/
bool doRun();
/**
* HttpServlet HTTP doXXX
* @param session {session&} session
@ -72,8 +109,7 @@ public:
* @param stream {socket_stream*}
* @return {bool}
*/
bool doRun(const char* memcached_addr = "127.0.0.1:11211",
socket_stream* stream = NULL);
bool doRun(const char* memcached_addr, socket_stream* stream);
/**
* HTTP GET
@ -148,6 +184,27 @@ public:
return false;
}
/**
* HTTP PROPFIND
*/
virtual bool doPropfind(HttpServletRequest&, HttpServletResponse&)
{
logger_error("child not implement doPurge yet!");
return false;
}
/**
* HTTP
* @param method {const char*}
*/
virtual bool doOther(HttpServletRequest&, HttpServletResponse&,
const char* method)
{
(void) method;
logger_error("child not implement doOther yet!");
return false;
}
/**
* HTTP
*/
@ -167,11 +224,16 @@ public:
}
private:
session* session_;
session* session_ptr_;
socket_stream* stream_;
bool first_;
char local_charset_[32];
int rw_timeout_;
bool parse_body_enable_;
int parse_body_limit_;
void init();
};
} // namespace acl

View File

@ -32,28 +32,31 @@ public:
* @param res {HttpServletResponse&}
* @param store {session&}
* @param stream {socket_stream&}
* @param local_charset {const char*}
* @param charset {const char*}
* HTTP
* @param body_parse {bool} POST
* HTTP n/v true
* HTTP getParameter
* URL POST
* false
*
* HTTP true
* true HTTP
* 1) x-www-form-urlencoded getParameter
* URL POST
* 2) xml getXml xml
* 3) json getJson json
* false
* @param body_limit {int} POST
* MIME
* body_read false
* on false
*/
HttpServletRequest(HttpServletResponse& res, session& store,
socket_stream& stream, const char* local_charset = NULL,
socket_stream& stream, const char* charset = NULL,
bool body_parse = true, int body_limit = 102400);
~HttpServletRequest(void);
/**
* HTTP GET, POST, PUT, CONNECT, PURGE
* @param method_s {string*}
* @return {http_method_t}
*/
http_method_t getMethod(void) const;
http_method_t getMethod(string* method_s = NULL) const;
/**
* HTTP cookie
@ -348,7 +351,7 @@ private:
xml* xml_;
bool readHeaderCalled_;
bool readHeader(void);
bool readHeader(string* method_s);
void parseParameters(const char* str);
};

View File

@ -233,6 +233,15 @@ public:
*/
void setHttpServletRequest(HttpServletRequest* request);
/**
* http_client
* @return {http_client*} NULL
*/
http_client* getClient() const
{
return client_;
}
private:
socket_stream& stream_; // 客户端连接流
HttpServletRequest* request_; // http 请求对象

View File

@ -406,6 +406,8 @@ private:
int read_response_body(string& out, bool clean, int* real_size);
HTTP_HDR* get_http_hdr() const;
public:
bool write_chunk(ostream& out, const void* data, size_t len);
bool write_chunk_trailer(ostream& out);

View File

@ -18,7 +18,7 @@ protected:
/**
*
* @param addr {const char*} ip:port
* @param count {size_t}
* @param count {size_t} 0
* @param idx {size_t} ( 0 )
* @return {connect_pool*}
*/

View File

@ -19,7 +19,7 @@ public:
/**
*
* @param addr {const char*} ip:port(domain:port)
* @param count {size_t}
* @param count {size_t} 0
* @param idx {size_t} ( 0 )
*/
http_request_pool(const char* addr, size_t count, size_t idx = 0);
@ -31,7 +31,7 @@ public:
* @param rw_timeout {int} IO ()
* @return {http_request_pool&}
*/
http_request_pool& set_timeout(int conn_timeout = 30, int rw_timeout = 60);
http_request_pool& set_timeout(int conn_timeout, int rw_timeout);
protected:
// 基类纯虚函数

View File

@ -36,8 +36,9 @@ typedef enum
HTTP_METHOD_PURGE, // PURGE 方法
HTTP_METHOD_DELETE, // DELETE 方法
HTTP_METHOD_HEAD, // HEAD 方法
HTTP_METHOD_OPTION // OPTION 方法
HTTP_METHOD_OPTION, // OPTION 方法
HTTP_METHOD_PROPFIND, // PROPFIND 方法
HTTP_METHOD_OTHER, // 其它的方法
} http_method_t;
typedef enum

View File

@ -122,7 +122,7 @@ protected:
{
(void) nclients;
(void) nthreads;
return false;
return true;
}
private:

View File

@ -18,7 +18,7 @@ protected:
/**
*
* @param addr {const char*} ip:port
* @param count {size_t}
* @param count {size_t} 0
* @param idx {size_t} ( 0 )
*/
connect_pool* create_pool(const char* addr, size_t count, size_t idx);

View File

@ -19,7 +19,7 @@ public:
/**
*
* @param addr {const char*} ip:port
* @param count {size_t}
* @param count {size_t} 0
* @param idx {size_t} ( 0 )
*/
memcache_pool(const char* addr, size_t count, size_t idx = 0);

View File

@ -41,8 +41,26 @@ class ACL_CPP_API redis
, public redis_geo
{
public:
/**
*
* the constructor with no redis cluster
* @param conn {redis_client*} redis
* one redis node's connection
*/
redis(redis_client* conn = NULL);
redis(redis_client_cluster* cluster, size_t max_conns);
/**
*
* the constructor in redis cluster mode
* @param cluster {redis_client_cluster*}
* the redis cluster object
* @param max_conns {size_t} redis
* 0
* the limit of each connections pool in redis cluster mode,
* there is no connections limit of each pool if the max_conns
* is set to 0.
*/
redis(redis_client_cluster* cluster, size_t max_conns = 0);
~redis() {}
};

View File

@ -137,13 +137,13 @@ protected:
* the connection pool
* @param addr {const char*} ip:port;
* the server addr for the connection pool, such as ip:port
* @param count {size_t} ;
* the max connections in one connection pool
* @param count {size_t} 0
* the max connections in one connection pool, if it's 0 there
* is no limit of the connections pool.
* @param idx {size_t} ( 0 );
* the index of the connection pool in pool array
*/
connect_pool* create_pool(const char* addr,
size_t count, size_t idx);
connect_pool* create_pool(const char* addr, size_t count, size_t idx);
private:
int conn_timeout_;

View File

@ -19,8 +19,10 @@ public:
* constructor
* @param addr {const char*} ip:port
* the redis-server's listening address, format: ip:port
* @param count {size_t}
* the max connections for each connection pool
* @param count {size_t} 0
*
* the max connections for each connection pool. there is
* no connections limit of the pool when the count is 0.
* @param idx {size_t} ( 0 )
* the subscript of the connection pool in the connection cluster
*/

View File

@ -43,8 +43,11 @@ public:
* cluster mode.
* @param cluster {redis_client_cluster*} redis
* redis cluster object in cluster mode
* @param max_conns {size_t}
* the max of every connection pool with all the redis nodes
* @param max_conns {size_t}
* 0
* the max of every connection pool with all the redis nodes,
* if be set 0, then there is no connections limit in
* connections pool.
*/
redis_command(redis_client_cluster* cluster, size_t max_conns);

View File

@ -14,7 +14,7 @@ class ACL_CPP_API mail_attach
{
public:
/**
*
*
* @param filepath {const char*}
* @param content_type {const char*}
* @param charset {const char*}

View File

@ -43,7 +43,7 @@ public:
}
/**
* HTML
* TEXT/HTML
* @param html {const char*} HTML
* @param len {size_t} html ( html
* strlen )
@ -52,42 +52,42 @@ public:
mail_body& set_html(const char* html, size_t len);
/**
* TEXT
* @param text {const char*} TEXT
* @param len {size_t} text ( text
* TEXT/PLAIN
* @param plain {const char*} TEXT
* @param len {size_t} plain ( plain
* strlen )
* @return {mail_body&}
*/
mail_body& set_text(const char* text, size_t len);
mail_body& set_plain(const char* plain, size_t len);
/**
* multipart/alternative
*
* @param html {const char*} HTML ()
* @param hlen {size_t} html (>0)
* @param text {const char*} TEXT ()
* @param tlen {size_t} text (>0)
* @param plain {const char*} TEXT ()
* @param plen {size_t} plain (>0)
* @return {mail_body&}
*/
mail_body& set_alternative(const char* html, size_t hlen,
const char* text, size_t tlen);
const char* plain, size_t plen);
/**
* multipart/relative
* @param html {const char*} HTML ()
* @param hlen {size_t} html (>0)
* @param text {const char*} TEXT ()
* @param tlen {size_t} text (>0)
* @param plain {const char*} plain ()
* @param plen {size_t} plain (>0)
* @param attachments {const std::vector<mail_attach*>&}
* html cid
* @return {mail_body&}
*/
mail_body& set_relative(const char* html, size_t hlen,
const char* text, size_t tlen,
const char* plain, size_t plen,
const std::vector<mail_attach*>& attachments);
/**
* set_html html
* set_html html/plain
* @param len {size_t}
* @return {const char*}
*/
@ -98,14 +98,14 @@ public:
}
/**
* set_text text
* set_plain plain/plain
* @param len {size_t}
* @return {const char*}
*/
const char* get_text(size_t& len) const
const char* get_plain(size_t& len) const
{
len = tlen_;
return text_;
len = plen_;
return plain_;
}
/**
@ -147,21 +147,21 @@ public:
* @param out {string&}
* @return {bool}
*/
bool save_text(const char* in, size_t len, string& out) const;
bool save_plain(const char* in, size_t len, string& out) const;
/**
* multipart/relative
* @param html {const char*} html
* @param hlen {size_t} html
* @param text {const char*} TEXT ()
* @param tlen {size_t} text (>0)
* @param plain {const char*} TEXT ()
* @param plen {size_t} plain (>0)
* @param attachments {const std::vector<mail_attach*>&}
* html cid
* @param out {string&}
* @return {bool}
*/
bool save_relative(const char* html, size_t hlen,
const char* text, size_t tlen,
const char* plain, size_t plen,
const std::vector<mail_attach*>& attachments,
string& out) const;
@ -169,13 +169,13 @@ public:
* multipart/alternative
* @param html {const char*} html
* @param hlen {size_t} html
* @param text {const char*} TEXT ()
* @param tlen {size_t} text (>0)
* @param plain {const char*} TEXT ()
* @param plen {size_t} plain (>0)
* @param out {string&}
* @return {bool}
*/
bool save_alternative(const char* html, size_t hlen,
const char* text, size_t tlen, string& out) const;
const char* plain, size_t plen, string& out) const;
private:
string charset_;
@ -188,11 +188,17 @@ private:
const char* html_;
size_t hlen_;
const char* text_;
size_t tlen_;
const char* plain_;
size_t plen_;
const std::vector<mail_attach*>* attachments_;
bool build(const char* in, size_t len, string& out) const;
bool build(const char* in, size_t len, const char* content_type,
const char* charset, mime_code& coder, string& out) const;
bool build_html(const char* in, size_t len,
const char* charset, string& out) const;
bool build_plain(const char* in, size_t len,
const char* charset, string& out) const;
void set_content_type(const char* content_type);
};

View File

@ -309,8 +309,15 @@ public:
* json reset()
*
* @param data {const char*} json
@return {const char*}
*/
void update(const char* data);
const char* update(const char* data);
/**
*
* @return {bool}
*/
bool finish();
/**
* json json json
@ -504,7 +511,7 @@ public:
* json
* @param out {string&}
*/
void build_json(string& out);
void build_json(string& out) const;
/**
* json json

View File

@ -458,7 +458,7 @@ public:
* xml
* @param out {string&}
*/
void build_xml(string& out);
void build_xml(string& out) const;
// pipe_stream 虚函数重载

View File

@ -93,3 +93,5 @@ clean:
@(cd socket; make clean)
@(cd db; make clean)
@(cd redis; make clean)
rebuild rb: clean all

View File

@ -136,9 +136,12 @@ all: RM $(OBJ)
@echo ""
@echo "All ok! Output:$(PROG)"
@echo ""
rebuild rb: clean all
RM:
rm -f $(PROG)
clean:
clean cl:
rm -f $(PROG)
rm -f $(OBJ)
rebuild rb: clean all
###########################################################

View File

@ -10,7 +10,8 @@ using namespace acl;
class http_servlet : public HttpServlet
{
public:
http_servlet(void)
http_servlet(socket_stream* stream, session* session)
: HttpServlet(stream, session)
{
}
@ -20,7 +21,8 @@ public:
}
virtual bool doUnknown(HttpServletRequest&, HttpServletResponse& res)
virtual bool doOther(HttpServletRequest&, HttpServletResponse& res,
const char* method)
{
res.setStatus(400);
res.setContentType("text/xml; charset=gb2312");
@ -28,7 +30,8 @@ public:
if (res.sendHeader() == false)
return false;
// 发送 http 响应体
string buf("<root error='unkown request method' />\r\n");
string buf;
buf.format("<root error='unkown method: %s' />\r\n", method);
(void) res.getOutputStream().write(buf);
return false;
}
@ -107,9 +110,9 @@ private:
static void do_run(socket_stream* stream)
{
memcache_session session("127.0.0.1:11211");
http_servlet servlet;
http_servlet servlet(stream, &session);
servlet.setLocalCharset("gb2312");
servlet.doRun(session, stream);
servlet.doRun();
}
// 服务器方式运行时的服务类

View File

@ -12,7 +12,8 @@ using namespace acl;
class http_servlet : public HttpServlet
{
public:
http_servlet(void)
http_servlet(socket_stream* stream, session& session)
: HttpServlet(stream, &session)
{
param1_ = NULL;
param2_ = NULL;
@ -287,9 +288,9 @@ private:
static void do_run(socket_stream* stream)
{
memcache_session session("127.0.0.1:11211");
http_servlet servlet;
http_servlet servlet(stream, session);
servlet.setLocalCharset("gb2312");
servlet.doRun(session, stream);
servlet.doRun();
}
// 服务器方式运行时的服务类

View File

@ -13,7 +13,8 @@ using namespace acl;
class http_servlet : public HttpServlet
{
public:
http_servlet(void)
http_servlet(socket_stream* stream, session* session)
: HttpServlet(stream, session)
{
}
@ -106,9 +107,9 @@ protected:
virtual void on_accept(socket_stream* stream)
{
memcache_session session("127.0.0.1:11211");
http_servlet servlet;
http_servlet servlet(stream, &session);
servlet.setLocalCharset("gb2312");
servlet.doRun(session, stream);
servlet.doRun();
}
};
@ -125,7 +126,7 @@ int main(int argc, char* argv[])
{
format = (void (*)(const char*, ...)) printf;
printf("listen: 0.0.0.0:8888 ...\r\n");
service.run_alone("0.0.0.0:8888", NULL, 1); // 单独运行方式
service.run_alone("0.0.0.0:8888", NULL, 0); // 单独运行方式
}
else
{

View File

@ -1,7 +1,8 @@
#include "stdafx.h"
#include "http_servlet.h"
http_servlet::http_servlet(void)
http_servlet::http_servlet(acl::socket_stream* stream, acl::session* session)
: acl::HttpServlet(stream, session)
{
}

View File

@ -3,7 +3,7 @@
class http_servlet : public acl::HttpServlet
{
public:
http_servlet();
http_servlet(acl::socket_stream* stream, acl::session* session);
~http_servlet();
protected:

View File

@ -19,7 +19,7 @@
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}</ProjectGuid>
<ProjectGuid>{685428CA-8DD4-489F-AC7F-0F5B70191D0F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<ProjectName>http_servlet2</ProjectName>
</PropertyGroup>
@ -200,4 +200,4 @@ copy ..\..\..\dist\lib\win32\lib_protocol_d.dll $(OutDir) /Y</Command>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -49,7 +49,7 @@ bool master_service::thread_on_read(acl::socket_stream* conn)
if (servlet == NULL)
logger_fatal("servlet null!");
return servlet->doRun("127.0.0.1:11211", conn);
return servlet->doRun();
}
bool master_service::thread_on_accept(acl::socket_stream* conn)
@ -58,7 +58,9 @@ bool master_service::thread_on_accept(acl::socket_stream* conn)
conn->sock_handle());
conn->set_rw_timeout(5);
http_servlet* servlet = new http_servlet();
acl::memcache_session* session =
new acl::memcache_session("127.0.0.1:11211");
http_servlet* servlet = new http_servlet(conn, session);
conn->set_ctx(servlet);
return true;
@ -77,8 +79,9 @@ void master_service::thread_on_close(acl::socket_stream* conn)
conn->sock_handle());
http_servlet* servlet = (http_servlet*) conn->get_ctx();
if (servlet)
delete servlet;
acl::session* session = &servlet->getSession();
delete session;
delete servlet;
}
void master_service::thread_on_init()

View File

@ -9,6 +9,10 @@ all:
@(cd json5; make)
@(cd json6; make)
@(cd json7; make)
@(cd json8; make)
@(cd json9; make)
@(cd json10; make)
@(cd json11; make)
clean:
@(cd json0; make clean)
@(cd json1; make clean)
@ -18,3 +22,29 @@ clean:
@(cd json5; make clean)
@(cd json6; make clean)
@(cd json7; make clean)
@(cd json8; make clean)
@(cd json9; make clean)
@(cd json10; make clean)
@(cd json11; make clean)
test:
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json0 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json0; ./json)
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json1 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json1; ./json)
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json2 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json2; ./json)
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json3 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json3; ./json)
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json4 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json4; ./json)
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json5 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json5; ./json)
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json6 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json6; ./json)
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json7 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json7; ./json)
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json8 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json8; ./json)
@echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test json9 ...<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
@(cd json9; ./json)

View File

@ -0,0 +1,3 @@
base_path = ../../..
PROG = json
include ../../Makefile.in

View File

@ -0,0 +1,53 @@
#include "stdafx.h"
int main()
{
acl::json json;
acl::json_node& root = json.get_root();
//////////////////////////////////////////////////////////////////////
// 方法一:
root.add_child("Para", json.create_node()
.add_child("xxx", "111")
.add_child("yyy", "222")
.add_bool("zzz", true)
.add_number("eee", 100));
printf("%s\r\n", json.to_string().c_str());
acl::string buf1;
json.build_json(buf1);
//////////////////////////////////////////////////////////////////////
// 在重新使用前需要重置 json 生成器状态
json.reset();
//////////////////////////////////////////////////////////////////////
// 方法二:
acl::json_node& node1 = json.create_node();
root.add_child("Para", node1);
acl::json_node& node11 = json.create_node("xxx", "111");
node1.add_child(node11);
acl::json_node& node12 = json.create_node("yyy", "222");
node1.add_child(node12);
acl::json_node& node13 = json.create_node("zzz", true);
node1.add_child(node13);
acl::json_node& node14 = json.create_node("eee", (long long int) 100);
node1.add_child(node14);
printf("%s\r\n", json.to_string().c_str());
acl::string buf2;
json.build_json(buf2);
if (buf2 == buf1)
printf("OK\r\n");
else
printf("ERROR\r\n");
return 0;
}

View File

@ -0,0 +1,271 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="json10"
ProjectGUID="{56199633-C345-4733-8292-A4F2D86AA847}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;VC2003"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="lib_acl_vc2003d.lib ws2_32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;VC2003"
RuntimeLibrary="0"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib wsock32.lib lib_acl_vc2003.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="DebugDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;VC2003;ACL_CPP_DLL;ACL_DLL"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="ReleaseDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;VC2003"
RuntimeLibrary="0"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib wsock32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Ô´Îļþ"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\json.cpp">
</File>
<File
RelativePath=".\stdafx.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="DebugDll|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="ReleaseDll|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Í·Îļþ"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\stdafx.h">
</File>
</Filter>
<Filter
Name="×ÊÔ´Îļþ"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
<File
RelativePath=".\ReadMe.txt">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,8 @@
// stdafx.cpp : 只包括标准包含文件的源文件
// json.pch 将成为预编译头
// stdafx.obj 将包含预编译类型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中
//引用任何所需的附加头文件,而不是在此文件中引用

View File

@ -0,0 +1,41 @@
// stdafx.h : 标准系统包含文件的包含文件,
// 或是常用但不常更改的项目特定的包含文件
//
#pragma once
//#include <iostream>
//#include <tchar.h>
// TODO: 在此处引用程序要求的附加头文件
#include "acl_cpp/lib_acl.hpp"
#include "lib_acl.h"
#ifdef WIN32
#include <io.h>
#define snprintf _snprintf
#endif
#ifdef DEBUG
// 以下宏定义用来帮助检查变参中的参数类型是否合法
#undef logger
#define logger printf
#undef logger_error
#define logger_error printf
#undef logger_warn
#define logger_warn printf
#undef logger_fatal
#define logger_fatal printf
#undef logger_panic
#define logger_panic printf
extern void __attribute__((format(printf,3,4))) \
dummy_debug(int, int, const char*, ...);
#undef logger_debug
#define logger_debug dummy_debug
#endif

View File

@ -0,0 +1,3 @@
#!/bin/sh
valgrind --tool=memcheck --leak-check=yes -v ./json

View File

@ -0,0 +1,3 @@
base_path = ../../..
PROG = json
include ../../Makefile.in

View File

@ -0,0 +1,58 @@
#include "stdafx.h"
int main()
{
const char* sss =
"{\r\n"
" \"data\" : \"dGVzdHFxcQ==\", \r\n"
" \"receiver_id\" : [\r\n"
" \"1442365683\"\r\n"
" ],\r\n"
" \"extra\" : \"\",\r\n"
" \"group_id\" : \"\"\r\n"
"}\r\n";
acl::json json;
const char* ptr = json.update(sss);
const std::vector<acl::json_node*> &receiver =
json.getElementsByTagName("receiver_id");
std::vector<acl::json_node*>::const_iterator cit;
for (cit = receiver.begin(); cit != receiver.end(); ++cit)
{
acl::json_node* node = (*cit)->get_obj();
if (node == NULL)
{
printf("get_obj null error\r\n");
return 1;
}
printf("--------list all elements of the array --------\r\n");
acl::json_node* child = node->first_child();
while (child)
{
const char* txt = child->get_text();
if (txt && *txt)
printf("%s\r\n", txt);
else
printf("null\r\n");
child = node->next_child();
}
printf("----------------- list end --------------------\r\n");
}
printf("-------------------------------------------------------\r\n");
printf("%s\r\n", sss);
printf("-------------------------------------------------------\r\n");
printf("json finish: %s, left char: %s\r\n",
json.finish() ? "yes" : "no", ptr);
printf(">>>to string: %s\r\n", json.to_string().c_str());
return 0;
}

View File

@ -0,0 +1,271 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="json11"
ProjectGUID="{56199633-C345-4733-8292-A4F2D86AA847}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;VC2003"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="lib_acl_vc2003d.lib ws2_32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;VC2003"
RuntimeLibrary="0"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib wsock32.lib lib_acl_vc2003.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="DebugDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;VC2003;ACL_CPP_DLL;ACL_DLL"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="ReleaseDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;VC2003"
RuntimeLibrary="0"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib wsock32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Ô´Îļþ"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\json.cpp">
</File>
<File
RelativePath=".\stdafx.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="DebugDll|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="ReleaseDll|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Í·Îļþ"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\stdafx.h">
</File>
</Filter>
<Filter
Name="×ÊÔ´Îļþ"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
<File
RelativePath=".\ReadMe.txt">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,8 @@
// stdafx.cpp : 只包括标准包含文件的源文件
// json.pch 将成为预编译头
// stdafx.obj 将包含预编译类型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中
//引用任何所需的附加头文件,而不是在此文件中引用

View File

@ -0,0 +1,41 @@
// stdafx.h : 标准系统包含文件的包含文件,
// 或是常用但不常更改的项目特定的包含文件
//
#pragma once
//#include <iostream>
//#include <tchar.h>
// TODO: 在此处引用程序要求的附加头文件
#include "acl_cpp/lib_acl.hpp"
#include "lib_acl.h"
#ifdef WIN32
#include <io.h>
#define snprintf _snprintf
#endif
#ifdef DEBUG
// 以下宏定义用来帮助检查变参中的参数类型是否合法
#undef logger
#define logger printf
#undef logger_error
#define logger_error printf
#undef logger_warn
#define logger_warn printf
#undef logger_fatal
#define logger_fatal printf
#undef logger_panic
#define logger_panic printf
extern void __attribute__((format(printf,3,4))) \
dummy_debug(int, int, const char*, ...);
#undef logger_debug
#define logger_debug dummy_debug
#endif

View File

@ -0,0 +1,3 @@
#!/bin/sh
valgrind --tool=memcheck --leak-check=yes -v ./json

View File

@ -66,7 +66,7 @@ static void test(void)
{
printf("%s(%d): result should:\r\n%s\r\n",
__FUNCTION__, __LINE__, default_result);
return;
exit (1);
}
else
printf("%s(%d): Build json OK!\r\n", __FUNCTION__, __LINE__);
@ -170,6 +170,7 @@ static void test(void)
__FUNCTION__, __LINE__, json1.to_string().c_str());
printf(">>%s(%d)->json3:\r\n%s\r\n",
__FUNCTION__, __LINE__, json3.to_string().c_str());
exit (1);
}
printf("-------------------------------------------------\r\n");
}

View File

@ -49,7 +49,7 @@ static void test(bool once)
printf(">>>src:\r\n%s\r\n>>>dst:\r\n%s\r\n",
default_data, json.to_string().c_str());
printf("%s(%d): build json ERROR!\r\n", __FUNCTION__, __LINE__);
return;
exit (1);
}
printf("-------------------------------------------------\r\n");
@ -96,7 +96,7 @@ static void test(bool once)
else
{
printf(">>>%s(%d)->ERROR not parent\r\n", __FUNCTION__, __LINE__);
return;
exit (1);
}
printf("-------------------------------------------------\r\n");

View File

@ -98,7 +98,7 @@ int main(int argc, char* argv[])
printf("====================================================================\r\n");
printf("ERROR, not equal, item: %d\r\n", (int) i);
print(json);
return 0;
exit (1);
}
else
{

View File

@ -0,0 +1,3 @@
base_path = ../../..
PROG = json
include ../../Makefile.in

View File

@ -0,0 +1,49 @@
#include "stdafx.h"
int main()
{
const char* sss =
"["
"{\"DataKey\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": null}, "
"{\"DataKey\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": null}"
"]";
acl::json json3(sss);
const char* tags = "DataValue";
printf("----------------------------------------------------\r\n");
printf(">>%s\r\n", sss);
const acl::string& s = json3.to_string();
printf(">>%s\r\n", s.c_str());
if (json3.to_string() == sss)
printf("parse OK, enter any key to continue\r\n");
else
{
printf("parse ERROR\r\n");
return 1;
}
getchar();
printf("----------------------------------------------------\r\n");
acl::json_node* iter = json3.first_node();
while (iter)
{
const char* tag = iter->tag_name();
const char* txt = iter->get_text();
printf("tag: %s, txt: %s\r\n", tag ? tag : "null", txt ? txt : "null");
if (txt)
iter->set_text("hello");
printf("tag: %s, txt: %s\r\n", tag ? tag : "null", txt ? txt : "null");
iter = json3.next_node();
}
printf("----------------------------------------------------\r\n");
const std::vector<acl::json_node*>& nodes = json3.getElementsByTags(tags);
if (nodes.empty() == false)
printf(">>>%s\r\n", nodes[0]->to_string().c_str());
return 0;
}

View File

@ -0,0 +1,271 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="json8"
ProjectGUID="{56199633-C345-4733-8292-A4F2D86AA847}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;VC2003"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="lib_acl_vc2003d.lib ws2_32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;VC2003"
RuntimeLibrary="0"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib wsock32.lib lib_acl_vc2003.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="DebugDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;VC2003;ACL_CPP_DLL;ACL_DLL"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="ReleaseDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;VC2003"
RuntimeLibrary="0"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib wsock32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Ô´Îļþ"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\json.cpp">
</File>
<File
RelativePath=".\stdafx.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="DebugDll|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="ReleaseDll|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Í·Îļþ"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\stdafx.h">
</File>
</Filter>
<Filter
Name="×ÊÔ´Îļþ"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
<File
RelativePath=".\ReadMe.txt">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,8 @@
// stdafx.cpp : 只包括标准包含文件的源文件
// json.pch 将成为预编译头
// stdafx.obj 将包含预编译类型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中
//引用任何所需的附加头文件,而不是在此文件中引用

View File

@ -0,0 +1,41 @@
// stdafx.h : 标准系统包含文件的包含文件,
// 或是常用但不常更改的项目特定的包含文件
//
#pragma once
//#include <iostream>
//#include <tchar.h>
// TODO: 在此处引用程序要求的附加头文件
#include "acl_cpp/lib_acl.hpp"
#include "lib_acl.h"
#ifdef WIN32
#include <io.h>
#define snprintf _snprintf
#endif
#ifdef DEBUG
// 以下宏定义用来帮助检查变参中的参数类型是否合法
#undef logger
#define logger printf
#undef logger_error
#define logger_error printf
#undef logger_warn
#define logger_warn printf
#undef logger_fatal
#define logger_fatal printf
#undef logger_panic
#define logger_panic printf
extern void __attribute__((format(printf,3,4))) \
dummy_debug(int, int, const char*, ...);
#undef logger_debug
#define logger_debug dummy_debug
#endif

View File

@ -0,0 +1,3 @@
#!/bin/sh
valgrind --tool=memcheck --leak-check=yes -v ./json

View File

@ -0,0 +1,3 @@
base_path = ../../..
PROG = json
include ../../Makefile.in

View File

@ -0,0 +1,54 @@
#include "stdafx.h"
int main()
{
#if 1
const char* sss =
"[{\"DataKey1\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": \"null\"},\r\n"
"{\"DataKey2\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": \"null\"},\r\n"
"{\"member\": [25, 26, 27, 28, 29, true, false]},\r\n"
"[\"string\", true, false, 100, 200, 300, null, null],\r\n"
"{\"hello world\": true, \"name\": null, \"age\": 25}]\r\n"
"{\"hello\" : \"world\"} \r\n";
#else
const char* sss = "{\"name\": \"100\"}";
#endif
acl::json json;
const char* ptr = json.update(sss);
printf("-------------------------------------------------------\r\n");
printf("%s\r\n", sss);
printf("-------------------------------------------------------\r\n");
printf("json finish: %s, left char: %s\r\n",
json.finish() ? "yes" : "no", ptr);
printf(">>>to string: %s\r\n", json.to_string().c_str());
const char* ss =
"[{\"DataKey1\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": \"null\"}, "
"{\"DataKey2\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": \"null\"}, "
"{\"member\": [25, 26, 27, 28, 29, true, false]}, "
"[\"string\", true, false, 100, 200, 300, null, null], "
"{\"hello world\": true, \"name\": null, \"age\": 25}]";
printf("-------------------------------------------------------\r\n");
if (json.to_string() == ss)
printf("All OK\r\n\r\n");
else
{
printf("Error\r\n");
printf("-------------------------------------------------------\r\n");
printf("%s\r\n", ss);
printf("-------------------------------------------------------\r\n");
printf("%s\r\n", json.to_string().c_str());
printf("\r\n");
exit (1);
}
return 0;
}

View File

@ -0,0 +1,271 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="json9"
ProjectGUID="{56199633-C345-4733-8292-A4F2D86AA847}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;VC2003"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="lib_acl_vc2003d.lib ws2_32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;VC2003"
RuntimeLibrary="0"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib wsock32.lib lib_acl_vc2003.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="DebugDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;VC2003;ACL_CPP_DLL;ACL_DLL"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/json.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="ReleaseDll|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\include;..\..\..\..\lib_acl\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;VC2003"
RuntimeLibrary="0"
UsePrecompiledHeader="3"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib wsock32.lib"
OutputFile="$(OutDir)/json.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib;..\..\..\..\dist\lib\win32"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Ô´Îļþ"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\json.cpp">
</File>
<File
RelativePath=".\stdafx.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="DebugDll|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
<FileConfiguration
Name="ReleaseDll|Win32">
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Í·Îļþ"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\stdafx.h">
</File>
</Filter>
<Filter
Name="×ÊÔ´Îļþ"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
<File
RelativePath=".\ReadMe.txt">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,8 @@
// stdafx.cpp : 只包括标准包含文件的源文件
// json.pch 将成为预编译头
// stdafx.obj 将包含预编译类型信息
#include "stdafx.h"
// TODO: 在 STDAFX.H 中
//引用任何所需的附加头文件,而不是在此文件中引用

View File

@ -0,0 +1,41 @@
// stdafx.h : 标准系统包含文件的包含文件,
// 或是常用但不常更改的项目特定的包含文件
//
#pragma once
//#include <iostream>
//#include <tchar.h>
// TODO: 在此处引用程序要求的附加头文件
#include "acl_cpp/lib_acl.hpp"
#include "lib_acl.h"
#ifdef WIN32
#include <io.h>
#define snprintf _snprintf
#endif
#ifdef DEBUG
// 以下宏定义用来帮助检查变参中的参数类型是否合法
#undef logger
#define logger printf
#undef logger_error
#define logger_error printf
#undef logger_warn
#define logger_warn printf
#undef logger_fatal
#define logger_fatal printf
#undef logger_panic
#define logger_panic printf
extern void __attribute__((format(printf,3,4))) \
dummy_debug(int, int, const char*, ...);
#undef logger_debug
#define logger_debug dummy_debug
#endif

View File

@ -0,0 +1,3 @@
#!/bin/sh
valgrind --tool=memcheck --leak-check=yes -v ./json

View File

@ -15,7 +15,7 @@ static void build_html(void)
.set_subject("主题:中国人民银行!")
.add_header("X-Forward-For", "<zsx@263.net>");
const char* html = "<html><body>中国人民银行 HTML 格式</body></html>";
const char* html = "<html><body><B><font color='red'>中国人民银行 HTML 格式</font></B></body></html>";
acl::mail_body body("gbk");
body.set_html(html, strlen(html));
message.set_body(body);
@ -27,7 +27,7 @@ static void build_html(void)
printf("compose %s ok\r\n", filepath);
}
static void build_text(void)
static void build_plain(void)
{
acl::mail_message message("gbk");
@ -38,12 +38,12 @@ static void build_text(void)
.add_cc("\"郑树新3\" <zsx1@163.com>; \"郑树新4\" <zsx2@163.com>")
.set_subject("主题:中国人民银行!");
const char* text = "中国人民银行 TEXT 格式";
const char* plain = "中国人民银行 TEXT 格式";
acl::mail_body body("gbk");
body.set_text(text, strlen(text));
body.set_plain(plain, strlen(plain));
message.set_body(body);
const char* filepath = "./text.eml";
const char* filepath = "./plain.eml";
if (message.save_to(filepath) == false)
printf("compose %s error: %s\r\n", filepath, acl::last_serror());
else
@ -63,10 +63,10 @@ static void build_alternative(void)
message.add_attachment("main.cpp", "text/plain")
.add_attachment("Makefile", "text/plain");
const char* text = "中国人民银行 TEXT 格式";
const char* html = "<html><body>中国人民银行 HTML 格式</body></html>";
const char* plain = "中国人民银行 TEXT 格式";
const char* html = "<html><body><B><font color='red'>中国人民银行 HTML 格式</font></B></body></html>";
acl::mail_body body("gbk");
body.set_alternative(html, strlen(html), text, strlen(text));
body.set_alternative(html, strlen(html), plain, strlen(plain));
message.set_body(body);
const char* filepath = "./alternative.eml";
@ -87,12 +87,12 @@ static void build_relative(void)
.add_cc("\"郑树新3\" <zsx1@163.com>; \"郑树新4\" <zsx2@163.com>")
.set_subject("主题:中国人民银行!");
const char* text_file = "./var/text.txt";
const char* plain_file = "./var/plain.txt";
const char* html_file = "./var/html.txt";
acl::string text, html;
if (acl::ifstream::load(text_file, &text) == false)
acl::string plain, html;
if (acl::ifstream::load(plain_file, &plain) == false)
{
printf("load %s error %s\r\n", text_file, acl::last_serror());
printf("load %s error %s\r\n", plain_file, acl::last_serror());
return;
}
if (acl::ifstream::load(html_file, &html) == false)
@ -108,72 +108,72 @@ static void build_relative(void)
acl::mail_attach* attach;
attach = new((char*) dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/spacer.gif", "image/gif", "gbk");
acl::mail_attach("./var/email1/img/spacer.gif", "image/gif", "gbk");
attach->set_content_id("__0@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/tl.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/tl.jpg", "image/jpg", "gbk");
attach->set_content_id("__1@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/t_bg.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/t_bg.jpg", "image/jpg", "gbk");
attach->set_content_id("__2@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/tr.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/tr.jpg", "image/jpg", "gbk");
attach->set_content_id("__3@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/m_bgl.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/m_bgl.jpg", "image/jpg", "gbk");
attach->set_content_id("__4@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/m.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/m.jpg", "image/jpg", "gbk");
attach->set_content_id("__5@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/m_bgr.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/m_bgr.jpg", "image/jpg", "gbk");
attach->set_content_id("__6@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/dl.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/dl.jpg", "image/jpg", "gbk");
attach->set_content_id("__7@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/d_bg.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/d_bg.jpg", "image/jpg", "gbk");
attach->set_content_id("__8@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/dr.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/dr.jpg", "image/jpg", "gbk");
attach->set_content_id("__9@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/t_ml.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/t_ml.jpg", "image/jpg", "gbk");
attach->set_content_id("__10@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/m_tl.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/m_tl.jpg", "image/jpg", "gbk");
attach->set_content_id("__11@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/m_dr.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/m_dr.jpg", "image/jpg", "gbk");
attach->set_content_id("__12@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/img/d_mr.jpg", "image/jpg", "gbk");
acl::mail_attach("./var/email1/img/d_mr.jpg", "image/jpg", "gbk");
attach->set_content_id("__13@Foxmail.net");
attachments.push_back(attach);
@ -181,7 +181,7 @@ static void build_relative(void)
acl::mail_body body("gbk");
body.set_relative(html.c_str(), html.size(),
text.c_str(), text.size(), attachments);
plain.c_str(), plain.size(), attachments);
message.set_body(body);
const char* filepath = "./relative.eml";
@ -199,10 +199,278 @@ static void build_relative(void)
dbuf->destroy();
}
static void build_mixed_relative(void)
{
acl::mail_message message("gbk");
message.set_from("zsxxsz@263.net", "郑树新")
.set_sender("zsx1@263.net")
.set_reply_to("zsx2@263.net")
.add_to("\"郑树新1\" <zsx1@sina.com>; \"郑树新2\" <zsx2@sina.com>")
.add_cc("\"郑树新3\" <zsx1@163.com>; \"郑树新4\" <zsx2@163.com>")
.set_subject("主题:中国人民银行!");
message.add_attachment("main.cpp", "text/plain")
.add_attachment("Makefile", "text/plain");
const char* plain_file = "./var/email1/plain.txt";
const char* html_file = "./var/email1/html.txt";
acl::string plain, html;
if (acl::ifstream::load(plain_file, &plain) == false)
{
printf("load %s error %s\r\n", plain_file, acl::last_serror());
return;
}
if (acl::ifstream::load(html_file, &html) == false)
{
printf("load %s error %s\r\n", html_file, acl::last_serror());
return;
}
/////////////////////////////////////////////////////////////////////
acl::dbuf_pool* dbuf = new acl::dbuf_pool;
std::vector<acl::mail_attach*> attachments;
acl::mail_attach* attach;
attach = new((char*) dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/spacer.gif", "image/gif", "gbk");
attach->set_content_id("__0@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/tl.jpg", "image/jpg", "gbk");
attach->set_content_id("__1@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/t_bg.jpg", "image/jpg", "gbk");
attach->set_content_id("__2@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/tr.jpg", "image/jpg", "gbk");
attach->set_content_id("__3@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/m_bgl.jpg", "image/jpg", "gbk");
attach->set_content_id("__4@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/m.jpg", "image/jpg", "gbk");
attach->set_content_id("__5@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/m_bgr.jpg", "image/jpg", "gbk");
attach->set_content_id("__6@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/dl.jpg", "image/jpg", "gbk");
attach->set_content_id("__7@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/d_bg.jpg", "image/jpg", "gbk");
attach->set_content_id("__8@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/dr.jpg", "image/jpg", "gbk");
attach->set_content_id("__9@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/t_ml.jpg", "image/jpg", "gbk");
attach->set_content_id("__10@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/m_tl.jpg", "image/jpg", "gbk");
attach->set_content_id("__11@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/m_dr.jpg", "image/jpg", "gbk");
attach->set_content_id("__12@Foxmail.net");
attachments.push_back(attach);
attach = new(dbuf->dbuf_alloc(sizeof(acl::mail_attach)))
acl::mail_attach("./var/email1/img/d_mr.jpg", "image/jpg", "gbk");
attach->set_content_id("__13@Foxmail.net");
attachments.push_back(attach);
/////////////////////////////////////////////////////////////////////
acl::mail_body body("gbk");
body.set_relative(html.c_str(), html.size(),
plain.c_str(), plain.size(), attachments);
message.set_body(body);
const char* filepath = "./mixed_relative.eml";
if (message.save_to(filepath) == false)
printf("compose %s error: %s\r\n", filepath, acl::last_serror());
else
printf("compose %s ok\r\n", filepath);
// 调用所有动态对象的析构函数
std::vector<acl::mail_attach*>::iterator it = attachments.begin();
for (; it != attachments.end(); ++it)
(*it)->~mail_attach();
// 一次性释放前面动态分配的内存
dbuf->destroy();
}
static void build_mixed_relative2(void)
{
acl::mail_message message("gbk");
message.set_from("zsxxsz@263.net", "郑树新")
.set_sender("zsx1@263.net")
.set_reply_to("zsx2@263.net")
.add_to("\"郑树新1\" <zsx1@sina.com>; \"郑树新2\" <zsx2@sina.com>")
.add_cc("\"郑树新3\" <zsx1@163.com>; \"郑树新4\" <zsx2@163.com>")
.set_subject("主题:中国人民银行!");
message.add_attachment("main.cpp", "text/plain")
.add_attachment("var/email2/architecture.pptx", "application/ms-pptx");
const char* plain_file = "./var/email2/plain.txt";
const char* html_file = "./var/email2/html.txt";
acl::string plain, html;
if (acl::ifstream::load(plain_file, &plain) == false)
{
printf("load %s error %s\r\n", plain_file, acl::last_serror());
return;
}
if (acl::ifstream::load(html_file, &html) == false)
{
printf("load %s error %s\r\n", html_file, acl::last_serror());
return;
}
/////////////////////////////////////////////////////////////////////
std::vector<acl::mail_attach*> attachments;
acl::mail_attach* attach = new acl::mail_attach("./var/email2/img/q.JPG", "image/jpg", "gbk");
attach->set_content_id("111CF2FD1A884FF9BD0A2B735ED773F3@ikerf954f96714");
attachments.push_back(attach);
/////////////////////////////////////////////////////////////////////
acl::mail_body body("gbk");
body.set_relative(html.c_str(), html.size(),
plain.c_str(), plain.size(), attachments);
message.set_body(body);
const char* filepath = "./mixed_relative2.eml";
if (message.save_to(filepath) == false)
printf("compose %s error: %s\r\n", filepath, acl::last_serror());
else
printf("compose %s ok\r\n", filepath);
delete attach;
}
static void build_mixed(void)
{
acl::mail_message message("gbk");
message.set_from("zsxxsz@263.net", "郑树新")
.set_sender("zsx1@263.net")
.set_reply_to("zsx2@263.net")
.add_to("\"郑树新1\" <zsx1@sina.com>; \"郑树新2\" <zsx2@sina.com>")
.add_cc("\"郑树新3\" <zsx1@163.com>; \"郑树新4\" <zsx2@163.com>")
.set_subject("主题:中国人民银行!");
message.add_attachment("main.cpp", "text/plain")
.add_attachment("var/email2/architecture.pptx", "application/ms-pptx");
const char* filepath = "./mixed.eml";
if (message.save_to(filepath) == false)
printf("compose %s error: %s\r\n", filepath, acl::last_serror());
else
printf("compose %s ok\r\n", filepath);
}
static void build_mixed_html(void)
{
acl::mail_message message("gbk");
message.set_from("zsxxsz@263.net", "郑树新")
.set_sender("zsx1@263.net")
.set_reply_to("zsx2@263.net")
.add_to("\"郑树新1\" <zsx1@sina.com>; \"郑树新2\" <zsx2@sina.com>")
.add_cc("\"郑树新3\" <zsx1@163.com>; \"郑树新4\" <zsx2@163.com>")
.set_subject("主题:中国人民银行!");
message.add_attachment("main.cpp", "text/plain")
.add_attachment("var/email2/architecture.pptx", "application/ms-pptx");
const char* html_file = "./var/html.txt";
acl::string html;
if (acl::ifstream::load(html_file, &html) == false)
{
printf("load %s error %s\r\n", html_file, acl::last_serror());
return;
}
/////////////////////////////////////////////////////////////////////
acl::mail_body body("gbk");
body.set_html(html.c_str(), html.size());
message.set_body(body);
const char* filepath = "./mixed_html.eml";
if (message.save_to(filepath) == false)
printf("compose %s error: %s\r\n", filepath, acl::last_serror());
else
printf("compose %s ok\r\n", filepath);
}
static void build_mixed_plain(void)
{
acl::mail_message message("gbk");
message.set_from("zsxxsz@263.net", "郑树新")
.set_sender("zsx1@263.net")
.set_reply_to("zsx2@263.net")
.add_to("\"郑树新1\" <zsx1@sina.com>; \"郑树新2\" <zsx2@sina.com>")
.add_cc("\"郑树新3\" <zsx1@163.com>; \"郑树新4\" <zsx2@163.com>")
.set_subject("主题:中国人民银行!");
message.add_attachment("main.cpp", "text/plain")
.add_attachment("var/email2/architecture.pptx", "application/ms-pptx");
const char* plain_file = "./var/plain.txt";
acl::string plain;
if (acl::ifstream::load(plain_file, &plain) == false)
{
printf("load %s error %s\r\n", plain_file, acl::last_serror());
return;
}
/////////////////////////////////////////////////////////////////////
acl::mail_body body("gbk");
body.set_html(plain.c_str(), plain.size());
message.set_body(body);
const char* filepath = "./mixed_plain.eml";
if (message.save_to(filepath) == false)
printf("compose %s error: %s\r\n", filepath, acl::last_serror());
else
printf("compose %s ok\r\n", filepath);
}
static void usage(const char* procname)
{
printf("usage: %s -h [help]\r\n"
"-t mime_type[1: html, 2: text, 3: alternative, 4: relative\r\n",
"-t mime_type[1: html, 2: plain, 3: alternative, 4: relative, 5: mixed_relative, 6: mixed_relative2, 7: mixed, 8: mixed_html, 9: mixed_plain\r\n",
procname);
#if defined(_WIN32) || defined(_WIN64)
@ -216,6 +484,8 @@ int main(int argc, char* argv[])
int ch;
int mime_type = 0;
acl::log::stdout_open(true);
while ((ch = getopt(argc, argv, "ht:")) > 0)
{
switch (ch)
@ -234,17 +504,32 @@ int main(int argc, char* argv[])
if (mime_type == 1)
build_html();
else if (mime_type == 2)
build_text();
build_plain();
else if (mime_type == 3)
build_alternative();
else if (mime_type == 4)
build_relative();
else if (mime_type == 5)
build_mixed_relative();
else if (mime_type == 6)
build_mixed_relative2();
else if (mime_type == 7)
build_mixed();
else if (mime_type == 8)
build_mixed_html();
else if (mime_type == 9)
build_mixed_plain();
else
{
build_html();
build_text();
build_plain();
build_mixed_html();
build_mixed_plain();
build_alternative();
build_relative();
build_mixed_relative();
build_mixed_relative2();
build_mixed();
}
#if defined(_WIN32) || defined(_WIN64)

View File

@ -0,0 +1,100 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o = "urn:schemas-microsoft-com:office:office"><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<STYLE type=text/css>BODY {
PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px
}
BLOCKQUOTE {
MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em
}
OL {
MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
UL {
MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
</STYLE>
<META content="MSHTML 6.00.2900.6003" name=GENERATOR></HEAD>
<BODY style="MARGIN-TOP: 0px; MARGIN-LEFT: 0px; MARGIN-RIGHT: 0px"><!-- 52_302903_e11415f126781bf -->
<TABLE id=Table_01
style="BACKGROUND: #fff; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif"
cellSpacing=0 cellPadding=0 width="99.99%" border=0>
<TBODY>
<TR>
<TD vAlign=top background=cid:__1@Foxmail.net><IMG height=1
src="cid:__0@Foxmail.net" width=49></TD>
<TD vAlign=top background=cid:__2@Foxmail.net>
<TABLE cellSpacing=0 cellPadding=0 width=87 border=0>
<TBODY>
<TR>
<TD background=cid:__10@Foxmail.net><IMG height=50
src="cid:__0@Foxmail.net" width=87></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top background=cid:__3@Foxmail.net><IMG height=50
src="cid:__0@Foxmail.net" width=84></TD></TR>
<TR>
<TD vAlign=top align=right background=cid:__4@Foxmail.net>
<TABLE cellSpacing=0 cellPadding=0 width=50 border=0>
<TBODY>
<TR>
<TD background=cid:__11@Foxmail.net><IMG height=134
src="cid:__0@Foxmail.net" width=49></TD></TR></TBODY></TABLE></TD>
<TD
style="PADDING-RIGHT: 50px; BACKGROUND-POSITION: right bottom; PADDING-LEFT: 40px; PADDING-BOTTOM: 60px; PADDING-TOP: 40px; BACKGROUND-REPEAT: no-repeat; HEIGHT: 300px"
vAlign=top width="100%" background=cid:__5@Foxmail.net bgColor=#fffcf3>
<TABLE style="MARGIN-TOP: 0px; cellpadding: 0px; cellspacing: 0px"
width="100%" valign="top">
<TBODY>
<TR>
<TD style="LINE-HEIGHT: 160%">
<DIV
style="WIDTH: 100%; WORD-BREAK: break-all; WHITE-SPACE: normal"><FONT
face=Verdana color=#000080 size=2>
<DIV>
<DIV><FONT size=3></FONT></DIV>&nbsp;</DIV>
<DIV><FONT color=#c0c0c0>
<DIV><FONT color=#000000 size=4>各位同学:</FONT></DIV>
<DIV><FONT color=#000000 size=4></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000
size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;本月考勤统计日为20日烦请各位同学在19日下班之前尽快将个人需要申诉的事由找部门领导审批通</FONT></DIV>
<DIV><FONT color=#000000 size=4></FONT>&nbsp;</DIV>
<DIV><FONT color=#000000 size=4>过。</FONT><FONT color=#ff0000
size=4><STRONG>逾期不再修改考勤。</STRONG></FONT></DIV>
<DIV><FONT color=#000000 size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</FONT></DIV>
<DIV><FONT color=#000000 size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
另烦请本月有请年假、事假、病假的同学补发邮件给部门领导审批并转发给行政部。谢谢各位同学配合。</FONT></DIV><FONT
color=#000000 size=4></FONT>
<DIV><FONT color=#c0c0c0><FONT color=#000000
size=4></FONT></FONT>&nbsp;</DIV>
<DIV><FONT color=#c0c0c0><FONT color=#ff0000
size=4><STRONG>如在考勤日未收到以上邮件,我部门将按照考勤严格执行不再做任何修改。</STRONG></FONT></FONT></DIV>
<DIV><FONT color=#c0c0c0><STRONG><FONT color=#ff0000
size=4></FONT></STRONG></FONT>&nbsp;</DIV>
<DIV><FONT color=#c0c0c0><STRONG><FONT color=#ff0000
size=4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<FONT
color=#000000>艾克赛乐行政部</FONT></FONT></STRONG></FONT><BR>2010-09-17
</FONT></DIV></DIV>
<DIV align=left>
<HR style="WIDTH: 122px; HEIGHT: 2px" align=left SIZE=2>
</DIV>
<DIV><FONT color=#c0c0c0><SPAN>行政部</SPAN>
</DIV></FONT></DIV></FONT></TD></TR></TBODY></TABLE></TD>
<TD vAlign=bottom background=cid:__6@Foxmail.net>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD background=cid:__12@Foxmail.net><IMG height=357
src="cid:__0@Foxmail.net" width=84></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD vAlign=top background=cid:__7@Foxmail.net><IMG height=1
src="cid:__0@Foxmail.net" width=49></TD>
<TD vAlign=top align=right background=cid:__8@Foxmail.net>
<TABLE cellSpacing=0 cellPadding=0 width=125 border=0>
<TBODY>
<TR>
<TD background=cid:__13@Foxmail.net><IMG height=58
src="cid:__0@Foxmail.net" width=125></TD></TR></TBODY></TABLE></TD>
<TD vAlign=top background=cid:__9@Foxmail.net><IMG height=58
src="cid:__0@Foxmail.net" width=84></TD></TR></TBODY></TABLE></BODY></HTML>

Binary file not shown.

After

Width:  |  Height:  |  Size: 682 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

Some files were not shown because too many files have changed in this diff Show More