]> code.citadel.org Git - citadel.git/blobdiff - citadel/routines.c
* First cut at Solaris fixes. There may still be some *printf("%s", NULL)
[citadel.git] / citadel / routines.c
index 2cea59f5ae56f42dc9508a8a6fc2c298e7f7dffd..6757a59f0d70e47e861b35e1d0cfadc22c14e752 100644 (file)
 #include <errno.h>
 #include <time.h>
 #include <limits.h>
+#ifdef HAVE_UTMP_H
+#include <utmp.h>
+#endif
+#ifdef HAVE_UTMPX_H
+#include <utmpx.h>
+#endif
+
+#ifndef HAVE_GETUTLINE
+struct utmp *getutline(struct utmp *ut);
+#endif
 
 #define ROUTINES_C
 
 #include "citadel.h"
 #include "routines.h"
 #include "commands.h"
+#include "tools.h"
 
 void sttybbs(int cmd);
 void newprompt(char *prompt, char *str, int len);
-void val_user(char *user);
+void val_user(char *, int);
 void formout(char *name);
 void logoff(int code);
 void set_keepalives(int s);
@@ -41,6 +52,7 @@ extern char *axdefs[7];
 extern char sigcaught;
 extern struct CtdlServInfo serv_info;
 extern char rc_floor_mode;
+extern int rc_ansi_color;
 
 int struncmp(char *lstr, char *rstr, int len)
 {
@@ -58,82 +70,6 @@ int struncmp(char *lstr, char *rstr, int len)
        }
 
 
