[libpri-commits] rmudgett: branch group/ccss r1289 - /team/group/ccss/

SVN commits to the libpri project libpri-commits at lists.digium.com
Tue Nov 10 16:44:39 CST 2009


Author: rmudgett
Date: Tue Nov 10 16:44:35 2009
New Revision: 1289

URL: http://svnview.digium.com/svn/libpri?view=rev&rev=1289
Log:
Merged revisions 1283 via svnmerge from 
https://origsvn.digium.com/svn/libpri/branches/1.4

........
  r1283 | rmudgett | 2009-11-10 15:51:26 -0600 (Tue, 10 Nov 2009) | 11 lines
  
  The facility ie queue needs to remove facilities that have been sent.
  
  The facility ie queue needs to remove facilities that have been sent.
  Otherwise, the queue just grows until the call is terminated.  AOC
  messages can clog the queue during a long call and the dummy call
  reference may never be deleted.
  
  Also removed unneeded elements of struct apdu_event.  The callback
  function was not a good idea since many facility messages do not have
  responses and the callback would prevents removal of events from the list.
........

Modified:
    team/group/ccss/   (props changed)
    team/group/ccss/pri_facility.c
    team/group/ccss/pri_facility.h
    team/group/ccss/pri_internal.h
    team/group/ccss/q931.c

Propchange: team/group/ccss/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/group/ccss/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Nov 10 16:44:35 2009
@@ -1,1 +1,1 @@
-/branches/1.4:1-1281
+/branches/1.4:1-1288

Modified: team/group/ccss/pri_facility.c
URL: http://svnview.digium.com/svn/libpri/team/group/ccss/pri_facility.c?view=diff&rev=1289&r1=1288&r2=1289
==============================================================================
--- team/group/ccss/pri_facility.c (original)
+++ team/group/ccss/pri_facility.c Tue Nov 10 16:44:35 2009
@@ -1028,7 +1028,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer);
 }
 
 /*!
@@ -1197,7 +1197,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer);
 }
 
 /*!
@@ -1319,7 +1319,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, messagetype, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, messagetype, buffer, end - buffer);
 }
 
 /*!
@@ -1390,7 +1390,7 @@
 		return -1;
 	}
 
-	if (pri_call_apdu_queue(apdubearer, Q931_FACILITY, buffer, end - buffer, NULL, NULL)) {
+	if (pri_call_apdu_queue(apdubearer, Q931_FACILITY, buffer, end - buffer)) {
 		return -1;
 	}
 
@@ -1453,7 +1453,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer);
 }
 
 /*!
@@ -1562,7 +1562,7 @@
 			return -1;
 		}
 
-		if (pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer, NULL, NULL)) {
+		if (pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer)) {
 			return -1;
 		}
 
@@ -1585,15 +1585,11 @@
 		mymessage = Q931_FACILITY;
 	}
 
-	return pri_call_apdu_queue(call, mymessage, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, mymessage, buffer, end - buffer);
 }
 /* End Callername */
 
 /* MWI related encode and decode functions */
-static void mwi_activate_encode_cb(void *data)
-{
-	return;
-}
 
 /*!
  * \internal
@@ -1723,8 +1719,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer,
-		mwi_activate_encode_cb, NULL);
+	return pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer);
 }
 /* End MWI */
 
@@ -1783,7 +1778,7 @@
 		return -1;
 	}
 
-	if (pri_call_apdu_queue(c1, Q931_FACILITY, buffer, end - buffer, NULL, NULL)) {
+	if (pri_call_apdu_queue(c1, Q931_FACILITY, buffer, end - buffer)) {
 		pri_message(ctrl, "Could not queue APDU in facility message\n");
 		return -1;
 	}
@@ -2104,7 +2099,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer);
 }
 
 /*!
@@ -2238,9 +2233,7 @@
 	}
 
 	/* Send message */
-	res =
-		pri_call_apdu_queue(call->bridged_call, Q931_FACILITY, ie->data, ie->len, NULL,
-		NULL);
+	res = pri_call_apdu_queue(call->bridged_call, Q931_FACILITY, ie->data, ie->len);
 	if (res) {
 		pri_message(ctrl, "Could not queue ADPU in facility message\n");
 		return -1;
@@ -2308,7 +2301,7 @@
 		return -1;
 	}
 
