format code style

This commit is contained in:
zhengshuxin 2019-07-14 10:17:55 +08:00
parent 5653b32c34
commit 1e48c13176
20 changed files with 722 additions and 710 deletions

View File

@ -17,12 +17,10 @@ namespace acl
db_row::db_row(const std::vector<const char*>& names)
: names_(names)
{
}
db_row::~db_row(void)
{
}
void db_row::clear(void)
@ -53,8 +51,9 @@ const char* db_row::field_value(const char* name) const
// 通过扫描字段名找出字段值的下标位置
for (i = 0; i < n; i++) {
if (strcasecmp(name, names_[i]) == 0)
if (strcasecmp(name, names_[i]) == 0) {
break;
}
}
if (i == n) {
logger_error("cloumn not exist, name: %s", name);
@ -89,73 +88,81 @@ const char* db_row::operator [](size_t ifield) const
int db_row::field_int(size_t ifield, int null_value /* = 0 */) const
{
const char* ptr = field_value(ifield);
if (ptr == NULL)
if (ptr == NULL) {
return null_value;
else
} else {
return atoi(ptr);
}
}
int db_row::field_int(const char* name, int null_value /* = 0 */) const
{
const char* ptr = field_value(name);
if (ptr == NULL)
if (ptr == NULL) {
return null_value;
else
} else {
return atoi(ptr);
}
}
acl_int64 db_row::field_int64(size_t ifield, acl_int64 null_value /* = 0 */) const
{
const char* ptr = field_value(ifield);
if (ptr == NULL)
if (ptr == NULL) {
return null_value;
else
} else {
return acl_atoi64(ptr);
}
}
acl_int64 db_row::field_int64(const char* name, acl_int64 null_value /* = 0 */) const
{
const char* ptr = field_value(name);
if (ptr == NULL)
if (ptr == NULL) {
return null_value;
else
} else {
return acl_atoi64(ptr);
}
}
double db_row::field_double(size_t ifield, double null_value /* = 0.0 */) const
{
const char* ptr = field_value(ifield);
if (ptr == NULL)
if (ptr == NULL) {
return null_value;
else
} else {
return atof(ptr);
}
}
double db_row::field_double(const char* name, double null_value /* = 0.0 */) const
{
const char* ptr = field_value(name);
if (ptr == NULL)
if (ptr == NULL) {
return null_value;
else
} else {
return atof(ptr);
}
}
const char* db_row::field_string(size_t ifield) const
{
const char* ptr = field_value(ifield);
if (ptr == NULL)
if (ptr == NULL) {
return NULL;
else
} else {
return ptr;
}
}
const char* db_row::field_string(const char* name) const
{
const char* ptr = field_value(name);
if (ptr == NULL)
if (ptr == NULL) {
return NULL;
else
} else {
return ptr;
}
}
size_t db_row::field_length(size_t ifield) const
@ -182,8 +189,9 @@ size_t db_row::field_length(const char* name) const
// 通过扫描字段名找出字段值的下标位置
for (i = 0; i < n; i++) {
if (strcasecmp(name, names_[i]) == 0)
if (strcasecmp(name, names_[i]) == 0) {
break;
}
}
if (i == n) {
logger_error("cloumn not exist, name: %s", name);
@ -207,22 +215,22 @@ size_t db_row::length(void) const
//////////////////////////////////////////////////////////////////////////
db_rows::db_rows()
db_rows::db_rows(void)
: result_tmp_(NULL)
, result_free(NULL)
{
}
db_rows::~db_rows()
db_rows::~db_rows(void)
{
std::vector<db_row*>::iterator it = rows_.begin();
for (; it != rows_.end(); ++it) {
delete (*it);
}
if (result_free && result_tmp_)
if (result_free && result_tmp_) {
result_free(result_tmp_);
}
}
const std::vector<const db_row*>& db_rows::get_rows(
@ -231,15 +239,17 @@ const std::vector<const db_row*>& db_rows::get_rows(
// 先清空上一次的临时结果集
rows_tmp_.clear();
if (empty())
if (empty()) {
return rows_tmp_;
}
size_t icolumn, ncolumn = names_.size();
// 通过扫描字段名找出字段值的下标位置
for (icolumn = 0; icolumn < ncolumn; icolumn++) {
if (strcasecmp(name, names_[icolumn]) == 0)
if (strcasecmp(name, names_[icolumn]) == 0) {
break;
}
}
const db_row* row;
@ -251,14 +261,15 @@ const std::vector<const db_row*>& db_rows::get_rows(
row = rows_[irow];
acl_assert(row->length() == ncolumn);
ptr = (*row)[icolumn];
if (ptr && strcmp(ptr, value) == 0)
if (ptr && strcmp(ptr, value) == 0) {
rows_tmp_.push_back(row);
}
}
return rows_tmp_;
}
const std::vector<db_row*>& db_rows::get_rows() const
const std::vector<db_row*>& db_rows::get_rows(void) const
{
return rows_;
}
@ -275,33 +286,34 @@ const db_row* db_rows::operator [](size_t idx) const
return row;
}
bool db_rows::empty() const
bool db_rows::empty(void) const
{
return rows_.empty();
}
size_t db_rows::length() const
size_t db_rows::length(void) const
{
return rows_.size();
}
//////////////////////////////////////////////////////////////////////////
db_handle::db_handle()
db_handle::db_handle(void)
: result_(NULL)
, id_(NULL)
{
time(&when_);
}
db_handle::~db_handle()
db_handle::~db_handle(void)
{
if (id_)
if (id_) {
acl_myfree(id_);
}
free_result();
}
bool db_handle::open()
bool db_handle::open(void)
{
// 调用虚方法的子类实现过程
return dbopen();
@ -362,13 +374,15 @@ void db_handle::print_out(size_t max /* = 0 */) const
{
// 列出查询结果方法二
for (size_t i = 0; i < length(); i++) {
if (max > 0 && i >= max)
if (max > 0 && i >= max) {
continue;
}
const acl::db_row* row = (*this)[i];
for (size_t j = 0; j < row->length(); j++)
for (size_t j = 0; j < row->length(); j++) {
printf("%s, ", (*row)[j]);
}
printf("\r\n");
}
@ -376,7 +390,7 @@ void db_handle::print_out(size_t max /* = 0 */) const
}
const db_rows* db_handle::get_result() const
const db_rows* db_handle::get_result(void) const
{
return result_;
}
@ -384,24 +398,27 @@ const db_rows* db_handle::get_result() const
const std::vector<const db_row*>* db_handle::get_rows(
const char* name, const char* value)
{
if (result_ == NULL)
if (result_ == NULL) {
return NULL;
}
const std::vector<const db_row*>& rows = result_->get_rows(name, value);
return &rows;
}
const std::vector<db_row*>* db_handle::get_rows() const
const std::vector<db_row*>* db_handle::get_rows(void) const
{
if (result_ == NULL)
if (result_ == NULL) {
return NULL;
}
const std::vector<db_row*>& rows = result_->get_rows();
return &rows;
}
const db_row* db_handle::get_first_row() const
const db_row* db_handle::get_first_row(void) const
{
if (result_ == NULL)
if (result_ == NULL) {
return NULL;
}
const std::vector<db_row*>& rows = result_->get_rows();
const acl::db_row* first_row = rows[0];
@ -409,7 +426,7 @@ const db_row* db_handle::get_first_row() const
return first_row;
}
void db_handle::free_result()
void db_handle::free_result(void)
{
if (result_) {
delete result_;
@ -419,32 +436,37 @@ void db_handle::free_result()
const db_row* db_handle::operator [](size_t idx) const
{
if (result_ == NULL)
if (result_ == NULL) {
return NULL;
if (idx >= result_->length())
return (NULL);
}
if (idx >= result_->length()) {
return NULL;
}
return (*result_)[idx];
}
size_t db_handle::length() const
size_t db_handle::length(void) const
{
if (result_ == NULL)
if (result_ == NULL) {
return 0;
else
} else {
return result_->length();
}
}
bool db_handle::empty() const
bool db_handle::empty(void) const
{
return length() == 0 ? true : false;
}
db_handle& db_handle::set_id(const char* id)
{
if (id == NULL || *id == 0)
if (id == NULL || *id == 0) {
return *this;
if (id_)
}
if (id_) {
acl_myfree(id_);
}
id_ = acl_mystrdup(id);
return *this;
}
@ -459,11 +481,12 @@ static string __loadpath;
void db_handle::set_loadpath(const char* path)
{
if (path && *path)
if (path && *path) {
__loadpath = path;
}
}
const char* db_handle::get_loadpath()
const char* db_handle::get_loadpath(void)
{
return __loadpath.empty() ? NULL : __loadpath.c_str();
}

View File

@ -14,15 +14,16 @@
namespace acl
{
master_aio::master_aio() : handle_(NULL) {}
master_aio::master_aio(void) : handle_(NULL) {}
master_aio::~master_aio()
master_aio::~master_aio(void)
{
if (daemon_mode_ == false)
if (!daemon_mode_) {
delete handle_;
}
}
aio_handle* master_aio::get_handle() const
aio_handle* master_aio::get_handle(void) const
{
acl_assert(handle_);
return handle_;
@ -59,14 +60,12 @@ void master_aio::run_daemon(int argc, char** argv)
const char* master_aio::get_conf_path(void) const
{
#ifndef ACL_WINDOWS
if (daemon_mode_)
{
if (daemon_mode_) {
const char* ptr = acl_aio_server_conf();
return ptr && *ptr ? ptr : NULL;
}
else
#endif
return conf_.get_path();
return conf_.get_path();
}
//////////////////////////////////////////////////////////////////////////
@ -74,8 +73,9 @@ const char* master_aio::get_conf_path(void) const
static void close_all_listener(std::vector<aio_listen_stream*>& sstreams)
{
std::vector<aio_listen_stream*>::iterator it = sstreams.begin();
for (; it != sstreams.end(); ++it)
for (; it != sstreams.end(); ++it) {
(*it)->close();
}
}
bool master_aio::run_alone(const char* addrs, const char* path /* = NULL */,
@ -102,13 +102,11 @@ bool master_aio::run_alone(const char* addrs, const char* path /* = NULL */,
ACL_EVENT* eventp = acl_aio_event(aio);
set_event(eventp); // 设置基类的事件句柄
acl_foreach(iter, tokens)
{
acl_foreach(iter, tokens) {
const char* addr = (const char*) iter.data;
aio_listen_stream* sstream = NEW aio_listen_stream(handle_);
// 监听指定的地址
if (sstream->open(addr) == false)
{
if (!sstream->open(addr)) {
logger_error("listen %s error: %s", addr, last_serror());
close_all_listener(sstreams);
// XXX: 为了保证能关闭监听流,应在此处再 check 一下
@ -124,11 +122,9 @@ bool master_aio::run_alone(const char* addrs, const char* path /* = NULL */,
service_pre_jail(this);
service_init(this);
while (true)
{
while (true) {
// 如果返回 false 则表示不再继续,需要退出
if (handle_->check() == false)
{
if (!handle_->check()) {
logger("aio_server stop now ...");
break;
}
@ -139,7 +135,7 @@ bool master_aio::run_alone(const char* addrs, const char* path /* = NULL */,
return true;
}
void master_aio::stop()
void master_aio::stop(void)
{
acl_assert(handle_);
handle_->stop();
@ -166,10 +162,10 @@ public:
stream_ = ss->get_astream();
}
~aio_close_callback() {}
~aio_close_callback(void) {}
protected:
void close_callback()
void close_callback(void)
{
#ifndef ACL_WINDOWS
// 通过下面调用通知服务器框架目前已经处理的连接个数,便于
@ -191,8 +187,7 @@ void master_aio::service_pre_jail(void* ctx)
acl_assert(ma != NULL);
#ifndef ACL_WINDOWS
if (ma->daemon_mode_)
{
if (ma->daemon_mode_) {
acl_assert(ma->handle_ == NULL);
ACL_EVENT* eventp = acl_aio_server_event();
@ -252,8 +247,9 @@ int master_aio::service_on_sighup(void* ctx, ACL_VSTRING* buf)
acl_assert(ma);
string s;
bool ret = ma->proc_on_sighup(s);
if (buf)
if (buf) {
acl_vstring_strcpy(buf, s.c_str());
}
return ret ? 0 : -1;
}

View File

@ -11,18 +11,18 @@
namespace acl
{
master_base::master_base()
master_base::master_base(void)
{
daemon_mode_ = false;
proc_inited_ = false;
event_ = NULL;
}
master_base::~master_base()
master_base::~master_base(void)
{
for (std::vector<server_socket*>::iterator it = servers_.begin();
it != servers_.end(); ++it)
{
it != servers_.end(); ++it) {
delete *it;
}
@ -35,33 +35,33 @@ master_base::~master_base()
void master_base::set_cfg_bool(master_bool_tbl* table)
{
if (table == NULL)
return;
conf_.set_cfg_bool(table);
if (table) {
conf_.set_cfg_bool(table);
}
}
void master_base::set_cfg_int(master_int_tbl* table)
{
if (table == NULL)
return;
conf_.set_cfg_int(table);
if (table) {
conf_.set_cfg_int(table);
}
}
void master_base::set_cfg_int64(master_int64_tbl* table)
{
if (table == NULL)
return;
conf_.set_cfg_int64(table);
if (table) {
conf_.set_cfg_int64(table);
}
}
void master_base::set_cfg_str(master_str_tbl* table)
{
if (table == NULL)
return;
conf_.set_cfg_str(table);
if (table) {
conf_.set_cfg_str(table);
}
}
bool master_base::daemon_mode() const
bool master_base::daemon_mode(void) const
{
return daemon_mode_;
}
@ -74,8 +74,7 @@ static void timer_callback(int, ACL_EVENT* event, void* ctx)
acl_int64 next_delay = timer->trigger();
// 如果定时器中的任务为空或未设置定时器的重复使用,则删除定时器
if (timer->empty() || !timer->keep_timer())
{
if (timer->empty() || !timer->keep_timer()) {
// 删除定时器
acl_event_cancel_timer(event, timer_callback, timer);
timer->destroy();
@ -96,13 +95,10 @@ void master_base::set_event(ACL_EVENT* event)
bool master_base::proc_set_timer(event_timer* timer)
{
if (event_ == NULL)
{
if (event_ == NULL) {
logger_warn("event NULL!");
return false;
}
else
{
} else {
acl_event_request_timer(event_, timer_callback, timer,
timer->min_delay(), timer->keep_timer() ? 1 : 0);
return true;
@ -111,10 +107,11 @@ bool master_base::proc_set_timer(event_timer* timer)
void master_base::proc_del_timer(event_timer* timer)
{
if (event_ == NULL)
if (event_ == NULL) {
logger_warn("event NULL!");
else
} else {
acl_event_cancel_timer(event_, timer_callback, timer);
}
}
} // namespace acl

View File

@ -8,7 +8,7 @@
namespace acl
{
master_conf::master_conf()
master_conf::master_conf(void)
{
path_ = NULL;
cfg_loaded_ = false;
@ -25,64 +25,61 @@ master_conf::master_conf()
str_cfg_ = NULL;
}
master_conf::~master_conf()
master_conf::~master_conf(void)
{
reset();
}
void master_conf::reset()
void master_conf::reset(void)
{
if (path_)
if (path_) {
acl_myfree(path_);
if (cfg_)
{
}
if (cfg_) {
acl_xinetd_cfg_free(cfg_);
cfg_ = NULL;
}
if (int_cfg_)
{
if (int_cfg_) {
acl_myfree(int_cfg_);
int_cfg_ = NULL;
}
if (int64_cfg_)
{
if (int64_cfg_) {
acl_myfree(int64_cfg_);
int64_cfg_ = NULL;
}
if (str_cfg_)
{
for (int i = 0; str_cfg_[i].name != NULL; i++)
{
if (*str_cfg_[i].target)
if (str_cfg_) {
for (int i = 0; str_cfg_[i].name != NULL; i++) {
if (*str_cfg_[i].target) {
acl_myfree(*str_cfg_[i].target);
}
}
acl_myfree(str_cfg_);
str_cfg_ = NULL;
}
if (bool_cfg_)
{
if (bool_cfg_) {
acl_myfree(bool_cfg_);
bool_cfg_ = NULL;
}
cfg_loaded_ = false;
bool_tbl_ = NULL;
int_tbl_ = NULL;
bool_tbl_ = NULL;
int_tbl_ = NULL;
int64_tbl_ = NULL;
str_tbl_ = NULL;
str_tbl_ = NULL;
}
void master_conf::load(const char* path)
{
if (cfg_loaded_)
if (cfg_loaded_) {
return;
}
if (path)
{
if (path) {
cfg_ = acl_xinetd_cfg_load(path);
if (path_)
if (path_) {
acl_myfree(path_);
}
path_ = acl_mystrdup(path);
}
@ -99,38 +96,43 @@ const char* master_conf::get_path(void) const
return path_;
}
void master_conf::load_bool()
void master_conf::load_bool(void)
{
if (!cfg_loaded_ || bool_cfg_ == NULL)
if (!cfg_loaded_ || bool_cfg_ == NULL) {
return;
}
acl_xinetd_params_bool_table(cfg_, bool_cfg_);
}
void master_conf::load_int()
void master_conf::load_int(void)
{
if (!cfg_loaded_ || int_cfg_ == NULL)
if (!cfg_loaded_ || int_cfg_ == NULL) {
return;
}
acl_xinetd_params_int_table(cfg_, int_cfg_);
}
void master_conf::load_int64()
void master_conf::load_int64(void)
{
if (!cfg_loaded_ || int64_cfg_ == NULL)
if (!cfg_loaded_ || int64_cfg_ == NULL) {
return;
}
acl_xinetd_params_int64_table(cfg_, int64_cfg_);
}
void master_conf::load_str()
void master_conf::load_str(void)
{
if (!cfg_loaded_ || str_cfg_ == NULL)
if (!cfg_loaded_ || str_cfg_ == NULL) {
return;
}
acl_xinetd_params_str_table(cfg_, str_cfg_);
}
void master_conf::set_cfg_bool(master_bool_tbl* table)
{
if (table == NULL || bool_cfg_)
if (table == NULL || bool_cfg_) {
return;
}
int i = 0;
for (; table[i].name != NULL; i++) {}
@ -138,8 +140,7 @@ void master_conf::set_cfg_bool(master_bool_tbl* table)
bool_cfg_ = (ACL_CFG_BOOL_TABLE*) acl_mycalloc(i + 1,
sizeof(ACL_CFG_BOOL_TABLE));
for (i = 0; table[i].name != NULL; i++)
{
for (i = 0; table[i].name != NULL; i++) {
bool_cfg_[i].name = table[i].name;
bool_cfg_[i].defval = table[i].defval;
bool_cfg_[i].target = table[i].target;
@ -150,8 +151,9 @@ void master_conf::set_cfg_bool(master_bool_tbl* table)
void master_conf::set_cfg_int(master_int_tbl* table)
{
if (table == NULL || int_cfg_)
if (table == NULL || int_cfg_) {
return;
}
int i = 0;
for (; table[i].name != NULL; i++) {}
@ -159,13 +161,12 @@ void master_conf::set_cfg_int(master_int_tbl* table)
int_cfg_ = (ACL_CFG_INT_TABLE*) acl_mycalloc(i + 1,
sizeof(ACL_CFG_INT_TABLE));
for (i = 0; table[i].name != NULL; i++)
{
int_cfg_[i].name = table[i].name;
for (i = 0; table[i].name != NULL; i++) {
int_cfg_[i].name = table[i].name;
int_cfg_[i].defval = table[i].defval;
int_cfg_[i].target = table[i].target;
int_cfg_[i].min = table[i].min;
int_cfg_[i].max = table[i].max;
int_cfg_[i].min = table[i].min;
int_cfg_[i].max = table[i].max;
}
int_cfg_[i].name = NULL;
load_int();
@ -173,8 +174,9 @@ void master_conf::set_cfg_int(master_int_tbl* table)
void master_conf::set_cfg_int64(master_int64_tbl* table)
{
if (table == NULL || int64_cfg_)
if (table == NULL || int64_cfg_) {
return;
}
int i = 0;
for (i = 0; table[i].name != NULL; i++) {}
@ -182,13 +184,12 @@ void master_conf::set_cfg_int64(master_int64_tbl* table)
int64_cfg_ = (ACL_CFG_INT64_TABLE*) acl_mycalloc(i + 1,
sizeof(ACL_CFG_INT64_TABLE));
for (i = 0; table[i].name != NULL; i++)
{
int64_cfg_[i].name = table[i].name;
for (i = 0; table[i].name != NULL; i++) {
int64_cfg_[i].name = table[i].name;
int64_cfg_[i].defval = table[i].defval;
int64_cfg_[i].target = table[i].target;
int64_cfg_[i].min = table[i].min;
int64_cfg_[i].max = table[i].max;
int64_cfg_[i].min = table[i].min;
int64_cfg_[i].max = table[i].max;
}
int64_cfg_[i].name = NULL;
@ -197,8 +198,9 @@ void master_conf::set_cfg_int64(master_int64_tbl* table)
void master_conf::set_cfg_str(master_str_tbl* table)
{
if (table == NULL || str_cfg_)
if (table == NULL || str_cfg_) {
return;
}
int i = 0;
for (; table[i].name != NULL; i++) {}
@ -206,9 +208,8 @@ void master_conf::set_cfg_str(master_str_tbl* table)
str_cfg_ = (ACL_CFG_STR_TABLE*) acl_mycalloc(i + 1,
sizeof(ACL_CFG_STR_TABLE));
for (i = 0; table[i].name != NULL; i++)
{
str_cfg_[i].name = table[i].name;
for (i = 0; table[i].name != NULL; i++) {
str_cfg_[i].name = table[i].name;
str_cfg_[i].defval = table[i].defval;
str_cfg_[i].target = table[i].target;
}
@ -216,22 +217,22 @@ void master_conf::set_cfg_str(master_str_tbl* table)
load_str();
}
ACL_CFG_INT_TABLE* master_conf::get_int_cfg() const
ACL_CFG_INT_TABLE* master_conf::get_int_cfg(void) const
{
return int_cfg_;
}
ACL_CFG_INT64_TABLE* master_conf::get_int64_cfg() const
ACL_CFG_INT64_TABLE* master_conf::get_int64_cfg(void) const
{
return int64_cfg_;
}
ACL_CFG_STR_TABLE* master_conf::get_str_cfg() const
ACL_CFG_STR_TABLE* master_conf::get_str_cfg(void) const
{
return str_cfg_;
}
ACL_CFG_BOOL_TABLE* master_conf::get_bool_cfg() const
ACL_CFG_BOOL_TABLE* master_conf::get_bool_cfg(void) const
{
return bool_cfg_;
}

View File

@ -13,9 +13,9 @@
namespace acl
{
master_proc::master_proc() : stop_(false), count_limit_(0), count_(0) {}
master_proc::master_proc(void) : stop_(false), count_limit_(0), count_(0) {}
master_proc::~master_proc() {}
master_proc::~master_proc(void) {}
static bool __has_called = false;
@ -47,14 +47,12 @@ void master_proc::run_daemon(int argc, char** argv)
const char* master_proc::get_conf_path(void) const
{
#ifndef ACL_WINDOWS
if (daemon_mode_)
{
if (daemon_mode_) {
const char* ptr = acl_single_server_conf();
return ptr && *ptr ? ptr : NULL;
}
else
#endif
return conf_.get_path();
return conf_.get_path();
}
//////////////////////////////////////////////////////////////////////////
@ -62,8 +60,9 @@ const char* master_proc::get_conf_path(void) const
static void close_all_listener(std::vector<ACL_VSTREAM*>& sstreams)
{
std::vector<ACL_VSTREAM*>::iterator it = sstreams.begin();
for (; it != sstreams.end(); ++it)
for (; it != sstreams.end(); ++it) {
acl_vstream_close(*it);
}
}
void master_proc::listen_callback(int, ACL_EVENT*, ACL_VSTREAM *sstream,
@ -73,19 +72,17 @@ void master_proc::listen_callback(int, ACL_EVENT*, ACL_VSTREAM *sstream,
acl_assert(mp);
ACL_VSTREAM* client = acl_vstream_accept(sstream, NULL, 0);
if (client == NULL)
{
if (client == NULL) {
logger_error("accept error %s", last_serror());
mp->stop_ = true;
}
else
{
} else {
service_main(ctx, client);
acl_vstream_close(client); // 因为在 service_main 里不会关闭连接
mp->count_++;
if (mp->count_limit_ > 0 && mp->count_ >= mp->count_limit_)
if (mp->count_limit_ > 0 && mp->count_ >= mp->count_limit_) {
mp->stop_ = true;
}
}
}
@ -109,12 +106,10 @@ bool master_proc::run_alone(const char* addrs, const char* path /* = NULL */,
ACL_ARGV* tokens = acl_argv_split(addrs, ";,| \t");
ACL_ITER iter;
acl_foreach(iter, tokens)
{
acl_foreach(iter, tokens) {
const char* addr = (const char*) iter.data;
ACL_VSTREAM* sstream = acl_vstream_listen(addr, 128);
if (sstream == NULL)
{
if (sstream == NULL) {
logger_error("listen %s error %s", addr, last_serror());
close_all_listener(sstreams);
acl_argv_free(tokens);
@ -134,8 +129,9 @@ bool master_proc::run_alone(const char* addrs, const char* path /* = NULL */,
service_pre_jail(this);
service_init(this);
while (!stop_)
while (!stop_) {
acl_event_loop(eventp);
}
close_all_listener(sstreams);
acl_event_free(eventp);
@ -152,12 +148,14 @@ void master_proc::service_main(void* ctx, ACL_VSTREAM *stream)
acl_assert(mp != NULL);
socket_stream* client = NEW socket_stream();
if (client->open(stream) == false)
if (!client->open(stream)) {
logger_fatal("open stream error!");
}
#ifndef ACL_WINDOWS
if (mp->daemon_mode_)
if (mp->daemon_mode_) {
acl_watchdog_pat(); // 必须通知 acl_master 框架一下
}
#endif
mp->on_accept(client);
client->unbind();
@ -170,8 +168,7 @@ void master_proc::service_pre_jail(void* ctx)
acl_assert(mp != NULL);
#ifndef ACL_WINDOWS
if (mp->daemon_mode())
{
if (mp->daemon_mode()) {
ACL_EVENT* eventp = acl_single_server_event();
mp->set_event(eventp);
}
@ -214,8 +211,9 @@ int master_proc::service_on_sighup(void* ctx, ACL_VSTRING* buf)
acl_assert(mp != NULL);
string s;
bool ret = mp->proc_on_sighup(s);
if (buf)
if (buf) {
acl_vstring_strcpy(buf, s.c_str());
}
return ret ? 0 : -1;
}

View File

@ -47,13 +47,12 @@ void master_threads::run(int argc, char** argv)
const char* master_threads::get_conf_path(void) const
{
if (daemon_mode_)
{
if (daemon_mode_) {
const char* ptr = acl_threads_server_conf();
return ptr && *ptr ? ptr : NULL;
}
else
} else {
return conf_.get_path();
}
}
void master_threads::run_daemon(int argc, char** argv)
@ -90,8 +89,7 @@ bool master_threads::run_alone(const char* addrs, const char* path /* = NULL */,
argv[argc++] = proc ? proc : "demo";
argv[argc++] = "-L";
argv[argc++] = addrs;
if (path && *path)
{
if (path && *path) {
argv[argc++] = "-f";
argv[argc++] = path;
}
@ -106,27 +104,28 @@ void master_threads::thread_disable_read(socket_stream* stream)
{
ACL_EVENT* event = get_event();
if (event == NULL)
if (event == NULL) {
logger_error("event NULL");
else
} else {
acl_event_disable_readwrite(event, stream->get_vstream());
}
}
void master_threads::thread_enable_read(socket_stream* stream)
{
ACL_EVENT* event = get_event();
if (event == NULL)
{
if (event == NULL) {
logger_error("event NULL");
return;
}
acl_pthread_pool_t* threads = acl_threads_server_threads();
if (threads != NULL)
if (threads != NULL) {
acl_threads_server_enable_read(event, threads,
stream->get_vstream());
else
} else {
logger_error("threads NULL!");
}
}
void master_threads::push_back(server_socket* ss)
@ -204,8 +203,9 @@ int master_threads::service_on_accept(void* ctx, ACL_VSTREAM* client)
acl_assert(mt);
// client->context 不应被占用
if (client->context != NULL)
if (client->context != NULL) {
logger_fatal("client->context not null!");
}
socket_stream* stream = NEW socket_stream();
@ -213,8 +213,7 @@ int master_threads::service_on_accept(void* ctx, ACL_VSTREAM* client)
// service_on_close 中被释放
client->context = stream;
if (stream->open(client) == false)
{
if (!stream->open(client)) {
logger_error("open stream error(%s)", acl_last_serror());
// 返回 -1 由上层框架调用 service_on_close 过程,在里面
// 释放 stream 对象
@ -224,8 +223,9 @@ int master_threads::service_on_accept(void* ctx, ACL_VSTREAM* client)
// 如果子类的 thread_on_accept 方法返回 false则直接返回给上层
// 框架 -1由上层框架再调用 service_on_close 过程,从而在该过程
// 中将 stream 对象释放
if (mt->thread_on_accept(stream) == false)
if (!mt->thread_on_accept(stream)) {
return -1;
}
// 如果子类的 thread_on_handshake 方法返回 false则直接返回给上层
// 框架 -1由上层框架再调用 service_on_close 过程,从而在该过程
@ -245,14 +245,16 @@ int master_threads::service_on_handshake(void* ctx, ACL_VSTREAM *client)
// client->context 在 service_on_accept 中被设置
socket_stream* stream = (socket_stream*) client->context;
if (stream == NULL)
if (stream == NULL) {
logger_fatal("client->context is null!");
}
// 如果子类的 thread_on_handshake 方法返回 false则直接返回给上层
// 框架 -1由上层框架再调用 service_on_close 过程,从而在该过程
// 中将 stream 对象释放
if (mt->thread_on_handshake(stream) == true)
if (mt->thread_on_handshake(stream)) {
return 0;
}
return -1;
}
@ -263,8 +265,9 @@ int master_threads::service_main(void* ctx, ACL_VSTREAM *client)
// client->context 在 service_on_accept 中被设置
socket_stream* stream = (socket_stream*) client->context;
if (stream == NULL)
if (stream == NULL) {
logger_fatal("client->context is null!");
}
// 调用子类的虚函数实现,如果返回 true 表示让框架继续监控该连接流,
// 否则需要关闭该流
@ -273,15 +276,14 @@ int master_threads::service_main(void* ctx, ACL_VSTREAM *client)
// -1 表示需要关闭该连接
// 1 表示不再监控该连接
if (mt->thread_on_read(stream) == true)
{
if (mt->thread_on_read(stream)) {
// 如果子类在返回 true 后不希望框架继续监控流,则直接返回给框架 1
if (!mt->keep_read(stream))
if (!mt->keep_read(stream)) {
return 1;
}
// 否则,需要检查该流是否已经关闭,如果关闭,则必须返回 -1
if (stream->eof())
{
if (stream->eof()) {
logger_error("DISCONNECTED, CLOSING, FD: %d",
(int) stream->sock_handle());
return -1;
@ -312,8 +314,9 @@ int master_threads::service_on_timeout(void* ctx, ACL_VSTREAM* client)
acl_assert(mt);
socket_stream* stream = (socket_stream*) client->context;
if (stream == NULL)
if (stream == NULL) {
logger_fatal("client->context is null!");
}
acl_assert(mt != NULL);
@ -326,8 +329,9 @@ void master_threads::service_on_close(void* ctx, ACL_VSTREAM* client)
acl_assert(mt != NULL);
socket_stream* stream = (socket_stream*) client->context;
if (stream == NULL)
if (stream == NULL) {
logger_fatal("client->context is null!");
}
// 调用子类函数对将要关闭的流进行善后处理
mt->thread_on_close(stream);
@ -345,8 +349,9 @@ int master_threads::service_on_sighup(void* ctx, ACL_VSTRING* buf)
acl_assert(mt);
string s;
bool ret = mt->proc_on_sighup(s);
if (buf)
if (buf) {
acl_vstring_strcpy(buf, s.c_str());
}
return ret ? 0 : -1;
}

View File

@ -10,9 +10,9 @@
namespace acl
{
master_trigger::master_trigger() {}
master_trigger::master_trigger(void) {}
master_trigger::~master_trigger() {}
master_trigger::~master_trigger(void) {}
static bool has_called = false;
@ -23,7 +23,7 @@ void master_trigger::run_daemon(int argc, char** argv)
#else
// 每个进程只能有一个实例在运行
acl_assert(has_called == false);
has_called = true;
has_called = true;
daemon_mode_ = true;
acl_trigger_server_main(argc, argv, service_main,
@ -50,8 +50,9 @@ void master_trigger::run_alone(const char* path /* = NULL */,
#ifdef ACL_WINDOWS
acl_cpp_init();
#endif
if (interval <= 0)
if (interval <= 0) {
interval = 1;
}
// 初始化配置参数
conf_.load(path);
@ -60,12 +61,12 @@ void master_trigger::run_alone(const char* path /* = NULL */,
service_init(this);
int i = 0;
while (true)
{
while (true) {
sleep(interval);
service_main(this);
if (count > 0 && ++i >= count)
if (count > 0 && ++i >= count) {
break;
}
}
service_exit(this);
@ -74,14 +75,12 @@ void master_trigger::run_alone(const char* path /* = NULL */,
const char* master_trigger::get_conf_path(void) const
{
#ifndef ACL_WINDOWS
if (daemon_mode_)
{
if (daemon_mode_) {
const char* ptr = acl_trigger_server_conf();
return ptr && *ptr ? ptr : NULL;
}
else
#endif
return conf_.get_path();
return conf_.get_path();
}
//////////////////////////////////////////////////////////////////////////
@ -92,8 +91,9 @@ void master_trigger::service_main(void* ctx)
acl_assert(mt != NULL);
#ifndef ACL_WINDOWS
if (mt->daemon_mode_)
if (mt->daemon_mode_) {
acl_watchdog_pat();
}
#endif
mt->on_trigger();
}
@ -104,8 +104,7 @@ void master_trigger::service_pre_jail(void* ctx)
acl_assert(mt != NULL);
#ifndef ACL_WINDOWS
if (mt->daemon_mode())
{
if (mt->daemon_mode()) {
ACL_EVENT* eventp = acl_trigger_server_event();
mt->set_event(eventp); // 设置基类的事件引擎句柄
}
@ -137,8 +136,9 @@ int master_trigger::service_on_sighup(void* ctx, ACL_VSTRING* buf)
acl_assert(mt);
string s;
bool ret = mt->proc_on_sighup(s);
if (buf)
if (buf) {
acl_vstring_strcpy(buf, s.c_str());
}
return ret ? 0 : -1;
}

View File

@ -17,8 +17,8 @@ master_udp::master_udp(void) {}
master_udp::~master_udp(void)
{
for (std::vector<socket_stream*>::iterator it = sstreams_.begin();
it != sstreams_.end(); ++it)
{
it != sstreams_.end(); ++it) {
(*it)->unbind();
delete *it;
}
@ -63,14 +63,12 @@ void master_udp::run_daemon(int argc, char** argv)
const char* master_udp::get_conf_path(void) const
{
#ifndef ACL_WINDOWS
if (daemon_mode_)
{
if (daemon_mode_) {
const char* ptr = acl_udp_server_conf();
return ptr && *ptr ? ptr : NULL;
}
else
#endif
return conf_.get_path();
return conf_.get_path();
}
//////////////////////////////////////////////////////////////////////////
@ -95,8 +93,7 @@ bool master_udp::run_alone(const char* addrs, const char* path /* = NULL */,
argv[argc++] = proc ? proc : "demo";
argv[argc++] = "-n";
argv[argc++] = addrs;
if (path && *path)
{
if (path && *path) {
argv[argc++] = "-f";
argv[argc++] = path;
}
@ -118,6 +115,7 @@ void master_udp::remove(socket_stream* ss)
for (std::vector<socket_stream*>::iterator it = sstreams_.begin();
it != sstreams_.end(); ++it) {
if (*it == ss) {
sstreams_.erase(it);
return;
@ -198,8 +196,9 @@ void master_udp::service_on_bind(void* ctx, ACL_VSTREAM* stream)
acl_assert(mu);
socket_stream* ss = NEW socket_stream();
if (ss->open(stream) == false)
if (!ss->open(stream)) {
logger_fatal("open stream error!");
}
stream->context = ss;
mu->push_back(ss);
@ -233,8 +232,9 @@ int master_udp::service_on_sighup(void* ctx, ACL_VSTRING* buf)
acl_assert(mu);
string s;
bool ret = mu->proc_on_sighup(s);
if (buf)
if (buf) {
acl_vstring_strcpy(buf, s.c_str());
}
return ret ? 0 : -1;
}

View File

@ -30,7 +30,7 @@ memcache::memcache(const char* addr /* = "127.0.0.1:11211" */,
set_timeout(conn_timeout, rw_timeout);
}
memcache::~memcache()
memcache::~memcache(void)
{
close();
delete keypre_;
@ -39,8 +39,7 @@ memcache::~memcache()
memcache& memcache::set_prefix(const char* keypre)
{
if (keypre == NULL || *keypre == 0)
{
if (keypre == NULL || *keypre == 0) {
delete keypre_;
keypre_ = NULL;
return *this;
@ -48,32 +47,30 @@ memcache& memcache::set_prefix(const char* keypre)
bool beCoding = false;
if (keypre_ == NULL)
if (keypre_ == NULL) {
keypre_ = NEW string(strlen(keypre));
else
} else {
keypre_->clear();
}
while (*keypre)
{
if (SPECIAL_CHAR(*keypre) || !ACL_ISPRINT(*keypre))
{
while (*keypre) {
if (SPECIAL_CHAR(*keypre) || !ACL_ISPRINT(*keypre)) {
coder_.encode_update(keypre, 1, keypre_);
beCoding = true;
}
else if (beCoding)
{
} else if (beCoding) {
coder_.encode_finish(keypre_);
coder_.reset();
beCoding = false;
*keypre_ << (char) *keypre;
}
else
} else {
*keypre_ << (char) *keypre;
}
keypre++;
}
if (beCoding)
if (beCoding) {
coder_.encode_finish(keypre_);
}
return *this;
}
@ -89,28 +86,26 @@ memcache& memcache::encode_key(bool onoff)
return *this;
}
void memcache::close()
void memcache::close(void)
{
if (opened_ == false)
if (!opened_) {
return;
if (conn_)
{
delete conn_;
conn_ = NULL;
}
delete conn_;
conn_ = NULL;
opened_ = false;
}
bool memcache::open()
bool memcache::open(void)
{
if (opened_)
if (opened_) {
return true;
}
conn_ = NEW socket_stream();
if (conn_->open(addr_, conn_timeout_, rw_timeout_) == false)
{
if (!conn_->open(addr_, conn_timeout_, rw_timeout_)) {
logger_error("connect %s error(%s)", addr_, last_serror());
delete conn_;
conn_ = NULL;
@ -131,8 +126,9 @@ bool memcache::set(const string& key, const void* dat, size_t dlen,
req_line_.format("set %s %u %d %d\r\n", key.c_str(),
flags, (int) timeout, (int) dlen);
AGAIN:
if (open() == false)
if (!open()) {
return false;
}
#ifdef MINGW
v[0].iov_base = (char*) req_line_.c_str();
@ -153,11 +149,9 @@ AGAIN:
#endif
v[2].iov_len = 2;
if (conn_->writev(v, 3) < 0)
{
if (conn_->writev(v, 3) < 0) {
close();
if (retry_ && !has_tried)
{
if (retry_ && !has_tried) {
has_tried = true;
goto AGAIN;
}
@ -165,11 +159,9 @@ AGAIN:
return false;
}
if (conn_->gets(res_line_) == false)
{
if (!conn_->gets(res_line_)) {
close();
if (retry_ && !has_tried)
{
if (retry_ && !has_tried) {
has_tried = true;
goto AGAIN;
}
@ -177,11 +169,9 @@ AGAIN:
return false;
}
if (res_line_.compare("STORED", false) != 0)
{
if (res_line_.compare("STORED", false) != 0) {
close();
if (retry_ && !has_tried)
{
if (retry_ && !has_tried) {
has_tried = true;
goto AGAIN;
}
@ -209,8 +199,9 @@ bool memcache::set(const char* key, size_t klen, time_t timeout /* = 0 */)
{
string buf;
unsigned short flags;
if (get(key, klen, buf, &flags) == false)
if (!get(key, klen, buf, &flags)) {
return false;
}
const string& kbuf = build_key(key, klen);
return set(kbuf, buf.c_str(), buf.length(), timeout, flags);
@ -224,8 +215,7 @@ bool memcache::set(const char* key, time_t timeout /* = 0 */)
bool memcache::set_begin(const char* key, size_t dlen,
time_t timeout /* = 0 */, unsigned short flags /* = 0 */)
{
if (dlen == 0)
{
if (dlen == 0) {
logger_error("dlen == 0, invalid");
return false;
}
@ -240,14 +230,13 @@ bool memcache::set_begin(const char* key, size_t dlen,
bool has_tried = false;
AGAIN:
if (open() == false)
if (!open()) {
return false;
}
if (conn_->write(req_line_) == -1)
{
if (conn_->write(req_line_) == -1) {
close();
if (retry_ && !has_tried)
{
if (retry_ && !has_tried) {
has_tried = true;
goto AGAIN;
}
@ -259,30 +248,25 @@ AGAIN:
bool memcache::set_data(const void* data, size_t dlen)
{
if (!opened_)
{
if (!opened_) {
ebuf_.format("not opened yet!");
return false;
}
if (data == NULL || dlen == 0)
{
if (data == NULL || dlen == 0) {
ebuf_.format("invalid input, data %s, dlen %d",
data ? "not null" : "null", dlen ? (int) dlen : 0);
return false;
}
if (dlen + length_ > content_length_)
{
if (dlen + length_ > content_length_) {
ebuf_.format("dlen(%d) + length_(%d) > content_length_(%d)",
(int) dlen, (int) length_, (int) content_length_);
return false;
}
if (dlen + length_ < content_length_)
{
if (conn_->write(data, dlen) == -1)
{
if (dlen + length_ < content_length_) {
if (conn_->write(data, dlen) == -1) {
close();
ebuf_.format("write data error");
return false;
@ -306,23 +290,20 @@ bool memcache::set_data(const void* data, size_t dlen)
#endif
v[1].iov_len = 2;
if (conn_->writev(v, 2) < 0)
{
if (conn_->writev(v, 2) < 0) {
close();
ebuf_.format("write data2 error!");
return false;
}
length_ += dlen;
if (conn_->gets(res_line_) == false)
{
if (!conn_->gets(res_line_)) {
close();
ebuf_.format("reply forerror");
return false;
}
if (res_line_.compare("STORED", false) != 0)
{
if (res_line_.compare("STORED", false) != 0) {
close();
ebuf_.format("reply(%s) error", res_line_.c_str());
return false;
@ -346,13 +327,12 @@ int memcache::get_begin(const void* key, size_t klen, unsigned short* flags)
req_line_.format("get %s\r\n", kbuf.c_str());
AGAIN:
if (open() == false)
if (!open()) {
return -1;
if (conn_->write(req_line_) < 0)
{
}
if (conn_->write(req_line_) < 0) {
close();
if (retry_ && !has_tried)
{
if (retry_ && !has_tried) {
has_tried = true;
goto AGAIN;
}
@ -361,47 +341,42 @@ AGAIN:
}
// 读取服务器响应行
if (conn_->gets(res_line_) == false)
{
if (!conn_->gets(res_line_)) {
close();
if (retry_ && !has_tried)
{
if (retry_ && !has_tried) {
has_tried = true;
goto AGAIN;
}
ebuf_.format("reply for get(%s) error", kbuf.c_str());
return -1;
}
else if (res_line_.compare("END", false) == 0)
{
} else if (res_line_.compare("END", false) == 0) {
ebuf_.format("not found");
return 0;
}
else if (error_happen(res_line_.c_str()))
{
} else if (error_happen(res_line_.c_str())) {
close();
return -1;
}
// VALUE {key} {flags} {bytes}\r\n
ACL_ARGV* tokens = acl_argv_split(res_line_.c_str(), " \t");
if (tokens->argc < 4 || strcasecmp(tokens->argv[0], "VALUE") != 0)
{
if (tokens->argc < 4 || strcasecmp(tokens->argv[0], "VALUE") != 0) {
close();
ebuf_.format("server error for get(%s), value: %s",
kbuf.c_str(), res_line_.c_str());
acl_argv_free(tokens);
return -1;
}
if (flags)
if (flags) {
*flags = (unsigned short) atoi(tokens->argv[2]);
}
content_length_ = atoi(tokens->argv[3]);
acl_argv_free(tokens);
// 如果服务端返回数据体长度值为 0 则当不存在处理
if (content_length_ == 0)
if (content_length_ == 0) {
return 0;
}
return (int) content_length_;
}
@ -409,19 +384,17 @@ int memcache::get_data(void* buf, size_t size)
{
acl_assert(content_length_ >= length_);
if (length_ == content_length_)
{
if (length_ == content_length_) {
// 读取数据尾部的 "\r\n"
if (conn_->gets(res_line_) == false)
{
if (!conn_->gets(res_line_)) {
close();
ebuf_.format("read data CRLF error");
return -1;
}
// 读取 "END\r\n"
if (conn_->gets(res_line_) == false
|| res_line_.compare("END", false) != 0)
{
if (!conn_->gets(res_line_)
|| res_line_.compare("END", false) != 0) {
close();
ebuf_.format("END flag not found");
return -1;
@ -430,10 +403,10 @@ int memcache::get_data(void* buf, size_t size)
}
size_t n = content_length_ - length_;
if (n > size)
if (n > size) {
n = size;
if (conn_->read(buf, n) < 0)
{
}
if (conn_->read(buf, n) < 0) {
close();
ebuf_.format("read data error!");
return -1;
@ -448,21 +421,22 @@ bool memcache::get(const char* key, size_t klen, string& out,
out.clear();
int len = get_begin(key, klen, flags);
if (len <= 0)
if (len <= 0) {
return false;
}
// 得需要保证足够的空间能容纳读取的数据,该种方式
// 可能会造成数据量非常大时的缓冲区溢出!
char buf[4096];
int n;
while (true)
{
while (true) {
n = get_data(buf, sizeof(buf));
if (n < 0)
if (n < 0) {
return false;
else if (n == 0)
} else if (n == 0) {
break;
}
out.append(buf, n);
}
@ -480,14 +454,13 @@ bool memcache::del(const char* key, size_t klen)
const string& kbuf = build_key(key, klen);
AGAIN:
if (open() == false)
if (!open()) {
return false;
}
req_line_.format("delete %s\r\n", kbuf.c_str());
if (conn_->write(req_line_) < 0)
{
if (retry_ && !has_tried)
{
if (conn_->write(req_line_) < 0) {
if (retry_ && !has_tried) {
has_tried = true;
goto AGAIN;
}
@ -495,10 +468,8 @@ AGAIN:
return false;
}
// DELETED|NOT_FOUND\r\n
if (conn_->gets(res_line_) == false)
{
if (retry_ && !has_tried)
{
if (!conn_->gets(res_line_)) {
if (retry_ && !has_tried) {
has_tried = true;
goto AGAIN;
}
@ -506,8 +477,8 @@ AGAIN:
return false;
}
if (res_line_.compare("DELETED", false) != 0
&& res_line_.compare("NOT_FOUND", false) != 0)
{
&& res_line_.compare("NOT_FOUND", false) != 0) {
ebuf_.format("reply(%s) for (%s) error",
res_line_.c_str(), req_line_.c_str());
return false;
@ -520,16 +491,17 @@ bool memcache::del(const char* key)
return del(key, strlen(key));
}
const char* memcache::last_serror() const
const char* memcache::last_serror(void) const
{
static const char* dummy = "ok";
if (ebuf_.empty())
if (ebuf_.empty()) {
return dummy;
}
return ebuf_.c_str();
}
int memcache::last_error() const
int memcache::last_error(void) const
{
return enum_;
}
@ -537,13 +509,13 @@ int memcache::last_error() const
const string& memcache::build_key(const char* key, size_t klen)
{
kbuf_.clear();
if (keypre_)
if (keypre_) {
kbuf_.format("%s:", keypre_->c_str());
}
coder_.reset();
if (encode_key_)
{
if (encode_key_) {
coder_.encode_update(key, (int) klen, &kbuf_);
coder_.encode_finish(&kbuf_);
return kbuf_;
@ -551,58 +523,56 @@ const string& memcache::build_key(const char* key, size_t klen)
bool beCoding = false;
while (klen > 0)
{
if (SPECIAL_CHAR(*key) || !ACL_ISPRINT(*key))
{
while (klen > 0) {
if (SPECIAL_CHAR(*key) || !ACL_ISPRINT(*key)) {
coder_.encode_update(key, 1, &kbuf_);
beCoding = true;
}
else if (beCoding)
{
} else if (beCoding) {
coder_.encode_finish(&kbuf_);
coder_.reset();
beCoding = false;
kbuf_ << (char) *key;
}
else
} else {
kbuf_ << (char) *key;
}
key++;
klen--;
}
if (beCoding)
if (beCoding) {
coder_.encode_finish(&kbuf_);
}
return kbuf_;
}
bool memcache::error_happen(const char* line)
{
if (strcasecmp(line, "ERROR") == 0)
if (strcasecmp(line, "ERROR") == 0) {
return true;
if (strncasecmp(line, "CLIENT_ERROR", sizeof("CLIENT_ERROR") - 1) == 0)
{
}
if (strncasecmp(line, "CLIENT_ERROR", sizeof("CLIENT_ERROR") - 1) == 0) {
ebuf_.format("%s", line);
const char* ptr = line + sizeof("CLIENT_ERROR") - 1;
if (*ptr == ' ' || *ptr == '\t')
if (*ptr == ' ' || *ptr == '\t') {
ptr++;
}
enum_ = atoi(ptr);
return true;
}
if (strncasecmp(line, "SERVER_ERROR", sizeof("SERVER_ERROR") - 1) == 0)
{
if (strncasecmp(line, "SERVER_ERROR", sizeof("SERVER_ERROR") - 1) == 0) {
ebuf_.format("%s", line);
const char* ptr = line + sizeof("SERVER_ERROR") - 1;
if (*ptr == ' ' || *ptr == '\t')
if (*ptr == ' ' || *ptr == '\t') {
ptr++;
}
enum_ = atoi(ptr);
return true;
}
return false;
}
void memcache::property_list()
void memcache::property_list(void)
{
}

View File

@ -9,11 +9,11 @@
namespace acl
{
memcache_manager::memcache_manager()
memcache_manager::memcache_manager(void)
{
}
memcache_manager::~memcache_manager()
memcache_manager::~memcache_manager(void)
{
}

View File

@ -15,12 +15,11 @@ memcache_pool::memcache_pool(const char* addr, size_t count,
{
}
memcache_pool::~memcache_pool()
memcache_pool::~memcache_pool(void)
{
}
connect_client* memcache_pool::create_connect()
connect_client* memcache_pool::create_connect(void)
{
return NEW memcache(addr_);
}

View File

@ -14,7 +14,7 @@ namespace acl
#define INT64_LEN 21
#define FLOAT_LEN 32
redis_hash::redis_hash()
redis_hash::redis_hash(void)
: redis_command(NULL)
{
}
@ -29,7 +29,7 @@ redis_hash::redis_hash(redis_client_cluster* cluster, size_t max_conns)
{
}
redis_hash::~redis_hash()
redis_hash::~redis_hash(void)
{
}

View File

@ -12,7 +12,7 @@
namespace acl
{
redis_pubsub::redis_pubsub()
redis_pubsub::redis_pubsub(void)
: redis_command(NULL)
{
}
@ -27,7 +27,7 @@ redis_pubsub::redis_pubsub(redis_client_cluster* cluster, size_t max_conns)
{
}
redis_pubsub::~redis_pubsub()
redis_pubsub::~redis_pubsub(void)
{
}

View File

@ -31,13 +31,13 @@ memcache_session::memcache_session(memcache* cache, bool auto_free /* = false */
, cache_(cache)
, auto_free_(auto_free)
{
}
memcache_session::~memcache_session()
memcache_session::~memcache_session(void)
{
if (auto_free_)
if (auto_free_) {
delete cache_;
}
}
bool memcache_session::get_attrs(std::map<string, session_string>& attrs)
@ -45,12 +45,14 @@ bool memcache_session::get_attrs(std::map<string, session_string>& attrs)
// 清空原有数据
attrs_clear(attrs);
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return false;
}
string buf;
if (cache_->get(sid, buf) == false)
if (!cache_->get(sid, buf)) {
return false;
}
// 反序列化
deserialize(buf, attrs);
@ -60,8 +62,9 @@ bool memcache_session::get_attrs(std::map<string, session_string>& attrs)
bool memcache_session::set_attrs(const std::map<string, session_string>& attrs)
{
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return false;
}
string buf;
serialize(attrs, buf); // 序列化数据
@ -69,11 +72,12 @@ bool memcache_session::set_attrs(const std::map<string, session_string>& attrs)
return cache_->set(sid, buf.c_str(), buf.length(), ttl);
}
bool memcache_session::remove()
bool memcache_session::remove(void)
{
const char* sid = get_sid();
if (sid == NULL || * sid == 0)
if (sid == NULL || * sid == 0) {
return false;
}
return cache_->del(sid);
}
@ -81,8 +85,9 @@ bool memcache_session::remove()
bool memcache_session::set_timeout(time_t ttl)
{
const char* sid = get_sid();
if (sid == NULL || * sid == 0)
if (sid == NULL || * sid == 0) {
return false;
}
return cache_->set(sid, ttl);
}

View File

@ -12,19 +12,20 @@ namespace acl
redis_session::redis_session(redis_client_cluster& cluster, size_t max_conns,
time_t ttl /* = 0 */, const char* sid /* = NULL */)
: session(ttl, sid)
, cluster_(cluster)
: session(ttl, sid)
, cluster_(cluster)
{
command_ = NEW redis;
command_->set_cluster(&cluster_, max_conns == 0 ? 128 : max_conns);
}
redis_session::~redis_session()
redis_session::~redis_session(void)
{
delete command_;
std::map<string, session_string*>::iterator it;
for (it = buffers_.begin(); it != buffers_.end(); ++it)
for (it = buffers_.begin(); it != buffers_.end(); ++it) {
delete it->second;
}
}
bool redis_session::set(const char* name, const char* value)
@ -35,15 +36,18 @@ bool redis_session::set(const char* name, const char* value)
bool redis_session::set(const char* name, const void* value, size_t len)
{
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return false;
}
command_->clear();
if (command_->hset(sid, name, (const char*) value, len) < 0)
if (command_->hset(sid, name, (const char*) value, len) < 0) {
return false;
}
time_t ttl = get_ttl();
if (ttl > 0)
if (ttl > 0) {
return set_timeout(ttl);
}
return true;
}
@ -51,35 +55,35 @@ const session_string* redis_session::get_buf(const char* name)
{
command_->clear();
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return NULL;
}
// 先尝试从缓存池中获得一个缓冲区,如果没有合适的,则创建新的缓冲区对象
// 并将之加入至缓冲池中,以备下次重复查询相同属性时使用
session_string* ss;
std::map<string, session_string*>::iterator it = buffers_.find(name);
if (it == buffers_.end())
{
if (it == buffers_.end()) {
ss = NEW session_string;
buffers_[name] = ss;
}
else
{
} else {
ss = it->second;
ss->clear();
}
if (command_->hget(sid, name, *ss) == false)
if (!command_->hget(sid, name, *ss)) {
return NULL;
}
return ss;
}
bool redis_session::del(const char* name)
{
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return false;
}
command_->clear();
return command_->hdel(sid, name) >= 0 ? true : false;
@ -88,26 +92,30 @@ bool redis_session::del(const char* name)
bool redis_session::set_attrs(const std::map<string, session_string>& attrs)
{
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return false;
}
command_->clear();
if (command_->hmset(sid, (const std::map<string, string>&) attrs) == false)
if (!command_->hmset(sid, (const std::map<string, string>&) attrs)) {
return false;
}
time_t ttl = get_ttl();
if (ttl > 0)
if (ttl > 0) {
return set_timeout(ttl);
else
} else {
return true;
}
}
bool redis_session::get_attrs(std::map<string, session_string>& attrs)
{
attrs_clear(attrs);
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return false;
}
command_->clear();
return command_->hgetall(sid, (std::map<string, string>&) attrs);
@ -118,28 +126,31 @@ bool redis_session::get_attrs(const std::vector<string>& names,
{
values.clear();
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return false;
}
command_->clear();
std::vector<string> vals;
if (command_->hmget(sid, names, &vals) == false)
if (!command_->hmget(sid, names, &vals)) {
return false;
}
for (std::vector<string>::const_iterator cit = vals.begin();
cit != vals.end(); ++cit)
{
cit != vals.end(); ++cit) {
values.push_back(*cit);
}
return true;
}
bool redis_session::remove()
bool redis_session::remove(void)
{
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return false;
}
command_->clear();
return command_->del(sid) >= 0 ? true : false;
@ -148,8 +159,9 @@ bool redis_session::remove()
bool redis_session::set_timeout(time_t ttl)
{
const char* sid = get_sid();
if (sid == NULL || *sid == 0)
if (sid == NULL || *sid == 0) {
return false;
}
command_->clear();
return command_->expire(sid, (int) ttl) > 0 ? true : false;

View File

@ -18,8 +18,7 @@ session::session(time_t ttl /* = 0 */, const char* sid /* = NULL */)
, ttl_(ttl)
, dirty_(false)
{
if (sid == NULL || *sid == 0)
{
if (sid == NULL || *sid == 0) {
struct timeval tv;
(void) gettimeofday(&tv, NULL);
@ -27,16 +26,14 @@ session::session(time_t ttl /* = 0 */, const char* sid /* = NULL */)
(int) tv.tv_usec, rand());
sid_.todo_ = TODO_NUL;
sid_saved_ = false;
}
else
{
} else {
sid_.copy(sid);
sid_.todo_ = TODO_NUL;
sid_saved_ = true;
}
}
session::~session()
session::~session(void)
{
reset();
}
@ -47,14 +44,15 @@ void session::set_sid(const char* sid)
sid_.todo_ = TODO_NUL;
// 有可能已经存储在后端 cache 服务端了
if (!sid_saved_)
if (!sid_saved_) {
sid_saved_ = true;
}
// 必须清除上次的中间结果
reset();
}
void session::reset()
void session::reset(void)
{
attrs_clear(attrs_);
attrs_clear(attrs_cache_);
@ -65,45 +63,39 @@ void session::attrs_clear(std::map<string, session_string>& attrs)
attrs.clear();
}
bool session::flush()
bool session::flush(void)
{
if (!dirty_)
if (!dirty_) {
return true;
}
dirty_ = false;
// 调用纯虚接口,获得原来的 sid 数据
if (get_attrs(attrs_) == true)
{
if (!sid_saved_)
if (get_attrs(attrs_)) {
if (!sid_saved_) {
sid_saved_ = true;
}
}
std::map<string, session_string>::iterator it_cache =
attrs_cache_.begin();
for (; it_cache != attrs_cache_.end(); ++it_cache)
{
for (; it_cache != attrs_cache_.end(); ++it_cache) {
// 如果该属性已存在,则需要先释放原来的属性值后再添加新值
std::map<string, session_string>::iterator it_attr =
attrs_.find(it_cache->first);
if (it_attr == attrs_.end())
{
if (it_cache->second.todo_ == TODO_SET)
if (it_attr == attrs_.end()) {
if (it_cache->second.todo_ == TODO_SET) {
attrs_.insert(std::make_pair(it_cache->first,
it_cache->second));
}
else if (it_cache->second.todo_ == TODO_SET)
{
}
} else if (it_cache->second.todo_ == TODO_SET) {
// 设置新的数据
attrs_.insert(std::make_pair(it_cache->first,
it_cache->second));
}
else if (it_cache->second.todo_ == TODO_DEL)
{
} else if (it_cache->second.todo_ == TODO_DEL) {
attrs_.erase(it_attr);
}
else
{
} else {
logger_warn("unknown todo(%d)",
(int) it_cache->second.todo_);
}
@ -114,8 +106,7 @@ bool session::flush()
attrs_cache_.clear();
// 调用纯虚接口,向 memcached 或类似缓存中添加数据
if (set_attrs(attrs_) == false)
{
if (!this->set_attrs(attrs_)) {
logger_error("set cache error, sid(%s)", sid_.c_str());
attrs_clear(attrs_); // 清除属性集合数据
@ -124,8 +115,9 @@ bool session::flush()
attrs_clear(attrs_); // 清除属性集合数据
if (!sid_saved_)
if (!sid_saved_) {
sid_saved_ = true;
}
return true;
}
@ -150,18 +142,17 @@ bool session::set(const char* name, const void* value, size_t len)
// 直接操作后端 cache 服务器,设置(添加/修改) 属性字段
// 调用纯虚接口,获得原来的 sid 数据
if (get_attrs(attrs_) == false)
{
if (!this->get_attrs(attrs_)) {
session_string ss(len);
ss.copy(value, len);
ss.todo_ = TODO_SET;
attrs_cache_.insert(std::make_pair(string(name), ss));
}
// 如果存在对应 sid 的数据,则将新数据添加在原来数据中
else
{
if (!sid_saved_)
else {
if (!sid_saved_) {
sid_saved_ = true;
}
// 如果该属性已存在,则需要先释放原来的属性值后再添加新值
session_string ss(len);
@ -171,8 +162,7 @@ bool session::set(const char* name, const void* value, size_t len)
}
// 调用纯虚接口,向 memcached 或类似缓存中添加数据
if (set_attrs(attrs_) == false)
{
if (!this->set_attrs(attrs_)) {
logger_error("set cache error, sid(%s)", sid_.c_str());
attrs_clear(attrs_); // 清除属性集合数据
@ -180,16 +170,18 @@ bool session::set(const char* name, const void* value, size_t len)
}
attrs_clear(attrs_); // 清除属性集合数据
if (!sid_saved_)
if (!sid_saved_) {
sid_saved_ = true;
}
return true;
}
const char* session::get(const char* name)
{
const session_string* bf = get_buf(name);
if (bf == NULL)
if (bf == NULL) {
return "";
}
return bf->c_str();
}
@ -197,12 +189,14 @@ const session_string* session::get_buf(const char* name)
{
attrs_clear(attrs_);
if (get_attrs(attrs_) == false)
if (!get_attrs(attrs_)) {
return NULL;
}
std::map<string, session_string>::const_iterator cit = attrs_.find(name);
if (cit == attrs_.end())
if (cit == attrs_.end()) {
return NULL;
}
return &cit->second;
}
@ -211,18 +205,20 @@ bool session::get_attrs(const std::vector<string>& names,
{
attrs_clear(attrs_);
if (get_attrs(attrs_) == false)
if (!get_attrs(attrs_)) {
return false;
}
for (std::vector<string>::const_iterator cit = names.begin();
cit != names.end(); ++cit)
{
cit != names.end(); ++cit) {
std::map<string, session_string>::const_iterator cit2
= attrs_.find(*cit);
if (cit2 != attrs_.end())
if (cit2 != attrs_.end()) {
values.push_back(cit2->second);
else
} else {
values.push_back("");
}
}
return true;
@ -230,41 +226,40 @@ bool session::get_attrs(const std::vector<string>& names,
bool session::set_ttl(time_t ttl, bool delay)
{
if (ttl == ttl_)
if (ttl == ttl_) {
return true;
}
// 如果是延迟修改,则仅设置相关成员变量,最后统一 flush
else if (delay)
{
ttl_ = ttl;
else if (delay) {
ttl_ = ttl;
dirty_ = true;
return true;
}
#if 0
// 如果该 sid 还没有在后端 cache 上存储过,则仅在对象中本地设置一下
else if (!sid_saved_)
{
else if (!sid_saved_) {
ttl_ = ttl;
return true;
}
#endif
// 修改后端 cache 上针对该 sid 的 ttl
else if (set_timeout(ttl) == true)
{
else if (set_timeout(ttl)) {
ttl_ = ttl;
return true;
}
else
} else {
return false;
}
}
bool session::del_delay(const char* name)
{
std::map<string, session_string>::iterator it = attrs_cache_.find(name);
if (it != attrs_cache_.end())
if (it != attrs_cache_.end()) {
it->second.todo_ = TODO_DEL;
}
dirty_ = true;
return true;
}
@ -273,22 +268,22 @@ bool session::del(const char* name)
{
// 直接操作后端 cache 服务器,删除属性字段
if (get_attrs(attrs_) == false)
if (!get_attrs(attrs_)) {
return true;
}
std::map<string, session_string>::iterator it = attrs_.find(name);
if (it == attrs_.end())
if (it == attrs_.end()) {
return false;
}
// 先删除并释放对应的对象
attrs_.erase(it);
// 如果 sid 中已经没有了数据,则应该将 sid 对象从 memcached 中删除
if (attrs_.empty())
{
if (attrs_.empty()) {
// 调用虚函数,删除该 sid 对应的缓存内容
if (remove() == false)
{
if (!this->remove()) {
logger_error("del sid(%s) error", sid_.c_str());
return false;
}
@ -297,15 +292,14 @@ bool session::del(const char* name)
// 重新添加剩余的数据
if (set_attrs(attrs_) == false)
{
if (!set_attrs(attrs_)) {
logger_error("set cache error, sid(%s)", sid_.c_str());
attrs_clear(attrs_); // 清除属性集合数据
return false;
}
attrs_clear(attrs_); // Çå³ýÊôÐÔ¼¯ºÏÊý¾Ý
attrs_clear(attrs_); // Çå³ýÊôÐÔ¼¯ºÏÊý¾Ý
return true;
}
@ -317,8 +311,9 @@ void session::serialize(const std::map<string, session_string>& attrs,
out.clear(); // 先清除缓冲区
std::map<string, session_string>::const_iterator it = attrs.begin();
if (it == attrs.end())
if (it == attrs.end()) {
return;
}
// 添加第一个属性
const char ch = 1;
@ -328,8 +323,7 @@ void session::serialize(const std::map<string, session_string>& attrs,
++it;
// 添加后续的属性
for (; it != attrs.end(); ++it)
{
for (; it != attrs.end(); ++it) {
// 除第一个属性外后续的都需要添加分隔符
out << '\t';
escape(it->first.c_str(), it->first.length(), out);
@ -346,14 +340,12 @@ void session::deserialize(string& buf, std::map<string, session_string>& attrs)
ACL_ARGV* tokens = acl_argv_split(buf.c_str(), "\t");
ACL_ITER iter;
acl_foreach(iter, tokens)
{
acl_foreach(iter, tokens) {
char* ptr = (char*) iter.data;
// 重复使用原来的内存区,因为 tokens 中已经存储了中间结果数据
buf.clear();
if (unescape(ptr, strlen(ptr), buf) == false)
{
if (!unescape(ptr, strlen(ptr), buf)) {
logger_error("unescape error");
continue;
}
@ -361,8 +353,9 @@ void session::deserialize(string& buf, std::map<string, session_string>& attrs)
// 因为 acl::string 肯定能保证缓冲区数据的尾部有 \0所以在用
// strchr 时不必须担心越界问题,但 std::string 并不保证这样
char* p1 = strchr(ptr, 1);
if (p1 == NULL || *(p1 + 1) == 0)
if (p1 == NULL || *(p1 + 1) == 0) {
continue;
}
*p1++ = 0;
//std::map<string, session_string>::iterator it = attrs.find(ptr);

View File

@ -24,24 +24,24 @@ mail_attach::mail_attach(const char* filepath, const char* content_type,
filename.basename(filename);
// 文件名需要采用 rfc2047 编码
if (rfc2047_encode(filename.c_str(), charset, filename_) == false)
if (!rfc2047_encode(filename.c_str(), charset, filename_)) {
filename_ = filename.c_str();
}
}
mail_attach::~mail_attach()
mail_attach::~mail_attach(void)
{
}
bool mail_attach::rfc2047_encode(const char* name, const char* charset,
string& out)
{
if (charset == NULL || *charset == 0)
if (charset == NULL || *charset == 0) {
return false;
}
// 文件名需要采用 rfc2047 编码
if (rfc2047::encode(name, (int) strlen(name),
&out, charset, 'B', false) == false)
{
if (!rfc2047::encode(name, (int) strlen(name), &out, charset, 'B', false)) {
out = name;
return false;
}
@ -52,41 +52,42 @@ bool mail_attach::rfc2047_encode(const char* name, const char* charset,
mail_attach& mail_attach::set_filename(const char* name,
const char* charset /* = NULL */)
{
if (rfc2047_encode(name, charset, filename_) == false)
if (!rfc2047_encode(name, charset, filename_)) {
filename_ = name;
}
return *this;
}
mail_attach& mail_attach::set_content_id(const char* id)
{
if (id && *id)
if (id && *id) {
cid_.format("%s", id);
}
return *this;
}
bool mail_attach::save_to(mime_code* coder, string& out)
{
if (coder)
if (coder) {
build_header(coder->get_encoding_type(), out);
else
} else {
build_header(NULL, out);
}
string buf;
if (ifstream::load(filepath_.c_str(), &buf) == false)
{
if (!ifstream::load(filepath_.c_str(), &buf)) {
logger_error("load %s error %s",
filepath_.c_str(), last_serror());
return false;
}
if (coder)
{
if (coder) {
coder->reset();
coder->encode_update(buf.c_str(), (int) buf.size(), &out);
coder->encode_finish(&out);
}
else
} else {
out.append(buf);
}
return true;
}
@ -95,20 +96,19 @@ bool mail_attach::save_to(mime_code* coder, ostream& out)
{
string header;
if (coder)
if (coder) {
build_header(coder->get_encoding_type(), header);
else
} else {
build_header(NULL, header);
}
if (out.write(header) == -1)
{
if (out.write(header) == -1) {
logger_error("write to stream error %s", last_serror());
return false;
}
ifstream in;
if (in.open_read(filepath_.c_str()) == false)
{
if (!in.open_read(filepath_.c_str())) {
logger_error("open %s error %s",
filepath_.c_str(), last_serror());
return false;
@ -118,15 +118,13 @@ bool mail_attach::save_to(mime_code* coder, ostream& out)
int ret;
string body(8192);
while (!in.eof())
{
while (!in.eof()) {
ret = in.read(buf, sizeof(buf), false);
if (ret == -1)
if (ret == -1) {
break;
if (coder == NULL)
{
if (out.write(buf, ret) == -1)
{
}
if (coder == NULL) {
if (out.write(buf, ret) == -1) {
logger_error("write body error %s",
last_serror());
return false;
@ -134,27 +132,25 @@ bool mail_attach::save_to(mime_code* coder, ostream& out)
}
coder->encode_update(buf, ret, &body);
if (body.empty())
if (body.empty()) {
continue;
}
if (out.write(body) == -1)
{
if (out.write(body) == -1) {
logger_error("write body error %s", last_serror());
return false;
}
body.clear();
}
if (coder)
{
if (coder) {
coder->encode_finish(&body);
body.append("\r\n");
}
else
} else {
body.append("\r\n");
}
if (out.write(body) == -1)
{
if (out.write(body) == -1) {
logger_error("write body error %s", last_serror());
return false;
}
@ -167,15 +163,17 @@ void mail_attach::build_header(const char* transfer_encoding, string& out)
out.format_append("Content-Type: %s;\r\n", ctype_.c_str());
out.format_append("\tname=\"%s\"\r\n", filename_.c_str());
if (transfer_encoding && *transfer_encoding)
if (transfer_encoding && *transfer_encoding) {
out.format_append("Content-Transfer-Encoding: %s\r\n",
transfer_encoding);
}
if (cid_.empty())
if (cid_.empty()) {
out.format_append("Content-Disposition: attachment;\r\n"
"\tfilename=\"%s\"\r\n", filename_.c_str());
else
} else {
out.format_append("Content-ID: <%s>\r\n", cid_.c_str());
}
out.append("\r\n");
}

View File

@ -18,29 +18,30 @@ namespace acl {
mail_body::mail_body(const char* charset /* = "utf-8" */,
const char* encoding /* = "base64" */)
: charset_(charset)
, transfer_encoding_(encoding)
: charset_(charset)
, transfer_encoding_(encoding)
{
if (transfer_encoding_.compare("base64", false) == 0)
if (transfer_encoding_.compare("base64", false) == 0) {
coder_ = NEW mime_base64(true, true);
else if (transfer_encoding_.compare("qp", false) == 0)
} else if (transfer_encoding_.compare("qp", false) == 0) {
coder_ = NEW mime_quoted_printable(true, true);
else if (transfer_encoding_.compare("uucode", false) == 0)
} else if (transfer_encoding_.compare("uucode", false) == 0) {
coder_ = NEW mime_uucode(true, true);
else if (transfer_encoding_.compare("xxcode", false) == 0)
} else if (transfer_encoding_.compare("xxcode", false) == 0) {
coder_ = NEW mime_xxcode(true, true);
else
} else {
coder_ = NULL;
}
html_ = NULL;
hlen_ = 0;
plain_ = NULL;
plen_ = 0;
html_ = NULL;
hlen_ = 0;
plain_ = NULL;
plen_ = 0;
attachments_ = NULL;
mime_stype_ = MIME_STYPE_OTHER;
mime_stype_ = MIME_STYPE_OTHER;
}
mail_body::~mail_body()
mail_body::~mail_body(void)
{
delete coder_;
}
@ -49,29 +50,29 @@ mail_body& mail_body::set_html(const char* html, size_t len)
{
html_ = html;
hlen_ = len;
mime_stype_ = MIME_STYPE_HTML;
mime_stype_ = MIME_STYPE_HTML;
return *this;
}
mail_body& mail_body::set_plain(const char* plain, size_t len)
{
plain_ = plain;
plen_ = len;
mime_stype_ = MIME_STYPE_PLAIN;
plen_ = len;
mime_stype_ = MIME_STYPE_PLAIN;
return *this;
}
mail_body& mail_body::set_alternative(const char* html, size_t hlen,
const char* plain, size_t plen)
{
html_ = html;
hlen_ = hlen;
html_ = html;
hlen_ = hlen;
plain_ = plain;
plen_ = plen;
mime_stype_ = MIME_STYPE_ALTERNATIVE;
plen_ = plen;
mime_stype_ = MIME_STYPE_ALTERNATIVE;
return *this;
}
@ -79,12 +80,13 @@ mail_body& mail_body::set_relative(const char* html, size_t hlen,
const char* plain, size_t plen,
const std::vector<mail_attach*>& attachments)
{
html_ = html;
hlen_ = hlen;
html_ = html;
hlen_ = hlen;
plain_ = plain;
plen_ = plen;
plen_ = plen;
attachments_ = &attachments;
mime_stype_ = MIME_STYPE_RELATED;
mime_stype_ = MIME_STYPE_RELATED;
return *this;
}
@ -117,8 +119,7 @@ bool mail_body::build_plain(const char* in, size_t len,
bool mail_body::save_to(string& out) const
{
switch (mime_stype_)
{
switch (mime_stype_) {
case MIME_STYPE_HTML:
return save_html(html_, hlen_, out);
case MIME_STYPE_PLAIN:
@ -143,8 +144,7 @@ void mail_body::set_content_type(const char* content_type)
bool mail_body::save_html(const char* html, size_t len, string& out) const
{
if (!html || !len)
{
if (!html || !len) {
logger_error("invalid input!");
return false;
}
@ -156,8 +156,7 @@ bool mail_body::save_html(const char* html, size_t len, string& out) const
bool mail_body::save_plain(const char* plain, size_t len, string& out) const
{
if (!plain || !len)
{
if (!plain || !len) {
logger_error("invalid input!");
return false;
}
@ -172,8 +171,7 @@ bool mail_body::save_relative(const char* html, size_t hlen,
const std::vector<mail_attach*>& attachments,
string& out) const
{
if (!html || !hlen || !plain || !plen || attachments.empty())
{
if (!html || !hlen || !plain || !plen || attachments.empty()) {
logger_error("invalid input!");
return false;
}
@ -193,30 +191,29 @@ bool mail_body::save_relative(const char* html, size_t hlen,
// 递归一层,调用生成 alternative 格式数据
mail_body body(charset_.c_str(), transfer_encoding_.c_str());
bool ret = body.save_alternative(html, hlen, plain, plen, out);
if (ret == false)
if (ret == false) {
return ret;
}
out.append("\r\n");
std::vector<mail_attach*>::const_iterator cit;
for (cit = attachments.begin(); cit != attachments.end(); ++cit)
{
for (cit = attachments.begin(); cit != attachments.end(); ++cit) {
out.format_append("--%s\r\n", boundary_.c_str());
if ((*cit)->save_to(coder_, out) == false)
if (!(*cit)->save_to(coder_, out)) {
return false;
}
out.append("\r\n");
}
out.format_append("\r\n--%s--\r\n", boundary_.c_str());
return true;
}
bool mail_body::save_alternative(const char* html, size_t hlen,
const char* plain, size_t plen, string& out) const
{
if (!html || !hlen || !plain || !plen)
{
if (!html || !hlen || !plain || !plen) {
logger_error("invalid input!");
return false;
}
@ -230,17 +227,18 @@ bool mail_body::save_alternative(const char* html, size_t hlen,
out.format_append("Content-Type: %s\r\n\r\n", content_type_.c_str());
out.format_append("--%s\r\n", boundary_.c_str());
if (build_plain(plain, plen, charset_.c_str(), out) == false)
if (!build_plain(plain, plen, charset_.c_str(), out)) {
return false;
}
out.append("\r\n\r\n");
out.format_append("--%s\r\n", boundary_.c_str());
if (build_html(html, hlen, charset_.c_str(), out) == false)
if (!build_html(html, hlen, charset_.c_str(), out)) {
return false;
}
out.append("\r\n\r\n");
out.format_append("--%s--\r\n", boundary_.c_str());
return true;
}

View File

@ -24,35 +24,36 @@ namespace acl
mail_message::mail_message(const char* charset /* = "utf-8"*/)
{
dbuf_ = new dbuf_pool;
if (charset == NULL || *charset == 0)
if (charset == NULL || *charset == 0) {
charset = "utf-8";
}
charset_ = dbuf_->dbuf_strdup(charset);
transfer_encoding_ = dbuf_->dbuf_strdup("base64");
auth_user_ = NULL;
auth_pass_ = NULL;
from_ = NULL;
sender_ = NULL;
reply_to_ = NULL;
return_path_ = NULL;
auth_user_ = NULL;
auth_pass_ = NULL;
from_ = NULL;
sender_ = NULL;
reply_to_ = NULL;
return_path_ = NULL;
delivered_to_ = NULL;
subject_ = NULL;
body_ = NULL;
body_len_ = 0;
filepath_ = NULL;
subject_ = NULL;
body_ = NULL;
body_len_ = 0;
filepath_ = NULL;
}
mail_message::~mail_message()
mail_message::~mail_message(void)
{
std::vector<mail_attach*>::iterator it;
for (it = attachments_.begin(); it != attachments_.end(); ++it)
for (it = attachments_.begin(); it != attachments_.end(); ++it) {
(*it)->~mail_attach();
}
dbuf_->destroy();
}
mail_message& mail_message::set_auth(const char* user, const char* pass)
{
if (user && *user && pass && *pass)
{
if (user && *user && pass && *pass) {
auth_user_ = dbuf_->dbuf_strdup(user);
auth_pass_ = dbuf_->dbuf_strdup(pass);
}
@ -61,47 +62,54 @@ mail_message& mail_message::set_auth(const char* user, const char* pass)
mail_message& mail_message::set_from(const char* from, const char* name)
{
if (from == NULL || *from == 0)
if (from == NULL || *from == 0) {
return *this;
}
from_ = (rfc822_addr*) dbuf_->dbuf_alloc(sizeof(rfc822_addr));
from_->addr = dbuf_->dbuf_strdup(from);
if (name && *name)
if (name && *name) {
from_->comment = dbuf_->dbuf_strdup(name);
else
} else {
from_->comment = NULL;
}
return *this;
}
mail_message& mail_message::set_sender(const char* sender, const char* name)
{
if (sender == NULL || *sender == 0)
if (sender == NULL || *sender == 0) {
return *this;
}
sender_ = (rfc822_addr*) dbuf_->dbuf_alloc(sizeof(rfc822_addr));
sender_->addr = dbuf_->dbuf_strdup(sender);
if (name && *name)
if (name && *name) {
sender_->comment = dbuf_->dbuf_strdup(name);
else
} else {
sender_->comment = NULL;
}
return *this;
}
mail_message& mail_message::set_reply_to(const char* replyto, const char* name)
{
if (replyto == NULL || *replyto == 0)
if (replyto == NULL || *replyto == 0) {
return *this;
}
reply_to_ = (rfc822_addr*) dbuf_->dbuf_alloc(sizeof(rfc822_addr));
reply_to_->addr = dbuf_->dbuf_strdup(replyto);
if (name && *name)
if (name && *name) {
reply_to_->comment = dbuf_->dbuf_strdup(name);
else
} else {
reply_to_->comment = NULL;
}
return *this;
}
mail_message& mail_message::set_return_path(const char* return_path)
{
if (return_path == NULL || *return_path == 0)
if (return_path == NULL || *return_path == 0) {
return *this;
}
return_path_ = (rfc822_addr*) dbuf_->dbuf_alloc(sizeof(rfc822_addr));
return_path_->addr = dbuf_->dbuf_strdup(return_path);
return_path_->comment = NULL;
@ -110,8 +118,9 @@ mail_message& mail_message::set_return_path(const char* return_path)
mail_message& mail_message::set_delivered_to(const char* delivered_to)
{
if (delivered_to == NULL || *delivered_to == 0)
if (delivered_to == NULL || *delivered_to == 0) {
return *this;
}
delivered_to_ = (rfc822_addr*) dbuf_->dbuf_alloc(sizeof(rfc822_addr));
delivered_to_->addr = dbuf_->dbuf_strdup(delivered_to);
delivered_to_->comment = NULL;
@ -123,17 +132,18 @@ void mail_message::add_addrs(const char* in, std::vector<rfc822_addr*>& out)
rfc822 rfc;
const std::list<rfc822_addr*>& addrs = rfc.parse_addrs(in, charset_);
std::list<rfc822_addr*>::const_iterator cit = addrs.begin();
for (; cit != addrs.end(); ++cit)
{
for (; cit != addrs.end(); ++cit) {
rfc822_addr* addr = (rfc822_addr* )
dbuf_->dbuf_alloc(sizeof(rfc822_addr));
if ((*cit)->addr == NULL)
if ((*cit)->addr == NULL) {
continue;
}
addr->addr = dbuf_->dbuf_strdup((*cit)->addr);
if ((*cit)->comment)
if ((*cit)->comment) {
addr->comment = dbuf_->dbuf_strdup((*cit)->comment);
else
} else {
addr->comment = NULL;
}
out.push_back(addr);
}
}
@ -143,15 +153,15 @@ mail_message& mail_message::add_recipients(const char* recipients)
string buf(recipients);
std::list<string>& tokens = buf.split(" \t;,");
std::list<string>::const_iterator cit;
for (cit = tokens.begin(); cit != tokens.end(); ++cit)
for (cit = tokens.begin(); cit != tokens.end(); ++cit) {
(void) add_to((*cit).c_str());
}
return *this;
}
mail_message& mail_message::add_to(const char* to)
{
if (to && *to)
{
if (to && *to) {
add_addrs(to, to_list_);
add_addrs(to, recipients_);
}
@ -160,8 +170,7 @@ mail_message& mail_message::add_to(const char* to)
mail_message& mail_message::add_cc(const char* cc)
{
if (cc && *cc)
{
if (cc && *cc) {
add_addrs(cc, to_list_);
add_addrs(cc, recipients_);
}
@ -170,8 +179,7 @@ mail_message& mail_message::add_cc(const char* cc)
mail_message& mail_message::add_bcc(const char* bcc)
{
if (bcc && *bcc)
{
if (bcc && *bcc) {
add_addrs(bcc, to_list_);
add_addrs(bcc, recipients_);
}
@ -180,15 +188,17 @@ mail_message& mail_message::add_bcc(const char* bcc)
mail_message& mail_message::set_subject(const char* subject)
{
if (subject && *subject)
if (subject && *subject) {
subject_ = dbuf_->dbuf_strdup(subject);
}
return *this;
}
mail_message& mail_message::add_header(const char* name, const char* value)
{
if (name == NULL || *name == 0 || value == NULL || *value == 0)
if (name == NULL || *name == 0 || value == NULL || *value == 0) {
return *this;
}
char* n = dbuf_->dbuf_strdup(name);
char* v = dbuf_->dbuf_strdup(value);
headers_.push_back(std::make_pair(n, v));
@ -198,10 +208,10 @@ mail_message& mail_message::add_header(const char* name, const char* value)
const char* mail_message::get_header_value(const char* name) const
{
std::vector<std::pair<char*, char*> >::const_iterator cit;
for (cit = headers_.begin(); cit != headers_.end(); ++cit)
{
if (strcasecmp((*cit).first, name) == 0)
for (cit = headers_.begin(); cit != headers_.end(); ++cit) {
if (strcasecmp((*cit).first, name) == 0) {
return (*cit).second;
}
}
return NULL;
}
@ -215,8 +225,9 @@ mail_message& mail_message::set_body(const mail_body& body)
mail_message& mail_message::add_attachment(const char* filepath,
const char* content_type)
{
if (filepath == NULL || content_type == NULL)
if (filepath == NULL || content_type == NULL) {
return *this;
}
char* buf = (char*) dbuf_->dbuf_alloc(sizeof(mail_attach));
mail_attach* attach = new(buf) mail_attach(filepath,
@ -235,12 +246,11 @@ mail_message& mail_message::add_attachment(const char* filepath,
bool mail_message::append_addr(const rfc822_addr& addr, string& out)
{
if (addr.comment)
{
if (addr.comment) {
out.append("\"");
if (rfc2047::encode(addr.comment, (int) strlen(addr.comment),
&out, charset_, 'B', false) == false)
{
if (!rfc2047::encode(addr.comment, (int) strlen(addr.comment),
&out, charset_, 'B', false)) {
logger_error("rfc2047::encode(%s) error",
addr.comment);
return false;
@ -257,8 +267,9 @@ bool mail_message::append_addr(const char* name, const rfc822_addr& addr,
{
out.format_append("%s: ", name);
if (append_addr(addr, out) == false)
if (!append_addr(addr, out)) {
return false;
}
out.append("\r\n");
return true;
@ -268,29 +279,29 @@ bool mail_message::append_addrs(const char* name,
const std::vector<rfc822_addr*>& addrs, string& out)
{
std::vector<rfc822_addr*>::const_iterator cit = addrs.begin();
if (cit == addrs.end())
if (cit == addrs.end()) {
return true;
}
out.format_append("%s: ", name);
if (append_addr(**cit, out) == false)
if (!append_addr(**cit, out)) {
return false;
}
if (++cit == addrs.end())
{
if (++cit == addrs.end()) {
out.append("\r\n");
return true;
}
out.append(",\r\n");
while (true)
{
while (true) {
out.append("\t");
if (append_addr(**cit, out) == false)
if (!append_addr(**cit, out)) {
return false;
}
if (++cit == addrs.end())
{
if (++cit == addrs.end()) {
out.append("\r\n");
break;
}
@ -303,9 +314,9 @@ bool mail_message::append_addrs(const char* name,
bool mail_message::append_subject(const char* subject, string& out)
{
out.append("Subject: ");
if (rfc2047::encode(subject, (int) strlen(subject), &out,
charset_, 'B', false) == false)
{
if (!rfc2047::encode(subject, (int) strlen(subject), &out,
charset_, 'B', false)) {
logger_error("rfc2047::encode error!");
return false;
}
@ -333,37 +344,46 @@ bool mail_message::append_message_id(string& out)
bool mail_message::build_header(string& out)
{
std::vector<std::pair<char*, char*> >::const_iterator cit;
for (cit = headers_.begin(); cit != headers_.end(); ++cit)
for (cit = headers_.begin(); cit != headers_.end(); ++cit) {
out.format_append("%s: %s\r\n", (*cit).first, (*cit).second);
}
//if (reply_to_ && !append_addr(fp, "ReplyTo", *reply_to_))
// return false;
if (return_path_ && !append_addr("Return-Path", *return_path_, out))
if (return_path_ && !append_addr("Return-Path", *return_path_, out)) {
return false;
}
if (delivered_to_ && !append_addr("Delivered-To", *delivered_to_, out))
if (delivered_to_ && !append_addr("Delivered-To", *delivered_to_, out)) {
return false;
}
if (from_ && !append_addr("From", *from_, out))
if (from_ && !append_addr("From", *from_, out)) {
return false;
}
if (!append_addrs("To", to_list_, out))
if (!append_addrs("To", to_list_, out)) {
return false;
}
if (!append_addrs("Cc", cc_list_, out))
if (!append_addrs("Cc", cc_list_, out)) {
return false;
}
if (subject_ && !append_subject(subject_, out))
if (subject_ && !append_subject(subject_, out)) {
return false;
}
if (!append_date(out))
if (!append_date(out)) {
return false;
}
out.append("MIME-Version: 1.0\r\n");
if (append_message_id(out) == false)
if (!append_message_id(out)) {
return false;
}
return true;
}
@ -372,11 +392,11 @@ bool mail_message::append_header(ofstream& fp)
{
string buf;
if (build_header(buf) == false)
if (!build_header(buf)) {
return false;
}
if (fp.write(buf) == -1)
{
if (fp.write(buf) == -1) {
logger_error("write mail header to %s error %s",
fp.file_path(), last_serror());
return false;
@ -410,17 +430,16 @@ bool mail_message::append_multipart(ofstream& fp)
buf.format_append("%s\r\n\r\n", prompt);
// 添加数据体
if (body_ != NULL)
{
if (body_ != NULL) {
buf.format_append("--%s\r\n", boundary.c_str());
if (body_->save_to(buf) == false)
if (!body_->save_to(buf)) {
return false;
}
buf.append("\r\n");
}
if (fp.write(buf) == -1)
{
if (fp.write(buf) == -1) {
logger_error("write to %s error %s",
fp.file_path(), last_serror());
return false;
@ -431,17 +450,14 @@ bool mail_message::append_multipart(ofstream& fp)
mime_base64 base64(true, false);
std::vector<mail_attach*>::const_iterator cit;
for (cit = attachments_.begin(); cit != attachments_.end(); ++cit)
{
if (fp.format("--%s\r\n", boundary.c_str()) == -1)
{
for (cit = attachments_.begin(); cit != attachments_.end(); ++cit) {
if (fp.format("--%s\r\n", boundary.c_str()) == -1) {
logger_error("write boundary to %s error %s",
fp.file_path(), last_serror());
return false;
}
if ((*cit)->save_to(&base64, fp) == false)
{
if (!(*cit)->save_to(&base64, fp)) {
logger_error("write attachment header to %s error %s",
fp.file_path(), last_serror());
return false;
@ -450,8 +466,7 @@ bool mail_message::append_multipart(ofstream& fp)
// 添加最后的分隔符至邮件尾部
if (fp.format("--%s--\r\n", boundary.c_str()) == -1)
{
if (fp.format("--%s--\r\n", boundary.c_str()) == -1) {
logger_error("write boundary end to %s error %s",
fp.file_path(), last_serror());
return false;
@ -463,8 +478,7 @@ bool mail_message::append_multipart(ofstream& fp)
bool mail_message::save_to(const char* filepath)
{
ofstream fp;
if (fp.open_write(filepath) == false)
{
if (!fp.open_write(filepath)) {
logger_error("open %s error: %s", filepath, last_serror());
return false;
}
@ -473,16 +487,17 @@ bool mail_message::save_to(const char* filepath)
// 先添加邮件头部分数据至文件流中
if (append_header(fp) == false)
if (!append_header(fp)) {
return false;
}
// 如果是 multipart 格式,则将 multipart 数据输出至文件流中
if (!attachments_.empty())
if (!attachments_.empty()) {
return append_multipart(fp);
}
if (body_ == NULL)
{
if (body_ == NULL) {
logger_error("body null!");
return false;
}
@ -490,11 +505,11 @@ bool mail_message::save_to(const char* filepath)
// 对非 multipart 格式,直接将正文数据输出至文件流中
string buf(8192);
if (body_->save_to(buf) == false)
if (!body_->save_to(buf)) {
return false;
}
if (fp.write(buf) == -1)
{
if (fp.write(buf) == -1) {
logger_error("write to %s error %s",
fp.file_path(), last_serror());
return false;

View File

@ -27,7 +27,7 @@ smtp_client::smtp_client(const char* addr, int conn_timeout /* = 60 */,
ssl_conf_ = NULL;
}
smtp_client::~smtp_client()
smtp_client::~smtp_client(void)
{
acl_myfree(addr_);
close();
@ -39,12 +39,12 @@ smtp_client& smtp_client::set_ssl(polarssl_conf* ssl_conf)
return *this;
}
int smtp_client::get_code() const
int smtp_client::get_code(void) const
{
return client_ == NULL ? -1 : client_->smtp_code;
}
const char* smtp_client::get_status() const
const char* smtp_client::get_status(void) const
{
return client_ == NULL ? "unknown" : client_->buf;
}
@ -53,24 +53,29 @@ bool smtp_client::send(const mail_message& message,
const char* email /* = NULL */)
{
// 发送 SMTP 邮件信封过程
if (send_envelope(message) == false)
if (!send_envelope(message)) {
return false;
}
// 优先使用参数给出的邮件文件,然后才是 message 中自动生成的邮件文件
if (email == NULL)
if (email == NULL) {
email = message.get_email();
}
// 如果没有可发送的邮件文件,则认为调用者想通过 write 等接口直接发送数据
if (email == NULL)
if (email == NULL) {
return true;
}
// 发送 DATA 命令
if (data_begin() == false)
if (!data_begin()) {
return false;
}
// 发送邮件
if (send_email(email) == false)
if (!send_email(email)) {
return false;
}
// 发送 DATA 结束符
return data_end();
@ -78,33 +83,36 @@ bool smtp_client::send(const mail_message& message,
bool smtp_client::send_envelope(const mail_message& message)
{
if (open() == false)
if (!open()) {
return false;
if (get_banner() == false)
}
if (!get_banner()) {
return false;
if (greet() == false)
}
if (!greet()) {
return false;
}
const char* user = message.get_auth_user();
const char* pass = message.get_auth_pass();
if (user && pass && auth_login(user, pass) == false)
if (user && pass && !auth_login(user, pass)) {
return false;
}
const rfc822_addr* from = message.get_from();
if (from == NULL)
{
if (from == NULL) {
logger_error("from null");
return false;
}
if (mail_from(from->addr) == false)
if (!mail_from(from->addr)) {
return false;
}
return to_recipients(message.get_recipients());
}
bool smtp_client::open()
bool smtp_client::open(void)
{
if (stream_.opened())
{
if (stream_.opened()) {
acl_assert(client_ != NULL);
acl_assert(client_->conn == stream_.get_vstream());
reuse_ = true;
@ -114,8 +122,7 @@ bool smtp_client::open()
reuse_ = false;
client_ = smtp_open(addr_, conn_timeout_, rw_timeout_, 1024);
if (client_ == NULL)
{
if (client_ == NULL) {
logger_error("connect %s error: %s", addr_, last_serror());
return false;
}
@ -124,11 +131,9 @@ bool smtp_client::open()
stream_.open(client_->conn);
// 如果设置了 SSL 通信方式,则需要打开 SSL 通信接口
if (ssl_conf_)
{
if (ssl_conf_) {
polarssl_io* ssl = new polarssl_io(*ssl_conf_, false);
if (stream_.setup_hook(ssl) == ssl)
{
if (stream_.setup_hook(ssl) == ssl) {
logger_error("open ssl client error!");
ssl->destroy();
return false;
@ -138,10 +143,9 @@ bool smtp_client::open()
return true;
}
void smtp_client::close()
void smtp_client::close(void)
{
if (client_)
{
if (client_) {
// 将 SMTP_CLIENT 对象的流置空,以避免内部再次释放,
// 因为该流对象会在下面 stream_.close() 时被释放
client_->conn = NULL;
@ -150,22 +154,24 @@ void smtp_client::close()
}
// 当 socket 流对象打开着,则关闭之,同时将依附于其的 SSL 对象释放
if (stream_.opened())
if (stream_.opened()) {
stream_.close();
}
// 重置连接是否被重用的状态
reuse_ = false;
}
bool smtp_client::get_banner()
bool smtp_client::get_banner(void)
{
// 如果是同一个连接被使用,则不必再获得服务端的欢迎信息
if (reuse_)
if (reuse_) {
return true;
}
return smtp_get_banner(client_) == 0 ? true : false;
}
bool smtp_client::greet()
bool smtp_client::greet(void)
{
return smtp_greet(client_, "localhost", ehlo_ ? 1 : 0)
== 0 ? true : false;
@ -173,13 +179,11 @@ bool smtp_client::greet()
bool smtp_client::auth_login(const char* user, const char* pass)
{
if (user == NULL || *user == 0)
{
if (user == NULL || *user == 0) {
logger_error("user null");
return false;
}
if (pass == NULL || *pass == 0)
{
if (pass == NULL || *pass == 0) {
logger_error("pass null");
return false;
}
@ -188,8 +192,7 @@ bool smtp_client::auth_login(const char* user, const char* pass)
bool smtp_client::mail_from(const char* from)
{
if (from == NULL || *from == 0)
{
if (from == NULL || *from == 0) {
logger_error("from null");
return false;
}
@ -198,8 +201,7 @@ bool smtp_client::mail_from(const char* from)
bool smtp_client::rcpt_to(const char* to)
{
if (to == NULL || *to == 0)
{
if (to == NULL || *to == 0) {
logger_error("to null");
return false;
}
@ -209,35 +211,35 @@ bool smtp_client::rcpt_to(const char* to)
bool smtp_client::to_recipients(const std::vector<rfc822_addr*>& recipients)
{
std::vector<rfc822_addr*>::const_iterator cit;
for (cit = recipients.begin(); cit != recipients.end(); ++cit)
{
if ((*cit)->addr && rcpt_to((*cit)->addr) == false)
for (cit = recipients.begin(); cit != recipients.end(); ++cit) {
if ((*cit)->addr && !rcpt_to((*cit)->addr)) {
return false;
}
}
return true;
}
bool smtp_client::data_begin()
bool smtp_client::data_begin(void)
{
return smtp_data(client_) == 0 ? true : false;
}
bool smtp_client::data_end()
bool smtp_client::data_end(void)
{
return smtp_data_end(client_) == 0 ? true : false;
}
bool smtp_client::quit()
bool smtp_client::quit(void)
{
return smtp_quit(client_) == 0 ? true : false;
}
bool smtp_client::noop()
bool smtp_client::noop(void)
{
return smtp_noop(client_) == 0 ? true : false;
}
bool smtp_client::reset()
bool smtp_client::reset(void)
{
return smtp_rset(client_) == 0 ? true : false;
}