_actions.c revision 1846
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <Python.h>
#include <string.h>
static PyObject *MalformedActionError;
static PyObject *InvalidActionError;
static int
{
if (contains == 0) {
} else if (contains == 1) {
if (PyList_Check(av)) {
return (ret);
} else {
return (-1);
return (ret);
}
} else if (contains == -1)
return (-1);
/* Shouldn't ever get here */
return (0);
}
static void *
{
}
return (NULL);
}
static void *
{
}
return (NULL);
}
/*ARGSUSED*/
static PyObject *
{
int strl;
char quote;
enum {
KEY, /* key */
UQVAL, /* unquoted value */
QVAL, /* quoted value */
WS /* whitespace */
} state;
#define CLEANUP_REFS \
Py_XDECREF(key);\
Py_XDECREF(type);\
Py_XDECREF(attr);\
Py_XDECREF(attrs);\
return (NULL);
}
i = strl;
if (s == NULL)
return (malformed("no attributes"));
return (NULL);
return (NULL);
}
return (malformed("whitespace in key"));
}
else {
if ((hash = PyString_FromStringAndSize(
return (NULL);
}
}
} else if (str[i] == '=') {
if ((key = PyString_FromStringAndSize(
return (NULL);
}
return (invalid("invalid key: 'data'"));
}
/*
* Pool attribute key to reduce memory usage and
* potentially improve lookup performance.
*/
if (i == ks) {
return (malformed("impossible: missing key"));
}
else if (++i == strl) {
return (malformed("missing value"));
}
vs = i + 1;
return (malformed("missing value"));
}
else {
vs = i;
}
return (malformed("quote in key"));
}
if (str[i] == '\\') {
if (i == strl - 1)
break;
/*
* "slashmap" is a simple bitmap (bytemap?)
* keeping track of what characters are
* backslashes that need to be removed
* from the final attribute string.
* All other bytes are NUL bytes.
*/
return (PyErr_NoMemory());
}
i++;
}
char *sattr;
int j, o, attrlen;
return (PyErr_NoMemory());
}
/*
* Copy the attribute from str into
* sattr, removing backslashes as
* slashmap indicates we should.
*/
for (j = 0, o = 0; j < attrlen; j++) {
if (slashmap[j] == '\\') {
o++;
continue;
}
}
if ((attr = PyString_FromStringAndSize(
return (NULL);
}
} else {
if ((attr = PyString_FromStringAndSize(
return (NULL);
}
}
return (NULL);
}
}
return (NULL);
}
}
ks = i;
if (str[i] == '=') {
return (malformed("missing key"));
}
}
}
}
return (malformed("unfinished quoted value"));
}
return (malformed("missing value"));
}
return (NULL);
}
}
return (ret);
}
static PyMethodDef methods[] = {
};
init_actions(void)
{
return;
/*
* We need to retrieve the MalformedActionError object from pkg.actions.
* We can't import pkg.actions directly, because that would result in a
* circular dependency. But the "sys" module has a dict called
* "modules" which maps loaded module names to the corresponding module
* objects. We can then grab the exception from those objects.
*/
return;
return;
== NULL) {
/* No exception is set */
return;
}
}