smf_lookup.h File Reference

SQL and LDAP lookup functions. More...

#include "smf_settings.h"
#include "smf_list.h"
Include dependency graph for smf_lookup.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * smf_lookup_db4_query (char *database, char *key)
 function to get value by key from berkeley hash table
 
int smf_lookup_db4_update (const char *database, const char *key, const char *value)
 Updates a key in a berkeley database. The database is created if it does not exist. Afterwards the key is created or updated with the given value.
 
int smf_lookup_sql_connect (SMFSettings_T *settings)
 connect to sql server
 
void smf_lookup_sql_disconnect (SMFSettings_T *settings)
 Disconnect from sql server.
 
SMFList_Tsmf_lookup_sql_query (SMFSettings_T *settings, const char *q,...)
 Query SQL server with given query string.
 
int smf_lookup_ldap_connect (SMFSettings_T *settings)
 Open a connection to ldap server.
 
void smf_lookup_ldap_disconnect (SMFSettings_T *settings)
 Disconnect from LDAP Server.
 
SMFList_Tsmf_lookup_ldap_query (SMFSettings_T *settings, const char *q,...)
 query LDAP Server with given query string
 

Detailed Description

SQL and LDAP lookup functions.

Spmfilter implements a small, fast, and easy to use database API with thread-safe connection pooling. The library can connect transparently to multiple database systems, has zero configuration and connections are specified via a standard URL scheme.

Supported are variety of database systems:

  • MySQL
  • PostgreSQL
  • Oracle
  • SQLite
  • Berkeley DB
  • LDAP directories

Spmfilter cares completely around connection management, load balancing and fallback connections. Failed connections will be also reconnected again automatically.

Whether you are using a SQL database or a LDAP directory, all results are delivered as a SMFList_T back. Each element is a SMFDict_T dictionary, in which each key a SQL column or a LDAP attribute represents.

The only exception here is Berkeley DB, as this does not require a query language and is based on key/values.

In order to use database lookups, you have to set a appropriate backend in spmfilter.conf, this can be sql or ldap. If a valid backend is configured, spmfilter will automatically establish the connection.

Function Documentation

char * smf_lookup_db4_query ( char *  database,
char *  key 
)

function to get value by key from berkeley hash table

Parameters
databasepath to database
keykey for which the value should be returned
Returns
newly allocated char pointer value string for given key, NULL if none found
int smf_lookup_db4_update ( const char *  database,
const char *  key,
const char *  value 
)

Updates a key in a berkeley database. The database is created if it does not exist. Afterwards the key is created or updated with the given value.

Parameters
databaseThe path of the database to update (resp. create)
keyThe key to update (resp. create)
valueThe new value of the key
Returns
On success 0 is returned or -1 in case of an error
int smf_lookup_ldap_connect ( SMFSettings_T settings)

Open a connection to ldap server.

Parameters
settingsPointer to SMFSettings_T
Returns
0 on success or -1 in case of error
void smf_lookup_ldap_disconnect ( SMFSettings_T settings)

Disconnect from LDAP Server.

Parameters
settingsPointer to SMFSettings_T
Returns
newly allocated char pointer value string for given key, NULL if none found
SMFList_T * smf_lookup_ldap_query ( SMFSettings_T settings,
const char *  q,
  ... 
)

query LDAP Server with given query string

Parameters
settingsPointer to SMFSettings_T
qformat string pointer for ldap query
...format string arguments
Returns
newly allocated SMFList_T
int smf_lookup_sql_connect ( SMFSettings_T settings)

connect to sql server

Parameters
settingsPointer to SMFSettings_T
Returns
0 on success or -1 in case of error
void smf_lookup_sql_disconnect ( SMFSettings_T settings)

Disconnect from sql server.

Parameters
settingsa SMFSettings_T object
SMFList_T * smf_lookup_sql_query ( SMFSettings_T settings,
const char *  q,
  ... 
)

Query SQL server with given query string.

Parameters
settingsPointer to SMFSettings_T
qformat string for sql query for sql query
Returns
SMFList_T or NULL