# HG changeset patch # User Michiel Broek # Date 1406405924 -7200 # Node ID e7e7a23af89066bdee251bc0967860200c64b969 # Parent e4518fd9b6261a1b2cd74431c9f7c56371e2e437 Added DEL PROFILE command diff -r e4518fd9b626 -r e7e7a23af890 thermferm/server.c --- a/thermferm/server.c Sat Jul 26 17:30:47 2014 +0200 +++ b/thermferm/server.c Sat Jul 26 22:18:44 2014 +0200 @@ -126,6 +126,7 @@ uuid_generate(uu); uuid_unparse(uu, profile->uuid); profile->name = xstrcpy(param); + profile->busy = 0; profile->steps = NULL; if (Config.profiles == NULL) { @@ -189,6 +190,92 @@ + +void delete_Profile(char *uuid) +{ + profiles_list *current = Config.profiles; + profiles_list *previous = NULL; + prof_step *step, *olds; + + + while (current) { + if (strcmp(current->uuid, uuid) == 0) { + if (previous == NULL) { + Config.profiles = current->next; + free(current->uuid); + current->uuid = NULL; + free(current->name); + current->name = NULL; + if (current->steps) { + for (step = current->steps; step; step = olds) { + olds = step->next; + free(step); + } + current->steps = NULL; + } + free(current); + return; + } else { + free(current->uuid); + current->uuid = NULL; + free(current->name); + current->name = NULL; + if (current->steps) { + for (step = current->steps; step; step = olds) { + olds = step->next; + free(step); + } + current->steps = NULL; + } + previous->next = current->next; + free(current); + current = previous->next; + return; + } + } else { + previous = current; + current = current->next; + } + } +} + + + +/* + * DEL PROFILE + */ +int cmd_del(char *buf) +{ + char *opt, *param; + + opt = strtok(buf, " \0"); + opt = strtok(NULL, " \0"); + if (opt == NULL) { + srv_send((char *)"501 Subcommand missing"); + return 1; + } + + param = strtok(NULL, "\0"); + if (param == NULL) { + srv_send((char *)"501 Parameter missing"); + return 1; + } + + if (debug) + fprintf(stdout, "opt: '%s' param: '%s'\n", MBSE_SS(opt), MBSE_SS(param)); + + if (strcmp(opt, (char *)"PROFILE") == 0) { + delete_Profile(param); + srv_send((char *)"211 Profile %s deleted", param); + return 0; + } + + srv_send((char *)"502 Unknown command option"); + return 1; +} + + + /* * LIST * LIST BUS @@ -719,6 +806,9 @@ if (strncmp(buf, "ADD", 3) == 0) { if (unit_add(buf) == 0) wrconfig(); + } else if (strncmp(buf, "DEL", 3) == 0) { + if (cmd_del(buf) == 0) + wrconfig(); } else if (strncmp(buf, "HELP", 4) == 0) { srv_send((char *)"100 Help text follows"); srv_send((char *)"Recognized commands:"); @@ -726,7 +816,7 @@ // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 srv_send((char *)"ADD PROFILE name Add a new profile with \"name\""); srv_send((char *)"ADD UNIT name Add a new unit with \"name\""); -// srv_send((char *)"DEL PROFILE uuid Delete profile with uuid"); + srv_send((char *)"DEL PROFILE uuid Delete profile with uuid"); // srv_send((char *)"DEL UNIT uuid Delete unit with uuid"); srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)"); srv_send((char *)"LIST List all fermenter units");