int _iodbcdm_list_entries (PCONFIG pCfg, LPCSTR lpszSection, LPSTR lpszRetBuffer, int cbRetBuffer) { int curr = 0, sect_len = 0; lpszRetBuffer[0] = 0; if (0 == _iodbcdm_cfg_rewind (pCfg)) { while (curr < cbRetBuffer && 0 == _iodbcdm_cfg_nextentry (pCfg)) { if (_iodbcdm_cfg_define (pCfg) && !strcmp (pCfg->section, lpszSection) && pCfg->id) { sect_len = strlen (pCfg->id) + 1; sect_len = sect_len > cbRetBuffer - curr ? cbRetBuffer - curr : sect_len; memmove (lpszRetBuffer + curr, pCfg->id, sect_len); curr += sect_len; } } if (curr < cbRetBuffer) lpszRetBuffer[curr] = 0; return curr; } return 0; }
int _iodbcdm_cfg_to_string (PCONFIG pconfig, char *section, char *buf, size_t buf_sz) { BOOL atsection; if (_iodbcdm_cfg_rewind (pconfig) == -1) return -1; atsection = FALSE; buf[0] = '\0'; while (_iodbcdm_cfg_nextentry (pconfig) == 0) { if (atsection) { if (_iodbcdm_cfg_section (pconfig)) break; else if (_iodbcdm_cfg_define (pconfig)) { if (buf[0] != '\0') CATBUF (buf, ";", buf_sz); CATBUF (buf, pconfig->id, buf_sz); CATBUF (buf, "=", buf_sz); CATBUF (buf, pconfig->value, buf_sz); } } else if (_iodbcdm_cfg_section (pconfig) && !strcasecmp (pconfig->section, section)) atsection = TRUE; } return 0; }
BOOL do_create_dsns (PCONFIG pCfg, PCONFIG pInfCfg, LPSTR szDriver, LPSTR szDSNS, LPSTR szDiz) { char *szValue = strdup (szDSNS), *szCurr = szValue, *szComma; int hasMore = FALSE; BOOL retcode = FALSE; do { szComma = strchr (szCurr, ','); if (szComma) { *szComma = 0; hasMore = TRUE; } else hasMore = FALSE; #ifdef WIN32 if (_iodbcdm_cfg_write (pCfg, "ODBC 32 bit Data Sources", szCurr, szDiz)) #else if (_iodbcdm_cfg_write (pCfg, "ODBC Data Sources", szCurr, szDiz)) #endif goto error; if (!ValidDSN (szCurr) || _iodbcdm_cfg_write (pCfg, szCurr, NULL, NULL)) goto error; if (_iodbcdm_cfg_find (pInfCfg, szCurr, NULL) && !_iodbcdm_cfg_write (pCfg, szCurr, NULL, NULL)) { if (_iodbcdm_cfg_write (pCfg, szCurr, "Driver", szDriver)) goto error; while (!_iodbcdm_cfg_nextentry (pInfCfg) && _iodbcdm_cfg_define (pInfCfg)) { if (_iodbcdm_cfg_write (pCfg, szCurr, pInfCfg->id, pInfCfg->value)) goto error; } } szCurr = szComma + 1; } while (hasMore); retcode = TRUE; error: free (szValue); return retcode; }
int _iodbcdm_cfg_find (PCONFIG pconfig, char *section, char *id) { int atsection; if (!_iodbcdm_cfg_valid (pconfig) || _iodbcdm_cfg_rewind (pconfig)) return -1; atsection = 0; while (_iodbcdm_cfg_nextentry (pconfig) == 0) { if (atsection) { if (_iodbcdm_cfg_section (pconfig)) return -1; else if (_iodbcdm_cfg_define (pconfig)) { char *szId = _iodbcdm_remove_quotes (pconfig->id); int bSame; if (szId) { bSame = !strcasecmp (szId, id); free (szId); if (bSame) return 0; } } } else if (_iodbcdm_cfg_section (pconfig) && !strcasecmp (pconfig->section, section)) { if (id == NULL) return 0; atsection = 1; } } return -1; }
BOOL install_from_ini (PCONFIG pCfg, PCONFIG pOdbcCfg, LPSTR szInfFile, LPSTR szDriver, BOOL drivers) { PCONFIG pInfCfg; char *szKeysSection = NULL, *szDriverFile = NULL, *szSetupFile = NULL, *szValue = NULL, *szId = NULL, *szComma, *szComma1; BOOL ret = FALSE; if (_iodbcdm_cfg_write (pCfg, szDriver, NULL, NULL)) return ret; if (_iodbcdm_cfg_init (&pInfCfg, szInfFile, FALSE)) return ret; if (_iodbcdm_cfg_find (pInfCfg, drivers ? "ODBC Drivers" : "ODBC Translators", szDriver)) goto error; #ifdef WIN32 if (_iodbcdm_cfg_write (pCfg, drivers ? "ODBC 32 bit Drivers" : "ODBC 32 bit Translators", szDriver, "Installed")) #else if (_iodbcdm_cfg_write (pCfg, drivers ? "ODBC Drivers" : "ODBC Translators", szDriver, "Installed")) #endif goto error; if (_iodbcdm_cfg_find (pInfCfg, szDriver, drivers ? "Driver" : "Translator")) goto error; szComma = strchr (pInfCfg->value, ','); szComma1 = strchr (szComma + 1, ','); if (!szComma || !szComma1 || szComma + 1 == szComma1) goto error; *szComma1 = 0; szDriverFile = strdup (szComma + 1); if (_iodbcdm_cfg_write (pCfg, szDriver, drivers ? "Driver" : "Translator", szDriverFile)) goto error; if (!_iodbcdm_cfg_find (pInfCfg, szDriver, "Setup")) { szComma = strchr (pInfCfg->value, ','); szComma1 = strchr (szComma + 1, ','); if (!szComma || !szComma1 || szComma + 1 == szComma1) goto error; *szComma1 = 0; szSetupFile = strdup (szComma + 1); if (_iodbcdm_cfg_write (pCfg, szDriver, "Setup", szSetupFile)) goto error; } if (!_iodbcdm_cfg_find (pInfCfg, szDriver, NULL)) { while (!_iodbcdm_cfg_nextentry (pInfCfg) && _iodbcdm_cfg_define (pInfCfg)) if (strcmp (pInfCfg->id, drivers ? "\"Driver\"" : "\"Translator\"") && strcmp (pInfCfg->id, "\"Setup\"")) { szComma = strchr (pInfCfg->value, ','); szComma1 = strchr (szComma + 1, ','); if (!szComma || !szComma1 || szComma + 1 == szComma1) szValue = strdup (""); else { *szComma1 = 0; szValue = strdup (szComma + 1); } szComma = strchr (pInfCfg->id, '"'); szComma1 = strchr (szComma + 1, '"'); if (!szComma || !szComma1 || szComma + 1 == szComma1) goto loop_cont; else { *szComma1 = 0; szId = strdup (szComma + 1); } if (_iodbcdm_cfg_write (pCfg, szDriver, szId, szValue)) goto error; loop_cont: if (szValue) { free (szValue); szValue = NULL; } if (szId) { free (szId); szId = NULL; } } } if (!drivers) goto quit; szKeysSection = (char *) calloc (strlen (szDriver) + 6, sizeof (char)); strcpy (szKeysSection, szDriver); strcat (szKeysSection, "-Keys"); if (!_iodbcdm_cfg_find (pInfCfg, szKeysSection, NULL)) { while (!_iodbcdm_cfg_nextentry (pInfCfg) && _iodbcdm_cfg_define (pInfCfg)) { if (strcmp (pInfCfg->id, "CreateDSN")) { if (_iodbcdm_cfg_write (pCfg, szDriver, pInfCfg->id, pInfCfg->value)) goto error; } else if (!do_create_dsns (pOdbcCfg, pCfg, szDriverFile, pInfCfg->value, szDriver)) goto error; } } quit: ret = TRUE; error: if (szKeysSection) free (szKeysSection); if (szDriverFile) free (szDriverFile); if (szSetupFile) free (szSetupFile); if (szValue) free (szValue); if (szId) free (szId); _iodbcdm_cfg_done (pInfCfg); return ret; }
BOOL GetAvailableDrivers (LPCSTR lpszInfFile, LPSTR lpszBuf, WORD cbBufMax, WORD * pcbBufOut, BOOL infFile) { int sect_len = 0; WORD curr = 0; BOOL retcode = FALSE; PCONFIG pCfg; char *szId; if (!lpszBuf || !cbBufMax) { PUSH_ERROR (ODBC_ERROR_INVALID_BUFF_LEN); goto quit; } /* Open the file to read from */ if (_iodbcdm_cfg_init (&pCfg, lpszInfFile, FALSE)) { PUSH_ERROR (ODBC_ERROR_COMPONENT_NOT_FOUND); goto quit; } /* Get the ODBC Drivers section */ #ifdef WIN32 if (_iodbcdm_cfg_find (pCfg, "ODBC 32 bit Drivers", NULL)) #else if (_iodbcdm_cfg_find (pCfg, "ODBC Drivers", NULL)) #endif { PUSH_ERROR (ODBC_ERROR_COMPONENT_NOT_FOUND); goto done; } while (curr < cbBufMax && 0 == _iodbcdm_cfg_nextentry (pCfg)) { if (_iodbcdm_cfg_section (pCfg)) break; if (_iodbcdm_cfg_define (pCfg) && pCfg->id) { szId = pCfg->id; while (infFile && *szId == '"') szId++; sect_len = STRLEN (szId); if (!sect_len) { PUSH_ERROR (ODBC_ERROR_INVALID_INF); goto done; } while (infFile && *(szId + sect_len - 1) == '"') sect_len -= 1; sect_len = sect_len > cbBufMax - curr ? cbBufMax - curr : sect_len; if (sect_len) memmove (lpszBuf + curr, szId, sect_len); else { PUSH_ERROR (ODBC_ERROR_INVALID_INF); goto done; } curr += sect_len; lpszBuf[curr++] = 0; } } if (curr < cbBufMax) lpszBuf[curr + 1] = 0; if (pcbBufOut) *pcbBufOut = curr; retcode = TRUE; done: _iodbcdm_cfg_done (pCfg); quit: return retcode; }