Skip to content

Commit

Permalink
Merge pull request #309 from michaelrsweet/multi-document-jobs
Browse files Browse the repository at this point in the history
Multi document jobs
  • Loading branch information
michaelrsweet authored Nov 24, 2023
2 parents 9792d00 + 7ae702d commit 0d68220
Show file tree
Hide file tree
Showing 29 changed files with 1,934 additions and 587 deletions.
8 changes: 4 additions & 4 deletions pappl.spec
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#
# RPM spec file for the Printer Application Framework
#
# Copyright © 2020-2022 by Michael R Sweet
# Copyright © 2020-2023 by Michael R Sweet
#
# Licensed under Apache License v2.0. See the file "LICENSE" for more
# information.
#

Summary: Printer Application Framework (PAPPL)
Name: pappl
Version: 1.3.0
Version: 2.0.0
Release: 1
License: Apache 2.0
Group: Development/Libraries
Expand All @@ -18,8 +18,8 @@ Url: https://www.msweet.org/pappl
Packager: John Doe <johndoe@example.com>
Vendor: Michael R Sweet

BuildRequires: avahi-devel, cups-devel, gnutls-devel, libjpeg-turbo-devel, libpng-devel, libusbx-devel, pam-devel, zlib-devel
Requires: cups-devel
BuildRequires: avahi-devel, libcups3-devel, openssl-devel, libjpeg-turbo-devel, libpng-devel, libusbx-devel, pam-devel, zlib-devel
Requires: libcups3-devel

# Use buildroot so as not to disturb the version already installed
BuildRoot: /var/tmp/%{name}-root
Expand Down
9 changes: 8 additions & 1 deletion pappl/base-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ extern char **environ;
// Types and structures...
//

typedef struct _pappl_attr_s // Input attribute structure
{
const char *name; // Attribute name
ipp_tag_t value_tag; // Value tag
size_t max_count; // Max number of values
} _pappl_attr_t;

