code:
/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
   See the file src/contrib/expat/COPYING for copying permission.
*/

#ifndef Expat_INCLUDED
#define Expat_INCLUDED 1

#include <stdlib.h>
#include "bsdxml_external.h"

#ifdef __cplusplus
extern "C" {
#endif

struct XML_ParserStruct;
typedef struct XML_ParserStruct *XML_Parser;

/* Should this be defined using stdbool.h when C99 is available? */
typedef unsigned char XML_Bool;
#define XML_TRUE   ((XML_Bool) 1)
#define XML_FALSE  ((XML_Bool) 0)

/* The XML_Status enum gives the possible return values for several
   API functions.  The preprocessor #defines are included so this
   stanza can be added to code that still needs to support older
   versions of Expat 1.95.x:

   #ifndef XML_STATUS_OK
   #define XML_STATUS_OK    1
   #define XML_STATUS_ERROR 0
   #endif

   Otherwise, the #define hackery is quite ugly and would have been
   dropped.
*/
enum XML_Status {
  XML_STATUS_ERROR = 0,
#define XML_STATUS_ERROR XML_STATUS_ERROR
  XML_STATUS_OK = 1,
#define XML_STATUS_OK XML_STATUS_OK
  XML_STATUS_SUSPENDED = 2
#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED
};

enum XML_Error {
  XML_ERROR_NONE,
  XML_ERROR_NO_MEMORY,
  XML_ERROR_SYNTAX,
  XML_ERROR_NO_ELEMENTS,
  XML_ERROR_INVALID_TOKEN,
  XML_ERROR_UNCLOSED_TOKEN,
  XML_ERROR_PARTIAL_CHAR,
  XML_ERROR_TAG_MISMATCH,
  XML_ERROR_DUPLICATE_ATTRIBUTE,
  XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
  XML_ERROR_PARAM_ENTITY_REF,
  XML_ERROR_UNDEFINED_ENTITY,
  XML_ERROR_RECURSIVE_ENTITY_REF,
  XML_ERROR_ASYNC_ENTITY,
  XML_ERROR_BAD_CHAR_REF,
  XML_ERROR_BINARY_ENTITY_REF,
  XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
  XML_ERROR_MISPLACED_XML_PI,
  XML_ERROR_UNKNOWN_ENCODING,
  XML_ERROR_INCORRECT_ENCODING,
  XML_ERROR_UNCLOSED_CDATA_SECTION,
  XML_ERROR_EXTERNAL_ENTITY_HANDLING,
  XML_ERROR_NOT_STANDALONE,
  XML_ERROR_UNEXPECTED_STATE,
  XML_ERROR_ENTITY_DECLARED_IN_PE,
  XML_ERROR_FEATURE_REQUIRES_XML_DTD,
  XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
  /* Added in 1.95.7. */
  XML_ERROR_UNBOUND_PREFIX,
  /* Added in 1.95.8. */
  XML_ERROR_UNDECLARING_PREFIX,
  XML_ERROR_INCOMPLETE_PE,
  XML_ERROR_XML_DECL,
  XML_ERROR_TEXT_DECL,
  XML_ERROR_PUBLICID,
  XML_ERROR_SUSPENDED,
  XML_ERROR_NOT_SUSPENDED,
  XML_ERROR_ABORTED,
  XML_ERROR_FINISHED,
  XML_ERROR_SUSPEND_PE,
  /* Added in 2.0. */
  XML_ERROR_RESERVED_PREFIX_XML,
  XML_ERROR_RESERVED_PREFIX_XMLNS,
  XML_ERROR_RESERVED_NAMESPACE_URI
};

enum XML_Content_Type {
  XML_CTYPE_EMPTY = 1,
  XML_CTYPE_ANY,
  XML_CTYPE_MIXED,
  XML_CTYPE_NAME,
  XML_CTYPE_CHOICE,
  XML_CTYPE_SEQ
};

enum XML_Content_Quant {
  XML_CQUANT_NONE,
  XML_CQUANT_OPT,
  XML_CQUANT_REP,
  XML_CQUANT_PLUS
};

/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
   XML_CQUANT_NONE, and the other fields will be zero or NULL.
   If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
   numchildren will contain number of elements that may be mixed in
   and children point to an array of XML_Content cells that will be
   all of XML_CTYPE_NAME type with no quantification.

   If type == XML_CTYPE_NAME, then the name points to the name, and
   the numchildren field will be zero and children will be NULL. The
   quant fields indicates any quantifiers placed on the name.

   CHOICE and SEQ will have name NULL, the number of children in
   numchildren and children will point, recursively, to an array
   of XML_Content cells.

   The EMPTY, ANY, and MIXED types will only occur at top level.
*/

typedef struct XML_cp XML_Content;

struct XML_cp {
  enum XML_Content_Type         type;
  enum XML_Content_Quant        quant;
  XML_Char *                    name;
  unsigned int                  numchildren;
  XML_Content *                 children;
};

/* This is called for an element declaration. See above for
   description of the model argument. It's the caller's responsibility
   to free model when finished with it.
*/
typedef void (XMLCALL *XML_ElementDeclHandler) (void *userData,
                                                const XML_Char *name,
                                                XML_Content *model);

XMLPARSEAPI(void)
XML_SetElementDeclHandler(XML_Parser parser,
                          XML_ElementDeclHandler eldecl);

/* The Attlist declaration handler is called for *each* attribute. So
   a single Attlist declaration with multiple attributes declared will
   generate multiple calls to this handler. The "default" parameter
   may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
   keyword. The "isrequired" parameter will be true and the default
   value will be NULL in the case of "#REQUIRED". If "isrequired" is
   true and default is non-NULL, then this is a "#FIXED" default.
*/
typedef void (XMLCALL *XML_AttlistDeclHandler) (
                                    void            *userData,
                                    const XML_Char  *elname,
                                    const XML_Char  *attname,
                                    const XML_Char  *att_type,
                                    const XML_Char  *dflt,
                                    int              isrequired);

XMLPARSEAPI(void)
XML_SetAttlistDeclHandler(XML_Parser parser,
                          XML_AttlistDeclHandler attdecl);

/* The XML declaration handler is called for *both* XML declarations
   and text declarations. The way to distinguish is that the version
   parameter will be NULL for text declarations. The encoding
   parameter may be NULL for XML declarations. The standalone
   parameter will be -1, 0, or 1 indicating respectively that there
   was no standalone parameter in the declaration, that it was given
   as no, or that it was given as yes.
*/
typedef void (XMLCALL *XML_XmlDeclHandler) (void           *userData,
                                            const XML_Char *version,
                                            const XML_Char *encoding,
                                            int             standalone);

XMLPARSEAPI(void)
XML_SetXmlDeclHandler(XML_Parser parser,
                      XML_XmlDeclHandler xmldecl);

typedef struct {
  void *(*malloc_fcn)(size_t size);
  void *(*realloc_fcn)(void *ptr, size_t size);
  void (*free_fcn)(void *ptr);
} XML_Memory_Handling_Suite;

/* Constructs a new parser; encoding is the encoding specified by the
   external protocol or NULL if there is none specified.
*/
XMLPARSEAPI(XML_Parser)
XML_ParserCreate(const XML_Char *encoding);

/* Constructs a new parser and namespace processor.  Element type
   names and attribute names that belong to a namespace will be
   expanded; unprefixed attribute names are never expanded; unprefixed
   element type names are expanded only if there is a default
   namespace. The expanded name is the concatenation of the namespace
   URI, the namespace separator character, and the local part of the
   name.  If the namespace separator is '\0' then the namespace URI
   and the local part will be concatenated without any separator.
   It is a programming error to use the separator '\0' with namespace
   triplets (see XML_SetReturnNSTriplet).
*/
XMLPARSEAPI(XML_Parser)
XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);

/* Constructs a new parser using the memory management suite referred to
   by memsuite. If memsuite is NULL, then use the standard library memory
   suite. If namespaceSeparator is non-NULL it creates a parser with
   namespace processing as described above. The character pointed at
   will serve as the namespace separator.

   All further memory operations used for the created parser will come from
   the given suite.
*/
XMLPARSEAPI(XML_Parser)
XML_ParserCreate_MM(const XML_Char *encoding,
                    const XML_Memory_Handling_Suite *memsuite,
                    const XML_Char *namespaceSeparator);

/* Prepare a parser object to be re-used.  This is particularly
   valuable when memory allocation overhead is disproportionatly high,
   such as when a large number of small documnents need to be parsed.
   All handlers are cleared from the parser, except for the
   unknownEncodingHandler. The parser's external state is re-initialized
   except for the values of ns and ns_triplets.

   Added in Expat 1.95.3.
*/
XMLPARSEAPI(XML_Bool)
XML_ParserReset(XML_Parser parser, const XML_Char *encoding);

/* atts is array of name/value pairs, terminated by 0;
   names and values are 0 terminated.
*/
typedef void (XMLCALL *XML_StartElementHandler) (void *userData,
                                                 const XML_Char *name,
                                                 const XML_Char **atts);

typedef void (XMLCALL *XML_EndElementHandler) (void *userData,
                                               const XML_Char *name);

