return type of decoded inap arg

mprokop/packaging
Richard Fuchs 12 years ago
parent 87a8f10a89
commit cd9d536d92

@ -4,10 +4,11 @@
#include "TCMessage.h" #include "TCMessage.h"
#include "Invoke.h" #include "Invoke.h"
#include "constr_TYPE.h"
TCMessage_t *tcap_decode(const char *buf, size_t len); TCMessage_t *tcap_decode(const char *buf, size_t len);
void *inap_decode(Invoke_t *invoke); void *inap_decode(Invoke_t *invoke, asn_TYPE_descriptor_t **);
#endif #endif

@ -13,11 +13,20 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#define INVOKE_OPCODE_INITIALDP 0 #define INVOKE_OPCODE_INITIALDP 0
#define INVOKE_OPCODE_CONNECT 20 #define INVOKE_OPCODE_CONNECT 20
#define INVOKE_OPCODE_FURNISHCHARGINGINFORMATION 34 #define INVOKE_OPCODE_FURNISHCHARGINGINFORMATION 34
static asn_TYPE_descriptor_t *opcode_type_map[] = {
[INVOKE_OPCODE_INITIALDP] = &asn_DEF_InitialDPArg,
[INVOKE_OPCODE_CONNECT] = &asn_DEF_ConnectArg,
[INVOKE_OPCODE_FURNISHCHARGINGINFORMATION] = &asn_DEF_FurnishChargingInformationArg,
};
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;
@ -32,12 +41,12 @@ TCMessage_t *tcap_decode(const char *buf, size_t len) {
return NULL; return NULL;
} }
void *inap_decode(Invoke_t *invoke) { void *inap_decode(Invoke_t *invoke, asn_TYPE_descriptor_t **type) {
long opcode; long opcode;
int rv; int rv;
void *arg = 0; void *arg = 0;
if (!invoke || !invoke->parameter) if (!invoke || !invoke->parameter || !type)
goto nothing; goto nothing;
if (invoke->opCode.present != OPERATION_PR_localValue) if (invoke->opCode.present != OPERATION_PR_localValue)
@ -46,28 +55,20 @@ void *inap_decode(Invoke_t *invoke) {
if (asn_INTEGER2long(&invoke->opCode.choice.localValue, &opcode)) if (asn_INTEGER2long(&invoke->opCode.choice.localValue, &opcode))
goto nothing; goto nothing;
switch (opcode) { if (opcode >= ARRAY_SIZE(opcode_type_map))
case INVOKE_OPCODE_INITIALDP: goto nothing;
rv = ANY_to_type(invoke->parameter, &asn_DEF_InitialDPArg, &arg);
break;
case INVOKE_OPCODE_CONNECT:
rv = ANY_to_type(invoke->parameter, &asn_DEF_ConnectArg, &arg);
break;
case INVOKE_OPCODE_FURNISHCHARGINGINFORMATION: *type = opcode_type_map[opcode];
rv = ANY_to_type(invoke->parameter, &asn_DEF_FurnishChargingInformationArg, &arg);
break;
default: rv = ANY_to_type(invoke->parameter, *type, &arg);
goto nothing;
}
if (!rv) if (!rv)
return arg; return arg;
/* free struct */ if (arg)
(*type)->free_struct(*type, arg, 0);
nothing: nothing:
*type = NULL;
return NULL; return NULL;
} }

@ -15,6 +15,7 @@ int main() {
Component_t *component; Component_t *component;
int i; int i;
void *arg; void *arg;
asn_TYPE_descriptor_t *type;
tcm = tcap_decode(tcap, tcap_len); tcm = tcap_decode(tcap, tcap_len);
@ -65,8 +66,8 @@ int main() {
case Component_PR_invoke: case Component_PR_invoke:
printf("invoke\n"); printf("invoke\n");
arg = inap_decode(&component->choice.invoke); arg = inap_decode(&component->choice.invoke, &type);
printf("arg: %p\n", arg); printf("arg: type %s -> %p\n", type ? type->name : "n/a", arg);
break; break;
case Component_PR_returnResultLast: case Component_PR_returnResultLast:

Loading…
Cancel
Save