- ma.api: add per-instance FOpCS critical section to serialise Do* calls (fixes racing writers that dropped 8/100 messages) - .uni adapters: momCreate pre-creates empty format files - example_read/example_write/example_tosser - tests: test_read (samples), test_roundtrip (all 5 storage formats), test_lock (4 threads/100 msgs), test_batch (5 pkts*10 msgs/3 threads) - run_tests.sh: single-command test runner - build.sh: per-target binutils (i386-linux, i386-freebsd12, i386-emx)
109 lines
2.7 KiB
ObjectPascal
109 lines
2.7 KiB
ObjectPascal
{
|
|
example_write.pas - post one test message to any supported base
|
|
via the unified API.
|
|
|
|
usage: example_write <format> <path> <from> <to> <subject> <body>
|
|
|
|
Example:
|
|
example_write jam /tmp/testarea Sysop All Hello 'Hello, world'
|
|
|
|
For Hudson/GoldBase/MSG the path is a directory; for JAM/Squish
|
|
it is <dir>/<areaname> (no extension); for PKT it is the full
|
|
*.pkt filename; for EzyCom it is the base directory and board 1
|
|
is used by default.
|
|
}
|
|
|
|
program example_write;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
uses
|
|
SysUtils,
|
|
ma.types, ma.events, ma.api,
|
|
ma.fmt.hudson, ma.fmt.hudson.uni,
|
|
ma.fmt.jam, ma.fmt.jam.uni,
|
|
ma.fmt.squish, ma.fmt.squish.uni,
|
|
ma.fmt.msg, ma.fmt.msg.uni,
|
|
ma.fmt.pkt, ma.fmt.pkt.uni,
|
|
ma.fmt.pcboard, ma.fmt.pcboard.uni,
|
|
ma.fmt.ezycom, ma.fmt.ezycom.uni,
|
|
ma.fmt.goldbase, ma.fmt.goldbase.uni;
|
|
|
|
function ParseFormat(const S: string; out AFormat: TMsgBaseFormat): boolean;
|
|
begin
|
|
Result := True;
|
|
case LowerCase(S) of
|
|
'hudson': AFormat := mbfHudson;
|
|
'jam': AFormat := mbfJam;
|
|
'squish': AFormat := mbfSquish;
|
|
'msg': AFormat := mbfMsg;
|
|
'pcboard': AFormat := mbfPCBoard;
|
|
'ezycom': AFormat := mbfEzyCom;
|
|
'goldbase': AFormat := mbfGoldBase;
|
|
else
|
|
Result := False;
|
|
end;
|
|
end;
|
|
|
|
procedure Usage;
|
|
begin
|
|
WriteLn('Usage: example_write <format> <path> <from> <to> <subject> <body>');
|
|
WriteLn(' formats: hudson jam squish msg pcboard ezycom goldbase');
|
|
Halt(2);
|
|
end;
|
|
|
|
var
|
|
fmtName, path, whoFrom, whoTo, subject, body: string;
|
|
fmt: TMsgBaseFormat;
|
|
base: TMessageBase;
|
|
msg: TUniMessage;
|
|
begin
|
|
if ParamCount < 6 then Usage;
|
|
fmtName := ParamStr(1);
|
|
path := ParamStr(2);
|
|
whoFrom := ParamStr(3);
|
|
whoTo := ParamStr(4);
|
|
subject := ParamStr(5);
|
|
body := ParamStr(6);
|
|
|
|
if not ParseFormat(fmtName, fmt) then Usage;
|
|
|
|
try
|
|
base := MessageBaseOpen(fmt, path, momReadWrite);
|
|
except
|
|
on E: Exception do begin
|
|
WriteLn('error: ', E.Message);
|
|
Halt(1);
|
|
end;
|
|
end;
|
|
|
|
if not base.Open then begin
|
|
WriteLn('error: Open returned False (missing files? lock busy?)');
|
|
base.Free;
|
|
Halt(1);
|
|
end;
|
|
|
|
msg.MsgNum := 0;
|
|
msg.WhoFrom := whoFrom;
|
|
msg.WhoTo := whoTo;
|
|
msg.Subject := subject;
|
|
msg.DateWritten := Now;
|
|
msg.DateReceived := 0;
|
|
msg.Attr := MSG_ATTR_LOCAL;
|
|
msg.OrigAddr := MakeFTNAddress(1, 1, 1, 0);
|
|
msg.DestAddr := MakeFTNAddress(1, 1, 2, 0);
|
|
msg.Cost := 0;
|
|
msg.Body := body + #13;
|
|
msg.AreaTag := '';
|
|
|
|
try
|
|
if base.WriteMessage(msg) then
|
|
WriteLn('wrote message #', msg.MsgNum)
|
|
else
|
|
WriteLn('error: WriteMessage returned False');
|
|
finally
|
|
base.Close;
|
|
base.Free;
|
|
end;
|
|
end.
|