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

Commits (3)
......@@ -125,7 +125,7 @@ bool get_file_diz(file_t* f, char* ext, size_t maxlen)
return false;
}
printf("Parsing DIZ: %s\n", diz_fpath);
str_list_t lines = read_diz(diz_fpath, /* max_line_len: */80);
str_list_t lines = read_diz(diz_fpath);
format_diz(lines, ext, maxlen, /* allow_ansi: */false);
strListFree(&lines);
remove(diz_fpath);
......
......@@ -231,7 +231,7 @@ bool sbbs_t::movefile(smb_t* smb, file_t* f, int newdir)
return false;
}
if(!addfile(&cfg, newdir, f, f->extdesc))
if(!addfile(&cfg, newdir, f, f->extdesc, /* client: */NULL))
return false;
removefile(smb, f);
bprintf(text[MovedFile],f->name
......
......@@ -585,7 +585,28 @@ bool hashfile(scfg_t* cfg, file_t* f)
return result;
}
bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc)
int file_client_hfields(file_t* f, client_t* client)
{
int i;
if(client == NULL)
return -1;
if(*client->addr && (i = smb_hfield_str(f, SENDERIPADDR, client->addr)) != SMB_SUCCESS)
return i;
if(*client->host && (i = smb_hfield_str(f, SENDERHOSTNAME, client->host)) != SMB_SUCCESS)
return i;
if(client->protocol != NULL && (i = smb_hfield_str(f, SENDERPROTOCOL, client->protocol)) != SMB_SUCCESS)
return i;
if(client->port) {
char port[16];
SAFEPRINTF(port,"%u",client->port);
return smb_hfield_str(f, SENDERPORT, port);
}
return SMB_SUCCESS;
}
bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc, client_t* client)
{
char fpath[MAX_PATH + 1];
smb_t smb;
......@@ -594,6 +615,7 @@ bool addfile(scfg_t* cfg, uint dirnum, file_t* f, const char* extdesc)
return false;
getfilepath(cfg, f, fpath);
file_client_hfields(f, client);
int result = smb_addfile(&smb, f, SMB_SELFPACK, extdesc, fpath);
smb_close(&smb);
return result == SMB_SUCCESS;
......@@ -923,13 +945,13 @@ bool extract_diz(scfg_t* cfg, file_t* f, str_list_t diz_fnames, char* path, size
return false;
}
str_list_t read_diz(const char* path, size_t max_line_len)
str_list_t read_diz(const char* path)
{
FILE* fp = fopen(path, "r");
if(fp == NULL)
return NULL;
str_list_t lines = strListReadFile(fp, NULL, max_line_len);
str_list_t lines = strListReadFile(fp, NULL, /* max_line_len: */255);
fclose(fp);
return lines;
}
......
......@@ -23,6 +23,7 @@
#define _FILEDAT_H_
#include "scfgdefs.h" // scfg_t
#include "client.h"
#include "dllexport.h"
#include "smblib.h"
......@@ -52,13 +53,14 @@ 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);
DLLEXPORT bool addfile(scfg_t*, uint dirnum, file_t*, const char* extdesc, 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 extract_diz(scfg_t*, file_t*, str_list_t diz_fname, char* path, size_t);
DLLEXPORT str_list_t read_diz(const char* path, size_t max_line_len);
DLLEXPORT str_list_t read_diz(const char* path);
DLLEXPORT char* format_diz(str_list_t lines, char*, size_t maxlen, bool allow_ansi);
DLLEXPORT char* prep_file_desc(const char *src, char* dst);
DLLEXPORT int file_client_hfields(file_t*, client_t*);
DLLEXPORT str_list_t directory(const char* path);
DLLEXPORT long create_archive(const char* archive, const char* format
......
......@@ -1075,7 +1075,7 @@ static void receive_thread(void* arg)
lprintf(LOG_DEBUG,"%04d <%s> DATA Extracting DIZ from: %s",xfer.ctrl_sock, xfer.user->alias,xfer.filename);
if(extract_diz(&scfg, &f, /* diz_fnames */NULL, tmp, sizeof(tmp))) {
lprintf(LOG_DEBUG,"%04d <%s> DATA Parsing DIZ: %s",xfer.ctrl_sock, xfer.user->alias,tmp);
str_list_t lines = read_diz(tmp, /* max_line_len: */80);
str_list_t lines = read_diz(tmp);
format_diz(lines, extdesc, sizeof(extdesc), /* allow_ansi: */false);
strListFree(&lines);
if(!fdesc[0]) { /* use for normal description */
......@@ -1093,7 +1093,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))
if(!addfile(&scfg, xfer.dir, &f, extdesc, xfer.client))
lprintf(LOG_ERR,"%04d <%s> !DATA ERROR adding file (%s) to database"
,xfer.ctrl_sock, xfer.user->alias, f.name);
}
......
......@@ -185,6 +185,26 @@ set_file_properties(JSContext *cx, JSObject* obj, file_t* f, enum file_detail de
|| !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_extdesc)
&& ((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_extdesc)
&& ((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_extdesc)
&& ((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_extdesc)
&& ((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->to_list != NULL && *f->to_list != '\0') || detail > file_detail_extdesc)
&& ((js_str = JS_NewStringCopyZ(cx, f->to_list)) == NULL
|| !JS_DefineProperty(cx, obj, "to_list", STRING_TO_JSVAL(js_str), NULL, NULL, flags)))
......@@ -384,6 +404,66 @@ parse_file_properties(JSContext *cx, JSObject* obj, file_t* file, char** extdesc
}
}
prop_name = "from_ip_addr";
if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
HANDLE_PENDING(cx, cp);
if(cp == NULL) {
JS_ReportError(cx, "Invalid '%s' string in file object", prop_name);
return SMB_FAILURE;
}
if(smb_hfield_str(file, SENDERIPADDR, cp) != SMB_SUCCESS) {
free(cp);
JS_ReportError(cx, "Error %d adding '%s' property to file object", result, prop_name);
return result;
}
}
prop_name = "from_host_name";
if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
HANDLE_PENDING(cx, cp);
if(cp == NULL) {
JS_ReportError(cx, "Invalid '%s' string in file object", prop_name);
return SMB_FAILURE;
}
if(smb_hfield_str(file, SENDERHOSTNAME, cp) != SMB_SUCCESS) {
free(cp);
JS_ReportError(cx, "Error %d adding '%s' property to file object", result, prop_name);
return result;
}
}
prop_name = "from_protocol";
if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
HANDLE_PENDING(cx, cp);
if(cp == NULL) {
JS_ReportError(cx, "Invalid '%s' string in file object", prop_name);
return SMB_FAILURE;
}
if(smb_hfield_str(file, SENDERPROTOCOL, cp) != SMB_SUCCESS) {
free(cp);
JS_ReportError(cx, "Error %d adding '%s' property to file object", result, prop_name);
return result;
}
}
prop_name = "from_port";
if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
HANDLE_PENDING(cx, cp);
if(cp == NULL) {
JS_ReportError(cx, "Invalid '%s' string in file object", prop_name);
return SMB_FAILURE;
}
if(smb_hfield_str(file, SENDERPORT, cp) != SMB_SUCCESS) {
free(cp);
JS_ReportError(cx, "Error %d adding '%s' property to file object", result, prop_name);
return result;
}
}
prop_name = "desc";
if(JS_GetProperty(cx, obj, prop_name, &val) && !JSVAL_NULL_OR_VOID(val)) {
JSVALUE_TO_RASTRING(cx, val, cp, &cp_sz, NULL);
......@@ -969,7 +1049,7 @@ static void get_diz(scfg_t* scfg, file_t* file, char** extdesc)
char diz_fpath[MAX_PATH + 1];
if(extract_diz(scfg, file, /* diz_fnames: */NULL, diz_fpath, sizeof(diz_fpath))) {
char extbuf[LEN_EXTDESC + 1] = "";
str_list_t lines = read_diz(diz_fpath, /* max_line_len: */80);
str_list_t lines = read_diz(diz_fpath);
if(lines != NULL) {
format_diz(lines, extbuf, sizeof(extbuf), /* allow_ansi: */false);
strListFree(&lines);
......@@ -990,6 +1070,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
private_t* p;
char* extdesc = NULL;
file_t file;
client_t* client = NULL;
bool use_diz_always = false;
jsrefcount rc;
......@@ -1021,6 +1102,13 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
use_diz_always = JSVAL_TO_BOOLEAN(argv[argn]);
argn++;
}
if(argn < argc && JSVAL_IS_OBJECT(argv[argn]) && !JSVAL_IS_NULL(argv[argn])) {
JSObject* objarg = JSVAL_TO_OBJECT(argv[argn]);
JSClass* cl;
if((cl = JS_GetClass(cx, objarg)) != NULL && strcmp(cl->name, "Client") == 0) {
client = JS_GetPrivate(cx, objarg);
}
}
file.dir = p->smb.dirnum;
rc=JS_SUSPENDREQUEST(cx);
......@@ -1032,6 +1120,7 @@ js_add_file(JSContext *cx, uintN argc, jsval *arglist)
}
char fpath[MAX_PATH + 1];
getfilepath(scfg, &file, fpath);
file_client_hfields(&file, client);
p->smb_result = smb_addfile(&p->smb, &file, SMB_SELFPACK, extdesc, fpath);
JS_SET_RVAL(cx, arglist, BOOLEAN_TO_JSVAL(p->smb_result == SMB_SUCCESS));
}
......@@ -1471,7 +1560,7 @@ static jsSyncMethodSpec js_filebase_functions[] = {
,31900
},
{"add", js_add_file, 1, JSTYPE_BOOLEAN
,JSDOCSTR("file-meta-object [,use_diz_always=false]")
,JSDOCSTR("file-meta-object [,use_diz_always=false] [,object client=none]")
,JSDOCSTR("add a file to the file base")
,31900
},
......
......@@ -954,7 +954,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);
addfile(&cfg, i, f, f->extdesc, /* client: */NULL);
}
}
}
......
......@@ -505,8 +505,8 @@ typedef enum { /* Values for xtrn_t.event */
#define LEN_LOCATION 30 /* Location (City, State) */
#define LEN_ZIPCODE 10 /* Zip/Postal code */
#define LEN_MODEM 8 /* User modem type description */
#define LEN_FDESC 58 /* File description */
#define LEN_EXTDESC 1024 /* extended file description */
#define LEN_FDESC 58 /* File description (summary) */
#define LEN_EXTDESC 4000 /* Extended file description */
#define LEN_TITLE 70 /* Message title */
#define LEN_MAIN_CMD 28 /* Unused Storage in user.dat */
#define LEN_COLS 3
......
......@@ -154,7 +154,7 @@ bool sbbs_t::uploadfile(file_t* f)
if(extract_diz(&cfg, f, /* diz_fnames: */NULL, str, sizeof(str))) {
lprintf(LOG_DEBUG, "Parsing DIZ: %s", str);
str_list_t lines = read_diz(str, /* max_line_len: */80);
str_list_t lines = read_diz(str);
if(lines != NULL)
format_diz(lines, ext, sizeof(ext), /* allow_ansi: */false);
strListFree(&lines);
......@@ -186,7 +186,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))
if(!addfile(&cfg, f->dir, f, ext, &client))
return false;
safe_snprintf(str,sizeof(str),"uploaded %s to %s %s"
......
......@@ -596,6 +596,7 @@ typedef struct { /* Message or File */
*from_ip, /* From IP address (e.g. "192.168.1.2") */
*from_host, /* From host name */
*from_prot, /* From protocol (e.g. "Telnet", "NNTP", "HTTP", etc.) */
*from_port, /* From TCP/UDP port number */
*replyto, /* Reply-to name */
*replyto_ext, /* Reply-to extension */
*replyto_list, /* Comma-separated list of mailboxes, RFC822-style */
......
......@@ -773,6 +773,9 @@ static void set_convenience_ptr(smbmsg_t* msg, uint16_t hfield_type, void* hfiel
case SENDERPROTOCOL:
msg->from_prot=(char*)hfield_dat;
break;
case SENDERPORT:
msg->from_port=(char*)hfield_dat;
break;
case REPLYTO:
msg->replyto=(char*)hfield_dat;
break;
......@@ -910,6 +913,7 @@ static void clear_convenience_ptrs(smbmsg_t* msg)
msg->from_ip=NULL;
msg->from_host=NULL;
msg->from_prot=NULL;
msg->from_port=NULL;
memset(&msg->from_net,0,sizeof(net_t));
msg->replyto=NULL;
......