本文整理匯總了C++中ACL_SAFE_STRNCPY函數的典型用法代碼示例。如果您正苦於以下問題:C++ ACL_SAFE_STRNCPY函數的具體用法?C++ ACL_SAFE_STRNCPY怎麽用?C++ ACL_SAFE_STRNCPY使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ACL_SAFE_STRNCPY函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: http_hdr_req_new
HTTP_HDR_REQ *http_hdr_req_clone(const HTTP_HDR_REQ* hdr_req)
{
HTTP_HDR_REQ *hh;
hh = http_hdr_req_new();
http_hdr_clone(&hdr_req->hdr, &hh->hdr);
hh->port = hdr_req->port;
ACL_SAFE_STRNCPY(hh->method, hdr_req->method, sizeof(hh->method));
ACL_SAFE_STRNCPY(hh->host, hdr_req->host, sizeof(hh->host));
acl_vstring_strcpy(hh->url_part, acl_vstring_str(hdr_req->url_part));
acl_vstring_strcpy(hh->url_path, acl_vstring_str(hdr_req->url_path));
acl_vstring_strcpy(hh->url_params, acl_vstring_str(hdr_req->url_params));
acl_vstring_strcpy(hh->file_path, acl_vstring_str(hdr_req->file_path));
if (hdr_req->params_table) {
hh->params_table = acl_htable_create(__http_hdr_max_request, 0);
acl_htable_walk(hdr_req->params_table, clone_table_entry,
(void*) hh->params_table);
}
if (hdr_req->cookies_table) {
hh->cookies_table = acl_htable_create(__http_hdr_max_cookies, 0);
acl_htable_walk(hdr_req->cookies_table, clone_table_entry,
(void*) hh->cookies_table);
}
return hh;
}
示例2: dbconn_init
static void dbconn_init(const char *addr, const char *name, const char *usr,
const char *pass, int dbpool_max, int dbping, int dbtimeout)
{
const char *myname = "dbconn_init";
ACL_DB_INFO db_info;
memset(&db_info, 0, sizeof(ACL_DB_INFO));
ACL_SAFE_STRNCPY(db_info.db_addr, addr, sizeof(db_info.db_addr));
ACL_SAFE_STRNCPY(db_info.db_name, name, sizeof(db_info.db_name));
ACL_SAFE_STRNCPY(db_info.db_user, usr, sizeof(db_info.db_user));
ACL_SAFE_STRNCPY(db_info.db_pass, pass, sizeof(db_info.db_pass));
db_info.db_max = dbpool_max;
db_info.ping_inter = dbping;
db_info.timeout_inter = dbtimeout;
db_info.auto_commit = 1;
//db_info.db_before_connect = db_before_connect;
//db_info.db_after_connect = db_after_connect;
__db_pool = acl_dbpool_create("mysql", &db_info);
if (__db_pool == NULL)
acl_msg_fatal("%s(%d): init db pool error", myname, __LINE__);
}
示例3: xml_new_gid
static int xml_new_gid(ACL_VSTREAM *client, int keep_alive, ACL_XML_NODE *node)
{
acl_int64 gid;
char buf[256], tag[64];
const char *ptr;
int errnum = 0;
#define STR acl_vstring_str
ACL_SAFE_STRNCPY(tag, "default:", sizeof(tag));
ptr = acl_xml_getElementAttrVal(node, "tag");
if (ptr && *ptr) {
ACL_SAFE_STRNCPY(tag, ptr, sizeof(tag));
}
gid = gid_next(var_cfg_gid_path, tag, var_cfg_gid_step, &errnum);
if (gid >= 0)
snprintf(buf, sizeof(buf),
"<respond status='ok' gid='%lld' tag='%s' />\r\n", gid, tag);
else
snprintf(buf, sizeof(buf),
"<respond status='error' gid='%lld' tag='%s'"
" err='%d' msg='%s' />\r\n",
gid, tag, errnum, gid_serror(errnum));
return (http_server_send_respond(client, 200, keep_alive,
buf, (int) strlen(buf)));
}
示例4: sizeof
bool http_utils::get_addr(const char* url, char* domain, size_t size,
unsigned short* pport)
{
#define HTTP_PREFIX "http://"
#define HTTPS_PREFIX "https://"
const char* ptr;
unsigned short default_port;
if (strncasecmp(url, HTTP_PREFIX, sizeof(HTTP_PREFIX) - 1) == 0)
{
ptr = url + sizeof(HTTP_PREFIX) - 1;
default_port = 80;
}
else if (strncasecmp(url, HTTPS_PREFIX, sizeof(HTTPS_PREFIX) - 1) == 0)
{
ptr = url + sizeof(HTTPS_PREFIX) - 1;
default_port = 443;
}
else
{
logger_error("invalid url: %s", url);
return false;
}
if (*ptr == 0)
{
logger_error("invalid url: %s", url);
return false;
}
char buf[256];
ACL_SAFE_STRNCPY(buf, ptr, sizeof(buf));
char* slash = strchr(buf, '/');
if (slash)
*slash = 0;
unsigned short port;
char* col = strchr(buf, ':');
if (col == NULL)
port = default_port;
else
{
*col++ = 0;
port = (unsigned short) atoi(col);
if (port == 0 || port == 65535)
port = default_port;
}
if (pport)
*pport = port;
ACL_SAFE_STRNCPY(domain, buf, size);
return true;
}
示例5: acl_netdb_add_addr
void acl_netdb_add_addr(ACL_DNS_DB *dns_db, const char *ip, int hport)
{
const char *myname = "acl_netdb_add_addr";
ACL_HOSTNAME *phost;
char buf[256];
if (dns_db == NULL || dns_db->h_db == NULL || ip == NULL) {
acl_msg_error("%s(%d): input invalid", myname, __LINE__);
return;
}
phost = acl_mycalloc(1, sizeof(ACL_HOSTNAME));
if (phost == NULL) {
acl_msg_error("%s(%d): calloc error(%s)",
myname, __LINE__, acl_last_strerror(buf, sizeof(buf)));
return;
}
memset(&phost->saddr, 0, sizeof(phost->saddr));
ACL_SAFE_STRNCPY(phost->ip, ip, sizeof(phost->ip));
phost->saddr.sin_addr.s_addr = (unsigned long) inet_addr(ip);
phost->hport = hport;
if (acl_array_append(dns_db->h_db, phost) < 0) {
acl_msg_error("%s(%d): array append error(%s)",
myname, __LINE__, acl_last_strerror(buf, sizeof(buf)));
return;
}
dns_db->size++;
}
示例6: acl_unix_listen
bool server_socket::open(const char* addr)
{
#ifndef ACL_WINDOWS
if (strchr(addr, '/') != NULL)
{
fd_ = acl_unix_listen(addr, backlog_, block_
? ACL_BLOCKING : ACL_NON_BLOCKING);
unix_sock_ = true;
ACL_SAFE_STRNCPY(addr_, addr, sizeof(addr_));
}
else
#endif
fd_ = acl_inet_listen(addr, backlog_, block_
? ACL_BLOCKING : ACL_NON_BLOCKING);
if (fd_ == ACL_SOCKET_INVALID)
{
logger_error("listen %s error %s", addr, last_serror());
unix_sock_ = false;
ACL_SAFE_STRNCPY(addr_, addr, sizeof(addr_));
return false;
}
if (unix_sock_)
return true;
// 之所以再用 getsockname 重新獲得一些監聽地址,主要是為了應對當輸入的 addr
// 為 ip:0 的情形,即當給定的地址中的端口為 0 時要求操作係統自動分配一個端口號
if (acl_getsockname(fd_, addr_, sizeof(addr_)) < 0)
{
logger_error("getsockname error: %s", acl_last_serror());
ACL_SAFE_STRNCPY(addr_, addr, sizeof(addr_));
}
return true;
}
示例7: main
int main(int argc, char *argv[])
{
int ch;
char url[256], dump[256];
acl_init(); /* ³õʼ»¯ acl ¿â */
url[0] = 0;
dump[0] = 0;
while ((ch = getopt(argc, argv, "hr:t:f:X:")) > 0) {
switch (ch) {
case 'h':
usage(argv[0]);
return (0);
case 'r':
ACL_SAFE_STRNCPY(url, optarg, sizeof(url));
break;
case 'f':
ACL_SAFE_STRNCPY(dump, optarg, sizeof(dump));
break;
default:
break;
}
}
if (url[0] == 0) {
usage(argv[0]);
return (0);
}
get_url(url, dump);
return (0);
}
示例8: buf
bool queue_file::move_file(const char* queueName, const char* extName)
{
acl::string buf(256);
bool once_again = false;
while (true)
{
buf.clear();
buf << m_home << PATH_SEP << queueName << PATH_SEP << m_queueSub
<< PATH_SEP << m_partName << "." << extName;
#ifdef WIN32
// 在win32下必須先關閉文件句柄
this->close();
#endif
if (rename(m_filePath.c_str(), buf.c_str()) == 0)
break;
// 如果返回錯誤原因是目標路徑不存在,則嘗試創建目錄結構
if (once_again || acl_last_error() != ENOENT)
{
logger_error("move from %s to %s error(%s), errno: %d, %d",
m_filePath.c_str(), buf.c_str(), acl_last_serror(),
acl_last_error(), ENOENT);
return (false);
}
// 設置重試標誌位
once_again = true;
buf.clear();
buf << m_home << PATH_SEP << queueName
<< PATH_SEP << m_queueSub;
// 創建隊列目錄
if (acl_make_dirs(buf.c_str(), 0700) == -1)
{
logger_error("mkdir: %s error(%s)",
buf.c_str(), acl_last_serror());
return false;
}
}
#ifdef WIN32
// win32 下需要重新再打開
return (open(m_home, queueName, m_queueSub, m_partName, extName));
#else
if (m_queueName != queueName)
ACL_SAFE_STRNCPY(m_queueName, queueName, sizeof(m_queueName));
if (m_extName != extName)
ACL_SAFE_STRNCPY(m_extName, extName, sizeof(m_extName));
m_filePath.clear();
m_filePath << m_home << PATH_SEP << m_queueName << PATH_SEP
<< m_queueSub << PATH_SEP << m_partName << "." << m_extName;
#endif
return (true);
}
示例9: ACL_SAFE_STRNCPY
connect_pool& connect_manager::set(const char* addr, int count)
{
char key[256];
ACL_SAFE_STRNCPY(key, addr, sizeof(key));
acl_lowercase(key);
lock_.lock();
std::vector<connect_pool*>::iterator it = pools_.begin();
for (; it != pools_.end(); ++it)
{
if (strcasecmp(key, (*it)->get_addr()) == 0)
{
lock_.unlock();
return **it;
}
}
connect_pool* pool = create_pool(key, count, pools_.size() - 1);
pools_.push_back(pool);
lock_.unlock();
logger("Add one service, addr: %s, count: %d", addr, count);
return *pool;
}
示例10: ACL_SAFE_STRNCPY
void queue_file::set_extName(const char* extName)
{
ACL_SAFE_STRNCPY(m_extName, extName, sizeof(m_extName));
m_filePath.clear();
m_filePath << m_home << PATH_SEP << m_queueName << PATH_SEP
<< m_queueSub << PATH_SEP << m_partName << "." << m_extName;
}
示例11: main
int main(int argc, char *argv[])
{
char ch, addr[32];
int n = 1, keep_alive = 0, cmd_num = 0;
addr[0] = 0;
while ((ch = getopt(argc, argv, "hks:n:i:")) > 0) {
switch (ch) {
case 's':
ACL_SAFE_STRNCPY(addr, optarg, sizeof(addr));
break;
case 'n':
n = atoi(optarg);
break;
case 'k':
keep_alive = 1;
break;
case 'i':
cmd_num = atoi(optarg);
break;
case 'h':
default:
usage(argv[0]);
return (0);
}
}
if (addr[0] == 0 || n <= 0) {
usage(argv[0]);
return (0);
}
run(addr, n, keep_alive, cmd_num);
return (0);
}
示例12: acl_array_size
ACL_DNS_DB *acl_netdb_clone(const ACL_DNS_DB *db)
{
ACL_DNS_DB *dbp;
ACL_HOSTNAME *phost, *h_host;
int i, n;
if (db == NULL || db->h_db == NULL)
return NULL;
n = acl_array_size(db->h_db);
if (n <= 0) {
acl_msg_error("%s, %s(%d): h_db's size(%d) <= 0",
__FILE__, __FUNCTION__, __LINE__, n);
return NULL;
}
dbp = acl_netdb_new(db->name);
for (i = 0; i < n; i++) {
phost = (ACL_HOSTNAME *) acl_array_index(db->h_db, i);
acl_assert(phost);
h_host = acl_mycalloc(1, sizeof(ACL_HOSTNAME));
memcpy(&h_host->saddr, &phost->saddr, sizeof(h_host->saddr));
ACL_SAFE_STRNCPY(h_host->ip, phost->ip, sizeof(h_host->ip));
h_host->hport = phost->hport;
(void) acl_array_append(dbp->h_db, h_host);
dbp->size++;
}
return dbp;
}
示例13: rfc1035BuildPTRQuery
/*
* rfc1035BuildPTRQuery()
*
* Builds a message buffer with a QUESTION to lookup PTR records
* for an address. Caller must allocate 'buf' which should
* probably be at least 512 octets. The 'szp' initially
* specifies the size of the buffer, on return it contains
* the size of the message (i.e. how much to write).
* Returns the size of the query
*/
ssize_t rfc1035BuildPTRQuery(const struct in_addr addr, char *buf,
size_t sz, unsigned short qid, rfc1035_query * query)
{
const char *myname = "rfc1035BuildPTRQuery";
rfc1035_message h;
size_t offset = 0;
static char rev[32];
unsigned int i;
memset(&h, '\0', sizeof(h));
i = (unsigned int) ntohl(addr.s_addr);
snprintf(rev, 32, "%u.%u.%u.%u.in-addr.arpa.",
i & 255, (i >> 8) & 255, (i >> 16) & 255, (i >> 24) & 255);
h.id = qid;
h.qr = 0;
h.rd = 1;
h.opcode = 0; /* QUERY */
h.qdcount = (unsigned int) 1;
offset += rfc1035HeaderPack(buf + offset, sz - offset, &h);
offset += rfc1035QuestionPack(buf + offset, sz - offset, rev,
RFC1035_TYPE_PTR, RFC1035_CLASS_IN);
if (query) {
query->qtype = RFC1035_TYPE_PTR;
query->qclass = RFC1035_CLASS_IN;
ACL_SAFE_STRNCPY(query->name, rev, sizeof(query->name));
}
if (offset > sz)
acl_msg_fatal("%s: offset(%d) > sz(%d)", myname, offset, sz);
return (ssize_t) offset;
}
示例14: rfc1035BuildAQuery
/*
* rfc1035BuildAQuery()
*
* Builds a message buffer with a QUESTION to lookup A records
* for a hostname. Caller must allocate 'buf' which should
* probably be at least 512 octets. The 'szp' initially
* specifies the size of the buffer, on return it contains
* the size of the message (i.e. how much to write).
* Returns the size of the query
*/
ssize_t rfc1035BuildAQuery(const char *hostname, char *buf, size_t sz,
unsigned short qid, rfc1035_query * query)
{
const char *myname = "rfc1035BuildAQuery";
rfc1035_message h;
size_t offset = 0;
memset(&h, '\0', sizeof(h));
h.id = qid;
h.qr = 0;
h.rd = 1;
h.opcode = 0; /* QUERY */
h.qdcount = (unsigned int) 1;
offset += rfc1035HeaderPack(buf + offset, sz - offset, &h);
offset += rfc1035QuestionPack(buf + offset, sz - offset, hostname,
RFC1035_TYPE_A, RFC1035_CLASS_IN);
if (query) {
query->qtype = RFC1035_TYPE_A;
query->qclass = RFC1035_CLASS_IN;
ACL_SAFE_STRNCPY(query->name, hostname, sizeof(query->name));
}
if (offset > sz)
acl_msg_fatal("%s: offset(%d) > sz(%d)", myname, offset, sz);
return (ssize_t) offset;
}
示例15: ACL_SAFE_STRNCPY
connect_pool* connect_manager::get(const char* addr,
bool exclusive /* = true */, bool restore /* = false */)
{
char key[256];
ACL_SAFE_STRNCPY(key, addr, sizeof(key));
acl_lowercase(key);
if (exclusive)
lock_.lock();
std::vector<connect_pool*>::iterator it = pools_.begin();
for (; it != pools_.end(); ++it)
{
if (strcasecmp(key, (*it)->get_addr()) == 0)
{
if (restore && (*it)->aliving() == false)
(*it)->set_alive(true);
if (exclusive)
lock_.unlock();
return *it;
}
}
if (exclusive)
lock_.unlock();
logger_error("no connect pool for addr %s", addr);
return NULL;
}