IDMEF XML Library (libidmef) version 0.7.2
This library is compliant with version 0.7 of the IDMEF specification.

     ---+================ LIBIDMEF API ================+---

/*************************************************************************
 * With the exception of newSimpleElement, newCreateTime, newAnalyzerTime
 * and newDetectTime, each of these "new" functions accepts an xmlNodePtr, 
 * and a variable list of parameters, which should be xmlNodePtrs as well.
 * The parameters must be passed in the order specified by the DTD.  The 
 * functions will check to see if all required parameters were passed.  
 * If not, it will return NULL.  Possible parameters are displayed above the
 * functions.
 *
 * There are some parts in this library that you may not find documentation
 * for in this package.  Most likely, they are components of libxml.  Libxml
 * documentation is available online at http://xmlsoft.org  Some notable
 * libxml components are:
 *
 *   - xmlNodePtr : defined as (xmlNode *).  The xmlNode structure definition
 *                  is available at xmlsoft.org
 *
 * Notes: You may create empty elements by passing NULL in as the only
 *        parameter.  This is especially useful when creating messages
 *        with an unknown number of elements at compile time.
 *
 *        You must pass NULL in as the last argument. This is to let the 
 *        function know when to quit reading in arguments.  Failure to do this
 *        will result in "undefined behavior".
 *
 *************************************************************************/
 
/*********************************************************************
 *********************************************************************
 *****								 *****
 *****			The Message Classes			 *****
 *****								 *****
 *********************************************************************
 *********************************************************************/

/*==================================================================
 * Name: newIDMEF_Message
 *
 * Declaration: xmlNodePtr newIDMEF_Message(xmlNodePtr, ...);
 *
 * Possible parameters:
 *
 *   ATTRIBUTES
 *   xmlNodePtr version: optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr Alert    : zero or more
 *   xmlNodePtr Heartbeat: zero or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the root element
 *
 * Example:
 *	    if(newIDMEF_Message(theAlert, NULL))
 *              printCurrentMessage(stdout);
 *===================================================================*/

/*==================================================================
 * Name: newAlert
 *
 * Declaration: xmlNodePtr newAlert(xmlNodePtr, ...);
 *
 * Possible parameters:
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident  : optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr Analyzer        : exactly one
 *   xmlNodePtr CreateTime      : exactly one
 *   xmlNodePtr DetectTime      : zero or one
 *   xmlNodePtr AnalyzerTime    : zero or one
 *   xmlNodePtr Source          : zero or more
 *   xmlNodePtr Target          : zero or more
 *   xmlNodePtr Classification  : one or more
 +   xmlNodePtr Assessment      : zero or one
 *   xmlNodePtr ToolAlert       : zero or one
 *   xmlNodePtr OverflowAlert   : zero or one
 *   xmlNodePtr CorrelationAlert: zero or one
 *   xmlNodePtr AdditionalData  : zero or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Alert node.
 *
 * Example:
 *	    xmlNodePtr theAlert = newAlert(myident,myImpact,myCreateTime,
 *                                         myAnalyzer,myClassification,
 *                                         mySource,myTarget, NULL);
 *
 *===================================================================*/

/*==================================================================
 * Name: newToolAlert
 *
 * Declaration: xmlNodePtr newToolAlert(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   SUB-ELEMENTS
 *   xmlNodePtr name      : exactly one
 *   xmlNodePtr command   : zero or more
 *   xmlNodePtr alertident: one or more
 *
 * !Remember!: the last argument must be NULL.
 *===================================================================*/

