backup
authorSuper User <root@isdn.jolly.ten>
Sun, 8 Jul 2007 09:24:26 +0000 (11:24 +0200)
committerSuper User <root@isdn.jolly.ten>
Sun, 8 Jul 2007 09:24:26 +0000 (11:24 +0200)
still debugging...

admin.h
admin_client.c
admin_server.c
admin_server.h
callpbx.cpp
mISDN.cpp
main.c
todo.txt
trace.c
trace.h

diff --git a/admin.h b/admin.h
index 40a0cb8..f5ca7d4 100644 (file)
--- a/admin.h
+++ b/admin.h
@@ -127,8 +127,7 @@ struct admin_call {
 
 struct admin_trace_req {
        int             detail;
-       char            category[4];
-       char            name[64];
+       char            category;
        int             port;
        char            interface[64];
        char            caller[34];
@@ -136,7 +135,7 @@ struct admin_trace_req {
 };
 
 struct admin_trace_rsp {
-       char            text[512];
+       char            text[1024];
 };
 
 //struct admin_msg {
index 982b836..2bffa73 100644 (file)
@@ -1251,7 +1251,7 @@ char *admin_trace(int sock, int argc, char *argv[])
        int i;
 
        /* show help */
-       if (!strcasecmp(argv[2], "help"))
+       if (argc > 2) if (!strcasecmp(argv[2], "help"))
        {
                printf("Trace Help\n----------\n");
                printf("%s trace [brief|short] [<filter>=<value> [...]]\n\n", argv[0]);
@@ -1284,7 +1284,7 @@ char *admin_trace(int sock, int argc, char *argv[])
                else if (!strcasecmp(argv[i], "short"))
                        msg.u.trace_req.detail = 2;
                else if (!strncasecmp(argv[i], "category=", 9))
-                       SCPY(msg.u.trace_req.category, argv[i]+9);
+                       msg.u.trace_req.category = atoi(argv[i]+9);
                else if (!strncasecmp(argv[i], "port=", 5))
                        msg.u.trace_req.port = atoi(argv[i]+5);
                else if (!strncasecmp(argv[i], "interface=", 10))
index ad40516..1bb07af 100644 (file)
@@ -262,6 +262,7 @@ int admin_route(struct admin_queue **responsep)
                                CATEGORY_EP,
                                apppbx->ea_endpoint->ep_serial,
                                "KICK (reload routing)");
+                       end_trace();
                }
 
                apppbx->e_action_timeout = NULL;
@@ -340,6 +341,16 @@ int admin_dial(struct admin_queue **responsep, char *message)
 
 
 /*
+ * do tracing
+ */
+int admin_trace(struct admin_list *admin, struct admin_trace_req *trace)
+{
+       memcpy(&admin->trace, trace, sizeof(struct admin_trace_req));
+       return(0);
+}
+
+
+/*
  * do blocking
  * 
  * 0 = make port available
@@ -1043,6 +1054,14 @@ int admin_handle(void)
                        }
                        break;
 
+                       case ADMIN_TRACE_REQUEST:
+                       if (admin_trace(admin, &msg.u.trace_req) < 0)
+                       {
+                               PERROR("Failed to create trace response for socket %d.\n", admin->sock);
+                               goto response_error;
+                       }
+                       break;
+
                        case ADMIN_REQUEST_CMD_BLOCK:
                        if (admin_block(&admin->response, msg.u.x.portnum, msg.u.x.block) < 0)
                        {
@@ -1077,7 +1096,7 @@ int admin_handle(void)
                        break;
 
                        case ADMIN_CALL_SETUP:
-                       if (admin_call(admin, &msg))
+                       if (admin_call(admin, &msg) < 0)
                        {
                                PERROR("Failed to create call for socket %d.\n", admin->sock);
                                response_error:
index 9361b3f..1b472bb 100644 (file)
@@ -22,10 +22,12 @@ struct admin_list {
        struct admin_list *next;
        int sock;
        int sockserial;
+       struct admin_trace_req trace; /* stores trace, if detail != 0 */
        unsigned long epointid;
        struct admin_queue *response;
 };
 
