Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Enduro/X ini config driver
0003  *
0004  * @file inicfg.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 #ifndef _INICFG_H
0035 #define _INICFG_H
0036 
0037 #ifdef  __cplusplus
0038 extern "C" {
0039 #endif
0040 
0041 /*---------------------------Includes-----------------------------------*/
0042 #include <sys/stat.h>
0043 #include <stdint.h>
0044 #include <exhash.h>
0045 #include <sys_unix.h>
0046 #include <limits.h>
0047 /*---------------------------Externs------------------------------------*/
0048 #define NDRX_INICFG_SUBSECT_SPERATOR '/' /* seperate sub-sections with */
0049 #define NDRX_INICFG_SUBSECT_SPERATOR_STR "/" /* seperate sub-sections with */
0050 #define NDRX_INICFG_RESOURCES_MAX   5
0051 /*---------------------------Macros-------------------------------------*/
0052 /*---------------------------Enums--------------------------------------*/
0053 /*---------------------------Typedefs-----------------------------------*/
0054 
0055 /**
0056  * This is key/value entry (linked list)
0057  */
0058 typedef struct ndrx_inicfg_section_keyval ndrx_inicfg_section_keyval_t;
0059 struct ndrx_inicfg_section_keyval
0060 {
0061     char *section; /* section */
0062     char *key; /* key for ini */
0063     char *val; /* value for ini */
0064     
0065     EX_hash_handle hh;         /* makes this structure hashable */
0066 };
0067 
0068 /**
0069  * This is section handler
0070  */    
0071 struct ndrx_inicfg_section
0072 {
0073     char *section; /* section */
0074     
0075     ndrx_inicfg_section_keyval_t *values; /* list of values */
0076     
0077     EX_hash_handle hh;         /* makes this structure hashable */
0078 };
0079 typedef struct ndrx_inicfg_section ndrx_inicfg_section_t;
0080 
0081 /**
0082  * Config handler
0083  */
0084 struct ndrx_inicfg_file
0085 {
0086     /* full path */
0087     char fullname[PATH_MAX+1];
0088     /* original path */
0089     char resource[PATH_MAX+1];
0090     
0091     struct stat attr; /* time stamp when read */
0092     
0093     ndrx_inicfg_section_t *sections;
0094     
0095     int refreshed; /* marked as not refreshed (to kill after reload) */
0096     EX_hash_handle hh;         /* makes this structure hashable */
0097 };
0098 
0099 typedef struct ndrx_inicfg_file ndrx_inicfg_file_t;
0100 
0101 
0102 /**
0103  * Config handle
0104  */
0105 struct ndrx_inicfg
0106 {
0107     int load_global_env; /* Should we load global env */
0108     /* resource files (if set to EOS, not used) */
0109     /* List of resources */
0110     string_hash_t *resource_hash;
0111     ndrx_inicfg_file_t *cfgfile;
0112 };
0113 
0114 typedef struct ndrx_inicfg ndrx_inicfg_t;
0115 
0116 
0117 /*---------------------------Globals------------------------------------*/
0118 /*---------------------------Statics------------------------------------*/
0119 /*---------------------------Prototypes---------------------------------*/
0120 extern NDRX_API  ndrx_inicfg_t * ndrx_inicfg_new(void);
0121 extern NDRX_API ndrx_inicfg_t * ndrx_inicfg_new2(int load_global_env);
0122 extern NDRX_API  int ndrx_inicfg_load_single_file(ndrx_inicfg_t *cfg, 
0123         char *resource, char *fullname, char **section_start_with);
0124 extern NDRX_API  int ndrx_inicfg_update_single_file(ndrx_inicfg_t *cfg, 
0125         char *resource, char *fullname, char **section_start_with);
0126 extern NDRX_API  int ndrx_inicfg_add(ndrx_inicfg_t *cfg, char *resource, char **section_start_with);
0127 extern NDRX_API  int ndrx_inicfg_reload(ndrx_inicfg_t *cfg, char **section_start_with);
0128 extern NDRX_API  int ndrx_keyval_hash_add(ndrx_inicfg_section_keyval_t **h, 
0129             ndrx_inicfg_section_keyval_t *src);
0130 extern NDRX_API  ndrx_inicfg_section_keyval_t * ndrx_keyval_hash_get(
0131         ndrx_inicfg_section_keyval_t *h, char *key);
0132 extern NDRX_API  void ndrx_keyval_hash_free(ndrx_inicfg_section_keyval_t *h);
0133 extern NDRX_API  int ndrx_inicfg_resolve(ndrx_inicfg_t *cfg, char **resources, char *section, 
0134         ndrx_inicfg_section_keyval_t **out);
0135 extern NDRX_API  int ndrx_inicfg_get_subsect(ndrx_inicfg_t *cfg, 
0136         char **resources, char *section, ndrx_inicfg_section_keyval_t **out);
0137 extern NDRX_API  int ndrx_inicfg_iterate(ndrx_inicfg_t *cfg, 
0138         char **resources,
0139         char **section_start_with, 
0140         ndrx_inicfg_section_t **out);
0141 extern NDRX_API  void ndrx_inicfg_sections_free(ndrx_inicfg_section_t *sections);
0142 extern NDRX_API  void ndrx_inicfg_file_free(ndrx_inicfg_t *cfg, ndrx_inicfg_file_t *cfgfile);
0143 extern NDRX_API  void ndrx_inicfg_free(ndrx_inicfg_t *cfg);
0144 
0145 #ifdef  __cplusplus
0146 }
0147 #endif
0148 
0149 #endif  /* _INICFG_H */
0150 
0151 /* vim: set ts=4 sw=4 et smartindent: */