# db.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  $RCSfile: db.h,v $
    00003  -------------------
    00004  cvs         : $Id: db.h,v 1.41 2005/03/09 11:34:30 aquamaniac Exp $
    00005  begin       : Tue Sep 09 2003
    00006  copyright   : (C) 2003 by Martin Preuss
    00007  email       : martin@libchipcard.de
    00008
    00009  ***************************************************************************
    00010  *                                                                         *
    00011  *   This library is free software; you can redistribute it and/or         *
    00012  *   modify it under the terms of the GNU Lesser General Public            *
    00013  *   License as published by the Free Software Foundation; either          *
    00014  *   version 2.1 of the License, or (at your option) any later version.    *
    00015  *                                                                         *
    00016  *   This library is distributed in the hope that it will be useful,       *
    00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
    00019  *   Lesser General Public License for more details.                       *
    00020  *                                                                         *
    00021  *   You should have received a copy of the GNU Lesser General Public      *
    00022  *   License along with this library; if not, write to the Free Software   *
    00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
    00024  *   MA  02111-1307  USA                                                   *
    00025  *                                                                         *
    00026  ***************************************************************************/
    00027
    00028
    00031 #ifndef GWENHYWFAR_DB_H
    00032 #define GWENHYWFAR_DB_H
    00033
    00034 #include <gwenhywfar/gwenhywfarapi.h>
    00035 #include <gwenhywfar/path.h>
    00036 #include <gwenhywfar/bufferedio.h>
    00037 #include <gwenhywfar/types.h>
    00038 #include <stdio.h>
    00039
    00040 #ifdef __cplusplus
    00041 extern "C" {
    00042 #endif
    00043
    00044
    00105 #define GWEN_DB_LINE_MAXSIZE  1024
    00106
    00122 #define GWEN_DB_FLAGS_OVERWRITE_VARS         0x00010000
    00123
    00124 #define GWEN_DB_FLAGS_OVERWRITE_GROUPS       0x00020000
    00125
    00126 #define GWEN_DB_FLAGS_QUOTE_VARNAMES         0x00040000
    00127
    00128 #define GWEN_DB_FLAGS_QUOTE_VALUES           0x00080000
    00129
    00130 #define GWEN_DB_FLAGS_WRITE_SUBGROUPS        0x00100000
    00131
    00132 #define GWEN_DB_FLAGS_DETAILED_GROUPS        0x00200000
    00133
    00135 #define GWEN_DB_FLAGS_INDEND                 0x00400000
    00136
    00138 #define GWEN_DB_FLAGS_ADD_GROUP_NEWLINES     0x00800000
    00139
    00141 #define GWEN_DB_FLAGS_USE_COLON              0x01000000
    00142
    00143 #define GWEN_DB_FLAGS_STOP_ON_EMPTY_LINE     0x02000000
    00144
    00146 #define GWEN_DB_FLAGS_OMIT_TYPES             0x04000000
    00147
    00148 #define GWEN_DB_FLAGS_APPEND_FILE            0x08000000
    00149
    00150 #define GWEN_DB_FLAGS_ESCAPE_CHARVALUES      0x10000000
    00151
    00153 #define GWEN_DB_FLAGS_UNESCAPE_CHARVALUES    0x10000000
    00154
    00156 #define GWEN_DB_FLAGS_LOCKFILE               0x20000000
    00157
    00158 #define GWEN_DB_FLAGS_DEFAULT \
    00159   (\
    00160   GWEN_DB_FLAGS_QUOTE_VALUES | \
    00161   GWEN_DB_FLAGS_WRITE_SUBGROUPS | \
    00162   GWEN_DB_FLAGS_DETAILED_GROUPS | \
    00163   GWEN_DB_FLAGS_INDEND | \
    00164   GWEN_DB_FLAGS_ADD_GROUP_NEWLINES | \
    00165   GWEN_DB_FLAGS_ESCAPE_CHARVALUES | \
    00166   GWEN_DB_FLAGS_UNESCAPE_CHARVALUES\
    00167   )
    00168
    00169
    00172 #define GWEN_DB_FLAGS_COMPACT \
    00173   (\
    00174   GWEN_DB_FLAGS_QUOTE_VALUES | \
    00175   GWEN_DB_FLAGS_WRITE_SUBGROUPS | \
    00176   GWEN_DB_FLAGS_ESCAPE_CHARVALUES | \
    00177   GWEN_DB_FLAGS_UNESCAPE_CHARVALUES\
    00178   )
    00179
    00183 #define GWEN_DB_FLAGS_HTTP \
    00184   (\
    00185   GWEN_DB_FLAGS_USE_COLON |\
    00186   GWEN_DB_FLAGS_STOP_ON_EMPTY_LINE\
    00187   )
    00188
    00195 #define GWEN_DB_NODE_FLAGS_DIRTY                   0x00000001
    00196
    00197 #define GWEN_DB_NODE_FLAGS_VOLATILE                0x00000002
    00198
    00200 #define GWEN_DB_NODE_FLAGS_INHERIT_HASH_MECHANISM  0x00000004
    00201
    00211 typedef union GWEN_DB_NODE GWEN_DB_NODE;
    00212
    00216 typedef enum {
    00218   GWEN_DB_VALUETYPE_UNKNOWN=0,
    00220   GWEN_DB_VALUETYPE_CHAR,
    00222   GWEN_DB_VALUETYPE_INT,
    00224   GWEN_DB_VALUETYPE_BIN,
    00226   GWEN_DB_VALUETYPE_PTR
    00227 } GWEN_DB_VALUETYPE;
    00228
    00229
    00234
    00241 GWENHYWFAR_API
    00242 GWEN_DB_NODE *GWEN_DB_Group_new(const char *name);
    00243
    00249 GWENHYWFAR_API
    00250 void GWEN_DB_Group_free(GWEN_DB_NODE *n);
    00251
    00252
    00259 GWENHYWFAR_API
    00260 GWEN_DB_NODE *GWEN_DB_Group_dup(const GWEN_DB_NODE *n);
    00261
    00279 GWENHYWFAR_API
    00280 GWEN_DB_NODE *GWEN_DB_GetFirstGroup(GWEN_DB_NODE *n);
    00281
    00304 GWENHYWFAR_API
    00305 GWEN_DB_NODE *GWEN_DB_GetNextGroup(GWEN_DB_NODE *n);
    00306
    00307
    00319 GWENHYWFAR_API
    00320 GWEN_DB_NODE *GWEN_DB_FindFirstGroup(GWEN_DB_NODE *n, const char *name);
    00321
    00340 GWENHYWFAR_API
    00341 GWEN_DB_NODE *GWEN_DB_FindNextGroup(GWEN_DB_NODE *n, const char *name);
    00342
    00343
    00354 typedef void *(*GWEN_DB_NODES_CB)(GWEN_DB_NODE *node, void *user_data);
    00355
    00372 GWENHYWFAR_API
    00373 void *GWEN_DB_Groups_Foreach(GWEN_DB_NODE *node, GWEN_DB_NODES_CB func,
    00374                              void *user_data);
    00375
    00379 GWENHYWFAR_API
    00380 unsigned int GWEN_DB_Groups_Count(const GWEN_DB_NODE *node);
    00438 GWENHYWFAR_API
    00439 const char *GWEN_DB_GetCharValue(GWEN_DB_NODE *n,
    00440                                  const char *path,
    00441                                  int idx,
    00442                                  const char *defVal);
    00451 GWENHYWFAR_API
    00452 int GWEN_DB_SetCharValue(GWEN_DB_NODE *n,
    00453                          GWEN_TYPE_UINT32 flags,
    00454                          const char *path,
    00455                          const char *val);
    00456
    00457
    00468 GWENHYWFAR_API
    00469 int GWEN_DB_AddCharValue(GWEN_DB_NODE *n,
    00470                          const char *path,
    00471                          const char *val,
    00472                          int senseCase,
    00473                          int check);
    00474
    00475
    00483 GWENHYWFAR_API
    00484 int GWEN_DB_GetIntValue(GWEN_DB_NODE *n,
    00485                         const char *path,
    00486                         int idx,
    00487                         int defVal);
    00488
    00497 GWENHYWFAR_API
    00498 int GWEN_DB_SetIntValue(GWEN_DB_NODE *n,
    00499                         GWEN_TYPE_UINT32 flags,
    00500                         const char *path,
    00501                         int val);
    00502
    00503
    00515 GWENHYWFAR_API
    00516 const void *GWEN_DB_GetBinValue(GWEN_DB_NODE *n,
    00517                                 const char *path,
    00518                                 int idx,
    00519                                 const void *defVal,
    00520                                 unsigned int defValSize,
    00521                                 unsigned int *returnValueSize);
    00522
    00533 GWENHYWFAR_API
    00534 int GWEN_DB_SetBinValue(GWEN_DB_NODE *n,
    00535                         GWEN_TYPE_UINT32 flags,
    00536                         const char *path,
    00537                         const void *val,
    00538                         unsigned int valSize);
    00539
    00540
    00548 GWENHYWFAR_API
    00549 void *GWEN_DB_GetPtrValue(GWEN_DB_NODE *n,
    00550                           const char *path,
    00551                           int idx,
    00552                           void *defVal);
    00553
    00563 GWENHYWFAR_API
    00564 int GWEN_DB_SetPtrValue(GWEN_DB_NODE *n,
    00565                         GWEN_TYPE_UINT32 flags,
    00566                         const char *path,
    00567                         void *val);
    00576
    00586 GWENHYWFAR_API
    00587 GWEN_DB_NODE *GWEN_DB_GetGroup(GWEN_DB_NODE *n,
    00588                                GWEN_TYPE_UINT32 flags,
    00589                                const char *path);
    00590
    00594 GWENHYWFAR_API
    00595 const char *GWEN_DB_GroupName(GWEN_DB_NODE *n);
    00596
    00602 GWENHYWFAR_API
    00603 void GWEN_DB_GroupRename(GWEN_DB_NODE *n, const char *newname);
    00604
    00619 GWENHYWFAR_API
    00620 int GWEN_DB_AddGroup(GWEN_DB_NODE *parent, GWEN_DB_NODE *node);
    00621
    00637 GWENHYWFAR_API
    00638 int GWEN_DB_InsertGroup(GWEN_DB_NODE *parent, GWEN_DB_NODE *node);
    00639
    00649 GWENHYWFAR_API
    00650 int GWEN_DB_AddGroupChildren(GWEN_DB_NODE *n, GWEN_DB_NODE *nn);
    00651
    00661 GWENHYWFAR_API
    00662 void GWEN_DB_UnlinkGroup(GWEN_DB_NODE *n);
    00663
    00670 GWENHYWFAR_API
    00671 int GWEN_DB_DeleteGroup(GWEN_DB_NODE *n,
    00672                         const char *path);
    00680 GWENHYWFAR_API
    00681 int GWEN_DB_ClearGroup(GWEN_DB_NODE *n,
    00682                        const char *path);
    00683
    00690 GWENHYWFAR_API
    00691 int GWEN_DB_IsGroup(const GWEN_DB_NODE *n);
    00692
    00704 GWENHYWFAR_API
    00705   GWEN_TYPE_UINT32 GWEN_DB_GetNodeFlags(const GWEN_DB_NODE *n);
    00706
    00712 GWENHYWFAR_API
    00713   void GWEN_DB_SetNodeFlags(GWEN_DB_NODE *n,
    00714                             GWEN_TYPE_UINT32 flags);
    00715
    00724 void GWEN_DB_ModifyBranchFlagsUp(GWEN_DB_NODE *n,
    00725                                  GWEN_TYPE_UINT32 newflags,
    00726                                  GWEN_TYPE_UINT32 mask);
    00727
    00736 void GWEN_DB_ModifyBranchFlagsDown(GWEN_DB_NODE *n,
    00737                                    GWEN_TYPE_UINT32 newflags,
    00738                                    GWEN_TYPE_UINT32 mask);
    00739
    00753
    00761 GWENHYWFAR_API
    00762 int GWEN_DB_ReadFromStream(GWEN_DB_NODE *n,
    00763                            GWEN_BUFFEREDIO *bio,
    00764                            GWEN_TYPE_UINT32 dbflags);
    00765
    00773 GWENHYWFAR_API
    00774 int GWEN_DB_ReadFile(GWEN_DB_NODE *n,
    00775                      const char *fname,
    00776                      GWEN_TYPE_UINT32 dbflags);
    00777
    00785 GWENHYWFAR_API
    00786 int GWEN_DB_WriteToStream(GWEN_DB_NODE *n,
    00787                           GWEN_BUFFEREDIO *bio,
    00788                           GWEN_TYPE_UINT32 dbflags);
    00789
    00798 GWENHYWFAR_API
    00799 int GWEN_DB_WriteFile(GWEN_DB_NODE *n,
    00800                       const char *fname,
    00801                       GWEN_TYPE_UINT32 dbflags);
    00802
    00813 GWENHYWFAR_API
    00814 int GWEN_DB_ReadFileAs(GWEN_DB_NODE *n,
    00815                        const char *fname,
    00816                        const char *type,
    00817                        GWEN_DB_NODE *params,
    00818                        GWEN_TYPE_UINT32 dbflags);
    00819
    00830 GWENHYWFAR_API
    00831 int GWEN_DB_WriteFileAs(GWEN_DB_NODE *n,
    00832                         const char *fname,
    00833                         const char *type,
    00834                         GWEN_DB_NODE *params,
    00835                         GWEN_TYPE_UINT32 dbflags);
    00848 GWENHYWFAR_API
    00849 GWEN_DB_NODE *GWEN_DB_GetFirstVar(GWEN_DB_NODE *n);
    00850
    00851
    00873 GWENHYWFAR_API
    00874 GWEN_DB_NODE *GWEN_DB_GetNextVar(GWEN_DB_NODE *n);
    00875
    00880 GWENHYWFAR_API
    00881 const char *GWEN_DB_VariableName(GWEN_DB_NODE *n);
    00882
    00899 GWENHYWFAR_API
    00900 void *GWEN_DB_Variables_Foreach(GWEN_DB_NODE *node, GWEN_DB_NODES_CB func,
    00901                                 void *user_data);
    00902
    00907 GWENHYWFAR_API
    00908 unsigned int GWEN_DB_Variables_Count(const GWEN_DB_NODE *node);
    00909
    00915 GWENHYWFAR_API
    00916 GWEN_DB_VALUETYPE GWEN_DB_GetVariableType(GWEN_DB_NODE *n,
    00917                                           const char *p);
    00918
    00925 GWENHYWFAR_API
    00926 int GWEN_DB_DeleteVar(GWEN_DB_NODE *n,
    00927                       const char *path);
    00928
    00935 GWENHYWFAR_API
    00936 int GWEN_DB_VariableExists(GWEN_DB_NODE *n,
    00937                            const char *path);
    00938
    00946 GWENHYWFAR_API
    00947   int GWEN_DB_ValueExists(GWEN_DB_NODE *n,
    00948                           const char *path,
    00949                           unsigned int idx);
    00950
    00957 GWENHYWFAR_API
    00958 int GWEN_DB_IsVariable(const GWEN_DB_NODE *n);
    00971 GWENHYWFAR_API
    00972 GWEN_DB_NODE *GWEN_DB_GetFirstValue(GWEN_DB_NODE *n);
    00973
    00998 GWENHYWFAR_API
    00999 GWEN_DB_NODE *GWEN_DB_GetNextValue(GWEN_DB_NODE *n);
    01000
    01017 GWENHYWFAR_API
    01018 void *GWEN_DB_Values_Foreach(GWEN_DB_NODE *node, GWEN_DB_NODES_CB func,
    01019                              void *user_data);
    01020
    01024 GWENHYWFAR_API
    01025 unsigned int GWEN_DB_Values_Count(const GWEN_DB_NODE *node);
    01026
    01031 GWENHYWFAR_API
    01032 GWEN_DB_VALUETYPE GWEN_DB_GetValueType(GWEN_DB_NODE *n);
    01033
    01034 GWENHYWFAR_API
    01035 GWEN_DB_VALUETYPE GWEN_DB_GetValueTypeByPath(GWEN_DB_NODE *n,
    01036                                              const char *p,
    01037                                              unsigned int i);
    01038
    01045 GWENHYWFAR_API
    01046 int GWEN_DB_IsValue(const GWEN_DB_NODE *n);
    01060
    01067 GWENHYWFAR_API
    01068 void GWEN_DB_Dump(GWEN_DB_NODE *n, FILE *f, int insert);
    01081 typedef struct GWEN_DB_HASH_MECHANISM GWEN_DB_HASH_MECHANISM;
    01082
    01083 typedef int (*GWEN_DB_HASH_INITNODE_FN)(GWEN_DB_HASH_MECHANISM *hm,
    01084                                         GWEN_DB_NODE *node,
    01085                                         void **hashData);
    01086 typedef int (*GWEN_DB_HASH_FININODE_FN)(GWEN_DB_HASH_MECHANISM *hm,
    01087                                         GWEN_DB_NODE *node,
    01088                                         void **hashData);
    01089 typedef int (*GWEN_DB_HASH_ADDNODE_FN)(GWEN_DB_HASH_MECHANISM *hm,
    01090                                        GWEN_DB_NODE *parent,
    01091                                        GWEN_DB_NODE *node,
    01092                                        int appendOrInsert, /* 1=append */
    01093                                        void *hashData);
    01094 typedef int (*GWEN_DB_HASH_UNLINKNODE_FN)(GWEN_DB_HASH_MECHANISM *hm,
    01095                                           GWEN_DB_NODE *parent,
    01096                                           GWEN_DB_NODE *node,
    01097                                           void *hashData);
    01098 typedef GWEN_DB_NODE* (*GWEN_DB_HASH_GETNODE_FN)(GWEN_DB_HASH_MECHANISM *hm,
    01099                                                  GWEN_DB_NODE *parent,
    01100                                                  const char *name,
    01101                                                  int idx,
    01102                                                  void *hashData);
    01103
    01104 GWENHYWFAR_API
    01105 GWEN_DB_HASH_MECHANISM *GWEN_DB_HashMechanism_new();
    01106
    01107 GWENHYWFAR_API
    01108 void GWEN_DB_HashMechanism_Attach(GWEN_DB_HASH_MECHANISM *hm);
    01109
    01110 GWENHYWFAR_API
    01111 void GWEN_DB_HashMechanism_free(GWEN_DB_HASH_MECHANISM *hm);
    01112
    01113
    01114 GWENHYWFAR_API
    01115 void GWEN_DB_HashMechanism_SetInitNodeFn(GWEN_DB_HASH_MECHANISM *hm,
    01116                                          GWEN_DB_HASH_INITNODE_FN f);
    01117
    01118 GWENHYWFAR_API
    01119 void GWEN_DB_HashMechanism_SetFiniNodeFn(GWEN_DB_HASH_MECHANISM *hm,
    01120                                          GWEN_DB_HASH_FININODE_FN f);
    01121
    01122 GWENHYWFAR_API
    01123 void GWEN_DB_HashMechanism_SetAddNodeFn(GWEN_DB_HASH_MECHANISM *hm,
    01124                                         GWEN_DB_HASH_ADDNODE_FN f);
    01125
    01126 GWENHYWFAR_API
    01127 void GWEN_DB_HashMechanism_SetUnlinkNodeFn(GWEN_DB_HASH_MECHANISM *hm,
    01128                                            GWEN_DB_HASH_UNLINKNODE_FN f);
    01129
    01130 GWENHYWFAR_API
    01131 void GWEN_DB_HashMechanism_SetGetNodeFn(GWEN_DB_HASH_MECHANISM *hm,
    01132                                         GWEN_DB_HASH_GETNODE_FN f);
    01133
    01134
    01149 GWENHYWFAR_API
    01150 int GWEN_DB_Group_SetHashMechanism(GWEN_DB_NODE *node,
    01151                                    GWEN_DB_HASH_MECHANISM *hm);
    01152
    01157
    01158
    01159 #ifdef __cplusplus
    01160 }
    01161 #endif
    01162
    01163
    01164 #endif
    01165
    01166
    01167