32 len = (strlen(rf_shortname) <
sizeof(long)) ? strlen(rf_shortname) :
sizeof(long);
33 for (i=0; i<len;i++) hashval += rf_shortname[i] << 8*i;
34 hashval = hashval % pcroot->
maxnodes;
52 pcnode = pcroot->
nodes;
55 if (pcnode->
rf_pk != 0L)
77 pcnode = pcroot->
nodes;
80 if (pcnode->
rf_pk != 0L)
111 noden = (hashval +i) & (pcroot->
maxnodes -1);
113 pcnode = pcroot->
nodes + noden;
117 pcnode->
rf_pk = rf_pk;
121 if (i < pcroot->maxnodes)
return 0;
147 noden = (hashval +i) & (pcroot->
maxnodes -1);
149 pcnode = pcroot->
nodes + noden;
150 if (!pcnode->
rf_pk)
return 0;
153 return pcnode->
rf_pk;
181 if (!pcroot)
return 0;
183 snprintf(query,
sizeof(query),
184 "SELECT rf_pk, rf_shortname FROM license_ref where rf_detector_type=2;");
185 result = PQexec(
pgConn, query);
188 numLics = PQntuples(result);
190 for (row = 0; row < numLics; row++)
192 lrcache_add(pcroot, atol(PQgetvalue(result, row, 0)), PQgetvalue(result, row, 1));
218 if ((len = strlen(rf_shortname)) == 0)
220 printf(
"ERROR! %s.%d get_rfpk() passed empty name", __FILE__, __LINE__);
226 if (rf_pk)
return rf_pk;
251 char escLicName[256];
252 char *specialLicenseText;
260 len = strlen(licenseName);
261 PQescapeStringConn(
pgConn, escLicName, licenseName, len, &error);
263 printf(
"WARNING: %s(%d): Does license name have multibyte encoding?", __FILE__, __LINE__);
266 sprintf(query,
"SELECT rf_pk FROM license_ref where rf_shortname='%s' and rf_detector_type=2", escLicName);
267 result = PQexec(
pgConn, query);
269 numRows = PQntuples(result);
272 rf_pk = atol(PQgetvalue(result, 0, 0));
277 specialLicenseText =
"License by Nomos.";
280 "insert into license_ref(rf_shortname, rf_text, rf_detector_type) values('%s', '%s', 2)",
281 escLicName, specialLicenseText);
282 result = PQexec(
pgConn, insert);
287 result = PQexec(
pgConn, query);
289 numRows = PQntuples(result);
291 rf_pk = atol(PQgetvalue(result, 0, 0));
294 printf(
"ERROR: %s:%s:%d Just inserted value is missing. On: %s", __FILE__,
"add2license_ref()", __LINE__, query);
PGconn * pgConn
Database connection.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres commands (not select) If an error occured, write the error to s...
FUNCTION void lrcache_print(cacheroot_t *pcroot)
Print the contents of the hash table.
FUNCTION void lrcache_free(cacheroot_t *pcroot)
Free the hash table.
FUNCTION long lrcache_lookup(cacheroot_t *pcroot, char *rf_shortname)
Lookup rf_pk in the license_ref cache rf_shortname is the key.
FUNCTION long add2license_ref(PGconn *pgConn, char *licenseName)
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.
FUNCTION long get_rfpk(PGconn *pgConn, cacheroot_t *pcroot, char *rf_shortname)
Get the rf_pk for rf_shortname.
FUNCTION int lrcache_init(PGconn *pgConn, cacheroot_t *pcroot)
Build a cache the license ref db table.
FUNCTION long lrcache_hash(cacheroot_t *pcroot, char *rf_shortname)
Calculate the hash of an rf_shortname rf_shortname is the key.
long rf_pk
License id from database.
char * rf_shortname
License shortname.
int maxnodes
No. of nodes in the list.
cachenode_t * nodes
Array of nodes.