Merge branch 'master' of ssh://jolly@www.mISDN.org/var/git/lcr
authorSuper User <root@isdn.jolly.ten>
Mon, 28 Apr 2008 17:34:33 +0000 (19:34 +0200)
committerSuper User <root@isdn.jolly.ten>
Mon, 28 Apr 2008 17:34:33 +0000 (19:34 +0200)
Conflicts:

chan_lcr.c

1  2 
chan_lcr.c
chan_lcr.h

diff --cc chan_lcr.c
@@@ -771,79 -553,51 +773,120 @@@ void lcr_thread(void
        }
  }
  
 -
 -static struct ast_channel *lcr_ast_new(struct chan_call *call, char *exten, char *callerid, int ref);
 -
 -static struct ast_channel *lcr_request(const char *type, int format, void *data, int *cause)
 +/*
 + * send setup info to LCR
 + * this function is called, when asterisk call is received and ref is received
 + */
 +static void send_setup_to_lcr(struct chan_call *call)
  {
 -      struct ast_channel *ast=NULL;
 +      if (!ast || !call->ref)
 +              return;
  
 -      char buf[128];
 -        char *port_str, *ext, *p;
 -        int port;
 -
 -        ast_copy_string(buf, data, sizeof(buf)-1);
 -        p=buf;
 -        port_str=strsep(&p, "/");
 -        ext=strsep(&p, "/");
 -        ast_verbose("portstr:%s ext:%s\n",port_str, ext);
 +      /* send setup message to LCR */
 +      memset(&newparam, 0, sizeof(union parameter));
 +      newparam.setup.xxxxxx = 
 +      send_message(MESSAGE_SETUP, call->ref, &newparam);
 +      /* change to outgoing setup state */
 +      call->state = CHAN_LCR_STATE_OUT_SETUP;
 +}
  
 -      sprintf(buf,"%s/%s",lcr_type,(char*)data);
