Check for errors. Store an updated addressbook.
This commit is contained in:
parent
4a03096436
commit
08117318a8
34
src/main.c
34
src/main.c
@ -1,8 +1,8 @@
|
|||||||
#include <bits/endian.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <arpa/inet.h>
|
|
||||||
|
|
||||||
#include "addrbook.h"
|
#include "addrbook.h"
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
@ -47,12 +47,12 @@ int main(int argc, const char **argv) {
|
|||||||
struct options opts = {0};
|
struct options opts = {0};
|
||||||
|
|
||||||
addrbook_t ab = {0};
|
addrbook_t ab = {0};
|
||||||
|
bool is_ab_changed = false;
|
||||||
net_t n = {0};
|
net_t n = {0};
|
||||||
crypt_session_t s = {0};
|
crypt_session_t s = {0};
|
||||||
crypt_key_t ok = {0}, rk = {0};
|
crypt_key_t ok = {0}, rk = {0};
|
||||||
|
|
||||||
result = parse_argv(argc, argv, &opts);
|
switch (parse_argv(argc, argv, &opts)) {
|
||||||
switch (result) {
|
|
||||||
case -1: usage(); return 1;
|
case -1: usage(); return 1;
|
||||||
case -2: version(); return 0;
|
case -2: version(); return 0;
|
||||||
case -3: usage(); return 0;
|
case -3: usage(); return 0;
|
||||||
@ -88,6 +88,7 @@ int main(int argc, const char **argv) {
|
|||||||
FILE *skey_file = fopen("tat_own_sec_key", "r");
|
FILE *skey_file = fopen("tat_own_sec_key", "r");
|
||||||
if (pkey_file == NULL || skey_file == NULL) {
|
if (pkey_file == NULL || skey_file == NULL) {
|
||||||
if ((result = crypt_key_gen(&ok)) == -1) {
|
if ((result = crypt_key_gen(&ok)) == -1) {
|
||||||
|
fprintf(stderr, "Failed to generate the keys.\n");
|
||||||
result = 1;
|
result = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -100,7 +101,15 @@ int main(int argc, const char **argv) {
|
|||||||
pkey_file = fopen("tat_own_pub_key", "w+");
|
pkey_file = fopen("tat_own_pub_key", "w+");
|
||||||
skey_file = fopen("tat_own_sec_key", "w+");
|
skey_file = fopen("tat_own_sec_key", "w+");
|
||||||
|
|
||||||
crypt_store_key(&ok, pkey_file, skey_file);
|
if (pkey_file == NULL || skey_file == NULL) {
|
||||||
|
fprintf(stderr, "Cannot open tat_own_*_key files to write: %s\n", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crypt_store_key(&ok, pkey_file, skey_file) == -1) {
|
||||||
|
fprintf(stderr, "Failed to save the keys.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
fclose(pkey_file);
|
fclose(pkey_file);
|
||||||
fclose(skey_file);
|
fclose(skey_file);
|
||||||
@ -108,7 +117,7 @@ int main(int argc, const char **argv) {
|
|||||||
printf("The new cryptographical keys was written.\n");
|
printf("The new cryptographical keys was written.\n");
|
||||||
} else {
|
} else {
|
||||||
if (crypt_load_key(&ok, pkey_file, skey_file) == -1) {
|
if (crypt_load_key(&ok, pkey_file, skey_file) == -1) {
|
||||||
fprintf(stderr, "Cannot load the keys.");
|
fprintf(stderr, "Cannot load the keys.\n");
|
||||||
result = 1;
|
result = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -161,6 +170,15 @@ int main(int argc, const char **argv) {
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
||||||
|
if (is_ab_changed) {
|
||||||
|
addrbook_file = fopen((opts.addressbook_path == NULL) ? "addressbook" : opts.addressbook_path, "w+");
|
||||||
|
if (addrbook_file != NULL) {
|
||||||
|
if (addrbook_store(&ab, addrbook_file) == -1)
|
||||||
|
fprintf(stderr, "Failed to store an addressbook: %s\n", strerror(errno));
|
||||||
|
fclose(addrbook_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addrbook_destroy(&ab);
|
addrbook_destroy(&ab);
|
||||||
audio_destroy(&aud);
|
audio_destroy(&aud);
|
||||||
net_destroy(&n);
|
net_destroy(&n);
|
||||||
@ -168,8 +186,8 @@ cleanup:
|
|||||||
crypt_key_destroy(&ok);
|
crypt_key_destroy(&ok);
|
||||||
crypt_key_destroy(&rk);
|
crypt_key_destroy(&rk);
|
||||||
|
|
||||||
if (audio_terminate_soundsystem() == -1)
|
// if (audio_terminate_soundsystem() == -1)
|
||||||
return 1;
|
// return 1;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user