/*==================================================================
 * Name: newCorrelationAlert
 *
 * Declaration: xmlNodePtr newCorrelationAlert(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   SUB-ELEMENTS
 *   xmlNodePtr name      : exactly one
 *   xmlNodePtr alertident: one or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created CorrelationAlert node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newOverflowAlert
 *
 * Declaration: xmlNodePtr newOverflowAlert(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   SUB-ELEMENTS
 *   xmlNodePtr program: exactly one
 *   xmlNodePtr size   : zero or one
 *   xmlNodePtr buffer : zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created OverflowAlert node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newHeartbeat
 *
 * Declaration: xmlNodePtr newHeartbeat(xmlNodePtr, ...);
 *
 * Possible parameters:
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident: optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr Analyzer        : exactly one
 *   xmlNodePtr CreateTime      : exactly one
 *   xmlNodePtr AnalyzerTime    : zero or one
 *   xmlNodePtr AdditionalData  : zero or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Heartbeat node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*********************************************************************
 *********************************************************************
 *****								 *****
 *****			The Core Classes			 *****
 *****								 *****
 *********************************************************************
 *********************************************************************/

/*==================================================================
 * Name: newAnalyzer
 *
 * Declaration: xmlNodePtr newAnalyzer(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr analyzerid  : optional (but see spec)
 *   xmlNodePtr manufacturer: optional
 *   xmlNodePtr model       : optional
 *   xmlNodePtr version     : optional
 *   xmlNodePtr class       : optional
 +   xmlNodePtr ostype      : optional
 +   xmlNodePtr osversion   : optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr Node   : zero or one
 *   xmlNodePtr Process: zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Analyzer node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newClassification
 *
 * Declaration: xmlNodePtr newClassification(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr origin: required
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr name: exactly one
 *   xmlNodePtr url : exactly one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Classification node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newSource
 *
 * Declaration: xmlNodePtr newSource(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident  : optional
 *   xmlNodePtr spoofed: optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr Node   : zero or one
 *   xmlNodePtr User   : zero or one
 *   xmlNodePtr Process: zero or one
 *   xmlNodePtr Service: zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Source node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newTarget
 *
 * Declaration: xmlNodePtr newTarget(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident: optional
 *   xmlNodePtr decoy: optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr Node    : zero or one
 *   xmlNodePtr User    : zero or one
 *   xmlNodePtr Process : zero or one
 *   xmlNodePtr Service : zero or one
 *   xmlNodePtr FileList: zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Target node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newAssessment
 *
 * Declaration: xmlNodePtr newAssessment(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   SUB-ELEMENTS
 *   xmlNodePtr Impact    : zero or one
 *   xmlNodePtr Action    : zero or more
 *   xmlNodePtr Confidence: zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Assessment node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newAdditionalData
 *
 * Declaration: xmlNodePtr newAdditionalData(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr type   : required
 *   xmlNodePtr meaning: optional
 *
 *   VALUE
 *   xmlNodePtr value: exactly one (the additional data)
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created AdditionalData node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*********************************************************************
 *********************************************************************
 *****								 *****
 *****			The Time Classes			 *****
 *****								 *****
 *********************************************************************
 *********************************************************************/

/*==================================================================
 * Name: newCreateTime
 *
 * Declaration: xmlNodePtr newCreateTime(struct timeval *);
 *
 * parameter:
 * 
 *   struct timeval * : If provided, the timeval will be used to create the
 *                      ntpstamp and DATETIME.  NULL must be passed in if
 *                      the newCreateTime function is to create the ntpstamp
 *                      and DATETIME itself.
 *
 * Returns: an xmlNodePtr to the newly created CreateTime node.
 *
 * Example: xmlNodePtr createTime =  newCreateTime(NULL);
 *          xmlNodePtr createTime2 = newCreateTime(&mytimeval); // use provided
 *                                                             
 *===================================================================*/

/*==================================================================
 * Name: newAnalyzerTime
 *
 * Declaration: xmlNodePtr newAnalyzerTime(struct timeval *);
 *
 * parameter: 
 * 
 *   struct timeval * : If provided, the timeval will be used to create the
 *                      ntpstamp and DATETIME.  NULL must be passed in if
 *                      the newAnalyzerTime function is to create the ntpstamp
 *                      and DATETIME itself.
 *
 * Returns: an xmlNodePtr to the newly created AnayzerTime node.
 *
 * Example: xmlNodePtr analyzerTime =  newAnalyzerTime(NULL);
 *          xmlNodePtr analyzerTime2 = newAnalyzerTime(&mytimeval); 
 *                                                             
 *===================================================================*/