++#if 0
++CHRISTIAN: das war ein konflikt beim pullen
++siehe anderes lcr_request();
++bedenke: das ast_log muss noch üeberall eingepflegt werden
++static struct ast_channel *lcr_request(const char *type, int format, void *data, int *cause)
++{
+       struct chan_call *call=alloc_call();
+       if (call) {
+ #warning hier muss jetzt wohl eine Ref angefordert werden!
+               ast=lcr_ast_new(call, ext, NULL, 0 );
+               if (ast) {
+                       call->ast=ast;
+               } else {
+                       ast_log(LOG_WARNING, "Could not create new Asterisk Channel\n");
+                       free_call(call);
+               }
+       } else {
+               ast_log(LOG_WARNING, "Could not create new Lcr Call Handle\n");
+       }
+       return ast;
+ }
++      struct ast_channel *ast=NULL;
++
++      char buf[128];
++        char *port_str, *ext, *p;
++        int port;
++
++        ast_copy_string(buf, data, sizeof(buf)-1);
++        p=buf;
++        port_str=strsep(&p, "/");
++        ext=strsep(&p, "/");
++        ast_verbose("portstr:%s ext:%s\n",port_str, ext);
++
++      sprintf(buf,"%s/%s",lcr_type,(char*)data);
++#endif
++
 +/*
 + * send dialing info to LCR
 + * this function is called, when setup acknowledge is received and dialing
 + * info is available.
 + */
 +static void send_dialing_to_lcr(struct chan_call *call)
 +{
 +      if (!ast || !call->ref || !call->dialque)
 +              return;
 +      
 +      /* send setup message to LCR */
 +      memset(&newparam, 0, sizeof(union parameter));
 +      strncpy(newparam.dialinginfo.id, call->dialque, sizeof(newparam.dialinginfo.id)-1);
 +      call->dialque[0] = '\0';
 +      send_message(MESSAGE_INFORMATION, call->ref, &newparam);
 +}
 +
 +/*
 + * new asterisk instance
 + */
 +static struct ast_channel *lcr_request(const char *type, int format, void *data, int *cause)
 +{
 +      /* create call instance */
 +      call = alloc_call();
 +      if (!call)
 +      {
 +              /* failed to create instance */
 +              return NULL;
 +      }
 +      /* create asterisk channel instrance */
 +      ast = ast_channel_alloc(1);
 +      if (!ast)
 +      {
 +              free_call(call);
 +              /* failed to create instance */
 +              return NULL;
 +      }
 +      /* link together */
 +      ast->tech_pvt = call;
 +      call->ast = ast;
 +      /* send MESSAGE_NEWREF */
 +      memset(&newparam, 0, sizeof(union parameter));
 +      newparam.direction = 0; /* request from app */
 +      send_message(MESSAGE_NEWREF, 0, &newparam);
 +      /* set state */
 +      call->state = CHAN_LCR_STATE_OUT_PREPARE;
 +}
  
 -/* call from asterisk (new instance) */
 +/*
 + * call from asterisk
 + */
  static int lcr_call(struct ast_channel *ast, char *dest, int timeout)
  {
-         struct lcr_pvt *lcr=ast->tech_pvt;
+         struct chan_call *call=ast->tech_pvt;
  
-         if (!lcr) return -1;
+         if (!call) return -1;
  
          char buf[128];
          char *port_str, *dad, *p;
        return 0; 
  }
  
 +static int lcr_digit(struct ast_channel *ast, char digit)
 +{
 +      char buf[]="x";
 +
 +      /* only pass IA5 number space */
 +      if (digit > 126 || digit < 32)
 +              return 0;
 +
 +      /* send information or queue them */
 +      if (call->ref && call->state == CHAN_LCR_STATE_OUT_DIALING)
 +      {
 +              send_dialing_to_lcr(call);
 +      } else
 +      if (!call->ref
 +       && (call->state == CHAN_LCR_STATE_OUT_PREPARE || call->state == CHAN_LCR_STATE_OUT_SETUP));
 +      {
 +              *buf = digit;
 +              strncat(call->dialque, buf, strlen(char->dialque)-1);
 +      } else
 +      {
 +digits kommen, koennen aber nicht verwendet werden.
 +      sollen wir sie als info senden (im connect zb.)
 +      }
 +}
 +
  static int lcr_answer(struct ast_channel *c)
  {
-         struct lcr_pvt *lcr=c->tech_pvt;
+         struct chan_call *call=c->tech_pvt;
          return 0;
  }
  
 -static int lcr_hangup(struct ast_channel *c)
 +static int lcr_hangup(struct ast_channel *ast)
  {
++<<<<<<< HEAD:chan_lcr.c
 +        struct chan_call *call = ast->tech_pvt;
++=======
+         struct chan_call *call=c->tech_pvt;
+       c->tech_pvt=NULL;
+ }
++>>>>>>> 350450b9cadc6107449fe2630843d4f898f680b7:chan_lcr.c
  
 +      /* disconnect asterisk, maybe not required */
 +      ast->tech_pvt = NULL;
 +      if (ref)
 +      {
 +              /* release */
 +              memset(&newparam, 0, sizeof(union parameter));
 +              newparam.disconnectinfo.cause = CAUSE_RESSOURCEUNAVAIL;
 +              newparam.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
 +              send_message(MESSAGE_RELEASE, call->ref, &newparam);
 +              /* remove call */
 +              free_call(call);
 +              return;
 +      } else
 +      {
 +              /* ref is not set, due to prepare setup or release */
 +              if (call->state == CHAN_LCR_STATE_RELEASE)
 +              {
 +                      /* we get the response to our release */
 +                      free_call(call);
 +              } else
 +              {
 +                      /* during prepare, we change to release state */
 +                      call->state = CHAN_LCR_STATE_RELEASE;
 +              }
 +      } 
 +}
  
  static int lcr_write(struct ast_channel *c, struct ast_frame *f)
  {
diff --cc chan_lcr.h
  
  /* structure for all calls */
  struct chan_call {
 -      struct chan_call *next;
 -      unsigned long ref;      /* callref, is 0, if not yet set */
 -      unsigned long bchannel_handle;  /* reference to bchannel, if set */
 -
 +      struct chan_call        *next;  /* link to next call instance */
 +      int                     state;  /* current call state CHAN_LCR_STATE */
 +      unsigned long           ref;    /* callref for this channel */
 +      struct ast_channel      *ast;   /* current asterisk channel */
 +      unsigned long           bchannel_handle;
 +                                      /* reference to bchannel, if set */
        unsigned short bridge_id; /* 0 = off, equal ids are bridged */
+       struct ast_channel *ast;
  };
  
 +enum {
 +      CHAN_LCR_STATE_IN_PREPARE = 0,
 +      CHAN_LCR_STATE_IN_SETUP,
 +      CHAN_LCR_STATE_IN_DIALING,
 +      CHAN_LCR_STATE_IN_PROCEEDING,
 +      CHAN_LCR_STATE_IN_ALERTING,
 +      CHAN_LCR_STATE_OUT_PREPARE,
 +      CHAN_LCR_STATE_OUT_SETUP,
 +      CHAN_LCR_STATE_OUT_DIALING,
 +      CHAN_LCR_STATE_OUT_PROCEEDING,
 +      CHAN_LCR_STATE_OUT_ALERTING,
 +      CHAN_LCR_STATE_CONNECT,
 +      CHAN_LCR_STATE_IN_DISCONNECT,
 +      CHAN_LCR_STATE_OUT_DISCONNECT,
 +      CHAN_LCR_STATE_RELEASE,
 +};
 +
 +#define CHAN_LCR_STATE static const struct chan_lcr_state { \
 +      char name, \
 +      char meaning, \
 +} chan_lcr_state[] = { \
 +      { "IN_PREPARE", \
 +        "New call from ISDN is waiting for setup." }, \
 +      { "IN_SETUP", \
 +        "Call from ISDN is currently set up." }, \
 +      { "IN_DIALING", \
 +        "Call from ISDN is currently waiting for digits to be dialed." }, \
 +      { "IN_PROCEEDING", \
 +        "Call from ISDN is complete and proceeds to ring." }, \
 +      { "IN_ALERTING", \
 +        "Call from ISDN is ringing." }, \
 +      { "OUT_PREPARE", \
 +        "New call to ISDN is wating for setup." }, \
 +      { "OUT_SETUP", \
 +        "Call to ISDN is currently set up." }, \
 +      { "OUT_DIALING", \
 +        "Call to ISDN is currently waiting for digits to be dialed." }, \
 +      { "OUT_PROCEEDING", \
 +        "Call to ISDN is complete and proceeds to ring." }, \
 +      { "OUT_ALERTING", \
 +        "Call to ISDN is ringing." }, \
 +      { "CONNECT", \
 +        "Call has been answered." }, \
 +      { "IN_DISCONNECT", \
 +        "Call has been hung up on ISDN side." }, \
 +      { "OUT_DISCONNECT", \
 +        "Call has been hung up on Asterisk side." }, \
 +      { "RELEASE", \
 +        "Call is waiting for complete release." }, \
 +};
 +