Exemplo n.º 1
0
int http_hdr_req_cookies_parse(HTTP_HDR_REQ *hh)
{
	/* data format: "name1=value1; name2=value2; name3=value3" */
	const char  *myname = "http_hdr_req_cookies_parse";
	const HTTP_HDR_ENTRY *entry;
	ACL_ARGV *argv;
	const char *ptr;
	ACL_ITER iter;

	if (hh == NULL)
		acl_msg_fatal("%s, %s(%d): input invalid",
			__FILE__, myname, __LINE__);
	if ((hh->flag & HTTP_HDR_REQ_FLAG_PARSE_COOKIE) == 0)
		return 0;

	entry = http_hdr_entry((HTTP_HDR *) hh, "Cookie");
	if (entry == NULL)
		return 0;

	if (hh->cookies_table == NULL)
		hh->cookies_table = acl_htable_create(__http_hdr_max_cookies,
					ACL_HTABLE_FLAG_KEY_REUSE);
	if (hh->cookies_table == NULL)
		acl_msg_fatal("%s, %s(%d): htable create error(%s)",
			__FILE__, myname, __LINE__, acl_last_serror());

	/* 分隔数据段 */
	argv = acl_argv_split(entry->value, ";");
	acl_foreach(iter, argv) {
		ptr = (const char*) iter.data;
		__add_cookie_item(hh->cookies_table, ptr);
	}
Exemplo n.º 2
0
int http_hdr_req_cookies_parse(HTTP_HDR_REQ *hh)
{
	/* data format: "name1=value1; name2=value2; name3=value3" */
	const char  *myname = "http_hdr_req_cookies_parse";
	const HTTP_HDR_ENTRY *entry;
	ACL_ARGV *argv;
	const char *ptr;
	ACL_ITER iter;

	if (hh == NULL)
		acl_msg_fatal("%s, %s(%d): input invalid",
			__FILE__, myname, __LINE__);
	if ((hh->flag & HTTP_HDR_REQ_FLAG_PARSE_COOKIE) == 0)
		return 0;

	entry = http_hdr_entry((HTTP_HDR *) hh, "Cookie");
	if (entry == NULL)
		return 0;

	/* bugfix: 在创建哈希表时此处不应设置 ACL_HTABLE_FLAG_KEY_REUSE 标志位,
	 * 如果设置了此标志,则在 __add_cookie_item 中调用 acl_htable_enter 时,
	 * 会将 name 值的内存交给 htable,但随后在宏 RETURN 时却调用了释放数组
	 * 的函数 acl_argv_free(argv),将 name 所属的数组内存一起给释放了
	 * ---zsx, 2014.5.13
	 */
	if (hh->cookies_table == NULL)
#if 0
		hh->cookies_table = acl_htable_create(__http_hdr_max_cookies,
			ACL_HTABLE_FLAG_KEY_REUSE);
#else
		hh->cookies_table = acl_htable_create(__http_hdr_max_cookies, 0);
#endif

	if (hh->cookies_table == NULL)
		acl_msg_fatal("%s, %s(%d): htable create error(%s)",
			__FILE__, myname, __LINE__, acl_last_serror());

	/* 分隔数据段 */
	argv = acl_argv_split(entry->value, ";");
	acl_foreach(iter, argv) {
		ptr = (const char*) iter.data;
		if (ptr && *ptr)
			__add_cookie_item(hh->cookies_table, ptr);
	}