-	res = pri_call_apdu_queue(c1, Q931_FACILITY, buffer, pos - buffer, NULL, NULL);
+	res = pri_call_apdu_queue(c1, Q931_FACILITY, buffer, pos - buffer);
 	if (res) {
 		pri_message(ctrl, "Could not queue ADPU in facility message\n");
 		return -1;
@@ -2337,7 +2330,7 @@
 		return -1;
 	}
 
-	res = pri_call_apdu_queue(c2, Q931_FACILITY, buffer, pos - buffer, NULL, NULL);
+	res = pri_call_apdu_queue(c2, Q931_FACILITY, buffer, pos - buffer);
 	if (res) {
 		pri_message(ctrl, "Could not queue ADPU in facility message\n");
 		return -1;
@@ -2422,7 +2415,7 @@
 
 	/* Remember that if we queue a facility IE for a facility message we
 	 * have to explicitly send the facility message ourselves */
-	if (pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer, NULL, NULL)
+	if (pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer)
 		|| q931_facility(call->pri, call)) {
 		pri_message(ctrl, "Could not schedule facility message for call %d\n", call->cr);
 		return -1;
@@ -2568,7 +2561,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer);
 }
 
 /* ===== End Call Transfer Supplementary Service (ECMA-178) ===== */
@@ -2636,7 +2629,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, messagetype, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, messagetype, buffer, end - buffer);
 }
 
 /*!
@@ -2702,7 +2695,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, messagetype, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, messagetype, buffer, end - buffer);
 }
 
 /* ===== Begin Call Completion Supplementary Service (ETS 300 366/ECMA 186) ===== */
@@ -2775,7 +2768,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, messagetype, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, messagetype, buffer, end - buffer);
 }
 /* ===== End Call Completion Supplementary Service (ETS 300 366/ECMA 186) ===== */
 
@@ -2786,40 +2779,49 @@
  * \param messagetype Q.931 message type.
  * \param apdu Facility ie contents buffer.
  * \param apdu_len Length of the contents buffer.
- * \param function Callback function for when response is received. (Not implemented)
- * \param data Parameter to callback function.
  *
  * \retval 0 on success.
  * \retval -1 on error.
  */
-int pri_call_apdu_queue(q931_call *call, int messagetype, void *apdu, int apdu_len,
-	void (*function)(void *data), void *data)
+int pri_call_apdu_queue(q931_call *call, int messagetype, const unsigned char *apdu, int apdu_len)
 {
 	struct apdu_event *cur = NULL;
 	struct apdu_event *new_event = NULL;
 
-	if (!call || !messagetype || !apdu || (apdu_len < 1) || (apdu_len > 255))
-		return -1;
-
-	if (!(new_event = calloc(1, sizeof(*new_event)))) {
+	if (!call || !messagetype || !apdu
+		|| apdu_len < 1 || sizeof(new_event->apdu) < apdu_len) {
+		return -1;
+	}
+	switch (messagetype) {
+	case Q931_FACILITY:
+		break;
+	default:
+		if (q931_is_dummy_call(call)) {
+			pri_error(call->pri, "!! Cannot send %s message on dummy call reference.\n",
+				msg2str(messagetype));
+			return -1;
+		}
+		break;
+	}
+
+	new_event = calloc(1, sizeof(*new_event));
+	if (!new_event) {
 		pri_error(call->pri, "!! Malloc failed!\n");
 		return -1;
 	}
 
 	new_event->message = messagetype;
-	new_event->callback = function;
-	new_event->data = data;
+	new_event->apdu_len = apdu_len;
 	memcpy(new_event->apdu, apdu, apdu_len);
-	new_event->apdu_len = apdu_len;
-
+
+	/* Append APDU to the end of the list. */
 	if (call->apdus) {
-		cur = call->apdus;
-		while (cur->next) {
-			cur = cur->next;
+		for (cur = call->apdus; cur->next; cur = cur->next) {
 		}
 		cur->next = new_event;
-	} else
+	} else {
 		call->apdus = new_event;
+	}
 
 	return 0;
 }
@@ -2830,13 +2832,13 @@
 
 	if (call && call->apdus) {
 		cur_event = call->apdus;
+		call->apdus = NULL;
 		while (cur_event) {
 			/* TODO: callbacks, some way of giving return res on status of apdu */
 			free_event = cur_event;
 			cur_event = cur_event->next;
 			free(free_event);
 		}
-		call->apdus = NULL;
 	}
 
 	return 0;
@@ -2936,7 +2938,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, Q931_SETUP, buffer, end - buffer);
 }
 /* ===== End Call Completion Supplementary Service (ETS 300 366/ECMA 186) ===== */
 