/*==================================================================
 * Name: newDetectTime
 *
 * Declaration: xmlNodePtr newDetectTime(struct timeval *);
 *
 * parameter: 
 * 
 *   struct timeval * : If provided, the timeval will be used to create the
 *                      ntpstamp and DATETIME.  NULL must be passed in if
 *                      the newDetectTime function is to create the ntpstamp
 *                      and DATETIME itself.
 *
 * Returns: an xmlNodePtr to the newly created Time node.
 *
 * Example: xmlNodePtr detectTime =  newDetectTime(NULL);
 *          xmlNodePtr detectTime2 = newDetectTime(&mytimeval); // use provided
 *                                                             
 *===================================================================*/

/*********************************************************************
 *********************************************************************
 *****								 *****
 *****			The Support Classes			 *****
 *****								 *****
 *********************************************************************
 *********************************************************************/

/*==================================================================
 * Name: newNode
 *
 * Declaration: xmlNodePtr newNode(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident   : optional
 *   xmlNodePtr category: optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr location: zero or one
 *   xmlNodePtr name    : zero or one
 *   xmlNodePtr Address : zero or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Node node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newAddress
 *
 * Declaration: xmlNodePtr newAddress(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident    : optional
 *   xmlNodePtr category : optional
 *   xmlNodePtr vlan-name: optional
 *   xmlNodePtr vlan-num : optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr address: exactly one
 *   xmlNodePtr netmask: zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Address node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newUser
 *
 * Declaration: xmlNodePtr newUser(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident   : optional
 *   xmlNodePtr category: optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr UserId: one or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created User node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newUserId
 *
 * Declaration: xmlNodePtr newUserId(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident: optional
 *   xmlNodePtr type : optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr name  : zero or one
 *   xmlNodePtr number: zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created User node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newProcess
 *
 * Declaration: xmlNodePtr newProcess(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident: optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr name: exactly one
 *   xmlNodePtr pid : zero or one
 *   xmlNodePtr path: zero or one
 *   xmlNodePtr arg : zero or more
 *   xmlNodePtr env : zero or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Process node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newService
 *
 * Declaration: xmlNodePtr newService(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident: optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr name       : zero or one
 *   xmlNodePtr port       : zero or one
 *   xmlNodePtr portlist   : zero or one
 *   xmlNodePtr protocol   : zero or one
 *   xmlNodePtr SNMPService: zero or one
 *   xmlNodePtr WebService : zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Service node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newWebService
 *
 * Declaration: xmlNodePtr newWebService(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   SUB-ELEMENTS
 *   xmlNodePtr url        : exactly one
 *   xmlNodePtr cgi        : zero or one
 *   xmlNodePtr http-method: zero or one
 *   xmlNodePtr arg        : zero or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created WebService node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newSNMPService
 *
 * Declaration: xmlNodePtr newSNMPService(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   SUB-ELEMENTS
 *   xmlNodePtr oid      : zero or one
 *   xmlNodePtr community: zero or one
 *   xmlNodePtr command  : zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly create SNMPService node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newFileList
 *
 * Declaration: xmlNodePtr newFileList(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   SUB-ELEMENTS
 *   xmlNodePtr FileList: one or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly create FileList node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newFile
 *
 * Declaration: xmlNodePtr newFile(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr ident   : optional
 *   xmlNodePtr category: required
 *   xmlNodePtr fstype  : required
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr name       : exactly one
 *   xmlNodePtr path       : exactly one
 *   xmlNodePtr create-time: Zero or one
 *   xmlNodePtr modify-time: Zero or one
 *   xmlNodePtr access-time: Zero or one
 *   xmlNodePtr disk-size  : Zero or one
 *   xmlNodePtr FileAccess : Zero or one
 *   xmlNodePtr Linkage    : Zero or one
 *   xmlNodePtr Inode      : Zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created File node.
 *
 * Example: similar to newAlert.
 *
 * NOTE: As the specification states, create-time, modify-time, and
 *       access-time are DATETIME formatted values.  These can be created
 *       using currentDatetime() or both newSimpleElement() and
 *       timevalToDatetime().  See the example1.c file for an example.
 *===================================================================*/

