Back to index

citadel  8.12
Functions
routines.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void edituser (CtdlIPC *ipc, int cmd)
void interr (int errnum)
int struncmp (char *lstr, char *rstr, int len)
int pattern (char *search, char *patn)
void enter_config (CtdlIPC *ipc, int mode)
void locate_host (CtdlIPC *ipc, char *hbuf)
void misc_server_cmd (CtdlIPC *ipc, char *cmd)
int nukedir (char *dirname)
void strproc (char *string)
void back (int spaces)
void progress (CtdlIPC *ipc, unsigned long curr, unsigned long cmax)
int set_attr (CtdlIPC *ipc, unsigned int sval, char *prompt, unsigned int sbit, int backwards)

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:

void interr ( int  errnum)
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:

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);
}
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:

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:

void strproc ( char *  string)

Definition at line 21 of file support.c.

{
       int a, b;

       if (string == NULL) return;
       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;
       }

       /* a is now the length of our string. */
       /* Remove leading and trailing blanks */
       while( (string[a-1]<33) && (!IsEmptyStr(string)) )
              string[--a]=0;
       b = 0;
       while( (string[b]<33) && (!IsEmptyStr(&string[b])) )
              b++;
       if (b > 0)
              memmove(string,&string[b], a - b + 1);

       /* Remove double blanks */
       for (a=0; !IsEmptyStr(&string[a]); ++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; !IsEmptyStr(&string[a]); ++a) {
              while (string[a]=='!') strcpy(&string[a],&string[a+1]);
              while (string[a]=='@') strcpy(&string[a],&string[a+1]);
              while (string[a]=='_') strcpy(&string[a],&string[a+1]);
              while (string[a]==',') strcpy(&string[a],&string[a+1]);
              while (string[a]=='%') strcpy(&string[a],&string[a+1]);
              while (string[a]=='|') strcpy(&string[a],&string[a+1]);
       }

}

Here is the caller graph for this function:

int struncmp ( char *  lstr,
char *  rstr,
int  len 
)