+extern struct admin_list *admin_list;
 int admin_init(void);
 void admin_cleanup(void);
 int admin_handle(void);
index 7fd1a94..418654d 100644 (file)
@@ -310,7 +310,8 @@ void CallPBX::bridge(void)
        class Endpoint *epoint;
        struct port_list *portlist;
        class Port *port;
-       int allmISDN = 0; // relations that are no mISDN
+       int allmISDN = 0; // set until a non-mISDN relation is found
+fix:
 
        relation = c_relation;
        while(relation)
@@ -329,7 +330,7 @@ void CallPBX::bridge(void)
                portlist = epoint->ep_portlist;
                if (!portlist)
                {
-                       PDEBUG((DEBUG_CALL|DEBUG_PORT), "ignoring relation without port object.\n");
+                       PDEBUG(DEBUG_CALL, "CALL%d ignoring relation without port object.\n", c_serial);
 //#warning testing: keep on hold until single audio stream available
                        relation->channel_state = CHANNEL_STATE_HOLD;
                        relation = relation->next;
@@ -337,7 +338,7 @@ void CallPBX::bridge(void)
                }
                if (portlist->next)
                {
-                       PDEBUG((DEBUG_CALL|DEBUG_PORT), "ignoring relation with ep%d due to port_list.\n", epoint->ep_serial);
+                       PDEBUG(DEBUG_CALL, "CALL%d ignoring relation with ep%d due to port_list.\n", c_serial, epoint->ep_serial);
 //#warning testing: keep on hold until single audio stream available
                        relation->channel_state = CHANNEL_STATE_HOLD;
                        relation = relation->next;
@@ -346,24 +347,26 @@ void CallPBX::bridge(void)
                port = find_port_id(portlist->port_id);
                if (!port)
                {
-                       PDEBUG((DEBUG_CALL|DEBUG_PORT), "ignoring relation without existing port object.\n");
+                       PDEBUG(DEBUG_CALL, "CALL%d ignoring relation without existing port object.\n", c_serial);
                        relation = relation->next;
                        continue;
                }
                if ((port->p_type&PORT_CLASS_MASK)!=PORT_CLASS_mISDN)
                {
-                       PDEBUG((DEBUG_CALL|DEBUG_PORT), "ignoring relation ep%d because it's port is not mISDN.\n", epoint->ep_serial);
+                       PDEBUG(DEBUG_CALL, "CALL%d ignoring relation ep%d because it's port is not mISDN.\n", c_serial, epoint->ep_serial);
                        if (allmISDN)
                        {
-                               PDEBUG((DEBUG_CALL|DEBUG_PORT), "not all endpoints are mISDN.\n");
+                               PDEBUG(DEBUG_CALL, "CALL%d not all endpoints are mISDN.\n", c_serial);
                                allmISDN = 0;
                        }
                        relation = relation->next;
                        continue;
                }
+               
                relation = relation->next;
        }
 
+       PDEBUG(DEBUG_CALL, "CALL%d members=%d %s\n", c_serial, relations, (allmISDN)?"(all are mISDN-members)":"(not all are mISDN-members)");
        /* we notify all relations about rxdata. */
        relation = c_relation;
        while(relation)
@@ -378,20 +381,20 @@ void CallPBX::bridge(void)
                if (relation->channel_state == CHANNEL_STATE_CONNECT
                 && relation->rx_state != NOTIFY_STATE_HOLD
                 && relation->rx_state != NOTIFY_STATE_SUSPEND
-                && relations>1 // no conf with on party
+                && relations>1 // no conf with one member
                 && allmISDN) // no conf if any member is not mISDN
                {
                        message = message_create(c_serial, relation->epoint_id, CALL_TO_EPOINT, MESSAGE_mISDNSIGNAL);
                        message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
                        message->param.mISDNsignal.conf = c_serial<<16 | c_pid;
-                       PDEBUG(DEBUG_CALL, "%s +on+ id: 0x%08x\n", port->p_name, message->param.mISDNsignal.conf);
+                       PDEBUG(DEBUG_CALL, "CALL%d EP%d +on+ id: 0x%08x\n", c_serial, relation->epoint_id, message->param.mISDNsignal.conf);
                        message_put(message);
                } else
                {
                        message = message_create(c_serial, relation->epoint_id, CALL_TO_EPOINT, MESSAGE_mISDNSIGNAL);
                        message->param.mISDNsignal.message = mISDNSIGNAL_CONF;
                        message->param.mISDNsignal.conf = 0;
-                       PDEBUG(DEBUG_CALL, "%s +off+ id: 0x%08x\n", port->p_name, message->param.mISDNsignal.conf);
+                       PDEBUG(DEBUG_CALL, "CALL%d EP%d +off+ id: 0x%08x\n", c_serial, relation->epoint_id, message->param.mISDNsignal.conf);
                        message_put(message);
                }
 
