CAPS Universe documentation  1.0.4
All you need to know to be successful
Functions
lib-caps-printer-prep.c File Reference

A collection of functions used by caps-printer-prep. More...

Functions

void caps_prn_print_verbose_printer_message (const struct usb_printer *prn)
 
static int caps_prn_fix_directory_permissions (const char *dir)
 
static int caps_prn_create_initial_parameter_ini (const struct usb_printer *usb_prn, const char *dir)
 
static bool whitespace_less (const char *string)
 
static const char * caps_prn_get_useful_default_name (const struct usb_printer *prn)
 
static int caps_prn_create_unique_parameter_dir (const struct usb_printer *prn, char **param_dir)
 
int caps_prn_recognize_new_printer_device (const struct usb_printer *prn, struct caps_inif_table *db)
 

Detailed Description

Author
Jürgen Borleis
Warning
Use as experimental

This collection isn't part of the main C file in order to run tests on it.

Function Documentation

◆ caps_prn_print_verbose_printer_message()

void caps_prn_print_verbose_printer_message ( const struct usb_printer prn)

Fill the log with some useful information about the found printer device.

Parameters
[in]prnThe USB printer device information

Give the user a chance to find/install the correct printer driver for this device by providing more useful information about it.

Todo:

Use the libusb DEVICE ID database ("/usr/share/misc/usb.ids") to output better Vendor and Device information.

Check what the tool 'usb_printerid' is

Avoid duplicate code, refer caps_prn_print_verbose_printer_message() in caps-printer.c

◆ caps_prn_fix_directory_permissions()

static int caps_prn_fix_directory_permissions ( const char *  dir)
static

Adapt the permissions and owners of the given directory to our needs

Parameters
[in]dirPath to a directory (not(!) a file) to adapt
Return values
0On success
negative-errno else

All regular CAPS components should have only read access to all kind of resources in the filesystem Expected here is, we are running as root to be able to change the owner/group of the directory.

◆ caps_prn_create_initial_parameter_ini()

static int caps_prn_create_initial_parameter_ini ( const struct usb_printer usb_prn,
const char *  dir 
)
static

Create an INI file to define a default name for the new printer device

Parameters
[in]usb_prnPrinter device description from the USB point of view
[in]dirDirectory name of the driver's run-time parameter directory
Return values
0On success
negative-errno else

usb_prn is used to create a useful default name for this new printer device

Note
We need to be root here to be able to change the file's owner

◆ whitespace_less()

static bool whitespace_less ( const char *  string)
static

Check if a string does not contain whitespace

Parameters
[in]stringString to check for whitespaces
Return values
trueIf the string is whitespace less
falseIf the string contains whitespaces
Todo:
Find an optimized way from the str* family of functions

◆ caps_prn_get_useful_default_name()

static const char * caps_prn_get_useful_default_name ( const struct usb_printer prn)
static

Return something useful to create a directory name for a printer from it

Parameters
[in]prnPrinter Device info
Returns
Pointer to some (hopefully) useful string

What is a useful name? Hard to say. The product name is to be preferred, because it is the best for the reader. The manufacturer name is also okay, but might be confusing, if more than one printer device of the same manufacturer is/was connected. The IEEE ID is more useful for technicians and the serial number is a pain - but can be some kind of last resourt. And if nothing of this information is available, just the name "printer" helps.

Todo:
None of the returned strings should embed a whitespace!

◆ caps_prn_create_unique_parameter_dir()

static int caps_prn_create_unique_parameter_dir ( const struct usb_printer prn,
char **  param_dir 
)
static

Create a printer device unique CAPS Printer Device Parameter Directory in the main CAPS Printer Device Database Directory and return the full path to it

Parameters
[in]prnPrinter Device Info
[out]param_dirFull path to the "CAPS Printer Device Parameter Directory" for this printer
Return values
0On success (*param_dir is valid)
negativeErrno code about whats failed (mkdtemp(), chown() and chmod() calls)

This function will create a directory like: /var/lib/caps/printer_768747 with owner #CAPS_ADMIN_ID and group #CAPS_GROUP_ID and 0755 permission.

Note
*param_dir needs to be freed after use.
Function doesn't return on memory pressure

◆ caps_prn_recognize_new_printer_device()

int caps_prn_recognize_new_printer_device ( const struct usb_printer prn,
struct caps_inif_table db 
)

The printer device isn't known yet. Search the printer driver database for a corresponding printer driver.

Parameters
[in]prnThe USB printer device information
[in,out]dbThe current device database to store the new entry to (on demand)
Return values
0On success
negativeErnno

If a printer driver is found, create its corresponding Instance's Parameter Directory in the Driver's Configuration Directory, create the file service.ini with the parameter entry 'name' and a unique name (to be adpated by the user) and add this information beside some other run-time information (like the USB connection to recognize this printer device the next time) to its run-time database.

Note
The run-time information is only added to the in-memory device database. And still needs to be written back to the filesystem

Think about: We could create everything relevant even for the case no printer driver is installed. We just skip the parameter directory and description INI in this case and stop here. But the run-time database gets updated so we know the printer the next time and amend the missing information when available.