[Asterisk-Dev] chan_capi patch to work with head April 2005

Gregory Hinton Nietsky gregory at networksentry.co.za
Wed Apr 27 03:27:35 MST 2005


--- chan_capi-0.3.5/chan_capi.c	2004-08-13 12:07:28.000000000 +0200
+++ chan_capi-0.3.5-asthead-april-2005/chan_capi.c	2005-04-27 
11:10:02.000000000 +0200
@@ -14,7 +14,9 @@
 #include <asterisk/lock.h>
 #include <asterisk/frame.h> 
 #include <asterisk/channel.h>
+#ifndef UNSTABLE_CVS
 #include <asterisk/channel_pvt.h>
+#endif
 #include <asterisk/logger.h>
 #include <asterisk/module.h>
 #include <asterisk/pbx.h>
@@ -37,25 +39,35 @@
 #include <asterisk/dsp.h>
 #include "xlaw.h"
 #include "chan_capi_pvt.h"
+#ifdef UNSTABLE_CVS
+#include "chan_capi_app.h"
+#endif
 
 unsigned ast_capi_ApplID;
+#ifdef UNSTABLE_CVS
+unsigned ast_capi_MessageNumber=1;
+#else
 _cword ast_capi_MessageNumber=1;
+#endif
 static char *desc = "Common ISDN API for Asterisk";
 #ifdef CAPI_ULAW
 #ifdef UNSTABLE_CVS
-static char *tdesc = "Common ISDN API Driver (0.3.5) muLaw CVS HEAD";
+static char tdesc[] = "Common ISDN API Driver (0.3.5) muLaw CVS HEAD";
 #else
 static char *tdesc = "Common ISDN API Driver (0.3.5) muLaw";
 #endif
 #else
 #ifdef UNSTABLE_CVS
-static char *tdesc = "Common ISDN API Driver (0.3.5) aLaw CVS HEAD";
+static char tdesc[] = "Common ISDN API Driver (0.3.5) aLaw CVS HEAD";
 #else
 static char *tdesc = "Common ISDN API Driver (0.3.5) aLaw";
 #endif
 #endif
+#ifdef UNSTABLE_CVS
+static char type[] = "CAPI";
+#else
 static char *type = "CAPI";
-
+#endif
 
 static int usecnt;
 #ifdef UNSTABLE_CVS
@@ -101,6 +113,48 @@
 
 int capidebug = 0;
 