/*==================================================================
 * Name: newFileAccess
 *
 * Declaration: xmlNodePtr newFileAccess(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   SUB-ELEMENTS
 *   xmlNodePtr UserID    : Exactly one
 *   xmlNodePtr permission: one or more
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created FileAccess node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newLinkage
 *
 * Declaration: xmlNodePtr newLinkage(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr category: optional
 *
 *   SUB-ELEMENTS
 *   xmlNodePtr name: Exactly one
 *   xmlNodePtr path: Exactly one
 *   xmlNodePtr File: Exactly one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Linkage node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newInode
 *
 * Declaration: xmlNodePtr newInode(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   SUB-ELEMENTS
 *   xmlNodePtr change-time   : zero or one
 *   xmlNodePtr number        : zero or one
 *   xmlNodePtr major-device  : zero or one
 *   xmlNodePtr minor-device  : zero or one
 *   xmlNodePtr c-major-device: zero or one
 *   xmlNodePtr c-minor-device: zero or one
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Inode node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*********************************************************************
 *********************************************************************
 *****								 *****
 *****			The Assessment Classes			 *****
 *****								 *****
 *********************************************************************
 *********************************************************************/

/*==================================================================
 * Name: newImpact
 *
 * Declaration: xmlNodePtr newImpact(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr severity  : optional
 *   xmlNodePtr completion: optional
 *   xmlNodePtr type      : optional
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Impact node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newAction
 *
 * Declaration: xmlNodePtr newAction(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr category: required
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Action node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*==================================================================
 * Name: newConfidence
 *
 * Declaration: xmlNodePtr newConfidence(xmlNodePtr, ...);
 *
 * Possible parameters: 
 * 
 *   ATTRIBUTES
 *   xmlNodePtr rating: optional
 *
 * !Remember!: the last argument must be NULL.
 *
 * Returns: an xmlNodePtr to the newly created Confidence node.
 *
 * Example: similar to newAlert.
 *===================================================================*/

/*********************************************************************
 *********************************************************************
 *****								 *****
 *****			Utility Functions			 *****
 *****								 *****
 *********************************************************************
 *********************************************************************/

/*==================================================================
 * Name: newSimpleElement
 *
 * Declaration: xmlNodePtr newSimpleElement(char *, char *);
 *
 * Parameters 
 *  (1) char *name : the parameter name
 *  (2) char *value: the value of the parameter
 *
 * Returns: an xmlNodePtr to the new node.
 *
 * Example:
 *          xmlNodePtr myArg = newSimpleElement("port","53");
 *
 *===================================================================*/

/*==================================================================
 * Name: newAttribute
 *
 * Declaration: xmlNodePtr newAttribute(char *, char *);
 *
 * Parameters 
 *  (1) char *name : the parameter name
 *  (2) char *value: the value of the parameter
 *
 * Note: This is the same function as newSimpleElement.  It was added to
 *       avoid confusion in building xml documents by following the
 *       nomenclature illustrated in the idmef-xml spec.  You may use
 *       newSimpleElement for adding new xml attributes if you so desire.
 *===================================================================*/

 /***********************************************************************
  *
  * These are functions that perform different operations on XML elements
  * that have been created with the above "new" functions.
  *
  ***********************************************************************/