/* s is not 0 terminated. */
typedef void (XMLCALL *XML_CharacterDataHandler) (void *userData,
                                                  const XML_Char *s,
                                                  int len);

/* target and data are 0 terminated */
typedef void (XMLCALL *XML_ProcessingInstructionHandler) (
                                                void *userData,
                                                const XML_Char *target,
                                                const XML_Char *data);

/* data is 0 terminated */
typedef void (XMLCALL *XML_CommentHandler) (void *userData,
                                            const XML_Char *data);

typedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData);
typedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData);

/* This is called for any characters in the XML document for which
   there is no applicable handler.  This includes both characters that
   are part of markup which is of a kind that is not reported
   (comments, markup declarations), or characters that are part of a
   construct which could be reported but for which no handler has been
   supplied. The characters are passed exactly as they were in the XML
   document except that they will be encoded in UTF-8 or UTF-16.
   Line boundaries are not normalized. Note that a byte order mark
   character is not passed to the default handler. There are no
   guarantees about how characters are divided between calls to the
   default handler: for example, a comment might be split between
   multiple calls.
*/
typedef void (XMLCALL *XML_DefaultHandler) (void *userData,
                                            const XML_Char *s,
                                            int len);

/* This is called for the start of the DOCTYPE declaration, before
   any DTD or internal subset is parsed.
*/
typedef void (XMLCALL *XML_StartDoctypeDeclHandler) (
                                            void *userData,
                                            const XML_Char *doctypeName,
                                            const XML_Char *sysid,
                                            const XML_Char *pubid,
                                            int has_internal_subset);

/* This is called for the start of the DOCTYPE declaration when the
   closing > is encountered, but after processing any external
   subset.
*/
typedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);

/* This is called for entity declarations. The is_parameter_entity
   argument will be non-zero if the entity is a parameter entity, zero
   otherwise.

   For internal entities (<!ENTITY foo "bar">), value will
   be non-NULL and systemId, publicID, and notationName will be NULL.
   The value string is NOT nul-terminated; the length is provided in
   the value_length argument. Since it is legal to have zero-length
   values, do not use this argument to test for internal entities.

   For external entities, value will be NULL and systemId will be
   non-NULL. The publicId argument will be NULL unless a public
   identifier was provided. The notationName argument will have a
   non-NULL value only for unparsed entity declarations.

   Note that is_parameter_entity can't be changed to XML_Bool, since
   that would break binary compatibility.
*/
typedef void (XMLCALL *XML_EntityDeclHandler) (
                              void *userData,
                              const XML_Char *entityName,
                              int is_parameter_entity,
                              const XML_Char *value,
                              int value_length,
                              const XML_Char *base,
                              const XML_Char *systemId,
                              const XML_Char *publicId,
                              const XML_Char *notationName);

XMLPARSEAPI(void)
XML_SetEntityDeclHandler(XML_Parser parser,
                         XML_EntityDeclHandler handler);

/* OBSOLETE -- OBSOLETE -- OBSOLETE
   This handler has been superceded by the EntityDeclHandler above.
   It is provided here for backward compatibility.

   This is called for a declaration of an unparsed (NDATA) entity.
   The base argument is whatever was set by XML_SetBase. The
   entityName, systemId and notationName arguments will never be
   NULL. The other arguments may be.
*/
typedef void (XMLCALL *XML_UnparsedEntityDeclHandler) (
                                    void *userData,
                                    const XML_Char *entityName,
                                    const XML_Char *base,
                                    const XML_Char *systemId,
                                    const XML_Char *publicId,
                                    const XML_Char *notationName);

/* This is called for a declaration of notation.  The base argument is
   whatever was set by XML_SetBase. The notationName will never be
   NULL.  The other arguments can be.
*/
typedef void (XMLCALL *XML_NotationDeclHandler) (
                                    void *userData,
                                    const XML_Char *notationName,
                                    const XML_Char *base,
                                    const XML_Char *systemId,
                                    const XML_Char *publicId);

/* When namespace processing is enabled, these are called once for
   each namespace declaration. The call to the start and end element
   handlers occur between the calls to the start and end namespace
   declaration handlers. For an xmlns attribute, prefix will be
   NULL.  For an xmlns="" attribute, uri will be NULL.
*/
typedef void (XMLCALL *XML_StartNamespaceDeclHandler) (
                                    void *userData,
                                    const XML_Char *prefix,
                                    const XML_Char *uri);

typedef void (XMLCALL *XML_EndNamespaceDeclHandler) (
                                    void *userData,
                                    const XML_Char *prefix);

/* This is called if the document is not standalone, that is, it has an
   external subset or a reference to a parameter entity, but does not
   have standalone="yes". If this handler returns XML_STATUS_ERROR,
   then processing will not continue, and the parser will return a
   XML_ERROR_NOT_STANDALONE error.
   If parameter entity parsing is enabled, then in addition to the
   conditions above this handler will only be called if the referenced
   entity was actually read.
*/
typedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData);

/* This is called for a reference to an external parsed general
   entity.  The referenced entity is not automatically parsed.  The
   application can parse it immediately or later using
   XML_ExternalEntityParserCreate.

   The parser argument is the parser parsing the entity containing the
   reference; it can be passed as the parser argument to
   XML_ExternalEntityParserCreate.  The systemId argument is the
   system identifier as specified in the entity declaration; it will
   not be NULL.

   The base argument is the system identifier that should be used as
   the base for resolving systemId if systemId was relative; this is
   set by XML_SetBase; it may be NULL.

   The publicId argument is the public identifier as specified in the
   entity declaration, or NULL if none was specified; the whitespace
   in the public identifier will have been normalized as required by
   the XML spec.

   The context argument specifies the parsing context in the format
   expected by the context argument to XML_ExternalEntityParserCreate;
   context is valid only until the handler returns, so if the
   referenced entity is to be parsed later, it must be copied.
   context is NULL only when the entity is a parameter entity.

   The handler should return XML_STATUS_ERROR if processing should not
   continue because of a fatal error in the handling of the external
   entity.  In this case the calling parser will return an
   XML_ERROR_EXTERNAL_ENTITY_HANDLING error.

   Note that unlike other handlers the first argument is the parser,
   not userData.
*/
typedef int (XMLCALL *XML_ExternalEntityRefHandler) (
                                    XML_Parser parser,
                                    const XML_Char *context,
                                    const XML_Char *base,
                                    const XML_Char *systemId,
                                    const XML_Char *publicId);

/* This is called in two situations:
   1) An entity reference is encountered for which no declaration
      has been read *and* this is not an error.
   2) An internal entity reference is read, but not expanded, because
      XML_SetDefaultHandler has been called.
   Note: skipped parameter entities in declarations and skipped general
         entities in attribute values cannot be reported, because
         the event would be out of sync with the reporting of the
         declarations or attribute values
*/
typedef void (XMLCALL *XML_SkippedEntityHandler) (
                                    void *userData,
                                    const XML_Char *entityName,
                                    int is_parameter_entity);

/* This structure is filled in by the XML_UnknownEncodingHandler to
   provide information to the parser about encodings that are unknown
   to the parser.

   The map[b] member gives information about byte sequences whose
   first byte is b.

   If map[b] is c where c is >= 0, then b by itself encodes the
   Unicode scalar value c.

   If map[b] is -1, then the byte sequence is malformed.

   If map[b] is -n, where n >= 2, then b is the first byte of an
   n-byte sequence that encodes a single Unicode scalar value.

   The data member will be passed as the first argument to the convert
   function.

   The convert function is used to convert multibyte sequences; s will
   point to a n-byte sequence where map[(unsigned char)*s] == -n.  The
   convert function must return the Unicode scalar value represented
   by this byte sequence or -1 if the byte sequence is malformed.

   The convert function may be NULL if the encoding is a single-byte
   encoding, that is if map[b] >= -1 for all bytes b.

   When the parser is finished with the encoding, then if release is
   not NULL, it will call release passing it the data member; once
   release has been called, the convert function will not be called
   again.

   Expat places certain restrictions on the encodings that are supported
   using this mechanism.

   1. Every ASCII character that can appear in a well-formed XML document,
      other than the characters

      $@\^`{}~

      must be represented by a single byte, and that byte must be the
      same byte that represents that character in ASCII.

   2. No character may require more than 4 bytes to encode.

   3. All characters encoded must have Unicode scalar values <=
      0xFFFF, (i.e., characters that would be encoded by surrogates in
      UTF-16 are  not allowed).  Note that this restriction doesn't
      apply to the built-in support for UTF-8 and UTF-16.

   4. No Unicode character may be encoded by more than one distinct
      sequence of bytes.
*/
typedef struct {
  int map[256];
  void *data;
  int (XMLCALL *convert)(void *data, const char *s);
  void (XMLCALL *release)(void *data);
} XML_Encoding;

/* This is called for an encoding that is unknown to the parser.

   The encodingHandlerData argument is that which was passed as the
   second argument to XML_SetUnknownEncodingHandler.

   The name argument gives the name of the encoding as specified in
   the encoding declaration.

   If the callback can provide information about the encoding, it must
   fill in the XML_Encoding structure, and return XML_STATUS_OK.
   Otherwise it must return XML_STATUS_ERROR.

   If info does not describe a suitable encoding, then the parser will
   return an XML_UNKNOWN_ENCODING error.
*/
typedef int (XMLCALL *XML_UnknownEncodingHandler) (
                                    void *encodingHandlerData,
                                    const XML_Char *name,
                                    XML_Encoding *info);

