Back to index

citadel  8.12
Defines | Functions | Variables
routines.c File Reference
#include "sysdep.h"
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <pwd.h>
#include <signal.h>
#include <dirent.h>
#include <errno.h>
#include <time.h>
#include <libcitadel.h>
#include "citadel.h"
#include "citadel_ipc.h"
#include "screen.h"
#include "routines.h"
#include "commands.h"
#include "citadel_decls.h"
#include "routines2.h"
#include "tuiconfig.h"

Go to the source code of this file.

Defines

#define ROUTINES_C
#define IFAIDE   if(axlevel>=AxAideU)
#define IFNAIDE   if (axlevel<AxAideU)

Functions

struct utmp * getutline (struct utmp *ut)
void back (int spaces)
void edituser (CtdlIPC *ipc, int cmd)
int set_attr (CtdlIPC *ipc, unsigned int sval, char *prompt, unsigned int sbit, int backwards)
void enter_config (CtdlIPC *ipc, int mode)
int getstring (FILE *fp, char *string)
int pattern (char *search, char *patn)
void strproc (char *string)
char * strerror (int e)
void progress (CtdlIPC *ipc, unsigned long curr, unsigned long cmax)
void locate_host (CtdlIPC *ipc, char *hbuf)
void misc_server_cmd (CtdlIPC *ipc, char *cmd)
int file_checksum (char *filename)
int nukedir (char *dirname)

Variables

unsigned userflags
char sigcaught
char rc_floor_mode
int rc_ansi_color
int rc_prompt_control

Define Documentation

#define IFAIDE   if(axlevel>=AxAideU)

Definition at line 68 of file routines.c.

#define IFNAIDE   if (axlevel<AxAideU)

Definition at line 69 of file routines.c.

#define ROUTINES_C

Definition at line 59 of file routines.c.


Function Documentation

void back ( int  spaces)

