| 1 | /* Account management and operations */ |
| 2 | |
| 3 | #ifndef ACCOUNTS_H |
| 4 | #define ACCOUNTS_H |
| 5 | |
| 6 | #include "gitswitch.h" |
| 7 | |
| 8 | /* Account validation result */ |
| 9 | typedef struct { |
| 10 | bool valid; |
| 11 | char error_message[512]; |
| 12 | char warnings[1024]; |
| 13 | } account_validation_t; |
| 14 | |
| 15 | /* Function prototypes */ |
| 16 | |
| 17 | /** |
| 18 | * Initialize accounts system |
| 19 | */ |
| 20 | int accounts_init(gitswitch_ctx_t *ctx); |
| 21 | |
| 22 | /** |
| 23 | * Switch to specified account |
| 24 | * - Validates account exists and is properly configured |
| 25 | * - Coordinates SSH and GPG switching |
| 26 | * - Updates git configuration |
| 27 | * - Verifies switch was successful |
| 28 | */ |
| 29 | int accounts_switch(gitswitch_ctx_t *ctx, const char *identifier); |
| 30 | |
| 31 | /** |
| 32 | * Add new account interactively |
| 33 | * - Prompts for account details |
| 34 | * - Validates input |
| 35 | * - Tests SSH/GPG configuration if provided |
| 36 | * - Saves to configuration |
| 37 | */ |
| 38 | int accounts_add_interactive(gitswitch_ctx_t *ctx); |
| 39 | |
| 40 | /** |
| 41 | * Remove account with confirmation |
| 42 | * - Shows account details |
| 43 | * - Prompts for confirmation |
| 44 | * - Cleans up associated SSH/GPG resources |
| 45 | * - Updates configuration |
| 46 | */ |
| 47 | int accounts_remove(gitswitch_ctx_t *ctx, const char *identifier); |
| 48 | |
| 49 | /** |
| 50 | * List all configured accounts |
| 51 | * - Shows account details in formatted table |
| 52 | * - Indicates current active account |
| 53 | * - Shows validation status for each account |
| 54 | */ |
| 55 | int accounts_list(const gitswitch_ctx_t *ctx); |
| 56 | |
| 57 | /** |
| 58 | * Show current account status |
| 59 | * - Displays currently active git configuration |
| 60 | * - Shows SSH keys loaded |
| 61 | * - Shows GPG signing configuration |
| 62 | * - Indicates scope (local/global) |
| 63 | */ |
| 64 | int accounts_show_status(const gitswitch_ctx_t *ctx); |
| 65 | |
| 66 | /** |
| 67 | * Validate account configuration |
| 68 | * - Checks required fields are present |
| 69 | * - Validates email format |
| 70 | * - Verifies SSH key file exists and has correct permissions |
| 71 | * - Validates GPG key exists and is usable |
| 72 | * - Tests connectivity if possible |
| 73 | */ |
| 74 | int accounts_validate(const account_t *account); |
| 75 | |
| 76 | /** |
| 77 | * Find account by various identifiers |
| 78 | * - Numeric ID (exact match) |
| 79 | * - Name (exact or partial match) |
| 80 | * - Email (exact match) |
| 81 | * - Description (partial match) |
| 82 | */ |
| 83 | account_t *accounts_find(const gitswitch_ctx_t *ctx, const char *identifier); |
| 84 | |
| 85 | /** |
| 86 | * Get next available account ID |
| 87 | */ |
| 88 | uint32_t accounts_get_next_id(const gitswitch_ctx_t *ctx); |
| 89 | |
| 90 | /** |
| 91 | * Clone account configuration (for editing) |
| 92 | */ |
| 93 | int accounts_clone(const account_t *src, account_t *dst); |
| 94 | |
| 95 | /** |
| 96 | * Compare two accounts for equality |
| 97 | */ |
| 98 | bool accounts_equal(const account_t *a, const account_t *b); |
| 99 | |
| 100 | /** |
| 101 | * Initialize account structure with defaults |
| 102 | */ |
| 103 | void accounts_init_struct(account_t *account); |
| 104 | |
| 105 | /** |
| 106 | * Clean up account resources |
| 107 | */ |
| 108 | void accounts_cleanup_struct(account_t *account); |
| 109 | |
| 110 | /** |
| 111 | * Run comprehensive health check on all accounts |
| 112 | * - Validates configuration |
| 113 | * - Tests SSH connectivity |
| 114 | * - Verifies GPG functionality |
| 115 | * - Reports issues and recommendations |
| 116 | */ |
| 117 | int accounts_health_check(const gitswitch_ctx_t *ctx); |
| 118 | |
| 119 | /** |
| 120 | * Clean up active session resources |
| 121 | * - Stops SSH agent if one was started |
| 122 | * - Restores original GNUPGHOME environment |
| 123 | * - Cleans up isolated GPG home if created |
| 124 | * Call this before program exit or when switching accounts |
| 125 | */ |
| 126 | void accounts_session_cleanup(void); |
| 127 | |
| 128 | /** |
| 129 | * Detect current account from SSH socket symlink |
| 130 | * - Reads the current.sock symlink in gitswitch-ssh directory |
| 131 | * - Parses account name from socket filename |
| 132 | * - Sets ctx->current_account if a match is found |
| 133 | * Call this after accounts are loaded from config |
| 134 | */ |
| 135 | int accounts_detect_current(gitswitch_ctx_t *ctx); |
| 136 | |
| 137 | #endif /* ACCOUNTS_H */ |