2 * This module implementsserver commands related to the display and
3 * manipulation of user "bio" files.
5 * Copyright (c) 1987-2015 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"
21 #include <sys/types.h>
29 void cmd_ebio(char *cmdbuf) {
35 if (!(CC->logged_in)) {
36 cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
40 snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,CC->user.usernum);
43 cprintf("%d Cannot create file: %s\n", ERROR + INTERNAL_ERROR,
47 cprintf("%d \n",SEND_LISTING);
48 while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
49 if (ftell(fp) < CtdlGetConfigLong("c_maxmsglen")) {
50 fprintf(fp,"%s\n",buf);
59 void cmd_rbio(char *cmdbuf)
61 struct ctdluser ruser;
65 extract_token(buf, cmdbuf, 0, '|', sizeof buf);
66 if (CtdlGetUser(&ruser, buf) != 0) {
67 cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
70 snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,ruser.usernum);
72 cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
73 ruser.fullname, ruser.usernum, ruser.axlevel,
74 (long)ruser.lastcall, ruser.timescalled, ruser.posted);
77 cprintf("%s has no bio on file.\n", ruser.fullname);
79 while (fgets(buf, sizeof buf, fp) != NULL) cprintf("%s",buf);
86 * list of users who have entered bios
88 void cmd_lbio(char *cmdbuf)
91 struct dirent *filedir_entry;
93 int dont_resolve_uids;
95 struct ctdluser usbuf;
99 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 2);
101 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
105 filedir = opendir (ctdl_bio_dir);
106 if (filedir == NULL) {
108 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
111 dont_resolve_uids = *cmdbuf == '1';
112 cprintf("%d\n", LISTING_FOLLOWS);
113 while ((readdir_r(filedir, d, &filedir_entry) == 0) &&
114 (filedir_entry != NULL))
116 #ifdef _DIRENT_HAVE_D_NAMLEN
117 d_namelen = filedir_entry->d_namlen;
120 d_namelen = strlen(filedir_entry->d_name);
123 #ifdef _DIRENT_HAVE_D_TYPE
124 d_type = filedir_entry->d_type;
133 #define IFTODT(mode) (((mode) & 0170000) >> 12)
134 #define DTTOIF(dirtype) ((dirtype) << 12)
138 if ((d_namelen == 1) &&
139 (filedir_entry->d_name[0] == '.'))
142 if ((d_namelen == 2) &&
143 (filedir_entry->d_name[0] == '.') &&
144 (filedir_entry->d_name[1] == '.'))
147 if (d_type == DT_UNKNOWN) {
150 snprintf(path, PATH_MAX, "%s/%s",
151 ctdl_bio_dir, filedir_entry->d_name);
152 if (lstat(path, &s) == 0) {
153 d_type = IFTODT(s.st_mode);
162 if (dont_resolve_uids) {
163 filedir_entry->d_name[d_namelen++] = '\n';
164 filedir_entry->d_name[d_namelen] = '\0';
165 client_write(filedir_entry->d_name, d_namelen);
167 else if (CtdlGetUserByNumber(&usbuf,atol(filedir_entry->d_name))==0)
168 cprintf("%s\n", usbuf.fullname);
179 CTDL_MODULE_INIT(bio)
183 CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
184 CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
185 CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
187 /* return our module name for the log */