예제 #1
0
bool pop3_client::pop3_uidl(acl::socket_stream& conn,
	std::vector<acl::string>& out)
{
	if (conn.puts("UIDL") == -1)
	{
		logger_error("send UIDL to pop3 server(%s) error %s, "
			"user: %s", pop3_ip_.c_str(), acl::last_serror(),
			auth_account_.c_str());
		return false;
	}

	acl::string line;
	if (conn.gets(line) == false)
	{
		logger_error("gets UIDL's reply from server(%s) error(%s), "
			"user: %s", pop3_ip_.c_str(), acl::last_serror(),
			auth_account_.c_str());
		return false;
	}
	if (line.ncompare("+OK", 3, false) != 0)
	{
		logger_error("UIDL's reply(%s) error from server %s, user: %s",
			line.c_str(), pop3_ip_.c_str(), auth_account_.c_str());
		return false;
	}

	logger("UIDL's first reply: %s", line.c_str());

	while (true)
	{
		if (conn.gets(line) == false)
		{
			logger_error("UIDL's reply error %s, from server %s, "
				"user %s", acl::last_serror(),
				pop3_ip_.c_str(), auth_account_.c_str());
			return false;
		}
		logger("UIDL: %s", line.c_str());

		if (line == ".")
			break;
		char* ptr = line.c_str();
		char* p1 = acl_mystrtok(&ptr, " \t");
		if (ptr == NULL || *ptr == 0)
		{
			logger_error("invalid UIDL's reply(%s) from server %s, "
				"user %s", p1, pop3_ip_.c_str(),
				auth_account_.c_str());
			return false;
		}
		out.push_back(ptr);
	}

	meter_.total_uidl = out.size();
	return true;
}
예제 #2
0
/*
* rfc1035NamePack()
* 
* Packs a name into a buffer.  Names are packed as a
* sequence of labels, terminated with NULL label.
* Note message compression is not supported here.
* Returns number of octets packed.
*/
static int rfc1035NamePack(char *buf, size_t sz, const char *name)
{
	const char *myname = "rfc1035NamePack";
	int off = 0;
	char *copy, *ptr;
	char *t;

	copy = acl_mystrdup(name);
	/*
	* NOTE: use of strtok here makes names like foo....com valid.
	*/
	ptr = copy;
	for (t = acl_mystrtok(&ptr, "."); t; t = acl_mystrtok(&ptr, "."))
		off += rfc1035LabelPack(buf + off, sz - off, t);
	acl_myfree(copy);
	off += rfc1035LabelPack(buf + off, sz - off, NULL);
	if (off > (int) sz)
		acl_msg_fatal("%s: off(%d) > sz(%d)", myname, off, sz);
	return off;
}
예제 #3
0
파일: main.c 프로젝트: 1514louluo/acl
int main(void)
{
	char *src = acl_mystrdup("hello \tworld! you're  welcome to China!");
	char *ptr, *src_saved;
	ACL_VSTRING* buf;
	const char* s = "hello";
	unsigned int   n1 = (unsigned int) -1;
	unsigned long  n2 = (unsigned long) -1;
	unsigned long long n3 = (unsigned long long) -1;
	const char *str2 = "hello world, you're welcome!";
	ACL_ARGV *tokens = acl_argv_split(str2, " \t,'!");
	ACL_ITER  iter;

	printf("----------------------------------------------\r\n");
	acl_foreach(iter, tokens)
		printf("tokens[%d]: %s\r\n", iter.i, (const char*) iter.data);
	printf("total: %d\r\n", iter.size);
	acl_argv_free(tokens);
	printf("----------------------------------------------\r\n");

	src_saved = src;
	printf("src: %s\r\n", src);
	while ((ptr = acl_mystrtok(&src, " \t!'")) != NULL)
	{
		printf("--------------------------------------\r\n");
		printf("ptr: |%s|\r\n", ptr);
		printf("src: |%s|\r\n", src);
		printf("src_saved: |%s|\r\n", src_saved);
	}

	acl_myfree(src_saved);

	printf("----------------------------------------------\r\n");

	buf = acl_vstring_alloc(1);
	acl_vstring_sprintf(buf, "%*lu, s: %s, n1: %20u, n2: %20lu, n3: %20llu\n",
		(int) sizeof(unsigned long) * 4, (unsigned long) getpid(),
		s, n1, n2, n3);
	printf("buf: %s\r\n", acl_vstring_str(buf));
	acl_vstring_free(buf);

	printf("Enter any key to continue ...\r\n");
	getchar();

	test_quote_split();

	return 0;
}
예제 #4
0
ACL_ARGV   *acl_argv_splitn_append(ACL_ARGV *argvp, const char *str, const char *delim, size_t n)
{
	char   *saved_string = argvp->slice ?
		acl_slice_pool_strdup(__FILE__, __LINE__, argvp->slice, str) :
		acl_mystrdup(str);
	char   *bp = saved_string;
	char   *arg;

	while (n-- > 0 && (arg = acl_mystrtok(&bp, delim)) != 0)
		acl_argv_add(argvp, arg, (char *) 0);
	acl_argv_terminate(argvp);
	if (argvp->slice)
		acl_slice_pool_free(__FILE__, __LINE__, saved_string);
	else
		acl_myfree(saved_string);
	return (argvp);
}
예제 #5
0
파일: name_mask.c 프로젝트: 10jschen/acl
int     name_mask_delim_opt(const char *context, const NAME_MASK *table,
		const char *names, const char *delim, int flags)
{
	const char *myname = "name_mask";
	char   *saved_names = acl_mystrdup(names);
	char   *bp = saved_names;
	int     result = 0;
	const NAME_MASK *np;
	char   *name;
	int     (*lookup) (const char *, const char *);

	if (flags & NAME_MASK_ANY_CASE)
		lookup = strcasecmp;
	else
		lookup = strcmp;

	/*
	 * Break up the names string, and look up each component in the table. If
	 * the name is found, merge its mask with the result.
	 */
	while ((name = acl_mystrtok(&bp, delim)) != 0) {
		for (np = table; /* void */ ; np++) {
			if (np->name == 0) {
				if (flags & NAME_MASK_FATAL)
					acl_msg_fatal("unknown %s value \"%s\" in \"%s\"",
							context, name, names);
				if (flags & NAME_MASK_RETURN) {
					acl_msg_warn("unknown %s value \"%s\" in \"%s\"",
							context, name, names);
					return (0);
				}
				break;
			}
			if (lookup(name, np->name) == 0) {
				acl_debug(DEBUG_NAME_MASK, 1) ("%s: %s", myname, name);
				result |= np->mask;
				break;
			}
		}
	}
	acl_myfree(saved_names);
	return (result);
}
예제 #6
0
ACL_ARGV   *acl_argv_splitn4(const char *str, const char *delim,
	size_t n, ACL_SLICE_POOL *slice)
{
	ACL_ARGV   *argvp = acl_argv_alloc2(n > 0 ? (int) n : 1, slice);
	char   *saved_string = slice ?
		acl_slice_pool_strdup(__FILE__, __LINE__, slice, str) :
		acl_mystrdup(str);
	char   *bp = saved_string;
	char   *arg;

	while (n-- > 0 && (arg = acl_mystrtok(&bp, delim)) != 0)
		acl_argv_add(argvp, arg, (char *) 0);
	acl_argv_terminate(argvp);
	if (slice)
		acl_slice_pool_free(__FILE__, __LINE__, saved_string);
	else
		acl_myfree(saved_string);
	return (argvp);
}
예제 #7
0
static ACL_CFG_LINE *_create_cfg_line(char *data, const char *delimiter)
{
	ACL_CFG_LINE *cfg_line = NULL;
	ACL_ARRAY *a = NULL;
	int   i, n;
	char *ptr, *pdata, *pitem;

#undef	ERETURN
#define	ERETURN(x) do {                                                      \
	if (a)                                                               \
		acl_array_destroy(a, acl_myfree_fn);                         \
	if (cfg_line) {                                                      \
		if (cfg_line->value)                                         \
			acl_myfree(cfg_line);                                    \
		acl_myfree(cfg_line);                                            \
	}                                                                    \
	return (x);                                                          \
} while (0);

	if (data == NULL)
		return (NULL);

	pdata = data;

	cfg_line = (ACL_CFG_LINE *) acl_mycalloc(1, sizeof(ACL_CFG_LINE));
	if (cfg_line == NULL)
		return (NULL);

	a = acl_array_create(10);
	while (1) {
		ptr = acl_mystrtok(&pdata, delimiter);
		if (ptr == NULL)
			break;
		pitem = acl_mystrdup(ptr);
		if (pitem == NULL) {
			ERETURN (NULL);
		}
		if (acl_array_append(a, (void *) pitem) < 0) {
			ERETURN (NULL);
		}
	}

	cfg_line->ncount = 0;
	cfg_line->pdata = NULL;
	n = acl_array_size(a);
	if (n > 0) {
		cfg_line->value = (char **) acl_mycalloc(1 + n, sizeof(char *));
		if (cfg_line->value == NULL) {
			ERETURN (NULL);
		}
		for (i = 0; i < n; i++) {
			pitem = (char *) acl_array_index(a, i);
			if (pitem == NULL)
				break;
			cfg_line->value[i] = pitem;
			if (cfg_line->value[i] == NULL)
				ERETURN (NULL);
			cfg_line->ncount++;
		}
	}

	/* NOTICE: in acl_array_destroy, please don't input acl_myfree, but
	 * NULL as the second parameter, because the mystrup's result
	 * set are stored in cfg_line->value now:)
	 */
	acl_array_destroy(a, NULL);

	return (cfg_line);
}
예제 #8
0
bool pop3_client::pop3_list(acl::socket_stream& conn, std::vector<size_t>& out)
{
	if (conn.puts("LIST") == -1)
	{
		logger_error("send LIST to pop3 server(%s) error %s, "
			"user: %s", pop3_ip_.c_str(), acl::last_serror(),
			auth_account_.c_str());
		return false;
	}

	acl::string line;
	if (conn.gets(line) == false)
	{
		logger_error("gets LIST's reply from server(%s) error(%s), "
			"user: %s", pop3_ip_.c_str(), acl::last_serror(),
			auth_account_.c_str());
		return false;
	}
	if (line.ncompare("+OK", 3, false) != 0)
	{
		logger_error("LIST's reply(%s) error from server %s, user: %s",
			line.c_str(), pop3_ip_.c_str(), auth_account_.c_str());
		return false;
	}

	logger("LIST's first reply: %s", line.c_str());

	while (true)
	{
		if (conn.gets(line) == false)
		{
			logger_error("LIST's reply error %s, from server %s, "
				"user %s", acl::last_serror(),
				pop3_ip_.c_str(), auth_account_.c_str());
			return false;
		}

		logger("LIST: %s", line.c_str());

		if (line == ".")
			break;
		char* ptr = line.c_str();
		char* p1 = acl_mystrtok(&ptr, " \t");
		if (ptr == NULL || *ptr == 0)
		{
			logger_error("invalid LIST's reply(%s) from server %s, "
				"user %s", p1, pop3_ip_.c_str(),
				auth_account_.c_str());
			return false;
		}
		int len = atoi(ptr);
		if (len <= 0)
		{
			logger_error("invalid LIST size(%d) from server %s, "
				"user %s", len, pop3_ip_.c_str(),
				auth_account_.c_str());
			return false;
		}
		out.push_back((size_t) len);
		meter_.total_size += len;
	}
	meter_.total_list = out.size();
	return true;
}
예제 #9
0
파일: acl_test_cfg.c 프로젝트: 10jschen/acl
/* 分析配置文件中的第四个参数, 将其进行分解并存入动态数组之中 */
ACL_ARRAY *aut_parse_args_list(const char *str_in)
{
	const char *myname = "aut_parse_args_list";
	ACL_ARRAY *argvs_array = NULL;
	AUT_ARG_ITEM *arg_item = NULL;
	char *ptr_item, *pstr, *pstr_saved, *pname, *pvalue;
	char *ptr;
	int   len;
	char  tbuf[256];

	argvs_array = acl_array_create(10);
	pstr = acl_mystrdup(str_in);
	pstr_saved = pstr;

#define	SKIP_WHILE(_cond, _ptr) { while (*_ptr && (_cond)) _ptr++; }
#define	SKIP_WHILE_DEC(_cond, _ptr) { while (*_ptr && (_cond)) _ptr--; }

	len = strlen("=");
	while (1) {
		/* 找到每一参数项, 分隔符为逗号 */
		ptr_item = acl_mystrtok(&pstr, ",");
		if (ptr_item == NULL)
			break;

		/* 删除变量名前的空格和 tab */
		SKIP_WHILE((*ptr_item == ' ' || *ptr_item == '\t'), ptr_item);
		pname = ptr_item;

		/* 先找到等于号分隔符 */
		pvalue = strstr(ptr_item, "=");
		if (pvalue == NULL) /* not found '=' */
			continue;

		ptr = pvalue;

		/* 删除等号左边的空格或 tab */
		SKIP_WHILE_DEC((*ptr == ' ' || *ptr == '\t'), ptr);
		if (ptr < pvalue)
			*(++ptr) = 0;

		*pvalue = 0;
		pvalue += len; /* skip '=' */

		/* 删除等号右边的空格和ab */
		SKIP_WHILE((*pvalue == ' ' || *pvalue == '\t'), pvalue);
		if (*pvalue == 0)
			continue;

		/* 分配一个参数项 */
		arg_item = (AUT_ARG_ITEM *) acl_mycalloc(1, sizeof(AUT_ARG_ITEM));
		arg_item->name = acl_mystrdup(pname);
		arg_item->value = acl_mystrdup(pvalue);

		/* 把该参数项加入到动态数组之中 */
		if (acl_array_append(argvs_array, (void *) arg_item) < 0)
			aut_log_fatal("%s(%d): append to array error(%s)",
				myname, __LINE__, acl_last_strerror(tbuf, sizeof(tbuf)));
	}

	acl_myfree(pstr_saved);

	return (argvs_array);
}