HUGE PATCH. This moves all of mime_parser.c and all
[citadel.git] / citadel / modules / bio / serv_bio.c
1 /*
2  * $Id$
3  *
4  * This module implementsserver commands related to the display and
5  * manipulation of user "bio" files.
6  *
7  */
8
9 #include "sysdep.h"
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <pwd.h>
16 #include <errno.h>
17 #include <sys/types.h>
18
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
21 # include <time.h>
22 #else
23 # if HAVE_SYS_TIME_H
24 #  include <sys/time.h>
25 # else
26 #  include <time.h>
27 # endif
28 #endif
29
30 #include <sys/wait.h>
31 #include <string.h>
32 #include <limits.h>
33 #include <libcitadel.h>
34 #include "citadel.h"
35 #include "server.h"
36 #include "citserver.h"
37 #include "support.h"
38 #include "config.h"
39 #include "control.h"
40 #include "room_ops.h"
41 #include "user_ops.h"
42 #include "policy.h"
43 #include "database.h"
44 #include "msgbase.h"
45 #include "citadel_dirs.h"
46
47 #include "ctdl_module.h"
48
49 /*
50  * enter user bio
51  */
52 void cmd_ebio(char *cmdbuf) {
53         char buf[SIZ];
54         FILE *fp;
55
56         unbuffer_output();
57
58         if (!(CC->logged_in)) {
59                 cprintf("%d Not logged in.\n",ERROR + NOT_LOGGED_IN);
60                 return;
61         }
62
63         snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,CC->user.usernum);
64         fp = fopen(buf,"w");
65         if (fp == NULL) {
66                 cprintf("%d Cannot create file: %s\n", ERROR + INTERNAL_ERROR,
67                                 strerror(errno));
68                 return;
69         }
70         cprintf("%d  \n",SEND_LISTING);
71         while(client_getln(buf, sizeof buf), strcmp(buf,"000")) {
72                 if (ftell(fp) < config.c_maxmsglen) {
73                         fprintf(fp,"%s\n",buf);
74                 }
75         }
76         fclose(fp);
77 }
78
79 /*
80  * read user bio
81  */
82 void cmd_rbio(char *cmdbuf)
83 {
84         struct ctdluser ruser;
85         char buf[256];
86         FILE *fp;
87
88         extract_token(buf, cmdbuf, 0, '|', sizeof buf);
89         if (getuser(&ruser, buf) != 0) {
90                 cprintf("%d No such user.\n",ERROR + NO_SUCH_USER);
91                 return;
92         }
93         snprintf(buf, sizeof buf, "%s%ld",ctdl_bio_dir,ruser.usernum);
94         
95         cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
96                 ruser.fullname, ruser.usernum, ruser.axlevel,
97                 (long)ruser.lastcall, ruser.timescalled, ruser.posted);
98         fp = fopen(buf,"r");
99         if (fp == NULL)
100                 cprintf("%s has no bio on file.\n", ruser.fullname);
101         else {
102                 while (fgets(buf, sizeof buf, fp) != NULL) cprintf("%s",buf);
103                 fclose(fp);
104         }
105         cprintf("000\n");
106 }
107
108 /*
109  * list of users who have entered bios
110  */
111 void cmd_lbio(char *cmdbuf) {
112         char buf[256];
113         FILE *ls;
114         struct ctdluser usbuf;
115         char listbios[256];
116
117         snprintf(listbios, sizeof(listbios),"cd %s; ls",ctdl_bio_dir);
118         ls = popen(listbios, "r");
119         if (ls == NULL) {
120                 cprintf("%d Cannot open listing.\n", ERROR + FILE_NOT_FOUND);
121                 return;
122         }
123
124         cprintf("%d\n", LISTING_FOLLOWS);
125         while (fgets(buf, sizeof buf, ls)!=NULL)
126                 if (getuserbynumber(&usbuf,atol(buf))==0)
127                         cprintf("%s\n", usbuf.fullname);
128         pclose(ls);
129         cprintf("000\n");
130 }
131
132
133
134
135 CTDL_MODULE_INIT(bio)
136 {
137         CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
138         CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
139         CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
140
141         /* return our Subversion id for the Log */
142         return "$Id$";
143 }
144
145