1
0

Current state.

This commit is contained in:
Alexander Andreev 2024-03-30 04:35:11 +04:00
parent 489d885049
commit 23599f4420
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34
2 changed files with 23 additions and 12 deletions

View File

@ -1,3 +1,4 @@
#include <bits/endian.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
@ -65,13 +66,13 @@ int main(int argc, const char **argv) {
// if (audio_init_soundsystem() == -1)
// return 1;
FILE *addrbook_file = fopen("addressbook", "r");
FILE *addrbook_file = fopen((opts.addressbook_path == NULL) ? "addressbook" : opts.addressbook_path, "r");
if (addrbook_file != NULL) {
addrbook_load(&ab, addrbook_file);
fclose(addrbook_file);
}
if (opts.is_alias_passed) {
if (opts.command == 'c' && opts.is_alias_passed) {
addrbook_entry_t *aec = addrbook_get_by_alias(&ab, opts.addr);
if (aec == NULL) {
fprintf(stderr, "An alias \"%s\" is not in an addressbook!\n", opts.addr);
@ -91,6 +92,11 @@ int main(int argc, const char **argv) {
goto cleanup;
}
if (pkey_file != NULL)
fclose(pkey_file);
if (skey_file != NULL)
fclose(skey_file);
pkey_file = fopen("tat_own_pub_key", "w+");
skey_file = fopen("tat_own_sec_key", "w+");
@ -98,7 +104,8 @@ int main(int argc, const char **argv) {
fclose(pkey_file);
fclose(skey_file);
printf("A new cryptographical keys was written.\n");
printf("The new cryptographical keys was written.\n");
} else {
if (crypt_load_key(&ok, pkey_file, skey_file) == -1) {
fprintf(stderr, "Cannot load the keys.");
@ -134,11 +141,11 @@ int main(int argc, const char **argv) {
unsigned char aud_buf[AUDIO_BUF_SIZE];
memset(aud_buf, 0, AUDIO_BUF_SIZE);
audio_init_default(&aud, CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFFER);
// audio_init_default(&aud, CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFFER);
(opts.command == 'c') ?
(audio_stream_input_toggle(&aud))
: (audio_stream_output_toggle(&aud));
// (opts.command == 'c') ?
// (audio_stream_input_toggle(&aud))
// : (audio_stream_output_toggle(&aud));
// for (size_t i = 0; i < (20 * SAMPLE_RATE)/FRAMES_PER_BUFFFER; ++i) {
// if (opts.command == 'c') {
@ -148,9 +155,9 @@ int main(int argc, const char **argv) {
// }
// }
(opts.command == 'c') ?
(audio_stream_input_toggle(&aud))
: (audio_stream_output_toggle(&aud));
// (opts.command == 'c') ?
// (audio_stream_input_toggle(&aud))
// : (audio_stream_output_toggle(&aud));
cleanup:
@ -286,9 +293,10 @@ int parse_argv(int argc, const char **argv, struct options *opts) {
}
}
int r = inet_pton(AF_INET, opts->addr, NULL);
struct sockaddr test = {0};
int r = inet_pton(AF_INET, opts->addr, &test);
if (r == -1)
r = inet_pton(AF_INET6, opts->addr, NULL);
r = inet_pton(AF_INET6, opts->addr, &test);
opts->is_alias_passed = r == 0;
if (opts->command == '\0' || opts->addr[0] == '\0'

View File

@ -5,6 +5,9 @@
#include <netdb.h>
int net_client_init(net_t *const n, const char *const raddr, const char *const rport) {
if (raddr == NULL || rport == NULL)
return -1;
struct addrinfo hints, *ri, *cri;
memset(&hints, 0, sizeof(hints));