Mercurial > sci
comparison scid/scid.c @ 44:576f4b1ec79f
scid: implement API authentication
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 11 Aug 2022 21:24:07 +0200 |
parents | 1d0ddf9e6efd |
children | 85c59fbf1407 |
comparison
equal
deleted
inserted
replaced
43:6854efe15210 | 44:576f4b1ec79f |
---|---|
26 | 26 |
27 struct scid scid = { | 27 struct scid scid = { |
28 .dbpath = VARDIR "/db/sci/sci.db" | 28 .dbpath = VARDIR "/db/sci/sci.db" |
29 }; | 29 }; |
30 | 30 |
31 void | 31 static void |
32 scid_init(void) | 32 init_misc(void) |
33 { | 33 { |
34 log_open("scid: version " VERSION); | 34 log_open("scid: version " VERSION); |
35 log_info("scid: opening database %s", scid.dbpath); | 35 log_info("scid: opening database %s", scid.dbpath); |
36 | 36 |
37 theme_open(scid.themedir); | |
38 } | |
39 | |
40 static void | |
41 init_database(void) | |
42 { | |
37 if (db_open(scid.dbpath) < 0) | 43 if (db_open(scid.dbpath) < 0) |
38 log_die("scid: abort: unable to open database"); | 44 log_die("scid: unable to open database"); |
39 | 45 |
40 theme_open(scid.themedir); | 46 /* Retrieve or create the API key if not existing. */ |
47 switch (db_key_get(scid.apikey, sizeof (scid.apikey))) { | |
48 case 0: | |
49 /* Not found, create immediately. */ | |
50 if (db_key_init(scid.apikey, sizeof (scid.apikey)) < 0) | |
51 log_die("scid: unable to insert key"); | |
52 | |
53 break; | |
54 case -1: | |
55 log_die("scid: unable to retrieve API key in database"); | |
56 break; | |
57 default: | |
58 /* We already fetched it. */ | |
59 break; | |
60 } | |
61 } | |
62 | |
63 void | |
64 scid_init(void) | |
65 { | |
66 init_misc(); | |
67 init_database(); | |
41 } | 68 } |
42 | 69 |
43 void | 70 void |
44 scid_finish(void) | 71 scid_finish(void) |
45 { | 72 { |