Exemplo n.º 1
0
void connect_manager::set_service_list(const char* addr_list, int count,
	int conn_timeout, int rw_timeout)
{
	if (addr_list == NULL || *addr_list == 0)
	{
		logger("addr_list null");
		return;
	}

	// 创建连接池服务集群
	char* buf = acl_mystrdup(addr_list);
	char* addrs = acl_mystr_trim(buf);
	ACL_ARGV* tokens = acl_argv_split(addrs, ";,");
	ACL_ITER iter;
	acl::string addr;
	acl_foreach(iter, tokens)
	{
		const char* ptr = (const char*) iter.data;
		int max = check_addr(ptr, addr, count);
		if (max < 0)
		{
			logger_error("invalid server addr: %s", addr.c_str());
			continue;
		}
		(void) set(addr.c_str(), max, conn_timeout, rw_timeout);
		logger("add one service: %s, max connect: %d",
			addr.c_str(), max);
	}
	acl_argv_free(tokens);
	acl_myfree(buf);
}
Exemplo n.º 2
0
http_service_request::http_service_request(const char* domain,
	unsigned short port)
{
	acl_assert(domain && *domain);
	domain_ = acl_mystrdup(domain);
	port_ = port;
}
Exemplo n.º 3
0
TLS_SCACHE *tls_scache_open(const char *dbname, const char *cache_label,
	int verbose, int timeout)
{
    const char *myname = "tls_scache_open";
    TLS_SCACHE *cp;
    DICT   *dict;

    /*
     * Logging.
     */
    if (verbose)
	acl_msg_info("open %s TLS cache %s", cache_label, dbname);

    /*
     * Open the dictionary with O_TRUNC, so that we never have to worry about
     * opening a damaged file after some process terminated abnormally.
     */
#ifdef SINGLE_UPDATER
#define DICT_FLAGS (DICT_FLAG_DUP_REPLACE)
#elif defined(ACL_UNIX)
#define DICT_FLAGS \
	(DICT_FLAG_DUP_REPLACE | DICT_FLAG_LOCK | DICT_FLAG_SYNC_UPDATE)
#elif defined(ACL_MS_WINDOWS)
#define DICT_FLAGS \
	(DICT_FLAG_DUP_REPLACE | DICT_FLAG_SYNC_UPDATE)
#endif

    dict = dict_open(dbname, O_RDWR | O_CREAT | O_TRUNC, DICT_FLAGS);

    /*
     * Sanity checks.
     */
    if (dict->lock_fd < 0)
	acl_msg_fatal("%s: dictionary %s is not a regular file", myname, dbname);
#ifdef SINGLE_UPDATER
    if (acl_myflock(dict->lock_fd, INTERNAL_LOCK,
		MYFLOCK_OP_EXCLUSIVE | MYFLOCK_OP_NOWAIT) < 0)
	acl_msg_fatal("%s: cannot lock dictionary %s for exclusive use: %s",
		myname, dbname, acl_last_serror());
#endif
    if (dict->update == 0)
	acl_msg_fatal("%s: dictionary %s does not support update operations", myname, dbname);
    if (dict->delete_it == 0)
	acl_msg_fatal("%s: dictionary %s does not support delete operations", myname, dbname);
    if (dict->sequence == 0)
	acl_msg_fatal("%s: dictionary %s does not support sequence operations", myname, dbname);

    /*
     * Create the TLS_SCACHE object.
     */
    cp = (TLS_SCACHE *) acl_mymalloc(sizeof(*cp));
    cp->flags = 0;
    cp->db = dict;
    cp->cache_label = acl_mystrdup(cache_label);
    cp->verbose = verbose;
    cp->timeout = timeout;
    cp->saved_cursor = 0;

    return (cp);
}
Exemplo n.º 4
0
mime_head& mime_head::add_rcpt(const char* addr)
{
	if (m_rcpts == NULL)
		m_rcpts = NEW std::list<char*>;
	m_rcpts->push_back(acl_mystrdup(addr));
	return (*this);
}
Exemplo n.º 5
0
int acl_scan_dir_push(ACL_SCAN_DIR *scan, const char *path)
{
	const char *myname = "acl_scan_dir_push";
	ACL_SCAN_INFO *info;

	info = (ACL_SCAN_INFO *) acl_mymalloc(sizeof(*info));
	if (scan->current) {
		info->path =
			acl_concatenate(ACL_SCAN_DIR_PATH(scan), "/", path, (char *) 0);
	} else {
		info->path = acl_mystrdup(path);
	}

	if ((info->dir_name = opendir(info->path)) == 0) {
		char tbuf[256];
		acl_msg_error("%s(%d), %s: open directory(%s) error(%s)",
			__FILE__, __LINE__, myname,
			info->path, acl_last_strerror(tbuf, sizeof(tbuf)));
		return (-1);
	}
	if (acl_msg_verbose > 1)
		acl_msg_info("%s: open %s", myname, info->path);
	info->parent = scan->current;
	scan->current = info;
	return (0);
}
Exemplo n.º 6
0
TLS_PRNG_SRC *tls_prng_egd_open(const char *name, int timeout)
{
    const char *myname = "tls_prng_egd_open";
    TLS_PRNG_SRC *egd;
    ACL_SOCKET     fd;

    if (acl_msg_verbose)
	acl_msg_info("%s: connect to EGD server %s", myname, name);

#ifdef ACL_UNIX
    fd = acl_unix_connect(name, ACL_BLOCKING, timeout);
#elif defined(ACL_MS_WINDOWS)
	fd = acl_inet_connect(name, ACL_BLOCKING, timeout);
#endif
	
	if (fd < 0) {
	if (acl_msg_verbose)
	    acl_msg_info("%s: cannot connect to EGD server %s: %s",
		myname, name, acl_last_serror());
	return (0);
    } else {
	egd = (TLS_PRNG_SRC *) acl_mymalloc(sizeof(*egd));
	egd->fd.sock = fd;
	egd->name = acl_mystrdup(name);
	egd->timeout = timeout;
	if (acl_msg_verbose)
	    acl_msg_info("%s: connected to EGD server %s", myname, name);
	return (egd);
    }
}
Exemplo n.º 7
0
static ACL_CFG_LINE *_backup_junk_line(const char *ptr)
{
	char  myname[] = "_backup_junk_line";
	ACL_CFG_LINE *cfg_line;
	char  tbuf[256];

	if (ptr == NULL)
		return (NULL);

	cfg_line = (ACL_CFG_LINE *) acl_mycalloc(1, sizeof(ACL_CFG_LINE));
	if (cfg_line == NULL) {
		printf("%s: calloc ACL_CFG_LINE, errmsg=%s",
				myname, acl_last_strerror(tbuf, sizeof(tbuf)));
		return (NULL);
	}

	cfg_line->ncount = 0;
	cfg_line->value = NULL;
	cfg_line->pdata = acl_mystrdup(ptr);
	if (cfg_line->pdata == NULL) {
		printf("%s: strdup pdata, errmsg=%s",
				myname, acl_last_strerror(tbuf, sizeof(tbuf)));
		return (NULL);
	}

	return (cfg_line);
}
Exemplo n.º 8
0
void redis_client_cluster::set_slot(int slot, const char* addr)
{
	if (slot < 0 || slot >= max_slot_ || addr == NULL || *addr == 0)
		return;

	// 遍历缓存的所有地址,若该地址不存在则直接添加,然后使之与 slot 进行关联

	// 该段代码需要加锁保护
	lock();

	std::vector<char*>::const_iterator cit = addrs_.begin();
	for (; cit != addrs_.end(); ++cit)
	{
		if (strcmp((*cit), addr) == 0)
			break;
	}

	// 将 slot 与地址进行关联映射
	if (cit != addrs_.end())
		slot_addrs_[slot] = *cit;
	else
	{
		// 只所以采用动态分配方式,是因为在往数组中添加对象时,无论
		// 数组如何做动态调整,该添加的动态内存地址都是固定的,所以
		// slot_addrs_ 的下标地址也是相对不变的
		char* buf = acl_mystrdup(addr);
		addrs_.push_back(buf);
		slot_addrs_[slot] = buf;
	}

	unlock();
}
Exemplo n.º 9
0
int acl_unix_trigger(ACL_EVENT *event, const char *service,
	const char *buf, int len, int timeout)
{
	const char *myname = "acl_unix_trigger";
	struct ACL_UNIX_TRIGGER *up;
	ACL_SOCKET fd;

	if (acl_msg_verbose > 0)
		acl_msg_info("%s: service %s", myname, service);

	/*
	 * Connect...
	 */
	if ((fd = acl_unix_connect(service, ACL_BLOCKING, timeout)) < 0) {
		if (acl_msg_verbose)
			acl_msg_warn("%s: connect to %s: %s",
				myname, service, strerror(errno));
		return -1;
	}
	acl_close_on_exec(fd, ACL_CLOSE_ON_EXEC);

	/*
	 * Stash away context.
	 */
	up = (struct ACL_UNIX_TRIGGER *) acl_mymalloc(sizeof(*up));
	up->service = acl_mystrdup(service);
	up->stream = acl_vstream_fdopen(fd, O_RDWR, 4096,
			timeout, ACL_VSTREAM_TYPE_LISTEN_UNIX);

	/*
	 * Write the request...
	 */
	if (acl_vstream_writen(up->stream, buf, len) < 0
		|| acl_vstream_writen(up->stream, "", 1) < 0)
	{
		if (acl_msg_verbose)
			acl_msg_warn("%s: write to %s: %s",
				myname, service, strerror(errno));
	}

	/*
	 * Wakeup when the peer disconnects, or when we lose patience.
	 */
#ifdef	__USE_TIMER
	if (timeout > 0)
		acl_event_request_timer(event, acl_unix_trigger_timer,
			(void *) up, (timeout + 100) * 1000000);
	acl_event_enable_read(event, up->stream, 0,
		acl_unix_trigger_event, (void *) up);
#else
	if (timeout > 0)
		acl_event_enable_read(event, up->stream, timeout + 100,
			acl_unix_trigger_event, (void *) up);
	else
		acl_event_enable_read(event, up->stream, 0,
			acl_unix_trigger_event, (void *) up);
#endif

	return 0;
}
Exemplo n.º 10
0
/**
 * 创建索引
 */
