static void parse_credential_file(const char *fn, struct credential *c, void (*match_cb)(struct credential *), void (*other_cb)(struct strbuf *)) { FILE *fh; struct strbuf line = STRBUF_INIT; struct credential entry = CREDENTIAL_INIT; fh = fopen(fn, "r"); if (!fh) { if (errno != ENOENT) die_errno("unable to open %s", fn); return; } while (strbuf_getline(&line, fh, '\n') != EOF) { credential_from_url(&entry, line.buf); if (entry.username && entry.password && credential_match(c, &entry)) { if (match_cb) { match_cb(&entry); break; } } else if (other_cb) other_cb(&line); } credential_clear(&entry); strbuf_release(&line); fclose(fh); }
static int cb_foreach_i(void* ptr, const void* key, size_t keylen, int (*match_cb)(const void* match, const void* key, size_t keylen, void*), void* data) { int result = 0; if(decode_pointer(&ptr) == INTERNAL_NODE) { struct critbit_node* node = (struct critbit_node*)ptr; result = cb_foreach_i(node->child[0], key, keylen, match_cb, data); if(!result) { result = cb_foreach_i(node->child[1], key, keylen, match_cb, data); } } else { /* reached an external node */ void* match; size_t len; from_external_node(ptr, &match, &len); if(len >= keylen && byte_diff(key, keylen, match) == 0) { return match_cb(match, key, keylen, data); } } return result; }