pike.git / lib / modules / Protocols.pmod / EngineIO.pmod

version» Context lines:

pike.git/lib/modules/Protocols.pmod/EngineIO.pmod:85:    BASE64='b', OPEN='0', CLOSE, PING, PONG, MESSAGE, UPGRADE, NOOP,    SENDQEMPTY, FORCECLOSE   };      // All EngineIO sessions indexed on sid.   private mapping(string:Socket) clients = ([]);      private Regexp acceptgzip = Regexp("(^|,)gzip(,|$)");   private Regexp xxsua = Regexp(";MSIE|Trident/");    - //! @param _options + //! @param options   //! Optional options to override the defaults.   //! This parameter is passed down as is to the underlying   //! @[Socket].   //!   //! @example   //! Sample minimal implementation of an EngineIO server farm:   //!   //!void echo(mixed id, string|Stdio.Buffer msg) {   //! id->write(msg);   //!}
pike.git/lib/modules/Protocols.pmod/EngineIO.pmod:120:   //! }   //!}   //!   //!int main(int argc, array(string) argv)   //!{ Protocols.WebSocket.Port(httprequest, wsrequest, 80);   //! return -1;   //!}   //!   //! @seealso   //! @[Socket.create()] - final Socket farm(Protocols.WebSocket.Request req, void|mapping _options) { + final Socket farm(Protocols.WebSocket.Request req, void|mapping options) {    string sid;    PD("Request %O\n", req.query);    if (sid = req.variables.sid) {    Socket client;    if (!(client = clients[sid]))    req.response_and_finish((["data":"Unknown sid",    "error":Protocols.HTTP.HTTP_GONE]));    else    client.onrequest(req);    } else -  return Socket(req, _options); +  return Socket(req, options);    return 0;   }      //! Runs a single Engine.IO session.   class Socket {       //! Contains the last request seen on this connection.    //! Can be used to obtain cookies etc.    final Protocols.WebSocket.Request request;       //! The unique session identifier (in the Engine.IO docs referred    //! to as simply: id).    final string sid;       private mixed id; // This is the callback parameter -  mapping options; +  final mapping _options;    private Stdio.Buffer ci = Stdio.Buffer();    private function(mixed, string|Stdio.Buffer:void) read_cb;    private function(mixed:void) close_cb;    private Thread.Queue sendq = Thread.Queue();    private ADT.Queue recvq = ADT.Queue();    private string curtransport;    private Transport conn;    private Transport upgtransport;    private enum {RUNNING = 0, PAUSED, SCLOSING, RCLOSING};    private int state = RUNNING;       class Transport {    final function(int, void|string|Stdio.Buffer:void) read_cb;    final protected int pingtimeout;       protected void create(Protocols.WebSocket.Request req) { -  pingtimeout = options->pingTimeout/1000+1; +  pingtimeout = _options->pingTimeout/1000+1;    kickwatchdog();    }       private void droptimeout() {    remove_call_out(close);    }       protected void destroy() {    droptimeout();    }
pike.git/lib/modules/Protocols.pmod/EngineIO.pmod:217:       protected void getbody(Protocols.WebSocket.Request _req);    protected void wrapfinish(Protocols.WebSocket.Request req, string body);       protected void respfinish(Protocols.WebSocket.Request req,    void|string body, void|string mimetype) {    mapping|string comprheads;    if (!body)    body = noop;    #if constant(Gz.deflate) -  if (gzfile && sizeof(body) >= options->compressionThreshold +  if (gzfile && sizeof(body) >= _options->compressionThreshold    && (comprheads = req.request_headers["accept-encoding"])    && acceptgzip.match(comprheads)) {    Stdio.FakeFile f = Stdio.FakeFile("", "wb");    gzfile.open(f, "wb"); -  gzfile.setparams(options->compressionLevel, -  options->compressionStrategy, options->compressionWindowSize); +  gzfile.setparams(_options->compressionLevel, +  _options->compressionStrategy, _options->compressionWindowSize);    gzfile.write(body);    gzfile.close();    comprheads = headers;    if (sizeof(body)>f.stat().size) {    body = (string)f;    comprheads += (["Content-Encoding":"gzip"]);    }    } else    #endif    comprheads = headers;
pike.git/lib/modules/Protocols.pmod/EngineIO.pmod:245:    "data":body,    "type":mimetype||"text/plain;charset=UTF-8",    "extra_heads":comprheads]));    }       protected void create(Protocols.WebSocket.Request _req) {    noop = sprintf("1:%c", NOOP);    forceascii = !zero_type(_req.variables->b64);    ci->set_error_mode(1);    #if constant(Gz.deflate) -  if (options->compressionLevel) +  if (_options->compressionLevel)    gzfile = Gz.File();    #endif    t::create(_req);    if (_req.request_headers.origin) {    headers["Access-Control-Allow-Credentials"] = "true";    headers["Access-Control-Allow-Origin"] = _req.request_headers.origin;    } else    headers["Access-Control-Allow-Origin"] = "*";    // prevent XSS warnings on IE    string ua = _req.request_headers["user-agent"];
pike.git/lib/modules/Protocols.pmod/EngineIO.pmod:646:    flush();    break;    }    }    }       protected void destroy() {    close();    }    -  //! @param _options +  //! @param options    //! Optional options to override the defaults.    //! @mapping    //! @member int "pingTimeout"    //! If, the connection is idle for longer than this, the connection    //! is terminated, unit in @expr{ms}.    //! @member int "pingInterval"    //! The browser-client will send a small ping message every    //! @expr{pingInterval ms}.    //! @member int "allowUpgrades"    //! When @expr{true} (default), it allows the server to upgrade    //! the connection to a real @[Protocol.WebSocket] connection.    //! @member int "compressionLevel"    //! The gzip compressionlevel used to compress packets.    //! @member int "compressionThreshold"    //! Packets smaller than this will not be compressed.    //! @endmapping    protected void create(Protocols.WebSocket.Request req, -  void|mapping _options) { +  void|mapping options) {    request = req; -  options = .EngineIO.options; -  if (_options && sizeof(_options)) -  options += _options; +  _options = .EngineIO.options; +  if (options && sizeof(options)) +  _options += options;    switch (curtransport = req.variables->transport) {    default:    req.response_and_finish((["data":"Unsupported transport",    "error":Protocols.HTTP.HTTP_UNSUPP_MEDIA]));    return;    case "websocket":    conn = WebSocket(req, req.websocket_accept(0));    break;    case "polling":    conn = req.variables.j ? JSONP(req) : XHR(req);    break;    }    conn.read_cb = recv;    ci->add(Crypto.Random.random_string(SIDBYTES-TIMEBYTES));    ci->add_hint(gethrtime(), TIMEBYTES);    sid = MIME.encode_base64(ci->read());    clients[sid] = this;    send(OPEN, Standards.JSON.encode(    (["sid":sid,    "upgrades": -  options->allowUpgrades ? ({"websocket"}) : ({}), -  "pingInterval":options->pingInterval, -  "pingTimeout":options->pingTimeout +  _options->allowUpgrades ? ({"websocket"}) : ({}), +  "pingInterval":_options->pingInterval, +  "pingTimeout":_options->pingTimeout    ])));    PD("New EngineIO sid: %O\n", sid);    }       //! Handle request, and returns a new Socket object if it's a new    //! connection.    final void onrequest(Protocols.WebSocket.Request req) {    string s;    request = req;    if ((s = req.variables->transport) == curtransport)