[svn-commits] rmudgett: branch 1.4 r1534 - /branches/1.4/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Mar 17 12:47:57 CDT 2010


Author: rmudgett
Date: Wed Mar 17 12:47:53 2010
New Revision: 1534

URL: http://svnview.digium.com/svn/libpri?view=rev&rev=1534
Log:
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.

Modified:
    branches/1.4/pri.c
    branches/1.4/pri_facility.c
    branches/1.4/pri_internal.h
    branches/1.4/q921.c
    branches/1.4/q931.c

Modified: branches/1.4/pri.c
URL: http://svnview.digium.com/svn/libpri/branches/1.4/pri.c?view=diff&rev=1534&r1=1533&r2=1534
==============================================================================
--- branches/1.4/pri.c (original)
+++ branches/1.4/pri.c Wed Mar 17 12:47:53 2010
@@ -194,7 +194,7 @@
 	if (!pri) {
 		return -1;
 	}
-	pri->service_message_support = supportflag;
+	pri->service_message_support = supportflag ? 1 : 0;
 	return 0;
 }
 
@@ -776,7 +776,7 @@
 		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 @@
 		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 @@
 	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 @@
 	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 @@
 /* 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_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 @@
 
 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;
 	}
 }

Modified: branches/1.4/pri_facility.c
URL: http://svnview.digium.com/svn/libpri/branches/1.4/pri_facility.c?view=diff&rev=1534&r1=1533&r2=1534
==============================================================================
--- branches/1.4/pri_facility.c (original)
+++ branches/1.4/pri_facility.c Wed Mar 17 12:47:53 2010
@@ -2072,7 +2072,7 @@
 	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 @@
 	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;
 		}

Modified: branches/1.4/pri_internal.h
URL: http://svnview.digium.com/svn/libpri/branches/1.4/pri_internal.h?view=diff&rev=1534&r1=1533&r2=1534
==============================================================================
--- branches/1.4/pri_internal.h (original)
+++ branches/1.4/pri_internal.h Wed Mar 17 12:47:53 2010
@@ -86,6 +86,10 @@
 	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 @@
 	 */
 	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 @@
 #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 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 @@
 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)
-{
-	struct pri *pri = mypri;
-	
-	if (!pri)
-		return NULL;
-
-	while (pri->master)
-		pri = pri->master;
-
-	return pri;
-}
-
-static inline int BRI_NT_PTMP(struct pri *mypri)
-{
-	struct pri *pri;
-
-	pri = PRI_MASTER(mypri);
-
-	return pri->bri && (((pri)->localtype == PRI_NETWORK) && ((pri)->tei == Q921_TEI_GROUP));
-}
-
-static inline int BRI_TE_PTMP(struct pri *mypri)
-{
-	struct pri *pri;
-
-	pri = PRI_MASTER(mypri);
-
-	return pri->bri && (((pri)->localtype == PRI_CPE) && ((pri)->tei == Q921_TEI_GROUP));
-}
-
-static inline int NT_MODE(struct pri *mypri)
-{
-	struct pri *pri;
-
-	pri = PRI_MASTER(mypri);
-
-	return pri->localtype == PRI_NETWORK;
-}
-
-static inline int TE_MODE(struct pri *mypri)
-{
-	struct pri *pri;
-
-	pri = PRI_MASTER(mypri);
-
-	return pri->localtype == PRI_CPE;
-}
-
-static inline int PTP_MODE(struct pri *mypri)
-{
-	struct pri *pri;
-
-	pri = PRI_MASTER(mypri);
-
-	return pri->tei == Q921_TEI_PRI;
-}
-
-static inline int PTMP_MODE(struct pri *mypri)
-{
-	struct pri *pri;
-
-	pri = PRI_MASTER(mypri);
-
-	return pri->tei == Q921_TEI_GROUP;
+/*!
+ * \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)
+{
+	while (ctrl->master) {
+		ctrl = ctrl->master;
+	}
+	return ctrl;
+}
+
+/*!
+ * \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 *my_ctrl = (struct pri *) ctrl;
+
+	/* 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;
+}
+
+/*!
+ * \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 *my_ctrl = (struct pri *) ctrl;
+
+	/* 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;
+}
+
+/*!
+ * \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 *my_ctrl = (struct pri *) ctrl;
+
+	/* Check master control structure */
+	my_ctrl = PRI_MASTER(my_ctrl);
+	return my_ctrl->localtype == PRI_NETWORK;
+}
+
+/*!
+ * \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 *my_ctrl = (struct pri *) ctrl;
+
+	/* Check master control structure */
+	my_ctrl = PRI_MASTER(my_ctrl);
+	return my_ctrl->localtype == PRI_CPE;
+}
+
+/*!
+ * \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 *my_ctrl = (struct pri *) ctrl;
+
+	/* Check master control structure */
+	my_ctrl = PRI_MASTER(my_ctrl);
+	return my_ctrl->tei == Q921_TEI_PRI;
+}
+
+/*!
+ * \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 *my_ctrl = (struct pri *) ctrl;
+
+	/* Check master control structure */
+	my_ctrl = PRI_MASTER(my_ctrl);
+	return my_ctrl->tei == Q921_TEI_GROUP;
 }
 
 #define Q931_DUMMY_CALL_REFERENCE	-1

Modified: branches/1.4/q921.c
URL: http://svnview.digium.com/svn/libpri/branches/1.4/q921.c?view=diff&rev=1534&r1=1533&r2=1534
==============================================================================
--- branches/1.4/q921.c (original)
+++ branches/1.4/q921.c Wed Mar 17 12:47:53 2010
@@ -94,8 +94,7 @@
 {
 	int res;
 
-	if (pri->master)
-		pri = pri->master;
+	pri = PRI_MASTER(pri);
 
 #ifdef RANDOM_DROPS
    if (!(random() % 3)) {

Modified: branches/1.4/q931.c
URL: http://svnview.digium.com/svn/libpri/branches/1.4/q931.c?view=diff&rev=1534&r1=1533&r2=1534
==============================================================================
--- branches/1.4/q931.c (original)
+++ branches/1.4/q931.c Wed Mar 17 12:47:53 2010
@@ -318,22 +318,6 @@
 	}
 	return channelno | (ds1no << 8) | (call->ds1explicit << 16) | (call->cis_call << 17)
 		| 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;
 }
 
 /*!
@@ -4872,7 +4856,7 @@
 	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 @@
 	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 @@
 		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 @@
 		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;




More information about the svn-commits mailing list