libextractor  1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
  Fossies Dox: libextractor-1.11.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

extractor_plugin_main.c File Reference

main loop for an out-of-process plugin More...

#include "platform.h"
#include "extractor.h"
#include "extractor_common.h"
#include "extractor_datasource.h"
#include "extractor_plugins.h"
#include "extractor_ipc.h"
#include "extractor_logging.h"
#include "extractor_plugin_main.h"
#include <dirent.h>
#include <sys/types.h>
Include dependency graph for extractor_plugin_main.c:

Go to the source code of this file.

Data Structures

struct  ProcessingContext
 

Macros

#define SHM_ID   int
 
#define INVALID_SHM_ID   -1
 

Functions

static int64_t plugin_env_seek (void *cls, int64_t pos, int whence)
 
static ssize_t plugin_env_read (void *cls, void **data, size_t count)
 
static uint64_t plugin_env_get_size (void *cls)
 
static int plugin_env_send_proc (void *cls, const char *plugin_name, enum EXTRACTOR_MetaType type, enum EXTRACTOR_MetaFormat format, const char *data_mime_type, const char *data, size_t data_len)
 
static int handle_init_message (struct ProcessingContext *pc)
 
static int handle_start_message (struct ProcessingContext *pc)
 
static void process_requests (struct ProcessingContext *pc)
 
static void open_dev_null (int target_fd, int flags)
 
void EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin, int in, int out)
 

Detailed Description

main loop for an out-of-process plugin

Author
Christian Grothoff

Definition in file extractor_plugin_main.c.

Macro Definition Documentation

◆ INVALID_SHM_ID

#define INVALID_SHM_ID   -1

Definition at line 46 of file extractor_plugin_main.c.

◆ SHM_ID

#define SHM_ID   int

Definition at line 45 of file extractor_plugin_main.c.

Function Documentation

◆ EXTRACTOR_plugin_main_()

void EXTRACTOR_plugin_main_ ( struct EXTRACTOR_PluginList plugin,
int  in,
int  out 
)

'main' function of the child process. Loads the plugin, sets up its in and out pipes, then runs the request serving function.

Parameters
pluginextractor plugin to use
instream to read from
outstream to write to

Definition at line 606 of file extractor_plugin_main.c.

References EXTRACTOR_plugin_load_(), ProcessingContext::in, INVALID_SHM_ID, LOG, LOG_STRERROR, NULL, open_dev_null(), ProcessingContext::out, ProcessingContext::plugin, process_requests(), ProcessingContext::shm, ProcessingContext::shm_id, ProcessingContext::shm_map_size, EXTRACTOR_PluginList::short_libname, and EXTRACTOR_PluginList::specials.

Referenced by EXTRACTOR_IPC_channel_create_().

◆ handle_init_message()

static int handle_init_message ( struct ProcessingContext pc)
static

Handle an init message. The opcode itself has already been read.

Parameters
pcprocessing context
Returns
0 on success, -1 on error

Definition at line 382 of file extractor_plugin_main.c.

References EXTRACTOR_read_all_(), ProcessingContext::in, LOG, LOG_STRERROR_FILE, MAX_SHM_NAME, MESSAGE_INIT_STATE, NULL, InitMessage::opcode, InitMessage::reserved, ProcessingContext::shm, ProcessingContext::shm_id, InitMessage::shm_map_size, ProcessingContext::shm_map_size, and InitMessage::shm_name_length.

Referenced by process_requests().

◆ handle_start_message()

◆ open_dev_null()

static void open_dev_null ( int  target_fd,
int  flags 
)
static

Open '/dev/null' and make the result the given file descriptor.

Parameters
target_fddesired FD to point to /dev/null
flagsopen flags (O_RDONLY, O_WRONLY)

Definition at line 568 of file extractor_plugin_main.c.

References LOG_STRERROR, and LOG_STRERROR_FILE.

Referenced by EXTRACTOR_plugin_main_().

◆ plugin_env_get_size()

static uint64_t plugin_env_get_size ( void *  cls)
static

Provide the overall file size to plugins.

Parameters
clsthe 'struct ProcessingContext'
Returns
overall file size of the current file

