Exemplo n.º 1
0
void loadmod(void) {
	int (*lse_mod_test)(void) ;
	char * modname = cstring(0,0);
        lt_dlhandle modp;

        // Initialize libtool
        lt_dlinit(); 
        // Add local modules to search path
        lt_dladdsearchdir("./modules/");

#ifdef PKGLIBDIR
        // Add global modules to search path
        lt_dladdsearchdir(PKGLIBDIR);
#endif
        // try to load the module
        modp = lt_dlopenext(modname);

        // If we fail, set the flag to 0 and exit
	flag = 0;
	if ( ! modp ) return;

        // Else make sure the module is sane
	if ( !(lse_mod_test = (int (*)(void)) lt_dlsym(modp, "lse_mod_test")) ) return;
        // If all is well, then the test value 
        // should return 1, so se the flag to this and 
	flag = lse_mod_test();
}
Exemplo n.º 2
0
static void
add_myself(void)
{
	static const char myself[] = "/proc/self/exe";
	static const char moddir[] = PKGLIBDIR;
	static const char eprefix[] = "${exec_prefix}";
	static const char prefix[] = "${prefix}";
	const char *relmoddir;
	char wd[PATH_MAX], *dp;
	size_t sz;

	sz = readlink(myself, wd, sizeof(wd));
	wd[sz] = '\0';
	if ((dp = strrchr(wd, '/')) == NULL) {
		return;
	}
	/* add the path where the binary resides */
	*dp = '\0';
	EDEBUG("adding %s\n", wd);
	lt_dladdsearchdir(wd);

#define MEMCMPLIT(a, b)	memcmp((a), (b), sizeof(b) - 1)
	if (moddir[0] == '/') {
		/* absolute libdir, add him */
		lt_dladdsearchdir(moddir);
		return;
	} else if (moddir[0] == '.') {
		/* relative libdir? relative to what? */
		return;
	} else if (memcmp(moddir, eprefix, sizeof(eprefix) - 1) == 0) {
		/* take the bit after EPREFIX for catting later on */
		relmoddir = moddir + sizeof(eprefix) - 1;
	} else if (memcmp(moddir, prefix, sizeof(prefix) - 1) == 0) {
		/* take the bit after PREFIX for catting later on */
		relmoddir = moddir + sizeof(prefix) - 1;
	} else {
		/* don't know, i guess i'll leave ya to it */
		return;
	}

	/* go back one level in dp */
	if ((dp = strrchr(wd, '/')) == NULL) {
		return;
	} else if (strcmp(dp, "/bin") && strcmp(dp, "/sbin")) {
		/* dp doesn't end in /bin nor /sbin */
		return;
	}

	/* good, now we're ready to cat relmoddir to dp */
	strncpy(dp, relmoddir, sizeof(wd) - (dp - wd));
	EDEBUG("adding %s\n", wd);
	lt_dladdsearchdir(wd);
	return;
}
Exemplo n.º 3
0
int
radiusd_add_load_path(const char *path)
{
	if (lt_dlinit())
		return 1;
	return lt_dladdsearchdir(path);
}
Exemplo n.º 4
0
int
mu_sv_load_add_dir (mu_sieve_machine_t mach, const char *name)
{
  if (sieve_init_load_path ())
    return 1;
  mu_sieve_machine_add_destructor (mach, (mu_sieve_destructor_t) lt_dlexit, 
                                   NULL);
  return lt_dladdsearchdir (name);
}
Exemplo n.º 5
0
void moduleloader_init(const char* searchpath){
	lt_dlinit();

	char* path_list = strdup(searchpath);
	char* path = strtok(path_list, ":");
	while ( path ){
		lt_dladdsearchdir(path);
		path = strtok(NULL, ":");
	}
	free(path_list);
}
Exemplo n.º 6
0
static void initlibltdl(void) {
    char buffer[2000];

    if (!plugins_are_initialized()) {
        init_plugins();
        if (getPfaEditDir(buffer)!=NULL ) {
            strcpy(buffer,getPfaEditDir(buffer));
            strcat(buffer,"/plugins");
            lt_dladdsearchdir(strdup(buffer));
        }
    }
}
Exemplo n.º 7
0
static void initlibltdl(void) {
    char buffer[2000];
    char *userConfigDir;

    if (!plugins_are_initialized()) {
        init_plugins();
        userConfigDir = getFontForgeUserDir(Config);
        if ( userConfigDir != NULL ) {
            strcpy(buffer,userConfigDir);
            strcat(buffer,"/plugins");
            free(userConfigDir);
            lt_dladdsearchdir(buffer);
        }
    }
}
Exemplo n.º 8
0
int module_add_dir(const char *moddir)
{
	char *fixed_moddir;

	if (*moddir != '/') {
		char cwd[1024];

		cwd[0] = 0;
		getcwd(cwd, sizeof(cwd));
		cwd[sizeof(cwd)-1] = 0;
		fixed_moddir = egg_mprintf("%s/%s", cwd, moddir);
	}
	else fixed_moddir = (char *)moddir;

	lt_dladdsearchdir(fixed_moddir);
	if (fixed_moddir != moddir) free(fixed_moddir);
	return(0);
}
/**
 * \brief Load system ports
 * 
 * \param list a #GPPortInfoList
 *
 * Searches the system for io-drivers and appends them to the list. You would
 * normally call this function once after #gp_port_info_list_new and then
 * use this list in order to supply #gp_port_set_info with parameters or to do
 * autodetection.
 *
 * \return a gphoto2 error code
 **/
