Implement response processors
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {PDU} from "../CommonObjects";
|
||||
import Logger from "../Logger";
|
||||
import SmppSession from "../SmppSession";
|
||||
|
||||
export default abstract class PduProcessor {
|
||||
readonly abstract type: string
|
||||
@@ -11,7 +11,7 @@ export default abstract class PduProcessor {
|
||||
this.sessionType = type;
|
||||
}
|
||||
|
||||
abstract processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any>;
|
||||
abstract processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any>;
|
||||
|
||||
serialize(): object {
|
||||
return {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import Center from "../../../Center/Center";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
const smpp = require("smpp");
|
||||
|
||||
export default class BindTranscieverReplyProcessor extends Postprocessor {
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: any, entity?: Center | undefined): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!!pdu.command && pdu.command === 'bind_transceiver') {
|
||||
if (!entity) {
|
||||
reject();
|
||||
}
|
||||
|
||||
this.logger.log1(`Center-${entity?.id} got a bind_transciever with system_id ${pdu.system_id} and password ${pdu.password}`);
|
||||
session.pause();
|
||||
if (pdu.system_id === entity?.username && pdu.password === entity?.password) {
|
||||
this.logger.log1(`Center-${entity?.id} client connection successful`);
|
||||
if (pdu.response) {
|
||||
session.send(pdu.response());
|
||||
}
|
||||
session.resume();
|
||||
// @ts-ignore
|
||||
entity?.pendingSessions = entity?.pendingSessions.filter((s) => s !== session);
|
||||
entity?.sessions.push(session);
|
||||
entity?.updateStatus();
|
||||
} else {
|
||||
this.logger.log1(`Center-${entity?.id} client connection failed, invalid credentials (expected: ${entity?.username}, ${entity?.password})`);
|
||||
if (pdu.response) {
|
||||
session.send(pdu.response({
|
||||
command_status: smpp.ESME_RBINDFAIL
|
||||
}));
|
||||
}
|
||||
// @ts-ignore
|
||||
entity?.pendingSessions = entity?.pendingSessions.filter((s) => s !== session);
|
||||
entity?.updateStatus();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
export default class DebugPduProcessor extends Postprocessor {
|
||||
@@ -6,7 +6,7 @@ export default class DebugPduProcessor extends Postprocessor {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (pdu.response) {
|
||||
session.send(pdu.response(), (replyPdu: any) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
const smpp = require("smpp");
|
||||
@@ -8,7 +8,7 @@ export default class EchoPduProcessor extends Postprocessor {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
let promises = [];
|
||||
if (pdu.response) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
export default class SubmitSmReplyProcessor extends Postprocessor {
|
||||
constructor(type: string) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!!pdu.command && pdu.command === 'submit_sm') {
|
||||
session.send(pdu.response());
|
||||
resolve(pdu);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Postprocessor from "../Postprocessor";
|
||||
|
||||
export default class DeliverSmReplyProcessor extends Postprocessor {
|
||||
@@ -6,11 +6,11 @@ export default class DeliverSmReplyProcessor extends Postprocessor {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!!pdu.command && pdu.command === 'deliver_sm') {
|
||||
// @ts-ignore
|
||||
session.send(pdu.response());
|
||||
resolve(pdu);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Preprocessor from "../Preprocessor";
|
||||
|
||||
export default class DestinationEnumeratorProcessor extends Preprocessor {
|
||||
@@ -7,7 +7,7 @@ export default class DestinationEnumeratorProcessor extends Preprocessor {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (!!pdu.destination_addr) {
|
||||
pdu.destination_addr = pdu.destination_addr + this.padLeft(String(this.iterator++), '0', 5);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {PDU} from "../../../CommonObjects";
|
||||
import SmppSession from "../../../SmppSession";
|
||||
import Preprocessor from "../Preprocessor";
|
||||
|
||||
export default class SourceEnumeratorProcessor extends Preprocessor {
|
||||
@@ -7,7 +7,7 @@ export default class SourceEnumeratorProcessor extends Preprocessor {
|
||||
super(type);
|
||||
}
|
||||
|
||||
processPdu(session: any, pdu: PDU, ...args: any[]): Promise<any> {
|
||||
processPdu(session: any, pdu: any, entity?: SmppSession | undefined): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
if (!!pdu.source_addr) {
|
||||
pdu.source_addr = pdu.source_addr + this.padLeft(String(this.iterator++), '0', 5);
|
||||
|
||||
@@ -3,8 +3,10 @@ import Client from "../Client/Client";
|
||||
import Logger from "../Logger";
|
||||
import SmppSession from "../SmppSession";
|
||||
import PduProcessor from "./PduProcessor";
|
||||
import BindTranscieverReplyProcessor from "./Postprocessor/Center/BindTranscieverReplyProcessor";
|
||||
import DebugPduProcessor from "./Postprocessor/Center/DebugPduProcessor";
|
||||
import EchoPduProcessor from "./Postprocessor/Center/EchoPduProcessor";
|
||||
import SubmitSmReplyProcessor from "./Postprocessor/Center/SubmitSmReplyProcessor";
|
||||
import DeliverSmReplyProcessor from "./Postprocessor/Client/DeliverSmReplyProcessor";
|
||||
import Postprocessor from "./Postprocessor/Postprocessor";
|
||||
import DestinationEnumeratorProcessor from "./Preprocessor/Client/DestinationEnumeratorProcessor";
|
||||
@@ -26,7 +28,9 @@ export default class ProcessorManager {
|
||||
ProcessorManager.postprocessors = [
|
||||
new DebugPduProcessor(Center.name),
|
||||
new EchoPduProcessor(Center.name),
|
||||
new DeliverSmReplyProcessor(Center.name),
|
||||
new DeliverSmReplyProcessor(Client.name),
|
||||
new SubmitSmReplyProcessor(Center.name),
|
||||
new BindTranscieverReplyProcessor(Center.name)
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user