[Asterisk-cvs] libpri libpri.h, 1.51, 1.52 pri.c, 1.36, 1.37 pri_facility.c, 1.12, 1.13 pri_facility.h, 1.5, 1.6 pri_internal.h, 1.22, 1.23 pri_q921.h, 1.12, 1.13 pri_q931.h, 1.21, 1.22 prisched.c, 1.4, 1.5 q921.c, 1.20, 1.21 q931.c, 1.125, 1.126

mattf at lists.digium.com mattf at lists.digium.com
Mon May 23 11:02:11 CDT 2005


Update of /usr/cvsroot/libpri
In directory mongoose.digium.com:/tmp/cvs-serv18240

Modified Files:
	libpri.h pri.c pri_facility.c pri_facility.h pri_internal.h 
	pri_q921.h pri_q931.h prisched.c q921.c q931.c 
Log Message:
PRI debug additions -- testing...


Index: libpri.h
===================================================================
RCS file: /usr/cvsroot/libpri/libpri.h,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- libpri.h	12 May 2005 14:48:00 -0000	1.51
+++ libpri.h	23 May 2005 15:06:33 -0000	1.52
@@ -526,8 +526,8 @@
 int pri_channel_bridge(q931_call *call1, q931_call *call2);
 
 /* Override message and error stuff */
-extern void pri_set_message(void (*__pri_error)(char *));
-extern void pri_set_error(void (*__pri_error)(char *));
+extern void pri_set_message(void (*__pri_error)(struct pri *pri, char *));
+extern void pri_set_error(void (*__pri_error)(struct pri *pri, char *));
 
 /* Set overlap mode */
 #define PRI_SET_OVERLAPDIAL

Index: pri.c
===================================================================
RCS file: /usr/cvsroot/libpri/pri.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- pri.c	12 May 2005 14:48:00 -0000	1.36
+++ pri.c	23 May 2005 15:06:33 -0000	1.37
@@ -158,7 +158,7 @@
 	int res = read(pri->fd, buf, buflen);
 	if (res < 0) {
 		if (errno != EAGAIN)
-			pri_error("Read on %d failed: %s\n", pri->fd, strerror(errno));
+			pri_error(pri, "Read on %d failed: %s\n", pri->fd, strerror(errno));
 		return 0;
 	}
 	return res;
@@ -169,7 +169,7 @@
 	int res = write(pri->fd, buf, buflen);
 	if (res < 0) {
 		if (errno != EAGAIN)
-			pri_error("Write to %d failed: %s\n", pri->fd, strerror(errno));
+			pri_error(pri, "Write to %d failed: %s\n", pri->fd, strerror(errno));
 		return 0;
 	}
 	return res;
@@ -536,26 +536,26 @@
 {
 	if (!pri || !e)
 		return;
-	pri_message("Event type: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
+	pri_message(pri, "Event type: %s (%d)\n", pri_event2str(e->gen.e), e->gen.e);
 	switch(e->gen.e) {
 	case PRI_EVENT_DCHAN_UP:
 	case PRI_EVENT_DCHAN_DOWN:
 		break;
 	case PRI_EVENT_CONFIG_ERR:
-		pri_message("Error: %s", e->err.err);
+		pri_message(pri, "Error: %s", e->err.err);
 		break;
 	case PRI_EVENT_RESTART:
-		pri_message("Restart on channel %d\n", e->restart.channel);
+		pri_message(pri, "Restart on channel %d\n", e->restart.channel);
 	case PRI_EVENT_RING:
-		pri_message("Calling number: %s (%s, %s)\n", e->ring.callingnum, pri_plan2str(e->ring.callingplan), pri_pres2str(e->ring.callingpres));
-		pri_message("Called number: %s (%s)\n", e->ring.callednum, pri_plan2str(e->ring.calledplan));
-		pri_message("Channel: %d (%s) Reference number: %d\n", e->ring.channel, e->ring.flexible ? "Flexible" : "Not Flexible", e->ring.cref);
+		pri_message(pri, "Calling number: %s (%s, %s)\n", e->ring.callingnum, pri_plan2str(e->ring.callingplan), pri_pres2str(e->ring.callingpres));
+		pri_message(pri, "Called number: %s (%s)\n", e->ring.callednum, pri_plan2str(e->ring.calledplan));
+		pri_message(pri, "Channel: %d (%s) Reference number: %d\n", e->ring.channel, e->ring.flexible ? "Flexible" : "Not Flexible", e->ring.cref);
 		break;
 	case PRI_EVENT_HANGUP:
-		pri_message("Hangup, reference number: %d, reason: %s\n", e->hangup.cref, pri_cause2str(e->hangup.cause));
+		pri_message(pri, "Hangup, reference number: %d, reason: %s\n", e->hangup.cref, pri_cause2str(e->hangup.cause));
 		break;
 	default:
-		pri_message("Don't know how to dump events of type %d\n", e->gen.e);
+		pri_message(pri, "Don't know how to dump events of type %d\n", e->gen.e);
 	}
 }
 
@@ -593,7 +593,7 @@
 	req.calledplan = calledplan;
 
 	if (mwi_message_send(pri, c, &req, 1) < 0) {
-		pri_message("Unable to send MWI activate message\n");
+		pri_message(pri, "Unable to send MWI activate message\n");
 		return -1;
 	}
 	/* Do more stuff when we figure out that the CISC stuff works */
@@ -618,7 +618,7 @@
 	req.calledplan = calledplan;
 
 	if(mwi_message_send(pri, c, &req, 0) < 0) {
-		pri_message("Unable to send MWI deactivate message\n");
+		pri_message(pri, "Unable to send MWI deactivate message\n");
 		return -1;
 	}
 
@@ -655,20 +655,20 @@
 	return q931_setup(pri, c, &req);
 }	
 
-static void (*__pri_error)(char *stuff);
-static void (*__pri_message)(char *stuff);
+static void (*__pri_error)(struct pri *pri, char *stuff);
+static void (*__pri_message)(struct pri *pri, char *stuff);
 
-void pri_set_message(void (*func)(char *stuff))
+void pri_set_message(void (*func)(struct pri *pri, char *stuff))
 {
 	__pri_message = func;
 }
 
-void pri_set_error(void (*func)(char *stuff))
+void pri_set_error(void (*func)(struct pri *pri, char *stuff))
 {
 	__pri_error = func;
 }
 
-void pri_message(char *fmt, ...)
+void pri_message(struct pri *pri, char *fmt, ...)
 {
 	char tmp[1024];
 	va_list ap;
@@ -676,12 +676,12 @@
 	vsnprintf(tmp, sizeof(tmp), fmt, ap);
 	va_end(ap);
 	if (__pri_message)
-		__pri_message(tmp);
+		__pri_message(pri, tmp);
 	else
 		fputs(tmp, stdout);
 }
 
-void pri_error(char *fmt, ...)
+void pri_error(struct pri *pri, char *fmt, ...)
 {
 	char tmp[1024];
 	va_list ap;
@@ -689,7 +689,7 @@
 	vsnprintf(tmp, sizeof(tmp), fmt, ap);
 	va_end(ap);
 	if (__pri_error)
-		__pri_error(tmp);
+		__pri_error(pri, tmp);
 	else
 		fputs(tmp, stderr);
 }

Index: pri_facility.c
===================================================================
RCS file: /usr/cvsroot/libpri/pri_facility.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- pri_facility.c	12 May 2005 14:48:00 -0000	1.12
+++ pri_facility.c	23 May 2005 15:06:33 -0000	1.13
@@ -33,7 +33,7 @@
 	int  pres;
 };
 
-static void dump_apdu(unsigned char *c, int len) 
+static void dump_apdu(struct pri *pri, unsigned char *c, int len) 
 {
 	#define MAX_APDU_LENGTH	255
 	int i;
@@ -53,7 +53,7 @@
 			snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, "%c", c[i]);
 	}
 	snprintf((char *)(message+strlen(message)), sizeof(message)-strlen(message)-1, "]\n");
-	pri_message(message);
+	pri_message(pri, message);
 }
 
 int redirectingreason_from_q931(struct pri *pri, int redirectingreason)