static ACL_MDT_IDX *mdt_idx_create(ACL_MDT *mdt, size_t init_capacity,
	const char *name, unsigned int flag)
{
	ACL_MDT_IDX_BHASH *idx;
	unsigned int flag2 = 0;

	if (init_capacity < 128)
		init_capacity = 128;
	idx = (ACL_MDT_IDX_BHASH*) acl_mycalloc(1, sizeof(ACL_MDT_IDX_BHASH));

	if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE1))
		flag2 |= ACL_BINHASH_FLAG_SLICE1;
	else if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE2))
		flag2 |= ACL_BINHASH_FLAG_SLICE2;
	else if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE3))
		flag2 |= ACL_BINHASH_FLAG_SLICE3;

	if ((mdt->tbl_flag & ACL_MDT_FLAG_SLICE_RTGC_OFF))
		flag2 |= ACL_BINHASH_FLAG_SLICE_RTGC_OFF;
	if ((flag & ACL_MDT_FLAG_KMR))
		flag2 |= ACL_BINHASH_FLAG_KEY_REUSE;

	idx->table = acl_binhash_create(init_capacity, flag2);
	idx->idx.name = acl_mystrdup(name);
	idx->idx.flag = flag;
	return ((ACL_MDT_IDX*) idx);
}
Exemplo n.º 11
0
OSSClient::OSSClient(const char* end_point, const char* key_id,
	const char* key_secret)
{
	acl_assert(end_point && *end_point);
	acl_assert(key_id_ && *key_id_);
	acl_assert(key_secret && *key_secret);

	end_point_ = acl_mystrdup(end_point);
	key_id_ = acl_mystrdup(key_id);
	key_secret_ = acl_mystrdup(key_secret);

	bucket_oper_ = NULL;
	object_oper_ = NULL;
	multipart_oper_ = NULL;
	cors_oper_ = NULL;
}
Exemplo n.º 12
0
const char *tls_dns_name(const GENERAL_NAME *gn, const TLS_SESS_STATE *TLScontext)
{
    const char *myname = "tls_dns_name";
    char   *cp;
    const char *dnsname;
    int     len;

    /*
     * Peername checks are security sensitive, carefully scrutinize the
     * input!
     */
    if (gn->type != GEN_DNS)
	acl_msg_panic("%s: Non DNS input argument", myname);

    /*
     * We expect the OpenSSL library to construct GEN_DNS extesion objects as
     * ASN1_IA5STRING values. Check we got the right union member.
     */
    if (ASN1_STRING_type(gn->d.ia5) != V_ASN1_IA5STRING) {
	acl_msg_warn("%s: %s: invalid ASN1 value type in subjectAltName",
		 myname, TLScontext->namaddr);
	return (0);
    }

    /*
     * Safe to treat as an ASCII string possibly holding a DNS name
     */
    dnsname = (char *) ASN1_STRING_data(gn->d.ia5);
    len = ASN1_STRING_length(gn->d.ia5);
    TRIM0(dnsname, len);

    /*
     * Per Dr. Steven Henson of the OpenSSL development team, ASN1_IA5STRING
     * values can have internal ASCII NUL values in this context because
     * their length is taken from the decoded ASN1 buffer, a trailing NUL is
     * always appended to make sure that the string is terminated, but the
     * ASN.1 length may differ from strlen().
     */
    if (len != (int) strlen(dnsname)) {
	acl_msg_warn("%s: %s: internal NUL in subjectAltName",
		 myname, TLScontext->namaddr);
	return 0;
    }

    /*
     * XXX: Should we be more strict and call valid_hostname()? So long as
     * the name is safe to handle, if it is not a valid hostname, it will not
     * compare equal to the expected peername, so being more strict than
     * "printable" is likely excessive...
     */
    if (*dnsname && !allprint(dnsname)) {
	cp = acl_mystrdup(dnsname);
	acl_msg_warn("%s: %s: non-printable characters in subjectAltName: %.100s",
		 myname, TLScontext->namaddr, printable(cp, '?'));
	acl_myfree(cp);
	return 0;
    }
    return (dnsname);
}
Exemplo n.º 13
0
char   *tls_peer_CN(X509 *peercert, const TLS_SESS_STATE *TLScontext)
{
    char   *cn;

    cn = tls_text_name(X509_get_subject_name(peercert), NID_commonName,
		       "subject CN", TLScontext, DO_GRIPE);
    return (cn ? cn : acl_mystrdup(""));
}
Exemplo n.º 14
0
redis_client::redis_client(const char* addr, int conn_timeout /* = 60 */,
	int rw_timeout /* = 30 */, bool retry /* = true */)
