fixed some essential segfaults happening under heavy load. Added a bit more error...
authorChristian Richter <christian.richter@beronet.com>
Tue, 4 Apr 2006 19:09:26 +0000 (19:09 +0000)
committerChristian Richter <christian.richter@beronet.com>
Tue, 4 Apr 2006 19:09:26 +0000 (19:09 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@17404 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_misdn.c
channels/misdn/Makefile
channels/misdn/isdn_lib.c
channels/misdn/isdn_msg_parser.c

index 8bebe2a..0ab599d 100644 (file)
@@ -1218,6 +1218,9 @@ void config_jitterbuffer(struct chan_list *ch)
                }
                
                ch->jb=misdn_jb_init(len, threshold);
+
+               if (!ch->jb ) 
+                       bc->nojitter=1;
        }
 }
 
@@ -1930,7 +1933,6 @@ static int misdn_hangup(struct ast_channel *ast)
        
        release_unlock;
        
-       
        {
                const char *varcause=NULL;
                bc->cause=ast->hangupcause?ast->hangupcause:16;
@@ -2012,6 +2014,7 @@ static int misdn_hangup(struct ast_channel *ast)
     
        }
        
+
        chan_misdn_log(1, bc->port, "Channel: %s hanguped\n",ast->name);
        
        return 0;
@@ -2107,7 +2110,7 @@ static int misdn_write(struct ast_channel *ast, struct ast_frame *frame)
        }
 
        if ( ! ch->bc->addr ) {
-               chan_misdn_log(4, ch->bc->port, "misdn_write: no addr for bc dropping:%d\n", frame->samples);
+               chan_misdn_log(8, ch->bc->port, "misdn_write: no addr for bc dropping:%d\n", frame->samples);
                return 0;
        }
        
@@ -4227,7 +4230,19 @@ struct misdn_jb *misdn_jb_init(int size, int upper_threshold)
     jb->state_empty = 0;
     jb->bytes_wrote = 0;
     jb->samples = (char *)malloc(size*sizeof(char));
+
+    if (!jb->samples) {
+           chan_misdn_log(-1,0,"No free Mem for jb->samples\n");
+           return NULL;
+    }
+    
     jb->ok = (char *)malloc(size*sizeof(char));
+
+    if (!jb->ok) {
+           chan_misdn_log(-1,0,"No free Mem for jb->ok\n");
+           return NULL;
+    }
+
     for(i=0; i<size; i++)
        jb->ok[i]=0;
 
@@ -4241,7 +4256,6 @@ void misdn_jb_destroy(struct misdn_jb *jb)
 {
        ast_mutex_destroy(&jb->mutexjb);
        
-       
        free(jb->samples);
        free(jb);
 }