@@ -72,7 +72,7 @@
 				case PRI_REDIR_DEFLECTION:
 				case PRI_REDIR_DTE_OUT_OF_ORDER:
 				case PRI_REDIR_FORWARDED_BY_DTE:
-					pri_message("!! Don't know how to convert Q.931 redirection reason %d to Q.SIG\n", redirectingreason);
+					pri_message(pri, "!! Don't know how to convert Q.931 redirection reason %d to Q.SIG\n", redirectingreason);
 					/* Fall through */
 				default:
 					return QSIG_DIVERT_REASON_UNKNOWN;
@@ -91,7 +91,7 @@
 					return Q952_DIVERT_REASON_CFU;
 				case PRI_REDIR_DTE_OUT_OF_ORDER:
 				case PRI_REDIR_FORWARDED_BY_DTE:
-					pri_message("!! Don't know how to convert Q.931 redirection reason %d to Q.952\n", redirectingreason);
+					pri_message(pri, "!! Don't know how to convert Q.931 redirection reason %d to Q.952\n", redirectingreason);
 					/* Fall through */
 				default:
 					return Q952_DIVERT_REASON_UNKNOWN;
@@ -113,7 +113,7 @@
 				case QSIG_DIVERT_REASON_CFNR:
 					return PRI_REDIR_FORWARD_ON_NO_REPLY;
 				default:
-					pri_message("!! Unknown Q.SIG diversion reason %d\n", redirectingreason);
+					pri_message(pri, "!! Unknown Q.SIG diversion reason %d\n", redirectingreason);
 					return PRI_REDIR_UNKNOWN;
 			}
 		default:
@@ -129,10 +129,10 @@
 				case Q952_DIVERT_REASON_CD:
 					return PRI_REDIR_DEFLECTION;
 				case Q952_DIVERT_REASON_IMMEDIATE:
-					pri_message("!! Dont' know how to convert Q.952 diversion reason IMMEDIATE to PRI analog\n");
+					pri_message(pri, "!! Dont' know how to convert Q.952 diversion reason IMMEDIATE to PRI analog\n");
 					return PRI_REDIR_UNKNOWN;	/* ??? */
 				default:
-					pri_message("!! Unknown Q.952 diversion reason %d\n", redirectingreason);
+					pri_message(pri, "!! Unknown Q.952 diversion reason %d\n", redirectingreason);
 					return PRI_REDIR_UNKNOWN;
 			}
 	}
@@ -153,7 +153,7 @@
 			return Q932_TON_ABBREVIATED;
 		case PRI_TON_RESERVED:
 		default:
-			pri_message("!! Unsupported Q.931 TypeOfNumber value (%d)\n", ton);
+			pri_message(pri, "!! Unsupported Q.931 TypeOfNumber value (%d)\n", ton);
 			/* fall through */
 		case PRI_TON_UNKNOWN:
 			return Q932_TON_UNKNOWN;
@@ -176,7 +176,7 @@
 		case Q932_TON_ABBREVIATED:
 			return PRI_TON_ABBREVIATED;
 		default:
-			pri_message("!! Invalid Q.932 TypeOfNumber %d\n", ton);
+			pri_message(pri, "!! Invalid Q.932 TypeOfNumber %d\n", ton);
 			return PRI_TON_UNKNOWN;
 	}
 }
@@ -230,7 +230,7 @@
 		GET_COMPONENT(comp, i, vdata, len);
 		CHECK_COMPONENT(comp, ASN1_NUMERICSTRING, "Don't know what to do with PublicPartyNumber ROSE component type 0x%x\n");
 		if(comp->len > 20 && comp->len != ASN1_LEN_INDEF) {
-			pri_message("!! Oversized NumberDigits component (%d)\n", comp->len);
+			pri_message(pri, "!! Oversized NumberDigits component (%d)\n", comp->len);
 			return -1;
 		}
 		if (comp->len == ASN1_LEN_INDEF) {
@@ -303,14 +303,14 @@
 			value->npi = PRI_NPI_E163_E164;
 			break;
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2):	/* [2] nsapEncodedNumber */
-			pri_message("!! NsapEncodedNumber isn't handled\n");
+			pri_message(pri, "!! NsapEncodedNumber isn't handled\n");
 			return -1;
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_3):	/* [3] dataPartyNumber */
 			if(rose_number_digits_decode(pri, call, comp->data, comp->len, value))
 				return -1;
 			value->npi = PRI_NPI_X121 /* ??? */;
 			value->ton = PRI_TON_UNKNOWN /* ??? */;
-			pri_message("!! dataPartyNumber isn't handled\n");
+			pri_message(pri, "!! dataPartyNumber isn't handled\n");
 			return -1;
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_4):	/* [4] telexPartyNumber */
 			res = rose_number_digits_decode(pri, call, comp->data, comp->len, value);
@@ -318,10 +318,10 @@
 				return -1;
 			value->npi = PRI_NPI_F69 /* ??? */;
 			value->ton = PRI_TON_UNKNOWN /* ??? */;
-			pri_message("!! telexPartyNumber isn't handled\n");
+			pri_message(pri, "!! telexPartyNumber isn't handled\n");
 			return -1;
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_5):	/* [5] priavePartyNumber */
-			pri_message("!! privatePartyNumber isn't handled\n");
+			pri_message(pri, "!! privatePartyNumber isn't handled\n");
 			value->npi = PRI_NPI_PRIVATE;
 			return -1;
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_8):	/* [8] nationalStandardPartyNumber */
@@ -332,12 +332,12 @@
 			value->ton = PRI_TON_NATIONAL;
 			break;
 		default:
-			pri_message("!! Unknown Party number component received 0x%X\n", comp->type);
+			pri_message(pri, "!! Unknown Party number component received 0x%X\n", comp->type);
 			return -1;
 		}
 		NEXT_COMPONENT(comp, i);
 		if(i < len)
-			pri_message("!! not all information is handled from Address component\n");
+			pri_message(pri, "!! not all information is handled from Address component\n");
 		return res;
 	}
 	while (0);
@@ -365,14 +365,14 @@
 			return rose_address_decode(pri, call, comp->data, comp->len, value) + 2;
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1):		/* [1] IMPLICIT presentationRestricted */
 			if (comp->len != 0) { /* must be NULL */
-				pri_error("!! Invalid PresentationRestricted component received (len != 0)\n");
+				pri_error(pri, "!! Invalid PresentationRestricted component received (len != 0)\n");
 				return -1;
 			}
 			value->pres = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
 			return 2;
 		case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2):		/* [2] IMPLICIT numberNotAvailableDueToInterworking */
 			if (comp->len != 0) { /* must be NULL */
-				pri_error("!! Invalid NumberNotAvailableDueToInterworking component received (len != 0)\n");
+				pri_error(pri, "!! Invalid NumberNotAvailableDueToInterworking component received (len != 0)\n");
 				return -1;
 			}
 			value->pres = PRES_NUMBER_NOT_AVAILABLE;
@@ -381,7 +381,7 @@
 			value->pres = PRES_PROHIB_USER_NUMBER_NOT_SCREENED;
 			return rose_address_decode(pri, call, comp->data, comp->len, value) + 2;
 		default:
-			pri_message("Invalid PresentedNumberUnscreened component 0x%X\n", comp->type);
+			pri_message(pri, "Invalid PresentedNumberUnscreened component 0x%X\n", comp->type);
 		}
 		return -1;
 	}
@@ -418,7 +418,7 @@
 		diversion_reason = redirectingreason_for_q931(pri, diversion_reason);
 	
 		if(pri->debug & PRI_DEBUG_APDU)
