Added layer1 hold feature. Requires new mISDN and mISDNuser package from git.
[lcr.git] / trace.c
diff --git a/trace.c b/trace.c
index 02a39b3..2050a2d 100644 (file)
--- a/trace.c
+++ b/trace.c
 struct trace trace;
 char trace_string[MAX_TRACE_ELEMENTS * 100 + 400];
 
-static char *spaces[11] = {
-       "          ",
-       "         ",
-       "        ",
-       "       ",
-       "      ",
-       "     ",
-       "    ",
-       "   ",
-       "  ",
-       " ",
-       "",
-};
+static const char *spaces = "          ";
 
 /*
  * initializes a new trace
  * all values will be reset
  */
-void start_trace(int port, struct interface *interface, char *caller, char *dialing, int direction, int category, int serial, char *name)
+void _start_trace(const char *__file, int __line, int port, struct interface *interface, const char *caller, const char *dialing, int direction, int category, int serial, const char *name)
 {
        if (trace.name[0])
-               PERROR("trace already started (name=%s)\n", trace.name);
+               PERROR("trace already started (name=%s) in file %s line %d\n", trace.name, __file, __line);
        memset(&trace, 0, sizeof(struct trace));
        trace.port = port;
        if (interface)
@@ -49,6 +37,8 @@ void start_trace(int port, struct interface *interface, char *caller, char *dial
        trace.serial = serial;
        if (name) if (name[0])
                SCPY(trace.name, name);
+       if (!trace.name[0])
+               SCPY(trace.name, "<unknown>");
        trace.sec = now_tv.tv_sec;
        trace.usec = now_tv.tv_usec;
 }
@@ -59,12 +49,12 @@ void start_trace(int port, struct interface *interface, char *caller, char *dial
  * if subelement is given, element will also contain a subelement
  * if multiple subelements belong to same element, name must be equal for all subelements
  */
-void add_trace(char *name, char *sub, const char *fmt, ...)
+void _add_trace(const char *__file, int __line, const char *name, const char *sub, const char *fmt, ...)
 {
        va_list args;
 
        if (!trace.name[0])
-               PERROR("trace not started\n");
+               PERROR("trace not started in file %s line %d\n", __file, __line);
        
        /* check for required name value */
        if (!name)
@@ -110,7 +100,7 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
                return(NULL);
 
        /* filter trace */
-       if (port && trace.port)
+       if (port >= 0 && trace.port >= 0)
                if (port != trace.port) return(NULL);
        if (interface) if (interface[0] && trace.interface[0])
                if (!!strcasecmp(interface, trace.interface)) return(NULL);
@@ -126,7 +116,7 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
        {
                SCAT(trace_string, "------------------------------------------------------------------------------\n");
                /* "Port: 1 (BRI PTMP TE)" */
-               if (trace.port)
+               if (trace.port >= 0)
                {
                        mISDNport = mISDNport_first;
                        while(mISDNport)
@@ -217,6 +207,11 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
        switch(detail)
        {
                case 1: /* brief */
+               if (trace.port >= 0)
+               {
+                       SPRINT(buffer, "  port %d", trace.port);
+                       SCAT(trace_string, buffer);
+               }
                i = 0;
                while(i < trace.elements)
                {
@@ -245,12 +240,12 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
                i = 0;
                while(i < trace.elements)
                {
-                       SPRINT(buffer, " %s%s", trace.element[i].name, spaces[strlen(trace.element[i].name)]);
+                       SPRINT(buffer, " %s%s", trace.element[i].name, &spaces[strlen(trace.element[i].name)]);
                        if (i) if (!strcmp(trace.element[i].name, trace.element[i-1].name))
                                SPRINT(buffer, "           ");
                        SCAT(trace_string, buffer);
                        if (trace.element[i].sub[0])
-                               SPRINT(buffer, " : %s%s = ", trace.element[i].sub, spaces[strlen(trace.element[i].sub)]);
+                               SPRINT(buffer, " : %s%s = ", trace.element[i].sub, &spaces[strlen(trace.element[i].sub)]);
                        else
                                SPRINT(buffer, " :              ");
                        SCAT(trace_string, buffer);
@@ -275,7 +270,7 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch
  * trace ends
  * this function will put the trace to sockets and logfile, if requested
  */
-void end_trace(void)
+void _end_trace(const char *__file, int __line)
 {
        char *string;
        FILE *fp;
@@ -283,11 +278,11 @@ void end_trace(void)
        struct admin_queue      *response, **responsep; /* response pointer */
 
        if (!trace.name[0])
-               PERROR("trace not started\n");
+               PERROR("trace not started in file %s line %d\n", __file, __line);
        
        if (options.deb || options.log[0])
        {
-               string = print_trace(1, 0, NULL, NULL, NULL, 0);
+               string = print_trace(1, -1, NULL, NULL, NULL, 0);
                if (string)
                {
                        /* process debug */
@@ -307,7 +302,7 @@ void end_trace(void)
        }
 
        /* process admin */
-       admin = admin_list;
+       admin = admin_first;
        while(admin)
        {
                if (admin->trace.detail)