28 #include "archlib-windows.h"
41 #define DBG_PROGNAME "INSTCBM.EXE"
44 #define DBG_IS_DEBUG_C
61 #define PLUGIN_PREFIX "opencbm-"
72 #define PLUGIN_SUFFIX ".dll"
96 malloc_plugin_file_name(
const char *PluginName)
98 char * filename = NULL;
107 if (filename == NULL)
111 strcat(filename, PluginName);
147 for (currentPlugin = InstallParameter->PluginList; currentPlugin != NULL; currentPlugin = currentPlugin->Next) {
148 if (strcmp(currentPlugin->Name, PluginName) == 0) {
191 while (previousPlugin->Next) {
192 previousPlugin = previousPlugin->Next;
197 previousPlugin->Next = Plugin;
223 nextPlugin = InstallParameter->PluginList;
225 while (nextPlugin != NULL) {
226 currentPlugin = nextPlugin;
228 nextPlugin = currentPlugin->Next;
230 free(currentPlugin->Name);
231 free(currentPlugin->FileName);
232 free(currentPlugin->OptionMemory);
261 getopt_long_callback(
int Argc,
263 const char *Optstring,
264 const struct option *Longopts)
270 retValue = getopt_long(Argc, Argv, Optstring, Longopts, NULL);
276 GetPluginData(
const char *
const PluginName,
cbm_install_parameter_t * InstallParameter,
int Argc,
char *
const Argv[])
278 HINSTANCE library = NULL;
279 char *plugin_file_name = NULL;
280 void *option_memory = NULL;
289 unsigned int option_memory_size = 0;
298 memset(&commandLineData, 0,
sizeof(commandLineData));
300 if (PluginAlreadyInList(PluginName, InstallParameter)) {
301 fprintf(stderr,
"Please, do not add plugin '%s' multiple times!\n", PluginName);
305 pluginData = malloc(
sizeof(*pluginData));
309 memset(pluginData, 0,
sizeof(*pluginData));
311 plugin_file_name = malloc_plugin_file_name(PluginName);
313 if (plugin_file_name == NULL)
322 UINT oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
324 library = LoadLibrary(plugin_file_name);
326 SetErrorMode(oldErrorMode);
329 if (library == NULL) {
330 fprintf(stderr,
"Error loading plugin '%s', ABORTING!.\n\n", PluginName);
335 opencbm_plugin_install_process_commandline = (
void *) GetProcAddress(library,
"opencbm_plugin_install_process_commandline");
336 opencbm_plugin_install_get_needed_files = (
void *) GetProcAddress(library,
"opencbm_plugin_install_get_needed_files");
338 if (0 == (opencbm_plugin_install_process_commandline && opencbm_plugin_install_get_needed_files))
348 option_memory_size = (option_memory_size > 0) ? option_memory_size : 1;
350 option_memory = malloc(option_memory_size);
352 if (option_memory == NULL)
355 memset(option_memory, 0, option_memory_size);
357 commandLineData.Argc = Argc;
358 commandLineData.Argv = Argv;
359 commandLineData.OptArg = &optarg;
360 commandLineData.OptInd = &optind;
361 commandLineData.OptErr = &opterr;
362 commandLineData.OptOpt = &optopt;
363 commandLineData.OptionMemory = option_memory;
364 commandLineData.GetoptLongCallback = &getopt_long_callback;
365 commandLineData.InstallParameter = InstallParameter;
369 if ( ! error && pluginData) {
373 if (pluginData->Name == NULL || pluginData->FileName == NULL) {
379 free(pluginData->FileName);
380 free(pluginData->Name);
383 free(commandLineData.OptionMemory);
388 pluginData->OptionMemory = commandLineData.OptionMemory;
395 pluginData->NeededFiles = malloc(needed_files_length);
397 if (NULL == pluginData->NeededFiles)
405 returnValue = pluginData;
410 FreeLibrary(library);
413 free(plugin_file_name);
448 const char *
const PluginName,
458 pluginParameter = GetPluginData(PluginName, InstallParameter, Argc, Argv);
460 error = pluginParameter == NULL ? TRUE : FALSE;
463 PluginAddToList(InstallParameter, pluginParameter);
489 WIN32_FIND_DATA finddata;
492 const char *findfilename = NULL;
497 findfilename = malloc_plugin_file_name(
"*");
499 if ( ! findfilename) {
504 findhandle = FindFirstFile(findfilename, &finddata);
507 if (findhandle != INVALID_HANDLE_VALUE) {
511 if (finddata.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) {
516 int len = strlen(finddata.cFileName) + 1;
517 char *pluginName = malloc(len);
519 if (pluginName == NULL) {
524 strcpy(pluginName, finddata.cFileName +
sizeof(
PLUGIN_PREFIX) - 1);
525 pluginName[strlen(pluginName) - (
sizeof(
PLUGIN_SUFFIX) - 1)] =
'\0';
527 pluginParameter = GetPluginData(pluginName, InstallParameter, 1, NULL);
529 if (pluginParameter) {
530 PluginAddToList(InstallParameter, pluginParameter);
539 if (FindNextFile(findhandle, &finddata) == 0) {
544 FindClose(findhandle);
598 HMODULE openCbmDllHandle = NULL;
605 opencbm_plugin_get_all_plugin_names_context_t opencbm_plugin_get_all_plugin_names_context;
609 if (openCbmDllHandle == NULL) {
611 fprintf(stderr,
"Could not open the OpenCBM DLL.");
615 opencbm_plugin_get_all_plugin_names = (opencbm_plugin_get_all_plugin_names_t *)
616 GetProcAddress(openCbmDllHandle,
"opencbm_plugin_get_all_plugin_names");
618 if ( ! opencbm_plugin_get_all_plugin_names ) {
622 opencbm_plugin_get_all_plugin_names_context.Callback = get_all_installed_plugins_callback;
623 opencbm_plugin_get_all_plugin_names_context.InstallParameter = InstallParameter;
633 if (openCbmDllHandle) {
634 FreeLibrary(openCbmDllHandle);
671 for (plugin = InstallParameter->PluginList; (plugin != NULL) && ! error; plugin = plugin->Next) {
672 printf(
"Using plugin: '%s' with filename '%s'.\n", plugin->Name, plugin->FileName);
673 error = Callback(plugin, Context);
struct cbm_install_parameter_plugin_s cbm_install_parameter_plugin_t
BOOL PluginForAll_Callback_t(cbm_install_parameter_plugin_t *PluginInstallParameter, void *Context)
#define FUNC_LEAVE_INT(_xxx)
Header for installation routines.
char * cbmlibmisc_strdup(const char *const OldString)
Duplicate a given string.
Define makros for debugging purposes.
struct CbmPluginInstallProcessCommandlineData_s CbmPluginInstallProcessCommandlineData_t
void PluginListFree(cbm_install_parameter_t *InstallParameter)
Free all the memory occupied by plugin management.
void cbmlibmisc_strfree(const char *String)
Free a string.
HMODULE LoadLocalOpenCBMDll(void)
@@@
BOOL get_all_plugins(cbm_install_parameter_t *InstallParameter)
Get all the plugins.
Define the IOCTL codes for the opencbm driver.
struct cbm_install_parameter_s cbm_install_parameter_t
unsigned int CBMAPIDECL opencbm_plugin_install_get_needed_files(CbmPluginInstallProcessCommandlineData_t *Data, opencbm_plugin_install_neededfiles_t *Destination)
@@@
#define FUNC_LEAVE_PTR(_xxx, _TYPE)
char * cbmlibmisc_stralloc(unsigned int Length)
allocate memory for a string of a given size
Shared library / DLL for accessing the driver Read configuration file.
BOOL get_all_installed_plugins(cbm_install_parameter_t *InstallParameter)
Get all the installed plugins.
#define FUNC_LEAVE_BOOL(_xxx)
#define PLUGIN_SUFFIX
name suffix for the plugin executable
unsigned int CBMAPIDECL opencbm_plugin_install_process_commandline(CbmPluginInstallProcessCommandlineData_t *Data)
@@@
EXTERN BOOL CBMAPIDECL opencbm_plugin_get_all_plugin_names(opencbm_plugin_get_all_plugin_names_context_t *Context)
@@@
Defining OpenCBM version.
#define FUNC_LEAVE_STRING(_xxx)
Define makros and functions which account for differences between the different architectures.
Internal API for opencbm installation.
BOOL ProcessPluginCommandlineAndAddIt(cbm_install_parameter_t *InstallParameter, const char *const PluginName, int Argc, char *const Argv[])
Process the command-line parameters for a plugin and add that plugin to the plugin list...
BOOL PluginForAll(cbm_install_parameter_t *InstallParameter, PluginForAll_Callback_t *Callback, void *Context)
Execute a callback function for all plugins in the plugin list.
Some functions for string handling.
#define PLUGIN_PREFIX
name prefix for the plugin executable
int opencbm_configuration_close(opencbm_configuration_handle Handle)
Close the configuration file.