-			pri_message("    Redirection reason: %d, total diversions: %d\n", diversion_reason, diversion_counter);
+			pri_message(pri, "    Redirection reason: %d, total diversions: %d\n", diversion_reason, diversion_counter);
 
 		for(; i < len; NEXT_COMPONENT(comp, i)) {
 			GET_COMPONENT(comp, i, vdata, len);
@@ -426,7 +426,7 @@
 			case ASN1_TAG_0:
 				call->origredirectingreason = redirectingreason_for_q931(pri, comp->data[0]);
 				if (pri->debug & PRI_DEBUG_APDU)
-					pri_message("    Received reason for original redirection %d\n", call->origredirectingreason);
+					pri_message(pri, "    Received reason for original redirection %d\n", call->origredirectingreason);
 				break;
 			case ASN1_TAG_1:		/* divertingnr: presentednumberunscreened */
 				res = rose_presented_number_unscreened_decode(pri, call, comp->data, comp->len, &divertingnr);
@@ -435,8 +435,8 @@
 				if (res < 0)
 					return -1;
 				if (pri->debug & PRI_DEBUG_APDU) {
-					pri_message("    Received divertingNr '%s'\n", divertingnr.partyaddress);
-					pri_message("      ton = %d, pres = %d, npi = %d\n", divertingnr.ton, divertingnr.pres, divertingnr.npi);
+					pri_message(pri, "    Received divertingNr '%s'\n", divertingnr.partyaddress);
+					pri_message(pri, "      ton = %d, pres = %d, npi = %d\n", divertingnr.ton, divertingnr.pres, divertingnr.npi);
 				}
 				break;
 			case ASN1_TAG_2:		/* originalCalledNr: PresentedNumberUnscreened */
@@ -445,22 +445,22 @@
 					return -1;
 				comp->len = res;
 				if (pri->debug & PRI_DEBUG_APDU) {
-					pri_message("    Received originalcallednr '%s'\n", originalcallednr.partyaddress);
-					pri_message("      ton = %d, pres = %d, npi = %d\n", originalcallednr.ton, originalcallednr.pres, originalcallednr.npi);
+					pri_message(pri, "    Received originalcallednr '%s'\n", originalcallednr.partyaddress);
+					pri_message(pri, "      ton = %d, pres = %d, npi = %d\n", originalcallednr.ton, originalcallednr.pres, originalcallednr.npi);
 				}
 				break;
 			case ASN1_TAG_3:
 				comp->len = asn1_name_decode(comp->data, comp->len, redirectingname, sizeof(redirectingname));
 				if (pri->debug & PRI_DEBUG_APDU)
-					pri_message("    Received RedirectingName '%s'\n", redirectingname);
+					pri_message(pri, "    Received RedirectingName '%s'\n", redirectingname);
 				break;
 			case ASN1_TAG_4:
 				comp->len = asn1_name_decode(comp->data, comp->len, origcalledname, sizeof(origcalledname));
 				if (pri->debug & PRI_DEBUG_APDU)
-					pri_message("    Received Originally Called Name '%s'\n", origcalledname);
+					pri_message(pri, "    Received Originally Called Name '%s'\n", origcalledname);
 				break;
 			default:
-				pri_message("!! Invalid DivertingLegInformation2 component received 0x%X\n", comp->type);
+				pri_message(pri, "!! Invalid DivertingLegInformation2 component received 0x%X\n", comp->type);
 				return -1;
 			}
 		}
@@ -570,7 +570,7 @@
 			ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i);
 			break;
 		default:
-			pri_message("!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres);
+			pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres);
 		case PRES_NUMBER_NOT_AVAILABLE:
 			ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i);
 			break;
@@ -614,7 +614,7 @@
 			ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1), buffer, i);
 			break;
 		default:
-			pri_message("!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres);
+			pri_message(pri, "!! Undefined presentation value for redirecting number: %d\n", call->redirectingpres);
 		case PRES_NUMBER_NOT_AVAILABLE:
 			ASN1_ADD_SIMPLE(comp, (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_2), buffer, i);
 			break;
@@ -841,7 +841,7 @@
 
 	res = pri_call_apdu_queue(c1, Q931_FACILITY, buffer, i, NULL, NULL);
 	if (res) {
-		pri_message("Could not queue ADPU in facility message\n");
+		pri_message(pri, "Could not queue ADPU in facility message\n");
 		return -1;
 	}
 
@@ -850,7 +850,7 @@
 
 	res = q931_facility(c1->pri, c1);
 	if (res) {
-		pri_message("Could not schedule facility message for call %d\n", c1->cr);
+		pri_message(pri, "Could not schedule facility message for call %d\n", c1->cr);
 		return -1;
 	}
 
@@ -867,7 +867,7 @@
 	int pos1 = 0;
 
 	if (pri->debug & PRI_DEBUG_AOC)
-		dump_apdu (data, len);
+		dump_apdu (pri, data, len);
 
 	do {
 		GET_COMPONENT(comp, pos1, vdata, len);
@@ -875,17 +875,17 @@
 		ASN1_GET_INTEGER(comp, chargingcase);				
 		if (chargingcase >= 0 && chargingcase <= 2) {
 			if (pri->debug & PRI_DEBUG_APDU)
-				pri_message("Channel %d/%d, Call %d  - received AOC charging request - charging case: %i\n", 
+				pri_message(pri, "Channel %d/%d, Call %d  - received AOC charging request - charging case: %i\n", 
 					call->ds1no, call->channelno, call->cr, chargingcase);
 		} else {
-			pri_message("!! unkown AOC ChargingCase: 0x%02X", chargingcase);
+			pri_message(pri, "!! unkown AOC ChargingCase: 0x%02X", chargingcase);
 			chargingcase = -1;
 		}
 		NEXT_COMPONENT(comp, pos1);
 	} while (pos1 < len);
 	if (pos1 < len) {
-		pri_message("!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len );
-		dump_apdu (data, len);
+		pri_message(pri, "!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len );
+		dump_apdu (pri, data, len);
 		return -1;	/* Aborted before */
 	}
 	return 0;
@@ -901,7 +901,7 @@
 	struct addressingdataelements_presentednumberunscreened chargednr;
 
 	if (pri->debug & PRI_DEBUG_AOC)
-		dump_apdu (data, len);
+		dump_apdu (pri, data, len);
 
 	do {
 		GET_COMPONENT(comp1, pos1, vdata, len);	/* AOCEChargingUnitInfo */
@@ -934,34 +934,34 @@
 									case ASN1_NULL:		/* notAvailable */
 										break;
 									default:
-										pri_message("!! Don't know how to handle 0x%02X in AOC-E RecordedUnits\n", comp3->type);
+										pri_message(pri, "!! Don't know how to handle 0x%02X in AOC-E RecordedUnits\n", comp3->type);
 								}
 								NEXT_COMPONENT(comp3, pos3);
 							} while (pos3 < sublen3);
 							if (pri->debug & PRI_DEBUG_AOC)
-								pri_message("Channel %d/%d, Call %d - received AOC-E charging: %i unit%s\n", 
+								pri_message(pri, "Channel %d/%d, Call %d - received AOC-E charging: %i unit%s\n", 
 									call->ds1no, call->channelno, call->cr, chargingunits, (chargingunits == 1) ? "" : "s");
 							break;
 						case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_2):	/* AOCEBillingID (0xA2) */
 							SUB_COMPONENT(comp2, pos2);
 							GET_COMPONENT(comp2, pos2, vdata, len);
 							ASN1_GET_INTEGER(comp2, chargetype);
-							pri_message("!! not handled: Channel %d/%d, Call %d - received AOC-E billing ID: %i\n", 
+							pri_message(pri, "!! not handled: Channel %d/%d, Call %d - received AOC-E billing ID: %i\n", 
 								call->ds1no, call->channelno, call->cr, chargetype);
 							break;
 						default:
-							pri_message("!! Don't know how to handle 0x%02X in AOC-E RecordedUnitsList\n", comp2->type);
+							pri_message(pri, "!! Don't know how to handle 0x%02X in AOC-E RecordedUnitsList\n", comp2->type);
 					}
 					NEXT_COMPONENT(comp2, pos2);
 				} while (pos2 < sublen2);
 				break;
 			case (ASN1_CONTEXT_SPECIFIC | ASN1_TAG_1): /* freeOfCharge (0x81) */
 				if (pri->debug & PRI_DEBUG_AOC)
-					pri_message("Channel %d/%d, Call %d - received AOC-E free of charge\n", call->ds1no, call->channelno, call->cr);
+					pri_message(pri, "Channel %d/%d, Call %d - received AOC-E free of charge\n", call->ds1no, call->channelno, call->cr);
 				chargingunits = 0;
 				break;
 			default:
-				pri_message("!! Invalid AOC-E specificChargingUnits. Expected Sequence (0x30) or Object Identifier (0x81/0x01) but received 0x%02X\n", comp1->type);
+				pri_message(pri, "!! Invalid AOC-E specificChargingUnits. Expected Sequence (0x30) or Object Identifier (0x81/0x01) but received 0x%02X\n", comp1->type);
 		}
 		NEXT_COMPONENT(comp1, pos1);
 		GET_COMPONENT(comp1, pos1, vdata, len); /* get optional chargingAssociation. will 'break' when reached end of structure */
@@ -970,21 +970,21 @@
 			case (ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTOR | ASN1_TAG_0): /* chargedNumber (0xA0) */
 				if(rose_presented_number_unscreened_decode(pri, call, comp1->data, comp1->len, &chargednr) != 0)
 					return -1;
-				pri_message("!! not handled: Received ChargedNr '%s' \n", chargednr.partyaddress);
-				pri_message("  ton = %d, pres = %d, npi = %d\n", chargednr.ton, chargednr.pres, chargednr.npi);
+				pri_message(pri, "!! not handled: Received ChargedNr '%s' \n", chargednr.partyaddress);
+				pri_message(pri, "  ton = %d, pres = %d, npi = %d\n", chargednr.ton, chargednr.pres, chargednr.npi);
 				break;
 			case ASN1_INTEGER:
 				ASN1_GET_INTEGER(comp1, chargeIdentifier);
 				break;
 			default:
-				pri_message("!! Invalid AOC-E chargingAssociation. Expected Object Identifier (0xA0) or Integer (0x02) but received 0x%02X\n", comp1->type);
+				pri_message(pri, "!! Invalid AOC-E chargingAssociation. Expected Object Identifier (0xA0) or Integer (0x02) but received 0x%02X\n", comp1->type);
 		}
 		NEXT_COMPONENT(comp1, pos1);
 	} while (pos1 < len);
 
 	if (pos1 < len) {
-		pri_message("!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len );
-		dump_apdu (data, len);
+		pri_message(pri, "!! Only reached position %i in %i bytes long AOC-E structure:", pos1, len );
+		dump_apdu (pri, data, len);
 		return -1;	/* oops - aborted before */
 	}
 	call->aoc_units = chargingunits;
@@ -1043,12 +1043,12 @@
 	ASN1_FIXUP(compstk, compsp, buffer, i); 
 	
 	if (pri->debug & PRI_DEBUG_AOC)
-		dump_apdu (buffer, i);
+		dump_apdu (pri, buffer, i);
 		
 	/* code below is untested */
 	res = pri_call_apdu_queue(c, Q931_FACILITY, buffer, i, NULL, NULL);
 	if (res) {
-		pri_message("Could not queue ADPU in facility message\n");
+		pri_message(pri, "Could not queue ADPU in facility message\n");
 		return -1;
 	}
 
@@ -1056,7 +1056,7 @@
 	 * have to explicitly send the facility message ourselves */
 	res = q931_facility(c->pri, c);
 	if (res) {
-		pri_message("Could not schedule facility message for call %d\n", c->cr);
+		pri_message(pri, "Could not schedule facility message for call %d\n", c->cr);
 		return -1;
 	}
 
@@ -1095,68 +1095,68 @@
 			return -1;
 
 		if (pri->debug & PRI_DEBUG_APDU)
-			pri_message("  [ Handling operation %d ]\n", operation_tag);
+			pri_message(pri, "  [ Handling operation %d ]\n", operation_tag);
 		switch (operation_tag) {
 		case SS_CNID_CALLINGNAME:
 			if (pri->debug & PRI_DEBUG_APDU)
-				pri_message("  Handle Name display operation\n");
+				pri_message(pri, "  Handle Name display operation\n");
 			switch (comp->type) {
 				case ROSE_NAME_PRESENTATION_ALLOWED_SIMPLE:
 					memcpy(call->callername, comp->data, comp->len);
 					call->callername[comp->len] = 0;
 					if (pri->debug & PRI_DEBUG_APDU)
-						pri_message("    Received caller name '%s'\n", call->callername);
+						pri_message(pri, "    Received caller name '%s'\n", call->callername);
 					return 0;
 				default:
 					if (pri->debug & PRI_DEBUG_APDU)
-						pri_message("Do not handle argument of type 0x%X\n", comp->type);
+						pri_message(pri, "Do not handle argument of type 0x%X\n", comp->type);
 					return -1;
 			}
 			break;
 		case ROSE_DIVERTING_LEG_INFORMATION2:
 			if (pri->debug & PRI_DEBUG_APDU)
-				pri_message("  Handle DivertingLegInformation2\n");
+				pri_message(pri, "  Handle DivertingLegInformation2\n");
 			if (comp->type != (ASN1_CONSTRUCTOR | ASN1_SEQUENCE)) { /* Constructed Sequence */
-				pri_message("Invalid DivertingLegInformation2Type argument\n");
+				pri_message(pri, "Invalid DivertingLegInformation2Type argument\n");
 				return -1;
 			}
 			return rose_diverting_leg_information2_decode(pri, call, comp->data, comp->len);
 		case ROSE_AOC_NO_CHARGING_INFO_AVAILABLE:
 			if (pri->debug & PRI_DEBUG_APDU) {
-				pri_message("ROSE %i: AOC No Charging Info Available - not handled!", operation_tag);
-				dump_apdu (comp->data, comp->len);
+				pri_message(pri, "ROSE %i: AOC No Charging Info Available - not handled!", operation_tag);
+				dump_apdu (pri, comp->data, comp->len);
 			}
 			return -1;
 		case ROSE_AOC_CHARGING_REQUEST:
 			return aoc_aoce_charging_request_decode(pri, call, (u_int8_t *)comp, comp->len + 2);
 		case ROSE_AOC_AOCS_CURRENCY:
 			if (pri->debug & PRI_DEBUG_APDU) {
-				pri_message("ROSE %i: AOC-S Currency - not handled!", operation_tag);
-				dump_apdu ((u_int8_t *)comp, comp->len + 2);
+				pri_message(pri, "ROSE %i: AOC-S Currency - not handled!", operation_tag);
+				dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 			}
 			return -1;
 		case ROSE_AOC_AOCS_SPECIAL_ARR:
 			if (pri->debug & PRI_DEBUG_APDU) {
-				pri_message("ROSE %i: AOC-S Special Array - not handled!", operation_tag);
-				dump_apdu ((u_int8_t *)comp, comp->len + 2);
+				pri_message(pri, "ROSE %i: AOC-S Special Array - not handled!", operation_tag);
+				dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 			}
 			return -1;
 		case ROSE_AOC_AOCD_CURRENCY:
 			if (pri->debug & PRI_DEBUG_APDU) {
-				pri_message("ROSE %i: AOC-D Currency - not handled!", operation_tag);
-				dump_apdu ((u_int8_t *)comp, comp->len + 2);
+				pri_message(pri, "ROSE %i: AOC-D Currency - not handled!", operation_tag);
+				dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 			}
 			return -1;
 		case ROSE_AOC_AOCD_CHARGING_UNIT:
 			if (pri->debug & PRI_DEBUG_APDU) {
-				pri_message("ROSE %i: AOC-D Charging Unit - not handled!", operation_tag);
-				dump_apdu ((u_int8_t *)comp, comp->len + 2);
+				pri_message(pri, "ROSE %i: AOC-D Charging Unit - not handled!", operation_tag);
+				dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 			}
 			return -1;
 		case ROSE_AOC_AOCE_CURRENCY:
 			if (pri->debug & PRI_DEBUG_APDU) {
-				pri_message("ROSE %i: AOC-E Currency - not handled!", operation_tag);
-				dump_apdu ((u_int8_t *)comp, comp->len + 2);
+				pri_message(pri, "ROSE %i: AOC-E Currency - not handled!", operation_tag);
+				dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 			}
 			return -1;
 		case ROSE_AOC_AOCE_CHARGING_UNIT:
@@ -1167,14 +1167,14 @@
 			}
 		case ROSE_AOC_IDENTIFICATION_OF_CHARGE:
 			if (pri->debug & PRI_DEBUG_APDU) {
-				pri_message("ROSE %i: AOC Identification Of Charge - not handled!", operation_tag);
-				dump_apdu ((u_int8_t *)comp, comp->len + 2);
+				pri_message(pri, "ROSE %i: AOC Identification Of Charge - not handled!", operation_tag);
+				dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 			}
 			return -1;
 		default:
 			if (pri->debug & PRI_DEBUG_APDU) {
-				pri_message("!! Unable to handle ROSE operation %d", operation_tag);
-				dump_apdu ((u_int8_t *)comp, comp->len + 2);
+				pri_message(pri, "!! Unable to handle ROSE operation %d", operation_tag);
+				dump_apdu (pri, (u_int8_t *)comp, comp->len + 2);
 			}
 			return -1;
 		}
