Skip to content

Add capability management functions and integrate with D-Bus interface - #67

Draft
Souptik-De wants to merge 44 commits into
OpenPrinting:masterfrom
Souptik-De:master
Draft

Add capability management functions and integrate with D-Bus interface#67
Souptik-De wants to merge 44 commits into
OpenPrinting:masterfrom
Souptik-De:master

Conversation

@Souptik-De

@Souptik-De Souptik-De commented Jul 17, 2026

Copy link
Copy Markdown

Also updated build.yml and codeql.yml to use git clone cpdb-libs instead of wget the last release

Update: locale + human-readable strings for GetAllCapabilities.

  • backend_helper.c: extract_ipp_attribute() was missing a case for
    IPP_TAG_BOOLEAN and fell through to ippGetString(), which returns
    NULL for boolean-tagged IPP values — real boolean options were
    coming back as "NA" instead of their actual value. Fixed.

…ket and add cupsFreeOptions and g_free for failure return paths
cupsCreateDestJob() was called with a manually managed http_t* from
cupsConnectDest(). This creates a TCP connection to the printer queue
where Local peer credential auth is impossible and Kerberos is
unavailable, causing a 401 Unauthorized when the CUPS policy requires
authentication.

Fix by using CUPS_HTTP_DEFAULT for all CUPS job I/O. This causes the
CUPS library to connect to cupsd via the Unix domain socket, where the
kernel automatically vouches for the caller's UID via peer credentials
(SO_PEERCRED), satisfying the authenticated policy without a password.

Also fix a thread safety bug: cupsStartDestDocument was called on the
main thread but cupsWriteRequestData and cupsFinishDestDocument were
called on the worker thread using the same http_t*. Since
CUPS_HTTP_DEFAULT is per-thread (stored in _cups_globals_t), all three
calls must be on the same thread. Move cupsStartDestDocument and
cupsCopyDestInfo into the worker thread alongside the data transfer
calls.
Remove p->http from PrinterCUPS and replace ensure_printer_connection()
with ensure_dest_info() which only manages p->dinfo. All CUPS API calls
now use CUPS_HTTP_DEFAULT, letting the library manage its own per-thread
Unix domain socket connection to cupsd.

Also fix a memory leak in cups_get_Resolution which never
freed its dinfo or closed its http_t.
…et/print_fd signatures for thread management
…IPP extraction

backend_helper.h: Add CPDB_CAP_UNKNOWN to CapabilityType; expand
Capability struct with human_readable_name, group_name,
human_readable_group, human_readable_choices; add locale param to
get_all_capabilities().

backend_helper.c:
- Fix extract_ipp_attribute(): add IPP_TAG_BOOLEAN case using
  ippGetBoolean() — was falling through to ippGetString() which
  returns NULL for boolean attributes, breaking both get_all_options()
  and get_all_capabilities() for boolean options.
- get_all_capabilities(): accept locale; populate human-readable
  fields via get_option_translation/get_choice_translation/
  cpdbGetGroupTranslation2 with raw-string fallback. Also store
  group_name directly instead of computing it only in pack_capability.
- pack_capability(): update to a(sssisia(ss)ii) tuple (10 fields).
- free_capabilities(): free all new fields.

print_backend_cups.c: Update on_handle_get_all_capabilities handler
signature to include locale; pass locale to get_all_capabilities();
update GVariantBuilder type string.
Three new wrapper functions (get_option_translation_with_fallback,
get_choice_translation_with_fallback, get_group_translation_with_fallback)
retry with locale 'en' when the requested locale returns NULL or the raw
keyword (no real translation found). Used in get_all_capabilities() to
ensure human-readable strings always have an English fallback before
falling back to raw IPP keywords.

The underlying get_option_translation, get_choice_translation, and
cpdbGetGroupTranslation2 are unchanged.
Remove get_option_translation_with_fallback,
get_choice_translation_with_fallback, get_group_translation_with_fallback
from backend_helper.c/h. Restore get_all_capabilities() to call plain
get_option_translation/get_choice_translation/cpdbGetGroupTranslation2
with no retry logic (those calls just pass locale through).

The English-fallback retry mechanism is now entirely in cpdb-libs
(cpdb-frontend.c: cpdbGetOptionTranslation, cpdbGetChoiceTranslation,
cpdbGetGroupTranslation, cpdbGetAllTranslations, cpdbGetAllCapabilities),
requiring ZERO backend-side changes — works against any backend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant