summaryrefslogtreecommitdiff
path: root/src/interfaces/odbc/setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/odbc/setup.c')
-rw-r--r--src/interfaces/odbc/setup.c615
1 files changed, 173 insertions, 442 deletions
diff --git a/src/interfaces/odbc/setup.c b/src/interfaces/odbc/setup.c
index 05f076a1e5e..42f538dc7d7 100644
--- a/src/interfaces/odbc/setup.c
+++ b/src/interfaces/odbc/setup.c
@@ -1,95 +1,28 @@
-
-/* Module: setup.c
- *
- * Description: This module contains the setup functions for
- * adding/modifying a Data Source in the ODBC.INI portion
- * of the registry.
- *
- * Classes: n/a
- *
- * API functions: ConfigDSN
- *
- * Comments: See "notice.txt" for copyright and license information.
- *
- *************************************************************************************/
-
-/*
-** SETUP.C - This is the ODBC sample driver code for
-** setup.
-**
-** This code is furnished on an as-is basis as part of the ODBC SDK and is
-** intended for example purposes only.
-**
-*/
-/*--------------------------------------------------------------------------
- setup.c -- Sample ODBC setup
-
- This code demonstrates how to interact with the ODBC Installer. These
- functions may be part of your ODBC driver or in a separate DLL.
-
- The ODBC Installer allows a driver to control the management of
- data sources by calling the ConfigDSN entry point in the appropriate
- DLL. When called, ConfigDSN receives four parameters:
-
- hwndParent ---- Handle of the parent window for any dialogs which
- may need to be created. If this handle is NULL,
- then no dialogs should be displayed (that is, the
- request should be processed silently).
-
- fRequest ------ Flag indicating the type of request (add, configure
- (edit), or remove).
-
- lpszDriver ---- Far pointer to a null-terminated string containing
- the name of your driver. This is the same string you
- supply in the ODBC.INF file as your section header
- and which ODBC Setup displays to the user in lieu
- of the actual driver filename. This string needs to
- be passed back to the ODBC Installer when adding a
- new data source name.
-
- lpszAttributes- Far pointer to a list of null-terminated attribute
- keywords. This list is similar to the list passed
- to SQLDriverConnect, except that each key-value
- pair is separated by a null-byte rather than a
- semicolon. The entire list is then terminated with
- a null-byte (that is, two consecutive null-bytes
- mark the end of the list). The keywords accepted
- should be those for SQLDriverConnect which are
- applicable, any new keywords you define for ODBC.INI,
- and any additional keywords you decide to document.
-
- ConfigDSN should return TRUE if the requested operation succeeds and
- FALSE otherwise. The complete prototype for ConfigDSN is:
-
- BOOL FAR PASCAL ConfigDSN(HWND hwndParent,
- WORD fRequest,
- LPSTR lpszDriver,
- LPCSTR lpszAttributes)
-
- Your setup code should not write to ODBC.INI directly to add or remove
- data source names. Instead, link with ODBCINST.LIB (the ODBC Installer
- library) and call SQLWriteDSNToIni and SQLRemoveDSNFromIni.
- Use SQLWriteDSNToIni to add data source names. If the data source name
- already exists, SQLWriteDSNToIni will delete it (removing all of its
- associated keys) and rewrite it. SQLRemoveDSNToIni removes a data
- source name and all of its associated keys.
-
- For NT compatibility, the driver code should not use the
- Get/WritePrivateProfileString windows functions for ODBC.INI, but instead,
- use SQLGet/SQLWritePrivateProfileString functions that are macros (16 bit) or
- calls to the odbcinst.dll (32 bit).
---------------------------------------------------------------------------*/
-
-
-// Includes ----------------------------------------------------------------
-#include "psqlodbc.h" // Local include files
+/* Module: setup.c
+ *
+ * Description: This module contains the setup functions for
+ * adding/modifying a Data Source in the ODBC.INI portion
+ * of the registry.
+ *
+ * Classes: n/a
+ *
+ * API functions: ConfigDSN
+ *
+ * Comments: See "notice.txt" for copyright and license information.
+ *
+ *************************************************************************************/
+
+#include "psqlodbc.h"
+#include "connection.h"
#include <windows.h>
#include <windowsx.h>
-#include <odbcinst.h> // ODBC installer prototypes
-#include <string.h> // C include files
+#include <odbcinst.h>
+#include <string.h>
#include <stdlib.h>
#include "resource.h"
+#include "dlg_specific.h"
+
#define INTFUNC __stdcall
@@ -104,81 +37,27 @@ extern GLOBAL_VALUES globals;
#define MAXDESC (255+1) // Max description length
#define MAXDSNAME (32+1) // Max data source name length
-static char far EMPTYSTR []= "";
-static char far OPTIONON []= "Yes";
-static char far OPTIONOFF []= "No";
-
-// Attribute key indexes (into an array of Attr structs, see below)
-#define KEY_DSN 0
-#define KEY_DESC 1
-#define KEY_PORT 2
-#define KEY_SERVER 3
-#define KEY_DATABASE 4
-#define KEY_USER 5
-#define KEY_PASSWORD 6
-#define KEY_DEBUG 7
-#define KEY_FETCH 8
-#define KEY_READONLY 9
-#define KEY_PROTOCOL 10
-#define NUMOFKEYS 11 // Number of keys supported
-
-// Attribute string look-up table (maps keys to associated indexes)
-static struct {
- char szKey[MAXKEYLEN];
- int iKey;
-} s_aLookup[] = { "DSN", KEY_DSN,
- INI_KDESC, KEY_DESC,
- INI_PORT, KEY_PORT,
- INI_SERVER, KEY_SERVER,
- INI_DATABASE, KEY_DATABASE,
- INI_USER, KEY_USER,
- INI_PASSWORD, KEY_PASSWORD,
- INI_DEBUG, KEY_DEBUG,
- INI_FETCH, KEY_FETCH,
- INI_READONLY, KEY_READONLY,
- INI_PROTOCOL, KEY_PROTOCOL,
- "", 0
- };
-
-
-
-// Types -------------------------------------------------------------------
-typedef struct tagAttr {
- BOOL fSupplied;
- char szAttr[MAXPATHLEN];
-} Attr, FAR * LPAttr;
-
// Globals -----------------------------------------------------------------
// NOTE: All these are used by the dialog procedures
typedef struct tagSETUPDLG {
- HWND hwndParent; // Parent window handle
- LPCSTR lpszDrvr; // Driver description
- Attr aAttr[NUMOFKEYS]; // Attribute array
- char szDSN[MAXDSNAME]; // Original data source name
- BOOL fNewDSN; // New data source flag
- BOOL fDefault; // Default data source flag
+ HWND hwndParent; // Parent window handle
+ LPCSTR lpszDrvr; // Driver description
+ ConnInfo ci;
+ char szDSN[MAXDSNAME]; // Original data source name
+ BOOL fNewDSN; // New data source flag
+ BOOL fDefault; // Default data source flag
} SETUPDLG, FAR *LPSETUPDLG;
// Prototypes --------------------------------------------------------------
-void INTFUNC CenterDialog (HWND hdlg);
-
-int CALLBACK ConfigDlgProc (HWND hdlg,
- WORD wMsg,
- WPARAM wParam,
- LPARAM lParam);
-void INTFUNC ParseAttributes (LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg);
+void INTFUNC CenterDialog(HWND hdlg);
+int CALLBACK ConfigDlgProc(HWND hdlg, WORD wMsg, WPARAM wParam, LPARAM lParam);
+void INTFUNC ParseAttributes (LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg);
+BOOL INTFUNC SetDSNAttributes(HWND hwnd, LPSETUPDLG lpsetupdlg);
-/* CC: SetDSNAttributes is declared as "INTFUNC" below, but here it is declared as
- "CALLBACK" -- Watcom complained about disagreeing modifiers. Changed
- "CALLBACK" to "INTFUNC" here.
- BOOL CALLBACK SetDSNAttributes(HWND hwnd, LPSETUPDLG lpsetupdlg);
-*/
-
-BOOL INTFUNC SetDSNAttributes(HWND hwnd, LPSETUPDLG lpsetupdlg);
/* ConfigDSN ---------------------------------------------------------------
Description: ODBC Setup entry point
@@ -196,9 +75,9 @@ BOOL CALLBACK ConfigDSN (HWND hwnd,
LPCSTR lpszDriver,
LPCSTR lpszAttributes)
{
- BOOL fSuccess; // Success/fail flag
- GLOBALHANDLE hglbAttr;
- LPSETUPDLG lpsetupdlg;
+BOOL fSuccess; // Success/fail flag
+GLOBALHANDLE hglbAttr;
+LPSETUPDLG lpsetupdlg;
// Allocate attribute array
@@ -212,20 +91,20 @@ BOOL CALLBACK ConfigDSN (HWND hwnd,
ParseAttributes(lpszAttributes, lpsetupdlg);
// Save original data source name
- if (lpsetupdlg->aAttr[KEY_DSN].fSupplied)
- lstrcpy(lpsetupdlg->szDSN, lpsetupdlg->aAttr[KEY_DSN].szAttr);
+ if (lpsetupdlg->ci.dsn[0])
+ lstrcpy(lpsetupdlg->szDSN, lpsetupdlg->ci.dsn);
else
lpsetupdlg->szDSN[0] = '\0';
// Remove data source
if (ODBC_REMOVE_DSN == fRequest) {
// Fail if no data source name was supplied
- if (!lpsetupdlg->aAttr[KEY_DSN].fSupplied)
+ if (!lpsetupdlg->ci.dsn[0])
fSuccess = FALSE;
// Otherwise remove data source from ODBC.INI
else
- fSuccess = SQLRemoveDSNFromIni(lpsetupdlg->aAttr[KEY_DSN].szAttr);
+ fSuccess = SQLRemoveDSNFromIni(lpsetupdlg->ci.dsn);
}
// Add or Configure data source
@@ -235,19 +114,19 @@ BOOL CALLBACK ConfigDSN (HWND hwnd,
lpsetupdlg->lpszDrvr = lpszDriver;
lpsetupdlg->fNewDSN = (ODBC_ADD_DSN == fRequest);
lpsetupdlg->fDefault =
- !lstrcmpi(lpsetupdlg->aAttr[KEY_DSN].szAttr, INI_DSN);
+ !lstrcmpi(lpsetupdlg->ci.dsn, INI_DSN);
// Display the appropriate dialog (if parent window handle supplied)
if (hwnd) {
// Display dialog(s)
fSuccess = (IDOK == DialogBoxParam(s_hModule,
- MAKEINTRESOURCE(CONFIGDSN),
- hwnd,
- ConfigDlgProc,
- (LONG)(LPSTR)lpsetupdlg));
+ MAKEINTRESOURCE(DLG_CONFIG),
+ hwnd,
+ ConfigDlgProc,
+ (LONG)(LPSTR)lpsetupdlg));
}
- else if (lpsetupdlg->aAttr[KEY_DSN].fSupplied)
+ else if (lpsetupdlg->ci.dsn[0])
fSuccess = SetDSNAttributes(hwnd, lpsetupdlg);
else
fSuccess = FALSE;
@@ -314,208 +193,123 @@ void INTFUNC CenterDialog(HWND hdlg)
--------------------------------------------------------------------------*/
-
-int CALLBACK ConfigDlgProc
- (HWND hdlg,
- WORD wMsg,
- WPARAM wParam,
- LPARAM lParam)
+int CALLBACK ConfigDlgProc(HWND hdlg,
+ WORD wMsg,
+ WPARAM wParam,
+ LPARAM lParam)
{
- switch (wMsg) {
- // Initialize the dialog
- case WM_INITDIALOG:
- {
- LPSETUPDLG lpsetupdlg;
- LPCSTR lpszDSN;
-
- SetWindowLong(hdlg, DWL_USER, lParam);
- CenterDialog(hdlg); // Center dialog
-
- lpsetupdlg = (LPSETUPDLG) lParam;
- lpszDSN = lpsetupdlg->aAttr[KEY_DSN].szAttr;
- // Initialize dialog fields
- // NOTE: Values supplied in the attribute string will always
- // override settings in ODBC.INI
- SetDlgItemText(hdlg, IDC_DSNAME, lpszDSN);
-
- // Description
- if (!lpsetupdlg->aAttr[KEY_DESC].fSupplied)
- SQLGetPrivateProfileString(lpszDSN, INI_KDESC,
- EMPTYSTR,
- lpsetupdlg->aAttr[KEY_DESC].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_DESC].szAttr),
- ODBC_INI);
- SetDlgItemText(hdlg, IDC_DESC, lpsetupdlg->aAttr[KEY_DESC].szAttr);
-
- // Database
- if (!lpsetupdlg->aAttr[KEY_DATABASE].fSupplied)
- SQLGetPrivateProfileString(lpszDSN, INI_DATABASE,
- EMPTYSTR,
- lpsetupdlg->aAttr[KEY_DATABASE].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_DATABASE].szAttr),
- ODBC_INI);
- SetDlgItemText(hdlg, IDC_DATABASE, lpsetupdlg->aAttr[KEY_DATABASE].szAttr);
-
- // Server
- if (!lpsetupdlg->aAttr[KEY_SERVER].fSupplied)
- SQLGetPrivateProfileString(lpszDSN, INI_SERVER,
- EMPTYSTR,
- lpsetupdlg->aAttr[KEY_SERVER].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_SERVER].szAttr),
- ODBC_INI);
- SetDlgItemText(hdlg, IDC_SERVER, lpsetupdlg->aAttr[KEY_SERVER].szAttr);
-
- // Port
- if (!lpsetupdlg->aAttr[KEY_PORT].fSupplied)
- SQLGetPrivateProfileString(lpszDSN, INI_PORT,
- EMPTYSTR,
- lpsetupdlg->aAttr[KEY_PORT].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_PORT].szAttr),
- ODBC_INI);
- if (lpsetupdlg->aAttr[KEY_PORT].szAttr[0] == '\0')
- strcpy(lpsetupdlg->aAttr[KEY_PORT].szAttr, DEFAULT_PORT);
- SetDlgItemText(hdlg, IDC_PORT, lpsetupdlg->aAttr[KEY_PORT].szAttr);
-
- /* Username */
- if (!lpsetupdlg->aAttr[KEY_USER].fSupplied)
- SQLGetPrivateProfileString(lpszDSN, INI_USER,
- EMPTYSTR,
- lpsetupdlg->aAttr[KEY_USER].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_USER].szAttr),
- ODBC_INI);
- SetDlgItemText(hdlg, IDC_USER, lpsetupdlg->aAttr[KEY_USER].szAttr);
-
- // Password
- if (!lpsetupdlg->aAttr[KEY_PASSWORD].fSupplied)
- SQLGetPrivateProfileString(lpszDSN, INI_PASSWORD,
- EMPTYSTR,
- lpsetupdlg->aAttr[KEY_PASSWORD].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_PASSWORD].szAttr),
- ODBC_INI);
- SetDlgItemText(hdlg, IDC_PASSWORD, lpsetupdlg->aAttr[KEY_PASSWORD].szAttr);
-
- // ReadOnly Parameter
- if (!lpsetupdlg->aAttr[KEY_READONLY].fSupplied) {
- SQLGetPrivateProfileString(lpszDSN, INI_READONLY,
- EMPTYSTR,
- lpsetupdlg->aAttr[KEY_READONLY].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_READONLY].szAttr),
- ODBC_INI);
- }
- if (lpsetupdlg->aAttr[KEY_READONLY].szAttr[0] == '\0')
- strcpy(lpsetupdlg->aAttr[KEY_READONLY].szAttr, DEFAULT_READONLY);
- CheckDlgButton(hdlg, IDC_READONLY, atoi(lpsetupdlg->aAttr[KEY_READONLY].szAttr));
-
- // Protocol Parameter
- if (!lpsetupdlg->aAttr[KEY_PROTOCOL].fSupplied) {
- SQLGetPrivateProfileString(lpszDSN, INI_PROTOCOL,
- EMPTYSTR,
- lpsetupdlg->aAttr[KEY_PROTOCOL].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_PROTOCOL].szAttr),
- ODBC_INI);
- }
- if (strncmp(lpsetupdlg->aAttr[KEY_PROTOCOL].szAttr, PG62, strlen(PG62)) == 0)
- CheckDlgButton(hdlg, IDC_PG62, 1);
- else
- CheckDlgButton(hdlg, IDC_PG62, 0);
-
-
- // CommLog Parameter (this is global)
- CheckDlgButton(hdlg, IDC_COMMLOG, globals.commlog);
-
-
- if (lpsetupdlg->fDefault)
- {
- EnableWindow(GetDlgItem(hdlg, IDC_DSNAME), FALSE);
- EnableWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), FALSE);
- }
- else
- SendDlgItemMessage(hdlg, IDC_DSNAME,
- EM_LIMITTEXT, (WPARAM)(MAXDSNAME-1), 0L);
- SendDlgItemMessage(hdlg, IDC_DESC,
- EM_LIMITTEXT, (WPARAM)(MAXDESC-1), 0L);
- return TRUE; // Focus was not set
+ switch (wMsg) {
+ // Initialize the dialog
+ case WM_INITDIALOG:
+ {
+ LPSETUPDLG lpsetupdlg = (LPSETUPDLG) lParam;
+ ConnInfo *ci = &lpsetupdlg->ci;
+
+ /* Hide the driver connect message */
+ ShowWindow(GetDlgItem(hdlg, DRV_MSG_LABEL), SW_HIDE);
+
+ SetWindowLong(hdlg, DWL_USER, lParam);
+ CenterDialog(hdlg); // Center dialog
+
+ // NOTE: Values supplied in the attribute string will always
+ // override settings in ODBC.INI
+
+ // Get the rest of the common attributes
+ getDSNinfo(ci, CONN_DONT_OVERWRITE);
+
+ // Fill in any defaults
+ getDSNdefaults(ci);
+
+
+ // Initialize dialog fields
+ SetDlgStuff(hdlg, ci);
+
+
+ if (lpsetupdlg->fDefault) {
+ EnableWindow(GetDlgItem(hdlg, IDC_DSNAME), FALSE);
+ EnableWindow(GetDlgItem(hdlg, IDC_DSNAMETEXT), FALSE);
+ }
+ else
+ SendDlgItemMessage(hdlg, IDC_DSNAME,
+ EM_LIMITTEXT, (WPARAM)(MAXDSNAME-1), 0L);
+
+ SendDlgItemMessage(hdlg, IDC_DESC,
+ EM_LIMITTEXT, (WPARAM)(MAXDESC-1), 0L);
+ return TRUE; // Focus was not set
}
- // Process buttons
- case WM_COMMAND:
- switch (GET_WM_COMMAND_ID(wParam, lParam)) {
- // Ensure the OK button is enabled only when a data source name
- // is entered
- case IDC_DSNAME:
- if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE)
- {
- char szItem[MAXDSNAME]; // Edit control text
-
- // Enable/disable the OK button
- EnableWindow(GetDlgItem(hdlg, IDOK),
- GetDlgItemText(hdlg, IDC_DSNAME,
- szItem, sizeof(szItem)));
- return TRUE;
- }
- break;
-
- // Accept results
- case IDOK:
- {
- LPSETUPDLG lpsetupdlg;
-
- lpsetupdlg = (LPSETUPDLG)GetWindowLong(hdlg, DWL_USER);
- // Retrieve dialog values
- if (!lpsetupdlg->fDefault)
- GetDlgItemText(hdlg, IDC_DSNAME,
- lpsetupdlg->aAttr[KEY_DSN].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_DSN].szAttr));
- GetDlgItemText(hdlg, IDC_DESC,
- lpsetupdlg->aAttr[KEY_DESC].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_DESC].szAttr));
-
- GetDlgItemText(hdlg, IDC_DATABASE,
- lpsetupdlg->aAttr[KEY_DATABASE].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_DATABASE].szAttr));
-
- GetDlgItemText(hdlg, IDC_PORT,
- lpsetupdlg->aAttr[KEY_PORT].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_PORT].szAttr));
-
- GetDlgItemText(hdlg, IDC_SERVER,
- lpsetupdlg->aAttr[KEY_SERVER].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_SERVER].szAttr));
-
- GetDlgItemText(hdlg, IDC_USER,
- lpsetupdlg->aAttr[KEY_USER].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_USER].szAttr));
-
- GetDlgItemText(hdlg, IDC_PASSWORD,
- lpsetupdlg->aAttr[KEY_PASSWORD].szAttr,
- sizeof(lpsetupdlg->aAttr[KEY_PASSWORD].szAttr));
-
- if ( IsDlgButtonChecked(hdlg, IDC_PG62))
- strcpy(lpsetupdlg->aAttr[KEY_PROTOCOL].szAttr, PG62);
- else
- lpsetupdlg->aAttr[KEY_PROTOCOL].szAttr[0] = '\0';
-
- sprintf(lpsetupdlg->aAttr[KEY_READONLY].szAttr, "%d", IsDlgButtonChecked(hdlg, IDC_READONLY));
-
- globals.commlog = IsDlgButtonChecked(hdlg, IDC_COMMLOG);
-
-
- // Update ODBC.INI
- SetDSNAttributes(hdlg, lpsetupdlg);
- }
+ // Process buttons
+ case WM_COMMAND:
- // Return to caller
- case IDCANCEL:
- EndDialog(hdlg, wParam);
- return TRUE;
- }
- break;
+ switch (GET_WM_COMMAND_ID(wParam, lParam)) {
+ // Ensure the OK button is enabled only when a data source name
+ // is entered
+ case IDC_DSNAME:
+ if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE)
+ {
+ char szItem[MAXDSNAME]; // Edit control text
+
+ // Enable/disable the OK button
+ EnableWindow(GetDlgItem(hdlg, IDOK),
+ GetDlgItemText(hdlg, IDC_DSNAME,
+ szItem, sizeof(szItem)));
+
+ return TRUE;
+ }
+ break;
+
+ // Accept results
+ case IDOK:
+ {
+ LPSETUPDLG lpsetupdlg;
+
+ lpsetupdlg = (LPSETUPDLG)GetWindowLong(hdlg, DWL_USER);
+ // Retrieve dialog values
+ if (!lpsetupdlg->fDefault)
+ GetDlgItemText(hdlg, IDC_DSNAME,
+ lpsetupdlg->ci.dsn,
+ sizeof(lpsetupdlg->ci.dsn));
+
+
+ // Get Dialog Values
+ GetDlgStuff(hdlg, &lpsetupdlg->ci);
+
+ // Update ODBC.INI
+ SetDSNAttributes(hdlg, lpsetupdlg);
}
- // Message not processed
- return FALSE;
+ // Return to caller
+ case IDCANCEL:
+ EndDialog(hdlg, wParam);
+ return TRUE;
+
+ case IDC_DRIVER:
+
+ DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
+ hdlg, driver_optionsProc, (LPARAM) NULL);
+
+ return TRUE;
+
+ case IDC_DATASOURCE:
+ {
+ LPSETUPDLG lpsetupdlg;
+
+ lpsetupdlg = (LPSETUPDLG)GetWindowLong(hdlg, DWL_USER);
+
+ DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
+ hdlg, ds_optionsProc, (LPARAM) &lpsetupdlg->ci);
+
+ return TRUE;
+ }
+ }
+
+ break;
+ }
+
+ // Message not processed
+ return FALSE;
}
@@ -526,11 +320,13 @@ int CALLBACK ConfigDlgProc
--------------------------------------------------------------------------*/
void INTFUNC ParseAttributes(LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg)
{
- LPCSTR lpsz;
- LPCSTR lpszStart;
- char aszKey[MAXKEYLEN];
- int iElement;
- int cbKey;
+LPCSTR lpsz;
+LPCSTR lpszStart;
+char aszKey[MAXKEYLEN];
+int cbKey;
+char value[MAXPATHLEN];
+
+ memset(&lpsetupdlg->ci, 0, sizeof(ConnInfo));
for (lpsz=lpszAttributes; *lpsz; lpsz++)
{ // Extract key name (e.g., DSN), it must be terminated by an equals
@@ -543,38 +339,26 @@ void INTFUNC ParseAttributes(LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg)
break; // Valid key found
}
// Determine the key's index in the key table (-1 if not found)
- iElement = -1;
cbKey = lpsz - lpszStart;
if (cbKey < sizeof(aszKey))
{
- register int j;
_fmemcpy(aszKey, lpszStart, cbKey);
aszKey[cbKey] = '\0';
- for (j = 0; *s_aLookup[j].szKey; j++)
- {
- if (!lstrcmpi(s_aLookup[j].szKey, aszKey))
- {
- iElement = s_aLookup[j].iKey;
- break;
- }
- }
}
// Locate end of key value
lpszStart = ++lpsz;
for (; *lpsz; lpsz++);
- // Save value if key is known
- // NOTE: This code assumes the szAttr buffers in aAttr have been
- // zero initialized
- if (iElement >= 0)
- {
- lpsetupdlg->aAttr[iElement].fSupplied = TRUE;
- _fmemcpy(lpsetupdlg->aAttr[iElement].szAttr,
- lpszStart,
- MIN(lpsz-lpszStart+1, sizeof(lpsetupdlg->aAttr[0].szAttr)-1));
- }
+
+ // lpsetupdlg->aAttr[iElement].fSupplied = TRUE;
+ _fmemcpy(value, lpszStart, MIN(lpsz-lpszStart+1, MAXPATHLEN));
+
+ mylog("aszKey='%s', value='%s'\n", aszKey, value);
+
+ // Copy the appropriate value to the conninfo
+ copyAttributes(&lpsetupdlg->ci, aszKey, value);
}
return;
}
@@ -588,12 +372,12 @@ void INTFUNC ParseAttributes(LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg)
BOOL INTFUNC SetDSNAttributes(HWND hwndParent, LPSETUPDLG lpsetupdlg)
{
- LPCSTR lpszDSN; // Pointer to data source name
+LPCSTR lpszDSN; // Pointer to data source name
- lpszDSN = lpsetupdlg->aAttr[KEY_DSN].szAttr;
+ lpszDSN = lpsetupdlg->ci.dsn;
// Validate arguments
- if (lpsetupdlg->fNewDSN && !*lpsetupdlg->aAttr[KEY_DSN].szAttr)
+ if (lpsetupdlg->fNewDSN && !*lpsetupdlg->ci.dsn)
return FALSE;
// Write the data source name
@@ -614,64 +398,11 @@ BOOL INTFUNC SetDSNAttributes(HWND hwndParent, LPSETUPDLG lpsetupdlg)
// Update ODBC.INI
- // Save the value if the data source is new, if it was edited, or if
- // it was explicitly supplied
- if (hwndParent || lpsetupdlg->aAttr[KEY_DESC].fSupplied )
- SQLWritePrivateProfileString(lpszDSN,
- INI_KDESC,
- lpsetupdlg->aAttr[KEY_DESC].szAttr,
- ODBC_INI);
-
- if (hwndParent || lpsetupdlg->aAttr[KEY_DATABASE].fSupplied )
- SQLWritePrivateProfileString(lpszDSN,
- INI_DATABASE,
- lpsetupdlg->aAttr[KEY_DATABASE].szAttr,
- ODBC_INI);
-
- if (hwndParent || lpsetupdlg->aAttr[KEY_PORT].fSupplied )
- SQLWritePrivateProfileString(lpszDSN,
- INI_PORT,
- lpsetupdlg->aAttr[KEY_PORT].szAttr,
- ODBC_INI);
-
- if (hwndParent || lpsetupdlg->aAttr[KEY_SERVER].fSupplied )
- SQLWritePrivateProfileString(lpszDSN,
- INI_SERVER,
- lpsetupdlg->aAttr[KEY_SERVER].szAttr,
- ODBC_INI);
-
- if (hwndParent || lpsetupdlg->aAttr[KEY_USER].fSupplied )
- SQLWritePrivateProfileString(lpszDSN,
- INI_USER,
- lpsetupdlg->aAttr[KEY_USER].szAttr,
- ODBC_INI);
-
- if (hwndParent || lpsetupdlg->aAttr[KEY_PASSWORD].fSupplied )
- SQLWritePrivateProfileString(lpszDSN,
- INI_PASSWORD,
- lpsetupdlg->aAttr[KEY_PASSWORD].szAttr,
- ODBC_INI);
-
- if (hwndParent || lpsetupdlg->aAttr[KEY_READONLY].fSupplied )
- SQLWritePrivateProfileString(lpszDSN,
- INI_READONLY,
- lpsetupdlg->aAttr[KEY_READONLY].szAttr,
- ODBC_INI);
-
- if (hwndParent || lpsetupdlg->aAttr[KEY_PROTOCOL].fSupplied )
- SQLWritePrivateProfileString(lpszDSN,
- INI_PROTOCOL,
- lpsetupdlg->aAttr[KEY_PROTOCOL].szAttr,
- ODBC_INI);
-
- // CommLog Parameter -- write to ODBCINST_INI (for the whole driver)
- if (hwndParent ) {
- updateGlobals();
- }
+ writeDSNinfo(&lpsetupdlg->ci);
+
// If the data source name has changed, remove the old name
- if (lpsetupdlg->aAttr[KEY_DSN].fSupplied &&
- lstrcmpi(lpsetupdlg->szDSN, lpsetupdlg->aAttr[KEY_DSN].szAttr))
+ if (lstrcmpi(lpsetupdlg->szDSN, lpsetupdlg->ci.dsn))
{
SQLRemoveDSNFromIni(lpsetupdlg->szDSN);
}