XMLPARSEAPI(void)
XML_SetElementHandler(XML_Parser parser,
                      XML_StartElementHandler start,
                      XML_EndElementHandler end);

XMLPARSEAPI(void)
XML_SetStartElementHandler(XML_Parser parser,
                           XML_StartElementHandler handler);

XMLPARSEAPI(void)
XML_SetEndElementHandler(XML_Parser parser,
                         XML_EndElementHandler handler);

XMLPARSEAPI(void)
XML_SetCharacterDataHandler(XML_Parser parser,
                            XML_CharacterDataHandler handler);

XMLPARSEAPI(void)
XML_SetProcessingInstructionHandler(XML_Parser parser,
                                    XML_ProcessingInstructionHandler handler);
XMLPARSEAPI(void)
XML_SetCommentHandler(XML_Parser parser,
                      XML_CommentHandler handler);

XMLPARSEAPI(void)
XML_SetCdataSectionHandler(XML_Parser parser,
                           XML_StartCdataSectionHandler start,
                           XML_EndCdataSectionHandler end);

XMLPARSEAPI(void)
XML_SetStartCdataSectionHandler(XML_Parser parser,
                                XML_StartCdataSectionHandler start);

XMLPARSEAPI(void)
XML_SetEndCdataSectionHandler(XML_Parser parser,
                              XML_EndCdataSectionHandler end);

/* This sets the default handler and also inhibits expansion of
   internal entities. These entity references will be passed to the
   default handler, or to the skipped entity handler, if one is set.
*/
XMLPARSEAPI(void)
XML_SetDefaultHandler(XML_Parser parser,
                      XML_DefaultHandler handler);

/* This sets the default handler but does not inhibit expansion of
   internal entities.  The entity reference will not be passed to the
   default handler.
*/
XMLPARSEAPI(void)
XML_SetDefaultHandlerExpand(XML_Parser parser,
                            XML_DefaultHandler handler);

XMLPARSEAPI(void)
XML_SetDoctypeDeclHandler(XML_Parser parser,
                          XML_StartDoctypeDeclHandler start,
                          XML_EndDoctypeDeclHandler end);

XMLPARSEAPI(void)
XML_SetStartDoctypeDeclHandler(XML_Parser parser,
                               XML_StartDoctypeDeclHandler start);

XMLPARSEAPI(void)
XML_SetEndDoctypeDeclHandler(XML_Parser parser,
                             XML_EndDoctypeDeclHandler end);

XMLPARSEAPI(void)
XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
                                 XML_UnparsedEntityDeclHandler handler);

XMLPARSEAPI(void)
XML_SetNotationDeclHandler(XML_Parser parser,
                           XML_NotationDeclHandler handler);

XMLPARSEAPI(void)
XML_SetNamespaceDeclHandler(XML_Parser parser,
                            XML_StartNamespaceDeclHandler start,
                            XML_EndNamespaceDeclHandler end);

XMLPARSEAPI(void)
XML_SetStartNamespaceDeclHandler(XML_Parser parser,
                                 XML_StartNamespaceDeclHandler start);

XMLPARSEAPI(void)
XML_SetEndNamespaceDeclHandler(XML_Parser parser,
                               XML_EndNamespaceDeclHandler end);

XMLPARSEAPI(void)
XML_SetNotStandaloneHandler(XML_Parser parser,
                            XML_NotStandaloneHandler handler);

XMLPARSEAPI(void)
XML_SetExternalEntityRefHandler(XML_Parser parser,
                                XML_ExternalEntityRefHandler handler);

/* If a non-NULL value for arg is specified here, then it will be
   passed as the first argument to the external entity ref handler
   instead of the parser object.
*/
XMLPARSEAPI(void)
XML_SetExternalEntityRefHandlerArg(XML_Parser parser,
                                   void *arg);

XMLPARSEAPI(void)
XML_SetSkippedEntityHandler(XML_Parser parser,
                            XML_SkippedEntityHandler handler);

XMLPARSEAPI(void)
XML_SetUnknownEncodingHandler(XML_Parser parser,
                              XML_UnknownEncodingHandler handler,
                              void *encodingHandlerData);

/* This can be called within a handler for a start element, end
   element, processing instruction or character data.  It causes the
   corresponding markup to be passed to the default handler.
*/
XMLPARSEAPI(void)
XML_DefaultCurrent(XML_Parser parser);

/* If do_nst is non-zero, and namespace processing is in effect, and
   a name has a prefix (i.e. an explicit namespace qualifier) then
   that name is returned as a triplet in a single string separated by
   the separator character specified when the parser was created: URI
   + sep + local_name + sep + prefix.

   If do_nst is zero, then namespace information is returned in the
   default manner (URI + sep + local_name) whether or not the name
   has a prefix.

   Note: Calling XML_SetReturnNSTriplet after XML_Parse or
     XML_ParseBuffer has no effect.
*/

XMLPARSEAPI(void)
XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);

/* This value is passed as the userData argument to callbacks. */
XMLPARSEAPI(void)
XML_SetUserData(XML_Parser parser, void *userData);

/* Returns the last value set by XML_SetUserData or NULL. */
#define XML_GetUserData(parser) (*(void **)(parser))

/* This is equivalent to supplying an encoding argument to
   XML_ParserCreate. On success XML_SetEncoding returns non-zero,
   zero otherwise.
   Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer
     has no effect and returns XML_STATUS_ERROR.
*/
XMLPARSEAPI(enum XML_Status)
XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);

/* If this function is called, then the parser will be passed as the
   first argument to callbacks instead of userData.  The userData will
   still be accessible using XML_GetUserData.
*/
XMLPARSEAPI(void)
XML_UseParserAsHandlerArg(XML_Parser parser);

/* If useDTD == XML_TRUE is passed to this function, then the parser
   will assume that there is an external subset, even if none is
   specified in the document. In such a case the parser will call the
   externalEntityRefHandler with a value of NULL for the systemId
   argument (the publicId and context arguments will be NULL as well).
   Note: For the purpose of checking WFC: Entity Declared, passing
     useDTD == XML_TRUE will make the parser behave as if the document
     had a DTD with an external subset.
   Note: If this function is called, then this must be done before
     the first call to XML_Parse or XML_ParseBuffer, since it will
     have no effect after that.  Returns
     XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.
   Note: If the document does not have a DOCTYPE declaration at all,
     then startDoctypeDeclHandler and endDoctypeDeclHandler will not
     be called, despite an external subset being parsed.
   Note: If XML_DTD is not defined when Expat is compiled, returns
     XML_ERROR_FEATURE_REQUIRES_XML_DTD.
*/
XMLPARSEAPI(enum XML_Error)
XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);

/* Sets the base to be used for resolving relative URIs in system
   identifiers in declarations.  Resolving relative identifiers is
   left to the application: this value will be passed through as the
   base argument to the XML_ExternalEntityRefHandler,
   XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base
   argument will be copied.  Returns XML_STATUS_ERROR if out of memory,
   XML_STATUS_OK otherwise.
*/
XMLPARSEAPI(enum XML_Status)
XML_SetBase(XML_Parser parser, const XML_Char *base);

XMLPARSEAPI(const XML_Char *)
XML_GetBase(XML_Parser parser);

/* Returns the number of the attribute/value pairs passed in last call
   to the XML_StartElementHandler that were specified in the start-tag
   rather than defaulted. Each attribute/value pair counts as 2; thus
   this correspondds to an index into the atts array passed to the
   XML_StartElementHandler.
*/
XMLPARSEAPI(int)
XML_GetSpecifiedAttributeCount(XML_Parser parser);

/* Returns the index of the ID attribute passed in the last call to
   XML_StartElementHandler, or -1 if there is no ID attribute.  Each
   attribute/value pair counts as 2; thus this correspondds to an
   index into the atts array passed to the XML_StartElementHandler.
*/
XMLPARSEAPI(int)
XML_GetIdAttributeIndex(XML_Parser parser);

/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
   detected.  The last call to XML_Parse must have isFinal true; len
   may be zero for this call (or any other).

   Though the return values for these functions has always been
   described as a Boolean value, the implementation, at least for the
   1.95.x series, has always returned exactly one of the XML_Status
   values.
*/
XMLPARSEAPI(enum XML_Status)
XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);

XMLPARSEAPI(void *)
XML_GetBuffer(XML_Parser parser, int len);

XMLPARSEAPI(enum XML_Status)
XML_ParseBuffer(XML_Parser parser, int len, int isFinal);

