1 /* cc import.c database.o control.o -lgdbm -o import */
16 int ssv_maxfloors = 0;
20 /**** stubs which need to be defined for database.c to work ****/
23 struct CitContext MyCC;
25 struct CitContext *MyContext() {
29 void begin_critical_section(int c) { }
30 void end_critical_section(int c) { }
32 void lprintf(int loglevel, const char *format, ...) {
37 va_start(arg_ptr, format);
38 rc = vsprintf(buf, format, arg_ptr);
41 fprintf(stderr, "%s", buf);
46 void fpgetfield(fp,string)
65 char key[256], value[256];
67 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
68 fpgetfield(imfp, value);
69 lprintf(9, " %s = %s\n", key, value);
71 if (!strcasecmp(key, "maxrooms")) {
72 ssv_maxrooms = atol(value);
73 if (ssv_maxrooms > MAXROOMS) {
74 lprintf(3, "ERROR: maxrooms is %d, need %d\n",
75 ssv_maxrooms, MAXROOMS);
81 if (!strcasecmp(key, "maxfloors")) {
82 ssv_maxfloors = atol(value);
83 if (ssv_maxfloors > MAXFLOORS) {
84 lprintf(3, "ERROR: maxfloors is %d, need %d\n",
85 ssv_maxfloors, MAXFLOORS);
95 char key[256], value[256];
98 bzero(&config, sizeof(struct config));
99 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
100 fpgetfield(imfp, value);
101 lprintf(9, " %s = %s\n", key, value);
103 if (!strcasecmp(key, "c_nodename"))
104 strcpy(config.c_nodename, value);
105 if (!strcasecmp(key, "c_fqdn"))
106 strcpy(config.c_fqdn, value);
107 if (!strcasecmp(key, "c_humannode"))
108 strcpy(config.c_humannode, value);
109 if (!strcasecmp(key, "c_phonenum"))
110 strcpy(config.c_phonenum, value);
111 if (!strcasecmp(key, "c_phonenum"))
112 strcpy(config.c_phonenum, value);
113 if (!strcasecmp(key, "c_bbsuid"))
114 config.c_bbsuid = atoi(value);
115 if (!strcasecmp(key, "c_creataide"))
116 config.c_creataide = atoi(value);
117 if (!strcasecmp(key, "c_sleeping"))
118 config.c_sleeping = atoi(value);
119 if (!strcasecmp(key, "c_initax"))
120 config.c_initax = atoi(value);
121 if (!strcasecmp(key, "c_regiscall"))
122 config.c_regiscall = atoi(value);
123 if (!strcasecmp(key, "c_twitdetect"))
124 config.c_twitdetect = atoi(value);
125 if (!strcasecmp(key, "c_twitroom"))
126 strcpy(config.c_twitroom, value);
127 if (!strcasecmp(key, "c_defent"))
128 config.c_defent = atoi(value);
129 if (!strcasecmp(key, "c_moreprompt"))
130 strcpy(config.c_moreprompt, value);
131 if (!strcasecmp(key, "c_restrict"))
132 config.c_restrict = atoi(value);
133 if (!strcasecmp(key, "c_bbs_city"))
134 strcpy(config.c_bbs_city, value);
135 if (!strcasecmp(key, "c_sysadm"))
136 strcpy(config.c_sysadm, value);
137 if (!strcasecmp(key, "c_bucket_dir"))
138 strcpy(config.c_bucket_dir, value);
139 if (!strcasecmp(key, "c_setup_level"))
140 config.c_setup_level = atoi(value);
141 if (!strcasecmp(key, "c_maxsessions"))
142 config.c_maxsessions = atoi(value);
143 if (!strcasecmp(key, "c_net_password"))
144 strcpy(config.c_net_password, value);
145 if (!strcasecmp(key, "c_port_number"))
146 config.c_port_number = atoi(value);
149 fp = fopen("citadel.config", "wb");
150 fwrite(&config, sizeof(struct config), 1, fp);
156 char key[256], value[256];
159 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
160 fpgetfield(imfp, value);
161 lprintf(9, " %s = %s\n", key, value);
163 if (!strcasecmp(key, "mmhighest"))
164 CitControl.MMhighest = atol(value);
165 if (!strcasecmp(key, "mmnextuser"))
166 CitControl.MMnextuser = atol(value);
172 void import_message(long msgnum, long msglen) {
176 msgtext = malloc(msglen);
177 if (msgtext == NULL) {
178 lprintf(3, "ERROR: cannot allocate memory\n");
179 lprintf(3, "Your data files are now corrupt.\n");
184 fread(msgtext, msglen, 1, imfp);
185 cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), msgtext, msglen);
189 void import_a_user() {
190 char key[256], value[256], list[256];
199 bzero(&us, sizeof(struct usersupp));
200 while(fpgetfield(imfp, key), strcasecmp(key, "enduser")) {
201 if ((strcasecmp(key, "mail"))
202 &&(strcasecmp(key, "lastseen"))
203 &&(strcasecmp(key, "generation"))
204 &&(strcasecmp(key, "forget")) ) {
205 fpgetfield(imfp, value);
211 if (!strcasecmp(key, "usuid"))
212 us.USuid = atoi(value);
213 if (!strcasecmp(key, "password")) {
214 strcpy(us.password, value);
216 if (!strcasecmp(key, "lastseen"))
217 for (a=0; a<ssv_maxrooms; ++a) {
218 fpgetfield(imfp, list);
219 us.lastseen[a] = atol(list);
221 if (!strcasecmp(key, "generation"))
222 for (a=0; a<ssv_maxrooms; ++a) {
223 fpgetfield(imfp, list);
224 us.generation[a] = atoi(list);
226 if (!strcasecmp(key, "forget"))
227 for (a=0; a<ssv_maxrooms; ++a) {
228 fpgetfield(imfp, list);
229 us.forget[a] = atol(list);
231 if (!strcasecmp(key, "flags"))
232 us.flags = atoi(value);
233 if (!strcasecmp(key, "timescalled"))
234 us.timescalled = atoi(value);
235 if (!strcasecmp(key, "posted"))
236 us.posted = atoi(value);
237 if (!strcasecmp(key, "fullname")) {
238 strcpy(us.fullname, value);
239 lprintf(9, "User <%s>", us.fullname);
241 if (!strcasecmp(key, "axlevel"))
242 us.axlevel = atoi(value);
243 if (!strcasecmp(key, "usscreenwidth"))
244 us.USscreenwidth = atoi(value);
245 if (!strcasecmp(key, "usscreenheight"))
246 us.USscreenheight = atoi(value);
247 if (!strcasecmp(key, "usernum"))
248 us.usernum = atol(value);
249 if (!strcasecmp(key, "lastcall"))
250 us.lastcall = atol(value);
251 if (!strcasecmp(key, "usname"))
252 strcpy(us.USname, value);
253 if (!strcasecmp(key, "usaddr"))
254 strcpy(us.USaddr, value);
255 if (!strcasecmp(key, "uscity"))
256 strcpy(us.UScity, value);
257 if (!strcasecmp(key, "usstate"))
258 strcpy(us.USstate, value);
259 if (!strcasecmp(key, "uszip"))
260 strcpy(us.USzip, value);
261 if (!strcasecmp(key, "usphone"))
262 strcpy(us.USphone, value);
263 if (!strcasecmp(key, "usemail"))
264 strcpy(us.USemail, value);
265 if (!strcasecmp(key, "mail")) {
267 fpgetfield(imfp, list);
269 fpgetfield(imfp, list);
271 import_message(msgnum, msglen);
273 mbox = realloc(mbox, (sizeof(long)*mbox_size) );
274 mbox[mbox_size - 1] = msgnum;
278 for (a=0; a<=strlen(us.fullname); ++a) {
279 lcasename[a] = tolower(us.fullname[a]);
281 cdb_store(CDB_USERSUPP,
282 lcasename, strlen(lcasename),
283 &us, sizeof(struct usersupp));
285 cdb_store(CDB_MAILBOXES,
286 &us.usernum, sizeof(long),
287 mbox, (mbox_size * sizeof(long)) );
294 void imp_usersupp() {
295 char key[256], value[256];
297 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
298 if (strcasecmp(key, "user")) {
299 fpgetfield(imfp, value);
304 lprintf(9, " %s = %s\n", key, value);
306 if (!strcasecmp(key, "user")) {
315 char key[256], tag[256], tval[256];
320 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
322 if (!strcasecmp(key, "floor")) {
323 bzero(&fl, sizeof(struct floor));
325 while(fpgetfield(imfp, tag),
326 strcasecmp(tag, "endfloor")) {
327 fpgetfield(imfp, tval);
329 if (!strcasecmp(tag, "f_flags"))
330 fl.f_flags = atoi(tval);
331 if (!strcasecmp(tag, "f_name")) {
332 lprintf(9, "Floor <%s>\n", tval);
333 strcpy(fl.f_name, tval);
335 if (!strcasecmp(tag, "f_ref_count"))
336 fl.f_ref_count = atoi(tval);
339 cdb_store(CDB_FLOORTAB,
340 &floornum, sizeof(int),
341 &fl, sizeof(struct floor) );
345 lprintf(3, "ERROR: invalid floor section.\n");
346 lprintf(3, "Your data files are now corrupt.\n");
355 char key[256], value[256];
356 char tag[256], tval[256];
363 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
364 if (!strcasecmp(key, "room")) {
365 bzero(&qr, sizeof(struct quickroom));
370 while(fpgetfield(imfp, tag),
371 strcasecmp(tag, "endroom")) {
372 if (strcasecmp(tag, "message")) {
373 fpgetfield(imfp, tval);
379 if (!strcasecmp(tag, "qrname")) {
380 strcpy(qr.QRname, tval);
381 lprintf(9, "<%s>", qr.QRname);
383 if (!strcasecmp(tag, "qrpasswd"))
384 strcpy(qr.QRpasswd, tval);
385 if (!strcasecmp(tag, "qrroomaide"))
386 qr.QRroomaide = atol(tval);
387 if (!strcasecmp(tag, "qrhighest"))
388 qr.QRhighest = atol(tval);
389 if (!strcasecmp(tag, "qrgen"))
390 qr.QRgen = atoi(tval);
391 if (!strcasecmp(tag, "qrflags"))
392 qr.QRflags = atoi(tval);
393 if (!strcasecmp(tag, "qrdirname"))
394 strcpy(qr.QRdirname, tval);
395 if (!strcasecmp(tag, "qrinfo"))
396 qr.QRinfo = atol(tval);
397 if (!strcasecmp(tag, "qrfloor"))
398 qr.QRfloor = atoi(tval);
399 if (!strcasecmp(tag, "message")) {
401 fpgetfield(imfp, tval);
403 fpgetfield(imfp, tval);
405 import_message(msgnum, msglen);
407 msglist = realloc(msglist,
408 (sizeof(long)*num_msgs) );
409 msglist[num_msgs - 1] = msgnum;
415 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE))
416 cdb_store(CDB_QUICKROOM,
417 &roomnum, sizeof(int),
418 &qr, sizeof(struct quickroom) );
421 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE))
422 cdb_store(CDB_MSGLISTS, &roomnum, sizeof(int),
423 msglist, (sizeof(long)*num_msgs) );
431 lprintf(3, "ERROR: invalid room section.\n");
432 lprintf(3, "Your data files are now corrupt.\n");
441 void import_databases() {
444 lprintf(9, " ** IMPORTING ** \n");
445 imfp = fopen("/appl/citadel/exported", "rb");
446 while (fpgetfield(imfp, section), strcasecmp(section, "endfile")) {
447 lprintf(9, "Section: <%s>\n", section);
449 if (!strcasecmp(section, "ssv")) imp_ssv();
450 else if (!strcasecmp(section, "config")) imp_config();
451 else if (!strcasecmp(section, "globals")) imp_globals();
452 else if (!strcasecmp(section, "usersupp")) imp_usersupp();
453 else if (!strcasecmp(section, "rooms")) imp_rooms();
454 else if (!strcasecmp(section, "floors")) imp_floors();
456 lprintf(3, "ERROR: invalid import section.\n");
457 lprintf(3, "Your data files are now corrupt.\n");