1 /* 2 * SQLInstallerError.c 3 * 4 * $Id$ 5 * 6 * These functions intentionally left blank 7 * 8 * The iODBC driver manager. 9 * 10 * Copyright (C) 1996-2021 OpenLink Software <iodbc@openlinksw.com> 11 * All Rights Reserved. 12 * 13 * This software is released under the terms of either of the following 14 * licenses: 15 * 16 * - GNU Library General Public License (see LICENSE.LGPL) 17 * - The BSD License (see LICENSE.BSD). 18 * 19 * Note that the only valid version of the LGPL license as far as this 20 * project is concerned is the original GNU Library General Public License 21 * Version 2, dated June 1991. 22 * 23 * While not mandated by the BSD license, any patches you make to the 24 * iODBC source code may be contributed back into the iODBC project 25 * at your discretion. Contributions will benefit the Open Source and 26 * Data Access community as a whole. Submissions may be made at: 27 * 28 * http://www.iodbc.org 29 * 30 * 31 * GNU Library Generic Public License Version 2 32 * ============================================ 33 * This library is free software; you can redistribute it and/or 34 * modify it under the terms of the GNU Library General Public 35 * License as published by the Free Software Foundation; only 36 * Version 2 of the License dated June 1991. 37 * 38 * This library is distributed in the hope that it will be useful, 39 * but WITHOUT ANY WARRANTY; without even the implied warranty of 40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 41 * Library General Public License for more details. 42 * 43 * You should have received a copy of the GNU Library General Public 44 * License along with this library; if not, write to the Free 45 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 46 * 47 * 48 * The BSD License 49 * =============== 50 * Redistribution and use in source and binary forms, with or without 51 * modification, are permitted provided that the following conditions 52 * are met: 53 * 54 * 1. Redistributions of source code must retain the above copyright 55 * notice, this list of conditions and the following disclaimer. 56 * 2. Redistributions in binary form must reproduce the above copyright 57 * notice, this list of conditions and the following disclaimer in 58 * the documentation and/or other materials provided with the 59 * distribution. 60 * 3. Neither the name of OpenLink Software Inc. nor the names of its 61 * contributors may be used to endorse or promote products derived 62 * from this software without specific prior written permission. 63 * 64 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 65 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 66 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 67 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR 68 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 69 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 70 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 71 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 72 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 73 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 74 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 75 */ 76 77 78 #include <iodbc.h> 79 #include <odbcinst.h> 80 #include "unicode.h" 81 82 #include "iodbc_error.h" 83 84 LPSTR errortable[] = { 85 "", 86 "General installer error", 87 "Invalid buffer length", 88 "Invalid window handle", 89 "Invalid string parameter", 90 "Invalid type of request", 91 "Component not found", 92 "Invalid driver or translator name", 93 "Invalid keyword-value pairs", 94 "Invalid DSN", 95 "Invalid .INF file", 96 "Request failed", 97 "Invalid install path.", SQLInstallTranslator(LPCSTR lpszInfFile,LPCSTR lpszTranslator,LPCSTR lpszPathIn,LPSTR lpszPathOut,WORD cbPathOutMax,WORD * pcbPathOut,WORD fRequest,LPDWORD lpdwUsageCount)98 "Could not load the driver or translator setup library", 99 "Invalid parameter sequence", 100 "Invalid log file name.", 101 "Operation canceled on user request", 102 "Could not increment or decrement the component usage count", 103 "Creation of the DSN failed", 104 "Error during writing system information", 105 "Deletion of the DSN failed", 106 "Out of memory", 107 "Output string truncated due to a buffer not large enough", 108 "Driver- or translator-specific error", 109 }; 110 111 112 RETCODE INSTAPI 113 SQLInstallerError (WORD iError, DWORD * pfErrorCode, LPSTR lpszErrorMsg, 114 WORD cbErrorMsgMax, WORD * pcbErrorMsg) 115 { 116 LPSTR message; 117 RETCODE retcode = SQL_ERROR; 118 119 /* Check if the index is valid to retrieve an error */ 120 if ((iError - 1) > numerrors) 121 { 122 retcode = SQL_NO_DATA; 123 goto quit; 124 } 125 126 if (!lpszErrorMsg || !cbErrorMsgMax) 127 goto quit; 128 129 lpszErrorMsg[cbErrorMsgMax - 1] = 0; 130 131 /* Copy the message error */ 132 message = (errormsg[iError - 1]) ? 133 errormsg[iError - 1] : errortable[ierror[iError - 1]]; 134 135 if (STRLEN (message) >= cbErrorMsgMax - 1) 136 { 137 STRNCPY (lpszErrorMsg, message, cbErrorMsgMax - 1); 138 retcode = SQL_SUCCESS_WITH_INFO; 139 goto quit; 140 } 141 else 142 STRCPY (lpszErrorMsg, message); 143 144 if (pfErrorCode) 145 *pfErrorCode = ierror[iError - 1]; 146 if (pcbErrorMsg) 147 *pcbErrorMsg = STRLEN (lpszErrorMsg); 148 retcode = SQL_SUCCESS; 149 150 quit: 151 return retcode; 152 } 153 154 RETCODE INSTAPI 155 SQLInstallerErrorW (WORD iError, DWORD * pfErrorCode, LPWSTR lpszErrorMsg, 156 WORD cbErrorMsgMax, WORD * pcbErrorMsg) 157 { 158 char *_errormsg_u8 = NULL; 159 RETCODE retcode = SQL_ERROR; 160 161 if (cbErrorMsgMax > 0) 162 { 163 if ((_errormsg_u8 = 164 malloc (cbErrorMsgMax * UTF8_MAX_CHAR_LEN + 1)) == NULL) 165 { 166 PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM); 167 goto done; 168 } 169 } 170 171 retcode = 172 SQLInstallerError (iError, pfErrorCode, _errormsg_u8, 173 cbErrorMsgMax * UTF8_MAX_CHAR_LEN, pcbErrorMsg); 174 175 if (retcode != SQL_ERROR) 176 { 177 dm_StrCopyOut2_U8toW ((SQLCHAR *)_errormsg_u8, lpszErrorMsg, cbErrorMsgMax, 178 pcbErrorMsg); 179 } 180 181 done: 182 MEM_FREE (_errormsg_u8); 183 184 return retcode; 185 } 186