コード例 #1
0
ファイル: channel.c プロジェクト: xdgimf/Renewal
/**
 * Unbans a character from the given channel.
 *
 * @param chan The channel.
 * @param ssd  The source character, if any.
 * @param tsd  The target character. If no target character is specified, all characters are unbanned.
 * @retval HCS_STATUS_OK if the operation succeeded.
 * @retval HCS_STATUS_ALREADY if the target character is not banned.
 * @retval HCS_STATUS_NOPERM if the source character doesn't have enough permissions.
 * @retval HCS_STATUS_FAIL in case of generic failure.
 */
enum channel_operation_status channel_unban(struct channel_data *chan, const struct map_session_data *ssd, struct map_session_data *tsd)
{
	nullpo_retr(HCS_STATUS_FAIL, chan);

	if (ssd && chan->owner != ssd->status.char_id && !pc_has_permission(ssd, PC_PERM_HCHSYS_ADMIN))
		return HCS_STATUS_NOPERM;

	if (!chan->banned)
		return HCS_STATUS_ALREADY;

	if (!tsd) {
		// Unban all
		db_destroy(chan->banned);
		chan->banned = NULL;
		return HCS_STATUS_OK;
	}

	// Unban one
	if (!idb_exists(chan->banned, tsd->status.account_id))
		return HCS_STATUS_ALREADY;

	idb_remove(chan->banned, tsd->status.account_id);
	if (!db_size(chan->banned)) {
		db_destroy(chan->banned);
		chan->banned = NULL;
	}

	return HCS_STATUS_OK;
}
コード例 #2
0
ファイル: channel.c プロジェクト: xdgimf/Renewal
/**
 * Deletes a chat channel.
 *
 * @param chan The channel to delete
 */
void channel_delete(struct channel_data *chan)
{
	nullpo_retv(chan);

	if (db_size(chan->users) && !channel->config->closing) {
		struct map_session_data *sd;
		struct DBIterator *iter = db_iterator(chan->users);
		for (sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter)) {
			channel->leave_sub(chan, sd);
		}
		dbi_destroy(iter);
	}
	if (chan->banned) {
		db_destroy(chan->banned);
		chan->banned = NULL;
	}
	db_destroy(chan->users);
	if (chan->m) {
		map->list[chan->m].channel = NULL;
		aFree(chan);
	} else if (chan->type == HCS_TYPE_ALLY) {
		aFree(chan);
	} else if (!channel->config->closing) {
		strdb_remove(channel->db, chan->name);
	}
}
コード例 #3
0
ファイル: mapreg.c プロジェクト: Chocolate31/eamod
void mapreg_final(void)
{
	if( mapreg_dirty )
		script_save_mapreg();

	db_destroy(mapreg_db);
	db_destroy(mapregstr_db);
}
コード例 #4
0
ファイル: pc_groups.c プロジェクト: AsaK/rathena
/**
 * Finalize PC Groups: free DBMaps and config.
 * @public
 */
void do_final_pc_groups(void)
{
	if (pc_group_db != NULL)
		db_destroy(pc_group_db);
	if (pc_groupname_db != NULL )
		db_destroy(pc_groupname_db);
	destroy_config();
}
コード例 #5
0
int main(void) {
	struct db_context *ctx=db_prop_new(PROTO_ISAKMP, 0, 0);
	db_trans_add(ctx, KEY_IKE);
	db_attr_add_values(ctx, OAKLEY_ENCRYPTION_ALGORITHM, OAKLEY_DES_CBC);
	db_attr_add_values(ctx, OAKLEY_HASH_ALGORITHM, OAKLEY_MD5);
	db_attr_add_values(ctx, OAKLEY_AUTHENTICATION_METHOD, OAKLEY_RSA_SIG);
	db_attr_add_values(ctx, OAKLEY_GROUP_DESCRIPTION, OAKLEY_GROUP_MODP1024);
	db_trans_add(ctx, KEY_IKE);
	db_attr_add_values(ctx, OAKLEY_ENCRYPTION_ALGORITHM, OAKLEY_3DES_CBC);
	db_attr_add_values(ctx, OAKLEY_HASH_ALGORITHM, OAKLEY_MD5);
	db_attr_add_values(ctx, OAKLEY_AUTHENTICATION_METHOD, OAKLEY_RSA_SIG);
	db_attr_add_values(ctx, OAKLEY_GROUP_DESCRIPTION, OAKLEY_GROUP_MODP1024);
	db_trans_add(ctx, KEY_IKE);
	db_attr_add_values(ctx, OAKLEY_ENCRYPTION_ALGORITHM, OAKLEY_AES_CBC);
	db_attr_add_values(ctx, OAKLEY_HASH_ALGORITHM, OAKLEY_MD5);
	db_attr_add_values(ctx, OAKLEY_AUTHENTICATION_METHOD, OAKLEY_PRESHARED_KEY);
	db_attr_add_values(ctx, OAKLEY_GROUP_DESCRIPTION, OAKLEY_GROUP_MODP1536);	
	db_trans_add(ctx, ESP_3DES);
	db_attr_add_values(ctx, AUTH_ALGORITHM, AUTH_ALGORITHM_HMAC_SHA1);
	db_trans_add(ctx, ESP_DES);
	db_attr_add_values(ctx, AUTH_ALGORITHM, AUTH_ALGORITHM_HMAC_SHA1);
	db_print(ctx);
	db_destroy(ctx);
	return 0;
}
コード例 #6
0
ファイル: channel.c プロジェクト: Chocolate31/eamod
static int channel_db_final(DBKey key, DBData *data, va_list ap)
{
	struct channel_data *cd = (struct channel_data *)db_data2ptr(data);
	ShowInfo("Channel System : Removing Channel %s from memory.\n", cd->name);
	db_destroy(cd->users_db);
	return 0;
}
コード例 #7
0
ファイル: db.c プロジェクト: DhruvRelwani/GamesmanClassic
/*
** function code
*/
void db_create() {

	/*if there is an old database table, get rid of it*/
	db_destroy();

	/* get a new table */
	db_functions = (DB_Table *) SafeMalloc(sizeof(DB_Table));

	/*set all function pointers to NULL, and each database can choose*/
	/*whatever ones they wanna implement and associate them*/

	db_functions->get_value = db_get_value;
	db_functions->put_value = db_put_value;
	db_functions->get_remoteness = db_get_remoteness;
	db_functions->put_remoteness = db_put_remoteness;
	db_functions->check_visited = db_check_visited;
	db_functions->mark_visited = db_mark_visited;
	db_functions->unmark_visited = db_unmark_visited;
	db_functions->get_mex = db_get_mex;
	db_functions->put_mex = db_put_mex;
	db_functions->get_winby = db_get_winby;
	db_functions->put_winby = db_put_winby;
	db_functions->save_database = db_save_database;
	db_functions->load_database = db_load_database;
	db_functions->free_db = db_free;
	db_functions->get_bulk = db_get_bulk;
}
コード例 #8
0
ファイル: pc_groups.c プロジェクト: Abunay01/Cronus
/**
 * Finalize PC Groups: free DBMaps and config.
 * @public
 */
