]> jfr.im git - solanum.git/blobdiff - src/irc_string.c
Functions replacement: ircd_baseXX_{en,de}code -> rb_baseXX_{en,de}code
[solanum.git] / src / irc_string.c
index a32c1ccbbe2bc6c09a7890c1c57945c1456f0a87..62cdc7ec410cafb0bd9c719cdbfa45a0d8634cdc 100644 (file)
@@ -34,7 +34,7 @@
 #define INADDRSZ 4
 #endif
 
-#ifdef IPV6
+#ifdef RB_IPV6
 #ifndef IN6ADDRSZ
 #define IN6ADDRSZ 16
 #endif
@@ -207,102 +207,6 @@ static const short base64_reverse_table[256] = {
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
 };
 
-unsigned char *
-ircd_base64_encode(const unsigned char *str, int length)
-{
-       const unsigned char *current = str;
-       unsigned char *p;
-       unsigned char *result;
-
-       if ((length + 2) < 0 || ((length + 2) / 3) >= (1 << (sizeof(int) * 8 - 2))) {
-               return NULL;
-       }
-
-       result = rb_malloc(((length + 2) / 3) * 5);
-       p = result;
-
-       while (length > 2) 
-       { 
-               *p++ = base64_table[current[0] >> 2];
-               *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
-               *p++ = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
-               *p++ = base64_table[current[2] & 0x3f];
-
-               current += 3;
-               length -= 3; 
-       }
-
-       if (length != 0) {
-               *p++ = base64_table[current[0] >> 2];
-               if (length > 1) {
-                       *p++ = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
-                       *p++ = base64_table[(current[1] & 0x0f) << 2];
-                       *p++ = base64_pad;
-               } else {
-                       *p++ = base64_table[(current[0] & 0x03) << 4];
-                       *p++ = base64_pad;
-                       *p++ = base64_pad;
-               }
-       }
-       *p = '\0';
-       return result;
-}
-
-unsigned char *
-ircd_base64_decode(const unsigned char *str, int length, int *ret)
-{
-       const unsigned char *current = str;
-       int ch, i = 0, j = 0, k;
-       unsigned char *result;
-       
-       result = rb_malloc(length + 1);
-
-       while ((ch = *current++) != '\0' && length-- > 0) {
-               if (ch == base64_pad) break;
-
-               ch = base64_reverse_table[ch];
-               if (ch < 0) continue;
-
-               switch(i % 4) {
-               case 0:
-                       result[j] = ch << 2;
-                       break;
-               case 1:
-                       result[j++] |= ch >> 4;
-                       result[j] = (ch & 0x0f) << 4;
-                       break;
-               case 2:
-                       result[j++] |= ch >>2;
-                       result[j] = (ch & 0x03) << 6;
-                       break;
-               case 3:
-                       result[j++] |= ch;
-                       break;
-               }
-               i++;
-       }
-
-       k = j;
-
-       if (ch == base64_pad) {
-               switch(i % 4) {
-               case 1:
-                       free(result);
-                       return NULL;
-               case 2:
-                       k++;
-               case 3:
-                       result[k++] = 0;
-               }
-       }
-       result[j] = '\0';
-
-       if(ret)
-               *ret = j;
-
-       return result;
-}
-
 /* 
  * From: Thomas Helvey <tomh@inxpress.net>
  */
@@ -398,7 +302,7 @@ inetntoa(const char *in)
  */
 
 static const char *inet_ntop4(const u_char * src, char *dst, unsigned int size);
-#ifdef IPV6
+#ifdef RB_IPV6
 static const char *inet_ntop6(const u_char * src, char *dst, unsigned int size);
 #endif
 
@@ -427,7 +331,7 @@ inet_ntop4(const unsigned char *src, char *dst, unsigned int size)
  * author:
  *     Paul Vixie, 1996.
  */
-#ifdef IPV6
+#ifdef RB_IPV6
 static const char *
 inet_ntop6(const unsigned char *src, char *dst, unsigned int size)
 {
@@ -539,15 +443,15 @@ inetpton_sock(const char *src, struct sockaddr *dst)
        {
                ((struct sockaddr_in *) dst)->sin_port = 0;
                ((struct sockaddr_in *) dst)->sin_family = AF_INET;
-               SET_SS_LEN((struct irc_sockaddr_storage *) dst, sizeof(struct sockaddr_in));
+               SET_SS_LEN((struct rb_sockaddr_storage *) dst, sizeof(struct sockaddr_in));
                return 1;
        }
-#ifdef IPV6
+#ifdef RB_IPV6
        else if(inetpton(AF_INET6, src, &((struct sockaddr_in6 *) dst)->sin6_addr))
        {
                ((struct sockaddr_in6 *) dst)->sin6_port = 0;
                ((struct sockaddr_in6 *) dst)->sin6_family = AF_INET6;
-               SET_SS_LEN((struct irc_sockaddr_storage *) dst, sizeof(struct sockaddr_in6));
+               SET_SS_LEN((struct rb_sockaddr_storage *) dst, sizeof(struct sockaddr_in6));
                return 1;
        }
 #endif
@@ -562,7 +466,7 @@ inetntop_sock(struct sockaddr *src, char *dst, unsigned int size)
        case AF_INET:
                return (inetntop(AF_INET, &((struct sockaddr_in *) src)->sin_addr, dst, size));
                break;
-#ifdef IPV6
+#ifdef RB_IPV6
        case AF_INET6:
                return (inetntop(AF_INET6, &((struct sockaddr_in6 *) src)->sin6_addr, dst, size));
                break;
@@ -588,7 +492,7 @@ inetntop(int af, const void *src, char *dst, unsigned int size)
        {
        case AF_INET:
                return (inet_ntop4(src, dst, size));
-#ifdef IPV6
+#ifdef RB_IPV6
        case AF_INET6:
                if(IN6_IS_ADDR_V4MAPPED((const struct in6_addr *) src) ||
                   IN6_IS_ADDR_V4COMPAT((const struct in6_addr *) src))
@@ -677,7 +581,7 @@ inet_pton4(src, dst)
        return (1);
 }
 
-#ifdef IPV6
+#ifdef RB_IPV6
 /* int
  * inet_pton6(src, dst)
  *     convert presentation level address to network order binary form.
@@ -803,7 +707,7 @@ inetpton(af, src, dst)
        {
        case AF_INET:
                return (inet_pton4(src, dst));
-#ifdef IPV6
+#ifdef RB_IPV6
        case AF_INET6:
                /* Somebody might have passed as an IPv4 address this is sick but it works */
                if(inet_pton4(src, dst))