@@ -404,7 +407,7 @@ void CallPBX::bridge(void)
                message = message_create(c_serial, relation->epoint_id, CALL_TO_EPOINT, MESSAGE_mISDNSIGNAL);
                message->param.mISDNsignal.message = mISDNSIGNAL_CALLDATA;
                message->param.mISDNsignal.calldata = (relations==2 && !allmISDN);
-               PDEBUG(DEBUG_CALL, "call %d sets 'calldata' on port %s to %d\n", c_serial, port->p_name, message->param.mISDNsignal.calldata);
+               PDEBUG(DEBUG_CALL, "CALL%d EP%d set calldata=%d\n", c_serial, relation->epoint_id, message->param.mISDNsignal.calldata);
                message_put(message);
 
                relation = relation->next;
@@ -413,6 +416,7 @@ void CallPBX::bridge(void)
        /* two people just exchange their states */
        if (relations==2 && !c_partyline)
        {
+               PDEBUG(DEBUG_CALL, "CALL%d 2 relations / no partyline\n", c_serial);
                relation = c_relation;
                relation->tx_state = notify_state_change(c_serial, relation->epoint_id, relation->tx_state, relation->next->rx_state);
                relation->next->tx_state = notify_state_change(c_serial, relation->next->epoint_id, relation->next->tx_state, relation->rx_state);
@@ -420,6 +424,7 @@ void CallPBX::bridge(void)
        /* one member in a call, so we put her on hold */
        if (relations==1 || numconnect==1)
        {
+               PDEBUG(DEBUG_CALL, "CALL%d 1 member or only 1 connected, put on hold\n");
                relation = c_relation;
                while(relation)
                {
@@ -432,6 +437,7 @@ void CallPBX::bridge(void)
        } else
        /* if conference/partyline or (more than two members and more than one is connected), so we set conference state */ 
        {
+               PDEBUG(DEBUG_CALL, "CALL%d %d members, %d connected, signal conference\n", relations, numconnect);
                relation = c_relation;
                while(relation)
                {
@@ -472,7 +478,7 @@ void CallPBX::bridge_data(unsigned long epoint_from, struct call_relation *relat
                relation_to = relation_to->next;
        }
 
-       /* skip if destomatopm endpoint has NOT audio mode CONNECT */
+       /* skip if destination endpoint has NOT audio mode CONNECT */
        if (relation_to->channel_state != CHANNEL_STATE_CONNECT)
                return;
 
@@ -480,6 +486,7 @@ void CallPBX::bridge_data(unsigned long epoint_from, struct call_relation *relat
         * will be delivered to the port
         */
 //PDEBUG(DEBUG_CALL, "mixing from %d to %d\n", epoint_from, relation_to->epoint_id);
+printf("from %d, to %d\n", relation_from->epoint_id, relation_to->epoint_id);
        message = message_create(c_serial, relation_to->epoint_id, CALL_TO_EPOINT, MESSAGE_DATA);
        memcpy(&message->param, param, sizeof(union parameter));
        message_put(message);
index 4f6f678..c53b758 100644 (file)
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -794,6 +794,7 @@ int PmISDN::handler(void)
                                elapsed = ISDN_PRELOAD;
                        }
                }
+printf("p%d elapsed=%d\n", p_serial, elapsed);
                if (elapsed >= ISDN_TRANSMIT)
                {
                        unsigned char buf[mISDN_HEADER_LEN+ISDN_PRELOAD];
@@ -812,9 +813,9 @@ int PmISDN::handler(void)
                         * the part that is filles with tones (length) is skipped, so tones have priority
                         * the length value is increased by the number of data copied from fromup_buffer
                         */
+printf("p%d inbuffer=%d\n", p_serial, inbuffer);
                        if (inbuffer)
                        {
-                               printf("nix\n");
                                /* inbuffer might be less than we skip due to audio */
                                if (inbuffer <= length)
                                {
@@ -833,6 +834,7 @@ int PmISDN::handler(void)
                                        inbuffer = elapsed - length;
                                /* set length to what we actually have */
                                length = length + inbuffer;
+printf("p%d inbuffer=%d\n", p_serial, inbuffer);
                                /* now fill up with fromup_buffer */
                                while (inbuffer)
                                {
@@ -841,11 +843,11 @@ int PmISDN::handler(void)
                                        inbuffer--;
                                }
                        }
+printf("p%d length=%d\n", p_serial, length);
 
                        /* overwrite buffer with crypto stuff */
                        if (p_m_crypt_msg_loops)
                        {
-                               printf("nix2\n");
                                /* send pending message */
                                int tosend;
 
@@ -921,28 +923,6 @@ void PmISDN::bchannel_receive(iframe_t *frm)
        unsigned char *p;
        int l;
        unsigned long cont;
-//     iframe_t rsp; /* response to possible indication */
-#if 0
-#warning BCHANNEL-DEBUG
-{
-       // check if we are part of all ports */
-       class Port *port = port_first;
-       while(port)
-       {
-               if (port==this)
-                       break;
-               port=port->next;
-       }
-       if (!port)
-       {
-               PERROR_RUNTIME("**************************************************\n");
-               PERROR_RUNTIME("*** BCHANNEL-DEBUG: !this! is not in list of ports\n");
-               PERROR_RUNTIME("**************************************************\n");
-               return;
-       }
-}
-#endif
-
 
        if (frm->prim == (PH_CONTROL | INDICATION))
        {
@@ -952,7 +932,6 @@ void PmISDN::bchannel_receive(iframe_t *frm)
                        return;
                }
                cont = *((unsigned long *)&frm->data.p);
-               // PDEBUG(DEBUG_PORT, "PmISDN(%s) received a PH_CONTROL INDICATION 0x%x\n", p_name, cont);
                if ((cont&(~DTMF_TONE_MASK)) == DTMF_TONE_VAL)
                {
                        chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
@@ -1003,7 +982,7 @@ void PmISDN::bchannel_receive(iframe_t *frm)
                        end_trace();
                }
                return;
-       }       
+       }
        if (frm->prim != (PH_DATA | INDICATION) && frm->prim != (DL_DATA | INDICATION))
        {
                PERROR("Bchannel received unknown primitve: 0x%x\n", frm->prim);
@@ -1011,17 +990,13 @@ void PmISDN::bchannel_receive(iframe_t *frm)
        }
 
        /* calls will not process any audio data unless
-        * the call is connected OR tones feature is enabled.
+        * the call is connected OR interface features audio during call setup.
         */
-       if (p_state!=PORT_STATE_CONNECT
-        && !p_m_mISDNport->tones)
-               return;
-
+//printf("%d -> %d prim=%x calldata=%d tones=%d\n", p_serial, ACTIVE_EPOINT(p_epointlist), frm->prim, p_m_calldata, p_m_mISDNport->earlyb);    
+#warning "disabled for debug"
 #if 0
-       /* the bearer capability must be audio in order to send and receive
-        * audio prior or after connect.
-        */
-       if (!(p_bearerinfo.capability&CLASS_CAPABILITY_AUDIO) && p_state!=PORT_STATE_CONNECT)
+       if (p_state!=PORT_STATE_CONNECT
+        && !p_m_mISDNport->earlyb)
                return;
 #endif
 
@@ -1053,7 +1028,6 @@ void PmISDN::bchannel_receive(iframe_t *frm)
        /* send data to epoint */
        if (p_m_calldata && ACTIVE_EPOINT(p_epointlist)) /* only if we have an epoint object */
        {
-//printf("we are port %s and sending to epoint %d\n", p_m_cardname, p_epoint->serial);
                length_temp = frm->len;
                data_temp = p;
                while(length_temp)
@@ -1068,15 +1042,6 @@ void PmISDN::bchannel_receive(iframe_t *frm)
                        length_temp -= sizeof(message->param.data.data);
                }
        }
-#if 0
-       /* response to the data indication */
-       rsp.prim = frm->prim & 0xfffffffc | RESPONSE; 
-       rsp.addr = frm->addr & INST_ID_MASK | FLG_MSG_DOWN;
-       rsp.dinfo = frm->dinfo;
-       rsp.len = 0;
-       mISDN_write(mISDNdevice, &rsp, mISDN_HEADER_LEN+rsp.len, TIMEOUT_1SEC);
-//PDEBUG(DEBUG_ISDN, "written %d bytes.\n", length);
-#endif
 }
 
 
@@ -1222,7 +1187,8 @@ void PmISDN::message_mISDNsignal(unsigned long epoint_id, int message_id, union
                        if (p_m_b_channel)
                                if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
                                        ph_control(p_m_mISDNport, this, p_m_mISDNport->b_addr[p_m_b_index], VOL_CHANGE_TX, p_m_txvol, "DSP-TXVOL", p_m_txvol);
-               }
+               } else
+                       PDEBUG(DEBUG_BCHANNEL, "we already have tx-volume shift=%d.\n", p_m_rxvol);
                if (p_m_rxvol != param->mISDNsignal.rxvol)
                {
                        p_m_rxvol = param->mISDNsignal.rxvol;
@@ -1230,7 +1196,8 @@ void PmISDN::message_mISDNsignal(unsigned long epoint_id, int message_id, union
                        if (p_m_b_channel)
                                if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
                                        ph_control(p_m_mISDNport, this, p_m_mISDNport->b_addr[p_m_b_index], VOL_CHANGE_RX, p_m_rxvol, "DSP-RXVOL", p_m_rxvol);
-               }
+               } else
+                       PDEBUG(DEBUG_BCHANNEL, "we already have rx-volume shift=%d.\n", p_m_rxvol);
                break;
 
                case mISDNSIGNAL_CONF:
@@ -1243,7 +1210,8 @@ void PmISDN::message_mISDNsignal(unsigned long epoint_id, int message_id, union
                        if (p_m_b_channel)
                                if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
                                        ph_control(p_m_mISDNport, this, p_m_mISDNport->b_addr[p_m_b_index], (p_m_conf)?CMX_CONF_JOIN:CMX_CONF_SPLIT, p_m_conf, "DSP-CONF", p_m_conf);
-               }
+               } else
+                       PDEBUG(DEBUG_BCHANNEL, "we already have conf=%d.\n", p_m_conf);
                /* we must set, even if currently tone forbids conf */
                p_m_conf = param->mISDNsignal.conf;
 //if (dddebug) PDEBUG(DEBUG_ISDN, "dddebug = %d\n", dddebug->type);