void do_final_pc_groups(void)
{
	if (pc_group_db != NULL)
		pc_group_db->destroy(pc_group_db, group_db_clear_sub);
	if (pc_groupname_db != NULL)
		db_destroy(pc_groupname_db);
}
コード例 #9
0
ファイル: channel.c プロジェクト: Chocolate31/eamod
void channel_close(struct channel_data *cd)
{
	int j;
	char output[128];
	struct map_session_data *pl_sd;
	DBIterator* iter;

	if( cd == NULL || cd->type != CHN_USER )
		return;
	
	sprintf(output, msg_txt(804), cd->name);
	clif_channel_message(cd, output, -1);

	iter = db_iterator(cd->users_db);
	for( pl_sd = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); pl_sd = (struct map_session_data *)dbi_next(iter) )
	{
		idb_remove(cd->users_db, pl_sd->bl.id);
		ARR_FIND(0, MAX_USER_CHANNELS, j, pl_sd->cd[j] == cd);
		if( j == MAX_USER_CHANNELS )
			continue;
		
		pl_sd->cd[j] = NULL;
	}
	dbi_destroy(iter);
	
	db_destroy(cd->users_db);
	strdb_remove(channel_db, cd->name);
}
コード例 #10
0
ファイル: login-converter.c プロジェクト: Yushiko/element-ro
void do_final(void)
{
	if( gm_account_db )
	{
		db_destroy(gm_account_db);
		gm_account_db = NULL;
	}
}
コード例 #11
0
ファイル: project1.c プロジェクト: jreese/rit
/**
 * Program dispatch; get a line of input, and call the appropriate
 * command function.
 */
