aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/mime_extractor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/mime_extractor.c')
-rw-r--r--src/plugins/mime_extractor.c83
1 files changed, 42 insertions, 41 deletions
diff --git a/src/plugins/mime_extractor.c b/src/plugins/mime_extractor.c
index b9fb3cf..cfcfab9 100644
--- a/src/plugins/mime_extractor.c
+++ b/src/plugins/mime_extractor.c
@@ -36,7 +36,7 @@ static magic_t magic;
36 * Path we used for loading magic data, NULL is used for 'default'. 36 * Path we used for loading magic data, NULL is used for 'default'.
37 */ 37 */
38static char *magic_path; 38static char *magic_path;
39 39
40 40
41/** 41/**
42 * Main entry method for the 'application/ogg' extraction plugin. The 42 * Main entry method for the 'application/ogg' extraction plugin. The
@@ -54,74 +54,75 @@ EXTRACTOR_mime_extract_method (struct EXTRACTOR_ExtractContext *ec)
54 const char *mime; 54 const char *mime;
55 55
56 ret = ec->read (ec->cls, 56 ret = ec->read (ec->cls,
57 &buf, 57 &buf,
58 16 * 1024); 58 16 * 1024);
59 if (-1 == ret) 59 if (-1 == ret)
60 return; 60 return;
61 if ( ( (NULL == magic_path) && 61 if ( ( (NULL == magic_path) &&
62 (NULL != ec->config) ) || 62 (NULL != ec->config) ) ||
63 ( (NULL != magic_path) && 63 ( (NULL != magic_path) &&
64 (NULL == ec->config) ) || 64 (NULL == ec->config) ) ||
65 ( (NULL != magic_path) && 65 ( (NULL != magic_path) &&
66 (NULL != ec->config) && 66 (NULL != ec->config) &&
67 (0 != strcmp (magic_path, 67 (0 != strcmp (magic_path,
68 ec->config) )) ) 68 ec->config) )) )
69 {
70 if (NULL != magic_path)
71 free (magic_path);
72 magic_close (magic);
73 magic = magic_open (MAGIC_MIME_TYPE);
74 if (0 != magic_load (magic, ec->config))
69 { 75 {
70 if (NULL != magic_path) 76 /* FIXME: report errors? */
71 free (magic_path);
72 magic_close (magic);
73 magic = magic_open (MAGIC_MIME_TYPE);
74 if (0 != magic_load (magic, ec->config))
75 {
76 /* FIXME: report errors? */
77 }
78 if (NULL != ec->config)
79 magic_path = strdup (ec->config);
80 else
81 magic_path = NULL;
82 } 77 }
78 if (NULL != ec->config)
79 magic_path = strdup (ec->config);
80 else
81 magic_path = NULL;
82 }
83 if (NULL == (mime = magic_buffer (magic, buf, ret))) 83 if (NULL == (mime = magic_buffer (magic, buf, ret)))
84 return; 84 return;
85 ec->proc (ec->cls, 85 ec->proc (ec->cls,
86 "mime", 86 "mime",
87 EXTRACTOR_METATYPE_MIMETYPE, 87 EXTRACTOR_METATYPE_MIMETYPE,
88 EXTRACTOR_METAFORMAT_UTF8, 88 EXTRACTOR_METAFORMAT_UTF8,
89 "text/plain", 89 "text/plain",
90 mime, 90 mime,
91 strlen (mime) + 1); 91 strlen (mime) + 1);
92} 92}
93 93
94 94
95/** 95/**
96 * Constructor for the library. Loads the magic file. 96 * Constructor for the library. Loads the magic file.
97 */ 97 */
98void __attribute__ ((constructor)) 98void __attribute__ ((constructor))
99mime_ltdl_init () 99mime_ltdl_init ()
100{ 100{
101 magic = magic_open (MAGIC_MIME_TYPE); 101 magic = magic_open (MAGIC_MIME_TYPE);
102 if (0 != magic_load (magic, magic_path)) 102 if (0 != magic_load (magic, magic_path))
103 { 103 {
104 /* FIXME: how to deal with errors? */ 104 /* FIXME: how to deal with errors? */
105 } 105 }
106} 106}
107 107
108 108
109/** 109/**
110 * Destructor for the library, cleans up. 110 * Destructor for the library, cleans up.
111 */ 111 */
112void __attribute__ ((destructor)) 112void __attribute__ ((destructor))
113mime_ltdl_fini () 113mime_ltdl_fini ()
114{ 114{
115 if (NULL != magic) 115 if (NULL != magic)
116 { 116 {
117 magic_close (magic); 117 magic_close (magic);
118 magic = NULL; 118 magic = NULL;
119 } 119 }
120 if (NULL != magic_path) 120 if (NULL != magic_path)
121 { 121 {
122 free (magic_path); 122 free (magic_path);
123 magic_path = NULL; 123 magic_path = NULL;
124 } 124 }
125} 125}
126 126
127
127/* end of mime_extractor.c */ 128/* end of mime_extractor.c */