int
gp_port_info_list_load (GPPortInfoList *list)
{
	const char *iolibs_env = getenv(IOLIBDIR_ENV);
	const char *iolibs = (iolibs_env != NULL)?iolibs_env:IOLIBS;
	int result;

	CHECK_NULL (list);

	gp_log (GP_LOG_DEBUG, "gphoto2-port-info-list",
		_("Using ltdl to load io-drivers from '%s'..."),
		iolibs);
	lt_dlinit ();
	lt_dladdsearchdir (iolibs);
	result = lt_dlforeachfile (iolibs, foreach_func, list);
	lt_dlexit ();
	if (result < 0)
		return (result);
        return (GP_OK);
}
Exemplo n.º 10
0
/*
 * Load all available modules.  Return nonzero on failure.
 */
int stp_module_load(void)
{
  /* initialise libltdl */
#ifdef USE_LTDL
  static int ltdl_is_initialised = 0;        /* Is libltdl initialised? */
#endif
  static int module_list_is_initialised = 0; /* Is the module list initialised? */
#if defined(USE_LTDL) || defined(USE_DLOPEN)
  stp_list_t *dir_list;                      /* List of directories to scan */
  stp_list_t *file_list;                     /* List of modules to open */
  stp_list_item_t *file;                     /* Pointer to current module */
#endif

#ifdef USE_LTDL
  if (!ltdl_is_initialised)
    {
      if (lt_dlinit())
	{
	  stp_erprintf("Error initialising libltdl: %s\n", DLERROR());
	  return 1;
	}
      ltdl_is_initialised = 1;
    }
  /* set default search paths */
  lt_dladdsearchdir(PKGMODULEDIR);
#endif

  /* initialise module_list */
  if (!module_list_is_initialised)
    {
      if (!(module_list = stp_list_create()))
	return 1;
      stp_list_set_freefunc(module_list, module_list_freefunc);
      module_list_is_initialised = 1;
    }

  /* search for available modules */
#if defined (USE_LTDL) || defined (USE_DLOPEN)
  if (!(dir_list = stp_list_create()))
    return 1;
  stp_list_set_freefunc(dir_list, stp_list_node_free_data);
  if (getenv("STP_MODULE_PATH"))
    {
      stp_path_split(dir_list, getenv("STP_MODULE_PATH"));
    }
  else
    {
#ifdef USE_LTDL
      stp_path_split(dir_list, getenv("LTDL_LIBRARY_PATH"));
      stp_path_split(dir_list, lt_dlgetsearchpath());
#else
      stp_path_split(dir_list, PKGMODULEDIR);
#endif
    }
#ifdef USE_LTDL
  file_list = stp_path_search(dir_list, ".la");
#else
  file_list = stp_path_search(dir_list, ".so");
#endif
  stp_list_destroy(dir_list);

  /* load modules */
  file = stp_list_get_start(file_list);
  while (file)
    {
      stp_module_open((const char *) stp_list_item_get_data(file));
      file = stp_list_item_next(file);
    }

  stp_list_destroy(file_list);
#else /* use a static module list */
  {
    int i=0;
    while (static_modules[i])
      {
	stp_module_register(static_modules[i]);
	i++;
      }
  }
#endif
  return 0;
  }
