C · 2358 bytes Raw Blame History
1 /* Configuration file management and TOML parsing */
2
3 #ifndef CONFIG_H
4 #define CONFIG_H
5
6 #include "gitswitch.h"
7
8 /* Configuration file format version */
9 #define CONFIG_FORMAT_VERSION "1.0"
10
11 /* Default configuration template */
12 extern const char *default_config_template;
13
14 /* Function prototypes */
15
16 /**
17 * Initialize configuration system
18 * - Locates configuration file
19 * - Creates default config if none exists
20 * - Validates configuration format
21 */
22 int config_init(gitswitch_ctx_t *ctx);
23
24 /**
25 * Load configuration from TOML file
26 * - Parses TOML configuration
27 * - Validates all required fields
28 * - Populates gitswitch_ctx_t structure
29 */
30 int config_load(gitswitch_ctx_t *ctx, const char *config_path);
31
32 /**
33 * Save configuration to TOML file
34 * - Creates backup of existing config
35 * - Writes updated configuration
36 * - Validates written file
37 */
38 int config_save(const gitswitch_ctx_t *ctx, const char *config_path);
39
40 /**
41 * Create default configuration file
42 */
43 int config_create_default(const char *config_path);
44
45 /**
46 * Validate configuration structure
47 * - Checks all required fields are present
48 * - Validates account data integrity
49 * - Verifies file paths exist and are accessible
50 */
51 int config_validate(const gitswitch_ctx_t *ctx);
52
53 /**
54 * Get configuration file path
55 * - Checks environment variables
56 * - Falls back to default location
57 * - Creates directories if needed
58 */
59 int config_get_path(char *path_buffer, size_t buffer_size);
60
61 /**
62 * Add new account to configuration
63 */
64 int config_add_account(gitswitch_ctx_t *ctx, const account_t *account);
65
66 /**
67 * Remove account from configuration
68 */
69 int config_remove_account(gitswitch_ctx_t *ctx, uint32_t account_id);
70
71 /**
72 * Update existing account in configuration
73 */
74 int config_update_account(gitswitch_ctx_t *ctx, const account_t *account);
75
76 /**
77 * Find account by ID or name/description
78 */
79 account_t *config_find_account(gitswitch_ctx_t *ctx, const char *identifier);
80
81 /**
82 * Parse git scope from string
83 */
84 git_scope_t config_parse_scope(const char *scope_str);
85
86 /**
87 * Convert git scope to string
88 */
89 const char *config_scope_to_string(git_scope_t scope);
90
91 /**
92 * Backup configuration file with timestamp
93 */
94 int config_backup(const char *config_path);
95
96 /**
97 * Migrate configuration from older format versions
98 */
99 int config_migrate(const char *config_path);
100
101 #endif /* CONFIG_H */