Ports can now be specified by number or by name.
[lcr.git] / lcradmin.c
index f771609..8cd40da 100644 (file)
@@ -23,6 +23,7 @@
 #include <errno.h>
 #include <curses.h>
 #include "macro.h"
+#include "options.h"
 #include "join.h"
 #include "joinpbx.h"
 #include "extension.h"
@@ -53,14 +54,14 @@ enum {
        MODE_TRACE,
 };
 
-char *text_interfaces[] = {
+const char *text_interfaces[] = {
        "off",
        "brief",
        "active channels",
        "all channels",
 };
 
-char *text_calls[] = {
+const char *text_calls[] = {
        "off",
        "brief",
        "structured",
@@ -76,7 +77,7 @@ char  red = 1,
 
 #define LOGLINES 128
 char logline[LOGLINES][512];
-unsigned long logcur = 0;
+unsigned int logcur = 0;
 int logfh = -1;
 char logfile[128];
 
@@ -209,7 +210,7 @@ int debug_port(struct admin_message *msg, struct admin_message *m, int line, int
 }
 int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, int i, int vline)
 {
-       unsigned long epoint = m[i].u.e.serial;
+       unsigned int epoint = m[i].u.e.serial;
        char buffer[256];
        unsigned char c;
        int j, jj;
@@ -359,7 +360,7 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
        }
        /* loop all related ports */
        ltee = 0;
-       j = msg->u.s.interfaces+msg->u.s.joins+msg->u.s.epoints;
+       j = msg->u.s.interfaces+msg->u.s.remotes+msg->u.s.joins+msg->u.s.epoints;
        jj = j + msg->u.s.ports;
        while(j < jj)
        {
@@ -392,7 +393,7 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i
 }
 int debug_join(struct admin_message *msg, struct admin_message *m, int line, int i)
 {
-       unsigned long   join = m[i].u.j.serial;
+       unsigned int    join = m[i].u.j.serial;
        char            buffer[256];
        int             j, jj;
 
@@ -416,7 +417,7 @@ int debug_join(struct admin_message *msg, struct admin_message *m, int line, int
                addstr(buffer);
        }
        /* find number of epoints */
-       j = msg->u.s.interfaces+msg->u.s.joins;
+       j = msg->u.s.interfaces+msg->u.s.remotes+msg->u.s.joins;
        jj = j + msg->u.s.epoints;
        i = 0;
        while(j < jj)
@@ -426,7 +427,7 @@ int debug_join(struct admin_message *msg, struct admin_message *m, int line, int
                j++;
        }
        /* loop all related endpoints */
-       j = msg->u.s.interfaces+msg->u.s.joins;
+       j = msg->u.s.interfaces+msg->u.s.remotes+msg->u.s.joins;
        jj = j + msg->u.s.epoints;
        while(j < jj)
        {
@@ -449,7 +450,8 @@ int debug_join(struct admin_message *msg, struct admin_message *m, int line, int
 
        return(line);
 }
-char *admin_state(int sock, char *argv[])
+
+const char *admin_state(int sock, char *argv[])
 {
        struct admin_message    msg,
                                *m;
@@ -457,7 +459,7 @@ char *admin_state(int sock, char *argv[])
                                *p;
        int                     line, offset = 0, hoffset = 0;
        int                     i, ii, j, jj, k;
-       unsigned long           l, ll;
+       unsigned int            l, ll;
        int                     num;
        int                     len;
        int                     off;
@@ -666,21 +668,24 @@ char *admin_state(int sock, char *argv[])
                        color(white);
                        if (m[i].u.i.block >= 2)
                        {
-                               SPRINT(buffer, "%s (%d)%s", m[i].u.i.interface_name, m[i].u.i.portnum, (m[i].u.i.extension)?" (extension)":"");
+                               SPRINT(buffer, "%s (port %d: %s)%s", m[i].u.i.interface_name, m[i].u.i.portnum, m[i].u.i.portname, (m[i].u.i.extension)?" extension":"");
                                addstr(buffer);
                                color(red);
                                addstr("  not loaded");
                        } else
                        {
-                               SPRINT(buffer, "%s (%d) %s %s%s use:%d", m[i].u.i.interface_name, m[i].u.i.portnum, (m[i].u.i.ntmode)?"NT-mode":"TE-mode", (m[i].u.i.ptp)?"ptp ":"ptmp", (m[i].u.i.extension)?" extension":"", m[i].u.i.use);
+                               SPRINT(buffer, "%s (port %d: %s) %s %s%s use:%d", m[i].u.i.interface_name, m[i].u.i.portnum, m[i].u.i.portname, (m[i].u.i.ntmode)?"NT-mode":"TE-mode", (m[i].u.i.ptp)?"ptp ":"ptmp", (m[i].u.i.extension)?" extension":"", m[i].u.i.use);
                                addstr(buffer);
                                if (m[i].u.i.ptp || !m[i].u.i.ntmode)
                                {
                                        color((m[i].u.i.l2link)?green:red);
                                        addstr((m[i].u.i.l2link)?"  L2 UP":"  L2 down");
                                }
-                               color((m[i].u.i.l1link)?green:blue);
-                               addstr((m[i].u.i.l1link)?"  L1 ACTIVE":"  L1 inactive");
+                               color((m[i].u.i.l1link > 0)?green:blue);
+                               if (m[i].u.i.l1link < 0)
+                                       addstr("  L1 unknown");
+                               else
+                                       addstr((m[i].u.i.l1link)?"  L1 ACTIVE":"  L1 inactive");
                                if (m[i].u.i.los)
                                {
                                        color(red);
@@ -736,6 +741,8 @@ char *admin_state(int sock, char *argv[])
                                                                SPRINT(buffer,"S%2d: ", j+1+(j>=15));
                                                        else
                                                                SPRINT(buffer,"B%2d: ", j+1);
+                                                       if (m[i].u.i.mode[j] == B_MODE_HDLC)
+                                                               SCAT(buffer,"HDLC ");
                                                        addstr(buffer);
                                                        switch(m[i].u.i.busy[j])
                                                        {
@@ -778,7 +785,7 @@ char *admin_state(int sock, char *argv[])
                                                        if (m[i].u.i.port[j])
                                                        {
                                                                /* search for port */
-                                                               l = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
+                                                               l = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins+msg.u.s.epoints;
                                                                ll = l+msg.u.s.ports;
                                                                while(l < ll)
                                                                {
@@ -834,7 +841,7 @@ char *admin_state(int sock, char *argv[])
                        i++;
                        anything = 1;
                }
-               i = 0;
+               i = msg.u.s.interfaces;
                ii = i + msg.u.s.remotes;
                while(i < ii)
                {
@@ -853,7 +860,7 @@ char *admin_state(int sock, char *argv[])
        if (show_calls == 1)
        {
                anything = 0;
-               i = msg.u.s.interfaces+msg.u.s.joins;
+               i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins;
                ii = i+msg.u.s.epoints;
                while(i < ii)
                {
@@ -892,7 +899,7 @@ char *admin_state(int sock, char *argv[])
                        i++;
                        anything = 1;
                }
-               j = msg.u.s.interfaces;
+               j = msg.u.s.interfaces+msg.u.s.remotes;
                jj = j+msg.u.s.joins;
                while(j < jj)
                {
@@ -901,7 +908,7 @@ char *admin_state(int sock, char *argv[])
                        color(white);
                        SPRINT(buffer, "(%d):", m[j].u.j.serial);
                        addstr(buffer);
-                       i = msg.u.s.interfaces+msg.u.s.joins;
+                       i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins;
                        ii = i+msg.u.s.epoints;
                        while(i < ii)
                        {
@@ -943,7 +950,7 @@ char *admin_state(int sock, char *argv[])
        {
                /* show all ports with no epoint */
                anything = 0;
-               i = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints;
+               i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins+msg.u.s.epoints;
                ii = i+msg.u.s.ports;
                while(i < ii)
                {
@@ -963,7 +970,7 @@ char *admin_state(int sock, char *argv[])
 
                /* show all epoints with no call */
                anything = 0;
-               i = msg.u.s.interfaces+msg.u.s.joins;
+               i = msg.u.s.interfaces+msg.u.s.remotes+msg.u.s.joins;
                ii = i+msg.u.s.epoints;
                while(i < ii)
                {
@@ -983,7 +990,7 @@ char *admin_state(int sock, char *argv[])
 
                /* show all joins */
                anything = 0;
-               i = msg.u.s.interfaces;
+               i = msg.u.s.interfaces+msg.u.s.remotes;
                ii = i+msg.u.s.joins;
                while(i < ii)
                {
@@ -1251,7 +1258,7 @@ char *admin_state(int sock, char *argv[])
 /*
  * Send command and show error message.
  */
-char *admin_cmd(int sock, int mode, char *extension, char *number)
+const char *admin_cmd(int sock, int mode, char *extension, char *number)
 {
        static struct admin_message msg;
 
@@ -1339,14 +1346,14 @@ char *admin_cmd(int sock, int mode, char *extension, char *number)
        gettimeofday(&now_tv, &now_tz); \
        now_d = ((double)(now_tv.tv_usec))/1000000 + now_tv.tv_sec; \
        }
-char *admin_testcall(int sock, int argc, char *argv[])
+const char *admin_testcall(int sock, int argc, char *argv[])
 {
        static struct admin_message msg;
        int ar = 2;
        int stimeout = 0, ptimeout = 0, atimeout = 0, ctimeout = 0;
        int l;
        double timer = 0, now_d;
-       unsigned long on = 1;
+       unsigned int on = 1;
        struct timeval now_tv;
        struct timezone now_tz;
 
@@ -1549,7 +1556,7 @@ next:
 /*
  * makes a trace
  */
-char *admin_trace(int sock, int argc, char *argv[])
+const char *admin_trace(int sock, int argc, char *argv[])
 {
        static struct admin_message msg;
        int i;
@@ -1625,10 +1632,9 @@ next:
 int main(int argc, char *argv[])
 {
        int mode;
-       char *socket_name = SOCKET_NAME;
        int sock, conn;
        struct sockaddr_un sock_address;
-       char *ret;
+       const char *ret;
 
 
        /* show options */
@@ -1712,6 +1718,10 @@ int main(int argc, char *argv[])
                goto usage;
        }
 
+       if (read_options() == 0) {
+               exit(EXIT_FAILURE);
+       }
+
 //pipeagain:
        /* open socket */
        if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) < 0)
@@ -1720,8 +1730,8 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
        memset(&sock_address, 0, sizeof(sock_address));
+       SPRINT(sock_address.sun_path, SOCKET_NAME, options.lock);
        sock_address.sun_family = PF_UNIX;
-       UCPY(sock_address.sun_path, socket_name);
        if ((conn = connect(sock, (struct sockaddr *)&sock_address, SUN_LEN(&sock_address))) < 0)
        {
                close(sock);