libextractor
1.11
About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.
![]() ![]() |
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>
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) |
main loop for an out-of-process plugin
Definition in file extractor_plugin_main.c.
#define INVALID_SHM_ID -1 |
Definition at line 46 of file extractor_plugin_main.c.
#define SHM_ID int |
Definition at line 45 of file extractor_plugin_main.c.
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.
plugin | extractor plugin to use |
in | stream to read from |
out | stream 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_().
|
static |
Handle an init message. The opcode itself has already been read.
pc | processing context |
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().
|
static |
Handle a start message. The opcode itself has already been read.
pc | processing context |
Definition at line 461 of file extractor_plugin_main.c.
References EXTRACTOR_ExtractContext::cls, EXTRACTOR_ExtractContext::config, EXTRACTOR_PluginList::extract_method, EXTRACTOR_read_all_(), EXTRACTOR_write_all_(), StartMessage::file_size, ProcessingContext::file_size, EXTRACTOR_ExtractContext::get_size, ProcessingContext::in, LOG, MESSAGE_DONE, MESSAGE_EXTRACT_START, NULL, StartMessage::opcode, ProcessingContext::out, ProcessingContext::plugin, plugin_env_get_size(), plugin_env_read(), plugin_env_seek(), plugin_env_send_proc(), EXTRACTOR_PluginList::plugin_options, EXTRACTOR_ExtractContext::proc, EXTRACTOR_ExtractContext::read, ProcessingContext::read_position, StartMessage::reserved, EXTRACTOR_ExtractContext::seek, ProcessingContext::shm_off, StartMessage::shm_ready_bytes, ProcessingContext::shm_ready_bytes, and EXTRACTOR_PluginList::specials.
Referenced by process_requests().
|
static |
Open '/dev/null' and make the result the given file descriptor.
target_fd | desired FD to point to /dev/null |
flags | open 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_().
|
static |
Provide the overall file size to plugins.
cls | the 'struct ProcessingContext' |
Definition at line 291 of file extractor_plugin_main.c.
References ProcessingContext::file_size.
Referenced by handle_start_message().
|
static |
Fills data with a pointer to the data buffer.
plugin | plugin context |
data | location to store data pointer |
count | number of bytes to read |
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().
|
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.
plugin | plugin context |
pos | position to move to |
whence | seek mode (SEEK_CUR, SEEK_SET, SEEK_END) |
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().
|
static |
Function called by a plugin in a child process. Transmits the meta data back to the parent process.
cls | closure, "struct ProcessingContext" with the FD for transmission |
plugin_name | name 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). |
type | libextractor-type describing the meta data |
format | basic format information about data |
data_mime_type | mime-type of data (not of the original file); can be NULL (if mime-type is not known) |
data | actual meta-data found |
data_len | number of bytes in data |
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().
|
static |
Main loop function for plugins. Reads a message from the plugin input pipe and acts on it.
pc | processing 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_().