/*===========================================================================
 * Name: addElement
 *
 * Purpose: Add a child element to a parent.
 *
 * Declaration: xmlNodePtr addElement(xmlNodePtr, xmlNodePtr);
 *
 * Parameters:
 *            (1) xmlNodePtr parent: an xmlNodePtr to the parent
 *            (2) xmlNodePtr child : an xmlNodePtr to the child
 *
 * Returns: A pointer to the child, or NULL if error
 *
 * Example:
 *          if(addElement(theAlert, target1) != NULL)
 *              return 1;
 *          else
 *              return 0;
 *
 *==========================================================================*/

/*===========================================================================
 * Name: addElements
 *
 * Purpose: Add a child elements to a parent.
 *
 * Declaration: int addElements(xmlNodePtr, xmlNodePtr, ...);
 *
 * Parameters:
 *           - xmlNodePtr parent : an xmlNodePtr to the parent
 *           - xmlNodePtr child  : an xmlNodePtr to a child
 *           - ...    : a variable size list of xmlNodePtrs to children
 *
 * Returns: the number of children added
 *
 * NOTE: The last parameter MUST be NULL.  Otherwise, the function will not
 *       know when to stop reading in the variable length parameter list, and
 *       bad things will happen.
 *
 * Example:
 *          if(addElements(theAlert, target1, target2, target3, NULL))
 *             return 1;
 *          else
 *             return 0;
 *
 *==========================================================================*/

/*===========================================================================
 * Name: setAttribute
 *
 * Purpose: Set attributes to an element.
 *
 * Declaration: xmlNodePtr setAttribute(xmlNodePtr, xmlNodePtr);
 *
 * Parameters:
 *           - xmlNodePtr element : an xmlNodePtr to the element
 *           - xmlNodePtr attrib  : an xmlNodePtr to the attribute
 *
 * Returns: A pointer to the element, or NULL if error
 *
 * Example:
 *          setAttribute(theAlert, myAlertID);
 *==========================================================================*/

/*===========================================================================
 * Name: setAttributes
 *
 * Purpose: Set attributes to a element.
 *
 * Declaration: int setAttributes(xmlNodePtr, xmlNodePtr, ...);
 *
 * Parameters:
 *           - xmlNodePtr element : an xmlNodePtr to the element
 *           - xmlNodePtr attrib  : an xmlNodePtr to an attribute
 *           - ...     : a variable size list of xmlNodePtrs to attributes
 *
 * Returns: the number of attributes set
 *
 * NOTE: The last parameter MUST be NULL.  Otherwise, the function will not
 *       know when to stop reading in the variable length parameter list, and
 *       bad things will happen.
 *
 * Example:
 *          setAttributes(theAlert, myAlertId, myImpact, myVersion, NULL);
 *==========================================================================*/

/*==========================================================================*
 * Name: getElement
 *
 * Purpose: Retrieve a pointer to the first child element directly under a
 *          parent element whose name matches the provided string.
 *
 * Declaration: xmlNodePtr getElement(xmlNodePtr, char *);
 *
 * Parameters:
 *           - xmlNodePtr parent : an xmlNodePtr to the parent
 *           - char *name        : a string representing the child's name
 *
 * Returns: A xmlNodePtr containing the element.
 *
 * Example:
 *          xmlNodePtr theTarget = getElement(theAlert,"Target");
 *==========================================================================*/

/*==========================================================================*
 * Name: hasElement
 *
 * Purpose: Determines whether a parent element has a specified child element
 *          directly below it.  This is to say it only searches for first
 *          generation children.
 *
 * Declaration: xmlNodePtr getElement(xmlNodePtr, char *);
 *
 * Parameters:
 *           - xmlNodePtr parent : an xmlNodePtr to the parent
 *           - char *name        : a string representing the child's name
 *
 * Returns: 1 for yes, 0 for no
 *
 * Example:
 *          if(!hasElement(theAlert,"CorrelationAlert"))
 *             xmlAddChild(theAlert,myOverflowAlert);
 *              
 *==========================================================================*/

 /***********************************************************************
  *
  * These are functions that perform different operations on XML documents.
  *
  ***********************************************************************/

