aboutsummaryrefslogtreecommitdiff
path: root/src/main/extractor_ipc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/extractor_ipc.c')
-rw-r--r--src/main/extractor_ipc.c106
1 files changed, 41 insertions, 65 deletions
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 }