2 /* cc import.c database.o control.o -lgdbm -o import */
17 int ssv_maxfloors = 0;
21 /**** stubs which need to be defined for database.c to work ****/
24 struct CitContext MyCC;
26 struct CitContext *MyContext() {
30 void begin_critical_section(int c) { }
31 void end_critical_section(int c) { }
33 void lprintf(int loglevel, const char *format, ...) {
36 va_start(arg_ptr, format);
37 vfprintf(stderr, format, arg_ptr);
42 void fpgetfield(fp,string)
61 char key[256], value[256];
63 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
64 fpgetfield(imfp, value);
65 lprintf(9, " %s = %s\n", key, value);
67 if (!strcasecmp(key, "maxfloors")) {
68 ssv_maxfloors = atol(value);
69 if (ssv_maxfloors > MAXFLOORS) {
70 lprintf(3, "ERROR: maxfloors is %d, need %d\n",
71 ssv_maxfloors, MAXFLOORS);
81 char key[256], value[256];
84 bzero(&config, sizeof(struct config));
85 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
86 fpgetfield(imfp, value);
87 lprintf(9, " %s = %s\n", key, value);
89 if (!strcasecmp(key, "c_nodename"))
90 strcpy(config.c_nodename, value);
91 if (!strcasecmp(key, "c_fqdn"))
92 strcpy(config.c_fqdn, value);
93 if (!strcasecmp(key, "c_humannode"))
94 strcpy(config.c_humannode, value);
95 if (!strcasecmp(key, "c_phonenum"))
96 strcpy(config.c_phonenum, value);
97 if (!strcasecmp(key, "c_phonenum"))
98 strcpy(config.c_phonenum, value);
99 if (!strcasecmp(key, "c_bbsuid"))
100 config.c_bbsuid = atoi(value);
101 if (!strcasecmp(key, "c_creataide"))
102 config.c_creataide = atoi(value);
103 if (!strcasecmp(key, "c_sleeping"))
104 config.c_sleeping = atoi(value);
105 if (!strcasecmp(key, "c_initax"))
106 config.c_initax = atoi(value);
107 if (!strcasecmp(key, "c_regiscall"))
108 config.c_regiscall = atoi(value);
109 if (!strcasecmp(key, "c_twitdetect"))
110 config.c_twitdetect = atoi(value);
111 if (!strcasecmp(key, "c_twitroom"))
112 strcpy(config.c_twitroom, value);
113 if (!strcasecmp(key, "c_moreprompt"))
114 strcpy(config.c_moreprompt, value);
115 if (!strcasecmp(key, "c_restrict"))
116 config.c_restrict = atoi(value);
117 if (!strcasecmp(key, "c_bbs_city"))
118 strcpy(config.c_bbs_city, value);
119 if (!strcasecmp(key, "c_sysadm"))
120 strcpy(config.c_sysadm, value);
121 if (!strcasecmp(key, "c_bucket_dir"))
122 strcpy(config.c_bucket_dir, value);
123 if (!strcasecmp(key, "c_setup_level"))
124 config.c_setup_level = atoi(value);
125 if (!strcasecmp(key, "c_maxsessions"))
126 config.c_maxsessions = atoi(value);
127 if (!strcasecmp(key, "c_net_password"))
128 strcpy(config.c_net_password, value);
129 if (!strcasecmp(key, "c_port_number"))
130 config.c_port_number = atoi(value);
133 fp = fopen("citadel.config", "wb");
134 fwrite(&config, sizeof(struct config), 1, fp);
140 char key[256], value[256];
143 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
144 fpgetfield(imfp, value);
145 lprintf(9, " %s = %s\n", key, value);
147 if (!strcasecmp(key, "mmhighest"))
148 CitControl.MMhighest = atol(value);
149 if (!strcasecmp(key, "mmnextuser"))
150 CitControl.MMnextuser = atol(value);
156 void import_message(long msgnum, long msglen) {
160 msgtext = malloc(msglen);
161 if (msgtext == NULL) {
162 lprintf(3, "ERROR: cannot allocate memory\n");
163 lprintf(3, "Your data files are now corrupt.\n");
168 fread(msgtext, msglen, 1, imfp);
169 cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), msgtext, msglen);
173 void import_a_user() {
174 char key[256], value[256], list[256];
183 bzero(&us, sizeof(struct usersupp));
184 while(fpgetfield(imfp, key), strcasecmp(key, "enduser")) {
185 if ((strcasecmp(key, "mail"))
186 &&(strcasecmp(key, "lastseen"))
187 &&(strcasecmp(key, "generation"))
188 &&(strcasecmp(key, "forget")) ) {
189 fpgetfield(imfp, value);
195 if (!strcasecmp(key, "usuid"))
196 us.USuid = atoi(value);
197 if (!strcasecmp(key, "password")) {
198 strcpy(us.password, value);
200 if (!strcasecmp(key, "lastseen"))
201 for (a=0; a<ssv_maxrooms; ++a) {
202 fpgetfield(imfp, list);
203 us.lastseen[a] = atol(list);
205 if (!strcasecmp(key, "generation"))
206 for (a=0; a<ssv_maxrooms; ++a) {
207 fpgetfield(imfp, list);
208 us.generation[a] = atol(list);
210 if (!strcasecmp(key, "forget"))
211 for (a=0; a<ssv_maxrooms; ++a) {
212 fpgetfield(imfp, list);
213 us.forget[a] = atol(list);
215 if (!strcasecmp(key, "flags"))
216 us.flags = atoi(value);
217 if (!strcasecmp(key, "timescalled"))
218 us.timescalled = atoi(value);
219 if (!strcasecmp(key, "posted"))
220 us.posted = atoi(value);
221 if (!strcasecmp(key, "fullname")) {
222 strcpy(us.fullname, value);
223 lprintf(9, "User <%s>", us.fullname);
225 if (!strcasecmp(key, "axlevel"))
226 us.axlevel = atoi(value);
227 if (!strcasecmp(key, "usscreenwidth"))
228 us.USscreenwidth = atoi(value);
229 if (!strcasecmp(key, "usscreenheight"))
230 us.USscreenheight = atoi(value);
231 if (!strcasecmp(key, "usernum"))
232 us.usernum = atol(value);
233 if (!strcasecmp(key, "lastcall"))
234 us.lastcall = atol(value);
235 if (!strcasecmp(key, "usname"))
236 strcpy(us.USname, value);
237 if (!strcasecmp(key, "usaddr"))
238 strcpy(us.USaddr, value);
239 if (!strcasecmp(key, "uscity"))
240 strcpy(us.UScity, value);
241 if (!strcasecmp(key, "usstate"))
242 strcpy(us.USstate, value);
243 if (!strcasecmp(key, "uszip"))
244 strcpy(us.USzip, value);
245 if (!strcasecmp(key, "usphone"))
246 strcpy(us.USphone, value);
247 if (!strcasecmp(key, "usemail"))
248 strcpy(us.USemail, value);
249 if (!strcasecmp(key, "mail")) {
251 fpgetfield(imfp, list);
253 fpgetfield(imfp, list);
255 import_message(msgnum, msglen);
257 mbox = realloc(mbox, (sizeof(long)*mbox_size) );
258 mbox[mbox_size - 1] = msgnum;
262 for (a=0; a<=strlen(us.fullname); ++a) {
263 lcasename[a] = tolower(us.fullname[a]);
265 cdb_store(CDB_USERSUPP,
266 lcasename, strlen(lcasename),
267 &us, sizeof(struct usersupp));
269 cdb_store(CDB_MAILBOXES,
270 &us.usernum, sizeof(long),
271 mbox, (mbox_size * sizeof(long)) );
278 void imp_usersupp() {
279 char key[256], value[256];
281 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
282 if (strcasecmp(key, "user")) {
283 fpgetfield(imfp, value);
288 lprintf(9, " %s = %s\n", key, value);
290 if (!strcasecmp(key, "user")) {
299 char key[256], tag[256], tval[256];
304 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
306 if (!strcasecmp(key, "floor")) {
307 bzero(&fl, sizeof(struct floor));
309 while(fpgetfield(imfp, tag),
310 strcasecmp(tag, "endfloor")) {
311 fpgetfield(imfp, tval);
313 if (!strcasecmp(tag, "f_flags"))
314 fl.f_flags = atoi(tval);
315 if (!strcasecmp(tag, "f_name")) {
316 lprintf(9, "Floor <%s>\n", tval);
317 strcpy(fl.f_name, tval);
319 if (!strcasecmp(tag, "f_ref_count"))
320 fl.f_ref_count = atoi(tval);
323 cdb_store(CDB_FLOORTAB,
324 &floornum, sizeof(int),
325 &fl, sizeof(struct floor) );
329 lprintf(3, "ERROR: invalid floor section.\n");
330 lprintf(3, "Your data files are now corrupt.\n");
339 char key[256], value[256];
340 char tag[256], tval[256];
348 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
349 if (!strcasecmp(key, "room")) {
350 bzero(&qr, sizeof(struct quickroom));
355 while(fpgetfield(imfp, tag),
356 strcasecmp(tag, "endroom")) {
357 if (strcasecmp(tag, "message")) {
358 fpgetfield(imfp, tval);
364 if (!strcasecmp(tag, "qrname")) {
365 strcpy(qr.QRname, tval);
366 lprintf(9, "<%s>", qr.QRname);
368 if (!strcasecmp(tag, "qrpasswd"))
369 strcpy(qr.QRpasswd, tval);
370 if (!strcasecmp(tag, "qrroomaide"))
371 qr.QRroomaide = atol(tval);
372 if (!strcasecmp(tag, "qrhighest"))
373 qr.QRhighest = atol(tval);
374 if (!strcasecmp(tag, "qrgen"))
375 qr.QRgen = atol(tval);
376 if (!strcasecmp(tag, "qrflags"))
377 qr.QRflags = atoi(tval);
378 if (!strcasecmp(tag, "qrdirname"))
379 strcpy(qr.QRdirname, tval);
380 if (!strcasecmp(tag, "qrinfo"))
381 qr.QRinfo = atol(tval);
382 if (!strcasecmp(tag, "qrfloor"))
383 qr.QRfloor = atoi(tval);
384 if (!strcasecmp(tag, "message")) {
386 fpgetfield(imfp, tval);
388 fpgetfield(imfp, tval);
390 import_message(msgnum, msglen);
392 msglist = realloc(msglist,
393 (sizeof(long)*num_msgs) );
394 msglist[num_msgs - 1] = msgnum;
400 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
401 cdb_store(CDB_QUICKROOM,
402 &roomnum, sizeof(int),
403 &qr, sizeof(struct quickroom) );
407 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
408 cdb_store(CDB_MSGLISTS,
409 &roomnum, sizeof(int),
411 (sizeof(long)*num_msgs) );
420 lprintf(3, "ERROR: invalid room section.\n");
421 lprintf(3, "Your data files are now corrupt.\n");
430 void import_databases() {
433 lprintf(9, " ** IMPORTING ** \n");
434 imfp = fopen("/appl/citadel/exported", "rb");
435 while (fpgetfield(imfp, section), strcasecmp(section, "endfile")) {
436 lprintf(9, "Section: <%s>\n", section);
438 if (!strcasecmp(section, "ssv")) imp_ssv();
439 else if (!strcasecmp(section, "config")) imp_config();
440 else if (!strcasecmp(section, "globals")) imp_globals();
441 else if (!strcasecmp(section, "usersupp")) imp_usersupp();
442 else if (!strcasecmp(section, "rooms")) imp_rooms();
443 else if (!strcasecmp(section, "floors")) imp_floors();
445 lprintf(3, "ERROR: invalid import section.\n");
446 lprintf(3, "Your data files are now corrupt.\n");