summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2015-07-15 19:27:33 +0200
committerDavid Härdeman <david@hardeman.nu>2015-07-15 19:27:33 +0200
commit02dee330f76ea0361dba8a049529e978bb80013c (patch)
treeeff7c33cf229180ced2b43520b068ee654dcdcfa
parent35234714a0a51ae7f77cde26a76678d52b7eaeeb (diff)
Improve keymap parsing in server
-rw-r--r--linux-input-keycodes.h4
-rw-r--r--rcm-server-keymap.c40
2 files changed, 38 insertions, 6 deletions
diff --git a/linux-input-keycodes.h b/linux-input-keycodes.h
index 509aa52..4ef6bd3 100644
--- a/linux-input-keycodes.h
+++ b/linux-input-keycodes.h
@@ -3,6 +3,10 @@
#include "linux-input-enum.h"
+#ifndef cairo_surface_t
+typedef void * cairo_surface_t;
+#endif
+
struct linux_input_keycode {
const char *name;
enum linux_input_keyval value;
diff --git a/rcm-server-keymap.c b/rcm-server-keymap.c
index af72045..8a4fa3e 100644
--- a/rcm-server-keymap.c
+++ b/rcm-server-keymap.c
@@ -14,6 +14,7 @@
#include <limits.h>
#include "utils.h"
+#include "linux-input-keycodes.h"
#include "rcm-server-main.h"
#include "rcm-server-keymap.h"
@@ -175,7 +176,6 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
char *end;
uint64_t scancode;
- printf("Map %s\n", tmp);
protocol = strtok(tmp, " :");
scanstr = strtok(NULL, " :");
keycode = strtok(NULL, " :");
@@ -192,14 +192,24 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
return r;
}
- printf("Map means protocol %s scancode 0x%08" PRIx64 " keycode %s\n",
- protocol, scancode, keycode);
+ for (i = 0; linux_input_keycodes[i].name; i++) {
+ if (!strcmp(keycode, linux_input_keycodes[i].name))
+ break;
+ }
+
+ if (!linux_input_keycodes[i].name || linux_input_keycodes[i].value < 1) {
+ fprintf(stderr, "Invalid keycode name: %s\n", keycode);
+ return -EINVAL;
+ }
if (keymap) {
/* FIXME: leaks */
keymap->keycodes[keycode_count].protocol = strdup(protocol);
keymap->keycodes[keycode_count].scancode = scancode;
keymap->keycodes[keycode_count].keycode = strdup(keycode);
+ printf("\tMapping: protocol %s scancode 0x%08" PRIx64 " keycode %s\n",
+ protocol, scancode, keycode);
+
}
keycode_count++;
} else {
@@ -236,8 +246,18 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
if (keymap) {
if (!strcasecmp(tmp, "Blank"))
keymap->layout[layout_count] = NULL;
- else
- keymap->layout[layout_count] = &keymap->keycodes[1];
+ else {
+ for (i = 0; i < keycode_count; i++)
+ if (!strcasecmp(tmp, keymap->keycodes[i].keycode))
+ break;
+
+ if (i >= keycode_count) {
+ fprintf(stderr, "Invalid button keycode: %s\n", tmp);
+ return -EINVAL;
+ }
+
+ keymap->layout[layout_count] = &keymap->keycodes[i];
+ }
}
layout_count++;
@@ -321,6 +341,7 @@ keymap_read(int dfd, const char *name)
return NULL;
fd = -1;
+ printf("Parsing keymap %s\n", name);
r = keymap_parse(fp, &line, &buf_size, NULL, &rows, &cols, &keycode_count);
if (r < 0) {
fprintf(stderr, "Invalid keymap: %s\n", name);
@@ -337,7 +358,14 @@ keymap_read(int dfd, const char *name)
return NULL;
}
- keymap_parse(fp, &line, &buf_size, keymap, NULL, NULL, NULL);
+ r = keymap_parse(fp, &line, &buf_size, keymap, NULL, NULL, NULL);
+ if (r < 0) {
+ fprintf(stderr, "Invalid keymap: %s\n", name);
+ free(keymap->layout);
+ free(keymap);
+ return NULL;
+ }
+ printf("\tLayout: %u rows x %u cols = %u entries\n", rows, cols, rows * cols);
return keymap;
}