- struct udev_device *dev = event->dev;
- char temp[UTIL_PATH_SIZE];
- char temp2[UTIL_PATH_SIZE];
- char *head, *tail, *cpos, *attr, *rest;
- int len;
- int i;
- int count;
- enum subst_type {
- SUBST_UNKNOWN,
- SUBST_DEVPATH,
- SUBST_KERNEL,
- SUBST_KERNEL_NUMBER,
- SUBST_ID,
- SUBST_DRIVER,
- SUBST_MAJOR,
- SUBST_MINOR,
- SUBST_RESULT,
- SUBST_ATTR,
- SUBST_PARENT,
- SUBST_TEMP_NODE,
- SUBST_NAME,
- SUBST_LINKS,
- SUBST_ROOT,
- SUBST_SYS,
- SUBST_ENV,
- };
- static const struct subst_map {
- char *name;
- char fmt;
- enum subst_type type;
- } map[] = {
- { .name = "devpath", .fmt = 'p', .type = SUBST_DEVPATH },
- { .name = "number", .fmt = 'n', .type = SUBST_KERNEL_NUMBER },
- { .name = "kernel", .fmt = 'k', .type = SUBST_KERNEL },
- { .name = "id", .fmt = 'b', .type = SUBST_ID },
- { .name = "driver", .fmt = 'd', .type = SUBST_DRIVER },
- { .name = "major", .fmt = 'M', .type = SUBST_MAJOR },
- { .name = "minor", .fmt = 'm', .type = SUBST_MINOR },
- { .name = "result", .fmt = 'c', .type = SUBST_RESULT },
- { .name = "attr", .fmt = 's', .type = SUBST_ATTR },
- { .name = "sysfs", .fmt = 's', .type = SUBST_ATTR },
- { .name = "parent", .fmt = 'P', .type = SUBST_PARENT },
- { .name = "tempnode", .fmt = 'N', .type = SUBST_TEMP_NODE },
- { .name = "name", .fmt = 'D', .type = SUBST_NAME },
- { .name = "links", .fmt = 'L', .type = SUBST_LINKS },
- { .name = "root", .fmt = 'r', .type = SUBST_ROOT },
- { .name = "sys", .fmt = 'S', .type = SUBST_SYS },
- { .name = "env", .fmt = 'E', .type = SUBST_ENV },
- { NULL, '\0', 0 }
- };
- enum subst_type type;
- const struct subst_map *subst;
-
- head = string;
- while (1) {
- len = -1;
- while (head[0] != '\0') {
- if (head[0] == '$') {
- /* substitute named variable */
- if (head[1] == '\0')
- break;
- if (head[1] == '$') {
- util_strlcpy(temp, head+2, sizeof(temp));
- util_strlcpy(head+1, temp, maxsize);
- head++;
- continue;
- }
- head[0] = '\0';
- for (subst = map; subst->name; subst++) {
- if (strncasecmp(&head[1], subst->name, strlen(subst->name)) == 0) {
- type = subst->type;
- tail = head + strlen(subst->name)+1;
- dbg(event->udev, "will substitute format name '%s'\n", subst->name);
- goto found;
- }
- }
- head[0] = '$';
- err(event->udev, "unknown format variable '%s'\n", head);
- } else if (head[0] == '%') {
- /* substitute format char */
- if (head[1] == '\0')
- break;
- if (head[1] == '%') {
- util_strlcpy(temp, head+2, sizeof(temp));
- util_strlcpy(head+1, temp, maxsize);
- head++;
- continue;
- }
- head[0] = '\0';
- tail = head+1;
- len = get_format_len(event->udev, &tail);
- for (subst = map; subst->name; subst++) {
- if (tail[0] == subst->fmt) {
- type = subst->type;
- tail++;
- dbg(event->udev, "will substitute format char '%c'\n", subst->fmt);
- goto found;
- }
- }
- head[0] = '%';
- err(event->udev, "unknown format char '%c'\n", tail[0]);
- }
- head++;
- }
- break;
-found:
- attr = get_format_attribute(event->udev, &tail);
- util_strlcpy(temp, tail, sizeof(temp));
- dbg(event->udev, "format=%i, string='%s', tail='%s'\n", type ,string, tail);
-
- switch (type) {
- case SUBST_DEVPATH:
- util_strlcat(string, udev_device_get_devpath(dev), maxsize);
- dbg(event->udev, "substitute devpath '%s'\n", udev_device_get_devpath(dev));
- break;
- case SUBST_KERNEL:
- util_strlcat(string, udev_device_get_sysname(dev), maxsize);
- dbg(event->udev, "substitute kernel name '%s'\n", udev_device_get_sysname(dev));
- break;
- case SUBST_KERNEL_NUMBER:
- if (udev_device_get_sysnum(dev) == NULL)
- break;
- util_strlcat(string, udev_device_get_sysnum(dev), maxsize);
- dbg(event->udev, "substitute kernel number '%s'\n", udev_device_get_sysnum(dev));
- break;
- case SUBST_ID:
- if (event->dev_parent != NULL) {
- util_strlcat(string, udev_device_get_sysname(event->dev_parent), maxsize);
- dbg(event->udev, "substitute id '%s'\n", udev_device_get_sysname(event->dev_parent));
- }
- break;
- case SUBST_DRIVER:
- if (event->dev_parent != NULL) {
- const char *driver = udev_device_get_driver(event->dev_parent);