Esempio n. 1
0
File: cfg.c Progetto: Tilka/pmacct
void parse_core_process_name(char *filename, int rows, int ignore_names)
{
  int index = 0, found = 0;
  char key[SRVBUFLEN], name[SRVBUFLEN], *start, *end;

  /* searching for 'plugins' key */
  while (index < rows) {
    memset(key, 0, SRVBUFLEN);
    start = NULL; end = NULL;

    start = cfg[index];
    end = strchr(cfg[index], ':');
    if (end > start) {
      strlcpy(key, cfg[index], (end-start)+1);
      if (!strncmp(key, "core_proc_name", sizeof("core_proc_name"))) {
        start = end+1;
        strlcpy(name, start, SRVBUFLEN);
	found = TRUE;
        break;
      }
    }
    index++;
  }

  if (!found || ignore_names) create_plugin(filename, "default", "core");
  else create_plugin(filename, name, "core");
}
void PluginCreatorPlugin::domenu(const QString &menu_name, V3DPluginCallback2 &callback, QWidget *parent)
{
	if (menu_name == tr("create plugin"))
	{
		create_plugin(callback,parent);
	}
    else if(menu_name == tr("create plugin for neuron reconstruction"))
    {
        create_plugin_neuronrec(callback,parent);
    }
	else if(menu_name == tr("produce simplest plugin"))
	{
		QString dir = QFileDialog::getExistingDirectory(0, tr("Save to directory"),
				"/home",
				QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);	
		produce_simplest_plugin(dir.toStdString());
		QMessageBox::information(0, "Success", tr("Plugin codes are produced in %1\n"
					">> cd %1\n"
					">> qmake && make").arg(dir));
	}
	else if(menu_name == tr("domenu usage demo"))
	{
		create_demo1(callback,parent);
	}
	else if(menu_name == tr("load image and swc demo"))
	{
		create_demo2(callback,parent);
	}
	else
	{
		v3d_msg(tr("This plugin is used to produce v3d plugin project from a template file. "
			"Developed by Hang Xiao, 2012-01-27"));
	}
}
Esempio n. 3
0
int PluginLoader::tryToAdd(const char *file) {
	void *plugin_h = dlopen(file, RTLD_NOW);
	if (!plugin_h)
		std::cout << "Could not open plugin " << file << dlerror() << std::endl;

	create_t* create_plugin = (create_t*) dlsym(plugin_h, "create");
	destroy_t* destroy_plugin = (destroy_t*) dlsym(plugin_h, "destroy");

	if (!create_plugin || !destroy_plugin) {
		std::cout << "Could not load symbols for " << file << dlerror()
				<< std::endl;
		return 1;
	}

	AquariusPlugin * plugin = create_plugin();

	if (plugin) {
		plugins.push_back(plugin);
		plugin_destructor.push_back(destroy_plugin);
		return 0;
	} else
		std::cout << "Could not create object pointer  " << file << dlerror()
				<< std::endl;

	return 1;
}
Esempio n. 4
0
PlugInContainer *PlugInManager::LoadPlugIn(wxString plugin_file)
{
      wxString msg(_("PlugInManager: Loading PlugIn: "));
      msg += plugin_file;
      wxLogMessage(msg);

      PlugInContainer *pic = new PlugInContainer;
      pic->m_plugin_file = plugin_file;

   // load the library
      wxDynamicLibrary *plugin = new wxDynamicLibrary(plugin_file);
      pic->m_plibrary = plugin;     // Save a pointer to the wxDynamicLibrary for later deletion

      if(!plugin->IsLoaded())
      {
            wxString msg(_("   PlugInManager: Cannot load library: "));
            msg += plugin_file;
            wxLogMessage(msg);
            delete plugin;
            delete pic;
            return NULL;
      }


    // load the factory symbols
      create_t* create_plugin = (create_t*)plugin->GetSymbol(_T("create_pi"));
      if (NULL == create_plugin)
      {
            wxString msg(_("   PlugInManager: Cannot load symbol create_pi: "));
            msg += plugin_file;
            wxLogMessage(msg);
            delete plugin;
            delete pic;
            return NULL;
      }

      destroy_t* destroy_plugin = (destroy_t*) plugin->GetSymbol(_T("destroy_pi"));
      pic->m_destroy_fn = destroy_plugin;
      if (NULL == destroy_plugin) {
            wxString msg(_("   PlugInManager: Cannot load symbol destroy_pi: "));
            msg += plugin_file;
            wxLogMessage(msg);
            delete plugin;
            delete pic;
            return NULL;
      }


    // create an instance of the plugin class
      opencpn_plugin* plug_in = create_plugin(this);

      pic->m_pplugin = plug_in;

      return pic;

}
Esempio n. 5
0
File: Plugin.c Progetto: aldavud/p
IdentityDictionary add_plugin(const wchar_t * name)
{
    Optr symbol = (Optr)new_Symbol(name);
    IdentityDictionary plugin
        = (IdentityDictionary)IdentityDictionary_lookup(_NATIVES_, symbol);
    if (plugin) { return plugin; }

    plugin = create_plugin();
    IdentityDictionary_store(_NATIVES_,
                             (Optr)new_Symbol(name),
                             (Optr)plugin);
    return plugin;
}
Esempio n. 6
0
File: hangman.c Progetto: Lopo/Lotos
int pl02x100_init(int cm)
{
	PL_OBJECT plugin;
	CM_OBJECT com;
	int i=0;

	set_crash();
/* create plugin */
	if ((plugin=create_plugin())==NULL) {
		write_syslog(ERRLOG, 1, "Nemozem vytvorit novu polozku v registroch pre plugin 'hangman'!\n");
		return 0;
		}
	strcpy(plugin->name,"Hangman");                 /* Plugin Description   */
	strcpy(plugin->author,"Lopo");                  /* Author's name        */
	strcpy(plugin->registration,"02-100");          /* Plugin/Author ID     */
	strcpy(plugin->ver,"1.3");                      /* Plugin version       */
	strcpy(plugin->req_ver,"120");                  /* OSS version required */
	plugin->id = cm;                                /* ID used as reference */
	plugin->req_userfile = 1;                       /* Requires user data?  */
	                                                /* (no separate file required
	                                                    since it keeps its data
	                                                    in a central file, but
	                                                    we need to do housekeeping
	                                                    procedures when the user
	                                                    leaves, so we set this to
	                                                    1 so that we are notified
	                                                    when a user leaves.) */
	plugin->triggerable = 0;                        /* This plugin is triggered
	                                                   by the system timer, and
	                                                   it will automatically
	                                                   save the current poker
	                                                   data when the boards
	                                                   are automatically
	                                                   checked. */
/* create associated command */
	if ((com=create_cmd())==NULL) {
		write_syslog(ERRLOG, 1, "Nemozem pridat prikaz do registrov pre plugin %s !\n", plugin->registration);
		return 0;
		}
	i++;                                            /* Keep track of number created */
	strcpy(com->command,"hangman");                 /* Name of command */
	com->id = plugin->id;                           /* Command reference ID */
	com->req_lev = USER;                            /* Required level for cmd. */
	com->comnum = i;
	com->plugin = plugin;
/* end creating command - repeat as needed for more commands */

	return i;
}
Esempio n. 7
0
int pl00x100_init(int cm)
{
	PL_OBJECT plugin;
	CM_OBJECT com;
	int i=0;

	set_crash();
/* create plugin */
	if ((plugin=create_plugin())==NULL) {
		write_syslog(ERRLOG, 1, "Unable to create new registry entry!\n");
		return 0;
		}
	strcpy(plugin->name,"TalkerMagicEightBall");    /* Plugin Description   */
	strcpy(plugin->author,"Lopo");                  /* Author's name        */
	strcpy(plugin->registration,"00-100");          /* Plugin/Author ID     */
	strcpy(plugin->ver,"1.2");                      /* Plugin version       */
	strcpy(plugin->req_ver,"110");                  /* Runtime ver required */
	plugin->id = cm;                                /* ID used as reference */
	plugin->req_userfile = 0;                       /* Requires user data?  */
	plugin->triggerable = 0;                        /* Can be triggered by
	                                                   regular speech? */

/* create associated command */
	if ((com=create_cmd())==NULL) {
		write_syslog(ERRLOG, 1, "Unable to add command to registry!\n");
		return 0;
		}
	i++;                                            /* Keep track of number created */
	strcpy(com->command,"8ball");                   /* Name of command */
	com->id = plugin->id;                           /* Command reference ID */
	com->req_lev = USER;                            /* Required level for cmd. */
	com->comnum = i;                                /* Per-plugin command ID */
	com->plugin = plugin;                           /* Link to parent plugin */
/* end creating command - repeat as needed for more commands */
	return i;
}
Esempio n. 8
0
File: cfg.c Progetto: Tilka/pmacct
/* parse_configuration_file() reads configuration file
   and stores its content in an array; then creates
   plugin structures and parses supported config keys */
