aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/Makefile.am8
-rw-r--r--src/main/extractor.c47
-rw-r--r--src/main/extractor_datasource.h2
-rw-r--r--src/main/extractor_ipc.c106
-rw-r--r--src/main/extractor_ipc.h57
-rw-r--r--src/main/extractor_ipc_gnu.c45
-rw-r--r--src/main/extractor_plugin_main.c1
-rw-r--r--src/main/extractor_plugins.c7
-rw-r--r--src/main/extractor_plugins.h24
-rw-r--r--src/main/extractor_plugpath.c21
-rw-r--r--src/main/extractor_plugpath.h22
11 files changed, 167 insertions, 173 deletions
diff --git a/src/main/Makefile.am b/src/main/Makefile.am
index d319421..09b3d05 100644
--- a/src/main/Makefile.am
+++ b/src/main/Makefile.am
@@ -40,13 +40,13 @@ EXTRA_DIST = \
40libextractor_la_CPPFLAGS = -DPLUGINDIR=\"@RPLUGINDIR@\" -DPLUGININSTDIR=\"${plugindir}\" $(AM_CPPFLAGS) 40libextractor_la_CPPFLAGS = -DPLUGINDIR=\"@RPLUGINDIR@\" -DPLUGININSTDIR=\"${plugindir}\" $(AM_CPPFLAGS)
41 41
42libextractor_la_SOURCES = \ 42libextractor_la_SOURCES = \
43 extractor.c \ 43 extractor_metatypes.c \
44 $(EXTRACTOR_IPC) extractor_ipc.c extractor_ipc.h \ 44 extractor_print.c \
45 extractor_plugpath.c extractor_plugpath.h \ 45 extractor_plugpath.c extractor_plugpath.h \
46 extractor_plugins.c extractor_plugins.h \ 46 extractor_plugins.c extractor_plugins.h \
47 $(EXTRACTOR_IPC) extractor_ipc.c extractor_ipc.h \
47 extractor_plugin_main.c extractor_plugin_main.h \ 48 extractor_plugin_main.c extractor_plugin_main.h \
48 extractor_metatypes.c \ 49 extractor.c
49 extractor_print.c
50 50
51extract_SOURCES = \ 51extract_SOURCES = \
52 extract.c \ 52 extract.c \
diff --git a/src/main/extractor.c b/src/main/extractor.c
index d5dbd4d..1875ab2 100644
--- a/src/main/extractor.c
+++ b/src/main/extractor.c
@@ -31,64 +31,17 @@
31#include "extractor_plugpath.h" 31#include "extractor_plugpath.h"
32#include "extractor_plugins.h" 32#include "extractor_plugins.h"
33 33
34
35/**
36 * How long do we allow an individual meta data object to be?
37 * Used to guard against (broken) plugns causing us to use
38 * excessive amounts of memory.
39 */
40#define MAX_META_DATA 32 * 1024 * 1024
41
42/** 34/**
43 * Maximum length of a Mime-Type string. 35 * Maximum length of a Mime-Type string.
44 */ 36 */
45#define MAX_MIME_LEN 256 37#define MAX_MIME_LEN 256
46 38
47/** 39/**
48 * Maximum length of a shared memory object name
49 */
50#define MAX_SHM_NAME 255
51
52/**
53 * Set to 1 to get failure info, 40 * Set to 1 to get failure info,
54 * 2 for actual debug info. 41 * 2 for actual debug info.
55 */ 42 */
56#define DEBUG 1 43#define DEBUG 1
57 44
58/**
59 * Sent from LE to a plugin to initialize it (open shm,
60 * reset position counters etc).
61 */
62#define MESSAGE_INIT_STATE 0x01
63
64/**
65 * Sent from LE to a plugin to tell it that shm contents
66 * were updated. Only used for OPMODE_COMPRESS.
67 */
68#define MESSAGE_UPDATED_SHM 0x02
69
70/**
71 * Sent from plugin to LE to tell LE that plugin is done
72 * analyzing current file and will send no more data.
73 */
74#define MESSAGE_DONE 0x03
75
76/**
77 * Sent from plugin to LE to tell LE that plugin needs
78 * to read a different part of the source file.
79 */
80#define MESSAGE_SEEK 0x04
81
82/**
83 * Sent from plugin to LE to tell LE about metadata discovered.
84 */
85#define MESSAGE_META 0x05
86
87/**
88 * Sent from LE to plugin to make plugin discard its state (unmap
89 * and close shm).
90 */
91#define MESSAGE_DISCARD_STATE 0x06
92 45
93/** 46/**
94 * Client provided a memory buffer, analyze it. Creates a shm, copies 47 * Client provided a memory buffer, analyze it. Creates a shm, copies
diff --git a/src/main/extractor_datasource.h b/src/main/extractor_datasource.h
index c71f4fd..d2bd4f8 100644
--- a/src/main/extractor_datasource.h
+++ b/src/main/extractor_datasource.h
@@ -25,6 +25,8 @@
25#ifndef EXTRACTOR_DATASOURCE_H 25#ifndef EXTRACTOR_DATASOURCE_H
26#define EXTRACTOR_DATASOURCE_H 26#define EXTRACTOR_DATASOURCE_H
27 27
28#include "extractor.h"
29
28/** 30/**
29 * Handle to a datasource we can use for the plugins. 31 * Handle to a datasource we can use for the plugins.
30 */ 32 */
diff --git a/src/main/extractor_ipc.c b/src/main/extractor_ipc.c
index 8c3a687..eb21993 100644
--- a/src/main/extractor_ipc.c
+++ b/src/main/extractor_ipc.c
@@ -23,11 +23,14 @@
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "extractor_ipc.h"
27#include "extractor_plugins.h"
26 28
27 29
28/** 30/**
29 * Process a reply from channel (seek request, metadata and done message) 31 * Process a reply from channel (seek request, metadata and done message)
30 * 32 *
33 * @param plugin plugin this communication is about
31 * @param buf buffer with data from IPC channel 34 * @param buf buffer with data from IPC channel
32 * @param size number of bytes in buffer 35 * @param size number of bytes in buffer
33 * @param proc metadata callback 36 * @param proc metadata callback
@@ -35,98 +38,71 @@
35 * @return number of bytes processed, -1 on error 38 * @return number of bytes processed, -1 on error
36 */ 39 */
37ssize_t 40ssize_t
38EXTRACTOR_IPC_process_reply_ (const void *data, 41EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin,
42 const void *data,
39 size_t size, 43 size_t size,
40 EXTRACTOR_ChannelMessageProcessor proc, 44 EXTRACTOR_ChannelMessageProcessor proc,
41 void *proc_cls) 45 void *proc_cls)
42{ 46{
43 int read_result; 47 const char *cdata = data;
44 unsigned char code; 48 unsigned char code;
45 int64_t seek_position; 49 int64_t seek_position;
46 struct IpcHeader hdr; 50 struct IpcHeader hdr;
47 char *mime_type; 51 const char *mime_type;
48 char *data; 52 const char *value;
49 int must_read = 1;
50 53
51 while (must_read) 54 while (size > 0)
52 { 55 {
53 read_result = plugin_read (plugin, &code, 1); 56 code = (unsigned char) cdata[0];
54 if (read_result < 1)
55 return -1;
56 switch (code) 57 switch (code)
57 { 58 {
58 case MESSAGE_DONE: /* Done */ 59 case MESSAGE_DONE: /* Done */
59 plugin->seek_request = -1; 60 plugin->seek_request = -1;
60 must_read = 0; 61 plugin->round_finished = 1;
61 break; 62 return 1;
62 case MESSAGE_SEEK: /* Seek */ 63 case MESSAGE_SEEK: /* Seek */
63 read_result = plugin_read (plugin, 64 if (size < 1 + sizeof (int64_t))
64 &seek_position, sizeof (int64_t)); 65 {
65 if (read_result < sizeof (int64_t)) 66 plugin->seek_request = -1;
66 return -1; 67 return 0;
68 }
69 memcpy (&seek_position, &cdata[1], sizeof (int64_t));
67 plugin->seek_request = seek_position; 70 plugin->seek_request = seek_position;
68 must_read = 0; 71 return 1 + sizeof (int64_t);
69 break;
70 case MESSAGE_META: /* Meta */ 72 case MESSAGE_META: /* Meta */
71 read_result = plugin_read (plugin, 73 if (size < 1 + sizeof (hdr) )
72 &hdr, sizeof (hdr)); 74 {
73 if (read_result < sizeof (hdr)) 75 plugin->seek_request = -1;
74 return -1; 76 return 0;
75 /* FIXME: check hdr for sanity */ 77 }
78 memcpy (&hdr, &cdata[1], sizeof (hdr));
79 /* check hdr for sanity */
76 if (hdr.data_len > MAX_META_DATA) 80 if (hdr.data_len > MAX_META_DATA)
77 return -1; /* not allowing more than MAX_META_DATA meta data */ 81 return -1; /* not allowing more than MAX_META_DATA meta data */
82 if (size < 1 + sizeof (hdr) + hdr.mime_len + hdr.data_len)
83 {
84 plugin->seek_request = -1;
85 return 0;
86 }
78 if (0 == hdr.mime_len) 87 if (0 == hdr.mime_len)
79 { 88 {
80 mime_type = NULL; 89 mime_type = NULL;
81 } 90 }
82 else 91 else
83 { 92 {
84 if (NULL == (mime_type = malloc (hdr.mime_len))) 93 mime_type = &cdata[1 + sizeof (hdr)];
85 return -1; 94 if ('\0' != mime_type[hdr.mime_len-1])
86 read_result = plugin_read (plugin, 95 return -1;
87 mime_type,
88 hdr.mime_len);
89 if ( (read_result < hdr.mime_len) ||
90 ('\0' != mime_type[hdr.mime_len-1]) )
91 {
92 if (NULL != mime_type)
93 free (mime_type);
94 return -1;
95 }
96 } 96 }
97 if (0 == hdr.data_len) 97 if (0 == hdr.data_len)
98 { 98 value = NULL;
99 data = NULL;
100 }
101 else 99 else
102 { 100 value = &cdata[1 + sizeof (hdr) + hdr.mime_len];
103 if (NULL == (data = malloc (hdr.data_len))) 101 proc (proc_cls,
104 { 102 plugin,
105 if (NULL != mime_type) 103 &hdr,
106 free (mime_type); 104 mime_type, value);
107 return -1; 105 return 1 + sizeof (hdr) + hdr.mime_len + hdr.data_len;
108 }
109 read_result = plugin_read (plugin,
110 data, hdr.data_len);
111 if (read_result < hdr.data_len)
112 {
113 if (NULL != mime_type)
114 free (mime_type);
115 free (data);
116 return -1;
117 }
118 }
119 read_result = proc (proc_cls,
120 plugin->short_libname,
121 hdr.meta_type, hdr.meta_format,
122 mime_type, data, hdr.data_len);
123 if (NULL != mime_type)
124 free (mime_type);
125 if (NULL != data)
126 free (data);
127 if (0 != read_result)
128 return 1;
129 break;
130 default: 106 default:
131 return -1; 107 return -1;
132 } 108 }
diff --git a/src/main/extractor_ipc.h b/src/main/extractor_ipc.h
index d430923..ce54f4d 100644
--- a/src/main/extractor_ipc.h
+++ b/src/main/extractor_ipc.h
@@ -25,6 +25,53 @@
25#ifndef EXTRACTOR_IPC_H 25#ifndef EXTRACTOR_IPC_H
26#define EXTRACTOR_IPC_H 26#define EXTRACTOR_IPC_H
27 27
28#include "extractor_datasource.h"
29
30
31/**
32 * How long do we allow an individual meta data object to be?
33 * Used to guard against (broken) plugns causing us to use
34 * excessive amounts of memory.
35 */
36#define MAX_META_DATA 32 * 1024 * 1024
37
38
39/**
40 * Sent from LE to a plugin to initialize it (open shm,
41 * reset position counters etc).
42 */
43#define MESSAGE_INIT_STATE 0x01
44
45/**
46 * Sent from LE to a plugin to tell it that shm contents
47 * were updated. Only used for OPMODE_COMPRESS.
48 */
49#define MESSAGE_UPDATED_SHM 0x02
50
51/**
52 * Sent from plugin to LE to tell LE that plugin is done
53 * analyzing current file and will send no more data.
54 */
55#define MESSAGE_DONE 0x03
56
57/**
58 * Sent from plugin to LE to tell LE that plugin needs
59 * to read a different part of the source file.
60 */
61#define MESSAGE_SEEK 0x04
62
63/**
64 * Sent from plugin to LE to tell LE about metadata discovered.
65 */
66#define MESSAGE_META 0x05
67
68/**
69 * Sent from LE to plugin to make plugin discard its state (unmap
70 * and close shm).
71 */
72#define MESSAGE_DISCARD_STATE 0x06
73
74
28/** 75/**
29 * Definition of an IPC communication channel with 76 * Definition of an IPC communication channel with
30 * some plugin. 77 * some plugin.
@@ -107,12 +154,12 @@ EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm,
107 * Create a channel to communicate with a process wrapping 154 * Create a channel to communicate with a process wrapping
108 * the plugin of the given name. Starts the process as well. 155 * the plugin of the given name. Starts the process as well.
109 * 156 *
110 * @param short_libname name of the plugin 157 * @param plugin the plugin
111 * @param shm memory to share with the process 158 * @param shm memory to share with the process
112 * @return NULL on error, otherwise IPC channel 159 * @return NULL on error, otherwise IPC channel
113 */ 160 */
114struct EXTRACTOR_Channel * 161struct EXTRACTOR_Channel *
115EXTRACTOR_IPC_channel_create_ (const char *short_libname, 162EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
116 struct EXTRACTOR_SharedMemory *shm); 163 struct EXTRACTOR_SharedMemory *shm);
117 164
118 165
@@ -151,7 +198,7 @@ EXTRACTOR_IPC_channel_send_ (struct EXTRACTOR_Channel *channel,
151 * @param mime mime string send from the plugin 198 * @param mime mime string send from the plugin
152 */ 199 */
153typedef void (*EXTRACTOR_ChannelMessageProcessor) (void *cls, 200typedef void (*EXTRACTOR_ChannelMessageProcessor) (void *cls,
154 const char *short_libname, 201 struct EXTRACTOR_PluginList *plugin,
155 const struct IpcHeader *msg, 202 const struct IpcHeader *msg,
156 const void *value, 203 const void *value,
157 const char *mime); 204 const char *mime);
@@ -159,6 +206,7 @@ typedef void (*EXTRACTOR_ChannelMessageProcessor) (void *cls,
159/** 206/**
160 * Process a reply from channel (seek request, metadata and done message) 207 * Process a reply from channel (seek request, metadata and done message)
161 * 208 *
209 * @param plugin plugin this communication is about
162 * @param buf buffer with data from IPC channel 210 * @param buf buffer with data from IPC channel
163 * @param size number of bytes in buffer 211 * @param size number of bytes in buffer
164 * @param proc metadata callback 212 * @param proc metadata callback
@@ -166,7 +214,8 @@ typedef void (*EXTRACTOR_ChannelMessageProcessor) (void *cls,
166 * @return number of bytes processed, -1 on error 214 * @return number of bytes processed, -1 on error
167 */ 215 */
168ssize_t 216ssize_t
169EXTRACTOR_IPC_process_reply_ (const void *data, 217EXTRACTOR_IPC_process_reply_ (struct EXTRACTOR_PluginList *plugin,
218 const void *data,
170 size_t size, 219 size_t size,
171 EXTRACTOR_ChannelMessageProcessor proc, 220 EXTRACTOR_ChannelMessageProcessor proc,
172 void *proc_cls); 221 void *proc_cls);
diff --git a/src/main/extractor_ipc_gnu.c b/src/main/extractor_ipc_gnu.c
index 7e7a086..6c80188 100644
--- a/src/main/extractor_ipc_gnu.c
+++ b/src/main/extractor_ipc_gnu.c
@@ -26,6 +26,7 @@
26#include "plibc.h" 26#include "plibc.h"
27#include "extractor.h" 27#include "extractor.h"
28#include "extractor_datasource.h" 28#include "extractor_datasource.h"
29#include "extractor_plugin_main.h"
29#include "extractor_ipc.h" 30#include "extractor_ipc.h"
30#include <dirent.h> 31#include <dirent.h>
31#include <sys/types.h> 32#include <sys/types.h>
@@ -33,12 +34,12 @@
33#include <sys/shm.h> 34#include <sys/shm.h>
34#include <signal.h> 35#include <signal.h>
35 36
37
36/** 38/**
37 * Size of the channel buffer; determines largest IPC message that 39 * Maximum length of a shared memory object name
38 * is going to be allowed. FIXME: we might want to grow this
39 * buffer dynamically instead...
40 */ 40 */
41#define CHANNEL_BUFFER_SIZE (1024 * 256) 41#define MAX_SHM_NAME 255
42
42 43
43/** 44/**
44 * A shared memory resource (often shared with several 45 * A shared memory resource (often shared with several
@@ -64,7 +65,7 @@ struct EXTRACTOR_SharedMemory
64 /** 65 /**
65 * POSIX id of the shm into which data is uncompressed 66 * POSIX id of the shm into which data is uncompressed
66 */ 67 */
67 int shm; 68 int shm_id;
68 69
69 /** 70 /**
70 * Name of the shm 71 * Name of the shm
@@ -83,8 +84,10 @@ struct EXTRACTOR_Channel
83 84
84 /** 85 /**
85 * Buffer for reading data from the plugin. 86 * Buffer for reading data from the plugin.
87 * FIXME: we might want to grow this
88 * buffer dynamically instead of always using 32 MB!
86 */ 89 */
87 char data[CHANNEL_BUFFER_SIZE]; 90 char data[MAX_META_DATA];
88 91
89 /** 92 /**
90 * Memory segment shared with this process. 93 * Memory segment shared with this process.
@@ -92,9 +95,9 @@ struct EXTRACTOR_Channel
92 struct EXTRACTOR_SharedMemory *shm; 95 struct EXTRACTOR_SharedMemory *shm;
93 96
94 /** 97 /**
95 * Name of the plugin to use for this channel. 98 * The plugin this channel is to communicate with.
96 */ 99 */
97 const char *short_libname; 100 struct EXTRACTOR_PluginList *plugin;
98 101
99 /** 102 /**
100 * Pipe used to communicate information to the plugin child process. 103 * Pipe used to communicate information to the plugin child process.
@@ -179,8 +182,8 @@ EXTRACTOR_IPC_shared_memory_create_ (size_t size)
179void 182void
180EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm) 183EXTRACTOR_IPC_shared_memory_destroy_ (struct EXTRACTOR_SharedMemory *shm)
181{ 184{
182 munmap (shm->shm_ptr, shm->map_size); 185 munmap (shm->shm_ptr, shm->shm_size);
183 (void) close (plugin->shm_id); 186 (void) close (shm->shm_id);
184 (void) shm_unlink (shm->shm_name); 187 (void) shm_unlink (shm->shm_name);
185 free (shm); 188 free (shm);
186} 189}
@@ -204,8 +207,8 @@ EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm,
204 if (-1 == 207 if (-1 ==
205 EXTRACTOR_datasource_seek_ (ds, off, SEEK_SET)) 208 EXTRACTOR_datasource_seek_ (ds, off, SEEK_SET))
206 return -1; 209 return -1;
207 if (size > shm->map_size) 210 if (size > shm->shm_size)
208 size = shm->map_size; 211 size = shm->shm_size;
209 return EXTRACTOR_datasource_read_ (ds, 212 return EXTRACTOR_datasource_read_ (ds,
210 shm->shm_ptr, 213 shm->shm_ptr,
211 size); 214 size);
@@ -216,24 +219,23 @@ EXTRACTOR_IPC_shared_memory_set_ (struct EXTRACTOR_SharedMemory *shm,
216 * Create a channel to communicate with a process wrapping 219 * Create a channel to communicate with a process wrapping
217 * the plugin of the given name. Starts the process as well. 220 * the plugin of the given name. Starts the process as well.
218 * 221 *
219 * @param short_libname name of the plugin 222 * @param plugin the plugin
220 * @param shm memory to share with the process 223 * @param shm memory to share with the process
221 * @return NULL on error, otherwise IPC channel 224 * @return NULL on error, otherwise IPC channel
222 */ 225 */
223struct EXTRACTOR_Channel * 226struct EXTRACTOR_Channel *
224EXTRACTOR_IPC_channel_create_ (const char *short_libname, 227EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin,
225 struct EXTRACTOR_SharedMemory *shm) 228 struct EXTRACTOR_SharedMemory *shm)
226{ 229{
227 struct EXTRACTOR_Channel *channel; 230 struct EXTRACTOR_Channel *channel;
228 int p1[2]; 231 int p1[2];
229 int p2[2]; 232 int p2[2];
230 pid_t pid; 233 pid_t pid;
231 int status;
232 234
233 if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel)))) 235 if (NULL == (channel = malloc (sizeof (struct EXTRACTOR_Channel))))
234 return NULL; 236 return NULL;
235 channel->shm = shm; 237 channel->shm = shm;
236 channel->short_libname = short_libname; 238 channel->plugin = plugin;
237 if (0 != pipe (p1)) 239 if (0 != pipe (p1))
238 { 240 {
239 free (channel); 241 free (channel);
@@ -244,7 +246,7 @@ EXTRACTOR_IPC_channel_create_ (const char *short_libname,
244 (void) close (p1[0]); 246 (void) close (p1[0]);
245 (void) close (p1[1]); 247 (void) close (p1[1]);
246 free (channel); 248 free (channel);
247 return; 249 return NULL;
248 } 250 }
249 pid = fork (); 251 pid = fork ();
250 if (pid == -1) 252 if (pid == -1)
@@ -260,7 +262,7 @@ EXTRACTOR_IPC_channel_create_ (const char *short_libname,
260 { 262 {
261 (void) close (p1[1]); 263 (void) close (p1[1]);
262 (void) close (p2[0]); 264 (void) close (p2[0]);
263 EXTRACTOR_plugin_main_ (short_libname, p1[0], p2[1]); 265 EXTRACTOR_plugin_main_ (plugin, p1[0], p2[1]);
264 _exit (0); 266 _exit (0);
265 } 267 }
266 (void) close (p1[0]); 268 (void) close (p1[0]);
@@ -376,12 +378,13 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels,
376 continue; 378 continue;
377 if ( (-1 == (iret = read (channel->cpipe_out, 379 if ( (-1 == (iret = read (channel->cpipe_out,
378 &channel->data[channel->size], 380 &channel->data[channel->size],
379 CHANNEL_BUFFER_SIZE - channel->size)) ) || 381 MAX_META_DATA - channel->size)) ) ||
380 (ret = EXTRACTOR_IPC_process_reply_ (channel->data, 382 (ret = EXTRACTOR_IPC_process_reply_ (channel->plugin,
383 channel->data,
381 channel->size + iret, 384 channel->size + iret,
382 proc, proc_cls)) ) 385 proc, proc_cls)) )
383 { 386 {
384 EXTRACTOR_IPC_channel_destroy (channel); 387 EXTRACTOR_IPC_channel_destroy_ (channel);
385 channels[i] = NULL; 388 channels[i] = NULL;
386 } 389 }
387 else 390 else
diff --git a/src/main/extractor_plugin_main.c b/src/main/extractor_plugin_main.c
index eb36233..03269fb 100644
--- a/src/main/extractor_plugin_main.c
+++ b/src/main/extractor_plugin_main.c
@@ -27,6 +27,7 @@
27#include "plibc.h" 27#include "plibc.h"
28#include "extractor.h" 28#include "extractor.h"
29#include "extractor_datasource.h" 29#include "extractor_datasource.h"
30#include "extractor_plugin_main.h"
30#include <dirent.h> 31#include <dirent.h>
31#include <sys/types.h> 32#include <sys/types.h>
32#include <sys/wait.h> 33#include <sys/wait.h>
diff --git a/src/main/extractor_plugins.c b/src/main/extractor_plugins.c
index 2b5f06a..edefc47 100644
--- a/src/main/extractor_plugins.c
+++ b/src/main/extractor_plugins.c
@@ -24,6 +24,7 @@
24 */ 24 */
25#include "extractor_plugins.h" 25#include "extractor_plugins.h"
26#include "extractor_plugpath.h" 26#include "extractor_plugpath.h"
27#include "extractor_ipc.h"
27 28
28 29
29/** 30/**
@@ -227,7 +228,7 @@ EXTRACTOR_plugin_add (struct EXTRACTOR_PluginList *prev,
227 for (pos = prev; NULL != pos; pos = pos->next) 228 for (pos = prev; NULL != pos; pos = pos->next)
228 if (0 == strcmp (pos->short_libname, library)) 229 if (0 == strcmp (pos->short_libname, library))
229 return prev; /* no change, library already loaded */ 230 return prev; /* no change, library already loaded */
230 if (NULL == (libname = find_plugin (library))) 231 if (NULL == (libname = EXTRACTOR_find_plugin_ (library)))
231 { 232 {
232 fprintf (stderr, 233 fprintf (stderr,
233 "Could not load `%s'\n", 234 "Could not load `%s'\n",
@@ -391,8 +392,8 @@ EXTRACTOR_plugin_remove (struct EXTRACTOR_PluginList * prev,
391 first = pos->next; 392 first = pos->next;
392 else 393 else
393 prev->next = pos->next; 394 prev->next = pos->next;
394 /* found */ 395 if (NULL != pos->channel)
395 stop_process (pos); 396 EXTRACTOR_IPC_channel_destroy_ (pos->channel);
396 free (pos->short_libname); 397 free (pos->short_libname);
397 free (pos->libname); 398 free (pos->libname);
398 free (pos->plugin_options); 399 free (pos->plugin_options);
diff --git a/src/main/extractor_plugins.h b/src/main/extractor_plugins.h
index 592cfb2..2fd57d7 100644
--- a/src/main/extractor_plugins.h
+++ b/src/main/extractor_plugins.h
@@ -31,6 +31,7 @@
31#include <signal.h> 31#include <signal.h>
32#include <ltdl.h> 32#include <ltdl.h>
33 33
34
34/** 35/**
35 * Linked list of extractor plugins. An application builds this list 36 * Linked list of extractor plugins. An application builds this list
36 * by telling libextractor to load various keyword-extraction 37 * by telling libextractor to load various keyword-extraction
@@ -77,10 +78,27 @@ struct EXTRACTOR_PluginList
77 const char *specials; 78 const char *specials;
78 79
79 /** 80 /**
81 * Channel to communicate with out-of-process plugin.
82 */
83 struct EXTRACTOR_Channel *channel;
84
85 /**
80 * Flags to control how the plugin is executed. 86 * Flags to control how the plugin is executed.
81 */ 87 */
82 enum EXTRACTOR_Options flags; 88 enum EXTRACTOR_Options flags;
83 89
90#if WINDOWS
91 /**
92 * Page size. Mmap offset is a multiple of this number.
93 */
94 DWORD allocation_granularity;
95#else
96 /**
97 * Page size. Mmap offset is a multiple of this number.
98 */
99 long allocation_granularity;
100#endif
101
84 /** 102 /**
85 * A position this plugin wants us to seek to. -1 if it's finished. 103 * A position this plugin wants us to seek to. -1 if it's finished.
86 * Starts at 0; 104 * Starts at 0;
@@ -88,6 +106,12 @@ struct EXTRACTOR_PluginList
88 int64_t seek_request; 106 int64_t seek_request;
89 107
90 /** 108 /**
109 * Is this plugin finished extracting for this round?
110 * 0: no, 1: yes
111 */
112 int round_finished;
113
114 /**
91 * Mode of operation. One of the OPMODE_* constants 115 * Mode of operation. One of the OPMODE_* constants
92 */ 116 */
93 uint8_t operation_mode; 117 uint8_t operation_mode;
diff --git a/src/main/extractor_plugpath.c b/src/main/extractor_plugpath.c
index 47cb67e..af3c94a 100644
--- a/src/main/extractor_plugpath.c
+++ b/src/main/extractor_plugpath.c
@@ -28,15 +28,22 @@
28#include "extractor.h" 28#include "extractor.h"
29#include <dirent.h> 29#include <dirent.h>
30#include <sys/types.h> 30#include <sys/types.h>
31#ifndef WINDOWS
32#include <sys/wait.h>
33#include <sys/shm.h>
34#endif
35#include <signal.h> 31#include <signal.h>
36#include <ltdl.h> 32#include <ltdl.h>
37 33
38#include "extractor_plugpath.h" 34#include "extractor_plugpath.h"
39 35
36
37/**
38 * Function to call on paths.
39 *
40 * @param cls closure
41 * @param path a directory path
42 */
43typedef void (*EXTRACTOR_PathProcessor) (void *cls,
44 const char *path);
45
46
40/** 47/**
41 * Remove a trailing '/bin/' from 'in' (if present). 48 * Remove a trailing '/bin/' from 'in' (if present).
42 * 49 *
@@ -392,9 +399,9 @@ append_to_dir (const char *path,
392 * @param pp function to call for each path 399 * @param pp function to call for each path
393 * @param pp_cls cls argument for pp. 400 * @param pp_cls cls argument for pp.
394 */ 401 */
395void 402static void
396EXTRACTOR_get_installation_paths_ (EXTRACTOR_PathProcessor pp, 403get_installation_paths (EXTRACTOR_PathProcessor pp,
397 void *pp_cls) 404 void *pp_cls)
398{ 405{
399 const char *p; 406 const char *p;
400 char *path; 407 char *path;
diff --git a/src/main/extractor_plugpath.h b/src/main/extractor_plugpath.h
index b3c3d19..d1c1739 100644
--- a/src/main/extractor_plugpath.h
+++ b/src/main/extractor_plugpath.h
@@ -26,28 +26,6 @@
26#define EXTRACTOR_PLUGPATH_H 26#define EXTRACTOR_PLUGPATH_H
27 27
28/** 28/**
29 * Function to call on paths.
30 *
31 * @param cls closure
32 * @param path a directory path
33 */
34typedef void (*EXTRACTOR_PathProcessor) (void *cls,
35 const char *path);
36
37
38/**
39 * Iterate over all paths where we expect to find GNU libextractor
40 * plugins.
41 *
42 * @param pp function to call for each path
43 * @param pp_cls cls argument for pp.
44 */
45void
46EXTRACTOR_get_installation_paths_ (EXTRACTOR_PathProcessor pp,
47 void *pp_cls);
48
49
50/**
51 * Given a short name of a library (i.e. "mime"), find 29 * Given a short name of a library (i.e. "mime"), find
52 * the full path of the respective plugin. 30 * the full path of the respective plugin.
53 */ 31 */