Skip to content
Browse files

trim function removes redundant whitespaces from parameters

  • Loading branch information...
1 parent 5e3d714 commit 48890eab1355a016d3dce4fbf5994101dc00b745 Robert A committed
Showing with 28 additions and 0 deletions.
  1. +28 −0 duoit.c
View
28 duoit.c
@@ -204,6 +204,30 @@ int format_command(char *command, int size) {
}
/*
+ * removes preceding/trailing white-space-characters
+ * TODO: make sure string is null-terminated
+ */
+char *trim(char *str) {
+ char *temp;
+
+ temp = str;
+ //remove trailing white-spaces
+ while (*temp != '\0') {
+ temp++;
+ }
+ while (isspace(*(--temp))) {
+ *temp = '\0';
+ }
+ //remove preceding white-spaces
+ temp = str;
+ while (isspace(*temp)) {
+ temp++;
+ }
+
+ return temp;
+}
+
+/*
* send messages to socket
*
* TODO: prüfen was gesendet wurde, send_all
@@ -224,6 +248,10 @@ int user_command(instruc *instruction, usr *user) {
send_message(user->csocket, "501 Syntax error in parameters or arguments.");
return 1;
}
+
+ //remove redundant whitespaces from params
+ instruction->params = trim(instruction->params);
+
if (!(strcmp(instruction->params, "duoit"))) {
send_message(user->csocket, "230 User logged in.");
} else {

0 comments on commit 48890ea

Please sign in to comment.
Something went wrong with that request. Please try again.