: conn_timeout_(conn_timeout)
, rw_timeout_(rw_timeout)
, retry_(retry)
{
	addr_ = acl_mystrdup(addr);
}
Exemplo n.º 15
0
db_handle& db_handle::set_id(const char* id)
{
	if (id == NULL || *id == 0)
		return *this;
	if (id_)
		acl_myfree(id_);
	id_ = acl_mystrdup(id);
	return *this;
}
Exemplo n.º 16
0
tcp_client::tcp_client(const char* addr, int conn_timeout, int rw_timeout)
: conn_timeout_(conn_timeout)
, rw_timeout_(rw_timeout)
{
	addr_   = acl_mystrdup(addr);
	conn_   = new socket_stream;
	sender_ = new tcp_sender(*conn_);
	reader_ = NULL;
}
Exemplo n.º 17
0
void redis_client::set_password(const char* pass)
{
	if (pass_)
		acl_myfree(pass_);
	if (pass && *pass)
		pass_ = acl_mystrdup(pass);
	else
		pass_ = NULL;
}
Exemplo n.º 18
0
const std::list<rfc822_addr*>& rfc822::parse_addrs(const char* in,
	const char* to_charset /* = "utf-8" */)
{
	reset();

	if (to_charset == NULL)
		to_charset = "gb18030";

	if (in == NULL || *in == 0)
	{
		logger_error("input invalid");
		return (addrs_);
	}
	TOK822 *tree = tok822_parse(in);
	if (tree == NULL)
	{
		logger_error("tok822_parse(%s) error", in);
		return (addrs_);
	}

	const ACL_VSTRING* comment_prev = NULL;
	string buf;

	for (TOK822 *tp = tree; tp; tp = tp->next)
	{
		if (tp->type == TOK822_ATOM
			|| tp->type == TOK822_COMMENT
			|| tp->type == TOK822_QSTRING
			|| tp->vstr != NULL)
		{
			comment_prev = tp->vstr;
		}

		if (tp->type != TOK822_ADDR || tp->head == NULL)
			continue;

		ACL_VSTRING* addrp = acl_vstring_alloc(32);
		(void) tok822_internalize(addrp, tp->head, TOK822_STR_DEFL);
		rfc822_addr* addr = (rfc822_addr*)
			acl_mymalloc(sizeof(rfc822_addr));
		addr->addr = acl_vstring_export(addrp);
		if (comment_prev)
		{
			buf.clear();
			rfc2047::decode(STR(comment_prev),
				(int) LEN(comment_prev), &buf, to_charset);
			addr->comment = acl_mystrdup(buf.c_str());
			comment_prev = NULL;
		}
		else
			addr->comment = NULL;
		addrs_.push_back(addr);
	}

	tok822_free_tree(tree);
	return (addrs_);
}
Exemplo n.º 19
0
void db_mysql::sane_mysql_init(const char* dbaddr, const char* dbname,
	const char* dbuser, const char* dbpass,
	unsigned long dbflags, bool auto_commit,
	int conn_timeout, int rw_timeout,
	const char* charset)
{
	if (dbaddr == NULL || *dbaddr == 0)
		logger_fatal("dbaddr null");
	if (dbname == NULL || *dbname == 0)
		logger_fatal("dbname null");

	// 地址格式:[dbname@]dbaddr
	const char* ptr = strchr(dbaddr, '@');
	if (ptr)
		ptr++;
	else
		ptr = dbaddr;
	acl_assert(*ptr);
	dbaddr_ = acl_mystrdup(ptr);
	dbname_ = acl_mystrdup(dbname);

	if (dbuser && *dbuser)
		dbuser_ = acl_mystrdup(dbuser);
	else
		dbuser_ = NULL;

	if (dbpass && *dbpass)
		dbpass_ = acl_mystrdup(dbpass);
	else
		dbpass_ = NULL;

	if (charset && *charset)
		charset_ = charset;

	dbflags_      = dbflags;
	auto_commit_  = auto_commit;
	conn_timeout_ = conn_timeout;
	rw_timeout_   = rw_timeout;

#ifdef HAS_MYSQL_DLL
	acl_pthread_once(&__mysql_once, __mysql_dll_load);
#endif
	conn_ = NULL;
}
Exemplo n.º 20
0
redis_client::redis_client(const char* addr, int conn_timeout /* = 60 */,
	int rw_timeout /* = 30 */, bool retry /* = true */)
