Kaynağa Gözat

* Port [3239] to 1.2.14
* Port over bdlib::base64


svn: 3240

Bryan Drewery 19 yıl önce
ebeveyn
işleme
7bf2529945

+ 1 - 1
autotools/configure.ac

@@ -158,7 +158,7 @@ EGG_SUBST_VERSION
 EGG_SUBST_MOD_UPDIR
 DO_DEPS
 
-AC_CONFIG_FILES([Makefile src/Makefile src/compat/Makefile src/crypto/Makefile src/mod/Makefile src/buildinfo.h])
+AC_CONFIG_FILES([Makefile src/Makefile src/compat/Makefile src/bdlib/Makefile src/crypto/Makefile src/mod/Makefile src/buildinfo.h])
 AC_OUTPUT
 
 AH_TEMPLATE(HAVE_ST_MTIM, [Define to 1 if your struct stat has an st_mtim member])

+ 1 - 1
autotools/includes/depend.m4

@@ -19,7 +19,7 @@ AC_SUBST(GCC3)dnl
 
 AC_DEFUN([DO_DEPS],
 [
-files="src/Makefile.in src/compat/Makefile.in src/crypto/Makefile.in src/mod/channels.mod/Makefile src/mod/compress.mod/Makefile src/mod/console.mod/Makefile src/mod/ctcp.mod/Makefile src/mod/irc.mod/Makefile src/mod/server.mod/Makefile src/mod/share.mod/Makefile src/mod/transfer.mod/Makefile src/mod/update.mod/Makefile"
+files="src/Makefile.in src/compat/Makefile.in src/bdlib/Makefile.in src/crypto/Makefile.in src/mod/channels.mod/Makefile src/mod/compress.mod/Makefile src/mod/console.mod/Makefile src/mod/ctcp.mod/Makefile src/mod/irc.mod/Makefile src/mod/server.mod/Makefile src/mod/share.mod/Makefile src/mod/transfer.mod/Makefile src/mod/update.mod/Makefile"
 for mf in $files; do
   # Strip MF so we end up with the name of the file.
 #  echo "MF: $mf"

+ 3 - 2
configure

@@ -11860,7 +11860,7 @@ case "$srcdir" in
 esac
 
 
-files="src/Makefile.in src/compat/Makefile.in src/crypto/Makefile.in src/mod/channels.mod/Makefile src/mod/compress.mod/Makefile src/mod/console.mod/Makefile src/mod/ctcp.mod/Makefile src/mod/irc.mod/Makefile src/mod/server.mod/Makefile src/mod/share.mod/Makefile src/mod/transfer.mod/Makefile src/mod/update.mod/Makefile"
+files="src/Makefile.in src/compat/Makefile.in src/bdlib/Makefile.in src/crypto/Makefile.in src/mod/channels.mod/Makefile src/mod/compress.mod/Makefile src/mod/console.mod/Makefile src/mod/ctcp.mod/Makefile src/mod/irc.mod/Makefile src/mod/server.mod/Makefile src/mod/share.mod/Makefile src/mod/transfer.mod/Makefile src/mod/update.mod/Makefile"
 for mf in $files; do
   # Strip MF so we end up with the name of the file.
 #  echo "MF: $mf"
@@ -11919,7 +11919,7 @@ echo X"$mf" |
 done
 
 
-ac_config_files="$ac_config_files Makefile src/Makefile src/compat/Makefile src/crypto/Makefile src/mod/Makefile src/buildinfo.h"
+ac_config_files="$ac_config_files Makefile src/Makefile src/compat/Makefile src/bdlib/Makefile src/crypto/Makefile src/mod/Makefile src/buildinfo.h"
 
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -12477,6 +12477,7 @@ do
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
     "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
     "src/compat/Makefile") CONFIG_FILES="$CONFIG_FILES src/compat/Makefile" ;;
+    "src/bdlib/Makefile") CONFIG_FILES="$CONFIG_FILES src/bdlib/Makefile" ;;
     "src/crypto/Makefile") CONFIG_FILES="$CONFIG_FILES src/crypto/Makefile" ;;
     "src/mod/Makefile") CONFIG_FILES="$CONFIG_FILES src/mod/Makefile" ;;
     "src/buildinfo.h") CONFIG_FILES="$CONFIG_FILES src/buildinfo.h" ;;

