int main(void) { int quit = 0; // Initialize mail server seed_prng(*(uint32_t *)FLAG_PAGE); int num_mailq = 0; abook = calloc(sizeof(address_book)); initialize_address_book(); initialize_mail_queues(); // run a mail server char line[MAX_LINE+1]; int line_size = 0; printf("sendmail:"); do { // Read a line if ((line_size = receive_until(line, MAX_LINE, '\n')) <= 0) { break; } line[line_size] = '\0'; // Process the command char *next = line; // Terminate first command word while ((*next != ' ') && (*next != '\0')) next++; *next++ = '\0'; if (strcmp(line, "LIST")==0) { // List one mail queue list_queue(next); } else if (strcmp(line, "LISTALL")==0) { // List all mail queues list_all_queues(); } else if (strcmp(line, "POST")==0) { // Post a message sendmail_post(next); } else if (strcmp(line, "READ")==0) { // Read a message read_message(next); } else if (strcmp(line, "ADDRESSBOOK")==0) { // Print address book print_address_book(); } else if (strcmp(line, "QUIT")==0) { // Quit mail server break; } else { // Invalid command printf("Invalid Command!\n"); quit = 1; } } while (quit == 0); printf("Goodbye.\n"); }
void mailsend(int argc, char **argv) { int quit = 0; // parse arguments while (argc > 0) { if (!strcmp(*argv, "-d")) { debug_mode = 1; goto next; } next: argc--; argv++; } // Initialize mail server srand(); int num_mailq = 0; abook = calloc(sizeof(address_book)); initialize_address_book(); initialize_mail_queues(); // run a mail server char line[MAX_LINE+1]; int line_size = 0; do { // Read a line if ((line_size = receive_until(line, MAX_LINE, '\n')) <= 0) { break; } line[line_size] = '\0'; // Process the command char *next = line; // Terminate first command word while ((*next != ' ') && (*next != '\0')) next++; *next++ = '\0'; if (strcmp(line, "LIST")==0) { // List one mail queue list_queue(next); } else if (strcmp(line, "LISTALL")==0) { // List all mail queues list_all_queues(); } else if (strcmp(line, "POST")==0) { // Post a message mailsend_post(next); } else if (strcmp(line, "READ")==0) { // Read a message read_message(next); } else if (strcmp(line, "ADDRESSBOOK")==0) { // Print address book print_address_book(); } else if (strcmp(line, "QUIT")==0) { // Quit mail server break; } else { // Invalid command printf("Invalid Command!\n"); quit = 1; } } while (quit == 0); printf("Goodbye.\n"); }