Skip to content
Snippets Groups Projects
Commit b1449b27 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix DIZ extraction/use for FTP uploads

1. Was not setting f->dir to the correct directory number, so only ftp-uploads to the *first* directory (dirnum = 0) would extract DIZ files of uploaded files.

Removing the 'dirnum' parameter to addfile() since that implied that you did not have to initialize the 'dir' element of the passed file_t, but you do: to get the correct file path for file size/date detection and the DIZ extraction.

2. Was getting heap-corruption when freeing the imported/formatted DIZ text on Windows once the above problem was fixed: can't free() in one DLL memory that was allocated in another DLL. Created and now using free_diz() to free the memory allocated in read_diz().

format_diz() handles a NULL 'lines' argument correctly/gracefully, so no need for the NULL lines check in sbbs_t::uploadfile().

Added FTP server log messages for successful file upload or update by user.
parent bf1cae28
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #3015 passed
...@@ -108,7 +108,7 @@ bool get_file_diz(file_t* f, char* ext, size_t maxlen) ...@@ -108,7 +108,7 @@ bool get_file_diz(file_t* f, char* ext, size_t maxlen)
printf("Parsing DIZ: %s\n", diz_fpath); printf("Parsing DIZ: %s\n", diz_fpath);
char* lines = read_diz(diz_fpath, NULL); char* lines = read_diz(diz_fpath, NULL);
format_diz(lines, ext, maxlen, 0, false); format_diz(lines, ext, maxlen, 0, false);
free(lines); free_diz(lines);
remove(diz_fpath); remove(diz_fpath);
if(mode&ASCII_ONLY) if(mode&ASCII_ONLY)
......
...@@ -239,8 +239,9 @@ bool sbbs_t::movefile(smb_t* smb, file_t* f, int newdir) ...@@ -239,8 +239,9 @@ bool sbbs_t::movefile(smb_t* smb, file_t* f, int newdir)
return false; return false;
} }
f->dir = newdir;
newfile.dfield = NULL; // addfile() ends up realloc'ing dfield (in smb_addmsg) newfile.dfield = NULL; // addfile() ends up realloc'ing dfield (in smb_addmsg)
bool result = addfile(&cfg, newdir, &newfile, newfile.extdesc, newfile.metadata, /* client: */NULL); bool result = addfile(&cfg, &newfile, newfile.extdesc, newfile.metadata, /* client: */NULL);
free(newfile.dfield); free(newfile.dfield);
if(!result) if(!result)
return false; return false;
......
...@@ -725,12 +725,12 @@ int file_sauce_hfields(file_t* f, struct sauce_charinfo* info) ...@@ -725,12 +725,12 @@ int file_sauce_hfields(file_t* f, struct sauce_charinfo* info)
return SMB_SUCCESS; return SMB_SUCCESS;
} }
bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc, const char* metadata, client_t* client) bool addfile(scfg_t* cfg, file_t* f, const char* extdesc, const char* metadata, client_t* client)
{ {
char fpath[MAX_PATH + 1]; char fpath[MAX_PATH + 1];
smb_t smb; smb_t smb;
if(smb_open_dir(cfg, &smb, dirnum) != SMB_SUCCESS) if(smb_open_dir(cfg, &smb, f->dir) != SMB_SUCCESS)
return false; return false;
getfilepath(cfg, f, fpath); getfilepath(cfg, f, fpath);
...@@ -1112,6 +1112,11 @@ char* read_diz(const char* path, struct sauce_charinfo* sauce) ...@@ -1112,6 +1112,11 @@ char* read_diz(const char* path, struct sauce_charinfo* sauce)
return buf; return buf;
} }
void free_diz(char* buf)
{
free(buf);
}
char* format_diz(const char* src, char* dest, size_t maxlen, int width, bool ice) char* format_diz(const char* src, char* dest, size_t maxlen, int width, bool ice)
{ {
if(src == NULL) { if(src == NULL) {
......
...@@ -55,7 +55,7 @@ DLLEXPORT time_t getfiletime(scfg_t*, file_t*); ...@@ -55,7 +55,7 @@ DLLEXPORT time_t getfiletime(scfg_t*, file_t*);
DLLEXPORT ulong gettimetodl(scfg_t*, file_t*, uint rate_cps); DLLEXPORT ulong gettimetodl(scfg_t*, file_t*, uint rate_cps);
DLLEXPORT ulong getuserxfers(scfg_t*, const char* from, uint to); DLLEXPORT ulong getuserxfers(scfg_t*, const char* from, uint to);
DLLEXPORT bool hashfile(scfg_t*, file_t*); DLLEXPORT bool hashfile(scfg_t*, file_t*);
DLLEXPORT bool addfile(scfg_t*, uint dirnum, file_t*, const char* extdesc, const char* metadata, client_t*); DLLEXPORT bool addfile(scfg_t*, file_t*, const char* extdesc, const char* metadata, client_t*);
DLLEXPORT bool removefile(scfg_t*, uint dirnum, const char* filename); DLLEXPORT bool removefile(scfg_t*, uint dirnum, const char* filename);
DLLEXPORT char* format_filename(const char* fname, char* buf, size_t, bool pad); DLLEXPORT char* format_filename(const char* fname, char* buf, size_t, bool pad);
DLLEXPORT bool safest_filename(const char* fname); DLLEXPORT bool safest_filename(const char* fname);
...@@ -63,6 +63,7 @@ DLLEXPORT bool illegal_filename(const char* fname); ...@@ -63,6 +63,7 @@ DLLEXPORT bool illegal_filename(const char* fname);
DLLEXPORT bool allowed_filename(scfg_t*, const char* fname); DLLEXPORT bool allowed_filename(scfg_t*, const char* fname);
DLLEXPORT bool extract_diz(scfg_t*, file_t*, str_list_t diz_fname, char* path, size_t); DLLEXPORT bool extract_diz(scfg_t*, file_t*, str_list_t diz_fname, char* path, size_t);
DLLEXPORT char* read_diz(const char* path, struct sauce_charinfo*); DLLEXPORT char* read_diz(const char* path, struct sauce_charinfo*);
DLLEXPORT void free_diz(char*);
DLLEXPORT char* format_diz(const char* src, char* dest, size_t maxlen, int width, bool ice_color); DLLEXPORT char* format_diz(const char* src, char* dest, size_t maxlen, int width, bool ice_color);
DLLEXPORT char* prep_file_desc(const char *src, char* dst); DLLEXPORT char* prep_file_desc(const char *src, char* dst);
DLLEXPORT int file_client_hfields(file_t*, client_t*); DLLEXPORT int file_client_hfields(file_t*, client_t*);
......
...@@ -1014,6 +1014,7 @@ static void receive_thread(void* arg) ...@@ -1014,6 +1014,7 @@ static void receive_thread(void* arg)
if(xfer.dir>=0) { if(xfer.dir>=0) {
memset(&f,0,sizeof(f)); memset(&f,0,sizeof(f));
f.dir = xfer.dir;
smb_hfield_str(&f, SMB_FILENAME, getfname(xfer.filename)); smb_hfield_str(&f, SMB_FILENAME, getfname(xfer.filename));
smb_hfield_str(&f, SENDER, xfer.user->alias); smb_hfield_str(&f, SENDER, xfer.user->alias);
...@@ -1039,7 +1040,7 @@ static void receive_thread(void* arg) ...@@ -1039,7 +1040,7 @@ static void receive_thread(void* arg)
lprintf(LOG_DEBUG,"%04d <%s> DATA Parsing DIZ: %s",xfer.ctrl_sock, xfer.user->alias,tmp); lprintf(LOG_DEBUG,"%04d <%s> DATA Parsing DIZ: %s",xfer.ctrl_sock, xfer.user->alias,tmp);
char* lines = read_diz(tmp, &sauce); char* lines = read_diz(tmp, &sauce);
format_diz(lines, extdesc, sizeof(extdesc), sauce.width, sauce.ice_color); format_diz(lines, extdesc, sizeof(extdesc), sauce.width, sauce.ice_color);
free(lines); free_diz(lines);
if(!fdesc[0]) { /* use for normal description */ if(!fdesc[0]) { /* use for normal description */
prep_file_desc(extdesc, fdesc); /* strip control chars and dupe chars */ prep_file_desc(extdesc, fdesc); /* strip control chars and dupe chars */
} }
...@@ -1052,12 +1053,18 @@ static void receive_thread(void* arg) ...@@ -1052,12 +1053,18 @@ static void receive_thread(void* arg)
if(f.desc == NULL) if(f.desc == NULL)
smb_new_hfield_str(&f, SMB_FILEDESC, fdesc); smb_new_hfield_str(&f, SMB_FILEDESC, fdesc);
if(filedat) { if(filedat) {
if(!updatefile(&scfg, &f)) if(updatefile(&scfg, &f))
lprintf(LOG_INFO,"%04d <%s> DATA updated file: %s"
,xfer.ctrl_sock, xfer.user->alias, f.name);
else
lprintf(LOG_ERR,"%04d <%s> !DATA ERROR updating file (%s) in database" lprintf(LOG_ERR,"%04d <%s> !DATA ERROR updating file (%s) in database"
,xfer.ctrl_sock, xfer.user->alias, f.name); ,xfer.ctrl_sock, xfer.user->alias, f.name);
/* need to update the index here */ /* need to update the index here */
} else { } else {
if(!addfile(&scfg, xfer.dir, &f, extdesc, /* metatdata: */NULL, xfer.client)) if(addfile(&scfg, &f, extdesc, /* metatdata: */NULL, xfer.client))
lprintf(LOG_INFO,"%04d <%s> DATA uploaded file: %s"
,xfer.ctrl_sock, xfer.user->alias, f.name);
else
lprintf(LOG_ERR,"%04d <%s> !DATA ERROR adding file (%s) to database" lprintf(LOG_ERR,"%04d <%s> !DATA ERROR adding file (%s) to database"
,xfer.ctrl_sock, xfer.user->alias, f.name); ,xfer.ctrl_sock, xfer.user->alias, f.name);
} }
......
...@@ -1143,7 +1143,7 @@ static void get_diz(scfg_t* scfg, file_t* file, char** extdesc) ...@@ -1143,7 +1143,7 @@ static void get_diz(scfg_t* scfg, file_t* file, char** extdesc)
char* lines = read_diz(diz_fpath, &sauce); char* lines = read_diz(diz_fpath, &sauce);
if(lines != NULL) { if(lines != NULL) {
format_diz(lines, extbuf, sizeof(extbuf), sauce.width, sauce.ice_color); format_diz(lines, extbuf, sizeof(extbuf), sauce.width, sauce.ice_color);
free(lines); free_diz(lines);
free(*extdesc); free(*extdesc);
*extdesc = strdup(extbuf); *extdesc = strdup(extbuf);
file_sauce_hfields(file, &sauce); file_sauce_hfields(file, &sauce);
......
...@@ -875,7 +875,8 @@ int sbbs_t::listfileinfo(uint dirnum, const char *filespec, long mode) ...@@ -875,7 +875,8 @@ int sbbs_t::listfileinfo(uint dirnum, const char *filespec, long mode)
sprintf(str,text[AddToOfflineDirQ] sprintf(str,text[AddToOfflineDirQ]
,f->name,cfg.lib[cfg.dir[i]->lib]->sname,cfg.dir[i]->sname); ,f->name,cfg.lib[cfg.dir[i]->lib]->sname,cfg.dir[i]->sname);
if(yesno(str)) { if(yesno(str)) {
addfile(&cfg, i, f, f->extdesc, f->metadata, /* client: */NULL); f->dir = i;
addfile(&cfg, f, f->extdesc, f->metadata, /* client: */NULL);
} }
} }
} }
......
...@@ -148,9 +148,8 @@ bool sbbs_t::uploadfile(file_t* f) ...@@ -148,9 +148,8 @@ bool sbbs_t::uploadfile(file_t* f)
lprintf(LOG_DEBUG, "Parsing DIZ: %s", str); lprintf(LOG_DEBUG, "Parsing DIZ: %s", str);
char* lines = read_diz(str, &sauce); char* lines = read_diz(str, &sauce);
if(lines != NULL)
format_diz(lines, ext, sizeof(ext), sauce.width, sauce.ice_color); format_diz(lines, ext, sizeof(ext), sauce.width, sauce.ice_color);
free(lines); free_diz(lines);
file_sauce_hfields(f, &sauce); file_sauce_hfields(f, &sauce);
if(f->desc == NULL || f->desc[0] == 0) { if(f->desc == NULL || f->desc[0] == 0) {
...@@ -174,7 +173,7 @@ bool sbbs_t::uploadfile(file_t* f) ...@@ -174,7 +173,7 @@ bool sbbs_t::uploadfile(file_t* f)
smb_hfield_bin(f, SMB_COST, length); smb_hfield_bin(f, SMB_COST, length);
smb_hfield_str(f, SENDER, useron.alias); smb_hfield_str(f, SENDER, useron.alias);
bprintf(text[FileNBytesReceived],f->name, u64toac(length,tmp)); bprintf(text[FileNBytesReceived],f->name, u64toac(length,tmp));
if(!addfile(&cfg, f->dir, f, ext, /* metadata: */NULL, &client)) if(!addfile(&cfg, f, ext, /* metadata: */NULL, &client))
return false; return false;
safe_snprintf(str,sizeof(str),"uploaded %s to %s %s" safe_snprintf(str,sizeof(str),"uploaded %s to %s %s"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment