PyObject* info( int type, const char *name) { PyObject* output = NULL; switch(type) { /* display requested info */ case TYPE: output = get_types(name, policy); break; case ATTRIBUTE: output = get_attribs(name, policy); break; case ROLE: output = get_roles(name, policy); break; case USER: output = get_users(name, policy); break; case CLASS: output = get_classes(name, policy); break; case BOOLEAN: output = get_booleans(name, policy); break; case PORT: output = get_ports(name, policy); break; default: errno = EINVAL; PyErr_SetString(PyExc_RuntimeError,strerror(errno)); break; } return output; }
static int show_sysfs_attribs(struct rc_device *rc_dev) { static struct sysfs_names *names, *cur; int fd; names = find_device(NULL); if (!names) return -1; for (cur = names; cur->next; cur = cur->next) { if (cur->name) { if (get_attribs(rc_dev, cur->name)) return -1; fprintf(stderr, "Found %s (%s) with:\n", rc_dev->sysfs_name, rc_dev->input_name); fprintf(stderr, "\tDriver %s, table %s\n", rc_dev->drv_name, rc_dev->keytable_name); fprintf(stderr, "\tSupported protocols: "); show_proto(rc_dev->supported); fprintf(stderr, "\n\t"); display_proto(rc_dev); fd = open(rc_dev->input_name, O_RDONLY); if (fd > 0) { device_info(fd, "\t"); show_evdev_attribs(fd); close(fd); } else { printf("\tExtra capabilities: <access denied>\n"); } } } return 0; }
int main(int argc, char *argv[]) { int dev_from_class = 0, write_cnt; int fd; static struct sysfs_names *names; struct rc_device rc_dev; argp_parse(&argp, argc, argv, 0, 0, 0); /* Just list all devices */ if (!clear && !readtable && !keys.next && !ch_proto && !cfg.next && !test && !delay && !period) { if (devicename) { fd = open(devicename, O_RDONLY); if (fd < 0) { perror("Can't open device"); return -1; } device_info(fd, ""); close(fd); return 0; } if (show_sysfs_attribs(&rc_dev)) return -1; return 0; } if (cfg.next && (clear || keys.next || ch_proto || devicename)) { fprintf (stderr, "Auto-mode can be used only with --read, --debug and --sysdev options\n"); return -1; } if (!devicename) { names = find_device(devclass); if (!names) return -1; rc_dev.sysfs_name = names->name; if (get_attribs(&rc_dev, names->name)) { free_names(names); return -1; } names->name = NULL; free_names(names); devicename = rc_dev.input_name; dev_from_class++; } if (cfg.next) { struct cfgfile *cur; char *fname, *name; int rc; for (cur = &cfg; cur->next; cur = cur->next) { if ((!rc_dev.drv_name || strcasecmp(cur->driver, rc_dev.drv_name)) && strcasecmp(cur->driver, "*")) continue; if ((!rc_dev.keytable_name || strcasecmp(cur->table, rc_dev.keytable_name)) && strcasecmp(cur->table, "*")) continue; break; } if (!cur->next) { if (debug) fprintf(stderr, "Table for %s, %s not found. Keep as-is\n", rc_dev.drv_name, rc_dev.keytable_name); return 0; } if (debug) fprintf(stderr, "Table for %s, %s is on %s file.\n", rc_dev.drv_name, rc_dev.keytable_name, cur->fname); if (cur->fname[0] == '/' || ((cur->fname[0] == '.') && strchr(cur->fname, '/'))) { fname = cur->fname; rc = parse_keyfile(fname, &name); if (rc < 0) { fprintf(stderr, "Can't load %s table\n", fname); return -1; } } else { fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_USER_DIR) + 2); strcpy(fname, IR_KEYTABLE_USER_DIR); strcat(fname, "/"); strcat(fname, cur->fname); rc = parse_keyfile(fname, &name); if (rc != 0) { fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_SYSTEM_DIR) + 2); strcpy(fname, IR_KEYTABLE_SYSTEM_DIR); strcat(fname, "/"); strcat(fname, cur->fname); rc = parse_keyfile(fname, &name); } if (rc != 0) { fprintf(stderr, "Can't load %s table from %s or %s\n", cur->fname, IR_KEYTABLE_USER_DIR, IR_KEYTABLE_SYSTEM_DIR); return -1; } } if (!keys.next) { fprintf(stderr, "Empty table %s\n", fname); return -1; } clear = 1; } if (debug) fprintf(stderr, "Opening %s\n", devicename); fd = open(devicename, O_RDONLY); if (fd < 0) { perror(devicename); return -1; } if (dev_from_class) free(devicename); if (get_input_protocol_version(fd)) return -1; /* * First step: clear, if --clear is specified */ if (clear) { clear_table(fd); fprintf(stderr, "Old keytable cleared\n"); } /* * Second step: stores key tables from file or from commandline */ write_cnt = add_keys(fd); if (write_cnt) fprintf(stderr, "Wrote %d keycode(s) to driver\n", write_cnt); /* * Third step: change protocol */ if (ch_proto) { rc_dev.current = ch_proto; if (set_proto(&rc_dev)) fprintf(stderr, "Couldn't change the IR protocols\n"); else { fprintf(stderr, "Protocols changed to "); show_proto(rc_dev.current); fprintf(stderr, "\n"); } } /* * Fourth step: display current keytable */ if (readtable) display_table(&rc_dev, fd); /* * Fiveth step: change repeat rate/delay */ if (delay || period) { unsigned int new_delay, new_period; get_rate(fd, &new_delay, &new_period); if (delay) new_delay = delay; if (period) new_period = period; set_rate(fd, new_delay, new_period); } if (test) test_event(fd); return 0; }
int main(int argc, char *argv[]) { int dev_from_class = 0, write_cnt; int fd; static struct sysfs_names *names; struct rc_device rc_dev; argp_parse(&argp, argc, argv, 0, 0, 0); /* Just list all devices */ if (!clear && !read && !keys.next && !ch_proto && !cfg.next) { static struct sysfs_names *names, *cur; names = find_device(NULL); if (!names) return -1; for (cur = names; cur->next; cur = cur->next) { if (cur->name) { if (get_attribs(&rc_dev, cur->name)) return -1; fprintf(stderr, "Found %s (%s) with:\n", rc_dev.sysfs_name, rc_dev.input_name); fprintf(stderr, "\tDriver %s, %s decoder, table %s\n", rc_dev.drv_name, (rc_dev.type == SOFTWARE_DECODER) ? "raw software" : "hardware", rc_dev.keytable_name); fprintf(stderr, "\tSupported protocols: "); show_proto(rc_dev.supported); fprintf(stderr, "\t"); display_proto(&rc_dev); } } return 0; } if (cfg.next && (clear || keys.next || ch_proto || devname)) { fprintf (stderr, "Auto-mode can be used only with --read, --debug and --sysdev options\n"); return -1; } if (!devname) { names = find_device(devclass); if (!names) return -1; rc_dev.sysfs_name = names->name; if (get_attribs(&rc_dev, names->name)) { free_names(names); return -1; } names->name = NULL; free_names(names); devname = rc_dev.input_name; dev_from_class++; } if (cfg.next) { struct cfgfile *cur; char *fname, *name; int rc; for (cur = &cfg; cur->next; cur = cur->next) { if (strcasecmp(cur->driver, rc_dev.drv_name) && strcasecmp(cur->driver, "*")) continue; if (strcasecmp(cur->table, rc_dev.keytable_name) && strcasecmp(cur->table, "*")) continue; break; } if (!cur->next) { if (debug) fprintf(stderr, "Table for %s, %s not found. Keep as-is\n", rc_dev.drv_name, rc_dev.keytable_name); return 0; } if (debug) fprintf(stderr, "Table for %s, %s is on %s file.\n", rc_dev.drv_name, rc_dev.keytable_name, cur->fname); if (cur->fname[0] == '/' || ((cur->fname[0] == '.') && strchr(cur->fname, '/'))) { fname = cur->fname; } else { fname = malloc(strlen(cur->fname) + strlen(CFGDIR) + 2); strcpy(fname, CFGDIR); strcat(fname, "/"); strcat(fname, cur->fname); } rc = parse_keyfile(fname, &name); if (rc < 0 || !keys.next) { fprintf(stderr, "Can't load %s table or empty table\n", fname); return -1; } clear = 1; } if (debug) fprintf(stderr, "Opening %s\n", devname); fd = open(devname, O_RDONLY); if (fd < 0) { perror(devname); return -1; } if (dev_from_class) free(devname); /* * First step: clear, if --clear is specified */ if (clear) { clear_table(fd); fprintf(stderr, "Old keytable cleared\n"); } /* * Second step: stores key tables from file or from commandline */ write_cnt = add_keys(fd); if (write_cnt) fprintf(stderr, "Wrote %d keycode(s) to driver\n", write_cnt); /* * Third step: change protocol */ if (ch_proto) { rc_dev.current = ch_proto; if (set_proto(&rc_dev)) fprintf(stderr, "Couldn't change the IR protocols\n"); else { fprintf(stderr, "Protocols changed to "); show_proto(rc_dev.current); fprintf(stderr, "\n"); } } /* * Fourth step: display current keytable */ if (read) display_table(&rc_dev, fd); return 0; }