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_defent"))
119 config.c_defent = atoi(value);
120 if (!strcasecmp(key, "c_moreprompt"))
121 strcpy(config.c_moreprompt, value);
122 if (!strcasecmp(key, "c_restrict"))
123 config.c_restrict = atoi(value);
124 if (!strcasecmp(key, "c_bbs_city"))
125 strcpy(config.c_bbs_city, value);
126 if (!strcasecmp(key, "c_sysadm"))
127 strcpy(config.c_sysadm, value);
128 if (!strcasecmp(key, "c_bucket_dir"))
129 strcpy(config.c_bucket_dir, value);
130 if (!strcasecmp(key, "c_setup_level"))
131 config.c_setup_level = atoi(value);
132 if (!strcasecmp(key, "c_maxsessions"))
133 config.c_maxsessions = atoi(value);
134 if (!strcasecmp(key, "c_net_password"))
135 strcpy(config.c_net_password, value);
136 if (!strcasecmp(key, "c_port_number"))
137 config.c_port_number = atoi(value);
140 fp = fopen("citadel.config", "wb");
141 fwrite(&config, sizeof(struct config), 1, fp);
147 char key[256], value[256];
150 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
151 fpgetfield(imfp, value);
152 lprintf(9, " %s = %s\n", key, value);
154 if (!strcasecmp(key, "mmhighest"))
155 CitControl.MMhighest = atol(value);
156 if (!strcasecmp(key, "mmnextuser"))
157 CitControl.MMnextuser = atol(value);
163 void import_message(long msgnum, long msglen) {
167 msgtext = malloc(msglen);
168 if (msgtext == NULL) {
169 lprintf(3, "ERROR: cannot allocate memory\n");
170 lprintf(3, "Your data files are now corrupt.\n");
175 fread(msgtext, msglen, 1, imfp);
176 cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), msgtext, msglen);
180 void import_a_user() {
181 char key[256], value[256], list[256];
190 bzero(&us, sizeof(struct usersupp));
191 while(fpgetfield(imfp, key), strcasecmp(key, "enduser")) {
192 if ((strcasecmp(key, "mail"))
193 &&(strcasecmp(key, "lastseen"))
194 &&(strcasecmp(key, "generation"))
195 &&(strcasecmp(key, "forget")) ) {
196 fpgetfield(imfp, value);
202 if (!strcasecmp(key, "usuid"))
203 us.USuid = atoi(value);
204 if (!strcasecmp(key, "password")) {
205 strcpy(us.password, value);
207 if (!strcasecmp(key, "lastseen"))
208 for (a=0; a<ssv_maxrooms; ++a) {
209 fpgetfield(imfp, list);
210 us.lastseen[a] = atol(list);
212 if (!strcasecmp(key, "generation"))
213 for (a=0; a<ssv_maxrooms; ++a) {
214 fpgetfield(imfp, list);
215 us.generation[a] = atol(list);
217 if (!strcasecmp(key, "forget"))
218 for (a=0; a<ssv_maxrooms; ++a) {
219 fpgetfield(imfp, list);
220 us.forget[a] = atol(list);
222 if (!strcasecmp(key, "flags"))
223 us.flags = atoi(value);
224 if (!strcasecmp(key, "timescalled"))
225 us.timescalled = atoi(value);
226 if (!strcasecmp(key, "posted"))
227 us.posted = atoi(value);
228 if (!strcasecmp(key, "fullname")) {
229 strcpy(us.fullname, value);
230 lprintf(9, "User <%s>", us.fullname);
232 if (!strcasecmp(key, "axlevel"))
233 us.axlevel = atoi(value);
234 if (!strcasecmp(key, "usscreenwidth"))
235 us.USscreenwidth = atoi(value);
236 if (!strcasecmp(key, "usscreenheight"))
237 us.USscreenheight = atoi(value);
238 if (!strcasecmp(key, "usernum"))
239 us.usernum = atol(value);
240 if (!strcasecmp(key, "lastcall"))
241 us.lastcall = atol(value);
242 if (!strcasecmp(key, "usname"))
243 strcpy(us.USname, value);
244 if (!strcasecmp(key, "usaddr"))
245 strcpy(us.USaddr, value);
246 if (!strcasecmp(key, "uscity"))
247 strcpy(us.UScity, value);
248 if (!strcasecmp(key, "usstate"))
249 strcpy(us.USstate, value);
250 if (!strcasecmp(key, "uszip"))
251 strcpy(us.USzip, value);
252 if (!strcasecmp(key, "usphone"))
253 strcpy(us.USphone, value);
254 if (!strcasecmp(key, "usemail"))
255 strcpy(us.USemail, value);
256 if (!strcasecmp(key, "mail")) {
258 fpgetfield(imfp, list);
260 fpgetfield(imfp, list);
262 import_message(msgnum, msglen);
264 mbox = realloc(mbox, (sizeof(long)*mbox_size) );
265 mbox[mbox_size - 1] = msgnum;
269 for (a=0; a<=strlen(us.fullname); ++a) {
270 lcasename[a] = tolower(us.fullname[a]);
272 cdb_store(CDB_USERSUPP,
273 lcasename, strlen(lcasename),
274 &us, sizeof(struct usersupp));
276 cdb_store(CDB_MAILBOXES,
277 &us.usernum, sizeof(long),
278 mbox, (mbox_size * sizeof(long)) );
285 void imp_usersupp() {
286 char key[256], value[256];
288 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
289 if (strcasecmp(key, "user")) {
290 fpgetfield(imfp, value);
295 lprintf(9, " %s = %s\n", key, value);
297 if (!strcasecmp(key, "user")) {
306 char key[256], tag[256], tval[256];
311 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
313 if (!strcasecmp(key, "floor")) {
314 bzero(&fl, sizeof(struct floor));
316 while(fpgetfield(imfp, tag),
317 strcasecmp(tag, "endfloor")) {
318 fpgetfield(imfp, tval);
320 if (!strcasecmp(tag, "f_flags"))
321 fl.f_flags = atoi(tval);
322 if (!strcasecmp(tag, "f_name")) {
323 lprintf(9, "Floor <%s>\n", tval);
324 strcpy(fl.f_name, tval);
326 if (!strcasecmp(tag, "f_ref_count"))
327 fl.f_ref_count = atoi(tval);
330 cdb_store(CDB_FLOORTAB,
331 &floornum, sizeof(int),
332 &fl, sizeof(struct floor) );
336 lprintf(3, "ERROR: invalid floor section.\n");
337 lprintf(3, "Your data files are now corrupt.\n");
346 char key[256], value[256];
347 char tag[256], tval[256];
355 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
356 if (!strcasecmp(key, "room")) {
357 bzero(&qr, sizeof(struct quickroom));
362 while(fpgetfield(imfp, tag),
363 strcasecmp(tag, "endroom")) {
364 if (strcasecmp(tag, "message")) {
365 fpgetfield(imfp, tval);
371 if (!strcasecmp(tag, "qrname")) {
372 strcpy(qr.QRname, tval);
373 lprintf(9, "<%s>", qr.QRname);
375 if (!strcasecmp(tag, "qrpasswd"))
376 strcpy(qr.QRpasswd, tval);
377 if (!strcasecmp(tag, "qrroomaide"))
378 qr.QRroomaide = atol(tval);
379 if (!strcasecmp(tag, "qrhighest"))
380 qr.QRhighest = atol(tval);
381 if (!strcasecmp(tag, "qrgen"))
382 qr.QRgen = atol(tval);
383 if (!strcasecmp(tag, "qrflags"))
384 qr.QRflags = atoi(tval);
385 if (!strcasecmp(tag, "qrdirname"))
386 strcpy(qr.QRdirname, tval);
387 if (!strcasecmp(tag, "qrinfo"))
388 qr.QRinfo = atol(tval);
389 if (!strcasecmp(tag, "qrfloor"))
390 qr.QRfloor = atoi(tval);
391 if (!strcasecmp(tag, "message")) {
393 fpgetfield(imfp, tval);
395 fpgetfield(imfp, tval);
397 import_message(msgnum, msglen);
399 msglist = realloc(msglist,
400 (sizeof(long)*num_msgs) );
401 msglist[num_msgs - 1] = msgnum;
407 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
408 cdb_store(CDB_QUICKROOM,
409 &roomnum, sizeof(int),
410 &qr, sizeof(struct quickroom) );
414 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
415 cdb_store(CDB_MSGLISTS,
416 &roomnum, sizeof(int),
418 (sizeof(long)*num_msgs) );
427 lprintf(3, "ERROR: invalid room section.\n");
428 lprintf(3, "Your data files are now corrupt.\n");
437 void import_databases() {
440 lprintf(9, " ** IMPORTING ** \n");
441 imfp = fopen("/appl/citadel/exported", "rb");
442 while (fpgetfield(imfp, section), strcasecmp(section, "endfile")) {
443 lprintf(9, "Section: <%s>\n", section);
445 if (!strcasecmp(section, "ssv")) imp_ssv();
446 else if (!strcasecmp(section, "config")) imp_config();
447 else if (!strcasecmp(section, "globals")) imp_globals();
448 else if (!strcasecmp(section, "usersupp")) imp_usersupp();
449 else if (!strcasecmp(section, "rooms")) imp_rooms();
450 else if (!strcasecmp(section, "floors")) imp_floors();
452 lprintf(3, "ERROR: invalid import section.\n");
453 lprintf(3, "Your data files are now corrupt.\n");