/builds/xfbs/passgen/src/env.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "passgen/pattern/env.h" |
2 | | #include "passgen/util/utf8.h" |
3 | | #include "passgen/wordlist.h" |
4 | | #include <stdlib.h> |
5 | | #include <string.h> |
6 | | |
7 | 43 | void passgen_env_init(passgen_env *env, passgen_random *random) { |
8 | 43 | env->depth_limit = 1024; |
9 | 43 | env->random = random; |
10 | 43 | passgen_hashmap_init(&env->wordlists, &passgen_hashmap_context_utf8); |
11 | 43 | passgen_hashmap_init(&env->presets, &passgen_hashmap_context_utf8); |
12 | 43 | } |
13 | | |
14 | 0 | static int wordlist_entry_free(void *user, passgen_hashmap_entry *entry) { |
15 | 0 | (void) user; |
16 | 0 | free((void *) entry->key); |
17 | 0 | passgen_wordlist_free(entry->value); |
18 | 0 | free(entry->value); |
19 | 0 | return 0; |
20 | 0 | } |
21 | | |
22 | 5 | void passgen_env_free(passgen_env *env) { |
23 | 5 | if(env->random) { |
24 | 0 | passgen_random_free(env->random); |
25 | 0 | } |
26 | 5 | |
27 | 5 | passgen_hashmap_foreach(&env->wordlists, NULL, wordlist_entry_free); |
28 | 5 | passgen_hashmap_free(&env->wordlists); |
29 | 5 | passgen_hashmap_free(&env->presets); |
30 | 5 | } |
31 | | |
32 | | int passgen_env_wordlist_add( |
33 | | passgen_env *env, |
34 | | char *name, |
35 | | FILE *file, |
36 | 0 | size_t markov_length) { |
37 | 0 | passgen_wordlist *wordlist = malloc(sizeof(passgen_wordlist)); |
38 | 0 | passgen_hashmap_insert(&env->wordlists, name, wordlist); |
39 | 0 | passgen_wordlist_init(wordlist, file, markov_length); |
40 | 0 |
|
41 | 0 | return 0; |
42 | 0 | } |
43 | | |
44 | 0 | int passgen_env_config(passgen_env env, FILE *file) { |
45 | 0 | (void) env; |
46 | 0 | (void) file; |
47 | 0 | // TODO: implement |
48 | 0 | return 1; |
49 | 0 | } |