@@ -1201,7 +1201,7 @@
 		memcpy(new_event->apdu, apdu, apdu_len);
 		new_event->apdu_len = apdu_len;
 	} else {
-		pri_error("!! Malloc failed!\n");
+		pri_error(call->pri, "!! Malloc failed!\n");
 		return -1;
 	}
 	

Index: pri_facility.h
===================================================================
RCS file: /usr/cvsroot/libpri/pri_facility.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- pri_facility.h	6 Apr 2005 19:42:41 -0000	1.5
+++ pri_facility.h	23 May 2005 15:06:33 -0000	1.6
@@ -147,7 +147,7 @@
 	(component) = (struct rose_component*)&((ptr)[idx]); \
 	if ((idx)+(component)->len+2 > (length)) { \
 		if ((component)->len != 128) \
-			pri_message("Length (%d) of 0x%X component is too long\n", (component)->len, (component)->type); \
+			pri_message(pri, "Length (%d) of 0x%X component is too long\n", (component)->len, (component)->type); \
 	}
 /*
 	pri_message("XX Got component %d (0x%02X), length %d\n", (component)->type, (component)->type, (component)->len); \
@@ -168,7 +168,7 @@
 
 #define CHECK_COMPONENT(component, comptype, message) \
 	if ((component)->type && ((component)->type & ASN1_TYPE_MASK) != (comptype)) { \
-		pri_message((message), (component)->type); \
+		pri_message(pri, (message), (component)->type); \
 		break; \
 	}
 	

Index: pri_internal.h
===================================================================
RCS file: /usr/cvsroot/libpri/pri_internal.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- pri_internal.h	19 May 2005 14:06:43 -0000	1.22
+++ pri_internal.h	23 May 2005 15:06:33 -0000	1.23
@@ -246,8 +246,8 @@
 
 extern pri_event *pri_mkerror(struct pri *pri, char *errstr);
 
-extern void pri_message(char *fmt, ...);
+extern void pri_message(struct pri *pri, char *fmt, ...);
 
-extern void pri_error(char *fmt, ...);
+extern void pri_error(struct pri *pri, char *fmt, ...);
 
 #endif

Index: pri_q921.h
===================================================================
RCS file: /usr/cvsroot/libpri/pri_q921.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- pri_q921.h	20 Apr 2005 15:23:35 -0000	1.12
+++ pri_q921.h	23 May 2005 15:06:33 -0000	1.13
@@ -161,7 +161,7 @@
 } q921_state;
 
 /* Dumps a *known good* Q.921 packet */
-extern void q921_dump(q921_h *h, int len, int showraw, int txrx);
+extern void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx);
 
 /* Bring up the D-channel */
 extern void q921_start(struct pri *pri, int now);

Index: pri_q931.h
===================================================================
RCS file: /usr/cvsroot/libpri/pri_q931.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- pri_q931.h	20 Apr 2005 15:23:35 -0000	1.21
+++ pri_q931.h	23 May 2005 15:06:33 -0000	1.22
@@ -276,7 +276,7 @@
 extern q931_call *q931_new_call(struct pri *pri);
 
 extern int q931_setup(struct pri *pri, q931_call *c, struct pri_sr *req);
-extern void q931_dump(q931_h *h, int len, int txrx);
+extern void q931_dump(struct pri *pri, q931_h *h, int len, int txrx);
 
 extern void __q931_destroycall(struct pri *pri, q931_call *c);
 	

Index: prisched.c
===================================================================
RCS file: /usr/cvsroot/libpri/prisched.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- prisched.c	5 Jun 2004 06:50:55 -0000	1.4
+++ prisched.c	23 May 2005 15:06:33 -0000	1.5
@@ -38,7 +38,7 @@
 		if (!pri->pri_sched[x].callback)
 			break;
 	if (x == MAX_SCHED) {
-		pri_error("No more room in scheduler\n");
+		pri_error(pri, "No more room in scheduler\n");
 		return -1;
 	}
 	if (x > maxsched)
@@ -113,6 +113,6 @@
 void pri_schedule_del(struct pri *pri,int id)
 {
 	if ((id >= MAX_SCHED) || (id < 0)) 
-		pri_error("Asked to delete sched id %d???\n", id);
+		pri_error(pri, "Asked to delete sched id %d???\n", id);
 	pri->pri_sched[id].callback = NULL;
 }

Index: q921.c
===================================================================
RCS file: /usr/cvsroot/libpri/q921.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- q921.c	17 Mar 2005 15:46:23 -0000	1.20
+++ q921.c	23 May 2005 15:06:33 -0000	1.21
@@ -72,7 +72,7 @@
 		return q921_transmit(pri->master, h, len);
 #ifdef RANDOM_DROPS
    if (!(random() % 3)) {
-         pri_message(" === Dropping Packet ===\n");
+         pri_message(pri, " === Dropping Packet ===\n");
          return 0;
    }
 #endif   
@@ -81,11 +81,11 @@
 #endif
 	/* Just send it raw */
 	if (pri->debug & PRI_DEBUG_Q921_DUMP)
-		q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1);
+		q921_dump(pri, h, len, pri->debug & PRI_DEBUG_Q921_RAW, 1);
 	/* Write an extra two bytes for the FCS */
 	res = pri->write_func ? pri->write_func(pri, h, len + 2) : 0;
 	if (res != (len + 2)) {
-		pri_error("Short write: %d/%d (%s)\n", res, len + 2, strerror(errno));
+		pri_error(pri, "Short write: %d/%d (%s)\n", res, len + 2, strerror(errno));
 		return -1;
 	}
 	reschedule_t203(pri);
@@ -108,11 +108,11 @@
 		h.h.c_r = 1;
 		break;
 	default:
-		pri_error("Don't know how to U/A on a type %d node\n", pri->localtype);
+		pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
 		return;
 	}
 	if (pri->debug & PRI_DEBUG_Q921_STATE)
-		pri_message("Sending Unnumbered Acknowledgement\n");
+		pri_message(pri, "Sending Unnumbered Acknowledgement\n");
 	q921_transmit(pri, &h, 3);
 }
 
@@ -140,11 +140,11 @@
 		h.h.c_r = 0;
 		break;
 	default:
-		pri_error("Don't know how to U/A on a type %d node\n", pri->localtype);
+		pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
 		return;
 	}
 	if (pri->debug & PRI_DEBUG_Q921_STATE)
-		pri_message("Sending Set Asynchronous Balanced Mode Extended\n");
+		pri_message(pri, "Sending Set Asynchronous Balanced Mode Extended\n");
 	q921_transmit(pri, &h, 3);
 	pri->q921_state = Q921_AWAITING_ESTABLISH;
 }
@@ -167,7 +167,7 @@
 			else
 				pri->txqueue = f->next;
 			if (pri->debug & PRI_DEBUG_Q921_STATE)
-				pri_message("-- ACKing packet %d, new txqueue is %d (-1 means empty)\n", f->h.n_s, pri->txqueue ? pri->txqueue->h.n_s : -1);
+				pri_message(pri, "-- ACKing packet %d, new txqueue is %d (-1 means empty)\n", f->h.n_s, pri->txqueue ? pri->txqueue->h.n_s : -1);
 			/* Update v_a */
 			pri->v_a = num;
 			free(f);
