Esempio n. 1
0
int input_init(char* exe_name, const char* forced_plugin) {
  int plugin_found = 0;
  const char** cur_plugin_name = plugin_names;
  struct input_ops* ops;
  char** exts;
  GModule* module;
  char* exe_dir;
  const char* env_path;
  char** env_path_split;
  char** it;

  exe_dir = g_path_get_dirname(exe_name);
  plugin_search_dirs[3] = exe_dir;

  env_path = g_getenv("PATH");
  env_path_split = g_strsplit(env_path, G_SEARCHPATH_SEPARATOR_S, 0);
  for (it = env_path_split; *it; ++it) {
    char* r128_path = g_build_filename(*it, "r128", NULL);
    g_free(*it);
    *it = r128_path;
  }

  if (forced_plugin) plugin_forced = 1;
  /* Load plugins */
  while (*cur_plugin_name) {
    if (forced_plugin && strcmp(forced_plugin, (*cur_plugin_name) + 6)) {
      ++cur_plugin_name;
      continue;
    }
    ops = NULL;
    exts = NULL;
    module = NULL;
    search_module_in_paths(*cur_plugin_name, &module, plugin_search_dirs);
    search_module_in_paths(*cur_plugin_name, &module,
                           (const char* const*) env_path_split);
    if (!module) {
      /* fprintf(stderr, "%s\n", g_module_error()); */
    } else {
      if (!g_module_symbol(module, "ip_ops", (gpointer*) &ops)) {
        fprintf(stderr, "%s: %s\n", *cur_plugin_name, g_module_error());
      }
      if (!g_module_symbol(module, "ip_exts", (gpointer*) &exts)) {
        fprintf(stderr, "%s: %s\n", *cur_plugin_name, g_module_error());
      }
    }
    if (ops) {
      if (verbose) fprintf(stderr, "found plugin %s\n", *cur_plugin_name);
      ops->init_library();
      plugin_found = 1;
    }
    g_modules = g_slist_append(g_modules, module);
    plugin_ops = g_slist_append(plugin_ops, ops);
    plugin_exts = g_slist_append(plugin_exts, exts);
    ++cur_plugin_name;
  }
#ifdef GSTREAMER_INPUT_STATIC
  plugin_ops = g_slist_append(plugin_ops, &gstreamer_ip_ops);
  plugin_exts = g_slist_append(plugin_exts, &gstreamer_ip_exts);
  gstreamer_ip_ops.init_library();
  plugin_found = 1;
#endif
  g_free(exe_dir);
  g_strfreev(env_path_split);
  if (!plugin_found) {
    fprintf(stderr, "Warning: no plugins found!\n");
    return 1;
  }
  return 0;
}
Esempio n. 2
0
static gboolean
load_module_from_file (GjsRequire   *self,
                       const gchar  *module_id,
                       gchar       **script,
                       gsize        *script_len,
                       gchar       **file_name,
                       gchar       **search_path,
                       GError      **error)
{
  gchar *module_id_dot_js;
  gboolean result = FALSE;

  /* add .js to module id if not present */
  if (g_strcmp0 (module_id + strlen (module_id) - 3, ".js") == 0)
    module_id_dot_js = g_strdup (module_id);
  else
    module_id_dot_js = g_strdup_printf ("%s.js", module_id);

  if (module_id_is_relative (module_id))
    {
      const gchar *current_module_dir;
      gchar *tmp_file_name;

      current_module_dir = (const gchar*)g_queue_peek_head (self->priv->dir_stack);
      if (current_module_dir == NULL)
        current_module_dir = ".";

      tmp_file_name = g_strdup_printf ("%s/%s",
                                       current_module_dir,
                                       module_id_dot_js);

      *file_name = normalize_file_name (tmp_file_name, ".");
      g_free (tmp_file_name);

      if (! g_file_get_contents (*file_name,
                                 script,
                                 script_len,
                                 error))
        {
          goto out;
        }

      *search_path = g_strdup (".");

      result = TRUE;
    }
  else
    {
      if (! search_module_in_paths (self->priv->context,
                                    self->priv->exported_paths,
                                    module_id_dot_js,
                                    script,
                                    script_len,
                                    file_name,
                                    search_path,
                                    error))
        {
          if ((*error)->code == G_FILE_ERROR_NOENT)
            {
              g_clear_error (error);
              if (! search_module_in_paths (self->priv->context,
                                            self->priv->private_paths,
                                            module_id_dot_js,
                                            script,
                                            script_len,
                                            file_name,
                                            search_path,
                                            error))
                {
                  goto out;
                }
            }
          else
            {
              goto out;
            }
        }

      result = TRUE;
    }

 out:
  g_free (module_id_dot_js);

  return result;
}