Moved to new module init structure.
[citadel.git] / citadel / serv_bio.c
index 7915bbfb5d367f255b7ddd0487a08e1057ec1963..9f5589b3b2434af55248a65e177375a58a8c5931 100644 (file)
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
 #include "control.h"
-#include "dynloader.h"
 #include "room_ops.h"
 #include "user_ops.h"
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
 #include "tools.h"
+#include "citadel_dirs.h"
 
-
-
+#include "ctdl_module.h"
 
 /*
  * enter user bio
@@ -55,20 +53,25 @@ void cmd_ebio(char *cmdbuf) {
        char buf[SIZ];
        FILE *fp;
 
+       unbuffer_output();
+
        if (!(CC->logged_in)) {
-               cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
+               cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
                return;
        }
 
-       sprintf(buf,"./bio/%ld",CC->usersupp.usernum);
+       snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,CC->user.usernum);
        fp = fopen(buf,"w");
        if (fp == NULL) {
-               cprintf("%d Cannot create file\n",ERROR);
+               cprintf("%d Cannot create file: %s\n", ERROR + INTERNAL_ERROR,
+                               strerror(errno));
                return;
        }
        cprintf("%d  \n",SEND_LISTING);
-       while(client_gets(buf), strcmp(buf,"000")) {
-               fprintf(fp,"%s\n",buf);
+       while(client_getln(buf, sizeof buf), strcmp(buf,"000")) {
+               if (ftell(fp) < config.c_maxmsglen) {
+                       fprintf(fp,"%s\n",buf);
+               }
        }
        fclose(fp);
 }
@@ -78,25 +81,25 @@ void cmd_ebio(char *cmdbuf) {
  */
 void cmd_rbio(char *cmdbuf)
 {
-       struct usersupp ruser;
-       char buf[SIZ];
+       struct ctdluser ruser;
+       char buf[256];
        FILE *fp;
 
-       extract(buf,cmdbuf,0);
-       if (getuser(&ruser,buf)!=0) {
-               cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
+       extract_token(buf, cmdbuf, 0, '|', sizeof buf);
+       if (getuser(&ruser, buf) != 0) {
+               cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
                return;
        }
-       sprintf(buf,"./bio/%ld",ruser.usernum);
+       snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,ruser.usernum);
        
        cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
                ruser.fullname, ruser.usernum, ruser.axlevel,
-               ruser.lastcall, ruser.timescalled, ruser.posted);
+               (long)ruser.lastcall, ruser.timescalled, ruser.posted);
        fp = fopen(buf,"r");
        if (fp == NULL)
                cprintf("%s has no bio on file.\n", ruser.fullname);
        else {
-               while (fgets(buf,256,fp)!=NULL) cprintf("%s",buf);
+               while (fgets(buf, sizeof buf, fp) != NULL) cprintf("%s",buf);
                fclose(fp);
        }
        cprintf("000\n");
@@ -106,20 +109,22 @@ void cmd_rbio(char *cmdbuf)
  * list of users who have entered bios
  */
 void cmd_lbio(char *cmdbuf) {
-       char buf[SIZ];
+       char buf[256];
        FILE *ls;
-       struct usersupp usbuf;
+       struct ctdluser usbuf;
+       char listbios[256];
 
-       ls=popen("cd ./bio; ls","r");
-       if (ls==NULL) {
-               cprintf("%d Cannot open listing.\n",ERROR+FILE_NOT_FOUND);
+       snprintf(listbios, sizeof(listbios),"cd %s; ls",ctdl_bio_dir);
+       ls = popen(listbios, "r");
+       if (ls == NULL) {
+               cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
                return;
        }
 
-       cprintf("%d\n",LISTING_FOLLOWS);
-       while (fgets(buf,sizeof buf,ls)!=NULL)
+       cprintf("%d\n", LISTING_FOLLOWS);
+       while (fgets(buf, sizeof buf, ls)!=NULL)
                if (getuserbynumber(&usbuf,atol(buf))==0)
-                       cprintf("%s\n",usbuf.fullname);
+                       cprintf("%s\n", usbuf.fullname);
        pclose(ls);
        cprintf("000\n");
 }
@@ -127,11 +132,13 @@ void cmd_lbio(char *cmdbuf) {
 
 
 
-char *Dynamic_Module_Init(void)
+CTDL_MODULE_INIT(bio)
 {
         CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
         CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
         CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
+
+       /* return our Subversion id for the Log */
         return "$Id$";
 }