2 * This module implementsserver commands related to the display and
3 * manipulation of user "bio" files.
6 * Copyright (c) 1987-2009 by the citadel.org team
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "ctdl_module.h"
25 #include <sys/types.h>
33 void cmd_ebio(char *cmdbuf) {
39 if (!(CC->logged_in)) {
40 cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
44 snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,CC->user.usernum);
47 cprintf("%d Cannot create file: %s\n", ERROR + INTERNAL_ERROR,
51 cprintf("%d \n",SEND_LISTING);
52 while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
53 if (ftell(fp) < config.c_maxmsglen) {
54 fprintf(fp,"%s\n",buf);
63 void cmd_rbio(char *cmdbuf)
65 struct ctdluser ruser;
69 extract_token(buf, cmdbuf, 0, '|', sizeof buf);
70 if (CtdlGetUser(&ruser, buf) != 0) {
71 cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
74 snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,ruser.usernum);
76 cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
77 ruser.fullname, ruser.usernum, ruser.axlevel,
78 (long)ruser.lastcall, ruser.timescalled, ruser.posted);
81 cprintf("%s has no bio on file.\n", ruser.fullname);
83 while (fgets(buf, sizeof buf, fp) != NULL) cprintf("%s",buf);
90 * list of users who have entered bios
92 void cmd_lbio(char *cmdbuf)
95 struct dirent *filedir_entry;
97 int dont_resolve_uids;
99 struct ctdluser usbuf;
101 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 2);
103 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
107 filedir = opendir (ctdl_bio_dir);
108 if (filedir == NULL) {
110 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
113 dont_resolve_uids = *cmdbuf == '1';
114 cprintf("%d\n", LISTING_FOLLOWS);
115 while ((readdir_r(filedir, d, &filedir_entry) == 0) &&
116 (filedir_entry != NULL))
118 #ifdef _DIRENT_HAVE_D_NAMELEN
119 d_namelen = filedir_entry->d_namelen;
121 d_namelen = strlen(filedir_entry->d_name);
123 if (((d_namelen == 1) && (filedir_entry->d_name[0] == '.')) ||
124 ((d_namelen == 2) && (filedir_entry->d_name[0] == '.') && (filedir_entry->d_name[1] == '.')))
127 if (dont_resolve_uids) {
128 filedir_entry->d_name[d_namelen++] = '\n';
129 filedir_entry->d_name[d_namelen] = '\0';
130 client_write(filedir_entry->d_name, d_namelen);
132 else if (CtdlGetUserByNumber(&usbuf,atol(filedir_entry->d_name))==0)
133 cprintf("%s\n", usbuf.fullname);
143 CTDL_MODULE_INIT(bio)
147 CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
148 CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
149 CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
151 /* return our module name for the log */