Use both CRC and User ID to search lastread record

This commit is contained in:
Michiel Broek 2007-09-02 15:04:35 +00:00
parent 1a9eed3a8e
commit 9b545491ca
6 changed files with 143 additions and 39 deletions

View File

@ -64,6 +64,7 @@ v0.91.10 21-Aug-2007
Fixed a lot of compiler warnings. Fixed a lot of compiler warnings.
Fixed compiling on NetBSD 3.1. Fixed compiling on NetBSD 3.1.
Catch SIGIOT. Catch SIGIOT.
Use both CRC and User ID to search lastread record.
mbnewusr: mbnewusr:
Catch SIGIOT. Catch SIGIOT.

View File

@ -120,6 +120,45 @@ void JAMset_flags()
int JAM_SearchUser(unsigned int crcval)
{
char *temp;
FILE *fp;
struct userhdr usrhdr;
struct userrec usr;
unsigned int mycrc;
int rc = 0;
if (crcval == 0)
return -1;
temp = calloc(PATH_MAX, sizeof(char));
snprintf(temp, PATH_MAX -1, "%s/etc/users.data", getenv("MBSE_ROOT"));
if ((fp = fopen(temp, "r")) == NULL) {
free(temp);
return -1;
}
free(temp);
fread(&usrhdr, sizeof(usrhdr), 1, fp);
while (fread(&usr, usrhdr.recsize, 1, fp) == 1) {
mycrc = StringCRC32(tl(usr.sUserName));
if (mycrc == crcval) {
fclose(fp);
return rc;
}
rc++;
}
/*
* Nothing found
*/
fclose(fp);
return -1;
}
/* /*
* Add a message, the structure msg must contain all needed * Add a message, the structure msg must contain all needed
@ -341,21 +380,22 @@ void JAM_DeleteJAM(char *Base)
*/ */
int JAM_GetLastRead(lastread *LR) int JAM_GetLastRead(lastread *LR)
{ {
lastread lr; lastread lr;
LastReadRec = 0L; LastReadRec = 0L;
lseek(fdJlr, 0, SEEK_SET); lseek(fdJlr, 0, SEEK_SET);
while (read(fdJlr, &lr, sizeof(lastread)) == sizeof(lastread)) { while (read(fdJlr, &lr, sizeof(lastread)) == sizeof(lastread)) {
if (lr.UserID == LR->UserID) { if (lr.UserID == LR->UserID) {
LR->LastReadMsg = lr.LastReadMsg; LR->LastReadMsg = lr.LastReadMsg;
LR->HighReadMsg = lr.HighReadMsg; LR->HighReadMsg = lr.HighReadMsg;
return TRUE; return TRUE;
}
LastReadRec++;
} }
LastReadRec++;
}
return FALSE; return FALSE;
} }

View File