/*==========================================================================*
 * Name: globalsInit
 *
 * Purpose: Initialize global variables, and those structures we can reuse
 *          for each IDMEF Message.
 *
 * Declaration: int globalsInit(char *);
 *
 * Parameters: The current version of XML
 *
 * Returns: 1 for success, and 0 otherwise
 *
 * NOTE: You MUST call this function before you start to create IDMEF messages
 *
 * Example:
 *          if(!globalsInit("1.0"))
 *          {
 *              fprintf(stderr,"myfile.c: Problem initializing globals\n");
 *              return 0;
 *          }
 *==========================================================================*/

/*==========================================================================*
 * Name: createCurrentDoc
 *
 * Purpose: Creates the a new xmlDoc and sets it as the current (doc).
 *
 * Declaration: int createCurrentDoc(const char *);
 *
 * Parameters: The current version of XML
 *
 * Returns: 1 for success, and 0 otherwise
 *
 * Example:
 *          if(!createCurrentDoc("1.0"))
 *          {
 *              fprintf(stderr,"myfile.c: Problem creating current xml doc\n");
 *              return 0;
 *          }
 *==========================================================================*/

/*==========================================================================*
 * Name: createDoc
 *
 * Purpose: Creates a new xmlDoc, initializes the root element, and links
 *          to the DTD.
 *
 * Declaration: xmlDocPtr createDoc(const char *);
 *
 * Parameters: The current version of XML
 *
 * Returns: an xmlDocPtr to the newly created doc, or NULL for error.
 *
 * NOTE: You must set the newly created doc as current doc before you begin
 *       building an xml tree off the root.  It is reccomended that you
 *       just call createCurrentDoc rather than createDoc and setCurrentDoc.
 *
 * Example:
 *          if(createDoc("1.0") == NULL)
 *          {
 *              fprintf(stderr,"myfile.c: Problem creating an xml doc\n");
 *              return 0;
 *          }
 *==========================================================================*/

/*==========================================================================*
 * Name: setCurrentDoc
 * 
 * Purpose : Sets the current doc and free's the old doc if need be.
 *
 * Declaration: int setCurrentDoc(xmlDocPtr);
 *
 * Parameters: An pointer to the doc to be set as the current
 *
 * Returns: 1 if success, 0 otherwise
 *
 * Example:
 *          if(!setCurrentDoc(myDoc))
 *          {
 *              fprintf(stderr,"myfile.c: Problem setting current xml doc\n");
 *              return 0;
 *          }
 *==========================================================================*/

/*==========================================================================*
 * Name: getCurrentDoc
 *
 * Purpose: gets the current xmlDoc (the global "doc").
 *
 * Declaration: xmlDocPtr getCurrentDoc();
 *
 * Returns: an xmlDocPtr to the current doc.
 *
 * Example:
 *          xmlDocPtr currentDoc = getCurrentDoc();
 *==========================================================================*/

/*==========================================================================*
 * Name: clearCurrentDoc
 *
 * Purpose: Free the current xmlDoc, including all it's structures, except
 *          for the DTD.  The DTD is unlinked first, as it is re-usable.
 *
 * Declaration: void clearCurrentDoc();
 *==========================================================================*/

/*==========================================================================*
 * Name: copyCurrentDoc
 *
 * Purpose: Create a copy of the current xmlDoc.  This copies everything
 *          _except_ the DTD, as the DTD is re-usable, and we don't need
 *          extraneous copies running amok.
 *
 * Declaration: xmlDocPtr copyCurrentDoc();
 *
 * Returns: A copy of the current xml doc
 *
 * NOTE: The xmlDoc copy is NOT linked to the DTD.  If you wish it to be,
 *       setCurrentDoc must be called on the document.
 * 
 * Example:
 *          xmlDocPtr docCopy = copyCurrentDoc();
 *==========================================================================*/