@@ -1254,7 +1222,8 @@ void PmISDN::message_mISDNsignal(unsigned long epoint_id, int message_id, union
                {
                        p_m_calldata = param->mISDNsignal.calldata;
                        PDEBUG(DEBUG_BCHANNEL, "we change to calldata=%d.\n", p_m_calldata);
-               }
+               } else
+                       PDEBUG(DEBUG_BCHANNEL, "we already have calldata=%d.\n", p_m_calldata);
                break;
                
                case mISDNSIGNAL_DELAY:
@@ -1265,7 +1234,8 @@ void PmISDN::message_mISDNsignal(unsigned long epoint_id, int message_id, union
                        if (p_m_b_channel)
                                if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
                                        ph_control(p_m_mISDNport, this, p_m_mISDNport->b_addr[p_m_b_index], p_m_delay?CMX_DELAY:CMX_JITTER, p_m_delay, "DSP-DELAY", p_m_delay);
-               }
+               } else
+                       PDEBUG(DEBUG_BCHANNEL, "we already have delay=%d.\n", p_m_delay);
                break;
 
                default:
@@ -1736,7 +1706,7 @@ int mISDN_handler(void)
                        }
                        if (i == mISDNport->b_num)
                        {
-                               PERROR("unhandled b-message (address 0x%x).\n", frm->addr);
+                               PERROR("unhandled b-message (prim 0x%x address 0x%x).\n", frm->prim, frm->addr);
                                break;
                        }
                        if (mISDNport->b_port[i])
