增加了 mime 邮件解析的几个方法;修改 lib_acl_cpp/Makefile.db

This commit is contained in:
zsxxsz 2015-03-22 17:25:48 +08:00
parent 972b011c3d
commit be60e809c1
6 changed files with 88 additions and 30 deletions

Binary file not shown.

View File

@ -95,6 +95,7 @@ OBJS_DST = $(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/*.cpp)
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/mime/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/mime/internal/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/connpool/*.cpp))) \
$(patsubst %.cpp, $(OBJ_PATH_DST)/%.o, $(notdir $(wildcard src/redis/*.cpp)))
OBJS_DEF = $(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/stdlib/*.cpp))) \
@ -112,6 +113,7 @@ OBJS_DEF = $(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/*.cp
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/mime/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/mime/internal/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/connpool/*.cpp))) \
$(patsubst %.cpp, $(DEF_PATH_DST)/%.inc, $(notdir $(wildcard src/redis/*.cpp)))
###########################################################
.PHONY = static shared clean
@ -166,7 +168,7 @@ shared: depends $(OBJS_DST)
depends: $(OBJS_DEF)
# src
## for src
$(OBJ_PATH_DST)/%.o: ./src/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/stdlib/%.cpp
@ -197,7 +199,12 @@ $(OBJ_PATH_DST)/%.o: ./src/connpool/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/mime/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/mime/internal/%.cpp
$(COMPILE_OBJ)
$(OBJ_PATH_DST)/%.o: ./src/redis/%.cpp
$(COMPILE_OBJ)
## for depend
$(DEF_PATH_DST)/%.inc: ./src/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/stdlib/%.cpp
@ -228,13 +235,10 @@ $(DEF_PATH_DST)/%.inc: ./src/connpool/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/mime/%.cpp
$(CREATE_DEF)
# mime
$(OBJ_PATH_DST)/%.o: ./src/mime/internal/%.cpp
$(COMPILE_OBJ)
$(DEF_PATH_DST)/%.inc: ./src/mime/internal/%.cpp
$(CREATE_DEF)
$(DEF_PATH_DST)/%.inc: ./src/redis/%.cpp
$(CREATE_DEF)
clean:
rm -f $(LIB_PATH_DST)/lib_acl_cpp.a

View File

@ -12,29 +12,36 @@
#define MIME_CTYPE_MULTIPART 3
#define MIME_CTYPE_IMAGE 4
#define MIME_CTYPE_APPLICATION 5
#define MIME_CTYPE_MIN MIME_CTYPE_OTHER
#define MIME_CTYPE_MAX MIME_CTYPE_APPLICATION
#define MIME_STYPE_OTHER 0
#define MIME_STYPE_PLAIN 1
#define MIME_STYPE_HTML 2
#define MIME_STYPE_RFC822 3
#define MIME_STYPE_PARTIAL 4
#define MIME_STYPE_EXTERN_BODY 5
#define MIME_STYPE_JPEG 6
#define MIME_STYPE_GIF 7
#define MIME_STYPE_BMP 8
#define MIME_STYPE_PNG 9
#define MIME_STYPE_OCTET_STREAM 10
#define MIME_STYPE_MIXED 11
#define MIME_STYPE_ALTERNATIVE 12
#define MIME_STYPE_RELATED 13
#define MIME_STYPE_OTHER 6
#define MIME_STYPE_PLAIN 7
#define MIME_STYPE_HTML 8
#define MIME_STYPE_RFC822 9
#define MIME_STYPE_PARTIAL 10
#define MIME_STYPE_EXTERN_BODY 11
#define MIME_STYPE_JPEG 12
#define MIME_STYPE_GIF 13
#define MIME_STYPE_BMP 14
#define MIME_STYPE_PNG 15
#define MIME_STYPE_OCTET_STREAM 16
#define MIME_STYPE_MIXED 17
#define MIME_STYPE_ALTERNATIVE 18
#define MIME_STYPE_RELATED 19
#define MIME_STYPE_MIN MIME_STYPE_OTHER
#define MIME_STYPE_MAX MIME_STYPE_RELATED
#define MIME_ENC_OTHER 0
#define MIME_ENC_QP 1 /* encoding + domain */
#define MIME_ENC_BASE64 2 /* encoding + domain */
#define MIME_ENC_7BIT 7 /* domain only */
#define MIME_ENC_8BIT 8 /* domain only */
#define MIME_ENC_BINARY 9 /* domain only */
#define MIME_ENC_UUCODE 10 /* encoding + domain */
#define MIME_ENC_XXCODE 11 /* encoding + domain */
#define MIME_ENC_OTHER 20
#define MIME_ENC_QP 21 /* encoding + domain */
#define MIME_ENC_BASE64 22 /* encoding + domain */
#define MIME_ENC_7BIT 23 /* domain only */
#define MIME_ENC_8BIT 24 /* domain only */
#define MIME_ENC_BINARY 25 /* domain only */
#define MIME_ENC_UUCODE 26 /* encoding + domain */
#define MIME_ENC_XXCODE 27 /* encoding + domain */
#define MIME_ENC_MIN MIME_ENC_OTHER
#define MIME_ENC_MAX MIME_ENC_XXCODE
#define MIME_MIN MIME_CTYPE_OTHER
#define MIME_MAX MIME_ENC_MAX

View File

@ -1,6 +1,7 @@
#pragma once
#include "acl_cpp/acl_cpp_define.hpp"
#include <stdlib.h>
#include <map>
#include "acl_cpp/stdlib/string.hpp"
struct MIME_NODE;
@ -117,6 +118,12 @@ public:
*/
const char* header_value(const char* name) const;
/**
*
* @return {const std::map<string, string>&}
*/
const std::map<string, string>& get_headers() const;
/**
*
* @param out {pipe_manager&}
@ -241,6 +248,7 @@ protected:
char m_toCharset[32];
off_t m_bodyBegin;
off_t m_bodyEnd;
std::map<string, string>* m_headers_;
const MIME_NODE* m_pMimeNode;
mime_node* m_pParent;
};

View File

@ -283,6 +283,22 @@ int main(void)
}
////////////////////////////////////////////////////////////////////
printf("\r\n");
json.reset();
buf.clear();
json.get_root().add_text("name", "value");
json.build_json(buf);
printf("%s\r\n", buf.c_str());
s = "{\"name\": \"value\"}";
if (strcmp(s, buf.c_str()) != 0)
{
printf("%s\r\n", s);
printf("%s(%d): Error\r\n", __FUNCTION__, __LINE__);
return 1;
}
////////////////////////////////////////////////////////////////////
printf("\r\n");

View File

@ -19,10 +19,10 @@ mime_node::mime_node(const char* emailFile, const MIME_NODE* node,
const char* toCharset /* = "gb2312" */,
off_t off /* = 0 */)
: m_name(128)
, m_headers_(NULL)
, m_pMimeNode(node)
, m_pParent(NULL)
{
m_pMimeNode = node;
if (emailFile)
m_emailFile = emailFile;
m_enableDecode = enableDecode;
@ -57,6 +57,7 @@ mime_node::mime_node(const char* emailFile, const MIME_NODE* node,
mime_node::~mime_node()
{
delete m_headers_;
delete m_pParent;
}
@ -74,6 +75,28 @@ const char* mime_node::header_value(const char* name) const
return (NULL);
}
const std::map<string, string>& mime_node::get_headers() const
{
if (m_headers_ != NULL)
return *m_headers_;
const_cast<mime_node*> (this)->m_headers_ =
NEW std::map<string, string>;
ACL_ITER iter;
acl_foreach(iter, m_pMimeNode->header_list)
{
HEADER_NV* hdr = (HEADER_NV*) iter.data;
if (*hdr->value == 0)
continue;
std::pair<string, string> entry(hdr->name, hdr->value);
const_cast<mime_node*> (this)->m_headers_->insert(entry);
}
return *m_headers_;
}
bool mime_node::save(pipe_manager& out) const
{
if (m_emailFile.empty())