libscipaper 1.0.x
Data Structures | Macros | Typedefs | Functions
Module API

Api for use by libscipaper modules. More...

Data Structures

struct  Pair
 A key value Pair struct to be used wih G(S)Lists. More...
 

Macros

#define sci_module_log(loglevel, fmt, ...)   sci_log(loglevel, "%s: " fmt, MODULE_NAME, ##__VA_ARGS__)
 Print a string to the log.
 

Typedefs

typedef const char * sci_module_init_fn(void **data)
 Modules must export a symbol of this type called sci_module_init, it will be called when the module is loaded.
 
typedef void sci_module_exit_fn(void *data)
 Modules must export a symbol of this type called sci_module_exit, it will be called just before the module is removed.
 

Functions

int sci_plugin_register (const BackendInfo *backend_info, RequestReturn *(*fill_meta_in)(const DocumentMeta *, size_t, size_t, void *), char *(*get_document_text_in)(const DocumentMeta *, void *), PdfData *(*get_document_pdf_data_in)(const DocumentMeta *, void *), void *user_data)
 Registers a backend, not all functions have to be regisered for eatch backend, pass NULL for unwanted functions.
 
void sci_plugin_unregister (int id)
 Unregisters a backend, must be called before the backend exits.
 
bool sci_conf_get_bool (const gchar *group, const gchar *key, const bool defaultval, gpointer keyfileptr)
 Get a boolean configuration value.
 
gint sci_conf_get_int (const gchar *group, const gchar *key, const gint defaultval, gpointer keyfileptr)
 Get an integer configuration value.
 
gint * sci_conf_get_int_list (const gchar *group, const gchar *key, gsize *length, gpointer keyfileptr)
 Get an integer list configuration value.
 
gchar * sci_conf_get_string (const gchar *group, const gchar *key, const gchar *defaultval, gpointer keyfileptr)
 Get a string configuration value.
 
gchar ** sci_conf_get_string_list (const gchar *group, const gchar *key, gsize *length, gpointer keyfileptr)
 Get a string list configuration value.
 
gpointer sci_conf_read_conf_file (const gchar *const conffile)
 Read configuration file.
 
gpointer sci_conf_read_conf_bytes (const char *data, size_t length)
 Read configuration from raw memory.
 
void sci_conf_free_conf_file (gpointer keyfileptr)
 
void pair_free (struct Pair *pair)
 Frees a pair struct.
 
struct Pairpair_new (const char *key, const char *value)
 Frees a pair struct.
 
GString * buildQuery (const GSList *list)
 Builds an url encoded query string that can be added to a url.
 
PdfDatawgetPdf (const char *url, int timeout)
 Get a pdf file va a http(s) GET request.
 
GString * wgetUrl (const char *url, int timeout)
 Get the http data return as a string from a url via a http(s) GET request.
 
GString * wpostUrl (const char *url, const char *data, int timeout)
 Get the http data return as a string from a url via a http(s) POST request.
 
GString * createJsonEntry (const int indent, const char *key, const char *value, bool quote, bool newline)
 Create a json style entry string.
 

Detailed Description

Api for use by libscipaper modules.

This api is to be used by implemeters of libscipaper modules to expose the various features of webapis used as sources of metadata as well as full text information.

Macro Definition Documentation

◆ sci_module_log