@@ -4374,7 +4388,8 @@ void chan_misdn_log(int level, int port, char *tmpl, ...)
 {
        if (! ((0 <= port) && (port <= max_ports))) {
                ast_log(LOG_WARNING, "cb_log called with out-of-range port number! (%d)\n", port);
-               port=-1;
+               port=0;
+               level=-1;
        }
                
        va_list ap;
index 1db4ee6..e0e63d7 100644 (file)
@@ -5,7 +5,7 @@
 #
 
 # Verify those options with main Makefile
-CFLAGS         = -pipe -c -Wall
+CFLAGS         = -pipe -c -Wall -ggdb
 ifeq ($(shell uname -m),x86_64)
 CFLAGS        += -fPIC
 endif
index f9d5029..e1eb61a 100644 (file)
@@ -880,6 +880,11 @@ int setup_bc(struct misdn_bchannel *bc)
        
 
        struct misdn_stack *stack=get_stack_by_bc(bc);
+
+       if (!stack) {
+               cb_log(-1, bc->port, "setup_bc: NO STACK FOUND!!\n");
+               return -1;
+       }
        
        int midev=stack->midev;
        int channel=bc->channel-1-(bc->channel>16);
@@ -2790,7 +2795,12 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
        if (!bc) goto ERR; 
        
        struct misdn_stack *stack=get_stack_by_bc(bc);
-
+       
+       if (!stack) {
+               cb_log(-1,bc->port,"SENDEVENT: no Stack for event:%s oad:%s dad:%s \n", isdn_get_info(msgs_g, event, 0), bc->oad, bc->dad);
+               return -1;
+       }
+       
        cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->uperid:%x\n",stack->nt, stack->upper_id);
 
        if ( stack->nt && !stack->l1link) {
@@ -2938,6 +2948,43 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
 }
 
 
+int handle_err(msg_t *msg)
+{
+       iframe_t *frm = (iframe_t*) msg->data;
+       unsigned char buff[32];
+       
+       switch (frm->prim) {
+               case DL_DATA|INDICATION:
+                       {
+                       struct misdn_stack *stack=find_stack_by_port( (frm->addr&MASTER_ID_MASK) >> 8);
+                       if (!stack) {
+                               cb_log(-1,0,"BCHAN DATA without having a Chan Object (addr:%x) probably we died before closing..\n",frm->addr);
+                               return 0;
+                       }
+                       cb_log(-1,stack->port,"BCHAN DATA without having a Chan Object (addr:%x) probably we died before closing..\n",frm->addr);
+
+                       if (stack->l1link)
+                               misdn_lib_get_l1_down(stack);
+#if 0
+                       iframe_t dact;
+                       dact.prim = DL_RELEASE | REQUEST;
+                       dact.addr = frm->addr | FLG_MSG_DOWN;
+                       dact.dinfo = 0;
+                       dact.len = 0;
+       
+                       mISDN_write(glob_mgr->midev, &dact, mISDN_HEADER_LEN+dact.len, TIMEOUT_1SEC);
+
+                       mISDN_write_frame(glob_mgr->midev, buff, frm->addr|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
+#endif
+                       free_msg(msg);
+                       return 1;
+                       }
+       }
+
+       return 0;
+}
+
+
 int manager_isdn_handler(iframe_t *frm ,msg_t *msg)
 {  
 
@@ -2971,6 +3018,9 @@ int manager_isdn_handler(iframe_t *frm ,msg_t *msg)
        if (handle_frm(msg)) 
                return 0 ;
 
+       if (handle_err(msg)) 
+               return 0 ;
+       
        cb_log(-1, 0, "Unhandled Message: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo);           
    
        free_msg(msg);
@@ -3322,7 +3372,8 @@ void manager_bchannel_activate(struct misdn_bchannel *bc)
        struct misdn_stack *stack=get_stack_by_bc(bc);
 
        if (!stack) {
-               cb_log(-1, stack->port, "bchannel_activate: Stack not found !");
+               cb_log(-1, bc->port, "bchannel_activate: Stack not found !");
+               return ;
        }
        
        if (!msg) {
@@ -3370,7 +3421,6 @@ void manager_bchannel_activate(struct misdn_bchannel *bc)
 
 void manager_bchannel_deactivate(struct misdn_bchannel * bc)
 {
-       iframe_t dact;
 
        struct misdn_stack *stack=get_stack_by_bc(bc);
 
@@ -3391,6 +3441,7 @@ void manager_bchannel_deactivate(struct misdn_bchannel * bc)
        
        bc->generate_tone=0;
        
+       iframe_t dact;
        dact.prim = DL_RELEASE | REQUEST;
        dact.addr = bc->addr | FLG_MSG_DOWN;
        dact.dinfo = 0;
index 7ae9a53..c225755 100644 (file)
@@ -333,10 +333,17 @@ void parse_connect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *b
        int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
        CONNECT_t *connect=(CONNECT_t*)((unsigned long)(msg->data+HEADER_LEN));
   
+       int type,plan,pres,screen;
+       char connected_pn[32];
+       
        bc->ces = connect->ces;
        bc->ces = connect->ces;
 
        dec_ie_progress(connect->PROGRESS, (Q931_info_t *)connect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
+
+       dec_ie_connected_pn(connect->CONNECT_PN,(Q931_info_t *)connect, &type, &plan, &pres, &screen, connected_pn, 31, nt, bc);
+
+       cb_log(1,bc->port,"CONNETED PN: %s cpn_dialplan:%d\n", connected_pn, type);
        
 #if DEBUG 
        printf("Parsing CONNECT Msg\n");