/*==========================================================================*
 * Name: resetCurrentDoc
 *
 * Purpose: Reset the current document by clearing it and re-initializing
 *          it.
 *
 * Declaration: int resetCurrentDoc();
 *
 * Returns: 1 for success, and 0 otherwise
 *==========================================================================*/

/*==========================================================================*
 * Name: validateCurrentDoc
 *
 * Purpose: Validates the current document using the DTD.
 *
 * Declaration: int validateCurrentDoc();
 *
 * Returns: 1 for success, and 0 otherwise
 *==========================================================================*/

/***********************************************************************
 *
 *               Miscellaneous time format functions.
 *
 ***********************************************************************/

/*==========================================================================*
 * Name: currentNtpTimestamp
 *
 * Purpose: Creates a NTP timestamp with the current time
 *
 * Declaration: char *currentNtpTimestamp();
 *
 * Returns: The current NTP timestamp as a char *
 *
 * Example:
 *          char *ntp_timestamp = currentNtpTimestamp();
 *==========================================================================*/

/*==========================================================================*
 * Name: currentDatetime
 *
 * Purpose: Formats the current datetime as specified by the IDMEF XML
 *          specification version 3 (4.4.6). YYYY-MM-DDThh:mm:ss(+|-)hh:mm
 *
 * Declaration: char *currentDatetime();
 *
 * Returns: The formated date as a char *
 *
 * Example: 
 *          char *datetime = currentDatetime();
 *==========================================================================*/

/*==========================================================================*
 * Name: timevalToNtpTimestamp
 *
 * Purpose: Creates a NTP timestamp with the provided timeval struct
 *
 * Declaration: char *convertNtpTimestamp(const time_t *);
 *
 * Returns: The provided NTP timestamp as a char *
 *
 * Example:
 *          struct timeval t;
 *          char *ntp_timestamp_string;
 *
 *          gettimeofday(&t,0);
 *          ntp_timestamp_string = timevalToNtpTimestamp(&t);
 *==========================================================================*/

/*==========================================================================*
 * Name: timevalToDatetime *
 * Purpose: Formats the provided time as specified by the IDMEF XML
 *          specification version 3 (4.4.6). YYYY-MM-DDThh:mm:ssZ.  Time
 *          is represented as UTC.
 *
 * Declaration: char *convertTime(const time_t *);
 *
 * Returns: The formated time as a char *
 *
 * Example:
 *          time_t t;
 *          char *datetime_string;
 *
 *          t = time(NULL);
 *          datetime_string = timeToDatetime(&t);
 *
 * Note: This function outputs time in UTC, partially because we technically
 *       save space and bandwith, but more so because strftime's representation
 *       of "time-zone as hour offset from GMT", excludes the ':', which is
 *       required in the IDMEF spec.
 *==========================================================================*/

/***********************************************************************
 *
 *               		I/0 functions.
 *
 ***********************************************************************/

/*==========================================================================*
 * Name: printCurrentMessage
 *
 * Purpose: Prints the current IDMEF message to the FILE * provided
 *
 * Declaration: void printCurrentMessage(FILE *);
 *==========================================================================*/

/*=========================================================================*
 * Name: IDMEFxmlOutputBufferCreate:
 * Purpose: Create a buffered  output for the progressive saving of a file
 *          If filename is "-' then we use stdout as the output.
 *          Automatic support for ZLIB/Compress compressed document is provided
 *          by default if found at compile-time.
 *
 * Parameters:
 *             @URI:  a C string containing the URI or filename
 *             @encoder:  the encoding converter or NULL
 *             @compression:  the compression ration (0 none, 9 max).
 *
 * Returns: the new output or NULL
 * Note: This function is another strain of the xmlOutputBufferCreate functions
 *       from libxml.  It's also happens to be used in an I/0 example from
 *       www.xmlsoft.org, and happens to fit our needs nicely.
 *=========================================================================*/

