added some code
[NextIRCd.git] / src / ircd_sock.c
index 602282a35302caa16242da44181b0dee38c44329..259c74b84a851806a8e740d9d1d2aabeb2d834e1 100644 (file)
 #include "ircd_config.h"
 #include "ircd_sock.h"
 #include "ircd_client.h"
+#include "ircd_parse.h"
+#include "ircd_auth.h"
 #include "struct_connection.h"
+#include "struct_client.h"
+#include "struct_auth.h"
 
 #include "IOHandler/IOSockets.h"
 
 #include <stdlib.h>
 #include <string.h>
+#include <stdarg.h>
 #include <stdio.h> // @debug
 
 static struct Connection *sockets_listening = NULL;
@@ -134,7 +139,7 @@ static void sockets_accept_client(struct IOSocket *new_client, struct Connection
     new_client->data = connection;
     sockets_append_list(connection);
     
-    client_connected(connection);
+    auth_new(connection);
 }
 
 static CONFRELOAD_CALLBACK(sockets_config_reload) {
@@ -179,9 +184,13 @@ static IOSOCKET_CALLBACK(sockets_iohandler_callback) {
         sockets_remove_list(connection);
         if(connection->server) {
         
+        } else if(connection->authed) {
+                       connection->data.client->conn = NULL;
+            client_exit(connection->data.client, "Client disconnected.");
         } else {
-            client_disconnected(connection);
-        }
+                       connection->data.auth->conn = NULL;
+                       auth_abort(connection->data.auth);
+               }
         sockets_free_connection(connection);
         break;
     
@@ -190,17 +199,17 @@ static IOSOCKET_CALLBACK(sockets_iohandler_callback) {
             // listening socket could not be opened
         } else {
             sockets_remove_list(connection);
-            client_disconnected(connection);
             sockets_free_connection(connection);
         }
         break;
     
     case IOSOCKETEVENT_RECV:
-        if(connection->server) {
-            
-        } else {
-            client_recv(connection, event->data.recv_str);
-        }
+        if(connection->server)
+            parse_server_data(connection->data.server, event->data.recv_buf);
+        else if(connection->authed)
+            parse_client_data(connection->data.client, event->data.recv_str);
+        else
+                       parse_unauth_data(connection->data.auth, event->data.recv_str);
         break;
     
     default:
@@ -212,3 +221,27 @@ void socket_send(struct Connection *conn, char *data, int len) {
     iosocket_send(conn->socket, data, len);
 }
 
+void socket_printf(struct Connection *conn, const char *text, ...) {
+    va_list arg_list;
+       char sendBuf[512];
+       int pos;
+       sendBuf[0] = '\0';
+       va_start(arg_list, text);
+       pos = vsnprintf(sendBuf, 512 - 2, text, arg_list);
+       va_end(arg_list);
+       if (pos < 0 || pos > (512 - 2)) pos = 512 - 2;
+       sendBuf[pos] = '\n';
+    sendBuf[pos+1] = '\0';
+       iosocket_send(conn->socket, sendBuf, pos+1);
+}
+
+void socket_close(struct Connection *conn) {
+    iosocket_close(conn->socket);
+    sockets_free_connection(conn);
+}
+
+void socket_set_server(struct Connection *conn) {
+       struct IOSocket *iosock = conn->socket;
+       iosock->parse_delimiter = 0;
+       conn->server = 1;
+}