: retry_(retry)
, slice_req_(false)
, slice_res_(false)
{
	addr_ = acl_mystrdup(addr);
	pass_ = NULL;
	set_timeout(conn_timeout, rw_timeout);
}
Exemplo n.º 21
0
int acl_inet_trigger(ACL_EVENT *eventp, const char *service,
	const char *buf, int len, int timeout)
{
	const char *myname = "acl_inet_trigger";
	struct ACL_INET_TRIGGER *ip;
	int     fd;

	if (acl_msg_verbose > 1)
		acl_msg_info("%s: service %s", myname, service);

	/*
	 * Connect...
	 */
	if ((fd = acl_inet_connect(service, ACL_BLOCKING, timeout)) < 0) {
		if (acl_msg_verbose)
			acl_msg_warn("%s: connect to %s: %s",
				myname, service, strerror(errno));
		return (-1);
	}
	acl_close_on_exec(fd, ACL_CLOSE_ON_EXEC);

	/*
	 * Stash away context.
	 */
	ip = (struct ACL_INET_TRIGGER *) acl_mymalloc(sizeof(*ip));
	ip->fd = fd;
	ip->service = acl_mystrdup(service);
	ip->stream = acl_vstream_fdopen(fd, O_RDWR, 4096,
		timeout, ACL_VSTREAM_TYPE_LISTEN_INET);
	ip->eventp = eventp;

	/*
	 * Write the request...
	 */
	if (acl_write_buf(fd, buf, len, timeout) < 0
		|| acl_write_buf(fd, "", 1, timeout) < 0)
	{
		if (acl_msg_verbose)
			acl_msg_warn("%s: write to %s: %s",
				myname, service, strerror(errno));
	}

	/*
	 * Wakeup when the peer disconnects, or when we lose patience.
	 */

	if (timeout > 0)
		acl_event_enable_read(ip->eventp, ip->stream, timeout + 100,
			acl_inet_trigger_event, (void *) ip);
	else
		acl_event_enable_read(ip->eventp, ip->stream, 0,
			acl_inet_trigger_event, (void *) ip);

	return (0);
}
Exemplo n.º 22
0
void db_pgsql::sane_pgsql_init(const char* dbaddr, const char* dbname,
	const char* dbuser, const char* dbpass, int conn_timeout,
	int rw_timeout, const char* charset)
{
	affect_count_ = 0;

	if (dbaddr == NULL || *dbaddr == 0)
		logger_fatal("dbaddr null");
	if (dbname == NULL || *dbname == 0)
		logger_fatal("dbname null");

	// 地址格式:[dbname@]dbaddr
	const char* ptr = strchr(dbaddr, '@');
	if (ptr)
		ptr++;
	else
		ptr = dbaddr;
	acl_assert(*ptr);
	dbaddr_ = acl_mystrdup(ptr);
	dbname_ = acl_mystrdup(dbname);

	if (dbuser && *dbuser)
		dbuser_ = acl_mystrdup(dbuser);
	else
		dbuser_ = NULL;

	if (dbpass && *dbpass)
		dbpass_ = acl_mystrdup(dbpass);
	else
		dbpass_ = NULL;

	if (charset && *charset)
		charset_ = charset;

	conn_timeout_ = conn_timeout;
	rw_timeout_   = rw_timeout;

#ifdef HAS_PGSQL_DLL
	acl_pthread_once(&__pgsql_once, __pgsql_dll_load);
#endif
	conn_ = NULL;
}
Exemplo n.º 23
0
static void mail_from(MIME_NODE *node, const HEADER_OPTS *header_info)
{
	//MIME_STATE *state = node->state;
	TOK822 *tree;
	TOK822 **addr_list;
	TOK822 **tpp;
	ACL_VSTRING *temp;
	const char *cp;

	temp = acl_vstring_alloc(10);
	cp = STR(node->buffer) + strlen(header_info->name) + 1;
	tree = tok822_parse(cp);
	addr_list = tok822_grep(tree, TOK822_ADDR);
	for (tpp = addr_list; *tpp; tpp++) {
		tok822_internalize(temp, tpp[0]->head, TOK822_STR_DEFL);
		if (header_info->type == HDR_SENDER) {
			if (node->header_sender)
				acl_myfree(node->header_sender);
			node->header_sender = acl_mystrdup(STR(temp));
			break;
		} else if (header_info->type == HDR_FROM) {
			if (node->header_from)
				acl_myfree(node->header_from);
			node->header_from = acl_mystrdup(STR(temp));
			break;
		} else if (header_info->type == HDR_REPLY_TO) {
			if (node->header_replyto)
				acl_myfree(node->header_replyto);
			node->header_replyto = acl_mystrdup(STR(temp));
			break;
		} else if (header_info->type == HDR_RETURN_PATH) {
			if (node->header_returnpath)
				acl_myfree(node->header_returnpath);
			node->header_returnpath = acl_mystrdup(STR(temp));
		}
	}

	acl_myfree(addr_list);
	
	tok822_free_tree(tree);
	acl_vstring_free(temp);
}
Exemplo n.º 24
0
void acl_proctl_deamon_init(const char *progname)
{
	acl_pthread_attr_t attr;
	acl_pthread_t tid;

	var_progname = acl_mystrdup(progname);
	proctl_start_init(var_progname);
	acl_pthread_attr_init(&attr);
	(void) acl_pthread_attr_setdetachstate(&attr, 1);
	acl_pthread_create(&tid, &attr, proctl_monitor_thread, NULL);
}
Exemplo n.º 25
0
void acl_proctl_child(const char *progname, void (*onexit_fn)(void *), void *arg)
{
	acl_pthread_attr_t attr;
	acl_pthread_t tid;

	proctl_child_atexit(onexit_fn, arg);
	var_progname = acl_mystrdup(progname);
	acl_pthread_attr_init(&attr);
	(void) acl_pthread_attr_setdetachstate(&attr, 1);
	acl_pthread_create(&tid, &attr, proctl_child_thread, NULL);
}
Exemplo n.º 26
0
static ACL_FIFO *mail_addr_add(ACL_FIFO *addr_list, const char *addr)
{
	MAIL_ADDR *mail_addr;

	if (addr_list == NULL)
		addr_list = acl_fifo_new();
	mail_addr = (MAIL_ADDR*) acl_mycalloc(1, sizeof(MAIL_ADDR));
	mail_addr->addr = acl_mystrdup(addr);
	acl_fifo_push(addr_list, mail_addr);
	return (addr_list);
}
Exemplo n.º 27
0
	mem_cache::mem_cache(const char* key_pre /* = NULL */,
		const char* addr /* = "127.0.0.1:11211" */, bool retry /* = true */,
		int conn_timeout /* = 180 */, int rw_timeout /* = 300 */,
		bool encode_key /* = true */)
	: m_coder(false, false)
	, m_conn_timeout(conn_timeout)
	, m_rw_timeout(rw_timeout)
	, m_encode_key(encode_key)	
	, m_opened(false)
	, m_retry(retry)
	, m_conn(NULL)
	{
		if (key_pre && *key_pre)
		{
			bool beCoding = false;

			m_key_pre = NEW acl::string(strlen(key_pre));
			while (*key_pre)
			{
				if (SPECIAL_CHAR(*key_pre) || !ACL_ISPRINT(*key_pre))
				{
					m_coder.encode_update(key_pre, 1, m_key_pre);
					beCoding = true;
				}
				else if (beCoding)
				{
					m_coder.encode_finish(m_key_pre);
					m_coder.reset();
					beCoding = false;
					*m_key_pre << (char) *key_pre;
				}
				else
					*m_key_pre << (char) *key_pre;
				key_pre++;
			}
			if (beCoding)
				m_coder.encode_finish(m_key_pre);
		}
		else
			m_key_pre = NULL;

		acl_assert(addr && *addr);
		m_addr = acl_mystrdup(addr);
		char* ptr = strchr(m_addr, ':');
		if (ptr == NULL)
			logger_fatal("addr(%s) invalid", addr);
		*ptr++ = 0;
		if (*ptr == 0)
			logger_fatal("addr(%s) invalid", addr);
		m_ip = m_addr;
		m_port = atoi(ptr);
		if (m_port <= 0)
			logger_fatal("addr(%s) invalid", addr);
	}
