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

Contents of /imapfilter/destroy.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Fri Aug 1 13:30:04 2003 UTC (20 years, 8 months ago) by lefcha
Branch: MAIN
Changes since 1.1: +5 -0 lines
File MIME type: text/plain
When destroying data structures cur_acct and cur_fltr must be also reset.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26