Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List raw sockets during printers subcommand if available #340

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to initialize a default attr_name or value_tag value. And printer-uri-supported is multi-valued so we might as well show all of the values.

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\n", printer_name, printer_uri);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not keen on the format here - better to display the raw URL separately, e.g.:

PRINTER-NAME
    ipp://HOSTNAME:PORT/ipp/print/PRINTER-NAME
    ipps://HOSTNAME:PORT/ipp/print/PRINTER-NAME
    socket://HOSTNAME:PORT

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, any text would need to be localized, so the above format avoids that particular issue...


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"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "smi55357-socket-uri-configured"? You need to configure for raw printing support and we don't need to have "printer" in the name.

{
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
Loading