Removed unnecessary functions

master
Aadhavan Srinivasan 2 years ago
parent ace4e3c8e5
commit 70ecbae964

@ -2,36 +2,44 @@
#include "message_helpers.h" #include "message_helpers.h"
char* fetch_dest_user_string(char* message) { char* fetch_from_string(char* message, char* indicator) {
char* token = malloc (sizeof(char) * strlen(message));
token = strtok(message," \r\n"); char* message_copy = malloc(strlen(message));
if (strcmp(token,"TO:") == 0) { strcpy(message_copy,message);
char* token = malloc (sizeof(char) * strlen(message_copy));
char* string_to_search = malloc(strlen(indicator) + 1);
strcpy(string_to_search,indicator);
strcat(string_to_search,":");
token = strtok(message_copy," r\n");
while (strcmp(token,string_to_search) != 0) {
token = strtok(NULL," \r\n"); token = strtok(NULL," \r\n");
} else { if (token == NULL) {
return NULL; return NULL;
} }
return token;
} }
token = strtok(NULL," \r\n");
return token;
char* fetch_sender_user_string(char* message) {
fetch_generic_string("IAM",message);
} }
char* fetch_generic_string(char* indicator, char* message) { char* fetch_message_string(char* message) {
char* token = malloc (sizeof(char) * strlen(message)); char* start = strstr(message,"START_OF_MESSAGE");
if (start == NULL) {
char* string_to_search = malloc(strlen(indicator) + 1); return NULL;
strcpy(string_to_search,indicator); }
strcat(string_to_search,":"); int start_index = start - message;
token = strtok(message," r\n"); char* end = strstr(message,"END_OF_MESSAGE");
if (strcmp(token,string_to_search) == 0) { if (end == NULL) {
token = strtok(NULL," \r\n");
} else {
return NULL; return NULL;
} }
int end_index = end - message;
return token; int message_length = end_index - start_index;
char* message_string = malloc(message_length + 1);
for (int i=0;i < message_length; i++) {
*(message_string + i) = *(message_
} }

@ -1,21 +1,12 @@
/* If the message contains a string of the form:
TO: <Username>
then return 'Username' */
char* fetch_dest_user_string(char* message);
/* If the message contains a string of the form:
IAM: <Username>
then return 'Username' */
char* fetch_sender_user_string(char* message);
/* If the message contains a string of the form: /* If the message contains a string of the form:
<Indicator>: <Value> <Indicator>: <Value>
Then return 'value' */ Then return 'value' */
char* fetch_generic_string(char* indicator, char* message); char* fetch_from_string(char* message, char* indicator);
/* If the message contains a string of the form: /* If the message contains a string of the form:
START_OF_MESSAGE START_OF_MESSAGE
<text> <text>
END_OF_MESSAGE END_OF_MESSAGE
Then return <text> */
char* fetch_message_string(char* message);

Loading…
Cancel
Save