void key_value_storage_clear(key_value_storage_t* stor);
int key_value_storage_add(key_value_storage_t* stor, const char* key, const char* value);
char* key_value_storage_find(key_value_storage_t* stor, const char* key);
+/* Warning: this function only works if you actually store \0-terminated strings as values!! */
+char* key_value_storage_find_first_stringvalue(key_value_storage_t* stor, const char* value);
int key_value_storage_length(key_value_storage_t* stor);
void key_value_storage_print(key_value_storage_t* stor, const char* head, const char* sep, const char* tail);
PARSE_STRING_PARAM("-s","--socket", opt->command_sock_)
PARSE_STRING_PARAM("-p","--powerid-file", opt->powerid_file_)
PARSE_STRING_PARAM("-a","--sampledev-file", opt->sampledev_file_)
- PARSE_STRING_PARAM("-a","--sampledev-file", opt->sampledev_file_)
PARSE_KEY_VALUE("-A","--autosampledev", ',', opt->autosampledevs_)
else
return i;
if(cmd_id == POWER_ON || cmd_id == POWER_OFF) {
char* orig_param = param;
- param = key_value_storage_find(&opt->powerids_, param);
+ param = key_value_storage_find(&(opt->powerids_), param);
if(!param) {
send_response(fd, "Error: invalid power id");
log_printf(WARNING, "invalid power id '%s' in command from %d", orig_param, fd);
if(cmd_id == SAMPLE) {
char* orig_param = param;
- param = key_value_storage_find(&opt->sampledevs_, param);
+ param = key_value_storage_find(&(opt->sampledevs_), param);
if(!param) {
send_response(fd, "Error: invalid sample device");
log_printf(WARNING, "invalid sample device '%s' in command from %d", orig_param, fd);
return ret;
}
-int process_tty(read_buffer_t* buffer, int tty_fd, cmd_t **cmd_q, client_t* client_lst)
+int process_tty(read_buffer_t* buffer, int tty_fd, cmd_t **cmd_q, client_t* client_lst, options_t* opt)
{
int ret = 0;
struct timeval tv;
}
if(!strncmp(buffer->buf, "Sensor ", 7)) {
- SEND_TO_LISTENER(sensor_listener, "", cmd_fd, buffer->buf);
+ if (buffer->buf[7] != 0)
+ {
+ char const *sampledev_key;
+ if (asprintf(sampledev_key, "%c",buffer->buf[7]))
+ {
+ char const *sampledev_name = key_value_storage_find_first_stringvalue(&(opt->sampledevs_), sampledev_key);
+ if(sampledev_name)
+ {
+ char const *rev_lookuped_output;
+ if (asprintf(rev_lookuped_output, "%s%s", sampledev_name, &(buffer->buf[8])))
+ {
+ SEND_TO_LISTENER(sensor_listener, "", cmd_fd, rev_lookuped_output);
+ free((void*) rev_lookuped_output);
+ }
+ }
+ else
+ {
+ log_printf(WARNING, "unknown sample device key '%s' encountered", sampledev_key);
+ SEND_TO_LISTENER(sensor_listener, "", cmd_fd, buffer->buf);
+ }
+ free((void*) sampledev_key);
+ }
+ }
}
cmd_pop(cmd_q);
}
if(FD_ISSET(tty_fd, &tmpfds)) {
- return_value = process_tty(&tty_buffer, tty_fd, &cmd_q, client_lst);
+ return_value = process_tty(&tty_buffer, tty_fd, &cmd_q, client_lst, opt);
if(return_value)
break;
}