| 1 | /* gitswitch-c: Main header with common definitions and constants */ |
| 2 | |
| 3 | #ifndef GITSWITCH_H |
| 4 | #define GITSWITCH_H |
| 5 | |
| 6 | #include <stddef.h> |
| 7 | #include <stdbool.h> |
| 8 | #include <stdint.h> |
| 9 | |
| 10 | /* Version information - can be overridden at build time via -D flags */ |
| 11 | #ifndef GITSWITCH_VERSION |
| 12 | #define GITSWITCH_VERSION "1.1.7" |
| 13 | #endif |
| 14 | #ifndef GITSWITCH_COMMIT |
| 15 | #define GITSWITCH_COMMIT "unknown" |
| 16 | #endif |
| 17 | #define GITSWITCH_NAME "gitswitch-c" |
| 18 | |
| 19 | /* Configuration constants */ |
| 20 | #define MAX_PATH_LEN 4096 |
| 21 | #define MAX_NAME_LEN 256 |
| 22 | #define MAX_EMAIL_LEN 320 /* RFC 5321 limit */ |
| 23 | #define MAX_DESC_LEN 512 |
| 24 | #define MAX_KEY_ID_LEN 64 |
| 25 | #define MAX_ACCOUNTS 64 |
| 26 | |
| 27 | /* Default configuration paths */ |
| 28 | #define DEFAULT_CONFIG_DIR ".config/gitswitch" |
| 29 | #define DEFAULT_CONFIG_FILE "accounts.toml" |
| 30 | #define DEFAULT_SSH_DIR ".ssh" |
| 31 | #define DEFAULT_GPG_DIR ".gnupg" |
| 32 | |
| 33 | /* Exit codes */ |
| 34 | #define EXIT_SUCCESS 0 |
| 35 | #define EXIT_FAILURE 1 |
| 36 | #define EXIT_CONFIG_ERROR 2 |
| 37 | #define EXIT_VALIDATION_ERROR 3 |
| 38 | #define EXIT_SSH_ERROR 4 |
| 39 | #define EXIT_GPG_ERROR 5 |
| 40 | |
| 41 | /* Git scopes */ |
| 42 | typedef enum { |
| 43 | GIT_SCOPE_LOCAL, |
| 44 | GIT_SCOPE_GLOBAL, |
| 45 | GIT_SCOPE_SYSTEM |
| 46 | } git_scope_t; |
| 47 | |
| 48 | /* Account structure */ |
| 49 | typedef struct { |
| 50 | uint32_t id; |
| 51 | char name[MAX_NAME_LEN]; |
| 52 | char email[MAX_EMAIL_LEN]; |
| 53 | char description[MAX_DESC_LEN]; |
| 54 | git_scope_t preferred_scope; |
| 55 | |
| 56 | /* SSH configuration */ |
| 57 | bool ssh_enabled; |
| 58 | char ssh_key_path[MAX_PATH_LEN]; |
| 59 | char ssh_host_alias[MAX_NAME_LEN]; |
| 60 | |
| 61 | /* GPG configuration */ |
| 62 | bool gpg_enabled; |
| 63 | bool gpg_signing_enabled; |
| 64 | char gpg_key_id[MAX_KEY_ID_LEN]; |
| 65 | |
| 66 | } account_t; |
| 67 | |
| 68 | /* Global configuration */ |
| 69 | typedef struct { |
| 70 | git_scope_t default_scope; |
| 71 | char config_path[MAX_PATH_LEN]; |
| 72 | bool verbose; |
| 73 | bool dry_run; |
| 74 | bool color_output; |
| 75 | } config_t; |
| 76 | |
| 77 | /* Application context */ |
| 78 | typedef struct { |
| 79 | config_t config; |
| 80 | account_t accounts[MAX_ACCOUNTS]; |
| 81 | size_t account_count; |
| 82 | account_t *current_account; |
| 83 | } gitswitch_ctx_t; |
| 84 | |
| 85 | /* Function prototypes */ |
| 86 | int gitswitch_init(gitswitch_ctx_t *ctx); |
| 87 | void gitswitch_cleanup(gitswitch_ctx_t *ctx); |
| 88 | |
| 89 | #endif /* GITSWITCH_H */ |