added basic ssl support to ircu
[ircu2.10.12-pk.git] / ircd / packet.c
index bfeebfa284dc5417f3a5f5dbab428b47eea611b4..763440864ab2e84ef722f1656d45a25427c7d87e 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Id$
+ */
+/** @file
+ * @brief Input packet handling functions.
+ * @version $Id$
  */
 #include "config.h"
 
 #include "client.h"
 #include "ircd.h"
 #include "ircd_chattr.h"
+#include "ircd_log.h"
 #include "parse.h"
 #include "s_bsd.h"
 #include "s_misc.h"
 #include "send.h"
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 
+/** Add a certain number of bytes to a client's received statistics.
+ * @param[in,out] cptr Client to update.
+ * @param[in] length Number of newly received bytes to add.
+ */
 static void update_bytes_received(struct Client* cptr, unsigned int length)
 {
   cli_receiveB(&me)  += length;     /* Update bytes received */
   cli_receiveB(cptr) += length;
-
-  if (cli_receiveB(cptr) > 1023) {
-    cli_receiveK(cptr) += (cli_receiveB(cptr) >> 10);
-    cli_receiveB(cptr) &= 0x03ff;   /* 2^10 = 1024, 3ff = 1023 */
-  }
-  if (cli_receiveB(&me) > 1023) {
-    cli_receiveK(&me) += (cli_receiveB(&me) >> 10);
-    cli_receiveB(&me) &= 0x03ff;
-  }
 }
 
+/** Add one message to a client's received statistics.
+ * @param[in,out] cptr Client to update.
+ */
 static void update_messages_received(struct Client* cptr)
 {
   ++(cli_receiveM(&me));
   ++(cli_receiveM(cptr));
 }
 
-/*
- * dopacket
- *
- *    cptr - pointer to client structure for which the buffer data
- *           applies.
- *    buffer - pointer to the buffer containing the newly read data
- *    length - number of valid bytes of data in the buffer
- *
- *  Note:
- *    It is implicitly assumed that dopacket is called only
- *    with cptr of "local" variation, which contains all the
- *    necessary fields (buffer etc..)
+/** Handle received data from a directly connected server.
+ * @param[in] cptr Peer server that sent us data.
+ * @param[in] buffer Input buffer.
+ * @param[in] length Number of bytes in input buffer.
+ * @return 1 on success or CPTR_KILLED if the client is squit.
  */
 int server_dopacket(struct Client* cptr, const char* buffer, int length)
 {
   const char* src;
   char*       endp;
   char*       client_buffer;
-  
+
   assert(0 != cptr);
 
   update_bytes_received(cptr, length);
@@ -112,12 +106,18 @@ int server_dopacket(struct Client* cptr, const char* buffer, int length)
   return 1;
 }
 
+/** Handle received data from a new (unregistered) connection.
+ * @param[in] cptr Unregistered connection that sent us data.
+ * @param[in] buffer Input buffer.
+ * @param[in] length Number of bytes in input buffer.
+ * @return 1 on success or CPTR_KILLED if the client is squit.
+ */
 int connect_dopacket(struct Client *cptr, const char *buffer, int length)
 {
   const char* src;
   char*       endp;
   char*       client_buffer;
-  
+
   assert(0 != cptr);
 
   update_bytes_received(cptr, length);
@@ -150,18 +150,25 @@ int connect_dopacket(struct Client *cptr, const char *buffer, int length)
       /* Socket is dead so exit */
       if (IsDead(cptr))
         return exit_client(cptr, cptr, &me, cli_info(cptr));
+      else if (IsServer(cptr))
+      {
+        cli_count(cptr) = 0;
+        return server_dopacket(cptr, src, length);
+      }
       endp = client_buffer;
     }
     else if (endp < client_buffer + BUFSIZE)
       /* There is always room for the null */
-      ++endp;                   
+      ++endp;
   }
   cli_count(cptr) = endp - cli_buffer(cptr);
-  return 1;  
+  return 1;
 }
 
-/*
- * client_dopacket - handle client messages
+/** Handle received data from a local client.
+ * @param[in] cptr Local client that sent us data.
+ * @param[in] length Total number of bytes in client's input buffer.
+ * @return 1 on success or CPTR_KILLED if the client is squit.
  */
 int client_dopacket(struct Client *cptr, unsigned int length)
 {