CAPS Universe documentation  1.0.4
All you need to know to be successful
Macros | Functions
caps-printer-db.c File Reference

CAPS Printer Device Database handler routines. More...

Macros

#define PRINTER_DATABASE_NAME   "printer-devices.ini"
 

Functions

int caps_prn_get_printer_device_database (struct caps_inif_table *db)
 
static int caps_prn_create_run_time_database (char *devices_database_path)
 
struct caps_inif_lockcaps_prn_get_printer_device_database_locked (struct caps_inif_table *db)
 
int caps_prn_get_printer_driver_database (struct caps_inif_table *db)
 
int caps_prn_get_printing_providers_description (struct caps_inif_table *db, const char *filename)
 
static const char * caps_prn_get_parameter (const struct caps_inif_table *db, const char *section, const char *key)
 
int caps_prn_get_printer_device_description (const struct caps_inif_table *db, const char *section, struct caps_prn_printer_description *desc)
 
static int caps_prn_set_parameter (struct caps_inif_table *db, const char *section, const char *key, const char *value)
 
static int caps_prn_set_number (struct caps_inif_table *db, const char *section, const char *key, int value)
 
int caps_prn_set_printer_description (struct caps_inif_table *db, const char *section, struct caps_prn_printer_description *desc)
 
int caps_prn_check_printer_entry (const struct caps_inif_table *db, const char *drv, const struct usb_printer *pr)
 

Detailed Description

Author
Jürgen Borleis
Warning
Use as experimental

Macro Definition Documentation

◆ PRINTER_DATABASE_NAME

#define PRINTER_DATABASE_NAME   "printer-devices.ini"

Name of the CAPS database of already known printers, located in the CAPS Printer Device Database Directory. "Already known" means, the printer device was at least attached once to the host and a driver was available at this time, e.g. the discover process was fully successful.

Function Documentation

◆ caps_prn_get_printer_device_database()

int caps_prn_get_printer_device_database ( struct caps_inif_table db)

Read in the run-time printer device database

Parameters
[in,out]dbWhere to store the content
Return values
0On success
-EINVALError in INI file
negativeErrno else (from open() for example)
Note
The db doesn't include the content of the "Printer Device Parameter Directories" (CAPS Printer Device Parameter Directory)
Precondition
db must be already initialised and thus, empty

◆ caps_prn_create_run_time_database()

static int caps_prn_create_run_time_database ( char *  devices_database_path)
static

Create an empty run-time printer database INI file with correct permissions

Parameters
[in]devices_database_pathName of the INI file to be created
Return values
0On success
-EINVALProcess does not run as 'root'
openEverything from open()
Precondition
The CAPS Printer Device Database Directory must already exist
Needs root permissions
Todo:
The open() and chown() operation must be atomic (or should?)!

◆ caps_prn_get_printer_device_database_locked()

struct caps_inif_lock * caps_prn_get_printer_device_database_locked ( struct caps_inif_table db)

Read in the run-time printer device database and lock the corresponding INI file

Parameters
[in,out]dbWhere to store the content (expected to be already initialised)
Returns
Pointer to transparent info or NULL in case of a disaster
Note
The INI file is locked! Must be freed with caps_inif_locked_file_close()
Keep in mind, the file is locked and prevents other caps-printer instances doing their job.
Precondition
The CAPS Printer Device Database Directory must already exist
Needs root permissions
Todo:
Check if CAPS Printer Device Database Directory exists and output a useful error message if not

◆ caps_prn_get_printer_driver_database()

int caps_prn_get_printer_driver_database ( struct caps_inif_table db)

Read in the persistent printer driver database

Parameters
[out]dbWhere to store the content (expected to be already initialised)
Return values
0on success
-ENODEVno drivers installed

This reads in all existing INI files in the CAPS Printer Driver Database Directory

◆ caps_prn_get_printing_providers_description()

int caps_prn_get_printing_providers_description ( struct caps_inif_table db,
const char *  filename 
)

Read in one printing provider's description INI from the CAPS driver database directory

Parameters
[out]dbWhere to store the content (expected to be already initialised)
[in]filenamePrinting provider's description INI file name (name only, no path)
Returns
0 on success, negative errno else

This reads in an INI file with filename from the CAPS Printer Driver Database Directory

◆ caps_prn_get_parameter()

static const char * caps_prn_get_parameter ( const struct caps_inif_table db,
const char *  section,
const char *  key 
)
static

◆ caps_prn_get_printer_device_description()

int caps_prn_get_printer_device_description ( const struct caps_inif_table db,
const char *  section,
struct caps_prn_printer_description desc 
)

Convert a device data base entry into our local description structure

Parameters
[in]dbThe run-time device database of currently known printer devices
[in]sectionThe section to examine
[in]desc
Returns
0 on success, negative errno else
Todo:

This functionname should show we work with the persistent printer database -> run-time database

Error handling. Print correct missing entry if any!

Todo:
We do support nothing else than USB printers, yet

◆ caps_prn_set_parameter()

static int caps_prn_set_parameter ( struct caps_inif_table db,
const char *  section,
const char *  key,
const char *  value 
)
static

Set an entry in the device database with a string value

Parameters
[in,out]dbThe device database
[in]sectionIn which section
[in]keyThe name of the key
[in]valueThe value of the key as a string
Returns
Anything from caps_inif_option_add()

◆ caps_prn_set_number()

static int caps_prn_set_number ( struct caps_inif_table db,
const char *  section,
const char *  key,
int  value 
)
static

Set an entry in the device database with an integer value

Parameters
[in,out]dbThe device database
[in]sectionIn which section
[in]keyThe name of the key
[in]valueThe value of the key as an integer
Returns
Anything from caps_inif_option_add()

Just a convenience function, since 'values' are always strings in the device database.

◆ caps_prn_set_printer_description()

int caps_prn_set_printer_description ( struct caps_inif_table db,
const char *  section,
struct caps_prn_printer_description desc 
)

Add a new printer device to the list/database of known devices

Parameters
[in,out]dbThe device database
[in]sectionThe specific printer section of this new data
[in]descThe printer device description
Return values
0On success
-EINVALYou add a non-USB device (not yet supported)

◆ caps_prn_check_printer_entry()

int caps_prn_check_printer_entry ( const struct caps_inif_table db,
const char *  drv,
const struct usb_printer pr 
)

Check if one given driver from the printer driver database corresponds to the given USB printing device

Parameters
[in]dbThe driver database
[in]drvThe 'level' where to search in the database
[in]prThe USB printer device description/information
Return values
0The given driver corresponds to the USB printer device
-ENODEVThe USB printer device doesn't match

Compares USB specific information with a driver database entry.