Exemplo n.º 11
0
BOOL SQLCreateDataSource(		HWND	hWnd,
								LPCSTR	pszDS )
{
	BOOL	nReturn;
	void 	*hDLL;
	BOOL	(*pSQLCreateDataSource)(HWND, LPCSTR);
	char 	*p;
	char    szGUILibFile[FILENAME_MAX];
	int		found;

	if ( !hWnd )
	{
        inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_INVALID_HWND, "" );
		return FALSE;
	}

    /*
     * initialize libtool
     */

    lt_dlinit();

    /*
     * DETERMINE PATH FOR GUI PLUGIN
     *
     */

    /*
     * first look in the environment
     */

	p  = getenv( "ODBCINSTQ" );
	if ( p )
	{
		strcpy( szGUILibFile, p );
	}
	else
	{
		SQLGetPrivateProfileString( "ODBC", "ODBCINSTQ", "", szGUILibFile, sizeof( szGUILibFile ), "odbcinst.ini" );

		if ( strlen( szGUILibFile ) == 0 )
		{
			/*
			 * we need to find the extension to use as well
			 */

			get_lib_file( szGUILibFile, NULL );

			if ( lt_dladdsearchdir( DEFLIB_PATH ) )
			{
				inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, 
						ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );
			}
		}
	}

    /*
     * USE libtool TO LOAD PLUGIN AND CALL FUNCTION
     */

    nReturn = FALSE;
	found = FALSE;
    hDLL = lt_dlopen( szGUILibFile );
	if ( hDLL )
	{
        /* change the name, as it avoids it finding it in the calling lib */
		pSQLCreateDataSource = (BOOL (*)(HWND, LPSTR))lt_dlsym( hDLL, "QTSQLCreateDataSources" );
		if ( pSQLCreateDataSource )
			nReturn = pSQLCreateDataSource(NULL,pszDS);
		else
			inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );

		found = TRUE;
	}
	else
   	{
        /*
         * try after adding the explicit path
         */

		get_lib_file( szGUILibFile, DEFLIB_PATH );
        hDLL = lt_dlopen( szGUILibFile );
        if ( hDLL )
        {
            /* change the name, as it avoids it finding it in the calling lib */
            pSQLCreateDataSource = (BOOL (*)(HWND))lt_dlsym( hDLL, "QTSQLCreateDataSources" );
            if ( pSQLCreateDataSource )
                nReturn = pSQLCreateDataSource(NULL,pszDS);
            else
                inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, (char*)lt_dlerror() );

			found = TRUE;
        }
    }

	if ( !found )
	{
		/* TRY TO PASS THROUGH TO GUI SHADOW LIB */
		if ( (hDLL = lt_dlopen( "libodbcinstG.so" ))  )
		{
			pSQLCreateDataSource = (BOOL(*)(HWND,LPSTR))lt_dlsym( hDLL, "SQLCreateDataSource" );
			if ( pSQLCreateDataSource )
				nReturn = pSQLCreateDataSource( NULL,pszDS );
			else
				inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );

			found = TRUE;
		}
	}

	if ( !found )
	{
		inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_GENERAL_ERR, "" );
	}

	return nReturn;
}
int
gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir,
			    GPContext *context)
{
	CameraLibraryIdFunc id;
	CameraLibraryAbilitiesFunc ab;
	CameraText text;
	int ret, x, old_count, new_count;
	unsigned int i, p;
	const char *filename;
	CameraList *flist;
	int count;
	lt_dlhandle lh;

	CHECK_NULL (list && dir);

	gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list",
		"Using ltdl to load camera libraries from '%s'...", dir);
	CHECK_RESULT (gp_list_new (&flist));
	ret = gp_list_reset (flist);
	if (ret < GP_OK) {
		gp_list_free (flist);
		return ret;
	}
	if (1) { /* a new block in which we can define a temporary variable */
		foreach_data_t foreach_data = { NULL, GP_OK };
		foreach_data.list = flist;
		lt_dlinit ();
		lt_dladdsearchdir (dir);
		ret = lt_dlforeachfile (dir, foreach_func, &foreach_data);
		lt_dlexit ();
		if (ret != 0) {
			gp_list_free (flist);
			gp_log (GP_LOG_ERROR, "gp-abilities-list", 
				"Internal error looking for camlibs (%d)", ret);
			gp_context_error (context,
					  _("Internal error looking for camlibs. "
					    "(path names too long?)"));
			return (foreach_data.result!=GP_OK)?foreach_data.result:GP_ERROR;
		}
	}
	count = gp_list_count (flist);
	if (count < GP_OK) {
		gp_list_free (flist);
		return ret;
	}
	gp_log (GP_LOG_DEBUG, "gp-abilities-list", "Found %i "
		"camera drivers.", count);
	lt_dlinit ();
	p = gp_context_progress_start (context, count,
		_("Loading camera drivers from '%s'..."), dir);
	for (i = 0; i < count; i++) {
		ret = gp_list_get_name (flist, i, &filename);
		if (ret < GP_OK) {
			gp_list_free (flist);
			return ret;
		}
		lh = lt_dlopenext (filename);
		if (!lh) {
			gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list",
				"Failed to load '%s': %s.", filename,
				lt_dlerror ());
			continue;
		}

		/* camera_id */
		id = lt_dlsym (lh, "camera_id");
		if (!id) {
			gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list",
				"Library '%s' does not seem to "
				"contain a camera_id function: %s",
				filename, lt_dlerror ());
			lt_dlclose (lh);
			continue;
		}

		/*
		 * Make sure the camera driver hasn't been
		 * loaded yet.
		 */
		if (id (&text) != GP_OK) {
			lt_dlclose (lh);
			continue;
		}
		if (gp_abilities_list_lookup_id (list, text.text) >= 0) {
			lt_dlclose (lh);
			continue;
		} 

		/* camera_abilities */
		ab = lt_dlsym (lh, "camera_abilities");
		if (!ab) {
			gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list",
				"Library '%s' does not seem to "
				"contain a camera_abilities function: "
				"%s", filename, lt_dlerror ());
			lt_dlclose (lh);
			continue;
		}

		old_count = gp_abilities_list_count (list);
		if (old_count < 0) {
			lt_dlclose (lh);
			continue;
		}

		if (ab (list) != GP_OK) {
			lt_dlclose (lh);
			continue;
		}

		lt_dlclose (lh);

		new_count = gp_abilities_list_count (list);
		if (new_count < 0)
			continue;

		/* Copy in the core-specific information */
		for (x = old_count; x < new_count; x++) {
			strcpy (list->abilities[x].id, text.text);
			strcpy (list->abilities[x].library, filename);
		}

		gp_context_progress_update (context, p, i);
		if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) {
			lt_dlexit ();
			gp_list_free (flist);
			return (GP_ERROR_CANCEL); 
		}
	}
	gp_context_progress_stop (context, p);
	lt_dlexit ();
	gp_list_free (flist);

	return (GP_OK);
}
Exemplo n.º 13
0
/**************************************************************************
  Initialize ai stuff
**************************************************************************/
void ai_init(void)
{
  bool failure = FALSE;
#if !defined(AI_MODULES) || defined(AI_MOD_STATIC_CLASSIC) || defined(AI_MOD_STATIC_THREADED)
  /* First !defined(AI_MODULES) case is for default ai support. */
  struct ai_type *ai;
#endif

#ifdef AI_MODULES
  if (lt_dlinit()) {
    failure = TRUE;
  }
  if (!failure) {

#ifdef DEBUG
    /* First search ai modules under directory ai/<module> under
       current directory. This allows us to run freeciv without
       installing it. */
    const char *moduledirs[] = { "default", "threaded", "stub", NULL };
    int i;

    for (i = 0; moduledirs[i] != NULL ; i++) {
      char buf[2048];

      fc_snprintf(buf, sizeof(buf), "ai/%s", moduledirs[i]);
      lt_dladdsearchdir(buf);
    }
#endif /* DEBUG */

    /* Then search ai modules from their installation directory. */
    lt_dladdsearchdir(AI_MODULEDIR);
  }
#endif /* AI_MODULES */

#if defined(AI_MODULES) && !defined(AI_MOD_STATIC_CLASSIC)

  if (!failure && !load_ai_module("classic")) {
    failure = TRUE;
  }

#else  /* AI_MOD_STATIC_CLASSIC */

  ai = ai_type_alloc();
  init_ai(ai);
  if (!fc_ai_classic_setup(ai)) {
    failure = TRUE;
  }

#endif /* AI_MOD_STATIC_CLASSIC */

  if (failure) {
    log_fatal(_("Failed to setup default AI module, cannot continue."));
    exit(EXIT_FAILURE);
  }

  default_ai = ai;

#ifdef AI_MOD_STATIC_THREADED
  ai = ai_type_alloc();
  if (ai != NULL) {
    init_ai(ai);
    if (!fc_ai_threaded_setup(ai)) {
      log_error(_("Failed to setup threaded AI module"));
    }
  }
#endif /* AI_MOD_STATIC_THREADED */
}
Exemplo n.º 14
0
/*
 * rig_load_backend
 * Dynamically load a rig backend through dlopen mechanism
 */
