thermferm/server.c

changeset 138
e7e7a23af890
parent 136
264e5ee5abfc
child 140
1b001de37945
equal deleted inserted replaced
137:e4518fd9b626 138:e7e7a23af890
124 profile->version = 1; 124 profile->version = 1;
125 profile->uuid = malloc(37); 125 profile->uuid = malloc(37);
126 uuid_generate(uu); 126 uuid_generate(uu);
127 uuid_unparse(uu, profile->uuid); 127 uuid_unparse(uu, profile->uuid);
128 profile->name = xstrcpy(param); 128 profile->name = xstrcpy(param);
129 profile->busy = 0;
129 profile->steps = NULL; 130 profile->steps = NULL;
130 131
131 if (Config.profiles == NULL) { 132 if (Config.profiles == NULL) {
132 Config.profiles = profile; 133 Config.profiles = profile;
133 } else { 134 } else {
179 } 180 }
180 181
181 syslog(LOG_NOTICE, "Unit with uuid %s added", unit->uuid); 182 syslog(LOG_NOTICE, "Unit with uuid %s added", unit->uuid);
182 srv_send((char *)"211 Unit with uuid %s added", unit->uuid); 183 srv_send((char *)"211 Unit with uuid %s added", unit->uuid);
183 return 0; 184 return 0;
185 }
186
187 srv_send((char *)"502 Unknown command option");
188 return 1;
189 }
190
191
192
193
194 void delete_Profile(char *uuid)
195 {
196 profiles_list *current = Config.profiles;
197 profiles_list *previous = NULL;
198 prof_step *step, *olds;
199
200
201 while (current) {
202 if (strcmp(current->uuid, uuid) == 0) {
203 if (previous == NULL) {
204 Config.profiles = current->next;
205 free(current->uuid);
206 current->uuid = NULL;
207 free(current->name);
208 current->name = NULL;
209 if (current->steps) {
210 for (step = current->steps; step; step = olds) {
211 olds = step->next;
212 free(step);
213 }
214 current->steps = NULL;
215 }
216 free(current);
217 return;
218 } else {
219 free(current->uuid);
220 current->uuid = NULL;
221 free(current->name);
222 current->name = NULL;
223 if (current->steps) {
224 for (step = current->steps; step; step = olds) {
225 olds = step->next;
226 free(step);
227 }
228 current->steps = NULL;
229 }
230 previous->next = current->next;
231 free(current);
232 current = previous->next;
233 return;
234 }
235 } else {
236 previous = current;
237 current = current->next;
238 }
239 }
240 }
241
242
243
244 /*
245 * DEL PROFILE
246 */
247 int cmd_del(char *buf)
248 {
249 char *opt, *param;
250
251 opt = strtok(buf, " \0");
252 opt = strtok(NULL, " \0");
253 if (opt == NULL) {
254 srv_send((char *)"501 Subcommand missing");
255 return 1;
256 }
257
258 param = strtok(NULL, "\0");
259 if (param == NULL) {
260 srv_send((char *)"501 Parameter missing");
261 return 1;
262 }
263
264 if (debug)
265 fprintf(stdout, "opt: '%s' param: '%s'\n", MBSE_SS(opt), MBSE_SS(param));
266
267 if (strcmp(opt, (char *)"PROFILE") == 0) {
268 delete_Profile(param);
269 srv_send((char *)"211 Profile %s deleted", param);
270 return 0;
184 } 271 }
185 272
186 srv_send((char *)"502 Unknown command option"); 273 srv_send((char *)"502 Unknown command option");
187 return 1; 274 return 1;
188 } 275 }
717 * Process commands from the client 804 * Process commands from the client
718 */ 805 */
719 if (strncmp(buf, "ADD", 3) == 0) { 806 if (strncmp(buf, "ADD", 3) == 0) {
720 if (unit_add(buf) == 0) 807 if (unit_add(buf) == 0)
721 wrconfig(); 808 wrconfig();
809 } else if (strncmp(buf, "DEL", 3) == 0) {
810 if (cmd_del(buf) == 0)
811 wrconfig();
722 } else if (strncmp(buf, "HELP", 4) == 0) { 812 } else if (strncmp(buf, "HELP", 4) == 0) {
723 srv_send((char *)"100 Help text follows"); 813 srv_send((char *)"100 Help text follows");
724 srv_send((char *)"Recognized commands:"); 814 srv_send((char *)"Recognized commands:");
725 srv_send((char *)""); 815 srv_send((char *)"");
726 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890 816 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
727 srv_send((char *)"ADD PROFILE name Add a new profile with \"name\""); 817 srv_send((char *)"ADD PROFILE name Add a new profile with \"name\"");
728 srv_send((char *)"ADD UNIT name Add a new unit with \"name\""); 818 srv_send((char *)"ADD UNIT name Add a new unit with \"name\"");
729 // srv_send((char *)"DEL PROFILE uuid Delete profile with uuid"); 819 srv_send((char *)"DEL PROFILE uuid Delete profile with uuid");
730 // srv_send((char *)"DEL UNIT uuid Delete unit with uuid"); 820 // srv_send((char *)"DEL UNIT uuid Delete unit with uuid");
731 srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)"); 821 srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)");
732 srv_send((char *)"LIST List all fermenter units"); 822 srv_send((char *)"LIST List all fermenter units");
733 srv_send((char *)"LIST BUS List 1-wire bus"); 823 srv_send((char *)"LIST BUS List 1-wire bus");
734 srv_send((char *)"LIST LOG List logfile data in 1 hour lines"); 824 srv_send((char *)"LIST LOG List logfile data in 1 hour lines");

mercurial