507 * PROFILE GETS uuid Get profile steps list |
507 * PROFILE GETS uuid Get profile steps list |
508 * PROFILE PUTS uuid Put profile steps list |
508 * PROFILE PUTS uuid Put profile steps list |
509 */ |
509 */ |
510 int cmd_profile(char *buf) |
510 int cmd_profile(char *buf) |
511 { |
511 { |
512 char ibuf[SS_BUFSIZE], *sstep, *rest, *targ, *param; |
512 char ibuf[SS_BUFSIZE], *sstep, *rest, *targ, *param, *kwd, *val; |
513 int i, j, rlen, istep, irest; |
513 int i, j, rlen, istep, irest; |
514 float ftarg; |
514 float ftarg, fval; |
515 socklen_t fromlen; |
515 socklen_t fromlen; |
516 char *opt; |
516 char *opt; |
517 profiles_list *profile, *tmpp; |
517 profiles_list *profile, *tmpp; |
518 prof_step *step, *olds; |
518 prof_step *step, *olds; |
519 uuid_t uu; |
519 uuid_t uu; |
582 } else { |
582 } else { |
583 srv_send((char *)"440 Delete Profile: No such profile%s", param); |
583 srv_send((char *)"440 Delete Profile: No such profile%s", param); |
584 return 1; |
584 return 1; |
585 } |
585 } |
586 |
586 |
|
587 } else if (strcmp(opt, (char *)"GET") == 0) { |
|
588 for (profile = Config.profiles; profile; profile = profile->next) { |
|
589 if (strcmp(profile->uuid, param) == 0) { |
|
590 srv_send((char *)"213 Profile %s record follows:", profile->uuid); |
|
591 srv_send((char *)"UUID,%s", profile->uuid); |
|
592 srv_send((char *)"NAME,%s", profile->name); |
|
593 srv_send((char *)"INITTEMP,%.1f", profile->inittemp); |
|
594 srv_send((char *)"."); |
|
595 return 1; |
|
596 } |
|
597 } |
|
598 srv_send((char *)"440 No such profile"); |
|
599 return 1; |
|
600 |
|
601 } else if (strcmp(opt, (char *)"PUT") == 0) { |
|
602 for (profile = Config.profiles; profile; profile = profile->next) { |
|
603 if (strcmp(profile->uuid, param) == 0) { |
|
604 while (1) { |
|
605 memset((char *)&ibuf, 0, SS_BUFSIZE); |
|
606 fromlen = sizeof(peeraddr_in); |
|
607 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen); |
|
608 if (rlen == -1) { |
|
609 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno)); |
|
610 srv_send((char *)"518 recfrom(): %s", strerror(errno)); |
|
611 return 1; |
|
612 } |
|
613 for (i = 0; i < strlen(ibuf); i++) { |
|
614 if (ibuf[i] == '\n') |
|
615 ibuf[i] = '\0'; |
|
616 if (ibuf[i] == '\r') |
|
617 ibuf[i] = '\0'; |
|
618 } |
|
619 for (i = strlen(ibuf) -1; i > 0; i--) { |
|
620 if (ibuf[i] == ' ') |
|
621 ibuf[i] = '\0'; |
|
622 else |
|
623 break; |
|
624 } |
|
625 if (strlen(ibuf)) { |
|
626 if (debug) { |
|
627 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf); |
|
628 fprintf(stdout, "recv: \"%s\"\n", ibuf); |
|
629 } |
|
630 if (strcmp(ibuf, (char *)".") == 0) { |
|
631 srv_send((char *)"219 Accepted Device record"); |
|
632 return 0; |
|
633 } |
|
634 kwd = strtok(ibuf, ",\0"); |
|
635 val = strtok(NULL, "\0"); |
|
636 if (kwd && val) { |
|
637 if (strcmp(kwd, (char *)"NAME") == 0) { |
|
638 if (profile->name) |
|
639 free(profile->name); |
|
640 profile->name = xstrcpy(val); |
|
641 } else if (strcmp(kwd, (char *)"INITTEMP") == 0) { |
|
642 if (sscanf(val, "%f", &fval) == 1) |
|
643 profile->inittemp = fval; |
|
644 } |
|
645 } |
|
646 } |
|
647 } |
|
648 } |
|
649 } |
|
650 srv_send((char *)"440 No such profile"); |
|
651 return 1; |
|
652 |
587 } else if (strcmp(opt, (char *)"GETS") == 0) { |
653 } else if (strcmp(opt, (char *)"GETS") == 0) { |
588 |
654 |
589 for (profile = Config.profiles; profile; profile = profile->next) { |
655 for (profile = Config.profiles; profile; profile = profile->next) { |
590 if (strcmp(profile->uuid, param) == 0) { |
656 if (strcmp(profile->uuid, param) == 0) { |
591 srv_send((char *)"215 Profile steps follow:"); |
657 srv_send((char *)"215 Profile steps follow:"); |
1177 srv_send((char *)"LIST LOG uuid List logfile data in 1 hour lines"); |
1243 srv_send((char *)"LIST LOG uuid List logfile data in 1 hour lines"); |
1178 srv_send((char *)"PROFILE uuid,name Profile rename"); |
1244 srv_send((char *)"PROFILE uuid,name Profile rename"); |
1179 srv_send((char *)"PROFILE ADD name Add new profile with name"); |
1245 srv_send((char *)"PROFILE ADD name Add new profile with name"); |
1180 srv_send((char *)"PROFILE DEL uuid Delete profile by uuid"); |
1246 srv_send((char *)"PROFILE DEL uuid Delete profile by uuid"); |
1181 srv_send((char *)"PROFILE LIST List available profiles"); |
1247 srv_send((char *)"PROFILE LIST List available profiles"); |
|
1248 srv_send((char *)"PROFILE GET uuid Get Profile record by uuid"); |
|
1249 srv_send((char *)"PROFILE PUT uuid Put Profile record by uuid"); |
1182 srv_send((char *)"PROFILE GETS uuid Profile get steps list"); |
1250 srv_send((char *)"PROFILE GETS uuid Profile get steps list"); |
1183 srv_send((char *)"PROFILE PUTS uuid Profile put steps list"); |
1251 srv_send((char *)"PROFILE PUTS uuid Profile put steps list"); |
1184 srv_send((char *)"UNIT uuid Select unit by uuid"); |
1252 srv_send((char *)"UNIT uuid Select unit by uuid"); |
1185 srv_send((char *)"UNIT ADD name Add a new unit with name"); |
1253 srv_send((char *)"UNIT ADD name Add a new unit with name"); |
1186 srv_send((char *)"UNIT DEL uuid Delete Unit by uuid"); |
1254 srv_send((char *)"UNIT DEL uuid Delete Unit by uuid"); |