Beispiel #1
0
  std::vector<std::string> process()
  {
    std::srand(std::time(0));

    std::vector<CallbackData> dbs;
    std::vector<std::string> tortured_databases;

    dbs.emplace_back(CallbackData(tortured_databases, open_database("test1.db")));
    dbs.emplace_back(CallbackData(tortured_databases, open_database("test2.db")));
    dbs.emplace_back(CallbackData(tortured_databases, open_database("test3.db")));
    dbs.emplace_back(CallbackData(tortured_databases, open_database("test4.db")));
    dbs.emplace_back(CallbackData(tortured_databases, open_database("test5.db")));

    for (size_t i = 0; i<dbs.size(); ++i) {
      sqlite3_trace(dbs[i].db_, trace_callback, &dbs[i]);
    }

    for (size_t i = 0; i<dbs.size(); ++i) {
      torture_database(dbs[std::rand() % dbs.size()].db_);  
    }

    for (size_t i = 0; i<dbs.size(); ++i) {
      sqlite3_close(dbs[i].db_);
    }
    return tortured_databases;
  }
Beispiel #2
0
int run(void)
{
  dbi_conn conn;

  if (!cache) {
    cache = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_probe);
  }
  
  LOG(LOG_INFO, "reading info from database"); 
  uw_setproctitle("reading info from database");
  conn = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_ARG(DBPORT), OPT_ARG(DBNAME), 
			OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
  if (conn) {
    refresh_database(conn);
    close_database(conn);
  }

  if (g_hash_table_size(cache) > 0) {
    LOG(LOG_INFO, "running %d probes", g_hash_table_size(cache));
    uw_setproctitle("running %d probes", g_hash_table_size(cache));
    run_actual_probes(); /* this runs the actual probes */

    LOG(LOG_INFO, "writing results"); 
    uw_setproctitle("writing results");
    write_results();
  }

  return(g_hash_table_size(cache));
}
int main(int argc, char *argv[])
{
    int opt = 0;
    int all = 0;
    unsigned int lb = 2, rb = -1;
	while ((opt = getopt_long(argc, argv, "al:r:", NULL, NULL))
			!= -1) {
		switch (opt) {
            case 'a':
                /* all distances */
                all = 1;
                break;
            case 'l':
                lb = atoi(optarg);
                break;
            case 'r':
                rb = atoi(optarg);
                break;
            default:
                return -1;
        }
    }

    assert(lb >= 2);
    open_database();

    if(all == 1)
        distance_between_all_chunk_references(lb, rb);
    else
        distance_between_first_two_chunk_references(lb, rb);

    close_database();

    return 0;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
    int opt = 0;
    unsigned int lb = 1, rb =-1;
    int distribution = 0;
	while ((opt = getopt_long(argc, argv, "l:r:d", NULL, NULL))
			!= -1) {
		switch (opt) {
            case 'l':
                lb = atoi(optarg);
                break;
            case 'r':
                rb = atoi(optarg);
                break;
            case 'd':
                distribution = 1;
                break;
            default:
                return -1;
        }
    }

    open_database();

    if(distribution)
        get_chunksize_distribution(lb, rb);
    else
        avg_chunksize();

    close_database();

    return 0;
}
Beispiel #5
0
int run(void)
{
  database *db;

  if (!cache) {
    cache = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, free_probe);
  }
  
  LOG(LOG_INFO, "reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID); 
  uw_setproctitle("reading info from database (group %u)", (unsigned)OPT_VALUE_GROUPID);
  db = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_VALUE_DBPORT, OPT_ARG(DBNAME), 
			OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
  if (db) {
    refresh_database(db);
    close_database(db);
  }

  if (g_hash_table_size(cache) > 0) {
    LOG(LOG_INFO, "running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID);
    uw_setproctitle("running %d probes from group %u", g_hash_table_size(cache), (unsigned)OPT_VALUE_GROUPID);
    run_actual_probes(); /* this runs the actual probes */

    LOG(LOG_INFO, "writing results"); 
    uw_setproctitle("writing results");
    write_results();
  }

  return(g_hash_table_size(cache));
}
DB_TEST_BASE::DB_TEST_BASE() : DateFormat("yyyy-MM-dd"), DateTimeFormat("yyyy-MM-dd hh:mm:ss"), TimeFormat("hh:mm:ss")
{
    database_name = QString("drc_db.db3");
    open_database();

    AllocateTableNames();

    AllocateTableColumns();

    AllocateVectorValues();

    //Write method that accepts vector, and inserts into DB Object
    FullPerson = InitializePersonObject(full_person_values);
    EmptyPerson = InitializePersonObject(empty_person_values);

    EmptyProcess = InitializeProcessObject(empty_process_values);
    FullProcess = InitializeProcessObject(full_process_values);

    EmptySession = InitializeSessionObject(empty_session_values);
    FullSession = InitializeSessionObject(full_session_values);

    EmptyParty = InitializeClientObject(EmptyPerson);
    FullParty = InitializeClientObject(FullPerson);

    EmptyClientSession = InitializeClientSessionObject(empty_client_session_values);
    FullClientSession = InitializeClientSessionObject(full_client_session_values);

    EmptyNote = InitializeNoteObject(empty_note_values);
    FullNote = InitializeNoteObject(full_note_values);

    EmptyEvaluation = InitializeEvaluationObject(empty_evaluation_values);
}
int main(int argc, char** argv) {
  u32 seed;
  struct timeval tv;
  signal(SIGINT, ctrlc_handler);
  signal(SIGPIPE, SIG_IGN);
  SSL_library_init();

  gettimeofday(&tv, NULL);
  seed = tv.tv_usec ^ (tv.tv_sec << 16) ^ getpid();

  srandom(seed);

  if (resp_tmout < rw_tmout) 
    resp_tmout = rw_tmout;

  if (max_connections < max_conn_host)
    max_connections = max_conn_host;
  open_database();
  setup_bayes();
  parse_opts(argc, argv);
  fflush(0);

  EVP_cleanup();
  CRYPTO_cleanup_all_ex_data();

  return 0;

}
Beispiel #8
0
static int 
check_passwd(const char * user, const char *pass)
{
	sqlite3_stmt *res;
	const char *tail;
	const char *tmp_pass;
	int ret = CMD_NOT_AUTHORIZED;
	char *sql;
	sql = "SELECT * FROM USERS WHERE NICK LIKE ?";


	passwd_db = open_database();

	CALL_SQLITE (prepare_v2(passwd_db, sql, strlen (sql),
		&res, &tail));

	CALL_SQLITE (bind_text(res, 1, user, strlen (user), 0));

	while (sqlite3_step(res) == SQLITE_ROW) {
		tmp_pass = (const char *) sqlite3_column_text(res, 1);
		if (strcmp(tmp_pass,pass) == 0) {
			log_debug("USER: (%s) is authenticated",user);
			ret = CMD_AUTHORIZED;
		}
	}

	sqlite3_reset(res);

	log_debug("auth_code_resp(%d) \n", ret);
	return (ret);
}
Beispiel #9
0
int
example_main(int argc, char **argv)
{
    /* Create a database with the current schema definition */
    db_t hdb = create_database( EXAMPLE_DATABASE, &v2_schema, init_data_cb );

    /* Create database with v1 schema */
    db_t hdb_upgrade = create_database( EXAMPLE_UPGRADE_DATABASE, &v1_schema, init_data_cb );

    /* Open database with v1 schema and upgrade to current schema */
    db_shutdown( hdb_upgrade, 0, NULL );
    hdb = open_database( EXAMPLE_UPGRADE_DATABASE, &v2_schema, &upgrade_schema_cb );

    if( hdb != NULL ) {
        int v = get_schema_version( hdb_upgrade );
        db_shutdown( hdb_upgrade, 0, NULL );
        db_shutdown( hdb, 0, NULL );
        if (v == v2_schema.version) {
            return EXIT_SUCCESS;
        }
    }
    db_shutdown( hdb_upgrade, 0, NULL );
    db_shutdown( hdb, 0, NULL );
    return EXIT_FAILURE;
}
Beispiel #10
0
int
main(int argc, char **argv)
{
    int fd, database_fd, database_size;
    krb5_error_code retval;
    krb5_context context;
    krb5_creds *my_creds;
    krb5_auth_context auth_context;

    setlocale(LC_ALL, "");
    retval = krb5_init_context(&context);
    if (retval) {
        com_err(argv[0], retval, _("while initializing krb5"));
        exit(1);
    }
    parse_args(argc, argv);
    get_tickets(context);

    database_fd = open_database(context, file, &database_size);
    open_connection(context, slave_host, &fd);
    kerberos_authenticate(context, &auth_context, fd, my_principal, &my_creds);
    xmit_database(context, auth_context, my_creds, fd, database_fd,
                  database_size);
    update_last_prop_file(slave_host, file);
    printf(_("Database propagation to %s: SUCCEEDED\n"), slave_host);
    krb5_free_cred_contents(context, my_creds);
    close_database(context, database_fd);
    exit(0);
}
Beispiel #11
0
int main(int argc, char *argv[])
{
	if(open_database())
		create_medialib();
	else {
		g_print("错误:无法打开数据库。");
		return 1;
	}
	link_t mlink = {NULL, 0};
	link_t plink = {NULL, 0};
	load_medialib(&mlink, 0);
	
	main_core(GENERAL_MEDIALIB_INIT, &mlink);
	main_core(GENERAL_PLAYLIST_INIT, &plink);

	gtk_init(&argc, &argv);
	InterFace ui;
	ui.winMain = create_winMain(&ui);
	ui.diaMedialib = create_diaMedialib(&ui);
	ui.diaPlaylist = create_diaPlaylist(&ui);
	ui.diaVolume = create_diaVolume(&ui);
	gtk_widget_show(ui.winMain);
	g_signal_connect(G_OBJECT(ui.winMain), "delete_event",
			G_CALLBACK(gtk_main_quit), NULL);
	gtk_main();

	link_del_all(&mlink);
	link_del_all(&plink);
	close_database();
	return 0;
}
Beispiel #12
0
static int uw_password_ok(char *user, char *passwd) 
{
  MYSQL_RES *result;

  if (open_database() == 0) {
    gchar buffer[256];
    MYSQL_ROW row;

    sprintf(buffer, "select id from contact where username = '******' and password = '******'", user, passwd);
    if (mysql_query(mysql, buffer)) {
      close_database();
      LOG(LOG_ERR, "buffer: %s", mysql_error(mysql));
      return(FALSE);
    }
    result = mysql_store_result(mysql);
    if (!result) {
      close_database();
      if (debug) LOG(LOG_DEBUG, "user %s, pwd %s not found", user, passwd);
      return(FALSE);
    }
    if ((row = mysql_fetch_row(result))) {
      int id;

      id = atoi(row[0]);
      if (debug) LOG(LOG_DEBUG, "user %s, pwd %s resulted in id %d", user, passwd, id);
      printf("\n");
    }
    mysql_free_result(result);
    close_database();
  }
  return(TRUE);
}
Beispiel #13
0
int main(int argc, char *argv[])
{
    int opt = 0;
    unsigned int lb = 2, rb =-1;
    int task = 0;
	while ((opt = getopt_long(argc, argv, "l:r:t", NULL, NULL))
			!= -1) {
		switch (opt) {
            case 'l':
                lb = atoi(optarg);
                break;
            case 'r':
                rb = atoi(optarg);
                break;
            case 't':
                task = 1;
                break;
            default:
                return -1;
        }
    }

    /* makes no sense to analyze reference number 1 */
    assert(lb > 1);
    open_database();

    if(task == 1)
        get_file2ref_ratio(lb, rb);
    else
        analyze_references_source(lb, rb);

    close_database();

    return 0;
}
Beispiel #14
0
int find_expired_probes(struct dbspec *dbspec)
{
  xmlDocPtr doc;
  xmlNodePtr probe;
  dbi_result result;
  dbi_conn conn;
  int count = 0;
  char buf[10];

  sprintf(buf, "%d", dbspec->port);

  conn = open_database(OPT_ARG(DBTYPE), dbspec->host, buf, dbspec->db,
                     dbspec->user, dbspec->password);
  if (!conn) return 0;

  doc = UpwatchXmlDoc("result", NULL);

  // find all expired probes, but skip those for which processing
  // has been stopped for some reason
  result = db_query(conn, 0, "select probe.name, pr_status.probe, " 
                             "       pr_status.server, pr_status.color, "
                             "       pr_status.expires "
                             "from   pr_status, probe "
                             "where  probe.id = pr_status.class and color <> 400 "
                             "       and expires < UNIX_TIMESTAMP()-30 "
                             "       and expires < probe.lastseen"
                             "       and probe.expiry = 'yes'");
  if (!result) goto errexit;

  while (dbi_result_next_row(result)) {
    char buffer[256];
    time_t now = time(NULL);

    probe = xmlNewChild(xmlDocGetRootElement(doc), NULL, dbi_result_get_string(result, "name"), NULL);
    xmlSetProp(probe, "realm", dbspec->realm);
    xmlSetProp(probe, "id", dbi_result_get_string(result, "probe"));
    xmlSetProp(probe, "server", dbi_result_get_string(result, "server"));
    sprintf(buffer, "%u", (int) now);	xmlSetProp(probe, "date", buffer);
    xmlSetProp(probe, "expires", dbi_result_get_string(result, "expires"));

    xmlNewChild(probe, NULL, "color", "400");  // PURPLE
    xmlNewChild(probe, NULL, "prevcolor", dbi_result_get_string(result, "color"));

    LOG(LOG_INFO, "%s: purpled %s %d", dbspec->realm, dbi_result_get_string(result, "name"), 
                                                      dbi_result_get_uint(result, "probe"));
    count++;
  }
  if (count) {
    xmlSetDocCompressMode(doc, OPT_VALUE_COMPRESS);
    spool_result(OPT_ARG(SPOOLDIR), OPT_ARG(OUTPUT), doc, NULL);
    LOG(LOG_INFO, "%s: purpled %u probes", dbspec->realm, count);
  }

errexit:
  if (result) dbi_result_free(result);
  if (conn) close_database(conn);
  if (doc) xmlFreeDoc(doc);
  return count;
}
Beispiel #15
0
void MainWindow::setup_database()
{
    //setup database
    QSettings settings;
    if(!settings.contains("database file name"))
        settings.setValue("database file name", db_location);
    QFileInfo dbpath(settings.value("database file name").toString());
    open_database(dbpath);
}
Beispiel #16
0
/**
* Start logging
*
* @param sqlite3 db
*
* @return int
*/
int activate_log(sqlite3* db)
{
	remove("log.db");

	if (open_database(db)) {
		if (create_table(db)) {
			enableLog = 1;
			return 1;
		}
	}
}
int main() {

  open_database("database.dat");
  int nums = 0;
  char** a = lookup_songs(&nums);
  for(int i = 0; i < nums; i++) {
     printf("%s\n", a[i]);
  }
 

  return 0;
}
Beispiel #18
0
/**
 * Inits the main structure.
 * @note With sqlite version > 3.7.7 we should use URI filename.
 * @param opt : a filled options_t * structure that contains all options
 *        by default, read into the file or selected in the command line.
 * @returns a main_struct_t * pointer to the main structure
 */
static main_struct_t *init_main_structure(options_t *opt)
{
    main_struct_t *main_struct = NULL;
    gchar *db_uri = NULL;
    gchar *conn = NULL;

    if (opt != NULL)
    {

        print_debug(_("Please wait while initializing main structure...\n"));

        main_struct = (main_struct_t *) g_malloc0(sizeof(main_struct_t));

        create_directory(opt->dircache);
        db_uri = g_build_filename(opt->dircache, opt->dbname , NULL);
        main_struct->database = open_database(db_uri);
        db_uri = free_variable(db_uri);

        main_struct->opt = opt;
        main_struct->hostname = g_get_host_name();

        if (opt != NULL && opt->ip != NULL)
        {
            conn = make_connexion_string(opt->ip, opt->port);
            main_struct->comm = init_comm_struct(conn);
            main_struct->reconnected = init_comm_struct(conn);
            free_variable(conn);
        }
        else
        {
            /* This should never happen because we have default values */
            main_struct->comm = NULL;
        }

        main_struct->signal_fd = start_signals();
        main_struct->fanotify_fd = start_fanotify(opt);

        /* inits the queue that will wait for events on files */
        main_struct->save_queue = g_async_queue_new();
        main_struct->dir_queue = g_async_queue_new();
        main_struct->regex_exclude_list = make_regex_exclude_list(opt->exclude_list);

        /* Thread initialization */
        main_struct->save_one_file = g_thread_new("save_one_file", save_one_file_threaded, main_struct);
        main_struct->carve_all_directories = g_thread_new("carve_all_directories", carve_all_directories, main_struct);
        main_struct->reconn_thread = g_thread_new("reconnected", reconnected, main_struct);

        print_debug(_("Main structure initialized !\n"));

    }

    return main_struct;
}
Beispiel #19
0
void find(const bfs::path& cdb_path, const options& opt)
{
    config cfg = load_config(cdb_path / "config");

    const bfs::path cdb_root = cdb_path.parent_path();
    const bfs::path search_root = bfs::initial_path();

    std::size_t prefix_size = 0;
    std::string file_match;
    if(opt.m_options.count("-a") == 0 && search_root != cdb_root)
    {
        file_match = "^" + escape_regex(
            search_root.generic_string().substr(cdb_root.string().size() + 1) + "/") + ".*";
        prefix_size = search_root.string().size() - cdb_root.string().size();
    }

    file_lock lock(cdb_path / "lock");
    lock.lock_sharable();

    const char* find_regex_options =
        opt.m_options.count("-i") ? "i" : "";
    const char* file_regex_options =
        cfg.get_value("nocase-file-match") == "on" ? "i" : "";

    bool trim = cfg.get_value("find-trim-ws") == "on";
    unsigned thread_count = get_thread_count(cfg);
    unsigned buffer_count = get_buffer_count(thread_count);

    for(unsigned i = 0; i != opt.m_args.size(); ++i)
    {
        database_ptr db = open_database(cdb_path / "db");

        std::string pattern = opt.m_args[i];
        if(opt.m_options.count("-v"))
            pattern = escape_regex(pattern);

        mt_search mts(*db, trim, prefix_size, buffer_count);

        auto worker = [&]
        {
            mts.search_db(compile_regex(pattern, 0, find_regex_options),
                          compile_regex(file_match, 0, file_regex_options));
        };

        boost::thread_group workers;
        for(unsigned i = 0; i != thread_count-1; ++i)
            workers.create_thread(worker);

        worker();

        workers.join_all();
    }
}
Beispiel #20
0
static VALUE t_use(VALUE self, VALUE dbname)
{
    char *name;
	
	if (TYPE(dbname) != T_STRING){
		rb_raise(rb_eArgError, 
				 "ArgError: need a String, %s given", 
				 rb_obj_classname(dbname));
	}
    name = StringValueCStr(dbname);
    return INT2NUM(open_database(name));
}
Beispiel #21
0
int main(int argc, char *argv[])
{
	/* dedup? */
	int dedup = 0;
	/* weighted by file/chunk size? */
	int weighted = 0;
	/* chunk level or file level */
	int file_level = 0;

	char *pophash = NULL;

	int opt = 0;
	while ((opt = getopt_long(argc, argv, "fwdp:", NULL, NULL))
			!= -1) {
		switch (opt) {
			case'f':
				file_level = 1;
				break;
			case 'd':
				dedup = 1;
				break;
			case 'w':
				weighted = 1;
				break;
			case 'p':
				pophash = optarg;
				break;
			default:
				fprintf(stderr, "invalid option\n");
				return -1;
		}
	}

	open_database();

	if (!file_level) {
		if (!dedup)
			chunk_nodedup_simd_trace(&argv[optind], argc - optind,  weighted);
		else
			chunk_dedup_simd_trace(&argv[optind], argc - optind, weighted, pophash);
	} else {
		if (!dedup)
			file_nodedup_simd_trace(&argv[optind], argc - optind, weighted);
		else
			file_dedup_simd_trace(&argv[optind], argc - optind, weighted, pophash);
	}
	close_database();

	return 0;
}
Beispiel #22
0
/*==================================================
 * open_or_create_database -- open database, prompt for
 *  creating new one if it doesn't exist
 * if fails, displays error (show_open_error) and returns 
 *  FALSE
 *  alteration:   [IN]  flags for locking, forcing open...
 *  dbused:       [I/O] actual database path (may be relative)
 * If this routine creates new database, it will alter dbused
 * Created: 2001/04/29, Perry Rapp
 *================================================*/
BOOLEAN
open_or_create_database (INT alteration, STRING *dbused)
{
	INT lldberrnum=0;
	/* Open Database */
	if (open_database(alteration, *dbused, &lldberrnum))
		return TRUE;

	/* filter out real errors */
	if (lldberrnum != BTERR_NODB && lldberrnum != BTERR_NOKEY)
	{
		show_open_error(lldberrnum);
		return FALSE;
	}

	if (readonly || immutable || alteration)
	{
		llwprintf(_("Cannot create new database with -r, -i, -l, or -f flags."));
		return FALSE;
	}
	/*
	error was only that db doesn't exist, so lets try
	making a new one 
	If no database directory specified, add prefix llnewdbdir
	*/
	if (is_unadorned_directory(*dbused)) {
		STRING dbpath = getlloptstr("LLDATABASES", ".");
		CNSTRING newdbdir = get_first_path_entry(dbpath);
		STRING temp = *dbused;
		if (newdbdir) {
			char tempth[MAXPATHLEN];
			newdbdir = strdup(newdbdir);
			concat_path(newdbdir, *dbused, uu8, tempth, sizeof(tempth));
			*dbused = strsave(tempth);
			stdfree(temp);
			stdfree((STRING)newdbdir);
		}
	}

	/* Is user willing to make a new db ? */
	if (!ask_yes_or_no_msg(_(qSnodbse), _(qScrdbse))) 
		return FALSE;

	/* try to make a new db */
	if (create_database(*dbused, &lldberrnum))
		return TRUE;

	show_open_error(lldberrnum);
	return FALSE;
}
void result_obtainer::Get_Result()
{
    map_table *map_ptr = &Result_list;
    open_database();
    const char* sql = pre_sql.c_str();
    /* Execute SQL statement */
    rc = sqlite3_exec(db, sql, callback, (void*)map_ptr, &zErrMsg);
    if( rc != SQLITE_OK ){
        cout << sql << endl;
        fprintf(stderr, "SQL error: %s\n", zErrMsg);
        sqlite3_free(zErrMsg);
    }
    close_database();
}
Beispiel #24
0
static int
open_env(struct databases *db, int which)
{
	int e;

	memset(db, 0, sizeof(struct databases));
	e = db_env_create(&db->env, 0);
	if (e) {
		log_error("Cannot create database environment, %s\n", db_strerror(e));
		db->env = NULL;
		return -1;
	}
	e = db->env->open(db->env,
		cfg_data_dir,
		DB_INIT_LOCK |DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_TXN | DB_CREATE,
		0
	);
	if (e) {
		log_error("Cannot open database environment, %s\n", db_strerror(e));
		return -2;
	}

	if (which & MODEL_DB) {
		if (open_database(db->env, &db->model, "model.db")) return -3;
	}
	if (which & APP_DB) {
		if (open_database(db->env, &db->app, "app.db")) return -4;
	}
	if (which & CODE_DB) {
		if (open_database(db->env, &db->code, "code.db")) return -5;
	}
	if (which & PROFILE_DB) {
		if (open_database(db->env, &db->profile, "profile.db")) return -6;
	}

	return 0;
}
string Database::getInitDate()
{
    string re;
    open_database();
    string pre_sql = "SELECT DATE FROM DATE_TIME WHERE ID = 2;";
    const char* sql = pre_sql.c_str();

    sqlite3_stmt *pstmt;
    sqlite3_prepare(db, sql, (int)strlen(sql), &pstmt, NULL);
    sqlite3_step(pstmt);
    re = (const char*)sqlite3_column_text(pstmt, 0);
    sqlite3_finalize(pstmt);
    sqlite3_close(db);
    return re;
}
bool Database::exist_in_db(const string &name, const string &title, const string &table)
{
    open_database();
    string pre_sql = "SELECT COUNT(*) FROM " + table + " WHERE " + title + " = '" + name + "';";
    const char* sql = pre_sql.c_str();
    sqlite3_stmt *pstmt;
    sqlite3_prepare(db, sql, (int)strlen(sql), &pstmt, NULL);
    sqlite3_step(pstmt);
    int count = sqlite3_column_int(pstmt,0);
    sqlite3_finalize(pstmt);
    sqlite3_close(db);
    if(count > 0)
        return true;
    return false;
}
Beispiel #27
0
EAPI int
elm_main(int argc, char **argv)
{
    //const char *theme;

    //int ret;

    //get users home dir
    const char *name = "HOME";
    sprintf(home_dir, "%s", getenv(name));

    //adjust finger size
    elm_config_finger_size_set(55);

    //paroli theme fix - not required anymore
    //theme = "tasks";
    //elm_theme_overlay_add(theme);

    //set up win
    win = elm_win_add(NULL, "tasks", ELM_WIN_BASIC);
    elm_win_title_set(win, "Tasks");
    evas_object_smart_callback_add(win, "delete,request", my_win_del, NULL);

    //open database
    open_database();

    // show the window
    create_gui(win);
    evas_object_show(win);

    //restore state
    restore_state();

    occupy_cpu();

    elm_run();
    //clean up stuff
    //clean_up();
    ecore_main_loop_quit();
    elm_shutdown();

    return 0;
}
Beispiel #28
0
int main(int argc, char *argv[])
{
    int opt = 0;
    int flag = FLAG_IDENTICAL_FILES;
    while ((opt = getopt_long(argc, argv, "isdr", NULL, NULL))
            != -1) {
        switch (opt) {
            case 'i':
                flag = FLAG_IDENTICAL_FILES;
                break;
            case 's':
                flag = FLAG_SIMILAR_FILES;
                break;
            case 'd':
                flag = FLAG_DISTINCT_FILES;
                break;
            case 'r':
                flag = FLAG_INTRA_REDUNDANT_FILES;
                break;
            default:
                return -1;
        }
    }

    open_database();

    if(flag == FLAG_IDENTICAL_FILES)
        collect_identical_files();
    else if(flag == FLAG_SIMILAR_FILES)
        collect_similar_files();
    else if(flag == FLAG_DISTINCT_FILES)
        collect_distinct_files();
    else if(flag == FLAG_INTRA_REDUNDANT_FILES)
        collect_intra_redundant_files();

    close_database();

    return 0;
}
Beispiel #29
0
//************************************************************************
// read pr_status file for expired probes. Construct fake results
// for those.
//***********************************************************************
int run(void)
{
  dbi_result result;
  dbi_conn conn;
  int count = 0;

  conn = open_database(OPT_ARG(DBTYPE), OPT_ARG(DBHOST), OPT_ARG(DBPORT), OPT_ARG(DBNAME),
                        OPT_ARG(DBUSER), OPT_ARG(DBPASSWD));
  if (!conn) return 0;

  LOG(LOG_INFO, "processing ..");
  uw_setproctitle("reading info from database");
  result = db_query(conn, 0, "select pr_realm.id, pr_realm.name, pr_realm.host, "
                              "       pr_realm.port, pr_realm.db, pr_realm.user, "
                              "       pr_realm.password "
                              "from   pr_realm "
                              "where  pr_realm.id > 1");
  if (result) {
    while (dbi_result_next_row(result)) {
      struct dbspec db;

      db.domid = dbi_result_get_uint(result, "id");
      db.realm = dbi_result_get_string(result, "name");
      db.host = dbi_result_get_string(result, "host");
      db.port = dbi_result_get_uint(result, "port");
      db.db = dbi_result_get_string(result, "db");
      db.user = dbi_result_get_string(result, "user");
      db.password = dbi_result_get_string(result, "password");
      uw_setproctitle("checking %s", dbi_result_get_string(result, "name"));
      LOG(LOG_DEBUG, "checking %s", dbi_result_get_string(result, "name"));
      count += find_expired_probes(&db);
    }
    dbi_result_free(result);
  }
  close_database(conn);
  LOG(LOG_INFO, "sleeping");
  return count;
}
Beispiel #30
0
main()
{
  printf("hello\n");
  char* ptr = malloc(5);
  convertLengthTo2Bytes(ptr, 5);

  printf("%d\n", ptr[1]);

  
  open_database("compare.dat");
  char* in =  "Name913221111111111111222222222222222222221222111111111111122222222222222222222N12221111111111111222222222222222222222222222222222226Name412221111111111111222222222222222222221222111111111111122222222222222222222N12221111111111111222222222222222222222222222222222221Name112221111111111111222222222222222222221222111111111111122222222222222222222N12221111111111111222222222222222222222222222222222226";
  char* coma = compareSongsToClient(in, 2);
  char* comb = compareSongsToServer(in, 2);

  int lena = getLength(coma);
  coma += 2;
  for(int i = 0; i < lena; i++)
  {
    printf("song %s\n", coma);
    coma += SONG_LENGTH;
    printf("sha %s\n", coma);
    coma += SHA_LENGTH;
  }
  //printf("a: %s\n", coma);

  int lenb = getLength(comb);
  comb += 2;
  printf("\nnext\n");
  for(int i = 0; i < lenb; i++)
  {
    printf("song %s\n", comb);
    comb += SONG_LENGTH;
    printf("sha %s\n", comb);
    comb += SHA_LENGTH;
  }
  close_database();
}