1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*************************************************
* SQLInstallDriverEx
*
* pnUsageCount FileUsage is incremented and decremented
* only in this lib. This is done whenever
* a request is made to install or remove
* a driver.
* This differs slightly from the MS spec.
* see FileUsage entries in odbcinst.ini
*
* pszPathOut This lacks some smarts. I will pass pszPathIn
* back here or, if pszPathIn=NULL, I will default
* to /usr/lib
*
**************************************************
* This code was created by Peter Harvey @ CodeByDesign.
* Released under LGPL 28.JAN.99
*
* Contributions from...
* -----------------------------------------------
* Peter Harvey - pharvey@codebydesign.com
**************************************************/
#include <odbcinstext.h>
BOOL SQLInstallDriverEx( LPCSTR pszDriver,
LPCSTR pszPathIn,
LPSTR pszPathOut,
WORD nPathOutMax,
WORD *pnPathOut,
WORD nRequest,
LPDWORD pnUsageCount )
{
HINI hIni;
char szObjectName[INI_MAX_OBJECT_NAME+1];
char szNameValue[INI_MAX_PROPERTY_NAME+INI_MAX_PROPERTY_VALUE+3];
char szPropertyName[INI_MAX_PROPERTY_NAME+1];
char szValue[INI_MAX_PROPERTY_VALUE+1];
char szIniName[ INI_MAX_OBJECT_NAME + 1 ];
BOOL bInsertFileUsage;
int nElement;
int nUsageCount = 0; /* SHOULD GET THIS FROM SOMEWHERE ? */
/* SANITY CHECKS */
if ( pszDriver == NULL || pszPathOut == NULL )
{
inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
return FALSE;
}
if ( nRequest != ODBC_INSTALL_INQUIRY && nRequest != ODBC_INSTALL_COMPLETE )
{
inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_REQUEST_TYPE, "" );
return FALSE;
}
memset( pszPathOut, '\0', nPathOutMax );
if ( pszPathIn )
{
#ifdef VMS
sprintf( szIniName, "%sODBCINST.INI", pszPathIn );
#else
sprintf( szIniName, "%s/odbcinst.ini", pszPathIn );
#endif
}
else
{
#ifdef VMS
sprintf( szIniName, "%sODBCINST.INI", odbcinst_system_file_path() );
#else
sprintf( szIniName, "%s/odbcinst.ini", odbcinst_system_file_path() );
#endif
}
/* PROCESS ODBC INST INI FILE */
if ( iniOpen( &hIni, szIniName, '#', '[', ']', '=', TRUE ) != INI_SUCCESS )
{
inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_COMPONENT_NOT_FOUND, "" );
return FALSE;
}
if ( iniElement( (char *)pszDriver, '\0', '\0', 0, szObjectName, INI_MAX_OBJECT_NAME ) != INI_SUCCESS )
{
iniClose( hIni );
inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_KEYWORD_VALUE, "" );
return FALSE;
}
/* LETS GET ITS FILE USAGE VALUE (if any) */
if ( iniPropertySeek( hIni, szObjectName, "FileUsage", "" ) == INI_SUCCESS )
{
iniValue( hIni, szValue );
nUsageCount = atoi( szValue );
}
/* DOES THE OBJECT ALREADY EXIST? (also ensures that we have correct current object) */
if ( iniObjectSeek( hIni, szObjectName ) == INI_SUCCESS )
{
if ( nUsageCount == 0 )
nUsageCount = 1;
if ( nRequest == ODBC_INSTALL_COMPLETE )
{
iniObjectDelete( hIni );
}
}
/* LETS ADD THE SECTION AND ENTRY */
nUsageCount++;
if ( nRequest == ODBC_INSTALL_COMPLETE )
{
bInsertFileUsage = TRUE;
iniObjectInsert( hIni, szObjectName );
for ( nElement=1;
iniElement( (char *)pszDriver, '\0', '\0', nElement, szNameValue, INI_MAX_PROPERTY_NAME+INI_MAX_PROPERTY_VALUE+3 ) == INI_SUCCESS;
nElement++ )
{
iniElement( szNameValue, '=', '\0', 0, szPropertyName, INI_MAX_PROPERTY_NAME );
iniElement( szNameValue, '=', '\0', 1, szValue, INI_MAX_PROPERTY_VALUE );
if ( szPropertyName[0] != '\0' )
{
/* OVERRIDE ANY USAGE COUNT CHANGES */
if ( strcasecmp( szPropertyName, "FileUsage" ) == 0 )
{
bInsertFileUsage = FALSE;
sprintf( szValue, "%d", nUsageCount );
}
iniPropertyInsert( hIni, szPropertyName, szValue );
}
else
{
iniClose( hIni );
inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_KEYWORD_VALUE, "" );
return FALSE;
}
} /* for */
if ( bInsertFileUsage )
{
/* LETS INSERT USAGE COUNT */
sprintf( szValue, "%d", nUsageCount );
iniPropertyInsert( hIni, "FileUsage", szValue );
}
if ( iniCommit( hIni ) != INI_SUCCESS )
{
inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_PATH, "" );
iniClose( hIni );
return FALSE;
}
}
iniClose( hIni );
/* OK, SO WHATS LEFT? */
if ( pszPathIn == NULL )
{
if ( pszPathOut )
{
if ( strlen( odbcinst_system_file_path()) < nPathOutMax )
{
strcpy( pszPathOut, odbcinst_system_file_path());
}
else
{
strncpy( pszPathOut, odbcinst_system_file_path(), nPathOutMax );
pszPathOut[ nPathOutMax - 1 ] = '\0';
}
}
}
else
{
if ( pszPathOut )
{
if ( strlen( pszPathIn ) < nPathOutMax )
{
strcpy( pszPathOut, pszPathIn );
}
else
{
strncpy( pszPathOut, pszPathIn, nPathOutMax );
pszPathOut[ nPathOutMax - 1 ] = '\0';
}
}
}
if ( pnPathOut != NULL )
{
if ( pszPathIn == NULL )
{
*pnPathOut = strlen( odbcinst_system_file_path());
}
else
{
*pnPathOut = strlen( pszPathIn );
}
}
if ( pnUsageCount != NULL )
{
*pnUsageCount = nUsageCount;
}
return TRUE;
}
|