Added function for retrieving sender, message, and a generic string

master
Aadhavan Srinivasan 2 years ago
parent 3125dd48d6
commit 3e07370f31

@ -13,3 +13,25 @@ char* fetch_dest_user_string(char* message) {
return token; return token;
} }
char* fetch_sender_user_string(char* message) {
fetch_generic_string("IAM",message);
}
char* fetch_generic_string(char* indicator, char* message) {
char* token = malloc (sizeof(char) * strlen(message));
char* string_to_search = malloc(strlen(indicator) + 1);
strcpy(string_to_search,indicator);
strcat(string_to_search,":");
token = strtok(message," r\n");
if (strcmp(token,string_to_search) == 0) {
token = strtok(NULL," \r\n");
} else {
return NULL;
}
return token;
}

@ -4,3 +4,18 @@
TO: <Username> TO: <Username>
then return 'Username' */ then return 'Username' */
char* fetch_dest_user_string(char* message); 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:
<Indicator>: <Value>
Then return 'value' */
char* fetch_generic_string(char* indicator, char* message);
/* If the message contains a string of the form:
START_OF_MESSAGE
<text>
END_OF_MESSAGE

Loading…
Cancel
Save