@@ -3138,7 +3140,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, Q931_FACILITY, buffer, end - buffer);
 }
 
 /*!
@@ -3270,7 +3272,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, msgtype, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, msgtype, buffer, end - buffer);
 }
 
 /*!
@@ -3440,7 +3442,7 @@
 		return -1;
 	}
 
-	return pri_call_apdu_queue(call, msgtype, buffer, end - buffer, NULL, NULL);
+	return pri_call_apdu_queue(call, msgtype, buffer, end - buffer);
 }
 
 /*!

Modified: team/group/ccss/pri_facility.h
URL: http://svnview.digium.com/svn/libpri/team/group/ccss/pri_facility.h?view=diff&rev=1289&r1=1288&r2=1289
==============================================================================
--- team/group/ccss/pri_facility.h (original)
+++ team/group/ccss/pri_facility.h Tue Nov 10 16:44:35 2009
@@ -89,10 +89,7 @@
 
 int rose_cc_available_encode(struct pri *ctrl, q931_call *call, int msgtype);
 
-/* Use this function to queue a facility-IE born APDU onto a call
- * call is the call to use, messagetype is any one of the Q931 messages,
- * apdu is the apdu data, apdu_len is the length of the apdu data  */
-int pri_call_apdu_queue(q931_call *call, int messagetype, void *apdu, int apdu_len, void (*function)(void *data), void *data);
+int pri_call_apdu_queue(q931_call *call, int messagetype, const unsigned char *apdu, int apdu_len);
 
 /* Used by q931.c to cleanup the apdu queue upon destruction of a call */
 int pri_call_apdu_queue_cleanup(q931_call *call);

Modified: team/group/ccss/pri_internal.h
URL: http://svnview.digium.com/svn/libpri/team/group/ccss/pri_internal.h?view=diff&rev=1289&r1=1288&r2=1289
==============================================================================
--- team/group/ccss/pri_internal.h (original)
+++ team/group/ccss/pri_internal.h Tue Nov 10 16:44:35 2009
@@ -324,13 +324,10 @@
 #define Q931_MAX_TEI	8
 
 struct apdu_event {
+	struct apdu_event *next;	/* Linked list pointer */
 	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 */
+	int apdu_len; 			/* Length of ADPU */
 	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. */
@@ -655,6 +652,7 @@
 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);

Modified: team/group/ccss/q931.c
URL: http://svnview.digium.com/svn/libpri/team/group/ccss/q931.c?view=diff&rev=1289&r1=1288&r2=1289
==============================================================================
--- team/group/ccss/q931.c (original)
+++ team/group/ccss/q931.c Tue Nov 10 16:44:35 2009
@@ -229,7 +229,6 @@
 #define LOC_NETWORK_BEYOND_INTERWORKING	0xa
 
 static char *ie2str(int ie);
-static char *msg2str(int msg);
 
 
 #define FUNC_DUMP(name) void (name)(int full_ie, struct pri *pri, q931_ie *ie, int len, char prefix)
