Exemple #1
0
/* chan is created if not exists */
int db_getchancreate(char *chan)
{
	int res = -1;

#ifdef HASHLISTSUPPORT
	strtolwr(chan);
	res = hash_find_unsure(hashchans, chan, KEYCHAN);
#else
	MYSQL_RES *resptr;
	strtolwr(chan);
	db_query("SELECT chanid FROM " TBL_CHAN " WHERE channel=\'%s\'", chan);
	resptr = mysql_store_result(myptr);
	if (mysql_num_rows(resptr))
		res = atoi(*mysql_fetch_row(resptr));
	mysql_free_result(resptr);
#endif
	if (res == -1)

	{
		db_query("INSERT INTO " TBL_CHAN " (channel) VALUES (\'%s\')", chan);
		res = db_insertid();
#ifdef HASHLISTSUPPORT
		hash_add(hashchans, chan, res, KEYCHAN);
#endif
		nbchans++;
		do_checknbchansmax();
	}
	return res;
}
Exemple #2
0
/* changes a nick in the hashlist */
void db_chgnick(char *newnick, char *oldnick)
{
#ifdef HASHLISTSUPPORT
	/* people often change from NICK-sthing to NICK-sthing */
	strtolwr(newnick);
	strtolwr(oldnick);
	hash_update(hashnicks, newnick, oldnick, KEYOTHER);
#endif
}
Exemple #3
0
/* chan is created if not exists */
int db_getchancreate(char *chan)
{
    int res = -1;
    Channel *c;
    char *channel;
#ifdef USE_MYSQL
    MYSQL_RES *mysql_res;
#endif

    SET_SEGV_LOCATION();
    strtolwr(chan);

    c = findchan(chan);

    if (c) {
        if (c->sqlid) {
            return c->sqlid;
        } else {
            channel = sstrdup(c->sqlchan);
        }
    } else {
        channel = rdb_escape(chan);
    }


    if (!denora->do_sql) {
        return -1;
    }
    strtolwr(channel);
    rdb_query(QUERY_HIGH, "SELECT chanid FROM %s WHERE channel=\'%s\'",
              ChanTable, channel);
#ifdef USE_MYSQL
    mysql_res = mysql_store_result(mysql);
    if (mysql_res) {
        if (mysql_num_rows(mysql_res))
            res = atoi(*mysql_fetch_row(mysql_res));
        mysql_free_result(mysql_res);
    }
#endif
    SET_SEGV_LOCATION();
    if (res == -1) {
        rdb_query(QUERY_HIGH, "INSERT INTO %s (channel) VALUES (\'%s\')",
                  ChanTable, channel);
        res = rdb_insertid();
    }
    SET_SEGV_LOCATION();
    if (c && res) {
        c->sqlid = res;
    }
    free(channel);
    return res;
}
Exemple #4
0
/* add a nick to the hashlist */
void db_delnick(char *nick)
{
#ifdef HASHLISTSUPPORT
	strtolwr(nick);
	hash_del(hashnicks, nick, KEYOTHER);
#endif
}
Exemple #5
0
/* add a nick to the hashlist */
void db_addnick(char *nick, int nickid)
{
#ifdef HASHLISTSUPPORT
	strtolwr(nick);
	hash_add(hashnicks, nick, nickid, KEYOTHER);
#endif
}
Exemple #6
0
/* add a server to the hashlist */
void db_addserver(char *server, int servid)
{
#ifdef HASHLISTSUPPORT
	strtolwr(server);
	hash_add(hashservs, server, servid, KEYOTHER);
#endif
}
Exemple #7
0
/* remove a server from the hashlist */
void db_delserver(char *server)
{
#ifdef HASHLISTSUPPORT
	strtolwr(server);
	hash_del(hashservs, server, KEYOTHER);
#endif
}
Exemple #8
0
/* chan should be db_escape'd before call */
int db_getchannel_users(char *chan)
{
    int res = 0;
#ifdef USE_MYSQL
    MYSQL_RES *mysql_res;
#endif

    SET_SEGV_LOCATION();
    strtolwr(chan);

    if (!denora->do_sql) {
        return -1;
    }
    SET_SEGV_LOCATION();

    rdb_query(QUERY_HIGH,
              "SELECT currentusers FROM %s WHERE channel=\'%s\'",
              ChanTable, chan);
#ifdef USE_MYSQL
    mysql_res = mysql_store_result(mysql);
    SET_SEGV_LOCATION();
    if (mysql_res) {
        if (mysql_num_rows(mysql_res)) {
            res = strtol(*mysql_fetch_row(mysql_res), NULL, 10);
        } else {
            alog(LOG_DEBUG,
                 "debug: unable to find the requested channel %s", chan);
        }
        SET_SEGV_LOCATION();
        mysql_free_result(mysql_res);
    }
#endif
    return res;
}
Exemple #9
0
/* chan should be db_escape'd before call */
int db_getchannel(char *chan)
{
#ifdef HASHLISTSUPPORT
	strtolwr(chan);
	return hash_find(hashchans, chan, KEYCHAN);
#else
	int res = 0;

	MYSQL_RES *resptr;
	strtolwr(chan);
	db_query("SELECT chanid FROM " TBL_CHAN " WHERE channel=\'%s\'", chan);
	resptr = mysql_store_result(myptr);
	if (mysql_num_rows(resptr))
		res = atoi(*mysql_fetch_row(resptr));
	else
		fatal("channel not found !");
	mysql_free_result(resptr);
	return res;
#endif
}
Exemple #10
0
/* serv should be db_escape'd before call */
int db_getserver(char *serv)
{
#ifdef HASHLISTSUPPORT
	strtolwr(serv);
	return hash_find(hashservs, serv, KEYOTHER);
#else
	MYSQL_RES *resptr;
	int res = 0;

	db_query("SELECT servid FROM " TBL_SERV " WHERE server=\'%s\'", serv);
	resptr = mysql_store_result(myptr);
	if (mysql_num_rows(resptr))
		res = atoi(*mysql_fetch_row(resptr));
	mysql_free_result(resptr);
	return res;
#endif
}
Exemple #11
0
/* -1 if nick not found, nickid else */
int db_checknick(char *nick)
{
#ifdef HASHLISTSUPPORT
	int res = 0;
	char *nicklow = strdup(nick);
	strtolwr(nicklow);
	res = hash_find_unsure(hashnicks, nicklow, KEYOTHER);
	free(nicklow);
	return res;
#else
	int nickid = -1;
	MYSQL_RES *resptr;
	db_query("SELECT nickid FROM " TBL_USER " WHERE nick=\"%s\"", nick);
	resptr = mysql_store_result(myptr);
	if (mysql_num_rows(resptr))
		nickid = atoi(*mysql_fetch_row(resptr));
	mysql_free_result(resptr);
	return nickid;
#endif
}
Exemple #12
0
int db_getchmode(char *chan, char *chmode) {
        MYSQL_RES *resptr;
        strtolwr(chan);

	char *res = NULL;

        db_query("SELECT mode_%s FROM " TBL_CHAN " WHERE channel=\'%s\'", chmode, chan);
        resptr = mysql_store_result(myptr);
        if (mysql_num_rows(resptr))
                res = *mysql_fetch_row(resptr);
        else
                fatal("channel not found !");
        mysql_free_result(resptr);

	if (!strcmp(res, "N")) {
		return 0;
	}
	else {
		return 1;
	}
}
Exemple #13
0
/* chan should be db_escape'd before call */
int db_getchannel(char *chan)
{
    int res = 0;
    Channel *c;
#ifdef USE_MYSQL
    MYSQL_RES *mysql_res;
#endif

    if (!chan)
        return -1;

    strtolwr(chan);
    SET_SEGV_LOCATION();

    c = findchan(chan);
    if (c && c->sqlid) {
        return c->sqlid;
    }

    if (!denora->do_sql) {
        return -1;
    }

    rdb_query(QUERY_HIGH, "SELECT chanid FROM %s WHERE channel=\'%s\'",
              ChanTable, chan);
#ifdef USE_MYSQL
    mysql_res = mysql_store_result(mysql);
    if (mysql_res) {
        if (mysql_num_rows(mysql_res)) {
            mysql_row = mysql_fetch_row(mysql_res);
            res = strtol(mysql_row[0], NULL, 10);
        } else {
            alog(LOG_NONEXISTANT, "channel not found ! %s", chan);
        }
        SET_SEGV_LOCATION();
        mysql_free_result(mysql_res);
    }
#endif
    return res;
}
Exemple #14
0
/* nick should be db_escape'd before call */
int db_getnick(char *nick)
{
#ifdef HASHLISTSUPPORT
	int res = 0;
	char *nicklow = strdup(nick);
	strtolwr(nicklow);
	res = hash_find(hashnicks, nicklow, KEYOTHER);
	free(nicklow);
	return res;
#else
	MYSQL_RES *resptr;
	int res = 0;

	db_query("SELECT nickid FROM " TBL_USER " WHERE nick=\'%s\'", nick);
	resptr = mysql_store_result(myptr);
	if (mysql_num_rows(resptr))
		res = atoi(*mysql_fetch_row(resptr));
	else
		fatal("nickname not found !");
	mysql_free_result(resptr);
	return res;
#endif
}