int parse_configuration_file(char *filename)
{
  char localbuf[10240];
  char cmdline [] = "cmdline"; 
  FILE *file;
  int num = 0, cmdlineflag = FALSE, rows_cmdline = rows, idx;
  rows = 0;

  /* NULL filename means we don't have a configuration file; 1st stage: read from
     file and store lines into a first char* array; merge commandline options, if
     required, placing them at the tail - in order to override directives placed
     in the configuration file */
  if (filename) { 
    if ((file = fopen(filename,"r")) == NULL) {
      Log(LOG_ERR, "ERROR: file %s not found.\n", filename);
      return ERR;
    }
    else {
      while (!feof(file)) {
        if (rows == SRVBUFLEN) {
	  Log(LOG_ERR, "ERROR ( %s ): maximum number of %d lines reached.\n", filename, SRVBUFLEN);
	  break;
        }
	memset(localbuf, 0, sizeof(localbuf));
        if (fgets(localbuf, sizeof(localbuf), file) == NULL) break;	
        else {
	  localbuf[sizeof(localbuf)-1] = '\0';
          cfg[rows] = malloc(strlen(localbuf)+2);
	  if (!cfg[rows]) {
	    Log(LOG_ERR, "ERROR ( %s ): malloc() failed (parse_configuration_file). Exiting ..\n", filename);
	    exit(1);
	  }
          strcpy(cfg[rows], localbuf);
          cfg[rows][strlen(localbuf)+1] = '\0';
          rows++;
        } 
      }
    }
    fclose(file);
  }
  else {
    filename = cmdline;
    cmdlineflag = TRUE;
  }

  if (rows_cmdline) {
    for (idx = 0; idx < rows_cmdline && (rows+idx) < SRVBUFLEN; idx++) {
      cfg[rows+idx] = cfg_cmdline[idx];
    }
    rows += idx;
  }

  /* 2nd stage: sanitize lines */
  sanitize_cfg(rows, filename);

  /* 3rd stage: plugin structures creation; we discard
     plugin names if 'pmacctd' has been invoked commandline;
     if any plugin has been activated we default to a single
     'imt' plugin */ 
  if (!cmdlineflag) parse_core_process_name(filename, rows, FALSE);
  else parse_core_process_name(filename, rows, TRUE);

  if (!cmdlineflag) num = parse_plugin_names(filename, rows, FALSE);
  else num = parse_plugin_names(filename, rows, TRUE);

  if (!num) {
    Log(LOG_WARNING, "WARN ( %s ): No plugin has been activated; defaulting to in-memory table.\n", filename); 
    num = create_plugin(filename, "default", "memory");
  }

  if (debug) {
    struct plugins_list_entry *list = plugins_list;
    
    while (list) {
      Log(LOG_DEBUG, "DEBUG ( %s ): plugin name/type: '%s'/'%s'.\n", filename, list->name, list->type.string);
      list = list->next;
    }
  }

  /* 4th stage: setting some default value */
  set_default_values();
  
  /* 5th stage: parsing keys and building configurations */ 
  evaluate_configuration(filename, rows);

  return SUCCESS;
}
Esempio n. 9
0
File: cfg.c Progetto: Tilka/pmacct
/* parse_plugin_names() leaves cfg array untouched: parses the key 'plugins'
   if it exists and creates the plugins linked list */ 
