~vcs-imports/clamav/main-old

« back to all changes in this revision

Viewing changes to libclamav/unrar/unrarfilter.c

  • Committer: nervoso
  • Date: 2006-05-21 15:16:39 UTC
  • Revision ID: Arch-1:clamav@arch.ubuntu.com%clamav--MAIN--0--patch-1959
repository moved to cvs.clamav.net

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Extract RAR archives
3
 
 *
4
 
 *  Copyright (C) 2005 trog@uncon.org
5
 
 *
6
 
 *  This code is based on the work of Alexander L. Roshal
7
 
 *
8
 
 *  This program is free software; you can redistribute it and/or modify
9
 
 *  it under the terms of the GNU General Public License as published by
10
 
 *  the Free Software Foundation; either version 2 of the License, or
11
 
 *  (at your option) any later version.
12
 
 *
13
 
 *  This program is distributed in the hope that it will be useful,
14
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 *  GNU General Public License for more details.
17
 
 *
18
 
 *  You should have received a copy of the GNU General Public License
19
 
 *  along with this program; if not, write to the Free Software
20
 
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21
 
 *  MA 02110-1301, USA.
22
 
 */
23
 
 
24
 
#include <unistd.h>
25
 
 
26
 
#include "unrar.h"
27
 
#include "unrarfilter.h"
28
 
 
29
 
void rar_filter_array_init(rar_filter_array_t *filter_a)
30
 
{
31
 
        filter_a->array = NULL;
32
 
        filter_a->num_items = 0;
33
 
}
34
 
 
35
 
void rar_filter_array_reset(rar_filter_array_t *filter_a)
36
 
{
37
 
        int i;
38
 
        
39
 
        if (!filter_a) {
40
 
                return;
41
 
        }
42
 
        for (i=0 ; i < filter_a->num_items ; i++) {
43
 
                rar_filter_delete(filter_a->array[i]);
44
 
        }
45
 
        if (filter_a->array) {
46
 
                free(filter_a->array);
47
 
        }
48
 
        filter_a->array = NULL;
49
 
        filter_a->num_items = 0;
50
 
}
51
 
 
52
 
int rar_filter_array_add(rar_filter_array_t *filter_a, int num)
53
 
{
54
 
        filter_a->num_items += num;
55
 
        filter_a->array = (struct UnpackFilter **) realloc(filter_a->array,
56
 
                        filter_a->num_items * sizeof(struct UnpackFilter **));
57
 
        if (filter_a->array == NULL) {
58
 
                filter_a->num_items=0;
59
 
                return FALSE;
60
 
        }
61
 
        filter_a->array[filter_a->num_items-1] = NULL;
62
 
        return TRUE;
63
 
}
64
 
 
65
 
struct UnpackFilter *rar_filter_new(void)
66
 
{
67
 
        struct UnpackFilter *filter;
68
 
        
69
 
        filter = (struct UnpackFilter *) malloc(sizeof(struct UnpackFilter));
70
 
        if (!filter) {
71
 
                return NULL;
72
 
        }
73
 
        filter->block_start = 0;
74
 
        filter->block_length = 0;
75
 
        filter->exec_count = 0;
76
 
        filter->next_window = 0;
77
 
        
78
 
        rar_cmd_array_init(&filter->prg.cmd);
79
 
        filter->prg.global_data = NULL;
80
 
        filter->prg.static_data = NULL;
81
 
        filter->prg.global_size = filter->prg.static_size = 0;
82
 
        filter->prg.filtered_data = NULL;
83
 
        filter->prg.filtered_data_size = 0;
84
 
        return filter;
85
 
}
86
 
 
87
 
void rar_filter_delete(struct UnpackFilter *filter)
88
 
{
89
 
        if (!filter) {
90
 
                return;
91
 
        }
92
 
        if (filter->prg.global_data) {
93
 
                free(filter->prg.global_data);
94
 
        }
95
 
        if (filter->prg.static_data) {
96
 
                free(filter->prg.static_data);
97
 
        }
98
 
        rar_cmd_array_reset(&filter->prg.cmd);
99
 
        free(filter);
100
 
}