How to dissect a CUPS job control file '/var/spool/cups/cNNNNNN'?

Kur*_*fle 4 binaryfiles cups ipp-protocol

When printing a job to a CUPS server, you can set up the cupsd.conf parameters PreserveJobHistory and PreserveJobFiles to control how many jobs you want to keep.

CUPS always temporarily stores the actual print job files in directory /var/spool/cups/. The spool files as submitted by the print client (before CUPS' conversion chain of filters kicks in) are always named dNNNNNN-001 (starting with a 'd' as in 'datafile') where NNNNNN is the job ID assigned by CUPS. If you submit a multi-document print job, the second document's spool file within the same job ID is named dNNNNNN-002, and so on...

此外,同一目录将保存以另一个字符开头的文件,即控制文件,并且每个作业的它们将被命名为cNNNNNN

我想剖析这些控制文件。

当我使用该strings工具时,它只显示了我想要得到的部分内容:

例子:

 sudo strings /var/spool/cups/d00089

  attributes-charset
  utf-8H
  attributes-natural-language
  en-us
  printer-uri
  %ipp://localhost:631/printers/hp2B
  job-originating-user-name
  kurtpfeifleB
  job-name
  hosts!
  copies
  finishings
  job-cancel-after
  job-hold-until
  no-hold!

  job-priority
  job-sheets
  noneB
  none!
  number-up
  job-uuid
  -urn:uuid:ca854775-f721-34a5-57e0-b38b8fb0f4c8B
  job-originating-host-name
  localhost!
  time-at-creation
  time-at-processing
  time-at-completed
  job-id
  job-state
  job-state-reasons
  processing-to-stop-point!
  job-media-sheets-completed
  job-printer-uri
  (ipp://host13.local:631/printers/hp!

  job-k-octets
  document-format
  text/plainA
  job-printer-state-message
  job-printer-state-reasons
  none
Run Code Online (Sandbox Code Playgroud)

另外,该strings输出看起来不太好。

问题:是否有一种编程(或其他)方式来剖析这些 CUPS 作业控制文件并获取其包含所有信息的完整内容?

Kur*_*fle 11

我自己找到了答案...

当您从源代码编译 CUPS 时,会出现子目录cups。它还包含特定于该子目录的Makefile。该 Makefile 包含一个名为“unittests”的构建目标,默认情况下构建!

但是,如果您运行make unittests它,它不仅会运行其单元测试,还会创建一些命令行实用程序,这些实用程序也可能在单元测试之外发挥很好的作用!

对于解决我的问题的案例,事实证明testippCLI 实用程序是纯金的。看看你自己:

sudo ./testipp /var/spool/cups/c00089

 operation-attributes-tag:

     attributes-charset (charset): utf-8
     attributes-natural-language (naturalLanguage): en-us

 job-attributes-tag:

     printer-uri (uri): ipp://localhost:631/printers/hp
     job-originating-user-name (nameWithoutLanguage): kurtpfeifle
     job-name (nameWithoutLanguage): hosts
     copies (integer): 1
     finishings (enum): none
     job-cancel-after (integer): 10800
     job-hold-until (keyword): no-hold
     job-priority (integer): 50
     job-sheets (1setOf nameWithoutLanguage): none,none
     number-up (integer): 1
     job-uuid (uri): urn:uuid:ca854775-f721-34a5-57e0-b38b8fb0f4c8
     job-originating-host-name (nameWithoutLanguage): localhost
     time-at-creation (integer): 1472022731
     time-at-processing (integer): 1472022731
     time-at-completed (integer): 1472022732
     job-id (integer): 89
     job-state (enum): completed
     job-state-reasons (keyword): processing-to-stop-point
     job-media-sheets-completed (integer): 0
     job-printer-uri (uri): ipp://host13.local:631/printers/hp
     job-k-octets (integer): 1
     document-format (mimeMediaType): text/plain
     job-printer-state-message (textWithoutLanguage): Printing page 1, 4% complete.
     job-printer-state-reasons (keyword): none
Run Code Online (Sandbox Code Playgroud)

不幸的是,运行make install不会将此工具安装到系统中,因此它永远不会暴露给任何 CUPS 管理员!此外,Linux 发行版打包者可能很容易忽视它。testipp大多数 CUPS 极客都不会注意到它。

还有一些由 构建的更有用的实用程序make unittests
这些是: testadmin, testarray, testcache, testclient, testconflicts, testcreds, testcups, testdest, testfile, testgetdests, testhttp, testi18n, testlang, testoptions, testppd, testpwg, testraster, testsnmp

不幸的是,目前还没有 Linux 发行版构建和发布这些有用的工具。因此,如果您认识发行版打包者,请在此处向他指出这一发现,并要求她为、 或或或他的 $distro 的包名称后缀是什么的所有最终用户打包一个漂亮的捆绑包!`cups-test-utils.rpmcups-test-utils.debcups-test-utils.tgz


小智 5

我遇到了类似的问题 - 我们需要工作的持续时间并发现了您的线程。testIPP 到目前为止工作得很好,但我不想仅仅为了这些简洁的小工具来编译 cups,而且我还需要它集成到其他基于 go 的应用程序中。

我已经开始在 go 中实现小型 CLI 实用程序,它也可以用作库 https://github.com/ui-kreinhard/go-cups-control-files