int HAMLIB_API rig_load_backend(const char *be_name)
{
# define PREFIX "hamlib-"

	lt_dlhandle be_handle;
	backend_init_t be_init;
	int status;
	char libname[PATH_MAX];
	char probefname[MAXFUNCNAMELEN];
	int i;

	/*
	 * lt_dlinit may be called several times
	 *
	 * FIXME: make static build seamless
	 */
#if 0
	LTDL_SET_PRELOADED_SYMBOLS();
#endif

	status = lt_dlinit();
	if (status) {
    		rig_debug(RIG_DEBUG_ERR, "rig_backend_load: lt_dlinit for %s "
							"failed: %s\n", be_name, lt_dlerror());
    		return -RIG_EINTERNAL;
	}

	lt_dladdsearchdir(HAMLIB_MODULE_DIR);

	rig_debug(RIG_DEBUG_VERBOSE, "rig: loading backend %s\n",be_name);

	/*
	 * add hamlib directory here
	 */
	snprintf (libname, sizeof (libname), PREFIX"%s", be_name);

	be_handle = lt_dlopenext (libname);

	/*
	 * external module not found? try dlopenself for backends
	 * compiled in static
	 */
	if (!be_handle || rig_check_backend_version(be_handle, be_name, &be_init) != RIG_OK) {
		rig_debug(RIG_DEBUG_VERBOSE, "rig:  lt_dlopen(\"%s\") failed (%s), "
						"trying static symbols...\n",
						libname, lt_dlerror());
		be_handle = lt_dlopen (NULL);
		if (!be_handle || rig_check_backend_version(be_handle, be_name, &be_init) != RIG_OK) {
			rig_debug(RIG_DEBUG_ERR, "rig:  lt_dlopen(\"%s\") failed (%s)\n",
						libname, lt_dlerror());
			return -RIG_EINVAL;
		}
	}


	/*
	 * register probe function if present
	 * NOTE: rig_load_backend might have been called upon a backend
	 * 	not in riglist.h! In this case, do nothing.
	 */
	for (i=0; i<RIG_BACKEND_MAX && rig_backend_list[i].be_name; i++) {
		if (!strncmp(be_name, rig_backend_list[i].be_name, 64)) {
    			snprintf(probefname, MAXFUNCNAMELEN, "probeallrigs%d_%s", ABI_VERSION, be_name);
    			rig_backend_list[i].be_probe_all =
				(rig_model_t (*)(hamlib_port_t*, rig_probe_func_t, rig_ptr_t))
						lt_dlsym (be_handle, probefname);
				break;
		}
	}

	status = (*be_init)(be_handle);

 	return status;
}
Exemplo n.º 15
0
static int
_add_load_dir (void *item, void *unused)
{
  return lt_dladdsearchdir (item);
}
Exemplo n.º 16
0
/**
 * initializeScanRules
 *
 * this reads in the rules definition file for identifying the playload.
 * It compiles the regular
 * expressions and loads in the dynamic libraries as defined for later use
 *
 * @param scriptFile a file pointer to the rule definition file
 *
 */