Definition at line 291 of file extractor_plugin_main.c.

References ProcessingContext::file_size.

Referenced by handle_start_message().

◆ plugin_env_read()

static ssize_t plugin_env_read ( void *  cls,
void **  data,
size_t  count 
)
static

Fills data with a pointer to the data buffer.

Parameters
pluginplugin context
datalocation to store data pointer
countnumber of bytes to read
Returns
number of bytes (<= count) available in data, -1 on error

Definition at line 256 of file extractor_plugin_main.c.

References ProcessingContext::file_size, LOG, NULL, plugin_env_seek(), ProcessingContext::read_position, ProcessingContext::shm, ProcessingContext::shm_off, and ProcessingContext::shm_ready_bytes.

Referenced by handle_start_message().

◆ plugin_env_seek()

static int64_t plugin_env_seek ( void *  cls,
int64_t  pos,
int  whence 
)
static

Moves current absolute buffer position to 'pos' in 'whence' mode. Will move logical position without shifting the buffer, if possible. Will not move beyond the end of file.

Parameters
pluginplugin context
posposition to move to
whenceseek mode (SEEK_CUR, SEEK_SET, SEEK_END)
Returns
new absolute position, -1 on error

Definition at line 117 of file extractor_plugin_main.c.

References EXTRACTOR_read_all_(), EXTRACTOR_write_all_(), SeekRequestMessage::file_offset, UpdateMessage::file_size, ProcessingContext::file_size, ProcessingContext::in, LOG, MESSAGE_SEEK, MESSAGE_UPDATED_SHM, SeekRequestMessage::opcode, ProcessingContext::out, ProcessingContext::plugin, ProcessingContext::read_position, SeekRequestMessage::requested_bytes, UpdateMessage::reserved, SeekRequestMessage::reserved, ProcessingContext::shm_map_size, UpdateMessage::shm_off, ProcessingContext::shm_off, UpdateMessage::shm_ready_bytes, ProcessingContext::shm_ready_bytes, EXTRACTOR_PluginList::short_libname, and SeekRequestMessage::whence.

Referenced by handle_start_message(), and plugin_env_read().

◆ plugin_env_send_proc()

static int plugin_env_send_proc ( void *  cls,
const char *  plugin_name,
enum EXTRACTOR_MetaType  type,
enum EXTRACTOR_MetaFormat  format,
const char *  data_mime_type,
const char *  data,
size_t  data_len 
)
static

Function called by a plugin in a child process. Transmits the meta data back to the parent process.

Parameters
clsclosure, "struct ProcessingContext" with the FD for transmission
plugin_namename of the plugin that produced this value; special values can be used (i.e. '<zlib>' for zlib being used in the main libextractor library and yielding meta data).
typelibextractor-type describing the meta data
formatbasic format information about data
data_mime_typemime-type of data (not of the original file); can be NULL (if mime-type is not known)
dataactual meta-data found
data_lennumber of bytes in data
Returns
0 to continue extracting, 1 to abort (transmission error)

Definition at line 317 of file extractor_plugin_main.c.

References EXTRACTOR_read_all_(), EXTRACTOR_write_all_(), ProcessingContext::in, LOG, MAX_META_DATA, MESSAGE_CONTINUE_EXTRACTING, MESSAGE_DISCARD_STATE, MESSAGE_META, MetaMessage::meta_format, MetaMessage::meta_type, MetaMessage::mime_length, NULL, MetaMessage::opcode, ProcessingContext::out, MetaMessage::reserved, type, and MetaMessage::value_size.

Referenced by handle_start_message().

◆ process_requests()

static void process_requests ( struct ProcessingContext pc)
static

Main loop function for plugins. Reads a message from the plugin input pipe and acts on it.

Parameters
pcprocessing context

Definition at line 517 of file extractor_plugin_main.c.

References EXTRACTOR_read_all_(), handle_init_message(), handle_start_message(), ProcessingContext::in, LOG, MESSAGE_DISCARD_STATE, MESSAGE_EXTRACT_START, MESSAGE_INIT_STATE, and MESSAGE_UPDATED_SHM.

Referenced by EXTRACTOR_plugin_main_().