mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 11:57:43 +08:00
fixed one bug in mail_message class for build one message
This commit is contained in:
parent
a9101ebf0c
commit
ed2e304caf
@ -1,6 +1,9 @@
|
||||
修改历史列表:
|
||||
|
||||
------------------------------------------------------------------------
|
||||
503) 2015.11.11
|
||||
503.1) bugfix: acl_json_parse.c 针对 -xxx 或 +xxx 也应识别为数值类型
|
||||
|
||||
502) 2015.11.6
|
||||
502.1) feature: acl_htable.c 中新增函数 acl_htable_delete_entry
|
||||
|
||||
|
@ -515,32 +515,32 @@ static const char *json_strend(ACL_JSON *json, const char *data)
|
||||
return data;
|
||||
|
||||
#define EQ(x, y) !strcasecmp((x), ((y)))
|
||||
#define IS_NUMBER(x) (acl_alldig((x)) \
|
||||
|| ((*(x) == '-' || *(x) == '+') \
|
||||
&& *((x) + 1) != 0 && acl_alldig((x) + 1)))
|
||||
|
||||
if (node->parent && node->parent->type == ACL_JSON_T_ARRAY) {
|
||||
if (node->quote == 0) {
|
||||
if (EQ(STR(node->text), "null"))
|
||||
const char* txt = STR(node->text);
|
||||
|
||||
if (EQ(txt, "null"))
|
||||
node->type = ACL_JSON_T_A_NULL;
|
||||
else if (EQ(STR(node->text), "true")
|
||||
|| EQ(STR(node->text), "false"))
|
||||
{
|
||||
else if (EQ(txt, "true") || EQ(txt, "false"))
|
||||
node->type = ACL_JSON_T_A_BOOL;
|
||||
}
|
||||
else if (acl_alldig(STR(node->text)))
|
||||
else if (IS_NUMBER(txt))
|
||||
node->type = ACL_JSON_T_A_NUMBER;
|
||||
else
|
||||
node->type = ACL_JSON_T_A_STRING;
|
||||
} else
|
||||
node->type = ACL_JSON_T_STRING;
|
||||
} else if (node->quote == 0)
|
||||
{
|
||||
if (EQ(STR(node->text), "null"))
|
||||
} else if (node->quote == 0) {
|
||||
const char* txt = STR(node->text);
|
||||
|
||||
if (EQ(txt, "null"))
|
||||
node->type = ACL_JSON_T_NULL;
|
||||
else if (EQ(STR(node->text), "true")
|
||||
|| EQ(STR(node->text), "false"))
|
||||
{
|
||||
else if (EQ(txt, "true") || EQ(txt, "false"))
|
||||
node->type = ACL_JSON_T_BOOL;
|
||||
}
|
||||
else if (acl_alldig(STR(node->text)))
|
||||
else if (IS_NUMBER(txt))
|
||||
node->type = ACL_JSON_T_NUMBER;
|
||||
else
|
||||
node->type = ACL_JSON_T_STRING;
|
||||
|
@ -110,7 +110,7 @@ int acl_dbuf_pool_reset(ACL_DBUF_POOL *pool, size_t off)
|
||||
|
||||
if (off > pool->off) {
|
||||
acl_msg_warn("warning: %s(%d) off(%ld) > pool->off(%ld)",
|
||||
__FUNCTION__, __LINE__, off, pool->off);
|
||||
__FUNCTION__, __LINE__, (long) off, (long) pool->off);
|
||||
return -1;
|
||||
} else if (off == pool->off)
|
||||
return 0;
|
||||
@ -152,7 +152,7 @@ int acl_dbuf_pool_reset(ACL_DBUF_POOL *pool, size_t off)
|
||||
#endif
|
||||
}
|
||||
#if 0
|
||||
printf(">>Off: %ld\r\n", pool->off);
|
||||
printf(">>Off: %ld\r\n", (long) pool->off);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
修改历史列表:
|
||||
|
||||
------------------------------------------------------------------------
|
||||
374) 2015.11.12
|
||||
374.1) feature: http_request_manager 的构造函数增加了连接 http 服务器的超时时间
|
||||
及 IO 读写超时时间
|
||||
|
||||
373) 2015.11.11
|
||||
373.1) bugfix: mail_message 类中的 append_addrs 方法存在一处指针溢出的 BUG
|
||||
|
||||
372) 2015.11.10
|
||||
372.1) bugfix: redis_command 类中有两处 build 函数在构建请求命令时应该支持二进制格式
|
||||
372.2) feature: dbuf_obj 类增加了 nrefer_,便于 dbuf_guard 进行安全管理,以防止被
|
||||
dbug_guard 类对象重复释放
|
||||
|
||||
371) 2015.11.7
|
||||
371.1) feature: dbuf_pool.cpp 中增加了内存池管理类 dbuf_guard 及内存池对象类
|
||||
dbuf_obj,以方便使用 dbuf_pool 内存池
|
||||
|
@ -11,7 +11,12 @@ namespace acl
|
||||
class ACL_CPP_API http_request_manager : public acl::connect_manager
|
||||
{
|
||||
public:
|
||||
http_request_manager();
|
||||
/**
|
||||
* 构造函数
|
||||
* @param conn_timeout {int} 连接超时时间(秒)
|
||||
* @param rw_timeout {int} 网络 IO 读写超时时间(秒)
|
||||
*/
|
||||
http_request_manager(int conn_timeout = 30, int rw_timeout = 30);
|
||||
virtual ~http_request_manager();
|
||||
|
||||
protected:
|
||||
@ -23,6 +28,10 @@ protected:
|
||||
* @return {connect_pool*} 返回创建的连接池对象
|
||||
*/
|
||||
connect_pool* create_pool(const char* addr, size_t count, size_t idx);
|
||||
|
||||
private:
|
||||
int conn_timeout_;
|
||||
int rw_timeout_;
|
||||
};
|
||||
|
||||
} // namespace acl
|
||||
|
@ -169,6 +169,12 @@ public:
|
||||
dbuf_obj(dbuf_guard* guard = NULL);
|
||||
|
||||
virtual ~dbuf_obj() {}
|
||||
|
||||
private:
|
||||
friend class dbuf_guard;
|
||||
|
||||
// 该变量便于 dbuf_guard 对象使用,以增加安全性
|
||||
int nrefer_;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -298,7 +304,7 @@ public:
|
||||
* dbuf_guard 对象统一进行销毁管理
|
||||
* @param obj {dbuf_obj*}
|
||||
* @return {int} 返回 obj 被添加后其在 dbuf_obj 对象数组中的下标位置,
|
||||
* 如果返回值 < 0 则说明输入参数非法
|
||||
* 如果返回值 < 0 则说明输入的对象已经在 dbuf_guard 的监管中
|
||||
*/
|
||||
int push_back(dbuf_obj* obj);
|
||||
|
||||
|
@ -10,8 +10,9 @@ static void build_html(void)
|
||||
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>")
|
||||
.add_to("\"郑树新1\" <zsx1@sina.com>")
|
||||
// .add_to("\"郑树新1\" <zsx1@sina.com>; \"郑树新2\" <zsx2@sina.com>; <zsx3@sina.com>")
|
||||
// .add_cc("\"郑树新3\" <zsx1@163.com>; \"郑树新4\" <zsx2@163.com>")
|
||||
.set_subject("主题:中国人民银行!")
|
||||
.add_header("X-Forward-For", "<zsx@263.net>");
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
valgrind --tool=memcheck --leak-check=yes -v ./mail_build
|
||||
valgrind --tool=memcheck --leak-check=yes -v ./mail_builder
|
||||
|
@ -5,7 +5,10 @@
|
||||
namespace acl
|
||||
{
|
||||
|
||||
http_request_manager::http_request_manager()
|
||||
http_request_manager::http_request_manager(
|
||||
int conn_timeout /* = 30 */, int rw_timeout /* = 30 */)
|
||||
: conn_timeout_(conn_timeout)
|
||||
, rw_timeout_(rw_timeout)
|
||||
{
|
||||
}
|
||||
|
||||
@ -17,7 +20,8 @@ connect_pool* http_request_manager::create_pool(const char* addr,
|
||||
size_t count, size_t idx)
|
||||
{
|
||||
http_request_pool* conns = NEW http_request_pool(addr, count, idx);
|
||||
|
||||
if (conn_timeout_ > 0 && rw_timeout_ > 0)
|
||||
conns->set_timeout(conn_timeout_, rw_timeout_);
|
||||
return conns;
|
||||
}
|
||||
|
||||
|
@ -1244,11 +1244,11 @@ void redis_command::build(const char* cmd, const char* key,
|
||||
for (; cit != attrs.end(); ++cit)
|
||||
{
|
||||
argv_[i] = cit->first.c_str();
|
||||
argv_lens_[i] = strlen(argv_[i]);
|
||||
argv_lens_[i] = cit->first.size();
|
||||
i++;
|
||||
|
||||
argv_[i] = cit->second.c_str();
|
||||
argv_lens_[i] = strlen(argv_[i]);
|
||||
argv_lens_[i] = cit->second.size();
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -1279,7 +1279,7 @@ void redis_command::build(const char* cmd, const char* key,
|
||||
for (; cit != attrs.end(); ++cit)
|
||||
{
|
||||
argv_[i] = cit->first.c_str();
|
||||
argv_lens_[i] = strlen(argv_[i]);
|
||||
argv_lens_[i] = cit->first.size();
|
||||
i++;
|
||||
|
||||
argv_[i] = cit->second;
|
||||
@ -1323,11 +1323,11 @@ void redis_command::build(const char* cmd, const char* key,
|
||||
for (size_t j = 0; j < size; j++)
|
||||
{
|
||||
argv_[i] = names[j].c_str();
|
||||
argv_lens_[i] = strlen(argv_[i]);
|
||||
argv_lens_[i] = names[j].size();
|
||||
i++;
|
||||
|
||||
argv_[i] = values[j].c_str();
|
||||
argv_lens_[i] = strlen(argv_[i]);
|
||||
argv_lens_[i] = values[j].size();
|
||||
i++;
|
||||
}
|
||||
|
||||
@ -1511,7 +1511,7 @@ void redis_command::build(const char* cmd, const char* key,
|
||||
for (size_t j = 0; j < argc; j++)
|
||||
{
|
||||
argv_[i] = names[j].c_str();
|
||||
argv_lens_[i] = strlen(argv_[i]);
|
||||
argv_lens_[i] = names[j].size();
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -241,10 +241,10 @@ bool mail_message::append_addr(const rfc822_addr& addr, string& out)
|
||||
addr.comment);
|
||||
return false;
|
||||
}
|
||||
out.append("\"");
|
||||
out.append("\" ");
|
||||
}
|
||||
|
||||
out.format_append(" <%s>", addr.addr);
|
||||
out.format_append("<%s>", addr.addr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -270,21 +270,27 @@ bool mail_message::append_addrs(const char* name,
|
||||
out.format_append("%s: ", name);
|
||||
if (append_addr(**cit, out) == false)
|
||||
return false;
|
||||
out.append(";\r\n");
|
||||
++cit;
|
||||
|
||||
if (++cit == addrs.end())
|
||||
{
|
||||
out.append("\r\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
out.append(",\r\n");
|
||||
|
||||
while (true)
|
||||
{
|
||||
out.append("\t");
|
||||
if (append_addr(**cit, out) == false)
|
||||
return false;
|
||||
++cit;
|
||||
if (cit == addrs.end())
|
||||
|
||||
if (++cit == addrs.end())
|
||||
{
|
||||
out.append("\r\n");
|
||||
break;
|
||||
}
|
||||
out.append(";\r\n");
|
||||
out.append(",\r\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "acl_stdafx.hpp"
|
||||
#include "acl_cpp/stdlib/log.hpp"
|
||||
#include "acl_cpp/stdlib/dbuf_pool.hpp"
|
||||
|
||||
namespace acl
|
||||
@ -90,7 +91,12 @@ bool dbuf_pool::dbuf_unkeep(const void* addr)
|
||||
dbuf_obj::dbuf_obj(dbuf_guard* guard /* = NULL */)
|
||||
{
|
||||
if (guard)
|
||||
{
|
||||
nrefer_ = 1;
|
||||
guard->push_back(this);
|
||||
}
|
||||
else
|
||||
nrefer_ = 0;
|
||||
}
|
||||
|
||||
dbuf_guard::dbuf_guard(acl::dbuf_pool* dbuf /* = NULL */, size_t nblock /* = 2 */)
|
||||
@ -114,7 +120,15 @@ dbuf_guard::~dbuf_guard()
|
||||
|
||||
int dbuf_guard::push_back(dbuf_obj* obj)
|
||||
{
|
||||
if (obj->nrefer_ >= 1)
|
||||
{
|
||||
logger_error("obj->nrefer_: %d >= 1", obj->nrefer_);
|
||||
return -1;
|
||||
}
|
||||
|
||||
objs_.push_back(obj);
|
||||
obj->nrefer_++;
|
||||
|
||||
return (int) objs_.size() - 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user