added Makefile
[TransparentIRC.git] / src / UserClient.c
index c0d3af58daa4cf33e4cfaaebd0a8aee2325ce635..fccf56b1b563bff933b8ecc875a254df53302096 100644 (file)
@@ -14,8 +14,9 @@
  * You should have received a copy of the GNU General Public License 
  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
  */
-#include "UserClient.c"
+#include "UserClient.h"
 #include "IOHandler.h"
+#include "ServerSocket.h"
 
 static void userclient_callback(struct IOEvent *event);
 
@@ -30,14 +31,16 @@ void userclient_accepted(struct ServerSocket *server, int sockfd) {
     iohandler_update(iofd);
     client = malloc(sizeof(*client));
     client->iofd = iofd;
+    iofd->data = client;
     client->server = server;
     server->clientcount++;
     
     //add UserClient to the list
-    sock->prev = NULL;
-    sock->next = serversockets;
-    serversockets->prev = sock;
-    serversockets = sock;
+    client->prev = NULL;
+    client->next = userclients;
+    if(userclients)
+        userclients->prev = client;
+    userclients = client;
     
     //let's say hello to the client
     iohandler_printf(iofd, "NOTICE AUTH :*** TransparentIRC " TRANSIRC_VERSION " (use /quote transirc for more information)");
@@ -58,6 +61,7 @@ void userclient_close(struct UserClient *client) {
 void userclient_close_server(struct ServerSocket *server, int keep_clients) {
     struct UserClient *client, *next_client;
     for(client = userclients; client; client = next_client) {
+        next_client = client->next;
         if(client->server == server) {
             if(keep_clients)
                 client->server = NULL;
@@ -67,14 +71,20 @@ void userclient_close_server(struct ServerSocket *server, int keep_clients) {
     }
 }
 
+static void userclient_recv(struct UserClient *client, char *line) {
+    iohandler_printf(client->iofd, "reply: %s", line);
+}
+
 static void userclient_callback(struct IOEvent *event) {
+    struct UserClient *client = event->iofd->data;
     switch(event->type) {
         case IOEVENT_RECV:
-            char *line = event->data.recv_str;
-            iohandler_printf(event->iofd, "reply: %s", line);
+            userclient_recv(client, event->data.recv_str);
             break;
         case IOEVENT_CLOSED:
-            userclient_close(event->iofd);
+            userclient_close(client);
+            break;
+        default:
             break;
     }
 }