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 compiling on NetBSD 3.1.
Catch SIGIOT.
Use both CRC and User ID to search lastread record.
mbnewusr:
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
@ -341,21 +380,22 @@ void JAM_DeleteJAM(char *Base)
*/
int JAM_GetLastRead(lastread *LR)
{
lastread lr;
lastread lr;
LastReadRec = 0L;
lseek(fdJlr, 0, SEEK_SET);
LastReadRec = 0L;
lseek(fdJlr, 0, SEEK_SET);
while (read(fdJlr, &lr, sizeof(lastread)) == sizeof(lastread)) {
if (lr.UserID == LR->UserID) {
LR->LastReadMsg = lr.LastReadMsg;
LR->HighReadMsg = lr.HighReadMsg;
return TRUE;
}
LastReadRec++;
while (read(fdJlr, &lr, sizeof(lastread)) == sizeof(lastread)) {
if (lr.UserID == LR->UserID) {
LR->LastReadMsg = lr.LastReadMsg;
LR->HighReadMsg = lr.HighReadMsg;
return TRUE;
}
LastReadRec++;
}
return FALSE;
return FALSE;
}

View File

@ -572,9 +572,10 @@ char *ControlCodeU(int ch)
char *ControlCodeK(int ch)
{
FILE *pCallerLog;
char sDataFile[PATH_MAX];
char sDataFile[PATH_MAX], *p;
static char temp[81];
lastread LR;
unsigned int mycrc;
switch (toupper(ch)) {
case 'A':
@ -632,7 +633,11 @@ char *ControlCodeK(int ch)
break;
case 'M':
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_Open(sMsgAreaBase)) {
if (Msg_GetLastRead(&LR) == TRUE) {
if (LR.HighReadMsg > MsgBase.Highest)
@ -655,7 +660,11 @@ char *ControlCodeK(int ch)
case 'P':
SetEmailArea(sMailbox);
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_Open(sMailpath)) {
if (Msg_GetLastRead(&LR) == TRUE) {
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;
lastread LR;
unsigned int mycrc;
LastNum = Num;
iLineCount = 7;
@ -518,30 +519,32 @@ int Read_a_Email(unsigned int Num)
/*
* Update lastread pointer.
*/
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
if (Msg_Lock(30L)) {
LR.UserID = grecno;
p = xstrcpy(exitinfo.sUserName);
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR) == TRUE) {
LR.LastReadMsg = Num;
if (Num > LR.HighReadMsg)
LR.HighReadMsg = Num;
if (LR.HighReadMsg > EmailBase.Highest)
LR.HighReadMsg = EmailBase.Highest;
LR.UserCRC = StringCRC32(tl(p));
LR.UserCRC = mycrc;
if (!Msg_SetLastRead(LR))
WriteError("Error update lastread");
} else {
/*
* Append new lastread pointer
*/
LR.UserCRC = StringCRC32(tl(p));
LR.UserCRC = mycrc;
LR.UserID = grecno;
LR.LastReadMsg = Num;
LR.HighReadMsg = Num;
if (!Msg_NewLastRead(LR))
WriteError("Can't append lastread");
}
free(p);
Msg_UnLock();
}
@ -631,8 +634,8 @@ int EmailPanel(void)
*/
void Read_Email(void)
{
char *temp;
unsigned int Start;
char *temp, *p;
unsigned int Start, mycrc;
lastread LR;
if (HasNoEmail())
@ -649,8 +652,12 @@ void Read_Email(void)
* Check for lastread pointer, suggest lastread number for start.
*/
Start = EmailBase.Lowest;
p = xstrcpy(exitinfo.sUserName);
mycrc = StringCRC32(tl(p));
free(p);
if (Msg_Open(sMailpath)) {
LR.UserID = grecno;
LR.UserCRC = mycrc;
if (Msg_GetLastRead(&LR))
Start = LR.HighReadMsg + 1;
else

View File

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

View File

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