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, "maxfloors")) {
72 ssv_maxfloors = atol(value);
73 if (ssv_maxfloors > MAXFLOORS) {
74 lprintf(3, "ERROR: maxfloors is %d, need %d\n",
75 ssv_maxfloors, MAXFLOORS);
85 char key[256], value[256];
88 bzero(&config, sizeof(struct config));
89 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
90 fpgetfield(imfp, value);
91 lprintf(9, " %s = %s\n", key, value);
93 if (!strcasecmp(key, "c_nodename"))
94 strcpy(config.c_nodename, value);
95 if (!strcasecmp(key, "c_fqdn"))
96 strcpy(config.c_fqdn, value);
97 if (!strcasecmp(key, "c_humannode"))
98 strcpy(config.c_humannode, value);
99 if (!strcasecmp(key, "c_phonenum"))
100 strcpy(config.c_phonenum, value);
101 if (!strcasecmp(key, "c_phonenum"))
102 strcpy(config.c_phonenum, value);
103 if (!strcasecmp(key, "c_bbsuid"))
104 config.c_bbsuid = atoi(value);
105 if (!strcasecmp(key, "c_creataide"))
106 config.c_creataide = atoi(value);
107 if (!strcasecmp(key, "c_sleeping"))
108 config.c_sleeping = atoi(value);
109 if (!strcasecmp(key, "c_initax"))
110 config.c_initax = atoi(value);
111 if (!strcasecmp(key, "c_regiscall"))
112 config.c_regiscall = atoi(value);
113 if (!strcasecmp(key, "c_twitdetect"))
114 config.c_twitdetect = atoi(value);
115 if (!strcasecmp(key, "c_twitroom"))
116 strcpy(config.c_twitroom, value);
117 if (!strcasecmp(key, "c_defent"))
118 config.c_defent = atoi(value);
119 if (!strcasecmp(key, "c_moreprompt"))
120 strcpy(config.c_moreprompt, value);
121 if (!strcasecmp(key, "c_restrict"))
122 config.c_restrict = atoi(value);
123 if (!strcasecmp(key, "c_bbs_city"))
124 strcpy(config.c_bbs_city, value);
125 if (!strcasecmp(key, "c_sysadm"))
126 strcpy(config.c_sysadm, value);
127 if (!strcasecmp(key, "c_bucket_dir"))
128 strcpy(config.c_bucket_dir, value);
129 if (!strcasecmp(key, "c_setup_level"))
130 config.c_setup_level = atoi(value);
131 if (!strcasecmp(key, "c_maxsessions"))
132 config.c_maxsessions = atoi(value);
133 if (!strcasecmp(key, "c_net_password"))
134 strcpy(config.c_net_password, value);
135 if (!strcasecmp(key, "c_port_number"))
136 config.c_port_number = atoi(value);
139 fp = fopen("citadel.config", "wb");
140 fwrite(&config, sizeof(struct config), 1, fp);
146 char key[256], value[256];
149 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
150 fpgetfield(imfp, value);
151 lprintf(9, " %s = %s\n", key, value);
153 if (!strcasecmp(key, "mmhighest"))
154 CitControl.MMhighest = atol(value);
155 if (!strcasecmp(key, "mmnextuser"))
156 CitControl.MMnextuser = atol(value);
162 void import_message(long msgnum, long msglen) {
166 msgtext = malloc(msglen);
167 if (msgtext == NULL) {
168 lprintf(3, "ERROR: cannot allocate memory\n");
169 lprintf(3, "Your data files are now corrupt.\n");
174 fread(msgtext, msglen, 1, imfp);
175 cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), msgtext, msglen);
179 void import_a_user() {
180 char key[256], value[256], list[256];
189 bzero(&us, sizeof(struct usersupp));
190 while(fpgetfield(imfp, key), strcasecmp(key, "enduser")) {
191 if ((strcasecmp(key, "mail"))
192 &&(strcasecmp(key, "lastseen"))
193 &&(strcasecmp(key, "generation"))
194 &&(strcasecmp(key, "forget")) ) {
195 fpgetfield(imfp, value);
201 if (!strcasecmp(key, "usuid"))
202 us.USuid = atoi(value);
203 if (!strcasecmp(key, "password")) {
204 strcpy(us.password, value);
206 if (!strcasecmp(key, "lastseen"))
207 for (a=0; a<ssv_maxrooms; ++a) {
208 fpgetfield(imfp, list);
209 us.lastseen[a] = atol(list);
211 if (!strcasecmp(key, "generation"))
212 for (a=0; a<ssv_maxrooms; ++a) {
213 fpgetfield(imfp, list);
214 us.generation[a] = atol(list);
216 if (!strcasecmp(key, "forget"))
217 for (a=0; a<ssv_maxrooms; ++a) {
218 fpgetfield(imfp, list);
219 us.forget[a] = atol(list);
221 if (!strcasecmp(key, "flags"))
222 us.flags = atoi(value);
223 if (!strcasecmp(key, "timescalled"))
224 us.timescalled = atoi(value);
225 if (!strcasecmp(key, "posted"))
226 us.posted = atoi(value);
227 if (!strcasecmp(key, "fullname")) {
228 strcpy(us.fullname, value);
229 lprintf(9, "User <%s>", us.fullname);
231 if (!strcasecmp(key, "axlevel"))
232 us.axlevel = atoi(value);
233 if (!strcasecmp(key, "usscreenwidth"))
234 us.USscreenwidth = atoi(value);
235 if (!strcasecmp(key, "usscreenheight"))
236 us.USscreenheight = atoi(value);
237 if (!strcasecmp(key, "usernum"))
238 us.usernum = atol(value);
239 if (!strcasecmp(key, "lastcall"))
240 us.lastcall = atol(value);
241 if (!strcasecmp(key, "usname"))
242 strcpy(us.USname, value);
243 if (!strcasecmp(key, "usaddr"))
244 strcpy(us.USaddr, value);
245 if (!strcasecmp(key, "uscity"))
246 strcpy(us.UScity, value);
247 if (!strcasecmp(key, "usstate"))
248 strcpy(us.USstate, value);
249 if (!strcasecmp(key, "uszip"))
250 strcpy(us.USzip, value);
251 if (!strcasecmp(key, "usphone"))
252 strcpy(us.USphone, value);
253 if (!strcasecmp(key, "usemail"))
254 strcpy(us.USemail, value);
255 if (!strcasecmp(key, "mail")) {
257 fpgetfield(imfp, list);
259 fpgetfield(imfp, list);
261 import_message(msgnum, msglen);
263 mbox = realloc(mbox, (sizeof(long)*mbox_size) );
264 mbox[mbox_size - 1] = msgnum;
268 for (a=0; a<=strlen(us.fullname); ++a) {
269 lcasename[a] = tolower(us.fullname[a]);
271 cdb_store(CDB_USERSUPP,
272 lcasename, strlen(lcasename),
273 &us, sizeof(struct usersupp));
275 cdb_store(CDB_MAILBOXES,
276 &us.usernum, sizeof(long),
277 mbox, (mbox_size * sizeof(long)) );
284 void imp_usersupp() {
285 char key[256], value[256];
287 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
288 if (strcasecmp(key, "user")) {
289 fpgetfield(imfp, value);
294 lprintf(9, " %s = %s\n", key, value);
296 if (!strcasecmp(key, "user")) {
305 char key[256], tag[256], tval[256];
310 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
312 if (!strcasecmp(key, "floor")) {
313 bzero(&fl, sizeof(struct floor));
315 while(fpgetfield(imfp, tag),
316 strcasecmp(tag, "endfloor")) {
317 fpgetfield(imfp, tval);
319 if (!strcasecmp(tag, "f_flags"))
320 fl.f_flags = atoi(tval);
321 if (!strcasecmp(tag, "f_name")) {
322 lprintf(9, "Floor <%s>\n", tval);
323 strcpy(fl.f_name, tval);
325 if (!strcasecmp(tag, "f_ref_count"))
326 fl.f_ref_count = atoi(tval);
329 cdb_store(CDB_FLOORTAB,
330 &floornum, sizeof(int),
331 &fl, sizeof(struct floor) );
335 lprintf(3, "ERROR: invalid floor section.\n");
336 lprintf(3, "Your data files are now corrupt.\n");
345 char key[256], value[256];
346 char tag[256], tval[256];
354 while(fpgetfield(imfp, key), strcasecmp(key, "endsection")) {
355 if (!strcasecmp(key, "room")) {
356 bzero(&qr, sizeof(struct quickroom));
361 while(fpgetfield(imfp, tag),
362 strcasecmp(tag, "endroom")) {
363 if (strcasecmp(tag, "message")) {
364 fpgetfield(imfp, tval);
370 if (!strcasecmp(tag, "qrname")) {
371 strcpy(qr.QRname, tval);
372 lprintf(9, "<%s>", qr.QRname);
374 if (!strcasecmp(tag, "qrpasswd"))
375 strcpy(qr.QRpasswd, tval);
376 if (!strcasecmp(tag, "qrroomaide"))
377 qr.QRroomaide = atol(tval);
378 if (!strcasecmp(tag, "qrhighest"))
379 qr.QRhighest = atol(tval);
380 if (!strcasecmp(tag, "qrgen"))
381 qr.QRgen = atol(tval);
382 if (!strcasecmp(tag, "qrflags"))
383 qr.QRflags = atoi(tval);
384 if (!strcasecmp(tag, "qrdirname"))
385 strcpy(qr.QRdirname, tval);
386 if (!strcasecmp(tag, "qrinfo"))
387 qr.QRinfo = atol(tval);
388 if (!strcasecmp(tag, "qrfloor"))
389 qr.QRfloor = atoi(tval);
390 if (!strcasecmp(tag, "message")) {
392 fpgetfield(imfp, tval);
394 fpgetfield(imfp, tval);
396 import_message(msgnum, msglen);
398 msglist = realloc(msglist,
399 (sizeof(long)*num_msgs) );
400 msglist[num_msgs - 1] = msgnum;
406 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
407 cdb_store(CDB_QUICKROOM,
408 &roomnum, sizeof(int),
409 &qr, sizeof(struct quickroom) );
413 if ((roomnum!=1)&&(qr.QRflags&QR_INUSE)) {
414 cdb_store(CDB_MSGLISTS,
415 &roomnum, sizeof(int),
417 (sizeof(long)*num_msgs) );
426 lprintf(3, "ERROR: invalid room section.\n");
427 lprintf(3, "Your data files are now corrupt.\n");
436 void import_databases() {
439 lprintf(9, " ** IMPORTING ** \n");
440 imfp = fopen("/appl/citadel/exported", "rb");
441 while (fpgetfield(imfp, section), strcasecmp(section, "endfile")) {
442 lprintf(9, "Section: <%s>\n", section);
444 if (!strcasecmp(section, "ssv")) imp_ssv();
445 else if (!strcasecmp(section, "config")) imp_config();
446 else if (!strcasecmp(section, "globals")) imp_globals();
447 else if (!strcasecmp(section, "usersupp")) imp_usersupp();
448 else if (!strcasecmp(section, "rooms")) imp_rooms();
449 else if (!strcasecmp(section, "floors")) imp_floors();
451 lprintf(3, "ERROR: invalid import section.\n");
452 lprintf(3, "Your data files are now corrupt.\n");