-/* 
- * check for the presence of a character within a string (returns count)
- */
-int haschar(char *st, int ch)
-{
-       int a,b;
-       b=0;
-       for (a=0; a<strlen(st); ++a) if (st[a]==ch) ++b;
-       return(b);
-       }
-
-
-/*
- * num_parms()  -  discover number of parameters...
- */
-int num_parms(char *source)
-{
-       int a;
-       int count = 1;
-
-       for (a=0; a<strlen(source); ++a) 
-               if (source[a]=='|') ++count;
-       return(count);
-       }
-
-/*
- * extract()  -  extract a parameter from a series of "|" separated...
- */
-void extract(char *dest, char *source, int parmnum)
-{
-       char buf[256];
-       int count = 0;
-       int n;
-
-       n = num_parms(source);
-
-       if (parmnum >= n) {
-               strcpy(dest,"");
-               return;
-               }
-       strcpy(buf,source);
-       if ( (parmnum == 0) && (n == 1) ) {
-               strcpy(dest,buf);
-               return;
-               }
-
-       while (count++ < parmnum) do {
-               strcpy(buf,&buf[1]);
-               } while( (strlen(buf)>0) && (buf[0]!='|') );
-       if (buf[0]=='|') strcpy(buf,&buf[1]);
-       for (count = 0; count<strlen(buf); ++count)
-               if (buf[count] == '|') buf[count] = 0;
-       strcpy(dest,buf);
-       }
-
-/*
- * extract_int()  -  extract an int parm w/o supplying a buffer
- */
-int extract_int(char *source, int parmnum)
-{
-       char buf[256];
-       
-       extract(buf,source,parmnum);
-       return(atoi(buf));
-       }
-
-/*
- * extract_long()  -  extract a long parm w/o supplying a buffer
- */
-long extract_long(char *source, int parmnum)
-{
-       char buf[256];
-       
-       extract(buf,source,parmnum);
-       return(atol(buf));
-       }
 
 void back(int spaces) /* Destructive backspace */
             {
@@ -146,7 +82,10 @@ int a;
 void hit_any_key(void) {               /* hit any key to continue */
        int a,b;
 
+       color(COLOR_PUSH);
+       color(DIM_RED);
        printf("%s\r",serv_info.serv_moreprompt);
+       color(COLOR_POP);
        sttybbs(0);
        b=inkey();
        for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
@@ -191,8 +130,9 @@ void edituser(void)
        lastcall = extract_long(&buf[4], 7);
        userpurge = extract_int(&buf[4], 8);
 
-       val_user(who); /* Display registration, and set access level */
+       val_user(who, 0); /* Display registration */
        strprompt("Password", pass, 19);
+       axlevel = intprompt("Access level", axlevel, 0, 6);
        timescalled = intprompt("Times called", timescalled, 0, INT_MAX);
        posted = intprompt("Messages posted", posted, 0, INT_MAX);
        lastcall = (boolprompt("Set last call to now", 0)?time(NULL):lastcall);
@@ -201,7 +141,7 @@ void edituser(void)
 
        sprintf(buf, "ASUP %s|%s|%d|%d|%d|%d|%ld|%ld|%d",
                who, pass, flags, timescalled, posted, axlevel, usernum,
-               lastcall, userpurge);
+               (long)lastcall, userpurge);
        serv_puts(buf);
        serv_gets(buf);
        if (buf[0]!='2') {
@@ -216,15 +156,17 @@ int set_attr(int sval, char *prompt, unsigned int sbit)
        int temp;
 
        temp = sval;
-       color(3);
-       printf("%45s [", prompt);
-       color(1);
+       color(DIM_WHITE);
+       printf("%45s ", prompt);
+       color(DIM_MAGENTA);
+       printf("[");
+       color(BRIGHT_MAGENTA);
        printf("%3s", ((temp&sbit) ? "Yes":"No"));
-       color(3);
+       color(DIM_MAGENTA);
        printf("]? ");
-       color(2);
+       color(BRIGHT_CYAN);
        a=yesno_d(temp&sbit);
-       color(7);
+       color(DIM_WHITE);
        temp=(temp|sbit);
        if (!a) temp=(temp^sbit);
        return(temp);
@@ -273,6 +215,10 @@ void enter_config(int mode)
          flags = set_attr(flags,
                "View rooms by floor",US_FLOORS);
          }
+        if (rc_ansi_color == 3) {
+         flags = set_attr(flags,
+               "Enable color support",US_COLOR);
+         }
         }
 
        if (mode==2) {
@@ -451,6 +397,7 @@ void progress(long int curr, long int cmax)
  */
 void locate_host(char *hbuf)
 {
+#ifndef HAVE_UTMP_H
        char buf[256];
        FILE *who;
        int a,b;
@@ -483,6 +430,46 @@ void locate_host(char *hbuf)
 
        if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
        else strncpy(hbuf,buf,24);
+#else
+       char *tty = ttyname(0);
+#ifdef HAVE_GETUTXLINE
+       struct utmpx ut, *put;
+#else
+       struct utmp ut, *put;
+#endif
+
+       if (tty == NULL) {
+           fail:
+               safestrncpy(hbuf, serv_info.serv_fqdn, 24);
+               return;
+               }
+
+       if (strncmp(tty, "/dev/", 5))
+               goto fail;
+
+       safestrncpy(ut.ut_line, &tty[5], sizeof ut.ut_line);
+
+#ifdef HAVE_GETUTXLINE /* Solaris uses this */
+       if ((put = getutxline(&ut)) == NULL)
+#else
+       if ((put = getutline(&ut)) == NULL)
+#endif
+               goto fail;
+
+#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
+       if (put->ut_type == USER_PROCESS) {
+#endif
+#if defined(HAVE_UT_HOST) || defined(HAVE_GETUTXLINE)
+               if (*put->ut_host)
+                       safestrncpy(hbuf, put->ut_host, 24);
+               else
+#endif
+                       safestrncpy(hbuf, put->ut_line, 24);
+#if defined(HAVE_UT_TYPE) || defined(HAVE_GETUTXLINE)
+               }
+       else goto fail;
+#endif
+#endif /* HAVE_UTMP_H */
        }
 
 /*
@@ -495,9 +482,11 @@ void misc_server_cmd(char *cmd) {
        serv_gets(buf);
        printf("%s\n",buf);
        if (buf[0]=='1') {
+               set_keepalives(KA_NO);
                while (serv_gets(buf), strcmp(buf,"000")) {
                        printf("%s\n",buf);
                        }
+               set_keepalives(KA_YES);
                return;
                }
        if (buf[0]=='4') {