void get_cookies(const char *headers, char ***dynamic_cookies, int *n_dynamic_cookies, char ***static_cookies, int *n_static_cookies) { int index = 0; char **header_lines = NULL; int n_header_lines = 0; split_string(headers, "\r\n", &header_lines, &n_header_lines); for(index=0; index<n_header_lines; index++) { char use_static = 0; char *result = NULL; int cparts_index = 0; char **cparts = NULL; int n_cparts = 0; if (strncmp(header_lines[index], "Set-Cookie:", 11) != 0) continue; split_string(&header_lines[index][12], ";", &cparts, &n_cparts); for(cparts_index=0; cparts_index<n_cparts; cparts_index++) { char *part = cparts[cparts_index]; while(*part == ' ') part++; if (strncmp(part, "expires=", 8) == 0) { use_static = 1; continue; } if (strncmp(part, "path=", 5) == 0) continue; if (strncmp(part, "domain=", 7) == 0) continue; if (strncmp(part, "HttpOnly", 8) == 0) continue; str_add(&result, "%s ", part); } free_splitted_string(cparts, n_cparts); if (use_static) add_cookie(static_cookies, n_static_cookies, result); else add_cookie(dynamic_cookies, n_dynamic_cookies, result); free(result); } free_splitted_string(header_lines, n_header_lines); }
static PyObject* dtk_webkit_cookie_add_cookie(PyObject* self, PyObject* args) { char *cookie_file; if (!PyArg_ParseTuple(args, "s", &cookie_file)) { return NULL; } add_cookie(cookie_file); Py_RETURN_NONE; }
const std::vector<HttpCookie*>& HttpServletRequest::getCookies(void) const { if (cookies_inited_) return cookies_; // 设置标记表明已经分析过cookie了,以便于下次重复调用时节省时间 const_cast<HttpServletRequest*>(this)->cookies_inited_ = true; if (cgi_mode_) { const char* ptr = acl_getenv("HTTP_COOKIE"); if (ptr == NULL || *ptr == 0) return cookies_; ACL_ARGV* argv = acl_argv_split(ptr, ";"); ACL_ITER iter; acl_foreach(iter, argv) { add_cookie(const_cast<HttpServletRequest*> (this)->cookies_, (char*) iter.data); } acl_argv_free(argv); return cookies_; }
int http_parse_cookies(struct hashtable *ht, char *cookies_str) { char *p = cookies_str, *s = p; char c; for (;;) { switch (*p) { case 0: case ';': case ' ': c = *p; *p = 0; if (*s) add_cookie(ht, s); *p = c; for (; *p == ';' || *p == ' '; ++p); if (0 == *p) return 0; s = p; break; default: ++p; } } }
/* Prepare initial DHCPv4 message and add options as per message type */ static struct net_buf *prepare_message(struct net_if *iface, uint8_t type) { struct net_buf *buf; struct net_buf *frag; struct dhcp_msg *msg; buf = net_nbuf_get_reserve_tx(0); if (!buf) { return NULL; } frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, NULL)); if (!frag) { goto fail; } net_nbuf_set_ll_reserve(buf, net_buf_headroom(frag)); net_nbuf_set_iface(buf, iface); net_nbuf_set_family(buf, AF_INET); net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr)); net_buf_frag_add(buf, frag); /* Leave room for IPv4 + UDP headers */ net_buf_add(buf->frags, NET_IPV4UDPH_LEN); if (net_buf_tailroom(frag) < sizeof(struct dhcp_msg)) { goto fail; } msg = (struct dhcp_msg *)(frag->data + NET_IPV4UDPH_LEN); memset(msg, 0, sizeof(struct dhcp_msg)); msg->op = DHCPV4_MSG_BOOT_REQUEST; msg->htype = HARDWARE_ETHERNET_TYPE; msg->hlen = HARDWARE_ETHERNET_LEN; msg->xid = htonl(iface->dhcpv4.xid); msg->flags = htons(DHCPV4_MSG_BROADCAST); if (iface->dhcpv4.state == NET_DHCPV4_INIT) { memset(msg->ciaddr, 0, sizeof(msg->ciaddr)); } else { memcpy(msg->ciaddr, iface->dhcpv4.requested_ip.s4_addr, 4); } memcpy(msg->chaddr, iface->link_addr.addr, iface->link_addr.len); net_buf_add(frag, sizeof(struct dhcp_msg)); if (!add_sname(buf) || !add_file(buf) || !add_cookie(buf) || !add_msg_type(buf, type)) { goto fail; } return buf; fail: net_nbuf_unref(buf); return NULL; }