@@ -181,7 +181,7 @@
 				if (!f->transmitted) {
 					/* Send it now... */
 					if (pri->debug & PRI_DEBUG_Q921_STATE)
-						pri_message("-- Finally transmitting %d, since window opened up\n", f->h.n_s);
+						pri_message(pri, "-- Finally transmitting %d, since window opened up\n", f->h.n_s);
 					f->transmitted++;
 					pri->windowlen++;
 					f->h.n_r = pri->v_r;
@@ -207,7 +207,7 @@
 	if (pri->t203_timer) {
 		pri_schedule_del(pri, pri->t203_timer);
 		if (pri->debug &  PRI_DEBUG_Q921_STATE)
-			pri_message("-- Restarting T203 counter\n");
+			pri_message(pri, "-- Restarting T203 counter\n");
 		/* Nothing to transmit, start the T203 counter instead */
 		pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
 	}
@@ -222,7 +222,7 @@
 	for (x=pri->v_a; (x != pri->v_s) && (x != ack); Q921_INC(x));
 	if (x != ack) {
 		/* ACK was outside of our window --- ignore */
-		pri_error("ACK received for '%d' outside of window of '%d' to '%d', restarting\n", ack, pri->v_a, pri->v_s);
+		pri_error(pri, "ACK received for '%d' outside of window of '%d' to '%d', restarting\n", ack, pri->v_a, pri->v_s);
 		ev = q921_dchannel_down(pri);
 		q921_start(pri, 1);
 		pri->schedev = 1;
@@ -230,31 +230,31 @@
 	}
 	/* Cancel each packet as necessary */
 	if (pri->debug & PRI_DEBUG_Q921_STATE)
-		pri_message("-- ACKing all packets from %d to (but not including) %d\n", pri->v_a, ack);
+		pri_message(pri, "-- ACKing all packets from %d to (but not including) %d\n", pri->v_a, ack);
 	for (x=pri->v_a; x != ack; Q921_INC(x)) 
 		cnt += q921_ack_packet(pri, x);	
 	if (!pri->txqueue) {
 		if (pri->debug &  PRI_DEBUG_Q921_STATE)
-			pri_message("-- Since there was nothing left, stopping T200 counter\n");
+			pri_message(pri, "-- Since there was nothing left, stopping T200 counter\n");
 		/* Something was ACK'd.  Stop T200 counter */
 		pri_schedule_del(pri, pri->t200_timer);
 		pri->t200_timer = 0;
 	}
 	if (pri->t203_timer) {
 		if (pri->debug &  PRI_DEBUG_Q921_STATE)
-			pri_message("-- Stopping T203 counter since we got an ACK\n");
+			pri_message(pri, "-- Stopping T203 counter since we got an ACK\n");
 		pri_schedule_del(pri, pri->t203_timer);
 		pri->t203_timer = 0;
 	}
 	if (pri->txqueue) {
 		/* Something left to transmit, Start the T200 counter again if we stopped it */
 		if (pri->debug &  PRI_DEBUG_Q921_STATE)
-			pri_message("-- Something left to transmit (%d), restarting T200 counter\n", pri->txqueue->h.n_s);
+			pri_message(pri, "-- Something left to transmit (%d), restarting T200 counter\n", pri->txqueue->h.n_s);
 		if (!pri->t200_timer)
 			pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
 	} else {
 		if (pri->debug &  PRI_DEBUG_Q921_STATE)
-			pri_message("-- Nothing left, starting T203 counter\n");
+			pri_message(pri, "-- Nothing left, starting T203 counter\n");
 		/* Nothing to transmit, start the T203 counter instead */
 		pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T203], t203_expire, pri);
 	}
@@ -278,11 +278,11 @@
 		h.h.c_r = 1;
 		break;
 	default:
-		pri_error("Don't know how to U/A on a type %d node\n", pri->localtype);
+		pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
 		return;
 	}
 	if (pri->debug & PRI_DEBUG_Q921_STATE)
-		pri_message("Sending Reject (%d)\n", pri->v_r);
+		pri_message(pri, "Sending Reject (%d)\n", pri->v_r);
 	pri->sentrej = 1;
 	q921_transmit(pri, &h, 4);
 }
@@ -309,12 +309,12 @@
 			h.h.c_r = 1;
 		break;
 	default:
-		pri_error("Don't know how to U/A on a type %d node\n", pri->localtype);
+		pri_error(pri, "Don't know how to U/A on a type %d node\n", pri->localtype);
 		return;
 	}
 	pri->v_na = pri->v_r;	/* Make a note that we've already acked this */
 	if (pri->debug & PRI_DEBUG_Q921_STATE)
-		pri_message("Sending Receiver Ready (%d)\n", pri->v_r);
+		pri_message(pri, "Sending Receiver Ready (%d)\n", pri->v_r);
 	q921_transmit(pri, &h, 4);
 }
 
@@ -324,7 +324,7 @@
 	if (pri->txqueue) {
 		/* Retransmit first packet in the queue, setting the poll bit */
 		if (pri->debug & PRI_DEBUG_Q921_STATE)
-			pri_message("-- T200 counter expired, What to do...\n");
+			pri_message(pri, "-- T200 counter expired, What to do...\n");
 		/* Force Poll bit */
 		pri->txqueue->h.p_f = 1;	
 		/* Update nr */
@@ -336,20 +336,20 @@
       if (pri->retrans < pri->timers[PRI_TIMER_N200]) {
          /* Reschedule t200_timer */
          if (pri->debug & PRI_DEBUG_Q921_STATE)
-            pri_message("-- Retransmitting %d bytes\n", pri->txqueue->len);
+            pri_message(pri, "-- Retransmitting %d bytes\n", pri->txqueue->len);
 		if (pri->busy) 
 			q921_rr(pri, 1, 0);
 		else {
 			if (!pri->txqueue->transmitted) 
-				pri_error("!! Not good - head of queue has not been transmitted yet\n");
+				pri_error(pri, "!! Not good - head of queue has not been transmitted yet\n");
 			q921_transmit(pri, (q921_h *)&pri->txqueue->h, pri->txqueue->len);
 		}
          if (pri->debug & PRI_DEBUG_Q921_STATE) 
-               pri_message("-- Rescheduling retransmission (%d)\n", pri->retrans);
+               pri_message(pri, "-- Rescheduling retransmission (%d)\n", pri->retrans);
          pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
       } else {
          if (pri->debug & PRI_DEBUG_Q921_STATE) 
-               pri_message("-- Timeout occured, restarting PRI\n");
+               pri_message(pri, "-- Timeout occured, restarting PRI\n");
          pri->q921_state = Q921_LINK_CONNECTION_RELEASED;
       	pri->t200_timer = 0;
          q921_dchannel_down(pri);
@@ -358,7 +358,7 @@
       }
 	} else if (pri->solicitfbit) {
          if (pri->debug & PRI_DEBUG_Q921_STATE)
-            pri_message("-- Retrying poll with f-bit\n");
+            pri_message(pri, "-- Retrying poll with f-bit\n");
 		pri->retrans++;
 		if (pri->retrans < pri->timers[PRI_TIMER_N200]) {
 			pri->solicitfbit = 1;
@@ -366,7 +366,7 @@
 			pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
 		} else {
 			if (pri->debug & PRI_DEBUG_Q921_STATE) 
-				pri_message("-- Timeout occured, restarting PRI\n");
+				pri_message(pri, "-- Timeout occured, restarting PRI\n");
 			pri->q921_state = Q921_LINK_CONNECTION_RELEASED;
 			pri->t200_timer = 0;
 			q921_dchannel_down(pri);
@@ -374,7 +374,7 @@
 			pri->schedev = 1;
 		}
 	} else {
-		pri_error("T200 counter expired, nothing to send...\n");
+		pri_error(pri, "T200 counter expired, nothing to send...\n");
 	   	pri->t200_timer = 0;
 	}
 }
