/[imapfilter]/imapfilter/destroy.c
ViewVC logotype

Annotation of /imapfilter/destroy.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Mon Feb 9 17:34:56 2004 UTC (20 years, 1 month ago) by lefcha
Branch: MAIN
Changes since 1.3: +5 -15 lines
File MIME type: text/plain
Move DEBUG from compilation #define variable to runtime command line option.

1 lefcha 1.1 #include <stdio.h>
2    
3     #include "config.h"
4     #include "imapfilter.h"
5     #include "account.h"
6     #include "filter.h"
7    
8    
9     extern account_t *accounts;
10     extern mboxgrp_t *mboxgrps;
11     extern filter_t *filters;
12    
13 lefcha 1.2 extern account_t *cur_acct;
14     extern filter_t *cur_fltr;
15    
16 lefcha 1.1
17 lefcha 1.3 void destroy_mboxgrps(mboxgrp_t * node);
18     void destroy_mboxs(mbox_t * node);
19     void destroy_accounts(account_t * node);
20     void destroy_filters(filter_t * node);
21     void destroy_masks(mask_t * node);
22    
23    
24 lefcha 1.1 /*
25     * Free allocated memory of all data structures.
26     */
27     void
28     destroy_all(void)
29     {
30     destroy_accounts(accounts);
31     accounts = NULL;
32 lefcha 1.2 cur_acct = NULL;
33 lefcha 1.1 destroy_filters(filters);
34     filters = NULL;
35 lefcha 1.2 cur_fltr = NULL;
36 lefcha 1.1 destroy_mboxgrps(mboxgrps);
37     mboxgrps = NULL;
38     }
39    
40    
41     /*
42     * Free allocated memory of data structures that are not needed anymore.
43     */
44     void
45     destroy_unneeded(void)
46     {
47     destroy_mboxgrps(mboxgrps);
48     mboxgrps = NULL;
49     }
50    
51    
52     /*
53     * Go through the mailbox-group tree, and free the allocated memory of
54     * each node.
55     */
56     void
57     destroy_mboxgrps(mboxgrp_t * node)
58     {
59     if (node == NULL)
60     return;
61    
62     if (node->left != NULL) {
63     destroy_mboxgrps(node->left);
64     node->left = NULL;
65     }
66     if (node->right != NULL) {
67     destroy_mboxgrps(node->right);
68     node->right = NULL;
69     }
70 lefcha 1.4 debug("deleting FOLDER: '%s'\n", node->key);
71 lefcha 1.1
72     xfree(node);
73     }
74    
75    
76     /*
77     * Go through the mailbox linked list of the account and free the allocated
78     * memory of each node.
79     */
80     void
81     destroy_mboxs(mbox_t * node)
82     {
83     mbox_t *p, *t;
84    
85     for (p = node; p != NULL; p = t) {
86     t = p->next;
87 lefcha 1.4 debug("deleting MBOX: '%s'\n", p->name);
88 lefcha 1.1 xfree(p);
89     }
90     }
91    
92    
93     /*
94     * Go through the accounts' linked list and free the allocated memory of
95     * each node.
96     */
97     void
98     destroy_accounts(account_t * node)
99     {
100     account_t *p, *t;
101    
102     for (p = node; p != NULL; p = t) {
103     t = p->next;
104 lefcha 1.4 debug("deleting ACCOUNT: '%s'\n", p->key);
105 lefcha 1.1 destroy_mboxs(p->mboxes);
106     sfree(p->password);
107     xfree(p);
108     }
109     }
110    
111    
112     /*
113     * Go through the filters' tree and free the allocated memory of each node.
114     */
115     void
116     destroy_filters(filter_t * node)
117     {
118     if (node == NULL)
119     return;
120    
121     if (node->left != NULL) {
122     destroy_filters(node->left);
123     node->left = NULL;
124     }
125     if (node->right != NULL) {
126     destroy_filters(node->right);
127     node->right = NULL;
128     }
129 lefcha 1.4 debug("deleting FILTER: '%s'\n", node->key);
130 lefcha 1.1 destroy_masks(node->masks);
131     xfree(node);
132     }
133    
134    
135     /*
136     * Go through the masks' linked list and free the allocated memory of each
137     * node.
138     */
139     void
140     destroy_masks(mask_t * node)
141     {
142     mask_t *p, *t;
143    
144     for (p = node; p != NULL; p = t) {
145     t = p->next;
146 lefcha 1.4 debug("deleting MASK: '%s'\n", p->body);
147 lefcha 1.1 xfree(p);
148     }
149     }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26