istopwg / ippsample

IPP sample implementations.
http://istopwg.github.io/ippsample
Apache License 2.0
224 stars 80 forks source link

ippserver: Save documents with file extension corresponding to "document-format" Job Template attribute #219

Closed wifiprintguy closed 2 years ago

wifiprintguy commented 3 years ago

When ippserver receives a Document Creation operation (Print-Job, Send-Document, not sure about Send-URI), it saves the file using a .prn file extension. It would be better if it saved it using a file extension corresponding to the MIME media type specified by the "document-format" Job Template attribute.

As an example, here is a trace from ippserver receiving a JPEG file via Send-Document:

2021-02-02T22:54:30.070Z  [Client 22] POST /ipp/print/TestPrinter
2021-02-02T22:54:30.070Z  [Client 22] Continue
2021-02-02T22:54:30.070Z  [Client 22] Request: version=2.0
2021-02-02T22:54:30.070Z  [Client 22] Request: operation-id=Send-Document(0006)
2021-02-02T22:54:30.070Z  [Client 22] Request: request-id=4
2021-02-02T22:54:30.070Z  [Client 22] Request: operation-attributes-tag
2021-02-02T22:54:30.070Z  [Client 22] Request: attributes-charset (charset) utf-8
2021-02-02T22:54:30.070Z  [Client 22] Request: attributes-natural-language (naturalLanguage) en-us
2021-02-02T22:54:30.070Z  [Client 22] Request: printer-uri (uri) ipp://Serenity.local.:8503/ipp/print/TestPrinter
2021-02-02T22:54:30.070Z  [Client 22] Request: job-id (integer) 2
2021-02-02T22:54:30.070Z  [Client 22] Request: requesting-user-name (nameWithoutLanguage) mobile
2021-02-02T22:54:30.070Z  [Client 22] Request: last-document (boolean) true
2021-02-02T22:54:30.070Z  [Client 22] Request: document-format (mimeMediaType) image/jpeg
2021-02-02T22:54:30.070Z  [Client 22] Send-Document document-format='image/jpeg'
2021-02-02T22:54:30.070Z  [Job 2] Creating job file "./spool//TestPrinter/2-photo.prn", format "application/octet-stream".

If ippserver were to save the file appropriately, the last three lines would instead hopefully report this:

2021-02-02T22:54:30.070Z  [Client 22] Request: document-format (mimeMediaType) image/jpeg
2021-02-02T22:54:30.070Z  [Client 22] Send-Document document-format='image/jpeg'
2021-02-02T22:54:30.070Z  [Job 2] Creating job file "./spool//TestPrinter/2-photo.jpg", format "image/jpeg".

This would make examining the files directly easier, and this would also help downstream "transform" tools to make transform choices without having to open the files. Transform tools that always open the file and act on the byte stream don't need this change but this change won't break their implementation.

michaelrsweet commented 3 years ago

ippeveprinter and PAPPL both do this, investigating...

michaelrsweet commented 2 years ago

The code is setting the extension based on the job->format value, checking whether it is initialized before the calls...

michaelrsweet commented 2 years ago

Looks like Send-Document only set job->format if "document-format" wasn't specified or was 'application/octet-stream'.

[master ade54d0] Fix spool filename with Send-Document (Issue #219)