#define sci_module_log ( loglevel,
fmt,
... )   sci_log(loglevel, "%s: " fmt, MODULE_NAME, ##__VA_ARGS__)

Print a string to the log.

Parameters
loglevelLog level to use
fmtprintf style format string
...Values to place into format string

Typedef Documentation

◆ sci_module_exit_fn

typedef void sci_module_exit_fn(void *data)

Modules must export a symbol of this type called sci_module_exit, it will be called just before the module is removed.

Parameters
datathis pointer gives this funciton context passed from sci_module_init_fn.

◆ sci_module_init_fn

typedef const char * sci_module_init_fn(void **data)

Modules must export a symbol of this type called sci_module_init, it will be called when the module is loaded.

Parameters
datathis pointer may be set by the module to pass context that is later given to sci_module_exit_fn()
Returns
If initalization is sucessfull this symbol shal return NULL, otherwise a const string describeing the problem is to be passed

Function Documentation

◆ buildQuery()

GString * buildQuery ( const GSList * list)

Builds an url encoded query string that can be added to a url.

Parameters
listconst list of struct Pairs of key=value querys to add.
Returns
A newly allocated GString containing the query string

◆ createJsonEntry()

GString * createJsonEntry ( const int indent,
const char * key,
const char * value,
bool quote,
bool newline )

Create a json style entry string.

Parameters
indentintent level to prepend
keyjson entry key
valuejson entry value
quoteif true qoutes "" are placed around value
newlineif true the returned string ends with a unix newline
Returns
A newly allocated GString containing the data grabed from the url on sucess, or NULL on failure

◆ pair_free()

void pair_free ( struct Pair * pair)

Frees a pair struct.

Parameters
pairPair to free

◆ pair_new()

struct Pair * pair_new ( const char * key,
const char * value )

Frees a pair struct.

Parameters
keythe key of the key-value pair
valuethe value of the key-value pair
Returns
A newly allocated pair to be freed with pair_free

◆ sci_conf_get_bool()

bool sci_conf_get_bool ( const gchar * group,
const gchar * key,
const bool defaultval,
gpointer keyfileptr )

Get a boolean configuration value.

Parameters
groupThe configuration group to get the value from
keyThe configuration key to get the value of
defaultvalThe default value to use if the key isn't set
keyfileptrA keyfile pointer, or NULL to use the default keyfile
Returns
The configuration value on success, the default value on failure

◆ sci_conf_get_int()

gint sci_conf_get_int ( const gchar * group,
const gchar * key,
const gint defaultval,
gpointer keyfileptr )

Get an integer configuration value.

Parameters
groupThe configuration group to get the value from
keyThe configuration key to get the value of
defaultvalThe default value to use if the key isn't set
keyfileptrA keyfile pointer, or NULL to use the default keyfile
Returns
The configuration value on success, the default value on failure

◆ sci_conf_get_int_list()

gint * sci_conf_get_int_list ( const gchar * group,
const gchar * key,
gsize * length,
gpointer keyfileptr )

Get an integer list configuration value.

Parameters
groupThe configuration group to get the value from
keyThe configuration key to get the value of
lengthThe length of the list
keyfileptrA keyfile pointer, or NULL to use the default keyfile
Returns
The configuration value on success, NULL on failure

◆ sci_conf_get_string()

gchar * sci_conf_get_string ( const gchar * group,
const gchar * key,
const gchar * defaultval,
gpointer keyfileptr )

Get a string configuration value.

Parameters
groupThe configuration group to get the value from
keyThe configuration key to get the value of
defaultvalThe default value to use if the key isn't set
keyfileptrA keyfile pointer, or NULL to use the default keyfile
Returns
The configuration value on success, the default value on failure

◆ sci_conf_get_string_list()

gchar ** sci_conf_get_string_list ( const gchar * group,
const gchar * key,
gsize * length,
gpointer keyfileptr )

Get a string list configuration value.

Parameters
groupThe configuration group to get the value from
keyThe configuration key to get the value of
lengthThe length of the list
keyfileptrA keyfile pointer, or NULL to use the default keyfile
Returns
The configuration value on success, NULL on failure

◆ sci_conf_read_conf_bytes()

gpointer sci_conf_read_conf_bytes ( const char * data,
size_t length )

Read configuration from raw memory.

Parameters
dataPointer to raw data to read
lengthlength of data
Returns
A keyfile pointer on success, NULL on failure

◆ sci_conf_read_conf_file()

gpointer sci_conf_read_conf_file ( const gchar *const conffile)

Read configuration file.

Parameters
conffileThe full path to the configuration file to read
Returns
A keyfile pointer on success, NULL on failure

◆ sci_plugin_register()

int sci_plugin_register ( const BackendInfo * backend_info,
RequestReturn *(*)(const DocumentMeta *, size_t, size_t, void *) fill_meta_in,
char *(*)(const DocumentMeta *, void *) get_document_text_in,
PdfData *(*)(const DocumentMeta *, void *) get_document_pdf_data_in,
void * user_data )

Registers a backend, not all functions have to be regisered for eatch backend, pass NULL for unwanted functions.

Parameters
backend_infoa module_info_struct descibeing the backend in question. it is expected that this struct have static lifetime.
fill_meta_ina function pointer to a function that takes a DocumentMeta struct and fills it. See sci_fill_meta() for details on parameters
get_document_text_ina function pointer to a function that gets the full text for a document. See sci_get_document_text() for details on parameters
get_document_pdf_data_ina function pointer to a function that gets the pdf data for a document. See sci_get_document_pdf_data() for details on parameters
user_dataa point for context that will be passed to fill_meta_in, get_document_text_in, and get_document_pdf_data_in when called
Returns
backend id that is to be given in DocumentMeta backendId as well as input for sci_plugin_unregister()

◆ sci_plugin_unregister()

void sci_plugin_unregister ( int id)

Unregisters a backend, must be called before the backend exits.

Parameters
idthe backend id to unreigster.

◆ wgetPdf()

PdfData * wgetPdf ( const char * url,
int timeout )

Get a pdf file va a http(s) GET request.

Parameters
urlThe url to get
Returns
A newly PdfData struct or NULL if unsucessfull

◆ wgetUrl()

GString * wgetUrl ( const char * url,
int timeout )

Get the http data return as a string from a url via a http(s) GET request.

Parameters
urlThe url to get
Returns
A newly allocated GString containing the data grabed from the url on sucess, or NULL on failure

◆ wpostUrl()

GString * wpostUrl ( const char * url,
const char * data,
int timeout )

Get the http data return as a string from a url via a http(s) POST request.

Parameters
urlThe url to post
datanull terminated string that contains the data to post to url
Returns
A newly allocated GString containing the data grabed from the url on sucess, or NULL on failure