Skip to content

Commit

Permalink
List raw sockets during printers subcommand if available
Browse files Browse the repository at this point in the history
Provide a way how to show path to raw socket via CLI without 3rd part
tools.
  • Loading branch information
zdohnal committed Feb 13, 2024
1 parent 528bd54 commit 1d497ad
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
47 changes: 45 additions & 2 deletions pappl/mainloop-subcommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,11 @@ _papplMainloopShowPrinters(
ipp_t *request, // IPP request
*response; // IPP response
ipp_attribute_t *attr; // Current attribute
ipp_tag_t value_tag; // Value tag of IPP attribute
const char *printer_name, // Printer name
*printer_uri, // Printer URI
*attr_name, // Attribute name
*socket_uri; // Socket URI


(void)num_options;
Expand All @@ -1177,8 +1182,46 @@ _papplMainloopShowPrinters(

response = cupsDoRequest(http, request, "/ipp/system");

for (attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME); attr; attr = ippFindNextAttribute(response, "printer-name", IPP_TAG_NAME))
puts(ippGetString(attr, 0, NULL));
for (attr = ippGetFirstAttribute(response); attr; attr = ippGetNextAttribute(response))
{
while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER)
attr = ippGetNextAttribute(response);

if (attr == NULL)
break;

value_tag = IPP_TAG_CUPS_INVALID;
printer_name = NULL;
printer_uri = NULL;
attr_name = NULL;
socket_uri = NULL;

for (; attr && ippGetGroupTag(attr) == IPP_TAG_PRINTER; attr = ippGetNextAttribute(response))
{
value_tag = ippGetValueTag(attr);

if (value_tag != IPP_TAG_NAME &&
value_tag != IPP_TAG_URI)
continue;

attr_name = ippGetName(attr);

if (value_tag == IPP_TAG_NAME && !strcmp(attr_name, "printer-name"))
printer_name = ippGetString(attr, 0, NULL);

if (value_tag == IPP_TAG_URI && !strcmp(attr_name, "smi55357-printer-socket-uri-supported"))
socket_uri = ippGetString(attr, 0, NULL);

if (value_tag == IPP_TAG_URI && !strcmp(attr_name, "printer-uri-supported"))
printer_uri = ippGetString(attr, 0, NULL);
}

if (printer_name && printer_uri)
printf("%s - printer - %s", printer_name, printer_uri);

if (printer_name && socket_uri)
printf("%s - raw socket - %s\n", printer_name, socket_uri);
}

ippDelete(response);
httpClose(http);
Expand Down
11 changes: 11 additions & 0 deletions pappl/printer-ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,17 @@ _papplPrinterCopyAttributesNoLock(
ippAddStrings(client->response, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_KEYWORD), "uri-authentication-supported", 2, NULL, uri_authentication_none);
}
}

if (printer->raw_active)
{
if (!ra || cupsArrayFind(ra, "smi55357-printer-socket-uri-supported"))
{
char socket_uri[1024]; // Buffer for socket URI

httpAssembleURI(HTTP_URI_CODING_ALL, socket_uri, sizeof(socket_uri), "socket", NULL, client->host_field, 9099 + printer->printer_id, NULL);
ippAddString(client->response, IPP_TAG_PRINTER, IPP_TAG_URI, "smi55357-printer-socket-uri-supported", NULL, socket_uri);
}
}
}


Expand Down

0 comments on commit 1d497ad

Please sign in to comment.