@@ -1761,7 +1731,7 @@ int mISDN_handler(void)
                        }
                        if (i == mISDNport->b_num)
                        {
-                               PERROR("unhandled b-establish (address 0x%x).\n", frm->addr);
+                               PERROR("unhandled b-establish (prim 0x%x address 0x%x).\n", frm->prim, frm->addr);
                                break;
                        }
                        bchannel_event(mISDNport, i, B_EVENT_ACTIVATED);
@@ -1781,7 +1751,7 @@ int mISDN_handler(void)
                        }
                        if (i == mISDNport->b_num)
                        {
-                               PERROR("unhandled b-release (address 0x%x).\n", frm->addr);
+                               PERROR("unhandled b-release (prim 0x%x address 0x%x).\n", frm->prim, frm->addr);
                                break;
                        }
                        bchannel_event(mISDNport, i, B_EVENT_DEACTIVATED);
diff --git a/main.c b/main.c
index 770ecb1..3d905d0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -200,6 +200,7 @@ int main(int argc, char *argv[])
 #endif
        int                     idletime = 0, idlecheck = 0;
        char                    debug_log[128];
+       char                    tracetext[256];
 
        /* current time */
        GET_NOW();
@@ -458,7 +459,10 @@ int main(int argc, char *argv[])
        created_signal = 1;
 
        /*** main loop ***/