int main( int argc, char** argv ) {
#if DEBUG
	printf( "Program executed with %d arguments: \n", argc-1 );
	for ( int i = 1; i < argc; i++ ) {
		printf( "Argument: %s \n", argv[i] );
	}
	printf( "\n" );
#endif

	// Check for -v argument
	char* verbose_arg = "-v";
	for ( int i = 1; i < argc; i++ ) {
		if ( strcmp( verbose_arg, argv[i] ) == 0 ) {
			verbose = 1;
		}
	}

	// Initialize database and setup error function
	db_database* db = db_init();
	database = db;
	atexit( cleanup_db );

	// Main loop, get input and process it line by line
	char input[ LINE_SIZE ];   // input buffer
	char* tokens[ ARGS_SIZE ]; // array of pointers into input buffer
	int count;                 // count of input tokens
	char* command;             // the command string
	while ( ( count = tokenize_input( input, tokens ) ) >= 0 ) {

		// Dispatch processing based on the inputted command
		command = tokens[0];

		if ( strcmp( "student", command ) == 0 ) {
			db_new_student( db, tokens[1], tokens + 2 );

		} else if ( strcmp( "open", command ) == 0 ) {
			db_new_course( db, tokens[1], atoi( tokens[2] ) );

		} else if ( strcmp( "cancel", command ) == 0 ) {
			db_cancel_course( db, tokens[1] );

		} else if ( strcmp( "enroll", command ) == 0 ) {
			db_enroll_student( db, tokens[1], tokens[2] );

		} else if ( strcmp( "withdraw", command ) == 0 ) {
			db_withdraw_student( db, tokens[1], tokens[2] );

		}
	}

	// Done processing input
	db_dump( db );
	db_destroy( db );
	database = NULL;

	return 0;
}
コード例 #12
0
ファイル: agent.c プロジェクト: rttc/Crimson-Pyramid
void db_run_destruction(MYSQL_RES *dstrres)
{
	char delquery[QUERYLEN];
	MYSQL_ROW data;
	unsigned long uid;
	char *estr;

	if (!dstrres)
	{
		return;
	}
	if (mysql_num_rows(dstrres) < 1)
	{
		mysql_free_result(dstrres);
		return;
	}

	if (!ldb_init())
	{
		if (LocalDB)
		{
			if (rundaemon) { syslog(LOG_WARNING, "LocalDB connection failed: %s", mysql_error(LocalDB)); }
			else if (dlvl(1)) { fprintf(stdout, "LocalDB connection failed: %s\n", mysql_error(LocalDB)); }
			ldb_deinit();
		}
		else
		{
			if (rundaemon) { syslog(LOG_WARNING, "LocalDB connection failed: unknown"); }
			else if (dlvl(1)) { fprintf(stdout, "LocalDB connection failed: unknown\n"); }
		}
		mysql_free_result(dstrres);
		return;
	}
	while (data = mysql_fetch_row(dstrres))
	{
		uid = stringtoulong(data[1]);
		if (db_destroy(data[0], data[2]) == 0)
		{
			estr = (char *)malloc((strlen(data[0]) * 2) + 1);
			memset(estr, 0, ((strlen(data[0]) * 2) + 1));
			mysql_real_escape_string(DBhandle, estr, data[0], strlen(data[0]));
			memset(delquery, 0, QUERYLEN);
			snprintf(delquery, QUERYLEN, "delete from sql_destroy where uid=%lu and name=\"%s\"", uid, estr);
			free(estr);
			if (dlvl(5) && !rundaemon) { fprintf(stdout, "QUERY: %s\n", delquery); }
			mysql_query(DBhandle, delquery);
		}
	}
	mysql_free_result(dstrres);
	ldb_deinit();
}
コード例 #13
0
ファイル: mdbdump.c プロジェクト: jonrangel/mdb
int
main (int   argc,
      char *argv[])
{
   const bson_t *b;
   extent_t extent;
   record_t record;
   char *str;
   db_t db;
   ns_t ns;

   if (argc != 3) {
      fprintf(stderr, "usage: mdbdump DBPATH DBNAME\n");
      return ARGC_FAILURE;
   }

   errno = 0;
   if (!!db_init(&db, argv[1], argv[2])) {
      perror("Failed to load database");
      return DB_FAILURE;
   }

   errno = 0;
   if (!!db_namespaces(&db, &ns)) {
      perror("Failed to load namespaces");
      return NS_FAILURE;
   }

   do {
      //fprintf(stdout, "\nNamespace \"%s\"\n\n", ns_name(&ns));
      if (!!ns_extents(&ns, &extent)) {
         perror("Failed to load extent");
         return EXTENT_FAILURE;
      }
      do {
         if (!extent_records(&extent, &record)) {
            do {
               b = record_bson(&record);
               if ((str = bson_as_json(b, NULL))) {
                  puts(str);
               }
               bson_free(str);
            } while (!record_next(&record));
         }
      } while (!extent_next(&extent));
   } while (ns_next(&ns));

   db_destroy(&db);

   return 0;
}
コード例 #14
0
ファイル: channel.cpp プロジェクト: Atemo/rathena
/**
 * Delete a channel
 * - Checks if there is any user in channel and make them quit
 * @param channel: Channel data
 * @param force: Forcefully remove channel
 * @return
 *   0: Success
 *  -1: Invalid channel
 *  -2: Can't delete now
 */
int channel_delete(struct Channel *channel, bool force) {
	if(!channel)
		return -1;
	if(!force && channel->type == CHAN_TYPE_PUBLIC && runflag == MAPSERVER_ST_RUNNING) //only delete those serv stop
		return -2;
	if( db_size(channel->users)) {
		struct map_session_data *sd;
		DBIterator *iter = db_iterator(channel->users);
		for( sd = (struct map_session_data *)dbi_first(iter); dbi_exists(iter); sd = (struct map_session_data *)dbi_next(iter) ) { //for all users
			channel_clean(channel,sd,1); //make all quit
		}
		dbi_destroy(iter);
	}
	if (battle_config.etc_log)
		ShowInfo("Deleting channel %s alias %s type %d\n",channel->name,channel->alias,channel->type);
	db_destroy(channel->users);
	db_destroy(channel->banned);
	if (channel->groups)
		aFree(channel->groups);
	channel->groups = NULL;
	channel->group_count = 0;
	switch(channel->type){
	case CHAN_TYPE_MAP:
		map_getmapdata(channel->m)->channel = NULL;
		aFree(channel);
		break;
	case CHAN_TYPE_ALLY: {
		struct guild *g = guild_search(channel->gid);
		if(g) g->channel = NULL;
		aFree(channel);
		break;
	}
	default:
		strdb_remove(channel_db, channel->name);
		break;
	}
	return 0;
}
コード例 #15
0
ファイル: raconf.c プロジェクト: Abunay01/Cronus
void raconf_destroy(raconf rc){
	DBIterator *iter;
	struct conf_value *v;
	
	// Clear all entrys in db.
	iter = db_iterator(rc->db);
	for( v = (struct conf_value*)dbi_first(iter);  dbi_exists(iter);  v = (struct conf_value*)dbi_next(iter) ){
		aFree(v);
	}
	dbi_destroy(iter);

	db_destroy(rc->db);
	
	aFree(rc);	
	
}//end: raconf_destroy()
コード例 #16
0
ファイル: HPMHooking.c プロジェクト: MishimaHaruna/Hercules
void HPM_HP_final(void) {
	int i, len = HPMHooks.data.total * 2;

	if( hp_db )
		db_destroy(hp_db);

	for(i = 0; i < len; i++) {
		int *count = (int *)((char *)&HPMHooks.count + (sizeof(int)*(i)));

		if( count && *count ) {
			struct HPMHookPoint **hp = (struct HPMHookPoint **)((char *)&HPMHooks.list + (sizeof(struct HPMHookPoint *)*(i)));

			if( hp && *hp )
				aFree(*hp);
		}
	}
}
コード例 #17
0
ファイル: instance.c プロジェクト: Milkaka/Cronus-Emulator
/*--------------------------------------
 * Removes a instance, all its maps and npcs.
 *--------------------------------------*/