/*==========================================================================*
 * Name: IDMEFxmlFileWrite
 * Purpose: Writes @len bytes from @buffer to the I/O channel
 * 
 * Parameters:
 *            @context:  the I/O context
 *            @buffer:  where to drop data
 *            @len:  number of bytes to write
 *
 * Returns: The number of bytes written
 *
 * Note: This function is an import of a static function called xmlFileWrite
 *       from libxml.
 *==========================================================================*/

/*=========================================================================*
 * Name: IDMEFxmlDocContentDumpOutput:
 * Purpose: Dumps an xml Document to an xmlOutputBufferPtr
 *
 * Parameters:
 *             @buf:  the XML buffer output
 *             @cur:  the document
 *             @encoding:  an optional encoding string
 *             @format:  should formatting spaces been added
 *
 * Note: This function is an import of a static function called
 *       xmlDocContentDumpOutput from libxml.
 *==========================================================================*/

 /***********************************************************************
  *
  *                      Other utility functions.
  *
  ***********************************************************************/

/*==========================================================================*
 * Name: getStoredAlertID
 *
 * Purpose: Opens the specified file, and attempts to extract the stored
 *          alert id.
 *
 * Declaration: unsigned long getStoredAlertID(char *);
 *
 * Parameters: The name of the file to extract the alert ID from
 *
 * Returns: the alert id as an unsigned long integer, 1 if the file didn't
 *          contain an alert id, or 0 for error.
 * Example:
 *          unsigned long alertID;
 *          alertID = getStoredAlertID("/var/log/alertID.log");
 *==========================================================================*/

/*==========================================================================*
 * Name: saveAlertID
 *
 * Purpose: Opens the specified file, and attempts to extract the stored
 *          alert id.
 *
 * Declaration: int saveAlertID(unsigned long, char *);
 *
 * Parameters:
 *             - unsigned long alertid : the alert ID to store
 *             - char *filename        : the name of the file to store it in
 *
 * Returns: 1 for success or 0 for error.
 *
 * Example:
 *          unsigned long alertID;
 *          
 *                . . .  /* create some messages, incrementing the alert id */
 *          
 *          saveAlertID(alertID,"/var/log/alertID.log");
 *==========================================================================*/

/*==========================================================================*
 * Name: badNode
 *
 * Purpose: Prints a message to stderr with the invalid node name, and the
 *          parent it was attempted to be linked to.
 *
 * Declaration: void badNode(xmlNodePtr, char *);
 *
 * Parameters:
 *           - xmlNodePtr : the invalid node
 *           - char *     : the would-be parent node's name
 *==========================================================================*/

/*==========================================================================*
 * Name: intToString
 *
 * Purpose: Converts a signed integer value to it's ASCII representation.
 *
 * Declaration: char * intToString(int);
 *
 * Parameters:
 *           - int : the value to be converted
 *
 * Returns: The ASCII representation as a char *
 *
 * Example:
 *          xmlDocPtr myAlertId;
 *
 *          int idmef_alertid = 9999;
 *          myAlertId = newSimpleElement("alertid",intToString(idmef_alertid));
 *==========================================================================*/

/*==========================================================================*
 * Name: ulongToString
 *
 * Purpose: Converts an ulong integer value to it's ASCII representation.
 *
 * Declaration: char * ulongToString(unsigned long);
 *
 * Parameters:
 *           - unsigned long : the value to be converted
 *
 * Returns: The ASCII representation as a char *
 *
 * Example:
 *        xmlDocPtr myAlertId;
 *
 *        ulong idmef_alertid = 9999;
 *        myAlertId = newSimpleElement("alertid",ulongToString(idmef_alertid));
 *==========================================================================*/


