*push*
authorpk910 <philipp@zoelle1.de>
Tue, 9 Aug 2011 23:38:27 +0000 (01:38 +0200)
committerpk910 <philipp@zoelle1.de>
Tue, 9 Aug 2011 23:38:27 +0000 (01:38 +0200)
ChanNode.h
ChanUser.h
ClientSocket.c
ClientSocket.h
IRCParser.c
IRCParser.h
UserNode.c
UserNode.h

index 63aadcaf5254b41565062358c35dbb58119f8ad7..ead845a0c456161b9067c05328dfdf4aff30e75d 100644 (file)
@@ -10,7 +10,7 @@ struct ChanNode {
     struct ChanUser *user;
     
     struct ChanNode *next;
-}
+};
 
 /*
 void init_UserNode();
index b5cdd336642236004e93fee51de9be313094786c..8ca5b2bf00bbc7fe1ee8b80a2bf2dbdb07d6ff98 100644 (file)
@@ -17,6 +17,6 @@ struct ChanUser {
     
     struct ChanUser *next_user;
     struct ChanUser *next_chan;
-}
+};
 
 #endif
\ No newline at end of file
index 002a633516f84713d7d480afc10dca972b28bed5..5c81c040e07390ebc65a82918b1720f78944a9b2 100644 (file)
@@ -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;
index 3fff1e87f66e4f062621d4779ebf2158a0b7398a..dd8df540a02e437ecb4e578ac4ca1fd3ca6c0c7e 100644 (file)
@@ -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
index 22a9d956232c6be70e5eb02b06b2271a923e228b..4dc2da8a12b11957d03b9f22cdc8f399845facc8 100644 (file)
@@ -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);
+    
+}
index dfeee068429c99801de62bb70e623db919d308f3..65d476520b232929dbf482bfc818aa5e14143090 100644 (file)
@@ -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();
index 0e50b58c3b1137ea01a816ff346fbefc5bfbcd24..f6044ceb45701fd10d841994e213192c279b958a 100644 (file)
@@ -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) {
index 229ac1b5fa04ea04d5a80b1c42d88e7992af8e73..a0e418f45a66448f3d628d242b4cf8135da17f6e 100644 (file)
@@ -14,7 +14,7 @@ struct UserNode {
     struct ChanUser *channel;
     
     struct UserNode *next;
-}
+};
 
 void init_UserNode();
 int is_valid_nick(const char *nick);