@@ -424,26 +424,26 @@
 				f->transmitted++;
 			} else {
 				if (pri->debug & PRI_DEBUG_Q921_STATE)
-					pri_message("Delaying transmission of %d, window is %d/%d long\n", 
+					pri_message(pri, "Delaying transmission of %d, window is %d/%d long\n", 
 						f->h.n_s, pri->windowlen, pri->window);
 			}
 		}
 		if (pri->t203_timer) {
 			if (pri->debug & PRI_DEBUG_Q921_STATE)
-				pri_message("Stopping T_203 timer\n");
+				pri_message(pri, "Stopping T_203 timer\n");
 			pri_schedule_del(pri, pri->t203_timer);
 			pri->t203_timer = 0;
 		}
 		if (!pri->t200_timer) {
 			if (pri->debug & PRI_DEBUG_Q921_STATE)
-				pri_message("Starting T_200 timer\n");
+				pri_message(pri, "Starting T_200 timer\n");
 			pri->t200_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
 		} else
 			if (pri->debug & PRI_DEBUG_Q921_STATE)
-				pri_message("T_200 timer already going (%d)\n", pri->t200_timer);
+				pri_message(pri, "T_200 timer already going (%d)\n", pri->t200_timer);
 		
 	} else {
-		pri_error("!! Out of memory for Q.921 transmit\n");
+		pri_error(pri, "!! Out of memory for Q.921 transmit\n");
 		return -1;
 	}
 	return 0;
@@ -454,7 +454,7 @@
 	struct pri *pri = vpri;
 	if (pri->q921_state == Q921_LINK_CONNECTION_ESTABLISHED) {
 		if (pri->debug &  PRI_DEBUG_Q921_STATE)
-			pri_message("T203 counter expired, sending RR and scheduling T203 again\n");
+			pri_message(pri, "T203 counter expired, sending RR and scheduling T203 again\n");
 		/* Solicit an F-bit in the other's RR */
 		pri->solicitfbit = 1;
 		pri->retrans = 0;
@@ -463,7 +463,7 @@
 		pri->t203_timer = pri_schedule_event(pri, pri->timers[PRI_TIMER_T200], t200_expire, pri);
 	} else {
 		if (pri->debug &  PRI_DEBUG_Q921_STATE)
-			pri_message("T203 counter expired in weird state %d\n", pri->q921_state);
+			pri_message(pri, "T203 counter expired in weird state %d\n", pri->q921_state);
 		pri->t203_timer = 0;
 	}
 }
@@ -508,7 +508,7 @@
 	return NULL;
 }
 
-void q921_dump(q921_h *h, int len, int showraw, int txrx)
+void q921_dump(struct pri *pri, q921_h *h, int len, int showraw, int txrx)
 {
 	int x;
         char *type;
@@ -521,7 +521,7 @@
 		if (buf) {
 			for (x=0;x<len;x++) 
 				buflen += sprintf(buf + buflen, "%02x ", h->raw[x]);
-			pri_message("\n%c [ %s]\n", direction_tag, buf);
+			pri_message(pri, "\n%c [ %s]\n", direction_tag, buf);
 			free(buf);
 		}
 	}
@@ -529,17 +529,17 @@
 	switch (h->h.data[0] & Q921_FRAMETYPE_MASK) {
 	case 0:
 	case 2:
-		pri_message("\n%c Informational frame:\n", direction_tag);
+		pri_message(pri, "\n%c Informational frame:\n", direction_tag);
 		break;
 	case 1:
-		pri_message("\n%c Supervisory frame:\n", direction_tag);
+		pri_message(pri, "\n%c Supervisory frame:\n", direction_tag);
 		break;
 	case 3:
-		pri_message("\n%c Unnumbered frame:\n", direction_tag);
+		pri_message(pri, "\n%c Unnumbered frame:\n", direction_tag);
 		break;
 	}
 	
