Esempio n. 1
0
static void incr_string(ACL_VSTRING *vp, int len, const char* s, int debug)
{
	int   i;

	printf("max: %ld, len: %ld, cnt: %ld\r\n", (long) vp->maxlen,
		vp->vbuf.len, vp->vbuf.cnt);

	for (i = 0; i < len; i++)
		ACL_VSTRING_ADDCH(vp, 'x');

	if (s && *s)
		acl_vstring_sprintf_append(vp, "%s", s);
	else
		ACL_VSTRING_TERMINATE(vp);

	if (debug)
		printf("[%s]\r\n", acl_vstring_str(vp));

	printf("strlen: %ld, ACL_VSTRING_LEN: %ld, max: %ld\r\n",
		(long) strlen(acl_vstring_str(vp)),
		(long) ACL_VSTRING_LEN(vp), (long) vp->maxlen);

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

	ACL_VSTRING_RESET(vp);
	ACL_VSTRING_TERMINATE(vp);
}
Esempio n. 2
0
void http_error_reply(HTTP_CLIENT *http_client, int status, const char *msg)
{
	static __thread ACL_VSTRING *__buf = NULL;
	const ACL_VSTRING *str;
	const char *ptr;
	struct iovec iov[2];

	if (__buf == NULL) {
		__buf = acl_vstring_alloc(256);
		acl_pthread_atexit_add(__buf, free_buf);
	}

	ptr = http_tmpl_title(status);
	str = http_tmpl_get(status);
	
	if (msg == NULL || *msg == 0)
		msg = acl_vstring_str(str);

	acl_vstring_sprintf(__buf, reply_error_fmt, status, ptr);
	
	iov[0].iov_base = acl_vstring_str(__buf);
	iov[0].iov_len  = ACL_VSTRING_LEN(__buf);
	iov[1].iov_base = (char*) msg;
	iov[1].iov_len  = strlen(msg);

	acl_aio_writev(http_client->stream, iov, 2);
}
Esempio n. 3
0
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;
}
Esempio n. 4
0
static void test_json_build(void)
{
	ACL_JSON* json = acl_json_alloc();
	ACL_JSON_NODE* root, *node1, *node2, *node3;

	root  = acl_json_create_obj(json);
	acl_json_node_append_child(json->root, root);

	node1 = acl_json_create_leaf(json, "name1", "value1");
	acl_json_node_append_child(root, node1);

	node1 = acl_json_create_leaf(json, "name2", "value2");
	acl_json_node_append_child(root, node1);

	node1 = acl_json_create_obj(json);
	node2 = acl_json_create_leaf(json, "name3", "value3");
	acl_json_node_append_child(node1, node2);
	node2 = acl_json_create_node(json, "name4", node1);
	acl_json_node_append_child(root, node2);

	//////////////////////////////////////////////////////////////////////////

	node1 = acl_json_create_array(json);
	node2 = acl_json_create_node(json, "name5", node1);
	acl_json_node_append_child(root, node2);

	node3 = acl_json_create_leaf(json, "name6", "value6");
	acl_json_node_append_child(node1, node3);

	node3 = acl_json_create_leaf(json, "name7", "value7");
	acl_json_node_append_child(node1, node3);

	node3 = acl_json_create_obj(json);
	acl_json_node_append_child(node1, node3);
	node2 = acl_json_create_leaf(json, "name8", "value8");
	acl_json_node_append_child(node3, node2);
	node2 = acl_json_create_leaf(json, "name9", "value9");
	acl_json_node_append_child(node3, node2);

	//////////////////////////////////////////////////////////////////////////

	ACL_VSTRING *buf1 = acl_vstring_alloc(128);
	ACL_VSTRING *buf2 = acl_vstring_alloc(128);

	acl_json_build(json, buf1);
	acl_json_building(json, 1, build_callback, buf2);

	printf("%s\r\n", acl_vstring_str(buf1));
	printf("%s\r\n", acl_vstring_str(buf2));

	if (strcmp(STR(buf1), STR(buf2)) != 0)
		printf("BUILD ERROR\r\n");
	else
		printf("BUILD OK\r\n");

	acl_vstring_free(buf1);
	acl_vstring_free(buf2);

	acl_json_free(json);
}
Esempio n. 5
0
File: xml.cpp Progetto: 2202877/acl
const char* xml_node::id(void) const
{
	if (node_->id && ACL_VSTRING_LEN(node_->id) > 0)
		return acl_vstring_str(node_->id);
	else
		return NULL;
}
Esempio n. 6
0
PROCTL_SERVICE *proctl_service_new(const char *filepath, int argc, char *argv[])
{
	const char *myname = "proctl_service_new";
	PROCTL_SERVICE *service;
	ACL_VSTRING *cmdline = acl_vstring_alloc(256);
	int   i;

	acl_assert(cmdline);

	/* 组建启动进程命令行参数表 */

	/* 为了避免参数传递时可能因其中间含有空格而被分隔成
	 * 多个参数,所以需要在参数两边加上引号
	 */

	acl_vstring_strcat(cmdline, "\"");
	acl_vstring_strcat(cmdline, filepath);
	acl_vstring_strcat(cmdline, "\" ");

	for (i = 0; i < argc; i++) {
		acl_vstring_strcat(cmdline, "\"");
		acl_vstring_strcat(cmdline, argv[i]);
		acl_vstring_strcat(cmdline, "\" ");
	}

	acl_msg_info("%s(%d): filepath=%s, cmdline=%s",
		myname, __LINE__, filepath, acl_vstring_str(cmdline));

	service = proctl_service_alloc(filepath, cmdline);
	proctl_service_add(service);
	return (service);
}
Esempio n. 7
0
static void test_buffer_space()
{
	ACL_VSTRING *vp = acl_vstring_alloc(1);
	char *ptr;
	int   i;

	ACL_VSTRING_SPACE(vp, 10);
	ptr = acl_vstring_str(vp);
	printf("=========================1====================\n");
	for (i = 0; i < 10; i++)
		*ptr++ = 'x';
	ptr = acl_vstring_str(vp);
	printf("gets: %d\n", acl_vstream_gets(ACL_VSTREAM_IN, ptr, 10));
	printf("=========================2====================\n");
	acl_vstring_free(vp);
}
Esempio n. 8
0
const char* json_node::tag_name(void) const
{
	if (node_me_->ltag && ACL_VSTRING_LEN(node_me_->ltag) > 0)
		return (acl_vstring_str(node_me_->ltag));
	else
		return (NULL);
}
Esempio n. 9
0
static int chunked_trailer(ACL_ASTREAM *astream, HTTP_CHAT_CTX *ctx)
{
	HTTP_BODY_NOTIFY notify = ctx->notify.body_notify;
	void *arg = ctx->arg;
	ACL_VSTRING *sbuf;
	char *data;
	int   dlen;

	sbuf = acl_aio_gets_peek(astream);
	if (sbuf == NULL)
		return (0);

	data = acl_vstring_str(sbuf);
	dlen = (int) ACL_VSTRING_LEN(sbuf);
	ACL_VSTRING_RESET(sbuf);

	ctx->body_len += dlen;

	if (strcmp(data, "\r\n") == 0 || strcmp(data, "\n") == 0) {
		DISABLE_READ(astream);
		if ((dlen = notify(HTTP_CHAT_OK, data, dlen, arg)) < 0)
			return (-1);
		return (1);
	}
	if (notify(HTTP_CHAT_CHUNK_TRAILER, data, dlen, arg) < 0)
		return (-1);
	return (0);
}
Esempio n. 10
0
const char* json_node::get_text(void) const
{
	if (node_me_->text && ACL_VSTRING_LEN(node_me_->text) > 0)
		return acl_vstring_str(node_me_->text);
	else
		return NULL;
}
Esempio n. 11
0
void http_hdr_build_request(const HTTP_HDR_REQ *hdr_req, ACL_VSTRING *strbuf)
{
	ACL_ARRAY *entries;
	HTTP_HDR_ENTRY *entry;
	int   i, n;

	entries = hdr_req->hdr.entry_lnk;
	n = acl_array_size(entries);

	entry = (HTTP_HDR_ENTRY *) acl_array_index(entries, 0);
#if 0
	acl_vstring_sprintf(strbuf, "%s %s\r\n", entry->name, entry->value);
#else
	acl_vstring_sprintf(strbuf, "%s %s HTTP/%d.%d\r\n", entry->name,
		acl_vstring_str(hdr_req->url_part),
		hdr_req->hdr.version.major, hdr_req->hdr.version.minor);
#endif

	for (i = 1; i < n; i++) {
		entry = (HTTP_HDR_ENTRY *) acl_array_index(entries, i);
		if (entry == NULL)
			break;
		if (entry->off)
			continue;
		acl_vstring_sprintf_append(strbuf, "%s: %s\r\n", entry->name, entry->value);
	}

	acl_vstring_strcat(strbuf, "\r\n");
}
Esempio n. 12
0
void global::get_filename(const char* filepath, acl::string& buf)
{
	ACL_VSTRING* bp = acl_vstring_alloc(256);
	acl_sane_basename(bp, filepath);
	buf = acl_vstring_str(bp);
	acl_vstring_free(bp);
}
Esempio n. 13
0
File: xml.cpp Progetto: 2202877/acl
const char* xml_attr::get_value(void) const
{
	acl_assert(attr_);
	if (attr_->value)
		return acl_vstring_str(attr_->value);
	else
		return "";
}
Esempio n. 14
0
global::global()
{
	const char* filepath = acl_process_path();
	ACL_VSTRING* path = acl_vstring_alloc(256);
	acl_sane_dirname(path, filepath);
	path_ = acl_vstring_str(path);
	acl_vstring_free(path);
}
Esempio n. 15
0
static void free_buf_fn(void *arg)
{
	ACL_VSTRING *buf = (ACL_VSTRING*) arg;

	printf(">> current thread id=%u, buf = %s\r\n",
		(unsigned int) acl_pthread_self(), acl_vstring_str(buf));
	acl_vstring_free(buf);
}
Esempio n. 16
0
static void main_thread_atexit(void *arg)
{
	ACL_VSTRING *buf = (ACL_VSTRING*) arg;

	printf("main thread exit now, tid=%u, buf=%s\r\n",
		(unsigned int) acl_pthread_self(), acl_vstring_str(buf));
	printf("in the main thread_atexit, input any key to exit\r\n");
	getchar();
}
Esempio n. 17
0
int main(int argc, char *argv[])
{
	char  ch;
	char  dns_ip[64], domain[128];
	int   dns_port = 53, ret;
	ACL_VSTRING *sbuf;

	dns_ip[0] = 0;
	domain[0] = 0;

	while ((ch = getopt(argc, argv, "h:p:d:")) > 0) {
		switch (ch) {
		case 'h':
			ACL_SAFE_STRNCPY(dns_ip, optarg, sizeof(dns_ip));
			break;
		case 'p':
			dns_port = atoi(optarg);
			break;
		case 'd':
			ACL_SAFE_STRNCPY(domain, optarg, sizeof(domain));
			break;
		default:
			usage(argv[0]);
			return (0);
		}
	}

	if (dns_ip[0] == 0 || domain[0] == 0) {
		usage(argv[0]);
		return (0);
	}

	sbuf = acl_vstring_alloc(128);
	ret = dns_lookup(domain, dns_ip, dns_port, sbuf);
	if (ret < 0) {
		printf("dns lookup(%s) error(%s)\r\n", domain, acl_vstring_str(sbuf));
		acl_vstring_free(sbuf);
		return (0);
	}

	printf("domain: %s\r\n%s", domain, acl_vstring_str(sbuf));
	acl_vstring_free(sbuf);
	return (0);
}
Esempio n. 18
0
ACL_VSTRING *tok822_internalize(ACL_VSTRING *vp, TOK822 *tree, int flags)
{
	TOK822 *tp;

	if (flags & TOK822_STR_WIPE)
		ACL_VSTRING_RESET(vp);

	for (tp = tree; tp; tp = tp->next) {
		switch (tp->type) {
		case ',':
			ACL_VSTRING_ADDCH(vp, tp->type);
			if (flags & TOK822_STR_LINE) {
				ACL_VSTRING_ADDCH(vp, '\n');
				continue;
			}
			break;
		case TOK822_ADDR:
			tok822_internalize(vp, tp->head, TOK822_STR_NONE);
			break;
		case TOK822_COMMENT:
		case TOK822_ATOM:
		case TOK822_QSTRING:
			acl_vstring_strcat(vp, acl_vstring_str(tp->vstr));
			break;
		case TOK822_DOMLIT:
			ACL_VSTRING_ADDCH(vp, '[');
			acl_vstring_strcat(vp, acl_vstring_str(tp->vstr));
			ACL_VSTRING_ADDCH(vp, ']');
			break;
		case TOK822_STARTGRP:
			ACL_VSTRING_ADDCH(vp, ':');
			break;
		default:
			if (tp->type >= TOK822_MINTOK)
				acl_msg_panic("tok822_internalize: unknown operator %d", tp->type);
			ACL_VSTRING_ADDCH(vp, tp->type);
		}
		if (tok822_append_space(tp))
			ACL_VSTRING_ADDCH(vp, ' ');
	}
	if (flags & TOK822_STR_TERM)
		ACL_VSTRING_TERMINATE(vp);
	return (vp);
}
Esempio n. 19
0
static void b64_encode(const char *ptr)
{
	ACL_VSTRING *str = acl_vstring_alloc(1);

	acl_vstring_base64_encode(str, ptr, strlen(ptr));

	printf(">>>encode result:%s\n", acl_vstring_str(str));

	acl_vstring_free(str);
}
Esempio n. 20
0
static void __post_jail_init_fn(char *unused_name, char **unused_argv)
{
	char  myname[] = "__post_jail_init_fn";
	ACL_VSTRING *why = acl_vstring_alloc(100);

	unused_name = unused_name;
	unused_argv = unused_argv;

	if (acl_msg_verbose)
		acl_msg_info("%s(%d)->%s: test only",
				__FILE__, __LINE__, myname);

	__data_buf = acl_mymalloc(var_proxy_bufsize);
	if (__data_buf == NULL)
		acl_msg_fatal("%s(%d)->%s: malloc data_buf, serr = %s",
				__FILE__, __LINE__, myname,
				strerror(errno));

	if (var_proxy_debug_request) {
		__request_stream = acl_safe_open(var_proxy_request_file,
						O_CREAT | O_RDWR | O_APPEND, 0600,
						(struct stat *) 0, (uid_t)-1,
						(uid_t )-1, why);
		if (__request_stream == NULL)
			acl_msg_fatal("%s(%d)->%s: can't open %s, err = %s",
					__FILE__, __LINE__, myname,
					var_proxy_request_file, acl_vstring_str(why));
	}

	if (var_proxy_debug_respond) {
		__respond_stream = acl_safe_open(var_proxy_respond_file,
						O_CREAT | O_RDWR | O_APPEND, 0600,
						(struct stat *) 0, (uid_t)-1,
						(uid_t )-1, why);
		if (__respond_stream == NULL)
			acl_msg_fatal("%s(%d)->%s: can't open %s, err = %s",
					__FILE__, __LINE__, myname,
					var_proxy_respond_file, acl_vstring_str(why));
	}

	acl_vstring_free(why);
}
Esempio n. 21
0
void acl_proctl_start_one(const char *progname,
	const char *progchild, int argc, char *argv[])
{
	const char *myname = "acl_proctl_start_one";
	char  ebuf[256], buf[1024];
	ACL_VSTREAM *client;
	ACL_VSTRING *child_args = NULL;
	int   n;

	if (argc > 0) {
		int   i;

		child_args = acl_vstring_alloc(256);
		for (i = 0; i < argc; i++) {
			if (i > 0)
				acl_vstring_strcat(child_args, " ");
			acl_vstring_strcat(child_args, "\"");
			acl_vstring_strcat(child_args, argv[i]);
			acl_vstring_strcat(child_args, "\"");
		}

	}

	/* 打开与控制进程之间的连接 */
	client = proctl_client_open(progname);
	if (child_args) {
		/* 向控制进程发送消息,带有控制参数 */
		n = acl_vstream_fprintf(client, "%s|-d|START|-f|%s|-a|%s\r\n",
				progname, progchild, acl_vstring_str(child_args));
	} else {
		/* 向控制进程发送消息,不带控制参数 */
		n = acl_vstream_fprintf(client, "%s|-d|START|-f|%s\r\n",
				progname, progchild);
	}

	if (child_args != NULL)
		acl_vstring_free(child_args);

	if (n == ACL_VSTREAM_EOF)
		acl_msg_fatal("%s(%d): fprintf to acl_proctl error(%s)",
			myname, __LINE__, acl_last_strerror(ebuf, sizeof(ebuf)));

	/* 接收所有来自于控制进程的消息响应结果 */
	while (1) {
		n = acl_vstream_gets_nonl(client, buf, sizeof(buf));
		if (n == ACL_VSTREAM_EOF)
			break;
		acl_msg_info("%s(%d): %s", myname, __LINE__, buf);
	}

	proctl_client_close(client);
}
Esempio n. 22
0
static void strip_address(ACL_VSTRING *vp, ssize_t start, TOK822 *addr)
{
	ACL_VSTRING *tmp;

	/*
	 * Emit plain <address>. Discard any comments or phrases.
	 */
	ACL_VSTRING_TERMINATE(vp);
	acl_msg_warn("stripping too many comments from address: %.100s...",
			acl_vstring_str(vp) + start);
	//acl_printable(vstring_str(vp) + start, '?')); //zsx
	acl_vstring_truncate(vp, start);
	ACL_VSTRING_ADDCH(vp, '<');
	if (addr) {
		tmp = acl_vstring_alloc(100);
		tok822_internalize(tmp, addr, TOK822_STR_TERM);
		quote_822_local_flags(vp, acl_vstring_str(tmp),
			QUOTE_FLAG_8BITCLEAN | QUOTE_FLAG_APPEND);
		acl_vstring_free(tmp);
	}
	ACL_VSTRING_ADDCH(vp, '>');
}
Esempio n. 23
0
static void test_vstring_vsprintf(const char* fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);
	ACL_VSTRING *vbf = acl_vstring_alloc(1);
	acl_vstring_vsprintf(vbf, fmt, ap);
	va_end(ap);

	printf("%s\n", acl_vstring_str(vbf));

	acl_vstring_free(vbf);
}
Esempio n. 24
0
static int chunked_data(ACL_ASTREAM *astream, HTTP_CHAT_CTX *ctx)
{
	HTTP_BODY_NOTIFY notify = ctx->notify.body_notify;
	void *arg = ctx->arg;
	ACL_VSTRING *sbuf;
	char *data;
	int   dlen, ret;

	if (ctx->chunked) {
		ret = (int) HTTP_LEN_ROUND(ctx);
		sbuf = acl_aio_readn_peek(astream, ret);
	} else if (ctx->hdr->content_length <= 0) {
		sbuf = acl_aio_read_peek(astream);
	} else {
		ret = (int) HTTP_LEN_ROUND(ctx);
		sbuf = acl_aio_readn_peek(astream, ret);
	}

	if (sbuf == NULL) {
		return (0);
	}

	data = acl_vstring_str(sbuf);
	dlen = (int) ACL_VSTRING_LEN(sbuf);
	ACL_VSTRING_RESET(sbuf);

	ctx->body_len += dlen;
	ctx->read_cnt += dlen;

	if (ctx->chunk_len > 0 && ctx->read_cnt >= ctx->chunk_len) {
		if (!ctx->chunked) {
			/* xxx: 禁止连续读 */
			DISABLE_READ(astream);
			if (notify(HTTP_CHAT_OK, data, dlen, arg) < 0)
				return (-1);
			return (1);
		}

		if (notify(HTTP_CHAT_DATA, data, dlen, arg) < 0)
			return (-1);

		/* 设置标志位开始读取块数据体的分隔行数据 */
		ctx->status = CHAT_S_CHUNK_SEP;
		return (0);
	}

	if (notify(HTTP_CHAT_DATA, data, dlen, arg) < 0)
		return (-1);
	return (0);
}
Esempio n. 25
0
static void notify_thread(void *arg)
{
	const char *myname = "notify_thread";
	WARN_INFO *info = (WARN_INFO*) arg;
	ACL_VSTREAM *client;
	ACL_VSTRING *buf;
	int   ret;

	buf = acl_vstring_alloc(256);
	acl_vstring_sprintf(buf, "PROC=%s|PID=%d|RCPT=%s|info=%s\r\n",
		info->path, info->pid, info->notify_recipients, info->desc);

	client = acl_vstream_connect(info->notify_addr,
		ACL_BLOCKING, 60, 60, 1024);
	if (client == NULL) {
		acl_msg_error("%s(%d): connect %s error, info(%s)", myname,
			__LINE__, info->notify_addr, acl_vstring_str(buf));
		acl_vstring_free(buf);
		warn_info_free(info);
		return;
	}

	/* 禁止将该句柄传递给子进程 */
	acl_close_on_exec(ACL_VSTREAM_SOCK(client), ACL_CLOSE_ON_EXEC);

	ret = acl_vstream_writen(client, acl_vstring_str(buf),
		ACL_VSTRING_LEN(buf));
	if (ret == ACL_VSTREAM_EOF)
		acl_msg_error("%s(%d): write to notify server error, info(%s)",
			myname, __LINE__, acl_vstring_str(buf));
	else
		acl_msg_info("%s(%d): notify ok!", myname, __LINE__);

	acl_vstream_close(client);
	acl_vstring_free(buf);
	warn_info_free(info);
}
Esempio n. 26
0
static int sms_send(ACL_VSTREAM *client, const char *phone, const char *proc,
	int pid, const char *info, const char *ip)
{
	ACL_VSTRING *buf = acl_vstring_alloc(256);
	ACL_XML *xml = acl_xml_alloc();
	char  res[1024];
	int   ret;

	acl_vstring_sprintf(buf, "<send_sms phone=\"%s\" message=\"proc:%s, pid:%d, ip:%s, info:%s\" />",
			phone, proc, pid, ip, info);
	if (acl_vstream_writen(client, acl_vstring_str(buf), ACL_VSTRING_LEN(buf))
		== ACL_VSTREAM_EOF)
	{
		acl_msg_error("write to sms server error, msg: %s",
			acl_vstring_str(buf));
		acl_vstring_free(buf);
		return (-1);
	}

	acl_msg_info(">>send: %s", acl_vstring_str(buf));
	acl_vstring_free(buf);

	while (1) {
		ret = acl_vstream_read(client, res, sizeof(res) - 1);
		if (ret == ACL_VSTREAM_EOF)
			return (-1);
		res[ret] = 0;
		acl_xml_parse(xml, res);
		if (acl_xml_is_complete(xml, "send_sms")) {
			acl_msg_info("send ok!(%s)", res);
			break;
		}
	}

	return (0);
}
Esempio n. 27
0
static void test_string(ACL_FILE_HANDLE fd, ssize_t max, int debug)
{
	ACL_VSTRING *vp = acl_vstring_mmap_alloc(fd, 1, max);
	const char *s = "hello world!";

	printf("-------------------------------------------------------\r\n");
	incr_string(vp, max - 1, NULL, debug);

	printf("-------------------------------------------------------\r\n");
	incr_string(vp, max - 1 - strlen(s), s, debug);

	printf("-------------------------------------------------------\r\n");
	incr_string(vp, max, NULL, debug);

	printf("-------------------------------------------------------\r\n");
	incr_string(vp, max + 2, NULL, debug);

	printf("-------------------------------------------------------\r\n");
	acl_vstring_strcat(vp, s);
	incr_string(vp, max - strlen(s) - 1, NULL, debug);

	printf("-------------------------------------------------------\r\n");
	acl_vstring_strcat(vp, s);
	incr_string(vp, max, NULL, debug);

	printf("-------------------------------------------------------\r\n");
	acl_vstring_strcat(vp, s);
	incr_string(vp, max + 10, NULL, debug);

	printf(">>>[%s]\r\n", acl_vstring_str(vp));
	printf(">>>len: %ld, %ld, %p, %p\r\n",
		(long) strlen(acl_vstring_str(vp)),
		(long) ACL_VSTRING_LEN(vp),
		acl_vstring_str(vp), acl_vstring_end(vp));
	acl_vstring_free(vp);
}
Esempio n. 28
0
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;
}
Esempio n. 29
0
static int hdr_can_read(ACL_ASTREAM *astream, void *context)
{
	HTTP_CHAT_CTX *ctx = (HTTP_CHAT_CTX *) context;
	HTTP_HDR *hdr = ctx->hdr;
	HTTP_HDR_NOTIFY notify = ctx->notify.hdr_notify;
	void *arg = ctx->arg;
	ACL_VSTRING *sbuf;
	char *data;
	int   dlen;
	int   ret;

	while (1) {
		if ((ret = acl_aio_can_read(astream)) == ACL_VSTREAM_EOF) {
			notify(HTTP_CHAT_ERR_IO, arg);
			return (-1);
		} else if (ret == 0) {
			break;
		}
		sbuf = acl_aio_gets_nonl_peek(astream);
		if (sbuf == NULL) {
			break;
		}
		data = acl_vstring_str(sbuf);
		dlen = (int) ACL_VSTRING_LEN(sbuf);
		ACL_VSTRING_RESET(sbuf);

		ret = hdr_ready(hdr, data, dlen);
		switch (ret) {
		case HTTP_CHAT_CONTINUE:
			break;
		case HTTP_CHAT_OK:
			DISABLE_READ(astream);
			if (notify(ret, arg) < 0) {
				return (0);
			}
			return (0);
		default:
			DISABLE_READ(astream);
			(void) notify(ret, arg);
			return (0);
		}
	}

	acl_aio_enable_read(astream, hdr_can_read, ctx);
	return (0);
}
Esempio n. 30
0
static void tok822_quote_atom(TOK822 *tp)
{
	char   *cp;
	int     ch;

	/*
	 * RFC 822 expects 7-bit data. Rather than quoting every 8-bit character
	 * (and still passing it on as 8-bit data) we leave 8-bit data alone.
	 */
	for (cp = acl_vstring_str(tp->vstr); (ch = *(unsigned char *) cp) != 0; cp++) {
		if ( /* !ISASCII(ch) || */ ch == ' '
			|| ACL_ISCNTRL(ch) || strchr(tok822_opchar, ch))
		{
			tp->type = TOK822_QSTRING;
			break;
		}
	}
}