myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [3047] Code refactoring: the `base64Utils' global inst


From: Giuseppe Scrivano
Subject: [myserver-commit] [3047] Code refactoring: the `base64Utils' global instance was removed and some methods were renamed.
Date: Fri, 03 Apr 2009 08:26:25 +0000

Revision: 3047
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=3047
Author:   gscrivano
Date:     2009-04-03 08:26:24 +0000 (Fri, 03 Apr 2009)
Log Message:
-----------
Code refactoring: the `base64Utils' global instance was removed and some 
methods were renamed.

Modified Paths:
--------------
    trunk/myserver/include/base/base64/mime_utils.h
    trunk/myserver/src/base/base64/mime_utils.cpp
    trunk/myserver/src/protocol/http/http_headers.cpp
    trunk/myserver/tests/test_base64.cpp

Modified: trunk/myserver/include/base/base64/mime_utils.h
===================================================================
--- trunk/myserver/include/base/base64/mime_utils.h     2009-04-02 09:21:41 UTC 
(rev 3046)
+++ trunk/myserver/include/base/base64/mime_utils.h     2009-04-03 08:26:24 UTC 
(rev 3047)
@@ -1,7 +1,7 @@
 /* -*- mode: c++ -*- */
 /*
 MyServer
-Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
+Copyright (C) 2002, 2003, 2004, 2007, 2009 Free Software Foundation, Inc.
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
@@ -20,8 +20,6 @@
 #ifndef MIMEUTILS_H
 #define MIMEUTILS_H
 
-char* MimeDecodeMailHeaderField(char *s);
-
 class CBase64Utils
 {
 private:
@@ -30,23 +28,22 @@
        int GetLastError() {return ErrorCode;};
        CBase64Utils();
        ~CBase64Utils();
-       char* Decode(const char *in, int *bufsize);
-       char* Encode(const char *in, int bufsize);
+       char* decode(const char *in, int *bufsize);
+       char* encode(const char *in, int bufsize);
+  char* mimeDecodeMailHeaderField(char *s);
 };
 
 class CQPUtils
 {
 private:
-       char* ExpandBuffer(char *buffer, int UsedSize, int *BufSize, int 
SingleChar = 1);
+       char* expandBuffer(char *buffer, int UsedSize, int *BufSize, int 
SingleChar = 1);
        int ErrorCode;
 public:
-       int GetLastError() {return ErrorCode;};
-       char* Encode(char*in);
-       char* Decode(char*in);
+       int getLastError() {return ErrorCode;};
+       char* encode(char*in);
+       char* decode(char*in);
        CQPUtils();
        ~CQPUtils();
 }; 
 
-extern class CBase64Utils base64Utils;
 #endif
-

Modified: trunk/myserver/src/base/base64/mime_utils.cpp
===================================================================
--- trunk/myserver/src/base/base64/mime_utils.cpp       2009-04-02 09:21:41 UTC 
(rev 3046)
+++ trunk/myserver/src/base/base64/mime_utils.cpp       2009-04-03 08:26:24 UTC 
(rev 3047)
@@ -59,10 +59,6 @@
   delete [] cs;
   return result;
 }
-/*!
- *Unique instance of this class
- */
-CBase64Utils base64Utils;
 
 const char base64chars[] = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 #define SKIP '\202'
@@ -182,7 +178,7 @@
 
 
 
-char* MimeDecodeMailHeaderField(char *s)
+char* CBase64Utils::mimeDecodeMailHeaderField(char *s)
 {
 
   if (s == NULL) return s;
@@ -234,7 +230,7 @@
       s1 += pos;
       if (strlen(s1) < 4) return s;
       s1 += 3;
-      decodedText = qp.Decode(s1);
+      decodedText = qp.decode(s1);
     }
     if (strupos(s1, (char*) "?B?") > 0)
     {
@@ -245,7 +241,7 @@
       if (strlen(s1) < 4) return s; 
       s1 += 3;
       sLen = static_cast<int>(strlen(s1));
-      decodedText = bu.Decode(s1, &sLen);
+      decodedText = bu.decode(s1, &sLen);
     }
     alloclen =static_cast<int>(strlen(decodedText)) + 1;
     if (start != NULL) alloclen +=static_cast<int>(strlen(start));
@@ -280,7 +276,7 @@
 /*!
  *Decode a string using the Base64 codification
  */
-char* CBase64Utils::Encode(const char *input, int bufsize)
+char* CBase64Utils::encode(const char *input, int bufsize)
 {
   int alsize = ((bufsize * 4) / 3);
   char *finalresult = (char*)calloc(alsize + ((alsize / 76) * 2) + 
@@ -391,7 +387,7 @@
 /*!
  *Decode a Base64 coded string.
  */
-char* CBase64Utils::Decode(const char *input, int *bufsize)
+char* CBase64Utils::decode(const char *input, int *bufsize)
 {
   int std = 0, count = 1, resultlen = 0;
   char *finalresult = (char*)calloc(*bufsize + sizeof(char), sizeof(char));
@@ -470,7 +466,7 @@
 {
 
 }
-char* CQPUtils::Decode(char *input)
+char* CQPUtils::decode(char *input)
 {
   char *s = input;
   char *finalresult = (char*)calloc(strlen(input) + sizeof(char), 
@@ -532,7 +528,7 @@
 
 
 
-char* CQPUtils::ExpandBuffer(char *buffer, int UsedSize, int *BufSize, 
+char* CQPUtils::expandBuffer(char *buffer, int UsedSize, int *BufSize, 
                              int Singlechar)
 {
   int AddVal;
@@ -547,7 +543,7 @@
 }
 
 
-char* CQPUtils::Encode(char *input)
+char* CQPUtils::encode(char *input)
 {
   int BufSize = static_cast<int>(strlen(input) + BufAdd);
   int UsedSize = 0;
@@ -565,14 +561,14 @@
       char mids[3];
       if (LineLen >= MaxLineLength - 4)
       {
-        finalresult = ExpandBuffer(finalresult, UsedSize, &BufSize, 0);
+        finalresult = expandBuffer(finalresult, UsedSize, &BufSize, 0);
         *(fresult++) = '=';
         *(fresult++) = '\r';
         *(fresult++) = '\n';
         UsedSize += 3;
         LineLen = 0;
       }
-      finalresult = ExpandBuffer(finalresult, UsedSize, &BufSize, 0);
+      finalresult = expandBuffer(finalresult, UsedSize, &BufSize, 0);
 #ifdef WIN32
       itoa(mid, mids, 16);
 #else
@@ -590,14 +586,14 @@
     {
       if (LineLen >= MaxLineLength - 4)
       {
-        finalresult = ExpandBuffer(finalresult, UsedSize, &BufSize, 0);
+        finalresult = expandBuffer(finalresult, UsedSize, &BufSize, 0);
         *(fresult++) = '=';
         *(fresult++) = '\r';
         *(fresult++) = '\n';
         UsedSize += 3;
         LineLen = 0;
       }
-      finalresult = ExpandBuffer(finalresult, UsedSize, &BufSize);
+      finalresult = expandBuffer(finalresult, UsedSize, &BufSize);
       UsedSize++;
       LineLen++;
       *(fresult++) = *(s++);

Modified: trunk/myserver/src/protocol/http/http_headers.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http_headers.cpp   2009-04-02 09:21:41 UTC 
(rev 3046)
+++ trunk/myserver/src/protocol/http/http_headers.cpp   2009-04-03 08:26:24 UTC 
(rev 3047)
@@ -836,8 +836,9 @@
       const char* lsecondaryBuffer;
       const char* lsecondaryBufferOr;
       char login[32];
-      char password[32];
-      
+      char password[32]; 
+      CBase64Utils base64Utils;
+    
       if(len == -1)
         return 400;    
       
@@ -851,7 +852,7 @@
       if (len <= 1)
         return 400;
       
-      lsecondaryBuffer = base64Utils.Decode(base64,&len);
+      lsecondaryBuffer = base64Utils.decode(base64, &len);
       lsecondaryBufferOr = lsecondaryBuffer;
    
       for(i = 0; (*lsecondaryBuffer != ':') && (i < 32);i++)

Modified: trunk/myserver/tests/test_base64.cpp
===================================================================
--- trunk/myserver/tests/test_base64.cpp        2009-04-02 09:21:41 UTC (rev 
3046)
+++ trunk/myserver/tests/test_base64.cpp        2009-04-03 08:26:24 UTC (rev 
3047)
@@ -1,6 +1,6 @@
 /*
  MyServer
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009 Free Software Foundation, Inc.
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 3 of the License, or
@@ -51,17 +51,16 @@
   {
     int len = 0;
     char* input = (char*) "Hello world!\n";
-    char* encoded = base64->Encode(input, 13);
+    char* encoded = base64->encode(input, 13);
 
     len = strlen(encoded);
 
-    char* decoded = base64->Decode(encoded, &len);
+    char* decoded = base64->decode(encoded, &len);
 
     CPPUNIT_ASSERT_EQUAL(strlen(input), strlen(decoded));
 
     for (unsigned int i = 0; i < strlen(decoded); i++)
       CPPUNIT_ASSERT_EQUAL(input[i], decoded[i]);
-
   }
 };
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]