/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* artex72Q src/artex/usr/include/artex.h 1.25.2.4                        */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2008,2019              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)06     1.25.2.4  src/artex/usr/include/artex.h, artex, artex72Q, q2019_13A4 2/4/19 09:51:47 */

#ifndef _H_ARTEXEXT
#define _H_ARTEXEXT

#include <stdbool.h>
#include <stdlib.h>
#include <artexerr.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Profile handle */
typedef void *artexProfileHandle_t;

typedef enum { V_INTEGER, V_INTEGER_BI, V_INTEGER_SI, V_BOOLEAN, V_STRING, V_BINARY } artexValueType_t;

/*
 * The following structure represents the application target of a parameter.
 */
typedef struct artexTarget {
	char 	*class;				/* class of target, i.e. device, volume group... */
	char 	*instance;			/* instance of target, i.e. en0, rootvg... */
	char 	*match;			        /* match regexp for filtering targete instance */
        struct artexTarget *next;               /* Next target in list */
} artexTarget_t;

typedef artexTarget_t *p_artexTarget_t;

/*
 * The following structure represents the properties of a parameter contained in a profile.
 * The value of a parameter is determined by its length and a pointer to the data.
 */
typedef struct {
	size_t		valueLength;		/* length of value data */
	char 		*valueData;		/* pointer to value data string */
        artexValueType_t         valueType;     /* value type of the parameter */
} artexParamValue_t;

/*
 * The following structure represents the property of a parameter.
 */
typedef struct artexProperty {
        char    *name;
        artexParamValue_t value;                  /* value associated to the parameter */
        struct artexProperty *next;               /* Next property in list */
} artexProperty_t;

typedef artexProperty_t *p_artexProperty_t;


typedef struct artexParam {
	char 		 *name;		        /* unique identifier of the parameter */
	artexParamValue_t value;		/* value associated to the parameter */
	struct {
	    	int  	appType:1;		/* parameter apply type */
	    	int  	readOnly:1;		/* indicate if parameter is read-only */
		int  	reboot:1;		/* indicate if parameter requires a reboot */
        } flags;				/* flags associated to the parameter */
        p_artexTarget_t 	 target;        /* pointer to the first element of 
						   the list of targets for the parameter */
        p_artexProperty_t        property;      /* pointer to the first element of
                                                   the list of property for the parameter */
	struct artexCat   *parentCat;		/* parent catalog or sub-category */
	struct artexParam *next;		/* next parameter in the profile list */
	struct artexParam *nextCat;		/* next parameter in the catalog list */
} artexParam_t;

typedef artexParam_t *p_artexParam_t;


/*
 *Seed data structure
 */
typedef struct artexSeeds
{
    char             *id;               /* unique identifier of the seed */
    char             *parameterMatch;   /*Match filter for parameter id */
    p_artexTarget_t  target;            /* pointer to the first element of target list*/
    struct artexCat    *parentCat;      /* parent catalog or sub-category */
    struct artexSeeds *next;

}artexSeeds_t;

typedef artexSeeds_t *p_artexSeeds_t;

/*
 * The following structure represents the catalogs and sub-categories included in the public
 * representation of a profile.
 */
typedef struct artexCat {
	char 		*id;			/* identifier of the catalog or sub-category */
	char 		*shortDesc;		/* short description of catalog or sub-category */
	char 		*desc;		        /* description of the catalog or sub-category */
	p_artexParam_t 	paramList;		/* pointer to 1st element of parameters list */
	struct artexCat *childrenSubCatList;	/* pointer to 1st element of sub-categories list */
	struct artexCat *parentCat;		/* pointer to parent catalog or sub-category */
	struct artexCat	*next;			/* pointer to next category for the parent */
} artexCat_t;

typedef artexCat_t *p_artexCat_t;

/*
 * The following structure is the public representation of a ARTEX profile, including a parameters
 * list with their values and properties.
 */
typedef struct {
	char 		*id;		/* unique identifier of the profile */
	char 	        *date;		/* last modification date of the profile */
	char 		*version;	/* version of the profile */
	char 		*shortDesc;   	/* short description of the profile */
	char 		*desc;		/* description of the profile */
	p_artexParam_t	paramList;	/* chained list of parameters included in the profile */
	p_artexSeeds_t 	seedList;	/* pointer to 1st element of seeds list */
	p_artexCat_t	catList;	/* pointer to the first in the list of the catalogs referred
						by the parameters in this profile */
} binProfile_t;

typedef binProfile_t *p_binProfile_t;

/*
 * The following structure represents the constraints applied to a parameter. A parameter constraint
 * is used to indicated that it requires disruptive operations for the change to take effect.
 */