-	pri_message(
+	pri_message(pri, 
 "%c SAPI: %02d  C/R: %d EA: %d\n"
 "%c  TEI: %03d        EA: %d\n", 
     	direction_tag,
@@ -553,7 +553,7 @@
 	case 0:
 	case 2:
 		/* Informational frame */
-		pri_message(
+		pri_message(pri, 
 "%c N(S): %03d   0: %d\n"
 "%c N(R): %03d   P: %d\n"
 "%c %d bytes of data\n",
@@ -580,7 +580,7 @@
 			type = "REJ (reject)";
 			break;
 		}
-		pri_message(
+		pri_message(pri, 
 "%c Zero: %d     S: %d 01: %d  [ %s ]\n"
 "%c N(R): %03d P/F: %d\n"
 "%c %d bytes of data\n",
@@ -626,7 +626,7 @@
 				break;
 			}
 		}
-		pri_message(
+		pri_message(pri, 
 "%c   M3: %d   P/F: %d M2: %d 11: %d  [ %s ]\n"
 "%c %d bytes of data\n",
 	direction_tag,
@@ -709,23 +709,23 @@
 	case 0:
 	case 2:
 		if (pri->q921_state != Q921_LINK_CONNECTION_ESTABLISHED) {
-			pri_error("!! Got I-frame while link state %d\n", pri->q921_state);
+			pri_error(pri, "!! Got I-frame while link state %d\n", pri->q921_state);
 			return NULL;
 		}
 		/* Informational frame */
 		if (len < 4) {
-			pri_error("!! Received short I-frame (expected 4, got %d)\n", len);
+			pri_error(pri, "!! Received short I-frame (expected 4, got %d)\n", len);
 			break;
 		}
 		return q921_handle_iframe(pri, &h->i, len);	
 		break;
 	case 1:
 		if (pri->q921_state != Q921_LINK_CONNECTION_ESTABLISHED) {
-			pri_error("!! Got S-frame while link down\n");
+			pri_error(pri, "!! Got S-frame while link down\n");
 			return NULL;
 		}
 		if (len < 4) {
-			pri_error("!! Received short S-frame (expected 4, got %d)\n", len);
+			pri_error(pri, "!! Received short S-frame (expected 4, got %d)\n", len);
 			break;
 		}
 		switch(h->s.ss) {
@@ -740,10 +740,10 @@
 				/* If it's a p/f one then send back a RR in return with the p/f bit set */
 				if (pri->solicitfbit) {
 					if (pri->debug & PRI_DEBUG_Q921_STATE) 
-						pri_message("-- Got RR response to our frame\n");
+						pri_message(pri, "-- Got RR response to our frame\n");
 				} else {
 					if (pri->debug & PRI_DEBUG_Q921_STATE) 
-						pri_message("-- Unsolicited RR with P/F bit, responding\n");
+						pri_message(pri, "-- Unsolicited RR with P/F bit, responding\n");
 						q921_rr(pri, 1, 0);
 				}
 				pri->solicitfbit = 0;
@@ -752,7 +752,7 @@
       case 1:
          /* Receiver not ready */
          if (pri->debug & PRI_DEBUG_Q921_STATE)
-            pri_message("-- Got receiver not ready\n");
+            pri_message(pri, "-- Got receiver not ready\n");
 	 if(h->s.p_f) {
 		/* Send RR if poll bit set */
 		q921_rr(pri, h->s.p_f, 0);
@@ -762,7 +762,7 @@
       case 2:
          /* Just retransmit */
          if (pri->debug & PRI_DEBUG_Q921_STATE)
-            pri_message("-- Got reject requesting packet %d...  Retransmitting.\n", h->s.n_r);
+            pri_message(pri, "-- Got reject requesting packet %d...  Retransmitting.\n", h->s.n_r);
          if (h->s.p_f) {
             /* If it has the poll bit set, send an appropriate supervisory response */
             q921_rr(pri, 1, 0);
@@ -774,7 +774,7 @@
                      /* Matches the request, or follows in our window, and has
 					    already been transmitted. */
 					 sendnow = 1;
-					 pri_error("!! Got reject for frame %d, retransmitting frame %d now, updating n_r!\n", h->s.n_r, f->h.n_s);
+					 pri_error(pri, "!! Got reject for frame %d, retransmitting frame %d now, updating n_r!\n", h->s.n_r, f->h.n_s);
 				     f->h.n_r = pri->v_r;
                      q921_transmit(pri, (q921_h *)(&f->h), f->len);
                }
@@ -783,11 +783,11 @@
                if (pri->txqueue) {
                      /* This should never happen */
 		     if (!h->s.p_f || h->s.n_r) {
-			pri_error("!! Got reject for frame %d, but we only have others!\n", h->s.n_r);
+			pri_error(pri, "!! Got reject for frame %d, but we only have others!\n", h->s.n_r);
 		     }
                } else {
                      /* Hrm, we have nothing to send, but have been REJ'd.  Reset v_a, v_s, etc */
-				pri_error("!! Got reject for frame %d, but we have nothing -- resetting!\n", h->s.n_r);
+				pri_error(pri, "!! Got reject for frame %d, but we have nothing -- resetting!\n", h->s.n_r);
                      pri->v_a = h->s.n_r;
                      pri->v_s = h->s.n_r;
                      /* Reset t200 timer if it was somehow going */
@@ -803,13 +803,13 @@
          }
          break;
 		default:
-			pri_error("!! XXX Unknown Supervisory frame ss=0x%02x,pf=%02xnr=%02x vs=%02x, va=%02x XXX\n", h->s.ss, h->s.p_f, h->s.n_r,
+			pri_error(pri, "!! XXX Unknown Supervisory frame ss=0x%02x,pf=%02xnr=%02x vs=%02x, va=%02x XXX\n", h->s.ss, h->s.p_f, h->s.n_r,
 					pri->v_s, pri->v_a);
 		}
 		break;
 	case 3:
 		if (len < 3) {
-			pri_error("!! Received short unnumbered frame\n");
+			pri_error(pri, "!! Received short unnumbered frame\n");
 			break;
 		}
 		switch(h->u.m3) {
@@ -819,7 +819,7 @@
 					/* Section 5.7.1 says we should restart on receiving a DM response with the f-bit set to
 					   one, but we wait T200 first */
 					if (pri->debug & PRI_DEBUG_Q921_STATE)
-						pri_message("-- Got DM Mode from peer.\n");
+						pri_message(pri, "-- Got DM Mode from peer.\n");
 					/* Disconnected mode, try again after T200 */
 					ev = q921_dchannel_down(pri);
 					q921_start(pri, 0);
@@ -827,7 +827,7 @@
 						
 				} else {
 					if (pri->debug & PRI_DEBUG_Q921_STATE)
-						pri_message("-- Ignoring unsolicited DM with p/f set to 0\n");
+						pri_message(pri, "-- Ignoring unsolicited DM with p/f set to 0\n");
 #if 0
 					/* Requesting that we start */
 					q921_start(pri, 0);
@@ -835,12 +835,12 @@
 				}
 				break;
 			} else if (!h->u.m2) {
-				pri_message("XXX Unnumbered Information not implemented XXX\n");
+				pri_message(pri, "XXX Unnumbered Information not implemented XXX\n");
 			}
 			break;
 		case 2:
 			if (pri->debug &  PRI_DEBUG_Q921_STATE)
-				pri_message("-- Got Disconnect from peer.\n");
+				pri_message(pri, "-- Got Disconnect from peer.\n");
 			/* Acknowledge */
 			q921_send_ua(pri, h->u.p_f);
 			ev = q921_dchannel_down(pri);
@@ -850,7 +850,7 @@
 			if (h->u.m2 == 3) {
 				/* SABME */
 				if (pri->debug & PRI_DEBUG_Q921_STATE) {
-					pri_message("-- Got SABME from %s peer.\n", h->h.c_r ? "network" : "cpe");
+					pri_message(pri, "-- Got SABME from %s peer.\n", h->h.c_r ? "network" : "cpe");
 				}
 				if (h->h.c_r) {
 					pri->remotetype = PRI_NETWORK;
@@ -872,22 +872,22 @@
 					/* It's a UA */
 				if (pri->q921_state == Q921_AWAITING_ESTABLISH) {
 					if (pri->debug & PRI_DEBUG_Q921_STATE) {
-						pri_message("-- Got UA from %s peer  Link up.\n", h->h.c_r ? "cpe" : "network");
+						pri_message(pri, "-- Got UA from %s peer  Link up.\n", h->h.c_r ? "cpe" : "network");
 					}
 					return q921_dchannel_up(pri);
 				} else 
-					pri_error("!! Got a UA, but i'm in state %d\n", pri->q921_state);
+					pri_error(pri, "!! Got a UA, but i'm in state %d\n", pri->q921_state);
 			} else 
-				pri_error("!! Weird frame received (m3=3, m2 = %d)\n", h->u.m2);
+				pri_error(pri, "!! Weird frame received (m3=3, m2 = %d)\n", h->u.m2);
 			break;
 		case 4:
-			pri_error("!! Frame got rejected!\n");
+			pri_error(pri, "!! Frame got rejected!\n");
 			break;
 		case 5:
-			pri_error("!! XID frames not supported\n");
+			pri_error(pri, "!! XID frames not supported\n");
 			break;
 		default:
-			pri_error("!! Don't know what to do with M3=%d u-frames\n", h->u.m3);
+			pri_error(pri, "!! Don't know what to do with M3=%d u-frames\n", h->u.m3);
 		}
 		break;
 				
@@ -902,7 +902,7 @@
 	len -= 2;
 	
 	if (!pri->master && pri->debug & PRI_DEBUG_Q921_DUMP)
-		q921_dump(h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0);
+		q921_dump(pri, h, len, pri->debug & PRI_DEBUG_Q921_RAW, 0);
 
 	/* Check some reject conditions -- Start by rejecting improper ea's */
 	if (h->h.ea1 || !(h->h.ea2))
@@ -941,7 +941,7 @@
 void q921_start(struct pri *pri, int now)
 {
 	if (pri->q921_state != Q921_LINK_CONNECTION_RELEASED) {
-		pri_error("!! q921_start: Not in 'Link Connection Released' state\n");
+		pri_error(pri, "!! q921_start: Not in 'Link Connection Released' state\n");
 		return;
 	}
 	/* Reset our interface */

Index: q931.c
===================================================================
RCS file: /usr/cvsroot/libpri/q931.c,v
retrieving revision 1.125
retrieving revision 1.126
diff -u -d -r1.125 -r1.126
--- q931.c	19 May 2005 14:06:43 -0000	1.125
+++ q931.c	23 May 2005 15:06:33 -0000	1.126
@@ -209,7 +209,7 @@
 static char *msg2str(int msg);
 
 
-#define FUNC_DUMP(name) void ((name))(int full_ie, q931_ie *ie, int len, char prefix)
+#define FUNC_DUMP(name) void ((name))(int full_ie, struct pri *pri, q931_ie *ie, int len, char prefix)
 #define FUNC_RECV(name) int ((name))(int full_ie, struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len)
 #define FUNC_SEND(name) int ((name))(int full_ie, struct pri *pri, q931_call *call, int msgtype, q931_ie *ie, int len, int order)
 
@@ -273,7 +273,7 @@
 	int pos=0;
 #ifdef NO_BRI_SUPPORT
[...1070 lines suppressed...]
 		    (c->cause != PRI_CAUSE_INTERWORKING)) 
-			pri_error("Received unsolicited status: %s\n", pri_cause2str(c->cause));
+			pri_error(pri, "Received unsolicited status: %s\n", pri_cause2str(c->cause));
 		/* Workaround for S-12 ver 7.3 - it responds for invalid/non-implemented IEs at SETUP with null call state */
 		if (!c->sugcallstate && (c->ourcallstate != Q931_CALL_STATE_CALL_INITIATED)) {
 			pri->ev.hangup.channel = c->channelno | (c->ds1no << 8) | (c->ds1explicit << 16);
@@ -3665,11 +3665,11 @@
 	case Q931_SUSPEND:
 	case Q931_SUSPEND_ACKNOWLEDGE:
 	case Q931_SUSPEND_REJECT:
-		pri_error("!! Not yet handling post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
+		pri_error(pri, "!! Not yet handling post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
 		/* Fall through */
 	default:
 		
-		pri_error("!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
+		pri_error(pri, "!! Don't know how to post-handle message type %s (%d)\n", msg2str(mh->msg), mh->msg);
 		q931_status(pri,c, PRI_CAUSE_MESSAGE_TYPE_NONEXIST);
 		if (c->newcall) 
 			q931_destroycall(pri,c->cr);




More information about the svn-commits mailing list