@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Break Aphlict's flash policy server into a separate class

Summary: Ref T4324. One of the server we start just sends pre-canned XML responses. Separate it out of the main file and hand it all the objects it interacts with in structured, reasonable ways.

Test Plan: Hit "Send Test Notification", saw notification, saw flash policy info in the log.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4324

Differential Revision: https://secure.phabricator.com/D8257

+74 -23
+6 -23
support/aphlict/server/aphlict_server.js
··· 8 8 9 9 var JX = require('./lib/javelin').JX; 10 10 11 + JX.require('lib/AphlictFlashPolicyServer', __dirname); 11 12 JX.require('lib/AphlictListenerList', __dirname); 12 13 JX.require('lib/AphlictLog', __dirname); 13 14 ··· 64 65 var url = require('url'); 65 66 var querystring = require('querystring'); 66 67 67 - 68 68 process.on('uncaughtException', function (err) { 69 - log("\n<<< UNCAUGHT EXCEPTION! >>>\n\n" + err); 69 + debug.log("\n<<< UNCAUGHT EXCEPTION! >>>\n\n" + err); 70 70 process.exit(1); 71 71 }); 72 72 73 - function getFlashPolicy() { 74 - return [ 75 - '<?xml version="1.0"?>', 76 - '<!DOCTYPE cross-domain-policy SYSTEM ' + 77 - '"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">', 78 - '<cross-domain-policy>', 79 - '<allow-access-from domain="*" to-ports="'+config.port+'"/>', 80 - '</cross-domain-policy>' 81 - ].join('\n'); 82 - } 83 - 84 - net.createServer(function(socket) { 85 - socket.write(getFlashPolicy() + '\0'); 86 - socket.end(); 87 - 88 - debug.log('[' + socket.remoteAddress + '] Sent Flash Policy'); 89 - 90 - socket.on('error', function (e) { 91 - debug.log('Error in policy server: ' + e); 92 - }); 93 - }).listen(843); 73 + var flash_server = new JX.AphlictFlashPolicyServer() 74 + .setDebugLog(debug) 75 + .setAccessPort(config.port) 76 + .start(); 94 77 95 78 96 79 var send_server = net.createServer(function(socket) {
+68
support/aphlict/server/lib/AphlictFlashPolicyServer.js
··· 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(pattern) { 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 + });