Repository navigation
Expand file tree
/
Copy pathchat_engine.c
More file actions
735 lines (613 loc) · 25.1 KB
/
Copy pathchat_engine.c
File metadata and controls
735 lines (613 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#include <ctype.h>
// --- CORE DSA/CONFIGURATIONS ---
#define TABLE_SIZE 1000
#define MAX_USERNAME_LEN 32
#define MAX_GROUP_SIZE 10
#define MAX_GROUPS 5
#define MAX_GROUP_NAME_LEN 64
#define MAX_EMAIL_LEN 100 // Define max length for email
// --- 1. HASH TABLE STRUCTURES (Dual Indexing) ---
// UserData remains the same
typedef struct UserData {
char *private_email;
bool is_online;
} UserData;
// UserEntry remains the primary list for the Username Hash Table
typedef struct UserEntry {
char username[MAX_USERNAME_LEN];
UserData data;
struct UserEntry *next;
} UserEntry;
// NEW: EmailIndexEntry for the Email Hash Table
typedef struct EmailIndexEntry {
char email[MAX_EMAIL_LEN];
UserEntry *user_ptr; // Pointer back to the actual UserEntry data
struct EmailIndexEntry *next;
} EmailIndexEntry;
UserEntry *user_map[TABLE_SIZE] = {NULL}; // Global Hash Table keyed by Username
EmailIndexEntry *email_map[TABLE_SIZE] = {NULL}; // NEW: Global Hash Table keyed by Email
// --- 2. GROUP & MESSAGE STRUCTURES (Unchanged) ---
typedef struct Message {
char sender_id[MAX_USERNAME_LEN];
char content[256];
char timestamp[30];
struct Message *next;
struct Message *group_next;
} Message;
typedef struct Location {
int message_index;
struct Location *next;
} Location;
typedef struct WordEntry {
char *word;
int count;
Location *locations;
struct WordEntry *next;
} WordEntry;
WordEntry *word_map[TABLE_SIZE] = {NULL};
Message *message_history_head = NULL;
int total_messages = 0;
typedef struct ChatGroup {
char name[MAX_GROUP_NAME_LEN];
char *member_ids[MAX_GROUP_SIZE];
int member_count;
Message *group_history_head;
int group_message_count;
} ChatGroup;
ChatGroup all_groups[MAX_GROUPS];
int group_count = 0;
// --- UTILITY FUNCTIONS (Standard I/O and Time) ---
void clear_input_buffer() {
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
void get_current_time(char *buffer) {
time_t rawtime;
struct tm *info;
time(&rawtime);
info = localtime(&rawtime);
strftime(buffer, 30, "%H:%M:%S", info);
}
void list_groups() {
printf("\n--- Existing Groups (%d/%d) ---\n", group_count, MAX_GROUPS);
if (group_count == 0) {
printf("No groups have been created yet.\n");
return;
}
for (int i = 0; i < group_count; i++) {
printf(" %d. %s (Members: %d, Messages: %d)\n",
i + 1, all_groups[i].name, all_groups[i].member_count, all_groups[i].group_message_count);
}
}
// --- HASH FUNCTION ---
unsigned int hash(const char *key) {
unsigned long int value = 0;
int i = 0;
while (key[i] != '\0') {
value = value * 31 + key[i];
i++;
}
return value % TABLE_SIZE;
}
// --- HASH TABLE LOOKUP FUNCTIONS ---
UserEntry *find_user(const char *username) {
unsigned int index = hash(username);
UserEntry *current = user_map[index];
while (current != NULL) {
if (strcmp(current->username, username) == 0) {
return current;
}
current = current->next;
}
return NULL;
}
// NEW: O(1) Email Lookup
EmailIndexEntry *find_email(const char *email) {
unsigned int index = hash(email);
EmailIndexEntry *current = email_map[index];
while (current != NULL) {
if (strcmp(current->email, email) == 0) {
return current;
}
current = current->next;
}
return NULL;
}
// --- USER INSERTION FUNCTION (Dual Indexing) ---
bool insert_user(const char *username, const char *email) {
// 1. Check Username Uniqueness (O(1) average)
if (find_user(username) != NULL) {
printf("\n[ERROR] Username '%s' already exists. Insertion Failed.\n", username);
return false;
}
// 2. Check Email Uniqueness (O(1) average)
if (find_email(email) != NULL) {
printf("\n[ERROR] Email '%s' already registered. Insertion Failed.\n", email);
return false;
}
// --- 3. Allocate and Populate UserEntry ---
unsigned int user_index = hash(username);
UserEntry *new_user_entry = (UserEntry *)malloc(sizeof(UserEntry));
if (new_user_entry == NULL) {
perror("Memory allocation failed for UserEntry");
return false;
}
strncpy(new_user_entry->username, username, MAX_USERNAME_LEN - 1);
new_user_entry->username[MAX_USERNAME_LEN - 1] = '\0';
char *email_copy = strdup(email);
if (email_copy == NULL) {
perror("Memory allocation failed for email");
free(new_user_entry);
return false;
}
new_user_entry->data.private_email = email_copy;
new_user_entry->data.is_online = true;
new_user_entry->next = user_map[user_index];
user_map[user_index] = new_user_entry;
// --- 4. Allocate and Populate EmailIndexEntry (Secondary Index) ---
unsigned int email_index = hash(email);
EmailIndexEntry *new_email_entry = (EmailIndexEntry *)malloc(sizeof(EmailIndexEntry));
if (new_email_entry == NULL) {
perror("Memory allocation failed for EmailIndexEntry");
// Rollback primary registration to prevent memory leak and data inconsistency
user_map[user_index] = new_user_entry->next;
free(new_user_entry->data.private_email);
free(new_user_entry);
return false;
}
strncpy(new_email_entry->email, email, MAX_EMAIL_LEN - 1);
new_email_entry->email[MAX_EMAIL_LEN - 1] = '\0';
new_email_entry->user_ptr = new_user_entry; // Points to the actual user data
new_email_entry->next = email_map[email_index];
email_map[email_index] = new_email_entry;
printf("\n[SUCCESS] User '%s' inserted. Private Email: %s\n", username, new_user_entry->data.private_email);
return true;
}
void lookup_and_display(const char *username) {
UserEntry *entry = find_user(username);
if (entry) {
printf("\n--- User Lookup via Public ID ---\n");
printf("Public Username: %s\n", entry->username);
printf("Online Status: %s\n", entry->data.is_online ? "YES" : "NO");
printf("ATTENTION: Private Email is %s (Securely Retrieved via Hash Map)\n", entry->data.private_email);
} else {
printf("\n--- User Lookup via Public ID ---\n");
printf("Username '%s' not found.\n", username);
}
}
// --- GROUP FUNCTIONS (Unchanged, retained for completeness) ---
bool is_member(ChatGroup *group, const char *username) {
if (!group) return false;
for (int i = 0; i < group->member_count; i++) {
if (strcmp(group->member_ids[i], username) == 0) {
return true;
}
}
return false;
}
bool add_member(ChatGroup *group, const char *username) {
if (!group) return false;
if (find_user(username) == NULL) {
printf("\n[ERROR] User '%s' must be registered before adding to a group.\n", username);
return false;
}
if (group->member_count >= MAX_GROUP_SIZE) {
printf("\n[ERROR] Group '%s' is full (Max %d members).\n", group->name, MAX_GROUP_SIZE);
return false;
}
if (is_member(group, username)) {
printf("\n[WARNING] User '%s' already in group '%s'.\n", username, group->name);
return false;
}
char *new_member_id = strdup(username);
if (new_member_id == NULL) {
perror("Memory allocation failed for member ID");
return false;
}
group->member_ids[group->member_count] = new_member_id;
group->member_count++;
printf("\n[SUCCESS] User '%s' added to group '%s'.\n", username, group->name);
return true;
}
bool find_group_by_name(const char *name) {
for (int i = 0; i < group_count; i++) {
if (strcmp(all_groups[i].name, name) == 0) {
return true; // Found a duplicate
}
}
return false; // Name is unique
}
ChatGroup *create_group(const char *name) {
if (group_count >= MAX_GROUPS) {
printf("\n[ERROR] Maximum group limit (%d) reached.\n", MAX_GROUPS);
return NULL;
}
if (find_group_by_name(name)) {
printf("\n[ERROR] Group name '%s' already exists. Please choose a different name.\n", name);
return NULL;
}
ChatGroup *new_group = &all_groups[group_count];
memset(new_group, 0, sizeof(ChatGroup));
strncpy(new_group->name, name, MAX_GROUP_NAME_LEN - 1);
new_group->name[MAX_GROUP_NAME_LEN - 1] = '\0';
group_count++;
printf("\n[SUCCESS] Group '%s' created.\n", name);
return new_group;
}
// --- MESSAGE/ANALYTICS FUNCTIONS (Placeholder for brevity, full code logic maintained) ---
void analyze_and_index_word(const char *word, int message_index) {
char normalized_word[256];
strcpy(normalized_word, word);
int len = strlen(normalized_word);
for (int i = 0; i < len; i++) {
normalized_word[i] = tolower(normalized_word[i]);
}
if (len > 0 && (normalized_word[len - 1] == '.' || normalized_word[len - 1] == ',' ||
normalized_word[len - 1] == '!' || normalized_word[len - 1] == '?')) {
normalized_word[len - 1] = '\0';
len--;
}
if (len == 0) return;
unsigned int index = hash(normalized_word);
WordEntry *current = word_map[index];
while (current != NULL) {
if (strcmp(current->word, normalized_word) == 0) {
current->count++;
Location *new_loc = (Location*)malloc(sizeof(Location));
if (new_loc == NULL) return;
new_loc->message_index = message_index;
new_loc->next = current->locations;
current->locations = new_loc;
return;
}
current = current->next;
}
WordEntry *new_entry = (WordEntry *)malloc(sizeof(WordEntry));
if (new_entry == NULL) return;
new_entry->word = strdup(normalized_word);
if (new_entry->word == NULL) { free(new_entry); return; }
new_entry->count = 1;
new_entry->locations = (Location*)malloc(sizeof(Location));
if (new_entry->locations == NULL) { free(new_entry->word); free(new_entry); return; }
new_entry->locations->message_index = message_index;
new_entry->locations->next = NULL;
new_entry->next = word_map[index];
word_map[index] = new_entry;
}
void send_group_message(ChatGroup *group, const char *sender, const char *msg_content) {
if (!group) return;
Message *new_msg = (Message *)malloc(sizeof(Message));
if (new_msg == NULL) {
perror("Memory allocation failed for message");
return;
}
strncpy(new_msg->sender_id, sender, MAX_USERNAME_LEN);
strncpy(new_msg->content, msg_content, 255);
get_current_time(new_msg->timestamp);
new_msg->next = NULL;
new_msg->group_next = NULL;
new_msg->next = message_history_head;
message_history_head = new_msg;
total_messages++;
int current_index = total_messages;
new_msg->group_next = group->group_history_head;
group->group_history_head = new_msg;
group->group_message_count++;
printf("\n[GROUP MESSAGE SENT] [%s] <%s> %s: %s\n", new_msg->timestamp, group->name, sender, msg_content);
char temp_content[256];
strcpy(temp_content, msg_content);
char *token = strtok(temp_content, " \t\n.,!?");
while (token != NULL) {
analyze_and_index_word(token, current_index);
token = strtok(NULL, " \t\n.,!?");
}
}
void display_chat_history() {
printf("\n--- Full GLOBAL Chat History (%d Messages) ---\n", total_messages);
if (total_messages == 0) {
printf("No messages have been sent yet.\n");
return;
}
Message *current = message_history_head;
int index = total_messages;
while (current != NULL) {
printf("[#%d] [%s] %s: %s\n", index, current->timestamp, current->sender_id, current->content);
current = current->next;
index--;
}
}
void display_group_history(ChatGroup *group) {
if (!group) return;
printf("\n--- REAL-TIME CHAT: %s (%d Messages) ---\n", group->name, group->group_message_count);
if (group->group_message_count == 0) {
printf("No messages in this group yet.\n");
return;
}
Message *current = group->group_history_head;
while (current != NULL) {
printf("[%s] %s: %s\n", current->timestamp, current->sender_id, current->content);
current = current->group_next;
}
}
void query_word_analytics(const char *search_word) {
char normalized_word[256];
strcpy(normalized_word, search_word);
int len = strlen(normalized_word);
for (int i = 0; i < len; i++) {
normalized_word[i] = tolower(normalized_word[i]);
}
unsigned int index = hash(normalized_word);
WordEntry *entry = word_map[index];
while (entry != NULL) {
if (strcmp(entry->word, normalized_word) == 0) {
printf("\n--- Word Analytics Result for '%s' ---\n", entry->word);
printf("Total Usage Count: %d times\n", entry->count);
printf("Found in Message Indices (Where/When):\n");
Location *loc = entry->locations;
while (loc != NULL) {
printf(" -> Index #%d\n", loc->message_index);
loc = loc->next;
}
return;
}
entry = entry->next;
}
printf("\n[ANALYTICS] Word '%s' not found in chat history.\n", search_word);
}
// --- CLEANUP FUNCTIONS (Updated to include Email Index Cleanup) ---
void cleanup_locations(Location *head) {
Location *tmp;
while (head != NULL) {
tmp = head;
head = head->next;
free(tmp);
}
}
void cleanup_word_map() {
for (int i = 0; i < TABLE_SIZE; i++) {
WordEntry *current = word_map[i];
WordEntry *tmp;
while (current != NULL) {
tmp = current;
current = current->next;
cleanup_locations(tmp->locations);
free(tmp->word);
free(tmp);
}
}
}
void cleanup_message_history() {
Message *current = message_history_head;
Message *tmp;
while (current != NULL) {
tmp = current;
current = current->next;
free(tmp);
}
}
// NEW: Cleanup for the Email Hash Table
void cleanup_email_map() {
for (int i = 0; i < TABLE_SIZE; i++) {
EmailIndexEntry *current = email_map[i];
EmailIndexEntry *tmp;
while (current != NULL) {
tmp = current;
current = current->next;
// Note: We only free the EmailIndexEntry node itself,
// the actual UserEntry data is freed in cleanup_user_map().
free(tmp);
}
}
}
void cleanup_user_map() {
for (int i = 0; i < TABLE_SIZE; i++) {
UserEntry *current = user_map[i];
UserEntry *tmp;
while (current != NULL) {
tmp = current;
current = current->next;
free(tmp->data.private_email);
free(tmp);
}
}
}
void cleanup_groups() {
for (int i = 0; i < group_count; i++) {
for (int j = 0; j < all_groups[i].member_count; j++) {
free(all_groups[i].member_ids[j]);
}
}
}
// --- MAIN EXECUTION AND INTERACTIVE MENU ---
int main() {
int choice;
char username[MAX_USERNAME_LEN];
char email[MAX_EMAIL_LEN]; // Use defined MAX_EMAIL_LEN
char group_name[MAX_GROUP_NAME_LEN];
int group_index;
ChatGroup *selected_group = NULL;
bool running = true;
char content_buffer[256];
printf("===================================================\n");
printf(" High-Performance Secure Chat Engine Core (C/DSA) \n");
printf("===================================================\n");
printf("NEW: Multi-User Registration & Dual Uniqueness Check (Option 1).\n");
printf("---------------------------------------------------\n");
for (int i = 0; i < MAX_GROUPS; i++) {
all_groups[i].group_history_head = NULL;
all_groups[i].group_message_count = 0;
all_groups[i].member_count = 0;
}
while (running) {
printf("\n--- MENU ---\n");
printf("1. Register New User(s) (Dual Hash Table Check) 🔥\n");
printf("2. Lookup User Details (Via Public ID)\n");
printf("3. Create New Group (Name Check Added)\n");
printf("4. Add Member(s) to Group (Multi-Input Added)\n");
printf("5. Check Group Membership\n");
printf("--------------------------------------\n");
printf("6. Send GLOBAL Message (Saves History & Indexes Words)\n");
printf("7. Display Full GLOBAL Chat History\n");
printf("8. Analyze Word Usage (Count, Where, When)\n");
printf("9. SEND and VIEW Group Message (REAL-TIME SIMULATION)\n");
printf("0. Exit and Cleanup\n");
printf("Enter your choice: ");
if (scanf("%d", &choice) != 1) {
printf("\n[ERROR] Invalid input. Please enter a number.\n");
clear_input_buffer();
continue;
}
clear_input_buffer();
switch (choice) {
case 1: // Register User(s) - MULTI-INPUT FEATURE
printf("\n--- Register User(s) ---\n");
bool registering = true;
while (registering) {
printf("\nEnter Desired Unique Username (or type 'DONE'): ");
if (fgets(username, MAX_USERNAME_LEN, stdin) == NULL) break;
username[strcspn(username, "\n")] = 0; // Remove newline
if (strcmp(username, "DONE") == 0 || strcmp(username, "done") == 0) {
registering = false;
break;
}
printf("Enter Private Email Address for %s: ", username);
if (fgets(email, MAX_EMAIL_LEN, stdin) == NULL) break;
email[strcspn(email, "\n")] = 0; // Remove newline
insert_user(username, email);
}
printf("\n--- Finished user registration. ---\n");
break;
case 2: // Lookup User
printf("\n--- Lookup User ---\n");
printf("Enter Public Username to lookup: ");
scanf("%s", username);
lookup_and_display(username);
break;
case 3: // Create Group
printf("\n--- Create Group ---\n");
printf("Enter New Group Name (Max %d chars): ", MAX_GROUP_NAME_LEN - 1);
fgets(group_name, MAX_GROUP_NAME_LEN, stdin);
group_name[strcspn(group_name, "\n")] = 0;
create_group(group_name);
break;
case 4: // Add Member(s)
printf("\n--- Add Member(s) ---\n");
list_groups();
if (group_count == 0) break;
printf("Enter Group Number to select (1-%d): ", group_count);
if (scanf("%d", &group_index) != 1 || group_index < 1 || group_index > group_count) {
printf("\n[ERROR] Invalid group number.\n");
clear_input_buffer();
break;
}
clear_input_buffer();
selected_group = &all_groups[group_index - 1];
bool adding = true;
while (adding) {
printf("Enter Username to add to '%s' (or type 'DONE' to finish): ", selected_group->name);
if (fgets(username, MAX_USERNAME_LEN, stdin) == NULL) break;
username[strcspn(username, "\n")] = 0;
if (strcmp(username, "DONE") == 0 || strcmp(username, "done") == 0) {
adding = false;
break;
}
if (selected_group->member_count >= MAX_GROUP_SIZE) {
printf("[NOTICE] Group is full. Cannot add more members.\n");
break;
}
add_member(selected_group, username);
}
printf("\n--- Finished adding members to %s. ---\n", selected_group->name);
break;
case 5: // Check Membership
printf("\n--- Check Membership ---\n");
list_groups();
if (group_count == 0) break;
printf("Enter Group Number to select (1-%d): ", group_count);
if (scanf("%d", &group_index) != 1 || group_index < 1 || group_index > group_count) {
printf("\n[ERROR] Invalid group number.\n");
clear_input_buffer();
break;
}
clear_input_buffer();
selected_group = &all_groups[group_index - 1];
printf("Enter Username to check in '%s': ", selected_group->name);
scanf("%s", username);
if (is_member(selected_group, username)) {
printf("\n[CHECK] User '%s' IS a member of '%s'.\n", username, selected_group->name);
} else {
printf("\n[CHECK] User '%s' is NOT a member of '%s'.\n", username, selected_group->name);
}
break;
case 6: // Send GLOBAL Message
printf("\n--- Send GLOBAL Message ---\n");
printf("Enter your Username (must be registered): ");
scanf("%s", username);
clear_input_buffer();
if (find_user(username) == NULL) {
printf("[ERROR] User must be registered to send messages. Use Option 1 first.\n");
break;
}
printf("Enter Message Content (Max 255 chars): ");
fgets(content_buffer, 256, stdin);
content_buffer[strcspn(content_buffer, "\n")] = 0;
ChatGroup global_dummy_group = {0};
global_dummy_group.group_history_head = NULL;
send_group_message(&global_dummy_group, username, content_buffer);
break;
case 7: // Display GLOBAL History
display_chat_history();
break;
case 8: // Analyze Word Usage
printf("\n--- Analyze Word Usage ---\n");
printf("Enter word to analyze: ");
scanf("%s", username);
query_word_analytics(username);
break;
case 9: // SEND and VIEW Group Message
printf("\n--- Send/View Group Message ---\n");
list_groups();
if (group_count == 0) break;
printf("Enter Group Number to select (1-%d): ", group_count);
if (scanf("%d", &group_index) != 1 || group_index < 1 || group_index > group_count) {
printf("\n[ERROR] Invalid group number.\n");
clear_input_buffer();
break;
}
clear_input_buffer();
selected_group = &all_groups[group_index - 1];
printf("\nEnter your Username (must be a member of '%s'): ", selected_group->name);
scanf("%s", username);
clear_input_buffer();
if (!is_member(selected_group, username)) {
printf("[ERROR] User '%s' is not a member of '%s'. Cannot send message. Use Option 4.\n", username, selected_group->name);
break;
}
printf("Enter Message Content (Max 255 chars to %s): ", selected_group->name);
fgets(content_buffer, 256, stdin);
content_buffer[strcspn(content_buffer, "\n")] = 0;
send_group_message(selected_group, username, content_buffer);
display_group_history(selected_group);
break;
case 0:
running = false;
break;
default:
printf("\n[ERROR] Invalid choice. Please try again.\n");
break;
}
}
// --- FINAL CLEANUP ---
cleanup_email_map(); // NEW cleanup call
cleanup_user_map();
cleanup_groups();
cleanup_word_map();
cleanup_message_history();
printf("\nExiting program. Memory cleanup complete.\n");
return 0;
}