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

version» Context lines:

pike.git/lib/modules/Protocols.pmod/HTTP.pmod/module.pmod:78:   //! @param con   //! Old connection object.   //! @param data   //! Data payload to be transmitted in the request.   .Query do_method(string method,    string|Standards.URI url,    void|mapping(string:int|string) query_variables,    void|mapping(string:string|array(string)) request_headers,    void|Protocols.HTTP.Query con, void|string data)   { -  if(!con) -  con = .Query(); -  +     if(stringp(url))    url=Standards.URI(url);    -  +  if( (< "httpu", "httpmu" >)[url->scheme] ) { +  do_udp_method(method, url, query_variables, request_headers, data); +  return 0; +  } +  +  if(!con) +  con = .Query(); +    #if constant(SSL.sslfile)    if(url->scheme!="http" && url->scheme!="https")    error("Can't handle %O or any other protocols than HTTP or HTTPS.\n",    url->scheme);       con->https = (url->scheme=="https")? 1 : 0;   #else    if(url->scheme!="http")    error("Can't handle %O or any other protocol than HTTP.\n",    url->scheme);
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/module.pmod:134:    request_headers, data);       if (!con->ok) {    if (con->errno)    error ("I/O error: %s\n", strerror (con->errno));    return 0;    }    return con;   }    + static void do_udp_method(string method, Standards.URI url, +  void|mapping(string:int|string) query_variables, +  void|mapping(string:string|array(string)) +  request_headers, void|Stdio.UDP udp, +  void|string data) + { +  if(!request_headers) +  request_headers = ([]); +  +  string path = url->path; +  if(path=="") { +  if(url->method=="httpmu") +  path = "*"; +  else +  path = "/"; +  } +  string msg = method + " " + path + " HTTP/1.1\r\n"; +  if(!udp) { +  udp = Stdio.UDP(); +  int port = 10000 + random(1000); +  while( catch( udp->bind(port++) ) ); +  if(url->method=="httpmu") { +  udp->enable_multicast("130.236.182.86"); +  udp->add_membership(url->host, 0, 0); +  } +  udp->set_multicast_ttl(4); +  } +  udp->send(url->host, url->port, msg); + } +    //! Sends a HTTP GET request to the server in the URL and returns the   //! created and initialized @[Query] object. @expr{0@} is returned   //! upon failure. If a query object having   //! @expr{request_headers->Connection=="Keep-Alive"@} from a previous   //! request is provided and the already established server connection   //! can be used for the next request, you may gain some performance.   //!   .Query get_url(string|Standards.URI url,    void|mapping(string:int|string) query_variables,    void|mapping(string:string|array(string)) request_headers,
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/module.pmod:282:    return map(v[1], lambda (string val) {    return    http_encode_string(v[0])+"="+    http_encode_string(val);    })*"&";    return http_encode_string(v[0])+"="+    http_encode_string(v[1]);    })*"&";   }    + // RFC 1738, 2.2. URL Character Encoding Issues + static constant url_non_corresponding = enumerate(0x20) + ({ 0x1f }) + +  enumerate(128,1,0x80); + static constant url_unsafe = ({ '<', '>', '"', '#', '%', '{', '}', +  '|', '\\', '^', '~', '[', ']', '`' }); + static constant url_reserved = ({ ';', '/', '?', ':', '@', '=', '&' }); +  + // Encode these chars + static constant url_chars = url_non_corresponding + url_unsafe + +  url_reserved + ({ '+' }); + static constant url_from = sprintf("%c", url_chars[*]); + static constant url_to = sprintf("%%%02x", url_chars[*]); +  +    //! This protects all odd - see @[http_encode_query()] -   //! characters for transfer in HTTP.   //!   //! Do not use this function to protect URLs, since   //! it will protect URL characters like @expr{'/'@} and @expr{'?'@}.   //! @param in   //! The string to encode   //! @returns   //! The HTTP encoded string   string http_encode_string(string in)   { -  return replace( -  in, -  ({ "\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007", -  "\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017", -  "\020", "\021", "\022", "\023", "\024", "\025", "\026", "\027", -  "\030", "\031", "\032", "\033", "\034", "\035", "\036", "\037", -  "\177", -  "\200", "\201", "\202", "\203", "\204", "\205", "\206", "\207", -  "\210", "\211", "\212", "\213", "\214", "\215", "\216", "\217", -  "\220", "\221", "\222", "\223", "\224", "\225", "\226", "\227", -  "\230", "\231", "\232", "\233", "\234", "\235", "\236", "\237", -  " ", "%", "'", "\"", "+", "&", "=", "/", -  "#", ";", "\\", "<", ">", "\t", "\n", "\r", "@" }), -  ({ -  "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07", -  "%08", "%09", "%0a", "%0b", "%0c", "%0d", "%0e", "%0f", -  "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17", -  "%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f", -  "%7f", -  "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87", -  "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f", -  "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97", -  "%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f", -  "%20", "%25", "%27", "%22", "%2b", "%26", "%3d", "%2f", -  "%23", "%3b", "%5c", "%3c", "%3e", "%09", "%0a", "%0d", -  "%40" })); +  return replace(in, url_from, url_to);   }      //! Encode the specified string in as to the HTTP cookie standard.   //! @param f   //! The string to encode.   //! @returns   //! The HTTP cookie encoded string.   string http_encode_cookie(string f)   {    return replace(
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/module.pmod:353:    "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",    "%18", "%19", "%1a", "%1b", "%1c", "%1d", "%1e", "%1f",    "%7f",    "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",    "%88", "%89", "%8a", "%8b", "%8c", "%8d", "%8e", "%8f",    "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",    "%98", "%99", "%9a", "%9b", "%9c", "%9d", "%9e", "%9f",    "%20", "%25", "%27", "%22", "%2c", "%3b", "%3d", "%3a" }));   }    -  +    // --- Compatibility code      //! Helper function for replacing HTML entities with the corresponding   //! unicode characters.   //! @deprecated Parser.parse_html_entities   string unentity(string s)   {    return master()->resolv("Parser.parse_html_entities")(s,1);   }