udev_rules_parse.c revision 319c6700165dc38d7f813ff646bff0196f2aafe6
/*
*
* Userspace devfs
*
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2003-2005 Kay Sievers <kay.sievers@vrfy.org>
*
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "logging.h"
#include "udev_rules.h"
/* rules parsed from .rules files*/
static LIST_HEAD(rules_list);
static struct list_head *rules_list_current;
/* mapped compiled rules stored on disk */
static size_t rules_array_current;
static size_t rules_array_size = 0;
static size_t rules_count = 0;
int udev_rules_iter_init(void)
{
rules_array_current = 0;
return 0;
}
struct udev_rule *udev_rules_iter_next(void)
{
if (rules_array) {
if (rules_array_current >= rules_count)
return NULL;
} else {
if (rules_list_current == &rules_list)
return NULL;
}
return rule;
}
{
return -ENOMEM;
dbg("name='%s', symlink='%s', bus='%s', id='%s', "
"sysfs_file[0]='%s', sysfs_value[0]='%s', "
"kernel='%s', program='%s', result='%s', "
"owner='%s', group='%s', mode=%#o, "
"all_partions=%u, ignore_remove=%u, ignore_device=%u, last_rule=%u",
return 0;
}
{
char *linepos;
char *temp;
if (!linepos)
return -1;
/* skip whitespace */
linepos++;
/* get the key */
while (1) {
linepos++;
if (linepos[0] == '\0')
return -1;
break;
if (linepos[0] == '=')
break;
if (linepos[0] == '+')
break;
if (linepos[0] == '!')
break;
if (linepos[0] == ':')
break;
}
/* remember end of key */
/* skip whitespace after key */
linepos++;
/* get operation type */
linepos += 2;
dbg("operator=match");
linepos += 2;
dbg("operator=nomatch");
*operation = KEY_OP_ADD;
linepos += 2;
dbg("operator=add");
} else if (linepos[0] == '=') {
linepos++;
dbg("operator=assign");
linepos += 2;
dbg("operator=assign_final");
} else
return -1;
/* terminate key */
temp[0] = '\0';
/* skip whitespace after operator */
linepos++;
/* get the value*/
if (linepos[0] == '"')
linepos++;
else
return -1;
if (!temp)
return -1;
temp[0] = '\0';
temp++;
/* move line to next key */
return 0;
}
/* extract possible KEY{attr} */
static char *get_key_attribute(char *str)
{
char *pos;
char *attr;
attr++;
err("missing closing brace for format");
return NULL;
}
pos[0] = '\0';
return attr;
}
return NULL;
}
static int rules_parse(const char *filename)
{
char *bufline;
int lineno;
char *linepos;
char *attr;
char *buf;
int program_given = 0;
int valid;
int retval = 0;
return -1;
}
/* loop through the whole file */
cur = 0;
lineno = 0;
unsigned int i, j;
lineno++;
continue;
}
/* eat the whitespace */
bufline++;
count--;
}
if (count == 0)
continue;
/* see if this is a comment */
if (bufline[0] == COMMENT_CHARACTER)
continue;
/* skip backslash and newline from multi line rules */
for (i = j = 0; i < count; i++) {
continue;
}
line[j] = '\0';
/* get all known keys */
valid = 0;
while (1) {
char *key;
char *value;
if (retval)
break;
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
goto error;
}
goto error;
}
valid = 1;
continue;
}
goto error;
}
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
program_given = 1;
valid = 1;
continue;
}
dbg("creation of partition nodes requested");
}
dbg("remove event should be ignored");
}
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
dbg("last rule to be applied");
}
dbg("device should be ignored");
}
dbg("remove event should be ignored");
}
dbg("creation of partition nodes requested");
}
valid = 1;
continue;
}
goto error;
}
/* skip line if not any valid key was found */
if (!valid)
goto error;
goto error;
}
if (retval) {
continue;
err("parse error %s, line %d:%d, rule skipped",
}
}
return retval;
}
{
char *buf;
return -1;
if (size == 0)
return -1;
return 0;
}
int udev_rules_init(void)
{
int retval;
}
return -1;
} else {
}
}
return retval;
}
void udev_rules_close(void)
{
if (rules_array)
else
}
}