libscipaper 1.0.x
Plugin API

This API provides the ability to write a plugin that implements a backend to any database of papers. The hope being that libscipaper with eventually have modules that implement fetching from all major scientific databases. Full documentation can be found here: Module API. For the convenience of module developers, a Jason parsing API is also provided. This API is documented here: Json Parsing API.

A libscipaper module is a C or C++ tanslation unit that contains #define MODULE_NAME "some-name" as well as exporting the symbols sci_module_init of type sci_module_init_fn and sci_module_exit of type sci_module_exit_fn.

modules are expected to use the sci_conf_* family of functions to gain external site specific information sutch as API keys and use sci_module_log for debug as well as error output. Any library such as libcurl may be used to gather information to be returned.

For a module to be usefull it must also define an implementation at least one of the following functions:

and must register one or more of these functions with libscipaper using sci_plugin_register

thus the basic structure of a libscipaper plugin looks like this:

#include <glib.h>
#include "sci-modules.h"
#include "sci-log.h"
#include "sci-backend.h"
#include "scipaper.h"
//Module name every module is required to have this
#define MODULE_NAME "test"
//Module information every module is required to have this
static BackendInfo module_info = {
//Name of the module
.name = MODULE_NAME,
};
struct TestPriv {
int id;
};
static RequestReturn* test_fill_meta(const DocumentMeta* meta, size_t maxCount, size_t page, void* userData)
{
struct TestPriv* priv = userData;
//Check out the the contense of meta here and search for the contained fields in your database, return a list DocumentMeta structs that describe the search results
return request_return_new(1, maxCount);
}
static char* test_get_document_text(const DocumentMeta* meta, void* userData)
{
struct TestPriv* priv = userData;
//Check out the the contense of meta here and search for the contained fields in your database, return the full text of the first search result.
return g_strdup("This should be the document text");
}
static PdfData* test_get_document_pdf_data(const DocumentMeta* meta, void* userData)
{
struct TestPriv* priv = userData;
//Check out the the contense of meta here and search for the contained fields in your database, return raw PDF binary data for the first search result.
return NULL;
}
//function that is called when the module is loaded, every module is required to have this
G_MODULE_EXPORT const gchar *sci_module_init(void** data);
const gchar *sci_module_init(void** data)
{
//Do whatever is necessarily to initialize your database.
struct TestPriv* priv = g_malloc0(sizeof(*priv));
*data = priv;
priv->id = sci_plugin_register(&module_info, test_fill_meta, test_get_document_text, test_get_document_pdf_data, priv);
}
//function that is called when the module is unloaded, every module is required to have this
G_MODULE_EXPORT void sci_module_exit(void* data);
void sci_module_exit(void* data)
{
struct TestPriv* priv = data;
//Free any resources you have acquired.
g_free(priv);
}
RequestReturn * request_return_new(size_t count, size_t maxCount)
Allocates a empty RequestReturn struct.
@ SCI_CAP_GET_TEXT
Backend can get full text of documents.
Definition types.h:52
@ SCI_CAP_GET_PDF
Backend can get pdfs of documents.
Definition types.h:53
@ SCI_CAP_FILL
Backend can fill DocumentMeta structs.
Definition types.h:51
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...
Headers for the module handling for SCIPAPER.
Backend information struct.
Definition types.h:75
const char *const name
Name of the plugin.
Definition types.h:76
This struct contains the metadata of a paper, must be created via document_meta_new() and freed via d...
Definition types.h:103
This struct contains the raw data of a PDF document.
Definition types.h:260
This struct is details the result of a metadata search.
Definition types.h:234