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

Annotation of /imapfilter/destroy.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Fri Feb 13 12:17:15 2004 UTC (20 years, 1 month ago) by lefcha
Branch: MAIN
Changes since 1.4: +43 -43 lines
File MIME type: text/plain
Stylistic changes.

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.5 extern account_t *curacct;
14     extern filter_t *curfltr;
15 lefcha 1.2
16 lefcha 1.1
17 lefcha 1.5 void destroy_mboxgrps(mboxgrp_t * g);
18     void destroy_mboxes(mbox_t * m);
19     void destroy_accounts(account_t * a);
20     void destroy_filters(filter_t * f);
21     void destroy_masks(mask_t * k);
22 lefcha 1.3
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.5 curacct = NULL;
33 lefcha 1.1 destroy_filters(filters);
34     filters = NULL;
35 lefcha 1.5 curfltr = 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 lefcha 1.5 destroy_mboxgrps(mboxgrp_t * g)
58 lefcha 1.1 {
59 lefcha 1.5 if (g == NULL)
60 lefcha 1.1 return;
61    
62 lefcha 1.5 if (g->left != NULL) {
63     destroy_mboxgrps(g->left);
64     g->left = NULL;
65 lefcha 1.1 }
66 lefcha 1.5 if (g->right != NULL) {
67     destroy_mboxgrps(g->right);
68     g->right = NULL;
69 lefcha 1.1 }
70 lefcha 1.5 debug("deleting folder: '%s'\n", g->key);
71 lefcha 1.1
72 lefcha 1.5 xfree(g);
73 lefcha 1.1 }
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 lefcha 1.5 destroy_mboxes(mbox_t * m)
82 lefcha 1.1 {
83     mbox_t *p, *t;
84    
85 lefcha 1.5 for (p = m; p != NULL; p = t) {
86 lefcha 1.1 t = p->next;
87 lefcha 1.5 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 lefcha 1.5 destroy_accounts(account_t * a)
99 lefcha 1.1 {
100     account_t *p, *t;
101    
102 lefcha 1.5 for (p = a; p != NULL; p = t) {
103 lefcha 1.1 t = p->next;
104 lefcha 1.5 debug("deleting account: '%s'\n", p->key);
105     destroy_mboxes(p->mboxes);
106     sfree(p->pass);
107 lefcha 1.1 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 lefcha 1.5 destroy_filters(filter_t * f)
117 lefcha 1.1 {
118 lefcha 1.5 if (f == NULL)
119 lefcha 1.1 return;
120    
121 lefcha 1.5 if (f->left != NULL) {
122     destroy_filters(f->left);
123     f->left = NULL;
124     }
125     if (f->right != NULL) {
126     destroy_filters(f->right);
127     f->right = NULL;
128     }
129     debug("deleting filter: '%s'\n", f->key);
130     destroy_masks(f->masks);
131     xfree(f);
132 lefcha 1.1 }
133    
134    
135     /*
136     * Go through the masks' linked list and free the allocated memory of each
137     * node.
138     */
139     void
140 lefcha 1.5 destroy_masks(mask_t * k)
141 lefcha 1.1 {
142     mask_t *p, *t;
143    
144 lefcha 1.5 for (p = k; p != NULL; p = t) {
145 lefcha 1.1 t = p->next;
146 lefcha 1.5 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