acl/lib_acl_cpp/include/acl_cpp/mime/mime_node.hpp

276 lines
8.3 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2014-11-19 00:25:21 +08:00
#include <stdlib.h>
#include <map>
#include "../stdlib/noncopyable.hpp"
2017-06-02 14:47:24 +08:00
#include "../stdlib/string.hpp"
2014-11-19 00:25:21 +08:00
#if !defined(ACL_MIME_DISABLE)
2014-11-19 00:25:21 +08:00
struct MIME_NODE;
namespace acl {
class pipe_manager;
class ostream;
class ifstream;
class ACL_CPP_API mime_node : public noncopyable
2014-11-19 00:25:21 +08:00
{
public:
/**
*
* @param emailFile {const char*}
* save_body
* @param node {const MIME_NODE*}
* @param enableDecode {bool} base64/qp
*
* @param toCharset {const char*}
*
* @param off {off_t}
* 便
2014-11-19 00:25:21 +08:00
*/
mime_node(const char* emailFile, const MIME_NODE* node,
bool enableDecode = true, const char* toCharset = "gb2312",
off_t off = 0);
2019-07-07 13:27:58 +08:00
virtual ~mime_node(void);
2014-11-19 00:25:21 +08:00
/**
* MIME Content-Type name
* @return {const char*}
2014-11-19 00:25:21 +08:00
*/
2019-07-07 13:27:58 +08:00
const char* get_name(void) const
2014-11-19 00:25:21 +08:00
{
if (m_name.empty())
2019-07-07 13:27:58 +08:00
return NULL;
return m_name.c_str();
2014-11-19 00:25:21 +08:00
}
/**
* Content-Type : Content-Type: image/jpeg,
* MIME_CTYPE_IMAGE ( mime_define.hpp )
* @return {int} mime_define.hpp MIME_CTYPE_XXX
2014-11-19 00:25:21 +08:00
*/
int get_ctype(void) const
2014-11-19 00:25:21 +08:00
{
2019-07-07 13:27:58 +08:00
return m_ctype;
2014-11-19 00:25:21 +08:00
}
/**
* Content-Type : Content-Type: image/jpeg,
* MIME_STYPE_JPEG ( mime_define.hpp )
* @return {int} mime_define.hpp MIME_STYPE_XXX
2014-11-19 00:25:21 +08:00
*/
2019-07-07 13:27:58 +08:00
int get_stype(void) const
2014-11-19 00:25:21 +08:00
{
2019-07-07 13:27:58 +08:00
return m_stype;
2014-11-19 00:25:21 +08:00
}
/**
* Content-Type
* @return {const char*} ""
*/
const char* get_ctype_s(void) const;
/**
* Content-Type
* @return {const char*} ""
*/
const char* get_stype_s(void) const;
2014-11-19 00:25:21 +08:00
/**
* ( Content-Transfer-Encoding)
* @return {int} mime_define.hpp MIME_ENC_XXX
2014-11-19 00:25:21 +08:00
*/
2019-07-07 13:27:58 +08:00
int get_encoding(void) const
2014-11-19 00:25:21 +08:00
{
2019-07-07 13:27:58 +08:00
return m_encoding;
2014-11-19 00:25:21 +08:00
}
/**
* ( Content-Type charset )
* @return {const char*}
2014-11-19 00:25:21 +08:00
*/
2019-07-07 13:27:58 +08:00
const char* get_charset(void) const
2014-11-19 00:25:21 +08:00
{
2019-07-07 13:27:58 +08:00
return m_charset;
2014-11-19 00:25:21 +08:00
}
/**
* ,
* @return {const char*}
2014-11-19 00:25:21 +08:00
*/
2019-07-07 13:27:58 +08:00
const char* get_toCharset(void) const
2014-11-19 00:25:21 +08:00
{
if (m_toCharset[0])
2019-07-07 13:27:58 +08:00
return m_toCharset;
2014-11-19 00:25:21 +08:00
else
2019-07-07 13:27:58 +08:00
return NULL;
2014-11-19 00:25:21 +08:00
}
/**
*
2014-11-19 00:25:21 +08:00
* @return {off_t}
*/
2019-07-07 13:27:58 +08:00
off_t get_bodyBegin(void) const
2014-11-19 00:25:21 +08:00
{
2019-07-07 13:27:58 +08:00
return m_bodyBegin;
2014-11-19 00:25:21 +08:00
}
/**
*
2014-11-19 00:25:21 +08:00
* @return {off_t}
*/
2019-07-07 13:27:58 +08:00
off_t get_bodyEnd(void) const
2014-11-19 00:25:21 +08:00
{
2019-07-07 13:27:58 +08:00
return m_bodyEnd;
2014-11-19 00:25:21 +08:00
}
/**
*
* @param name {const char*} , : Content-Type
* @return {const char*}
2014-11-19 00:25:21 +08:00
*/
const char* header_value(const char* name) const;
/**
*
* @return {const std::map<string, string>&}
*/
2019-07-07 13:27:58 +08:00
const std::map<string, string>& get_headers(void) const;
2014-11-19 00:25:21 +08:00
/**
*
2014-11-19 00:25:21 +08:00
* @param out {pipe_manager&}
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool save(pipe_manager& out) const;
/**
*
2014-11-19 00:25:21 +08:00
* @param out {pipe_manager&}
* @param src {const char*}
* emailFile
* @param len {int} 0
* emailFile
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool save(pipe_manager& out, const char* src, int len) const;
/**
*
* @param out {ostream&}
* @param src {const char*}
* emailFile
* @param len {int} 0
* emailFile
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool save(ostream& out, const char* src = NULL, int len = 0) const;
/**
*
* @param outFile {const char*}
* @param src {const char*}
* emailFile
* @param len {int} 0
* emailFile
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool save(const char* outFile, const char* src = NULL, int len = 0) const;
/**
*
* @param out {string&}
* @param src {const char*}
* emailFile
* @param len {int} 0
* emailFile
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool save(string& out, const char* src, int len) const;
/**
*
* @return {mime_node*} (
* );
* delete
2014-11-19 00:25:21 +08:00
*/
2019-07-07 13:27:58 +08:00
mime_node* get_parent(void) const;
2014-11-19 00:25:21 +08:00
/**
*
* @return {bool} true ,
2014-11-19 00:25:21 +08:00
*/
2019-07-07 13:27:58 +08:00
bool has_parent(void) const;
2014-11-19 00:25:21 +08:00
/**
* (MIME_CTYPE_XXX), MIME_CTYPE_OTHER
*
2014-11-19 00:25:21 +08:00
* @return {int} MIME_CTYPE_XXX
*/
int parent_ctype(void) const;
const char* parent_ctype_s(void) const;
2014-11-19 00:25:21 +08:00
/**
* (MIME_STYPE_XXX), MIME_STYPE_OTHER
*
2014-11-19 00:25:21 +08:00
* @return {int} MIME_STYPE_XXX
*/
int parent_stype(void) const;
const char* parent_stype_s(void) const;
2014-11-19 00:25:21 +08:00
/**
* (MIME_ENC_XXX), MIME_ENC_OTHER
*
2014-11-19 00:25:21 +08:00
* @return {int} MIME_ENC_XXX
*/
2019-07-07 13:27:58 +08:00
int parent_encoding(void) const;
2014-11-19 00:25:21 +08:00
/**
* ,
*
2014-11-19 00:25:21 +08:00
* @return {const char*}
*/
2019-07-07 13:27:58 +08:00
char* parent_charset(void) const;
2014-11-19 00:25:21 +08:00
/**
*
* @return {off_t} -1
2014-11-19 00:25:21 +08:00
*/
2019-07-07 13:27:58 +08:00
off_t parent_bodyBegin(void) const;
2014-11-19 00:25:21 +08:00
/**
*
* @return {off_t} -1
2014-11-19 00:25:21 +08:00
*/
2019-07-07 13:27:58 +08:00
off_t parent_bodyEnd(void) const;
2014-11-19 00:25:21 +08:00
/**
* , : Content-Type
* @param name {const char*}
* @return {const char*} ,
*
2014-11-19 00:25:21 +08:00
*/
const char* parent_header_value(const char* name) const;
protected:
bool m_enableDecode;
string m_name;
string m_emailFile;
int m_ctype; // mime_define.hpp
int m_stype; // mime_define.hpp
int m_encoding; // mime_define.hpp
char m_charset[32];
char m_toCharset[32];
off_t m_bodyBegin;
off_t m_bodyEnd;
std::map<string, string>* m_headers_;
2014-11-19 00:25:21 +08:00
const MIME_NODE* m_pMimeNode;
mime_node* m_pParent;
};
} // namespace acl
#endif // !defined(ACL_MIME_DISABLE)