WIP: Read and write every copy of a TLV SMPP lets repeat, and drop the dormant tlvMap #26

Closed
lilleman wants to merge 3 commits from tlv-multiple into main
3 changed files with 10 additions and 3 deletions
Showing only changes of commit 9c83dd1d99 - Show all commits
+2 -1
View File
@@ -39,7 +39,8 @@
other limits. `server({ maxOctets: 0 })` used to start and then refuse every multipart message. other limits. `server({ maxOctets: 0 })` used to start and then refuse every multipart message.
- `callback_num`, `callback_num_atag`, `callback_num_pres_ind`, `broadcast_area_identifier` and - `callback_num`, `callback_num_atag`, `callback_num_pres_ind`, `broadcast_area_identifier` and
`broadcast_error_status` read as a list of every copy the peer sent, where only the last was kept, `broadcast_error_status` read as a list of every copy the peer sent, where only the last was kept,
and are written from a list. A single value for one of them, or a list for any other tag, is and are written from a list. A single value or an empty list for one of them, or a list for any
other tag, is
refused. refused.
- `tlvMap` is gone from the `broadcast_sm_resp` command definition. Nothing read it. - `tlvMap` is gone from the `broadcast_sm_resp` command definition. Nothing read it.
+5 -1
View File
@@ -135,7 +135,11 @@ export function tagIdOf(name: string, input: TlvInput): Result<{ tagId: number }
function copiesOf(name: string, definition: TlvDefinition | undefined, value: TlvValue): Result<{ copies: TlvScalar[] }> { function copiesOf(name: string, definition: TlvDefinition | undefined, value: TlvValue): Result<{ copies: TlvScalar[] }> {
const multiple = definition?.multiple === true; const multiple = definition?.multiple === true;
if (Array.isArray(value) && multiple) return { copies: value }; if (Array.isArray(value) && multiple) {
return value.length > 0
? { copies: value }
: { err: new Error(`TLV "${name}": give at least one value, or leave the tag out`) };
}
if (!Array.isArray(value) && !multiple) return { copies: [value] }; if (!Array.isArray(value) && !multiple) return { copies: [value] };
+3 -1
View File
@@ -432,16 +432,18 @@ describe('TLVs', () => {
assert.deepEqual(pduObj.tlvs.callback_num_pres_ind?.tagValue, [1]); assert.deepEqual(pduObj.tlvs.callback_num_pres_ind?.tagValue, [1]);
}); });
test('refuses a single value for a tag SMPP lets repeat, and a list for one it does not', () => { test('refuses a single value or an empty list for a tag SMPP lets repeat, and a list for one it does not', () => {
const params = { destination_addr: '46709771337', short_message: 'hi', source_addr: '46701113311' }; const params = { destination_addr: '46709771337', short_message: 'hi', source_addr: '46701113311' };
const single = objToPdu({ const single = objToPdu({
cmdName: 'submit_sm', cmdName: 'submit_sm',
params, params,
tlvs: { callback_num: { tagValue: Buffer.from('46701113311', 'latin1') } }, tlvs: { callback_num: { tagValue: Buffer.from('46701113311', 'latin1') } },
}); });
const empty = objToPdu({ cmdName: 'submit_sm', params, tlvs: { callback_num: { tagValue: [] } } });
const list = objToPdu({ cmdName: 'submit_sm', params, tlvs: { source_port: { tagValue: [1234] } } }); const list = objToPdu({ cmdName: 'submit_sm', params, tlvs: { source_port: { tagValue: [1234] } } });
assert.match(single.err?.message ?? '', /TLV "callback_num": .*list/); assert.match(single.err?.message ?? '', /TLV "callback_num": .*list/);
assert.match(empty.err?.message ?? '', /TLV "callback_num": .*leave the tag out/);
assert.match(list.err?.message ?? '', /TLV "source_port": .*list/); assert.match(list.err?.message ?? '', /TLV "source_port": .*list/);
}); });