HPROC _iodbcdm_dllproc (HDLL hdll, char FAR * sym) { return (HPROC) DLL_PROC (hdll, sym); }
static hosting_version_t * hosting_load_and_check_plugin ( char *file_name, char *function_name, unit_version_t *dock_version, void *appdata) { void *dll; unit_check_t *check_callback; unit_version_t *res; char *fname = file_name; hosting_version_t *hres; FILE *test; char *sys_err; test = fopen (fname, "rb"); if (NULL == test) { hres = (hosting_version_t *) calloc (1, sizeof (hosting_version_t)); res = &(hres->hv_pversion); res->uv_filename = strdup (fname); res->uv_load_error = "Unable to locate file"; return hres; } fclose (test); dll = DLL_OPEN_GLOBAL (fname); if (NULL == dll) { hres = (hosting_version_t *) calloc (1, sizeof (hosting_version_t)); res = &(hres->hv_pversion); res->uv_filename = strdup (fname); sys_err = DLL_ERROR (); res->uv_load_error = strdup (sys_err ? sys_err : ""); return hres; } check_callback = (unit_check_t *) DLL_PROC (dll, function_name); if (NULL == check_callback) { char *err; sys_err = DLL_ERROR (); err = strdup (sys_err ? sys_err : ""); DLL_CLOSE (dll); hres = (hosting_version_t *) calloc (1, sizeof (hosting_version_t)); res = &(hres->hv_pversion); res->uv_filename = strdup (fname); res->uv_load_error = err; return hres; } res = check_callback (dock_version, appdata); if (!res) { hres = (hosting_version_t *) calloc (1, sizeof (hosting_version_t)); res = &(hres->hv_pversion); res->uv_filename = strdup (fname); res->uv_load_error = "incorrect initialization"; return hres; } res->uv_filename = strdup (fname); if (NULL != res->uv_load_error) { char *err = strdup (res->uv_load_error); DLL_CLOSE (dll); hres = (hosting_version_t *) calloc (1, sizeof (hosting_version_t)); res = &(hres->hv_pversion); res->uv_filename = strdup (fname); res->uv_load_error = err; return hres; } if (strcmp (res->uv_title, HOSTING_TITLE)) { DLL_CLOSE (dll); hres = (hosting_version_t *) calloc (1, sizeof (hosting_version_t)); res = &(hres->hv_pversion); res->uv_filename = strdup (fname); res->uv_load_error = "Invalid hosting module loaded"; return hres; } if (NULL != res->uv_gate) { if (_gate_export (res->uv_gate)) { DLL_CLOSE (dll); hres = (hosting_version_t *) calloc (1, sizeof (hosting_version_t)); res = &(hres->hv_pversion); res->uv_filename = strdup (fname); res->uv_load_error = "Loaded plugin requires core functionality not provided by main application"; return hres; } } hres = (hosting_version_t *) res; SET_DLL_PROC (hres, http_handler, HOSTING_HTTP_HANDLER, 1); SET_DLL_PROC (hres, client_attach, HOSTING_CLIENT_ATTACH, 1); SET_DLL_PROC (hres, client_detach, HOSTING_CLIENT_DETACH, 1); SET_DLL_PROC (hres, client_free, HOSTING_CLIENT_FREE, 1); SET_DLL_PROC (hres, client_clone, HOSTING_CLIENT_CLONE, 0); return hres; }
void adddrivers_to_list (GtkWidget *widget, GtkWidget *dlg) { SQLCHAR drvdesc[1024], drvattrs[1024], driver[1024], size[64]; SQLCHAR *data[4]; void *handle; struct stat _stat; SQLSMALLINT len, len1; SQLRETURN ret; HENV henv, drv_henv; HDBC drv_hdbc; pSQLGetInfoFunc funcHdl; pSQLAllocHandle allocHdl; pSQLAllocEnv allocEnvHdl = NULL; pSQLAllocConnect allocConnectHdl = NULL; pSQLFreeHandle freeHdl; pSQLFreeEnv freeEnvHdl; pSQLFreeConnect freeConnectHdl; if (!GTK_IS_CLIST (widget)) return; gtk_clist_clear (GTK_CLIST (widget)); /* Create a HENV to get the list of drivers then */ ret = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto end; } /* Set the version ODBC API to use */ SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER); /* Get the list of drivers */ ret = SQLDrivers (henv, SQL_FETCH_FIRST, drvdesc, sizeof (drvdesc) / sizeof (SQLTCHAR), &len, drvattrs, sizeof (drvattrs) / sizeof (SQLTCHAR), &len1); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto error; } while (ret != SQL_NO_DATA) { data[0] = drvdesc; /* Get the driver library name */ SQLSetConfigMode (ODBC_BOTH_DSN); SQLGetPrivateProfileString (drvdesc, "Driver", "", driver, sizeof (driver) / sizeof (SQLTCHAR), "odbcinst.ini"); if (driver[0] == '\0') SQLGetPrivateProfileString ("Default", "Driver", "", driver, sizeof (driver) / sizeof (SQLTCHAR), "odbcinst.ini"); if (driver[0] == '\0') { data[0] = NULL; goto skip; } data[1] = driver; drv_hdbc = NULL; drv_henv = NULL; if ((handle = (void *) DLL_OPEN (driver)) != NULL) { if ((allocHdl = (pSQLAllocHandle) DLL_PROC (handle, "SQLAllocHandle")) != NULL) { ret = allocHdl (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &drv_henv); if (ret == SQL_ERROR) goto nodriverver; ret = allocHdl (SQL_HANDLE_DBC, drv_henv, &drv_hdbc); if (ret == SQL_ERROR) goto nodriverver; } else { if ((allocEnvHdl = (pSQLAllocEnv) DLL_PROC (handle, "SQLAllocEnv")) != NULL) { ret = allocEnvHdl (&drv_henv); if (ret == SQL_ERROR) goto nodriverver; } else goto nodriverver; if ((allocConnectHdl = (pSQLAllocConnect) DLL_PROC (handle, "SQLAllocConnect")) != NULL) { ret = allocConnectHdl (drv_henv, &drv_hdbc); if (ret == SQL_ERROR) goto nodriverver; } else goto nodriverver; } if ((funcHdl = (pSQLGetInfoFunc) DLL_PROC (handle, "SQLGetInfo")) != NULL) { /* Retrieve some information */ ret = funcHdl (drv_hdbc, SQL_DRIVER_VER, drvattrs, sizeof (drvattrs), &len); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { unsigned int z; /* Drop the description if one provided */ for (z = 0; ((char *) drvattrs)[z]; z++) if (((char *) drvattrs)[z] == ' ') ((char *) drvattrs)[z] = '\0'; data[2] = drvattrs; } else goto nodriverver; } else goto nodriverver; } else { nodriverver: data[2] = "##.##"; } if (drv_hdbc || drv_henv) { if (allocConnectHdl && (freeConnectHdl = (pSQLFreeConnect) DLL_PROC (handle, "SQLFreeConnect")) != NULL) { freeConnectHdl (drv_hdbc); drv_hdbc = NULL; } if (allocEnvHdl && (freeEnvHdl = (pSQLFreeEnv) DLL_PROC (handle, "SQLFreeEnv")) != NULL) { freeEnvHdl (drv_henv); drv_henv = NULL; } } if ((drv_hdbc || drv_henv) && (freeHdl = (pSQLFreeHandle) DLL_PROC (handle, "SQLFreeHandle")) != NULL) { if (drv_hdbc) freeHdl (SQL_HANDLE_DBC, drv_hdbc); if (drv_henv) freeHdl (SQL_HANDLE_ENV, drv_henv); } if (handle) DLL_CLOSE (handle); /* Get the size of the driver */ if (!stat (driver, &_stat)) { sprintf (size, "%d Kb", (int) (_stat.st_size / 1024)); data[3] = size; } else data[3] = "-"; gtk_clist_append (GTK_CLIST (widget), data); skip: ret = SQLDrivers (henv, SQL_FETCH_NEXT, drvdesc, sizeof (drvdesc) / sizeof (SQLTCHAR), &len, drvattrs, sizeof (drvattrs) / sizeof (SQLTCHAR), &len1); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto error; } } error: /* Clean all that */ SQLFreeHandle (SQL_HANDLE_ENV, henv); end: if (GTK_CLIST (widget)->rows > 0) { gtk_clist_columns_autosize (GTK_CLIST (widget)); gtk_clist_sort (GTK_CLIST (widget)); } }
/* Changed ... Have to implement the same for translators */ void adddrivers_to_list (ControlRef widget, WindowRef dlg, BOOL addNotify) { wchar_t drvdesc[1024], drvattrs[1024], driver[1024]; DataBrowserItemID item = DBITEM_ID + 1; DataBrowserCallbacks dbCallbacks; ThemeDrawingState outState = NULL; UInt16 colSize[5] = { 150, 150, 100, 50 , 50}; void *handle; SInt16 outBaseline; Point ioBound; struct stat _stat; SQLSMALLINT len, len1; SQLRETURN ret; HENV henv, drv_henv; HDBC drv_hdbc; pSQLGetInfoFunc funcHdl; pSQLAllocHandle allocHdl; pSQLAllocEnv allocEnvHdl = NULL; pSQLAllocConnect allocConnectHdl = NULL; pSQLFreeHandle freeHdl; pSQLFreeEnv freeEnvHdl; pSQLFreeConnect freeConnectHdl; char *_drv_u8 = NULL; int i; if (!widget) return; GetThemeDrawingState (&outState); /* Install an event handler on the component databrowser */ dbCallbacks.version = kDataBrowserLatestCallbacks; InitDataBrowserCallbacks (&dbCallbacks); if (addNotify) dbCallbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP (drivers_notification_item); /* On Mac OS X 10.0.x : clientDataCallback */ dbCallbacks.u.v1.itemDataCallback = NewDataBrowserItemDataUPP (drivers_getset_item); SetDataBrowserCallbacks (widget, &dbCallbacks); /* Begin the draw of the data browser */ SetDataBrowserTarget (widget, DBITEM_ID); /* Make the clean up */ for (i = 0; i < Drivers_nrows; i++, item++) { CFRelease (Drivers_array[0][i]); Drivers_array[0][i] = NULL; CFRelease (Drivers_array[1][i]); Drivers_array[1][i] = NULL; CFRelease (Drivers_array[2][i]); Drivers_array[2][i] = NULL; CFRelease (Drivers_array[3][i]); Drivers_array[3][i] = NULL; CFRelease (Drivers_array[4][i]); Drivers_array[4][i] = NULL; RemoveDataBrowserItems (widget, DBITEM_ID, 1, &item, DBNAME_ID); } /* Global Initialization */ Drivers_nrows = 0; item = DBITEM_ID + 1; /* Create a HENV to get the list of drivers then */ ret = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto end; } /* Set the version ODBC API to use */ SQLSetEnvAttr (henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); /* Get the list of drivers */ ret = SQLDriversW (henv, SQL_FETCH_FIRST, drvdesc, sizeof (drvdesc)/sizeof(wchar_t), &len, drvattrs, sizeof (drvattrs)/sizeof(wchar_t), &len1); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto error; } while (ret != SQL_NO_DATA) { Drivers_array[0][Drivers_nrows] = convert_wchar_to_CFString(drvdesc); /* Get the driver library name */ SQLSetConfigMode (ODBC_BOTH_DSN); SQLGetPrivateProfileStringW (drvdesc, L"Driver", L"", driver, sizeof (driver)/sizeof(wchar_t), L"odbcinst.ini"); if (driver[0] == L'\0') SQLGetPrivateProfileStringW (L"Default", L"Driver", L"", driver, sizeof (driver)/sizeof(wchar_t), L"odbcinst.ini"); if (driver[0] == L'\0') { if (Drivers_array[0][Drivers_nrows]) { CFRelease (Drivers_array[0][Drivers_nrows]); Drivers_array[0][Drivers_nrows] = NULL; } goto skip; } Drivers_array[1][Drivers_nrows] = convert_wchar_to_CFString(driver); /* Alloc a connection handle */ drv_hdbc = NULL; drv_henv = NULL; _drv_u8 = (char *) dm_SQL_WtoU8((SQLWCHAR*)driver, SQL_NTS); if (_drv_u8 == NULL) goto skip; if ((handle = DLL_OPEN(_drv_u8)) != NULL) { if ((allocHdl = (pSQLAllocHandle)DLL_PROC(handle, "SQLAllocHandle")) != NULL) { ret = allocHdl(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &drv_henv); if (ret == SQL_ERROR) goto nodriverver; ret = allocHdl(SQL_HANDLE_DBC, drv_henv, &drv_hdbc); if (ret == SQL_ERROR) goto nodriverver; } else { if ((allocEnvHdl = (pSQLAllocEnv)DLL_PROC(handle, "SQLAllocEnv")) != NULL) { ret = allocEnvHdl(&drv_henv); if (ret == SQL_ERROR) goto nodriverver; } else goto nodriverver; if ((allocConnectHdl = (pSQLAllocConnect)DLL_PROC(handle, "SQLAllocConnect")) != NULL) { ret = allocConnectHdl(drv_henv, &drv_hdbc); if (ret == SQL_ERROR) goto nodriverver; } else goto nodriverver; } /* * Use SQLGetInfoA for Unicode drivers * and SQLGetInfo for ANSI drivers */ funcHdl = (pSQLGetInfoFunc)DLL_PROC(handle, "SQLGetInfoA"); if (!funcHdl) funcHdl = (pSQLGetInfoFunc)DLL_PROC(handle, "SQLGetInfo"); if (funcHdl) { /* Retrieve some informations */ ret = funcHdl (drv_hdbc, SQL_DRIVER_VER, drvattrs, sizeof(drvattrs), &len); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { char *p = drvattrs; /* Find the description if one provided */ for (; *p ; p++) { if (*p == ' ') { *p++ = '\0'; break; } } /* * Store Version */ Drivers_array[2][Drivers_nrows] = CFStringCreateWithCString(NULL, (char *)drvattrs, kCFStringEncodingUTF8); } else goto nodriverver; } else if ((funcHdl = (pSQLGetInfoFunc)DLL_PROC(handle, "SQLGetInfoW")) != NULL) { /* Retrieve some informations */ ret = funcHdl (drv_hdbc, SQL_DRIVER_VER, drvattrs, sizeof(drvattrs), &len); if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { wchar_t *p = drvattrs; /* Find the description if one provided */ for (; *p ; p++) { if (*p == L' ') { *p++ = L'\0'; break; } } /* * Store Version */ Drivers_array[2][Drivers_nrows] = convert_wchar_to_CFString(drvattrs); } else goto nodriverver; } else goto nodriverver; } else { nodriverver: Drivers_array[2][Drivers_nrows] = CFStringCreateWithCString(NULL, "##.##", kCFStringEncodingUTF8); } if(drv_hdbc || drv_henv) { if(allocConnectHdl && (freeConnectHdl = (pSQLFreeConnect)DLL_PROC(handle, "SQLFreeConnect")) != NULL) { freeConnectHdl(drv_hdbc); drv_hdbc = NULL; } if(allocEnvHdl && (freeEnvHdl = (pSQLFreeEnv)DLL_PROC(handle, "SQLFreeEnv")) != NULL) { freeEnvHdl(drv_henv); drv_henv = NULL; } } if ((drv_hdbc || drv_henv) && (freeHdl = (pSQLFreeHandle)DLL_PROC(handle, "SQLFreeHandle")) != NULL) { if(drv_hdbc) freeHdl(SQL_HANDLE_DBC, drv_hdbc); if(drv_henv) freeHdl(SQL_HANDLE_ENV, drv_henv); } DLL_CLOSE(handle); /* Get the size and date of the driver */ if (!stat (_drv_u8, &_stat)) { CFStringRef strRef; struct tm drivertime; char buf[100]; Drivers_array[3][Drivers_nrows] = CFStringCreateWithFormat(NULL, NULL, strRef = CFStringCreateWithCString(NULL, "%d Kb", kCFStringEncodingUTF8), (int) (_stat.st_size / 1024)); CFRelease(strRef); localtime_r (&_stat.st_mtime, &drivertime); strftime (buf, sizeof (buf), "%c", &drivertime); Drivers_array[4][Drivers_nrows] = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8); } else { Drivers_array[3][Drivers_nrows] = CFStringCreateWithCString(NULL, "-", kCFStringEncodingUTF8); Drivers_array[4][Drivers_nrows] = CFStringCreateWithCString(NULL, "-", kCFStringEncodingUTF8); } for(i = 0 ; i < 5 ; i++) { GetThemeTextDimensions (Drivers_array[i][Drivers_nrows], kThemeSystemFont, kThemeStateActive, false, &ioBound, &outBaseline); if(colSize[i] < ioBound.h) colSize[i] = ioBound.h; } AddDataBrowserItems (widget, DBITEM_ID, 1, &item, DBNAME_ID); item++; Drivers_nrows++; /* Process next one */ skip: MEM_FREE (_drv_u8); _drv_u8 = NULL; ret = SQLDriversW (henv, SQL_FETCH_NEXT, drvdesc, sizeof (drvdesc)/sizeof(wchar_t), &len, drvattrs, sizeof (drvattrs)/sizeof(wchar_t), &len1); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA) { _iodbcdm_nativeerrorbox (dlg, henv, SQL_NULL_HANDLE, SQL_NULL_HANDLE); goto error; } } error: /* Clean all that */ SQLFreeHandle (SQL_HANDLE_ENV, henv); end: ActivateControl (widget); /* Resize the columns to have a good look */ SetDataBrowserTableViewNamedColumnWidth (widget, DBNAME_ID, colSize[0] + 20); SetDataBrowserTableViewNamedColumnWidth (widget, DBFILE_ID, colSize[1] + 20); SetDataBrowserTableViewNamedColumnWidth (widget, DBVERSION_ID, colSize[2] + 20); SetDataBrowserTableViewNamedColumnWidth (widget, DBSIZE_ID, colSize[3] + 20); SetDataBrowserTableViewNamedColumnWidth (widget, DBDATE_ID, colSize[4] + 20); DrawOneControl (widget); /* Remove the DataBrowser callback */ SetDataBrowserCallbacks (NULL, &dbCallbacks); if(outState) DisposeThemeDrawingState (outState); }
unit_version_t *uv_load_and_check_plugin( char *file_name, char *function_name, unit_version_t *dock_version, void *appdata) { char fname[255]; int fnameidx; unit_version_t *res; FILE *test; int so_ext_idx; void *dll; unit_check_t *check_callback; for (fnameidx = 0; fnameidx < (255-5); fnameidx++) { char c = file_name[fnameidx]; if ('\0' == c) break; fname[fnameidx] = (('\\' == c) ? '/' : c); } for (so_ext_idx = 0; so_ext_idx < so_extensions_n; so_ext_idx++) { strcpy (fname+fnameidx, so_extensions[so_ext_idx]); test = fopen (fname, "rb"); if (test) break; } if (NULL == test) { res = calloc (1, sizeof (unit_version_t)); res->uv_filename = (char *) strdup (fname); res->uv_load_error = "Unable to locate file"; return res; } fclose (test); /* open so */ dll = DLL_OPEN_GLOBAL (fname); if (NULL == dll) { res = calloc (1, sizeof (unit_version_t)); res->uv_filename = strdup (fname); res->uv_load_error = strdup (DLL_ERROR()); return res; } if (NULL == function_name) { res = calloc (1, sizeof (unit_version_t)); res->uv_filename = strdup (fname); res->uv_load_error = NULL; return res; } check_callback = (unit_check_t *) DLL_PROC (dll, function_name); if (NULL == check_callback) { char * err = strdup (DLL_ERROR()); DLL_CLOSE (dll); res = calloc (1, sizeof (unit_version_t)); res->uv_filename = strdup (fname); res->uv_load_error = err; return res; } res = check_callback (dock_version, appdata); res->uv_filename = strdup (fname); if (NULL != res->uv_load_error) { /* FreeLibrary (dll); -- result we will return now is in dll's address space */ return res; } if (NULL == res->uv_gate) { /* FreeLibrary (dll); -- result we will return now is in dll's address space */ res->uv_load_error = "Loaded plugin is not compatible with your version of OS"; return res; } if (0 != _gate_export (res->uv_gate)) { /* FreeLibrary (dll); -- result we will return now is in dll's address space */ res->uv_load_error = "Loaded plugin requires core functionality not provided by main application"; return res; } return res; }