Compare View

switch
from
...
to
 
Commits (2)

Changes

Showing 3 changed files Side-by-side Diff

lib/http-listener.js
... ... @@ -13,12 +13,35 @@ const messagesArchive = require('./messages-archive');
13 13 const app = express();
14 14 const port = config && config.listener && config.listener.http && config.listener.http.port ? config.listener.http.port : 32979;
15 15  
  16 +/**
  17 + * Handler utama.
  18 + *
  19 + * @param {object} req - Express request object
  20 + * @param {object} req.query - Express query string object
  21 + * @param {string} [req.query.partner] - Partner (pengirim atau penerima)
  22 + * @param {string} [req.query.from] - Pengirim, OBSOLETED: gunakan parameter partner
  23 + * @param {string} [req.query.from_raw] - Pengirim tanpa suffix (raw), OBSOLETED: gunakan parameter partner_raw
  24 + * @param {string} [req.query.to] - Tujuan, jika is_outgoing, OBSOLETED: gunakan parameter partner
  25 + * @param {string} req.query.msg - Isi pesan
  26 + * @param {string} req.query.origin - Nama origin
  27 + * @param {string} [req.query.origin_label] - Nama origin untuk ditulis di histori pesan
  28 + * @param {string} [req.query.do_not_forward_to_core] - Apakah teruskan pesan ke CORE
  29 + * @param {string} [req.query.is_outgoing] - Apakah pesan keluar
  30 + * @param {object} res - Express response object
  31 + */
16 32 function mainHandler(req, res) {
17   -
18 33 if (!req.body) req.body = {};
19 34  
20   - if (!req.query.from && !req.body.from) {
21   - res.end('ERROR. Undefined parameter: from');
  35 + if (
  36 + ( !req.body.partner || !req.query.partner )
  37 + &&
  38 + (
  39 + ( (!req.query.is_outgoing && !req.body.is_outgoing) && (!req.query.from && !req.body.from) )
  40 + ||
  41 + ( (req.query.is_outgoing || req.body.is_outgoing) && (!req.query.to && !req.body.to) )
  42 + )
  43 + ) {
  44 + res.end('ERROR. Undefined parameter: partner or from or to');
22 45 return;
23 46 }
24 47  
... ... @@ -31,13 +54,13 @@ function mainHandler(req, res) {
31 54 {
32 55 origin_label: req.body.origin_label || req.query.origin_label || req.body.origin || req.query.origin,
33 56 origin_transport: req.body.origin_transport || req.query.origin_transport,
34   - partner: req.body.from_raw || req.query.from_raw || req.body.from || req.query.from,
  57 + partner: req.body.partner_raw || req.query.partner_raw || req.body.from_raw || req.query.from_raw || req.body.from || req.query.from || req.body.to || req.query.to || req.body.partner || req.query.partner,
35 58 msg: req.body.msg || req.query.msg,
36 59 },
37   - messagesArchive.DIRECTION_INCOMING
  60 + ( req.body.is_outgoing || req.query.is_outgoing ) ? messagesArchive.DIRECTION_OUTGOING : messagesArchive.DIRECTION_INCOMING
38 61 );
39 62  
40   - if (req.body.do_not_forward_to_core || req.query.do_not_forward_to_core) {
  63 + if (req.body.do_not_forward_to_core || req.query.do_not_forward_to_core || req.body.is_outgoing || req.query.is_outgoing) {
41 64 logger.verbose('Ignoring message', { from: req.body.from || req.query.from, msg: req.body.msg || req.query.msg, do_not_forward_to_core: req.body.do_not_forward_to_core || req.query.do_not_forward_to_core });
42 65 res.end('OK');
43 66 return;
... ... @@ -52,7 +75,7 @@ function mainHandler(req, res) {
52 75 origin: req.body.origin || req.query.origin || 'MESSAGING',
53 76 report_ip: req.body.report_ip || req.query.report_ip || req.ip,
54 77 report_port: req.body.report_port || req.query.report_port,
55   - from: req.body.from || req.query.from,
  78 + from: req.body.partner || req.query.partner || req.body.from || req.query.from,
56 79 msg: req.body.msg || req.query.msg
57 80 }
58 81  
1 1 {
2 2 "name": "komodo-center-messaging",
3   - "version": "0.9.11",
  3 + "version": "0.9.12",
4 4 "lockfileVersion": 1,
5 5 "requires": true,
6 6 "dependencies": {
1 1 {
2 2 "name": "komodo-center-messaging",
3   - "version": "0.9.11",
  3 + "version": "0.9.12",
4 4 "description": "Komodo Common Messaging Center",
5 5 "main": "index.js",
6 6 "scripts": {