int parse_plugin_names(char *filename, int rows, int ignore_names)
{
  int index = 0, num = 0, found = 0;
  char *start, *end, *start_name, *end_name;
  char key[SRVBUFLEN], value[10240], token[SRVBUFLEN], name[SRVBUFLEN];

  /* searching for 'plugins' key */
  while (index < rows) {
    memset(key, 0, SRVBUFLEN);
    start = NULL; end = NULL;

    start = cfg[index];
    end = strchr(cfg[index], ':');
    if (end > start) {
      strlcpy(key, cfg[index], (end-start)+1); 
      if (!strncmp(key, "plugins", sizeof("plugins"))) {
	start = end+1;
	strcpy(value, start); 
	found = TRUE;
	break;
      }
    }
    index++;
  }

  if (!found) return 0;

  /* parsing declared plugins */
  start = value;
  while (*end != '\0') {
    memset(token, 0, SRVBUFLEN);
    if (!(end = strchr(start, ','))) end = strchr(start, '\0');
    if (end > start) {
      strlcpy(token, start, (end-start)+1);
      if ((start_name = strchr(token, '[')) && (end_name = strchr(token, ']'))) {
        if (end_name > (start_name+1)) {
          strlcpy(name, (start_name+1), (end_name-start_name));
	  trim_spaces(name);
	  *start_name = '\0';
	}
      }
      else strcpy(name, "default");
	
      /* Having already plugins name and type, we'll filter out reserved symbols */
      trim_spaces(token);
      if (!strcmp(token, "core")) {
        Log(LOG_ERR, "ERROR ( %s ): plugins of type 'core' are not allowed. Exiting.\n", filename);
        exit(1);
      }
      if (!ignore_names) {
        if (create_plugin(filename, name, token)) num++;
      }
      else {
        if (create_plugin(filename, "default", token)) num++;
      }
    }
    start = end+1;
  }

  /* having already processed it, we erase 'plugins' line */
  memset(cfg[index], 0, strlen(cfg[index]));

  return num;
}