typedef struct artexConstraint {
        char *id;                          /* Constraint's id, only set for constraints defined at the catalog level */
        char *msg;                         /* Optional message to be displayed */
        char *preOp;                      /* Command to be executed before parameter is set */
        char *postOp;                     /* Command to be executed after parameter is set */
        struct {
	    int bosboot:1;		   /* bosboot constraint */

	} builtin;                /* Bit field structure for builtin constraint */

} artexConstraint_t;

typedef artexConstraint_t *p_artexConstraint_t;

/*
 * The following structure is returned by the artexset() function.
 */
typedef enum { BOSBOOT_REQUIRED, REBOOT_REQUIRED, NONE_REQUIRED} requiredAction_t;

typedef struct artexSetData {
    requiredAction_t requiredAction; /*Action required after artexset for changes to take effect*/
   
}artexSetData_t;

/*
 * The following structure is returned by the artexpretend() function. This is a chained list of 
 * fields to be displayed by the artexset -p command.
 */
typedef enum { APPLY_RUNTIME, APPLY_NEXTBOOT, APPLY_PROFILE} artexApplyType_t;

typedef struct artexPretendData {
	char			*paramName;	/* name of the parameter */
	artexParamValue_t	paramValue;	/* new value of the parameter */
	artexApplyType_t	paramApply;	/* profile apply type */
	bool			paramReboot;	/* catalog apply type (reboot or not) */
	p_artexConstraint_t   	constraints;	/* constraints (actions required) */
        p_artexTarget_t         target;         /* parameter's list of targets needed to print targets*/
	struct artexPretendData	*nextPretend;	/* next parameter to display in list */
} artexPretendData_t;

typedef artexPretendData_t *p_artexPretendData_t;

/*
 * Debug levels and categories
 */
typedef enum { 
    COMMANDS = 0,
    DISCOVERY = 1,
    THREADS = 2,
    PARSING = 3,
    FLOW = 4
} artexDbgCat_t ;

#define NB_CATEGORY      5

typedef enum { 
    LEVEL_OFF = 0,
    LEVEL_FINE = 1,
    LEVEL_FINER = 2,
    LEVEL_FINEST = 3
} artexDbgLvl_t ;

/*
 * The following structures are passed to the error and warning callback
 * functions.
 */
typedef struct {    
	artexDbgLvl_t   level; /* Debug level */
	artexDbgCat_t   category; /*Debug category */
	char		*message; /* Textual version of error code */
} artexDbg_t;

typedef struct {

	artexErr_t	code;     /* Error code */
	char		*message; /* Textual version of error code */
	char		*details; /* Additional details on error */

	pthread_t	pthread;  /* Pthread that raised the error */

} artexError_t;

typedef artexError_t *p_artexError_t;

typedef struct {

	artexWarn_t	code;     /* Warning code */
	char		*message; /* Textual version of warning code */
	char		*details; /* Additional details on warning */

	pthread_t	pthread;  /* Pthread that raised the warning */

} artexWarning_t;

typedef artexWarning_t *p_artexWarning_t;

typedef void (*artexErrorCallback_t)(void *, p_artexError_t);
typedef void (*artexWarningCallback_t)(void *, p_artexWarning_t);
typedef void (*artexDebugCallback_t)(void *, artexDbg_t *);

/*
 * ARTEX interface definitions.
 */

artexErr_t artexparse(const char *, artexProfileHandle_t *, bool);

#define SELECT_DYNAMIC          0x1
#define SELECT_DISRUPTIVE       0x2
#define SELECT_REBOOT           0x4
#define SELECT_READ_WRITE       0x8 /* Select parameters which are not read-only */
#define DO_ONLY_IF_NOREBOOT     0
#define SELECT_NOREBOOT         (SELECT_DYNAMIC | SELECT_DISRUPTIVE)
#define SELECT_ALL              0xffffffff
typedef uint32_t artexSelector_t;
artexErr_t artexselect(artexProfileHandle_t, artexSelector_t, artexProfileHandle_t*);

typedef enum { GET_CURRENT, GET_NEXTBOOT, GET_PROFILE } artexGetType_t;
artexErr_t artexget(artexProfileHandle_t, artexGetType_t);

#define SET_AND_CHECK    0x1
#define ROLLBACK         0x2
#define SET_AND_DISCOVER 0x4

#define KEYID   1
#define KEYID_LOG   2   

typedef uint32_t artexSetflags_t;
artexErr_t artexset(artexProfileHandle_t, artexProfileHandle_t, artexSetflags_t, artexApplyType_t, artexSetData_t*);

artexErr_t artexpretend(artexProfileHandle_t, p_artexPretendData_t*);


typedef int artexDiffResult_t;