@ -572,9 +572,10 @@ char *ControlCodeU(int ch)
char *ControlCodeK(int ch) char *ControlCodeK(int ch)
{ {
FILE *pCallerLog; FILE *pCallerLog;
char sDataFile[PATH_MAX]; char sDataFile[PATH_MAX], *p;
static char temp[81]; static char temp[81];
lastread LR; lastread LR;
unsigned int mycrc;
switch (toupper(ch)) { switch (toupper(ch)) {
case 'A': case 'A':
@ -632,7 +633,11 @@ char *ControlCodeK(int ch)
break; break;
case 'M': case 'M':
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_Open(sMsgAreaBase)) { if (Msg_Open(sMsgAreaBase)) {
if (Msg_GetLastRead(&LR) == TRUE) { if (Msg_GetLastRead(&LR) == TRUE) {
if (LR.HighReadMsg > MsgBase.Highest) if (LR.HighReadMsg > MsgBase.Highest)
@ -655,7 +660,11 @@ char *ControlCodeK(int ch)
case 'P': case 'P':
SetEmailArea(sMailbox); SetEmailArea(sMailbox);
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_Open(sMailpath)) { if (Msg_Open(sMailpath)) {
if (Msg_GetLastRead(&LR) == TRUE) { if (Msg_GetLastRead(&LR) == TRUE) {
if (LR.HighReadMsg > EmailBase.Highest) if (LR.HighReadMsg > EmailBase.Highest)

View File

@ -381,6 +381,7 @@ int Read_a_Email(unsigned int Num)
{ {
char *p = NULL, *fn, *charset = NULL, *charsin = NULL; char *p = NULL, *fn, *charset = NULL, *charsin = NULL;
lastread LR; lastread LR;
unsigned int mycrc;
LastNum = Num; LastNum = Num;
iLineCount = 7; iLineCount = 7;
@ -518,30 +519,32 @@ int Read_a_Email(unsigned int Num)
/* /*
* Update lastread pointer. * Update lastread pointer.
*/ */
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
if (Msg_Lock(30L)) { if (Msg_Lock(30L)) {
LR.UserID = grecno; LR.UserID = grecno;
p = xstrcpy(exitinfo.sUserName); LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR) == TRUE) { if (Msg_GetLastRead(&LR) == TRUE) {
LR.LastReadMsg = Num; LR.LastReadMsg = Num;
if (Num > LR.HighReadMsg) if (Num > LR.HighReadMsg)
LR.HighReadMsg = Num; LR.HighReadMsg = Num;
if (LR.HighReadMsg > EmailBase.Highest) if (LR.HighReadMsg > EmailBase.Highest)
LR.HighReadMsg = EmailBase.Highest; LR.HighReadMsg = EmailBase.Highest;
LR.UserCRC = StringCRC32(tl(p)); LR.UserCRC = mycrc;
if (!Msg_SetLastRead(LR)) if (!Msg_SetLastRead(LR))
WriteError("Error update lastread"); WriteError("Error update lastread");
} else { } else {
/* /*
* Append new lastread pointer * Append new lastread pointer
*/ */
LR.UserCRC = StringCRC32(tl(p)); LR.UserCRC = mycrc;
LR.UserID = grecno; LR.UserID = grecno;
LR.LastReadMsg = Num; LR.LastReadMsg = Num;
LR.HighReadMsg = Num; LR.HighReadMsg = Num;
if (!Msg_NewLastRead(LR)) if (!Msg_NewLastRead(LR))
WriteError("Can't append lastread"); WriteError("Can't append lastread");
} }
free(p);
Msg_UnLock(); Msg_UnLock();
} }
@ -631,8 +634,8 @@ int EmailPanel(void)
*/ */
void Read_Email(void) void Read_Email(void)
{ {
char *temp; char *temp, *p;
unsigned int Start; unsigned int Start, mycrc;
lastread LR; lastread LR;
if (HasNoEmail()) if (HasNoEmail())
@ -649,8 +652,12 @@ void Read_Email(void)
* Check for lastread pointer, suggest lastread number for start. * Check for lastread pointer, suggest lastread number for start.
*/ */
Start = EmailBase.Lowest; Start = EmailBase.Lowest;
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
if (Msg_Open(sMailpath)) { if (Msg_Open(sMailpath)) {
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR)) if (Msg_GetLastRead(&LR))
Start = LR.HighReadMsg + 1; Start = LR.HighReadMsg + 1;
else else

View File

@ -1163,6 +1163,7 @@ int Read_a_Msg(unsigned int Num, int UpdateLR)
char *p = NULL, *fn, *charset = NULL, *charsin = NULL; char *p = NULL, *fn, *charset = NULL, *charsin = NULL;
int ShowMsg = TRUE; int ShowMsg = TRUE;
lastread LR; lastread LR;
unsigned int mycrc;
LastNum = Num; LastNum = Num;
iLineCount = 7; iLineCount = 7;
@ -1335,29 +1336,31 @@ int Read_a_Msg(unsigned int Num, int UpdateLR)
* Update lastread pointer if needed. Netmail boards are always updated. * Update lastread pointer if needed. Netmail boards are always updated.
*/ */
if (Msg_Lock(30L) && (UpdateLR || msgs.Type == NETMAIL)) { if (Msg_Lock(30L) && (UpdateLR || msgs.Type == NETMAIL)) {
LR.UserID = grecno;
p = xstrcpy(exitinfo.sUserName); p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR) == TRUE) { if (Msg_GetLastRead(&LR) == TRUE) {
LR.LastReadMsg = Num; LR.LastReadMsg = Num;
if (Num > LR.HighReadMsg) if (Num > LR.HighReadMsg)
LR.HighReadMsg = Num; LR.HighReadMsg = Num;
if (LR.HighReadMsg > MsgBase.Highest) if (LR.HighReadMsg > MsgBase.Highest)
LR.HighReadMsg = MsgBase.Highest; LR.HighReadMsg = MsgBase.Highest;
LR.UserCRC = StringCRC32(tl(p)); LR.UserCRC = mycrc;
if (!Msg_SetLastRead(LR)) if (!Msg_SetLastRead(LR))
WriteError("Error update lastread"); WriteError("Error update lastread");
} else { } else {
/* /*
* Append new lastread pointer * Append new lastread pointer
*/ */
LR.UserCRC = StringCRC32(tl(p)); LR.UserCRC = mycrc;
LR.UserID = grecno; LR.UserID = grecno;
LR.LastReadMsg = Num; LR.LastReadMsg = Num;
LR.HighReadMsg = Num; LR.HighReadMsg = Num;
if (!Msg_NewLastRead(LR)) if (!Msg_NewLastRead(LR))
WriteError("Can't append lastread"); WriteError("Can't append lastread");
} }
free(p);
Msg_UnLock(); Msg_UnLock();
} }
@ -1372,8 +1375,8 @@ int Read_a_Msg(unsigned int Num, int UpdateLR)
*/ */
void Read_Msgs() void Read_Msgs()
{ {
char *temp; char *temp, *p;
unsigned int Start; unsigned int Start, mycrc;
lastread LR; lastread LR;
temp = calloc(81, sizeof(char)); temp = calloc(81, sizeof(char));
@ -1388,7 +1391,11 @@ void Read_Msgs()
*/ */
Start = MsgBase.Lowest; Start = MsgBase.Lowest;
if (Msg_Open(sMsgAreaBase)) { if (Msg_Open(sMsgAreaBase)) {
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR)) if (Msg_GetLastRead(&LR))
Start = LR.HighReadMsg + 1; Start = LR.HighReadMsg + 1;
else else
@ -1990,8 +1997,9 @@ void MsgArea_List(char *Option)
int iGotArea = FALSE; /* Flag to check if user typed in area */ int iGotArea = FALSE; /* Flag to check if user typed in area */
int iCheckNew = FALSE; /* Flag to check for new mail in area */ int iCheckNew = FALSE; /* Flag to check for new mail in area */
int offset; int offset;
char *temp, msg[81]; char *temp, msg[81], *p;
lastread LR; lastread LR;
unsigned int mycrc;
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
snprintf(temp, PATH_MAX, "%s/etc/mareas.data", getenv("MBSE_ROOT")); snprintf(temp, PATH_MAX, "%s/etc/mareas.data", getenv("MBSE_ROOT"));
@ -2052,7 +2060,11 @@ void MsgArea_List(char *Option)
if ((Access(exitinfo.Security, msgs.RDSec)) && (msgs.Active) && (strlen(msgs.Password) == 0)) { if ((Access(exitinfo.Security, msgs.RDSec)) && (msgs.Active) && (strlen(msgs.Password) == 0)) {
if (Msg_Open(msgs.Base)) { if (Msg_Open(msgs.Base)) {
MsgBase.Highest = Msg_Highest(); MsgBase.Highest = Msg_Highest();
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR) != TRUE) { if (Msg_GetLastRead(&LR) != TRUE) {
LR.HighReadMsg = 0; LR.HighReadMsg = 0;
} }
@ -2093,7 +2105,11 @@ void MsgArea_List(char *Option)
if ((Access(exitinfo.Security, msgs.RDSec)) && (msgs.Active) && (strlen(msgs.Password) == 0)) { if ((Access(exitinfo.Security, msgs.RDSec)) && (msgs.Active) && (strlen(msgs.Password) == 0)) {
if (Msg_Open(msgs.Base)) { if (Msg_Open(msgs.Base)) {
MsgBase.Highest = Msg_Highest(); MsgBase.Highest = Msg_Highest();
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR) != TRUE ){ if (Msg_GetLastRead(&LR) != TRUE ){
LR.HighReadMsg = 0; LR.HighReadMsg = 0;
} }
@ -2175,7 +2191,11 @@ void MsgArea_List(char *Option)
if (iCheckNew) { if (iCheckNew) {
if (Msg_Open(msgs.Base)) { if (Msg_Open(msgs.Base)) {
MsgBase.Highest = Msg_Highest(); MsgBase.Highest = Msg_Highest();
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR) != TRUE) { if (Msg_GetLastRead(&LR) != TRUE) {
LR.HighReadMsg = 0; LR.HighReadMsg = 0;
} }
@ -2394,8 +2414,8 @@ void CheckMail()
{ {
FILE *pMsgArea, *Tmp; FILE *pMsgArea, *Tmp;
int x, Found = 0, Color, Count = 0, Reading, OldMsgArea; int x, Found = 0, Color, Count = 0, Reading, OldMsgArea;
char *temp, *sFileName, msg[81]; char *temp, *sFileName, msg[81], *p;
unsigned int i, Start; unsigned int i, Start, mycrc;
typedef struct _Mailrec { typedef struct _Mailrec {
int Area; int Area;
unsigned int Msg; unsigned int Msg;
@ -2438,7 +2458,11 @@ void CheckMail()
* Check lastread pointer, if none found start * Check lastread pointer, if none found start
* at the begin of the messagebase. * at the begin of the messagebase.
*/ */
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR)) if (Msg_GetLastRead(&LR))
Start = LR.HighReadMsg + 1; Start = LR.HighReadMsg + 1;
else else
@ -2516,7 +2540,11 @@ void CheckMail()
* Check lastread pointer, if none found start * Check lastread pointer, if none found start
* at the begin of the messagebase. * at the begin of the messagebase.
*/ */
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR)) if (Msg_GetLastRead(&LR))
Start = LR.HighReadMsg + 1; Start = LR.HighReadMsg + 1;
else else

View File

@ -146,6 +146,7 @@ void UpdateLR(msg_high *mhl, FILE *mf)
{ {
char *p; char *p;
msg_high *tmp; msg_high *tmp;
unsigned int mycrc;
/* Updating lastread pointer */ /* Updating lastread pointer */
poutCR(YELLOW, BLACK, (char *)Language(449)); poutCR(YELLOW, BLACK, (char *)Language(449));
@ -160,8 +161,11 @@ void UpdateLR(msg_high *mhl, FILE *mf)
if (tmp->Personal) if (tmp->Personal)
Syslog('?', "Personal messages to update"); Syslog('?', "Personal messages to update");
LR.UserID = grecno;
p = xstrcpy(exitinfo.sUserName); p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR) == TRUE) { if (Msg_GetLastRead(&LR) == TRUE) {
LR.LastReadMsg = tmp->LastMsg; LR.LastReadMsg = tmp->LastMsg;
if (tmp->LastMsg > LR.HighReadMsg) if (tmp->LastMsg > LR.HighReadMsg)
@ -170,21 +174,20 @@ void UpdateLR(msg_high *mhl, FILE *mf)
Syslog('?', "Highread was too high"); Syslog('?', "Highread was too high");
LR.HighReadMsg = Msg_Highest(); LR.HighReadMsg = Msg_Highest();
} }
LR.UserCRC = StringCRC32(tl(p)); LR.UserCRC = mycrc;
if (!Msg_SetLastRead(LR)) if (!Msg_SetLastRead(LR))
WriteError("Error update lastread"); WriteError("Error update lastread");
} else { } else {
/* /*
* Append new lastread pointer * Append new lastread pointer
*/ */
LR.UserCRC = StringCRC32(tl(p)); LR.UserCRC = mycrc;
LR.UserID = grecno; LR.UserID = grecno;
LR.LastReadMsg = tmp->LastMsg; LR.LastReadMsg = tmp->LastMsg;
LR.HighReadMsg = tmp->LastMsg; LR.HighReadMsg = tmp->LastMsg;
if (!Msg_NewLastRead(LR)) if (!Msg_NewLastRead(LR))
WriteError("Can't append new lastread"); WriteError("Can't append new lastread");
} }
free(p);
Msg_UnLock(); Msg_UnLock();
} }
Msg_Close(); Msg_Close();
@ -811,8 +814,8 @@ void OLR_ViewTags()
int OLR_Prescan() int OLR_Prescan()
{ {
unsigned short RetVal = FALSE, Areas; unsigned short RetVal = FALSE, Areas;
unsigned int Number; unsigned int Number, mycrc;
char *Temp, msg[81]; char *Temp, msg[81], *p;
FILE *mf, *tf; FILE *mf, *tf;
int x; int x;
@ -851,7 +854,11 @@ int OLR_Prescan()
pout(LIGHTCYAN, BLACK, msg); pout(LIGHTCYAN, BLACK, msg);
memset(&LR, 0, sizeof(LR)); memset(&LR, 0, sizeof(LR));
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR)) if (Msg_GetLastRead(&LR))
Number = LR.HighReadMsg; Number = LR.HighReadMsg;
else else
@ -1155,13 +1162,13 @@ void OLR_DownBW()
{ {
struct tm *tp; struct tm *tp;
time_t Now; time_t Now;
char Pktname[32], *Work, *Temp, *cwd = NULL; char Pktname[32], *Work, *Temp, *cwd = NULL, *p;
int Area = 0; int Area = 0;
int RetVal = FALSE, rc = 0; int RetVal = FALSE, rc = 0;
FILE *fp, *tf, *mf, *af; FILE *fp, *tf, *mf, *af;
INF_HEADER Inf; INF_HEADER Inf;
INF_AREA_INFO AreaInf; INF_AREA_INFO AreaInf;
unsigned int Start, High; unsigned int Start, High, mycrc;
msg_high *mhl = NULL; msg_high *mhl = NULL;
if (strlen(CFG.bbsid) == 0) { if (strlen(CFG.bbsid) == 0) {
@ -1332,7 +1339,11 @@ void OLR_DownBW()
Current = Personal = 0; Current = Personal = 0;
if (Msg_Highest() != 0) { if (Msg_Highest() != 0) {
memset(&LR, 0, sizeof(LR)); memset(&LR, 0, sizeof(LR));
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR)) if (Msg_GetLastRead(&LR))
Start = LR.HighReadMsg; Start = LR.HighReadMsg;
else else
@ -1931,10 +1942,10 @@ void OLR_DownQWK(void)
{ {
struct tm *tp; struct tm *tp;
time_t Now; time_t Now;
char Pktname[32], *cwd = NULL, *Work, *Temp; char Pktname[32], *cwd = NULL, *Work, *Temp, *p;
int Area = 0, i, rc = 0; int Area = 0, i, rc = 0;
FILE *fp = NULL, *tf, *mf, *af; FILE *fp = NULL, *tf, *mf, *af;
unsigned int Start, High; unsigned int Start, High, mycrc;
msg_high *tmp, *mhl = NULL; msg_high *tmp, *mhl = NULL;
if (strlen(CFG.bbsid) == 0) { if (strlen(CFG.bbsid) == 0) {
@ -1999,7 +2010,11 @@ void OLR_DownQWK(void)
Current = Personal = 0; Current = Personal = 0;
if (Msg_Highest() != 0) { if (Msg_Highest() != 0) {
memset(&LR, 0, sizeof(LR)); memset(&LR, 0, sizeof(LR));
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno; LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR)) if (Msg_GetLastRead(&LR))
Start = LR.HighReadMsg; Start = LR.HighReadMsg;
else else
@ -2643,10 +2658,10 @@ void OLR_DownASCII(void)
{ {
struct tm *tp; struct tm *tp;
time_t Now; time_t Now;
char Pktname[32], *Work, *Temp, *cwd = NULL, Atag[60], Kinds[12]; char Pktname[32], *Work, *Temp, *cwd = NULL, Atag[60], Kinds[12], *p;
int Area = 0, i, rc = 0; int Area = 0, i, rc = 0;
FILE *fp = NULL, *tf, *mf, *af, *inf; FILE *fp = NULL, *tf, *mf, *af, *inf;
unsigned int Start, High; unsigned int Start, High, mycrc;
msg_high *tmp, *mhl = NULL; msg_high *tmp, *mhl = NULL;
if (strlen(CFG.bbsid) == 0) { if (strlen(CFG.bbsid) == 0) {
@ -2764,6 +2779,10 @@ void OLR_DownASCII(void)
Current = Personal = 0; Current = Personal = 0;
if (Msg_Highest() != 0) { if (Msg_Highest() != 0) {
memset(&LR, 0, sizeof(LR)); memset(&LR, 0, sizeof(LR));
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserCRC = mycrc;
LR.UserID = grecno; LR.UserID = grecno;
if (Msg_GetLastRead(&LR)) if (Msg_GetLastRead(&LR))
Start = LR.HighReadMsg; Start = LR.HighReadMsg;