-       printf("%s %s started, waiting for calls...\n", NAME, VERSION_STRING);
+       SPRINT(tracetext, "%s %s started, waiting for calls...", NAME, VERSION_STRING);
+       start_trace(0, NULL, NULL, NULL, 0, 0, 0, tracetext);
+       printf("%s\n", tracetext);
+       end_trace();
        GET_NOW();
 #ifdef DEBUG_DURATION
        start_d = now_d;
@@ -782,6 +786,10 @@ free:
 #define MEMCHECK(a, b) \
        if (b) \
        { \
+               SPRINT(tracetext, a, NAME); \
+               start_trace(0, NULL, NULL, NULL, 0, 0, 0, tracetext); \
+               if (ret) add_trace("blocks", NULL, "%d", b); \
+               end_trace(); \
                printf("\n******************************\n\007"); \
                printf("\nERROR: %d %s\n", b, a); \
                printf("\n******************************\n"); \
@@ -799,13 +807,13 @@ free:
        MEMCHECK("file handler(s) left",fhuse)
 
        /* take me out */
+       SPRINT(tracetext, "%s exit", NAME);
+       printf("%s\n", tracetext);
+       start_trace(0, NULL, NULL, NULL, 0, 0, 0, tracetext);
        if (ret)
-               printf("LCR: Exit (code %d)\n", ret);
-#ifdef VOIP
-       return;
-#else
+               add_trace("error", NULL, "%d", ret);
+       end_trace();
        return(ret);
-#endif
 }
 
 
index dac9a7a..079294f 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -4,8 +4,6 @@ BUG: release to NT not always work
 
 make asterisk call implementation
 
-trace to debug, log and socket
-
 avoid disconnect-collision (release if disconnect from both sides)
 
 display message during nothing/play
diff --git a/trace.c b/trace.c
index 43ba441..9453bd7 100644 (file)
--- a/trace.c
+++ b/trace.c
@@ -115,11 +115,11 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
        if (interface) if (interface[0] && trace.interface[0])
                if (!!strcasecmp(interface, trace.interface)) return(NULL);
        if (caller) if (caller[0] && trace.caller[0])