Definition at line 79 of file routines.c.

                      {
       int a;
       for (a=0; a<spaces; ++a) {
              scr_putc(8);
              scr_putc(32);
              scr_putc(8);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void edituser ( CtdlIPC ipc,
int  cmd 
)

Definition at line 91 of file routines.c.

{
       char buf[SIZ];
       char who[USERNAME_SIZE];
       char newname[USERNAME_SIZE];
       struct ctdluser *user = NULL;
       int newnow = 0;
       int r;                      /* IPC response code */
       int change_name = 0;

       strcpy(newname, "");

       newprompt("User name: ", who, 29);
       while ((r = CtdlIPCAideGetUserParameters(ipc, who, &user, buf)) / 100 != 2) {
              scr_printf("%s\n", buf);
              if (cmd == 25) {
                     scr_printf("Do you want to create this user? ");
                     if (yesno()) {
                            r = CtdlIPCCreateUser(ipc, who, 0, buf);
                            if (r / 100 == 2) {
                                   newnow = 1;
                                   continue;
                            }
                            scr_printf("%s\n", buf);
                     }
              }
              free(user);
              return;
       }

       if (cmd == 25) {
              val_user(ipc, user->fullname, 0); /* Display registration */

              if (!newnow) {
                     change_name = 1;
                     while (change_name == 1) {
                            if (boolprompt("Change name", 0)) {
                                   strprompt("New name", newname, USERNAME_SIZE-1);
                                   r = CtdlIPCRenameUser(ipc, user->fullname, newname, buf);
                                   if (r / 100 != 2) {
                                          scr_printf("%s\n", buf);
                                   }
                                   else {
                                          strcpy(user->fullname, newname);
                                          change_name = 0;
                                   }
                            }
                            else {
                                   change_name = 0;
                            }
                     }
              }

              if (newnow || boolprompt("Change password", 0)) {
                     strprompt("Password", user->password, -19);
              }
       
              user->axlevel = intprompt("Access level", user->axlevel, 0, 6);
              if (boolprompt("Permission to send Internet mail", (user->flags & US_INTERNET)))
                     user->flags |= US_INTERNET;
              else
                     user->flags &= ~US_INTERNET;
              if (boolprompt("Ask user to register again", !(user->flags & US_REGIS)))
                     user->flags &= ~US_REGIS;
              else
                     user->flags |= US_REGIS;
              user->timescalled = intprompt("Times called",
                            user->timescalled, 0, INT_MAX);
              user->posted = intprompt("Messages posted",
                                   user->posted, 0, INT_MAX);
              user->lastcall = boolprompt("Set last call to now", 0) ?
                                   time(NULL) : user->lastcall;
              user->USuserpurge = intprompt("Purge time (in days, 0 for system default",
                            user->USuserpurge, 0, INT_MAX);
       }

       if (cmd == 96) {
              scr_printf("Do you want to delete this user? ");
              if (!yesno()) {
                     free(user);
                     return;
              }
              user->axlevel = AxDeleted;
       }

       r = CtdlIPCAideSetUserParameters(ipc, user, buf);
       if (r / 100 != 2) {
              scr_printf("%s\n", buf);
       }
       free(user);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void enter_config ( CtdlIPC ipc,
int  mode 
)

Definition at line 225 of file routines.c.

{
       char buf[SIZ];
       struct ctdluser *user = NULL;
       int r;                      /* IPC response code */

       r = CtdlIPCGetConfig(ipc, &user, buf);
       if (r / 100 != 2) {
              scr_printf("%s\n", buf);
              free(user);
              return;
       }

       if (mode == 0 || mode == 1) {

              user->flags = set_attr(ipc, user->flags,
                                   "Are you an experienced Citadel user",
                                   US_EXPERT, 0);
              if ((user->flags & US_EXPERT) == 0 && mode == 1) {
                     free(user);
                     return;
              }

              user->flags = set_attr(
                     ipc,
                     user->flags,
                     "Print last old message on New message request",
                     US_LASTOLD,
                     0
              );

              user->flags = set_attr(
                     ipc,
                     user->flags,
                     "Prompt after each message",
                     US_NOPROMPT,
                     1
              );

              if ((user->flags & US_NOPROMPT) == 0) {
                     user->flags = set_attr(
                            ipc,
                            user->flags,
                            "Use 'disappearing' prompts",
                            US_DISAPPEAR,
                            0
                     );
              }

              user->flags = set_attr(
                     ipc,
                     user->flags,
                     "Pause after each screenful of text",
                     US_PAGINATOR,
                     0
              );

              if (rc_prompt_control == 3 && (user->flags & US_PAGINATOR)) {
                     user->flags = set_attr(
                            ipc,
                            user->flags,
                            "<N>ext and <S>top work at paginator prompt",
                            US_PROMPTCTL,
                            0
                     );
              }

              if (rc_floor_mode == RC_DEFAULT) {
                     user->flags = set_attr(
                            ipc,
                            user->flags,
                            "View rooms by floor",
                            US_FLOORS,
                            0
                     );
              }

              if (rc_ansi_color == 3) {
                     user->flags = set_attr(
                            ipc,
                            user->flags,
                            "Enable color support",
                            US_COLOR,
                            0
                     );
              }

              if ((user->flags & US_EXPERT) == 0) {
                     formout(ipc, "unlisted");
              }

              user->flags = set_attr(
                     ipc,
                     user->flags,
                     "Be unlisted in userlog",
                     US_UNLISTED,
                     0
              );

              if (!IsEmptyStr(editor_path)) {
                     user->flags = set_attr(
                            ipc,
                            user->flags,
                            "Always enter messages with the full-screen editor",
                            US_EXTEDIT,
                            0
                     );
              }

       }

       if (mode == 2) {
              if (user->flags & US_EXPERT) {
                     user->flags ^= US_EXPERT;
                     scr_printf("Expert mode now OFF\n");
              } else {
                     user->flags |= US_EXPERT;
                     scr_printf("Expert mode now ON\n");
              }
       }

       if (mode == 3) {
              if (user->flags & US_FLOORS) {
                     user->flags ^= US_FLOORS;
                     scr_printf("Floor mode now OFF\n");
              } else {
                     user->flags |= US_FLOORS;
                     scr_printf("Floor mode now ON\n");
              }
       }

       r = CtdlIPCSetConfig(ipc, user, buf);
       if (r / 100 != 2) scr_printf("%s\n", buf);
       userflags = user->flags;
       free(user);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int file_checksum ( char *  filename)

Definition at line 584 of file routines.c.

{
       int cksum = 0;
       int ch;
       FILE *fp;

       fp = fopen(filename,"r");
       if (fp == NULL) return(0);

       /* yes, this algorithm may allow cksum to overflow, but that's ok
        * as long as it overflows consistently, which it will.
        */
       while (ch=getc(fp), ch>=0) {
              cksum = (cksum + ch);
       }

       fclose(fp);
       return(cksum);
}

Here is the caller graph for this function:

int getstring ( FILE *  fp,
char *  string 
)

Definition at line 366 of file routines.c.

{
       int a,c;
       do {
              strcpy(string,"");
              a=0;
              do {
                     c=getc(fp);
                     if (c<0) {
                            string[a]=0;
                            return(-1);
                     }
                     string[a++]=c;
              } while(c!=10);
                     string[a-1]=0;
       } while(string[0]=='#');
       return(strlen(string));
}
struct utmp* getutline ( struct utmp *  ut) [read]

Here is the caller graph for this function:

void locate_host ( CtdlIPC ipc,
char *  hbuf 
)

Definition at line 477 of file routines.c.

{
#ifndef HAVE_UTMP_H
       char buf[SIZ];
       FILE *who;
       int a,b;

       who = (FILE *)popen("who am i","r");
       if (who==NULL) {
              strcpy(hbuf, ipc->ServInfo.fqdn);
              return;       
       }
       fgets(buf,sizeof buf,who);
       pclose(who);

       b = 0;
       for (a=0; !IsEmptyStr(&buf[a]); ++a) {
              if ((buf[a]=='(')||(buf[a]==')')) ++b;
       }
       if (b<2) {
              strcpy(hbuf, ipc->ServInfo.fqdn);
              return;
       }

       for (a=0; a<strlen(buf); ++a) {
              if (buf[a]=='(') {
                     strcpy(buf,&buf[a+1]);
              }
       }
       for (a=0; a<strlen(buf); ++a) {
              if (buf[a]==')') buf[a] = 0;
       }

       if (IsEmptyStr(buf)) strcpy(hbuf, ipc->ServInfo.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, ipc->ServInfo.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 */
}

Here is the call graph for this function:

void misc_server_cmd ( CtdlIPC ipc,
char *  cmd 
)

Definition at line 557 of file routines.c.

                                              {
       char buf[SIZ];

       CtdlIPC_chat_send(ipc, cmd);
       CtdlIPC_chat_recv(ipc, buf);
       scr_printf("%s\n",buf);
       if (buf[0]=='1') {
              set_keepalives(KA_HALF);
              while (CtdlIPC_chat_recv(ipc, buf), strcmp(buf,"000")) {
                     scr_printf("%s\n",buf);
              }
              set_keepalives(KA_YES);
              return;
       }
       if (buf[0]=='4') {
              do {
                     newprompt("> ",buf,255);
                     CtdlIPC_chat_send(ipc, buf);
              } while(strcmp(buf,"000"));
              return;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nukedir ( char *  dirname)

Definition at line 607 of file routines.c.

{
       DIR *dp;
       struct dirent *d;
       char filename[SIZ];

       dp = opendir(dirname);
       if (dp == NULL) {
              return(errno);
       }

       while (d = readdir(dp), d != NULL) {
              snprintf(filename, sizeof filename, "%s/%s",
                     dirname, d->d_name);
              unlink(filename);
       }

       closedir(dp);
       return(rmdir(dirname));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pattern ( char *  search,
char *  patn 
)

Definition at line 387 of file routines.c.

                                      {
       int a,b,len;
       
       len = strlen(patn);
       for (a=0; !IsEmptyStr(&search[a]); ++a) {
              b=strncasecmp(&search[a],patn,len);
              if (b==0) return(b);
       }
       return(-1);
}

Here is the caller graph for this function:

void progress ( CtdlIPC ipc,
unsigned long  curr,
unsigned long  cmax 
)

Definition at line 450 of file routines.c.

{
       static char dots[] =
              "**************************************************";
       char dots_printed[51];
       char fmt[42];
       unsigned long a;

       if (curr >= cmax) {
              scr_printf("\r%79s\r","");
       } else {
              /* a will be range 0-50 rather than 0-100 */
              a=(curr * 50) / cmax;
              sprintf(fmt, "[%%s%%%lds] %%3ld%%%% %%10ld/%%10ld\r", 50 - a);
              strncpy(dots_printed, dots, a);
              dots_printed[a] = 0;
              scr_printf(fmt, dots_printed, "",
                            curr * 100 / cmax, curr, cmax);
              scr_flush();
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int set_attr ( CtdlIPC ipc,
unsigned int  sval,
char *  prompt,
unsigned int  sbit,
int  backwards 
)

Definition at line 188 of file routines.c.

{
       int a;
       int temp;

       temp = sval;
       color(DIM_WHITE);
       scr_printf("%50s ", prompt);
       color(DIM_MAGENTA);
       scr_printf("[");
       color(BRIGHT_MAGENTA);

       if (backwards) {
              scr_printf("%3s", ((temp&sbit) ? "No":"Yes"));
       }
       else {
              scr_printf("%3s", ((temp&sbit) ? "Yes":"No"));
       }

       color(DIM_MAGENTA);
       scr_printf("]? ");
       color(BRIGHT_CYAN);
       a = (temp & sbit);
       if (a != 0) a = 1;
       if (backwards) a = 1 - a;
       a = yesno_d(a);
       if (backwards) a = 1 - a;
       color(DIM_WHITE);
       temp = (temp|sbit);
       if (!a) temp = (temp^sbit);
       return(temp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* strerror ( int  e)

Definition at line 440 of file routines.c.

{
       static char buf[128];

       snprintf(buf, sizeof buf, "errno = %d",e);
       return(buf);
}

Here is the call graph for this function:

void strproc ( char *  string)

Definition at line 399 of file routines.c.

{
       int a;

       if (IsEmptyStr(string)) return;

       /* Convert non-printable characters to blanks */
       for (a=0; !IsEmptyStr(&string[a]); ++a) {
              if (string[a]<32) string[a]=32;
              if (string[a]>126) string[a]=32;
       }

       /* Remove leading and trailing blanks */
       while(string[0]<33) strcpy(string,&string[1]);
       while(string[strlen(string)-1]<33) string[strlen(string)-1]=0;

       /* Remove double blanks */
       for (a=0; a<strlen(string); ++a) {
              if ((string[a]==32)&&(string[a+1]==32)) {
                     strcpy(&string[a],&string[a+1]);
                     a=0;
              }
       }

       /* remove characters which would interfere with the network */
       for (a=0; a<strlen(string); ++a) {
              if (string[a]=='!') strcpy(&string[a],&string[a+1]);
              if (string[a]=='@') strcpy(&string[a],&string[a+1]);
              if (string[a]=='_') strcpy(&string[a],&string[a+1]);
              if (string[a]==',') strcpy(&string[a],&string[a+1]);
              if (string[a]=='%') strcpy(&string[a],&string[a+1]);
              if (string[a]=='|') strcpy(&string[a],&string[a+1]);
       }

}

Variable Documentation

Definition at line 87 of file commands.c.

Definition at line 105 of file citadel.c.

Definition at line 89 of file commands.c.

char sigcaught

Definition at line 100 of file citadel.c.

unsigned userflags

Definition at line 94 of file citadel.c.