backup
[lcr.git] / admin_client.c
index 982b836..5ab45f6 100644 (file)
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <curses.h>
-#include "save.h"
+#include "macro.h"
 #include "call.h"
 #include "callpbx.h"
+#include "extension.h"
+#include "message.h"
 #include "admin.h"
 #include "cause.h"
 
@@ -482,11 +484,7 @@ char *admin_state(int sock)
                return("Response not valid. Expecting state response.");
        }
        num = msg.u.s.interfaces + msg.u.s.calls + msg.u.s.epoints + msg.u.s.ports;
-       if (!(m = (struct admin_message *)malloc(num*sizeof(struct admin_message))))
-       {
-               cleanup_curses();
-               return("Not enough memory for messages.");
-       }
+       m = (struct admin_message *)MALLOC(num*sizeof(struct admin_message));
        off=0;
        if (num)
        {
@@ -494,7 +492,7 @@ char *admin_state(int sock)
                if ((len = read(sock, ((unsigned char *)(m))+off, num*sizeof(struct admin_message)-off)) != num*(int)sizeof(struct admin_message)-off)
                {
                        if (len <= 0) {
-                               free(m);
+                               FREE(m, 0);
        //                      fprintf(stderr, "got=%d expected=%d\n", i, num*sizeof(struct admin_message));
                                cleanup_curses();
                                return("Broken pipe while receiving state infos.");
@@ -514,7 +512,7 @@ char *admin_state(int sock)
 //             fprintf(stderr, "j=%d message=%d\n", j, m[j].message);
                if (m[j].message != ADMIN_RESPONSE_S_INTERFACE)
                {
-                       free(m);
+                       FREE(m, 0);
                        cleanup_curses();
                        return("Response not valid. Expecting interface information.");
                }
@@ -526,7 +524,7 @@ char *admin_state(int sock)
        {
                if (m[j].message != ADMIN_RESPONSE_S_CALL)
                {
-                       free(m);
+                       FREE(m, 0);
                        cleanup_curses();
                        return("Response not valid. Expecting call information.");
                }
@@ -538,7 +536,7 @@ char *admin_state(int sock)
        {
                if (m[j].message != ADMIN_RESPONSE_S_EPOINT)
                {
-                       free(m);
+                       FREE(m, 0);
                        cleanup_curses();
                        return("Response not valid. Expecting endpoint information.");
                }
@@ -550,7 +548,7 @@ char *admin_state(int sock)
        {
                if (m[j].message != ADMIN_RESPONSE_S_PORT)
                {
-                       free(m);
+                       FREE(m, 0);
                        cleanup_curses();
                        return("Response not valid. Expecting port information.");
                }
@@ -946,7 +944,7 @@ char *admin_state(int sock)
 
        end:
        /* free memory */
-       free(m);
+       FREE(m, 0);
        /* display name/time */
 //     move(0, 0);
 //     hline(' ', COLS);
@@ -1251,7 +1249,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 +1282,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))