+#ifdef UNSTABLE_CVS
+static struct ast_channel *capi_request(const char *type, int format, void 
*data, int *cause);
+static int capi_hangup(struct ast_channel *c);
+static int capi_answer(struct ast_channel *c);
+static struct ast_frame *capi_read(struct ast_channel *chan);
+static int capi_write(struct ast_channel *chan, struct ast_frame *f);
+static int capi_indicate(struct ast_channel *chan, int cond);
+static int capi_fixup(struct ast_channel *oldchan, struct ast_channel 
*newchan);
+static int capi_send_digit(struct ast_channel *c,char digit);
+int capi_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, 
struct ast_frame **fo, struct ast_channel **rc);
+
+static const struct ast_channel_tech capi_tech = {
+	.type = type,
+	.description = tdesc,
+#ifdef CAPI_ULAW
+	.capabilities = AST_FORMAT_ULAW,
+#else
+	.capabilities = AST_FORMAT_ALAW,
+#endif
+	.requester = capi_request,
+	.hangup = capi_hangup,
+	.answer = capi_answer,
+	.read = capi_read,
+	.call = capi_call,
+	.write = capi_write,
+        .indicate = capi_indicate,
+	.fixup = capi_fixup,
+	.send_digit = capi_send_digit,
+	.bridge = capi_bridge,
+	.properties = 0,
+	.devicestate = NULL,
+	.send_text = NULL,
+	.send_image = NULL,
+	.send_html = NULL,
+	.bridged_channel = NULL,
+	.setoption = NULL,
+	.queryoption = NULL,
+	.transfer = NULL,
+	.write_video = NULL,
+};
+#endif
+
 MESSAGE_EXCHANGE_ERROR _capi_put_cmsg(_cmsg *CMSG) {
     MESSAGE_EXCHANGE_ERROR error;
     if (ast_mutex_lock(&capi_put_lock)) {
@@ -172,7 +226,11 @@
 #define EC_DEFAULT_TAIL			64
 
 static int capi_echo_canceller(struct ast_channel *c, int function) {
+#ifdef UNSTABLE_CVS
+    struct ast_capi_pvt *i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
     struct ast_capi_pvt *i = c->pvt->pvt;
+#endif
     MESSAGE_EXCHANGE_ERROR  error;
     _cmsg		    CMSG;
     char   buf[7];
@@ -222,7 +280,11 @@
 }
 
 int capi_detect_dtmf(struct ast_channel *c, int flag) {
+#ifdef UNSTABLE_CVS
+    struct ast_capi_pvt *i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
     struct ast_capi_pvt *i = c->pvt->pvt;
+#endif
     MESSAGE_EXCHANGE_ERROR  error;
     _cmsg		    CMSG;
     char	buf[9];
@@ -269,7 +331,11 @@
     return 0;
 }
 static int capi_send_digit(struct ast_channel *c,char digit) {
+#ifdef UNSTABLE_CVS
+    struct ast_capi_pvt *i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
     struct ast_capi_pvt *i = c->pvt->pvt;
+#endif
     MESSAGE_EXCHANGE_ERROR  error;
     _cmsg		    CMSG;
     char	buf[10];
@@ -353,7 +419,11 @@
 }
 
 static int capi_alert(struct ast_channel *c) {
+#ifdef UNSTABLE_CVS
+    struct ast_capi_pvt *i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
     struct ast_capi_pvt *i = c->pvt->pvt;
+#endif
     MESSAGE_EXCHANGE_ERROR  error;
     _cmsg	CMSG;
     
@@ -376,7 +446,11 @@
 #ifdef DEFLECT_ON_CIRCUITBUSY
 static int capi_deflect(struct ast_channel *chan, void *data)
 {
+#ifdef UNSTABLE_CVS
+    struct ast_capi_pvt *i = (struct ast_capi_pvt *)chan->tech_pvt;
+#else
     struct ast_capi_pvt *i = chan->pvt->pvt;
+#endif
     MESSAGE_EXCHANGE_ERROR Info;
     _cmsg	CMSG;
     char	bchaninfo[1];
@@ -518,7 +592,11 @@
     struct ast_capi_pvt *i;
     MESSAGE_EXCHANGE_ERROR  error;
     _cmsg	CMSG;
+#ifdef UNSTABLE_CVS
+    i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
     i = c->pvt->pvt;
+#endif
 
     if (option_verbose > 2) {
 	if (capidebug)
@@ -581,7 +659,11 @@
 
 static int capi_hangup(struct ast_channel *c) {
     struct ast_capi_pvt *i;
+#ifdef UNSTABLE_CVS
+    i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
     i = c->pvt->pvt;
+#endif
 
     // hmm....ok...this is called to free the capi interface (passive 
disconnect)
     // or to bring down the channel (active disconnect)
@@ -616,7 +698,11 @@
     ast_update_use_count();
     i->mypipe = NULL;
     i = NULL;
+#ifdef UNSTABLE_CVS
+    c->tech_pvt = NULL;
+#else
     c->pvt->pvt = NULL;
+#endif
     ast_setstate(c,AST_STATE_DOWN);
     return 0;
 }
@@ -653,7 +739,11 @@
 		ast_log(LOG_WARNING, "Destination %s requres a real destination\n", idest);
 		return -1;
 	}
+#ifdef UNSTABLE_CVS
+	i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
 	i = c->pvt->pvt;
+#endif
 	i->doB3 = AST_CAPI_B3_DONT; // <homer>DOH</homer>
 
 	// always B3
@@ -687,7 +777,7 @@
 	    p = malloc(sizeof(struct capi_pipe));
 	    memset(p, 0, sizeof(struct capi_pipe));
 	    p->fd = fds[1];
-	    c->fds[0] = fds[1];
+	    c->fds[0] = fds[0];
 	    p->PLCI = -1;
 	    p->i = i;
 	    p->c = c;
@@ -758,7 +848,11 @@
 
 
 static int capi_answer(struct ast_channel *c) {
+#ifdef UNSTABLE_CVS
+    struct ast_capi_pvt *i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
     struct ast_capi_pvt *i = c->pvt->pvt;
+#endif
     MESSAGE_EXCHANGE_ERROR  error;
     _cmsg		    CMSG;
     char buf[AST_MAX_EXTENSION];
@@ -804,7 +898,11 @@
 
 struct ast_frame *capi_read(struct ast_channel *c) 
 {
+#ifdef UNSTABLE_CVS
+	struct ast_capi_pvt *i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
 	struct ast_capi_pvt *i = c->pvt->pvt;
+#endif
 	int readsize = 0;
 
 	if ((i->state == CAPI_STATE_REMOTE_HANGUP)) {
@@ -845,7 +943,11 @@
 
 int capi_write(struct ast_channel *c, struct ast_frame *f)
 {
+#ifdef UNSTABLE_CVS
+	struct ast_capi_pvt *i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
 	struct ast_capi_pvt *i = c->pvt->pvt;
+#endif
 	_cmsg CMSG;
 	MESSAGE_EXCHANGE_ERROR  error;
 	int j=0;
@@ -986,7 +1088,11 @@
 
 static int capi_fixup(struct ast_channel *oldchan, struct ast_channel 
*newchan)
 {
+#ifdef UNSTABLE_CVS
+	struct ast_capi_pvt *p = (struct ast_capi_pvt *)newchan->tech_pvt;
+#else
 	struct ast_capi_pvt *p = newchan->pvt->pvt;
+#endif
 	p->owner = newchan;
 	return 0;
 }
@@ -1006,6 +1112,9 @@
 
     tmp = ast_channel_alloc(1);
     if (tmp != NULL) {
+#ifdef UNSTABLE_CVS
+	tmp->tech = &capi_tech;
+#endif
 //	ast_log(LOG_NOTICE,"allocated channel for PLCI=%#x!\n",i->PLCI);
 	
snprintf(tmp->name,sizeof(tmp->name),"CAPI[contr%d/%s]/%d",i->controller,i->dnid,capi_counter++);
 	tmp->type = type;
@@ -1045,14 +1154,15 @@
 #ifndef FORCE_SOFTWARE_DTMF
 	    }
 #endif
-
+#ifndef UNSTABLE_CVS
 	if (tmp->pvt == NULL) {
 	    free(tmp);
 	    return NULL;
 	}
 	tmp->pvt->pvt = i;
-
+#endif
 	tmp->callgroup = i->callgroup;
+#ifndef UNSTABLE_CVS
 	tmp->pvt->call = capi_call;
 	tmp->pvt->fixup = capi_fixup;
 	tmp->pvt->indicate = capi_indicate;
@@ -1062,16 +1172,23 @@
 	tmp->pvt->read = capi_read;
 	tmp->pvt->write = capi_write;
 	tmp->pvt->send_digit = capi_send_digit;
+#endif
 	tmp->nativeformats = capi_capability;
 	fmt = ast_best_codec(tmp->nativeformats);
 //	fmt = capi_capability;
 	tmp->readformat = fmt;
 	tmp->writeformat = fmt;
+#ifdef UNSTABLE_CVS
+	tmp->rawreadformat = fmt;
+	tmp->rawwriteformat = fmt;
+	tmp->tech_pvt = i;
+#else
 	tmp->pvt->rawreadformat = fmt;
 	tmp->pvt->rawwriteformat = fmt;
+#endif
 	strncpy(tmp->context,i->context,sizeof(tmp->context)-1);
-	tmp->callerid = strdup(i->cid);
-	tmp->dnid = strdup(i->dnid);
+	tmp->cid.cid_num = strdup(i->cid);
+	tmp->cid.cid_dnid = strdup(i->dnid);
 	strncpy(tmp->exten,i->dnid,sizeof(tmp->exten)-1);
 	strncpy(tmp->accountcode,i->accountcode,sizeof(tmp->accountcode)-1);
 	i->owner = tmp;
@@ -1099,8 +1216,7 @@
     return tmp;
 }
 
-
-struct ast_channel *capi_request(char *type, int format, void *data)
+struct ast_channel *capi_request(const char *type, int format, void *data, 
int *cause)
 {
 	struct ast_capi_pvt *i;
 	struct ast_channel *tmp = NULL;
@@ -1245,7 +1361,11 @@
     // -1 = Failure 
     //  0 = Match
     //  1 = possible match 
+#ifdef UNSTABLE_CVS
+    struct ast_capi_pvt *i = (struct ast_capi_pvt *)c->tech_pvt;
+#else
     struct ast_capi_pvt *i = c->pvt->pvt;
+#endif
     char *exten;
     
     if (strlen(i->dnid)<strlen(i->incomingmsn))
@@ -1721,7 +1841,7 @@
 			    }
 			    if (INFO_IND_INFONUMBER(CMSG) == 0x74) {
 				
strncpy(p->i->owner->exten,capi_number(INFO_IND_INFOELEMENT(CMSG),3),sizeof(p->i->owner->exten)-1);
-				
strncpy(p->i->owner->dnid,capi_number(INFO_IND_INFOELEMENT(CMSG),3),sizeof(p->i->owner->dnid)-1);
+				
strncpy(p->i->owner->cid.cid_dnid,capi_number(INFO_IND_INFOELEMENT(CMSG),3),sizeof(p->i->owner->cid.cid_dnid)-1);
 				ast_log(LOG_NOTICE,"%s\n",capi_cmsg2str(CMSG));
 			    }
 			    if (INFO_IND_INFONUMBER(CMSG) == 0x28) {
@@ -2790,7 +2910,11 @@
 
 	ast_mutex_unlock(&iflock);
 	
+#ifdef UNSTABLE_CVS
+	if (ast_channel_register(&capi_tech)) {
+#else
 	if (ast_channel_register(type, tdesc, capi_capability, capi_request)) {
+#endif
 		ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
 		unload_module();
 		return -1;
@@ -2810,7 +2934,11 @@
 {
 	if (capi20_release(ast_capi_ApplID) != 0)
 		ast_log(LOG_WARNING,"Unable to unregister from CAPI!\n");
+#ifdef UNSTABLE_CVS
+	ast_channel_unregister(&capi_tech);
+#else
 	ast_channel_unregister(type);
+#endif
 	return 0;
 }
 

--
This message has been scanned for viruses and
dangerous content by Network Sentry, and is
believed to be clean.
http://www.networksentry.co.za




More information about the asterisk-dev mailing list