1 | /************************************************** |
2 | * odbcinstext.h |
3 | * |
4 | ************************************************** |
5 | * This code was created by Peter Harvey @ CodeByDesign. |
6 | * Released under LGPL 28.JAN.99 |
7 | * |
8 | * Contributions from... |
9 | * ----------------------------------------------- |
10 | * Peter Harvey - pharvey@codebydesign.com |
11 | **************************************************/ |
12 | #ifndef _ODBCINST_H |
13 | #define _ODBCINST_H |
14 | |
15 | #ifdef UNIXODBC_SOURCE |
16 | |
17 | #include <ltdl.h> |
18 | #ifdef HAVE_UNISTD_H |
19 | #include <unistd.h> |
20 | #endif |
21 | #ifdef HAVE_PWD_H |
22 | #include <pwd.h> |
23 | #endif |
24 | #ifdef HAVE_SYS_TYPES_H |
25 | #include <sys/types.h> |
26 | #endif |
27 | #include <stdio.h> |
28 | |
29 | #ifndef ODBCVER |
30 | #define ODBCVER 0x0380 |
31 | #endif |
32 | |
33 | #include <ini.h> |
34 | #include <log.h> |
35 | #include <odbcinst.h> |
36 | |
37 | /******************************************************** |
38 | * CONSTANTS WHICH DO NOT EXIST ELSEWHERE |
39 | ********************************************************/ |
40 | #ifndef TRUE |
41 | #define FALSE 0; |
42 | #define TRUE 1; |
43 | #endif |
44 | |
45 | #else /* not UNIXODBC_SOURCE */ |
46 | |
47 | /******************************************************** |
48 | * outside the unixODBC source tree only the * |
49 | * public interface is exposed * |
50 | ********************************************************/ |
51 | |
52 | #include <odbcinst.h> |
53 | |
54 | /******************************************************** |
55 | * these limits are originally defined in ini.h * |
56 | * but are needed to implement ODBCINSTGetProperties * |
57 | * for the Driver Setup * |
58 | ********************************************************/ |
59 | |
60 | #define INI_MAX_LINE 1000 |
61 | #define INI_MAX_OBJECT_NAME INI_MAX_LINE |
62 | #define INI_MAX_PROPERTY_NAME INI_MAX_LINE |
63 | #define INI_MAX_PROPERTY_VALUE INI_MAX_LINE |
64 | |
65 | #endif /* UNIXODBC_SOURCE */ |
66 | |
67 | /******************************************************** |
68 | * PUBLIC API |
69 | ********************************************************/ |
70 | |
71 | #ifdef __cplusplus |
72 | extern "C" |
73 | { |
74 | #endif |
75 | |
76 | BOOL INSTAPI SQLConfigDataSource( HWND hWnd, |
77 | WORD nRequest, |
78 | LPCSTR pszDriver, |
79 | LPCSTR pszAttributes ); |
80 | |
81 | BOOL INSTAPI SQLGetConfigMode( UWORD *pnConfigMode ); |
82 | |
83 | BOOL INSTAPI SQLGetInstalledDrivers( LPSTR pszBuf, |
84 | WORD nBufMax, |
85 | WORD *pnBufOut ); |
86 | |
87 | BOOL INSTAPI SQLInstallDriverEx( LPCSTR pszDriver, |
88 | LPCSTR pszPathIn, |
89 | LPSTR pszPathOut, |
90 | WORD nPathOutMax, |
91 | WORD *nPathOut, |
92 | WORD nRequest, |
93 | LPDWORD pnUsageCount ); |
94 | |
95 | BOOL INSTAPI SQLInstallDriverManager( LPSTR pszPath, |
96 | WORD nPathMax, |
97 | WORD *pnPathOut ); |
98 | |
99 | RETCODE INSTAPI SQLInstallerError( WORD nError, |
100 | DWORD *pnErrorCode, |
101 | LPSTR pszErrorMsg, |
102 | WORD nErrorMsgMax, |
103 | WORD *nErrorMsg ); |
104 | |
105 | BOOL INSTAPI SQLManageDataSources( HWND hWnd ); |
106 | |
107 | BOOL INSTAPI SQLReadFileDSN( LPCSTR pszFileName, |
108 | LPCSTR pszAppName, |
109 | LPCSTR pszKeyName, |
110 | LPSTR pszString, |
111 | WORD nString, |
112 | WORD *pnString ); |
113 | |
114 | BOOL INSTAPI SQLRemoveDriver( LPCSTR pszDriver, |
115 | BOOL nRemoveDSN, |
116 | LPDWORD pnUsageCount ); |
117 | |
118 | BOOL INSTAPI SQLRemoveDriverManager( LPDWORD pnUsageCount ); |
119 | |
120 | BOOL INSTAPI SQLRemoveDSNFromIni( LPCSTR pszDSN ); |
121 | |
122 | BOOL INSTAPI SQLRemoveTranslator( LPCSTR pszTranslator, |
123 | LPDWORD pnUsageCount ); |
124 | |
125 | BOOL INSTAPI SQLSetConfigMode( UWORD nConfigMode ); |
126 | |
127 | BOOL INSTAPI SQLValidDSN( LPCSTR pszDSN ); |
128 | |
129 | BOOL INSTAPI SQLWriteDSNToIni( LPCSTR pszDSN, |
130 | LPCSTR pszDriver ); |
131 | |
132 | BOOL INSTAPI SQLWriteFileDSN( LPCSTR pszFileName, |
133 | LPCSTR pszAppName, |
134 | LPCSTR pszKeyName, |
135 | LPCSTR pszString ); |
136 | |
137 | BOOL INSTAPI SQLWritePrivateProfileString( |
138 | LPCSTR pszSection, |
139 | LPCSTR pszEntry, |
140 | LPCSTR pszString, |
141 | LPCSTR pszFileName ); |
142 | |
143 | |
144 | |
145 | #ifdef __cplusplus |
146 | } |
147 | #endif |
148 | |
149 | #ifdef UNIXODBC_SOURCE |
150 | |
151 | /******************************************************** |
152 | * PRIVATE API |
153 | ********************************************************/ |
154 | #if defined(__cplusplus) |
155 | extern "C" { |
156 | #endif |
157 | |
158 | BOOL _odbcinst_UserINI( |
159 | char *pszFileName, |
160 | BOOL bVerify ); |
161 | |
162 | BOOL _odbcinst_SystemINI( |
163 | char *pszFileName, |
164 | BOOL bVerify ); |
165 | |
166 | BOOL _odbcinst_FileINI( char *pszPath ); |
167 | |
168 | char * INSTAPI odbcinst_system_file_path( char *buffer ); |
169 | char * INSTAPI odbcinst_system_file_name( char *buffer ); |
170 | char * INSTAPI odbcinst_user_file_path( char *buffer ); |
171 | char * INSTAPI odbcinst_user_file_name( char *buffer ); |
172 | |
173 | BOOL _odbcinst_ConfigModeINI( |
174 | char *pszFileName ); |
175 | |
176 | int _odbcinst_GetSections( |
177 | HINI hIni, |
178 | LPSTR pRetBuffer, |
179 | int nRetBuffer, |
180 | int *pnBufPos ); |
181 | |
182 | int _odbcinst_GetEntries( |
183 | HINI hIni, |
184 | LPCSTR pszSection, |
185 | LPSTR pRetBuffer, |
186 | int nRetBuffer, |
187 | int *pnBufPos ); |
188 | |
189 | int _SQLGetInstalledDrivers( |
190 | LPCSTR pszSection, |
191 | LPCSTR pszEntry, |
192 | LPCSTR pszDefault, |
193 | LPCSTR pRetBuffer, |
194 | int nRetBuffer ); |
195 | |
196 | BOOL _SQLWriteInstalledDrivers( |
197 | LPCSTR pszSection, |
198 | LPCSTR pszEntry, |
199 | LPCSTR pszString ); |
200 | |
201 | BOOL _SQLDriverConnectPrompt( |
202 | HWND hwnd, |
203 | SQLCHAR *dsn, |
204 | SQLSMALLINT len_dsn ); |
205 | |
206 | void __set_config_mode( int mode ); |
207 | int __get_config_mode( void ); |
208 | |
209 | int inst_logPushMsg( |
210 | char *pszModule, |
211 | char *pszFunctionName, |
212 | int nLine, |
213 | int nSeverity, |
214 | int nCode, |
215 | char *pszMessage ); |
216 | |
217 | int inst_logPeekMsg( long nMsg, HLOGMSG *phMsg ); |
218 | int inst_logClear(); |
219 | |
220 | |
221 | /* |
222 | * we should look at caching this info, the calls can become expensive |
223 | */ |
224 | |
225 | #ifndef DISABLE_INI_CACHING |
226 | |
227 | struct ini_cache |
228 | { |
229 | char *fname; |
230 | char *section; |
231 | char *entry; |
232 | char *value; |
233 | char *default_value; |
234 | int buffer_size; |
235 | int ret_value; |
236 | int config_mode; |
237 | long timestamp; |
238 | struct ini_cache *next; |
239 | }; |
240 | |
241 | #endif |
242 | |
243 | #ifdef __cplusplus |
244 | } |
245 | #endif |
246 | |
247 | #endif /* UNIXODBC_SOURCE */ |
248 | |
249 | /********************************* |
250 | * ODBCINST - PROPERTIES |
251 | ********************************* |
252 | * |
253 | * PURPOSE: |
254 | * |
255 | * To provide the caller a mechanism to interact with Data Source properties |
256 | * containing Driver specific options while avoiding embedding GUI code in |
257 | * the ODBC infrastructure. |
258 | * |
259 | * DETAILS: |
260 | * |
261 | * 1. Application calls libodbcinst.ODBCINSTConstructProperties() |
262 | * - odbcinst will load the driver and call libMyDrvS.ODBCINSTGetProperties() to build a list of all possible properties |
263 | * 2. Application calls libodbcinst.ODBCINSTSetProperty() |
264 | * - use, as required, to init values (ie if configuring existing DataSource) |
265 | * - use libodbcinst.SetConfigMode() & libodbcinst.SQLGetPrivateProfileString() to read existing Data Source info (do not forget to set the mode back) |
266 | * - do not forget to set mode back to ODBC_BOTH_DSN using SetConfigMode() when done reading |
267 | * - no call to Driver Setup |
268 | * 3. Application calls libodbcinst.ODBCINSTValidateProperty() |
269 | * - use as required (ie on leave widget event) |
270 | * - an assesment of the entire property list is also done |
271 | * - this is passed onto the driver setup DLL |
272 | * 4. Application should refresh widgets in case aPromptData or szValue has changed |
273 | * - refresh should occur for each property where bRefresh = 1 |
274 | * 5. Application calls libodbcinst.ODBCINSTValidateProperties() |
275 | * - call this just before saving new Data Source or updating existing Data Source |
276 | * - should always call this before saving |
277 | * - use libodbcinst.SetConfigMode() & libodbcinst.SQLWritePrivateProfileString() to save Data Source info |
278 | * - do not forget to set mode back to ODBC_BOTH_DSN using SetConfigMode() when done saving |
279 | * - this is passed onto the driver setup DLL |
280 | * 6. Application calls ODBCINSTDestructProperties() to free up memory |
281 | * - unload Driver Setup DLL |
282 | * - frees memory (Driver Setup allocates most of the memory but we free ALL of it in odbcinst) |
283 | * |
284 | * NOTES |
285 | * |
286 | * 1. odbcinst implements 5 functions to support this GUI config stuff |
287 | * 2. Driver Setup DLL implements just 3 functions for its share of the work |
288 | * |
289 | *********************************/ |
290 | |
291 | #define ODBCINST_SUCCESS 0 |
292 | #define ODBCINST_WARNING 1 |
293 | #define ODBCINST_ERROR 2 |
294 | |
295 | #define ODBCINST_PROMPTTYPE_LABEL 0 /* readonly */ |
296 | #define ODBCINST_PROMPTTYPE_TEXTEDIT 1 |
297 | #define ODBCINST_PROMPTTYPE_LISTBOX 2 |
298 | #define ODBCINST_PROMPTTYPE_COMBOBOX 3 |
299 | #define ODBCINST_PROMPTTYPE_FILENAME 4 |
300 | #define ODBCINST_PROMPTTYPE_HIDDEN 5 |
301 | #define ODBCINST_PROMPTTYPE_TEXTEDIT_PASSWORD 6 |
302 | |
303 | typedef struct tODBCINSTPROPERTY |
304 | { |
305 | struct tODBCINSTPROPERTY *pNext; /* pointer to next property, NULL if last property */ |
306 | |
307 | char szName[INI_MAX_PROPERTY_NAME+1]; /* property name */ |
308 | char szValue[INI_MAX_PROPERTY_VALUE+1]; /* property value */ |
309 | int nPromptType; /* PROMPTTYPE_TEXTEDIT, PROMPTTYPE_LISTBOX, PROMPTTYPE_COMBOBOX, PROMPTTYPE_FILENAME */ |
310 | char **aPromptData; /* array of pointers terminated with a NULL value in array. */ |
311 | char *pszHelp; /* help on this property (driver setups should keep it short) */ |
312 | void *pWidget; /* CALLER CAN STORE A POINTER TO ? HERE */ |
313 | int bRefresh; /* app should refresh widget ie Driver Setup has changed aPromptData or szValue */ |
314 | void *hDLL; /* for odbcinst internal use... only first property has valid one */ |
315 | } ODBCINSTPROPERTY, *HODBCINSTPROPERTY; |
316 | |
317 | /* |
318 | * Conversion routines for wide interface |
319 | */ |
320 | |
321 | char* _multi_string_alloc_and_copy( LPCWSTR in ); |
322 | char* _single_string_alloc_and_copy( LPCWSTR in ); |
323 | void _single_string_copy_to_wide( SQLWCHAR *out, LPCSTR in, int len ); |
324 | void _multi_string_copy_to_wide( SQLWCHAR *out, LPCSTR in, int len ); |
325 | void _single_copy_to_wide( SQLWCHAR *out, LPCSTR in, int len ); |
326 | SQLWCHAR* _multi_string_alloc_and_expand( LPCSTR in ); |
327 | SQLWCHAR* _single_string_alloc_and_expand( LPCSTR in ); |
328 | void _single_copy_from_wide( SQLCHAR *out, LPCWSTR in, int len ); |
329 | |
330 | /* |
331 | * To support finding UI plugin |
332 | */ |
333 | char *_getUIPluginName( char *pszName, char *pszUI ); |
334 | char *_appendUIPluginExtension( char *pszNameAndExtension, char *pszName ); |
335 | char *_prependUIPluginPath( char *pszPathAndName, char *pszName ); |
336 | |
337 | #if defined(__cplusplus) |
338 | extern "C" { |
339 | #endif |
340 | |
341 | /* ONLY IMPLEMENTED IN ODBCINST (not in Driver Setup) */ |
342 | int INSTAPI ODBCINSTConstructProperties( char *szDriver, HODBCINSTPROPERTY *hFirstProperty ); |
343 | int INSTAPI ODBCINSTSetProperty( HODBCINSTPROPERTY hFirstProperty, char *pszProperty, char *pszValue ); |
344 | int INSTAPI ODBCINSTDestructProperties( HODBCINSTPROPERTY *hFirstProperty ); |
345 | int INSTAPI ODBCINSTAddProperty( HODBCINSTPROPERTY hFirstProperty, char *pszProperty, char *pszValue ); |
346 | |
347 | /* IMPLEMENTED IN ODBCINST AND DRIVER SETUP */ |
348 | int INSTAPI ODBCINSTValidateProperty( HODBCINSTPROPERTY hFirstProperty, char *pszProperty, char *pszMessage ); |
349 | int INSTAPI ODBCINSTValidateProperties( HODBCINSTPROPERTY hFirstProperty, HODBCINSTPROPERTY hBadProperty, char *pszMessage ); |
350 | |
351 | /* ONLY IMPLEMENTED IN DRIVER SETUP (not in ODBCINST) */ |
352 | int INSTAPI ODBCINSTGetProperties( HODBCINSTPROPERTY hFirstProperty ); |
353 | |
354 | #if defined(__cplusplus) |
355 | } |
356 | #endif |
357 | |
358 | #endif |
359 | |
360 | |