Exemplo n.º 28
0
static void clone_table_entry(ACL_HTABLE_INFO *info, void *arg)
{
	const char *myname = "clone_table_entry";
	ACL_HTABLE *table = (ACL_HTABLE*) arg;
	char *value;

	value = acl_mystrdup(info->value);

	if (acl_htable_enter(table, info->key.key, value) == NULL)
		acl_msg_fatal("%s, %s(%d): acl_htable_enter error=%s",
			__FILE__, myname, __LINE__, acl_last_serror());
}
Exemplo n.º 29
0
PROCTL_SERVICE *proctl_service_alloc(const char *filepath, ACL_VSTRING *cmdline)
{
	PROCTL_SERVICE *service;

	service = (PROCTL_SERVICE*) acl_mycalloc(1, sizeof(PROCTL_SERVICE));
	acl_assert(service);
	service->filepath = acl_mystrdup(filepath);
	service->cmdline = cmdline;
	service->hProcess = INVALID_HANDLE_VALUE;

	return (service);
}
Exemplo n.º 30
0
AUT_LINE *aut_add_outer_cmd(const ACL_CFG_LINE *cfg_line)
{
	const char *myname = "aut_add_outer_cmd";
	AUT_LINE *test_line;

	if (cfg_line->ncount < 3)
		aut_log_fatal("%s: cmd_name=%s, ncount=%d, input error, "
				"please check configure file",
				myname, cfg_line->value[0], cfg_line->ncount);

	test_line = (AUT_LINE *) acl_mycalloc(1, sizeof(*test_line));

	if (test_line == NULL) {
		char tbuf[256];
		aut_log_fatal("%s: can't malloc AUT_LINE, err_msg=%s",
			myname, acl_last_strerror(tbuf, sizeof(tbuf)));
	}

	snprintf(test_line->cmd_name, sizeof(test_line->cmd_name),
			"%s", cfg_line->value[0]);
	test_line->line_number = cfg_line->line_number;
	test_line->result      = atoi(cfg_line->value[1]);
	test_line->argc        = atoi(cfg_line->value[2]);

	if (cfg_line->ncount >= 4) {
		test_line->args_str = acl_mystrdup(cfg_line->value[3]);
		if (test_line->args_str == NULL) {
			char tbuf[256];
			aut_log_fatal("%s: cmd_name=%s, strdup for "
					"args_str, err_msg=%s",
					myname,
					cfg_line->value[0],
					acl_last_strerror(tbuf, sizeof(tbuf)));
		}
		test_line->argv = aut_parse_args_list(cfg_line->value[3]);
		if (test_line->argv == NULL)
			aut_log_fatal("%s: cmd_name=%s, aut_parse_args_list error",
					myname, cfg_line->value[0]);
	} else {
		test_line->args_str = NULL;
		test_line->argv = NULL;
	}

	if (acl_array_append(var_aut_line_array, (void *) test_line) < 0) {
		char tbuf[256];
		aut_log_fatal("%s: cmd_name=%s, acl_array_append error, err_msg=%s",
				myname, acl_last_strerror(tbuf, sizeof(tbuf)));
	}

	test_line->valid_line_idx = var_aut_valid_line_idx++;

	return (test_line);
}