From: pk910 Date: Tue, 9 Aug 2011 23:38:27 +0000 (+0200) Subject: *push* X-Git-Tag: v5.3~654 X-Git-Url: http://git.pk910.de/?a=commitdiff_plain;h=394d5d44953b5f09a7c0a8f2cd79b74191e8cd85;p=NeonServV5.git *push* --- diff --git a/ChanNode.h b/ChanNode.h index 63aadca..ead845a 100644 --- a/ChanNode.h +++ b/ChanNode.h @@ -10,7 +10,7 @@ struct ChanNode { struct ChanUser *user; struct ChanNode *next; -} +}; /* void init_UserNode(); diff --git a/ChanUser.h b/ChanUser.h index b5cdd33..8ca5b2b 100644 --- a/ChanUser.h +++ b/ChanUser.h @@ -17,6 +17,6 @@ struct ChanUser { struct ChanUser *next_user; struct ChanUser *next_chan; -} +}; #endif \ No newline at end of file diff --git a/ClientSocket.c b/ClientSocket.c index 002a633..5c81c04 100644 --- a/ClientSocket.c +++ b/ClientSocket.c @@ -1,6 +1,6 @@ #include "ClientSocket.h" -#include IRCParser.h +#include "IRCParser.h" struct socket_list { struct ClientSocket *data; @@ -22,13 +22,13 @@ static void init() { sockets->count = 0; } -struct ClientSocket* create_socket(char *host, int *port, char *pass, struct UserNode *user) { +struct ClientSocket* create_socket(char *host, int port, char *pass, struct UserNode *user) { if(sockets == NULL) init(); struct ClientSocket *client = malloc(sizeof(*client)); if (!client) { perror("malloc() failed"); - return; + return NULL; } client->host = strdup(host); client->port = port; @@ -38,16 +38,17 @@ struct ClientSocket* create_socket(char *host, int *port, char *pass, struct Use client->bufferpos = 0; client->next = sockets->data; sockets->data = client; + return client; } -int connect_socket(struct ClientSocket *socket) { - if((socket->flsgs & SOCKET_FLAG_CONNECTED)) return 1; +int connect_socket(struct ClientSocket *client) { + if((client->flags & SOCKET_FLAG_CONNECTED)) return 1; struct hostent *host; struct sockaddr_in addr; int sock; - if (!inet_aton(socket->host, &addr.sin_addr)) + if (!inet_aton(client->host, &addr.sin_addr)) { - host = gethostbyname(socket->host); + host = gethostbyname(client->host); if (!host) { herror("gethostbyname() failed"); @@ -62,7 +63,7 @@ int connect_socket(struct ClientSocket *socket) { return 0; } - addr.sin_port = htons(socket->port); + addr.sin_port = htons(client->port); addr.sin_family = AF_INET; if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) @@ -75,27 +76,27 @@ int connect_socket(struct ClientSocket *socket) { char sendBuf[512]; int len; - if(socket->pass) { - len = sprintf(sendBuf, "PASS :%s\n", socket->pass); - write_socket(sock, sendBuf, len); + if(client->pass) { + len = sprintf(sendBuf, "PASS :%s\n", client->pass); + write_socket(client, sendBuf, len); } - len = sprintf(sendBuf, "USER %s 0 0 :%s\n", socket->user->ident, socket->user->realname); - write_socket(sock, sendBuf, len); - len = sprintf(sendBuf, "NICK %s\n", socket->user->nick); - write_socket(sock, sendBuf, len); + len = sprintf(sendBuf, "USER %s 0 0 :%s\n", client->user->ident, client->user->realname); + write_socket(client, &sendBuf, len); + len = sprintf(sendBuf, "NICK %s\n", client->user->nick); + write_socket(client, &sendBuf, len); - socket->socket = sock; - socket->flags |= SOCKET_FLAG_CONNECTED; + client->sock = sock; + client->flags |= SOCKET_FLAG_CONNECTED; return 1; } -int close_socket(struct ClientSocket *socket) { - if(socket == NULL) return 0; - if((socket->flags & SOCKET_FLAG_CONNECTED)) - close(socket->sock); +int close_socket(struct ClientSocket *client) { + if(client == NULL) return 0; + if((client->flags & SOCKET_FLAG_CONNECTED)) + close(client->sock); struct ClientSocket *sock, *last_sock = NULL; for (sock = sockets->data; sock; sock = sock->next) { - if(sock == socket) { + if(sock == client) { if(last_sock) last_sock->next = sock->next; else @@ -104,19 +105,19 @@ int close_socket(struct ClientSocket *socket) { } else last_sock = sock; } - free(socket->host); - free(socket->pass); - free(socket); + free(client->host); + free(client->pass); + free(client); } -int write_socket(struct ClientSocket *socket, char* msg, int len) { - if(!(socket->flags & SOCKET_FLAG_CONNECTED)) return 0; +int write_socket(struct ClientSocket *client, char* msg, int len) { + if(!(client->flags & SOCKET_FLAG_CONNECTED)) return 0; printf("[send %d] %s", len, msg); - write(socket->sock, msg, len); + write(client->sock, msg, len); return 1; } -void socket_loop(int timeout) { +void socket_loop(int timeout_seconds) { if(sockets == NULL) return; fd_set fds; struct timeval timeout; @@ -130,7 +131,7 @@ void socket_loop(int timeout) { if(sock->sock > ret) ret = sock->sock; } - timeout.tv_sec = timeout; + timeout.tv_sec = timeout_seconds; timeout.tv_usec = 0; ret = select(ret + 1, &fds, NULL, NULL, &timeout); if(ret == 0) return; diff --git a/ClientSocket.h b/ClientSocket.h index 3fff1e8..dd8df54 100644 --- a/ClientSocket.h +++ b/ClientSocket.h @@ -22,12 +22,12 @@ struct ClientSocket { struct UserNode *user; struct ClientSocket *next; -} +}; -struct ClientSocket* create_socket(char *host, int *port, char *pass, struct UserNode *user); -int connect_socket(struct ClientSocket *socket); -int close_socket(struct ClientSocket *socket); -int write_socket(struct ClientSocket *socket, char* msg, int len); -void socket_loop(int timeout); +struct ClientSocket* create_socket(char *host, int port, char *pass, struct UserNode *user); +int connect_socket(struct ClientSocket *client); +int close_socket(struct ClientSocket *client); +int write_socket(struct ClientSocket *client, char* msg, int len); +void socket_loop(int timeout_seconds); #endif \ No newline at end of file diff --git a/IRCParser.c b/IRCParser.c index 22a9d95..4dc2da8 100644 --- a/IRCParser.c +++ b/IRCParser.c @@ -4,12 +4,16 @@ struct irc_cmd *irc_commands = NULL; +static void parse_line(struct ClientSocket *client, char *line); +static void register_irc_function(char *command, irc_cmd_t *func); +static void parse_raw(struct ClientSocket *client, char *from, char *cmd, char **argv, int argc); + int parse_lines(struct ClientSocket *client, char *lines, int len) { int i, startpos = 0; for(i = 0; i < len; i++) { - if(lines[i] == "\r") //just zero it out :D + if(*lines[i] == "\r") //just zero it out :D lines[i] = 0; - if(lines[i] == "\n") { + if(*lines[i] == "\n") { lines[i] = 0; parse_line(client, lines); startpos = i+1; @@ -22,7 +26,7 @@ int parse_lines(struct ClientSocket *client, char *lines, int len) { static void parse_line(struct ClientSocket *client, char *line) { int i = 0, argc = 0; char *argv[MAXNUMPARAMS]; - printf("[recv %s] %s", strlen(line), line); + printf("[recv %d] %s", strlen(line), line); if(line[0] == ':') i = 1; else @@ -59,12 +63,6 @@ static void register_irc_function(char *command, irc_cmd_t *func) { irc_commands = irc_cmd; } -void parser_init() { - - register_irc_function("001", raw_001); - -} - static void parse_raw(struct ClientSocket *client, char *from, char *cmd, char **argv, int argc) { struct irc_cmd *irc_cmd; for(irc_cmd = irc_commands; irc_cmd; irc_cmd = irc_cmd->next) { @@ -80,4 +78,8 @@ static IRC_CMD(raw_001) { write_socket(client, "PRIVMSG Watchcat :hi\n", 21); } - +void parser_init() { + + register_irc_function("001", raw_001); + +} diff --git a/IRCParser.h b/IRCParser.h index dfeee06..65d4765 100644 --- a/IRCParser.h +++ b/IRCParser.h @@ -13,7 +13,7 @@ struct irc_cmd { char *cmd; irc_cmd_t *func; struct irc_cmd *next; -} +}; int parse_lines(struct ClientSocket *client, char *lines, int len); void parser_init(); diff --git a/UserNode.c b/UserNode.c index 0e50b58..f6044ce 100644 --- a/UserNode.c +++ b/UserNode.c @@ -21,9 +21,9 @@ int is_valid_nick(const char *nick) { return 1; } -static int get_nicklist_entry(const char *nick) { +static int get_nicklist_entry(int nick) { int i; - char valid_chars = VALID_NICK_CHARS_FIRST; + char *valid_chars = VALID_NICK_CHARS_FIRST; for(i = 0; i < VALID_NICK_CHARS_FIRST_LEN; i++) { if(valid_chars[i] == *nick) return i; @@ -32,7 +32,7 @@ static int get_nicklist_entry(const char *nick) { } struct UserNode* getUserByNick(const char *nick) { //case sensitive - int userListIndex = get_nicklist_entry(nick); + int userListIndex = get_nicklist_entry(*nick); if(userListIndex == -1 || userList[userListIndex] == NULL) return NULL; struct UserNode *user; @@ -51,7 +51,7 @@ struct UserNode* searchUserByNick(const char *nick) { //case insensitive struct UserNode *user; //search in the lower case "section" - userListIndex = get_nicklist_entry(tolower(nick)); + userListIndex = get_nicklist_entry(tolower(*nick)); if(userListIndex != -1 && userList[userListIndex] != NULL) { for(user = userList[userListIndex]; user; user = user->next) { if(!stricmp(nick, user->nick)) @@ -59,7 +59,7 @@ struct UserNode* searchUserByNick(const char *nick) { //case insensitive } } //search in the upper case "section" - userListIndex = get_nicklist_entry(toupper(nick)); + userListIndex = get_nicklist_entry(toupper(*nick)); if(userListIndex != -1 && userList[userListIndex] != NULL) { for(user = userList[userListIndex]; user; user = user->next) { if(!stricmp(nick, user->nick)) @@ -70,14 +70,14 @@ struct UserNode* searchUserByNick(const char *nick) { //case insensitive } struct UserNode* addUser(const char *nick) { - int userListIndex = get_nicklist_entry(nick); + int userListIndex = get_nicklist_entry(*nick); if(userListIndex == -1 || !is_valid_nick(nick)) return NULL; struct UserNode *user = malloc(sizeof(*user)); if (!user) { perror("malloc() failed"); - return; + return NULL; } strcpy(user->nick, nick); user->ident[0] = 0; @@ -96,7 +96,7 @@ int renameUser(struct UserNode* user, const char *new_nick) { strcpy(user->nick, new_nick); return 1; } - int userListIndex = get_nicklist_entry(new_nick); + int userListIndex = get_nicklist_entry(*new_nick); delUser(user, 0); strcpy(user->nick, new_nick); user->next = userList[userListIndex]; @@ -105,7 +105,7 @@ int renameUser(struct UserNode* user, const char *new_nick) { } void delUser(struct UserNode* user, int freeUser) { - int userListIndex = get_nicklist_entry(user->nick); + int userListIndex = get_nicklist_entry(user->nick[0]); if(userListIndex == -1) return; struct UserNode *cuser, *last_user = NULL; for(cuser = userList[userListIndex]; cuser; cuser = cuser->next) { diff --git a/UserNode.h b/UserNode.h index 229ac1b..a0e418f 100644 --- a/UserNode.h +++ b/UserNode.h @@ -14,7 +14,7 @@ struct UserNode { struct ChanUser *channel; struct UserNode *next; -} +}; void init_UserNode(); int is_valid_nick(const char *nick);