/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.
   Must be called from within a call-back handler, except when aborting
   (resumable = 0) an already suspended parser. Some call-backs may
   still follow because they would otherwise get lost. Examples:
   - endElementHandler() for empty elements when stopped in
     startElementHandler(),
   - endNameSpaceDeclHandler() when stopped in endElementHandler(),
   and possibly others.

   Can be called from most handlers, including DTD related call-backs,
   except when parsing an external parameter entity and resumable != 0.
   Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.
   Possible error codes:
   - XML_ERROR_SUSPENDED: when suspending an already suspended parser.
   - XML_ERROR_FINISHED: when the parser has already finished.
   - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.

   When resumable != 0 (true) then parsing is suspended, that is,
   XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.
   Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()
   return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.

   *Note*:
   This will be applied to the current parser instance only, that is, if
   there is a parent parser then it will continue parsing when the
   externalEntityRefHandler() returns. It is up to the implementation of
   the externalEntityRefHandler() to call XML_StopParser() on the parent
   parser (recursively), if one wants to stop parsing altogether.

   When suspended, parsing can be resumed by calling XML_ResumeParser().
*/
XMLPARSEAPI(enum XML_Status)
XML_StopParser(XML_Parser parser, XML_Bool resumable);

/* Resumes parsing after it has been suspended with XML_StopParser().
   Must not be called from within a handler call-back. Returns same
   status codes as XML_Parse() or XML_ParseBuffer().
   Additional error code XML_ERROR_NOT_SUSPENDED possible.

   *Note*:
   This must be called on the most deeply nested child parser instance
   first, and on its parent parser only after the child parser has finished,
   to be applied recursively until the document entity's parser is restarted.
   That is, the parent parser will not resume by itself and it is up to the
   application to call XML_ResumeParser() on it at the appropriate moment.
*/
XMLPARSEAPI(enum XML_Status)
XML_ResumeParser(XML_Parser parser);

enum XML_Parsing {
  XML_INITIALIZED,
  XML_PARSING,
  XML_FINISHED,
  XML_SUSPENDED
};

typedef struct {
  enum XML_Parsing parsing;
  XML_Bool finalBuffer;
} XML_ParsingStatus;

/* Returns status of parser with respect to being initialized, parsing,
   finished, or suspended and processing the final buffer.
   XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,
   XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED
*/
XMLPARSEAPI(void)
XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);

/* Creates an XML_Parser object that can parse an external general
   entity; context is a '\0'-terminated string specifying the parse
   context; encoding is a '\0'-terminated string giving the name of
   the externally specified encoding, or NULL if there is no
   externally specified encoding.  The context string consists of a
   sequence of tokens separated by formfeeds (\f); a token consisting
   of a name specifies that the general entity of the name is open; a
   token of the form prefix=uri specifies the namespace for a
   particular prefix; a token of the form =uri specifies the default
   namespace.  This can be called at any point after the first call to
   an ExternalEntityRefHandler so longer as the parser has not yet
   been freed.  The new parser is completely independent and may
   safely be used in a separate thread.  The handlers and userData are
   initialized from the parser argument.  Returns NULL if out of memory.
   Otherwise returns a new XML_Parser object.
*/
XMLPARSEAPI(XML_Parser)
XML_ExternalEntityParserCreate(XML_Parser parser,
                               const XML_Char *context,
                               const XML_Char *encoding);

enum XML_ParamEntityParsing {
  XML_PARAM_ENTITY_PARSING_NEVER,
  XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
  XML_PARAM_ENTITY_PARSING_ALWAYS
};

/* Controls parsing of parameter entities (including the external DTD
   subset). If parsing of parameter entities is enabled, then
   references to external parameter entities (including the external
   DTD subset) will be passed to the handler set with
   XML_SetExternalEntityRefHandler.  The context passed will be 0.

   Unlike external general entities, external parameter entities can
   only be parsed synchronously.  If the external parameter entity is
   to be parsed, it must be parsed during the call to the external
   entity ref handler: the complete sequence of
   XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
   XML_ParserFree calls must be made during this call.  After
   XML_ExternalEntityParserCreate has been called to create the parser
   for the external parameter entity (context must be 0 for this
   call), it is illegal to make any calls on the old parser until
   XML_ParserFree has been called on the newly created parser.
   If the library has been compiled without support for parameter
   entity parsing (ie without XML_DTD being defined), then
   XML_SetParamEntityParsing will return 0 if parsing of parameter
   entities is requested; otherwise it will return non-zero.
   Note: If XML_SetParamEntityParsing is called after XML_Parse or
      XML_ParseBuffer, then it has no effect and will always return 0.
*/
XMLPARSEAPI(int)
XML_SetParamEntityParsing(XML_Parser parser,
                          enum XML_ParamEntityParsing parsing);

/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
   XML_GetErrorCode returns information about the error.
*/
XMLPARSEAPI(enum XML_Error)
XML_GetErrorCode(XML_Parser parser);

/* These functions return information about the current parse
   location.  They may be called from any callback called to report
   some parse event; in this case the location is the location of the
   first of the sequence of characters that generated the event.  When
   called from callbacks generated by declarations in the document
   prologue, the location identified isn't as neatly defined, but will
   be within the relevant markup.  When called outside of the callback
   functions, the position indicated will be just past the last parse
   event (regardless of whether there was an associated callback).

   They may also be called after returning from a call to XML_Parse
   or XML_ParseBuffer.  If the return value is XML_STATUS_ERROR then
   the location is the location of the character at which the error
   was detected; otherwise the location is the location of the last
   parse event, as described above.
*/
XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);
XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);
XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);

/* Return the number of bytes in the current event.
   Returns 0 if the event is in an internal entity.
*/
XMLPARSEAPI(int)
XML_GetCurrentByteCount(XML_Parser parser);

/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
   the integer pointed to by offset to the offset within this buffer
   of the current parse position, and sets the integer pointed to by size
   to the size of this buffer (the number of input bytes). Otherwise
   returns a NULL pointer. Also returns a NULL pointer if a parse isn't
   active.

   NOTE: The character pointer returned should not be used outside
   the handler that makes the call.
*/
XMLPARSEAPI(const char *)
XML_GetInputContext(XML_Parser parser,
                    int *offset,
                    int *size);

/* For backwards compatibility with previous versions. */
#define XML_GetErrorLineNumber   XML_GetCurrentLineNumber
#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
#define XML_GetErrorByteIndex    XML_GetCurrentByteIndex

/* Frees the content model passed to the element declaration handler */
XMLPARSEAPI(void)
XML_FreeContentModel(XML_Parser parser, XML_Content *model);

/* Exposing the memory handling functions used in Expat */
XMLPARSEAPI(void *)
XML_MemMalloc(XML_Parser parser, size_t size);

XMLPARSEAPI(void *)
XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);

XMLPARSEAPI(void)
XML_MemFree(XML_Parser parser, void *ptr);

/* Frees memory used by the parser. */
XMLPARSEAPI(void)
XML_ParserFree(XML_Parser parser);

/* Returns a string describing the error. */
XMLPARSEAPI(const XML_LChar *)
XML_ErrorString(enum XML_Error code);

/* Return a string containing the version number of this expat */
XMLPARSEAPI(const XML_LChar *)
XML_ExpatVersion(void);

typedef struct {
  int major;
  int minor;
  int micro;
} XML_Expat_Version;

/* Return an XML_Expat_Version structure containing numeric version
   number information for this version of expat.
*/
XMLPARSEAPI(XML_Expat_Version)
XML_ExpatVersionInfo(void);

/* Added in Expat 1.95.5. */
enum XML_FeatureEnum {
  XML_FEATURE_END = 0,
  XML_FEATURE_UNICODE,
  XML_FEATURE_UNICODE_WCHAR_T,
  XML_FEATURE_DTD,
  XML_FEATURE_CONTEXT_BYTES,
  XML_FEATURE_MIN_SIZE,
  XML_FEATURE_SIZEOF_XML_CHAR,
  XML_FEATURE_SIZEOF_XML_LCHAR,
  XML_FEATURE_NS,
  XML_FEATURE_LARGE_SIZE
  /* Additional features must be added to the end of this enum. */
};

typedef struct {
  enum XML_FeatureEnum  feature;
  const XML_LChar       *name;
  long int              value;
} XML_Feature;

XMLPARSEAPI(const XML_Feature *)
XML_GetFeatureList(void);

/* Expat follows the GNU/Linux convention of odd number minor version for
   beta/development releases and even number minor version for stable
   releases. Micro is bumped with each release, and set to 0 with each
   change to major or minor version.
*/
#define XML_MAJOR_VERSION 2
#define XML_MINOR_VERSION 0
#define XML_MICRO_VERSION 1

#ifdef __cplusplus
}
#endif

#endif /* not Expat_INCLUDED */


code:
/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
   See the file COPYING for copying permission.
*/

#ifndef Expat_External_INCLUDED
#define Expat_External_INCLUDED 1

/* External API definitions */

#if defined(_MSC_EXTENSIONS) && !defined(__BEOS__) && !defined(__CYGWIN__)
#define XML_USE_MSC_EXTENSIONS 1
#endif

