FOSSology  4.4.0
Open Source License Compliance by Open Source Software
liccache.c File Reference

license_ref table cache functions More...

#include "buckets.h"
Include dependency graph for liccache.c:

Go to the source code of this file.

Functions

FUNCTION long lrcache_hash (cacheroot_t *pcroot, char *rf_shortname)
 Calculate the hash of an rf_shortname rf_shortname is the key. More...
 
FUNCTION void lrcache_print (cacheroot_t *pcroot)
 Print the contents of the hash table. More...
 
FUNCTION void lrcache_free (cacheroot_t *pcroot)
 Free the hash table. More...
 
FUNCTION int lrcache_add (cacheroot_t *pcroot, long rf_pk, char *rf_shortname)
 Add a rf_shortname, rf_pk to the license_ref cache rf_shortname is the key. More...
 
FUNCTION long lrcache_lookup (cacheroot_t *pcroot, char *rf_shortname)
 Lookup rf_pk in the license_ref cache rf_shortname is the key. More...
 
FUNCTION int lrcache_init (PGconn *pgConn, cacheroot_t *pcroot)
 Build a cache the license ref db table. More...
 
FUNCTION long get_rfpk (PGconn *pgConn, cacheroot_t *pcroot, char *rf_shortname)
 Get the rf_pk for rf_shortname. More...
 
FUNCTION long add2license_ref (PGconn *pgConn, char *licenseName)
 

Detailed Description

license_ref table cache functions

This cache is an in memory hash table of the license_ref license names and primary keys.

Definition in file liccache.c.

Function Documentation

◆ add2license_ref()

FUNCTION long add2license_ref ( PGconn *  pgConn,
char *  licenseName 
)

Adds a new license to license_ref table

Parameters
pgConnDatabase connection
licenseNameName of license to be added
Returns
rf_pk for success, 0 for failure

Definition at line 246 of file liccache.c.

◆ get_rfpk()

FUNCTION long get_rfpk ( PGconn *  pgConn,
cacheroot_t pcroot,
char *  rf_shortname 
)

Get the rf_pk for rf_shortname.

Checks the cache to get the rf_pk for this shortname. If it doesn't exist, add it to both license_ref and the license_ref cache (the hash table).

Parameters
pgConnDatabase connection
pcrootHash table to be looked
rf_shortnameShort name to search
Returns
rf_pk of the matched license or 0

Definition at line 213 of file liccache.c.

◆ lrcache_add()

FUNCTION int lrcache_add ( cacheroot_t pcroot,
long  rf_pk,
char *  rf_shortname 
)

Add a rf_shortname, rf_pk to the license_ref cache rf_shortname is the key.

Parameters
pcrootHash table to be modified
rf_pkLicense id to be added
rf_shortnameLicense short name to be added
Returns
-1 for failure, 0 for success

Definition at line 99 of file liccache.c.

◆ lrcache_free()

FUNCTION void lrcache_free ( cacheroot_t pcroot)

Free the hash table.

Parameters
pcrootHash table to be destroyed
Returns
none

Definition at line 72 of file liccache.c.

◆ lrcache_hash()

FUNCTION long lrcache_hash ( cacheroot_t pcroot,
char *  rf_shortname 
)

Calculate the hash of an rf_shortname rf_shortname is the key.

Parameters
pcrootHash table root
rf_shortnameLicense short name
Returns
Hash value

Definition at line 26 of file liccache.c.

◆ lrcache_init()

FUNCTION int lrcache_init ( PGconn *  pgConn,
cacheroot_t pcroot 
)

Build a cache the license ref db table.

Parameters
[in]pgConnDatabase connection
[out]pcrootHash table

lrcache_init builds a cache using the rf_shortname as the key and the rf_pk as the value. This is an optimization. The cache is used for reference license lookups instead of querying the db.

Returns
0 for failure, 1 for success

Definition at line 174 of file liccache.c.

◆ lrcache_lookup()

FUNCTION long lrcache_lookup ( cacheroot_t pcroot,
char *  rf_shortname 
)

Lookup rf_pk in the license_ref cache rf_shortname is the key.

Parameters
pcrootHash table (haystack)
rf_shortnameShort name to be searched (needle)
Returns
rf_pk, 0 if the shortname is not in the cache

Definition at line 135 of file liccache.c.

◆ lrcache_print()

FUNCTION void lrcache_print ( cacheroot_t pcroot)

Print the contents of the hash table.

Parameters
pcrootHash table to be printed
Returns
none

Definition at line 46 of file liccache.c.