2 * Copyright (c) 1992, 1993, 1995 Eugene W. Stark
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Eugene W. Stark.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY EUGENE W. STARK (THE AUTHOR) ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * $FreeBSD: src/libexec/xtend/user.c,v 1.9 1999/08/28 00:10:30 peter Exp $
32 * $DragonFly: src/libexec/xtend/user.c,v 1.3 2003/11/14 03:54:32 dillon Exp $
39 #include <sys/param.h>
45 MONENTRY Monitor
[MAXMON
];
47 int find (char *, char *[]);
48 void printstatus (FILE *, STATUS
*);
51 * Process a user command
60 char cmd
[512], dumppath
[MAXPATHLEN
+1], pkt
[3];
64 if(fgets(cmd
, 512, User
) != NULL
) {
66 while ( *m
!= '\0' ) {
71 if(sscanf(cmd
, "status %c %d", &h
, &i
) == 2
72 && h
>= 'a' && h
<= 'p' && i
>= 1 && i
<= 16) {
75 printstatus(User
, &Status
[h
][i
]);
76 } else if(sscanf(cmd
, "send %c %s %d", &h
, cmd
, &n
) == 3
77 && h
>= 'a' && h
<= 'p' && (i
= find(cmd
, X10cmdnames
)) >= 0) {
82 if(write(tw523
, pkt
, 3) != 3) {
83 fprintf(Log
, "%s: Transmission error (packet [%s %s]:%d).\n",
84 thedate(), X10housenames
[h
], X10cmdnames
[i
], n
);
87 fprintf(User
, "OK\n");
89 } else if(!strcmp("dump\n", cmd
)) {
90 strcpy(dumppath
, X10DIR
);
91 strcat(dumppath
, "/");
92 strcat(dumppath
, X10DUMPNAME
);
93 if((dumpf
= fopen(dumppath
, "w")) != NULL
) {
94 for(h
= 0; h
< 16; h
++) {
95 for(i
= 0; i
< 16; i
++) {
96 if(Status
[h
][i
].lastchange
) {
97 fprintf(dumpf
, "%s%d\t", X10housenames
[h
], i
+1);
98 printstatus(dumpf
, &Status
[h
][i
]);
103 fprintf(User
, "OK\n");
107 } else if(sscanf(cmd
, "monitor %c %d", &h
, &i
) == 2
108 && h
>= 'a' && h
<= 'p' && i
>= 1 && i
<= 16) {
111 for(k
= 0; k
< MAXMON
; k
++) {
112 if(!Monitor
[k
].inuse
) break;
117 Monitor
[k
].house
= h
;
119 Monitor
[k
].user
= User
;
120 Monitor
[k
].inuse
= 1;
121 fprintf(Log
, "%s: Adding %c %d to monitor list (entry %d)\n",
122 thedate(), h
+'A', i
+1, k
);
123 fprintf(User
, "OK\n");
126 return(0); /* We don't want caller to close stream */
128 } else if(!strcmp("done\n", cmd
)) {
129 fprintf(User
, "OK\n");
143 fprintf(User
, "ERROR\n");
156 for(i
= 0; tab
[i
] != NULL
; i
++) {
157 if(strcasecmp(s
, tab
[i
]) == 0) return(i
);
167 fprintf(f
, "%s:%d", s
->onoff
? "On" : "Off", s
->brightness
);
168 switch(s
->selected
) {
170 fprintf(f
, " (normal) "); break;
172 fprintf(f
, " (selected) "); break;
174 fprintf(f
, " (dimming) "); break;
176 fprintf(f
, " (brightening) "); break;
178 fprintf(f
, " (requested) "); break;
180 fprintf(f
, " (hailed) "); break;
182 fprintf(f
, " (bogus) "); break;
184 fprintf(f
, "%s", ctime(&s
->lastchange
));