* Holy war on strlen: use IsEmptyStr where apropriate.
[citadel.git] / citadel / routines.c
index 7bb82394998967c00d41b0655727239ed3c76f2e..cf627a5294335d4aaa5bd544ef7f681d23ea8d5b 100644 (file)
@@ -61,7 +61,6 @@ struct utmp *getutline(struct utmp *ut);
 extern unsigned userflags;
 extern char *axdefs[7];
 extern char sigcaught;
-extern struct CtdlServInfo serv_info;
 extern char rc_floor_mode;
 extern int rc_ansi_color;
 extern int rc_prompt_control;
@@ -81,14 +80,14 @@ void hit_any_key(CtdlIPC *ipc) {    /* hit any key to continue */
 
        color(COLOR_PUSH);
        color(DIM_RED);
-       scr_printf("%s\r",serv_info.serv_moreprompt);
+       scr_printf("%s\r", ipc->ServInfo.moreprompt);
        color(COLOR_POP);
-       sttybbs(0);
+       stty_ctdl(0);
        b=inkey();
-       for (a=0; a<strlen(serv_info.serv_moreprompt); ++a)
+       for (a=0; a<strlen(ipc->ServInfo.moreprompt); ++a)
                scr_putc(' ');
        scr_putc(13);
-       sttybbs(1);
+       stty_ctdl(1);
        if ( (rc_prompt_control == 1)
           || ((rc_prompt_control == 3) && (userflags & US_PROMPTCTL)) ) {
                if (b == 'q' || b == 'Q' || b == 's' || b == 'S')
@@ -101,57 +100,69 @@ void hit_any_key(CtdlIPC *ipc) {  /* hit any key to continue */
 }
 
 /*
- * change a user's access level
+ * Edit or delete a user (cmd=25 to edit/create, 96 to delete)
  */
-void edituser(CtdlIPC *ipc)
+void edituser(CtdlIPC *ipc, int cmd)
 {
        char buf[SIZ];
        char who[USERNAME_SIZE];
-       struct user *user = NULL;
+       struct ctdluser *user = NULL;
        int newnow = 0;
        int r;                          /* IPC response code */
 
-       newprompt("User name: ", who, 25);
+       newprompt("User name: ", who, 29);
        while ((r = CtdlIPCAideGetUserParameters(ipc, who, &user, buf)) / 100 != 2) {
                scr_printf("%s\n", buf);
-               scr_printf("Do you want to create this user? ");
-               if (yesno()) {
-                       r = CtdlIPCCreateUser(ipc, who, 0, buf);
-                       if (r / 100 == 2) {
-                               newnow = 1;
-                               continue;
+               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[4]);
                        }
-                       scr_printf("%s\n",&buf[4]);
                }
                free(user);
                return;
        }
 
-       val_user(ipc, user->fullname, 0); /* Display registration */
+       if (cmd == 25) {
+               val_user(ipc, user->fullname, 0); /* Display registration */
 
-       if (newnow || boolprompt("Change password", 0)) {       /* I'm lazy */
-               strprompt("Password", user->password, -19);
+               if (newnow || boolprompt("Change password", 0)) {
+                       strprompt("Password", user->password, -19);
+               }
+       
+               user->axlevel = intprompt("Access level", user->axlevel, 0, 6);
+/*             user->flags = set_attr(ipc, user->flags,
+                       "Permission to send Internet mail",
+                       US_INTERNET, 0); */
+               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);
        }
 
-       user->axlevel = intprompt("Access level", user->axlevel, 0, 6);
-
-       user->flags = set_attr(ipc, user->flags,
-               "Permission to send/receive Internet mail",
-               US_INTERNET, 0);
-
-       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()) return;
+               user->axlevel = 0;
+       }
+       
        r = CtdlIPCAideSetUserParameters(ipc, user, buf);
        if (r / 100 != 2) {
                scr_printf("%s\n", buf);
@@ -171,7 +182,7 @@ int set_attr(CtdlIPC *ipc, unsigned int sval, char *prompt, unsigned int sbit, i
 
        temp = sval;
        color(DIM_WHITE);
-       scr_printf("%45s ", prompt);
+       scr_printf("%50s ", prompt);
        color(DIM_MAGENTA);
        scr_printf("[");
        color(BRIGHT_MAGENTA);
@@ -204,7 +215,7 @@ int set_attr(CtdlIPC *ipc, unsigned int sval, char *prompt, unsigned int sbit, i
 void enter_config(CtdlIPC *ipc, int mode)
 {
        char buf[SIZ];
-       struct user *user = NULL;
+       struct ctdluser *user = NULL;
        int r;                          /* IPC response code */
 
        r = CtdlIPCGetConfig(ipc, &user, buf);
@@ -216,10 +227,16 @@ void enter_config(CtdlIPC *ipc, int mode)
 
        if (mode == 0 || mode == 1) {
 
+               /* Does anyone still use dialup connections with manual
+                * screen dimensions setting anymore?  For now we'll keep
+                * the system's ability to set these, but remove the prompts
+                * because they're spurious for nearly everyone.
+                * 
                user->USscreenwidth = intprompt("Enter your screen width",
                                                user->USscreenwidth, 20, 255);
                user->USscreenheight = intprompt("Enter your screen height",
                                                 user->USscreenheight, 3, 255);
+                */
  
                user->flags = set_attr(ipc, user->flags,
                                       "Are you an experienced Citadel user",
@@ -267,6 +284,13 @@ void enter_config(CtdlIPC *ipc, int mode)
                user->flags = set_attr(ipc, user->flags,
                                       "Be unlisted in userlog",
                                       US_UNLISTED, 0);
+
+               if (!IsEmptyStr(editor_paths[0])) {
+                       user->flags = set_attr(ipc, user->flags,
+                               "Always enter messages with the full-screen editor",
+                               US_EXTEDIT, 0);
+               }
+
        }
 
        if (mode == 2) {
@@ -335,7 +359,7 @@ void strproc(char *string)
 {
        int a;
 
-       if (strlen(string)==0) return;
+       if (IsEmptyStr(string)) return;
 
        /* Convert non-printable characters to blanks */
        for (a=0; a<strlen(string); ++a) {
@@ -382,7 +406,7 @@ char *strerror(int e)
 #endif
 
 
-void progress(unsigned long curr, unsigned long cmax)
+void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax)
 {
        static char dots[] =
                "**************************************************";
@@ -392,7 +416,7 @@ void progress(unsigned long curr, unsigned long cmax)
 
        if (curr >= cmax) {
                sln_printf("\r%79s\r","");
-               status_line(serv_info.serv_humannode, serv_info.serv_bbs_city,
+               status_line(ipc->ServInfo.humannode, ipc->ServInfo.site_location,
                        room_name, secure, 0);
        } else {
                /* a will be range 0-50 rather than 0-100 */
@@ -411,7 +435,7 @@ void progress(unsigned long curr, unsigned long cmax)
  * NOT the same locate_host() in locate_host.c.  This one just does a
  * 'who am i' to try to discover where the user is...
  */
-void locate_host(char *hbuf)
+void locate_host(CtdlIPC* ipc, char *hbuf)
 {
 #ifndef HAVE_UTMP_H
        char buf[SIZ];
@@ -420,7 +444,7 @@ void locate_host(char *hbuf)
 
        who = (FILE *)popen("who am i","r");
        if (who==NULL) {
-               strcpy(hbuf,serv_info.serv_fqdn);
+               strcpy(hbuf, ipc->ServInfo.fqdn);
                return; 
        }
        fgets(buf,sizeof buf,who);
@@ -431,7 +455,7 @@ void locate_host(char *hbuf)
                if ((buf[a]=='(')||(buf[a]==')')) ++b;
        }
        if (b<2) {
-               strcpy(hbuf,serv_info.serv_fqdn);
+               strcpy(hbuf, ipc->ServInfo.fqdn);
                return;
        }
 
@@ -444,7 +468,7 @@ void locate_host(char *hbuf)
                if (buf[a]==')') buf[a] = 0;
        }
 
-       if (strlen(buf)==0) strcpy(hbuf,serv_info.serv_fqdn);
+       if (IsEmptyStr(buf)) strcpy(hbuf, ipc->ServInfo.fqdn);
        else strncpy(hbuf,buf,24);
 #else
        char *tty = ttyname(0);
@@ -456,7 +480,7 @@ void locate_host(char *hbuf)
 
        if (tty == NULL) {
            fail:
-               safestrncpy(hbuf, serv_info.serv_fqdn, 24);
+               safestrncpy(hbuf, ipc->ServInfo.fqdn, 24);
                return;
        }
 
@@ -494,12 +518,12 @@ void locate_host(char *hbuf)
 void misc_server_cmd(CtdlIPC *ipc, char *cmd) {
        char buf[SIZ];
 
-       CtdlIPC_putline(ipc, cmd);
-       CtdlIPC_getline(ipc, buf);
+       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_getline(ipc, buf), strcmp(buf,"000")) {
+               while (CtdlIPC_chat_recv(ipc, buf), strcmp(buf,"000")) {
                        scr_printf("%s\n",buf);
                }
                set_keepalives(KA_YES);
@@ -508,7 +532,7 @@ void misc_server_cmd(CtdlIPC *ipc, char *cmd) {
        if (buf[0]=='4') {
                do {
                        newprompt("> ",buf,255);
-                       CtdlIPC_putline(ipc, buf);
+                       CtdlIPC_chat_send(ipc, buf);
                } while(strcmp(buf,"000"));
                return;
        }