/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['socket.io/listener.js']) {
  _$jscoverage['socket.io/listener.js'] = [];
  _$jscoverage['socket.io/listener.js'][1] = 0;
  _$jscoverage['socket.io/listener.js'][16] = 0;
  _$jscoverage['socket.io/listener.js'][17] = 0;
  _$jscoverage['socket.io/listener.js'][18] = 0;
  _$jscoverage['socket.io/listener.js'][19] = 0;
  _$jscoverage['socket.io/listener.js'][20] = 0;
  _$jscoverage['socket.io/listener.js'][29] = 0;
  _$jscoverage['socket.io/listener.js'][31] = 0;
  _$jscoverage['socket.io/listener.js'][32] = 0;
  _$jscoverage['socket.io/listener.js'][34] = 0;
  _$jscoverage['socket.io/listener.js'][35] = 0;
  _$jscoverage['socket.io/listener.js'][37] = 0;
  _$jscoverage['socket.io/listener.js'][38] = 0;
  _$jscoverage['socket.io/listener.js'][39] = 0;
  _$jscoverage['socket.io/listener.js'][40] = 0;
  _$jscoverage['socket.io/listener.js'][44] = 0;
  _$jscoverage['socket.io/listener.js'][45] = 0;
  _$jscoverage['socket.io/listener.js'][46] = 0;
  _$jscoverage['socket.io/listener.js'][47] = 0;
  _$jscoverage['socket.io/listener.js'][51] = 0;
  _$jscoverage['socket.io/listener.js'][52] = 0;
  _$jscoverage['socket.io/listener.js'][54] = 0;
  _$jscoverage['socket.io/listener.js'][57] = 0;
  _$jscoverage['socket.io/listener.js'][58] = 0;
  _$jscoverage['socket.io/listener.js'][60] = 0;
  _$jscoverage['socket.io/listener.js'][61] = 0;
  _$jscoverage['socket.io/listener.js'][62] = 0;
  _$jscoverage['socket.io/listener.js'][63] = 0;
  _$jscoverage['socket.io/listener.js'][66] = 0;
  _$jscoverage['socket.io/listener.js'][69] = 0;
  _$jscoverage['socket.io/listener.js'][70] = 0;
  _$jscoverage['socket.io/listener.js'][71] = 0;
  _$jscoverage['socket.io/listener.js'][72] = 0;
  _$jscoverage['socket.io/listener.js'][73] = 0;
  _$jscoverage['socket.io/listener.js'][74] = 0;
  _$jscoverage['socket.io/listener.js'][75] = 0;
  _$jscoverage['socket.io/listener.js'][76] = 0;
  _$jscoverage['socket.io/listener.js'][77] = 0;
  _$jscoverage['socket.io/listener.js'][78] = 0;
  _$jscoverage['socket.io/listener.js'][80] = 0;
  _$jscoverage['socket.io/listener.js'][81] = 0;
  _$jscoverage['socket.io/listener.js'][82] = 0;
  _$jscoverage['socket.io/listener.js'][85] = 0;
  _$jscoverage['socket.io/listener.js'][87] = 0;
  _$jscoverage['socket.io/listener.js'][89] = 0;
  _$jscoverage['socket.io/listener.js'][92] = 0;
  _$jscoverage['socket.io/listener.js'][93] = 0;
  _$jscoverage['socket.io/listener.js'][104] = 0;
  _$jscoverage['socket.io/listener.js'][105] = 0;
  _$jscoverage['socket.io/listener.js'][106] = 0;
  _$jscoverage['socket.io/listener.js'][107] = 0;
  _$jscoverage['socket.io/listener.js'][109] = 0;
  _$jscoverage['socket.io/listener.js'][110] = 0;
  _$jscoverage['socket.io/listener.js'][112] = 0;
  _$jscoverage['socket.io/listener.js'][114] = 0;
  _$jscoverage['socket.io/listener.js'][116] = 0;
  _$jscoverage['socket.io/listener.js'][117] = 0;
  _$jscoverage['socket.io/listener.js'][118] = 0;
  _$jscoverage['socket.io/listener.js'][119] = 0;
  _$jscoverage['socket.io/listener.js'][122] = 0;
  _$jscoverage['socket.io/listener.js'][123] = 0;
  _$jscoverage['socket.io/listener.js'][124] = 0;
  _$jscoverage['socket.io/listener.js'][125] = 0;
  _$jscoverage['socket.io/listener.js'][127] = 0;
  _$jscoverage['socket.io/listener.js'][128] = 0;
  _$jscoverage['socket.io/listener.js'][137] = 0;
  _$jscoverage['socket.io/listener.js'][141] = 0;
  _$jscoverage['socket.io/listener.js'][144] = 0;
  _$jscoverage['socket.io/listener.js'][147] = 0;
  _$jscoverage['socket.io/listener.js'][148] = 0;
  _$jscoverage['socket.io/listener.js'][149] = 0;
  _$jscoverage['socket.io/listener.js'][150] = 0;
  _$jscoverage['socket.io/listener.js'][151] = 0;
  _$jscoverage['socket.io/listener.js'][154] = 0;
  _$jscoverage['socket.io/listener.js'][155] = 0;
  _$jscoverage['socket.io/listener.js'][158] = 0;
  _$jscoverage['socket.io/listener.js'][159] = 0;
  _$jscoverage['socket.io/listener.js'][160] = 0;
  _$jscoverage['socket.io/listener.js'][161] = 0;
  _$jscoverage['socket.io/listener.js'][164] = 0;
  _$jscoverage['socket.io/listener.js'][165] = 0;
  _$jscoverage['socket.io/listener.js'][166] = 0;
}
_$jscoverage['socket.io/listener.js'][1]++;
var url = require("url"), sys = require("sys"), fs = require("fs"), options = require("./utils").options, Client = require("./client"), clientVersion = require("./../../support/socket.io-client/lib/io").io.version, transports = {"flashsocket": require("./transports/flashsocket"), "htmlfile": require("./transports/htmlfile"), "websocket": require("./transports/websocket"), "xhr-multipart": require("./transports/xhr-multipart"), "xhr-polling": require("./transports/xhr-polling"), "jsonp-polling": require("./transports/jsonp-polling")};
_$jscoverage['socket.io/listener.js'][16]++;
var Listener = module.exports = (function (server, options) {
  _$jscoverage['socket.io/listener.js'][17]++;
  process.EventEmitter.call(this);
  _$jscoverage['socket.io/listener.js'][18]++;
  var self = this;
  _$jscoverage['socket.io/listener.js'][19]++;
  this.server = server;
  _$jscoverage['socket.io/listener.js'][20]++;
  this.options({origins: "*:*", resource: "socket.io", flashPolicyServer: true, transports: ["websocket", "flashsocket", "htmlfile", "xhr-multipart", "xhr-polling", "jsonp-polling"], transportOptions: {}, log: sys.log}, options);
  _$jscoverage['socket.io/listener.js'][29]++;
  if (! this.options.log) {
    _$jscoverage['socket.io/listener.js'][29]++;
    this.options.log = (function () {
});
  }
  _$jscoverage['socket.io/listener.js'][31]++;
  this.clients = this.clientsIndex = {};
  _$jscoverage['socket.io/listener.js'][32]++;
  this._clientFiles = {};
  _$jscoverage['socket.io/listener.js'][34]++;
  var listeners = this.server.listeners("request");
  _$jscoverage['socket.io/listener.js'][35]++;
  this.server.removeAllListeners("request");
  _$jscoverage['socket.io/listener.js'][37]++;
  this.server.addListener("request", (function (req, res) {
  _$jscoverage['socket.io/listener.js'][38]++;
  if (self.check(req, res)) {
    _$jscoverage['socket.io/listener.js'][38]++;
    return;
  }
  _$jscoverage['socket.io/listener.js'][39]++;
  for (var i = 0, len = listeners.length; i < len; i++) {
    _$jscoverage['socket.io/listener.js'][40]++;
    listeners[i].call(this, req, res);
}
}));
  _$jscoverage['socket.io/listener.js'][44]++;
  this.server.addListener("upgrade", (function (req, socket, head) {
  _$jscoverage['socket.io/listener.js'][45]++;
  if (! self.check(req, socket, true, head)) {
    _$jscoverage['socket.io/listener.js'][46]++;
    socket.end();
    _$jscoverage['socket.io/listener.js'][47]++;
    socket.destroy();
  }
}));
  _$jscoverage['socket.io/listener.js'][51]++;
  for (var i in transports) {
    _$jscoverage['socket.io/listener.js'][52]++;
    if ("init" in transports[i]) {
      _$jscoverage['socket.io/listener.js'][52]++;
      transports[i].init(this);
    }
}
  _$jscoverage['socket.io/listener.js'][54]++;
  this.options.log("socket.io ready - accepting connections");
});
_$jscoverage['socket.io/listener.js'][57]++;
sys.inherits(Listener, process.EventEmitter);
_$jscoverage['socket.io/listener.js'][58]++;
for (var i in options) {
  _$jscoverage['socket.io/listener.js'][58]++;
  Listener.prototype[i] = options[i];
}
_$jscoverage['socket.io/listener.js'][60]++;
Listener.prototype.broadcast = (function (message, except) {
  _$jscoverage['socket.io/listener.js'][61]++;
  for (var i = 0, k = Object.keys(this.clients), l = k.length; i < l; i++) {
    _$jscoverage['socket.io/listener.js'][62]++;
    if (this.clients[k[i]] && (! except || [].concat(except).indexOf(this.clients[k[i]].sessionId) == -1)) {
      _$jscoverage['socket.io/listener.js'][63]++;
      this.clients[k[i]].send(message);
    }
}
  _$jscoverage['socket.io/listener.js'][66]++;
  return this;
});
_$jscoverage['socket.io/listener.js'][69]++;
Listener.prototype.check = (function (req, res, httpUpgrade, head) {
  _$jscoverage['socket.io/listener.js'][70]++;
  var path = url.parse(req.url).pathname, parts, cn;
  _$jscoverage['socket.io/listener.js'][71]++;
  if (path && path.indexOf("/" + this.options.resource) === 0) {
    _$jscoverage['socket.io/listener.js'][72]++;
    parts = path.substr(1).split("/");
    _$jscoverage['socket.io/listener.js'][73]++;
    if (this._serveClient(parts.slice(1).join("/"), req, res)) {
      _$jscoverage['socket.io/listener.js'][73]++;
      return true;
    }
    _$jscoverage['socket.io/listener.js'][74]++;
    if (! (parts[1] in transports)) {
      _$jscoverage['socket.io/listener.js'][74]++;
      return false;
    }
    _$jscoverage['socket.io/listener.js'][75]++;
    if (parts[2]) {
      _$jscoverage['socket.io/listener.js'][76]++;
      cn = this.clients[parts[2]];
      _$jscoverage['socket.io/listener.js'][77]++;
      if (cn) {
        _$jscoverage['socket.io/listener.js'][78]++;
        cn._onConnect(req, res);
      }
      else {
        _$jscoverage['socket.io/listener.js'][80]++;
        req.connection.end();
        _$jscoverage['socket.io/listener.js'][81]++;
        req.connection.destroy();
        _$jscoverage['socket.io/listener.js'][82]++;
        this.options.log("Couldnt find client with session id \"" + parts[2] + "\"");
      }
    }
    else {
      _$jscoverage['socket.io/listener.js'][85]++;
      this._onConnection(parts[1], req, res, httpUpgrade, head);
    }
    _$jscoverage['socket.io/listener.js'][87]++;
    return true;
  }
  _$jscoverage['socket.io/listener.js'][89]++;
  return false;
});
_$jscoverage['socket.io/listener.js'][92]++;
Listener.prototype._serveClient = (function (file, req, res) {
  _$jscoverage['socket.io/listener.js'][93]++;
  var self = this, clientPaths = {"socket.io.js": "socket.io.js", "lib/vendor/web-socket-js/WebSocketMain.swf": "lib/vendor/web-socket-js/WebSocketMain.swf", "WebSocketMain.swf": "lib/vendor/web-socket-js/WebSocketMain.swf"}, types = {swf: "application/x-shockwave-flash", js: "text/javascript"};
  _$jscoverage['socket.io/listener.js'][104]++;
  function write(path) {
    _$jscoverage['socket.io/listener.js'][105]++;
    if (req.headers["if-none-match"] == clientVersion) {
      _$jscoverage['socket.io/listener.js'][106]++;
      res.writeHead(304);
      _$jscoverage['socket.io/listener.js'][107]++;
      res.end();
    }
    else {
      _$jscoverage['socket.io/listener.js'][109]++;
      res.writeHead(200, self._clientFiles[path].headers);
      _$jscoverage['socket.io/listener.js'][110]++;
      res.end(self._clientFiles[path].content, self._clientFiles[path].encoding);
    }
}
  _$jscoverage['socket.io/listener.js'][112]++;
  ;
  _$jscoverage['socket.io/listener.js'][114]++;
  var path = clientPaths[file];
  _$jscoverage['socket.io/listener.js'][116]++;
  if (req.method == "GET" && path !== undefined) {
    _$jscoverage['socket.io/listener.js'][117]++;
    if (path in this._clientFiles) {
      _$jscoverage['socket.io/listener.js'][118]++;
      write(path);
      _$jscoverage['socket.io/listener.js'][119]++;
      return true;
    }
    _$jscoverage['socket.io/listener.js'][122]++;
    fs.readFile(__dirname + "/../../support/socket.io-client/" + path, (function (err, data) {
  _$jscoverage['socket.io/listener.js'][123]++;
  if (err) {
    _$jscoverage['socket.io/listener.js'][124]++;
    res.writeHead(404);
    _$jscoverage['socket.io/listener.js'][125]++;
    res.end("404");
  }
  else {
    _$jscoverage['socket.io/listener.js'][127]++;
    var ext = path.split(".").pop();
    _$jscoverage['socket.io/listener.js'][128]++;
    self._clientFiles[path] = {headers: {"Content-Length": data.length, "Content-Type": types[ext], "ETag": clientVersion}, content: data, encoding: ext == "swf"? "binary": "utf8"};
    _$jscoverage['socket.io/listener.js'][137]++;
    write(path);
  }
}));
    _$jscoverage['socket.io/listener.js'][141]++;
    return true;
  }
  _$jscoverage['socket.io/listener.js'][144]++;
  return false;
});
_$jscoverage['socket.io/listener.js'][147]++;
Listener.prototype._onClientConnect = (function (client) {
  _$jscoverage['socket.io/listener.js'][148]++;
  this.clients[client.sessionId] = client;
  _$jscoverage['socket.io/listener.js'][149]++;
  this.options.log("Client " + client.sessionId + " connected");
  _$jscoverage['socket.io/listener.js'][150]++;
  this.emit("clientConnect", client);
  _$jscoverage['socket.io/listener.js'][151]++;
  this.emit("connection", client);
});
_$jscoverage['socket.io/listener.js'][154]++;
Listener.prototype._onClientMessage = (function (data, client) {
  _$jscoverage['socket.io/listener.js'][155]++;
  this.emit("clientMessage", data, client);
});
_$jscoverage['socket.io/listener.js'][158]++;
Listener.prototype._onClientDisconnect = (function (client) {
  _$jscoverage['socket.io/listener.js'][159]++;
  delete this.clients[client.sessionId];
  _$jscoverage['socket.io/listener.js'][160]++;
  this.options.log("Client " + client.sessionId + " disconnected");
  _$jscoverage['socket.io/listener.js'][161]++;
  this.emit("clientDisconnect", client);
});
_$jscoverage['socket.io/listener.js'][164]++;
Listener.prototype._onConnection = (function (transport, req, res, httpUpgrade, head) {
  _$jscoverage['socket.io/listener.js'][165]++;
  this.options.log("Initializing client with transport \"" + transport + "\"");
  _$jscoverage['socket.io/listener.js'][166]++;
  new transports[transport](this, req, res, this.options.transportOptions[transport], head);
});
_$jscoverage['socket.io/listener.js'].source = ["var url = require('url')","  , sys = require('sys')","  , fs = require('fs')","  , options = require('./utils').options","  , Client = require('./client')","  , clientVersion = require('./../../support/socket.io-client/lib/io').io.version","  , transports = {","      'flashsocket': require('./transports/flashsocket')","    , 'htmlfile': require('./transports/htmlfile')","    , 'websocket': require('./transports/websocket')","    , 'xhr-multipart': require('./transports/xhr-multipart')","    , 'xhr-polling': require('./transports/xhr-polling')","    , 'jsonp-polling': require('./transports/jsonp-polling')","    };","","var Listener = module.exports = function(server, options){","  process.EventEmitter.call(this);","  var self = this;","  this.server = server;","  this.options({","    origins: '*:*',","    resource: 'socket.io',","    flashPolicyServer: true,","    transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling'],","    transportOptions: {},","    log: sys.log","  }, options);","  ","  if (!this.options.log) this.options.log = function(){};","","  this.clients = this.clientsIndex = {};","  this._clientFiles = {};","  ","  var listeners = this.server.listeners('request');","  this.server.removeAllListeners('request');","  ","  this.server.addListener('request', function(req, res){","    if (self.check(req, res)) return;","    for (var i = 0, len = listeners.length; i &lt; len; i++){","      listeners[i].call(this, req, res);","    }","  });","  ","  this.server.addListener('upgrade', function(req, socket, head){","    if (!self.check(req, socket, true, head)){","      socket.end();","      socket.destroy();","    }","  });","  ","  for (var i in transports)","    if ('init' in transports[i]) transports[i].init(this);","  ","  this.options.log('socket.io ready - accepting connections');","};","","sys.inherits(Listener, process.EventEmitter);","for (var i in options) Listener.prototype[i] = options[i];","","Listener.prototype.broadcast = function(message, except){","  for (var i = 0, k = Object.keys(this.clients), l = k.length; i &lt; l; i++){","    if (this.clients[k[i]] &amp;&amp; (!except || [].concat(except).indexOf(this.clients[k[i]].sessionId) == -1)){","      this.clients[k[i]].send(message);","    }","  }","  return this;","};","","Listener.prototype.check = function(req, res, httpUpgrade, head){","  var path = url.parse(req.url).pathname, parts, cn;","  if (path &amp;&amp; path.indexOf('/' + this.options.resource) === 0){","    parts = path.substr(1).split('/');","    if (this._serveClient(parts.slice(1).join('/'), req, res)) return true;","    if (!(parts[1] in transports)) return false;","    if (parts[2]){","      cn = this.clients[parts[2]];","      if (cn){","        cn._onConnect(req, res);","      } else {","        req.connection.end();","        req.connection.destroy();","        this.options.log('Couldnt find client with session id \"' + parts[2] + '\"');","      }","    } else {","      this._onConnection(parts[1], req, res, httpUpgrade, head);","    }","    return true;","  }","  return false;","};","","Listener.prototype._serveClient = function(file, req, res){","  var self = this","    , clientPaths = {","        'socket.io.js': 'socket.io.js',","        'lib/vendor/web-socket-js/WebSocketMain.swf': 'lib/vendor/web-socket-js/WebSocketMain.swf', // for compat with old clients","        'WebSocketMain.swf': 'lib/vendor/web-socket-js/WebSocketMain.swf'","      }","    , types = {","        swf: 'application/x-shockwave-flash',","        js: 'text/javascript'","      };","  ","  function write(path){","    if (req.headers['if-none-match'] == clientVersion){","      res.writeHead(304);","      res.end();","    } else {","      res.writeHead(200, self._clientFiles[path].headers);","      res.end(self._clientFiles[path].content, self._clientFiles[path].encoding);","    }","  };","  ","  var path = clientPaths[file];","  ","  if (req.method == 'GET' &amp;&amp; path !== undefined){","    if (path in this._clientFiles){","      write(path);","      return true;","    }","    ","    fs.readFile(__dirname + '/../../support/socket.io-client/' + path, function(err, data){","      if (err){","        res.writeHead(404);","        res.end('404');","      } else {","        var ext = path.split('.').pop();","        self._clientFiles[path] = {","          headers: {","            'Content-Length': data.length,","            'Content-Type': types[ext],","            'ETag': clientVersion","          },","          content: data,","          encoding: ext == 'swf' ? 'binary' : 'utf8'","        };","        write(path);","      }","    });","    ","    return true;","  }","  ","  return false;","};","","Listener.prototype._onClientConnect = function(client){","  this.clients[client.sessionId] = client;","  this.options.log('Client '+ client.sessionId +' connected');","  this.emit('clientConnect', client);","  this.emit('connection', client);","};","","Listener.prototype._onClientMessage = function(data, client){","  this.emit('clientMessage', data, client);","};","","Listener.prototype._onClientDisconnect = function(client){","  delete this.clients[client.sessionId];","  this.options.log('Client '+ client.sessionId +' disconnected');","  this.emit('clientDisconnect', client);","};","","Listener.prototype._onConnection = function(transport, req, res, httpUpgrade, head){","  this.options.log('Initializing client with transport \"'+ transport +'\"');","  new transports[transport](this, req, res, this.options.transportOptions[transport], head);","};"];