void instance_destroy(int instance_id)
{
	int last = 0, type;
	struct party_data *p;
	time_t now = time(NULL);

	if( !instance_is_valid(instance_id) )
		return; // nothing to do

	if( instance[instance_id].progress_timeout && instance[instance_id].progress_timeout <= now )
		type = 1;
	else if( instance[instance_id].idle_timeout && instance[instance_id].idle_timeout <= now )
		type = 2;
	else
		type = 3;

	clif_instance(instance_id, 5, type); // Report users this instance has been destroyed

	while( instance[instance_id].num_map && last != instance[instance_id].map[0] )
	{ // Remove all maps from instance
		last = instance[instance_id].map[0];
		instance_del_map( instance[instance_id].map[0] );
	}

	if( instance[instance_id].vars )
		db_destroy(instance[instance_id].vars);

	if( instance[instance_id].progress_timer != INVALID_TIMER )
		delete_timer( instance[instance_id].progress_timer, instance_destroy_timer);
	if( instance[instance_id].idle_timer != INVALID_TIMER )
		delete_timer( instance[instance_id].idle_timer, instance_destroy_timer);

	instance[instance_id].vars = NULL;

	if( instance[instance_id].party_id && (p = party_search(instance[instance_id].party_id)) != NULL )
		p->instance_id = 0; // Update Party information

	ShowInfo("[Instance] Destroyed %s.\n", instance[instance_id].name);
	memset( &instance[instance_id], 0x00, sizeof(instance[0]) );

	instance[instance_id].state = INSTANCE_FREE;
}
コード例 #18
0
/*
 * Create the in-memory database, *mdb.
 * If iflag is not set, fill-in mdb with the records of the disk-based
 * database dbname.
 * Upgrade old-version records by calling v1_to_v2.
 * Return 0 if OK, -1 on error.
 */
