taskmldonkey, a multi-networks file-sharing client - Tasks: task #5324, filetype recognition with libmagic

 
 

You are not allowed to post comments on this tracker with your current authentication level.

task #5324: filetype recognition with libmagic

Submitter:  Joakim Verona <jave>
Submitted:  Wed 15 Mar 2006 08:55:23 PM UTC
   
 
Category:  None Priority:  1 - Later
Status:  None Assigned to:  None
Open/Closed:  Closed Should Start On:  Wed 15 Mar 2006 12:00:00 AM UTC
Should be Finished on:  Wed 15 Mar 2006 12:00:00 AM UTC

Thu 16 Mar 2006 10:17:40 PM UTC, comment #5: 

Release version of the patch, GUI stuff has to be implemented.
libmagic, part of GNU file (http://directory.fsf.org/file.html)
is now an optional dependency of MLDonkey.

new configure option: --disable-magic
new debug command: debug_dir <dir>

to get the filetype computed by libmagic use

Magic.M.magic_fileinfo file

this function returns a string, if libmagic is not used it returns "not implemented"

spiralvoice <spiralvoice>
Group administrator
Thu 16 Mar 2006 12:11:35 PM UTC, comment #4: 

For later usage: libmagic requires (among other stuff) GNU regex
for compiling on MinGW, here is how to do it:
http://www.openldap.org/faq/data/cache/302.html#2
ftp://ftp.gnu.org/gnu/regex

        $ ./configure --prefix=/mingw i686-pc-mingw32
        $ make subdirs= (ignore the error message)
        $ ar ru libregex.a regex.o
        $ cp regex.h /mingw/include
        $ cp libregex.a /mingw/lib

spiralvoice <spiralvoice>
Group administrator
Thu 16 Mar 2006 08:42:02 AM UTC, comment #3: 

The mime type given by libmagic(as seen by "file -i filename") could
be compared with the file extensions to mime-type mapping given by
mailcap, which usually resides in /etc/mime-types.

This file is unfortunately not consistent with the one libmagic
handles. rar files arent identified by mailcap, but they are by libmagic.

Joakim Verona <jave>
Group Member
Wed 15 Mar 2006 10:48:43 PM UTC, comment #2: 

Attached a dirty hack for MLDonkey, no configure checking atm.
But libmagic function should be usable from inside MLDonkey now.

spiralvoice <spiralvoice>
Group administrator
Wed 15 Mar 2006 08:58:21 PM UTC, comment #1: 

heres how to perform the test:

- make a magic.i file like this:
%module ocamlmagic
%{
 /* Includes the header in the wrapper code */
 #include "/usr/include/magic.h"
%}

/* Parse the header file to generate wrappers */
%include "/usr/include/magic.h"

- compile it like so:
swig -ocaml magic.i

we get ocaml interface files and a c wrapper.
- guess it must all be compiled and linked...

swig -ocaml -co swig.mli
swig -ocaml -co swig.ml
ocamlc -c swig.mli
ocamlc -c swig.ml
ocamlc -c -ccopt "-I/usr/include/" magic_wrap.c
ocamlc -c ocamlmagic.mli
ocamlc -c ocamlmagic.ml


- making custom toplevel
ocamlmktop -cclib -lmagic -cclib -lz   -custom magic_wrap.o swig.cmo ocamlmagic.cmo -o magic_top
ticky to get the linking right

- calling the funs
 (maybe not necessary)

./magic_top
#load "ocamlmagic.cmo";;
open Swig;;
open Ocamlmagic;;
let magiccookie = _magic_open  (C_int 0);;(just opens the lib)                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                   
_magic_load (C_list [magiccookie; (C_int 0)]);; ( returns 0 on ok)                                                                                                                                                                                                               
let fileinfo= _magic_file (C_list [magiccookie; (C_string "/tmp/142328-5.pdf")]);;                                                                                                                                                                                                 
( returns val fileinfo : Ocamlmagic.c_obj = C_string "PDF document, version 1.2" )                                                                                                                                                                                               
_magic_close magiccookie;; (close the lib)


Joakim Verona <jave>
Group Member
Wed 15 Mar 2006 08:55:23 PM UTC, original submission:  

It would be desirable to know the real filetype of a downloading file as soon as possible. The filetype given by libmagic can then be compared with the file extension. If they differ, say a "rar" is reaaly an "avi", the file is probably a fake.

Libmagic, which is used in the unix "file" command can be used for this.

There didnt seem to be any mainatined libmagic wrappers for ocaml, so I tried generating them with swig. It worked fairly well.

See attached file with the experiment.

This should of course be a configure-time option.


Joakim Verona <jave>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #3566:  magic.patch added by spiralvoice (76KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

CC list is empty

 

There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

 

Follow 4 latest changes.

Date Changed by Updated Field Previous Value => Replaced by
2006-03-16 spiralvoice Reassign ItemFrom group mldonkey, a multi-networks file-sharing client, task tracker To group mldonkey, a multi-networks file-sharing client, patch tracker
2006-03-16 spiralvoice Attached File- Added magic.patch, #454
2006-03-16 spiralvoice Attached File#453 Removed
2006-03-15 spiralvoice Attached File- Added magic.patch, #453

Back to the top

Powered by Savane 3.13-758e.
Corresponding source code