#include "cache.h" #include "credential.h" #include "string-list.h" #include "run-command.h" #include "url.h" #include "prompt.h" void credential_write(const struct credential *c, FILE *fp) { credential_write_item(fp, "protocol", c->protocol); credential_write_item(fp, "host", c->host); credential_write_item(fp, "path", c->path); credential_write_item(fp, "username", c->username); credential_write_item(fp, "password", c->password); } void credential_init(struct credential *c) { memset(c, 0, sizeof(*c)); c->helpers.strdup_strings = 1; } void credential_clear(struct credential *c) { free(c->protocol); free(c->host); free(c->path); free(c->username); free(c->password); string_list_clear(&c->helpers, 0); credential_init(c); } int credential_match(const struct credential *want, const struct credential *have) { #define CHECK(x) (!want->x || (have->x && !strcmp(want->x, have->x))) return CHECK(protocol) && CHECK(host) && CHECK(path) && CHECK(username); #undef CHECK } static void credential_write_item(FILE *fp, const char *key, const char *value) { if (!value) return; fprintf(fp, "%s=%s\n", key, value); }