2 * This module implementsserver commands related to the display and
3 * manipulation of user "bio" files.
5 * Copyright (c) 1987-2012 by the citadel.org team
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include "ctdl_module.h"
20 #include <sys/types.h>
28 void cmd_ebio(char *cmdbuf) {
34 if (!(CC->logged_in)) {
35 cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
39 snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,CC->user.usernum);
42 cprintf("%d Cannot create file: %s\n", ERROR + INTERNAL_ERROR,
46 cprintf("%d \n",SEND_LISTING);
47 while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
48 if (ftell(fp) < config.c_maxmsglen) {
49 fprintf(fp,"%s\n",buf);
58 void cmd_rbio(char *cmdbuf)
60 struct ctdluser ruser;
64 extract_token(buf, cmdbuf, 0, '|', sizeof buf);
65 if (CtdlGetUser(&ruser, buf) != 0) {
66 cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
69 snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,ruser.usernum);
71 cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
72 ruser.fullname, ruser.usernum, ruser.axlevel,
73 (long)ruser.lastcall, ruser.timescalled, ruser.posted);
76 cprintf("%s has no bio on file.\n", ruser.fullname);
78 while (fgets(buf, sizeof buf, fp) != NULL) cprintf("%s",buf);
85 * list of users who have entered bios
87 void cmd_lbio(char *cmdbuf)
90 struct dirent *filedir_entry;
92 int dont_resolve_uids;
94 struct ctdluser usbuf;
98 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 2);
100 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
104 filedir = opendir (ctdl_bio_dir);
105 if (filedir == NULL) {
107 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
110 dont_resolve_uids = *cmdbuf == '1';
111 cprintf("%d\n", LISTING_FOLLOWS);
112 while ((readdir_r(filedir, d, &filedir_entry) == 0) &&
113 (filedir_entry != NULL))
115 #ifdef _DIRENT_HAVE_D_NAMLEN
116 d_namelen = filedir_entry->d_namlen;
119 d_namelen = strlen(filedir_entry->d_name);
122 #ifdef _DIRENT_HAVE_D_TYPE
123 d_type = filedir_entry->d_type;
132 #define IFTODT(mode) (((mode) & 0170000) >> 12)
133 #define DTTOIF(dirtype) ((dirtype) << 12)
137 if ((d_namelen == 1) &&
138 (filedir_entry->d_name[0] == '.'))
141 if ((d_namelen == 2) &&
142 (filedir_entry->d_name[0] == '.') &&
143 (filedir_entry->d_name[1] == '.'))
146 if (d_type == DT_UNKNOWN) {
149 snprintf(path, PATH_MAX, "%s/%s",
150 ctdl_bio_dir, filedir_entry->d_name);
151 if (lstat(path, &s) == 0) {
152 d_type = IFTODT(s.st_mode);
161 if (dont_resolve_uids) {
162 filedir_entry->d_name[d_namelen++] = '\n';
163 filedir_entry->d_name[d_namelen] = '\0';
164 client_write(filedir_entry->d_name, d_namelen);
166 else if (CtdlGetUserByNumber(&usbuf,atol(filedir_entry->d_name))==0)
167 cprintf("%s\n", usbuf.fullname);
178 CTDL_MODULE_INIT(bio)
182 CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
183 CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
184 CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
186 /* return our module name for the log */