Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit f07afb99 authored by rswindell's avatar rswindell

* Unified the msg tmp filename generation (i.e. INPUT.MSG and MSGTMP) in a

single function.
* editfile() now modifies a temporary copy of the file which solves 2 problems:
A. editors restricted to the temp dir (e.g. PICO) can now be used to edit other
    files (e.g. sig files)
B. DOS editors can now be used to edit files with long filenames
    (e.g. .plan files)
parent 0be95fab
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -62,7 +62,7 @@ bool sbbs_t::bulkmail(uchar *ar)
&& !noyes(text[AnonymousQ]))
msg.hdr.attr|=MSG_ANONYMOUS;
sprintf(msgpath,"%sinput.msg",cfg.node_dir);
msg_tmp_fname(useron.xedit, msgpath, sizeof(msgpath));
if(!writemsg(msgpath,nulstr,title,WM_EMAIL,INVALID_SUB,"Bulk Mailing")) {
bputs(text[Aborted]);
return(false);
......
......@@ -102,7 +102,7 @@ bool sbbs_t::email(int usernumber, char *top, char *subj, long mode)
if(cfg.sys_misc&SM_DELREADM)
msgattr|=MSG_KILLREAD;
sprintf(msgpath,"%sinput.msg", cfg.node_dir);
msg_tmp_fname(useron.xedit, msgpath, sizeof(msgpath));
username(&cfg,usernumber,str2);
if(!writemsg(msgpath,top,title,mode,INVALID_SUB,str2)) {
bputs(text[Aborted]);
......
......@@ -191,7 +191,7 @@ bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
if(cfg.sub[subnum]->misc&SUB_NAME)
bputs(text[UsingRealName]);
sprintf(str,"%sinput.msg",cfg.node_dir);
msg_tmp_fname(useron.xedit, str, sizeof(str));
if(!writemsg(str,top,title,wm_mode,subnum,touser)
|| (long)(length=flength(str))<1) { /* Bugfix Aug-20-2003: Reject negative length */
bputs(text[Aborted]);
......
......@@ -438,6 +438,7 @@ public:
void automsg(void);
bool writemsg(char *str, char *top, char *title, long mode, int subnum
,char *dest);
char* msg_tmp_fname(int xedit, char* fname, size_t len);
char putmsg(char *str, long mode);
bool msgabort(void);
bool email(int usernumber, char *top, char *title, long mode);
......@@ -858,6 +859,7 @@ extern "C" {
DLLEXPORT BOOL DLLCALL write_chat_cfg(scfg_t* cfg, int backup_level);
DLLEXPORT BOOL DLLCALL write_xtrn_cfg(scfg_t* cfg, int backup_level);
DLLEXPORT BOOL DLLCALL fcopy(char* src, char* dest);
DLLEXPORT BOOL DLLCALL fcompare(char* fn1, char* fn2);
DLLEXPORT BOOL DLLCALL backup(char *org, int backup_level, BOOL ren);
DLLEXPORT void DLLCALL refresh_cfg(scfg_t* cfg);
......
......@@ -110,6 +110,33 @@ BOOL DLLCALL fcopy(char* src, char* dest)
return(success);
}
BOOL DLLCALL fcompare(char* fn1, char* fn2)
{
FILE* fp1;
FILE* fp2;
BOOL success=TRUE;
if(flength(fn1) != flength(fn2))
return(FALSE);
if((fp1=fopen(fn1,"rb"))==NULL)
return(FALSE);
if((fp2=fopen(fn2,"rb"))==NULL) {
fclose(fp1);
return(FALSE);
}
while(!feof(fp1) && success) {
if(fgetc(fp1) != fgetc(fp2))
success=FALSE;
}
fclose(fp1);
fclose(fp2);
return(success);
}
/****************************************************************************/
/****************************************************************************/
BOOL DLLCALL backup(char *fname, int backup_level, BOOL ren)
......
......@@ -42,6 +42,23 @@
const char *qstr=" > %.76s\r\n";
void quotestr(char *str);
/****************************************************************************/
/* Returns temporary message text filename (for message/text editors) */
/****************************************************************************/
char* sbbs_t::msg_tmp_fname(int xedit, char* fname, size_t len)
{
safe_snprintf(fname, len, "%sINPUT.MSG", cfg.temp_dir);
if(xedit) {
if(cfg.xedit[xedit-1]->misc&QUICKBBS)
safe_snprintf(fname, len, "%sMSGTMP", cfg.node_dir); /* QuickBBS editors are dumb */
if(cfg.xedit[xedit-1]->misc&XTRN_LWRCASE)
strlwr(fname);
}
return(fname);
}
/****************************************************************************/
/* Creates a message (post or mail) using standard line editor. 'fname' is */
/* is name of file to create, 'top' is a buffer to place at beginning of */
......@@ -75,12 +92,7 @@ bool sbbs_t::writemsg(char *fname, char *top, char *title, long mode, int subnum
(!(mode&(WM_EMAIL|WM_NETMAIL)) && cfg.sub[subnum]->misc&SUB_PNET))
mode|=WM_NOTOP;
if(useron.xedit && cfg.xedit[useron.xedit-1]->misc&QUICKBBS)
sprintf(msgtmp,"%sMSGTMP",cfg.node_dir); /* QuickBBS editors are dumb */
else
sprintf(msgtmp,"%sINPUT.MSG",cfg.temp_dir);
if(useron.xedit && cfg.xedit[useron.xedit-1]->misc&XTRN_LWRCASE)
strlwr(msgtmp);
msg_tmp_fname(useron.xedit, msgtmp, sizeof(msgtmp));
if(mode&WM_QUOTE && !(useron.rest&FLAG('J'))
&& ((mode&(WM_EMAIL|WM_NETMAIL) && cfg.sys_misc&SM_QUOTE_EM)
......@@ -882,23 +894,28 @@ ulong sbbs_t::msgeditor(char *buf, char *top, char *title)
/****************************************************************************/
/* Edits an existing file or creates a new one in MSG format */
/****************************************************************************/
void sbbs_t::editfile(char *str)
void sbbs_t::editfile(char *fname)
{
char *buf,str2[128];
char *buf,path[MAX_PATH+1];
char msgtmp[MAX_PATH+1];
int file;
long length,maxlines,lines,l,mode=0;
maxlines=cfg.level_linespermsg[useron.level];
sprintf(str2,"%sQUOTES.TXT",cfg.node_dir);
fexistcase(str2);
remove(str2);
#if 0 /* no such thing as local logon */
if(cfg.node_editor[0] && online==ON_LOCAL) {
external(cmdstr(cfg.node_editor,str,nulstr,NULL),0,cfg.node_dir);
return;
}
#endif
sprintf(path,"%sQUOTES.TXT",cfg.node_dir);
if(fexistcase(path))
remove(path);
if(useron.xedit) {
msg_tmp_fname(useron.xedit, msgtmp, sizeof(msgtmp));
if(fexist(msgtmp))
remove(msgtmp);
SAFECOPY(path,fname);
if(fexistcase(path))
fcopy(path, msgtmp);
editor_inf(useron.xedit,nulstr,nulstr,0,INVALID_SUB);
if(cfg.xedit[useron.xedit-1]->misc&XTRN_NATIVE)
mode|=EX_NATIVE;
......@@ -909,24 +926,19 @@ void sbbs_t::editfile(char *str)
if(cfg.xedit[useron.xedit-1]->misc&WWIVCOLOR)
mode|=EX_WWIV;
}
#if 0 /* no such thing as local logon */
if(online==ON_LOCAL)
external(cmdstr(cfg.xedit[useron.xedit-1]->lcmd,str,nulstr,NULL),mode,cfg.node_dir);
else
#endif
{
CLS;
rioctl(IOCM|PAUSE|ABORT);
external(cmdstr(cfg.xedit[useron.xedit-1]->rcmd,str,nulstr,NULL),mode,cfg.node_dir);
rioctl(IOSM|PAUSE|ABORT);
}
CLS;
rioctl(IOCM|PAUSE|ABORT);
external(cmdstr(cfg.xedit[useron.xedit-1]->rcmd,msgtmp,nulstr,NULL),mode,cfg.node_dir);
if(!fcompare(msgtmp, path)) /* file changed */
fcopy(msgtmp, path);
rioctl(IOSM|PAUSE|ABORT);
return;
}
if((buf=(char *)malloc(maxlines*MAX_LINE_LEN))==NULL) {
errormsg(WHERE,ERR_ALLOC,nulstr,maxlines*MAX_LINE_LEN);
return;
}
if((file=nopen(str,O_RDONLY))!=-1) {
if((file=nopen(fname,O_RDONLY))!=-1) {
length=filelength(file);
if(length>(long)maxlines*MAX_LINE_LEN) {
close(file);
......@@ -939,7 +951,7 @@ void sbbs_t::editfile(char *str)
if(read(file,buf,length)!=length) {
close(file);
free(buf);
errormsg(WHERE,ERR_READ,str,length);
errormsg(WHERE,ERR_READ,fname,length);
return;
}
buf[length]=0;
......@@ -954,14 +966,14 @@ void sbbs_t::editfile(char *str)
return;
}
bputs(text[Saving]);
if((file=nopen(str,O_CREAT|O_WRONLY|O_TRUNC))==-1) {
errormsg(WHERE,ERR_OPEN,str,O_CREAT|O_WRONLY|O_TRUNC);
if((file=nopen(fname,O_CREAT|O_WRONLY|O_TRUNC))==-1) {
errormsg(WHERE,ERR_OPEN,fname,O_CREAT|O_WRONLY|O_TRUNC);
free(buf);
return;
}
if((size_t)write(file,buf,strlen(buf))!=strlen(buf)) {
close(file);
errormsg(WHERE,ERR_WRITE,str,strlen(buf));
errormsg(WHERE,ERR_WRITE,fname,strlen(buf));
free(buf);
return;
}
......@@ -1185,14 +1197,10 @@ void sbbs_t::editmsg(smbmsg_t *msg, uint subnum)
if(!msg->hdr.total_dfields)
return;
if(useron.xedit && cfg.xedit[useron.xedit-1]->misc&QUICKBBS)
sprintf(msgtmp,"%sMSGTMP",cfg.node_dir); /* QuickBBS editors are dumb */
else
sprintf(msgtmp,"%sINPUT.MSG",cfg.temp_dir);
if(useron.xedit && cfg.xedit[useron.xedit-1]->misc&XTRN_LWRCASE)
strlwr(msgtmp);
remove(msgtmp);
msg_tmp_fname(useron.xedit, msgtmp, sizeof(msgtmp));
if(fexist(msgtmp))
remove(msgtmp);
msgtotxt(msg,msgtmp,0,1);
editfile(msgtmp);
length=flength(msgtmp);
......
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