typedef struct _pappl_ipp_filter_s // Attribute filter
{
cups_array_t *ra; // Requested attributes
Expand All @@ -86,7 +93,7 @@ typedef struct _pappl_link_s // Web interface navigation link

extern ipp_t *_papplContactExport(pappl_contact_t *contact) _PAPPL_PRIVATE;
extern void _papplContactImport(ipp_t *col, pappl_contact_t *contact) _PAPPL_PRIVATE;
extern void _papplCopyAttributes(ipp_t *to, ipp_t *from, cups_array_t *ra, ipp_tag_t group_tag, int quickcopy) _PAPPL_PRIVATE;
extern void _papplCopyAttributes(ipp_t *to, ipp_t *from, cups_array_t *ra, ipp_tag_t group_tag, bool quickcopy) _PAPPL_PRIVATE;
extern bool _papplIsEqual(const char *a, const char *b) _PAPPL_PRIVATE;
extern const char *_papplLookupString(unsigned bit, size_t num_strings, const char * const *strings) _PAPPL_PRIVATE;
extern size_t _papplLookupStrings(unsigned value, size_t max_keywords, char *keywords[], size_t num_strings, const char * const *strings) _PAPPL_PRIVATE;
Expand Down
34 changes: 12 additions & 22 deletions pappl/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,20 @@ extern "C" {


//
// IPP operations/tags...
// PAPPL API version definitions...
//

# if CUPS_VERSION_MAJOR == 2 && CUPS_VERSION_MINOR < 3
# define IPP_OP_CREATE_PRINTER (ipp_op_t)0x004C
# define IPP_OP_DELETE_PRINTER (ipp_op_t)0x004E
# define IPP_OP_GET_PRINTERS (ipp_op_t)0x004F
# define IPP_OP_CREATE_SYSTEM_SUBSCRIPTIONS (ipp_op_t)0x0058
# define IPP_OP_DISABLE_ALL_PRINTERS (ipp_op_t)0x0059
# define IPP_OP_ENABLE_ALL_PRINTERS (ipp_op_t)0x005A
# define IPP_OP_GET_SYSTEM_ATTRIBUTES (ipp_op_t)0x005B
# define IPP_OP_GET_SYSTEM_SUPPORTED_VALUES (ipp_op_t)0x005C
# define IPP_OP_PAUSE_ALL_PRINTERS (ipp_op_t)0x005D
# define IPP_OP_PAUSE_ALL_PRINTERS_AFTER_CURRENT_JOB (ipp_op_t)0x005E
# define IPP_OP_RESUME_ALL_PRINTERS (ipp_op_t)0x0061
# define IPP_OP_SET_SYSTEM_ATTRIBUTES (ipp_op_t)0x0062
# define IPP_OP_SHUTDOWN_ALL_PRINTERS (ipp_op_t)0x0063

# define IPP_TAG_SYSTEM (ipp_tag_t)0x000A
# endif // CUPS_VERSION_MAJOR == 2 && CUPS_VERSION_MINOR < 3

# define IPP_OP_PAPPL_FIND_DEVICES (ipp_op_t)0x402b
# define IPP_OP_PAPPL_FIND_DRIVERS (ipp_op_t)0x402c
# define IPP_OP_PAPPL_CREATE_PRINTERS (ipp_op_t)0x402d
# define PAPPL_API_VERSION_MAJOR 2
# define PAPPL_API_VERSION_MIOR 0


//
// IPP operations...
//

# define PAPPL_IPP_OP_FIND_DEVICES (ipp_op_t)0x402b
# define PAPPL_IPP_OP_FIND_DRIVERS (ipp_op_t)0x402c
# define PAPPL_IPP_OP_CREATE_PRINTERS (ipp_op_t)0x402d


//
Expand Down
112 changes: 112 additions & 0 deletions pappl/device-network.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ static _pappl_dnssd_dev_t *pappl_dnssd_get_device(_pappl_dnssd_devs_t *devices,
static bool pappl_dnssd_list(pappl_devtype_t types, pappl_device_cb_t cb, void *data, pappl_deverror_cb_t err_cb, void *err_data);
static void pappl_dnssd_unescape(char *dst, const char *src, size_t dstsize);

static void pappl_ipp_close(pappl_device_t *device);
static char *pappl_ipp_getid(pappl_device_t *device, char *buffer, size_t bufsize);
static bool pappl_ipp_open(pappl_device_t *device, const char *device_uri, pappl_job_t *job);
static pappl_preason_t pappl_ipp_status(pappl_device_t *device);
static int pappl_ipp_supplies(pappl_device_t *device, int max_supplies, pappl_supply_t *supplies);
static ssize_t pappl_ipp_write(pappl_device_t *device, const void *buffer, size_t bytes);

static int pappl_snmp_compare_devices(_pappl_snmp_dev_t *a, _pappl_snmp_dev_t *b);
static bool pappl_snmp_find(pappl_device_cb_t cb, void *data, _pappl_socket_t *sock, pappl_deverror_cb_t err_cb, void *err_data);
static void pappl_snmp_free(_pappl_snmp_dev_t *d);
Expand All @@ -211,6 +218,7 @@ static ssize_t pappl_socket_read(pappl_device_t *device, void *buffer, size_t b
static pappl_preason_t pappl_socket_status(pappl_device_t *device);
static int pappl_socket_supplies(pappl_device_t *device, int max_supplies, pappl_supply_t *supplies);
static ssize_t pappl_socket_write(pappl_device_t *device, const void *buffer, size_t bytes);

static void utf16_to_utf8(char *dst, const unsigned char *src, size_t srcsize, size_t dstsize, bool le);


Expand All @@ -222,6 +230,8 @@ void
_papplDeviceAddNetworkSchemesNoLock(void)
{
_papplDeviceAddSchemeNoLock("dnssd", PAPPL_DEVTYPE_DNS_SD, pappl_dnssd_list, pappl_socket_open, pappl_socket_close, pappl_socket_read, pappl_socket_write, pappl_socket_status, pappl_socket_supplies, pappl_socket_getid);
_papplDeviceAddSchemeNoLock("ipp", PAPPL_DEVTYPE_IPP, pappl_dnssd_list, pappl_ipp_open, pappl_ipp_close, /*read_cb*/NULL, pappl_ipp_write, pappl_ipp_status, pappl_ipp_supplies, pappl_ipp_getid);
_papplDeviceAddSchemeNoLock("ipps", PAPPL_DEVTYPE_IPP, pappl_dnssd_list, pappl_ipp_open, pappl_ipp_close, /*read_cb*/NULL, pappl_ipp_write, pappl_ipp_status, pappl_ipp_supplies, pappl_ipp_getid);
_papplDeviceAddSchemeNoLock("snmp", PAPPL_DEVTYPE_SNMP, pappl_snmp_list, pappl_socket_open, pappl_socket_close, pappl_socket_read, pappl_socket_write, pappl_socket_status, pappl_socket_supplies, pappl_socket_getid);
_papplDeviceAddSchemeNoLock("socket", PAPPL_DEVTYPE_SOCKET, NULL, pappl_socket_open, pappl_socket_close, pappl_socket_read, pappl_socket_write, pappl_socket_status, pappl_socket_supplies, pappl_socket_getid);
}
Expand Down Expand Up @@ -773,6 +783,108 @@ pappl_dnssd_unescape(
}


//
// 'pappl_ipp_close()' - Close an IPP device.
//

static void
pappl_ipp_close(pappl_device_t *device) // I - Device
{
// TODO: Implement pappl_ipp_close
(void)device;
}


//
// 'pappl_ipp_getid()' - Get the IEEE-1284 device ID for an IPP device.
//

static char * // O - Device ID or `NULL` on error
pappl_ipp_getid(pappl_device_t *device, // I - Device
char *buffer, // I - Device ID buffer
size_t bufsize) // I - Size of device ID buffer
{
// TODO: Implement pappl_ipp_getid
(void)device;
(void)bufsize;

if (buffer)
*buffer = '\0';

return (NULL);
}


//
// 'pappl_ipp_open()' - Open a connection to an IPP printer.
//

static bool // O - `true` on success, `false` on failure
pappl_ipp_open(
pappl_device_t *device, // I - Device
const char *device_uri, // I - Device URI
pappl_job_t *job) // I - Job
{
// TODO: Implement pappl_ipp_open
(void)device;
(void)device_uri;
(void)job;

return (false);
}


//
// 'pappl_ipp_status()' - Get the current status of an IPP printer.
//

static pappl_preason_t // O - "printer-state-reasons" values
pappl_ipp_status(pappl_device_t *device)// I - Device
{
// TODO: Implement pappl_ipp_status
(void)device;
return (PAPPL_PREASON_NONE);
}


//
// 'pappl_ipp_supplies()' - Get the current supply levels for an IPP printer.
//

static int // O - Number of supplies
pappl_ipp_supplies(
pappl_device_t *device, // I - Device
int max_supplies, // I - Maximum number of supplies
pappl_supply_t *supplies) // I - Supplies
{
// TODO: Implement pappl_ipp_supplies
// TODO: Change supply API to use size_t
(void)device;
(void)max_supplies;
(void)supplies;

return (0);
}


//
// 'pappl_ipp_write()' - Write print data to an IPP printer.
//

static ssize_t // O - Number of bytes written
pappl_ipp_write(pappl_device_t *device, // I - Device
const void *buffer, // I - Buffer to write
size_t bytes) // I - Bytes to write
{
// TODO: Implement pappl_ipp_write
(void)device;
(void)buffer;
(void)bytes;

return (-1);
}


//
// 'pappl_snmp_compare_devices()' - Compare two SNMP devices.
//
Expand Down
81 changes: 73 additions & 8 deletions pappl/job-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,81 @@ papplJobGetData(pappl_job_t *job) // I - Job


//
// 'papplJobGetJobFilename()' - Get the job's filename.
// 'papplJobGetDocumentAttribute()' - Get an IPP attribute for a document.
//
// This function returns the filename for the job's document data.
// This function returns the named IPP attribute for a document in a job.
//

ipp_attribute_t * // O - IPP attribute or `NULL` for none
papplJobGetDocumentAttribute(
pappl_job_t *job, // I - Job
int doc_number, // I - File/document number (`1` based)
const char *name) // I - Attribute name
{
if (!job || doc_number < 1 || doc_number > job->num_documents)
return (NULL);
else
return (ippFindAttribute(job->documents[doc_number - 1].attrs, name, IPP_TAG_ZERO));
}


//
// 'papplJobGetDocumentFilename()' - Get the document's filename.
//
// This function returns the filename for the document in a job.
//

const char * // O - Filename or `NULL` if none
papplJobGetFilename(pappl_job_t *job) // I - Job
papplJobGetDocumentFilename(
pappl_job_t *job, // I - Job
int doc_number) // I - File/document number (`1` based)
{
if (!job || doc_number < 1 || doc_number > job->num_documents)
return (NULL);
else
return (job->documents[doc_number - 1].filename);
}


//
// 'papplJobGetDocumentFormat()' - Get the MIME media type for a document.
//
// This function returns the MIME media type for a document in a job.
//

const char * // O - MIME media type or `NULL` for none
papplJobGetDocumentFormat(
pappl_job_t *job, // I - Job
int doc_number) // I - File/document number (`1` based)
{
return (job ? job->filename : NULL);
if (!job || doc_number < 1 || doc_number > job->num_documents)
return (NULL);
else
return (job->documents[doc_number - 1].format);
}


//
// 'papplJobGetFormat()' - Get the MIME media type for the job's file.
// 'papplJobGetDocumentFormat()' - Get the MIME media type for a document.
//
// This function returns the MIME media type for the job's document data.
// This function returns the MIME media type for a document in a job.
//

const char * // O - MIME media type or `NULL` for none
papplJobGetFormat(pappl_job_t *job) // I - Job
papplJobGetDocumentName(
pappl_job_t *job, // I - Job
int doc_number) // I - File/document number (`1` based)
{
return (job ? job->format : NULL);
const char *ret = NULL; // Return value
if (!job)
return (NULL);

_papplRWLockRead(job);
if (doc_number >= 1 && doc_number <= job->num_documents)
ret = ippGetString(ippFindAttribute(job->documents[doc_number - 1].attrs, "document-name", IPP_TAG_NAME), 0, NULL);
_papplRWUnlock(job);

return (ret);
}


Expand Down Expand Up @@ -211,6 +264,18 @@ papplJobGetName(pappl_job_t *job) // I - Job
}


//
// 'papplJobGetNumberOfDocuments()' - Get the number of documents in a job.
//

int // O - Number of documents
papplJobGetNumberOfDocuments(
pappl_job_t *job) // I - Job
{
return (job ? job->num_documents : 0);
}


//
// 'papplJobGetPrinter()' - Get the printer for the job.
//
Expand Down
Loading

0 comments on commit 0d68220

Please sign in to comment.