udev_rules_parse.c revision 594dd610252923591ed0f310695e82d3fb87e581
/*
*
* 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"
{
}
{
if (!rules)
return NULL;
dbg("no more rules");
return NULL;
}
/* get next rule */
return rule;
}
{
next:
dbg("no more rules");
return NULL;
}
goto next;
}
return rule;
}
{
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;
}
{
return 0;
}
{
err("skip, too many keys in a single rule");
return -1;
}
/* add the key-name of the pair */
return 0;
}
{
int valid;
char *linepos;
char *attr;
int retval;
/* get all the keys */
if (!rule) {
err("malloc failed");
return -1;
}
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;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
err("error parsing ENV attribute");
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
dbg("IMPORT will be executed");
dbg("IMPORT will be included as file");
dbg("IMPORT will include the parent values");
} else {
/* figure it out if it is executable */
char *pos;
if (pos)
pos[0] = '\0';
dbg("IMPORT is executable, will be executed (autotype)");
} else {
dbg("IMPORT is not executable, will be included as file (autotype)");
}
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
valid = 1;
continue;
}
dbg("creation of partition nodes requested");
}
dbg("remove event should be ignored");
}
}
if (value[0] == '\0') {
dbg("name empty device should be ignored");
} else
continue;
}
valid = 1;
continue;
}
valid = 1;
char *endptr;
if (endptr[0] != '\0') {
char owner[32];
continue;
}
}
continue;
}
valid = 1;
char *endptr;
if (endptr[0] != '\0') {
char group[32];
continue;
}
}
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;
}
}
/* skip line if not any valid key was found */
if (!valid) {
goto exit;
}
/* grow buffer and add rule */
err("realloc failed");
goto exit;
}
exit:
return 0;
}
{
char *bufline;
int lineno;
char *buf;
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';
}
return retval;
}
{
return -1;
}
return -1;
}
return 0;
}
{
int retval;
/* check for precompiled rules */
return 0;
}
return -1;
} else {
}
}
return retval;
}
{
else
}