1 ////////////////////////////////////////////////////////////////////////// 2 // 3 // pgAdmin III - PostgreSQL Tools 4 // 5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team 6 // This software is released under the PostgreSQL Licence 7 // 8 // pgconfig.h - backend configuration classes 9 // 10 ////////////////////////////////////////////////////////////////////////// 11 12 13 #ifndef __PGCONFIG 14 #define __PGCONFIG 15 16 #include <wx/hashmap.h> 17 18 19 class pgSet; 20 class pgConn; 21 22 class pgSettingItem; 23 24 class pgConfigLine 25 { 26 public: pgConfigLine()27 pgConfigLine() 28 { 29 item = 0; 30 isComment = false; 31 } 32 33 pgConfigLine(pgConfigLine *line); 34 35 bool Differs(pgConfigLine *line); 36 wxString GetNewText(); 37 38 pgSettingItem *item; 39 wxString value; 40 wxString comment; 41 bool isComment; 42 }; 43 44 class pgConfigOrgLine : public pgConfigLine 45 { 46 public: pgConfigOrgLine(const wxString str)47 pgConfigOrgLine(const wxString str) : pgConfigLine() 48 { 49 text = str; 50 } 51 pgConfigOrgLine(pgConfigLine *line); 52 wxString GetNewText(); 53 54 wxString text; 55 wxString commentIndent; 56 }; 57 58 class pgHbaConfigLine 59 { 60 public: 61 pgHbaConfigLine(const wxString &line = wxEmptyString); 62 wxString GetText(); 63 const wxChar *GetConnectType(); 64 const wxChar *GetMethod(); 65 void Init(const wxString &line); 66 67 enum pgHbaConnectType 68 { 69 PGC_LOCAL = 0, 70 PGC_HOST, 71 PGC_HOSTSSL, 72 PGC_HOSTNOSSL, 73 PGC_INVALIDCONF 74 }; 75 enum pgHbaMethod 76 { 77 PGC_TRUST = 0, 78 PGC_REJECT, 79 PGC_MD5, 80 PGC_CRYPT, 81 PGC_PASSWORD, 82 PGC_KRB4, 83 PGC_KRB5, 84 PGC_IDENT, 85 PGC_PAM, 86 PGC_LDAP, 87 PGC_GSS, 88 PGC_SSPI, 89 PGC_CERT, 90 PGC_PEER, 91 PGC_RADIUS, 92 PGC_INVALIDMETHOD 93 }; 94 95 wxString text; 96 wxString database, user, ipaddress, option; 97 pgHbaConnectType connectType; 98 pgHbaMethod method; 99 100 long item; 101 102 bool isValid; 103 bool isComment; 104 bool changed; 105 }; 106 107 class pgPassConfigLine 108 { 109 public: 110 pgPassConfigLine(const wxString &line = wxEmptyString); 111 wxString GetText(); 112 void Init(const wxString &line); 113 114 wxString text; 115 wxString hostname, port, database, username, password; 116 117 long item; 118 119 bool isComment; 120 }; 121 122 123 class pgSettingItem 124 { 125 public: 126 enum pgConfigType 127 { 128 PGC_BOOL = 0, 129 PGC_INT, 130 PGC_REAL, 131 PGC_STRING 132 }; 133 134 enum pgConfigContext 135 { 136 PGC_INTERNAL = 0, 137 PGC_POSTMASTER, 138 PGC_SIGHUP, 139 PGC_BACKEND, 140 PGC_SUSET, 141 PGC_USERLIMIT, 142 PGC_USERSET, 143 PGC_UNKNOWNCONTEXT 144 }; 145 146 enum pgConfigSource 147 { 148 PGC_DEFAULT = 0, 149 PGC_ENVIRONMENT, 150 PGC_FILE, 151 PGC_ARGV, 152 PGC_UNPRIV, 153 PGC_DATABASE, 154 PGC_USER, 155 PGC_CLIENT, 156 PGC_OVERRIDE, 157 PGC_INTERACTIVE, 158 PGC_TEST, 159 PGC_SESSION, 160 PGC_UNKNOWNSOURCE 161 }; 162 pgSettingItem()163 pgSettingItem() 164 { 165 orgLine = 0; 166 newLine = 0; 167 source = PGC_UNKNOWNSOURCE; 168 context = PGC_UNKNOWNCONTEXT; 169 } ~pgSettingItem()170 ~pgSettingItem() 171 { 172 if (newLine) delete newLine; 173 } 174 175 void SetType(const wxString &str); 176 void SetContext(const wxString &str); 177 void SetSource(const wxString &str); 178 wxString GetActiveValue(); 179 180 wxString name; 181 wxString category; 182 wxString short_desc; 183 wxString extra_desc; 184 wxString value; 185 pgConfigType type; 186 pgConfigContext context; 187 pgConfigSource source; 188 189 wxString min_val, max_val; 190 191 pgConfigLine *newLine; 192 pgConfigOrgLine *orgLine; 193 }; 194 195 196 197 WX_DECLARE_HASH_MAP(wxString, pgSettingItem *, wxStringHash, wxStringEqual, pgSettingItemHashmap); 198 WX_DECLARE_HASH_MAP(wxString, wxArrayString *, wxStringHash, wxStringEqual, pgCategoryHashmap); 199 200 class pgSettingReader 201 { 202 public: 203 virtual bool IsValid() = 0; 204 virtual pgSettingItem *GetNextItem() = 0; ~pgSettingReader()205 virtual ~pgSettingReader() {} 206 }; 207 208 209 class pgSettingFileReader : public pgSettingReader 210 { 211 wxString columnNames; 212 wxString buffer; 213 wxChar *bp; 214 215 public: 216 pgSettingFileReader(bool localized); 217 ~pgSettingFileReader(); IsValid()218 virtual bool IsValid() 219 { 220 return !buffer.IsEmpty(); 221 } 222 virtual pgSettingItem *GetNextItem(); 223 }; 224 225 226 class pgSettingDbReader : public pgSettingReader 227 { 228 pgSet *set; 229 230 public: 231 pgSettingDbReader(pgConn *conn); 232 ~pgSettingDbReader(); 233 IsValid()234 virtual bool IsValid() 235 { 236 return set != NULL; 237 } 238 virtual pgSettingItem *GetNextItem(); 239 }; 240 241 #endif 242