]> code.citadel.org Git - citadel.git/blob - citadel/serv_vandelay.c
* Another attempt to fix the crashy crashy bug in serv_vcard
[citadel.git] / citadel / serv_vandelay.c
1 /*
2  * $Id$
3  *
4  * This is the "Art Vandelay" module.  It is an importer/exporter.
5  *
6  */
7
8 #include "sysdep.h"
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <pwd.h>
15 #include <errno.h>
16 #include <sys/types.h>
17 #include <sys/time.h>
18 #include <sys/wait.h>
19 #include <string.h>
20 #include <limits.h>
21 #include "citadel.h"
22 #include "server.h"
23 #include <time.h>
24 #include "sysdep_decls.h"
25 #include "citserver.h"
26 #include "support.h"
27 #include "config.h"
28 #include "dynloader.h"
29 #include "database.h"
30 #include "msgbase.h"
31 #include "tools.h"
32 #include "user_ops.h"
33 #include "room_ops.h"
34 #include "control.h"
35
36 char artv_tempfilename1[256];
37 char artv_tempfilename2[256];
38 FILE *artv_global_message_list;
39
40 void artv_export_users_backend(struct usersupp *usbuf, void *data) {
41         cprintf("user\n");
42         cprintf("%d\n", usbuf->version);
43         cprintf("%d\n", usbuf->uid);
44         cprintf("%s\n", usbuf->password);
45         cprintf("%u\n", usbuf->flags);
46         cprintf("%ld\n", usbuf->timescalled);
47         cprintf("%ld\n", usbuf->posted);
48         cprintf("%d\n", usbuf->axlevel);
49         cprintf("%ld\n", usbuf->usernum);
50         cprintf("%ld\n", usbuf->lastcall);
51         cprintf("%d\n", usbuf->USuserpurge);
52         cprintf("%s\n", usbuf->fullname);
53         cprintf("%d\n", usbuf->USscreenwidth);
54         cprintf("%d\n", usbuf->USscreenheight);
55         cprintf("%d\n", usbuf->moderation_filter);
56 }
57
58
59 void artv_export_users(void) {
60         ForEachUser(artv_export_users_backend, NULL);
61 }
62
63
64 void artv_export_room_msg(long msgnum) {
65         cprintf("%ld\n", msgnum);
66         fprintf(artv_global_message_list, "%ld\n", msgnum);
67 }
68
69
70 void artv_export_rooms_backend(struct quickroom *qrbuf, void *data) {
71         cprintf("room\n");
72         cprintf("%s\n", qrbuf->QRname);
73         cprintf("%s\n", qrbuf->QRpasswd);
74         cprintf("%ld\n", qrbuf->QRroomaide);
75         cprintf("%ld\n", qrbuf->QRhighest);
76         cprintf("%ld\n", qrbuf->QRgen);
77         cprintf("%u\n", qrbuf->QRflags);
78         cprintf("%s\n", qrbuf->QRdirname);
79         cprintf("%ld\n", qrbuf->QRinfo);
80         cprintf("%d\n", qrbuf->QRfloor);
81         cprintf("%ld\n", qrbuf->QRmtime);
82         cprintf("%d\n", qrbuf->QRep.expire_mode);
83         cprintf("%d\n", qrbuf->QRep.expire_value);
84         cprintf("%ld\n", qrbuf->QRnumber);
85         cprintf("%d\n", qrbuf->QRorder);
86
87         getroom(&CC->quickroom, qrbuf->QRname);
88         /* format of message list export is all message numbers output
89          * one per line terminated by a 0.
90          */
91         CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, NULL,
92                 artv_export_room_msg);
93         cprintf("0\n");
94
95 }
96
97
98
99 void artv_export_rooms(void) {
100         char cmd[256];
101         artv_global_message_list = fopen(artv_tempfilename1, "w");
102         ForEachRoom(artv_export_rooms_backend, NULL);
103         fclose(artv_global_message_list);
104
105         /*
106          * Process the 'global' message list.  (Sort it and remove dups.
107          * Dups are ok because a message may be in more than one room, but
108          * this will be handled by exporting the reference count, not by
109          * exporting the message multiple times.)
110          */
111         sprintf(cmd, "sort <%s >%s", artv_tempfilename1, artv_tempfilename2);
112         system(cmd);
113         sprintf(cmd, "uniq <%s >%s", artv_tempfilename2, artv_tempfilename1);
114         system(cmd);
115 }
116
117
118 void artv_export_floors(void) {
119         struct floor flbuf;
120         int i;
121
122         for (i=0; i < MAXFLOORS; ++i) {
123                 cprintf("floor\n");
124                 cprintf("%d\n", i);
125                 getfloor(&flbuf, i);
126                 cprintf("%u\n", flbuf.f_flags);
127                 cprintf("%s\n", flbuf.f_name);
128                 cprintf("%d\n", flbuf.f_ref_count);
129                 cprintf("%d\n", flbuf.f_ep.expire_mode);
130                 cprintf("%d\n", flbuf.f_ep.expire_value);
131         }
132 }
133
134
135
136
137
138 /* 
139  *  Traverse the room file...
140  */
141 void artv_export_visits(void) {
142         struct visit vbuf;
143         struct cdbdata *cdbv;
144
145         cdb_rewind(CDB_VISIT);
146
147         while (cdbv = cdb_next_item(CDB_VISIT), cdbv != NULL) {
148                 memset(&vbuf, 0, sizeof(struct visit));
149                 memcpy(&vbuf, cdbv->ptr,
150                        ((cdbv->len > sizeof(struct visit)) ?
151                         sizeof(struct visit) : cdbv->len));
152                 cdb_free(cdbv);
153
154                 cprintf("visit\n");
155                 cprintf("%ld\n", vbuf.v_roomnum);
156                 cprintf("%ld\n", vbuf.v_roomgen);
157                 cprintf("%ld\n", vbuf.v_usernum);
158                 cprintf("%ld\n", vbuf.v_lastseen);
159                 cprintf("%u\n", vbuf.v_flags);
160         }
161 }
162
163
164 void artv_export_message(long msgnum) {
165         cprintf("message\n");
166         cprintf("%ld\n", msgnum);
167         /* FIXME do more here of course */
168 }
169
170
171
172 void artv_export_messages(void) {
173         char buf[256];
174         long msgnum;
175         int count = 0;
176
177         artv_global_message_list = fopen(artv_tempfilename1, "r");
178         lprintf(7, "Opened %s\n", artv_tempfilename1);
179         while (fgets(buf, sizeof(buf), artv_global_message_list) != NULL) {
180                 msgnum = atol(buf);
181                 if (msgnum > 0L) {
182                         artv_export_message(msgnum);
183                         ++count;
184                 }
185         }
186         fclose(artv_global_message_list);
187         lprintf(7, "Exported %ld messages.\n", count);
188 }
189
190
191
192
193 void artv_do_export(void) {
194         cprintf("%d Yikes.\n", LISTING_FOLLOWS);
195
196         /* export the config file */
197         cprintf("config\n");
198         cprintf("%s\n", config.c_nodename);
199         cprintf("%s\n", config.c_fqdn);
200         cprintf("%s\n", config.c_humannode);
201         cprintf("%s\n", config.c_phonenum);
202         cprintf("%d\n", config.c_bbsuid);
203         cprintf("%d\n", config.c_creataide);
204         cprintf("%d\n", config.c_sleeping);
205         cprintf("%d\n", config.c_initax);
206         cprintf("%d\n", config.c_regiscall);
207         cprintf("%d\n", config.c_twitdetect);
208         cprintf("%s\n", config.c_twitroom);
209         cprintf("%s\n", config.c_moreprompt);
210         cprintf("%d\n", config.c_restrict);
211         cprintf("%ld\n", config.c_msgbase);
212         cprintf("%s\n", config.c_bbs_city);
213         cprintf("%s\n", config.c_sysadm);
214         cprintf("%s\n", config.c_bucket_dir);
215         cprintf("%d\n", config.c_setup_level);
216         cprintf("%d\n", config.c_maxsessions);
217         cprintf("%s\n", config.c_net_password);
218         cprintf("%d\n", config.c_port_number);
219         cprintf("%d\n", config.c_ipgm_secret);
220         cprintf("%d\n", config.c_ep.expire_mode);
221         cprintf("%d\n", config.c_ep.expire_value);
222         cprintf("%d\n", config.c_userpurge);
223         cprintf("%d\n", config.c_roompurge);
224         cprintf("%s\n", config.c_logpages);
225         cprintf("%d\n", config.c_createax);
226         cprintf("%ld\n", config.c_maxmsglen);
227         cprintf("%d\n", config.c_min_workers);
228         cprintf("%d\n", config.c_max_workers);
229         cprintf("%d\n", config.c_pop3_port);
230         cprintf("%d\n", config.c_smtp_port);
231         cprintf("%d\n", config.c_default_filter);
232
233         /* Export the control file */
234         get_control();
235         cprintf("control\n");
236         cprintf("%ld\n", CitControl.MMhighest);
237         cprintf("%u\n", CitControl.MMflags);
238         cprintf("%ld\n", CitControl.MMnextuser);
239         cprintf("%ld\n", CitControl.MMnextroom);
240         cprintf("%d\n", CitControl.version);
241
242         artv_export_users();
243         artv_export_rooms();
244         artv_export_floors();
245         artv_export_visits();
246         artv_export_messages();
247
248         cprintf("000\n");
249 }
250
251
252
253
254 void artv_do_import(void) {
255         cprintf("%d command not yet implemented\n", ERROR);
256
257 }
258
259
260
261 void cmd_artv(char *cmdbuf) {
262         char cmd[256];
263         static int is_running = 0;
264
265         if (CtdlAccessCheck(ac_aide)) return;   /* FIXME should be intpgm */
266         if (is_running) {
267                 cprintf("%d The importer/exporter is already running.\n",
268                         ERROR);
269                 return;
270         }
271         is_running = 1;
272
273         strcpy(artv_tempfilename1, tmpnam(NULL));
274         strcpy(artv_tempfilename2, tmpnam(NULL));
275
276         extract(cmd, cmdbuf, 0);
277         if (!strcasecmp(cmd, "export")) artv_do_export();
278         else if (!strcasecmp(cmd, "import")) artv_do_import();
279         else cprintf("%d illegal command\n", ERROR);
280
281         unlink(artv_tempfilename1);
282         unlink(artv_tempfilename2);
283
284         is_running = 0;
285 }
286
287
288
289
290 char *Dynamic_Module_Init(void)
291 {
292         CtdlRegisterProtoHook(cmd_artv, "ARTV", "import/export data store");
293         return "$Id$";
294 }