43#define INVALID_SHM_ID NULL
46#define INVALID_SHM_ID -1
135 LOG (
"Invalid seek operation\n");
138 if ((pos > 0) && ((pc->
read_position + pos < pc->read_position) ||
141 LOG (
"Invalid seek operation\n");
150 LOG (
"Invalid seek operation\n");
156 npos = (uint64_t) -pos;
162 if ( (pos < 0) || (pc->
file_size < pos) )
164 LOG (
"Invalid seek operation\n");
167 npos = (uint64_t) pos;
171 LOG (
"Invalid seek operation\n");
179 return (int64_t) npos;
198 LOG (
"Failed to send MESSAGE_SEEK\n");
203 &reply, sizeof (reply)))
205 LOG (
"Plugin `%s' failed to read response to MESSAGE_SEEK\n",
211 LOG (
"Unexpected reply %d to seek\n", reply);
216 LOG (
"Failed to read MESSAGE_UPDATED_SHM\n");
232 return (int64_t) npos;
237 "Plugin `%s' got invalid MESSAGE_UPDATED_SHM in response to my %d-seek (%llu not in %llu-%llu)\n",
240 (
unsigned long long) npos,
241 (
unsigned long long) pc->
shm_off,
272 LOG (
"Failed to seek to satisfy read\n");
318 const char *plugin_name,
321 const char *data_mime_type,
332 if (
NULL == data_mime_type)
335 mime_len = strlen (data_mime_type) + 1;
336 if (mime_len > UINT16_MAX)
337 mime_len = UINT16_MAX;
346 &mm, sizeof (mm))) ||
349 data_mime_type, mime_len)) ||
354 LOG (
"Failed to send meta message\n");
359 &reply, sizeof (reply)))
361 LOG (
"Failed to read response to meta message\n");
368 LOG (
"Received unexpected reply to meta data: %d\n", reply);
390 LOG (
"Cannot handle 'init' message, have already been initialized\n");
398 LOG (
"Failed to read 'init' message\n");
403 LOG (
"Invalid 'init' message\n");
414 LOG (
"Failed to read 'init' message\n");
422 pc->
shm_id = OpenFileMapping (FILE_MAP_READ, FALSE, shm_name);
425 pc->
shm = MapViewOfFile (pc->
shm_id, FILE_MAP_READ, 0, 0, 0);
432 pc->
shm_id = shm_open (shm_name, O_RDONLY, 0);
443 if ( ((
void*) -1) == pc->
shm)
474 LOG (
"Failed to read 'start' message\n");
491 LOG (
"Failed to write 'done' message\n");
525 LOG (
"Failed to read next request\n");
533 LOG (
"Failure to handle INIT\n");
540 LOG (
"Failure to handle START\n");
545 LOG (
"Illegal message\n");
552 LOG (
"Received invalid message %d\n", (
int) code);
574 fd = open (
"/dev/null", flags);
576 fd = open (
"\\\\?\\NUL", flags);
585 if (-1 == dup2 (fd, target_fd))
614 fprintf (stderr,
"Plugin `%s' failed to load!\n",
640 LOG (
"IPC error; plugin `%s' terminates!\n",
644 UnmapViewOfFile (pc.
shm);
649 (((
void*) 1) != pc.
shm) )
653 if (0 != close (pc.
shm_id))
669read_plugin_data (
int fd)
724RundllEntryPoint (HWND hwnd,
735 sscanf (lpszCmdLine,
"%lu %lu", &in_h, &out_h);
736 in = _open_osfhandle (in_h, _O_RDONLY);
737 out = _open_osfhandle (out_h, 0);
738 setmode (in, _O_BINARY);
739 setmode (out, _O_BINARY);
740 if (
NULL == (plugin = read_plugin_data (in)))
754TerminateProcess (GetCurrentProcess (), 0);
762RundllEntryPointA (HWND hwnd,
767 return RundllEntryPoint (hwnd, hinst, lpszCmdLine, nCmdShow);
void EXTRACTOR_plugin_main_(struct EXTRACTOR_PluginList *plugin, int in, int out)
static ssize_t plugin_env_read(void *cls, void **data, size_t count)
static void process_requests(struct ProcessingContext *pc)
static int handle_init_message(struct ProcessingContext *pc)
static void open_dev_null(int target_fd, int flags)
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 int64_t plugin_env_seek(void *cls, int64_t pos, int whence)
static int handle_start_message(struct ProcessingContext *pc)
static uint64_t plugin_env_get_size(void *cls)
struct EXTRACTOR_PluginList * plugin