Commit 742f1901 authored by rswindell's avatar rswindell
Browse files

loadmsg() now returns < 0 on error, >= 0 on success, this change was necessary

to be able to delete messages that have no hfields, for example, with sub-op
'D' command.
Now support polls with comments (displayed before the poll answers).
Poll results/statistics are only displayed to sub-ops and users who have voted
already. This may be optoinal behavior determined by the pollster in the future.
Sub-ops can now add comments to any post using the 'A' command from the
[O]perator menu - use with caution.
parent 85132fdd
......@@ -42,7 +42,7 @@
/****************************************************************************/
/* Loads an SMB message from the open msg base the fastest way possible */
/* first by offset, and if that's the wrong message, then by number. */
/* Returns 1 if the message was loaded and left locked, otherwise */
/* Returns >=0 if the message was loaded and left locked, otherwise < 0. */
/* !WARNING!: If you're going to write the msg index back to disk, you must */
/* Call this function with a msg->idx.offset of 0 (so msg->offset will be */
/* initialized correctly) */
......@@ -54,15 +54,15 @@ int sbbs_t::loadmsg(smbmsg_t *msg, ulong number)
if(msg->idx.offset) { /* Load by offset if specified */
if((i=smb_lockmsghdr(&smb,msg))!=0) {
if((i=smb_lockmsghdr(&smb,msg)) != SMB_SUCCESS) {
errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);
return(0);
return i;
}
i=smb_getmsghdr(&smb,msg);
if(i==SMB_SUCCESS) {
if(msg->hdr.number==number)
return(1);
return msg->total_hfields;
/* Wrong offset */
smb_freemsgmem(msg);
}
......@@ -72,19 +72,19 @@ int sbbs_t::loadmsg(smbmsg_t *msg, ulong number)
msg->hdr.number=number;
if((i=smb_getmsgidx(&smb,msg))!=SMB_SUCCESS) /* Message is deleted */
return(0);
return i;
if((i=smb_lockmsghdr(&smb,msg))!=SMB_SUCCESS) {
errormsg(WHERE,ERR_LOCK,smb.file,i,smb.last_error);
return(0);
return i;
}
if((i=smb_getmsghdr(&smb,msg))!=SMB_SUCCESS) {
SAFEPRINTF4(str,"(%06"PRIX32") #%"PRIu32"/%lu %s",msg->idx.offset,msg->idx.number
,number,smb.file);
smb_unlockmsghdr(&smb,msg);
errormsg(WHERE,ERR_READ,str,i,smb.last_error);
return(0);
return i;
}
return(msg->total_hfields);
return msg->total_hfields;
}
......@@ -192,6 +192,15 @@ void sbbs_t::show_msg(smbmsg_t* msg, long mode, post_t* post)
uint16_t votes = smb_voted_already(&smb, msg->hdr.number
,cfg.sub[smb.subnum]->misc&SUB_NAME ? useron.name : useron.alias, NET_NONE, NULL);
int comments=0;
for(int i = 0; i < msg->total_hfields; i++)
if(msg->hfield[i].type == SMB_COMMENT) {
bprintf("%s\r\n", (char*)msg->hfield_dat[i]);
comments++;
}
if(comments)
CRLF;
for(int i = 0; i < msg->total_hfields; i++) {
if(msg->hfield[i].type != SMB_POLL_ANSWER)
continue;
......@@ -213,11 +222,16 @@ void sbbs_t::show_msg(smbmsg_t* msg, long mode, post_t* post)
else if(width > cols-20)
width = cols-20;
bprintf(text[PollAnswerNumber], answers+1);
safe_snprintf(str, sizeof(str), text[PollAnswerFmt]
,width, width, answer, post->votes[answers], pct);
backfill(str, pct);
if(votes&(1<<answers))
bputs(text[PollAnswerChecked]);
if(votes || sub_op(smb.subnum)) {
safe_snprintf(str, sizeof(str), text[PollAnswerFmt]
,width, width, answer, post->votes[answers], pct);
backfill(str, pct);
if(votes&(1<<answers))
bputs(text[PollAnswerChecked]);
} else {
attr(cfg.color[clr_unfill]);
bputs(answer);
}
CRLF;
answers++;
}
......
/* mail.cpp */
/* Synchronet mail-related routines */
/* $Id$ */
......@@ -199,7 +197,7 @@ void sbbs_t::delallmail(uint usernumber, int which, bool permanent)
msg.idx.offset=0; /* search by number */
if((mail[u].attr&MSG_PERMANENT) && !permanent)
continue;
if(loadmsg(&msg,mail[u].number)) { /* message still there */
if(loadmsg(&msg,mail[u].number) >= 0) { /* message still there */
msg.hdr.attr|=MSG_DELETE;
msg.hdr.attr&=~MSG_PERMANENT;
msg.idx.attr=msg.hdr.attr;
......
......@@ -73,10 +73,13 @@ ulong sbbs_t::msgtoqwk(smbmsg_t* msg, FILE *qwk_fp, long mode, uint subnum
fprintf(voting, "[poll:%s]\n", msgid);
if(msg->hdr.votes)
fprintf(voting, "MaxVotes = %hd\n", msg->hdr.votes);
unsigned comments = 0;
unsigned answers = 0;
for(i=0; i < msg->total_hfields; i++) {
if(msg->hfield[i].type == SMB_POLL_ANSWER)
fprintf(voting, "Answer%u = %s\n", answers++, (char*)msg->hfield_dat[i]);
if(msg->hfield[i].type == SMB_COMMENT)
fprintf(voting, "%s%u = %s\n", smb_hfieldtype(msg->hfield[i].type), comments++, (char*)msg->hfield_dat[i]);
else if(msg->hfield[i].type == SMB_POLL_ANSWER)
fprintf(voting, "%s%u = %s\n", smb_hfieldtype(msg->hfield[i].type), answers++, (char*)msg->hfield_dat[i]);
}
}
if(msg->subj && *msg->subj)
......
/* pack_qwk.cpp */
/* Synchronet pack QWK packet routine */
/* $Id$ */
......@@ -396,7 +394,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
msg.idx=mail[u];
if(msg.idx.number>qwkmail_last)
qwkmail_last=msg.idx.number;
if(!loadmsg(&msg,mail[u].number))
if(loadmsg(&msg,mail[u].number) < 1)
continue;
if(msg.hdr.auxattr&MSG_FILEATTACH && useron.qwk&QWK_ATTACH) {
......@@ -518,7 +516,7 @@ bool sbbs_t::pack_qwk(char *packet, ulong *msgcnt, bool prepack)
memset(&msg,0,sizeof(msg));
msg.idx=post[u].idx;
if(!loadmsg(&msg,post[u].idx.number))
if(loadmsg(&msg,post[u].idx.number) < 1)
continue;
if(useron.rest&FLAG('Q')) {
......
......@@ -135,7 +135,7 @@ bool sbbs_t::pack_rep(uint hubnum)
msg.idx=mail[u];
if(msg.idx.number>qwkmail_last)
qwkmail_last=msg.idx.number;
if(!loadmsg(&msg,mail[u].number))
if(loadmsg(&msg,mail[u].number) < 1)
continue;
SAFEPRINTF(str,"%s/",cfg.qhub[hubnum]->id);
......@@ -200,7 +200,7 @@ bool sbbs_t::pack_rep(uint hubnum)
memset(&msg,0,sizeof(msg));
msg.idx=post[u].idx;
if(!loadmsg(&msg,post[u].idx.number))
if(loadmsg(&msg,post[u].idx.number) < 1)
continue;
if(msg.from_net.type && msg.from_net.type!=NET_QWK &&
......@@ -317,7 +317,7 @@ bool sbbs_t::pack_rep(uint hubnum)
continue;
memset(&msg,0,sizeof(msg));
/* !IMPORTANT: search by number (do not initialize msg.idx.offset) */
if(!loadmsg(&msg,mail[u].number))
if(loadmsg(&msg,mail[u].number) < 1)
continue;
SAFEPRINTF(str,"%s/",cfg.qhub[hubnum]->id);
......
......@@ -347,7 +347,7 @@ void sbbs_t::qwk_success(ulong msgcnt, char bi, char prepack)
continue;
memset(&msg,0,sizeof(msg));
/* !IMPORTANT: search by number (do not initialize msg.idx.offset) */
if(!loadmsg(&msg,mail[u].number))
if(loadmsg(&msg,mail[u].number) < 1)
continue;
if(!(msg.hdr.attr&MSG_READ)) {
if(thisnode.status==NODE_INUSE)
......@@ -1025,19 +1025,34 @@ bool sbbs_t::qwk_voting(const char* fname, smb_net_type_t net_type, const char*
for(u = 0; poll_list[u] != NULL; u++) {
smbmsg_t msg;
const char* notice = NULL;
ZERO_VAR(msg);
smb_hfield_str(&msg, RFC822MSGID, poll_list[u] + 5);
smb_hfield_str(&msg, SENDER, iniGetString(ini, poll_list[u], smb_hfieldtype(SENDER), NULL, NULL));
msg.hdr.votes = iniGetShortInt(ini, poll_list[u], "votes", 0);
if(net_type != NET_NONE) {
const char* netaddr = iniGetString(ini,poll_list[u], smb_hfieldtype(SENDERNETADDR), NULL, NULL);
const char* netaddr = iniGetString(ini, poll_list[u], smb_hfieldtype(SENDERNETADDR), NULL, NULL);
if(netaddr == NULL)
netaddr = qnet_id;
smb_hfield_netaddr(&msg, SENDERNETADDR, netaddr, &net_type);
smb_hfield(&msg, SENDERNETTYPE, sizeof(net_type), &net_type);
}
for(int i=0;;i++) {
char str[128];
SAFEPRINTF2(str, "%s%u", smb_hfieldtype(SMB_COMMENT), i);
const char* comment = iniGetString(ini, poll_list[u], str, NULL, NULL);
if(comment == NULL)
break;
smb_hfield_str(&msg, SMB_COMMENT, comment);
}
for(int i=0;;i++) {
char str[128];
SAFEPRINTF2(str, "%s%u", smb_hfieldtype(SMB_POLL_ANSWER), i);
const char* answer = iniGetString(ini, poll_list[u], str, NULL, NULL);
if(answer == NULL)
break;
smb_hfield_str(&msg, SMB_POLL_ANSWER, answer);
}
uint subnum = resolve_qwkconf(iniGetInteger(ini, poll_list[u], "Conference", 0));
if(subnum == INVALID_SUB)
continue;
......
......@@ -141,7 +141,7 @@ void sbbs_t::readmail(uint usernumber, int which)
smb_freemsgmem(&msg);
msg.total_hfields=0;
msg.idx.offset=mail[smb.curmsg].offset;
if(!loadmsg(&msg,mail[smb.curmsg].number))
if(loadmsg(&msg,mail[smb.curmsg].number) < 1)
continue;
smb_unlockmsghdr(&smb,&msg);
bprintf(text[MailWaitingLstFmt],smb.curmsg+1
......@@ -234,7 +234,7 @@ void sbbs_t::readmail(uint usernumber, int which)
continue;
}
if(!loadmsg(&msg,mail[smb.curmsg].number)) { /* Message header gone */
if(loadmsg(&msg,mail[smb.curmsg].number) < 0) { /* Message header gone */
if(mismatches>5) { /* We can't do this too many times in a row */
errormsg(WHERE,ERR_CHK,"message number",mail[smb.curmsg].number);
break;
......@@ -338,7 +338,7 @@ void sbbs_t::readmail(uint usernumber, int which)
msg.total_hfields=0;
msg.idx.offset=0; /* Search by number */
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >= 0) {
msg.hdr.attr|=MSG_READ;
if(msg.hdr.attr&MSG_KILLREAD)
msg.hdr.attr|=MSG_DELETE;
......@@ -447,7 +447,7 @@ void sbbs_t::readmail(uint usernumber, int which)
msg.total_hfields=0;
msg.idx.offset=0;
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >= 0) {
msg.hdr.attr|=MSG_REPLIED;
msg.idx.attr=msg.hdr.attr;
if((i=smb_putmsg(&smb,&msg))!=0)
......@@ -474,7 +474,7 @@ void sbbs_t::readmail(uint usernumber, int which)
msg.total_hfields=0;
msg.idx.offset=0;
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >= 0) {
msg.hdr.attr^=MSG_DELETE;
msg.idx.attr=msg.hdr.attr;
// mail[smb.curmsg].attr=msg.hdr.attr;
......@@ -516,7 +516,7 @@ void sbbs_t::readmail(uint usernumber, int which)
msg.total_hfields=0;
msg.idx.offset=0;
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >= 0) {
msg.hdr.attr|=MSG_DELETE;
msg.idx.attr=msg.hdr.attr;
// mail[smb.curmsg].attr=msg.hdr.attr;
......@@ -552,7 +552,7 @@ void sbbs_t::readmail(uint usernumber, int which)
smb_freemsgmem(&msg);
msg.total_hfields=0;
msg.idx.offset=mail[u].offset;
if(!loadmsg(&msg,mail[u].number))
if(loadmsg(&msg,mail[u].number) < 0)
continue;
smb_unlockmsghdr(&smb,&msg);
if(which==MAIL_ALL)
......@@ -583,7 +583,7 @@ void sbbs_t::readmail(uint usernumber, int which)
msg.total_hfields=0;
msg.idx.offset=0;
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >= 0) {
msg.hdr.attr=msg.idx.attr=(ushort)i;
if((i=smb_putmsg(&smb,&msg))!=0)
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
......@@ -721,7 +721,7 @@ void sbbs_t::readmail(uint usernumber, int which)
smb_freemsgmem(&msg);
msg.total_hfields=0;
msg.idx.offset=mail[u].offset;
if(!loadmsg(&msg,mail[u].number))
if(loadmsg(&msg,mail[u].number) < 0)
continue;
smb_unlockmsghdr(&smb,&msg);
if(which==MAIL_ALL)
......
......@@ -68,7 +68,7 @@ long sbbs_t::listmsgs(uint subnum, long mode, post_t *post, long i, long posts)
if(mode&SCAN_NEW && post[i].idx.number<=subscan[subnum].ptr)
continue;
msg.idx.offset=post[i].idx.offset;
if(!loadmsg(&msg,post[i].idx.number))
if(loadmsg(&msg,post[i].idx.number) < 0)
break;
smb_unlockmsghdr(&smb,&msg);
if(listed==0)
......@@ -617,7 +617,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
smb_freemsgmem(&msg);
msg.total_hfields=0;
if(!loadmsg(&msg,post[smb.curmsg].idx.number)) {
if(loadmsg(&msg,post[smb.curmsg].idx.number) < 0) {
if(mismatches>5) { /* We can't do this too many times in a row */
errormsg(WHERE,ERR_CHK,smb.file,post[smb.curmsg].idx.number);
break;
......@@ -692,7 +692,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
msg.total_hfields=0;
msg.idx.offset=0;
if(!smb_locksmbhdr(&smb)) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >= 0) {
msg.hdr.attr|=MSG_READ;
msg.idx.attr=msg.hdr.attr;
if((i=smb_putmsg(&smb,&msg))!=0)
......@@ -730,7 +730,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
msg.total_hfields=0;
msg.idx.offset=0;
if(!smb_locksmbhdr(&smb)) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >= 0) {
msg.hdr.attr=msg.idx.attr=msg_attr;
if((i=smb_putmsg(&smb,&msg))!=0)
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
......@@ -857,7 +857,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
msg.total_hfields=0;
msg.idx.offset=0;
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >=0 ) {
msg.idx.attr^=MSG_DELETE;
msg.hdr.attr=msg.idx.attr;
if((i=smb_putmsg(&smb,&msg))!=0)
......@@ -1106,7 +1106,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
if(!(useron.misc&EXPERT))
menu("sysmscan");
bputs(text[OperatorPrompt]);
strcpy(str,"?CEHMQUV");
strcpy(str,"?ACEHMQUV");
if(SYSOP)
strcat(str,"SP");
switch(getkeys(str,0)) {
......@@ -1114,6 +1114,15 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
if(useron.misc&EXPERT)
menu("sysmscan");
continue;
case 'A': /* Add comment */
bputs(text[UeditComment]);
if(!getstr(str, LEN_TITLE, K_LINE))
break;
smb_hfield_str(&msg, SMB_COMMENT, str);
msg.idx.offset=0;
if((i=smb_updatemsg(&smb, &msg)) != SMB_SUCCESS)
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
break;
case 'P': /* Purge user */
if(noyes(text[AreYouSureQ]))
break;
......@@ -1130,7 +1139,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
msg.total_hfields=0;
msg.idx.offset=0;
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >= 0) {
msg.hdr.attr=msg.idx.attr=i;
if((i=smb_putmsg(&smb,&msg))!=0)
errormsg(WHERE,ERR_WRITE,smb.file,i,smb.last_error);
......@@ -1155,7 +1164,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
msg.total_hfields=0;
msg.idx.offset=0;
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(!loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) < 0) {
errormsg(WHERE,ERR_READ,smb.file,msg.idx.number);
break;
}
......@@ -1193,7 +1202,7 @@ int sbbs_t::scanposts(uint subnum, long mode, const char *find)
msg.total_hfields=0;
msg.idx.offset=0;
if(smb_locksmbhdr(&smb)==SMB_SUCCESS) { /* Lock the entire base */
if(loadmsg(&msg,msg.idx.number)) {
if(loadmsg(&msg,msg.idx.number) >= 0) {
msg.idx.attr|=MSG_VALIDATED;
msg.hdr.attr=msg.idx.attr;
if((i=smb_putmsg(&smb,&msg))!=0)
......@@ -1418,7 +1427,7 @@ long sbbs_t::searchposts(uint subnum, post_t *post, long start, long posts
msg.total_hfields=0;
for(l=start;l<posts && !msgabort();l++) {
msg.idx.offset=post[l].idx.offset;
if(!loadmsg(&msg,post[l].idx.number))
if(loadmsg(&msg,post[l].idx.number) < 0)
continue;
smb_unlockmsghdr(&smb,&msg);
buf=smb_getmsgtxt(&smb,&msg,GETMSGTXT_ALL);
......@@ -1480,7 +1489,7 @@ long sbbs_t::showposts_toyou(uint subnum, post_t *post, ulong start, long posts,
smb_freemsgmem(&msg);
msg.total_hfields=0;
msg.idx.offset=post[l].idx.offset;
if(!loadmsg(&msg,post[l].idx.number))
if(loadmsg(&msg,post[l].idx.number) < 0)
continue;
smb_unlockmsghdr(&smb,&msg);
if((useron.number==1 && !stricmp(msg.to,"sysop") && !msg.from_net.type)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment