📄 connectparams.c
字号:
#ifdef WIN32# error There is something wrong in configuration...#endiftypedef struct{ LPCSTR entry; LPSTR buffer; int buffer_len; int ret_val; int found;}ProfileParam;static voidtdoParseProfile(const char *option, const char *value, void *param){ ProfileParam *p = (ProfileParam *) param; if (strcasecmp(p->entry, option) == 0) { tds_strlcpy(p->buffer, value, p->buffer_len); p->ret_val = strlen(p->buffer); p->found = 1; }}static intSQLGetPrivateProfileString(LPCSTR pszSection, LPCSTR pszEntry, LPCSTR pszDefault, LPSTR pRetBuffer, int nRetBuffer, LPCSTR pszFileName){ FILE *hFile; ProfileParam param; tdsdump_log(TDS_DBG_FUNC, "SQLGetPrivateProfileString(%p, %p, %p, %p, %d, %p)\n", pszSection, pszEntry, pszDefault, pRetBuffer, nRetBuffer, pszFileName); if (!pszSection) { /* spec says return list of all section names - but we will just return nothing */ tdsdump_log(TDS_DBG_WARN, "WARNING: Functionality for NULL pszSection not implemented.\n"); return 0; } if (!pszEntry) { /* spec says return list of all key names in section - but we will just return nothing */ tdsdump_log(TDS_DBG_WARN, "WARNING: Functionality for NULL pszEntry not implemented.\n"); return 0; } if (nRetBuffer < 1) tdsdump_log(TDS_DBG_WARN, "WARNING: No space to return a value because nRetBuffer < 1.\n"); if (pszFileName && *pszFileName == '/') hFile = fopen(pszFileName, "r"); else hFile = tdoGetIniFileName(); if (hFile == NULL) { tdsdump_log(TDS_DBG_ERROR, "ERROR: Could not open configuration file\n"); return 0; } param.entry = pszEntry; param.buffer = pRetBuffer; param.buffer_len = nRetBuffer; param.ret_val = 0; param.found = 0; pRetBuffer[0] = 0; tds_read_conf_section(hFile, pszSection, tdoParseProfile, ¶m); if (pszDefault && !param.found) { tds_strlcpy(pRetBuffer, pszDefault, nRetBuffer); param.ret_val = strlen(pRetBuffer); } fclose(hFile); return param.ret_val;}static FILE *tdoGetIniFileName(){ FILE *ret = NULL; char *p; char *fn; /* * First, try the ODBCINI environment variable */ if ((p = getenv("ODBCINI")) != NULL) ret = fopen(p, "r"); /* * Second, try the HOME environment variable */ if (!ret && (p = tds_get_homedir()) != NULL) { fn = NULL; if (asprintf(&fn, "%s/.odbc.ini", p) > 0) { ret = fopen(fn, "r"); free(fn); } free(p); } /* * As a last resort, try SYS_ODBC_INI */ if (!ret) ret = fopen(SYS_ODBC_INI, "r"); return ret;}#endif /* !HAVE_SQLGETPRIVATEPROFILESTRING */#ifdef UNIXODBC/* * Begin BIG Hack. * * We need these from odbcinstext.h but it wants to * include <log.h> and <ini.h>, which are not in the * standard include path. XXX smurph * confirmed by unixODBC stuff, odbcinstext.h shouldn't be installed. freddy77 */#define INI_MAX_LINE 1000#define INI_MAX_OBJECT_NAME INI_MAX_LINE#define INI_MAX_PROPERTY_NAME INI_MAX_LINE#define INI_MAX_PROPERTY_VALUE INI_MAX_LINE#define ODBCINST_PROMPTTYPE_LABEL 0 /* readonly */#define ODBCINST_PROMPTTYPE_TEXTEDIT 1#define ODBCINST_PROMPTTYPE_LISTBOX 2#define ODBCINST_PROMPTTYPE_COMBOBOX 3#define ODBCINST_PROMPTTYPE_FILENAME 4#define ODBCINST_PROMPTTYPE_HIDDEN 5typedef struct tODBCINSTPROPERTY{ struct tODBCINSTPROPERTY *pNext; /* pointer to next property, NULL if last property */ char szName[INI_MAX_PROPERTY_NAME + 1]; /* property name */ char szValue[INI_MAX_PROPERTY_VALUE + 1]; /* property value */ int nPromptType; /* PROMPTTYPE_TEXTEDIT, PROMPTTYPE_LISTBOX, PROMPTTYPE_COMBOBOX, PROMPTTYPE_FILENAME */ char **aPromptData; /* array of pointers terminated with a NULL value in array. */ char *pszHelp; /* help on this property (driver setups should keep it short) */ void *pWidget; /* CALLER CAN STORE A POINTER TO ? HERE */ int bRefresh; /* app should refresh widget ie Driver Setup has changed aPromptData or szValue */ void *hDLL; /* for odbcinst internal use... only first property has valid one */}ODBCINSTPROPERTY, *HODBCINSTPROPERTY;/* * End BIG Hack. */int ODBCINSTGetProperties(HODBCINSTPROPERTY hLastProperty);static const char *const aTDSver[] = { "", "4.2", "5.0", "7.0", "8.0", NULL};static const char *const aLanguage[] = { "us_english", NULL};/*static const char *aAuth[] = { "Server", "Domain", "Both", NULL};*/intODBCINSTGetProperties(HODBCINSTPROPERTY hLastProperty){ hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT; tds_strlcpy(hLastProperty->szName, "Servername", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("Name of FreeTDS connection to connect to.\n" "This server name refer to entry in freetds.conf file, not real server name.\n" "This property cannot be used with Server property."); hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT; tds_strlcpy(hLastProperty->szName, "Server", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("Name of server to connect to.\n" "This should be the name of real server.\n" "This property cannot be used with Servername property."); hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT; tds_strlcpy(hLastProperty->szName, "Address", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("The hostname or ip address of the server."); hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT; tds_strlcpy(hLastProperty->szName, "Port", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "1433", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("TCP/IP Port to connect to."); hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT; tds_strlcpy(hLastProperty->szName, "Database", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("Default database."); hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_LISTBOX; hLastProperty->aPromptData = malloc(sizeof(aTDSver)); memcpy(hLastProperty->aPromptData, aTDSver, sizeof(aTDSver)); tds_strlcpy(hLastProperty->szName, "TDS_Version", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "4.2", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("The TDS protocol version.\n" " 4.2 MSSQL 6.5 or Sybase < 10.x\n" " 5.0 Sybase >= 10.x\n" " 7.0 MSSQL 7 or MSSQL 2000\n" " 8.0 MSSQL 2000"); hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_COMBOBOX; hLastProperty->aPromptData = malloc(sizeof(aLanguage)); memcpy(hLastProperty->aPromptData, aLanguage, sizeof(aLanguage)); tds_strlcpy(hLastProperty->szName, "Language", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "us_english", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("The default language setting."); hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_HIDDEN; tds_strlcpy(hLastProperty->szName, "TextSize", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("Text datatype limit."); /* ??? in odbc.ini ??? *//* hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT; tds_strlcpy(hLastProperty->szName, "UID", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("User ID (Beware of security issues)."); hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT; tds_strlcpy(hLastProperty->szName, "PWD", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("Password (Beware of security issues).");*//* hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_LISTBOX; hLastProperty->aPromptData = malloc(sizeof(aAuth)); memcpy(hLastProperty->aPromptData, aAuth, sizeof(aAuth)); tds_strlcpy(hLastProperty->szName, "Authentication", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "Server", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("The server authentication mechanism.");*/ hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT; tds_strlcpy(hLastProperty->szName, "Domain", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("The default domain to use when using Domain Authentication."); hLastProperty->pNext = (HODBCINSTPROPERTY) malloc(sizeof(ODBCINSTPROPERTY)); hLastProperty = hLastProperty->pNext; memset(hLastProperty, 0, sizeof(ODBCINSTPROPERTY)); hLastProperty->nPromptType = ODBCINST_PROMPTTYPE_TEXTEDIT; tds_strlcpy(hLastProperty->szName, "PacketSize", INI_MAX_PROPERTY_NAME); tds_strlcpy(hLastProperty->szValue, "", INI_MAX_PROPERTY_VALUE); hLastProperty->pszHelp = (char *) strdup("Size of network packets."); return 1;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -