Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}