Exemple #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);
	}
Exemple #2
0
void http_util_set_req_cookie(HTTP_UTIL *http_util, const char *name, const char *value)
{
	HTTP_HDR_ENTRY *hdr_entry;
	char *ptr;

	if (name == NULL || *name == 0 || value == NULL)
		return;
	hdr_entry = http_hdr_entry(&http_util->hdr_req->hdr, name);
	if (hdr_entry == NULL) {
		http_hdr_put_str(&http_util->hdr_req->hdr, name, value);
		return;
	}

	ptr = acl_concatenate(hdr_entry->value, "; ", name, "=", value, NULL);
	acl_myfree(hdr_entry->value);
	hdr_entry->value = ptr;
}
Exemple #3
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);
	}
Exemple #4
0
HTTP_HDR_ENTRY *http_util_get_res_entry(HTTP_UTIL *http_util, const char *name)
{
	if (name == NULL || *name == 0)
		return (NULL);
	return (http_hdr_entry(&http_util->hdr_res->hdr, name));
}