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 3549be9f authored by Rob Swindell's avatar Rob Swindell 💬

Standardize on "metadata" as the description of a file's "tail" dfield

It's anticipated that this will be used for JS-populated file metadata in JSON format in the future (and not just "archive contents" in .ini format).

Also, fix the double-free issue that was occurring when moving files with extended file descriptions (sbbs_t::movefile()). This was actually the primary problem I was fixing here, but noticed the metadata issue: metadata would not have been moved along with the other file info between bases.
parent 80422644
Pipeline #2372 passed with stage
in 9 minutes and 35 seconds
......@@ -239,7 +239,8 @@ bool sbbs_t::movefile(smb_t* smb, file_t* f, int newdir)
return false;
}
if(!addfile(&cfg, newdir, &newfile, newfile.extdesc, /* client: */NULL))
newfile.dfield = NULL; // addfile() ends up realloc'ing dfield (in smb_addmsg)
if(!addfile(&cfg, newdir, &newfile, newfile.extdesc, newfile.metadata, /* client: */NULL))
return false;
if(!removefile(smb, f)) // Use ::removefile() here instead?
return false;
......
......@@ -634,7 +634,7 @@ int file_sauce_hfields(file_t* f, struct sauce_charinfo* info)
return SMB_SUCCESS;
}
bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc, client_t* client)
bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc, const char* metadata, client_t* client)
{
char fpath[MAX_PATH + 1];
smb_t smb;
......@@ -645,7 +645,7 @@ bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc, client_t*
getfilepath(cfg, f, fpath);
if(f->from_ip == NULL)
file_client_hfields(f, client);
int result = smb_addfile(&smb, f, SMB_SELFPACK, extdesc, /* contents: */NULL, fpath);
int result = smb_addfile(&smb, f, SMB_SELFPACK, extdesc, metadata, fpath);
smb_close(&smb);
return result == SMB_SUCCESS;
}
......
......@@ -54,7 +54,7 @@ DLLEXPORT time_t getfiletime(scfg_t*, file_t*);
DLLEXPORT ulong gettimetodl(scfg_t*, file_t*, uint rate_cps);
DLLEXPORT ulong getuserxfers(scfg_t*, const char* from, uint to);
DLLEXPORT bool hashfile(scfg_t*, file_t*);
DLLEXPORT bool addfile(scfg_t*, uint dirnum, file_t*, const char* extdesc, client_t*);
DLLEXPORT bool addfile(scfg_t*, uint dirnum, file_t*, const char* extdesc, const char* metadata, client_t*);
DLLEXPORT bool removefile(scfg_t*, uint dirnum, const char* filename);
DLLEXPORT char* format_filename(const char* fname, char* buf, size_t, bool pad);
DLLEXPORT bool safest_filename(const char* fname);
......
......@@ -1097,7 +1097,7 @@ static void receive_thread(void* arg)
,xfer.ctrl_sock, xfer.user->alias, f.name);
/* need to update the index here */
} else {
if(!addfile(&scfg, xfer.dir, &f, extdesc, xfer.client))
if(!addfile(&scfg, xfer.dir, &f, extdesc, /* metatdata: */NULL, xfer.client))
lprintf(LOG_ERR,"%04d <%s> !DATA ERROR adding file (%s) to database"
,xfer.ctrl_sock, xfer.user->alias, f.name);
}
......
......@@ -181,67 +181,67 @@ set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail de
|| !JS_DefineProperty(cx, obj, "name", STRING_TO_JSVAL(js_str), NULL, NULL, flags))
return false;
if(((f->from != NULL && *f->from != '\0') || detail > file_detail_content)
if(((f->from != NULL && *f->from != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->from)) == NULL
|| !JS_DefineProperty(cx, obj, "from", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(((f->from_ip != NULL && *f->from_ip != '\0') || detail > file_detail_content)
if(((f->from_ip != NULL && *f->from_ip != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->from_ip)) == NULL
|| !JS_DefineProperty(cx, obj, "from_ip_addr", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(((f->from_host != NULL && *f->from_host != '\0') || detail > file_detail_content)
if(((f->from_host != NULL && *f->from_host != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->from_host)) == NULL
|| !JS_DefineProperty(cx, obj, "from_host_name", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(((f->from_prot != NULL && *f->from_prot != '\0') || detail > file_detail_content)
if(((f->from_prot != NULL && *f->from_prot != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->from_prot)) == NULL
|| !JS_DefineProperty(cx, obj, "from_protocol", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(((f->from_port != NULL && *f->from_port != '\0') || detail > file_detail_content)
if(((f->from_port != NULL && *f->from_port != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->from_port)) == NULL
|| !JS_DefineProperty(cx, obj, "from_port", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(((f->author != NULL && *f->author != '\0') || detail > file_detail_content)
if(((f->author != NULL && *f->author != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->author)) == NULL
|| !JS_DefineProperty(cx, obj, "author", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(((f->author_org != NULL && *f->author_org != '\0') || detail > file_detail_content)
if(((f->author_org != NULL && *f->author_org != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->author_org)) == NULL
|| !JS_DefineProperty(cx, obj, "author_org", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(((f->to_list != NULL && *f->to_list != '\0') || detail > file_detail_content)
if(((f->to_list != NULL && *f->to_list != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->to_list)) == NULL
|| !JS_DefineProperty(cx, obj, "to_list", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
val = BOOLEAN_TO_JSVAL(f->idx.attr & FILE_ANONYMOUS);
if((val == JSVAL_TRUE || detail > file_detail_content)
if((val == JSVAL_TRUE || detail > file_detail_metadata)
&& !JS_DefineProperty(cx, obj, "anon", val, NULL, NULL, flags))
return false;
if(((f->tags != NULL && *f->tags != '\0') || detail > file_detail_content)
if(((f->tags != NULL && *f->tags != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->tags)) == NULL
|| !JS_DefineProperty(cx, obj, "tags", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(((f->desc != NULL && *f->desc != '\0') || detail > file_detail_content)
if(((f->desc != NULL && *f->desc != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->desc)) == NULL
|| !JS_DefineProperty(cx, obj, "desc", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(((f->extdesc != NULL && *f->extdesc != '\0') || detail > file_detail_content)
if(((f->extdesc != NULL && *f->extdesc != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->extdesc)) == NULL
|| !JS_DefineProperty(cx, obj, "extdesc", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
if(f->cost > 0 || detail > file_detail_content) {
if(f->cost > 0 || detail > file_detail_metadata) {
val = UINT_TO_JSVAL(f->cost);
if(!JS_DefineProperty(cx, obj, "cost", val, NULL, NULL, flags))
return false;
......@@ -253,17 +253,17 @@ set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail de
val = UINT_TO_JSVAL(f->hdr.when_written.time);
if(!JS_DefineProperty(cx, obj, "time", val, NULL, NULL, flags))
return false;
if(f->hdr.when_imported.time > 0 || detail > file_detail_content) {
if(f->hdr.when_imported.time > 0 || detail > file_detail_metadata) {
val = UINT_TO_JSVAL(f->hdr.when_imported.time);
if(!JS_DefineProperty(cx, obj, "added", val, NULL, NULL, flags))
return false;
}
if(f->hdr.last_downloaded > 0 || detail > file_detail_content) {
if(f->hdr.last_downloaded > 0 || detail > file_detail_metadata) {
val = UINT_TO_JSVAL(f->hdr.last_downloaded);
if(!JS_DefineProperty(cx, obj, "last_downloaded", val, NULL, NULL, flags))
return false;
}
if(f->hdr.times_downloaded > 0 || detail > file_detail_content) {
if(f->hdr.times_downloaded > 0 || detail > file_detail_metadata) {
val = UINT_TO_JSVAL(f->hdr.times_downloaded);
if(!JS_DefineProperty(cx, obj, "times_downloaded", val, NULL, NULL, flags))
return false;
......@@ -291,8 +291,8 @@ set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail de
return false;
}
if(((f->content != NULL && *f->content != '\0') || detail > file_detail_content)
&& ((js_str = JS_NewStringCopyZ(cx, f->content)) == NULL
if(((f->metadata != NULL && *f->metadata != '\0') || detail > file_detail_metadata)
&& ((js_str = JS_NewStringCopyZ(cx, f->metadata)) == NULL
|| !JS_DefineProperty(cx, obj, "metadata", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
return false;
......@@ -1844,9 +1844,9 @@ JSObject* js_CreateFileBaseClass(JSContext* cx, JSObject* parent, scfg_t* cfg)
, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
JS_DefineProperty(cx, detail, "EXTENDED", INT_TO_JSVAL(file_detail_extdesc), NULL, NULL
, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
JS_DefineProperty(cx, detail, "METADATA", INT_TO_JSVAL(file_detail_content), NULL, NULL
JS_DefineProperty(cx, detail, "METADATA", INT_TO_JSVAL(file_detail_metadata), NULL, NULL
, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
JS_DefineProperty(cx, detail, "MAX", INT_TO_JSVAL(file_detail_content + 1), NULL, NULL
JS_DefineProperty(cx, detail, "MAX", INT_TO_JSVAL(file_detail_metadata + 1), NULL, NULL
, JSPROP_PERMANENT|JSPROP_ENUMERATE|JSPROP_READONLY);
#ifdef BUILD_JSDOCS
js_DescribeSyncObject(cx, detail, "Detail level numeric constants (in increasing verbosity)", 0);
......
......@@ -884,7 +884,7 @@ int sbbs_t::listfileinfo(uint dirnum, const char *filespec, long mode)
sprintf(str,text[AddToOfflineDirQ]
,f->name,cfg.lib[cfg.dir[i]->lib]->sname,cfg.dir[i]->sname);
if(yesno(str)) {
addfile(&cfg, i, f, f->extdesc, /* client: */NULL);
addfile(&cfg, i, f, f->extdesc, f->metadata, /* client: */NULL);
}
}
}
......
......@@ -189,7 +189,7 @@ bool sbbs_t::uploadfile(file_t* f)
smb_hfield_bin(f, SMB_COST, cdt);
smb_hfield_str(f, SENDER, useron.alias);
bprintf(text[FileNBytesReceived],f->name,ultoac(length,tmp));
if(!addfile(&cfg, f->dir, f, ext, &client))
if(!addfile(&cfg, f->dir, f, ext, /* metadata: */NULL, &client))
return false;
safe_snprintf(str,sizeof(str),"uploaded %s to %s %s"
......
......@@ -634,7 +634,7 @@ typedef struct { /* Message or File */
};
union {
uchar* tail; /* Message body tail (optional) */
char* content; /* Archive content list */
char* metadata; /* File metadata */
};
char* tags; /* Message tags (space-delimited) */
char* editor; /* Message editor (if known) */
......
......@@ -296,8 +296,8 @@ int smb_getfile(smb_t* smb, smbfile_t* file, enum file_detail detail)
return result;
if(detail >= file_detail_extdesc)
file->extdesc = smb_getmsgtxt(smb, file, GETMSGTXT_BODY_ONLY);
if(detail >= file_detail_content)
file->content = smb_getmsgtxt(smb, file, GETMSGTXT_TAIL_ONLY);
if(detail >= file_detail_metadata)
file->metadata = smb_getmsgtxt(smb, file, GETMSGTXT_TAIL_ONLY);
}
file->dir = smb->dirnum;
......@@ -327,7 +327,7 @@ void smb_freefilemem(smbfile_t* file)
/****************************************************************************/
/****************************************************************************/
int smb_addfile(smb_t* smb, smbfile_t* file, int storage, const char* extdesc, const char* content, const char* path)
int smb_addfile(smb_t* smb, smbfile_t* file, int storage, const char* extdesc, const char* metadata, const char* path)
{
if(file->name == NULL || *file->name == '\0') {
safe_snprintf(smb->last_error, sizeof(smb->last_error), "%s missing name", __FUNCTION__);
......@@ -346,26 +346,26 @@ int smb_addfile(smb_t* smb, smbfile_t* file, int storage, const char* extdesc, c
file->hdr.attr |= MSG_FILE;
file->hdr.type = SMB_MSG_TYPE_FILE;
return smb_addmsg(smb, file, storage, SMB_HASH_SOURCE_NONE, XLAT_NONE
,/* body: */(const uchar*)extdesc, /* tail: */(const uchar*)content);
,/* body: */(const uchar*)extdesc, /* tail: */(const uchar*)metadata);
}
/****************************************************************************/
/* Like smb_addfile(), except 'content' is a str_list_t: 'list' */
/* Like smb_addfile(), except 'metadata' is a str_list_t: 'list' */
/****************************************************************************/
int smb_addfile_withlist(smb_t* smb, smbfile_t* file, int storage, const char* extdesc, str_list_t list, const char* path)
{
char* content = NULL;
char* metadata = NULL;
int result;
if(list != NULL && *list != NULL) {
size_t size = strListCount(list) * 1024;
content = calloc(1, size);
if(content == NULL)
metadata = calloc(1, size);
if(metadata == NULL)
return SMB_ERR_MEM;
strListCombine(list, content, size - 1, "\r\n");
strListCombine(list, metadata, size - 1, "\r\n");
}
result = smb_addfile(smb, file, storage, extdesc, content, path);
free(content);
result = smb_addfile(smb, file, storage, extdesc, metadata, path);
free(metadata);
return result;
}
......@@ -376,7 +376,7 @@ int smb_renewfile(smb_t* smb, smbfile_t* file, int storage, const char* path)
int result;
if((result = smb_removefile(smb, file)) != SMB_SUCCESS)
return result;
return smb_addfile(smb, file, storage, file->extdesc, file->content, path);
return smb_addfile(smb, file, storage, file->extdesc, file->metadata, path);
}
/****************************************************************************/
......
......@@ -283,8 +283,8 @@ SMBEXPORT int smb_open_fp(smb_t*, FILE**, int share);
SMBEXPORT void smb_close_fp(FILE**);
/* New FileBase API: */
enum file_detail { file_detail_index, file_detail_normal, file_detail_extdesc, file_detail_content };
SMBEXPORT int smb_addfile(smb_t*, smbfile_t*, int storage, const char* extdesc, const char* content, const char* path);
enum file_detail { file_detail_index, file_detail_normal, file_detail_extdesc, file_detail_metadata };
SMBEXPORT int smb_addfile(smb_t*, smbfile_t*, int storage, const char* extdesc, const char* metadata, const char* path);
SMBEXPORT int smb_addfile_withlist(smb_t*, smbfile_t*, int storage, const char* extdesc, str_list_t, const char* path);
SMBEXPORT int smb_renewfile(smb_t*, smbfile_t*, int storage, const char* path);
SMBEXPORT int smb_getfile(smb_t*, smbfile_t*, enum file_detail);
......
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