thermferm/server.c

changeset 192
5d013b4a9138
parent 191
c74bbc24a1c8
child 194
9eaaba49450f
--- a/thermferm/server.c	Thu Aug 07 19:38:30 2014 +0200
+++ b/thermferm/server.c	Thu Aug 07 20:34:07 2014 +0200
@@ -509,9 +509,9 @@
  */
 int cmd_profile(char *buf)
 {
-    char                ibuf[SS_BUFSIZE], *sstep, *rest, *targ, *param;
+    char                ibuf[SS_BUFSIZE], *sstep, *rest, *targ, *param, *kwd, *val;
     int                 i, j, rlen, istep, irest;
-    float		ftarg;
+    float		ftarg, fval;
     socklen_t           fromlen;
     char		*opt;
     profiles_list	*profile, *tmpp;
@@ -584,6 +584,72 @@
 	    return 1;
 	}
     
+    } else if (strcmp(opt, (char *)"GET") == 0) {
+	for (profile = Config.profiles; profile; profile = profile->next) {
+	    if (strcmp(profile->uuid, param) == 0) {
+		srv_send((char *)"213 Profile %s record follows:", profile->uuid);
+		srv_send((char *)"UUID,%s", profile->uuid);
+		srv_send((char *)"NAME,%s", profile->name);
+		srv_send((char *)"INITTEMP,%.1f", profile->inittemp);
+		srv_send((char *)".");
+		return 1;
+	    }
+	}
+	srv_send((char *)"440 No such profile");
+	return 1;
+
+    } else if (strcmp(opt, (char *)"PUT") == 0) {
+	for (profile = Config.profiles; profile; profile = profile->next) {
+	    if (strcmp(profile->uuid, param) == 0) {
+		while (1) {
+		    memset((char *)&ibuf, 0, SS_BUFSIZE);
+		    fromlen = sizeof(peeraddr_in);
+		    rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
+		    if (rlen == -1) {
+			syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
+			srv_send((char *)"518 recfrom(): %s", strerror(errno));
+			return 1;
+		    }
+		    for (i = 0; i < strlen(ibuf); i++) {
+			if (ibuf[i] == '\n')
+			    ibuf[i] = '\0';
+			if (ibuf[i] == '\r')
+			    ibuf[i] = '\0';
+		    }
+		    for (i = strlen(ibuf) -1; i > 0; i--) {
+			if (ibuf[i] == ' ')
+			    ibuf[i] = '\0';
+			else
+			    break;
+		    }
+		    if (strlen(ibuf)) {
+			if (debug) {
+			    syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
+			    fprintf(stdout, "recv: \"%s\"\n", ibuf);
+			}
+			if (strcmp(ibuf, (char *)".") == 0) {
+			    srv_send((char *)"219 Accepted Device record");
+			    return 0;
+			}
+			kwd = strtok(ibuf, ",\0");
+			val = strtok(NULL, "\0");
+			if (kwd && val) {
+			    if (strcmp(kwd, (char *)"NAME") == 0) {
+				if (profile->name)
+				    free(profile->name);
+				profile->name = xstrcpy(val);
+			    } else if (strcmp(kwd, (char *)"INITTEMP") == 0) {
+				if (sscanf(val, "%f", &fval) == 1)
+				    profile->inittemp = fval;
+			    }
+			}
+		    }
+		}
+	    }               
+	}
+	srv_send((char *)"440 No such profile");
+	return 1;
+
     } else if (strcmp(opt, (char *)"GETS") == 0) {
 
 	for (profile = Config.profiles; profile; profile = profile->next) {
@@ -1179,6 +1245,8 @@
 		srv_send((char *)"PROFILE ADD name              Add new profile with name");
 		srv_send((char *)"PROFILE DEL uuid              Delete profile by uuid");
 		srv_send((char *)"PROFILE LIST                  List available profiles");
+		srv_send((char *)"PROFILE GET uuid              Get Profile record by uuid");
+		srv_send((char *)"PROFILE PUT uuid              Put Profile record by uuid");
 		srv_send((char *)"PROFILE GETS uuid             Profile get steps list");
 		srv_send((char *)"PROFILE PUTS uuid             Profile put steps list");
 		srv_send((char *)"UNIT uuid                     Select unit by uuid");

mercurial