* NTLM authentication support with the ntlm library, in Unix systems.
[alpine.git] / pith / handle.c
blobe95a342f6796c6d290a36f19d9c6a90786694633
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: handle.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2013-2017 Eduardo Chappa
8 * Copyright 2006-2007 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 #include "../pith/headers.h"
20 #include "../pith/handle.h"
21 #include "../pith/mailview.h"
24 HANDLE_S *
25 get_handle(HANDLE_S *handles, int key)
27 HANDLE_S *h;
29 if((h = handles) != NULL){
30 for( ; h ; h = h->next)
31 if(h->key == key)
32 return(h);
34 for(h = handles->prev ; h ; h = h->prev)
35 if(h->key == key)
36 return(h);
39 return(NULL);
43 void
44 init_handles(HANDLE_S **handlesp)
46 if(handlesp)
47 *handlesp = NULL;
49 (void) url_external_specific_handler(NULL, 0);
54 HANDLE_S *
55 new_handle(HANDLE_S **handlesp)
57 HANDLE_S *hp, *h = NULL;
59 if(handlesp){
60 h = (HANDLE_S *) fs_get(sizeof(HANDLE_S));
61 memset(h, 0, sizeof(HANDLE_S));
63 /* Put it in the list */
64 if((hp = *handlesp) != NULL){
65 while(hp->next)
66 hp = hp->next;
68 h->key = hp->key + 1;
69 hp->next = h;
70 h->prev = hp;
72 else{
73 /* Assumption #2,340: There are NO ZERO KEY HANDLES */
74 h->key = 1;
75 *handlesp = h;
79 return(h);
84 * Normally we ignore the is_used bit in HANDLE_S. However, if we are
85 * using the delete_quotes filter, we pay attention to it. All of the is_used
86 * bits are off by default, and the delete_quotes filter turns them on
87 * if it is including lines with those handles.
89 * This is a bit of a crock, since it depends heavily on the order of the
90 * filters. Notice that the charset_editorial filter, which comes after
91 * delete_quotes and adds a handle, has to explicitly set the is_used bit!
93 void
94 delete_unused_handles(HANDLE_S **handlesp)
96 HANDLE_S *h, *nexth;
98 if(handlesp && *handlesp && (*handlesp)->using_is_used){
99 for(h = *handlesp; h && h->prev; h = h->prev)
102 for(; h; h = nexth){
103 nexth = h->next;
104 if(h->is_used == 0){
105 if(h == *handlesp)
106 *handlesp = nexth;
108 free_handle(&h);
115 void
116 free_handle(HANDLE_S **h)
118 if(h){
119 if((*h)->next) /* clip from list */
120 (*h)->next->prev = (*h)->prev;
122 if((*h)->prev)
123 (*h)->prev->next = (*h)->next;
125 if((*h)->type == URL){ /* destroy malloc'd data */
126 if((*h)->h.url.path)
127 fs_give((void **) &(*h)->h.url.path);
129 if((*h)->h.url.tool)
130 fs_give((void **) &(*h)->h.url.tool);
132 if((*h)->h.url.name)
133 fs_give((void **) &(*h)->h.url.name);
136 free_handle_locations(&(*h)->loc);
138 fs_give((void **) h);
143 void
144 free_handles(HANDLE_S **handlesp)
146 HANDLE_S *h;
148 if(handlesp && *handlesp){
149 while((h = (*handlesp)->next) != NULL)
150 free_handle(&h);
152 while((h = (*handlesp)->prev) != NULL)
153 free_handle(&h);
155 free_handle(handlesp);
160 void
161 free_handle_locations(POSLIST_S **l)
163 if(*l){
164 free_handle_locations(&(*l)->next);
165 fs_give((void **) l);