More removal of $Id$ tags
[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
26
27 /*
28  * enter user bio
29  */
30 void cmd_ebio(char *cmdbuf) {
31         char buf[SIZ];
32         FILE *fp;
33
34         unbuffer_output();
35
36         if (!(CC->logged_in)) {
37                 cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
38                 return;
39         }
40
41         snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,CC->user.usernum);
42         fp = fopen(buf,"w");
43         if (fp == NULL) {
44                 cprintf("%d Cannot create file: %s\n", ERROR + INTERNAL_ERROR,
45                                 strerror(errno));
46                 return;
47         }
48         cprintf("%d  \n",SEND_LISTING);
49         while(client_getln(buf, sizeof buf) >= 0 && strcmp(buf,"000")) {
50                 if (ftell(fp) < config.c_maxmsglen) {
51                         fprintf(fp,"%s\n",buf);
52                 }
53         }
54         fclose(fp);
55 }
56
57 /*
58  * read user bio
59  */
60 void cmd_rbio(char *cmdbuf)
61 {
62         struct ctdluser ruser;
63         char buf[256];
64         FILE *fp;
65
66         extract_token(buf, cmdbuf, 0, '|', sizeof buf);
67         if (CtdlGetUser(&ruser, buf) != 0) {
68                 cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
69                 return;
70         }
71         snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,ruser.usernum);
72         
73         cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
74                 ruser.fullname, ruser.usernum, ruser.axlevel,
75                 (long)ruser.lastcall, ruser.timescalled, ruser.posted);
76         fp = fopen(buf,"r");
77         if (fp == NULL)
78                 cprintf("%s has no bio on file.\n", ruser.fullname);
79         else {
80                 while (fgets(buf, sizeof buf, fp) != NULL) cprintf("%s",buf);
81                 fclose(fp);
82         }
83         cprintf("000\n");
84 }
85
86 /*
87  * list of users who have entered bios
88  */
89 void cmd_lbio(char *cmdbuf) {
90         char buf[256];
91         FILE *ls;
92         struct ctdluser usbuf;
93         char listbios[256];
94
95         snprintf(listbios, sizeof(listbios),"cd %s; ls",ctdl_bio_dir);
96         ls = popen(listbios, "r");
97         if (ls == NULL) {
98                 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
99                 return;
100         }
101
102         cprintf("%d\n", LISTING_FOLLOWS);
103         while (fgets(buf, sizeof buf, ls)!=NULL)
104                 if (CtdlGetUserByNumber(&usbuf,atol(buf))==0)
105                         cprintf("%s\n", usbuf.fullname);
106         pclose(ls);
107         cprintf("000\n");
108 }
109
110
111
112
113 CTDL_MODULE_INIT(bio)
114 {
115         if (!threading)
116         {
117                 CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
118                 CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
119                 CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
120         }
121         /* return our Subversion id for the Log */
122         return "bio";
123 }
124
125