/* Expat tries very hard to make the API boundary very specifically
   defined.  There are two macros defined to control this boundary;
   each of these can be defined before including this header to
   achieve some different behavior, but doing so it not recommended or
   tested frequently.

   XMLCALL    - The calling convention to use for all calls across the
                "library boundary."  This will default to cdecl, and
                try really hard to tell the compiler that's what we
                want.

   XMLIMPORT  - Whatever magic is needed to note that a function is
                to be imported from a dynamically loaded library
                (.dll, .so, or .sl, depending on your platform).

   The XMLCALL macro was added in Expat 1.95.7.  The only one which is
   expected to be directly useful in client code is XMLCALL.

   Note that on at least some Unix versions, the Expat library must be
   compiled with the cdecl calling convention as the default since
   system headers may assume the cdecl convention.
*/
#ifndef XMLCALL
#if defined(_MSC_VER)
#define XMLCALL __cdecl
#elif defined(__GNUC__) && defined(__i386) && !defined(__INTEL_COMPILER)
#define XMLCALL __attribute__((cdecl))
#else
/* For any platform which uses this definition and supports more than
   one calling convention, we need to extend this definition to
   declare the convention used on that platform, if it's possible to
   do so.

   If this is the case for your platform, please file a bug report
   with information on how to identify your platform via the C
   pre-processor and how to specify the same calling convention as the
   platform's malloc() implementation.
*/
#define XMLCALL
#endif
#endif  /* not defined XMLCALL */

#if !defined(XML_STATIC) && !defined(XMLIMPORT)
#ifndef XML_BUILDING_EXPAT
/* using Expat from an application */

#ifdef XML_USE_MSC_EXTENSIONS
#define XMLIMPORT __declspec(dllimport)
#endif

#endif
#endif  /* not defined XML_STATIC */

/* If we didn't define it above, define it away: */
#ifndef XMLIMPORT
#define XMLIMPORT
#endif

#define XMLPARSEAPI(type) XMLIMPORT type XMLCALL

#ifdef __cplusplus
extern "C" {
#endif

#ifdef XML_UNICODE_WCHAR_T
#define XML_UNICODE
#endif

#ifdef XML_UNICODE     /* Information is UTF-16 encoded. */
#ifdef XML_UNICODE_WCHAR_T
typedef wchar_t XML_Char;
typedef wchar_t XML_LChar;
#else
typedef unsigned short XML_Char;
typedef char XML_LChar;
#endif /* XML_UNICODE_WCHAR_T */
#else                  /* Information is UTF-8 encoded. */
typedef char XML_Char;
typedef char XML_LChar;
#endif /* XML_UNICODE */

#ifdef XML_LARGE_SIZE  /* Use large integers for file/stream positions. */
#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
typedef __int64 XML_Index;
typedef unsigned __int64 XML_Size;
#else
typedef long long XML_Index;
typedef unsigned long long XML_Size;
#endif
#else
typedef long XML_Index;
typedef unsigned long XML_Size;
#endif /* XML_LARGE_SIZE */

#ifdef __cplusplus
}
#endif

#endif /* not Expat_External_INCLUDED */

repo_name: veiledmerc/mira

license: mit


code:
/*-
 * Copyright (c) 2005-2009 Apple Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
 *     its contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit.h#10
 * $FreeBSD: release/9.0.0/sys/bsm/audit.h 195740 2009-07-17 14:02:20Z rwatson $
 */

#ifndef	_BSM_AUDIT_H
#define	_BSM_AUDIT_H

#include <sys/param.h>
#include <sys/types.h>

#define	AUDIT_RECORD_MAGIC	0x828a0f1b
#define	MAX_AUDIT_RECORDS	20
#define	MAXAUDITDATA		(0x8000 - 1)
#define	MAX_AUDIT_RECORD_SIZE	MAXAUDITDATA
#define	MIN_AUDIT_FILE_SIZE	(512 * 1024)

/*
 * Minimum noumber of free blocks on the filesystem containing the audit
 * log necessary to avoid a hard log rotation. DO NOT SET THIS VALUE TO 0
 * as the kernel does an unsigned compare, plus we want to leave a few blocks
 * free so userspace can terminate the log, etc.
 */
#define	AUDIT_HARD_LIMIT_FREE_BLOCKS	4

/*
 * Triggers for the audit daemon.
 */
#define	AUDIT_TRIGGER_MIN		1
#define	AUDIT_TRIGGER_LOW_SPACE		1	/* Below low watermark. */
#define	AUDIT_TRIGGER_ROTATE_KERNEL	2	/* Kernel requests rotate. */
#define	AUDIT_TRIGGER_READ_FILE		3	/* Re-read config file. */
#define	AUDIT_TRIGGER_CLOSE_AND_DIE	4	/* Terminate audit. */
#define	AUDIT_TRIGGER_NO_SPACE		5	/* Below min free space. */
#define	AUDIT_TRIGGER_ROTATE_USER	6	/* User requests rotate. */
#define	AUDIT_TRIGGER_INITIALIZE	7	/* User initialize of auditd. */
#define	AUDIT_TRIGGER_EXPIRE_TRAILS	8	/* User expiration of trails. */
#define	AUDIT_TRIGGER_MAX		8

/*
 * The special device filename (FreeBSD).
 */
#define	AUDITDEV_FILENAME	"audit"
#define	AUDIT_TRIGGER_FILE	("/dev/" AUDITDEV_FILENAME)

/*
 * Pre-defined audit IDs
 */
#define	AU_DEFAUDITID	(uid_t)(-1)
#define	AU_DEFAUDITSID	 0
#define	AU_ASSIGN_ASID	-1

/*
 * IPC types.
 */
#define	AT_IPC_MSG	((u_char)1)	/* Message IPC id. */
#define	AT_IPC_SEM	((u_char)2)	/* Semaphore IPC id. */
#define	AT_IPC_SHM	((u_char)3)	/* Shared mem IPC id. */

/*
 * Audit conditions.
 */
#define	AUC_UNSET		0
#define	AUC_AUDITING		1
#define	AUC_NOAUDIT		2
#define	AUC_DISABLED		-1

/*
 * auditon(2) commands.
 */
#define	A_OLDGETPOLICY	2
#define	A_OLDSETPOLICY	3
#define	A_GETKMASK	4
#define	A_SETKMASK	5
#define	A_OLDGETQCTRL	6
#define	A_OLDSETQCTRL	7
#define	A_GETCWD	8
#define	A_GETCAR	9
#define	A_GETSTAT	12
#define	A_SETSTAT	13
#define	A_SETUMASK	14
#define	A_SETSMASK	15
#define	A_OLDGETCOND	20
#define	A_OLDSETCOND	21
#define	A_GETCLASS	22
#define	A_SETCLASS	23
#define	A_GETPINFO	24
#define	A_SETPMASK	25
#define	A_SETFSIZE	26
#define	A_GETFSIZE	27
#define	A_GETPINFO_ADDR	28
#define	A_GETKAUDIT	29
#define	A_SETKAUDIT	30
#define	A_SENDTRIGGER	31
#define	A_GETSINFO_ADDR	32
#define	A_GETPOLICY	33
#define	A_SETPOLICY	34
#define	A_GETQCTRL	35
#define	A_SETQCTRL	36
#define	A_GETCOND	37
#define	A_SETCOND	38

/*
 * Audit policy controls.
 */
#define	AUDIT_CNT	0x0001
#define	AUDIT_AHLT	0x0002
#define	AUDIT_ARGV	0x0004
#define	AUDIT_ARGE	0x0008
#define	AUDIT_SEQ	0x0010
#define	AUDIT_WINDATA	0x0020
#define	AUDIT_USER	0x0040
#define	AUDIT_GROUP	0x0080
#define	AUDIT_TRAIL	0x0100
#define	AUDIT_PATH	0x0200
#define	AUDIT_SCNT	0x0400
#define	AUDIT_PUBLIC	0x0800
#define	AUDIT_ZONENAME	0x1000
#define	AUDIT_PERZONE	0x2000

/*
 * Default audit queue control parameters.
 */
#define	AQ_HIWATER	100
#define	AQ_MAXHIGH	10000
#define	AQ_LOWATER	10
#define	AQ_BUFSZ	MAXAUDITDATA
#define	AQ_MAXBUFSZ	1048576

/*
 * Default minimum percentage free space on file system.
 */
#define	AU_FS_MINFREE	20

/*
 * Type definitions used indicating the length of variable length addresses
 * in tokens containing addresses, such as header fields.
 */
#define	AU_IPv4		4
#define	AU_IPv6		16

__BEGIN_DECLS

typedef	uid_t		au_id_t;
typedef	pid_t		au_asid_t;
typedef	u_int16_t	au_event_t;
typedef	u_int16_t	au_emod_t;
typedef	u_int32_t	au_class_t;
typedef	u_int64_t	au_asflgs_t __attribute__ ((aligned (8)));

struct au_tid {
	dev_t		port;
	u_int32_t	machine;
};
typedef	struct au_tid	au_tid_t;

struct au_tid_addr {
	dev_t		at_port;
	u_int32_t	at_type;
	u_int32_t	at_addr[4];
};
typedef	struct au_tid_addr	au_tid_addr_t;

struct au_mask {
	unsigned int    am_success;     /* Success bits. */
	unsigned int    am_failure;     /* Failure bits. */
};
typedef	struct au_mask	au_mask_t;

struct auditinfo {
	au_id_t		ai_auid;	/* Audit user ID. */
	au_mask_t	ai_mask;	/* Audit masks. */
	au_tid_t	ai_termid;	/* Terminal ID. */
	au_asid_t	ai_asid;	/* Audit session ID. */
};
typedef	struct auditinfo	auditinfo_t;

