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; |
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) { |