~gnaservicesinc/vanquita/trunk

« back to all changes in this revision

Viewing changes to src/vaq_magic.c

  • Committer: GNAServicesInc
  • Date: 2014-01-13 23:29:31 UTC
  • Revision ID: andrew@gnaservicesinc.com-20140113232931-09mmd3502b3xxpk0
Initial Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-  */
 
2
/********************************************************************************* 
 
3
 *     COPYRIGHT NOTICE:
 
4
 *     Copyright © 2014  Andrew Smith (GNA SERVICES INC)<Andrew@GNAServicesInc.com>
 
5
 *     All Rights Reserved.
 
6
 *
 
7
 *   This file, vaq_magic.c, is part of Vaquita.
 
8
 *
 
9
 *   Vaquita is free software: you can redistribute it and/or modify
 
10
 *   it under the terms of the GNU General Public License as published by
 
11
 *   the Free Software Foundation, either version 3 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *   Vaquita is distributed in the hope that it will be useful,
 
15
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *   GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with tpad.  If not, see <http://www.gnu.org/licenses/>.
 
21
 ********************************************************************************/
 
22
#include "vaq_head.h"
 
23
#include <magic.h>
 
24
gint check_magic(gchar* file) {
 
25
                gint ret =0;
 
26
                gchar *actual_file = (gchar*) file;
 
27
                const gchar *magic_full;
 
28
                magic_t magic_cookie;
 
29
                magic_cookie = magic_open(MAGIC_MIME); 
 
30
        if (magic_cookie == NULL) {
 
31
 
 
32
                return(2);
 
33
                    }
 
34
        if (magic_load(magic_cookie, NULL) != 0) {
 
35
                magic_close(magic_cookie);
 
36
                return(3);
 
37
            }
 
38
        magic_full = magic_file(magic_cookie, actual_file);
 
39
        gchar* magic_string= (gchar*) magic_full;
 
40
 
 
41
        if(vaq_magic_test(magic_string,"audio") == 0) ret =1;
 
42
        else ret =0;
 
43
        return(ret);
 
44
 
 
45
 
 
46
        return(1);
 
47
}
 
48
        
 
49
gint vaq_magic_test (gchar file_mime_string[], gchar check_mime_string[]){
 
50
 
 
51
        unsigned int slen=strlen(check_mime_string);
 
52
        gchar beg_string[slen];
 
53
        strncpy ( beg_string, file_mime_string, (int)slen );
 
54
        if(strncmp(beg_string,check_mime_string,slen) == 0) return(0);
 
55
        else return(1);
 
56
 
 
57
        return(1);
 
58
 
 
59
}
 
 
b'\\ No newline at end of file'