Repository navigation
Description
@alexpevzner I'd like to work on the // Load IPP hooks // TODO in modeling/ipp.go and wanted to check the approach with you before writing any code.
Why
Static model attributes can't express a lot of real device quirks. A few from ipp-usb's quirks database:
- Canon SELPHY CP1500 answers Get-Printer-Attributes with
server-error-internal-error, but the attributes are fine. A model can't set a status. - HP LaserJet M406 only partly works for a while after a reboot. That's time-dependent.
- HP Color LaserJet Flow is slow enough that ipp-usb needs a 20s init timeout.
- Issue broken supply level reports in IPP #30 / modeling/examples: add Broken-Supplies-Xerox-B235.py (broken marker-* report, #30) #138 cover supplies that are always broken. Hooks would also allow "breaks after a job" or "only in Get-Printer-Attributes".
What I'd add
def ipp_onIPPRequest(q: query.Query, msg: ipp.MESSAGE): ...
def ipp_onIPPResponse(q: query.Query, rq: ipp.MESSAGE, rsp: ipp.MESSAGE): ...ipp.MESSAGE would have version, code, request_id and an ordered list of ipp.GROUPs. Each group works like COLLECTION, plus add() for duplicate names, and the list keeps repeated job groups. I'd also add an ipp.STATUS enum and an ipp.Reject(status, msg) exception for the request hook.
Things I measured that shape the design
- Cost. Running a Get-Printer-Attributes reply through the existing converters takes about 300 ms for the Xerox B235 model and about 1.5 s for the HP M426fdn. A request takes about 1 ms. So I'd export requests fully, but treat replies as patches: the hook gets the header and operation group, other groups load only when the hook reads them, and Go applies only what changed to the original message. With no hook defined,
ServerHooksstays nil, so it costs nothing. - Fidelity. The converters lose three things: non-UTF-8 octetStrings (export fails), dateTime deciseconds, and duplicate attribute names. If the hook changes nothing, the original message goes out untouched, so it's byte-identical. I'd fix those three for when it does.
- Concurrency. Unlike eSCL, IPP requests run in parallel, so the wrappers keep no state on
Model. I'd avoid a global lock so one slow hook doesn't block everything.
Faster, per-attribute loading would need argument support in cpython callbacks (the TODO in callback.go). I'd leave that to you as a separate change.
Plan
Following your advice on #139, I'd start with tests, in two PRs:
- Converter fixes, plus tests showing the round trip is byte-identical.
- The hooks: a no-op hook gives an identical reply, plus a status-rewrite test, an exception test, a parallel-requests test with
-race, and an end-to-end check withmfp-virtualandipptool.
Does this sound right to you? I'm especially unsure about the API names and the lazy reply groups.
Activity
atharrva01 commentedon Nov 25, 2026
Hi @alexpevzner , can u please take a look at this , whenever u have a chance
Thanks...
alexpevzner commentedon Nov 26, 2026
Hi!
These hooks are planned, but not implemented yet.
I think I'll refactor eSCL hooks a little bit to be more Python-idiomatic before implementing IPP/WSD hooks.
For example, there should be a method to cancel HTTP query from the Python hook, returning the appropriate HTTP status, not only 503, as now. Looks like throwing Python exception is the most natural method to express it at the Python side.
The result should be simple, convenient and idiomatic at the Python side. Otherwise, nobody will use this functionality.
Regarding simulation of delays, lets put it at the end. This is rarely required and in most cases will be annoying, so I think when delays will be implemented, there are should be playback modes "time-accurate (with delays)" and "ignore delays", and the second mode should be default
I'm open to any ideas here, but please discuss them first, before implementing, and concentrating on the usage convenience
atharrva01 commentedon Nov 26, 2026
@alexpevzner , do we have any communication channel, where we can discuss about this?
alexpevzner commentedon Nov 26, 2026
Yes, Telegram: @a_pevzner
atharrva01 commentedon Nov 26, 2026
i tried reahng out to you on 23rd on this ID, but i think i didnt get through
alexpevzner commentedon Nov 26, 2026
I'm here. Just not always respond quickly :)