backup
[lcr.git] / admin_client.c
index 41430f6..7e0e603 100644 (file)
@@ -43,6 +43,7 @@ enum {
        MODE_DIAL,
        MODE_RELEASE,
        MODE_TESTCALL,
+       MODE_TRACE,
 };
 
 char *text_interfaces[] = {
@@ -1202,6 +1203,84 @@ next:
 
 
 /*
+ * makes a trace
+ */
+char *admin_trace(int sock, int argc, char *argv[])
+{
+       static struct admin_message msg;
+       int i;
+
+       /* show help */
+       if (!strcasecmp(argv[2], "help"))
+       {
+               printf("Trace Help\n----------\n");
+               printf("%s trace [brief|short] [<filter>=<value> [...]]\n\n", argv[0]);
+               printf("By default a complete trace is shown in detailed format.\n");
+               printf("To show a more compact format, use 'brief' or 'short' keyword.\n");
+               printf("Use filter values to select specific trace messages.\n");
+               printf("All given filter values must match. If no filter is given, anything matches.\n\n");
+               printf("Filters:\n");
+               printf(" category=<mask bits>\n");
+               printf("  0x01 = L1: layer 1 trace (application view)\n");
+               printf("  0x02 = L2: layer 2 trace (application view)\n");
+               printf("  0x04 = L3: layer 3 trace (application view)\n");
+               printf("  0x08 = CH: channel selection trace\n");
+               printf("  0x10 = EP: endpoint trace\n");
+               printf("  0x20 = AP: application trace\n");
+               printf("  0x40 = RO: routing trace\n");
+               printf(" port=<mISDN port>  select only given port for trace\n");
+               printf(" interface=<interface name>  select only given interface for trace\n");
+               printf(" caller=<caller id>  select only given caller id for trace\n");
+               printf(" dialing=<number>  select only given dialed number for trace\n");
+               return(NULL);
+       }
+
+       /* init trace request */        
+       memset(&msg, 0, sizeof(msg));
+       msg.message = ADMIN_TRACE_REQUEST;
+       msg.u.trace_req.detail = 3;
+
+       /* parse args */
+       i = 2;
+       while(i < argc)
+       {
+               if (!strcasecmp(argv[i], "brief"))
+                       msg.u.trace_req.detail = 1;
+               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);
+               else if (!strncasecmp(argv[i], "port=", 5))
+                       msg.u.trace_req.port = atoi(argv[i]+5);
+               else if (!strncasecmp(argv[i], "interface=", 10))
+                       SCPY(msg.u.trace_req.interface, argv[i]+10);
+               else if (!strncasecmp(argv[i], "caller=", 7))
+                       SCPY(msg.u.trace_req.caller, argv[i]+7);
+               else if (!strncasecmp(argv[i], "dialing=", 8))
+                       SCPY(msg.u.trace_req.dialing, argv[i]+8);
+               else return("Invalid trace option, try 'trace help'.");
+
+               i++;
+       }
+
+       /* send trace request */
+       if (write(sock, &msg, sizeof(msg)) != sizeof(msg))
+               return("Broken pipe while sending trace request.");
+
+       /* receive response */
+next:
+       if (read(sock, &msg, sizeof(msg)) != sizeof(msg))
+               return("Broken pipe while receiving response.");
+
+       if (msg.message != ADMIN_TRACE_RESPONSE)
+               return("Response not valid.");
+
+       printf("%s", msg.u.trace_rsp.text);
+       goto next;
+}
+
+
+/*
  * main function
  */
 int main(int argc, char *argv[])
@@ -1226,6 +1305,8 @@ int main(int argc, char *argv[])
                printf("release <number> - Tell PBX to release endpoint with given number.\n");
                printf("testcall <interface> <callerid> <number> [present|restrict [<capability>]] - Testcall\n");
                printf(" -> capability = <bc> <mode> <codec> <hlc> <exthlc> (Values must be numbers, -1 to omit.)\n");
+               printf("trace [brief|short] [<filter> [...]] - Shows call trace. Use filter to reduce output.\n");
+               printf(" -> Use 'trace help' to see filter description.\n");
                printf("\n");
                return(0);
        }
@@ -1261,6 +1342,10 @@ int main(int argc, char *argv[])
                        goto usage;
                mode = MODE_TESTCALL;
        } else
+       if (!(strcasecmp(argv[1],"trace")))
+       {
+               mode = MODE_TRACE;
+       } else
        {
                goto usage;
        }
@@ -1304,6 +1389,9 @@ int main(int argc, char *argv[])
 
                case MODE_TESTCALL:
                ret = admin_testcall(sock, argc, argv);
+
+               case MODE_TRACE:
+               ret = admin_trace(sock, argc, argv);
        }
 
        close(sock);