[svn-commits] rmudgett: branch group/issue14068 r958 - /team/group/issue14068/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 23 17:26:10 CDT 2009


Author: rmudgett
Date: Thu Jul 23 17:26:06 2009
New Revision: 958

URL: http://svn.asterisk.org/svn-view/libpri?view=rev&rev=958
Log:
Add full caller ID and redirecting information to new SETUP record.

Modified:
    team/group/issue14068/libpri.h
    team/group/issue14068/pri.c
    team/group/issue14068/pri_internal.h
    team/group/issue14068/q931.c

Modified: team/group/issue14068/libpri.h
URL: http://svn.asterisk.org/svn-view/libpri/team/group/issue14068/libpri.h?view=diff&rev=958&r1=957&r2=958
==============================================================================
--- team/group/issue14068/libpri.h (original)
+++ team/group/issue14068/libpri.h Thu Jul 23 17:26:06 2009
@@ -726,13 +726,13 @@
 
 /*! 
  * \brief Give connected line information to a call 
- * \note Could be used instead of pri_sr_set_caller() before calling pri_setup().
+ * \note Could be used instead of pri_sr_set_caller_party() before calling pri_setup().
  */
 int pri_connected_line_update(struct pri *pri, q931_call *call, const struct pri_party_connected_line *connected);
 
 /*! 
  * \brief Give redirection information to a call
- * \note Should be used instead of pri_sr_set_redirecting() before calling pri_setup().
+ * \note Could be used instead of pri_sr_set_redirecting_parties() before calling pri_setup().
  */
 int pri_redirecting_update(struct pri *pri, q931_call *call, const struct pri_party_redirecting *redirecting);
 
@@ -790,9 +790,29 @@
 int pri_sr_set_channel(struct pri_sr *sr, int channel, int exclusive, int nonisdn);
 int pri_sr_set_bearer(struct pri_sr *sr, int transmode, int userl1);
 int pri_sr_set_called(struct pri_sr *sr, char *called, int calledplan, int complete);
-/*! \note Use pri_connected_line_update() instead to pass more precise caller information. */
+
+/*!
+ * \brief Set the caller party ID information in the call SETUP record.
+ *
+ * \param sr New call SETUP record.
+ * \param caller Caller party ID information to set.
+ *
+ * \return Nothing
+ */
+void pri_sr_set_caller_party(struct pri_sr *sr, const struct pri_party_id *caller);
+/*! \note Use pri_sr_set_caller_party() instead to pass more precise caller information. */
 int pri_sr_set_caller(struct pri_sr *sr, char *caller, char *callername, int callerplan, int callerpres);
-/*! \note Use pri_redirecting_update() instead to pass more precise redirecting information. */
+
+/*!
+ * \brief Set the redirecting information in the call SETUP record.
+ *
+ * \param sr New call SETUP record.
+ * \param caller Redirecting information to set.
+ *
+ * \return Nothing
+ */
+void pri_sr_set_redirecting_parties(struct pri_sr *sr, const struct pri_party_redirecting *redirecting);
+/*! \note Use pri_sr_set_redirecting_parties() instead to pass more precise redirecting information. */
 int pri_sr_set_redirecting(struct pri_sr *sr, char *num, int plan, int pres, int reason);
 
 #define PRI_USER_USER_TX

Modified: team/group/issue14068/pri.c
URL: http://svn.asterisk.org/svn-view/libpri/team/group/issue14068/pri.c?view=diff&rev=958&r1=957&r2=958
==============================================================================
--- team/group/issue14068/pri.c (original)
+++ team/group/issue14068/pri.c Thu Jul 23 17:26:06 2009
@@ -603,29 +603,17 @@
  * \internal
  * \brief Copy the PRI party number to the Q.931 party number structure.
  *
- * \param ctrl D channel controller.
  * \param q931_number Q.931 party number structure
  * \param pri_number PRI party number structure
  *
  * \return Nothing
  */
