gpt4 book ai didi

CUPS 状态变更订阅

转载 作者:太空宇宙 更新时间:2023-11-03 23:41:45 39 4
gpt4 key购买 nike

我正在尝试监听打印机状态变化(例如卡纸、暂停...) 下面的代码给出“Bad notify-recipient-uri”响应,然后锁定 ippReadFile 并且在打印机暂停时不释放/未暂停。

int main()
{
http_t *http = httpConnectEncrypt(cupsServer(), ippPort(),
cupsEncryption());

ipp_t *request = ippNewRequest(IPP_CREATE_PRINTER_SUBSCRIPTION);

ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
NULL, "ipp://localhost:631/printers/Generic-text-only");
ippAddString(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI, "notify-recipient-uri",
NULL, "cups_test://");
ippAddString(request, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, "notify-events",
NULL, "printer-state-changed");

ipp_t *response = cupsDoRequest(http, request, "/");

while (1)
{
ipp_state_t state;
ipp_t *event = ippNew();

while ((state = ippReadFile(0, event)) != IPP_DATA)
{
printf("%s\n","Got Data");
}

printf("%s\n","Repeating");
ippDelete(event);
}
}

在筛选打印机属性后,我发现 notify-schemes-supported 属性设置为“dbus”。我无法使用 IPP_SET_PRINTER_ATTRIBUTES 更改属性。关于如何让它发挥作用的任何想法?

最佳答案

一个不需要任何 C 代码的非常基本的示例是针对 create-printer-subscription 宏使用 ipptool 来订阅事件的 rss URI。这是 pyipptool 说明的方法。 .

ipptool 通常随 CUPS 一起提供,但对于现代 Ubuntu 版本,您可能需要安装 cups-ipp-utils

首先,创建一个可以接收事件的 HTTP 套接字监听器...

python -m SimpleHTTPServer 9876

其次,将事件发送到套接字监听器。

ipptool -d recipient=rss://localhost:9876 ipp://localhost:631/printers /usr/share/cups/ipptool/create-printer-subscription.test

最后,触发一个事件,比如禁用打印机。

cupsdisable PDFWriter # or some valid printer name
cupsenable PDFWriter

rss:// URI 方案将对 HTTP 套接字服务器使用 PUT 命令。由于 SimpleHTTPServer 没有对 PUT 命令的内置支持,因此会出现 501 错误。您将必须自定义 HTTP 监听器来处理这些命令,但您会看到触发的事件。

请注意,默认的 create-printer-subscription 宏配置为发送 printer-config-changedprinter-state-changed 的事件> 但是 not printer-queue-order-changed可以通过复制宏并对其进行编辑来进行调整。

此外,这将使订阅在默认租用期限内保持事件状态(定义为 86400 in the source,应该是一天)。可以为无限期订阅指定零的附加参数 notify-lease-duration

关于CUPS 状态变更订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43621322/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com