gboolean
ycInitializeScanRules (
    FILE * scriptFile,
    GError ** err)
{
/*
// for every rule that is "imagined" can be returned on a single call to
   pcre_exec, you need to multiply that number by 6 for the correct number of
   "vector" entries (and because of pcre limitation should be a multiple of 3)
*/
#define NUM_SUBSTRING_VECTS 60
    const char         *errorString;
    int                 errorPos;

    char                eString[ESTRING_SIZE];
    pcre               *ruleScanner;
    pcre               *pluginScanner;
    pcre               *commentScanner;
    pcre               *pluginArgScanner;
    pcre               *signatureScanner;
    const char          commentScannerExp[] = "^\\s*#[^\\n]*\\n";
    const char          pluginScannerExp[] =
      "^[[:space:]]*label[[:space:]]+([[:digit:]]+)"
      "[[:space:]]+plugin[[:space:]]*([^[:space:]\\n].*)\\n";
    const char          ruleScannerExp[] =
      "^[[:space:]]*label[[:space:]]+([[:digit:]]+)"
      "[[:space:]]+regex[[:space:]]*([^\\n].*)\\n";
    const char          signatureScannerExp[] =
      "^[[:space:]]*label[[:space:]]+([[:digit:]]+)"
      "[[:space:]]+signature[[:space:]]*([^\\n].*)\\n";
    const char          pluginArgScannerExp[] = "[[:word:]]";
    int                 rc;
    int                 substringVects[NUM_SUBSTRING_VECTS];
    char                lineBuffer[LINE_BUF_SIZE];
    int                 readLength;
    char               *captString;
    unsigned int        bufferOffset = 0;
    int                 currentStartPos = 0;
    int                 loop;
    char                *ltdl_lib_path = NULL;

    /* first mark all plugin entries as empty, just in case */
    for (loop = 0; loop < MAX_PAYLOAD_RULES; loop++) {
        ruleTable[loop].ruleType = EMPTY;
    }

    /* initialize the hash table */
    ycPortHashInitialize();


    /* initialize the dynamic loader library */
    rc = lt_dlinit();
    if (0 != rc) {
        *err = g_error_new (YAF_ERROR_DOMAIN, YAF_ERROR_IMPL,
                     "error initializing the dynamic loader library: \"%s\"",
                     lt_dlerror ());
        return FALSE;
    }
    /* if LTDL_LIBRARY_PATH is set - add this one first */
    ltdl_lib_path = getenv("LTDL_LIBRARY_PATH");
    if (ltdl_lib_path) {
        lt_dladdsearchdir(ltdl_lib_path);
    }

#ifdef YAF_APPLABEL_PATH
    /* add the applabel path based on libdir at build time */
    lt_dladdsearchdir(YAF_APPLABEL_PATH);
#else
    /* add /usr/local/lib/yaf to path since libtool can never find it */

    lt_dladdsearchdir(YAF_SEARCH_PATH);
    lt_dladdsearchdir(ALT_SEARCH_PATH);
    lt_dladdsearchdir(ALT_SEARCH_PATH64);
#endif
    /* create the hash table for library modules to library handle names */
    if (!hcreate ((MAX_PAYLOAD_RULES * 20) / 100)) {
        *err = g_error_new (YAF_ERROR_DOMAIN, YAF_ERROR_IMPL,
                     "couldn't create load module hash table (%d)", errno);
        return FALSE;
    }


    /*
     * take all of the rules needed to parse the rule file and compile
     * them into a form that // the regular expression engine can deal with */
    ruleScanner = pcre_compile(ruleScannerExp, PCRE_MULTILINE, &errorString,
                               &errorPos, NULL);
    if (NULL == ruleScanner) {
        ycDisplayScannerRuleError(eString, ESTRING_SIZE,
                                  "couldn't build the rule scanner",
                                  errorString, ruleScannerExp, errorPos);
        *err = g_error_new(YAF_ERROR_DOMAIN,YAF_ERROR_INTERNAL, "%s", eString);
        return FALSE;
    }

    pluginScanner = pcre_compile(pluginScannerExp, PCRE_MULTILINE,
                                 &errorString, &errorPos, NULL);
    if (NULL == pluginScanner) {
        ycDisplayScannerRuleError(eString, ESTRING_SIZE,
                                  "couldn't build the plugin scanner",
                                  errorString, pluginScannerExp, errorPos);
        *err = g_error_new(YAF_ERROR_DOMAIN,YAF_ERROR_INTERNAL, "%s", eString);
        return FALSE;
    }

    commentScanner = pcre_compile(commentScannerExp, PCRE_MULTILINE,
                                  &errorString, &errorPos, NULL);
    if (NULL == commentScanner) {
        ycDisplayScannerRuleError (eString, ESTRING_SIZE,
                                   "couldn't build the comment scanner",
                                   errorString, commentScannerExp, errorPos);
        *err = g_error_new(YAF_ERROR_DOMAIN,YAF_ERROR_INTERNAL, "%s", eString);
        return FALSE;
    }

    pluginArgScanner = pcre_compile(pluginArgScannerExp, PCRE_MULTILINE,
                                    &errorString, &errorPos, NULL);
    if (NULL == pluginArgScanner) {
        ycDisplayScannerRuleError(eString, ESTRING_SIZE,
                                  "couldn't build the plugin argument scanner",
                                  errorString, pluginArgScannerExp, errorPos);
        *err = g_error_new(YAF_ERROR_DOMAIN,YAF_ERROR_INTERNAL, "%s", eString);
        return FALSE;
    }

    signatureScanner = pcre_compile(signatureScannerExp, PCRE_MULTILINE,
                                    &errorString, &errorPos, NULL);
    if (NULL == signatureScanner) {
        ycDisplayScannerRuleError (eString, ESTRING_SIZE,
                       "couldn't build the signature scanner",
                       errorString, signatureScannerExp, errorPos);
        *err = g_error_new(YAF_ERROR_DOMAIN,YAF_ERROR_INTERNAL, "%s", eString);
        return FALSE;
    }

    /*
     * this is the loop that does the lion's share of the rule file
     * processing first read a hunk of the rule file, (this may include
     * multiple lines of stuff) this gets a little bit ugly, there are a
     * number of issues that have to handled; first, because there may be
     * multiple lines (which is in fact likely) it has to be able to work
     * its way through the buffer, a single pass of the buffer through the
     * pcre engine simply won't cut it; at the end, it is possible // to have
     * part of line, when this happens, it needs to copy the leftover part
     * of the read into the front of the buffer, and then read again to fill in
     * the rest of line.  (this detail limits a single line to
     * LINE_BUF_SIZE size) */
    do {
        readLength =
          fread (lineBuffer + bufferOffset, 1, LINE_BUF_SIZE - 1 -bufferOffset,
                 scriptFile);
        if (0 == readLength) {
            if (ferror (scriptFile)) {
                *err = g_error_new(YAF_ERROR_DOMAIN, YAF_ERROR_IO,
                                   "couldn't read the rule file: %s",
                                   strerror (errno));
                return FALSE;
            }
            break;
        }

        /* fread only returns how much it read from the file - need to add
           extra we put in the buffer from last read, if any */

        readLength += bufferOffset;

        /*
         * substringVects is used by the pcre library to indicate where the
         * matched substrings are in the input string, but [1] points to
         * the very end of the total match, we use this to iterate through
         * the readBuffer, always reset it after a read */
        substringVects[0] = 0;
        substringVects[1] = 0;

        /* parse as much of the input buffer as possible */
        while (substringVects[1] < readLength) {

#if YFDEBUG_APPLABEL
            g_debug("readLength %d startPosition %d\n", readLength,
                    substringVects[1]);
            for (loop=0; loop < 10; loop++) {
                if (loop+substringVects[1] > readLength) {
                    break;
                }
                char curChar = *(lineBuffer + substringVects[1] + loop);
                if (iscntrl(curChar)) {
                    g_debug(".");
                    continue;
                }
                if (isprint(curChar)) {
                    g_debug("%c", curChar);
                } else {
                    g_debug(".");
                }
            }
            g_debug("\n");
#endif
            /* get rid of CR's and LF's at the begging, use the simple manual
             * method, they gum up the regex works */
            if ('\n' == *(lineBuffer + substringVects[1])
                || '\r' == *(lineBuffer + substringVects[1])) {
                substringVects[1]++;
                continue;
            }

            /* first check for comments, and eliminate them */
            currentStartPos = substringVects[1];
            /* need to store the current offset, if we fail to match, we
               get -1 in [1] */
            rc = pcre_exec (commentScanner, NULL, lineBuffer, readLength,
                            substringVects[1], PCRE_ANCHORED, substringVects,
                            NUM_SUBSTRING_VECTS);
            if (rc > 0) {
#if YFDEBUG_APPLABEL
                g_debug("comment match pos %d to pos %d\n",
                    substringVects[0], substringVects[1]);
                pcre_get_substring(lineBuffer, substringVects, rc, 0,
                    (const char**)&captString);
                g_debug("comment line is \"%s\"\n", captString);
                pcre_free(captString);
#endif
                continue;
            }
            substringVects[1] = currentStartPos;

            /* scan the line to see if it is a regex statement, and get the
             * arguments if it is */
            rc = pcre_exec (ruleScanner, NULL, lineBuffer, readLength,
                            substringVects[1], PCRE_ANCHORED, substringVects,
                            NUM_SUBSTRING_VECTS);
            if (rc > 0) {
                pcre               *newRule;
                pcre_extra         *newExtra;

                /* get the first matched field from the regex rule expression
                 * (the label value) */
                pcre_get_substring (lineBuffer, substringVects, rc, 1,
                                    (const char **) &captString);
                ruleTable[numPayloadRules].payloadLabelValue =
                  strtoul (captString, NULL, 10);
#if YFDEBUG_APPLABEL
                g_debug("regex: rule # %u, label value %lu ",
                        numPayloadRules, strtoul(captString, NULL, 10));
#endif
                pcre_free (captString);

                /* get the second matched field from the regex rule expression
                 * (should be the regex) */

                pcre_get_substring(lineBuffer, substringVects, rc, 2,
                                   (const char **) &captString);
#if YF_DEBUG_APPLABEL
                g_debug(" regex \"%s\"\n", captString);
#endif
                newRule = pcre_compile(captString, 0, &errorString, &errorPos,
                                       NULL);
                if (NULL == newRule) {
                    ycDisplayScannerRuleError(eString, ESTRING_SIZE,
                                     "error in regex application labeler rule",
                                              errorString, captString,
                                              errorPos);

                } else {
                    newExtra = pcre_study (newRule, 0, &errorString);
                    ruleTable[numPayloadRules].ruleArgs.regexFields.
                      scannerExpression = newRule;
                    ruleTable[numPayloadRules].ruleArgs.regexFields.
                      scannerExtra = newExtra;
                    ruleTable[numPayloadRules].ruleType = REGEX;
                    ycPortHashInsert(ruleTable[numPayloadRules].payloadLabelValue, numPayloadRules);
                    numPayloadRules++;
                }
                pcre_free (captString);

                if (MAX_PAYLOAD_RULES == numPayloadRules) {
                    *err = g_error_new (YAF_ERROR_DOMAIN, YAF_ERROR_LIMIT,
                                        "maximum number of application labeler"
                                        " rules has been reached");
                    return FALSE;
                }

                continue;
            }
            substringVects[1] = currentStartPos;
            /* scan the line to see if it is a plugin statement, and handle the
             * arguments if it is */
            rc = pcre_exec (pluginScanner, NULL, lineBuffer, readLength,
                            substringVects[1], PCRE_ANCHORED, substringVects,
                            NUM_SUBSTRING_VECTS);
            if (rc > 0) {
                int                 numArgs;
                char             **argStrings;

                /* get the first matched field from the regex rule expression
                 * (the lable value) */
                pcre_get_substring (lineBuffer, substringVects, rc, 1,
                                    (const char **) &captString);
                ruleTable[numPayloadRules].payloadLabelValue =
                  strtoul (captString, NULL, 10);
#if YFDEBUG_APPLABEL
                g_debug("plugin: rule # %u, label value %lu ",
                        numPayloadRules, strtoul(captString, NULL, 10));
#endif
                pcre_free (captString);

                /*
                 * get the second matched field, which should be the plugin
                 * name and all of its arguments, now we need to chunk that
                 * into an array of strings, ala argc, argv
                 */
                pcre_get_substring(lineBuffer, substringVects, rc, 2,
                                   (const char **) &captString);
                ycChunkString(captString, &numArgs, &argStrings);

                if (numArgs < 2) {
                    g_critical("error: not enough arguments to load and call "
                               "a plugin, at least a library name and function"
                               " name are needed\n");
                    pcre_free(captString);
                    pcre_get_substring(lineBuffer, substringVects, rc, 0,
                                       (const char **) &captString);
                    g_critical("input line: \"%s\"\n", captString);
                } else {
                    ENTRY               newItem;
                    ENTRY              *foundItem;
                    lt_dlhandle         modHandle;
                    lt_ptr              funcPtr;

                    ruleTable[numPayloadRules].ruleType = PLUGIN;
                    ruleTable[numPayloadRules].ruleArgs.pluginArgs.numArgs =
                      numArgs;
                    ruleTable[numPayloadRules].ruleArgs.pluginArgs.pluginArgs =
                      argStrings;
                    newItem.key = strdup(argStrings[0]);
                    if (NULL == newItem.key) {
                        g_error("out of memory error\n");
                        for (loop = 0; loop < numArgs; loop++) {
                            free ((char *) (argStrings[loop]));
                        }
                        free(argStrings);
                        return FALSE;
                    }
                    newItem.data = NULL;
                    foundItem = hsearch(newItem, FIND);
                    if (NULL == foundItem) {

                        modHandle = lt_dlopenext(newItem.key);
                        if (NULL == modHandle) {
                            g_critical("Couldn't open library \"%s\": %s",
                                       argStrings[0], lt_dlerror());
                            g_critical("Search path set to %s",
                                       lt_dlgetsearchpath());
                            g_critical("Set LTDL_LIBRARY_PATH to correct"
                                       " location.");
                            for (loop = 0; loop < numArgs; loop++) {
                                free((char *) (argStrings[loop]));
                            }
                            free(argStrings);
                            pcre_free(captString);
                            continue;
                        } else {
#if YFDEBUG_APPLABEL
                            const lt_dlinfo *info = lt_dlgetinfo(modHandle);
                            g_debug("Loading %s plugin from %s", info->name, info->filename);
#endif
                        }
                        newItem.data = (void *)modHandle;
                        hsearch(newItem, ENTER);
                    } else {
                        modHandle = (lt_dlhandle)foundItem->data;
                    }

                    funcPtr = lt_dlsym(modHandle, argStrings[1]);
                    if (NULL == funcPtr) {
                        g_critical("couldn't find function \"%s\" in library"
                                   " \"%s\"\n", argStrings[1], argStrings[0]);
                        for (loop = 0; loop < numArgs; loop++) {
                            free ((char *) (argStrings[loop]));
                        }
                        free (argStrings);
                        pcre_free (captString);
                        continue;
                    }
                    ruleTable[numPayloadRules].ruleArgs.pluginArgs.func =
                        (ycScannerPlugin_fn) funcPtr;

                    ycPortHashInsert(ruleTable[numPayloadRules].payloadLabelValue, numPayloadRules);
                    numPayloadRules++;
                }

                pcre_free(captString);

                if (MAX_PAYLOAD_RULES == numPayloadRules) {
                    g_warning ("maximum number of rules has been reached\n");
                    return TRUE;
                }
                continue;
            }


        substringVects[1] = currentStartPos;

        /* scan the line to see if it is a signature, and get the
         * arguments if it is */
        rc = pcre_exec(signatureScanner, NULL, lineBuffer, readLength,
                       substringVects[1], PCRE_ANCHORED, substringVects,
                       NUM_SUBSTRING_VECTS);
        if (rc > 0) {
            pcre               *newRule;
            pcre_extra         *newExtra;

            /* get the first matched field from the regex rule expression
             * (the label value) */
            pcre_get_substring(lineBuffer, substringVects, rc, 1,
                               (const char **) &captString);

            sigTable[numSigRules].payloadLabelValue = strtoul(captString, NULL,
                                                              10);
#if YFDEBUG_APPLABEL
            g_debug("signature: rule # %u, label value %lu ",
                    numSigRules, strtoul(captString, NULL, 10));
#endif
            pcre_free (captString);

            /* get the second matched field from the regex rule expression
             * (should be the regex) */
            pcre_get_substring(lineBuffer, substringVects, rc, 2,
                               (const char **) &captString);
#if YFDEBUG_APPLABEL
            g_debug(" signature \"%s\"\n", captString);
#endif
            newRule = pcre_compile(captString, 0, &errorString, &errorPos,
                                   NULL);
            if (NULL == newRule) {
                ycDisplayScannerRuleError (eString, ESTRING_SIZE,
                                           "error in signature application "
                                           "labeler rule", errorString,
                                           captString, errorPos);

            } else {
                newExtra = pcre_study (newRule, 0, &errorString);
                sigTable[numSigRules].ruleArgs.regexFields.
                    scannerExpression = newRule;
                sigTable[numSigRules].ruleArgs.regexFields.
                    scannerExtra = newExtra;
                sigTable[numSigRules].ruleType = SIGNATURE;
                numSigRules++;
            }

            pcre_free(captString);

            if (MAX_PAYLOAD_RULES == numSigRules) {
                *err = g_error_new(YAF_ERROR_DOMAIN, YAF_ERROR_LIMIT,
                                   "maximum number of signature rules has "
                                   "been reached");
                return FALSE;
            }

            continue;
        }

        substringVects[1] = currentStartPos;


        /*   pcre_free (captString);*/

#if YFDEBUG_APPLABEL
        g_debug("plugin args: ");
        for (loop = 0; loop < numArgs; loop++) {
            g_debug("\"%s\" ", (*argStrings)[loop]);
        }
        g_debug("\n");
#endif

        /*
         * check to see if we have partial text left over at the end of
         * the read buffer, if we copy it to the front of the read
         * buffer, and on the next read, read a little less to
         * compensate for the left over amount */
        if ((PCRE_ERROR_NOMATCH == rc) && (substringVects[1] < readLength)
            && !feof (scriptFile)) {
            memmove (lineBuffer, lineBuffer + substringVects[1],
                     readLength - substringVects[1]);
            bufferOffset = readLength - substringVects[1];
            break;
        } else if (PCRE_ERROR_NOMATCH == rc && feof (scriptFile)) {
            /* this is an error, we have crap left over at the end of the
             * file that we can't parse! */
            g_critical("unparsed text at the end of the application labeler"
                       " rule file!\n");
            break;
        }
        }

    } while (!ferror (scriptFile) && !feof (scriptFile));

    /*
     * get rid of the module handle lookup hash; this creates a mem leak of
     * the module handles, they can't be freed any longer (although this is a
     * crappy hash, and iterating the hash is not possible....) */
    hdestroy();

    g_debug("Application Labeler accepted %d rules.", numPayloadRules);
    g_debug("Application Labeler accepted %d signatures.", numSigRules);
    pcre_free(ruleScanner);
    pcre_free(pluginScanner);
    pcre_free(commentScanner);
    pcre_free(pluginArgScanner);
    pcre_free(signatureScanner);

    /* debug */
    return TRUE;
}