-static void pri_copy_party_number_to_q931(struct pri *ctrl, struct q931_party_number *q931_number, const struct pri_party_number *pri_number)
+static void pri_copy_party_number_to_q931(struct q931_party_number *q931_number, const struct pri_party_number *pri_number)
 {
 	q931_party_number_init(q931_number);
 	if (pri_number->valid) {
 		q931_number->valid = 1;
 		q931_number->presentation = pri_number->presentation;
-		switch (ctrl->switchtype) {
-		case PRI_SWITCH_DMS100:
-		case PRI_SWITCH_ATT4ESS:
-			/* Doesn't like certain presentation types */
-			if (!(q931_number->presentation & 0x7c)) {
-				q931_number->presentation = PRES_ALLOWED_NETWORK_NUMBER;
-			}
-			break;
-		default:
-			break;
-		}
 		q931_number->plan = pri_number->plan;
 		libpri_copy_string(q931_number->str, pri_number->str, sizeof(q931_number->str));
 	}
@@ -635,16 +623,15 @@
  * \internal
  * \brief Copy the PRI party id to the Q.931 party id structure.
  *
- * \param ctrl D channel controller.
  * \param q931_id Q.931 party id structure
  * \param pri_id PRI party id structure
  *
  * \return Nothing
  */
-static void pri_copy_party_id_to_q931(struct pri *ctrl, struct q931_party_id *q931_id, const struct pri_party_id *pri_id)
+static void pri_copy_party_id_to_q931(struct q931_party_id *q931_id, const struct pri_party_id *pri_id)
 {
 	pri_copy_party_name_to_q931(&q931_id->name, &pri_id->name);
-	pri_copy_party_number_to_q931(ctrl, &q931_id->number, &pri_id->number);
+	pri_copy_party_number_to_q931(&q931_id->number, &pri_id->number);
 }
 
 int pri_connected_line_update(struct pri *ctrl, q931_call *call, const struct pri_party_connected_line *connected)
@@ -655,7 +642,8 @@
 		return -1;
 	}
 
-	pri_copy_party_id_to_q931(ctrl, &party_id, &connected->id);
+	pri_copy_party_id_to_q931(&party_id, &connected->id);
+	q931_party_id_fixup(ctrl, &party_id);
 	if (!q931_party_id_cmp(&party_id, &call->local_id)) {
 		/* The local party information did not change so do nothing. */
 		return 0;
@@ -708,14 +696,17 @@
 	}
 
 	/* Save redirecting.to information and reason. */
