1 /* 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, "maxrooms")) {
73 ssv_maxrooms = atol(value);
74 if (ssv_maxrooms > MAXROOMS) {
75 lprintf(3, "ERROR: maxrooms is %d, need %d\n",
76 ssv_maxrooms, MAXROOMS);
82 if (!strcasecmp(key, "maxfloors")) {
83 ssv_maxfloors = atol(value);
84 if (ssv_maxfloors > MAXFLOORS) {
85 lprintf(3, "ERROR: maxfloors is %d, need %d\n",
86 ssv_maxfloors, MAXFLOORS);
96 char key[256], value[256];
99 bzero(&config, sizeof(struct config));
100 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
101 fpgetfield(imfp, value);
102 lprintf(9, " %s = %s\n", key, value);
104 if (!strcasecmp(key, "c_nodename"))
105 strcpy(config.c_nodename, value);
106 if (!strcasecmp(key, "c_fqdn"))
107 strcpy(config.c_fqdn, value);
108 if (!strcasecmp(key, "c_humannode"))
109 strcpy(config.c_humannode, value);
110 if (!strcasecmp(key, "c_phonenum"))
111 strcpy(config.c_phonenum, value);
112 if (!strcasecmp(key, "c_phonenum"))
113 strcpy(config.c_phonenum, value);
114 if (!strcasecmp(key, "c_bbsuid"))
115 config.c_bbsuid = atoi(value);
116 if (!strcasecmp(key, "c_creataide"))
117 config.c_creataide = atoi(value);
118 if (!strcasecmp(key, "c_sleeping"))
119 config.c_sleeping = atoi(value);
120 if (!strcasecmp(key, "c_initax"))
121 config.c_initax = atoi(value);
122 if (!strcasecmp(key, "c_regiscall"))
123 config.c_regiscall = atoi(value);
124 if (!strcasecmp(key, "c_twitdetect"))
125 config.c_twitdetect = atoi(value);
126 if (!strcasecmp(key, "c_twitroom"))
127 strcpy(config.c_twitroom, value);
128 if (!strcasecmp(key, "c_defent"))
129 config.c_defent = atoi(value);
130 if (!strcasecmp(key, "c_moreprompt"))
131 strcpy(config.c_moreprompt, value);
132 if (!strcasecmp(key, "c_restrict"))
133 config.c_restrict = atoi(value);
134 if (!strcasecmp(key, "c_bbs_city"))
135 strcpy(config.c_bbs_city, value);
136 if (!strcasecmp(key, "c_sysadm"))
137 strcpy(config.c_sysadm, value);
138 if (!strcasecmp(key, "c_bucket_dir"))
139 strcpy(config.c_bucket_dir, value);
140 if (!strcasecmp(key, "c_setup_level"))
141 config.c_setup_level = atoi(value);
142 if (!strcasecmp(key, "c_maxsessions"))
143 config.c_maxsessions = atoi(value);
144 if (!strcasecmp(key, "c_net_password"))
145 strcpy(config.c_net_password, value);
146 if (!strcasecmp(key, "c_port_number"))
147 config.c_port_number = atoi(value);
150 fp = fopen("citadel.config", "wb");
151 fwrite(&config, sizeof(struct config), 1, fp);
157 char key[256], value[256];
160 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
161 fpgetfield(imfp, value);
162 lprintf(9, " %s = %s\n", key, value);
164 if (!strcasecmp(key, "mmhighest"))
165 CitControl.MMhighest = atol(value);
166 if (!strcasecmp(key, "mmnextuser"))
167 CitControl.MMnextuser = atol(value);
173 void import_message(long msgnum, long msglen) {
177 msgtext = malloc(msglen);
178 if (msgtext == NULL) {
179 lprintf(3, "ERROR: cannot allocate memory\n");
180 lprintf(3, "Your data files are now corrupt.\n");
185 fread(msgtext, msglen, 1, imfp);
186 cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), msgtext, msglen);
190 void import_a_user() {
191 char key[256], value[256], list[256];
200 bzero(&us, sizeof(struct usersupp));
201 while(fpgetfield(imfp, key), strcasecmp(key, "enduser")) {
202 if ((strcasecmp(key, "mail"))
203 &&(strcasecmp(key, "lastseen"))
204 &&(strcasecmp(key, "generation"))
205 &&(strcasecmp(key, "forget")) ) {
206 fpgetfield(imfp, value);
212 if (!strcasecmp(key, "usuid"))
213 us.USuid = atoi(value);
214 if (!strcasecmp(key, "password")) {
215 strcpy(us.password, value);
217 if (!strcasecmp(key, "lastseen"))
218 for (a=0; a<ssv_maxrooms; ++a) {
219 fpgetfield(imfp, list);
220 us.lastseen[a] = atol(list);
222 if (!strcasecmp(key, "generation"))
223 for (a=0; a<ssv_maxrooms; ++a) {
224 fpgetfield(imfp, list);
225 us.generation[a] = atoi(list);
227 if (!strcasecmp(key, "forget"))
228 for (a=0; a<ssv_maxrooms; ++a) {
229 fpgetfield(imfp, list);
230 us.forget[a] = atol(list);
232 if (!strcasecmp(key, "flags"))
233 us.flags = atoi(value);
234 if (!strcasecmp(key, "timescalled"))
235 us.timescalled = atoi(value);
236 if (!strcasecmp(key, "posted"))
237 us.posted = atoi(value);
238 if (!strcasecmp(key, "fullname")) {
239 strcpy(us.fullname, value);
240 lprintf(9, "User <%s>", us.fullname);
242 if (!strcasecmp(key, "axlevel"))
243 us.axlevel = atoi(value);
244 if (!strcasecmp(key, "usscreenwidth"))
245 us.USscreenwidth = atoi(value);
246 if (!strcasecmp(key, "usscreenheight"))
247 us.USscreenheight = atoi(value);
248 if (!strcasecmp(key, "usernum"))
249 us.usernum = atol(value);
250 if (!strcasecmp(key, "lastcall"))
251 us.lastcall = atol(value);
252 if (!strcasecmp(key, "usname"))
253 strcpy(us.USname, value);
254 if (!strcasecmp(key, "usaddr"))
255 strcpy(us.USaddr, value);
256 if (!strcasecmp(key, "uscity"))
257 strcpy(us.UScity, value);
258 if (!strcasecmp(key, "usstate"))
259 strcpy(us.USstate, value);
260 if (!strcasecmp(key, "uszip"))
261 strcpy(us.USzip, value);
262 if (!strcasecmp(key, "usphone"))
263 strcpy(us.USphone, value);
264 if (!strcasecmp(key, "usemail"))
265 strcpy(us.USemail, value);
266 if (!strcasecmp(key, "mail")) {
268 fpgetfield(imfp, list);
270 fpgetfield(imfp, list);
272 import_message(msgnum, msglen);
274 mbox = realloc(mbox, (sizeof(long)*mbox_size) );
275 mbox[mbox_size - 1] = msgnum;
279 for (a=0; a<=strlen(us.fullname); ++a) {
280 lcasename[a] = tolower(us.fullname[a]);
282 cdb_store(CDB_USERSUPP,
283 lcasename, strlen(lcasename),
284 &us, sizeof(struct usersupp));
286 cdb_store(CDB_MAILBOXES,
287 &us.usernum, sizeof(long),
288 mbox, (mbox_size * sizeof(long)) );
295 void imp_usersupp() {
296 char key[256], value[256];
298 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
299 if (strcasecmp(key, "user")) {
300 fpgetfield(imfp, value);
305 lprintf(9, " %s = %s\n", key, value);
307 if (!strcasecmp(key, "user")) {
316 char key[256], tag[256], tval[256];
321 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
323 if (!strcasecmp(key, "floor")) {
324 bzero(&fl, sizeof(struct floor));
326 while(fpgetfield(imfp, tag),
327 strcasecmp(tag, "endfloor")) {
328 fpgetfield(imfp, tval);
330 if (!strcasecmp(tag, "f_flags"))
331 fl.f_flags = atoi(tval);
332 if (!strcasecmp(tag, "f_name")) {
333 lprintf(9, "Floor <%s>\n", tval);
334 strcpy(fl.f_name, tval);
336 if (!strcasecmp(tag, "f_ref_count"))
337 fl.f_ref_count = atoi(tval);
340 cdb_store(CDB_FLOORTAB,
341 &floornum, sizeof(int),
342 &fl, sizeof(struct floor) );
346 lprintf(3, "ERROR: invalid floor section.\n");
347 lprintf(3, "Your data files are now corrupt.\n");
356 char key[256], value[256];
357 char tag[256], tval[256];
364 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
365 if (!strcasecmp(key, "room")) {
366 bzero(&qr, sizeof(struct quickroom));
371 while(fpgetfield(imfp, tag),
372 strcasecmp(tag, "endroom")) {
373 if (strcasecmp(tag, "message")) {
374 fpgetfield(imfp, tval);
380 if (!strcasecmp(tag, "qrname")) {
381 strcpy(qr.QRname, tval);
382 lprintf(9, "<%s>", qr.QRname);
384 if (!strcasecmp(tag, "qrpasswd"))
385 strcpy(qr.QRpasswd, tval);
386 if (!strcasecmp(tag, "qrroomaide"))
387 qr.QRroomaide = atol(tval);
388 if (!strcasecmp(tag, "qrhighest"))
389 qr.QRhighest = atol(tval);
390 if (!strcasecmp(tag, "qrgen"))
391 qr.QRgen = atoi(tval);
392 if (!strcasecmp(tag, "qrflags"))
393 qr.QRflags = atoi(tval);
394 if (!strcasecmp(tag, "qrdirname"))
395 strcpy(qr.QRdirname, tval);
396 if (!strcasecmp(tag, "qrinfo"))
397 qr.QRinfo = atol(tval);
398 if (!strcasecmp(tag, "qrfloor"))
399 qr.QRfloor = atoi(tval);
400 if (!strcasecmp(tag, "message")) {
402 fpgetfield(imfp, tval);
404 fpgetfield(imfp, tval);
406 import_message(msgnum, msglen);
408 msglist = realloc(msglist,
409 (sizeof(long)*num_msgs) );
410 msglist[num_msgs - 1] = msgnum;
416 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE))
417 cdb_store(CDB_QUICKROOM,
418 &roomnum, sizeof(int),
419 &qr, sizeof(struct quickroom) );
422 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE))
423 cdb_store(CDB_MSGLISTS, &roomnum, sizeof(int),
424 msglist, (sizeof(long)*num_msgs) );
432 lprintf(3, "ERROR: invalid room section.\n");
433 lprintf(3, "Your data files are now corrupt.\n");
442 void import_databases() {
445 lprintf(9, " ** IMPORTING ** \n");
446 imfp = fopen("/appl/citadel/exported", "rb");
447 while (fpgetfield(imfp, section), strcasecmp(section, "endfile")) {
448 lprintf(9, "Section: <%s>\n", section);
450 if (!strcasecmp(section, "ssv")) imp_ssv();
451 else if (!strcasecmp(section, "config")) imp_config();
452 else if (!strcasecmp(section, "globals")) imp_globals();
453 else if (!strcasecmp(section, "usersupp")) imp_usersupp();
454 else if (!strcasecmp(section, "rooms")) imp_rooms();
455 else if (!strcasecmp(section, "floors")) imp_floors();
457 lprintf(3, "ERROR: invalid import section.\n");
458 lprintf(3, "Your data files are now corrupt.\n");