+ 7 - 2
src/Makefile.in

@@ -94,11 +94,11 @@ stringfix: stringfix.c common.h ../config.h eggdrop.h
 	@$(CXX) $(CXXFLAGS) -I$(top_srcdir) -I$(top_srcdir)/pack $(CPPFLAGS) stringfix.c -o stringfix
 	@$(STRIP) stringfix@EXEEXT@
 
-../$(EGGEXEC): build_msg $(OBJS) mycrypto compatability
+../$(EGGEXEC): build_msg $(OBJS) mycrypto compatability mybdlib
 	@echo ""
 	@echo "Linking wraith... $(EGGBUILD)"
 	@echo ""
-	$(LD) -o ../$(EGGEXEC) $(OBJS) $(MODOBJS) $(LIBS) compat/*.o crypto/*.o
+	$(LD) -o ../$(EGGEXEC) $(OBJS) $(MODOBJS) $(LIBS) compat/*.o crypto/*.o bdlib/*.o
 	@$(STRIP) ../$(EGGEXEC)
 	@$(OBJCOPY) ../$(EGGEXEC)
 	@echo "Successful compile: $(EGGEXEC)"
@@ -117,6 +117,11 @@ compatability:
 	+@cd compat && $(MAKE_GENERIC) compat
 	@echo "[*] Linking"
 
+mybdlib:
+	@echo "[*] Compiling BDLIB components"
+	+@cd bdlib && $(MAKE_GENERIC) bdlib
+	@echo "[*] Linking"
+
 mycrypto:
 	@echo "[*] Compiling crypto"
 	+@cd crypto && $(MAKE_GENERIC) crypto

+ 41 - 0
src/bdlib/Makefile.in

@@ -0,0 +1,41 @@
+
+top_srcdir = @top_srcdir@
+srcdir = @srcdir@
+
+SHELL = @SHELL@
+CXXFLAGS = @CXXFLAGS@ -I.. -I$(top_srcdir) -I$(top_srcdir)/pack @DEFS@ $(CFLGS)
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+LD = @CXX@
+STRIP = @STRIP@
+
+VPATH = @srcdir@
+depcomp = /bin/sh $(top_srcdir)/autotools/depcomp
+
+@SET_MAKE@
+
+OBJS = base64.o 
+
+doofus:
+	@echo ""
+	@echo "Let's try this from the right directory..."
+	@echo ""
+	@cd ../../.. && $(MAKE)
+
+clean:
+	@rm -f .depend *.o *~
+
+bdlib: $(OBJS)
+
+include ./.deps/includes
+
+.SUFFIXES:
+.SUFFIXES: .c .o .h
+
+.c.o:
+	@echo -e "Compiling: \033[1m`basename $< .c`\033[0m"
+	source='$<' object='$@' depfile='.deps/$*.Po' tmpdepfile='.deps/$*.TPo' depmode=$(CCDEPMODE) $(depcomp) \
+	$(CXX) $(CXXFLAGS) -I../.. -I$(top_srcdir) -I$(top_srcdir)/src $(CPPFLAGS) -c $<
+
+
+

+ 171 - 0
src/bdlib/base64.c

@@ -0,0 +1,171 @@
+/* base64.c
+ *
+ * Copyright (C) Bryan Drewery
+ *
+ * This program is private and may not be distributed, modified
+ * or used without express permission of Bryan Drewery.
+ *
+ * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY.
+ * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
+ * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
+ * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
+ * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
+ * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS.
+ *
+ */
+
+#ifndef lint
+#endif                          /* lint */
+
+#include <cstdlib>
+#include "base64.h"
+
+BDLIB_NS_BEGIN
+
+#define NUM_ASCII_BYTES (3)
+#define NUM_ENCODED_BYTES (4)
+#define PADDING_CHAR '='
+
+static const char b64_charset[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";;
+static const signed char b64_indexes[256] = {
+  /* 0 - 31 / 0x00 - 0x1f */
+  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+  -1,
+  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+      /* 32 - 63 / 0x20 - 0x3f */
+      , -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63  /* ... , '+', ... '/' */
+      , 52, 53, 54, 55, 56, 57, 58, 59  /* '0' - '7' */
+      , 60, 61, -1, -1, -1, -1, -1, -1  /* '8', '9', ... */
+      /* 64 - 95 / 0x40 - 0x5f */
+      , -1, 0, 1, 2, 3, 4, 5, 6 /* ..., 'A' - 'G' */
+      , 7, 8, 9, 10, 11, 12, 13, 14     /* 'H' - 'O' */
+      , 15, 16, 17, 18, 19, 20, 21, 22  /* 'P' - 'W' */
+      , 23, 24, 25, -1, -1, -1, -1, -1  /* 'X', 'Y', 'Z', ... */
+      /* 96 - 127 / 0x60 - 0x7f */
+      , -1, 26, 27, 28, 29, 30, 31, 32  /* ..., 'a' - 'g' */
+      , 33, 34, 35, 36, 37, 38, 39, 40  /* 'h' - 'o' */
+      , 41, 42, 43, 44, 45, 46, 47, 48  /* 'p' - 'w' */
+      , 49, 50, 51, -1, -1, -1, -1, -1  /* 'x', 'y', 'z', ... */
+      , -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+  -1,
+  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+  -1, -1
+};
+
+void b64enc_buf(const unsigned char *data, size_t *len, char *dest)
+{
+  char *buf = dest;
+
+  /* Encode 3 bytes at a time. */
+
+  /*
+   *
+   * |       0       |       1       |       2       |
+   *
+   * |               |               |               |
+   * |       |       |       |       |       |       |
+   * |   |   |   |   |   |   |   |   |   |   |   |   |
+   * | | | | | | | | | | | | | | | | | | | | | | | | |
+   *  7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
+   * -------------------------------------------------
+   *  5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0 
+   * | | | | | | | | | | | | | | | | | | | | | | | | |
+   * |   | | |   |   | | |   |   | | |   |   | | |   |
+   * |     |     |     |     |     |     |     |     |
+   * |           |           |           |           |
+   *
+   * |     0     |     1     |     2     |     3     |
+   *
+   */
+
+
+  while (*len >= NUM_ASCII_BYTES) {
+    /* buf[0] is the 6 left-most bits of data[0] */
+    buf[0] = b64_charset[(data[0] & 0xfc) >> 2];
+    /* buf[1] is the right-most 2 bits of data[0] and the left-most 4 bits of data[1] */
+    buf[1] = b64_charset[((data[0] & 0x03) << 4) | ((data[1] & 0xf0) >> 4)];
+    /* buf[2] is the right-most 4 bits of data[1] and the 2 left-most bits of data[2] */
+    buf[2] = b64_charset[((data[1] & 0x0f) << 2) | ((data[2] & 0xc0) >> 6)];
+    /* buf[3] is the right-most 6 bits of data[2] */
+    buf[3] = b64_charset[data[2] & 0x3f];
+
+    data += NUM_ASCII_BYTES;
+    buf += NUM_ENCODED_BYTES;
+    *len -= NUM_ASCII_BYTES;
+  }
+
+  /* There is either 1 or 2 bytes left to encode (and possibly some padding to add) */
+  if (*len > 0) {
+    buf[0] = b64_charset[(data[0] & 0xfc) >> 2];
+    buf[1] = b64_charset[((data[0] & 0x03) << 4)];
+    if (*len > 1) {
+      /* Tack on to buf[1] the left-most 4 bits of data[1] */
+      buf[1] += (data[1] & 0xf0) >> 4;
+      buf[2] = b64_charset[(data[1] & 0x0f) << 2];
+    } else
+      buf[2] = PADDING_CHAR;
+    buf[3] = PADDING_CHAR;
+    buf += NUM_ENCODED_BYTES;
+  }
+
+  *len = buf - dest;
+}
+
+char *b64enc(const unsigned char *src, size_t *len)
+{
+  /* Take the length and round up the next 4-byte boundary */
+  size_t dlen = (((*len + (NUM_ASCII_BYTES - 1)) / NUM_ASCII_BYTES) * NUM_ENCODED_BYTES);
+  char *dest = (char *) malloc(dlen + 1);;
+
+  b64enc_buf(src, len, dest);
+  dest[*len] = '\0';
+  return dest;
+}
+
+void b64dec_buf(const unsigned char *data, size_t *len, char *dest)
+{
+  char *buf = dest;
+  size_t blocks = (*len / NUM_ENCODED_BYTES) + ((*len % NUM_ENCODED_BYTES) ? 1 : 0);
+
+  /* Convert the encoded base64 character back into our base255 ASCII character */
+  while (blocks > 0) {
+    /* buf[0] is the 6 bits from data[0] + left-most 2 bits of data[1] */
+    *buf++ = (b64_indexes[data[0]] << 2) + ((b64_indexes[data[1]] & 0x30) >> 4);  /* 0x30 not required but to be clear. */
+    if (data[2] != PADDING_CHAR) {
+      /* buf[1] is the right-most 4 bits of data[1] + left-most 4 bits of data[2] */
+      *buf++ = ((b64_indexes[data[1]] & 0x0f) << 4) + ((b64_indexes[data[2]] & 0x3c) >> 2);
+      if (data[3] != PADDING_CHAR) {
+        /* buf[2] is the right-most 2 bits of data[2] + data[3] */
+        *buf++ = ((b64_indexes[data[2]] & 0x03) << 6) + b64_indexes[data[3]];
+      }
+    }
+    data += NUM_ENCODED_BYTES;
+    --blocks;
+  }
+
+  *len = (buf - dest);
+}
+
+char *b64dec(const unsigned char *data, size_t *len)
+{
+  size_t dlen = ((*len / NUM_ENCODED_BYTES) + ((*len % NUM_ENCODED_BYTES) ? 1 : 0)) * NUM_ASCII_BYTES;
+  char *dest = (char *) malloc(dlen + 1);
+
+  b64dec_buf(data, len, dest);
+  dest[*len] = '\0';
+  return dest;
+}
+
+BDLIB_NS_END

+ 65 - 0
src/bdlib/base64.h

@@ -0,0 +1,65 @@
+/* Base64.h
+ *
+ * Copyright (C) Bryan Drewery
+ *
+ * This program is private and may not be distributed, modified
+ * or used without express permission of Bryan Drewery.
+ *
+ * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY.
+ * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
+ * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
+ * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
+ * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
+ * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS.
+ *
+ */
+#ifndef _W_BASE64_H
+#define _W_BASE64_H 1
+
+#include "bdlib.h"
+
+BDLIB_NS_BEGIN
+class Base64 {
+};
+
+/**
+  * @brief Encode a plaintext string into base64 (returns a buffer)
+  * @param src A c-style string to encode
+  * @param len Reference to length of string (to be updated on return)
+  * @return An encoded NULL-terminated c-style string (must be free()d later)
+  */
+char *b64enc(const unsigned char *src, size_t *len);
+
+/**
+  * @brief Encode a plaintext string into base64 (using a given buffer)
+  * @param data The c-style string to encode
+  * @param len Reference to length of string (to be updated on return)
+  * @param dest Reference to the buffer to encode into
+  */
+void b64enc_buf(const unsigned char *data, size_t *len, char *dest);
+
+/**
+  * @brief Decode a base64 encoded string into plaintext (returns a buffer)
+  * @param src A c-style string to decode
+  * @param len Reference to length of string (to be updated on return)
+  * @return A decoded NULL-terminated c-style string (must be free()d later)
+  */
+char *b64dec(const unsigned char *data, size_t *len);
+
+/**
+  * @brief Decode a base64 encoded string into plaintext (using a given buffer)
+  * @param data The c-style string to decode
+  * @param len Reference to length of string (to be updated on return)
+  * @param dest Reference to the buffer to decode into
+  */
+void b64dec_buf(const unsigned char *data, size_t *len, char *dest);
+
+BDLIB_NS_END
+#endif /* !_W_BASE64_H */ 

+ 43 - 0
src/bdlib/bdlib.h

@@ -0,0 +1,43 @@
+/* bdlib.h
+ *
+ * Copyright (C) Bryan Drewery
+ *
+ * This program is private and may not be distributed, modified
+ * or used without express permission of Bryan Drewery.
+ *
+ * THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY.
+ * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
+ * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ * ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
+ * DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
+ * IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
+ * NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+ * MODIFICATIONS.
+ *
+ */
+#ifndef _W_BDLIB_H
+#define _W_BDLIB_H 1
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+
+#define BDLIB_NS_BEGIN namespace bd {
+#define BDLIB_NS_END }
+#define BDLIB_NS bd
+
+#endif /* !_W_BDLIB_H */