-               if (!!strcasecmp(caller, trace.caller)) return(NULL);
+               if (!!strncasecmp(caller, trace.caller, strlen(trace.caller))) return(NULL);
        if (dialing) if (dialing[0] && trace.dialing[0])
-               if (!!strcasecmp(dialing, trace.dialing)) return(NULL);
+               if (!!strncasecmp(dialing, trace.dialing, strlen(trace.dialing))) return(NULL);
        if (category && trace.category)
-               if (category != trace.category) return(NULL);
+               if (!(category & trace.category)) return(NULL);
 
        /* head */
        if (detail >= 3)
@@ -187,6 +187,13 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
                SCAT(trace_string, "------------------------------------------------------------------------------\n");
        }
 
+       if (detail < 3)
+       {
+               tm = localtime(&ti);
+               SPRINT(buffer, "%02d.%02d.%02d %02d:%02d:%02d.%03d ", tm->tm_mday, tm->tm_mon+1, tm->tm_year%100, tm->tm_hour, tm->tm_min, tm->tm_sec, trace.usec/1000);
+               SCAT(trace_string, buffer);
+       }
+
        /* "CH(45): CC_SETUP (net->user)" */
        switch (trace.category)
        {       case CATEGORY_CH:
@@ -271,21 +278,70 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
 void end_trace(void)
 {
        char *string;
+       FILE *fp;
+       struct admin_list       *admin;
+       struct admin_queue      *response, **responsep; /* response pointer */
 
        if (!trace.name[0])
                PERROR("trace not started\n");
        
-       /* process log file */
-       if (options.deb)
+       if (options.deb || options.log[0])
        {
                string = print_trace(1, 0, NULL, NULL, NULL, 0);
                if (string)
                {
-                       debug(NULL, 0, "trace", string);
+                       /* process debug */
+                       if (options.deb)
+                               debug(NULL, 0, "trace", string);
+                       /* process log */
+                       if (options.log[0])
+                       {
+                               fp = fopen(options.log, "a");
+                               if (fp)
+                               {
+                                       fwrite(string, strlen(string), 1, fp);
+                                       fclose(fp);
+                               }
+                       }
+               }
+       }
+
+       /* process admin */
+       admin = admin_list;
+       while(admin)
+       {
+               if (admin->trace.detail)
+               {
+                       string = print_trace(admin->trace.detail, admin->trace.port, admin->trace.interface, admin->trace.caller, admin->trace.dialing, admin->trace.category);
+                       if (string)
+                       {
+                               /* seek to end of response list */
+                               response = admin->response;
+                               responsep = &admin->response;
+                               while(response)
+                               {
+                                       responsep = &response->next;
+                                       response = response->next;
+                               }
+
+                               /* create state response */
+                               response = (struct admin_queue *)malloc(sizeof(struct admin_queue)+sizeof(admin_message));
+                               if (!response)
+                                       return;
+                               memuse++;
+                               memset(response, 0, sizeof(admin_queue)+sizeof(admin_message));
+                               response->num = 1;
+                               /* message */
+                               response->am[0].message = ADMIN_TRACE_RESPONSE;
+                               SCPY(response->am[0].u.trace_rsp.text, string);
+
+                               /* attach to response chain */
+                               *responsep = response;
+                               responsep = &response->next;
+                       }
                }
+               admin = admin->next;
        }
-printf("%s", print_trace(3, 0, NULL, NULL, NULL, 0));
-#warning trace auch zum socket
 //     fwrite(string, strlen(string), 1, fp);
 
        memset(&trace, 0, sizeof(struct trace));
diff --git a/trace.h b/trace.h
index 54fdefe..03078ba 100644 (file)
--- a/trace.h
+++ b/trace.h
@@ -39,6 +39,7 @@ struct trace {
 
 #define        CATEGORY_CH     0x01
 #define        CATEGORY_EP     0x02
+//#define CATEGORY_BC  0x04 check lcradmin help
 
 
 void start_trace(int port, struct interface *interface, char *caller, char *dialing, int direction, int category, int serial, char *name);