From c32db895f6bd7d58f0ad46c796919ceaff3b81bf Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Thu, 6 May 2004 18:41:16 +0000 Subject: [PATCH] Updated mbcico fo new fdb code --- ChangeLog | 2 ++ mbcico/Makefile | 2 +- mbcico/respfreq.c | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index f36d7c64..e4e811ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,8 @@ v0.51.4 11-Apr-2004 must exist in the setup. Added protection against empty domain names received from remote systems. + Added new experimental files database code which will only be + used if configured with --enable-experiment. mbout: In check for T-Mail fileboxes added condition that the zone diff --git a/mbcico/Makefile b/mbcico/Makefile index 40b74acf..7b726319 100644 --- a/mbcico/Makefile +++ b/mbcico/Makefile @@ -110,7 +110,7 @@ opentcp.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ../lib/users.h ../lib/ rdoptions.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ../lib/users.h ../lib/mbsedb.h session.h config.h yoohoo.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ../lib/users.h ../lib/mbsedb.h statetbl.h ttyio.h session.h config.h emsi.h hydra.h rdoptions.h wazoo.h dietifna.h yoohoo.h inbound.h recvbark.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ttyio.h session.h statetbl.h recvbark.h respfreq.h filelist.h -respfreq.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ../lib/msg.h session.h lutil.h config.h atoul.h respfreq.h filelist.h +respfreq.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ../lib/msg.h ../lib/users.h ../lib/mbsedb.h session.h lutil.h config.h atoul.h respfreq.h filelist.h sendbark.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ttyio.h session.h statetbl.h sendbark.h xmrecv.h tcp.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ttyio.h session.h statetbl.h config.h emsi.h respfreq.h filelist.h tcpproto.h tcp.h tcpproto.o: ../config.h ../lib/mbselib.h ../lib/nodelist.h ttyio.h session.h config.h emsi.h lutil.h openfile.h filelist.h tcpproto.h diff --git a/mbcico/respfreq.c b/mbcico/respfreq.c index d861a7a6..134b7a28 100644 --- a/mbcico/respfreq.c +++ b/mbcico/respfreq.c @@ -32,6 +32,8 @@ #include "../lib/mbselib.h" #include "../lib/nodelist.h" #include "../lib/msg.h" +#include "../lib/users.h" +#include "../lib/mbsedb.h" #include "session.h" #include "lutil.h" #include "config.h" @@ -156,9 +158,14 @@ file_list *respfreq(char *nm, char *pw, char *dt) char mask[256], *p, *tnm, *t; time_t upd = 0L; int newer = 1, Send; - FILE *fa, *fb, *fi; + FILE *fa, *fi; long Area; struct FILEIndex idx; +#ifdef USE_EXPERIMENT + struct _fdbarea *fdb_area = NULL; +#else + FILE *fb; +#endif if (localoptions & NOFREQS) { Syslog('+', "File requests disabled"); @@ -259,6 +266,10 @@ file_list *respfreq(char *nm, char *pw, char *dt) return NULL; } Syslog('f', "Area %s", area.Name); +#ifdef USE_EXPERIMENT + if ((fdb_area = mbsedb_OpenFDB(idx.AreaNum, 30)) == 0) { + } else { +#else p = calloc(PATH_MAX, sizeof(char)); sprintf(p, "%s/fdb/file%ld.data", getenv("MBSE_ROOT"), idx.AreaNum); if ((fb = fopen(p, "r+")) == NULL) { @@ -267,10 +278,19 @@ file_list *respfreq(char *nm, char *pw, char *dt) } else { free(p); fread(&fdbhdr, sizeof(fdbhdr), 1, fb); +#endif + +#ifdef USE_EXPERIMENT + if (fseek(fdb_area->fp, fdbhdr.hdrsize + (idx.Record * fdbhdr.recsize), SEEK_SET) == -1) { + WriteError("$Can't seek filerecord %d", idx.Record); + } else { + if (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) != 1) { +#else if (fseek(fb, fdbhdr.hdrsize + (idx.Record * fdbhdr.recsize), SEEK_SET) == -1) { WriteError("$Can't seek filerecord %d", idx.Record); } else { if (fread(&fdb, fdbhdr.recsize, 1, fb) != 1) { +#endif WriteError("$Can't read filerecord %d", idx.Record); } else { Send = FALSE; @@ -347,13 +367,25 @@ file_list *respfreq(char *nm, char *pw, char *dt) */ fdb.TimesDL++; fdb.LastDL = time(NULL); +#ifdef USE_EXPERIMENT + if (mbsedb_LockFDB(fdb_area, 30)) { + fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR); + fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp); + mbsedb_UnlockFDB(fdb_area); + } +#else fseek(fb, - fdbhdr.recsize, SEEK_CUR); fwrite(&fdb, fdbhdr.recsize, 1, fb); +#endif } free(tnm); } } +#ifdef USE_EXPERIMENT + mbsedb_CloseFDB(fdb_area); +#else fclose(fb); +#endif } } }