Rev 5 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
/* $Id: main.c 7 2024-09-25 00:56:55Z nishi $ */
#include <stdio.h>
#include <string.h>
#include "ms_newlist.h"
#include "ms_server.h"
#include <cm_crypt.h>
#include <cm_version.h>
extern const char* cm_crypt_methods[];
int main(int argc, char** argv) {
int i;
int startsub = 0;
const char* option = NULL;
for(i = 1; i < argc; i++) {
if(argv[i][0] == '-') {
if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) {
printf("MLServ version %s\n", cm_get_version());
return 0;
} else if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
printf("Usage: %s [options] [subcommand] [subcommand options/arguments]\n", argv[0]);
printf("Options:\n");
printf("-V | --version Shows the version\n");
printf("-h | --help Shows the help\n");
printf("Subcommands:\n");
printf("newlist Creates a new list\n");
printf("server Starts a server\n");
return 0;
} else {
fprintf(stderr, "Invalid flag: %s\n", argv[i]);
return 1;
}
} else {
option = argv[i];
startsub = i + 1;
break;
}
}
if(option == NULL) {
fprintf(stderr, "Specify subcommand\n");
return 1;
} else if(strcmp(option, "newlist") == 0) {
return ms_handle_newlist(argc, argv, startsub);
} else if(strcmp(option, "server") == 0) {
int m;
if((m = cm_crypt_init()) < 0) {
fprintf(stderr, "No crypt() method available\n");
return 1;
}
if(m == C_DES) {
fprintf(stderr, "!!! DES IS VERY INSECURE! CONSIGER GETTING BETTER OS !!!\n");
}
printf("Using %s as the default crypt() method\n", cm_crypt_methods[m]);
return ms_handle_server(argc, argv, startsub);
} else {
fprintf(stderr, "Invalid subcommand: %s\n", option);
return 1;
}
return 0;
}