Further work with making the server actually work
This commit is contained in:
+23
-20
@@ -296,18 +296,20 @@ function pduReturn(pdu, status, callback) {
|
|||||||
status = 'ESME_ROK';
|
status = 'ESME_ROK';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defs.errors[status] === undefined) {
|
if (pdu === undefined || pdu.errors === undefined || pdu.cmdName === undefined || pdu.seqNr === undefined) {
|
||||||
err = new Error('larvitsmpp: pduReturn() - Invalid status');
|
err = new Error('larvitsmpp: pduReturn() - Invalid call PDU, cannot create response PDU');
|
||||||
log.warn(err.message);
|
|
||||||
|
|
||||||
callback(err);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defs.cmds[pdu.cmdName + '_resp'] === undefined) {
|
if (err === null && defs.errors[status] === undefined) {
|
||||||
err = new Error('larvitsmpp: pduReturn() - This command does not have a response listed. Given command: "' + pdu.cmdName + '"');
|
err = new Error('larvitsmpp: pduReturn() - Invalid status');
|
||||||
log.warn(err.message);
|
}
|
||||||
|
|
||||||
|
if (err === null && defs.cmds[pdu.cmdName + '_resp'] === undefined) {
|
||||||
|
err = new Error('larvitsmpp: pduReturn() - This command does not have a response listed. Given command: "' + pdu.cmdName + '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err !== null) {
|
||||||
|
log.warn(err.message);
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -349,11 +351,9 @@ function session(sock, options, callback) {
|
|||||||
var data,
|
var data,
|
||||||
respPdu;
|
respPdu;
|
||||||
|
|
||||||
// Try to parse the incoming PDU
|
pduToObj(pdu, function(err, data) {
|
||||||
try {
|
if (err) {
|
||||||
data = pduToObj(pdu);
|
log.warn('larvitsmpp: session() - Invalid PDU. ' + err.message);
|
||||||
} catch(e) {
|
|
||||||
log.warn('larvitsmpp: session() - Invalid PDU. ' + e.message);
|
|
||||||
|
|
||||||
pduReturn(data, 'ESME_RUNKNOWNERR', function(err, retPdu) {
|
pduReturn(data, 'ESME_RUNKNOWNERR', function(err, retPdu) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -366,22 +366,18 @@ function session(sock, options, callback) {
|
|||||||
sock.destroy();
|
sock.destroy();
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (loggedIn === false) {
|
if (loggedIn === false) {
|
||||||
// Only bind_* is accepted when the client is not logged in
|
// Only bind_* is accepted when the client is not logged in
|
||||||
|
|
||||||
if (data.cmdName !== 'bind_transceiver' && data.cmdName !== 'bind_receiver' && data.cmdName !== 'bind_transmitter') {
|
if (data.cmdName !== 'bind_transceiver' && data.cmdName !== 'bind_receiver' && data.cmdName !== 'bind_transmitter') {
|
||||||
pduReturn(data, 'ESME_RINVBNDSTS', function(err, retPdu) {
|
pduReturn(data, 'ESME_RINVBNDSTS', function(err, retPdu) {
|
||||||
|
|
||||||
})
|
});
|
||||||
sock.write(pduReturn(data, 'ESME_RINVBNDSTS'))
|
sock.write(pduReturn(data, 'ESME_RINVBNDSTS'))
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Pass the data along to the sessionEmitter
|
// Pass the data along to the sessionEmitter
|
||||||
//sessionEmitter.emit('data', data);
|
//sessionEmitter.emit('data', data);
|
||||||
@@ -394,6 +390,13 @@ function session(sock, options, callback) {
|
|||||||
console.log('DATA ' + sock.remoteAddress + ': ' + data);
|
console.log('DATA ' + sock.remoteAddress + ': ' + data);
|
||||||
// Write the data back to the socket, the client will receive it as data from the server
|
// Write the data back to the socket, the client will receive it as data from the server
|
||||||
sock.write('You said "' + data + '"');
|
sock.write('You said "' + data + '"');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add a 'close' event handler to this instance of socket
|
// Add a 'close' event handler to this instance of socket
|
||||||
|
|||||||
Reference in New Issue
Block a user