Esempio n. 1
0
static int test_from_file(void) {
    bool err = false;
    xcb_xrm_database_t *database;
    char *path;
    const char *srcdir;

    /* Set by automake, needed for out-of-tree builds */
    srcdir = getenv("srcdir");
    if (srcdir == NULL)
        srcdir = ".";

    /* Test xcb_xrm_database_from_file with relative #include directives */
    asprintf(&path, "%s/tests/resources/1/xresources1", srcdir);
    database = xcb_xrm_database_from_file(path);
    free(path);
    err |= check_database(database,
            "First: 1\n"
            "Third: 3\n"
            "Second: 2\n");
    xcb_xrm_database_free(database);

    /* Test that the inclusion depth is limited */
    asprintf(&path, "%s/tests/resources/3/loop.xresources", srcdir);
    database = xcb_xrm_database_from_file(path);
    free(path);
    err |= check_database(database,
            "First: 1\n"
            "Second: 2\n");
    xcb_xrm_database_free(database);

    /* Test xcb_xrm_database_from_default for resolution of $HOME. */
    set_env_var_to_path("HOME", srcdir, "tests/resources/2");
    set_env_var_to_path("XENVIRONMENT", srcdir, "tests/resources/2/xenvironment");
    database = xcb_xrm_database_from_default(conn);
    err |= check_database(database,
            "First: 1\n"
            "Second: 2\n");
    xcb_xrm_database_free(database);

    /* Test xcb_xrm_database_from_resource_manager. */
    xcb_change_property_checked(conn, XCB_PROP_MODE_REPLACE, screen->root, XCB_ATOM_RESOURCE_MANAGER,
            XCB_ATOM_STRING, 8, strlen("First: 1\n*Second: 2") + 1, "First: 1\n*Second: 2\0");
    xcb_flush(conn);
    database = xcb_xrm_database_from_resource_manager(conn, screen);
    err |= check_database(database,
            "First: 1\n"
            "*Second: 2\n");
    xcb_xrm_database_free(database);

    return err;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
    char *conffile = NULL;
    int request_kill = 0, show_message = 0;
    
    if (!read_parameters(argc, argv, &conffile, &request_kill, &show_message)) {
	print_usage(argv[0]);
	return 1;
    }
    
    /* read the config file; conffile = NULL means use the default. */
    if (!read_config(conffile))
	return 1; /* error reading the config file */
    setup_defaults();
    
    if (request_kill) {
	kill_server();
	return 0;
    }
    
    if (show_message) {
	signal_message();
	return 0;
    }
    
    setup_signals();
    
    /* Init files and directories.
     * Start logging last, so that the log is only created if startup succeeds. */
    if (!init_workdir() ||
	!init_database() ||
	!check_database() ||
	!begin_logging())
	return 1;
    
    if (!settings.nodaemon) {
    	if (daemon(0, 0) == -1) {
	    settings.nodaemon = TRUE;
	    log_msg("could not detach from terminal: %s", strerror(errno));
	    return 1;
	}
	if (!create_pidfile())
	    return 1;
    }

    /* give this process and its children their own process group id for kill() */
    setpgid(0, 0);
    report_startup();
    
    runserver();
        
    /* shutdown */
    remove_pidfile();
    end_logging();
    close_database();
    remove_unix_socket();
    free_config();
    
    return 0;
}
Esempio n. 3
0
static int test_combine_databases(void) {
    bool err = false;

    xcb_xrm_database_t *source_db;
    xcb_xrm_database_t *target_db;

    source_db = xcb_xrm_database_from_string(
            "a1.b1*c1: 1\n"
            "a2.b2: 2\n"
            "a3: 3\n");
    target_db = xcb_xrm_database_from_string(
            "a3: 0\n"
            "a1.b1*c1: 0\n"
            "a4.?.b4: 0\n");
    xcb_xrm_database_combine(source_db, &target_db, false);
    err |= check_database(target_db,
            "a3: 0\n"
            "a1.b1*c1: 0\n"
            "a4.?.b4: 0\n"
            "a2.b2: 2\n");
    xcb_xrm_database_free(source_db);
    xcb_xrm_database_free(target_db);

    source_db = xcb_xrm_database_from_string(
            "a1.b1*c1: 1\n"
            "a2.b2: 2\n"
            "a3: 3\n");
    target_db = xcb_xrm_database_from_string(
            "a3: 0\n"
            "a1.b1*c1: 0\n"
            "a4.?.b4: 0\n");
    xcb_xrm_database_combine(source_db, &target_db, true);
    err |= check_database(target_db,
            "a4.?.b4: 0\n"
            "a1.b1*c1: 1\n"
            "a2.b2: 2\n"
            "a3: 3\n");
    xcb_xrm_database_free(source_db);
    xcb_xrm_database_free(target_db);

    return err;
}
Esempio n. 4
0
void *CDATABASE_get(CCONNECTION *conn, const char *name)
{
  CDATABASE *_object;

  if (check_database(conn, name, TRUE))
    return NULL;

  _object = GB.New(GB.FindClass("Database"), NULL, NULL);
  THIS->conn = conn;
  THIS->driver = conn->driver;
  THIS->name = GB.NewZeroString(name);
  return THIS;
}
Esempio n. 5
0
static int test_put_resource(void) {
    bool err = false;

    xcb_xrm_database_t *database = NULL;
    xcb_xrm_database_put_resource(&database, "First", "1");
    xcb_xrm_database_put_resource(&database, "First*second", "2");
    xcb_xrm_database_put_resource(&database, "Third", "  a\\ b\nc d\te ");
    xcb_xrm_database_put_resource(&database, "Fourth", "\t\ta\\ b\nc d\te ");
    err |= check_database(database,
            "First: 1\n"
            "First*second: 2\n"
            "Third: \\  a\\\\ b\\nc d\te \n"
            "Fourth: \\\t\ta\\\\ b\\nc d\te \n");

    xcb_xrm_database_put_resource(&database, "First", "3");
    xcb_xrm_database_put_resource(&database, "First*second", "4");
    xcb_xrm_database_put_resource(&database, "Third", "x");
    xcb_xrm_database_put_resource(&database, "Fourth", "x");
    err |= check_database(database,
            "First: 3\n"
            "First*second: 4\n"
            "Third: x\n"
            "Fourth: x\n");

    xcb_xrm_database_put_resource_line(&database, "Second:xyz");
    xcb_xrm_database_put_resource_line(&database, "Third:  xyz");
    xcb_xrm_database_put_resource_line(&database, "*Fifth.sixth*seventh.?.eigth*?*last: xyz");
    err |= check_database(database,
            "First: 3\n"
            "First*second: 4\n"
            "Fourth: x\n"
            "Second: xyz\n"
            "Third: xyz\n"
            "*Fifth.sixth*seventh.?.eigth*?*last: xyz\n");

    xcb_xrm_database_free(database);
    return err;
}
Esempio n. 6
0
// -------------------------------------------------------------------------------------------------
int main(int argc, char**argv)
{
	try
	{

		// Settings
		aq::Settings settings;      
    settings.outputFile = "stdout";

		// log options
		std::string mode;
		std::string ident;
		unsigned int level;
		bool lock_mode = false;
		bool date_mode = false;
		bool pid_mode = false;

		// aq options
    std::string aqHome;
    std::string aqName;
		std::string propertiesFile;
		std::string queryIdent;
		std::string sqlQuery;
		std::string sqlQueriesFile;
		std::string baseDescr;
    std::string DLLFunction;
		unsigned int worker;
		bool multipleAnswerFiles = false;
		bool keepFiles = false;
		bool display = false;
    bool displayCount = false;
    bool trace = false;
		bool loadDatabase = false;
    bool force = false;
    bool useTextAQMatrix = false;

    // testing purpose options
		std::string aqMatrixFileName;
		bool transform = false;
    bool checkDatabase = false;
		bool simulateAQEngine = false;
		bool skipNestedQuery = false;

    // load option
    std::string tableNameToLoad;

    // generate tmp table option
    unsigned int nbValues = 100;
    unsigned int minValue = 0;
    unsigned int maxValue = 100;
    unsigned int nbTables = 1;
    bool generateTmpTable = false;

    char * s = ::getenv("AQ_HOME");
    if (s != NULL)
      aqHome = s;

    //
    // initialize verb builder
    aq::VerbBuilder vb;
    aq::verb::VerbFactory::GetInstance().setBuilder(&vb);

    //
    // if aq.ini exists in current directory, use it as default settings
    settings.iniFile = "aq.ini";
    boost::filesystem::path iniFile(settings.iniFile);
    if (boost::filesystem::exists(iniFile))
    {
      settings.load(settings.iniFile);
    }

    //
    // look for properties file in args
    for (size_t i = 1; i < argc; i++)
    {
      //
      // read ini file
      if ((strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--settings") == 0))
      {
        if ((i + 1) < argc)
        {
          propertiesFile = argv[i+1];
          settings.load(propertiesFile);
        }
      }

    }

    //
    // command line arguments are prior to settings file
    po::options_description all("Allowed options");
		all.add_options()
			("help,h", "produce help message")
      ;

    po::options_description log_options("Logging");
    log_options.add_options()
			("log-output", po::value<std::string>(&mode)->default_value("STDOUT"), "[STDOUT|LOCALFILE|SYSLOG]")
			("log-level,v", po::value<unsigned int>(&level)->default_value(AQ_LOG_WARNING), "CRITICAL(2), ERROR(3), WARNING(4), NOTICE(5), INFO(6), DEBUG(7)")
			("log-lock", po::bool_switch(&lock_mode), "for multithread program")
			("log-date", po::bool_switch(&date_mode), "add date to log")
			("log-pid", po::bool_switch(&pid_mode), "add thread id to log")
			("log-ident", po::value<std::string>(&ident)->default_value("aq_query_resolver"), "")
			;

    po::options_description engine("Engine");
    engine.add_options()
      ("settings,s", po::value<std::string>(&propertiesFile), "")
      ("aq-engine,e", po::value<std::string>(&settings.aqEngine))
      ("aq-home,r", po::value<std::string>(&aqHome)->default_value(aqHome), "set AQ Home (AQ_HOME environment variable)")
      ("aq-name,n", po::value<std::string>(&aqName), "")
			("query-ident,i", po::value<std::string>(&queryIdent), "")
      ("queries-file,f", po::value<std::string>(&sqlQueriesFile), "")
			("output,o", po::value<std::string>(&settings.outputFile), "")
			("worker,w", po::value<unsigned int>(&worker), "number of thread assigned to resolve the bunch of sql queries")
			("parralellize,p", po::value<size_t>(&settings.process_thread)->default_value(settings.process_thread), "number of thread assigned resolve one sql queries")
			("display-count", po::bool_switch(&displayCount), "")
      ("force", po::bool_switch(&force), "force use of directory if it already exists")
			("keep-file,k", po::bool_switch(&keepFiles), "")
      ("trace,t", po::bool_switch(&trace), "")
      ;

    po::positional_options_description positionalOptions; 
    positionalOptions.add("aq-name", -1); 

    po::options_description testing("Testing");
    testing.add_options()
      ("simulate-aq-engine,z", po::bool_switch(&simulateAQEngine), "")
			("transform", po::bool_switch(&transform), "")
			("skip-nested-query", po::value<bool>(&settings.skipNestedQuery), "")
			("aq-matrix", po::value<std::string>(&aqMatrixFileName), "")
      ("check-database", po::bool_switch(&checkDatabase), "")
      ;

    po::options_description external("External");
    external.add_options()
      ("use-dll-function", po::value<std::string>(&DLLFunction), "Choise your own .dll to use your function")
      ("use-bin-aq-matrix", po::bool_switch(&useTextAQMatrix), "")
      ;

    po::options_description loader("Loader");
    loader.add_options()
      ("aq-loader,l", po::value<std::string>(&settings.aqLoader))
			("load-db", po::bool_switch(&loadDatabase), "")
      ("load-table", po::value<std::string>(&tableNameToLoad), "")
			;
    
    po::options_description genTmpTable("GenerateTmpTable [TESTING PURPOSE]");
    genTmpTable.add_options()
      ("gen-tmp-table", po::bool_switch(&generateTmpTable), "")
			("nb-values", po::value<unsigned int>(&nbValues), "")
      ("min-value", po::value<unsigned int>(&minValue), "")
      ("max-value", po::value<unsigned int>(&maxValue), "")
      ("nb-tables", po::value<unsigned int>(&nbTables), "")
			;

    all.add(log_options).add(engine).add(testing).add(external).add(loader).add(genTmpTable);

		po::variables_map vm;
		po::store(po::command_line_parser(argc, argv).options(all).positional(positionalOptions).run(), vm);
		po::notify(vm);    

		if (vm.count("help"))
		{
			std::cout << all << "\n";
			return 1;
		}

    // parse positional options
    if (vm.count("aq-name"))
    {
      aqName = vm["aq-name"].as<std::string>();
    }
		
    //
    // settings flags bool
    settings.trace = trace || settings.trace;
    settings.displayCount = displayCount || settings.displayCount;
    settings.cmdLine = _isatty(_fileno(stdin)) != 0;
    
    //
    //
    boost::replace_all(aqHome, "\\", "/");
    boost::replace_all(aqHome, "//", "/");
    if ((!aqHome.empty()) && (*aqHome.rbegin() != '/'))
    {
      aqHome = aqHome + "/";
    }

    //
    //
    if (aqName == "")
    {
      aqName = settings.aqName;
    }
    if ((aqHome != "") && (aqName != ""))
    {
      settings.initPath(aqHome + aqName);
    }

		//
		// Initialize Logger
		aq::Logger::getInstance(ident.c_str(), mode == "STDOUT" ? STDOUT : mode == "LOCALFILE" ? LOCALFILE : mode == "SYSLOG" ? SYSLOG : STDOUT);
		aq::Logger::getInstance().setLevel(level);
		aq::Logger::getInstance().setLockMode(lock_mode);
		aq::Logger::getInstance().setDateMode(date_mode);
		aq::Logger::getInstance().setPidMode(pid_mode);
    
		//
		// print Project Settings
    aq::Logger::getInstance().log(AQ_DEBUG, "Settings:\n%s\n", settings.to_string().c_str());

		//
		// If Load database is invoked
		if (loadDatabase)
		{
      aq::base_t bd;
      if (aq::build_base_from_raw(settings.dbDesc.c_str(), bd) != -1)
      {
        return load_database(settings, bd, tableNameToLoad);
      }
      else
      {
        aq::Logger::getInstance().log(AQ_CRITICAL, "cannot find database desc file '%s'\n", settings.dbDesc.c_str());
        return EXIT_FAILURE;
      }
      assert(false);
		}

    //
    // Check Database
    if (checkDatabase)
    {
      return check_database(settings);
    }

    //
    // If generated temporary table is invoked
    if (generateTmpTable)
    {
      aq::base_t bd;
      if (aq::build_base_from_raw(settings.dbDesc.c_str(), bd) != -1)
      {
        int rc = 0;
        while ((nbTables-- > 0) && ((rc = generate_tmp_table(settings, bd, nbValues, minValue, maxValue)) == 0));
        return rc;
      }
      else
      {
        aq::Logger::getInstance().log(AQ_CRITICAL, "cannot find database desc file '%s'\n", settings.dbDesc.c_str());
        return EXIT_FAILURE;
      }
    }

    //
    // Solve Queries
    aq::Base bd(settings.dbDesc);
    return parse_queries(
      aqHome, aqName, queryIdent, sqlQueriesFile, aqMatrixFileName, 
      settings, bd,
      transform, simulateAQEngine, keepFiles, force);

  }
	catch (const aq::generic_error& error)
	{
    aq::Logger::getInstance().log(AQ_CRITICAL, error.what());
		std::cerr << "generic error: " << error.what() << std::endl;
		return error.getType();
	}
	catch (const std::exception& ex)
	{
		std::cerr << "standard exception" << ex.what() << std::endl;
		return EXIT_FAILURE;
	}
	catch (...)
	{
		std::cerr << "UNHANDLE EXCEPTION" << std::endl;
		return EXIT_FAILURE;
	}

  if (failedQueries) return EXIT_FAILURE;
	return EXIT_SUCCESS;
}