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, ...) {
38 va_start(arg_ptr, format);
39 rc = vsprintf(buf, format, arg_ptr);
42 fprintf(stderr, "%s", buf);
47 void fpgetfield(fp,string)
66 char key[256], value[256];
68 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
69 fpgetfield(imfp, value);
70 lprintf(9, " %s = %s\n", key, value);
72 if (!strcasecmp(key, "maxfloors")) {
73 ssv_maxfloors = atol(value);
74 if (ssv_maxfloors > MAXFLOORS) {
75 lprintf(3, "ERROR: maxfloors is %d, need %d\n",
76 ssv_maxfloors, MAXFLOORS);
86 char key[256], value[256];
89 bzero(&config, sizeof(struct config));
90 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
91 fpgetfield(imfp, value);
92 lprintf(9, " %s = %s\n", key, value);
94 if (!strcasecmp(key, "c_nodename"))
95 strcpy(config.c_nodename, value);
96 if (!strcasecmp(key, "c_fqdn"))
97 strcpy(config.c_fqdn, value);
98 if (!strcasecmp(key, "c_humannode"))
99 strcpy(config.c_humannode, value);
100 if (!strcasecmp(key, "c_phonenum"))
101 strcpy(config.c_phonenum, value);
102 if (!strcasecmp(key, "c_phonenum"))
103 strcpy(config.c_phonenum, value);
104 if (!strcasecmp(key, "c_bbsuid"))
105 config.c_bbsuid = atoi(value);
106 if (!strcasecmp(key, "c_creataide"))
107 config.c_creataide = atoi(value);
108 if (!strcasecmp(key, "c_sleeping"))
109 config.c_sleeping = atoi(value);
110 if (!strcasecmp(key, "c_initax"))
111 config.c_initax = atoi(value);
112 if (!strcasecmp(key, "c_regiscall"))
113 config.c_regiscall = atoi(value);
114 if (!strcasecmp(key, "c_twitdetect"))
115 config.c_twitdetect = atoi(value);
116 if (!strcasecmp(key, "c_twitroom"))
117 strcpy(config.c_twitroom, value);
118 if (!strcasecmp(key, "c_moreprompt"))
119 strcpy(config.c_moreprompt, value);
120 if (!strcasecmp(key, "c_restrict"))
121 config.c_restrict = atoi(value);
122 if (!strcasecmp(key, "c_bbs_city"))
123 strcpy(config.c_bbs_city, value);
124 if (!strcasecmp(key, "c_sysadm"))
125 strcpy(config.c_sysadm, value);
126 if (!strcasecmp(key, "c_bucket_dir"))
127 strcpy(config.c_bucket_dir, value);
128 if (!strcasecmp(key, "c_setup_level"))
129 config.c_setup_level = atoi(value);
130 if (!strcasecmp(key, "c_maxsessions"))
131 config.c_maxsessions = atoi(value);
132 if (!strcasecmp(key, "c_net_password"))
133 strcpy(config.c_net_password, value);
134 if (!strcasecmp(key, "c_port_number"))
135 config.c_port_number = atoi(value);
138 fp = fopen("citadel.config", "wb");
139 fwrite(&config, sizeof(struct config), 1, fp);
145 char key[256], value[256];
148 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
149 fpgetfield(imfp, value);
150 lprintf(9, " %s = %s\n", key, value);
152 if (!strcasecmp(key, "mmhighest"))
153 CitControl.MMhighest = atol(value);
154 if (!strcasecmp(key, "mmnextuser"))
155 CitControl.MMnextuser = atol(value);
161 void import_message(long msgnum, long msglen) {
165 msgtext = malloc(msglen);
166 if (msgtext == NULL) {
167 lprintf(3, "ERROR: cannot allocate memory\n");
168 lprintf(3, "Your data files are now corrupt.\n");
173 fread(msgtext, msglen, 1, imfp);
174 cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), msgtext, msglen);
178 void import_a_user() {
179 char key[256], value[256], list[256];
188 bzero(&us, sizeof(struct usersupp));
189 while(fpgetfield(imfp, key), strcasecmp(key, "enduser")) {
190 if ((strcasecmp(key, "mail"))
191 &&(strcasecmp(key, "lastseen"))
192 &&(strcasecmp(key, "generation"))
193 &&(strcasecmp(key, "forget")) ) {
194 fpgetfield(imfp, value);
200 if (!strcasecmp(key, "usuid"))
201 us.USuid = atoi(value);
202 if (!strcasecmp(key, "password")) {
203 strcpy(us.password, value);
205 if (!strcasecmp(key, "lastseen"))
206 for (a=0; a<ssv_maxrooms; ++a) {
207 fpgetfield(imfp, list);
208 us.lastseen[a] = atol(list);
210 if (!strcasecmp(key, "generation"))
211 for (a=0; a<ssv_maxrooms; ++a) {
212 fpgetfield(imfp, list);
213 us.generation[a] = atol(list);
215 if (!strcasecmp(key, "forget"))
216 for (a=0; a<ssv_maxrooms; ++a) {
217 fpgetfield(imfp, list);
218 us.forget[a] = atol(list);
220 if (!strcasecmp(key, "flags"))
221 us.flags = atoi(value);
222 if (!strcasecmp(key, "timescalled"))
223 us.timescalled = atoi(value);
224 if (!strcasecmp(key, "posted"))
225 us.posted = atoi(value);
226 if (!strcasecmp(key, "fullname")) {
227 strcpy(us.fullname, value);
228 lprintf(9, "User <%s>", us.fullname);
230 if (!strcasecmp(key, "axlevel"))
231 us.axlevel = atoi(value);
232 if (!strcasecmp(key, "usscreenwidth"))
233 us.USscreenwidth = atoi(value);
234 if (!strcasecmp(key, "usscreenheight"))
235 us.USscreenheight = atoi(value);
236 if (!strcasecmp(key, "usernum"))
237 us.usernum = atol(value);
238 if (!strcasecmp(key, "lastcall"))
239 us.lastcall = atol(value);
240 if (!strcasecmp(key, "usname"))
241 strcpy(us.USname, value);
242 if (!strcasecmp(key, "usaddr"))
243 strcpy(us.USaddr, value);
244 if (!strcasecmp(key, "uscity"))
245 strcpy(us.UScity, value);
246 if (!strcasecmp(key, "usstate"))
247 strcpy(us.USstate, value);
248 if (!strcasecmp(key, "uszip"))
249 strcpy(us.USzip, value);
250 if (!strcasecmp(key, "usphone"))
251 strcpy(us.USphone, value);
252 if (!strcasecmp(key, "usemail"))
253 strcpy(us.USemail, value);
254 if (!strcasecmp(key, "mail")) {
256 fpgetfield(imfp, list);
258 fpgetfield(imfp, list);
260 import_message(msgnum, msglen);
262 mbox = realloc(mbox, (sizeof(long)*mbox_size) );
263 mbox[mbox_size - 1] = msgnum;
267 for (a=0; a<=strlen(us.fullname); ++a) {
268 lcasename[a] = tolower(us.fullname[a]);
270 cdb_store(CDB_USERSUPP,
271 lcasename, strlen(lcasename),
272 &us, sizeof(struct usersupp));
274 cdb_store(CDB_MAILBOXES,
275 &us.usernum, sizeof(long),
276 mbox, (mbox_size * sizeof(long)) );
283 void imp_usersupp() {
284 char key[256], value[256];
286 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
287 if (strcasecmp(key, "user")) {
288 fpgetfield(imfp, value);
293 lprintf(9, " %s = %s\n", key, value);
295 if (!strcasecmp(key, "user")) {
304 char key[256], tag[256], tval[256];
309 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
311 if (!strcasecmp(key, "floor")) {
312 bzero(&fl, sizeof(struct floor));
314 while(fpgetfield(imfp, tag),
315 strcasecmp(tag, "endfloor")) {
316 fpgetfield(imfp, tval);
318 if (!strcasecmp(tag, "f_flags"))
319 fl.f_flags = atoi(tval);
320 if (!strcasecmp(tag, "f_name")) {
321 lprintf(9, "Floor <%s>\n", tval);
322 strcpy(fl.f_name, tval);
324 if (!strcasecmp(tag, "f_ref_count"))
325 fl.f_ref_count = atoi(tval);
328 cdb_store(CDB_FLOORTAB,
329 &floornum, sizeof(int),
330 &fl, sizeof(struct floor) );
334 lprintf(3, "ERROR: invalid floor section.\n");
335 lprintf(3, "Your data files are now corrupt.\n");
344 char key[256], value[256];
345 char tag[256], tval[256];
353 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
354 if (!strcasecmp(key, "room")) {
355 bzero(&qr, sizeof(struct quickroom));
360 while(fpgetfield(imfp, tag),
361 strcasecmp(tag, "endroom")) {
362 if (strcasecmp(tag, "message")) {
363 fpgetfield(imfp, tval);
369 if (!strcasecmp(tag, "qrname")) {
370 strcpy(qr.QRname, tval);
371 lprintf(9, "<%s>", qr.QRname);
373 if (!strcasecmp(tag, "qrpasswd"))
374 strcpy(qr.QRpasswd, tval);
375 if (!strcasecmp(tag, "qrroomaide"))
376 qr.QRroomaide = atol(tval);
377 if (!strcasecmp(tag, "qrhighest"))
378 qr.QRhighest = atol(tval);
379 if (!strcasecmp(tag, "qrgen"))
380 qr.QRgen = atol(tval);
381 if (!strcasecmp(tag, "qrflags"))
382 qr.QRflags = atoi(tval);
383 if (!strcasecmp(tag, "qrdirname"))
384 strcpy(qr.QRdirname, tval);
385 if (!strcasecmp(tag, "qrinfo"))
386 qr.QRinfo = atol(tval);
387 if (!strcasecmp(tag, "qrfloor"))
388 qr.QRfloor = atoi(tval);
389 if (!strcasecmp(tag, "message")) {
391 fpgetfield(imfp, tval);
393 fpgetfield(imfp, tval);
395 import_message(msgnum, msglen);
397 msglist = realloc(msglist,
398 (sizeof(long)*num_msgs) );
399 msglist[num_msgs - 1] = msgnum;
405 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
406 cdb_store(CDB_QUICKROOM,
407 &roomnum, sizeof(int),
408 &qr, sizeof(struct quickroom) );
412 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
413 cdb_store(CDB_MSGLISTS,
414 &roomnum, sizeof(int),
416 (sizeof(long)*num_msgs) );
425 lprintf(3, "ERROR: invalid room section.\n");
426 lprintf(3, "Your data files are now corrupt.\n");
435 void import_databases() {
438 lprintf(9, " ** IMPORTING ** \n");
439 imfp = fopen("/appl/citadel/exported", "rb");
440 while (fpgetfield(imfp, section), strcasecmp(section, "endfile")) {
441 lprintf(9, "Section: <%s>\n", section);
443 if (!strcasecmp(section, "ssv")) imp_ssv();
444 else if (!strcasecmp(section, "config")) imp_config();
445 else if (!strcasecmp(section, "globals")) imp_globals();
446 else if (!strcasecmp(section, "usersupp")) imp_usersupp();
447 else if (!strcasecmp(section, "rooms")) imp_rooms();
448 else if (!strcasecmp(section, "floors")) imp_floors();
450 lprintf(3, "ERROR: invalid import section.\n");
451 lprintf(3, "Your data files are now corrupt.\n");