-	pri_copy_party_id_to_q931(ctrl, &call->redirecting.to, &redirecting->to);
+	pri_copy_party_id_to_q931(&call->redirecting.to, &redirecting->to);
+	q931_party_id_fixup(ctrl, &call->redirecting.to);
 	call->redirecting.reason = redirecting->reason;
 
 	switch (call->ourcallstate) {
 	case Q931_CALL_STATE_NULL:
 		/* Save the remaining redirecting information before we place a call. */
-		pri_copy_party_id_to_q931(ctrl, &call->redirecting.from, &redirecting->from);
-		pri_copy_party_id_to_q931(ctrl, &call->redirecting.orig_called, &redirecting->orig_called);
+		pri_copy_party_id_to_q931(&call->redirecting.from, &redirecting->from);
+		q931_party_id_fixup(ctrl, &call->redirecting.from);
+		pri_copy_party_id_to_q931(&call->redirecting.orig_called, &redirecting->orig_called);
+		q931_party_id_fixup(ctrl, &call->redirecting.orig_called);
 		call->redirecting.orig_reason = redirecting->orig_reason;
 		if (redirecting->count <= 0) {
 			if (call->redirecting.from.number.valid) {
@@ -909,6 +900,8 @@
 static void pri_sr_init(struct pri_sr *req)
 {
 	memset(req, 0, sizeof(struct pri_sr));
+	q931_party_redirecting_init(&req->redirecting);
+	q931_party_id_init(&req->caller);
 	req->reversecharge = PRI_REVERSECHARGE_NONE;
 }
 
@@ -931,13 +924,8 @@
 
 	pri_sr_init(&req);
 	pri_sr_set_connection_call_independent(&req);
-
-	req.caller = caller;
-	req.callerplan = callerplan;
-	req.callername = callername;
-	req.callerpres = callerpres;
-	req.called = called;
-	req.calledplan = calledplan;
+	pri_sr_set_caller(&req, caller, callername, callerplan, callerpres);
+	pri_sr_set_called(&req, called, calledplan, 0);
 
 	if (mwi_message_send(pri, c, &req, 1) < 0) {
 		pri_message(pri, "Unable to send MWI activate message\n");
@@ -956,13 +944,8 @@
 
 	pri_sr_init(&req);
 	pri_sr_set_connection_call_independent(&req);
-
-	req.caller = caller;
-	req.callerplan = callerplan;
-	req.callername = callername;
-	req.callerpres = callerpres;
-	req.called = called;
-	req.calledplan = calledplan;
+	pri_sr_set_caller(&req, caller, callername, callerplan, callerpres);
+	pri_sr_set_called(&req, called, calledplan, 0);
 
 	if(mwi_message_send(pri, c, &req, 0) < 0) {
 		pri_message(pri, "Unable to send MWI deactivate message\n");
@@ -988,16 +971,12 @@
 	if (!pri || !c)
 		return -1;
 	pri_sr_init(&req);
+	pri_sr_set_caller(&req, caller, callername, callerplan, callerpres);
+	pri_sr_set_called(&req, called, calledplan, 0);
 	req.transmode = transmode;
 	req.channel = channel;
 	req.exclusive = exclusive;
 	req.nonisdn =  nonisdn;
-	req.caller = caller;
-	req.callerplan = callerplan;
-	req.callername = callername;
-	req.callerpres = callerpres;
-	req.called = called;
-	req.calledplan = calledplan;
 	req.userl1 = ulayer1;
 	return q931_setup(pri, c, &req);
 }	
@@ -1216,22 +1195,69 @@
 
 int pri_sr_set_caller(struct pri_sr *sr, char *caller, char *callername, int callerplan, int callerpres)
 {
-	sr->caller = caller;
-	sr->callername = callername;
-	sr->callerplan = callerplan;
-	sr->callerpres = callerpres;
+	q931_party_id_init(&sr->caller);
+	if (caller) {
+		sr->caller.number.valid = 1;
+		sr->caller.number.presentation = callerpres;
+		sr->caller.number.plan = callerplan;
+		libpri_copy_string(sr->caller.number.str, caller, sizeof(sr->caller.number.str));
+
+		if (callername) {
+			sr->caller.name.valid = 1;
+			sr->caller.name.presentation = callerpres;
+			sr->caller.name.char_set = PRI_CHAR_SET_ISO8859_1;
+			libpri_copy_string(sr->caller.name.str, callername,
+				sizeof(sr->caller.name.str));
+		}
+	}
 	return 0;
 }
 
+void pri_sr_set_caller_party(struct pri_sr *sr, const struct pri_party_id *caller)
+{
+	pri_copy_party_id_to_q931(&sr->caller, caller);
+}
+
 int pri_sr_set_redirecting(struct pri_sr *sr, char *num, int plan, int pres, int reason)
 {
-	sr->redirectingnum = num;
-	sr->redirectingplan = plan;
-	sr->redirectingpres = pres;
-	sr->redirectingreason = reason;
+	q931_party_redirecting_init(&sr->redirecting);
+	if (num && num[0]) {
+		sr->redirecting.from.number.valid = 1;
+		sr->redirecting.from.number.presentation = pres;
+		sr->redirecting.from.number.plan = plan;
+		libpri_copy_string(sr->redirecting.from.number.str, num,
+			sizeof(sr->redirecting.from.number.str));
+
+		sr->redirecting.count = 1;
+		sr->redirecting.reason = reason;
+	}
 	return 0;
 }
 
+void pri_sr_set_redirecting_parties(struct pri_sr *sr, const struct pri_party_redirecting *redirecting)
+{
+	pri_copy_party_id_to_q931(&sr->redirecting.from, &redirecting->from);
+	pri_copy_party_id_to_q931(&sr->redirecting.to, &redirecting->to);
+	pri_copy_party_id_to_q931(&sr->redirecting.orig_called, &redirecting->orig_called);
+	sr->redirecting.orig_reason = redirecting->orig_reason;
+	sr->redirecting.reason = redirecting->reason;
+	if (redirecting->count <= 0) {
+		if (sr->redirecting.from.number.valid) {
+			/*
+			 * We are redirecting with an unknown count
+			 * so assume the count is one.
+			 */
+			sr->redirecting.count = 1;
+		} else {
+			sr->redirecting.count = 0;
+		}
+	} else if (redirecting->count < PRI_MAX_REDIRECTS) {
+		sr->redirecting.count = redirecting->count;
+	} else {
+		sr->redirecting.count = PRI_MAX_REDIRECTS;
+	}
+}
+
 void pri_sr_set_reversecharge(struct pri_sr *sr, int requested)
 {
 	sr->reversecharge = requested;

Modified: team/group/issue14068/pri_internal.h
URL: http://svn.asterisk.org/svn-view/libpri/team/group/issue14068/pri_internal.h?view=diff&rev=958&r1=957&r2=958
==============================================================================
--- team/group/issue14068/pri_internal.h (original)
+++ team/group/issue14068/pri_internal.h Thu Jul 23 17:26:06 2009
@@ -135,44 +135,6 @@
 	unsigned char sendfacility;
 };
 
-/*! \brief New call setup parameter structure */
-struct pri_sr {
-	int transmode;
-	int channel;
-	int exclusive;
-	int nonisdn;
-	char *caller;
-	int callerplan;
-	char *callername;
-	int callerpres;
-	char *called;
-	int calledplan;
-	int userl1;
-	int numcomplete;
-	char *redirectingnum;
-	int redirectingplan;
-	int redirectingpres;
-	int redirectingreason;
-	int justsignalling;
-	const char *useruserinfo;
-	int transferable;
-	int reversecharge;
-};
-
-/* Internal switch types */
-#define PRI_SWITCH_GR303_EOC_PATH	19
-#define PRI_SWITCH_GR303_TMC_SWITCHING	20
-
-struct apdu_event {
-	int message;			/* What message to send the ADPU in */
-	void (*callback)(void *data);	/* Callback function for when response is received */
-	void *data;			/* Data to callback */
-	unsigned char apdu[255];			/* ADPU to send */
-	int apdu_len; 			/* Length of ADPU */
-	int sent;  			/* Have we been sent already? */
-	struct apdu_event *next;	/* Linked list pointer */
-};
-
 /*! \brief Maximum name length plus null terminator (From ECMA-164) */
 #define PRI_MAX_NAME_LEN		(50 + 1)
 
@@ -273,6 +235,38 @@
 	unsigned char orig_reason;
 	/*! \brief Redirection reasons */
 	unsigned char reason;
+};
+
+/*! \brief New call setup parameter structure */
+struct pri_sr {
+	int transmode;
+	int channel;
+	int exclusive;
+	int nonisdn;
+	struct q931_party_redirecting redirecting;
+	struct q931_party_id caller;
+	char *called;
+	int calledplan;
+	int userl1;
+	int numcomplete;
+	int justsignalling;
+	const char *useruserinfo;
+	int transferable;
+	int reversecharge;
+};
+
+/* Internal switch types */
+#define PRI_SWITCH_GR303_EOC_PATH	19
+#define PRI_SWITCH_GR303_TMC_SWITCHING	20
+
+struct apdu_event {
+	int message;			/* What message to send the ADPU in */
+	void (*callback)(void *data);	/* Callback function for when response is received */
+	void *data;			/* Data to callback */
+	unsigned char apdu[255];			/* ADPU to send */
+	int apdu_len; 			/* Length of ADPU */
+	int sent;  			/* Have we been sent already? */
+	struct apdu_event *next;	/* Linked list pointer */
 };
 
 /*! \brief Incoming call transfer states. */
@@ -459,6 +453,7 @@
 void q931_party_id_copy_to_pri(struct pri_party_id *pri_id, const struct q931_party_id *q931_id);
 void q931_party_redirecting_copy_to_pri(struct pri_party_redirecting *pri_redirecting, const struct q931_party_redirecting *q931_redirecting);
 
+void q931_party_id_fixup(const struct pri *ctrl, struct q931_party_id *id);
 int q931_party_id_presentation(const struct q931_party_id *id);
 
 const char *q931_call_state_str(int callstate);

Modified: team/group/issue14068/q931.c
URL: http://svn.asterisk.org/svn-view/libpri/team/group/issue14068/q931.c?view=diff&rev=958&r1=957&r2=958
==============================================================================
--- team/group/issue14068/q931.c (original)
+++ team/group/issue14068/q931.c Thu Jul 23 17:26:06 2009
@@ -490,6 +490,30 @@
 	pri_redirecting->count = q931_redirecting->count;
 	pri_redirecting->orig_reason = q931_redirecting->orig_reason;
 	pri_redirecting->reason = q931_redirecting->reason;
+}
+
+/*!
+ * \brief Fixup some values in the q931_party_id that may be objectionable by switches.
+ *
+ * \param ctrl D channel controller.
+ * \param id Party ID to tweak.
+ *
+ * \return Nothing
+ */
+void q931_party_id_fixup(const struct pri *ctrl, struct q931_party_id *id)
+{
+	switch (ctrl->switchtype) {
+	case PRI_SWITCH_DMS100:
+	case PRI_SWITCH_ATT4ESS:
+		/* Doesn't like certain presentation types */
+		if (id->number.valid && !(id->number.presentation & 0x7c)) {
+			/* i.e., If presentation is allowed it must be a network number */
+			id->number.presentation = PRES_ALLOWED_NETWORK_NUMBER;
+		}
+		break;
+	default:
+		break;
+	}
 }
 
 /*!
@@ -3745,55 +3769,19 @@
 		c->chanflags = FLAG_EXCLUSIVE;
 	else if (c->channelno)
 		c->chanflags = FLAG_PREFERRED;
-	if (req->caller) {
-		switch (ctrl->switchtype) {
-		case PRI_SWITCH_DMS100:
-		case PRI_SWITCH_ATT4ESS:
-			/* Doesn't like certain presentation types */
-			if (!(req->callerpres & 0x7c)) {
-				req->callerpres = PRES_ALLOWED_NETWORK_NUMBER;
-			}
-			break;
-		default:
-			break;
-		}
-
-		c->local_id.number.valid = 1;
-		c->local_id.number.presentation = req->callerpres;
-		c->local_id.number.plan = req->callerplan;
-		libpri_copy_string(c->local_id.number.str, req->caller,
-			sizeof(c->local_id.number.str));
-
-		if (req->callername) {
-			c->local_id.name.valid = 1;
-			c->local_id.name.presentation = req->callerpres;
-			c->local_id.name.char_set = PRI_CHAR_SET_ISO8859_1;
-			libpri_copy_string(c->local_id.name.str, req->callername,
-				sizeof(c->local_id.name.str));
-		}
-	}
-	if (req->redirectingnum && req->redirectingnum[0]) {
-		switch (ctrl->switchtype) {
-		case PRI_SWITCH_DMS100:
-		case PRI_SWITCH_ATT4ESS:
-			/* Doesn't like certain presentation types */
-			if (!(req->redirectingpres & 0x7c)) {
-				req->redirectingpres = PRES_ALLOWED_NETWORK_NUMBER;
-			}
-			break;
-		default:
-			break;
-		}
-
-		c->redirecting.from.number.valid = 1;
-		c->redirecting.from.number.presentation = req->redirectingpres;
-		c->redirecting.from.number.plan = req->redirectingplan;
-		libpri_copy_string(c->redirecting.from.number.str, req->redirectingnum,
-			sizeof(c->redirecting.from.number.str));
-
-		c->redirecting.count = 1;
-		c->redirecting.reason = req->redirectingreason;
-	}
+
+	if (req->caller.number.valid) {
+		c->local_id = req->caller;
+		q931_party_id_fixup(ctrl, &c->local_id);
+	}
+
+	if (req->redirecting.from.number.valid) {
+		c->redirecting = req->redirecting;
+		q931_party_id_fixup(ctrl, &c->redirecting.from);
+		q931_party_id_fixup(ctrl, &c->redirecting.to);
+		q931_party_id_fixup(ctrl, &c->redirecting.orig_called);
+	}
+
 	if (req->called) {
 		c->called_number.valid = 1;
 		c->called_number.plan = req->calledplan;




More information about the svn-commits mailing list