The executable now runs the app without its window: it owns the session
name or forwards to the instance that does (an sms: link, --quit; --quit
beside --send is refused, the errand being no instance, and so is a link
that is not UTF-8, which D-Bus does not carry; a name request that fails
or is refused ends the run with the error's words, exit 1, nobody being
shown to run), opens the database (the executable's own Crafter.DB
dependency enters here, with its first use), connects the GDBus client
to Sync and the notifier, and runs the GLib main loop. --daemon is the
resident mode, --headless adds a log line per event for the ssh smoke
test on the phone, --session talks to imsd --session, --data-dir and
--country override the database directory and the default country code
(a country code as the ITU's length rule reads one: a key is made of the
code as it is and read by that rule, so anything else is refused). A
--daemon with no sms: link that finds the name owned ends at once
instead of forwarding an Activate: the running instance already imports
and notifies, and a forwarded Activate asks it for its window;
--headless then exits 1, having run nothing (a link and --quit are
forwarded from a --daemon as from any launch). A Subscribe, a GetStatus
or a List that failed against a present imsd is tried again every 30 s,
and so is a text Sync holds for a store that refused it; that text is
notified all the same (OnUnstored), the notification being where it
shows, and is announced as any import once its row is in.
--send sends one text to the number as dialled (stored under its
normalised key; a NUMBER or TEXT that is not UTF-8 is refused before
anything is stored, exit 2: imsd takes D-Bus strings, and GLib would put
its own text in the place of other bytes and have that sent; an empty
NUMBER is refused there too) and exits on imsd's word for the submission
— sent (0) or failed (1), which reaches it as the message's change (a
status report's word follows sent, imsd's order) — or on its own failure
(1), a store that refuses the text among them; imsd has 60 s to be ready
and to take the text, then 2 (no final state) — once it has taken it the
clock decides nothing, since imsd bounds its submission itself and ends
it with a word, and a clock of the app's would report no final state for
a text imsd goes on to send — as a SIGINT or SIGTERM after the start-up,
before a final state, is 2 (a resident instance ending on either says so
in its log: a session bus closing under it sends SIGTERM too). It is a
client of its own: it takes no instance name, since a launch that finds
the name taken forwards and exits, and it leaves imsd's stored and
signalled texts to the instance that owns the user's store; beside that
instance it needs a --data-dir of its own, the store taking one writer.
It sends once GetStatus has answered, with Sync's Send gaining a force
flag that skips the local readiness check: imsd answers a Send to its
caller, subscribed or not, so a refused or unregistered errand ends with
imsd's own reason. Its rule is Sync's SendErrand, a class over the
listener's events with no GLib in it: one Send once the status is in and
none after an end, latched before the call (Sync announces a status from
inside Send — the store's word on its write — and the loop can dispatch
one after the clock's or a signal's end); one end — the message's final
state, the store's refusal, or none on the clock (which decides until
imsd has taken the text), a signal or the loop's end; the first of them
stands. The shell drives it with its loop, its 60 s source and its log.
Tested: tests/Sync, the errand among its cases (a forced send against an
unregistered status; imsd's words reaching the listener as the message's
changes, as they come), and its rule: one Send across a status announced
from inside Send (the store's recovery, end to end on a store refused
under the file-size limit), 0 on sent, 1 on failed and on the store's
refusal, 2 on the clock before imsd's id and on a signal, the clock
deciding nothing once imsd took the text, a final state given first
standing over the clock and the loop's end after it.
The GLib side of the app. Variant reads imsd's Received dictionary by
key and type as its SmsVariant writes it (`to`, the number the text
arrived for, a tel: URI read like the status's `ppi`; `operator`, the
SIM it arrived under), the GetStatus one with the subscriber's own
number and the SIM's operator in it (`ppi`, a tel: URI as the frozen
interface gives it; `operator`), and maps a GError to the core's error
kinds off GDBus's own mapping. Client is the Sync logic's transport:
asynchronous calls with their continuations as user data — every reply
guarded where it is delivered (OnCallDone), as are the signal handlers
and the name watch's callbacks: a throw is a fault the events hear, not
the end of the process — the calls behind imsd's polkit gate allow
interaction: Subscribe, List and Delete wait two minutes; Send has no
bound of the client's, since imsd sends the text once its prompt lets
the call through, however late, and a Send given up on would be failed
by Sync and be sent all the same; GetStatus ten seconds — (one call: the
Messaging status carries the own number, imsd reading both from one
snapshot; AGENTS.md §1 names both interfaces), the Messaging and
RegistrationChanged signals, and a watch on net.catcrafts.IMS1 whose
appeared callback is where Sync subscribes. Notifier shows one desktop
notification per conversation and replaces it as more texts arrive: one
Notify at a time per conversation, since the id to replace comes with
the answer; its default action asks the app for that conversation; the
body is escaped when the server renders markup (GetCapabilities, asked
once; Plasma and GNOME do), so a text's '<' or '&' shows as typed.
Instance owns net.catcrafts.ImsdMessages and serves
org.freedesktop.Application there, the Desktop Entry Specification's
interface of a running application: Activate, Open and ActivateAction,
each with its platform data — sent empty and not read: nothing in the
app can use an activation token yet — and one action, quit, any other
refused (the object registered before the name is asked for, so a launch
that forwards the moment the name is granted finds it; Own tells a name
another instance holds from a request that failed or was refused, and
keeps the error's words); it forwards a call to the owner. project.cpp
computes the gio flags once for the bus library, the executable and the
Decode test.
Tested: tests/Decode (every key of imsd's Received dictionary, one with
ten of them, GetStatus, the own number, the SIM's operator, the error
kinds, the markup escape, the parameters of the instance's three calls).
imsd keeps a received text it could store until the app deletes it and
sends its signals unicast to subscribers, so the logic is: Subscribe
whenever net.catcrafts.IMS1 appears (imsd's restart empties its list),
then GetStatus, whose answer ends the connecting state, and List, both
at once — a listed or signalled text keys itself by the number it
arrived for (imsd's `to`, the subscriber's own number at receipt) or,
lacking one, by the service centre that delivered it (Model's
MessageFromReceived), so no import waits for a status; import what the
store lacks, keyed by imsd's id (its run's token makes it unique across
imsd's runs, §8.4), and delete imsd's copy — again for a copy still
listed, so a delete that timed out gets another chance. A short message
type 0 (Model's IsType0) is not imported: imsd acknowledged it, and its
copy is deleted like any other. A copy polkit refused to delete is
counted on the banner and tried again at the next List imsd admits (one
polkit action gates List and Delete, so an admitted List means an
admitted Delete) and once imsd has restarted. A Received signal imports
and lists again, because a signal is queued for nobody. The listener is
called through a guard (GuardedListener): a throw out of a handler — a
logging failure, a bad_alloc — is caught and told once, so no handler
can stop Sync's own sequence, whatever the order of a word and the step
after it. A store that refuses a write (its disk full) is on the banner.
A listed text stays imsd's — nothing is deleted — and a signalled one is
held in memory and told through OnUnstored: imsd signals a text its own
store refused too, the signal then its only delivery, so no List may
ever carry it; the held text is tried again whenever a List comes back
with imsd's texts and at each Refresh, which is wanted while one is
held, until its row is in or a List carries it; one imsd did not store
is lost with a process that ends before then. Of the refusal itself the
store tells Sync of a refusal once and once of the next write that got
room (one that grew a file), every write but a Compact passing that one
gate, and the flag stays the store's — read again after the start's
sweep and after imsd's vanish; a send still goes, its own write a try —
refused, it answers kNotStored and the caller keeps the text; through,
it goes to imsd, and imsd's id lands in place (the store keeps it
inline) — a recovery lists at once and the Refresh lists meanwhile, so
the held imports are tried once there is room. A listener's call can
come from inside Sync's own (the store's word on a write, inside Send),
which the listener interface says. A Send stores the message pending
under its conversation key and asks imsd for the address as dialled (the
key groups; a country code completed for it is never dialled), the row
carrying the plan it is dialled under — the country code of the SIM's
own number, never the service centre's stand-in, and its operator, which
imsd's status gives — which a retry under another SIM's plan fails on,
since the address would reach another subscriber or another service
there (Number's AnotherPlan, here with its first caller: the same
operator is the same plan, a side's code known or not; under another
operator a national number means the same while both SIMs' own numbers
have one country code, and a short code is the operator's own; without
both operators the codes decide alone), and the StateChanged for its id
(unique across imsd's runs by the run's token, so it names one message)
moves it on — each word as it comes, imsd giving them in order (the
submission's first, a report's after sent; its AGENTS.md section 8.4) —
and a retry drops the failed attempt's imsd id (a row's id names its
current attempt); a Send's error fails the row and Retry sends the text
again, so the transport's contract (ImsdTransport's comment) is that a
Send is answered by imsd, or because imsd has left the bus, and never by
a clock of the transport's own, since imsd sends what it was asked once
its polkit prompt lets the call through, however late; imsd vanishing
fails what was in flight, and a message still pending from an earlier
run is failed at start, because its answer may have come while the app
was not running. A refused Subscribe or List is the degraded mode: the
banner says so and sending is off — until Refresh is admitted again,
since imsd asks polkit on every gated call and a refusal that held while
the session was inactive lifts when it is active (a List answered ends
it, a refused Subscribe is made again; every refusal is announced, and
RefreshWanted() asks for the Refresh). A Subscribe that fails otherwise,
a GetStatus or a List (one that timed out: the texts imsd holds would
wait for the next signal) is tried again by Refresh too, which
RefreshWanted() asks for — one Subscribe at a time, so a rule that
prompts is not asked again while that Subscribe waits on its prompt; a
registration change reads the status again, since imsd fills in the
subscriber's own number and the service centre's when it registers; the
own number's country code completes a typed national number (a received
one carries its own), the centre's stands in when the network gave no
tel: URI (an MVNO's centre can be abroad); without either a national
number stays as typed, since the store's correspondents do not say where
the subscriber is. The transport is an interface with callbacks, so the
tests' fake can stand in for the bus.
Tested: tests/Sync on a fake transport that records every call and
answers when told, the retries, the second GetStatus, the as-dialled
destination, a retry under another SIM (refused for a national number
under another country's and for a short code under another operator of
the same country; let through under the same operator, its own number
read or not, and for a national number under another operator of its
country), the plan's code the own number's or the constructor's override
and never the centre's, a short message type 0 left out of the store
with imsd's copy deleted, a text signalled before the status's answer
imported at once by the number it arrived for, a listener's throw at a
status — the constructor's among them, over a store that refuses — a log
line and a registration change caught and told, stopping no step, a
Refresh over an unanswered Subscribe sending none, a List that timed out
listed again, the words applied as they come, a retry under a new id,
and a refusal lifted among them; the store's refusal under the file-size
limit (the flag, the Refresh wanted and the log; a send answered
kNotStored with imsd asked nothing; an import refused leaving imsd's
copy with the banner up across imsd's restart; a short text sent through
the refusal, imsd's id landing in place and its `sent` with it, a failed
attempt's id dropped at the retry; then, room again, the send's own
write clearing the flag and the held text imported and deleted at the
List the recovery sends); a signalled text the store refuses that no
List carries (told as unstored once, unread though its conversation is
open, held across a List's answer and a Refresh, stored at the Refresh
after there is room, its delete answered NotFound), one a List does
carry (the copy held here dropped, the text imported by the next List),
and one still held when another write gives the store room (a Refresh
wanted for it alone until the recovery's List is answered); a listed
text the store refuses is not held.
One table without an ordered column: Crafter.DB enforces the order on
every write, and a List() import after a restart can carry an older
stamp than the last row, so a conversation is sorted on read. A row
carries the plan it was written under, the SIM's country code and its
operator, a column each. Messages are looked up by imsd id (unique
across imsd's runs by its run token: an id names one message, and an
empty one — a text imsd has not answered yet — none); read marks and
deletes go per message and per conversation; every write but a Compact
is caught at this one boundary — a store that refuses one (Crafter.DB's
IOError: the disk full, the file system read-only) answers nullopt from
Add, false or a count of 0 (a row appended before its Flush failed is
tombstoned; an in-place write whose Flush failed stays in the row as the
process reads it; SetState's state and imsd's id land in place even when
a reason cannot — the id is inline in the row, 64 bytes as imsd bounds
it, one past that refused rather than thrown), and tells its
onWriteState listener once of the refusal and once of the next write
that got room, which is one that grew a file: Crafter.DB allocates its
extents, so a write that fit the ones it had (an in-place one, a short
row) is no recovery. So a refused write ends no caller's process and the
app's banner can say so. A lock file beside the table, held for the
store's life, makes a second store on the same directory throw
LockedError (the table's own lock sits on an inode a Compact replaces);
it is built on Crafter.DB's File and Os — the directory made 0700 at
every component, the file 0600 and never a symlink, a lock that fails
for any reason but another holder an IOError, not a LockedError. Every
change a call answers as made — a row id, true, a count — is committed
before the call returns, so a row Add returned is on disk. The file's
format is held by the build: static_asserts on the row's size and layout
fingerprint (Crafter.DB's Layout) and on the stored values of Direction
and MessageState, so a column changed without a version bump fails the
build and not a user's open, and an enumerator moved fails it where an
open would misread the stored states without a word.
Tested: tests/Store in a temp directory: the round trip, the sort of a
later-appended older message, the updates, the lookup by imsd id and an
erased row's, an id past imsd's bound refused, the lock from a second
open, persistence across a reopen, Compact, a row kept by a child
process that ends without a flush, the private file modes, and a write
refused under the file-size limit (told once with its reason, the rows
before it standing, an in-place write going through and telling nothing,
a state landing without its refused reason and imsd's id beside it, the
next Add after the limit's lifting telling of the recovery once), and a
Flush failing after its Append (the descriptor pointed at /dev/null for
the one write) tombstoning the row Add refused.
The GLib-free shape of what the app shows: imsd's state words (each
applies as it comes: imsd gives a message's words in order, the
submission's first and a status report's after sent, its AGENTS.md
section 8.4); a received text (the dictionary of imsd's AGENTS.md
section 8.4) becoming a message keyed by the sender's address completed
with the code of the number it arrived for (imsd's `to`, the
subscriber's own number at receipt — the record's: a text imsd kept
across a SIM change would otherwise take the new SIM's code) or, lacking
one, of the service centre that delivered it, the own number's code —
none where the centre's stood in, which names no SIM's country — and the
operator of the SIM it arrived under (imsd's `operator`) its plan
(Number's SimPlan), and whose sort time is the service centre's stamp,
else its arrival; the short message type 0, which a phone acknowledges
and discards (IsType0, TS 23.040 9.2.3.9); the grouping into
conversations newest first, unread counting incoming unread only; and
the one-line banner from what the app knows about imsd: absent,
connecting (GetStatus has not answered since imsd appeared), off,
subscribe refused, unregistered, the store refusing a write (its disk
full: texts wait; a send still goes), subscribe failed otherwise — what
blocks sending before what only costs live updates — messages it may not
delete.
Tested: tests/Model.
Crafter.Graphics shapes one line at a time and drops newlines, so the app
breaks text itself: a greedy wrap with breaks after spaces and hyphens
(a space that itself overflows ends the line after the words that fit,
and opens no line of its own when it ends the text or a newline
follows; one at a line's start is no break at all, nor is a run of
them: a break is recorded only once the line holds a word, and a run of
spaces wider than the line splits like a word, with the same rule at the
text's end and before a newline), hard breaks at
newlines, over-long words split between code points, and
the run of spaces where a line wraps left out of both lines. Results are
cached per (text, width, size). The measure is a function, so the caller
supplies the advances; the tests use a constant ten-pixel advance.
Tested: tests/Wrap on a ten-pixel monospace measure, a leading run of
spaces among the cases.
imsd renders the service centre's time stamp of a text as ISO 8601 with
the centre's offset and adds the arrival epoch; the captions need the
user's local day and clock. The parser is hand-rolled, with the
calendar's own check of the date (a 30th of February is no date); the
civil dates, the weekdays and the month names are std::chrono's calendar
and its formatting; every caption takes the local offset of the instant
as an argument, so nothing here depends on a time zone database and the
tests inject the offsets.
Tested: tests/Time, the KPN bench stamp in five spellings, rejected
garbage and days the month does not have, the day and list captions
around midnight and across a year.
An address becomes one conversation key. A number in international form
becomes E.164, and one in national form gets the given country code in
front — nine digits or more with a leading 0, or eight or more without
one, as a plan without a trunk prefix writes its numbers, the latter
only while the result is no longer than a number can be; the country
code of an E.164 number is found by the ITU length rule; short codes and
alphanumeric senders are their own keys. The display form puts a space
after the country code.
The key groups; a text goes to the address as dialled (DialledNumber:
the separators gone, a parenthesised trunk zero after a country code
dropped — not after Italy's code or San Marino's, where no zero is a
trunk prefix (a landline's is part of its number, a mobile has none):
such an address names two numbers and is none — nothing added), since
imsd sends a national number or a short code with the type unknown and
the network reads it by its own dialling plan — a country code completed
for the key would be dialled for real. A national number's leading 0 is
taken for the trunk prefix and goes when the country code is added — not
under Italy's code or San Marino's, where it is the number's and stays.
The key's known limits are of grouping: a number written with its
country code and no '+' is completed as a national one, one of a plan
whose trunk prefix is not a lone 0 (Hungary's 06, Russia's 8) is
completed wrongly, and a national number shorter than those lengths
(Iceland's seven digits) stays its digits.
Tested: tests/Number, thirty-two normalisation cases (the parenthesised
trunk zero of an international number, one after San Marino's code left
as no number, a national number's zero kept under Italy's code and San
Marino's, the numbers without a trunk prefix and both rules' shortest
numbers among them), twelve dialled forms (two with a zero in
parentheses after Italy's code, left as typed, among them), the country
codes of one-, two- and three-digit countries, the display forms.
The SMS app for imsd's net.catcrafts.IMS1.Messaging interface starts
here: the licence (GPL-3.0-only), FUNDING.yml, README and AGENTS, a
project.cpp with the three build products (imsd-messages-core: std and
Crafter.DB; imsd-messages-bus: GLib; the imsd-messages executable),
their module units as stubs, the version constant, the bundled Noto Sans
font with its OFL text, and the first test. This commit is the base every
later range is reviewed against.
Tested: crafter-build builds the three products and --version answers,
crafter-build test passes the one test, lint and format --check are clean
on every text rule and on the AST rules for the eleven files without a
global module fragment; the four files that include gio/gio.h are not
parsed by the lint driver's libclang (no C++ standard library on its
include path: 'type_traits' file not found), which is a Crafter.Build
matter.