Anope IRC Services

Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: ns_ajoin.c  (Read 8102 times)

0 Members and 1 Guest are viewing this topic.

black-drag0n

  • Guest
ns_ajoin.c
« on: March 08, 2006, 04:33:22 PM »

hello dear anope developement team or any othe who can help me....
i try to install the module "ns_ajoin". i put the ns_ajoin.c file into the directory /home/.../anope-1.7.13/src/modules/
and used "make modules" on command line...
but than it shows me following "error":

Code: [Select]


orangevirus@debian:~/anope-1.7.13$ make modules
*** Building src
make[1]: Entering directory `/home/orangevirus/anope-1.7.13/src'
make[1]: Für das Ziel »all« ist nichts zu tun.
make[1]: Leaving directory `/home/orangevirus/anope-1.7.13/src'
(cd src/modules ; ./configure ; make 'CFLAGS=-pipe -g -O2 -pthread -export-dynamic' 'CC=gcc' 'ANOPELIBS=-lnsl -lresolv -ldl' 'LDFLAGS=' 'BINDEST=/home/orangevirus/services' 'INSTALL=/usr/bin/install' 'INCLUDEDIR=../include' 'RM=/bin/rm' 'CP=/bin/cp' 'TOUCH=/usr/bin/touch' 'SHELL=/bin/sh' 'DATDEST=/home/orangevirus/services' 'RUNGROUP=' 'MODULE_PATH=/home/orangevirus/services/modules/' 'RDB=' 'MYSQL=' 'SHARED=-shared' 'MODULEFLAGS=-fPIC -DPIC -shared' all; )
make[1]: Entering directory `/home/orangevirus/anope-1.7.13/src/modules'
gcc -pipe -g -O2 -pthread -export-dynamic -g -rdynamic -Wall -fPIC -DPIC -shared -I../../include -c ns_ajoin.c
ns_ajoin.c:336: error: Syntaxfehler before '*' token
ns_ajoin.c:336: Warnung: type defaults to `int' in declaration of `mysql'
ns_ajoin.c:336: Warnung: data definition has no type or storage class
ns_ajoin.c: In Funktion »AnopeInit«:
ns_ajoin.c:415: error: `do_mysql' undeclared (first use in this function)
ns_ajoin.c:415: error: (Each undeclared identifier is reported only once
ns_ajoin.c:415: error: for each function it appears in.)
ns_ajoin.c:521: Warnung: implicit declaration of function `db_keepalive'
ns_ajoin.c: In Funktion »AnopeFini«:
ns_ajoin.c:534: Warnung: implicit declaration of function `mysql_close'
ns_ajoin.c: In Funktion »get_src_dests«:
ns_ajoin.c:687: Warnung: unused variable `destination'
ns_ajoin.c: In Funktion »notice_user_ww«:
ns_ajoin.c:840: Warnung: implicit declaration of function `vasprintf'
ns_ajoin.c: In Funktion »ns_ajoin_replace«:
ns_ajoin.c:1551: Warnung: unused variable `oldchanlist'
ns_ajoin.c: In Funktion »ns_ajoin_list«:
ns_ajoin.c:1606: Warnung: suggest parentheses around assignment used as truth value
ns_ajoin.c: In Funktion »do_on_identify«:
ns_ajoin.c:1766: Warnung: suggest parentheses around assignment used as truth value
ns_ajoin.c:1783: error: `CMODE_i' undeclared (first use in this function)
ns_ajoin.c: In Funktion »quote«:
ns_ajoin.c:1822: Warnung: implicit declaration of function `mysql_real_escape_string'
ns_ajoin.c: Auf höchster Ebene:
ns_ajoin.c:1833: error: Syntaxfehler before "myRow"
ns_ajoin.c: In Funktion »fill_chan_info«:
ns_ajoin.c:1838: error: `myRow' undeclared (first use in this function)
ns_ajoin.c: Auf höchster Ebene:
ns_ajoin.c:1851: error: Syntaxfehler before "myRow"
ns_ajoin.c: In Funktion »fill_ajoin_info«:
ns_ajoin.c:1855: error: `myRow' undeclared (first use in this function)
ns_ajoin.c: In Funktion »group_info_ids«:
ns_ajoin.c:1870: error: `MYSQL_RES' undeclared (first use in this function)
ns_ajoin.c:1870: error: `myResult' undeclared (first use in this function)
ns_ajoin.c:1871: error: `MYSQL_ROW' undeclared (first use in this function)
ns_ajoin.c:1871: error: Syntaxfehler before "myRow"
ns_ajoin.c:1887: Warnung: implicit declaration of function `mysql_store_result'
ns_ajoin.c:1889: Warnung: implicit declaration of function `mysql_num_rows'
ns_ajoin.c:1898: error: `myRow' undeclared (first use in this function)
ns_ajoin.c:1898: Warnung: implicit declaration of function `mysql_fetch_row'
ns_ajoin.c: In Funktion »get_ajoin_info«:
ns_ajoin.c:1922: error: `MYSQL_RES' undeclared (first use in this function)
ns_ajoin.c:1922: error: `myResult' undeclared (first use in this function)
ns_ajoin.c:1923: error: `MYSQL_ROW' undeclared (first use in this function)
ns_ajoin.c:1923: error: Syntaxfehler before "myRow"
ns_ajoin.c:1934: error: `myRow' undeclared (first use in this function)
ns_ajoin.c:1946: Warnung: implicit declaration of function `mysql_free_result'
ns_ajoin.c: In Funktion »get_ajoin_list«:
ns_ajoin.c:1959: error: `MYSQL_RES' undeclared (first use in this function)
ns_ajoin.c:1959: error: `myResult' undeclared (first use in this function)
ns_ajoin.c:1960: error: `MYSQL_ROW' undeclared (first use in this function)
ns_ajoin.c:1960: error: Syntaxfehler before "myRow"
ns_ajoin.c:1968: error: `myRow' undeclared (first use in this function)
ns_ajoin.c:1979:1: nicht beendeter Kommentar
ns_ajoin.c:1986:26: Warnung: Kein Newline am Dateiende
make[1]: *** [ns_ajoin.o] Fehler 1
make[1]: Leaving directory `/home/orangevirus/anope-1.7.13/src/modules'
make: *** [modules] Fehler 2
orangevirus@debian:~/anope-1.7.13$


thx for any help
Logged

Dave Robson

  • Team
  • *
  • Offline Offline
  • Posts: 357
(No subject)
« Reply #1 on: March 08, 2006, 05:31:16 PM »

This module appears to require mysql...
Logged

black-drag0n

  • Guest
(No subject)
« Reply #2 on: March 08, 2006, 07:26:23 PM »

mysql is installed on this server ^^
Logged

lonewolf

  • Guest
(No subject)
« Reply #3 on: March 08, 2006, 09:05:19 PM »

Is anope compiled with mysql support?
Is mysql enabled in your services.conf?
Are the databases made in your database?
Logged

Tzann

  • Anope User
  • Offline Offline
  • Posts: 6
Re: ns_ajoin.c
« Reply #4 on: April 07, 2009, 05:36:53 PM »

Oook, it took a bit, but now I've added toLower for Channelnames and mysql_real_escape_string for Channelnames and Nicknames.

Source:
Code: [Select]
#include "module.h"
#include <mysql.h>

#define AUTHOR "Tzann"
#define VERSION "1.3"

// SQL
#define GET_MYSQL_ERROR      mysql_error(mysql_obj)
MYSQL *mysql_obj = NULL;
MYSQL_RES *res = NULL;
my_ulonglong q_mysql_affected_rows;

char *NICK_SQL_HOST = NULL;
unsigned int NICK_SQL_PORT = 0;
char *NICK_SQL_USER = NULL;
char *NICK_SQL_PASS = NULL;
char *NICK_SQL_DB = NULL;

// intern struct
struct c_userlist *cu, *next;
unsigned int i;

// Events
int reload_config(int ac, char **av);
int channels_update(int ac, char **av);
int user_quit(int ac, char **av);

// Methods
int load_config();
int channel_update(char *chan);

// SQL
int do_mysql_connect();
int do_mysql_query(char *q);
void do_mysql_close();

//Helper
char *lower(char *str);
char *esc_str(char *str);

int AnopeInit(void)
{
EvtHook *hook;
unsigned int ret;

moduleAddAuthor(AUTHOR);
moduleAddVersion(VERSION);

hook = createEventHook(EVENT_JOIN_CHANNEL, channels_update);
if (moduleAddEventHook(hook) != MOD_ERR_OK)
return MOD_STOP;

hook = createEventHook(EVENT_PART_CHANNEL, channels_update);
if (moduleAddEventHook(hook) != MOD_ERR_OK)
return MOD_STOP;

hook = createEventHook(EVENT_CHANGE_NICK, channels_update);
if (moduleAddEventHook(hook) != MOD_ERR_OK)
return MOD_STOP;

hook = createEventHook(EVENT_USER_LOGOFF, user_quit);
if (moduleAddEventHook(hook) != MOD_ERR_OK)
return MOD_STOP;

hook = createEventHook(EVENT_CHAN_DROP, channels_update);
if (moduleAddEventHook(hook) != MOD_ERR_OK)
return MOD_STOP;

hook = createEventHook(EVENT_CHAN_EXPIRE, channels_update);
if (moduleAddEventHook(hook) != MOD_ERR_OK)
return MOD_STOP;

hook = createEventHook(EVENT_NICK_LOGOUT, channels_update);
if (moduleAddEventHook(hook) != MOD_ERR_OK)
return MOD_STOP;

hook = createEventHook(EVENT_RELOAD, reload_config);
if (moduleAddEventHook(hook) != MOD_ERR_OK)
return MOD_STOP;

if (load_config() == MOD_STOP) return MOD_STOP;

if (do_mysql_connect() == MOD_STOP)
{
alog("[\002cs_nicklist\002] Can't connect to MySQL server");
return MOD_STOP;
}

ret = do_mysql_query("CREATE TABLE IF NOT EXISTS channels"
"(chan char(50),"
"user char(50))");

if(ret == MOD_STOP)
return MOD_STOP;

alog("[\002cs_nicklist\002]: loaded . . . [Author: \002%s\002] [Version: \002%s\002]", AUTHOR, VERSION);

return MOD_CONT;
}

int load_config(void)
{
Directive confvalues[][1] = {
{{ "NickMysqlHost",       { { PARAM_STRING, PARAM_RELOAD, &NICK_SQL_HOST       } } }},
{{ "NickMysqlPort",       { { PARAM_PORT,   PARAM_RELOAD, &NICK_SQL_PORT       } } }},
{{ "NickMysqlUser",       { { PARAM_STRING, PARAM_RELOAD, &NICK_SQL_USER       } } }},
{{ "NickMysqlPass",   { { PARAM_STRING, PARAM_RELOAD, &NICK_SQL_PASS       } } }},
{{ "NickMysqlName",   { { PARAM_STRING, PARAM_RELOAD, &NICK_SQL_DB         } } }}
};

NICK_SQL_PORT = 3306;
if (NICK_SQL_HOST) { free(NICK_SQL_HOST); NICK_SQL_HOST = NULL; }
if (NICK_SQL_USER) { free(NICK_SQL_USER); NICK_SQL_USER = NULL; }
if (NICK_SQL_PASS) { free(NICK_SQL_PASS); NICK_SQL_PASS = NULL; }
if (NICK_SQL_DB)   { free(NICK_SQL_DB);   NICK_SQL_DB = NULL;   }

i = 0;
for (i = 0; i < 5; i++)
{
moduleGetConfigDirective(confvalues[i]);
}

return MOD_CONT;
}

int reload_config(int ac, char **av)
{
  if (ac >= 1)
  {
    if (!stricmp(av[0], EVENT_START))
    {
      alog("[\002cs_nicklist\002]: Reloading configuration directives...");
      return load_config();
    }
  }
  return MOD_CONT;
}

void AnopeFini(void)
{
if (NICK_SQL_HOST) { free(NICK_SQL_HOST); NICK_SQL_HOST = NULL; }
if (NICK_SQL_USER) { free(NICK_SQL_USER); NICK_SQL_USER = NULL; }
if (NICK_SQL_PASS) { free(NICK_SQL_PASS); NICK_SQL_PASS = NULL; }
if (NICK_SQL_DB)   { free(NICK_SQL_DB);   NICK_SQL_DB = NULL;   }

do_mysql_close();

alog("[\002cs_nicklist\002]: Modul unloaded");
}

int channels_update(int ac, char **av)
{
FILE *file;

Channel *c;
ChannelInfo *ci;

    int carryon = 0;
    int i;

carryon = 0;
do_mysql_query("DELETE FROM channels;");
for(i = 0; i < 1024; i++)
{
for(c = chanlist[i]; c; c = c->next)
{
channel_update(c->name);
}
}

return MOD_CONT;
}

int user_quit(int ac, char **av)
{
char query[200];
snprintf(query, 200, "DELETE FROM channels WHERE (user=\"%s\");",esc_str(av[0]));
do_mysql_query(query);

return 1;
}

int channel_update(char *chan)
{
Channel *c;
char query[200];

c = findchan(chan);
cu = c->users;
while (cu)
{
next = cu->next;

snprintf(query, 200, "INSERT INTO channels(chan,user) VALUES (\"%s\",\"%s\");",esc_str(lower(c->name)),esc_str(cu->user->nick));
do_mysql_query(query);

cu = next;
}

return 1;
}

int do_mysql_connect()
{
mysql_obj = mysql_init(NULL);

if(mysql_real_connect(mysql_obj, NICK_SQL_HOST, NICK_SQL_USER, NICK_SQL_PASS, NICK_SQL_DB, 3306, NULL, 0) == NULL)
{
alog("[\002cs_nicklist\002]: mysql_real_connect FAILED!");
return MOD_STOP;
}

return MOD_CONT;
}

int do_mysql_query(char *q)
{
char log[300];
unsigned querysize = 0;

querysize = (unsigned) strlen(q);

//snprintf(log, 300, "Query: \"%s\" (%i)",q,querysize);
//alog(log);

if (mysql_real_query(mysql_obj, q, querysize)) {
alog("[\002cs_nicklist\002]: mysql_real_query FAILED!");
return MOD_STOP;
}
if(res != NULL)
{
mysql_free_result(res);
res = NULL;
}

res = mysql_store_result(mysql_obj);

return MOD_CONT;
}

void do_mysql_close()
{
if (res)
{
mysql_free_result(res);
res = NULL;
}
mysql_close(mysql_obj);
}

char *lower(char *str)
{
char *toRet = str;
for(i = 0; i < strlen(toRet); i++)
toRet[i] = tolower(toRet[i]);
return toRet;
}

char *esc_str(char *str)
{
char *toRet = (char *) malloc(strlen(str) * 2 + 1);
mysql_real_escape_string(mysql_obj, toRet, str, strlen(str));
return toRet;
}
Logged

Jan Milants

  • Team
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 1372
Re: ns_ajoin.c
« Reply #5 on: April 07, 2009, 05:50:29 PM »

this thread is old.. there is a much newer version of ns_ajoin (ns_ajoin_db) which doesn't require a MySQL DB but instead uses a .db file to store data.. unless you want the SQL backend it might be preferable :)
Logged
If you like me donate coins to 1FBmZVT4J8WAUMHKqpWhgNVj3XXnRN1cCk :)
Pages: [1]   Go Up