libidav/pwdstore.c

branch
dav-2
changeset 893
38800d479cd4
parent 891
4d58cbcc9efa
equal deleted inserted replaced
892:02ad5db5ad4d 893:38800d479cd4
409 409
410 free(p); 410 free(p);
411 } 411 }
412 412
413 int pwdstore_has_id(PwdStore *s, const char *id) { 413 int pwdstore_has_id(PwdStore *s, const char *id) {
414 return cxMapGet(s->index, cx_hash_key_str(id)) ? 1 : 0; 414 return cxMapGet(s->index, id) ? 1 : 0;
415 } 415 }
416 416
417 PwdEntry* pwdstore_get(PwdStore *p, const char *id) { 417 PwdEntry* pwdstore_get(PwdStore *p, const char *id) {
418 PwdEntry *e = cxMapGet(p->ids, cx_hash_key_str(id)); 418 PwdEntry *e = cxMapGet(p->ids, id);
419 if(e && e->user && e->password) { 419 if(e && e->user && e->password) {
420 return e; 420 return e;
421 } else { 421 } else {
422 return NULL; 422 return NULL;
423 } 423 }
426 void pwdstore_put(PwdStore *p, const char *id, const char *username, const char *password) { 426 void pwdstore_put(PwdStore *p, const char *id, const char *username, const char *password) {
427 PwdEntry *entry = malloc(sizeof(PwdEntry)); 427 PwdEntry *entry = malloc(sizeof(PwdEntry));
428 entry->id = strdup(id); 428 entry->id = strdup(id);
429 entry->user = strdup(username); 429 entry->user = strdup(username);
430 entry->password = strdup(password); 430 entry->password = strdup(password);
431 cxMapPut(p->ids, cx_hash_key_str(id), entry); 431 cxMapPut(p->ids, id, entry);
432 } 432 }
433 433
434 void pwdstore_put_index(PwdStore *p, char *id, CxList *locations) { 434 void pwdstore_put_index(PwdStore *p, char *id, CxList *locations) {
435 PwdIndexEntry *e = cxMapGet(p->index, cx_hash_key_str(id)); 435 PwdIndexEntry *e = cxMapGet(p->index, id);
436 if(e) { 436 if(e) {
437 return; 437 return;
438 } 438 }
439 PwdIndexEntry *newentry = malloc(sizeof(PwdIndexEntry)); 439 PwdIndexEntry *newentry = malloc(sizeof(PwdIndexEntry));
440 newentry->id = id; 440 newentry->id = id;
443 cxListAdd(p->locations, newentry); 443 cxListAdd(p->locations, newentry);
444 } else { 444 } else {
445 newentry->locations = NULL; 445 newentry->locations = NULL;
446 cxListAdd(p->noloc, newentry); 446 cxListAdd(p->noloc, newentry);
447 } 447 }
448 cxMapPut(p->index, cx_hash_key_str(id), newentry); 448 cxMapPut(p->index, id, newentry);
449 } 449 }
450 450
451 void write_index_entry(CxBuffer *out, PwdIndexEntry *e) { 451 void write_index_entry(CxBuffer *out, PwdIndexEntry *e) {
452 uint32_t idlen = strlen(e->id); 452 uint32_t idlen = strlen(e->id);
453 uint32_t netidlen = htonl(idlen); 453 uint32_t netidlen = htonl(idlen);

mercurial