[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/support/aphlict/server/lib/ -> AphlictFlashPolicyServer.js (source)

   1  var JX = require('javelin').JX;
   2  
   3  var net = require('net');
   4  
   5  /**
   6   * Server which handles cross-domain policy requests for Flash.
   7   *
   8   *   var server = new AphlictFlashPolicyServer()
   9   *     .setAccessPort(9999)
  10   *     .start();
  11   */
  12  JX.install('AphlictFlashPolicyServer', {
  13  
  14    members: {
  15      _server: null,
  16      _port: 843,
  17      _accessPort: null,
  18      _debug: null,
  19  
  20      setDebugLog: function(log) {
  21        this._debug = log;
  22        return this;
  23      },
  24  
  25      setAccessPort: function(port) {
  26        this._accessPort = port;
  27        return this;
  28      },
  29  
  30      start: function() {
  31        this._server = net.createServer(JX.bind(this, this._didConnect));
  32        this._server.listen(this._port);
  33        return this;
  34      },
  35  
  36      _didConnect: function(socket) {
  37        this._log('<FlashPolicy> Policy Request From %s', socket.remoteAddress);
  38  
  39        socket.on('error', JX.bind(this, this._didSocketError, socket));
  40  
  41        socket.write(this._getFlashPolicyResponse());
  42        socket.end();
  43      },
  44  
  45      _didSocketError: function(socket, error) {
  46        this._log('<FlashPolicy> Socket Error: %s', error);
  47      },
  48  
  49      _log: function() {
  50        this._debug && this._debug.log.apply(this._debug, arguments);
  51      },
  52  
  53      _getFlashPolicyResponse: function() {
  54        var policy = [
  55          '<?xml version="1.0"?>',
  56          '<!DOCTYPE cross-domain-policy SYSTEM ' +
  57            '"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">',
  58          '<cross-domain-policy>',
  59            '<allow-access-from domain="*" to-ports="' + this._accessPort + '"/>',
  60          '</cross-domain-policy>'
  61        ];
  62  
  63        return policy.join('\n') + '\0';
  64      }
  65  
  66    }
  67  
  68  });


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1