application/pwd.c

changeset 49
2f71f4ee247a
parent 6
09ac07345656
equal deleted inserted replaced
48:ae61523bce20 49:2f71f4ee247a
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <string.h> 31 #include <string.h>
32 32
33 #include "pwd.h" 33 #include "pwd.h"
34 34
35 #include <cx/buffer.h>
36 #include <cx/utils.h> 35 #include <cx/utils.h>
37 #include <cx/hash_map.h> 36 #include <cx/hash_map.h>
38 37
39 #ifdef _WIN32 38 #ifdef _WIN32
40 #include <winsock.h> 39 #include <winsock.h>
139 return 0; 138 return 0;
140 } 139 }
141 140
142 char *id = NULL; 141 char *id = NULL;
143 CxList *locations = cxLinkedListCreateSimple(CX_STORE_POINTERS); 142 CxList *locations = cxLinkedListCreateSimple(CX_STORE_POINTERS);
144 locations->simple_destructor = free; 143 cxDefineDestructor(locations, free);
145 144
146 // get id (required) 145 // get id (required)
147 int ret = 0; 146 int ret = 0;
148 if(readval(in, &id, FALSE)) { 147 if(readval(in, &id, FALSE)) {
149 ret = 1;
150 // get locations 148 // get locations
151 char *location = NULL; 149 char *location = NULL;
152 while((ret = readval(in, &location, TRUE)) == 1) { 150 while((ret = readval(in, &location, TRUE)) == 1) {
153 if(!location) { 151 if(!location) {
154 break; 152 break;
173 // only type 0 supported yet 171 // only type 0 supported yet
174 return 0; 172 return 0;
175 } 173 }
176 174
177 char *id = NULL; 175 char *id = NULL;
178 char *location = NULL;
179 char *user = NULL; 176 char *user = NULL;
180 char *password = NULL; 177 char *password = NULL;
181 178
182 int ret = 0; 179 int ret = 0;
183 if(readval(in, &id, FALSE)) { 180 if(readval(in, &id, FALSE)) {
188 } 185 }
189 } 186 }
190 } 187 }
191 188
192 if(id) free(id); 189 if(id) free(id);
193 if(location) free(location);
194 if(user) free(user); 190 if(user) free(user);
195 if(password) free(password); 191 if(password) free(password);
196 192
197 return ret; 193 return ret;
198 } 194 }
199 195
200 static int remove_list_entries(PwdStore *s, const char *id) { 196 static void remove_list_entries(PwdStore *s, const char *id) {
201 int ret = 0; 197 CxIterator i = cxListMutIterator(s->locations);
202
203 CxList *loc_entry = NULL;
204 CxList *noloc_entry = NULL;
205
206 CxMutIterator i = cxListMutIterator(s->locations);
207 cx_foreach(PwdIndexEntry*, ie, i) { 198 cx_foreach(PwdIndexEntry*, ie, i) {
208 if(!strcmp(ie->id, id)) { 199 if(!strcmp(ie->id, id)) {
209 cxIteratorFlagRemoval(i); 200 cxIteratorFlagRemoval(i);
210 // TODO: break loop 201 cxIteratorNext(i);
202 break;
211 } 203 }
212 } 204 }
213 i = cxListMutIterator(s->noloc); 205 i = cxListMutIterator(s->noloc);
214 cx_foreach(PwdIndexEntry*, ie, i) { 206 cx_foreach(PwdIndexEntry*, ie, i) {
215 if(!strcmp(ie->id, id)) { 207 if(!strcmp(ie->id, id)) {
216 cxIteratorFlagRemoval(i); 208 cxIteratorFlagRemoval(i);
217 // TODO: break loop 209 cxIteratorNext(i);
218 } 210 break;
219 } 211 }
220 212 }
221 return ret;
222 } 213 }
223 214
224 void pwdstore_remove_entry(PwdStore *s, const char *id) { 215 void pwdstore_remove_entry(PwdStore *s, const char *id) {
225 while(remove_list_entries(s, id)) {} 216 remove_list_entries(s, id);
226 217
227 CxHashKey key = cx_hash_key_str(id); 218 CxHashKey key = cx_hash_key_str(id);
228 PwdIndexEntry *i = cxMapRemoveAndGet(s->index, key); 219 PwdIndexEntry *i = cxMapRemoveAndGet(s->index, key);
229 PwdEntry *e = cxMapRemoveAndGet(s->ids, key); 220 PwdEntry *e = cxMapRemoveAndGet(s->ids, key);
230 221
329 if(e->password) free(e->password); 320 if(e->password) free(e->password);
330 free(e); 321 free(e);
331 } 322 }
332 323
333 void pwdstore_free(PwdStore* p) { 324 void pwdstore_free(PwdStore* p) {
334 p->ids->simple_destructor = (cx_destructor_func)pwdstore_free_entry; 325 cxDefineDestructor(p->ids, pwdstore_free_entry);
335 cxMapDestroy(p->ids); 326 cxMapDestroy(p->ids);
336 327
337 cxListDestroy(p->locations); 328 cxListDestroy(p->locations);
338 329
339 if(p->content) { 330 if(p->content) {

mercurial