MidgardConfig

MidgardConfig — Midgard unified config representation.

Synopsis

#include <midgard/midgard.h>

typedef             MidgardConfig;
typedef             MidgardConfigClass;
                    MidgardConfigPrivate;
enum                MidgardDBType;
MidgardConfig *     midgard_config_new                  (void);
gboolean            midgard_config_read_file            (MidgardConfig *self,
                                                         const gchar *filename,
                                                         gboolean user,
                                                         GError **error);
gboolean            midgard_config_read_file_at_path    (MidgardConfig *self,
                                                         const gchar *filepath,
                                                         GError **error);
gboolean            midgard_config_read_data            (MidgardConfig *self,
                                                         const gchar *data,
                                                         GError **error);
gchar **            midgard_config_list_files           (gboolean user);
gboolean            midgard_config_save_file            (MidgardConfig *self,
                                                         const gchar *name,
                                                         gboolean user,
                                                         GError **error);
gboolean            midgard_config_create_blobdir       (MidgardConfig *self);

Object Hierarchy

  GObject
   +----MidgardConfig

Properties

  "authtype"                 gchar*                : Read / Write
  "blobdir"                  gchar*                : Read / Write
  "cachedir"                 gchar*                : Read / Write
  "database"                 gchar*                : Read / Write
  "dbdir"                    gchar*                : Read / Write
  "dbpass"                   gchar*                : Read / Write
  "dbtype"                   gchar*                : Read / Write
  "dbuser"                   gchar*                : Read / Write
  "host"                     gchar*                : Read / Write
  "logfilename"              gchar*                : Read / Write
  "loglevel"                 gchar*                : Read / Write
  "midgardpassword"          gchar*                : Read / Write
  "midgardusername"          gchar*                : Read / Write
  "pamfile"                  gchar*                : Read / Write
  "port"                     guint                 : Read / Write
  "sharedir"                 gchar*                : Read / Write
  "tablecreate"              gboolean              : Read / Write
  "tableupdate"              gboolean              : Read / Write
  "testunit"                 gboolean              : Read / Write
  "vardir"                   gchar*                : Read / Write

Description

MidgardConfig class represents Midgard unified configuration file. Underlying configuration file representation is limited to GKeyFile. There are few ways to read configuration data: midgard_config_read_file(), which encapsulates real file location, midgard_config_read_file_at_path() if file location is not common or very specific for application or midgard_config_read_data(), which reads configuration from given buffer.

Details

MidgardConfig

typedef struct MidgardConfig MidgardConfig;


MidgardConfigClass

typedef struct MidgardConfigClass MidgardConfigClass;


MidgardConfigPrivate

typedef struct _MidgardConfigPrivate MidgardConfigPrivate;


enum MidgardDBType

typedef enum {
        MIDGARD_DB_TYPE_MYSQL = 1, 
        MIDGARD_DB_TYPE_POSTGRES, 
        MIDGARD_DB_TYPE_FREETDS, 
        MIDGARD_DB_TYPE_SQLITE, 
        MIDGARD_DB_TYPE_ODBC, 
        MIDGARD_DB_TYPE_ORACLE 
} MidgardDBType;


midgard_config_new ()

MidgardConfig *     midgard_config_new                  (void);

Initializes new instance of MidgardConfig object type. NULL is returned when object can not be initialized.

Returns :

pointer to MidgardConfig object or NULL on failure.

midgard_config_read_file ()

gboolean            midgard_config_read_file            (MidgardConfig *self,
                                                         const gchar *filename,
                                                         gboolean user,
                                                         GError **error);

This method reads configuration file from the given name and sets MidgardConfig object's properties. Such initialized MidgardConfig instance may be reused among midgard-core and midgard-php extension for example, without any need to re-read configuration file and without any need to re-initalize MidgardConfig object instance.

Set TRUE as user boolean value to read files from user's home directory.

self :

MidgardConfig object instance

filename :

name of the file to read

user :

boolean switch for system or user's config files

error :

pointer to store error

Returns :

TRUE when file has been read , FALSE otherwise.

Since 9.3


midgard_config_read_file_at_path ()

gboolean            midgard_config_read_file_at_path    (MidgardConfig *self,
                                                         const gchar *filepath,
                                                         GError **error);

self :

