gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r23106 - Extractor/src/plugins


From: gnunet
Subject: [GNUnet-SVN] r23106 - Extractor/src/plugins
Date: Sat, 4 Aug 2012 22:29:07 +0200

Author: grothoff
Date: 2012-08-04 22:29:07 +0200 (Sat, 04 Aug 2012)
New Revision: 23106

Modified:
   Extractor/src/plugins/
   Extractor/src/plugins/mime_extractor.c
Log:
-fix magic path code


Property changes on: Extractor/src/plugins
___________________________________________________________________
Modified: svn:ignore
   - test_ogg
thumbnailextractorqt.loT
Makefile.in
Makefile
.deps

   + test_mime
test_ogg
thumbnailextractorqt.loT
Makefile.in
Makefile
.deps


Modified: Extractor/src/plugins/mime_extractor.c
===================================================================
--- Extractor/src/plugins/mime_extractor.c      2012-08-04 20:17:03 UTC (rev 
23105)
+++ Extractor/src/plugins/mime_extractor.c      2012-08-04 20:29:07 UTC (rev 
23106)
@@ -28,9 +28,17 @@
  */
 static magic_t magic;
 
+/**
+ * Path we used for loading magic data, NULL is used for 'default'.
+ */
+static char *magic_path;
  
+
 /**
- * Main entry method for the 'application/ogg' extraction plugin.
+ * Main entry method for the 'application/ogg' extraction plugin.  The
+ * 'config' of the context can be used to specify an alternative magic
+ * path.  If config is not given, the default magic path will be
+ * used.  The default magic path is '/usr/share/misc/magic'.
  *
  * @param ec extraction context provided to the plugin
  */
@@ -46,6 +54,28 @@
                  16 * 1024);
   if (-1 == ret)
     return;
+  if ( ( (NULL == magic_path) &&
+        (NULL != ec->config) ) ||
+       ( (NULL != magic_path) &&
+        (NULL == ec->config) ) ||
+       ( (NULL != magic_path) &&
+        (NULL != ec->config) &&
+        (0 != strcmp (magic_path,
+                      ec->config) )) )
+    {
+      if (NULL != magic_path)
+       free (magic_path);              
+      magic_close (magic);
+      magic = magic_open (MAGIC_MIME_TYPE);
+      if (0 != magic_load (magic, ec->config))
+       {
+         /* FIXME: report errors? */
+       }
+      if (NULL != ec->config)
+       magic_path = strdup (ec->config);
+      else
+       magic_path = NULL;
+    }
   mime = magic_buffer (magic, buf, ret);
   if (NULL == mime)
     {
@@ -69,10 +99,10 @@
 mime_ltdl_init () 
 {
   magic = magic_open (MAGIC_MIME_TYPE);
-  /* FIXME: hard-wiring this path might not be the 
-     most sane thing to do; not sure what is a good
-     portable way to find the 'magic' file though... */
-  magic_load (magic, "/usr/share/misc/magic");
+  if (0 != magic_load (magic, magic_path))
+    {
+      /* FIXME: how to deal with errors? */
+    }
 }
 
 
@@ -84,6 +114,11 @@
 {
   magic_close (magic);
   magic = NULL;
+  if (NULL != magic_path)
+    {
+      free (magic_path);
+      magic_path = NULL;
+    }
 }
 
 /* end of mime_extractor.c */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]