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;
96 d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 2);
98 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
102 filedir = opendir (ctdl_bio_dir);
103 if (filedir == NULL) {
105 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
108 dont_resolve_uids = *cmdbuf == '1';
109 cprintf("%d\n", LISTING_FOLLOWS);
110 while ((readdir_r(filedir, d, &filedir_entry) == 0) &&
111 (filedir_entry != NULL))
113 #ifdef _DIRENT_HAVE_D_NAMELEN
114 d_namelen = filedir_entry->d_namelen;
116 d_namelen = strlen(filedir_entry->d_name);
118 if (((d_namelen == 1) && (filedir_entry->d_name[0] == '.')) ||
119 ((d_namelen == 2) && (filedir_entry->d_name[0] == '.') && (filedir_entry->d_name[1] == '.')))
122 if (dont_resolve_uids) {
123 filedir_entry->d_name[d_namelen++] = '\n';
124 filedir_entry->d_name[d_namelen] = '\0';
125 client_write(filedir_entry->d_name, d_namelen);
127 else if (CtdlGetUserByNumber(&usbuf,atol(filedir_entry->d_name))==0)
128 cprintf("%s\n", usbuf.fullname);
138 CTDL_MODULE_INIT(bio)
142 CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
143 CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
144 CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
146 /* return our module name for the log */