MidgardConfig instance

filepath :

a path to read file from

error :

a pointer to hold error

Returns :

TRUE if file has been read, FALSE otherwise

midgard_config_read_data ()

gboolean            midgard_config_read_data            (MidgardConfig *self,
                                                         const gchar *data,
                                                         GError **error);

self :

MidgardConfig instance

data :

a NULL-terminated buffer containing the configuration

error :

a pointer to hold error

Returns :

TRUE if data has been read, FALSE otherwise

midgard_config_list_files ()

gchar **            midgard_config_list_files           (gboolean user);

List all available configuration files. If user value is set to TRUE, all available files from ~/.midgard/conf.d will be listed. Only system files ( usually from /etc/midgard/conf.d ) will be listed if user value is set to FALSE.

Returned array should be freed when no longer needed.

user :

boolean switch for system or user's config files

Returns :

newly allocated and NULL terminated array of file names. [transfer full]

midgard_config_save_file ()

gboolean            midgard_config_save_file            (MidgardConfig *self,
                                                         const gchar *name,
                                                         gboolean user,
                                                         GError **error);

Saves configuration file for the given MidgardConfig.

This method saves configuration file with the given name. If third user parameter is set to TRUE, then configuration file will be saved in ~/.midgard2/conf.d directory.

User's conf.d directory will be created if doesn't exist.

self :

MidgardConfig instance

name :

configuration filename

user :

system or home directory switch

error :

pointer to store GError

Returns :

TRUE on success or FALSE ( with propper warning message ) if system wide directory doesn't exist or file can not be saved.

midgard_config_create_blobdir ()

gboolean            midgard_config_create_blobdir       (MidgardConfig *self);

Creates directories for blobs

self :

MidgardConfig instance

Returns :

TRUE on success, FALSE otherwise.

Property Details

The "authtype" property

  "authtype"                 gchar*                : Read / Write

Authentication type used with connection.

Default value: ""


The "blobdir" property

  "blobdir"                  gchar*                : Read / Write

Location of the blobs directory.

Default value: ""


The "cachedir" property

  "cachedir"                 gchar*                : Read / Write

Cached files.

Default value: ""


The "database" property

  "database"                 gchar*                : Read / Write

Name of the database.

Default value: "midgard"


The "dbdir" property

  "dbdir"                    gchar*                : Read / Write

Directory for SQLite database file ('~/.midgard2/data' by default).

Default value: ""


The "dbpass" property

  "dbpass"                   gchar*                : Read / Write

Password used by user who is able to connect to database.

Default value: "midgard"


The "dbtype" property

  "dbtype"                   gchar*                : Read / Write

Database type ( by default MySQL ).

Default value: "MySQL"


The "dbuser" property

  "dbuser"                   gchar*                : Read / Write

Username for user who is able to connect to database.

Default value: "midgard"


The "host" property

  "host"                     gchar*                : Read / Write

Database host ( 'localhost' by default ).

Default value: "localhost"


The "logfilename" property

  "logfilename"              gchar*                : Read / Write

Location of the log file.

Default value: ""


The "loglevel" property

  "loglevel"                 gchar*                : Read / Write

Log level.

Default value: "warn"


The "midgardpassword" property

  "midgardpassword"          gchar*                : Read / Write

Midgard user's password.

Default value: ""


The "midgardusername" property

  "midgardusername"          gchar*                : Read / Write

Midgard user's login.

Default value: ""


The "pamfile" property

  "pamfile"                  gchar*                : Read / Write

Name of the file used with PAM authentication type.

Default value: ""


The "port" property

  "port"                     guint                 : Read / Write

Database port ( 0 by default ).

Default value: 0


The "sharedir" property

  "sharedir"                 gchar*                : Read / Write

Directory for shared, architecture independent files.

Default value: ""


The "tablecreate" property

  "tablecreate"              gboolean              : Read / Write

Database creation switch.

Default value: FALSE


The "tableupdate" property

  "tableupdate"              gboolean              : Read / Write

Database update switch.

Default value: FALSE


The "testunit" property

  "testunit"                 gboolean              : Read / Write

Database and objects testing switch.

Default value: FALSE


The "vardir" property

  "vardir"                   gchar*                : Read / Write

Application specific directories.

Default value: ""