Skip to content

Add CUPS printing system bindings to c.s.j.p.unix - #1718

Merged
dbwiddis merged 1 commit into
java-native-access:masterfrom
dbwiddis:add-cups-bindings
May 10, 2026
Merged

dbwiddis merged 1 commit into
java-native-access:masterfrom
dbwiddis:add-cups-bindings

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Adds Cups interface to c.s.j.p.unix providing JNA bindings for libcups, the Common UNIX Printing System library available on Linux, macOS, and other UNIX platforms.

Structures

Structure C type Description
CupsDest cups_dest_t Printer/class destination with name, instance, and options
CupsOption cups_option_t Name/value option pair
CupsJob cups_job_t Print job with ID, state, title, user, and timestamps

Functions

Function Description
cupsGetDests / cupsGetDests2 Enumerate available printers
cupsFreeDests Free destination list
cupsGetDest Find a printer in a list by name
cupsGetNamedDest Optimized single-printer lookup
cupsGetDefault Get default printer name
cupsGetOption Read an option value
cupsAddOption Add/replace an option
cupsFreeOptions Free options array
cupsGetJobs2 Get print jobs (active/completed/all)
cupsFreeJobs Free job array
cupsCancelJob Cancel a print job
cupsServer / cupsSetServer Get/set CUPS server
cupsUser / cupsSetUser Get/set CUPS user
cupsLastError / cupsLastErrorString Error reporting

Constants

  • Printer state: IPP_PRINTER_IDLE, IPP_PRINTER_PROCESSING, IPP_PRINTER_STOPPED
  • Printer type flags: CUPS_PRINTER_CLASS, CUPS_PRINTER_COLOR, CUPS_PRINTER_DUPLEX, etc.
  • Job state: IPP_JSTATE_PENDING through IPP_JSTATE_COMPLETED
  • Job filters: CUPS_WHICHJOBS_ALL, CUPS_WHICHJOBS_ACTIVE, CUPS_WHICHJOBS_COMPLETED

Closes #1710

Test Output

On my local mac with actual printers:

[junit] Testsuite: com.sun.jna.platform.CupsTest
[junit] Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.393 sec
[junit] 
[junit] ------------- Standard Output ---------------
[junit] Default named dest: HP_ENVY_6000_series
[junit] Number of CUPS destinations: 2
[junit] First destination: SecurePrintAMER
[junit]   printer-info: Secure Print AMER
[junit]   printer-state: 3
[junit]   printer-type: 2109692
[junit] CUPS server: /private/var/run/cupsd
[junit] Number of CUPS jobs: 50
[junit] First job: id=4 dest=HP_ENVY_6000_series title=Microsoft Word - Guidelines.docx state=9
[junit] CUPS user: dbwiddis
[junit] Default printer: HP_ENVY_6000_series
[junit] ------------- ---------------- ---------------

@dbwiddis
dbwiddis force-pushed the add-cups-bindings branch 4 times, most recently from 9730d3f to 2e49a2e Compare May 9, 2026 21:47
@dbwiddis
dbwiddis requested a review from matthiasblaesing May 9, 2026 21:52

@matthiasblaesing matthiasblaesing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks sane to me. For the documentation references people need to be careful. I noticed for example for CupsJob the structure definition in the documentation did not match the header file. The mapping is sane with respect to the header, so is good.

You might want to consider this change:

--- a/contrib/platform/test/com/sun/jna/platform/CupsTest.java
+++ b/contrib/platform/test/com/sun/jna/platform/CupsTest.java
@@ -27,6 +27,9 @@
 import com.sun.jna.platform.unix.Cups;
 import com.sun.jna.Pointer;
 import com.sun.jna.ptr.PointerByReference;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
 
 import junit.framework.TestCase;
 
@@ -88,7 +91,8 @@
                 assertNotNull("Destinations pointer should not be null", destsPtr);
 
                 // Read the first destination
-                Cups.CupsDest dest = new Cups.CupsDest(destsPtr);
+                Cups.CupsDest[] dests = (Cups.CupsDest[]) new Cups.CupsDest(destsPtr).toArray(numDests);
+                Cups.CupsDest dest = dests[0];
                 assertNotNull("First destination name should not be null", dest.name);
                 System.out.println("First destination: " + dest.name
                         + (dest.is_default != 0 ? " (default)" : ""));
@@ -106,7 +110,7 @@
 
                     String printerType = Cups.INSTANCE.cupsGetOption(
                             "printer-type", dest.num_options, dest.options);
-                    System.out.println("  printer-type: " + printerType);
+                    System.out.println("  printer-type: " + printerType + " " + mapPrinterTypeEnumNames(printerType).toString());
                 }
             }
         } finally {
@@ -116,6 +120,28 @@
         }
     }
 
+    public List<String> mapPrinterTypeEnumNames(String printerType) throws RuntimeException, NumberFormatException {
+        try {
+            List<String> result = new ArrayList<>();
+
+            int printerTypeInt = Integer.parseInt(printerType);
+
+            for (Field f : Cups.class.getFields()) {
+                String fieldName = f.getName();
+                if (fieldName.startsWith("CUPS_PRINTER_")) {
+                    int val = f.getInt(null);
+                    if (((printerTypeInt & val) == val)) {
+                        result.add(fieldName);
+                    }
+                }
+            }
+
+            return result;
+        } catch (IllegalAccessException | IllegalArgumentException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
     public void testGetDefault() {
         if (!cupsAvailable) {
             return;
@@ -144,7 +170,8 @@
                 Pointer jobsPtr = jobsRef.getValue();
                 assertNotNull("Jobs pointer should not be null", jobsPtr);
 
-                Cups.CupsJob job = new Cups.CupsJob(jobsPtr);
+                Cups.CupsJob[] jobs = (Cups.CupsJob[]) new Cups.CupsJob(jobsPtr).toArray(numJobs);
+                Cups.CupsJob job = jobs[0];
                 assertTrue("Job ID should be positive", job.id > 0);
                 assertNotNull("Job destination should not be null", job.dest);
                 System.out.println("First job: id=" + job.id + " dest=" + job.dest

Both cupsGetDests and cupsGetJobs2 return an array of values and this demonstrates decoding. The code in mapPrinterTypeEnumNames was more for me to test what I get for my default printer.

Closes java-native-access#1710

Add Cups interface providing JNA bindings for libcups, the Common UNIX
Printing System library. Includes structures (CupsDest, CupsOption,
CupsJob), printer state/type constants, job state constants, and
functions for destination enumeration, job management, option handling,
and server/user configuration.
@dbwiddis
dbwiddis force-pushed the add-cups-bindings branch from 2e49a2e to 801734b Compare May 10, 2026 13:55
@dbwiddis

dbwiddis commented May 10, 2026 •

Copy link
Copy Markdown
Contributor Author

For the documentation references people need to be careful ... the structure definition in the documentation did not match the header file.

Yeah, I've seen that a lot in manpage docs as well, where they tell you what elements are in the structure (assuming you'll fetch via struct.foo in C) but don't give the correct order.

Applied your suggested changes, will merge when CI passes.

@dbwiddis
dbwiddis merged commit f103aa3 into java-native-access:master May 10, 2026
12 checks passed
@dbwiddis
dbwiddis deleted the add-cups-bindings branch May 10, 2026 14:26
markharding pushed a commit to futo-org/Harbor that referenced this pull request Oct 23, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [net.java.dev.jna:jna](https://github.com/java-native-access/jna) | `5.18.1` → `5.19.1` | ![age](https://developer.mend.io/api/mc/badges/age/maven/net.java.dev.jna:jna/5.19.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/net.java.dev.jna:jna/5.18.1/5.19.1?slim=true) |

---

### Release Notes

<details>
<summary>java-native-access/jna (net.java.dev.jna:jna)</summary>

### [`v5.19.1`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5191)

[Compare Source](java-native-access/jna@5.19.0...5.19.1)

\==============

## Bug Fixes

- [#&#8203;1730](java-native-access/jna#1730): Replace usage of `MethodHandle` with reflection to restore support for older Android releases - [@&#8203;matthiasblaesing](https://github.com/matthiasblaesing).

### [`v5.19.0`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5190)

[Compare Source](java-native-access/jna@5.18.1...5.19.0)

\==============

## Features

- [#&#8203;1696](java-native-access/jna#1696): Add `LARGE_INTEGER.ByValue` to `LARGE_INTEGER` in `WinNT.java` - [@&#8203;baier233](https://github.com/baier233).
- [#&#8203;1697](java-native-access/jna#1697): Add WlanApi module - [@&#8203;eranl](https://github.com/eranl).
- [#&#8203;1718](java-native-access/jna#1718): Add `Cups` to `c.s.j.p.unix` providing CUPS printing system bindings for destinations, jobs, options, and server configuration - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1720](java-native-access/jna#1720): Add `groupCount` and `groupMasks` fields to `CACHE_RELATIONSHIP` in `c.s.j.p.win32.WinNT`, matching the updated Windows struct layout - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1719](java-native-access/jna#1719): Add `CoreGraphics` to `c.s.j.p.mac` with Quartz Window Services and Display Services bindings; implement `getAllWindows()` in `MacWindowUtils` - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1723](java-native-access/jna#1723): Add `ProcFdInfo`, `InSockInfo`, `TcpSockInfo`, `proc_pidfdinfo`, `statfs64`, and `vm_deallocate` to `c.s.j.p.mac.SystemB` - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1725](java-native-access/jna#1725): Add `BluetoothApis` to `c.s.j.p.win32` providing Bluetooth device and radio enumeration via `BluetoothFindFirstRadio`, `BluetoothFindFirstDevice`, and related functions - [@&#8203;dbwiddis](https://github.com/dbwiddis).

## Bug Fixes

- [#&#8203;1644](java-native-access/jna#1644): Fix bug in VARDESC and TYPEDESC causing an illegal memory access - [@&#8203;lwahonen](https://github.com/lwahonen)
- [#&#8203;1715](java-native-access/jna#1715): Fix `UdevDevice.getSysname()` calling `udev_device_get_syspath` instead of `udev_device_get_sysname` - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1721](java-native-access/jna#1721): Fix switched `serverName`/`domainName` arguments in `Netapi32Util#getDCName` - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1722](java-native-access/jna#1722): Fix `Advapi32#RegisterServiceCtrlHandler` using wrong `Handler` type - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1636](java-native-access/jna#1636): Drop hard dependency on java.lang.SecurityManager/java.security.AccessController - [@&#8203;matthiasblaesing](https://github.com/matthiasblaesing).
- [#&#8203;1724](java-native-access/jna#1724): Fix `host_page_size` in `c.s.j.p.mac.SystemB` and `getxattr`/`setxattr`/`listxattr` in `c.s.j.p.mac.XAttr` using `long` instead of pointer-sized types for `size_t`/`ssize_t` parameters - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1727](java-native-access/jna#1727): Include DragonFlyBSD in `NativeLibrary` versioned library resolution, libc special-case loading, and 64-bit search paths - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1709](java-native-access/jna#1709): Rebuild native library for OpenBSD 7.9 x86-64, drop OpenBSD x86 - [@&#8203;matthiasblaesing](https://github.com/matthiasblaesing).

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - "before 9am on tuesday"
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE3NS4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1820
Reviewed-by: Mark Harding <[email protected]>
markharding pushed a commit to futo-org/Harbor that referenced this pull request Oct 29, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [net.java.dev.jna:jna](https://github.com/java-native-access/jna) | `5.18.1` → `5.19.1` | ![age](https://developer.mend.io/api/mc/badges/age/maven/net.java.dev.jna:jna/5.19.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/net.java.dev.jna:jna/5.18.1/5.19.1?slim=true) |

---

### Release Notes

<details>
<summary>java-native-access/jna (net.java.dev.jna:jna)</summary>

### [`v5.19.1`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5191)

[Compare Source](java-native-access/jna@5.19.0...5.19.1)

\==============

## Bug Fixes

- [#&#8203;1730](java-native-access/jna#1730): Replace usage of `MethodHandle` with reflection to restore support for older Android releases - [@&#8203;matthiasblaesing](https://github.com/matthiasblaesing).

### [`v5.19.0`](https://github.com/java-native-access/jna/blob/HEAD/CHANGES.md#Release-5190)

[Compare Source](java-native-access/jna@5.18.1...5.19.0)

\==============

## Features

- [#&#8203;1696](java-native-access/jna#1696): Add `LARGE_INTEGER.ByValue` to `LARGE_INTEGER` in `WinNT.java` - [@&#8203;baier233](https://github.com/baier233).
- [#&#8203;1697](java-native-access/jna#1697): Add WlanApi module - [@&#8203;eranl](https://github.com/eranl).
- [#&#8203;1718](java-native-access/jna#1718): Add `Cups` to `c.s.j.p.unix` providing CUPS printing system bindings for destinations, jobs, options, and server configuration - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1720](java-native-access/jna#1720): Add `groupCount` and `groupMasks` fields to `CACHE_RELATIONSHIP` in `c.s.j.p.win32.WinNT`, matching the updated Windows struct layout - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1719](java-native-access/jna#1719): Add `CoreGraphics` to `c.s.j.p.mac` with Quartz Window Services and Display Services bindings; implement `getAllWindows()` in `MacWindowUtils` - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1723](java-native-access/jna#1723): Add `ProcFdInfo`, `InSockInfo`, `TcpSockInfo`, `proc_pidfdinfo`, `statfs64`, and `vm_deallocate` to `c.s.j.p.mac.SystemB` - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1725](java-native-access/jna#1725): Add `BluetoothApis` to `c.s.j.p.win32` providing Bluetooth device and radio enumeration via `BluetoothFindFirstRadio`, `BluetoothFindFirstDevice`, and related functions - [@&#8203;dbwiddis](https://github.com/dbwiddis).

## Bug Fixes

- [#&#8203;1644](java-native-access/jna#1644): Fix bug in VARDESC and TYPEDESC causing an illegal memory access - [@&#8203;lwahonen](https://github.com/lwahonen)
- [#&#8203;1715](java-native-access/jna#1715): Fix `UdevDevice.getSysname()` calling `udev_device_get_syspath` instead of `udev_device_get_sysname` - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1721](java-native-access/jna#1721): Fix switched `serverName`/`domainName` arguments in `Netapi32Util#getDCName` - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1722](java-native-access/jna#1722): Fix `Advapi32#RegisterServiceCtrlHandler` using wrong `Handler` type - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1636](java-native-access/jna#1636): Drop hard dependency on java.lang.SecurityManager/java.security.AccessController - [@&#8203;matthiasblaesing](https://github.com/matthiasblaesing).
- [#&#8203;1724](java-native-access/jna#1724): Fix `host_page_size` in `c.s.j.p.mac.SystemB` and `getxattr`/`setxattr`/`listxattr` in `c.s.j.p.mac.XAttr` using `long` instead of pointer-sized types for `size_t`/`ssize_t` parameters - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1727](java-native-access/jna#1727): Include DragonFlyBSD in `NativeLibrary` versioned library resolution, libc special-case loading, and 64-bit search paths - [@&#8203;dbwiddis](https://github.com/dbwiddis).
- [#&#8203;1709](java-native-access/jna#1709): Rebuild native library for OpenBSD 7.9 x86-64, drop OpenBSD x86 - [@&#8203;matthiasblaesing](https://github.com/matthiasblaesing).

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - "before 9am on tuesday"
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE3NS4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1820
Reviewed-by: Mark Harding <[email protected]>
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.

New feature suggestions,

2 participants