Removed references to Subversion in the code
[citadel.git] / citadel / modules / bio / serv_bio.c
1 /*
2  * This module implementsserver commands related to the display and
3  * manipulation of user "bio" files.
4  *
5  *
6  * Copyright (c) 1987-2009 by the citadel.org team
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "ctdl_module.h"
24
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <dirent.h>
28
29
30 /*
31  * enter user bio
32  */
33 void cmd_ebio(char *cmdbuf) {
34         char buf[SIZ];
35         FILE *fp;
36
37         unbuffer_output();
38
39         if (!(CC->logged_in)) {
40                 cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
41                 return;
42         }
43
44         snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,CC->user.usernum);
45         fp = fopen(buf,"w");
46         if (fp == NULL) {
47                 cprintf("%d Cannot create file: %s\n", ERROR + INTERNAL_ERROR,
48                                 strerror(errno));
49                 return;
50         }
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);
55                 }
56         }
57         fclose(fp);
58 }
59
60 /*
61  * read user bio
62  */
63 void cmd_rbio(char *cmdbuf)
64 {
65         struct ctdluser ruser;
66         char buf[256];
67         FILE *fp;
68
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);
72                 return;
73         }
74         snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,ruser.usernum);
75         
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);
79         fp = fopen(buf,"r");
80         if (fp == NULL)
81                 cprintf("%s has no bio on file.\n", ruser.fullname);
82         else {
83                 while (fgets(buf, sizeof buf, fp) != NULL) cprintf("%s",buf);
84                 fclose(fp);
85         }
86         cprintf("000\n");
87 }
88
89 /*
90  * list of users who have entered bios
91  */
92 void cmd_lbio(char *cmdbuf)
93 {
94         DIR *filedir = NULL;
95         struct dirent *filedir_entry;
96         struct dirent *d;
97         int dont_resolve_uids;
98         size_t d_namelen;
99         struct ctdluser usbuf;
100
101         d = (struct dirent *)malloc(offsetof(struct dirent, d_name) + PATH_MAX + 2);
102         if (d == NULL) {
103                 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
104                 return;
105         }
106
107         filedir = opendir (ctdl_bio_dir);
108         if (filedir == NULL) {
109                 free(d);
110                 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
111                 return;
112         }
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))
117         {
118 #ifdef _DIRENT_HAVE_D_NAMELEN
119                 d_namelen = filedir_entry->d_namelen;
120 #else
121                 d_namelen = strlen(filedir_entry->d_name);
122 #endif
123                 if (((d_namelen == 1) && (filedir_entry->d_name[0] == '.')) || 
124                     ((d_namelen == 2) && (filedir_entry->d_name[0] == '.') && (filedir_entry->d_name[1] == '.')))
125                         continue;
126                     
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);
131                 }
132                 else if (CtdlGetUserByNumber(&usbuf,atol(filedir_entry->d_name))==0)
133                         cprintf("%s\n", usbuf.fullname);
134         }
135         free(d);
136         closedir(filedir);
137         cprintf("000\n");
138
139 }
140
141
142
143 CTDL_MODULE_INIT(bio)
144 {
145         if (!threading)
146         {
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");
150         }
151         /* return our module name for the log */
152         return "bio";
153 }
154
155