[IRCServices] Problems with chanserv.c and Db-support
Johan Yves August Grasmo
johanyg at ifi.uio.no
Fri May 18 21:23:02 PDT 2001
Hello again :-)
I'm trying to adjust the irc services to support mysql, and
I'm now just trying to get it to work. I've imported the
different nicks correctly, and now I'm trying to adjust the
chanserv.c to load the channels and user-permissions from
the db.
I seem to have some problems with my variable settings for a
channel, more specifically the ChanAccess *access pointer.
This returns 8 in get_access(...), and henche it segfaults.
Well, I'm at a loss here :( I would appreciate if anyone
here could lend me a hand to solve this. I hope the code
below is readable.
Thanx again,
Johan
Snip of load_cs_dbase :
void load_cs_dbase(void)
{
ChannelInfo *ci;
char usquery[500];
MYSQL cimysql,*cisock, usrmysql, *usrsock;
MYSQL_RES *res, *usres;
MYSQL_ROW row, usrrow;
int j;
unsigned int num_fields, num_users;
/* mysql-calls to get the channel information */
mysql_init(&cimysql);
mysql_init(&usrmysql);
if (!(cisock = mysql_real_connect(&cimysql,NULL,cidbuser,cidbpass,cidbname,0,NULL,0))) {
log("debug: Couldn't connect to %s as %s using pass %s",
cidbname, cidbuser, cidbpass);
exit(1);
}
if (mysql_select_db(&cimysql,cidbname)) {
log("debug: Failed to select table: Error: %s", mysql_error(&cimysql));
exit(1);
}
mysql_query(&cimysql,ciSELECT_QUERY);
res = mysql_use_result(&cimysql);
num_fields = mysql_num_fields(res);
/* End channel-information */
/* Mysql-calls to get the user information */
/* usrsock = mysql_real_connect(&cimysql,NULL,cidbuser,cidbpass,cidbname,0,NULL,0);
mysql_select_db(&usrmysql,cidbname);*/
if (!(usrsock = mysql_real_connect(&usrmysql,NULL,cidbuser,cidbpass,cidbname,0,NULL,0))) {
log("debug: Couldn't connect to %s as %s using pass %s",
cidbname, cidbuser, cidbpass);
exit(1);
}
if (mysql_select_db(&usrmysql,cidbname)) {
log("debug: Failed to select table: Error: %s", mysql_error(&usrmysql));
exit(1);
}
/* End user-information */
while ((row = mysql_fetch_row(res))) {
/*
row[2] - channelname
row[3] - flags (as defined in services.h (1,2,4,8,16 etc))
row[6] - founder
row[7] - founderpass
row[12] - entry_message
*/
log("debug: Processing channel %s(Flags: %s) with founder %s and pass %s", row[2], row[3], row[6], row[7]);
ci = smalloc(sizeof(ChannelInfo));
strcpy(ci->name,row[2]);
ci->founder = findnick(row[6]);
strcpy(ci->founderpass, row[7]);
ci->entry_message = row[12];
ci->flags = atoi(row[3]);
ci->levels = smalloc(2*CA_SIZE);
reset_levels(ci);
*(ci->levels) = 5;
ci->mlock_on = 548;
ci->time_registered = 0;
ci->last_used = 0;
ci->mlock_off = 0;
ci->mlock_key = 0;
ci->mlock_limit = 0;
/*
Various flags that has to be set :
Level - Desc.
10 Access to change things. Do not set this
5 Auto OP
4 Half OP
3 Auto Voice
0 Normal
-1 Auto De-op
-2 No-join (forces person to part channel)
*/
sprintf(usquery, "SELECT * FROM ircuserpermissions WHERE channel = '%s'", row[2]);
/*
The results from this query is :
row[0] - ircnick
row[1] - channelname
row[2] - flag (as defined in def_levels)
*/
mysql_query(&usrmysql, usquery);
usres = mysql_use_result(&usrmysql);
j=0;
num_users = mysql_num_fields(usres);
log("debug: Found %d users for channel %s", num_users, row[2]);
if (num_users > 0) {
ci->accesscount = num_users;
/* Looping here if we have registered any accesses on users */
while ((usrrow = mysql_fetch_row(usres))) {
ci->access = scalloc(ci->accesscount, sizeof(ChanAccess));
ci->access[j].in_use = 1;
ci->access[j].level = atoi(usrrow[2]);
ci->access[j].ni = findnick(usrrow[0]);
log("debug: &ci->access[j].in_use -> %d", ci->access[j].in_use);
if (ci->access[j].ni == NULL)
ci->access[j].in_use = 0;
log("debug: Setting flags for user %s for channel %s with permissions %d (%s)", usrrow[0], usrrow[1], ci->access[j].level, usrrow[2]);
j++;
}
}
alpha_insert_chan(ci);
}
mysql_close(cisock);
mysql_close(usrsock);
}