#define DIFFRESULT_MATCH          0x0
#define DIFFRESULT_VALUE      	  0x1
#define DIFFRESULT_FLAG 	  0x2
#define DIFFRESULT_FLAG_AND_VAL   0x3
#define DIFFRESULT_MISSING 	  0x4
#define DIFFRESULT_PROPERTY       0x8
#define DIFFRESULT_ERR            (artexDiffResult_t) -1

typedef int artexDiffFlag_t;
#define DIFFFLAG_SUMMARY	0x1
#define DIFFFLAG_INFO		0x2
#define DIFFFLAG_SYSCOMPARE	0x4

/* type artexDiffData */
#define TYPE_PARAMETER	 	0x0
#define TYPE_SEED 		0x1
typedef struct artexDiffDataParameter {
	artexParamValue_t        value; 
	struct artexParameterFlag {
        	int  appType:1;
        	int  readOnly:1;
        	int  reboot:1;
	} 			flags;
	char			 *parameterMatch;   	/* for seed only */
	p_artexTarget_t          target;		/* parameter's list of targets */
        p_artexProperty_t        property;      /* pointer to the first element of
                                                   the list of property for the parameter */
} artexDiffDataParameter_t;

typedef struct artexDiffData {
        int type;				/* parameter or Seed */	
	struct artexDiffData	*nextParam;	/* pointer to next parameter in list */
	char			*paramName;	/* parameter name */
	char			*catName;	/* catalog name */
	artexDiffResult_t	result;		/* indicates if the parameters match or not: see 
						   above constants (DIFFRESULT_...) */
	artexDiffDataParameter_t *param1;	/* 1st parameter (from profile #1) */
	artexDiffDataParameter_t *param2;	/* 2nd parameter (from profile #2) */
	artexValueType_t        paramType;      /* parameter type */
	char			* description;	/* parameter description */
} artexDiffData_t;

typedef artexDiffData_t *p_artexDiffData_t;
typedef union {
        p_artexDiffData_t diffData;
        char *xmlDiff;
        artexProfileHandle_t profileHandle;
} diffResult_t;


typedef enum { DIFF_O_ALL, DIFF_O_COMMON, DIFF_O_DIFF } diffOutput_t;
typedef enum { DIFF_F_XMLP, DIFF_F_XML, DIFF_F_BIN } diffOformat_t;

artexErr_t artexdiff(artexProfileHandle_t, artexProfileHandle_t, diffOutput_t, diffOformat_t, artexDiffFlag_t, int *, diffResult_t*);

artexErr_t artexph2xml(const artexProfileHandle_t, bool, char**);

artexErr_t artexph2bin(const artexProfileHandle_t, binProfile_t*);

artexErr_t artexphdup(artexProfileHandle_t, artexProfileHandle_t*);

artexErr_t artexphfree(artexProfileHandle_t);
void artexdifffree(p_artexDiffData_t diffData);

artexErr_t artexinit();
void artexcleanup();

artexErr_t artexmerge(const char**, bool, char*, char*, char**);

typedef enum { RDLOCK, WRLOCK } lockType_t;
artexErr_t artexlock(lockType_t, int keyid);
artexErr_t artexunlock(lockType_t, int keyid);

artexErr_t artexerr(artexErr_t, char**);

artexErr_t artexlist(char***, char*);

artexErr_t artexcat(char***);

void artexSetErrorCallback(artexErrorCallback_t, const void *);
void artexSetWarningCallback(artexWarningCallback_t, const void *);
void artexSetWarningComCallback(artexWarningCallback_t, const void *);
void artexSetDebugCallback(artexDebugCallback_t, const void *);
void artexSetDebugLogCallback(artexDebugCallback_t, const void *);
void artexSetDebugLevel(artexDbgLvl_t);
void artexSetDebugCat(artexDbgCat_t, bool);

artexErr_t artexldapget(const char*, char**);
artexErr_t artexldaplist(char***);

void artexRetrieveCoreVers(char**);
artexErr_t artexRetrieveProfileVers(char*, char**);
artexErr_t artexIncRevision(artexProfileHandle_t*);
artexErr_t artexSetRevision(artexProfileHandle_t*, char*);

void artexSetComments(artexProfileHandle_t*, char*);
char * artexCategoryDebug(artexDbgCat_t);
void artexDebug(artexDbgCat_t, artexDbgLvl_t, char *, ...);
bool artexIsDbgOn(artexDbgLvl_t level, artexDbgCat_t dbgcat);


typedef enum { UNDEFINED_RESULT = -1, EQUAL_VERSIONS, V1_GREATER, V2_GREATER} artexCompVersions_t;
artexCompVersions_t artexCompareVers(char*, char*);

artexErr_t artexphreduce(artexProfileHandle_t ph);

#ifdef __cplusplus
}
#endif

#endif /* _H_ARTEXEXT */