Index: pri_facility.c
===================================================================
RCS file: /usr/cvsroot/libpri/pri_facility.c,v
retrieving revision 1.5
diff -u -r1.5 pri_facility.c
--- pri_facility.c	2 Mar 2005 16:03:22 -0000	1.5
+++ pri_facility.c	10 Mar 2005 08:01:37 -0000
@@ -801,7 +801,7 @@
 		case SS_CNID_CALLINGNAME:
 			if (pri->debug & PRI_DEBUG_APDU)
 				pri_message("  Handle Name display operation\n");
-			switch (comp->type & PRI_DEBUG_APDU) {
+			switch (comp->type) {
 			case ROSE_NAME_PRESENTATION_ALLOWED_SIMPLE:
 				memcpy(call->callername, comp->data, comp->len);
 				call->callername[comp->len] = 0;
@@ -832,34 +832,27 @@
 
 extern int pri_call_apdu_queue(q931_call *call, int messagetype, void *apdu, int apdu_len, void (*function)(void *data), void *data)
 {
-	struct apdu_event *cur = NULL;
-	struct apdu_event *new_event = NULL;
+	struct apdu_event **cur;
+	struct apdu_event *new_event;
 
 	if (!call || !messagetype || !apdu || (apdu_len < 1) || (apdu_len > 255))
 		return -1;
 
 	new_event = malloc(sizeof(struct apdu_event));
-	memset(new_event, 0, sizeof(struct apdu_event));
-
-	if (new_event) {
-		new_event->message = messagetype;
-		new_event->callback = function;
-		new_event->data = data;
-		memcpy(new_event->apdu, apdu, apdu_len);
-		new_event->apdu_len = apdu_len;
-	} else {
+	if (!new_event) {
 		pri_error("malloc failed\n");
 		return -1;
 	}
-	
-	if (call->apdus) {
-		cur = call->apdus;
-		while (cur->next) {
-			cur = cur->next;
-		}
-		cur->next = new_event;
-	} else
-		call->apdus = new_event;
+
+	memset(new_event, 0, sizeof(struct apdu_event));
+	new_event->message = messagetype;
+	new_event->callback = function;
+	new_event->data = data;
+	memcpy(new_event->apdu, apdu, apdu_len);
+	new_event->apdu_len = apdu_len;
+
+	for (cur = &(call->apdus); *cur; cur = &((*cur)->next));
+	*cur = new_event;
 
 	return 0;
 }
@@ -873,8 +866,8 @@
 		while (cur_event) {
 			/* TODO: callbacks, some way of giving return res on status of apdu */
 			free_event = cur_event;
-			free(free_event);
 			cur_event = cur_event->next;
+			free(free_event);
 		}
 		call->apdus = NULL;
 	}
Index: testprilib.c
===================================================================
RCS file: /usr/cvsroot/libpri/testprilib.c,v
retrieving revision 1.5
diff -u -r1.5 testprilib.c
--- testprilib.c	2 Mar 2005 15:56:11 -0000	1.5
+++ testprilib.c	10 Mar 2005 08:01:37 -0000
@@ -76,7 +76,6 @@
 	int x;
 	static q931_call *calls[TEST_CALLS];
 	char name[256], num[256], dest[256];
-	struct pri_sr *sr;
 	switch(e->gen.e) {
 	case PRI_EVENT_DCHAN_UP:
 		printf("Network is up.  Sending blast of calls!\n");
@@ -89,15 +88,18 @@
 				continue;
 			}
 #if 0
-			sr = pri_sr_new();
-			pri_sr_set_channel(sr, x+1, 0, 0);
-			pri_sr_set_bearer(sr, 0, PRI_LAYER_1_ULAW);
-			pri_sr_set_called(sr, dest, PRI_NATIONAL_ISDN, 1);
-			pri_sr_set_caller(sr, num, name, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
-			pri_sr_set_redirecting(sr, num, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
-			if (pri_setup(pri, calls[x], sr))
-				perror("pri_setup");
-			pri_sr_free(sr);
+			{
+				struct pri_sr *sr;
+				sr = pri_sr_new();
+				pri_sr_set_channel(sr, x+1, 0, 0);
+				pri_sr_set_bearer(sr, 0, PRI_LAYER_1_ULAW);
+				pri_sr_set_called(sr, dest, PRI_NATIONAL_ISDN, 1);
+				pri_sr_set_caller(sr, num, name, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
+				pri_sr_set_redirecting(sr, num, PRI_NATIONAL_ISDN, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, PRI_REDIR_UNCONDITIONAL);
+				if (pri_setup(pri, calls[x], sr))
+					perror("pri_setup");
+				pri_sr_free(sr);
+			}
 #else
 			if (pri_call(pri, calls[x], PRI_TRANS_CAP_DIGITAL, x + 1, 1, 1, num, 
 				PRI_NATIONAL_ISDN, name, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN,
@@ -113,6 +115,10 @@
 		q931_facility(pri, e->ringing.call);
 		pri_answer(pri, e->ringing.call, e->ringing.channel, 0);
 		break;
+	case PRI_EVENT_HANGUP_REQ:
+		printf("PRI 1: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
+		pri_hangup(pri, e->hangup.call, e->hangup.cause);
+		break;
 	default:
 		printf("PRI 1: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
 	}
@@ -127,6 +133,14 @@
 		pri_proceeding(pri, e->ring.call, e->ring.channel, 0);
 		pri_acknowledge(pri, e->ring.call, e->ring.channel, 0);
 		break;
+	case PRI_EVENT_ANSWER:
+		printf("PRI 2: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
+		pri_hangup(pri, e->answer.call, PRI_CAUSE_NORMAL_UNSPECIFIED);
+		break;
+	case PRI_EVENT_HANGUP:
+		printf("PRI 2: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
+		pri_hangup(pri, e->hangup.call, e->hangup.cause);
+		break;
 	case PRI_EVENT_DCHAN_UP:
 	default:
 		printf("PRI 2: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
@@ -195,7 +209,7 @@
 	fd_set fds;
 	int res;
 	for(;;) {
-		if (next == pri_schedule_next(pri)) {
+		if ((next = pri_schedule_next(pri))) {
 			gettimeofday(&tv, NULL);
 			tv.tv_sec = next->tv_sec - tv.tv_sec;
 			tv.tv_usec = next->tv_usec - tv.tv_usec;