@@ -2364,32 +2363,41 @@
 
 static int transmit_facility(int full_ie, struct pri *ctrl, q931_call *call, int msgtype, q931_ie *ie, int len, int order)
 {
-	struct apdu_event *tmp;
-	int i = 0;
-
-	for (tmp = call->apdus; tmp; tmp = tmp->next) {
-		if ((tmp->message == msgtype) && !tmp->sent)
-			break;
-	}
-	if (!tmp)	/* No APDU found */
+	struct apdu_event **prev;
+	struct apdu_event *cur;
+	int apdu_len;
+
+	for (prev = &call->apdus, cur = call->apdus;
+		cur;
+		prev = &cur->next, cur = cur->next) {
+		if (cur->message == msgtype) {
+			/* Remove APDU from list. */
+			*prev = cur->next;
+			break;
+		}
+	}
+	if (!cur) {
+		/* No APDU found */
 		return 0;
+	}
 
 	if (ctrl->debug & PRI_DEBUG_APDU) {
 		pri_message(ctrl, "Adding facility ie contents to send in %s message:\n",
 			msg2str(msgtype));
-		facility_decode_dump(ctrl, tmp->apdu, tmp->apdu_len);
-	}
-
-	if (tmp->apdu_len > 235) { /* TODO: find out how much space we can use */
-		pri_message(ctrl, "Requested APDU (%d bytes) is too long\n", tmp->apdu_len);
+		facility_decode_dump(ctrl, cur->apdu, cur->apdu_len);
+	}
+
+	if (cur->apdu_len > 235) { /* TODO: find out how much space we can use */
+		pri_message(ctrl, "Requested APDU (%d bytes) is too long\n", cur->apdu_len);
+		free(cur);
 		return 0;
 	}
 
-	memcpy(&ie->data[i], tmp->apdu, tmp->apdu_len);
-	i += tmp->apdu_len;
-	tmp->sent = 1;
-
-	return i + 2;
+	memcpy(ie->data, cur->apdu, cur->apdu_len);
+	apdu_len = cur->apdu_len;
+	free(cur);
+
+	return apdu_len + 2;
 }
 
 static int receive_facility(int full_ie, struct pri *ctrl, q931_call *call, int msgtype, q931_ie *ie, int len)
@@ -3372,7 +3380,7 @@
 		return 2 + ie->len;
 }
 
-static char *msg2str(int msg)
+const char *msg2str(int msg)
 {
 	unsigned int x;
 	for (x=0;x<sizeof(msgs) / sizeof(msgs[0]); x++) 
@@ -6765,13 +6773,11 @@
 		libpri_copy_string(ctrl->ev.ringing.useruserinfo, c->useruserinfo, sizeof(ctrl->ev.ringing.useruserinfo));
 		c->useruserinfo[0] = '\0';
 
-		cur = c->apdus;
-		while (cur) {
-			if (!cur->sent && cur->message == Q931_FACILITY) {
+		for (cur = c->apdus; cur; cur = cur->next) {
+			if (cur->message == Q931_FACILITY) {
 				q931_facility(ctrl, c);
 				break;
 			}
-			cur = cur->next;
 		}
 
 		return Q931_RES_HAVEEVENT;
@@ -6877,13 +6883,11 @@
 		ctrl->ev.proceeding.cref = c->cr;
 		ctrl->ev.proceeding.call = c->master_call;
 
-		cur = c->apdus;
-		while (cur) {
-			if (!cur->sent && cur->message == Q931_FACILITY) {
+		for (cur = c->apdus; cur; cur = cur->next) {
+			if (cur->message == Q931_FACILITY) {
 				q931_facility(ctrl, c);
 				break;
 			}
-			cur = cur->next;
 		}
 		return Q931_RES_HAVEEVENT;
 	case Q931_CONNECT_ACKNOWLEDGE:
@@ -7156,13 +7160,11 @@
 		ctrl->ev.setup_ack.channel = q931_encode_channel(c);
 		ctrl->ev.setup_ack.call = c->master_call;
 
-		cur = c->apdus;
-		while (cur) {
-			if (!cur->sent && cur->message == Q931_FACILITY) {
+		for (cur = c->apdus; cur; cur = cur->next) {
+			if (cur->message == Q931_FACILITY) {
 				q931_facility(ctrl, c);
 				break;
 			}
-			cur = cur->next;
 		}
 
 		return Q931_RES_HAVEEVENT;




More information about the libpri-commits mailing list