struct auditinfo_addr {
	au_id_t		ai_auid;	/* Audit user ID. */
	au_mask_t	ai_mask;	/* Audit masks. */
	au_tid_addr_t	ai_termid;	/* Terminal ID. */
	au_asid_t	ai_asid;	/* Audit session ID. */
	au_asflgs_t	ai_flags;	/* Audit session flags. */
};
typedef	struct auditinfo_addr	auditinfo_addr_t;

struct auditpinfo {
	pid_t		ap_pid;		/* ID of target process. */
	au_id_t		ap_auid;	/* Audit user ID. */
	au_mask_t	ap_mask;	/* Audit masks. */
	au_tid_t	ap_termid;	/* Terminal ID. */
	au_asid_t	ap_asid;	/* Audit session ID. */
};
typedef	struct auditpinfo	auditpinfo_t;

struct auditpinfo_addr {
	pid_t		ap_pid;		/* ID of target process. */
	au_id_t		ap_auid;	/* Audit user ID. */
	au_mask_t	ap_mask;	/* Audit masks. */
	au_tid_addr_t	ap_termid;	/* Terminal ID. */
	au_asid_t	ap_asid;	/* Audit session ID. */
	au_asflgs_t	ap_flags;	/* Audit session flags. */
};
typedef	struct auditpinfo_addr	auditpinfo_addr_t;

struct au_session {
	auditinfo_addr_t	*as_aia_p;	/* Ptr to full audit info. */
	au_mask_t		 as_mask;	/* Process Audit Masks. */
};
typedef struct au_session       au_session_t;

/*
 * Contents of token_t are opaque outside of libbsm.
 */
typedef	struct au_token	token_t;

/*
 * Kernel audit queue control parameters:
 * 			Default:		Maximum:
 * 	aq_hiwater:	AQ_HIWATER (100)	AQ_MAXHIGH (10000)
 * 	aq_lowater:	AQ_LOWATER (10)		<aq_hiwater
 * 	aq_bufsz:	AQ_BUFSZ (32767)	AQ_MAXBUFSZ (1048576)
 * 	aq_delay:	20			20000 (not used)
 */
struct au_qctrl {
	int	aq_hiwater;	/* Max # of audit recs in queue when */
				/* threads with new ARs get blocked. */

	int	aq_lowater;	/* # of audit recs in queue when */
				/* blocked threads get unblocked. */

	int	aq_bufsz;	/* Max size of audit record for audit(2). */
	int	aq_delay;	/* Queue delay (not used). */
	int	aq_minfree;	/* Minimum filesystem percent free space. */
};
typedef	struct au_qctrl	au_qctrl_t;

/*
 * Structure for the audit statistics.
 */
struct audit_stat {
	unsigned int	as_version;
	unsigned int	as_numevent;
	int		as_generated;
	int		as_nonattrib;
	int		as_kernel;
	int		as_audit;
	int		as_auditctl;
	int		as_enqueue;
	int		as_written;
	int		as_wblocked;
	int		as_rblocked;
	int		as_dropped;
	int		as_totalsize;
	unsigned int	as_memused;
};
typedef	struct audit_stat	au_stat_t;

/*
 * Structure for the audit file statistics.
 */
struct audit_fstat {
	u_int64_t	af_filesz;
	u_int64_t	af_currsz;
};
typedef	struct audit_fstat	au_fstat_t;

/*
 * Audit to event class mapping.
 */
struct au_evclass_map {
	au_event_t	ec_number;
	au_class_t	ec_class;
};
typedef	struct au_evclass_map	au_evclass_map_t;

/*
 * Audit system calls.
 */
#if !defined(_KERNEL) && !defined(KERNEL)
int	audit(const void *, int);
int	auditon(int, void *, int);
int	auditctl(const char *);
int	getauid(au_id_t *);
int	setauid(const au_id_t *);
int	getaudit(struct auditinfo *);
int	setaudit(const struct auditinfo *);
int	getaudit_addr(struct auditinfo_addr *, int);
int	setaudit_addr(const struct auditinfo_addr *, int);

#ifdef __APPLE_API_PRIVATE
#include <mach/port.h>
mach_port_name_t audit_session_self(void);
au_asid_t	 audit_session_join(mach_port_name_t port);
#endif /* __APPLE_API_PRIVATE */

#endif /* defined(_KERNEL) || defined(KERNEL) */

__END_DECLS

#endif /* !_BSM_AUDIT_H */


code:
/*-
 * Copyright (c) 2008 Apple Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
 *     its contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_domain.h#2
 * $FreeBSD: release/9.0.0/sys/bsm/audit_domain.h 191273 2009-04-19 16:17:13Z rwatson $
 */

#ifndef _BSM_AUDIT_DOMAIN_H_
#define	_BSM_AUDIT_DOMAIN_H_

/*
 * BSM protocol domain constants - protocol domains defined in Solaris.
 */
#define	BSM_PF_UNSPEC		0
#define	BSM_PF_LOCAL		1
#define	BSM_PF_INET		2
#define	BSM_PF_IMPLINK		3
#define	BSM_PF_PUP		4
#define	BSM_PF_CHAOS		5
#define	BSM_PF_NS		6
#define	BSM_PF_NBS		7	/* Solaris-specific. */
#define	BSM_PF_ECMA		8
#define	BSM_PF_DATAKIT		9
#define	BSM_PF_CCITT		10
#define	BSM_PF_SNA		11
#define	BSM_PF_DECnet		12
#define	BSM_PF_DLI		13
#define	BSM_PF_LAT		14
#define	BSM_PF_HYLINK		15
#define	BSM_PF_APPLETALK	16
#define	BSM_PF_NIT		17	/* Solaris-specific. */
#define	BSM_PF_802		18	/* Solaris-specific. */
#define	BSM_PF_OSI		19
#define	BSM_PF_X25		20	/* Solaris/Linux-specific. */
#define	BSM_PF_OSINET		21	/* Solaris-specific. */
#define	BSM_PF_GOSIP		22	/* Solaris-specific. */
#define	BSM_PF_IPX		23
#define	BSM_PF_ROUTE		24
#define	BSM_PF_LINK		25
#define	BSM_PF_INET6		26
#define	BSM_PF_KEY		27
#define	BSM_PF_NCA		28	/* Solaris-specific. */
#define	BSM_PF_POLICY		29	/* Solaris-specific. */
#define	BSM_PF_INET_OFFLOAD	30	/* Solaris-specific. */

/*
 * BSM protocol domain constants - protocol domains not defined in Solaris.
 */
#define	BSM_PF_NETBIOS		500	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_ISO		501	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_XTP		502	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_COIP		503	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_CNT		504	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_RTIP		505	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_SIP		506	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_PIP		507	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_ISDN		508	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_E164		509	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_NATM		510	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_ATM		511	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_NETGRAPH		512	/* FreeBSD/Darwin-specific. */
#define	BSM_PF_SLOW		513	/* FreeBSD-specific. */
#define	BSM_PF_SCLUSTER		514	/* FreeBSD-specific. */
#define	BSM_PF_ARP		515	/* FreeBSD-specific. */
#define	BSM_PF_BLUETOOTH	516	/* FreeBSD-specific. */
					/* 517: unallocated. */
#define	BSM_PF_AX25		518	/* Linux-specific. */
#define	BSM_PF_ROSE		519	/* Linux-specific. */
#define	BSM_PF_NETBEUI		520	/* Linux-specific. */
#define	BSM_PF_SECURITY		521	/* Linux-specific. */
#define	BSM_PF_PACKET		522	/* Linux-specific. */
#define	BSM_PF_ASH		523	/* Linux-specific. */
#define	BSM_PF_ECONET		524	/* Linux-specific. */
#define	BSM_PF_ATMSVC		525	/* Linux-specific. */
#define	BSM_PF_IRDA		526	/* Linux-specific. */
#define	BSM_PF_PPPOX		527	/* Linux-specific. */
#define	BSM_PF_WANPIPE		528	/* Linux-specific. */
#define	BSM_PF_LLC		529	/* Linux-specific. */
#define	BSM_PF_CAN		530	/* Linux-specific. */
#define	BSM_PF_TIPC		531	/* Linux-specific. */
#define	BSM_PF_IUCV		532	/* Linux-specific. */
#define	BSM_PF_RXRPC		533	/* Linux-specific. */
#define	BSM_PF_PHONET		534	/* Linux-specific. */

/*
 * Used when there is no mapping from a local to BSM protocol domain.
 */
#define	BSM_PF_UNKNOWN		700	/* OpenBSM-specific. */

#endif /* !_BSM_AUDIT_DOMAIN_H_ */


code:
/*-
 * Copyright (c) 2008 Apple Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
 *     its contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_errno.h#5
 * $FreeBSD: release/9.0.0/sys/bsm/audit_errno.h 219128 2011-03-01 13:14:28Z rwatson $
 */

#ifndef _BSM_AUDIT_ERRNO_H_
#define	_BSM_AUDIT_ERRNO_H_

/*
 * For the purposes of portable encoding, we convert between local error
 * numbers and Solaris error numbers (as well as some extensions for error
 * numbers that don't exist in Solaris).  Although the first 35 or so
 * constants are the same across all OS's, we don't handle that in any
 * special way.
 *
 * When adding constants here, also add them to bsm_errno.c.
 */
