X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=trace.c;h=2f640a96660768e191f464076103cbf181cf9b39;hp=43ba44104d7c81793b9143a4faf27e0f93885641;hb=55a263bc1edd568d2fb85fcd2a8f3d118bebbeff;hpb=7b78740c6e5e4ad585d36c157333b8c5018dcc82 diff --git a/trace.c b/trace.c index 43ba441..2f640a9 100644 --- a/trace.c +++ b/trace.c @@ -32,10 +32,10 @@ static char *spaces[11] = { * 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, char *caller, char *dialing, int direction, int category, int serial, 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) @@ -59,12 +59,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, char *name, 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) @@ -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: @@ -201,7 +208,7 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch SCAT(trace_string, "--"); } if (trace.serial) - SPRINT(buffer, "(%d): %s", trace.serial, trace.name[0]?trace.name:""); + SPRINT(buffer, "(%lu): %s", trace.serial, trace.name[0]?trace.name:""); else SPRINT(buffer, ": %s", trace.name[0]?trace.name:""); SCAT(trace_string, buffer); @@ -210,6 +217,11 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch switch(detail) { case 1: /* brief */ + if (trace.port) + { + SPRINT(buffer, " port %d", trace.port); + SCAT(trace_string, buffer); + } i = 0; while(i < trace.elements) { @@ -268,24 +280,70 @@ 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; + struct admin_list *admin; + 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); - /* 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); + } + } } } -printf("%s", print_trace(3, 0, NULL, NULL, NULL, 0)); -#warning trace auch zum socket + + /* process admin */ + admin = admin_first; + 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)); + memuse++; + 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; + } // fwrite(string, strlen(string), 1, fp); memset(&trace, 0, sizeof(struct trace)); @@ -294,4 +352,3 @@ printf("%s", print_trace(3, 0, NULL, NULL, NULL, 0)); -