From d5d69dddac3e4652016462ded332beb09a4b69f8 Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Wed, 17 Mar 2010 17:47:53 +0000 Subject: [PATCH] Miscellaneous simple reorganization. 1) Make PRI_MASTER() no longer check for a NULL parameter. It is the caller's responsibility. Not many callers could have passed a NULL without crashing before or after anyway. 2) Replace calls to q931_is_ptmp() with PTMP_MODE(). They were equivalent. 3) Made the following boolean config options bit fields: sendfacility, overlapdial, chan_mapping_logical, and service_message_support. git-svn-id: https://origsvn.digium.com/svn/libpri/branches/1.4@1534 2fbb986a-6c06-0410-b554-c9c1f0a7f128 --- pri.c | 29 ++++++---- pri_facility.c | 4 +- pri_internal.h | 148 ++++++++++++++++++++++++++++++++----------------- q921.c | 3 +- q931.c | 24 ++------ 5 files changed, 121 insertions(+), 87 deletions(-) diff --git a/pri.c b/pri.c index a3fc133..adb5f89 100644 --- a/pri.c +++ b/pri.c @@ -194,7 +194,7 @@ int pri_set_service_message_support(struct pri *pri, int supportflag) if (!pri) { return -1; } - pri->service_message_support = supportflag; + pri->service_message_support = supportflag ? 1 : 0; return 0; } @@ -776,7 +776,7 @@ int pri_connected_line_update(struct pri *ctrl, q931_call *call, const struct pr switch (ctrl->switchtype) { case PRI_SWITCH_EUROISDN_E1: case PRI_SWITCH_EUROISDN_T1: - if (q931_is_ptmp(ctrl)) { + if (PTMP_MODE(ctrl)) { /* PTMP mode */ q931_notify_redirection(ctrl, call, PRI_NOTIFY_TRANSFER_ACTIVE, &call->local_id.number); @@ -867,7 +867,7 @@ int pri_redirecting_update(struct pri *ctrl, q931_call *call, const struct pri_p switch (ctrl->switchtype) { case PRI_SWITCH_EUROISDN_E1: case PRI_SWITCH_EUROISDN_T1: - if (q931_is_ptmp(ctrl)) { + if (PTMP_MODE(ctrl)) { /* PTMP mode */ q931_notify_redirection(ctrl, call, PRI_NOTIFY_CALL_DIVERTING, &call->redirecting.to.number); @@ -1161,7 +1161,9 @@ void pri_message(struct pri *ctrl, const char *fmt, ...) int added_length; va_list ap; - ctrl = PRI_MASTER(ctrl); + if (ctrl) { + ctrl = PRI_MASTER(ctrl); + } if (!ctrl || !ctrl->msg_line) { /* Just have to do it the old way. */ va_start(ap, fmt); @@ -1223,7 +1225,7 @@ void pri_error(struct pri *pri, const char *fmt, ...) vsnprintf(tmp, sizeof(tmp), fmt, ap); va_end(ap); if (__pri_error) - __pri_error(PRI_MASTER(pri), tmp); + __pri_error(pri ? PRI_MASTER(pri) : NULL, tmp); else fputs(tmp, stderr); } @@ -1231,18 +1233,23 @@ void pri_error(struct pri *pri, const char *fmt, ...) /* Set overlap mode */ void pri_set_overlapdial(struct pri *pri,int state) { - pri->overlapdial = state; + if (pri) { + pri->overlapdial = state ? 1 : 0; + } } void pri_set_chan_mapping_logical(struct pri *pri, int state) { - if (pri->switchtype == PRI_SWITCH_QSIG) - pri->chan_mapping_logical = state; + if (pri && pri->switchtype == PRI_SWITCH_QSIG) { + pri->chan_mapping_logical = state ? 1 : 0; + } } void pri_set_inbanddisconnect(struct pri *pri, unsigned int enable) { - pri->acceptinbanddisconnect = (enable != 0); + if (pri) { + pri->acceptinbanddisconnect = (enable != 0); + } } int pri_fd(struct pri *pri) @@ -1494,8 +1501,8 @@ void pri_sr_set_keypad_digits(struct pri_sr *sr, const char *keypad_digits) void pri_hold_enable(struct pri *ctrl, int enable) { - ctrl = PRI_MASTER(ctrl); if (ctrl) { + ctrl = PRI_MASTER(ctrl); ctrl->hold_support = enable ? 1 : 0; } } @@ -1558,8 +1565,8 @@ int pri_callrerouting_facility(struct pri *pri, q931_call *call, const char *des void pri_reroute_enable(struct pri *ctrl, int enable) { - ctrl = PRI_MASTER(ctrl); if (ctrl) { + ctrl = PRI_MASTER(ctrl); ctrl->deflection_support = enable ? 1 : 0; } } diff --git a/pri_facility.c b/pri_facility.c index 9a8e2ce..1539d19 100644 --- a/pri_facility.c +++ b/pri_facility.c @@ -2072,7 +2072,7 @@ static int rose_reroute_request_encode(struct pri *ctrl, q931_call *call, switch (ctrl->switchtype) { case PRI_SWITCH_EUROISDN_E1: case PRI_SWITCH_EUROISDN_T1: - if (q931_is_ptmp(ctrl)) { + if (PTMP_MODE(ctrl)) { end = enc_etsi_call_deflection(ctrl, buffer, buffer + sizeof(buffer), call, &deflection->to); @@ -2846,7 +2846,7 @@ int pri_call_add_standard_apdus(struct pri *ctrl, q931_call *call) switch (ctrl->switchtype) { case PRI_SWITCH_EUROISDN_E1: case PRI_SWITCH_EUROISDN_T1: - if (q931_is_ptmp(ctrl)) { + if (PTMP_MODE(ctrl)) { /* PTMP mode */ break; } diff --git a/pri_internal.h b/pri_internal.h index bf744db..13a31e2 100644 --- a/pri_internal.h +++ b/pri_internal.h @@ -86,6 +86,10 @@ struct pri { int protodisc; unsigned int bri:1; unsigned int acceptinbanddisconnect:1; /* Should we allow inband progress after DISCONNECT? */ + unsigned int sendfacility:1; + unsigned int overlapdial:1;/* TRUE if we do overlap dialing */ + unsigned int chan_mapping_logical:1;/* TRUE if do not skip channel 16 (Q.SIG) */ + unsigned int service_message_support:1;/* TRUE if upper layer supports SERVICE messages */ unsigned int hold_support:1;/* TRUE if upper layer supports call hold. */ unsigned int deflection_support:1;/* TRUE if upper layer supports call deflection/rerouting. */ @@ -141,15 +145,6 @@ struct pri { */ q931_call *dummy_call; - /* do we do overlap dialing */ - int overlapdial; - - /* do we support SERVICE messages */ - int service_message_support; - - /* do not skip channel 16 */ - int chan_mapping_logical; - #ifdef LIBPRI_COUNTERS /* q921/q931 packet counters */ unsigned int q921_txcount; @@ -159,7 +154,6 @@ struct pri { #endif short last_invoke; /* Last ROSE invoke ID (Valid in master record only) */ - unsigned char sendfacility; /*! For delayed processing of facility ie's. */ struct { @@ -561,7 +555,6 @@ void pri_error(struct pri *ctrl, const char *fmt, ...) __attribute__((format(pri void libpri_copy_string(char *dst, const char *src, size_t size); struct pri *__pri_new_tei(int fd, int node, int switchtype, struct pri *master, pri_io_cb rd, pri_io_cb wr, void *userdata, int tei, int bri); - void __pri_free_tei(struct pri *p); void q931_init_call_record(struct pri *ctrl, struct q931_call *call, int cr); @@ -596,77 +589,128 @@ int q931_party_id_presentation(const struct q931_party_id *id); const char *q931_call_state_str(enum Q931_CALL_STATE callstate); const char *msg2str(int msg); -int q931_is_ptmp(const struct pri *ctrl); int q931_master_pass_event(struct pri *ctrl, struct q931_call *subcall, int msg_type); struct pri_subcommand *q931_alloc_subcommand(struct pri *ctrl); int q931_notify_redirection(struct pri *ctrl, q931_call *call, int notify, const struct q931_party_number *number); -static inline struct pri * PRI_MASTER(struct pri *mypri) +/*! + * \brief Get the master PRI control structure. + * + * \param ctrl D channel controller. + * + * \return Master PRI control structure. + */ +static inline struct pri *PRI_MASTER(struct pri *ctrl) { - struct pri *pri = mypri; - - if (!pri) - return NULL; - - while (pri->master) - pri = pri->master; - - return pri; + while (ctrl->master) { + ctrl = ctrl->master; + } + return ctrl; } -static inline int BRI_NT_PTMP(struct pri *mypri) +/*! + * \brief Determine if layer 2 is in BRI NT PTMP mode. + * + * \param ctrl D channel controller. + * + * \retval TRUE if in BRI NT PTMP mode. + * \retval FALSE otherwise. + */ +static inline int BRI_NT_PTMP(const struct pri *ctrl) { - struct pri *pri; + struct pri *my_ctrl = (struct pri *) ctrl; - pri = PRI_MASTER(mypri); - - return pri->bri && (((pri)->localtype == PRI_NETWORK) && ((pri)->tei == Q921_TEI_GROUP)); + /* Check master control structure */ + my_ctrl = PRI_MASTER(my_ctrl); + return my_ctrl->bri && my_ctrl->localtype == PRI_NETWORK + && my_ctrl->tei == Q921_TEI_GROUP; } -static inline int BRI_TE_PTMP(struct pri *mypri) +/*! + * \brief Determine if layer 2 is in BRI TE PTMP mode. + * + * \param ctrl D channel controller. + * + * \retval TRUE if in BRI TE PTMP mode. + * \retval FALSE otherwise. + */ +static inline int BRI_TE_PTMP(const struct pri *ctrl) { - struct pri *pri; + struct pri *my_ctrl = (struct pri *) ctrl; - pri = PRI_MASTER(mypri); - - return pri->bri && (((pri)->localtype == PRI_CPE) && ((pri)->tei == Q921_TEI_GROUP)); + /* Check master control structure */ + my_ctrl = PRI_MASTER(my_ctrl); + return my_ctrl->bri && my_ctrl->localtype == PRI_CPE + && my_ctrl->tei == Q921_TEI_GROUP; } -static inline int NT_MODE(struct pri *mypri) +/*! + * \brief Determine if layer 2 is in NT mode. + * + * \param ctrl D channel controller. + * + * \retval TRUE if in NT mode. + * \retval FALSE otherwise. + */ +static inline int NT_MODE(const struct pri *ctrl) { - struct pri *pri; + struct pri *my_ctrl = (struct pri *) ctrl; - pri = PRI_MASTER(mypri); - - return pri->localtype == PRI_NETWORK; + /* Check master control structure */ + my_ctrl = PRI_MASTER(my_ctrl); + return my_ctrl->localtype == PRI_NETWORK; } -static inline int TE_MODE(struct pri *mypri) +/*! + * \brief Determine if layer 2 is in TE mode. + * + * \param ctrl D channel controller. + * + * \retval TRUE if in TE mode. + * \retval FALSE otherwise. + */ +static inline int TE_MODE(const struct pri *ctrl) { - struct pri *pri; + struct pri *my_ctrl = (struct pri *) ctrl; - pri = PRI_MASTER(mypri); - - return pri->localtype == PRI_CPE; + /* Check master control structure */ + my_ctrl = PRI_MASTER(my_ctrl); + return my_ctrl->localtype == PRI_CPE; } -static inline int PTP_MODE(struct pri *mypri) +/*! + * \brief Determine if layer 2 is in PTP mode. + * + * \param ctrl D channel controller. + * + * \retval TRUE if in PTP mode. + * \retval FALSE otherwise. + */ +static inline int PTP_MODE(const struct pri *ctrl) { - struct pri *pri; + struct pri *my_ctrl = (struct pri *) ctrl; - pri = PRI_MASTER(mypri); - - return pri->tei == Q921_TEI_PRI; + /* Check master control structure */ + my_ctrl = PRI_MASTER(my_ctrl); + return my_ctrl->tei == Q921_TEI_PRI; } -static inline int PTMP_MODE(struct pri *mypri) +/*! + * \brief Determine if layer 2 is in PTMP mode. + * + * \param ctrl D channel controller. + * + * \retval TRUE if in PTMP mode. + * \retval FALSE otherwise. + */ +static inline int PTMP_MODE(const struct pri *ctrl) { - struct pri *pri; + struct pri *my_ctrl = (struct pri *) ctrl; - pri = PRI_MASTER(mypri); - - return pri->tei == Q921_TEI_GROUP; + /* Check master control structure */ + my_ctrl = PRI_MASTER(my_ctrl); + return my_ctrl->tei == Q921_TEI_GROUP; } #define Q931_DUMMY_CALL_REFERENCE -1 diff --git a/q921.c b/q921.c index 8f4f776..8d181bd 100644 --- a/q921.c +++ b/q921.c @@ -94,8 +94,7 @@ static int q921_transmit(struct pri *pri, q921_h *h, int len) { int res; - if (pri->master) - pri = pri->master; + pri = PRI_MASTER(pri); #ifdef RANDOM_DROPS if (!(random() % 3)) { diff --git a/q931.c b/q931.c index 5e9c426..800cca5 100644 --- a/q931.c +++ b/q931.c @@ -320,22 +320,6 @@ static int q931_encode_channel(const q931_call *call) | held_call; } -/*! - * \brief Determine if layer 2 is in PTMP mode. - * - * \param ctrl D channel controller. - * - * \retval TRUE if in PTMP mode. - * \retval FALSE otherwise. - */ -int q931_is_ptmp(const struct pri *ctrl) -{ - /* Check master control structure */ - for (; ctrl->master; ctrl = ctrl->master) { - } - return ctrl->tei == Q921_TEI_GROUP; -} - /*! * \brief Initialize the given struct q931_party_name * @@ -4872,7 +4856,7 @@ static int q931_is_hold_allowed(const struct pri *ctrl, const struct q931_call * case Q931_CALL_STATE_CALL_RECEIVED: case Q931_CALL_STATE_CONNECT_REQUEST: case Q931_CALL_STATE_INCOMING_CALL_PROCEEDING: - if (q931_is_ptmp(ctrl)) { + if (PTMP_MODE(ctrl)) { /* HOLD request only allowed in these states if point-to-point mode. */ break; } @@ -5074,7 +5058,7 @@ static int q931_is_retrieve_allowed(const struct pri *ctrl, const struct q931_ca case Q931_CALL_STATE_CALL_RECEIVED: case Q931_CALL_STATE_CONNECT_REQUEST: case Q931_CALL_STATE_INCOMING_CALL_PROCEEDING: - if (q931_is_ptmp(ctrl)) { + if (PTMP_MODE(ctrl)) { /* RETRIEVE request only allowed in these states if point-to-point mode. */ break; } @@ -7124,7 +7108,7 @@ static int post_handle_q931_message(struct pri *ctrl, struct q931_mh *mh, struct case Q931_CALL_STATE_CALL_RECEIVED: case Q931_CALL_STATE_CONNECT_REQUEST: case Q931_CALL_STATE_INCOMING_CALL_PROCEEDING: - if (q931_is_ptmp(ctrl)) { + if (PTMP_MODE(ctrl)) { /* HOLD request only allowed in these states if point-to-point mode. */ q931_send_hold_rej_msg(ctrl, c, PRI_CAUSE_WRONG_CALL_STATE); break; @@ -7237,7 +7221,7 @@ static int post_handle_q931_message(struct pri *ctrl, struct q931_mh *mh, struct case Q931_CALL_STATE_CALL_RECEIVED: case Q931_CALL_STATE_CONNECT_REQUEST: case Q931_CALL_STATE_INCOMING_CALL_PROCEEDING: - if (q931_is_ptmp(ctrl)) { + if (PTMP_MODE(ctrl)) { /* RETRIEVE request only allowed in these states if point-to-point mode. */ q931_send_retrieve_rej_msg(ctrl, c, PRI_CAUSE_WRONG_CALL_STATE); break;