#define	BSM_ERRNO_ESUCCESS		0
#define	BSM_ERRNO_EPERM			1
#define	BSM_ERRNO_ENOENT		2
#define	BSM_ERRNO_ESRCH			3
#define	BSM_ERRNO_EINTR			4
#define	BSM_ERRNO_EIO			5
#define	BSM_ERRNO_ENXIO			6
#define	BSM_ERRNO_E2BIG			7
#define	BSM_ERRNO_ENOEXEC		8
#define	BSM_ERRNO_EBADF			9
#define	BSM_ERRNO_ECHILD		10
#define	BSM_ERRNO_EAGAIN		11
#define	BSM_ERRNO_ENOMEM		12
#define	BSM_ERRNO_EACCES		13
#define	BSM_ERRNO_EFAULT		14
#define	BSM_ERRNO_ENOTBLK		15
#define	BSM_ERRNO_EBUSY			16
#define	BSM_ERRNO_EEXIST		17
#define	BSM_ERRNO_EXDEV			18
#define	BSM_ERRNO_ENODEV		19
#define	BSM_ERRNO_ENOTDIR		20
#define	BSM_ERRNO_EISDIR		21
#define	BSM_ERRNO_EINVAL		22
#define	BSM_ERRNO_ENFILE		23
#define	BSM_ERRNO_EMFILE		24
#define	BSM_ERRNO_ENOTTY		25
#define	BSM_ERRNO_ETXTBSY		26
#define	BSM_ERRNO_EFBIG			27
#define	BSM_ERRNO_ENOSPC		28
#define	BSM_ERRNO_ESPIPE		29
#define	BSM_ERRNO_EROFS			30
#define	BSM_ERRNO_EMLINK		31
#define	BSM_ERRNO_EPIPE			32
#define	BSM_ERRNO_EDOM			33
#define	BSM_ERRNO_ERANGE		34
#define	BSM_ERRNO_ENOMSG		35
#define	BSM_ERRNO_EIDRM			36
#define	BSM_ERRNO_ECHRNG		37	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EL2NSYNC		38	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EL3HLT		39	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EL3RST		40	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ELNRNG		41	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EUNATCH		42	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ENOCSI		43	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EL2HLT		44	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EDEADLK		45
#define	BSM_ERRNO_ENOLCK		46
#define	BSM_ERRNO_ECANCELED		47
#define	BSM_ERRNO_ENOTSUP		48
#define	BSM_ERRNO_EDQUOT		49
#define	BSM_ERRNO_EBADE			50	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EBADR			51	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EXFULL		52	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ENOANO		53	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EBADRQC		54	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EBADSLT		55	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EDEADLOCK		56	/* Solaris-specific. */
#define	BSM_ERRNO_EBFONT		57	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EOWNERDEAD		58	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ENOTRECOVERABLE	59	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ENOSTR		60	/* Solaris/Darwin/Linux-specific. */
#define	BSM_ERRNO_ENODATA		61	/* Solaris/Darwin/Linux-specific. */
#define	BSM_ERRNO_ETIME			62	/* Solaris/Darwin/Linux-specific. */
#define	BSM_ERRNO_ENOSR			63	/* Solaris/Darwin/Linux-specific. */
#define	BSM_ERRNO_ENONET		64	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ENOPKG		65	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EREMOTE		66
#define	BSM_ERRNO_ENOLINK		67
#define	BSM_ERRNO_EADV			68	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ESRMNT		69	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ECOMM			70	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EPROTO		71
#define	BSM_ERRNO_ELOCKUNMAPPED		72	/* Solaris-specific. */
#define	BSM_ERRNO_ENOTACTIVE		73	/* Solaris-specific. */
#define	BSM_ERRNO_EMULTIHOP		74
#define	BSM_ERRNO_EBADMSG		77
#define	BSM_ERRNO_ENAMETOOLONG		78
#define	BSM_ERRNO_EOVERFLOW		79
#define	BSM_ERRNO_ENOTUNIQ		80	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EBADFD		81	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EREMCHG		82	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ELIBACC		83	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ELIBBAD		84	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ELIBSCN		85	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ELIBMAX		86	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ELIBEXEC		87	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_EILSEQ		88
#define	BSM_ERRNO_ENOSYS		89
#define	BSM_ERRNO_ELOOP			90
#define	BSM_ERRNO_ERESTART		91
#define	BSM_ERRNO_ESTRPIPE		92	/* Solaris/Linux-specific. */
#define	BSM_ERRNO_ENOTEMPTY		93
#define	BSM_ERRNO_EUSERS		94
#define	BSM_ERRNO_ENOTSOCK		95
#define	BSM_ERRNO_EDESTADDRREQ		96
#define	BSM_ERRNO_EMSGSIZE		97
#define	BSM_ERRNO_EPROTOTYPE		98
#define	BSM_ERRNO_ENOPROTOOPT		99
#define	BSM_ERRNO_EPROTONOSUPPORT	120
#define	BSM_ERRNO_ESOCKTNOSUPPORT	121
#define	BSM_ERRNO_EOPNOTSUPP		122
#define	BSM_ERRNO_EPFNOSUPPORT		123
#define	BSM_ERRNO_EAFNOSUPPORT		124
#define	BSM_ERRNO_EADDRINUSE		125
#define	BSM_ERRNO_EADDRNOTAVAIL		126
#define	BSM_ERRNO_ENETDOWN		127
#define	BSM_ERRNO_ENETUNREACH		128
#define	BSM_ERRNO_ENETRESET		129
#define	BSM_ERRNO_ECONNABORTED		130
#define	BSM_ERRNO_ECONNRESET		131
#define	BSM_ERRNO_ENOBUFS		132
#define	BSM_ERRNO_EISCONN		133
#define	BSM_ERRNO_ENOTCONN		134
#define	BSM_ERRNO_ESHUTDOWN		143
#define	BSM_ERRNO_ETOOMANYREFS		144
#define	BSM_ERRNO_ETIMEDOUT		145
#define	BSM_ERRNO_ECONNREFUSED		146
#define	BSM_ERRNO_EHOSTDOWN		147
#define	BSM_ERRNO_EHOSTUNREACH		148
#define	BSM_ERRNO_EALREADY		149
#define	BSM_ERRNO_EINPROGRESS		150
#define	BSM_ERRNO_ESTALE		151

/*
 * OpenBSM constants for error numbers not defined in Solaris.  In the event
 * that these errors are added to Solaris, we will deprecate the OpenBSM
 * numbers in the same way we do for audit event constants.
 *
 * ELAST doesn't get a constant in the BSM space.
 */
#define	BSM_ERRNO_EPROCLIM		190	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_EBADRPC		191	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_ERPCMISMATCH		192	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_EPROGUNAVAIL		193	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_EPROGMISMATCH		194	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_EPROCUNAVAIL		195	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_EFTYPE		196	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_EAUTH			197	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_ENEEDAUTH		198	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_ENOATTR		199	/* FreeBSD/Darwin-specific. */
#define	BSM_ERRNO_EDOOFUS		200	/* FreeBSD-specific. */
#define	BSM_ERRNO_EJUSTRETURN		201	/* FreeBSD-specific. */
#define	BSM_ERRNO_ENOIOCTL		202	/* FreeBSD-specific. */
#define	BSM_ERRNO_EDIRIOCTL		203	/* FreeBSD-specific. */
#define	BSM_ERRNO_EPWROFF		204	/* Darwin-specific. */
#define	BSM_ERRNO_EDEVERR		205	/* Darwin-specific. */
#define	BSM_ERRNO_EBADEXEC		206	/* Darwin-specific. */
#define	BSM_ERRNO_EBADARCH		207	/* Darwin-specific. */
#define	BSM_ERRNO_ESHLIBVERS		208	/* Darwin-specific. */
#define	BSM_ERRNO_EBADMACHO		209	/* Darwin-specific. */
#define	BSM_ERRNO_EPOLICY		210	/* Darwin-specific. */
#define	BSM_ERRNO_EDOTDOT		211	/* Linux-specific. */
#define	BSM_ERRNO_EUCLEAN		212	/* Linux-specific. */
#define	BSM_ERRNO_ENOTNAM		213	/* Linux(Xenix?)-specific. */
#define	BSM_ERRNO_ENAVAIL		214	/* Linux(Xenix?)-specific. */
#define	BSM_ERRNO_EISNAM		215	/* Linux(Xenix?)-specific. */
#define	BSM_ERRNO_EREMOTEIO		216	/* Linux-specific. */
#define	BSM_ERRNO_ENOMEDIUM		217	/* Linux-specific. */
#define	BSM_ERRNO_EMEDIUMTYPE		218	/* Linux-specific. */
#define	BSM_ERRNO_ENOKEY		219	/* Linux-specific. */
#define	BSM_ERRNO_EKEYEXPIRED		220	/* Linux-specific. */
#define	BSM_ERRNO_EKEYREVOKED		221	/* Linux-specific. */
#define	BSM_ERRNO_EKEYREJECTED		222	/* Linux-specific. */
#define	BSM_ERRNO_ENOTCAPABLE		223	/* FreeBSD-specific. */
#define	BSM_ERRNO_ECAPMODE		224	/* FreeBSD-specific. */

