}
}
+void free_ChanNode() {
+ //kamikaze free all channels and chanusers
+ int i;
+ struct ChanNode *chan, *next;
+ struct ChanUser *chanuser, *next_chanuser;
+ for(i = 0; i < 47; i++) {
+ for(chan = chanList[i]; chan; chan = next) {
+ next = chan->next;
+ for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = next_chanuser) {
+ next_chanuser = getChannelUsers(chan, chanuser);
+ free(chanuser);
+ }
+ freeChanNode(chan);
+ }
+ }
+ free(chanList);
+}
+
int is_valid_chan(const char *name) {
unsigned int ii;
if (*name !='#')
};
void init_ChanNode();
+void free_ChanNode();
int is_valid_chan(const char *name);
struct ChanNode* getChanByName(const char *name);
struct ChanNode* addChannel(const char *chan);
static struct socket_list *sockets = NULL;
static char buffer[BUF_SIZ];
-static void init() {
+static void init_sockets() {
sockets = malloc(sizeof(*sockets));
if (!sockets)
{
}
struct ClientSocket* create_socket(char *host, int port, char *pass, struct UserNode *user) {
- if(sockets == NULL) init();
+ if(sockets == NULL) init_sockets();
struct ClientSocket *client = malloc(sizeof(*client));
if (!client)
{
}
return NULL;
}
+
+void free_sockets() {
+ if(!sockets) return;
+ struct ClientSocket *client, *next;
+ for (client = sockets->data; client; client = next) {
+ next = client->next;
+ if((client->flags & SOCKET_FLAG_CONNECTED))
+ close(client->sock);
+ free(client->host);
+ free(client->pass);
+ free(client);
+ }
+ free(sockets);
+ sockets = NULL;
+}
void socket_loop(int timeout_seconds);
void putsock(struct ClientSocket *client, const char *text, ...) PRINTF_LIKE(2, 3);
struct ClientSocket* getBots(int flags, struct ClientSocket* last_bot);
+void free_sockets();
#endif
\ No newline at end of file
binds = calloc(TOTAL_BIND_TYPES, sizeof(*binds));
}
+void free_bind() {
+ struct binding *cbind, *next;
+ int i;
+ for(i = 0; i < TOTAL_BIND_TYPES; i++) {
+ for(cbind = binds[i]; cbind; cbind = next) {
+ next = cbind->next;
+ free(cbind);
+ }
+ }
+ free(binds);
+}
+
static int is_bound(unsigned char type, void *func) {
struct binding *cbind;
for(cbind = binds[type]; cbind; cbind = cbind->next) {
struct ClientSocket;
void init_bind();
+void free_bind();
typedef void join_func_t(struct ChanUser *chanuser);
int bind_join(join_func_t *func);
return 1;
}
-void parser_init() {
+void init_parser() {
//all the raws we receive...
register_irc_function("001", raw_001);
register_irc_function("324", raw_324);
register_irc_function("PING", raw_ping);
register_irc_function("PRIVMSG", raw_privmsg);
}
+
+void free_parser() {
+ struct irc_cmd *cmd, *next;
+ for(cmd = irc_commands; cmd; cmd = next) {
+ next = cmd->next;
+ free(cmd);
+ }
+}
+
int parse_lines(struct ClientSocket *client, char *lines, int len);
void bot_disconnect(struct ClientSocket *client);
-void parser_init();
+void init_parser();
+void free_parser();
#endif
\ No newline at end of file
gcc -g -O2 -I. -c ChanUser.c -o ChanUser.o ${CFLAGS}
gcc -g -O2 -I. -c WHOHandler.c -o WHOHandler.o ${CFLAGS}
gcc -g -O2 -I. -c modcmd.c -o modcmd.o ${CFLAGS}
+ gcc -g -O2 -I. -c bots.c -o bots.o ${CFLAGS}
install:
gcc -g -O0 -I. -o neonserv *.o ${CFLAGS}
userList = calloc(VALID_NICK_CHARS_FIRST_LEN+1, sizeof(*userList));
}
+void free_UserNode() {
+ //kamikaze free all users
+ //chanusers will be destroyed in free_ChanNode()
+ int i;
+ struct UserNode *user, *next;
+ for(i = 0; i < VALID_NICK_CHARS_FIRST_LEN+1; i++) {
+ for(user = userList[i]; user; user = next) {
+ next = user->next;
+ free(user);
+ }
+ }
+ free(userList);
+}
+
int is_valid_nick(const char *nick) {
unsigned int i;
//first char must be one of: a-zA-Z{|}~[\]^_`
};
void init_UserNode();
+void free_UserNode();
int is_valid_nick(const char *nick);
struct UserNode* getUserByNick(const char *nick);
struct UserNode* getUserByMask(const char *mask);
}
free(entry);
}
+
+void free_whoqueue() {
+ struct WHOQueueEntry *entry, *next;
+ for(entry = first_entry; entry; entry = next) {
+ next = entry->next
+ free(entry);
+ }
+ first_entry = NULL;
+ last_entry = NULL;
+}
void recv_whohandler_354(struct ClientSocket *client, char **argv, unsigned int argc);
void recv_whohandler_315(struct ClientSocket *client, char **argv, unsigned int argc);
void get_userlist(struct ChanNode *chan, userlist_callback_t callback, void *data);
+void free_whoqueue();
#endif
\ No newline at end of file
--- /dev/null
+
+#include "bots.h"
+
+void init_bots() {
+
+}
+
+void free_bots() {
+
+}
--- /dev/null
+#ifndef _bots_h
+#define _bots_h
+
+#include "main.h"
+
+void init_bots();
+void free_bots();
+
+#endif
\ No newline at end of file
#include "IRCEvents.h"
#include "IRCParser.h"
#include "modcmd.h"
+#include "WHOHandler.h"
+#include "bots.h"
void just_test_it() {
struct UserNode *user;
connect_socket(client);
}
+void cleanup() {
+ free_sockets();
+ free_parser();
+ free_UserNode();
+ free_ChanNode();
+ free_bind();
+ free_modcmd();
+ free_whoqueue();
+ free_bots();
+}
+
int main(void)
{
- parser_init();
+ init_parser();
init_UserNode();
init_ChanNode();
init_bind();
init_modcmd();
+ init_bots();
just_test_it();
time_t socket_wait;
}
static void handle_command(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
+ if(message[0] == '#') {
+ char *chanName = message;
+ message = strstr(message, ' ');
+ if(!message) return;
+ *message = '\0';
+ message++;
+ struct ChanNode *chan2 = getChanByName(chanName);
+ if(chan2)
+ chan = chan2;
+ }
+ int bind_index = get_binds_index(message[0]);
+ char *args = strstr(message, " ");
+ if(args) {
+ *args = '\0';
+ args++;
+ }
+ struct cmd_binding *cbind;
+ for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+ if(cbind->botid == client->botid && strcmp(cbind->cmd, message) == 0) {
+ struct cmd_function *cmdfunc = cbind->func;
+ //parse the arguments...
+ char *argv[MAXNUMPARAMS];
+ int argc = 0;
+ while(*args) {
+ //skip leading spaces
+ while (*args == ' ')
+ *args++ = 0;
+ argv[argc++] = args;
+ if (argc >= MAXNUMPARAMS)
+ break;
+ while (*args != ' ' && *args)
+ args++;
+ }
+ if(argc != 0 && args[0][0] == '#') {
+ struct ChanNode *chan2 = getChanByName(args[0]);
+ if(chan2) {
+ argv += 1;
+ argc -= 1;
+ chan = chan2;
+ }
+ }
+ cmdfunc->func(client, user, chan, argv, argc);
+ return;
+ }
+ }
+
if(!strcmp(message, "users")) {
struct ChanUser *chanuser;
putsock(client, "PRIVMSG %s :[BOT JOIN] Users on this Channel:", chan->name);
bind_privmsg(got_privmsg);
}
+void free_modcmd() {
+ int i;
+ for(i = 0; i < 27; i++) {
+ struct cmd_binding *cbind, *next;
+ for(cbind = cmd_binds[i]; cbind; cbind = next) {
+ next = cbind->next;
+ free(cbind->cmd);
+ free(cbind);
+ }
+ }
+ free(cmd_binds);
+ struct cmd_function *cmdfunct, *next;
+ for(cmdfunct = cmd_functions; cmdfunct; cmdfunct = next) {
+ next = cmdfunct->next;
+ free(cmdfunct->name);
+ free(cmdfunct);
+ }
+ struct trigger_callback *cb, *next_cb;
+ for(cb = trigger_callbacks; cb; cb = next_cb) {
+ next_cb = cb->next;
+ free(next_cb);
+ }
+ cmd_functions = NULL;
+ trigger_callbacks = NULL;
+}
+
};
void init_modcmd();
+void free_modcmd();
struct ClientSocket* get_prefered_bot(int botid);
int register_command(int botid, char *name, cmd_bind_t *func);
int set_trigger_callback(int botid, trigger_callback_t *func);