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

WIP: PAPPL Scan API Bridging v1.4.x (To be rebased after review) #371

Draft
wants to merge 31 commits into
base: v1.4.x
Choose a base branch
from

Conversation

Kappuccino111
Copy link

Opening the work completed for the Scan API in v1.4.x directly. Rebasing will be the final step after the base review and testing are completed. The rebasing process should not take long.

Kappuccino111 and others added 26 commits March 9, 2024 20:43
This commit introduces a new file scanner-driver.c that contains the
implementation of functions related to the scanner driver.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
This commit updates Scanner.h to closely follow the Mopria Scan
specifications. We should now have a very detailed implementaion of
scanner.h that closely follows the structure of printer.h while also
following the Mopria Scan specifications.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
This commit adds some basic features to closely follow
the printer-private.h file. The updated scanner-private.h should be
the final version of this file (for now).

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
- Implemented scanner-specific event handling and introduced new events for scanner operations.
- Added `scanner-escl.c` for eSCL-specific scanner state management.
- Modified `job-process.c`, `job.c`, `printer-accessors.c`, and `scanner-accessors.c` to integrate scanner event functions.
- Updated `system-subscription.c` to support scanner events and added `papplSystemAddScannerEvent`.
- Enhanced `system-private.h` and `subscription.h` with new scanner event types and callback definitions.
- Included necessary changes in `Makefile` and other system-related files for compatibility.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
This commit updates the Readme and Build files to
include libxml2 as a dependency.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
This commit finalises the scanner-driver.c file. It includes all the
functions as required for working with scanner-drivers and closely in
line with the printer-driver.c file.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
This commit finalises the scanner-webif.c file.
It closely follows all aspects of the printer-webif.c file, but
also follows the scan specific requirements.

This commit finalizes the implementation of the scanner web interface
functions, including the following features:

- Added `_papplScannerWebConfig()` to show and handle scanner configuration settings.
- Implemented `_papplScannerWebConfigFinalize()` to save changes to the scanner configuration.
- Developed `_papplScannerWebDefaults()` to display and update default scanning settings.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
This commit finalises the scanner.c file. It is closely in reference to
the printer.c file, while also covering the necessary details of
eSCL Scanning.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
Add a few comments and also add scanner_logging
function to the log file.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
This commits primarily adds functions for registration and unregistration
of DNSSD related to scanners.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
This commit creates a new file job-scan.c with various functions to handle scanning jobs.
The file is added to the Makefile and the job.h and job-private.h header file are updated to include the new functions.

Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
@Kappuccino111 Kappuccino111 marked this pull request as draft November 3, 2024 12:37
#endif // HAVE_MDNSRESPONDER

// Build formats string
for (i = 0, count = 0, ptr = formats; scanner->driver_data.document_formats_supported[i] && i < PAPPL_MAX_FORMATS; i++)

Check failure

Code scanning / CodeQL

Array offset used before range check High

This use of offset 'i' should follow the
range check
.
if (i > 0)
*ptr++ = ',';
if (scanner->driver_data.input_sources_supported[i] == PAPPL_FLATBED)
ptr += snprintf(ptr, sizeof(sources) - (size_t)(ptr - sources), "platen");

Check failure

Code scanning / CodeQL

Potentially overflowing call to snprintf High

The
size argument
of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow.
if (scanner->driver_data.input_sources_supported[i] == PAPPL_FLATBED)
ptr += snprintf(ptr, sizeof(sources) - (size_t)(ptr - sources), "platen");
else if (scanner->driver_data.input_sources_supported[i] == PAPPL_ADF)
ptr += snprintf(ptr, sizeof(sources) - (size_t)(ptr - sources), "adf");

Check failure

Code scanning / CodeQL

Potentially overflowing call to snprintf High

The
size argument
of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow.
}

// Build color spaces string
for (i = 0, count = 0, ptr = colorspaces; scanner->driver_data.color_spaces_supported[i] && i < PAPPL_MAX_COLOR_SPACES; i++)

Check failure