/*
 * In the event that OpenBSM doesn't have a file representation of a local
 * error number, use this.
 */
#define	BSM_ERRNO_UNKNOWN		250	/* OpenBSM-specific. */

#endif /* !_BSM_AUDIT_ERRNO_H_ */


code:
/*-
 * Copyright (c) 2009 Apple Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
 *     its contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_fcntl.h#2
 * $FreeBSD: release/9.0.0/sys/bsm/audit_fcntl.h 191147 2009-04-16 20:17:32Z rwatson $
 */

#ifndef	_BSM_AUDIT_FCNTL_H_
#define	_BSM_AUDIT_FCNTL_H_

/*
 * Shared and Solaris-specific: (0-99).
 */
#define	BSM_F_DUPFD		0
#define	BSM_F_GETFD		1
#define	BSM_F_SETFD		2
#define	BSM_F_GETFL		3
#define	BSM_F_SETFL		4
#define	BSM_F_O_GETLK		5	/* Solaris-specific. */
#define	BSM_F_SETLK		6
#define	BSM_F_SETLKW		7
#define	BSM_F_CHKFL		8	/* Solaris-specific. */
#define	BSM_F_DUP2FD		9	/* FreeBSD/Solaris-specific. */
#define	BSM_F_ALLOCSP		10	/* Solaris-specific. */
#define	BSM_F_FREESP		11	/* Solaris-specific. */

#define	BSM_F_ISSTREAM		13	/* Solaris-specific. */
#define	BSM_F_GETLK		14
#define	BSM_F_PRIV		15	/* Solaris-specific. */
#define	BSM_F_NPRIV		16	/* Solaris-specific. */
#define	BSM_F_QUOTACTL		17	/* Solaris-specific. */
#define	BSM_F_BLOCKS		18	/* Solaris-specific. */
#define	BSM_F_BLKSIZE		19	/* Solaris-specific. */

#define	BSM_F_GETOWN		23
#define	BSM_F_SETOWN		24
#define	BSM_F_REVOKE		25	/* Solaris-specific. */
#define	BSM_F_HASREMOTELOCKS	26	/* Solaris-specific. */
#define	BSM_F_FREESP64		27	/* Solaris-specific. */
#define	BSM_F_ALLOCSP64		28	/* Solaris-specific. */

#define	BSM_F_GETLK64		33	/* Solaris-specific. */
#define	BSM_F_SETLK64		34	/* Solaris-specific. */
#define	BSM_F_SETLKW64		35	/* Solaris-specific. */

#define	BSM_F_SHARE		40	/* Solaris-specific. */
#define	BSM_F_UNSHARE		41 	/* Solaris-specific. */
#define	BSM_F_SETLK_NBMAND	42	/* Solaris-specific. */
#define	BSM_F_SHARE_NBMAND	43	/* Solaris-specific. */
#define	BSM_F_SETLK64_NBMAND	44 	/* Solaris-specific. */
#define	BSM_F_GETXFL		45	/* Solaris-specific. */
#define	BSM_F_BADFD		46	/* Solaris-specific. */

/*
 * FreeBSD-specific (100-199).
 */
#define	BSM_F_OGETLK		107	/* FreeBSD-specific. */
#define	BSM_F_OSETLK		108	/* FreeBSD-specific. */
#define	BSM_F_OSETLKW		109	/* FreeBSD-specific. */

#define	BSM_F_SETLK_REMOTE	114	/* FreeBSD-specific. */

/*
 * Linux-specific (200-299).
 */
#define	BSM_F_SETSIG		210	/* Linux-specific. */
#define	BSM_F_GETSIG		211	/* Linux-specific. */

/*
 * Darwin-specific (300-399).
 */
#define	BSM_F_CHKCLEAN 		341	/* Darwin-specific. */
#define	BSM_F_PREALLOCATE	342	/* Darwin-specific. */
#define	BSM_F_SETSIZE		343	/* Darwin-specific. */
#define	BSM_F_RDADVISE		344	/* Darwin-specific. */
#define	BSM_F_RDAHEAD		345	/* Darwin-specific. */
#define	BSM_F_READBOOTSTRAP	346	/* Darwin-specific. */
#define	BSM_F_WRITEBOOTSTRAP	347	/* Darwin-specific. */
#define	BSM_F_NOCACHE		348	/* Darwin-specific. */
#define	BSM_F_LOG2PHYS		349	/* Darwin-specific. */
#define	BSM_F_GETPATH		350	/* Darwin-specific. */
#define	BSM_F_FULLFSYNC		351	/* Darwin-specific. */
#define	BSM_F_PATHPKG_CHECK	352	/* Darwin-specific. */
#define	BSM_F_FREEZE_FS		353	/* Darwin-specific. */
#define	BSM_F_THAW_FS		354	/* Darwin-specific. */
#define	BSM_F_GLOBAL_NOCACHE	355	/* Darwin-specific. */
#define	BSM_F_OPENFROM		356	/* Darwin-specific. */
#define	BSM_F_UNLINKFROM	357	/* Darwin-specific. */
#define	BSM_F_CHECK_OPENEVT	358	/* Darwin-specific. */
#define	BSM_F_ADDSIGS		359	/* Darwin-specific. */
#define	BSM_F_MARKDEPENDENCY	360	/* Darwin-specific. */

/*
 * Darwin file system specific (400-499).
 */
#define	BSM_F_FS_SPECIFIC_0	400	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_1	401	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_2	402	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_3	403	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_4	404	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_5	405	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_6	406	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_7	407	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_8	408	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_9	409	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_10	410	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_11	411	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_12	412	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_13	413	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_14	414	/* Darwin-fs-specific. */
#define	BSM_F_FS_SPECIFIC_15	415	/* Darwin-fs-specific. */

#define	BSM_F_UNKNOWN		0xFFFF

#endif /* !_BSM_AUDIT_FCNTL_H_ */


code:
/*-
 * Copyright (c) 2005-2008 Apple Inc.
 * Copyright (c) 2005 SPARTA, Inc.
 * All rights reserved.
 *
 * This code was developed in part by Robert N. M. Watson, Senior Principal
 * Scientist, SPARTA, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 *     its contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * P4: //depot/projects/trustedbsd/openbsm/sys/bsm/audit_internal.h#5
 * $FreeBSD: release/9.0.0/sys/bsm/audit_internal.h 187214 2009-01-14 10:44:16Z rwatson $
 */

#ifndef _AUDIT_INTERNAL_H
#define	_AUDIT_INTERNAL_H

#if defined(__linux__) && !defined(__unused)
#define	__unused
#endif

/*
 * audit_internal.h contains private interfaces that are shared by user space
 * and the kernel for the purposes of assembling audit records.  Applications
 * should not include this file or use the APIs found within, or it may be
 * broken with future releases of OpenBSM, which may delete, modify, or
 * otherwise break these interfaces or the assumptions they rely on.
 */
struct au_token {
	u_char			*t_data;
	size_t			 len;
	TAILQ_ENTRY(au_token)	 tokens;
};

struct au_record {
	char			 used;		/* Record currently in use? */
	int			 desc;		/* Descriptor for record. */
	TAILQ_HEAD(, au_token)	 token_q;	/* Queue of BSM tokens. */
	u_char			*data;
	size_t			 len;
	LIST_ENTRY(au_record)	 au_rec_q;
};
typedef	struct au_record	au_record_t;

/*
 * We could determined the header and trailer sizes by defining appropriate
 * structures.  We hold off that approach until we have a consistent way of
 * using structures for all tokens.  This is not straightforward since these
 * token structures may contain pointers of whose contents we do not know the
 * size (e.g text tokens).
 */
#define	AUDIT_HEADER_EX_SIZE(a)	((a)->ai_termid.at_type+18+sizeof(u_int32_t))
#define	AUDIT_HEADER_SIZE	18
#define	MAX_AUDIT_HEADER_SIZE	(5*sizeof(u_int32_t)+18)
#define	AUDIT_TRAILER_SIZE	7

/*
 * BSM token streams store fields in big endian byte order, so as to be
 * portable; when encoding and decoding, we must convert byte orders for
 * typed values.
 */
#define	ADD_U_CHAR(loc, val)						\
	do {								\
		*(loc) = (val);						\
		(loc) += sizeof(u_char);				\
	} while(0)

#define	ADD_U_INT16(loc, val)						\
	do {								\
		be16enc((loc), (val));					\
		(loc) += sizeof(u_int16_t);				\
	} while(0)

#define	ADD_U_INT32(loc, val)						\
	do {								\
		be32enc((loc), (val));					\
		(loc) += sizeof(u_int32_t);				\
	} while(0)

#define	ADD_U_INT64(loc, val)						\
	do {								\
		be64enc((loc), (val));					\
		(loc) += sizeof(u_int64_t); 				\
	} while(0)

#define	ADD_MEM(loc, data, size)					\
	do {								\
		memcpy((loc), (data), (size));				\
		(loc) += size;						\
	} while(0)

#define	ADD_STRING(loc, data, size)	ADD_MEM(loc, data, size)

#endif /* !_AUDIT_INTERNAL_H_ */