diff --git a/golded3/geall.h b/golded3/geall.h index d05b29f..a0c747f 100644 --- a/golded3/geall.h +++ b/golded3/geall.h @@ -550,17 +550,17 @@ enum { // The Message Browser struct MLst { - ulong msgno; - byte high; - char num[8]; - char marks[3]; - char by[sizeof(Name)+20]; - char to[sizeof(Name)+20]; - Subj re; - time_t written; - time_t arrived; - time_t received; - char goldmark; + ulong msgno; + byte high; + char num[8]; + char marks[3]; + char by[sizeof(Name)+20]; + char to[sizeof(Name)+20]; + Subj re; + time32_t written; + time32_t arrived; + time32_t received; + char goldmark; }; diff --git a/golded3/geedit.cpp b/golded3/geedit.cpp index 5fe2b7e..a5aaae0 100644 --- a/golded3/geedit.cpp +++ b/golded3/geedit.cpp @@ -2581,7 +2581,7 @@ int IEclass::Start(int __mode, uint* __position, GMsg* __msg) { gotorowcol(mincol, minrow); dispins(); - time_t _lasttime = time(NULL); + time32_t _lasttime = gtime(NULL); while(not done) { @@ -2613,7 +2613,7 @@ int IEclass::Start(int __mode, uint* __position, GMsg* __msg) { #endif if(EDIT->AutoSave()) { - time_t _thistime = time(NULL); + time32_t _thistime = gtime(NULL); if(_thistime >= (_lasttime+EDIT->AutoSave())) { _lasttime = _thistime; SaveFile(); diff --git a/golded3/geinit.cpp b/golded3/geinit.cpp index 3b0191a..9eb956b 100644 --- a/golded3/geinit.cpp +++ b/golded3/geinit.cpp @@ -515,7 +515,7 @@ void Initialize(int argc, char* argv[]) { #if defined(GUTLOS_FUNCS) g_init_os(1); #endif - srand((unsigned)time(NULL)); + srand(gtime(NULL)); // Display startup banner std::cout << __gver_longpid__ << " " << __gver_ver__ << "\n"; diff --git a/golded3/geline.cpp b/golded3/geline.cpp index f11e2ee..3ee8cb9 100644 --- a/golded3/geline.cpp +++ b/golded3/geline.cpp @@ -797,11 +797,11 @@ void KludgeDATE(GMsg* msg, const char* ptr) { t.tm_min = minute; t.tm_sec = second; t.tm_isdst = -1; - time_t a = mktime(&t); + time32_t a = gmktime(&t); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); - msg->written = a + a - b; + tp->tm_isdst = -1; + time32_t b = gmktime(tp); + msg->written = a + a - b; } } diff --git a/golded3/gemlst.cpp b/golded3/gemlst.cpp index f7bff39..030582f 100644 --- a/golded3/gemlst.cpp +++ b/golded3/gemlst.cpp @@ -314,7 +314,7 @@ void GMsgList::print_line(uint idx, uint pos, bool isbar) { char nbuf[33], dbuf[20]; strcpy(dbuf, LNG->n_a); - time_t dt = 0; + time32_t dt = 0; switch(AA->Msglistdate()) { case MSGLISTDATE_WRITTEN: dt = ml->written; break; case MSGLISTDATE_ARRIVED: dt = ml->arrived; break; @@ -896,7 +896,7 @@ void GThreadlist::print_line(uint idx, uint pos, bool isbar) { if(AA->Msglistdate() != MSGLISTDATE_NONE) { char dbuf[11]; - time_t dt = 0; + time32_t dt = 0; memset(dbuf, ' ', 10); dbuf[10] = NUL; diff --git a/golded3/gemsgid.cpp b/golded3/gemsgid.cpp index 1e22923..5fd24f8 100755 --- a/golded3/gemsgid.cpp +++ b/golded3/gemsgid.cpp @@ -34,7 +34,7 @@ static ulong msgcount = 0; ulong getClassicMsgId() { - return time(NULL)+(msgcount++); + return gtime(NULL)+(msgcount++); } // ------------------------------------------------------------------ diff --git a/golded3/gemsgs.cpp b/golded3/gemsgs.cpp index 0532cb6..a2413d8 100644 --- a/golded3/gemsgs.cpp +++ b/golded3/gemsgs.cpp @@ -106,7 +106,7 @@ char* TokenXlat(int mode, char* input, GMsg* msg, GMsg* oldmsg, int __origarea) const char *xmailer = get_informative_string(); const char *osver = ggetosstring(); - time_t t = time(NULL); + time32_t t = gtime(NULL); struct tm* written_tm = glocaltime(&t); char cdate[80]; strftimei(cdate, 80, LNG->DateFmt, written_tm); diff --git a/golded3/gepost.cpp b/golded3/gepost.cpp index 4ac6ca2..46d4fc1 100644 --- a/golded3/gepost.cpp +++ b/golded3/gepost.cpp @@ -243,10 +243,10 @@ static void MakeMsg3(int& mode, GMsg* msg) { // Do Timefields if(msg->attr.fmu()) { - time_t a = time(NULL); + time32_t a = gtime(NULL); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); a += a - b; if(AA->havereceivedstamp()) msg->received = a; @@ -824,10 +824,10 @@ void MakeMsg(int mode, GMsg* omsg, bool ignore_replyto) { dochgdate = false; } if(dochgdate) { - time_t a = time(NULL); + time32_t a = gtime(NULL); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); a += a - b; msg->received = msg->arrived = msg->written = a; } diff --git a/golded3/geqwks.cpp b/golded3/geqwks.cpp index 3649635..a1c95b4 100644 --- a/golded3/geqwks.cpp +++ b/golded3/geqwks.cpp @@ -208,15 +208,15 @@ int ImportQWK() { _tm.tm_min = _minute; _tm.tm_sec = 0; _tm.tm_isdst = -1; - time_t a = mktime(&_tm); + time32_t a = gmktime(&_tm); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); - msg->written = a + a - b; - a = time(NULL); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); + msg->written = a + a - b; + a = gtime(NULL); tp = ggmtime(&a); tp->tm_isdst = -1; - b = mktime(tp); + b = gmktime(tp); msg->arrived = a + a - b; // Read message text diff --git a/golded3/geread.cpp b/golded3/geread.cpp index 0c94bfc..92bb486 100644 --- a/golded3/geread.cpp +++ b/golded3/geread.cpp @@ -1174,10 +1174,10 @@ int LoadMessage(GMsg* msg, int margin) { if(msg->attr.tou()) { reader_rcv_noise = 1; if(not msg->attr.rcv()) { // Have we seen it? - time_t a = time(NULL); + time32_t a = gtime(NULL); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); msg->received = a + a - b; // Get current date msg->attr.rcv1(); // Mark as received reader_rcv_noise++; diff --git a/golded3/gesoup.cpp b/golded3/gesoup.cpp index 7b43343..89409d7 100644 --- a/golded3/gesoup.cpp +++ b/golded3/gesoup.cpp @@ -171,11 +171,11 @@ void ProcessSoupMsg(char* lbuf, GMsg* msg, int& msgs, char* areaname, int tossto msg->orig = msg->oorig = CFG->internetgate.addr.valid() ? CFG->internetgate.addr : AA->aka(); msg->dest = msg->odest = AA->aka(); - time_t a = time(NULL); + time32_t a = gtime(NULL); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); - msg->arrived = a + a - b; + tp->tm_isdst = -1; + time32_t b = gmktime(tp); + msg->arrived = a + a - b; Line* line = NULL; Line* fline = NULL; @@ -697,11 +697,11 @@ int ExportSoupMsg(GMsg* msg, char* msgfile, gfile& fp, int ismail) { msg->attr.snt1(); msg->attr.scn1(); msg->attr.uns0(); - time_t a = time(NULL); + time32_t a = gtime(NULL); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); - msg->arrived = a + a - b; + tp->tm_isdst = -1; + time32_t b = gmktime(tp); + msg->arrived = a + a - b; AA->SaveHdr(GMSG_UPDATE, msg); if(msg->attr.k_s()) AA->DeleteMsg(msg, DIR_NEXT); diff --git a/golded3/geusrbse.cpp b/golded3/geusrbse.cpp index 0501616..fc87ea0 100644 --- a/golded3/geusrbse.cpp +++ b/golded3/geusrbse.cpp @@ -342,7 +342,7 @@ bool guserbase::edit_entry(uint idx) { window.prints(13, 53, wattr, "Times Used:"); char dbuf[16]; - time_t dt = entry.firstdate; + time32_t dt = entry.firstdate; if(dt) window.prints(13, 13, wattr, strftimei(dbuf, 16, "%d %b %y", ggmtime(&dt))); dt = entry.lastdate; @@ -427,10 +427,10 @@ bool guserbase::find_entry(char* name, bool lookup) { void guserbase::write_entry(uint idx, bool updateit) { if(updateit and not entry.is_deleted) { - time_t a = time(NULL); + time32_t a = gtime(NULL); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); entry.lastdate = a + a - b; if(not entry.firstdate) entry.firstdate = entry.lastdate; diff --git a/golded3/geutil.cpp b/golded3/geutil.cpp index 514b058..5366ed6 100644 --- a/golded3/geutil.cpp +++ b/golded3/geutil.cpp @@ -54,7 +54,7 @@ void update_statuslines() { *help = NUL; if(CFG->switches.get(statuslineclock)) { - time_t t = time(NULL); + time32_t t = gtime(NULL); sprintf(clkinfo, " %s", strftimei(help, 40, LNG->StatusLineTimeFmt, glocaltime(&t))); } diff --git a/golded3/geutil2.cpp b/golded3/geutil2.cpp index d67bdae..3d2f279 100644 --- a/golded3/geutil2.cpp +++ b/golded3/geutil2.cpp @@ -267,7 +267,7 @@ void ScreenBlankIdle() { char blankmsg1[80]; char blankmsg2[80]; - time_t t = time(NULL); + time32_t t = gtime(NULL); sprintf(blankmsg1, " %s %s %s ", __gver_longpid__, __gver_ver__, strftimei(blankmsg2, 40, LNG->StatusLineTimeFmt, glocaltime(&t))); sprintf(blankmsg2, " %s ", LNG->BlankMsg); if(strblank(blankmsg2)) { diff --git a/goldlib/gall/gfilutil.h b/goldlib/gall/gfilutil.h index da5300c..7ccfcce 100644 --- a/goldlib/gall/gfilutil.h +++ b/goldlib/gall/gfilutil.h @@ -155,7 +155,7 @@ inline int is_dir(const std::string& path) { return is_dir(path.c_str()); } inline bool fexist(const char* filename) { return *filename ? ((access(filename, R_OK) == 0) and not is_dir(filename)) : false; } inline bool fexist(const std::string& filename) { return fexist(filename.c_str()); } -dword gfixstattime(time_t st_time); +dword gfixstattime(time32_t st_time); dword GetFiletime(const char* file); inline dword GetFiletime(const std::string& file) { return GetFiletime(file.c_str()); } diff --git a/goldlib/gall/gfilutl1.cpp b/goldlib/gall/gfilutl1.cpp index a135125..1cf729b 100644 --- a/goldlib/gall/gfilutl1.cpp +++ b/goldlib/gall/gfilutl1.cpp @@ -96,7 +96,7 @@ long GetFilesize(const char* file) { // ------------------------------------------------------------------ // Convert time returned with stat to FFTime -dword gfixstattime(time_t st_time) { +dword gfixstattime(time32_t st_time) { #if (defined(__MINGW32__) && !defined(__MSVCRT__)) || defined(__CYGWIN__) struct tm &f = *ggmtime(&st_time); diff --git a/goldlib/gall/glog.cpp b/goldlib/gall/glog.cpp index 7a8a78d..78b14f3 100644 --- a/goldlib/gall/glog.cpp +++ b/goldlib/gall/glog.cpp @@ -36,7 +36,7 @@ struct tm* glog::time_now; int glog::count = 0; -time_t glog::secs_now; +time32_t glog::secs_now; char glog::timebuf[20]; @@ -108,7 +108,7 @@ void glog::printf(const char* format, ...) { char buf[256]; char logbuf[256]; - secs_now = time(NULL); + secs_now = gtime(NULL); time_now = glocaltime(&secs_now); lineswritten++; diff --git a/goldlib/gall/glog.h b/goldlib/gall/glog.h index f4feed2..dfbb06a 100644 --- a/goldlib/gall/glog.h +++ b/goldlib/gall/glog.h @@ -61,7 +61,7 @@ private: static int count; static struct tm* time_now; - static time_t secs_now; + static time32_t secs_now; static char timebuf[20]; protected: diff --git a/goldlib/gall/gtimall.h b/goldlib/gall/gtimall.h index 05225e5..522041a 100644 --- a/goldlib/gall/gtimall.h +++ b/goldlib/gall/gtimall.h @@ -123,40 +123,54 @@ extern const char* gmonths[]; // ------------------------------------------------------------------ // Prototypes -inline struct tm *ggmtime(const time_t *timep) +inline struct tm *ggmtime(const time32_t *timep) { + const time_t temp(*timep); #if defined(__WIN32__) const time_t zero(0); - struct tm *time = gmtime(timep); + struct tm *time = gmtime(&temp); return time ? time : gmtime(&zero); #else - return gmtime(&timep); + return gmtime(&temp); #endif } -inline struct tm* glocaltime(const time_t *timep) +inline struct tm *glocaltime(const time32_t *timep) { + const time_t temp(*timep); #if defined(__WIN32__) const time_t zero(0); - struct tm *time = localtime(timep); + struct tm *time = localtime(&temp); return time ? time : localtime(&zero); #else - return localtime(timep); + return localtime(&temp); #endif } -inline struct tm* ggmtime(const time32_t *timep) +inline char *gctime(const time32_t *timep) { const time_t temp(*timep); - return ggmtime(&temp); +#if defined(__WIN32__) + const time_t zero(0); + char *time = ctime(&temp); + return time ? time : ctime(&zero); +#else + return ctime(&temp); +#endif } -inline struct tm* glocaltime(const time32_t *timep) +inline time32_t gtime(time32_t *timep) { - const time_t temp(*timep); - return glocaltime(&temp); + time32_t temp = (time32_t)time(NULL); + return timep ? *timep = temp : temp; } +inline time32_t gmktime(struct tm *timep) +{ + return (time32_t)mktime(timep); +} + + #if defined(__OS2__) inline void usleep(long duration) { DosSleep(duration); } #elif defined(__MINGW32__) || defined(_MSC_VER) @@ -178,13 +192,13 @@ int tzoffset(); char* strftimei(char* s, size_t maxsize, const char* fmt, const struct tm* t); // __attribute__ ((format (strftime, 3, 0))); -FTime TimeToFTime(time_t __time) __attribute__ ((const)); -time_t FTimeToTime(FTime* __ftime, struct tm* __tm=NULL); +FTime TimeToFTime(time32_t __time) __attribute__ ((const)); +time32_t FTimeToTime(FTime* __ftime, struct tm* __tm=NULL); -time_t FidoTimeToUnix(char* __fidotime); +time32_t FidoTimeToUnix(char* __fidotime); char* FTimeToStr(char* buf, FTime &t); -char* TimeToStr(char* buf, time_t t); +char* TimeToStr(char* buf, time32_t t); // ------------------------------------------------------------------ diff --git a/goldlib/gall/gtimutil.cpp b/goldlib/gall/gtimutil.cpp index aca4682..23cf25d 100644 --- a/goldlib/gall/gtimutil.cpp +++ b/goldlib/gall/gtimutil.cpp @@ -60,10 +60,10 @@ const char* gmonths[] = { int tzoffset() { - time_t t1 = time(NULL); + time32_t t1 = gtime(NULL); struct tm *tp = ggmtime(&t1); - tp->tm_isdst=-1; - time_t t2 = mktime(tp); + tp->tm_isdst = -1; + time32_t t2 = gmktime(tp); int dt = (int)(t1 - t2); return (dt / 3600) * 100 + (dt % 3600) / 60; } @@ -329,7 +329,7 @@ int str2mon(const char* ptr) { // ------------------------------------------------------------------ -time_t FTimeToTime(FTime* __ftime, struct tm* __tm) { +time32_t FTimeToTime(FTime* __ftime, struct tm* __tm) { struct tm _tm; ulong _time = 0; @@ -350,10 +350,10 @@ time_t FTimeToTime(FTime* __ftime, struct tm* __tm) { __tm->tm_sec = __ftime->ft_tsec * 2; __tm->tm_isdst = -1; - time_t a = mktime(__tm); + time32_t a = gmktime(__tm); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); _time = a + a - b; if(_time == (ulong)0xFFFFFFFFL) @@ -368,7 +368,7 @@ time_t FTimeToTime(FTime* __ftime, struct tm* __tm) { // ------------------------------------------------------------------ -FTime TimeToFTime(time_t __time) { +FTime TimeToFTime(time32_t __time) { FTime _ft; memset(&_ft, 0, sizeof(FTime)); @@ -390,7 +390,7 @@ FTime TimeToFTime(time_t __time) { // ------------------------------------------------------------------ -time_t FidoTimeToUnix(char* ptr) { +time32_t FidoTimeToUnix(char* ptr) { bool date_ok = false; int year=0, month=0, day=0; @@ -441,10 +441,10 @@ time_t FidoTimeToUnix(char* ptr) { t.tm_min = minute; t.tm_sec = second; t.tm_isdst = -1; - time_t a = mktime(&t); + time32_t a = gmktime(&t); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); return a + a - b; } return (ulong)-1; @@ -453,7 +453,7 @@ time_t FidoTimeToUnix(char* ptr) { // ------------------------------------------------------------------ -char* TimeToStr(char* buf, time_t t) { +char* TimeToStr(char* buf, time32_t t) { return strftimei(buf, 20, "%Y-%m-%d %H:%M:%S", ggmtime(&t)); } diff --git a/goldlib/gcfg/gs_im160.h b/goldlib/gcfg/gs_im160.h index ef851b7..2ae8d32 100644 --- a/goldlib/gcfg/gs_im160.h +++ b/goldlib/gcfg/gs_im160.h @@ -300,9 +300,9 @@ struct areas_record_type { byte days; /* days to keep messages */ word msgs; /* num messages to keep */ struct im_stats stats; /* statistics */ - time_t creation; /* date/time of statistic start */ - time_t update; /* last update by midnight update */ - time_t marked; /* used by kill dead */ + time32_t creation; /* date/time of statistic start */ + time32_t update; /* last update by midnight update */ + time32_t marked; /* used by kill dead */ byte kill_dead; /* kill echos without traffic */ word read_sec; /* Security level for read access */ word write_sec; /* Security level for write access */ diff --git a/goldlib/gcfg/gs_im175.h b/goldlib/gcfg/gs_im175.h index acf797d..e1334c3 100644 --- a/goldlib/gcfg/gs_im175.h +++ b/goldlib/gcfg/gs_im175.h @@ -229,7 +229,7 @@ struct im_config_type { bit ulnk_hudson_passth:1; /* unlinked Hudson areas passth */ bit compr_before_unpack:1; /* compress before unpacking */ bit rsvd3:1; /* reserved */ - time_t last_run; /* last maintenance run */ + time32_t last_run; /* last maintenance run */ word rsvd4; /* reserved */ byte rsvd5; /* reserved */ byte rsvd6; /* reserved */ @@ -322,9 +322,9 @@ struct areas_record_type byte days; /* days to keep messages */ word msgs; /* num messages to keep */ struct im_stats stats; /* statistics */ - time_t creation; /* date/time of statistic start */ - time_t update; /* last update by midnight update */ - time_t marked; /* used by kill dead */ + time32_t creation; /* date/time of statistic start */ + time32_t update; /* last update by midnight update */ + time32_t marked; /* used by kill dead */ byte kill_dead; /* kill echos without traffic */ word read_sec; /* Security level for read access */ word write_sec; /* Security level for write access */ diff --git a/goldlib/gcfg/gs_xbbs.h b/goldlib/gcfg/gs_xbbs.h index 9aad2c2..b506cc0 100644 --- a/goldlib/gcfg/gs_xbbs.h +++ b/goldlib/gcfg/gs_xbbs.h @@ -505,10 +505,10 @@ typedef struct _user_info USHORT computer_type; ULONG userid; USHORT pointid; - time_t initial_logon; - time_t expires; - time_t last_logon; - time_t logon_today; + time32_t initial_logon; + time32_t expires; + time32_t last_logon; + time32_t logon_today; USHORT birthyear; UCHAR birthmonth; UCHAR birthday; @@ -551,8 +551,8 @@ typedef struct _user_info SHORT CallsToday; LONG TotalMinsEver; LONG NetmailDebits; - time_t LastPWChange; - time_t LastListedNewFiles; //JM940822 + time32_t LastPWChange; + time32_t LastListedNewFiles; //JM940822 ULONG FileKCredit; CHAR UnixId[8]; CHAR Country[24]; @@ -591,7 +591,7 @@ typedef struct _xmsg CHAR indate[4]; /* import date (YMD(null)) */ ULONG msgnum; ULONG timesread; - time_t timerecv; + time32_t timerecv; ULONG length; /* Length of message */ LONG start; /* Starting postition in text file */ ULONG OrigMsg; diff --git a/goldlib/gmb3/gmofido3.cpp b/goldlib/gmb3/gmofido3.cpp index 728757e..aec6b98 100644 --- a/goldlib/gmb3/gmofido3.cpp +++ b/goldlib/gmb3/gmofido3.cpp @@ -97,10 +97,10 @@ int FidoArea::load_message(int __mode, gmsg* __msg, FidoHdr& __hdr) { __msg->written = __msg->written ? __msg->written : FidoTimeToUnix(__hdr.datetime); if(__msg->arrived == 0) { - time_t a = time(NULL); + time32_t a = gtime(NULL); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); __msg->arrived = a + a - b; } diff --git a/goldlib/gmb3/gmohuds3.cpp b/goldlib/gmb3/gmohuds3.cpp index 3290611..cbd2e60 100644 --- a/goldlib/gmb3/gmohuds3.cpp +++ b/goldlib/gmb3/gmohuds3.cpp @@ -134,10 +134,10 @@ int _HudsArea::load_message(in _tm.tm_min = _minute; _tm.tm_sec = 0; _tm.tm_isdst = -1; - time_t a = mktime(&_tm); + time32_t a = gmktime(&_tm); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); __msg->written = a + a - b; __msg->arrived = 0; diff --git a/goldlib/gmb3/gmojamm2.cpp b/goldlib/gmb3/gmojamm2.cpp index 49ad126..92c3097 100644 --- a/goldlib/gmb3/gmojamm2.cpp +++ b/goldlib/gmb3/gmojamm2.cpp @@ -152,10 +152,10 @@ void JamArea::open_area() { // Initialize header info memcpy(data->hdrinfo.signature, JAM_SIGNATURE, 4); - time_t a = time(NULL); + time32_t a = gtime(NULL); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); data->hdrinfo.datecreated = a + a - b; data->hdrinfo.passwordcrc = 0xFFFFFFFFL; data->hdrinfo.basemsgnum = 1; diff --git a/goldlib/gmb3/gmopcbd3.cpp b/goldlib/gmb3/gmopcbd3.cpp index 7412480..452ccae 100644 --- a/goldlib/gmb3/gmopcbd3.cpp +++ b/goldlib/gmb3/gmopcbd3.cpp @@ -79,10 +79,10 @@ int PcbArea::load_message(int __mode, gmsg* __msg, PcbHdr& __hdr) { _tm.tm_min = _minute; _tm.tm_sec = 0; _tm.tm_isdst = -1; - time_t a = mktime(&_tm); + time32_t a = gmktime(&_tm); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); __msg->written = a + a - b; __msg->arrived = 0; diff --git a/goldlib/gmb3/gmosmb1.cpp b/goldlib/gmb3/gmosmb1.cpp index 380bf19..1b2086e 100644 --- a/goldlib/gmb3/gmosmb1.cpp +++ b/goldlib/gmb3/gmosmb1.cpp @@ -324,13 +324,13 @@ int SMBArea::load_hdr(gmsg* __msg, smbmsg_t *smsg) __msg->attr.cfm(smsgp->hdr.auxattr & MSG_CONFIRMREQ); __msg->attr.tfs(smsgp->hdr.auxattr & MSG_TRUNCFILE); - time_t a = smsgp->hdr.when_written.time; + time32_t a = smsgp->hdr.when_written.time; struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); __msg->written = a + a - b; a = smsgp->hdr.when_imported.time; - b = mktime(ggmtime(&a)); + b = gmktime(ggmtime(&a)); __msg->arrived = a + a - b; __msg->received = 0; @@ -538,9 +538,9 @@ void SMBArea::save_hdr(int mode, gmsg* msg) smsg.hdr.version = smb_ver(); struct tm *tp = ggmtime(&msg->written); tp->tm_isdst = -1; - smsg.hdr.when_written.time = mktime(tp); + smsg.hdr.when_written.time = gmktime(tp); } - smsg.hdr.when_imported.time = time(NULL); + smsg.hdr.when_imported.time = gtime(NULL); // Transfer attributes if(msg->attr.pvt()) smsg.hdr.attr |= MSG_PRIVATE; @@ -968,9 +968,9 @@ Line* SMBArea::make_dump_msg(Line*& lin, gmsg* msg, char* lng_head) line = AddLineF(line, "Attr : %04Xh", smsg.hdr.attr); line = AddLineF(line, "AUXAttr : %04Xh", smsg.hdr.auxattr); line = AddLineF(line, "NetAttr : %04Xh", smsg.hdr.netattr); - stpcpy(buf, ctime((time_t *)&smsg.hdr.when_written.time))[-1] = NUL; + stpcpy(buf, gctime(&smsg.hdr.when_written.time))[-1] = NUL; line = AddLineF(line, "Written : %s", buf); - stpcpy(buf, ctime((time_t *)&smsg.hdr.when_imported.time))[-1] = NUL; + stpcpy(buf, gctime(&smsg.hdr.when_imported.time))[-1] = NUL; line = AddLineF(line, "Imported : %s", buf); line = AddLineF(line, "Number : %d (%d)", smsg.hdr.number, (int32_t)(ftell(data->sid_fp)/sizeof(idxrec_t))); line = AddLineF(line, "Thread orig : %d", smsg.hdr.thread_orig); diff --git a/goldlib/gmb3/gmosqsh3.cpp b/goldlib/gmb3/gmosqsh3.cpp index ab3a269..00116be 100644 --- a/goldlib/gmb3/gmosqsh3.cpp +++ b/goldlib/gmb3/gmosqsh3.cpp @@ -128,7 +128,7 @@ int SquishArea::load_message(int __mode, gmsg* __msg, SqshHdr& __hdr) { __msg->dest.point = __msg->odest.point = __hdr.dest.point; // Convert date and time - time_t _written = FTimeToTime(&__hdr.date_written); + time32_t _written = FTimeToTime(&__hdr.date_written); __msg->written = _written ? _written : FidoTimeToUnix(__hdr.ftsc_date); __msg->arrived = FTimeToTime(&__hdr.date_arrived); diff --git a/goldlib/gmb3/gmowcat3.cpp b/goldlib/gmb3/gmowcat3.cpp index 1e5cc9e..8895810 100644 --- a/goldlib/gmb3/gmowcat3.cpp +++ b/goldlib/gmb3/gmowcat3.cpp @@ -103,10 +103,10 @@ int WCatArea::load_message(int __mode, gmsg* __msg, WCatHdr& __hdr) { _tm.tm_min = _minute; _tm.tm_sec = _second; _tm.tm_isdst = -1; - time_t a = mktime(&_tm); + time32_t a = gmktime(&_tm); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); __msg->written = a + a - b; } @@ -123,10 +123,10 @@ int WCatArea::load_message(int __mode, gmsg* __msg, WCatHdr& __hdr) { _tm.tm_min = _minute; _tm.tm_sec = _second; _tm.tm_isdst = -1; - time_t a = mktime(&_tm); + time32_t a = gmktime(&_tm); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); __msg->received = a + a - b; } diff --git a/goldlib/gmb3/gmoxbbs3.cpp b/goldlib/gmb3/gmoxbbs3.cpp index 981e581..3c52551 100644 --- a/goldlib/gmb3/gmoxbbs3.cpp +++ b/goldlib/gmb3/gmoxbbs3.cpp @@ -72,10 +72,10 @@ int XbbsArea::load_message(int __mode, gmsg* __msg, XbbsHdr& __hdr) { t.tm_mday = __hdr.indate[2]; t.tm_hour = t.tm_min = t.tm_sec = 0; t.tm_isdst = -1; - time_t a = mktime(&t); + time32_t a = gmktime(&t); struct tm *tp = ggmtime(&a); - tp->tm_isdst = -1; - time_t b = mktime(tp); + tp->tm_isdst = -1; + time32_t b = gmktime(tp); __msg->arrived = a + a - b; } diff --git a/goldlib/smblib/smbdefs.h b/goldlib/smblib/smbdefs.h index acc09d1..93d11db 100644 --- a/goldlib/smblib/smbdefs.h +++ b/goldlib/smblib/smbdefs.h @@ -82,6 +82,7 @@ typedef int16_t sshort; typedef uint16_t ushort; typedef uint32_t dword; +typedef uint32_t time32_t; /* 32-bit time_t type */ #endif //#ifndef __goldall_h diff --git a/goldlib/smblib/smblib.c b/goldlib/smblib/smblib.c index bf3dc92..64f55cf 100644 --- a/goldlib/smblib/smblib.c +++ b/goldlib/smblib/smblib.c @@ -5,52 +5,52 @@ /* $Id$ */ /**************************************************************************** - * @format.tab-size 4 (Plain Text/Source Code File Header) * - * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * - * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * See the GNU Lesser General Public License for more details: lgpl.txt or * - * http://www.fsf.org/copyleft/lesser.html * - * * - * Anonymous FTP access to the most recent released source is available at * - * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * - * * - * Anonymous CVS access to the development source and modification history * - * is available at cvs.synchro.net:/cvsroot/sbbs, example: * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login * - * (just hit return, no password is necessary) * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src * - * * - * For Synchronet coding style and modification guidelines, see * - * http://www.synchro.net/source.html * - * * - * You are encouraged to submit any modifications (preferably in Unix diff * - * format) via e-mail to mods@synchro.net * - * * - * Note: If this box doesn't appear square, then you need to fix your tabs. * + * @format.tab-size 4 (Plain Text/Source Code File Header) * + * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * + * * + * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 2 * + * of the License, or (at your option) any later version. * + * See the GNU Lesser General Public License for more details: lgpl.txt or * + * http://www.fsf.org/copyleft/lesser.html * + * * + * Anonymous FTP access to the most recent released source is available at * + * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * + * * + * Anonymous CVS access to the development source and modification history * + * is available at cvs.synchro.net:/cvsroot/sbbs, example: * + * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login * + * (just hit return, no password is necessary) * + * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src * + * * + * For Synchronet coding style and modification guidelines, see * + * http://www.synchro.net/source.html * + * * + * You are encouraged to submit any modifications (preferably in Unix diff * + * format) via e-mail to mods@synchro.net * + * * + * Note: If this box doesn't appear square, then you need to fix your tabs. * ****************************************************************************/ #if defined __WATCOMC__ || defined __TURBOC__ - #include + #include #else - #include + #include #endif #ifdef __WATCOMC__ - #include + #include #elif defined __TURBOC__ - #include + #include #endif /* ANSI C Library headers */ #ifndef __FreeBSD__ - #include + #include #endif #include @@ -68,18 +68,26 @@ #include "filewrap.h" /* Use smb_ver() and smb_lib_ver() to obtain these values */ -#define SMBLIB_VERSION "2.16" /* SMB library version */ -#define SMB_VERSION 0x0121 /* SMB format version */ - /* High byte major, low byte minor */ +#define SMBLIB_VERSION "2.16" /* SMB library version */ +#define SMB_VERSION 0x0121 /* SMB format version */ + /* High byte major, low byte minor */ + +#ifndef __gtimall_h +time32_t gtime(time32_t *timep) +{ + time32_t temp = (time32_t)time(NULL); + return timep ? *timep = temp : temp; +} +#endif //#ifndef __gtimall_h int SMBCALL smb_ver(void) { - return(SMB_VERSION); + return(SMB_VERSION); } char* SMBCALL smb_lib_ver(void) { - return(SMBLIB_VERSION); + return(SMBLIB_VERSION); } /****************************************************************************/ @@ -90,287 +98,287 @@ int SMBCALL smb_open(smb_t* smb) { int file; char str[128]; - smbhdr_t hdr; + smbhdr_t hdr; - /* Set default values, if uninitialized */ - if(!smb->retry_time) - smb->retry_time=10; /* seconds */ - if(!smb->retry_delay - || smb->retry_delay>(smb->retry_time*100)) /* at least ten retries */ - smb->retry_delay=250; /* milliseconds */ - smb->shd_fp=smb->sdt_fp=smb->sid_fp=NULL; - smb->last_error[0]=0; - sprintf(str,"%s.shd",smb->file); - if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO))==-1) { - sprintf(smb->last_error,"%d opening %s",errno,str); - return(2); - } + /* Set default values, if uninitialized */ + if(!smb->retry_time) + smb->retry_time=10; /* seconds */ + if(!smb->retry_delay + || smb->retry_delay>(smb->retry_time*100)) /* at least ten retries */ + smb->retry_delay=250; /* milliseconds */ + smb->shd_fp=smb->sdt_fp=smb->sid_fp=NULL; + smb->last_error[0]=0; + sprintf(str,"%s.shd",smb->file); + if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO))==-1) { + sprintf(smb->last_error,"%d opening %s",errno,str); + return(2); + } - if((smb->shd_fp=fdopen(file,"r+b"))==NULL) { - sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); - close(file); - return(4); - } + if((smb->shd_fp=fdopen(file,"r+b"))==NULL) { + sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); + close(file); + return(4); + } - if(filelength(file)>=sizeof(smbhdr_t)) { - setvbuf(smb->shd_fp,smb->shd_buf,_IONBF,SHD_BLOCK_LEN); - if(smb_locksmbhdr(smb)!=0) { - smb_close(smb); - /* smb_lockmsghdr set last_error */ - return(-1); - } - memset(&hdr,0,sizeof(smbhdr_t)); - if(fread(&hdr,sizeof(smbhdr_t),1,smb->shd_fp)!=1) { - sprintf(smb->last_error,"reading header"); - smb_close(smb); - return(-10); - } - if(memcmp(hdr.id,SMB_HEADER_ID,LEN_HEADER_ID)) { - sprintf(smb->last_error,"corrupt SMB header ID: %.*s",LEN_HEADER_ID,hdr.id); - smb_close(smb); - return(-2); - } - if(hdr.version<0x110) { /* Compatibility check */ - sprintf(smb->last_error,"insufficient header version: %X",hdr.version); - smb_close(smb); - return(-3); - } - if(fread(&(smb->status),1,sizeof(smbstatus_t),smb->shd_fp) - !=sizeof(smbstatus_t)) { - sprintf(smb->last_error,"failed to read status"); - smb_close(smb); - return(-4); - } - smb_unlocksmbhdr(smb); - rewind(smb->shd_fp); - } + if(filelength(file)>=sizeof(smbhdr_t)) { + setvbuf(smb->shd_fp,smb->shd_buf,_IONBF,SHD_BLOCK_LEN); + if(smb_locksmbhdr(smb)!=0) { + smb_close(smb); + /* smb_lockmsghdr set last_error */ + return(-1); + } + memset(&hdr,0,sizeof(smbhdr_t)); + if(fread(&hdr,sizeof(smbhdr_t),1,smb->shd_fp)!=1) { + sprintf(smb->last_error,"reading header"); + smb_close(smb); + return(-10); + } + if(memcmp(hdr.id,SMB_HEADER_ID,LEN_HEADER_ID)) { + sprintf(smb->last_error,"corrupt SMB header ID: %.*s",LEN_HEADER_ID,hdr.id); + smb_close(smb); + return(-2); + } + if(hdr.version<0x110) { /* Compatibility check */ + sprintf(smb->last_error,"insufficient header version: %X",hdr.version); + smb_close(smb); + return(-3); + } + if(fread(&(smb->status),1,sizeof(smbstatus_t),smb->shd_fp) + !=sizeof(smbstatus_t)) { + sprintf(smb->last_error,"failed to read status"); + smb_close(smb); + return(-4); + } + smb_unlocksmbhdr(smb); + rewind(smb->shd_fp); + } - setvbuf(smb->shd_fp,smb->shd_buf,_IOFBF,SHD_BLOCK_LEN); + setvbuf(smb->shd_fp,smb->shd_buf,_IOFBF,SHD_BLOCK_LEN); - sprintf(str,"%s.sdt",smb->file); - if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO))==-1) { - sprintf(smb->last_error,"%d opening %s",errno,str); - smb_close(smb); - return(1); - } + sprintf(str,"%s.sdt",smb->file); + if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO))==-1) { + sprintf(smb->last_error,"%d opening %s",errno,str); + smb_close(smb); + return(1); + } - if((smb->sdt_fp=fdopen(file,"r+b"))==NULL) { - sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); - close(file); - smb_close(smb); - return(5); - } + if((smb->sdt_fp=fdopen(file,"r+b"))==NULL) { + sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); + close(file); + smb_close(smb); + return(5); + } - setvbuf(smb->sdt_fp,NULL,_IOFBF,2*1024); + setvbuf(smb->sdt_fp,NULL,_IOFBF,2*1024); - sprintf(str,"%s.sid",smb->file); - if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO))==-1) { - sprintf(smb->last_error,"%d opening %s",errno,str); - smb_close(smb); - return(3); - } + sprintf(str,"%s.sid",smb->file); + if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYNO))==-1) { + sprintf(smb->last_error,"%d opening %s",errno,str); + smb_close(smb); + return(3); + } - if((smb->sid_fp=fdopen(file,"r+b"))==NULL) { - sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); - close(file); - smb_close(smb); - return(6); - } + if((smb->sid_fp=fdopen(file,"r+b"))==NULL) { + sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); + close(file); + smb_close(smb); + return(6); + } - setvbuf(smb->sid_fp,NULL,_IOFBF,2*1024); + setvbuf(smb->sid_fp,NULL,_IOFBF,2*1024); - return(0); + return(0); } /****************************************************************************/ -/* Closes the currently open message base */ +/* Closes the currently open message base */ /****************************************************************************/ void SMBCALL smb_close(smb_t* smb) { - if(smb->shd_fp!=NULL) { - smb_unlocksmbhdr(smb); /* In case it's been locked */ - fclose(smb->shd_fp); - } - if(smb->sid_fp!=NULL) - fclose(smb->sid_fp); - if(smb->sdt_fp!=NULL) - fclose(smb->sdt_fp); - smb->sid_fp=smb->shd_fp=smb->sdt_fp=NULL; + if(smb->shd_fp!=NULL) { + smb_unlocksmbhdr(smb); /* In case it's been locked */ + fclose(smb->shd_fp); + } + if(smb->sid_fp!=NULL) + fclose(smb->sid_fp); + if(smb->sdt_fp!=NULL) + fclose(smb->sdt_fp); + smb->sid_fp=smb->shd_fp=smb->sdt_fp=NULL; } /****************************************************************************/ /* Opens the data block allocation table message base 'smb->file' */ -/* Retrys for retry_time number of seconds */ -/* Return 0 on success, non-zero otherwise */ +/* Retrys for retry_time number of seconds */ +/* Return 0 on success, non-zero otherwise */ /****************************************************************************/ int SMBCALL smb_open_da(smb_t* smb) { - int file; - char str[128]; - time_t start=0; + int file; + char str[128]; + time32_t start = 0; - sprintf(str,"%s.sda",smb->file); - while(1) { - if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYRW))!=-1) - break; - if(errno!=EACCES && errno!=EAGAIN) { - sprintf(smb->last_error,"%d opening %s",errno,str); - return(-1); - } - if(!start) - start=time(NULL); - else - if(time(NULL)-start>=(time_t)smb->retry_time) { - sprintf(smb->last_error,"timeout opening %s (retry_time=%d)" - ,str,smb->retry_time); - return(-2); - } - SLEEP(smb->retry_delay); - } - if((smb->sda_fp=fdopen(file,"r+b"))==NULL) { - sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); - close(file); - return(-3); - } - setvbuf(smb->sda_fp,NULL,_IOFBF,2*1024); - return(0); + sprintf(str,"%s.sda",smb->file); + while(1) { + if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYRW))!=-1) + break; + if(errno!=EACCES && errno!=EAGAIN) { + sprintf(smb->last_error,"%d opening %s",errno,str); + return(-1); + } + if(!start) + start = gtime(NULL); + else + if(gtime(NULL)-start >= smb->retry_time) { + sprintf(smb->last_error,"timeout opening %s (retry_time=%d)" + ,str,smb->retry_time); + return(-2); + } + SLEEP(smb->retry_delay); + } + if((smb->sda_fp=fdopen(file,"r+b"))==NULL) { + sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); + close(file); + return(-3); + } + setvbuf(smb->sda_fp,NULL,_IOFBF,2*1024); + return(0); } void SMBCALL smb_close_da(smb_t* smb) { - if(smb->sda_fp!=NULL) - fclose(smb->sda_fp); - smb->sda_fp=NULL; + if(smb->sda_fp!=NULL) + fclose(smb->sda_fp); + smb->sda_fp=NULL; } /****************************************************************************/ /* Opens the header block allocation table for message base 'smb.file' */ -/* Retrys for smb.retry_time number of seconds */ -/* Return 0 on success, non-zero otherwise */ +/* Retrys for smb.retry_time number of seconds */ +/* Return 0 on success, non-zero otherwise */ /****************************************************************************/ int SMBCALL smb_open_ha(smb_t* smb) { - int file; - char str[128]; - time_t start=0; + int file; + char str[128]; + time32_t start = 0; - sprintf(str,"%s.sha",smb->file); - while(1) { - if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYRW))!=-1) - break; - if(errno!=EACCES && errno!=EAGAIN) { - sprintf(smb->last_error,"%d opening %s",errno,str); - return(-1); - } - if(!start) - start=time(NULL); - else - if(time(NULL)-start>=(time_t)smb->retry_time) { - sprintf(smb->last_error,"timeout opening %s (retry_time=%d)" - ,str,smb->retry_time); - return(-2); - } - SLEEP(smb->retry_delay); - } - if((smb->sha_fp=fdopen(file,"r+b"))==NULL) { - sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); - close(file); - return(-3); - } - setvbuf(smb->sha_fp,NULL,_IOFBF,2*1024); - return(0); + sprintf(str,"%s.sha",smb->file); + while(1) { + if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYRW))!=-1) + break; + if(errno!=EACCES && errno!=EAGAIN) { + sprintf(smb->last_error,"%d opening %s",errno,str); + return(-1); + } + if(!start) + start = gtime(NULL); + else + if(gtime(NULL)-start >= smb->retry_time) { + sprintf(smb->last_error,"timeout opening %s (retry_time=%d)" + ,str,smb->retry_time); + return(-2); + } + SLEEP(smb->retry_delay); + } + if((smb->sha_fp=fdopen(file,"r+b"))==NULL) { + sprintf(smb->last_error,"%d fdopening %s (%d)",errno,str,file); + close(file); + return(-3); + } + setvbuf(smb->sha_fp,NULL,_IOFBF,2*1024); + return(0); } void SMBCALL smb_close_ha(smb_t* smb) { - if(smb->sha_fp!=NULL) - fclose(smb->sha_fp); - smb->sha_fp=NULL; + if(smb->sha_fp!=NULL) + fclose(smb->sha_fp); + smb->sha_fp=NULL; } /****************************************************************************/ /* If the parameter 'push' is non-zero, this function stores the currently */ /* open message base to the "virtual" smb stack. Up to SMB_STACK_LEN */ -/* message bases may be stored (defined in SMBDEFS.H). */ +/* message bases may be stored (defined in SMBDEFS.H). */ /* The parameter 'op' is the operation to perform on the stack. Either */ -/* SMB_STACK_PUSH, SMB_STACK_POP, or SMB_STACK_XCHNG */ +/* SMB_STACK_PUSH, SMB_STACK_POP, or SMB_STACK_XCHNG */ /* If the operation is SMB_STACK_POP, this function restores a message base */ -/* previously saved with a SMB_STACK_PUSH call to this same function. */ -/* If the operation is SMB_STACK_XCHNG, then the current message base is */ -/* exchanged with the message base on the top of the stack (most recently */ -/* pushed. */ -/* If the current message base is not open, the SMB_STACK_PUSH and */ -/* SMB_STACK_XCHNG operations do nothing */ +/* previously saved with a SMB_STACK_PUSH call to this same function. */ +/* If the operation is SMB_STACK_XCHNG, then the current message base is */ +/* exchanged with the message base on the top of the stack (most recently */ +/* pushed. */ +/* If the current message base is not open, the SMB_STACK_PUSH and */ +/* SMB_STACK_XCHNG operations do nothing */ /* Returns 0 on success, non-zero if stack full. */ -/* If operation is SMB_STACK_POP or SMB_STACK_XCHNG, it always returns 0. */ +/* If operation is SMB_STACK_POP or SMB_STACK_XCHNG, it always returns 0. */ /****************************************************************************/ int SMBCALL smb_stack(smb_t* smb, int op) { - static smb_t stack[SMB_STACK_LEN]; - static int stack_idx; - smb_t tmp_smb; + static smb_t stack[SMB_STACK_LEN]; + static int stack_idx; + smb_t tmp_smb; - if(op==SMB_STACK_PUSH) { - if(stack_idx>=SMB_STACK_LEN) { - sprintf(smb->last_error,"SMB stack overflow"); - return(1); - } - if(smb->shd_fp==NULL || smb->sdt_fp==NULL || smb->sid_fp==NULL) - return(0); /* Msg base not open */ - memcpy(&stack[stack_idx],smb,sizeof(smb_t)); - stack_idx++; - return(0); - } - /* pop or xchng */ - if(!stack_idx) /* Nothing on the stack, so do nothing */ - return(0); - if(op==SMB_STACK_XCHNG) { - if(smb->shd_fp==NULL) - return(0); - memcpy(&tmp_smb,smb,sizeof(smb_t)); - } + if(op==SMB_STACK_PUSH) { + if(stack_idx>=SMB_STACK_LEN) { + sprintf(smb->last_error,"SMB stack overflow"); + return(1); + } + if(smb->shd_fp==NULL || smb->sdt_fp==NULL || smb->sid_fp==NULL) + return(0); /* Msg base not open */ + memcpy(&stack[stack_idx],smb,sizeof(smb_t)); + stack_idx++; + return(0); + } + /* pop or xchng */ + if(!stack_idx) /* Nothing on the stack, so do nothing */ + return(0); + if(op==SMB_STACK_XCHNG) { + if(smb->shd_fp==NULL) + return(0); + memcpy(&tmp_smb,smb,sizeof(smb_t)); + } - stack_idx--; - memcpy(smb,&stack[stack_idx],sizeof(smb_t)); - if(op==SMB_STACK_XCHNG) { - memcpy(&stack[stack_idx],&tmp_smb,sizeof(smb_t)); - stack_idx++; - } - return(0); + stack_idx--; + memcpy(smb,&stack[stack_idx],sizeof(smb_t)); + if(op==SMB_STACK_XCHNG) { + memcpy(&stack[stack_idx],&tmp_smb,sizeof(smb_t)); + stack_idx++; + } + return(0); } /****************************************************************************/ -/* Truncates header file */ -/* Retrys for smb.retry_time number of seconds */ -/* Return 0 on success, non-zero otherwise */ +/* Truncates header file */ +/* Retrys for smb.retry_time number of seconds */ +/* Return 0 on success, non-zero otherwise */ /****************************************************************************/ int SMBCALL smb_trunchdr(smb_t* smb) { - time_t start=0; + time32_t start = 0; - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - rewind(smb->shd_fp); - while(1) { - if(!chsize(fileno(smb->shd_fp),0L)) - break; - if(errno!=EACCES && errno!=EAGAIN) { - sprintf(smb->last_error,"%d changing header file size",errno); - return(-1); - } - if(!start) - start=time(NULL); - else - if(time(NULL)-start>=(time_t)smb->retry_time) { /* Time-out */ - sprintf(smb->last_error,"timeout changing header file size (retry_time=%d)" - ,smb->retry_time); - return(-2); - } - SLEEP(smb->retry_delay); - } - return(0); + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + rewind(smb->shd_fp); + while(1) { + if(!chsize(fileno(smb->shd_fp),0L)) + break; + if(errno!=EACCES && errno!=EAGAIN) { + sprintf(smb->last_error,"%d changing header file size",errno); + return(-1); + } + if(!start) + start = gtime(NULL); + else + if(gtime(NULL)-start >= smb->retry_time) { /* Time-out */ + sprintf(smb->last_error,"timeout changing header file size (retry_time=%d)" + ,smb->retry_time); + return(-2); + } + SLEEP(smb->retry_delay); + } + return(0); } /*********************************/ @@ -378,93 +386,93 @@ int SMBCALL smb_trunchdr(smb_t* smb) /*********************************/ /****************************************************************************/ -/* Attempts for smb.retry_time number of seconds to lock the msg base hdr */ +/* Attempts for smb.retry_time number of seconds to lock the msg base hdr */ /****************************************************************************/ int SMBCALL smb_locksmbhdr(smb_t* smb) { - time_t start=0; + time32_t start = 0; - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - while(1) { - if(lock(fileno(smb->shd_fp),0L,sizeof(smbhdr_t)+sizeof(smbstatus_t))==0) { - smb->locked=1; /* TRUE */ - return(0); - } - if(!start) - start=time(NULL); - else - if(time(NULL)-start>=(time_t)smb->retry_time) - break; - /* In case we've already locked it */ - if(unlock(fileno(smb->shd_fp),0L,sizeof(smbhdr_t)+sizeof(smbstatus_t))==0) - smb->locked=0; /* FALSE */ - SLEEP(smb->retry_delay); - } - sprintf(smb->last_error,"timeout locking header"); - return(-1); + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + while(1) { + if(lock(fileno(smb->shd_fp),0L,sizeof(smbhdr_t)+sizeof(smbstatus_t))==0) { + smb->locked=1; /* TRUE */ + return(0); + } + if(!start) + start = gtime(NULL); + else + if(gtime(NULL)-start >= smb->retry_time) + break; + /* In case we've already locked it */ + if(unlock(fileno(smb->shd_fp),0L,sizeof(smbhdr_t)+sizeof(smbstatus_t))==0) + smb->locked=0; /* FALSE */ + SLEEP(smb->retry_delay); + } + sprintf(smb->last_error,"timeout locking header"); + return(-1); } /****************************************************************************/ -/* Read the SMB header from the header file and place into smb.status */ +/* Read the SMB header from the header file and place into smb.status */ /****************************************************************************/ int SMBCALL smb_getstatus(smb_t* smb) { - int i; + int i; - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - setvbuf(smb->shd_fp,smb->shd_buf,_IONBF,SHD_BLOCK_LEN); - clearerr(smb->shd_fp); - fseek(smb->shd_fp,sizeof(smbhdr_t),SEEK_SET); - i=fread(&(smb->status),1,sizeof(smbstatus_t),smb->shd_fp); - setvbuf(smb->shd_fp,smb->shd_buf,_IOFBF,SHD_BLOCK_LEN); - if(i==sizeof(smbstatus_t)) - return(0); - sprintf(smb->last_error,"read %d instead of %d",i,(int)sizeof(smbstatus_t)); - return(1); + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + setvbuf(smb->shd_fp,smb->shd_buf,_IONBF,SHD_BLOCK_LEN); + clearerr(smb->shd_fp); + fseek(smb->shd_fp,sizeof(smbhdr_t),SEEK_SET); + i=fread(&(smb->status),1,sizeof(smbstatus_t),smb->shd_fp); + setvbuf(smb->shd_fp,smb->shd_buf,_IOFBF,SHD_BLOCK_LEN); + if(i==sizeof(smbstatus_t)) + return(0); + sprintf(smb->last_error,"read %d instead of %d",i,(int)sizeof(smbstatus_t)); + return(1); } /****************************************************************************/ -/* Writes message base header */ +/* Writes message base header */ /****************************************************************************/ int SMBCALL smb_putstatus(smb_t* smb) { - int i; + int i; - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - clearerr(smb->shd_fp); - fseek(smb->shd_fp,sizeof(smbhdr_t),SEEK_SET); - i=fwrite(&(smb->status),1,sizeof(smbstatus_t),smb->shd_fp); - fflush(smb->shd_fp); - if(i==sizeof(smbstatus_t)) - return(0); - sprintf(smb->last_error,"wrote %d instead of %d",i,(int)sizeof(smbstatus_t)); - return(1); + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + clearerr(smb->shd_fp); + fseek(smb->shd_fp,sizeof(smbhdr_t),SEEK_SET); + i=fwrite(&(smb->status),1,sizeof(smbstatus_t),smb->shd_fp); + fflush(smb->shd_fp); + if(i==sizeof(smbstatus_t)) + return(0); + sprintf(smb->last_error,"wrote %d instead of %d",i,(int)sizeof(smbstatus_t)); + return(1); } /****************************************************************************/ -/* Unlocks previously locks message base header */ +/* Unlocks previously locks message base header */ /****************************************************************************/ int SMBCALL smb_unlocksmbhdr(smb_t* smb) { - int result; + int result; - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - result = unlock(fileno(smb->shd_fp),0L,sizeof(smbhdr_t)+sizeof(smbstatus_t)); - if(result==0) - smb->locked=0; /* FALSE */ - return(result); + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + result = unlock(fileno(smb->shd_fp),0L,sizeof(smbhdr_t)+sizeof(smbstatus_t)); + if(result==0) + smb->locked=0; /* FALSE */ + return(result); } /********************************/ @@ -476,370 +484,370 @@ int SMBCALL smb_unlocksmbhdr(smb_t* smb) /****************************************************************************/ int SMBCALL smb_lockmsghdr(smb_t* smb, smbmsg_t* msg) { - time_t start=0; + time32_t start = 0; - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - while(1) { - if(!lock(fileno(smb->shd_fp),msg->idx.offset,sizeof(msghdr_t))) - return(0); - if(!start) - start=time(NULL); - else - if(time(NULL)-start>=(time_t)smb->retry_time) - break; - /* In case we've already locked it */ - unlock(fileno(smb->shd_fp),msg->idx.offset,sizeof(msghdr_t)); - SLEEP(smb->retry_delay); - } - sprintf(smb->last_error,"timeout locking header"); - return(-1); + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + while(1) { + if(!lock(fileno(smb->shd_fp),msg->idx.offset,sizeof(msghdr_t))) + return(0); + if(!start) + start = gtime(NULL); + else + if(gtime(NULL)-start >= smb->retry_time) + break; + /* In case we've already locked it */ + unlock(fileno(smb->shd_fp),msg->idx.offset,sizeof(msghdr_t)); + SLEEP(smb->retry_delay); + } + sprintf(smb->last_error,"timeout locking header"); + return(-1); } /****************************************************************************/ -/* Fills msg->idx with message index based on msg->hdr.number */ -/* OR if msg->hdr.number is 0, based on msg->offset (record offset). */ -/* if msg.hdr.number does not equal 0, then msg->offset is filled too. */ -/* Either msg->hdr.number or msg->offset must be initialized before */ -/* calling this function */ +/* Fills msg->idx with message index based on msg->hdr.number */ +/* OR if msg->hdr.number is 0, based on msg->offset (record offset). */ +/* if msg.hdr.number does not equal 0, then msg->offset is filled too. */ +/* Either msg->hdr.number or msg->offset must be initialized before */ +/* calling this function */ /* Returns 1 if message number wasn't found, 0 if it was */ /****************************************************************************/ int SMBCALL smb_getmsgidx(smb_t* smb, smbmsg_t* msg) { - idxrec_t idx; - uint32_t l,length,total,bot,top; + idxrec_t idx; + uint32_t l,length,total,bot,top; - if(smb->sid_fp==NULL) { - sprintf(smb->last_error,"index not open"); - return(SMB_ERR_NOT_OPEN); - } - clearerr(smb->sid_fp); - if(!msg->hdr.number) { - fseek(smb->sid_fp,msg->offset*sizeof(idxrec_t),SEEK_SET); - if(!fread(&msg->idx,sizeof(idxrec_t),1,smb->sid_fp)) { - sprintf(smb->last_error,"reading index"); - return(1); - } - return(0); - } + if(smb->sid_fp==NULL) { + sprintf(smb->last_error,"index not open"); + return(SMB_ERR_NOT_OPEN); + } + clearerr(smb->sid_fp); + if(!msg->hdr.number) { + fseek(smb->sid_fp,msg->offset*sizeof(idxrec_t),SEEK_SET); + if(!fread(&msg->idx,sizeof(idxrec_t),1,smb->sid_fp)) { + sprintf(smb->last_error,"reading index"); + return(1); + } + return(0); + } - length=filelength(fileno(smb->sid_fp)); - if(!length) { - sprintf(smb->last_error,"invalid index file length: %d",length); - return(1); - } - total=length/sizeof(idxrec_t); - if(!total) { - sprintf(smb->last_error,"invalid index file length: %d",length); - return(1); - } + length=filelength(fileno(smb->sid_fp)); + if(!length) { + sprintf(smb->last_error,"invalid index file length: %d",length); + return(1); + } + total=length/sizeof(idxrec_t); + if(!total) { + sprintf(smb->last_error,"invalid index file length: %d",length); + return(1); + } - bot=0; - top=total; - l=total/2; /* Start at middle index */ - while(1) { - fseek(smb->sid_fp,l*sizeof(idxrec_t),SEEK_SET); - if(!fread(&idx,sizeof(idxrec_t),1,smb->sid_fp)) { - sprintf(smb->last_error,"reading index"); - return(1); - } - if(bot==top-1 && idx.number!=msg->hdr.number) { - sprintf(smb->last_error,"msg %d not found",msg->hdr.number); - return(1); - } - if(idx.number>msg->hdr.number) { - top=l; - l=bot+((top-bot)/2); - continue; - } - if(idx.numberhdr.number) { - bot=l; - l=top-((top-bot)/2); - continue; - } - break; - } - msg->idx=idx; - msg->offset=l; - return(0); + bot=0; + top=total; + l=total/2; /* Start at middle index */ + while(1) { + fseek(smb->sid_fp,l*sizeof(idxrec_t),SEEK_SET); + if(!fread(&idx,sizeof(idxrec_t),1,smb->sid_fp)) { + sprintf(smb->last_error,"reading index"); + return(1); + } + if(bot==top-1 && idx.number!=msg->hdr.number) { + sprintf(smb->last_error,"msg %d not found",msg->hdr.number); + return(1); + } + if(idx.number>msg->hdr.number) { + top=l; + l=bot+((top-bot)/2); + continue; + } + if(idx.numberhdr.number) { + bot=l; + l=top-((top-bot)/2); + continue; + } + break; + } + msg->idx=idx; + msg->offset=l; + return(0); } /****************************************************************************/ -/* Reads the first index record in the open message base */ +/* Reads the first index record in the open message base */ /****************************************************************************/ int SMBCALL smb_getfirstidx(smb_t* smb, idxrec_t *idx) { - if(smb->sid_fp==NULL) { - sprintf(smb->last_error,"index not open"); - return(SMB_ERR_NOT_OPEN); - } - clearerr(smb->sid_fp); - fseek(smb->sid_fp,0,SEEK_SET); - if(!fread(idx,sizeof(idxrec_t),1,smb->sid_fp)) { - sprintf(smb->last_error,"reading index"); - return(-2); - } - return(0); + if(smb->sid_fp==NULL) { + sprintf(smb->last_error,"index not open"); + return(SMB_ERR_NOT_OPEN); + } + clearerr(smb->sid_fp); + fseek(smb->sid_fp,0,SEEK_SET); + if(!fread(idx,sizeof(idxrec_t),1,smb->sid_fp)) { + sprintf(smb->last_error,"reading index"); + return(-2); + } + return(0); } /****************************************************************************/ -/* Reads the last index record in the open message base */ +/* Reads the last index record in the open message base */ /****************************************************************************/ int SMBCALL smb_getlastidx(smb_t* smb, idxrec_t *idx) { - int32_t length; + int32_t length; - if(smb->sid_fp==NULL) { - sprintf(smb->last_error,"index not open"); - return(SMB_ERR_NOT_OPEN); - } - clearerr(smb->sid_fp); - length=filelength(fileno(smb->sid_fp)); - if(lengthlast_error,"invalid index file length: %d",length); - return(-1); - } - fseek(smb->sid_fp,length-sizeof(idxrec_t),SEEK_SET); - if(!fread(idx,sizeof(idxrec_t),1,smb->sid_fp)) { - sprintf(smb->last_error,"reading index"); - return(-2); - } - return(0); + if(smb->sid_fp==NULL) { + sprintf(smb->last_error,"index not open"); + return(SMB_ERR_NOT_OPEN); + } + clearerr(smb->sid_fp); + length=filelength(fileno(smb->sid_fp)); + if(lengthlast_error,"invalid index file length: %d",length); + return(-1); + } + fseek(smb->sid_fp,length-sizeof(idxrec_t),SEEK_SET); + if(!fread(idx,sizeof(idxrec_t),1,smb->sid_fp)) { + sprintf(smb->last_error,"reading index"); + return(-2); + } + return(0); } /****************************************************************************/ /* Figures out the total length of the header record for 'msg' */ -/* Returns length */ +/* Returns length */ /****************************************************************************/ uint SMBCALL smb_getmsghdrlen(smbmsg_t* msg) { - int i; + int i; - /* fixed portion */ - msg->hdr.length=sizeof(msghdr_t); - /* data fields */ - msg->hdr.length+=msg->hdr.total_dfields*sizeof(dfield_t); - /* header fields */ - for(i=0;itotal_hfields;i++) { - msg->hdr.length+=sizeof(hfield_t); - msg->hdr.length+=msg->hfield[i].length; - } - return(msg->hdr.length); + /* fixed portion */ + msg->hdr.length=sizeof(msghdr_t); + /* data fields */ + msg->hdr.length+=msg->hdr.total_dfields*sizeof(dfield_t); + /* header fields */ + for(i=0;itotal_hfields;i++) { + msg->hdr.length+=sizeof(hfield_t); + msg->hdr.length+=msg->hfield[i].length; + } + return(msg->hdr.length); } /****************************************************************************/ /* Figures out the total length of the data buffer for 'msg' */ -/* Returns length */ +/* Returns length */ /****************************************************************************/ uint32_t SMBCALL smb_getmsgdatlen(smbmsg_t* msg) { - int i; - uint32_t length=0L; + int i; + uint32_t length=0L; - for(i=0;ihdr.total_dfields;i++) - length+=msg->dfield[i].length; - return(length); + for(i=0;ihdr.total_dfields;i++) + length+=msg->dfield[i].length; + return(length); } /****************************************************************************/ /* Read header information into 'msg' structure */ -/* msg->idx.offset must be set before calling this function */ -/* Must call smb_freemsgmem() to free memory allocated for var len strs */ -/* Returns 0 on success, non-zero if error */ +/* msg->idx.offset must be set before calling this function */ +/* Must call smb_freemsgmem() to free memory allocated for var len strs */ +/* Returns 0 on success, non-zero if error */ /****************************************************************************/ int SMBCALL smb_getmsghdr(smb_t* smb, smbmsg_t* msg) { - hfield_t *vp; - void **vpp; - ushort i; - uint32_t l,offset; - idxrec_t idx; + hfield_t *vp; + void **vpp; + ushort i; + uint32_t l,offset; + idxrec_t idx; - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - rewind(smb->shd_fp); - fseek(smb->shd_fp,msg->idx.offset,SEEK_SET); - idx=msg->idx; - offset=msg->offset; - memset(msg,0,sizeof(smbmsg_t)); - msg->idx=idx; - msg->offset=offset; - if(!fread(&msg->hdr,sizeof(msghdr_t),1,smb->shd_fp)) { - sprintf(smb->last_error,"reading msg header"); - return(-1); - } - if(memcmp(msg->hdr.id,SHD_HEADER_ID,LEN_HEADER_ID)) { - sprintf(smb->last_error,"corrupt message header ID: %.*s",LEN_HEADER_ID,msg->hdr.id); - return(-2); - } - if(msg->hdr.version<0x110) { - sprintf(smb->last_error,"insufficient header version: %X",msg->hdr.version); - return(-9); - } - l=sizeof(msghdr_t); - if(msg->hdr.total_dfields && (msg->dfield - =(dfield_t *)MALLOC(sizeof(dfield_t)*msg->hdr.total_dfields))==NULL) { - smb_freemsgmem(msg); - sprintf(smb->last_error,"malloc failure of %d bytes for %d data fields" - ,(int)sizeof(dfield_t)*msg->hdr.total_dfields, msg->hdr.total_dfields); - return(-3); - } - i=0; - while(ihdr.total_dfields && lhdr.length) { - if(!fread(&msg->dfield[i],sizeof(dfield_t),1,smb->shd_fp)) { - smb_freemsgmem(msg); - sprintf(smb->last_error,"reading data field %d",i); - return(-4); - } - i++; - l+=sizeof(dfield_t); - } - if(ihdr.total_dfields) { - smb_freemsgmem(msg); - sprintf(smb->last_error,"insufficient data fields read (%d instead of %d)" - ,i,msg->hdr.total_dfields); - return(-8); - } - while(lhdr.length) { - i=msg->total_hfields; - if((vpp=(void* *)REALLOC(msg->hfield_dat,sizeof(void* )*(i+1)))==NULL) { - smb_freemsgmem(msg); - sprintf(smb->last_error - ,"realloc failure of %d bytes for header field data" - ,(int)sizeof(void*)*(i+1)); - return(-3); - } - msg->hfield_dat=vpp; - if((vp=(hfield_t *)REALLOC(msg->hfield,sizeof(hfield_t)*(i+1)))==NULL) { - smb_freemsgmem(msg); - sprintf(smb->last_error - ,"realloc failure of %d bytes for header fields" - ,(int)sizeof(hfield_t)*(i+1)); - return(-3); - } - msg->hfield=vp; - msg->total_hfields++; - if(!fread(&msg->hfield[i],sizeof(hfield_t),1,smb->shd_fp)) { - smb_freemsgmem(msg); - sprintf(smb->last_error,"reading header field"); - return(-5); - } - l+=sizeof(hfield_t); - if((msg->hfield_dat[i]=(char*)MALLOC(msg->hfield[i].length+1)) - ==NULL) { /* Allocate 1 extra for NULL terminator */ - sprintf(smb->last_error - ,"malloc failure of %d bytes for header field %d" - ,msg->hfield[i].length+1, i); - smb_freemsgmem(msg); /* or 0 length field */ - return(-3); - } - memset(msg->hfield_dat[i],0,msg->hfield[i].length+1); /* init to NULL */ - if(msg->hfield[i].length - && !fread(msg->hfield_dat[i],msg->hfield[i].length,1,smb->shd_fp)) { - smb_freemsgmem(msg); - sprintf(smb->last_error,"reading header field data"); - return(-6); - } - switch(msg->hfield[i].type) { /* convenience variables */ - case SENDER: - if(!msg->from) { - msg->from=(char *)msg->hfield_dat[i]; - break; - } - case FORWARDED: /* fall through */ - msg->forwarded=1; - break; - case SENDERAGENT: - if(!msg->forwarded) - msg->from_agent=*(ushort *)msg->hfield_dat[i]; - break; - case SENDEREXT: - if(!msg->forwarded) - msg->from_ext=(char *)msg->hfield_dat[i]; - break; - case SENDERNETTYPE: - if(!msg->forwarded) - msg->from_net.type=*(ushort *)msg->hfield_dat[i]; - break; - case SENDERNETADDR: - if(!msg->forwarded) - msg->from_net.addr=(char *)msg->hfield_dat[i]; - break; - case REPLYTO: - msg->replyto=(char *)msg->hfield_dat[i]; - break; - case REPLYTOEXT: - msg->replyto_ext=(char *)msg->hfield_dat[i]; - break; - case REPLYTOAGENT: - msg->replyto_agent=*(ushort *)msg->hfield_dat[i]; - break; - case REPLYTONETTYPE: - msg->replyto_net.type=*(ushort *)msg->hfield_dat[i]; - break; - case REPLYTONETADDR: - msg->replyto_net.addr=(char *)msg->hfield_dat[i]; - break; - case RECIPIENT: - msg->to=(char *)msg->hfield_dat[i]; - break; - case RECIPIENTEXT: - msg->to_ext=(char *)msg->hfield_dat[i]; - break; - case RECIPIENTAGENT: - msg->to_agent=*(ushort *)msg->hfield_dat[i]; - break; - case RECIPIENTNETTYPE: - msg->to_net.type=*(ushort *)msg->hfield_dat[i]; - break; - case RECIPIENTNETADDR: - msg->to_net.addr=(char *)msg->hfield_dat[i]; - break; - case SUBJECT: - msg->subj=(char *)msg->hfield_dat[i]; - break; - case RFC822MSGID: - msg->id=(char *)msg->hfield_dat[i]; - break; - case RFC822REPLYID: - msg->reply_id=(char *)msg->hfield_dat[i]; - break; - case USENETPATH: - msg->path=(char *)msg->hfield_dat[i]; - break; - case USENETNEWSGROUPS: - msg->newsgroups=(char *)msg->hfield_dat[i]; - break; - case FIDOMSGID: - msg->ftn_msgid=(char *)msg->hfield_dat[i]; - break; - case FIDOREPLYID: - msg->ftn_reply=(char *)msg->hfield_dat[i]; - break; - case FIDOAREA: - msg->ftn_area=(char *)msg->hfield_dat[i]; - break; - case FIDOPID: - msg->ftn_pid=(char *)msg->hfield_dat[i]; - break; - case FIDOFLAGS: - msg->ftn_flags=(char *)msg->hfield_dat[i]; - break; - - } - l+=msg->hfield[i].length; - } + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + rewind(smb->shd_fp); + fseek(smb->shd_fp,msg->idx.offset,SEEK_SET); + idx=msg->idx; + offset=msg->offset; + memset(msg,0,sizeof(smbmsg_t)); + msg->idx=idx; + msg->offset=offset; + if(!fread(&msg->hdr,sizeof(msghdr_t),1,smb->shd_fp)) { + sprintf(smb->last_error,"reading msg header"); + return(-1); + } + if(memcmp(msg->hdr.id,SHD_HEADER_ID,LEN_HEADER_ID)) { + sprintf(smb->last_error,"corrupt message header ID: %.*s",LEN_HEADER_ID,msg->hdr.id); + return(-2); + } + if(msg->hdr.version<0x110) { + sprintf(smb->last_error,"insufficient header version: %X",msg->hdr.version); + return(-9); + } + l=sizeof(msghdr_t); + if(msg->hdr.total_dfields && (msg->dfield + =(dfield_t *)MALLOC(sizeof(dfield_t)*msg->hdr.total_dfields))==NULL) { + smb_freemsgmem(msg); + sprintf(smb->last_error,"malloc failure of %d bytes for %d data fields" + ,(int)sizeof(dfield_t)*msg->hdr.total_dfields, msg->hdr.total_dfields); + return(-3); + } + i=0; + while(ihdr.total_dfields && lhdr.length) { + if(!fread(&msg->dfield[i],sizeof(dfield_t),1,smb->shd_fp)) { + smb_freemsgmem(msg); + sprintf(smb->last_error,"reading data field %d",i); + return(-4); + } + i++; + l+=sizeof(dfield_t); + } + if(ihdr.total_dfields) { + smb_freemsgmem(msg); + sprintf(smb->last_error,"insufficient data fields read (%d instead of %d)" + ,i,msg->hdr.total_dfields); + return(-8); + } + while(lhdr.length) { + i=msg->total_hfields; + if((vpp=(void* *)REALLOC(msg->hfield_dat,sizeof(void* )*(i+1)))==NULL) { + smb_freemsgmem(msg); + sprintf(smb->last_error + ,"realloc failure of %d bytes for header field data" + ,(int)sizeof(void*)*(i+1)); + return(-3); + } + msg->hfield_dat=vpp; + if((vp=(hfield_t *)REALLOC(msg->hfield,sizeof(hfield_t)*(i+1)))==NULL) { + smb_freemsgmem(msg); + sprintf(smb->last_error + ,"realloc failure of %d bytes for header fields" + ,(int)sizeof(hfield_t)*(i+1)); + return(-3); + } + msg->hfield=vp; + msg->total_hfields++; + if(!fread(&msg->hfield[i],sizeof(hfield_t),1,smb->shd_fp)) { + smb_freemsgmem(msg); + sprintf(smb->last_error,"reading header field"); + return(-5); + } + l+=sizeof(hfield_t); + if((msg->hfield_dat[i]=(char*)MALLOC(msg->hfield[i].length+1)) + ==NULL) { /* Allocate 1 extra for NULL terminator */ + sprintf(smb->last_error + ,"malloc failure of %d bytes for header field %d" + ,msg->hfield[i].length+1, i); + smb_freemsgmem(msg); /* or 0 length field */ + return(-3); + } + memset(msg->hfield_dat[i],0,msg->hfield[i].length+1); /* init to NULL */ + if(msg->hfield[i].length + && !fread(msg->hfield_dat[i],msg->hfield[i].length,1,smb->shd_fp)) { + smb_freemsgmem(msg); + sprintf(smb->last_error,"reading header field data"); + return(-6); + } + switch(msg->hfield[i].type) { /* convenience variables */ + case SENDER: + if(!msg->from) { + msg->from=(char *)msg->hfield_dat[i]; + break; + } + case FORWARDED: /* fall through */ + msg->forwarded=1; + break; + case SENDERAGENT: + if(!msg->forwarded) + msg->from_agent=*(ushort *)msg->hfield_dat[i]; + break; + case SENDEREXT: + if(!msg->forwarded) + msg->from_ext=(char *)msg->hfield_dat[i]; + break; + case SENDERNETTYPE: + if(!msg->forwarded) + msg->from_net.type=*(ushort *)msg->hfield_dat[i]; + break; + case SENDERNETADDR: + if(!msg->forwarded) + msg->from_net.addr=(char *)msg->hfield_dat[i]; + break; + case REPLYTO: + msg->replyto=(char *)msg->hfield_dat[i]; + break; + case REPLYTOEXT: + msg->replyto_ext=(char *)msg->hfield_dat[i]; + break; + case REPLYTOAGENT: + msg->replyto_agent=*(ushort *)msg->hfield_dat[i]; + break; + case REPLYTONETTYPE: + msg->replyto_net.type=*(ushort *)msg->hfield_dat[i]; + break; + case REPLYTONETADDR: + msg->replyto_net.addr=(char *)msg->hfield_dat[i]; + break; + case RECIPIENT: + msg->to=(char *)msg->hfield_dat[i]; + break; + case RECIPIENTEXT: + msg->to_ext=(char *)msg->hfield_dat[i]; + break; + case RECIPIENTAGENT: + msg->to_agent=*(ushort *)msg->hfield_dat[i]; + break; + case RECIPIENTNETTYPE: + msg->to_net.type=*(ushort *)msg->hfield_dat[i]; + break; + case RECIPIENTNETADDR: + msg->to_net.addr=(char *)msg->hfield_dat[i]; + break; + case SUBJECT: + msg->subj=(char *)msg->hfield_dat[i]; + break; + case RFC822MSGID: + msg->id=(char *)msg->hfield_dat[i]; + break; + case RFC822REPLYID: + msg->reply_id=(char *)msg->hfield_dat[i]; + break; + case USENETPATH: + msg->path=(char *)msg->hfield_dat[i]; + break; + case USENETNEWSGROUPS: + msg->newsgroups=(char *)msg->hfield_dat[i]; + break; + case FIDOMSGID: + msg->ftn_msgid=(char *)msg->hfield_dat[i]; + break; + case FIDOREPLYID: + msg->ftn_reply=(char *)msg->hfield_dat[i]; + break; + case FIDOAREA: + msg->ftn_area=(char *)msg->hfield_dat[i]; + break; + case FIDOPID: + msg->ftn_pid=(char *)msg->hfield_dat[i]; + break; + case FIDOFLAGS: + msg->ftn_flags=(char *)msg->hfield_dat[i]; + break; + + } + l+=msg->hfield[i].length; + } - if(!msg->from || !msg->to || !msg->subj) { - sprintf(smb->last_error,"missing required header field (from/to/subj)"); - smb_freemsgmem(msg); - return(-7); - } - return(0); + if(!msg->from || !msg->to || !msg->subj) { + sprintf(smb->last_error,"missing required header field (from/to/subj)"); + smb_freemsgmem(msg); + return(-7); + } + return(0); } /****************************************************************************/ @@ -847,58 +855,58 @@ int SMBCALL smb_getmsghdr(smb_t* smb, smbmsg_t* msg) /****************************************************************************/ void SMBCALL smb_freemsgmem(smbmsg_t* msg) { - ushort i; + ushort i; - if(msg->dfield) { - FREE(msg->dfield); - msg->dfield=NULL; - } - for(i=0;itotal_hfields;i++) - if(msg->hfield_dat[i]) { - FREE(msg->hfield_dat[i]); - msg->hfield_dat[i]=NULL; - } - msg->total_hfields=0; - if(msg->hfield) { - FREE(msg->hfield); - msg->hfield=NULL; - } - if(msg->hfield_dat) { - FREE(msg->hfield_dat); - msg->hfield_dat=NULL; - } + if(msg->dfield) { + FREE(msg->dfield); + msg->dfield=NULL; + } + for(i=0;itotal_hfields;i++) + if(msg->hfield_dat[i]) { + FREE(msg->hfield_dat[i]); + msg->hfield_dat[i]=NULL; + } + msg->total_hfields=0; + if(msg->hfield) { + FREE(msg->hfield); + msg->hfield=NULL; + } + if(msg->hfield_dat) { + FREE(msg->hfield_dat); + msg->hfield_dat=NULL; + } } /****************************************************************************/ -/* Copies memory allocated for 'srcmsg' to 'msg' */ +/* Copies memory allocated for 'srcmsg' to 'msg' */ /****************************************************************************/ int SMBCALL smb_copymsgmem(smbmsg_t* msg, smbmsg_t* srcmsg) { - int i; + int i; - memcpy(msg,srcmsg,sizeof(smbmsg_t)); + memcpy(msg,srcmsg,sizeof(smbmsg_t)); - /* data field types/lengths */ - if((msg->dfield=(dfield_t *)MALLOC(msg->hdr.total_dfields*sizeof(dfield_t)))==NULL) - return(1); - memcpy(msg->dfield,srcmsg->dfield,msg->hdr.total_dfields*sizeof(dfield_t)); + /* data field types/lengths */ + if((msg->dfield=(dfield_t *)MALLOC(msg->hdr.total_dfields*sizeof(dfield_t)))==NULL) + return(1); + memcpy(msg->dfield,srcmsg->dfield,msg->hdr.total_dfields*sizeof(dfield_t)); - /* header field types/lengths */ - if((msg->hfield=(hfield_t *)MALLOC(msg->total_hfields*sizeof(hfield_t)))==NULL) - return(2); - memcpy(msg->hfield,srcmsg->hfield,msg->total_hfields*sizeof(hfield_t)); + /* header field types/lengths */ + if((msg->hfield=(hfield_t *)MALLOC(msg->total_hfields*sizeof(hfield_t)))==NULL) + return(2); + memcpy(msg->hfield,srcmsg->hfield,msg->total_hfields*sizeof(hfield_t)); - /* header field data */ - if((msg->hfield_dat=(void* *)MALLOC(msg->total_hfields*sizeof(void*)))==NULL) - return(3); + /* header field data */ + if((msg->hfield_dat=(void* *)MALLOC(msg->total_hfields*sizeof(void*)))==NULL) + return(3); - for(i=0;itotal_hfields;i++) { - if((msg->hfield_dat[i]=(char*)MALLOC(msg->hfield[i].length))==NULL) - return(4); - memcpy(msg->hfield_dat[i],srcmsg->hfield_dat[i],msg->hfield[i].length); - } + for(i=0;itotal_hfields;i++) { + if((msg->hfield_dat[i]=(char*)MALLOC(msg->hfield[i].length))==NULL) + return(4); + memcpy(msg->hfield_dat[i],srcmsg->hfield_dat[i],msg->hfield[i].length); + } - return(0); + return(0); } /****************************************************************************/ @@ -906,11 +914,11 @@ int SMBCALL smb_copymsgmem(smbmsg_t* msg, smbmsg_t* srcmsg) /****************************************************************************/ int SMBCALL smb_unlockmsghdr(smb_t* smb, smbmsg_t* msg) { - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - return(unlock(fileno(smb->shd_fp),msg->idx.offset,sizeof(msghdr_t))); + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + return(unlock(fileno(smb->shd_fp),msg->idx.offset,sizeof(msghdr_t))); } @@ -919,208 +927,208 @@ int SMBCALL smb_unlockmsghdr(smb_t* smb, smbmsg_t* msg) /****************************************************************************/ int SMBCALL smb_hfield(smbmsg_t* msg, ushort type, size_t length, void* data) { - hfield_t* vp; - void* *vpp; - int i; + hfield_t* vp; + void* *vpp; + int i; - i=msg->total_hfields; - if((vp=(hfield_t *)REALLOC(msg->hfield,sizeof(hfield_t)*(i+1)))==NULL) - return(1); + i=msg->total_hfields; + if((vp=(hfield_t *)REALLOC(msg->hfield,sizeof(hfield_t)*(i+1)))==NULL) + return(1); - msg->hfield=vp; - if((vpp=(void* *)REALLOC(msg->hfield_dat,sizeof(void* )*(i+1)))==NULL) - return(2); - - msg->hfield_dat=vpp; - msg->total_hfields++; - msg->hfield[i].type=type; - msg->hfield[i].length=length; - if(length) { - if((msg->hfield_dat[i]=(void* )MALLOC(length))==NULL) - return(4); - memcpy(msg->hfield_dat[i],data,length); - } - else - msg->hfield_dat[i]=NULL; - return(0); + msg->hfield=vp; + if((vpp=(void* *)REALLOC(msg->hfield_dat,sizeof(void* )*(i+1)))==NULL) + return(2); + + msg->hfield_dat=vpp; + msg->total_hfields++; + msg->hfield[i].type=type; + msg->hfield[i].length=length; + if(length) { + if((msg->hfield_dat[i]=(void* )MALLOC(length))==NULL) + return(4); + memcpy(msg->hfield_dat[i],data,length); + } + else + msg->hfield_dat[i]=NULL; + return(0); } /****************************************************************************/ -/* Searches for a specific header field (by type) and returns it */ +/* Searches for a specific header field (by type) and returns it */ /****************************************************************************/ void* SMBCALL smb_get_hfield(smbmsg_t* msg, ushort type, hfield_t* hfield) { - int i; + int i; - for(i=0;itotal_hfields;i++) - if(msg->hfield[i].type == type) { - if(hfield != NULL) - hfield = &msg->hfield[i]; - return(msg->hfield_dat[i]); - } + for(i=0;itotal_hfields;i++) + if(msg->hfield[i].type == type) { + if(hfield != NULL) + hfield = &msg->hfield[i]; + return(msg->hfield_dat[i]); + } - return(NULL); + return(NULL); } /****************************************************************************/ /* Adds a data field to the 'msg' structure (in memory only) */ -/* Automatically figures out the offset into the data buffer from existing */ -/* dfield lengths */ +/* Automatically figures out the offset into the data buffer from existing */ +/* dfield lengths */ /****************************************************************************/ int SMBCALL smb_dfield(smbmsg_t* msg, ushort type, uint32_t length) { - dfield_t* vp; - int i,j; + dfield_t* vp; + int i,j; - i=msg->hdr.total_dfields; - if((vp=(dfield_t *)REALLOC(msg->dfield,sizeof(dfield_t)*(i+1)))==NULL) - return(1); - - msg->dfield=vp; - msg->hdr.total_dfields++; - msg->dfield[i].type=type; - msg->dfield[i].length=length; - for(j=msg->dfield[i].offset=0;jdfield[i].offset+=msg->dfield[j].length; - return(0); + i=msg->hdr.total_dfields; + if((vp=(dfield_t *)REALLOC(msg->dfield,sizeof(dfield_t)*(i+1)))==NULL) + return(1); + + msg->dfield=vp; + msg->hdr.total_dfields++; + msg->dfield[i].type=type; + msg->dfield[i].length=length; + for(j=msg->dfield[i].offset=0;jdfield[i].offset+=msg->dfield[j].length; + return(0); } /****************************************************************************/ -/* Checks CRC history file for duplicate crc. If found, returns 1. */ -/* If no dupe, adds to CRC history and returns 0, or negative if error. */ +/* Checks CRC history file for duplicate crc. If found, returns 1. */ +/* If no dupe, adds to CRC history and returns 0, or negative if error. */ /****************************************************************************/ int SMBCALL smb_addcrc(smb_t* smb, uint32_t crc) { - char str[128]; - int file; - int32_t length; - uint32_t l,*buf; - time_t start=0; + char str[128]; + int file; + int32_t length; + uint32_t l, *buf; + time32_t start = 0; - if(!smb->status.max_crcs) - return(0); + if(!smb->status.max_crcs) + return(0); - sprintf(str,"%s.sch",smb->file); - while(1) { - if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYRW))!=-1) - break; - if(errno!=EACCES && errno!=EAGAIN) { - sprintf(smb->last_error,"%d opening %s", errno, str); - return(-1); - } - if(!start) - start=time(NULL); - else - if(time(NULL)-start>=(time_t)smb->retry_time) { - sprintf(smb->last_error,"timeout opening %s (retry_time=%d)" - ,str,smb->retry_time); - return(-2); - } - SLEEP(smb->retry_delay); - } + sprintf(str,"%s.sch",smb->file); + while(1) { + if((file=sopen(str,O_RDWR|O_CREAT|O_BINARY,SH_DENYRW))!=-1) + break; + if(errno!=EACCES && errno!=EAGAIN) { + sprintf(smb->last_error,"%d opening %s", errno, str); + return(-1); + } + if(!start) + start = gtime(NULL); + else + if(gtime(NULL)-start >= smb->retry_time) { + sprintf(smb->last_error,"timeout opening %s (retry_time=%d)" + ,str,smb->retry_time); + return(-2); + } + SLEEP(smb->retry_delay); + } - length=filelength(file); - if(length<0L) { - close(file); - sprintf(smb->last_error,"invalid file length: %d", length); - return(-4); - } - if((buf=(uint32_t*)MALLOC(smb->status.max_crcs*4))==NULL) { - close(file); - sprintf(smb->last_error - ,"malloc failure of %d bytes" - ,smb->status.max_crcs*4); - return(-3); - } - if((uint32_t)length>=smb->status.max_crcs*4L) { /* Reached or exceeds max crcs */ - read(file,buf,smb->status.max_crcs*4); - for(l=0;lstatus.max_crcs;l++) - if(crc==buf[l]) - break; - if(lstatus.max_crcs) { /* Dupe CRC found */ - close(file); - FREE(buf); - sprintf(smb->last_error - ,"duplicate message detected"); - return(1); - } - chsize(file,0L); /* truncate it */ - lseek(file,0L,SEEK_SET); - write(file,buf+4,(smb->status.max_crcs-1)*4); - } + length=filelength(file); + if(length<0L) { + close(file); + sprintf(smb->last_error,"invalid file length: %d", length); + return(-4); + } + if((buf=(uint32_t*)MALLOC(smb->status.max_crcs*4))==NULL) { + close(file); + sprintf(smb->last_error + ,"malloc failure of %d bytes" + ,smb->status.max_crcs*4); + return(-3); + } + if((uint32_t)length>=smb->status.max_crcs*4L) { /* Reached or exceeds max crcs */ + read(file,buf,smb->status.max_crcs*4); + for(l=0;lstatus.max_crcs;l++) + if(crc==buf[l]) + break; + if(lstatus.max_crcs) { /* Dupe CRC found */ + close(file); + FREE(buf); + sprintf(smb->last_error + ,"duplicate message detected"); + return(1); + } + chsize(file,0L); /* truncate it */ + lseek(file,0L,SEEK_SET); + write(file,buf+4,(smb->status.max_crcs-1)*4); + } - else if(length/4) { /* Less than max crcs */ - read(file,buf,length); - for(l=0;l<(uint32_t)(length/4);l++) - if(crc==buf[l]) - break; - if(l<(uint32_t)(length/4L)) { /* Dupe CRC found */ - close(file); - FREE(buf); - sprintf(smb->last_error - ,"duplicate message detected"); - return(1); - } - } + else if(length/4) { /* Less than max crcs */ + read(file,buf,length); + for(l=0;l<(uint32_t)(length/4);l++) + if(crc==buf[l]) + break; + if(l<(uint32_t)(length/4L)) { /* Dupe CRC found */ + close(file); + FREE(buf); + sprintf(smb->last_error + ,"duplicate message detected"); + return(1); + } + } - lseek(file,0L,SEEK_END); - write(file,&crc,sizeof(crc)); /* Write to the end */ - FREE(buf); - close(file); - return(0); + lseek(file,0L,SEEK_END); + write(file,&crc,sizeof(crc)); /* Write to the end */ + FREE(buf); + close(file); + return(0); } /****************************************************************************/ -/* Creates a new message header record in the header file. */ +/* Creates a new message header record in the header file. */ /* If storage is SMB_SELFPACK, self-packing conservative allocation is used */ -/* If storage is SMB_FASTALLOC, fast allocation is used */ -/* If storage is SMB_HYPERALLOC, no allocation tables are used (fastest) */ -/* This function will UN-lock the SMB header */ +/* If storage is SMB_FASTALLOC, fast allocation is used */ +/* If storage is SMB_HYPERALLOC, no allocation tables are used (fastest) */ +/* This function will UN-lock the SMB header */ /****************************************************************************/ int SMBCALL smb_addmsghdr(smb_t* smb, smbmsg_t* msg, int storage) { - int i; - int32_t l; + int i; + int32_t l; - if(!smb->locked && smb_locksmbhdr(smb)) - return(1); - if(smb_getstatus(smb)) { - smb_unlocksmbhdr(smb); - return(2); - } + if(!smb->locked && smb_locksmbhdr(smb)) + return(1); + if(smb_getstatus(smb)) { + smb_unlocksmbhdr(smb); + return(2); + } - if(storage!=SMB_HYPERALLOC && (i=smb_open_ha(smb))!=0) { - smb_unlocksmbhdr(smb); - return(i); - } + if(storage!=SMB_HYPERALLOC && (i=smb_open_ha(smb))!=0) { + smb_unlocksmbhdr(smb); + return(i); + } - msg->hdr.length=smb_getmsghdrlen(msg); - if(storage==SMB_HYPERALLOC) - l=smb_hallochdr(smb); - else if(storage==SMB_FASTALLOC) - l=smb_fallochdr(smb,msg->hdr.length); - else - l=smb_allochdr(smb,msg->hdr.length); - if(storage!=SMB_HYPERALLOC) - smb_close_ha(smb); - if(l==-1L) { - smb_unlocksmbhdr(smb); - return(-1); - } + msg->hdr.length=smb_getmsghdrlen(msg); + if(storage==SMB_HYPERALLOC) + l=smb_hallochdr(smb); + else if(storage==SMB_FASTALLOC) + l=smb_fallochdr(smb,msg->hdr.length); + else + l=smb_allochdr(smb,msg->hdr.length); + if(storage!=SMB_HYPERALLOC) + smb_close_ha(smb); + if(l==-1L) { + smb_unlocksmbhdr(smb); + return(-1); + } - msg->idx.number=msg->hdr.number=smb->status.last_msg+1; - msg->idx.offset=smb->status.header_offset+l; - msg->idx.time=msg->hdr.when_imported.time; - msg->idx.attr=msg->hdr.attr; - msg->offset=smb->status.total_msgs; - i=smb_putmsg(smb,msg); - if(i==0) { /* success */ - smb->status.last_msg++; - smb->status.total_msgs++; - smb_putstatus(smb); - } - smb_unlocksmbhdr(smb); - return(i); + msg->idx.number=msg->hdr.number=smb->status.last_msg+1; + msg->idx.offset=smb->status.header_offset+l; + msg->idx.time=msg->hdr.when_imported.time; + msg->idx.attr=msg->hdr.attr; + msg->offset=smb->status.total_msgs; + i=smb_putmsg(smb,msg); + if(i==0) { /* success */ + smb->status.last_msg++; + smb->status.total_msgs++; + smb_putstatus(smb); + } + smb_unlocksmbhdr(smb); + return(i); } /****************************************************************************/ @@ -1128,154 +1136,154 @@ int SMBCALL smb_addmsghdr(smb_t* smb, smbmsg_t* msg, int storage) /****************************************************************************/ int SMBCALL smb_putmsg(smb_t* smb, smbmsg_t* msg) { - int i; + int i; - i=smb_putmsghdr(smb,msg); - if(i) - return(i); - return(smb_putmsgidx(smb,msg)); + i=smb_putmsghdr(smb,msg); + if(i) + return(i); + return(smb_putmsgidx(smb,msg)); } /****************************************************************************/ /* Writes index information for 'msg' */ -/* msg->idx */ -/* and msg->offset must be set prior to calling to this function */ +/* msg->idx */ +/* and msg->offset must be set prior to calling to this function */ /* Returns 0 if everything ok */ /****************************************************************************/ int SMBCALL smb_putmsgidx(smb_t* smb, smbmsg_t* msg) { - if(smb->sid_fp==NULL) { - sprintf(smb->last_error,"index not open"); - return(SMB_ERR_NOT_OPEN); - } - clearerr(smb->sid_fp); - fseek(smb->sid_fp,msg->offset*sizeof(idxrec_t),SEEK_SET); - if(!fwrite(&msg->idx,sizeof(idxrec_t),1,smb->sid_fp)) { - sprintf(smb->last_error,"writing index"); - return(1); - } - fflush(smb->sid_fp); - return(0); + if(smb->sid_fp==NULL) { + sprintf(smb->last_error,"index not open"); + return(SMB_ERR_NOT_OPEN); + } + clearerr(smb->sid_fp); + fseek(smb->sid_fp,msg->offset*sizeof(idxrec_t),SEEK_SET); + if(!fwrite(&msg->idx,sizeof(idxrec_t),1,smb->sid_fp)) { + sprintf(smb->last_error,"writing index"); + return(1); + } + fflush(smb->sid_fp); + return(0); } /****************************************************************************/ /* Writes header information for 'msg' */ -/* msg->hdr.length */ -/* msg->idx.offset */ -/* and msg->offset must be set prior to calling to this function */ +/* msg->hdr.length */ +/* msg->idx.offset */ +/* and msg->offset must be set prior to calling to this function */ /* Returns 0 if everything ok */ /****************************************************************************/ int SMBCALL smb_putmsghdr(smb_t* smb, smbmsg_t* msg) { - ushort i; - uint32_t l; + ushort i; + uint32_t l; - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - if(msg->idx.offsetidx.offsetstatus.header_offset) { - sprintf(smb->last_error,"invalid header offset: %d",msg->idx.offset); - return(-7); - } - clearerr(smb->shd_fp); - if(fseek(smb->shd_fp,msg->idx.offset,SEEK_SET)) { - sprintf(smb->last_error,"seeking to %d in index",msg->idx.offset); - return(-1); - } + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + if(msg->idx.offsetidx.offsetstatus.header_offset) { + sprintf(smb->last_error,"invalid header offset: %d",msg->idx.offset); + return(-7); + } + clearerr(smb->shd_fp); + if(fseek(smb->shd_fp,msg->idx.offset,SEEK_SET)) { + sprintf(smb->last_error,"seeking to %d in index",msg->idx.offset); + return(-1); + } - /**********************************/ - /* Set the message header ID here */ - /**********************************/ - memcpy(&msg->hdr.id,SHD_HEADER_ID,LEN_HEADER_ID); + /**********************************/ + /* Set the message header ID here */ + /**********************************/ + memcpy(&msg->hdr.id,SHD_HEADER_ID,LEN_HEADER_ID); - /************************************************/ - /* Write the fixed portion of the header record */ - /************************************************/ - if(!fwrite(&msg->hdr,sizeof(msghdr_t),1,smb->shd_fp)) { - sprintf(smb->last_error,"writing fixed portion of header record"); - return(-2); - } + /************************************************/ + /* Write the fixed portion of the header record */ + /************************************************/ + if(!fwrite(&msg->hdr,sizeof(msghdr_t),1,smb->shd_fp)) { + sprintf(smb->last_error,"writing fixed portion of header record"); + return(-2); + } - /************************************************/ - /* Write the data fields (each is fixed length) */ - /************************************************/ - for(i=0;ihdr.total_dfields;i++) - if(!fwrite(&msg->dfield[i],sizeof(dfield_t),1,smb->shd_fp)) { - sprintf(smb->last_error,"writing data field"); - return(-3); - } + /************************************************/ + /* Write the data fields (each is fixed length) */ + /************************************************/ + for(i=0;ihdr.total_dfields;i++) + if(!fwrite(&msg->dfield[i],sizeof(dfield_t),1,smb->shd_fp)) { + sprintf(smb->last_error,"writing data field"); + return(-3); + } - /*******************************************/ - /* Write the variable length header fields */ - /*******************************************/ - for(i=0;itotal_hfields;i++) { - if(!fwrite(&msg->hfield[i],sizeof(hfield_t),1,smb->shd_fp)) { - sprintf(smb->last_error,"writing header field"); - return(-4); - } - if(msg->hfield[i].length /* more then 0 bytes int32_t */ - && !fwrite(msg->hfield_dat[i],msg->hfield[i].length,1,smb->shd_fp)) { - sprintf(smb->last_error,"writing header field data"); - return(-5); - } - } + /*******************************************/ + /* Write the variable length header fields */ + /*******************************************/ + for(i=0;itotal_hfields;i++) { + if(!fwrite(&msg->hfield[i],sizeof(hfield_t),1,smb->shd_fp)) { + sprintf(smb->last_error,"writing header field"); + return(-4); + } + if(msg->hfield[i].length /* more then 0 bytes int32_t */ + && !fwrite(msg->hfield_dat[i],msg->hfield[i].length,1,smb->shd_fp)) { + sprintf(smb->last_error,"writing header field data"); + return(-5); + } + } - l=smb_getmsghdrlen(msg); - while(l%SHD_BLOCK_LEN) { - if(fputc(0,smb->shd_fp)==EOF) { - sprintf(smb->last_error,"padding header block"); - return(-6); /* pad block with NULL */ - } - l++; - } - fflush(smb->shd_fp); - return(0); + l=smb_getmsghdrlen(msg); + while(l%SHD_BLOCK_LEN) { + if(fputc(0,smb->shd_fp)==EOF) { + sprintf(smb->last_error,"padding header block"); + return(-6); /* pad block with NULL */ + } + l++; + } + fflush(smb->shd_fp); + return(0); } /****************************************************************************/ /* Creates a sub-board's initial header file */ -/* Truncates and deletes other associated SMB files */ +/* Truncates and deletes other associated SMB files */ /****************************************************************************/ int SMBCALL smb_create(smb_t* smb) { char str[128]; - smbhdr_t hdr; + smbhdr_t hdr; - if(smb->shd_fp==NULL || smb->sdt_fp==NULL || smb->sid_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - if(filelength(fileno(smb->shd_fp))>=sizeof(smbhdr_t)+sizeof(smbstatus_t) - && smb_locksmbhdr(smb)) /* header exists, so lock it */ - return(1); - memset(&hdr,0,sizeof(smbhdr_t)); - memcpy(hdr.id,SMB_HEADER_ID,LEN_HEADER_ID); - hdr.version=SMB_VERSION; - hdr.length=sizeof(smbhdr_t)+sizeof(smbstatus_t); - smb->status.last_msg=smb->status.total_msgs=0; - smb->status.header_offset=sizeof(smbhdr_t)+sizeof(smbstatus_t); - rewind(smb->shd_fp); - fwrite(&hdr,1,sizeof(smbhdr_t),smb->shd_fp); - fwrite(&(smb->status),1,sizeof(smbstatus_t),smb->shd_fp); - rewind(smb->shd_fp); - chsize(fileno(smb->shd_fp),sizeof(smbhdr_t)+sizeof(smbstatus_t)); - fflush(smb->shd_fp); + if(smb->shd_fp==NULL || smb->sdt_fp==NULL || smb->sid_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + if(filelength(fileno(smb->shd_fp))>=sizeof(smbhdr_t)+sizeof(smbstatus_t) + && smb_locksmbhdr(smb)) /* header exists, so lock it */ + return(1); + memset(&hdr,0,sizeof(smbhdr_t)); + memcpy(hdr.id,SMB_HEADER_ID,LEN_HEADER_ID); + hdr.version=SMB_VERSION; + hdr.length=sizeof(smbhdr_t)+sizeof(smbstatus_t); + smb->status.last_msg=smb->status.total_msgs=0; + smb->status.header_offset=sizeof(smbhdr_t)+sizeof(smbstatus_t); + rewind(smb->shd_fp); + fwrite(&hdr,1,sizeof(smbhdr_t),smb->shd_fp); + fwrite(&(smb->status),1,sizeof(smbstatus_t),smb->shd_fp); + rewind(smb->shd_fp); + chsize(fileno(smb->shd_fp),sizeof(smbhdr_t)+sizeof(smbstatus_t)); + fflush(smb->shd_fp); - rewind(smb->sdt_fp); - chsize(fileno(smb->sdt_fp),0L); - rewind(smb->sid_fp); - chsize(fileno(smb->sid_fp),0L); + rewind(smb->sdt_fp); + chsize(fileno(smb->sdt_fp),0L); + rewind(smb->sid_fp); + chsize(fileno(smb->sid_fp),0L); - sprintf(str,"%s.sda",smb->file); - remove(str); /* if it exists, delete it */ - sprintf(str,"%s.sha",smb->file); - remove(str); /* if it exists, delete it */ - sprintf(str,"%s.sch",smb->file); - remove(str); - smb_unlocksmbhdr(smb); - return(0); + sprintf(str,"%s.sda",smb->file); + remove(str); /* if it exists, delete it */ + sprintf(str,"%s.sha",smb->file); + remove(str); /* if it exists, delete it */ + sprintf(str,"%s.sch",smb->file); + remove(str); + smb_unlocksmbhdr(smb); + return(0); } /****************************************************************************/ @@ -1283,12 +1291,12 @@ int SMBCALL smb_create(smb_t* smb) /****************************************************************************/ uint32_t SMBCALL smb_datblocks(uint32_t length) { - uint32_t blocks; + uint32_t blocks; - blocks=length/SDT_BLOCK_LEN; - if(length%SDT_BLOCK_LEN) - blocks++; - return(blocks); + blocks=length/SDT_BLOCK_LEN; + if(length%SDT_BLOCK_LEN) + blocks++; + return(blocks); } /****************************************************************************/ @@ -1296,199 +1304,199 @@ uint32_t SMBCALL smb_datblocks(uint32_t length) /****************************************************************************/ uint32_t SMBCALL smb_hdrblocks(uint32_t length) { - uint32_t blocks; + uint32_t blocks; - blocks=length/SHD_BLOCK_LEN; - if(length%SHD_BLOCK_LEN) - blocks++; - return(blocks); + blocks=length/SHD_BLOCK_LEN; + if(length%SHD_BLOCK_LEN) + blocks++; + return(blocks); } /****************************************************************************/ -/* Finds unused space in data file based on block allocation table and */ +/* Finds unused space in data file based on block allocation table and */ /* marks space as used in allocation table. */ -/* File must be opened read/write DENY ALL */ -/* Returns offset to beginning of data (in bytes, not blocks) */ -/* Assumes smb_open_da() has been called */ -/* smb_close_da() should be called after */ -/* Returns negative on error */ +/* File must be opened read/write DENY ALL */ +/* Returns offset to beginning of data (in bytes, not blocks) */ +/* Assumes smb_open_da() has been called */ +/* smb_close_da() should be called after */ +/* Returns negative on error */ /****************************************************************************/ int32_t SMBCALL smb_allocdat(smb_t* smb, uint32_t length, ushort headers) { ushort i,j; - uint32_t l,blocks,offset=0L; + uint32_t l,blocks,offset=0L; - if(smb->sda_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - blocks=smb_datblocks(length); - j=0; /* j is consecutive unused block counter */ - fflush(smb->sda_fp); - rewind(smb->sda_fp); - while(!feof(smb->sda_fp)) { - if(!fread(&i,2,1,smb->sda_fp)) - break; - offset+=SDT_BLOCK_LEN; - if(!i) j++; - else j=0; - if(j==blocks) { - offset-=(blocks*SDT_BLOCK_LEN); - break; - } - } - clearerr(smb->sda_fp); - fseek(smb->sda_fp,(offset/SDT_BLOCK_LEN)*2L,SEEK_SET); - for(l=0;lsda_fp)) { - sprintf(smb->last_error,"writing allocation bytes"); - return(-1); - } - fflush(smb->sda_fp); - return(offset); + if(smb->sda_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + blocks=smb_datblocks(length); + j=0; /* j is consecutive unused block counter */ + fflush(smb->sda_fp); + rewind(smb->sda_fp); + while(!feof(smb->sda_fp)) { + if(!fread(&i,2,1,smb->sda_fp)) + break; + offset+=SDT_BLOCK_LEN; + if(!i) j++; + else j=0; + if(j==blocks) { + offset-=(blocks*SDT_BLOCK_LEN); + break; + } + } + clearerr(smb->sda_fp); + fseek(smb->sda_fp,(offset/SDT_BLOCK_LEN)*2L,SEEK_SET); + for(l=0;lsda_fp)) { + sprintf(smb->last_error,"writing allocation bytes"); + return(-1); + } + fflush(smb->sda_fp); + return(offset); } /****************************************************************************/ /* Allocates space for data, but doesn't search for unused blocks */ -/* Returns negative on error */ +/* Returns negative on error */ /****************************************************************************/ int32_t SMBCALL smb_fallocdat(smb_t* smb, uint32_t length, ushort headers) { - uint32_t l,blocks,offset; + uint32_t l,blocks,offset; - if(smb->sda_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - fflush(smb->sda_fp); - clearerr(smb->sda_fp); - blocks=smb_datblocks(length); - fseek(smb->sda_fp,0L,SEEK_END); - offset=(ftell(smb->sda_fp)/2L)*SDT_BLOCK_LEN; - for(l=0;lsda_fp)) - break; - fflush(smb->sda_fp); - if(llast_error,"writing allocation bytes"); - return(-1L); - } - return(offset); + if(smb->sda_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + fflush(smb->sda_fp); + clearerr(smb->sda_fp); + blocks=smb_datblocks(length); + fseek(smb->sda_fp,0L,SEEK_END); + offset=(ftell(smb->sda_fp)/2L)*SDT_BLOCK_LEN; + for(l=0;lsda_fp)) + break; + fflush(smb->sda_fp); + if(llast_error,"writing allocation bytes"); + return(-1L); + } + return(offset); } /****************************************************************************/ -/* De-allocates space for data */ -/* Returns non-zero on error */ +/* De-allocates space for data */ +/* Returns non-zero on error */ /****************************************************************************/ int SMBCALL smb_freemsgdat(smb_t* smb, uint32_t offset, uint32_t length - , ushort headers) + , ushort headers) { - int da_opened=0; - int retval=0; - ushort i; - uint32_t l,blocks; + int da_opened=0; + int retval=0; + ushort i; + uint32_t l,blocks; - if(smb->status.attr&SMB_HYPERALLOC) /* do nothing */ - return(0); + if(smb->status.attr&SMB_HYPERALLOC) /* do nothing */ + return(0); - blocks=smb_datblocks(length); + blocks=smb_datblocks(length); - if(smb->sda_fp==NULL) { - if((i=smb_open_da(smb))!=0) - return(i); - da_opened=1; - } + if(smb->sda_fp==NULL) { + if((i=smb_open_da(smb))!=0) + return(i); + da_opened=1; + } - clearerr(smb->sda_fp); - for(l=0;lsda_fp,((offset/SDT_BLOCK_LEN)+l)*2L,SEEK_SET)) { - sprintf(smb->last_error - ,"seeking to %ld of allocation file" - ,((offset/SDT_BLOCK_LEN)+l)*2L); - retval=1; - break; - } - if(!fread(&i,2,1,smb->sda_fp)) { - sprintf(smb->last_error,"reading allocation bytes"); - retval=2; - break; - } - if(!headers || headers>i) - i=0; /* don't want to go negative */ - else - i-=headers; - if(fseek(smb->sda_fp,-2L,SEEK_CUR)) { - sprintf(smb->last_error,"seeking backwards 2 bytes in allocation file"); - retval=3; - break; - } - if(!fwrite(&i,2,1,smb->sda_fp)) { - sprintf(smb->last_error,"writing allocation bytes"); - retval=4; - break; - } - } - fflush(smb->sda_fp); - if(da_opened) - smb_close_da(smb); - return(retval); + clearerr(smb->sda_fp); + for(l=0;lsda_fp,((offset/SDT_BLOCK_LEN)+l)*2L,SEEK_SET)) { + sprintf(smb->last_error + ,"seeking to %ld of allocation file" + ,((offset/SDT_BLOCK_LEN)+l)*2L); + retval=1; + break; + } + if(!fread(&i,2,1,smb->sda_fp)) { + sprintf(smb->last_error,"reading allocation bytes"); + retval=2; + break; + } + if(!headers || headers>i) + i=0; /* don't want to go negative */ + else + i-=headers; + if(fseek(smb->sda_fp,-2L,SEEK_CUR)) { + sprintf(smb->last_error,"seeking backwards 2 bytes in allocation file"); + retval=3; + break; + } + if(!fwrite(&i,2,1,smb->sda_fp)) { + sprintf(smb->last_error,"writing allocation bytes"); + retval=4; + break; + } + } + fflush(smb->sda_fp); + if(da_opened) + smb_close_da(smb); + return(retval); } /****************************************************************************/ /* Adds to data allocation records for blocks starting at 'offset' */ -/* Returns non-zero on error */ +/* Returns non-zero on error */ /****************************************************************************/ int SMBCALL smb_incdat(smb_t* smb, uint32_t offset, uint32_t length, ushort headers) { - ushort i; - uint32_t l,blocks; + ushort i; + uint32_t l,blocks; - if(smb->sda_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - clearerr(smb->sda_fp); - blocks=smb_datblocks(length); - for(l=0;lsda_fp,((offset/SDT_BLOCK_LEN)+l)*2L,SEEK_SET); - if(!fread(&i,2,1,smb->sda_fp)) { - sprintf(smb->last_error,"reading allocation record"); - return(1); - } - i+=headers; - fseek(smb->sda_fp,-2L,SEEK_CUR); - if(!fwrite(&i,2,1,smb->sda_fp)) { - sprintf(smb->last_error,"writing allocation record"); - return(2); - } - } - fflush(smb->sda_fp); - return(0); + if(smb->sda_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + clearerr(smb->sda_fp); + blocks=smb_datblocks(length); + for(l=0;lsda_fp,((offset/SDT_BLOCK_LEN)+l)*2L,SEEK_SET); + if(!fread(&i,2,1,smb->sda_fp)) { + sprintf(smb->last_error,"reading allocation record"); + return(1); + } + i+=headers; + fseek(smb->sda_fp,-2L,SEEK_CUR); + if(!fwrite(&i,2,1,smb->sda_fp)) { + sprintf(smb->last_error,"writing allocation record"); + return(2); + } + } + fflush(smb->sda_fp); + return(0); } /****************************************************************************/ -/* De-allocates blocks for header record */ -/* Returns non-zero on error */ +/* De-allocates blocks for header record */ +/* Returns non-zero on error */ /****************************************************************************/ int SMBCALL smb_freemsghdr(smb_t* smb, uint32_t offset, uint32_t length) { - uchar c=0; - uint32_t l,blocks; + uchar c=0; + uint32_t l,blocks; - if(smb->sha_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - clearerr(smb->sha_fp); - blocks=smb_hdrblocks(length); - fseek(smb->sha_fp,offset/SHD_BLOCK_LEN,SEEK_SET); - for(l=0;lsha_fp)) { - sprintf(smb->last_error,"writing allocation record"); - return(1); - } - fflush(smb->sha_fp); - return(0); + if(smb->sha_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + clearerr(smb->sha_fp); + blocks=smb_hdrblocks(length); + fseek(smb->sha_fp,offset/SHD_BLOCK_LEN,SEEK_SET); + for(l=0;lsha_fp)) { + sprintf(smb->last_error,"writing allocation record"); + return(1); + } + fflush(smb->sha_fp); + return(0); } /****************************************************************************/ @@ -1496,226 +1504,226 @@ int SMBCALL smb_freemsghdr(smb_t* smb, uint32_t offset, uint32_t length) /****************************************************************************/ int SMBCALL smb_freemsg(smb_t* smb, smbmsg_t* msg) { - int i; - ushort x; + int i; + ushort x; - if(smb->status.attr&SMB_HYPERALLOC) /* Nothing to do */ - return(0); + if(smb->status.attr&SMB_HYPERALLOC) /* Nothing to do */ + return(0); - for(x=0;xhdr.total_dfields;x++) { - if((i=smb_freemsgdat(smb,msg->hdr.offset+msg->dfield[x].offset - ,msg->dfield[x].length,1))!=0) - return(i); - } - return(smb_freemsghdr(smb,msg->idx.offset-smb->status.header_offset - ,msg->hdr.length)); + for(x=0;xhdr.total_dfields;x++) { + if((i=smb_freemsgdat(smb,msg->hdr.offset+msg->dfield[x].offset + ,msg->dfield[x].length,1))!=0) + return(i); + } + return(smb_freemsghdr(smb,msg->idx.offset-smb->status.header_offset + ,msg->hdr.length)); } /****************************************************************************/ -/* Finds unused space in header file based on block allocation table and */ +/* Finds unused space in header file based on block allocation table and */ /* marks space as used in allocation table. */ -/* File must be opened read/write DENY ALL */ -/* Returns offset to beginning of header (in bytes, not blocks) */ -/* Assumes smb_open_ha() has been called */ -/* smb_close_ha() should be called after */ -/* Returns -1L on error */ +/* File must be opened read/write DENY ALL */ +/* Returns offset to beginning of header (in bytes, not blocks) */ +/* Assumes smb_open_ha() has been called */ +/* smb_close_ha() should be called after */ +/* Returns -1L on error */ /****************************************************************************/ int32_t SMBCALL smb_allochdr(smb_t* smb, uint32_t length) { - uchar c; - ushort i; - uint32_t l,blocks,offset=0; + uchar c; + ushort i; + uint32_t l,blocks,offset=0; - if(smb->sha_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - blocks=smb_hdrblocks(length); - i=0; /* i is consecutive unused block counter */ - fflush(smb->sha_fp); - rewind(smb->sha_fp); - while(!feof(smb->sha_fp)) { - if(!fread(&c,1,1,smb->sha_fp)) - break; - offset+=SHD_BLOCK_LEN; - if(!c) i++; - else i=0; - if(i==blocks) { - offset-=(blocks*SHD_BLOCK_LEN); - break; - } - } - clearerr(smb->sha_fp); - fseek(smb->sha_fp,offset/SHD_BLOCK_LEN,SEEK_SET); - c=1; - for(l=0;lsha_fp)) { - sprintf(smb->last_error,"writing allocation record"); - return(-1L); - } - fflush(smb->sha_fp); - return(offset); + if(smb->sha_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + blocks=smb_hdrblocks(length); + i=0; /* i is consecutive unused block counter */ + fflush(smb->sha_fp); + rewind(smb->sha_fp); + while(!feof(smb->sha_fp)) { + if(!fread(&c,1,1,smb->sha_fp)) + break; + offset+=SHD_BLOCK_LEN; + if(!c) i++; + else i=0; + if(i==blocks) { + offset-=(blocks*SHD_BLOCK_LEN); + break; + } + } + clearerr(smb->sha_fp); + fseek(smb->sha_fp,offset/SHD_BLOCK_LEN,SEEK_SET); + c=1; + for(l=0;lsha_fp)) { + sprintf(smb->last_error,"writing allocation record"); + return(-1L); + } + fflush(smb->sha_fp); + return(offset); } /****************************************************************************/ /* Allocates space for index, but doesn't search for unused blocks */ -/* Returns -1L on error */ +/* Returns -1L on error */ /****************************************************************************/ int32_t SMBCALL smb_fallochdr(smb_t* smb, uint32_t length) { - uchar c=1; - uint32_t l,blocks,offset; + uchar c=1; + uint32_t l,blocks,offset; - if(smb->sha_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - blocks=smb_hdrblocks(length); - fflush(smb->sha_fp); - clearerr(smb->sha_fp); - fseek(smb->sha_fp,0L,SEEK_END); - offset=ftell(smb->sha_fp)*SHD_BLOCK_LEN; - for(l=0;lsha_fp)) { - sprintf(smb->last_error,"writing allocation record"); - return(-1L); - } - fflush(smb->sha_fp); - return(offset); + if(smb->sha_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + blocks=smb_hdrblocks(length); + fflush(smb->sha_fp); + clearerr(smb->sha_fp); + fseek(smb->sha_fp,0L,SEEK_END); + offset=ftell(smb->sha_fp)*SHD_BLOCK_LEN; + for(l=0;lsha_fp)) { + sprintf(smb->last_error,"writing allocation record"); + return(-1L); + } + fflush(smb->sha_fp); + return(offset); } /************************************************************************/ -/* Allocate header blocks using Hyper Allocation */ -/* this function should be most likely not be called from anywhere but */ -/* smb_addmsghdr() */ +/* Allocate header blocks using Hyper Allocation */ +/* this function should be most likely not be called from anywhere but */ +/* smb_addmsghdr() */ /************************************************************************/ int32_t SMBCALL smb_hallochdr(smb_t* smb) { - uint32_t l; + uint32_t l; - if(smb->shd_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - fflush(smb->shd_fp); - fseek(smb->shd_fp,0L,SEEK_END); - l=ftell(smb->shd_fp); - if(lstatus.header_offset) /* Header file truncated?!? */ - return(smb->status.header_offset); - while((l-smb->status.header_offset)%SHD_BLOCK_LEN) /* Even block boundry */ - l++; - return(l-smb->status.header_offset); + if(smb->shd_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + fflush(smb->shd_fp); + fseek(smb->shd_fp,0L,SEEK_END); + l=ftell(smb->shd_fp); + if(lstatus.header_offset) /* Header file truncated?!? */ + return(smb->status.header_offset); + while((l-smb->status.header_offset)%SHD_BLOCK_LEN) /* Even block boundry */ + l++; + return(l-smb->status.header_offset); } /************************************************************************/ -/* Allocate data blocks using Hyper Allocation */ -/* smb_locksmbhdr() should be called before this function and not */ -/* unlocked until all data fields for this message have been written */ -/* to the SDT file */ +/* Allocate data blocks using Hyper Allocation */ +/* smb_locksmbhdr() should be called before this function and not */ +/* unlocked until all data fields for this message have been written */ +/* to the SDT file */ /************************************************************************/ int32_t SMBCALL smb_hallocdat(smb_t* smb) { - int32_t l; + int32_t l; - if(smb->sdt_fp==NULL) { - sprintf(smb->last_error,"msgbase not open"); - return(SMB_ERR_NOT_OPEN); - } - fflush(smb->sdt_fp); - fseek(smb->sdt_fp,0L,SEEK_END); - l=ftell(smb->sdt_fp); - if(l<=0) - return(l); - while(l%SDT_BLOCK_LEN) /* Make sure even block boundry */ - l++; - return(l); + if(smb->sdt_fp==NULL) { + sprintf(smb->last_error,"msgbase not open"); + return(SMB_ERR_NOT_OPEN); + } + fflush(smb->sdt_fp); + fseek(smb->sdt_fp,0L,SEEK_END); + l=ftell(smb->sdt_fp); + if(l<=0) + return(l); + while(l%SDT_BLOCK_LEN) /* Make sure even block boundry */ + l++; + return(l); } int SMBCALL smb_feof(FILE* fp) { - return(feof(fp)); + return(feof(fp)); } int SMBCALL smb_ferror(FILE* fp) { - return(ferror(fp)); + return(ferror(fp)); } int SMBCALL smb_fflush(FILE* fp) { - return(fflush(fp)); + return(fflush(fp)); } int SMBCALL smb_fgetc(FILE* fp) { - return(fgetc(fp)); + return(fgetc(fp)); } int SMBCALL smb_fputc(int ch, FILE* fp) { - return(fputc(ch,fp)); + return(fputc(ch,fp)); } int SMBCALL smb_fseek(FILE* fp, int32_t offset, int whence) { - return(fseek(fp,offset,whence)); + return(fseek(fp,offset,whence)); } int32_t SMBCALL smb_ftell(FILE* fp) { - return(ftell(fp)); + return(ftell(fp)); } int32_t SMBCALL smb_fgetlength(FILE* fp) { - return(filelength(fileno(fp))); + return(filelength(fileno(fp))); } int SMBCALL smb_fsetlength(FILE* fp, int32_t length) { - return(chsize(fileno(fp),length)); + return(chsize(fileno(fp),length)); } void SMBCALL smb_rewind(FILE* fp) { - rewind(fp); + rewind(fp); } void SMBCALL smb_clearerr(FILE* fp) { - clearerr(fp); + clearerr(fp); } int32_t SMBCALL smb_fread(void HUGE16* buf, int32_t bytes, FILE* fp) { #ifdef __FLAT__ - return(fread(buf,1,bytes,fp)); + return(fread(buf,1,bytes,fp)); #else - int32_t count; + int32_t count; - for(count=bytes;count>0x7fff;count-=0x7fff,(char*)buf+=0x7fff) - if(fread((char*)buf,1,0x7fff,fp)!=0x7fff) - return(bytes-count); - if(fread((char*)buf,1,(size_t)count,fp)!=(size_t)count) - return(bytes-count); - return(bytes); + for(count=bytes;count>0x7fff;count-=0x7fff,(char*)buf+=0x7fff) + if(fread((char*)buf,1,0x7fff,fp)!=0x7fff) + return(bytes-count); + if(fread((char*)buf,1,(size_t)count,fp)!=(size_t)count) + return(bytes-count); + return(bytes); #endif } int32_t SMBCALL smb_fwrite(void HUGE16* buf, int32_t bytes, FILE* fp) { #ifdef __FLAT__ - return(fwrite(buf,1,bytes,fp)); + return(fwrite(buf,1,bytes,fp)); #else - int32_t count; + int32_t count; - for(count=bytes;count>0x7fff;count-=0x7fff,(char*)buf+=0x7fff) - if(fwrite((char*)buf,1,0x7fff,fp)!=0x7fff) - return(bytes-count); - if(fwrite((char*)buf,1,(size_t)count,fp)!=(size_t)count) - return(bytes-count); - return(bytes); + for(count=bytes;count>0x7fff;count-=0x7fff,(char*)buf+=0x7fff) + if(fwrite((char*)buf,1,0x7fff,fp)!=0x7fff) + return(bytes-count); + if(fwrite((char*)buf,1,(size_t)count,fp)!=(size_t)count) + return(bytes-count); + return(bytes); #endif } diff --git a/goldnode/goldnode.cpp b/goldnode/goldnode.cpp index 12738cb..9be4ea8 100644 --- a/goldnode/goldnode.cpp +++ b/goldnode/goldnode.cpp @@ -143,7 +143,7 @@ const word _TEST = 777; static std::string nodepath; // Path to the nodelist files -static time_t runtime = 0; +static time32_t runtime = 0; static int sh_mod = SH_DENYWR; static bool fidouser = false; static Path fidouserlst; @@ -1017,7 +1017,7 @@ static void read_nodelists() { } // Note compile time - runtime = time(NULL) - runtime; + runtime = gtime(NULL) - runtime; if(not quiet) { if(dups) { @@ -1051,7 +1051,7 @@ static void check_nodelists(bool force) { strcpy(ext, ".*"); gposixdir f(newpath); const gdirentry *de; - time_t listtime = 0; + time32_t listtime = 0; bool listdefined = false; while((de = f.nextentry(buf)) != NULL) if(atoi(de->name.c_str()+extpos)) {