Skip to content
Snippets Groups Projects
Commit 6ffce6e3 authored by deuce's avatar deuce
Browse files

Split out FREQIT into a separate SRIF handler and FREQIT object to allow

embedding REQ handling into binkit.
parent e41f7ff2
No related branches found
No related tags found
No related merge requests found
......@@ -5,10 +5,21 @@
* exec "/sbbs/exec/jsexec freqit *S" *.req *.REQ
*/
load("filebase.js");
load("fidocfg.js");
load("freqit_common.js");
var cfg = new FREQITCfg();
FREQIT.add_file = function(filename, resp, cfg)
{
if (filename === undefined)
return;
if (FREQIT.files >= cfg.maxfiles)
return;
if (FREQIT.added[filename] !== undefined)
return;
resp.writeln('+'+filename);
FREQIT.files++;
FREQIT.added[filename]='';
};
function parse_srif(fname)
{
......@@ -21,7 +32,7 @@ function parse_srif(fname)
log(LOG_ERROR, "Unable to find SRIF file '"+f.name+"'");
return undefined;
}
while(l = f.readln(65535)) {
while((l = f.readln(65535))) {
if ((m=l.match(/^\s*([^ ]+)\s+(.*)$/)) !== null)
srif[m[1].toLowerCase()] = m[2];
}
......@@ -29,71 +40,6 @@ function parse_srif(fname)
return srif;
}
var dircache={};
var added={};
var files=0;
function add_file(filename, resp)
{
if (filename === undefined)
return;
if (files >= cfg.maxfiles)
return;
if (added[filename] !== undefined)
return;
resp.writeln('+'+filename);
files++;
added[filename]='';
}
/*
* TODO: built-in magic names... FILES and NEW
* FILES lists all FREQable files and
* NEW lists ones newer than 10 days.
*/
function handle_magic(magic, resp, protected, pw)
{
var file=undefined;
if (magic.secure && !protected)
return;
if (dircache[magic.dir] === undefined)
dircache[magic.dir] = FileBase(magic.dir);
dircache[magic.dir].forEach(function(fent) {
if (wildmatch(fent.name, magic.match, true)) {
if (file === undefined || fent.uldate > file.uldate)
file = fent;
}
});
if (file !== undefined) {
add_file(file.path, resp);
return 1;
}
return 0;
}
function handle_regular(match, resp, protected, pw)
{
var file=undefined;
var count=0;
function handle_list(list) {
list.forEach(function(dir) {
if (dircache[dir] === undefined)
dircache[dir] = FileBase(dir);
dircache[dir].forEach(function(fent) {
if (wildmatch(fent.name, match, true))
add_file(fent.path, resp);
});
});
}
if (protected)
handle_list(cfg.securedirs);
handle_list(cfg.dirs);
}
function handle_srif(srif)
{
var req=new File(srif.requestlist);
......@@ -101,6 +47,7 @@ function handle_srif(srif)
var m;
var fname;
var pw;
var cfg = new FREQITCfg();
if (!req.open("r"))
return;
......@@ -109,7 +56,7 @@ function handle_srif(srif)
resp.position = resp.length;
next_file:
while(fname=req.readln()) {
while((fname=req.readln())) {
if ((m=fname.match(/^(.*) !(.*?)$/))!==null) {
pw=m[2];
fname=m[1];
......@@ -117,13 +64,13 @@ function handle_srif(srif)
// First, check for magic!
for (m in cfg.magic) {
if (m == fname.toLowerCase()) {
handle_magic(cfg.magic[m], resp, srif.remotestatus.toLowerCase() === 'protected', pw);
FREQIT.handle_magic(cfg.magic[m], resp, srif.remotestatus.toLowerCase() === 'protected', pw, cfg);
continue next_file;
}
}
// Now, check for the file...
handle_regular(fname, resp, srif.remotestatus.toLowerCase() === 'protected', pw);
FREQIT.handle_regular(fname, resp, srif.remotestatus.toLowerCase() === 'protected', pw, cfg);
}
}
......
/*
* TODO: built-in magic names... FILES and NEW
* FILES lists all FREQable files and
* NEW lists ones newer than 10 days.
*/
load("filebase.js");
var FREQIT = {
dircache:{},
added:{},
files:0,
reset:function()
{
this.added = {};
this.files = 0;
},
handle_magic:function (magic, cb_data, protected, pw, cfg)
{
var file=undefined;
if (magic.secure && !protected)
return;
if (this.dircache[magic.dir] === undefined)
this.dircache[magic.dir] = new FileBase(magic.dir);
this.dircache[magic.dir].forEach(function(fent) {
if (wildmatch(fent.name, magic.match, true)) {
if (file === undefined || fent.uldate > file.uldate)
file = fent;
}
});
if (file !== undefined) {
this.add_file(file.path, cb_data, cfg);
return 1;
}
return 0;
},
handle_regular:function (match, cb_data, protected, pw, cfg)
{
var file=undefined;
var count=0;
function handle_list(list) {
list.forEach(function(dir) {
if (this.dircache[dir] === undefined)
this.dircache[dir] = new FileBase(dir);
this.dircache[dir].forEach(function(fent) {
if (wildmatch(fent.name, match, true))
this.add_file(fent.path, cb_data);
});
});
}
if (protected)
handle_list(cfg.securedirs);
handle_list(cfg.dirs);
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment