#include #include #include #include #include #include "algo_skel.h" #include "donar_client.h" #include "donar_server.h" int main(int argc, char** argv) { printf("~ Donar ~\n"); int opt, is_server, is_client, errored; char *host, *port, *onion_file, *algo; host = NULL; port = NULL; onion_file = NULL; algo = NULL; is_server = 0; is_client = 0; errored = 0; while ((opt = getopt(argc, argv, "csh:p:o:a:")) != -1) { switch(opt) { case 's': is_server = 1; break; case 'h': host = strdup(optarg); break; case 'p': port = strdup(optarg); break; case 'o': onion_file = strdup(optarg); break; case 'c': is_client = 1; break; case 'a': algo = strdup(optarg); break; default: goto in_error; } } if (!(is_server ^ is_client)) goto in_error; if (algo == NULL) goto in_error; struct algo_skel as; init_algo(&as, algo); if (is_server) { struct donar_server_ctx ctx; if (host == NULL || port == NULL) goto in_error; donar_server(&ctx, &as, host, port); } else if (is_client) { struct donar_client_ctx ctx; if (port == NULL || onion_file == NULL) goto in_error; donar_client(&ctx, &as, onion_file, port); } goto terminate; in_error: errored = 1; fprintf(stderr, "Usage as client : %s -c -a -p -o \n", argv[0]); fprintf(stderr, "Usage as server : %s -s -a -h -p \n\n", argv[0]); fprintf(stderr, "Passed parameters: client=%d, server=%d, algo=%s, host=%s, port=%s, onion_file=%s\n", is_client, is_server, algo, host, port, onion_file); terminate: if (host != NULL) free(host); if (onion_file != NULL) free(onion_file); if (port != NULL) free(port); if (algo != NULL) free(algo); return errored; }