Back to index

citadel  8.12
Functions
serv_bio.c File Reference
#include "ctdl_module.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>

Go to the source code of this file.

Functions

void cmd_ebio (char *cmdbuf)
void cmd_rbio (char *cmdbuf)
void cmd_lbio (char *cmdbuf)
 CTDL_MODULE_INIT (bio)

Function Documentation

void cmd_ebio ( char *  cmdbuf)

Definition at line 28 of file serv_bio.c.

                            {
       char buf[SIZ];
       FILE *fp;

       unbuffer_output();

       if (!(CC->logged_in)) {
              cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
              return;
       }

       snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,CC->user.usernum);
       fp = fopen(buf,"w");
       if (fp == NULL) {
              cprintf("%d Cannot create file: %s\n", ERROR + INTERNAL_ERROR,
                            strerror(errno));
              return;
       }
       cprintf("%d  \n",SEND_LISTING);
       while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
              if (ftell(fp) < config.c_maxmsglen) {
                     fprintf(fp,"%s\n",buf);
              }
       }
       fclose(fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void cmd_lbio ( char *  cmdbuf)

Definition at line 87 of file serv_bio.c.

{
       DIR *filedir = NULL;
       struct dirent *filedir_entry;
       struct dirent *d;
       int dont_resolve_uids;
       size_t d_namelen;
       struct ctdluser usbuf;

       d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 2);
       if (d == NULL) {
              cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
              return;
       }

       filedir = opendir (ctdl_bio_dir);
       if (filedir == NULL) {
              free(d);
              cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
              return;
       }
       dont_resolve_uids = *cmdbuf == '1';
        cprintf("%d\n", LISTING_FOLLOWS);
       while ((readdir_r(filedir, d, &filedir_entry) == 0) &&
              (filedir_entry != NULL))
       {
#ifdef _DIRENT_HAVE_D_NAMELEN
              d_namelen = filedir_entry->d_namelen;
#else
              d_namelen = strlen(filedir_entry->d_name);
#endif
              if (((d_namelen == 1) && (filedir_entry->d_name[0] == '.')) || 
                  ((d_namelen == 2) && (filedir_entry->d_name[0] == '.') && (filedir_entry->d_name[1] == '.')))
                     continue;
                  
              if (dont_resolve_uids) {
                     filedir_entry->d_name[d_namelen++] = '\n';
                     filedir_entry->d_name[d_namelen] = '\0';
                     client_write(filedir_entry->d_name, d_namelen);
              }
              else if (CtdlGetUserByNumber(&usbuf,atol(filedir_entry->d_name))==0)
                     cprintf("%s\n", usbuf.fullname);
       }
       free(d);
       closedir(filedir);
       cprintf("000\n");

}

Here is the call graph for this function:

Here is the caller graph for this function:

void cmd_rbio ( char *  cmdbuf)

Definition at line 58 of file serv_bio.c.

{
       struct ctdluser ruser;
       char buf[256];
       FILE *fp;

       extract_token(buf, cmdbuf, 0, '|', sizeof buf);
       if (CtdlGetUser(&ruser, buf) != 0) {
              cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
              return;
       }
       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,
              (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, sizeof buf, fp) != NULL) cprintf("%s",buf);
              fclose(fp);
       }
       cprintf("000\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

CTDL_MODULE_INIT ( bio  )

Definition at line 138 of file serv_bio.c.

{
       if (!threading)
       {
               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 module name for the log */
        return "bio";
}

Here is the call graph for this function: