TT#111150 Add new tcap_encode_with_routing() function

Refactor this function from the test case, and from the lnpd mock-test
implementation. This will make it possible to stop exposing ASN1C
internals as part of the public interface, as we do not have any control
over the API/ABI and means we cannot update to newer ASN1C versions w/o
continuously bumping the SONAME.

Change-Id: I6fa0a0e6b4360bebcd4a19c0e38be09cfdee1f2b
coverity_scan
Guillem Jover 4 years ago
parent 47005812e5
commit 8d9d957721

@ -1,6 +1,8 @@
#ifndef _LIBTCAP_H_ #ifndef _LIBTCAP_H_
#define _LIBTCAP_H_ #define _LIBTCAP_H_
#include <stddef.h>
#include <stdint.h>
#include "TCMessage.h" #include "TCMessage.h"
#include "Invoke.h" #include "Invoke.h"
@ -19,6 +21,7 @@ static inline void output_buffer_init(struct output_buffer *o, char *i, size_t s
o->used = 0; o->used = 0;
} }
int tcap_encode_with_routing(char **out, const uint8_t *routing, size_t routing_len);
TCMessage_t *tcap_decode(const char *buf, size_t len); TCMessage_t *tcap_decode(const char *buf, size_t len);

@ -9,14 +9,15 @@
#include "asn_SEQUENCE_OF.h" #include "asn_SEQUENCE_OF.h"
#include "constr_CHOICE.h" #include "constr_CHOICE.h"
#include "TCMessage.h" #include "CalledPartyNumber.h"
#include "Invoke.h" #include "Component.h"
#include "InitialDPArg.h" #include "ComponentPortion.h"
#include "ConnectArg.h" #include "ConnectArg.h"
#include "FurnishChargingInformationArg.h" #include "FurnishChargingInformationArg.h"
#include "INTEGER.h" #include "INTEGER.h"
#include "ComponentPortion.h" #include "InitialDPArg.h"
#include "Component.h" #include "Invoke.h"
#include "TCMessage.h"
@ -70,6 +71,53 @@ int tcap_encode(char **out, TCMessage_t *msg) {
return len; return len;
} }
int tcap_encode_with_routing(char **out, const uint8_t *routing, size_t routing_len) {
int ret;
TCMessage_t msg;
ComponentPortion_t cp;
Component_t *cmp_arr;
Component_t cmp;
ConnectArg_t ca;
CalledPartyNumber_t *cpn_arr;
CalledPartyNumber_t cpn;
// init first
memset(&msg, 0, sizeof(msg));
memset(&cp, 0, sizeof(cp));
memset(&cmp, 0, sizeof(cmp));
memset(&ca, 0, sizeof(ca));
memset(&cpn, 0, sizeof(cpn));
cpn.buf = (uint8_t *)routing;
cpn.size = routing_len;
// fill structs
msg.present = TCMessage_PR_begin;
msg.choice.begin.components = &cp;
cmp_arr = &cmp;
cp.list.count = 1;
cp.list.array = &cmp_arr;
cmp.present = Component_PR_invoke;
cmp.choice.invoke.opCode.present = OPERATION_PR_localValue;
asn_long2INTEGER(&cmp.choice.invoke.opCode.choice.localValue, 20); // connect
cpn_arr = &cpn;
ca.destinationRoutingAddress.list.count = 1;
ca.destinationRoutingAddress.list.array = &cpn_arr;
cmp.choice.invoke.parameter = ANY_new_fromType(&asn_DEF_ConnectArg, &ca);
ret = tcap_encode(out, &msg);
asn_DEF_ANY.free_struct(&asn_DEF_ANY, cmp.choice.invoke.parameter, 0);
//asn_DEF_INTEGER.free_struct(&asn_DEF_INTEGER, &cmp.choice.invoke.opCode.choice.localValue, 0);
free(cmp.choice.invoke.opCode.choice.localValue.buf);
return ret;
}
TCMessage_t *tcap_decode(const char *buf, size_t len) { TCMessage_t *tcap_decode(const char *buf, size_t len) {
TCMessage_t *ret = NULL; TCMessage_t *ret = NULL;
asn_dec_rval_t rv; asn_dec_rval_t rv;

@ -11,50 +11,17 @@
int main() { int main() {
char *buf; char *buf;
int ret; int ret;
TCMessage_t msg; const uint8_t number[] = "1234567890";
ComponentPortion_t cp;
Component_t *cmp_arr;
Component_t cmp;
ConnectArg_t ca;
CalledPartyNumber_t *cpn_arr;
CalledPartyNumber_t cpn;
memset(&msg, 0, sizeof(msg)); ret = tcap_encode_with_routing(&buf, number, sizeof(number) - 1);
memset(&cp, 0, sizeof(cp));
memset(&cmp, 0, sizeof(cmp));
memset(&ca, 0, sizeof(ca));
memset(&cpn, 0, sizeof(cpn));
msg.present = TCMessage_PR_begin;
msg.choice.begin.components = &cp;
cp.list.count = 1;
cmp_arr = &cmp;
cp.list.array = &cmp_arr;
cmp.present = Component_PR_invoke;
cmp.choice.invoke.opCode.present = OPERATION_PR_localValue;
asn_long2INTEGER(&cmp.choice.invoke.opCode.choice.localValue, 20); // connect
ca.destinationRoutingAddress.list.count = 1;
cpn_arr = &cpn;
ca.destinationRoutingAddress.list.array = &cpn_arr;
cpn.buf = (void *) "1234567890";
cpn.size = 10;
cmp.choice.invoke.parameter = ANY_new_fromType(&asn_DEF_ConnectArg, &ca);
ret = tcap_encode(&buf, &msg);
fprintf(stderr, "ret: %i\n", ret); fprintf(stderr, "ret: %i\n", ret);
if(ret < 0) { if (ret < 0) {
fprintf(stderr, "failed to encode tcap\n"); fprintf(stderr, "failed to encode tcap\n");
} else { } else {
fwrite(buf, ret, 1, stdout); fwrite(buf, ret, 1, stdout);
} }
free(buf); free(buf);
asn_DEF_ANY.free_struct(&asn_DEF_ANY, cmp.choice.invoke.parameter, 0);
return 0; return 0;
} }

Loading…
Cancel
Save