pike.git / lib / modules / Protocols.pmod / HTTP.pmod / Session.pike

version» Context lines:

pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:1:   #pike __REAL_VERSION__    - // $Id: Session.pike,v 1.17 2007/11/15 02:24:01 srb Exp $ + // $Id: Session.pike,v 1.18 2007/11/23 14:19:09 srb Exp $      import Protocols.HTTP;      typedef string|Standards.URI|SessionURL URL;      //! The number of redirects to follow, if any.   //! This is the default to the created Request objects.   //!   //! A redirect automatically turns into a GET request,   //! and all header, query, post or put information is dropped.
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:400:      // this class is internal for now, until there is a   // decent use for it externally      class Cookie   {    string key="?";    string data="?";    int expires=-1;    string path="/"; +  string domain="";    string site="?"; -  +  int secure=0;       string _sprintf(int t)    {    if (t=='O') -  return sprintf("Cookie(%O: %O=%O; expires=%s; path=%O)", +  return sprintf( +  "Cookie(%O: %O=%O; expires=%s; path=%O; domain=%O; secure=%d)",    site,    key,data,    Calendar.ISO.Second(expires)->format_http(), -  path); +  path,domain,secure);    }       void from_http(string s,Standards.URI at)    { -  array v=array_sscanf(s,"%{%s=%[^;]%*[; ]%}"); +  array v=array_sscanf(s,"%{%s=%[^;]%*[; ]%}%s");       site=at->host+":"+at->port;    -  +  if (sizeof(v)>=2 && lower_case(v[1])=="secure") +  secure=1; +     if (sizeof(v)<1) return;    v=v[0];    if (sizeof(v)<1) return;    [key,data]=v[0];       foreach (v[1..];;[string what,string value])    switch (lower_case(what))    {    case "expires":    expires=    (Calendar.ISO.parse("%e, %D %M %Y %h:%m:%s %z",value)||    Calendar.ISO.parse("%e, %D-%M-%y %h:%m:%s %z",value) )    ->unix_time();    break;       case "path":    path=value;    break; -  +  +  case "domain": +  domain=value; +  break;    }    }       string encode()    { -  return sprintf("%O\t%O=%O\t%O\t%O", +  return sprintf("%O\t%O=%O\t%O\t%O\t%O\t%O",    site,    key,data,    expires, -  path); +  path,domain,secure);    }       Cookie decode(string indata)    { -  array v=array_sscanf(indata,"%O\t%O=%O\t%O\t%O"); +  array v=array_sscanf(indata,"%O\t%O=%O\t%O\t%O\t%O\t%O");    if (sizeof(v)!=5) error("Cookie.decode: parse error\n"); -  [site,key,data,expires,path]=v; +  [site,key,data,expires,path,domain,secure]=v;    if (!stringp(site) ||    !stringp(key) ||    !stringp(data) ||    !stringp(path) || -  +  !stringp(domain) ||    !intp(expires))    error("Cookie.decode: parse error\n");    return this;    }   }         //! Parse and set a cookie received in the HTTP protocol.   //! The cookie will be checked against current security levels et al.   void set_http_cookie(string cookie,Standards.URI at)
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:530:      //! Get the cookies that we should send to this server,   //! for this url. They are presented in the form suitable   //! for HTTP headers (as an array).   //! This will also take in count expiration of cookies,   //! and delete expired cookies from the @[Session] unless   //! @[no_delete] is true.   array(string) get_cookies(Standards.URI|SessionURL for_url,    void|int(0..1) no_delete)   { +  string host=for_url->host;    mapping(string:Cookie) sc= -  cookie_lookup[for_url->host+":"+for_url->port]||([]); +  cookie_lookup[host+":"+for_url->port]||([]);       array(string) res=({});    int now=time();       foreach (sc;string key;Cookie c)    {    if (c->expires<now && c->expires!=-1)    {    if (!no_delete)    {    m_delete(sc,key);    all_cookies[c]=0;    }    } -  else -  { -  if (c->path!="/") -  { -  string path=for_url->path; -  if (path=="") continue; // =="/" and we didn't get that -  if (c->path[..strlen(path)]!=path) -  continue; // not our path -  } +  else if ((!sizeof(c->domain) +  || c->domain==host[sizeof(host)-sizeof(c->domain)..]) +  && (sizeof(c->path)<=1 || has_prefix(for_url->path, c->path)) +  && (!c->secure || has_prefix(for_url->scheme, "https")))    res+=({key+"="+c->data});    } -  } +     return res;   }      // ================================================================   // connections      //! Cache of hostname to IP lookups. Given to and used by the   //! @[Query] objects.   mapping hostname_cache=([]);