Skip to content

Commit

Permalink
Merge pull request #17 from M-griffin/feature/ArchCleanUp
Browse files Browse the repository at this point in the history
MSGID and REPLYID fixes for Network Messages.
  • Loading branch information
M-griffin committed Jun 18, 2017
2 parents b1fb066 + b69ca4c commit 6ccd59f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 21 deletions.
2 changes: 1 addition & 1 deletion linux/enthral/enthral.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=
Date :=06/11/17
Date :=06/17/17
CodeLitePath :=/home/blue/.codelite
LinkerName :=/usr/bin/g++
SharedObjectLinkerName :=/usr/bin/g++ -shared -fPIC
Expand Down
67 changes: 58 additions & 9 deletions src/mb_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
# include <cstdio>
# include <cstring>
# include <cstdlib>

# include <cctype>
# include <string>
# include <iomanip>
# include <iostream>

using namespace std;

Expand Down Expand Up @@ -60,6 +62,44 @@ char *mbapi_jam::faddr2char(char *s,fidoaddr *fa)
return(s);
}


// http://blog.refu.co/?p=804
static char hexset [] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9' ,'A', 'B', 'C', 'D', 'E', 'F' };

int uintToHexStr(unsigned long num, char* buff)
{
int len = 0;
do
{
buff[len] = hexset[num & 0xF];
len++;
num = num >> 4;

} while(num != 0);

for(int i = 0; i < len / 2; i++)
{
buff[i] ^= buff[len-i - 1];
buff[len-i - 1] ^= buff[i];
buff[i] ^= buff[len-i -1];
}

buff[len] = '\0';

// Move all Hex Letters to Lowercase.
for (int i = 0; i < len; i++)
{
if (buff[i] >= 'A' && buff[i] <= 'Z') {
buff[i] += 32;
}
}


return len;
}


