* Implement a different way to delete a password from the cache.
[alpine.git] / pith / handle.c
blob1e7f4b6189856e3909fead3bc7a5881f4a0941a9
1 /*
2 * ========================================================================
3 * Copyright 2013-2022 Eduardo Chappa
4 * Copyright 2006-2007 University of Washington
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 #include "../pith/headers.h"
16 #include "../pith/handle.h"
17 #include "../pith/mailview.h"
20 HANDLE_S *
21 get_handle(HANDLE_S *handles, int key)
23 HANDLE_S *h;
25 if((h = handles) != NULL){
26 for( ; h ; h = h->next)
27 if(h->key == key)
28 return(h);
30 for(h = handles->prev ; h ; h = h->prev)
31 if(h->key == key)
32 return(h);
35 return(NULL);
39 void
40 init_handles(HANDLE_S **handlesp)
42 if(handlesp)
43 *handlesp = NULL;
45 (void) url_external_specific_handler(NULL, 0);
50 HANDLE_S *
51 new_handle(HANDLE_S **handlesp)
53 HANDLE_S *hp, *h = NULL;
55 if(handlesp){
56 h = (HANDLE_S *) fs_get(sizeof(HANDLE_S));
57 memset(h, 0, sizeof(HANDLE_S));
59 /* Put it in the list */
60 if((hp = *handlesp) != NULL){
61 while(hp->next)
62 hp = hp->next;
64 h->key = hp->key + 1;
65 hp->next = h;
66 h->prev = hp;
68 else{
69 /* Assumption #2,340: There are NO ZERO KEY HANDLES */
70 h->key = 1;
71 *handlesp = h;
75 return(h);
80 * Normally we ignore the is_used bit in HANDLE_S. However, if we are
81 * using the delete_quotes filter, we pay attention to it. All of the is_used
82 * bits are off by default, and the delete_quotes filter turns them on
83 * if it is including lines with those handles.
85 * This is a bit of a crock, since it depends heavily on the order of the
86 * filters. Notice that the charset_editorial filter, which comes after
87 * delete_quotes and adds a handle, has to explicitly set the is_used bit!
89 void
90 delete_unused_handles(HANDLE_S **handlesp)
92 HANDLE_S *h, *nexth;
94 if(handlesp && *handlesp && (*handlesp)->using_is_used){
95 for(h = *handlesp; h && h->prev; h = h->prev)
98 for(; h; h = nexth){
99 nexth = h->next;
100 if(h->is_used == 0){
101 if(h == *handlesp)
102 *handlesp = nexth;
104 free_handle(&h);
111 void
112 free_handle(HANDLE_S **h)
114 if(h){
115 if((*h)->next) /* clip from list */
116 (*h)->next->prev = (*h)->prev;
118 if((*h)->prev)
119 (*h)->prev->next = (*h)->next;
121 if((*h)->type == URL){ /* destroy malloc'd data */
122 if((*h)->h.url.path)
123 fs_give((void **) &(*h)->h.url.path);
125 if((*h)->h.url.tool)
126 fs_give((void **) &(*h)->h.url.tool);
128 if((*h)->h.url.name)
129 fs_give((void **) &(*h)->h.url.name);
132 if((*h)->type == imgData){ /* destroy malloc'd data */
133 if((*h)->h.img.src)
134 fs_give((void **) &(*h)->h.img.src);
136 if((*h)->h.img.alt)
137 fs_give((void **) &(*h)->h.img.alt);
139 if((*h)->h.url.tool)
140 fs_give((void **) &(*h)->h.url.tool);
143 free_handle_locations(&(*h)->loc);
145 fs_give((void **) h);
150 void
151 free_handles(HANDLE_S **handlesp)
153 HANDLE_S *h;
155 if(handlesp && *handlesp){
156 while((h = (*handlesp)->next) != NULL)
157 free_handle(&h);
159 while((h = (*handlesp)->prev) != NULL)
160 free_handle(&h);
162 free_handle(handlesp);
167 void
168 free_handle_locations(POSLIST_S **l)
170 if(*l){
171 free_handle_locations(&(*l)->next);
172 fs_give((void **) l);