]> code.citadel.org Git - citadel.git/blob - citadel/serv_bio.c
513d0b3c396b9a5a161ae61f0a7659208849535a
[citadel.git] / citadel / 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 #include <sys/time.h>
19 #include <sys/wait.h>
20 #include <string.h>
21 #include <limits.h>
22 #include "citadel.h"
23 #include "server.h"
24 #include <time.h>
25 #include "sysdep_decls.h"
26 #include "citserver.h"
27 #include "support.h"
28 #include "config.h"
29 #include "control.h"
30 #include "dynloader.h"
31 #include "room_ops.h"
32 #include "user_ops.h"
33 #include "policy.h"
34 #include "database.h"
35 #include "msgbase.h"
36 #include "tools.h"
37
38
39
40
41 /*
42  * enter user bio
43  */
44 void cmd_ebio(char *cmdbuf) {
45         char cbuf[SIZ];
46         char *ibuf;
47         FILE *fp;
48
49         if (!(CC->logged_in)) {
50                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
51                 return;
52         }
53
54         sprintf(cbuf,"./bio/%ld",CC->usersupp.usernum);
55         fp = fopen(cbuf,"w");
56         if (fp == NULL) {
57                 cprintf("%d Cannot create file\n",ERROR);
58                 return;
59         }
60         cprintf("%d  \n",SEND_LISTING);
61         while(client_gets(&ibuf), strcmp(ibuf,"000")) {
62                 fprintf(fp,"%s\n",ibuf);
63         }
64         fclose(fp);
65 }
66
67 /*
68  * read user bio
69  */
70 void cmd_rbio(char *cmdbuf)
71 {
72         struct usersupp ruser;
73         char buf[SIZ];
74         FILE *fp;
75
76         extract(buf,cmdbuf,0);
77         if (getuser(&ruser,buf)!=0) {
78                 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
79                 return;
80         }
81         sprintf(buf,"./bio/%ld",ruser.usernum);
82         
83         cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
84                 ruser.fullname, ruser.usernum, ruser.axlevel,
85                 ruser.lastcall, ruser.timescalled, ruser.posted);
86         fp = fopen(buf,"r");
87         if (fp == NULL)
88                 cprintf("%s has no bio on file.\n", ruser.fullname);
89         else {
90                 while (fgets(buf,256,fp)!=NULL) cprintf("%s",buf);
91                 fclose(fp);
92         }
93         cprintf("000\n");
94 }
95
96 /*
97  * list of users who have entered bios
98  */
99 void cmd_lbio(char *cmdbuf) {
100         char buf[SIZ];
101         FILE *ls;
102         struct usersupp usbuf;
103
104         ls=popen("cd ./bio; ls","r");
105         if (ls==NULL) {
106                 cprintf("%d Cannot open listing.\n",ERROR+FILE_NOT_FOUND);
107                 return;
108         }
109
110         cprintf("%d\n",LISTING_FOLLOWS);
111         while (fgets(buf,sizeof buf,ls)!=NULL)
112                 if (getuserbynumber(&usbuf,atol(buf))==0)
113                         cprintf("%s\n",usbuf.fullname);
114         pclose(ls);
115         cprintf("000\n");
116 }
117
118
119
120
121 char *Dynamic_Module_Init(void)
122 {
123         CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
124         CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
125         CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
126         return "$Id$";
127 }
128
129