/**
* Message API - Save JAM Message
*/
Expand All @@ -68,6 +108,10 @@ int mbapi_jam::SaveMsg(unsigned long msgarea, unsigned long msgnum, int NewReply
MemMessage mm;
mm.msgnum = msgnum;

//enough for 64 bits integer
char msgIdbuff[16] = {0};
char newMsgId[200] = {0};

if(mr.Kind == NETMAIL) {
mm.Area[0] = 0;
} else {
Expand Down Expand Up @@ -99,8 +143,8 @@ int mbapi_jam::SaveMsg(unsigned long msgarea, unsigned long msgnum, int NewReply
mm.TextChunks = buff;

char adrs[21]= {0};
unsigned long num;
unsigned long MsgId;
unsigned long num = 0;
unsigned long MsgId = 0;

time((time_t *)&num);

Expand All @@ -111,19 +155,24 @@ int mbapi_jam::SaveMsg(unsigned long msgarea, unsigned long msgnum, int NewReply
mm.REPLY_CRC = 0;
mm.MSGID_CRC = 0;

sprintf((char *)mm.MSGID,"%s %ld", (const char *)adrs, num);
uintToHexStr(num, msgIdbuff);

std::string tmpMsgId;
sprintf((char *)newMsgId,"%s@%s %8.8s", (const char *)mr.mbfile, (const char *)adrs, msgIdbuff);
strncpy((char *)mm.MSGID, newMsgId, 79);

std::string tmpMsgId = "";
if (NewReply) {
MsgId = jamapi_readmsgid(&mr,msgnum,tmpMsgId);
MsgId = jamapi_readmsgid(&mr, msgnum, tmpMsgId);
sprintf((char *)mm.REPLY,"%s",(char *)tmpMsgId.c_str());
mm.REPLY_CRC = MsgId; // keep as CRC32, no need to convert back and forth.
} else {
tmpMsgId.clear();
sprintf((char *)mm.REPLY,"%s",(char *)tmpMsgId.c_str());
}

return (jamapi_writemsg(&mm, &mr));
int result = jamapi_writemsg(&mm, &mr);

return (result);
}

/**
Expand Down Expand Up @@ -581,9 +630,9 @@ void mbapi_jam::MsgSetupTxt()
if(mLink.current_node == 0) {
break;
}

// And Not At top of list, don't delete lines below
tmp = mLink.current_node;
tmp = mLink.current_node;

if (mLink.current_node->up_link == 0) break;
mLink.current_node = mLink.current_node->up_link;
Expand Down
22 changes: 13 additions & 9 deletions src/mb_jam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

# include <vector>
# include <string>
# include <iostream>

# define ulong unsigned long

Expand Down Expand Up @@ -752,7 +753,7 @@ BOOL jamapi_writemsg(struct MemMessage *mm, mb_list_rec *area)

// _s.errlog((char *)"4. MB_JAM() - TextChunks.size()");
msgsize = (uint32_t)mm->TextChunks.size();

// Later on convert this to string for unicode support aginst char *;)
if(msgsize != 0) {
msgtext = new uint8_t [msgsize]; // (uint8_t *)osAlloc(msgsize)))
Expand All @@ -765,7 +766,7 @@ BOOL jamapi_writemsg(struct MemMessage *mm, mb_list_rec *area)
ja = 0;
return(FALSE);
}
} else { // Can;t save message with no text!
} else { // Can;t save message with no text!
JAM_DelSubPacket(SubPacket_PS);
JAM_CloseMB(ja->Base_PS);
free(ja->Base_PS);
Expand All @@ -774,11 +775,11 @@ BOOL jamapi_writemsg(struct MemMessage *mm, mb_list_rec *area)
return(FALSE);
}


// _s.errlog((char *)"3. MB_JAM() - Do Header");
// Do header
// Header_S.DateProcessed = NULL;
// Header_S.DateWritten = time(NULL); //FidoToTime(mm->DateTime);


// Damned time zones... dates should be in local time in JAM
Header_S.DateProcessed = 0L; //NULL; //mm->DateTime; // Processed for Crashmail!
Expand All @@ -787,10 +788,13 @@ BOOL jamapi_writemsg(struct MemMessage *mm, mb_list_rec *area)
Header_S.Cost = mm->Cost;

Header_S.MsgIdCRC = JAM_Crc32(mm->MSGID,strlen((char *)mm->MSGID));
Header_S.ReplyCRC = JAM_Crc32(mm->REPLY,strlen((char *)mm->REPLY));

jam_addfield(SubPacket_PS,JAMSFLD_MSGID,mm->MSGID);
jam_addfield(SubPacket_PS,JAMSFLD_REPLYID,mm->REPLY);

if (strlen((char *)mm->REPLY) > 0) {
Header_S.ReplyCRC = JAM_Crc32(mm->REPLY,strlen((char *)mm->REPLY));
jam_addfield(SubPacket_PS,JAMSFLD_REPLYID,mm->REPLY);
}

jam_addfield(SubPacket_PS,JAMSFLD_PID, (uint8_t *)BBSVERSION);

// _s.errlog((char *)"Write: F: %s, T: %s, S: %s",(char *)mm->From,(char *)mm->To,(char *)mm->Subject);
Expand Down Expand Up @@ -1034,7 +1038,7 @@ BOOL jamapi_writemsg(struct MemMessage *mm, mb_list_rec *area)
}

// _s.errlog((char *)"3. MB_JAM() - AddMessage!");
res=JAM_AddMessage(ja->Base_PS,&Header_S,SubPacket_PS,msgtext,msgpos);
res = JAM_AddMessage(ja->Base_PS,&Header_S,SubPacket_PS,msgtext,msgpos);

// _s.errlog((char *)"3. MB_JAM() - UnLockMB");
JAM_UnlockMB(ja->Base_PS);
Expand Down Expand Up @@ -2069,8 +2073,8 @@ BOOL jamapi_readmsg(mb_list_rec *area, uint32_t num, struct MemMessage *mm, int
mystrncpy(mm->Subject,buf,72);
break;

/* Make this a sysop toggle.
WE are only reading a message.
/* Make this a sysop toggle.
// WE are only reading a message.
case JAMSFLD_MSGID:
Expand Down
2 changes: 1 addition & 1 deletion src/msg_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ void msg_read::DoPost(int mbnum, int Reply)
strcpy((char*)xmsg.subj, mHLocal.subj);

memset(&text,0,sizeof(text));
SaveMsg(mbnum,MI.cur_msg+1,Reply);
SaveMsg(mbnum, MI.cur_msg+1, Reply);

_lang.lang_get(text,34);
pipe2ansi(text);
Expand Down
2 changes: 1 addition & 1 deletion src/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

using namespace std;

# define BBSVERSION "Enthral BBS v.700"
# define BBSVERSION "Enthral BBS 0.700.1"
extern char OSSYSTEM[1024];
extern int UTF8Output;

Expand Down

0 comments on commit 6ccd59f

Please sign in to comment.