static void removeSessionCookies(WebCookieJar* cookieJar)
{
  CookieMonster* cookieMonster = cookieJar->cookieStore()->GetCookieMonster();
  CookieList cookies = cookieMonster->GetAllCookies();
  for (CookieList::const_iterator iter = cookies.begin(); iter != cookies.end(); ++iter) {
    if (iter->IsSessionCookie())
      cookieMonster->DeleteCanonicalCookie(*iter);
  }
}
예제 #2
0
// SAMSUNG_CHANGE : get_cookie_size >>
static int getCookieSize(JNIEnv* env)
{
  int size = 0;
  CookieMonster* cookieMonster = WebCookieJar::get(false)->cookieStore()->GetCookieMonster();
  CookieList cookies = cookieMonster->GetAllCookies();
  for (CookieList::const_iterator iter = cookies.begin(); iter != cookies.end(); ++iter) {
      size += iter->Name().length() + iter->Value().length();
  }
  return size;
}
예제 #3
0
OP_STATUS
OpScopeCookieManager::DoGetCookie(const GetCookieArg &in, CookieList &out)
{
	OpString in_domain;
	RETURN_IF_ERROR(in_domain.Set(in.GetDomain()));

	RETURN_IF_ERROR(Cookie_Manager::CheckLocalNetworkAndAppendDomain(in_domain));

	// we need non-const strings for the URL API
	OpAutoArray<uni_char> domain_copy( OP_NEWA(uni_char, in_domain.Length() + 1) );
	RETURN_OOM_IF_NULL(domain_copy.get());
	uni_strcpy(domain_copy.get(), in_domain.CStr());
	uni_char *domain = domain_copy.get();
	uni_char *path = NULL;

	OpAutoArray<uni_char> path_copy( in.HasPath() ? OP_NEWA(uni_char, in.GetPath().Length() + 1) : NULL );
	if (in.HasPath())
	{
		RETURN_OOM_IF_NULL(path_copy.get());
		uni_strcpy(path_copy.get(), in.GetPath().CStr());
		path = path_copy.get();
	}

	OpAutoArray< ::Cookie * > cookies( OP_NEWA(::Cookie *, urlManager->GetMaxCookiesInDomain()) );
	RETURN_OOM_IF_NULL(cookies.get());
	int cookie_size = 0;
	OP_STATUS status = g_url_api->BuildCookieList(cookies.get(), &cookie_size, domain, path, TRUE);
	if (OpStatus::IsError(status))
		return SetCommandError(OpScopeTPHeader::BadRequest, UNI_L("Could not get cookies for specified domain and path"));

	for (int i = 0; i < cookie_size; ++i)
	{
		Cookie *cookie_out = out.AppendNewCookieList();
		RETURN_OOM_IF_NULL(cookie_out);

		::Cookie *cookie = cookies[i];
		if (!cookie || !(cookie->Received_Domain().CStr() || (cookie->GetDomain() && cookie->GetDomain()->GetFullDomain())))
		{
			OP_ASSERT(cookie && cookie->GetDomain() && cookie->GetDomain()->GetFullDomain());
			return OpStatus::ERR_NULL_POINTER;
		}

		RETURN_IF_ERROR(SetCookieValue(*cookie_out, *cookie));
	}
	return OpStatus::OK;
}
예제 #4
0
static ngx_int_t ngx_http_cxxmvc_handler(ngx_http_request_t *r)
{
	using dragon::kHttp_Method_Get;
	using dragon::kResponseTypeRedirect;
	using dragon::HeaderList;
	using dragon::CookieList;
	using dragon::StringRef;
	using dragon::HttpRequest;
	using dragon::HttpResponse;

	ngx_buf_t *buf = NULL;
	ngx_chain_t out;

	unsigned uriLen = r->uri.len;
	if (r->args.len > 0) 
		uriLen = r->uri.len + r->args.len + 1;
	
	struct sockaddr_in *sin;
	ngx_addr_t          addr;
	addr.sockaddr = r->connection->sockaddr;
	addr.socklen  = r->connection->socklen;
	sin = (struct sockaddr_in *)addr.sockaddr;
	char *ip = inet_ntoa(sin->sin_addr);

	StringRef IP(ip, strlen(ip));
	StringRef routingUrl((const char *)r->uri.data, uriLen);
	StringRef userAgent;
	if (r->headers_in.user_agent)
		userAgent = StringRef((const char *)r->headers_in.user_agent->value.data, r->headers_in.user_agent->value.len);
	
	std::string userCookie = ngx_http_get_cookie(r);
	std::string lang       = ngx_http_get_language(r);

	HttpRequest  req;
	HttpResponse res;

	req.SetMethod(kHttp_Method_Get);
	req.SetUrl(routingUrl);
	req.SetIp(IP);
	//req.SetHost(StringRef(host, strlen(host)));
	req.SetUserAgent(userAgent);
	req.SetUserCookie(StringRef(userCookie.c_str(), userCookie.length()));
	req.SetAcceptLanguage(StringRef(lang.c_str(), lang.length()));
        req.ParseCookie();

	DE.ResponseRequest(req, res);

	ngx_str_t k = ngx_string("X-Powered-By");
	ngx_str_t v = ngx_string("cxxmvc/0.1");;
	ngx_http_add_header(r, &v, &k);

	if (res.GetResponseType() == kResponseTypeRedirect)
	{
		ngx_str_t k = ngx_string("location");
		ngx_str_t v = {res.GetContent().length(), (u_char *)res.GetContent().c_str()};
		ngx_http_add_header(r, &v, &k);
	}

	HeaderList headers = res.GetHeaders();
	if (headers.size() > 0) 
	{
		HeaderList::iterator iter;
		HeaderList::iterator end = headers.end();
		for (iter = headers.begin(); iter != end; ++iter)
		{		
			ngx_str_t k;
			ngx_str_t v; 

			k.data = (u_char *)ngx_pcalloc(r->pool, iter->first.length()+1);
			k.len  = iter->first.length();
			strcpy((char *)k.data, (const char *)iter->first.c_str());

			v.data = (u_char *)ngx_pcalloc(r->pool, iter->second.length()+1);
			v.len  = iter->second.length();
			strcpy((char *)v.data, (const char *)iter->second.c_str());

		//	std::cout << "key : "<< k.data << std::endl;
		//	std::cout << "value : " << v.data << std::endl;

			ngx_http_add_header(r, &v, &k);
		}
	}

	CookieList cookies = res.GetCookies();
	if (cookies.size() > 0)
	{
		CookieList::iterator iter;
		CookieList::iterator end = cookies.end();
		for (iter = cookies.begin(); iter != end; ++iter)
		{
			ngx_str_t v; 

			v.data = (u_char *)ngx_pcalloc(r->pool, iter->length()+1);
			v.len  = iter->length();
			strcpy((char *)v.data, (const char *)iter->c_str());

			ngx_http_add_cookie(r, v);
		}
	}

	r->headers_out.status             = res.GetStatusCode();
    	r->headers_out.content_type.len   = res.GetContentType().length();
	r->headers_out.content_type.data  = (u_char *)res.GetContentType().c_str();

	if (res.GetDetaRef().length() > 0)
		r->headers_out.content_length_n = res.GetDetaRef().length();
        else 
       		r->headers_out.content_length_n = res.GetContent().length();


        ngx_http_send_header(r);

        buf = (ngx_buf_t *)ngx_pcalloc(r->pool, sizeof(ngx_buf_t));

        if (buf == NULL) {
                ngx_log_error(NGX_LOG_ERR,
                              r->connection->log,
                              0,
                              "Failed to allocate response buffer.");
                return NGX_ERROR;
        }

	if (res.GetDetaRef().length() > 0) {
		buf->pos = (u_char *)res.GetDetaRef().data();
       		buf->last = buf->pos + res.GetDetaRef().length();
	} else {
       		buf->pos = (u_char *)res.GetContent().c_str();
        	buf->last = buf->pos + res.GetContent().length();
	}
        buf->memory   = 1; /* content is in read-only memory */
        buf->last_buf = 1; /* there will be no more buffers in the request */

	out.buf    = buf;
	out.next   = NULL;

	return ngx_http_output_filter(r, &out);
}
예제 #5
0
static int getCookieNumber(JNIEnv* env)
{
  CookieMonster* cookieMonster = WebCookieJar::get(false)->cookieStore()->GetCookieMonster();
  CookieList cookies = cookieMonster->GetAllCookies();
  return cookies.size();
}