int
db_copy_in(DB **mdb, const char *dbname, const char *uname, BTREEINFO *bti,
    int (*v1_to_v2)(DBT *key, DBT *data))
{
	DBT key, data;
	DB *ddb;
	int error, rv, version;

	if ((*mdb = dbopen(NULL, O_RDWR, 0, DB_BTREE, bti)) == NULL)
		return (-1);

	if (iflag)
		return (0);

	if ((ddb = dbopen(dbname, O_RDONLY, 0, DB_BTREE, bti)) == NULL) {
		if (errno == ENOENT)
			return (0);
		warn("retrieving %s summary", uname);
		db_destroy(*mdb, uname);
		return (-1);
	}

	error = 0;

	/* Obtain/set version. */
	version = 1;
	key.data = (void*)&VERSION_KEY;
	key.size = sizeof(VERSION_KEY);

	rv = DB_GET(ddb, &key, &data, 0);
	if (rv < 0) {
		warn("get version key from %s stats", uname);
		error = -1;
		goto closeout;
	} else if (rv == 0) {	/* It's there; verify version. */
		if (data.size != sizeof(version)) {
			warnx("invalid version size %zd in %s",
			    data.size, uname);
			error = -1;
			goto closeout;
		}
		memcpy(&version, data.data, data.size);
		if (version != 2) {
			warnx("unsupported version %d in %s",
			    version, uname);
			error = -1;
			goto closeout;
		}
	}

	for (rv = DB_SEQ(ddb, &key, &data, R_FIRST); rv == 0;
	    rv = DB_SEQ(ddb, &key, &data, R_NEXT)) {

		/* See if this is a version record. */
		if (key.size == sizeof(VERSION_KEY) &&
		    memcmp(key.data, VERSION_KEY, sizeof(VERSION_KEY)) == 0)
			continue;

		/* Convert record from v1, if needed. */
		if (version == 1 && v1_to_v2(&key, &data) < 0) {
			warn("converting %s stats", uname);
			error = -1;
			goto closeout;
		}

		/* Copy record to the in-memory database. */
		if ((rv = DB_PUT(*mdb, &key, &data, 0)) < 0) {
			warn("initializing %s stats", uname);
			error = -1;
			goto closeout;
		}
	}
	if (rv < 0) {
		warn("retrieving %s summary", uname);
		error = -1;
	}

closeout:
	if (DB_CLOSE(ddb) < 0) {
		warn("closing %s summary", uname);
		error = -1;
	}

	if (error)
		db_destroy(*mdb, uname);
	return (error);
}
コード例 #19
0
ファイル: main.c プロジェクト: nexie/ed2kd
int main( int argc, char *argv[] )
{
        size_t i;
        int ret, opt, longIndex = 0;
        struct event *evsig_int;
#ifdef _WIN32
        WSADATA WSAData;
#endif
        pthread_t tcp_thread, *job_threads;

        if ( evutil_secure_rng_init() < 0 ) {
                ED2KD_LOGERR("failed to seed random number generator");
                return EXIT_FAILURE;
        }

        /* parse command line arguments */
        opt = getopt_long( argc, argv, optString, longOpts, &longIndex );
        while( opt != -1 ) {
                switch( opt ) {
                case 'v':
                        display_version();
                        return EXIT_SUCCESS;

                case 'g': {
                        unsigned char hash[ED2K_HASH_SIZE];
                        char hex_hash[sizeof(hash)*2+1];
                        get_random_user_hash(hash);
                        bin2hex(hash, hex_hash, sizeof(hex_hash));
                        puts(hex_hash);
                        return EXIT_SUCCESS;
                }

                case 'h':
                        display_usage();
                        return EXIT_SUCCESS;

                default:
                        return EXIT_FAILURE;
                }
                opt = getopt_long( argc, argv, optString, longOpts, &longIndex );
        }

#ifdef _WIN32
        if ( 0 != WSAStartup(0x0201, &WSAData) ) {
                ED2KD_LOGERR("WSAStartup failed!");
                return EXIT_FAILURE;
        }
#endif

        if ( !server_load_config(NULL) ) {
                ED2KD_LOGERR("failed to load configuration file");
                return EXIT_FAILURE;
        }

        display_libevent_info();

#ifdef EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED
        ret = evthread_use_windows_threads();
#elif EVTHREAD_USE_PTHREADS_IMPLEMENTED
        ret = evthread_use_pthreads();
#else
#error "unable to determine threading model"
#endif
        if ( ret < 0 ) {
                ED2KD_LOGERR("failed to init libevent threading model");
                return EXIT_FAILURE;
        }

        g_srv.evbase_main = event_base_new();
        if ( NULL == g_srv.evbase_main ) {
                ED2KD_LOGERR("failed to create main event loop");
                return EXIT_FAILURE;
        }
        g_srv.evbase_tcp = event_base_new();
        if ( NULL == g_srv.evbase_tcp ) {
                ED2KD_LOGERR("failed to create tcp event loop");
                return EXIT_FAILURE;
        }

        evsig_int = evsignal_new(g_srv.evbase_main, SIGINT, sigint_cb, NULL);
        evsignal_add(evsig_int, NULL);

        // common timers timevals
        g_srv.portcheck_timeout_tv = event_base_init_common_timeout(g_srv.evbase_tcp, &g_srv.cfg->portcheck_timeout_tv);
        g_srv.status_notify_tv = event_base_init_common_timeout(g_srv.evbase_tcp, &g_srv.cfg->status_notify_tv);

        if ( !db_create() ) {
                ED2KD_LOGERR("failed to create database");
                return EXIT_FAILURE;
        }

        g_srv.thread_count = omp_get_num_procs() + 1;

        pthread_cond_init(&g_srv.job_cond, NULL);
        pthread_mutex_init(&g_srv.job_mutex, NULL);
        TAILQ_INIT(&g_srv.jqueue);

        job_threads = (pthread_t *)malloc(g_srv.thread_count * sizeof(*job_threads));

        // start tcp worker threads
        for ( i=0; i<g_srv.thread_count; ++i ) {
                pthread_create(&job_threads[i], NULL, server_job_worker, NULL);
        }

        // start tcp dispatch thread
        pthread_create(&tcp_thread, NULL, server_base_worker, g_srv.evbase_tcp);

        // start tcp listen loop
        if ( !server_listen() ) {
                ED2KD_LOGERR("failed to start server listener");
                server_stop();
        }

        pthread_join(tcp_thread, NULL);

        while ( EBUSY == pthread_cond_destroy(&g_srv.job_cond) ) {
                pthread_cond_broadcast(&g_srv.job_cond);
                //pthread_yield();
        }

        pthread_mutex_destroy(&g_srv.job_mutex);

        for ( i=0; i<g_srv.thread_count; ++i ) {
                pthread_join(job_threads[i], NULL);
        }

        free(job_threads);

        // todo: free job queue items

        evconnlistener_free(g_srv.tcp_listener);
        event_free(evsig_int);
        event_base_free(g_srv.evbase_tcp);
        event_base_free(g_srv.evbase_main);

        if ( db_destroy() < 0 ) {
                ED2KD_LOGERR("failed to destroy database");
        }

        server_free_config();

        return EXIT_SUCCESS;
}
コード例 #20
0
ファイル: discofs.c プロジェクト: laevar/discofs
/*! Main
@param argc number of arguments
@param argv arguments
 @return fuse_main()s return value
*/
int main(int argc, char **argv)
{
    /* return value of fuse_main() */
    int ret;

    /* for signal handling */
    struct sigaction sig;

    /* argument handling */
    struct fuse_args args = FUSE_ARGS_INIT(argc, argv);

    /* file name for database */
    char *db_file;


    /*------------------------*
     * install signal handler *
     *------------------------*/

    /* set handling function */
    sig.sa_handler = sig_handler;

    /* set (no) flags */
    sig.sa_flags = 0;

    /* don't ignore any signal */
    sigemptyset(&sig.sa_mask);

    /* install signal handler for USR1 and USR2 */
    sigaction(SIGUSR1, &sig, NULL);
    sigaction(SIGUSR2, &sig, NULL);


    /*------------------*
     * handle arguments *
     *------------------*/

    if (fuse_opt_parse(&args, &discofs_options, discofs_opts, discofs_opt_proc) == -1)
        return EXIT_FAILURE;

    /* after option parsing, remote mount point must be set */
    if (!REMOTE_ROOT)
    {
        fprintf(stderr, "no remote filesystem given\n");
        return EXIT_FAILURE;
    }

    /* a mount point for discofs must also be set */
    if (!discofs_options.discofs_mp)
    {
        fprintf(stderr, "no mount point given\n");
        return EXIT_FAILURE;
    }

    /* add "use_ino" to display inodes in stat(1)*/
    fuse_opt_add_arg(&args, "-ouse_ino");


    /*---------------*
     * set UID / GID *
     *---------------*/

    /* set GID first since permissions might not be
       sufficient if UID was set beforehand */
    if (discofs_options.gid)
    {
        VERBOSE("setting gid to %d\n", discofs_options.gid);
        if (setgid(discofs_options.gid))
        {
            perror("setting gid");
            return EXIT_FAILURE;
        }
    }
    if (discofs_options.uid)
    {
        VERBOSE("setting uid to %d\n", discofs_options.uid);
        if (setuid(discofs_options.uid))
        {
            perror("setting uid");
            return EXIT_FAILURE;
        }
    }


    /*--------------------*
     * initialize logging *
     *--------------------*/

    /* if -d is specified, override logging settings */
    if (discofs_options.debug)
        log_init(LOG_DEBUG, NULL);
    else
        log_init(discofs_options.loglevel, discofs_options.logfile);



    /*=========================*
     * INITIALIZE CACHE AND DB *
     *=========================*/

    /* compute data root if not passed as option */
    if (!discofs_options.data_root)
        discofs_options.data_root = paths_data_root(REMOTE_ROOT);

    if (!is_dir(discofs_options.data_root))
    {
        if (mkdir_rec(discofs_options.data_root))
            FATAL("failed to create data directory %s\n", discofs_options.data_root);
    }


    /*----------------------*
     * initialize cache dir *
     *----------------------*/

    /* set cache dir */
    CACHE_ROOT = join_path(discofs_options.data_root, "cache");

    /* store length of cache root (to save a few hundred strlen() calls)  */
    CACHE_ROOT_LEN = strlen(CACHE_ROOT);

    /* delete cache if "clear" specified */
    if (discofs_options.clear)
    {
        VERBOSE("deleting cache\n");
        rmdir_rec(CACHE_ROOT);
    }

    /* create cache root if needed */
    if (!is_dir(CACHE_ROOT))
    {
        if (mkdir(CACHE_ROOT, S_IRWXU) != 0)
            FATAL("failed to create cache directory %s\n", CACHE_ROOT);
    }


    /*---------------------*
     * initialize database *
     *---------------------*/

    /* set db filename */
    db_file = join_path(discofs_options.data_root, "db.sqlite");

    /* create database file if it doesn't exist  */
    int fd = open(db_file, (O_RDONLY | O_CREAT), (S_IRUSR | S_IWUSR));
    if (fd == -1)
    {
        perror(db_file);
        FATAL("couldn't open or create database file\n");
    }
    close(fd);

    /* initialize tables etc */
    db_init(db_file, discofs_options.clear);

    /* try to load filesystem features from DB */
    if (db_cfg_get_int(CFG_FS_FEATURES, &discofs_options.fs_features))
    {

        /* if loading failed, try to determine them */
        if (is_mounted(REMOTE_ROOT) && is_reachable(discofs_options.host))
        {
            if (test_fs_features(&discofs_options.fs_features))
            {
                ERROR("failed to test remote fs features\n");
                discofs_options.fs_features = 0;
            }
            /* test succeeded, store value for next time */
            else
                db_cfg_set_int(CFG_FS_FEATURES, discofs_options.fs_features);
        }
        /* nag and assume that no features available (but don't save that) */
        else
        {
            ERROR("could not determine remote fs features");
            discofs_options.fs_features = 0;
        }
    }


    /*------------------*
     * initialize stuff *
     *------------------*/
    #define INIT(name)                          \
        if (name ## _init())                    \
            FATAL("error initializing " #name)
    INIT(lock);
    INIT(sync);
    INIT(job);
    #undef INIT


    /*----------------------*
     * print options to log *
     *----------------------*/
    log_options(LOG_VERBOSE, discofs_options);


    /*-----------------*
     * run fuse_main() *
     *-----------------*/
    ret = fuse_main(args.argc, args.argv, &discofs_oper, NULL);


    /*------*
     * exit *
     *------*/

    lock_destroy();
    sync_destroy();
    job_destroy();

    /* free arguments */
    fuse_opt_free_args(&args);

    /* close database connection */
    db_destroy();


    /* end logging */
    INFO("exiting\n");
    log_destroy();


    /* return fuse_main()s return value */
    return ret;
}
コード例 #21
0
ファイル: db.c プロジェクト: DhruvRelwani/GamesmanClassic
void DestroyDatabases()
{
	db_destroy();
}
コード例 #22
0
ファイル: project1.c プロジェクト: jreese/rit
/**
 * Function to be executed before at exit, to cleanup the database if needed.
 */
void cleanup_db( void ) {
	if ( database != NULL ) {
		db_destroy( database );
	}
}
コード例 #23
0
ファイル: clan.c プロジェクト: AtlantisRO/rathena
void do_final_clan(){
	db_destroy(clan_db);
}
コード例 #24
0
ファイル: mapindex.c プロジェクト: 2serv/rathena
void mapindex_final(void) {
	db_destroy(mapindex_db);
}
コード例 #25
0
ファイル: usrdb.c プロジェクト: JabirTech/Source
void
usracct_destroy(void)
{
	db_destroy(usracct_db, "user accounting");
}
コード例 #26
0
ファイル: chat.c プロジェクト: AtlantisRO/Renewal
/*==========================================
 * Leave a chatroom
 * Return
 *  0: User not found in chatroom/Missing data
 *  1: Success
 *  2: Chat room deleted (chat room empty)
 *  3: Owner changed (Owner left and a new one as assigned)
 *------------------------------------------*/
int chat_leavechat(struct map_session_data* sd, bool kicked) {
	struct chat_data* cd;
	int i;
	int leavechar;

	nullpo_retr(0, sd);

	cd = map->id2cd(sd->chat_id);
	if (cd == NULL) {
		pc_setchatid(sd, 0);
		return 0;
	}

	ARR_FIND( 0, cd->users, i, cd->usersd[i] == sd );
	if (i == cd->users) {
		// Not found in the chatroom?
		pc_setchatid(sd, 0);
		return 0;
	}

	clif->leavechat(cd, sd, kicked);
	pc_setchatid(sd, 0);
	cd->users--;

	leavechar = i;

	for( i = leavechar; i < cd->users; i++ )
		cd->usersd[i] = cd->usersd[i+1];


	if( cd->users == 0 && cd->owner->type == BL_PC ) { // Delete empty chatroom
		struct skill_unit* su;
		struct skill_unit_group* group;

		clif->clearchat(cd, 0);
		db_destroy(cd->kick_list);
		map->deliddb(&cd->bl);
		map->delblock(&cd->bl);
		map->freeblock(&cd->bl);

		su = map->find_skill_unit_oncell(&sd->bl, sd->bl.x, sd->bl.y, AL_WARP, NULL, 0);
		group = (su != NULL) ? su->group : NULL;
		if (group != NULL)
			skill->unit_onplace(su, &sd->bl, group->tick);

		return 2;
	}

	if( leavechar == 0 && cd->owner->type == BL_PC ) {
		// Set and announce new owner
		cd->owner = &cd->usersd[0]->bl;
		clif->changechatowner(cd, cd->usersd[0]);
		clif->clearchat(cd, 0);

		//Adjust Chat location after owner has been changed.
		map->delblock( &cd->bl );
		cd->bl.x = cd->owner->x;
		cd->bl.y = cd->owner->y;
		map->addblock( &cd->bl );

		clif->dispchat(cd,0);
		return 3; // Owner changed
	}
	clif->dispchat(cd,0); // refresh chatroom

	return 1;
}
コード例 #27
0
ファイル: chat.c プロジェクト: philg666/Latest_eAmod
/*==========================================
 * leave a chatroom
 *------------------------------------------*/
int chat_leavechat(struct map_session_data *sd, bool kicked)
{
	struct chat_data *cd;
	int i;
	int leavechar;

	nullpo_retr(1, sd);

	cd = (struct chat_data *)map_id2bl(sd->chatID);
	if(cd == NULL) {
		pc_setchatid(sd, 0);
		return 1;
	}

	ARR_FIND(0, cd->users, i, cd->usersd[i] == sd);
	if(i == cd->users) {
		// Not found in the chatroom?
		pc_setchatid(sd, 0);
		return -1;
	}

	clif_leavechat(cd, sd, kicked);
	pc_setchatid(sd, 0);
	cd->users--;

	leavechar = i;

	for(i = leavechar; i < cd->users; i++)
		cd->usersd[i] = cd->usersd[i+1];


	if(cd->users == 0 && cd->owner->type == BL_PC) {   // Delete empty chatroom
		struct skill_unit *unit;
		struct skill_unit_group *group;

		clif_clearchat(cd, 0);
		db_destroy(cd->kick_list);
		map_deliddb(&cd->bl);
		map_delblock(&cd->bl);
		map_freeblock(&cd->bl);

		unit = map_find_skill_unit_oncell(&sd->bl, sd->bl.x, sd->bl.y, AL_WARP, NULL, 0);
		group = (unit != NULL) ? unit->group : NULL;
		if(group != NULL)
			ext_skill_unit_onplace(unit, &sd->bl, group->tick);

		return 1;
	}

	if(leavechar == 0 && cd->owner->type == BL_PC) {
		// Set and announce new owner
		cd->owner = (struct block_list *) cd->usersd[0];
		clif_changechatowner(cd, cd->usersd[0]);
		clif_clearchat(cd, 0);

		//Adjust Chat location after owner has been changed.
		map_delblock(&cd->bl);
		cd->bl.x=cd->usersd[0]->bl.x;
		cd->bl.y=cd->usersd[0]->bl.y;
		map_addblock(&cd->bl);

		clif_dispchat(cd,0);
	} else
		clif_dispchat(cd,0); // refresh chatroom

	return 0;
}
コード例 #28
0
ファイル: instance.c プロジェクト: MStr3am/idathena
/*==========================================
 * Removes a instance, all its maps and npcs.
 *------------------------------------------*/
int instance_destroy(short instance_id)
{
	struct instance_data *im;
	struct party_data *p;
	int i, type = 0;
	unsigned int now = (unsigned int)time(NULL);

	if(instance_id <= 0 || instance_id > MAX_INSTANCE_DATA)
		return 1;

	im = &instance_data[instance_id];

	if(im->state == INSTANCE_FREE)
		return 1;

	if(im->state == INSTANCE_IDLE) {
		for(i = 0; i < instance_wait.count; i++) {
			if(instance_wait.id[i] == instance_id) {
				instance_wait.count--;
				memmove(&instance_wait.id[i], &instance_wait.id[i + 1], sizeof(instance_wait.id[0]) * (instance_wait.count - i));
				memset(&instance_wait.id[instance_wait.count], 0, sizeof(instance_wait.id[0]));

				for(i = 0; i < instance_wait.count; i++) {
					if(instance_data[instance_wait.id[i]].state == INSTANCE_IDLE &&
						(p = party_search(instance_data[instance_wait.id[i]].party_id)) != NULL)
						clif_instance_changewait(party_getavailablesd(p), i + 1, 1);
				}

				if(instance_wait.count)
					instance_wait.timer = add_timer(gettick() + INSTANCE_INTERVAL, instance_subscription_timer, 0, 0);
				else
					instance_wait.timer = INVALID_TIMER;
				type = 0;
				break;
			}
		}
	} else {
		if(im->keep_limit && im->keep_limit <= now)
			type = 1;
		else if(im->idle_limit && im->idle_limit <= now)
			type = 2;
		else
			type = 3;

		for(i = 0; i < MAX_MAP_PER_INSTANCE; i++)
			map_delinstancemap(im->map[i].m);
	}

	if(im->keep_timer != INVALID_TIMER) {
		delete_timer(im->keep_timer, instance_delete_timer);
		im->keep_timer = INVALID_TIMER;
	}

	if(im->idle_timer != INVALID_TIMER) {
		delete_timer(im->idle_timer, instance_delete_timer);
		im->idle_timer = INVALID_TIMER;
	}

	if((p = party_search(im->party_id))) {
		p->instance_id = 0;

		if(type)
			clif_instance_changestatus(party_getavailablesd(p), type, 0, 1);
		else
			clif_instance_changewait(party_getavailablesd(p), 0xffff, 1);
	}

	if(im->vars) {
		db_destroy(im->vars);
		im->vars = NULL;
	}

	ShowInfo("[Instance] Destroyed %d.\n", instance_id);

	memset(&instance_data[instance_id], 0, sizeof(instance_data[instance_id]));

	return 0;
}
コード例 #29
0
ファイル: worker.c プロジェクト: saidimu/ninjaduino
void generic_worker(void * cvoid, zctx_t * context, void * pipe) {
  workerconfig_t *config = (workerconfig_t*) cvoid;

  rulepackage_t rpkg;
  child_handshake(pipe);


  rpkg.channel = config->channel;
  rpkg.actions = zhash_new();
  rpkg.triggers = zhash_new();
  rpkg.context = context;
  rpkg.base_config = config->base_config;

  // FIX this needs to be initialised differently for each channel
  // normal channels will always have the "value" service,
  // but (for instance) the Camera channel has the "photo" service

  // zhash_t * services = zhash_new();
  
  char * ninja = config->base_config->uuid;
  rpkg.servicename = malloc(strlen(ninja) +
                            strlen(rpkg.channel) + 4);
  sprintf(rpkg.servicename, "n:%s:%s", ninja,rpkg.channel);

  channeldb_t *db = db_init(rpkg.servicename);

  zclock_log("%s worker preparing rules...", rpkg.servicename);

  zclock_log("%s worker reloading rules from db...", rpkg.servicename);
  db_reload_rules(db, &rpkg);

  //  reload_rules_db(context, db, rpkg.servicename, channel, rules, config->base_config);
  zclock_log("%s worker checking rules with server...", rpkg.servicename);
  char * reup = config->base_config->reup_endpoint;
  if(!reup) {
    zclock_log("E: NO REUP CONNECTION DEFINED! Probably dealing with an old server.");
  } else {
    void * reup_sock = zsocket_new(rpkg.context, ZMQ_DEALER);

    zclock_log("connecting to %s", reup);
    zsocket_connect(reup_sock, reup);
    zlist_t * rules = fetch_rules(reup_sock, rpkg.servicename);
    zmsg_t *tmp;
    while(tmp=zlist_pop(rules)) {
      // handle_command(tmp, NULL, &rpkg, db); // FIXME what do we do
                                               // with the reply?
    }
  }

  db_display_rules(db) ;


  zclock_log("%s worker connecting...", rpkg.servicename);
  mdwrk_t *session = mdwrk_new (config->base_config->broker_endpoint, rpkg.servicename, 0);
  zclock_log("%s worker connected!", rpkg.servicename);
  zmsg_t *reply = NULL;
  while (1) {
    zclock_log("%s worker waiting for work.", rpkg.servicename);
    zmsg_t *request = mdwrk_recv (session, &reply);

    if (request == NULL)
      break;              //  Worker was interrupted
    reply = zmsg_new();
    handle_command(request, reply,  &rpkg, db);
  }
  db_destroy(db);
  mdwrk_destroy (&session);
  return;
}
コード例 #30
0
ファイル: vending.c プロジェクト: bdacode/rathena
/**
 * Initialise the vending module
 * called in map::do_init
 */
void do_final_vending(void) {
	db_destroy(vending_db);
}