From 8acf7175668ce2e55434e3a91912ced1c9724375 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 20 Jul 2010 14:28:11 +0200 Subject: introduce new 'tcap_prim_buf' as union for dialg and component primitives --- src/tcap_test.c | 24 +++++++++++++++--------- src/tcap_user.h | 30 ++++++++++++++++++++---------- src/tcu.c | 47 ++++++++++++++++++++++++++++------------------- 3 files changed, 63 insertions(+), 38 deletions(-) diff --git a/src/tcap_test.c b/src/tcap_test.c index 86a8d96..5f94f48 100644 --- a/src/tcap_test.c +++ b/src/tcap_test.c @@ -111,7 +111,7 @@ static int send_begin(uint32_t dialg_id, struct tcap_obj_ident *app_ctx) return tcap_user_req_dialg(TCAP_PR_TC_BEGIN, &tcdi); } -int tcap_user_ind_dialg(enum tcap_primitive prim, struct tcap_dialg_ind *tcdi) +static int tcap_user_ind_dialg(enum tcap_primitive prim, struct tcap_dialg_ind *tcdi) { printf("-> USER_IND_DIALG(%s): ", tcap_prim_name(prim)); @@ -127,19 +127,15 @@ int tcap_user_ind_dialg(enum tcap_primitive prim, struct tcap_dialg_ind *tcdi) printf("\n"); - talloc_free(tcdi); - return 0; } -int tcap_user_ind_comp(enum tcap_primitive prim, struct tcap_component_ind *tcci) +static int tcap_user_ind_comp(enum tcap_primitive prim, struct tcap_component_ind *tcci) { printf("-> USER_IND_COMP(%s)\n", tcap_prim_name(prim)); - if (!test_state.begin_rcvd) { - talloc_free(tcci); + if (!test_state.begin_rcvd) return -1; - } switch (prim) { case TCAP_PR_TC_INVOKE: @@ -152,11 +148,21 @@ int tcap_user_ind_comp(enum tcap_primitive prim, struct tcap_component_ind *tcci break; } - talloc_free(tcci); - return 0; } +int tcap_user_ind_cb(struct tcap_prim_buf *tcpb) +{ + int rc; + + if (tcpb->prim > _TCAP_PR_COMP_BASE) + rc = tcap_user_ind_comp(tcpb->prim, &tcpb->comp); + else + rc = tcap_user_ind_dialg(tcpb->prim, &tcpb->dialg); + + talloc_free(tcpb); +} + static void signal_handler(int signal) { switch (signal) { diff --git a/src/tcap_user.h b/src/tcap_user.h index b396384..3f25b4a 100644 --- a/src/tcap_user.h +++ b/src/tcap_user.h @@ -74,9 +74,6 @@ extern struct tcap_transport_entity *tcap_transp_udp_create(struct sockaddr_stor /* metadata associated with a dialogue indication primitive */ struct tcap_dialg_ind { - /* Dummy list head structure for the user. libosmo-tcap doesn't use it */ - struct llist_head list; - /* Dialogue ID to which this primitive relates */ uint32_t dialg_id; /* Reference to the user-provided TCAP transport entity */ @@ -95,8 +92,6 @@ struct tcap_dialg_ind { /* metadata associated with a component indication primitive */ struct tcap_component_ind { - /* Dummy list head structure for the user. libosmo-tcap doesn't use it */ - struct llist_head list; /* public */ uint32_t dialg_id; /* Dialogue ID */ int8_t invoke_id; /* Invoke ID */ @@ -127,10 +122,9 @@ struct tcap_component_ind { }; }; -struct scxp_entity; - enum tcap_primitive { /* dialogue handling primitives */ + _TCAP_PR_DIALG_BASE = 0, TCAP_PR_TC_UNI, TCAP_PR_TC_BEGIN, TCAP_PR_TC_CONTINUE, @@ -138,6 +132,7 @@ enum tcap_primitive { TCAP_PR_TC_U_ABORT, TCAP_PR_TC_NOTICE, /* component handling primitives */ + _TCAP_PR_COMP_BASE = 10, TCAP_PR_TC_INVOKE, TCAP_PR_TC_RESULT_L, TCAP_PR_TC_RESULT_NL, @@ -150,13 +145,28 @@ enum tcap_primitive { TCAP_PR_TC_P_ABORT, }; +/* primitive structure to pass primitives between TCAP-User and TCAP Layer */ +struct tcap_prim_buf { + /* Dummy list head structure for the user. libosmo-tcap doesn't use it */ + struct llist_head list; + + /* The actual primitive number */ + enum tcap_primitive prim; + union { + struct tcap_dialg_ind dialg; + struct tcap_component_ind comp; + }; +}; + +struct scxp_entity; + const char *tcap_prim_name(enum tcap_primitive prim); /* callbacks to application code regarding various INDICATIONs */ -extern int tcap_user_ind_comp(enum tcap_primitive prim, struct tcap_component_ind *tcci); -extern int tcap_user_ind_dialg(enum tcap_primitive prim, struct tcap_dialg_ind *tcdi); - +extern int tcap_user_ind_cb(struct tcap_prim_buf *tcpb); +/* application wants to issue a REQUEST type primitive */ +extern int tcap_user_req(struct tcap_prim_buf *tcpb); extern int tcap_user_req_comp(enum tcap_primitive prim, struct tcap_component_ind *tcci); extern int tcap_user_req_dialg(enum tcap_primitive prim, struct tcap_dialg_ind *tcdi); diff --git a/src/tcu.c b/src/tcu.c index 584644f..e736d42 100644 --- a/src/tcu.c +++ b/src/tcu.c @@ -60,17 +60,22 @@ LIB_EXPORTED const char *tcap_prim_name(enum tcap_primitive prim) return get_value_string(tcap_prim_names, prim); } +static struct tcap_prim_buf *tcap_prim_buf_alloc(enum tcap_primitive prim) +{ + struct tcap_prim_buf *tcpb = talloc_zero(tcap_ind_ctx, + struct tcap_prim_buf); + if (!tcpb) + return NULL; + + tcpb->prim = prim; + + return tcpb; +} + /***********************************************************************/ /* Dialogue Primitives */ /***********************************************************************/ -static struct tcap_dialg_ind *tcap_dialg_ind_alloc(void) -{ - struct tcap_dialg_ind *tcdi = talloc_zero(tcap_ind_ctx, - struct tcap_dialg_ind); - return tcdi; -} - /* fill the application context and user information part of 'tcap_dialg_ind' */ static int fill_tcap_dialg_ind(struct tcap_dialg_ind *tcdi, OBJECT_IDENTIFIER_t *app_ctx_name, @@ -109,7 +114,8 @@ static int _tcap_tcu_dialg_ind(enum tcap_primitive prim, struct tcap_dialogue *t OBJECT_IDENTIFIER_t *app_ctx_name, struct user_information *user_info, int comp_present) { - struct tcap_dialg_ind *tcdi = tcap_dialg_ind_alloc(); + struct tcap_prim_buf *tcpb = tcap_prim_buf_alloc(prim); + struct tcap_dialg_ind *tcdi = &tcpb->dialg; int rc; if (!tcdi) @@ -125,7 +131,7 @@ static int _tcap_tcu_dialg_ind(enum tcap_primitive prim, struct tcap_dialogue *t if (comp_present) tcdi->components_present = 1; - return tcap_user_ind_dialg(prim, tcdi); + return tcap_user_ind_cb(tcpb); } /* TC-BEGIN.ind from DHA */ @@ -234,17 +240,11 @@ LIB_EXPORTED int tcap_user_req_dialg(enum tcap_primitive prim, struct tcap_dialg /* Component Primitives */ /***********************************************************************/ -static struct tcap_component_ind *tcap_comp_ind_alloc(void) -{ - struct tcap_component_ind *tcci = talloc_zero(tcap_ind_ctx, - struct tcap_component_ind); - return tcci; -} - static int _tcu_comp_ind(enum tcap_primitive prim, struct tcap_invocation *ti, struct OPERATION *oper, Parameter_t *param, int last) { - struct tcap_component_ind *tcci = tcap_comp_ind_alloc(); + struct tcap_prim_buf *tcpb = tcap_prim_buf_alloc(prim); + struct tcap_component_ind *tcci = &tcpb->comp; int rc; tcci->dialg_id = ti->dialogue->dialogue_id; @@ -281,10 +281,10 @@ static int _tcu_comp_ind(enum tcap_primitive prim, struct tcap_invocation *ti, s } tcci->last_component = last; - return tcap_user_ind_comp(prim, tcci); + return tcap_user_ind_cb(tcpb); out_free: - talloc_free(tcci); + talloc_free(tcpb); return rc; } @@ -422,3 +422,12 @@ LIB_EXPORTED int tcap_user_req_comp(enum tcap_primitive prim, struct tcap_compon return rc; } + +/* primitive received from TC-User */ +LIB_EXPORTED int tcap_user_req(struct tcap_prim_buf *tcpb) +{ + if (tcpb->prim > _TCAP_PR_COMP_BASE) + return tcap_user_req_comp(tcpb->prim, &tcpb->comp); + else + return tcap_user_req_dialg(tcpb->prim, &tcpb->dialg); +} -- cgit v1.2.3