Code scanning / CodeQL

Array offset used before range check High

This use of offset 'i' should follow the
range check
.
{
if (i > 0)
*ptr++ = ',';
ptr += snprintf(ptr, sizeof(intents) - (size_t)(ptr - intents), "%s", scanner->driver_data.mandatory_intents[i]);

Check failure

Code scanning / CodeQL

Potentially overflowing call to snprintf High

The
size argument
of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow.
switch (scanner->driver_data.color_modes_supported[i])
{
case PAPPL_BLACKANDWHITE1:
ptr += snprintf(ptr, sizeof(color_modes) - (size_t)(ptr - color_modes), "BlackAndWhite1");

Check failure

Code scanning / CodeQL

Potentially overflowing call to snprintf High

The
size argument
of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow.
ptr += snprintf(ptr, sizeof(color_modes) - (size_t)(ptr - color_modes), "BlackAndWhite1");
break;
case PAPPL_GRAYSCALE8:
ptr += snprintf(ptr, sizeof(color_modes) - (size_t)(ptr - color_modes), "Grayscale8");

Check failure

Code scanning / CodeQL

Potentially overflowing call to snprintf High

The
size argument
of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow.
ptr += snprintf(ptr, sizeof(color_modes) - (size_t)(ptr - color_modes), "Grayscale8");
break;
case PAPPL_RGB24:
ptr += snprintf(ptr, sizeof(color_modes) - (size_t)(ptr - color_modes), "RGB24");

Check failure

Code scanning / CodeQL

Potentially overflowing call to snprintf High

The
size argument
of this snprintf call is derived from its return value, which may exceed the size of the buffer and overflow.

// Scan intent - Validate against supported intents
intent_supported = false;
for (i = 0; scanner->driver_data.mandatory_intents[i] && i < 5; i++)

Check failure

Code scanning / CodeQL

Array offset used before range check High

This use of offset 'i' should follow the
range check
.
job->state = IPP_JSTATE_COMPLETED;

// Ensure job->state is within the bounds of job_states array
if ((job->state - IPP_JSTATE_PENDING) >= 0 &&

Check warning

Code scanning / CodeQL

Unsigned comparison to zero Warning

Pointless comparison of unsigned value to zero.
Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
char *contentRegionUnits = getString(&scanSettings, "ContentRegionUnits", contentRegionUnitsPattern);

char *widthPattern = "<pwg:Width>([^<]*)</pwg:Width>";
double width = getNumber(&scanSettings, "Width", widthPattern);

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable width is not used.
double width = getNumber(&scanSettings, "Width", widthPattern);

char *xOffsetPattern = "<pwg:XOffset>([^<]*)</pwg:XOffset>";
double xOffset = getNumber(&scanSettings, "XOffset", xOffsetPattern);

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable xOffset is not used.
double xOffset = getNumber(&scanSettings, "XOffset", xOffsetPattern);

char *yOffsetPattern = "<pwg:YOffset>([^<]*)</pwg:YOffset>";
double yOffset = getNumber(&scanSettings, "YOffset", yOffsetPattern);

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable yOffset is not used.
free(inputSource);
free(colorMode);
free(blankPageDetection);
free(scanSettings.xml);

Check failure

Code scanning / CodeQL

Missing return statement Error

Function ScanSettingsFromXML should return a value of type void * but does not return a value here
Signed-off-by: Akarshan Kapoor <data.akarshan@icloud.com>
@michaelrsweet
Copy link
Owner

OK, I still need to do a more in-depth code review, but I'd prefer that you use Mini-XML for any of the XML support instead of libxml2, mainly because libxml2 is about twice the size of PAPPL itself and is nowhere near as fast as Mini-XML.

@Kappuccino111
Copy link
Author

Kappuccino111 commented Nov 11, 2024

@michaelrsweet okay, I will consider that. The XML libraries are primarily for parsing the XML side of eSCL requests, so I will have to probably make some library specific changes. I will review the mxml library documentation and get back to you.

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.

2 participants