aboutsummaryrefslogtreecommitdiff
path: root/dep/src/sockets/Base64.cpp
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:51:44 -0700
committermaximius <none@none>2009-10-17 15:51:44 -0700
commite585187b248f48b3c6e9247b49fa07c6565d65e5 (patch)
tree637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /dep/src/sockets/Base64.cpp
parent26b5e033ffde3d161382fc9addbfa99738379641 (diff)
*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
Diffstat (limited to 'dep/src/sockets/Base64.cpp')
-rw-r--r--dep/src/sockets/Base64.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/dep/src/sockets/Base64.cpp b/dep/src/sockets/Base64.cpp
index a6a6992798c..cb66b93af6f 100644
--- a/dep/src/sockets/Base64.cpp
+++ b/dep/src/sockets/Base64.cpp
@@ -4,34 +4,42 @@
**/
/*
Copyright (C) 2004-2007 Anders Hedstrom
+
This library is made available under the terms of the GNU GPL.
+
If you would like to use this library in a closed-source application,
a separate license agreement is available. For information about
the closed-source license agreement for the C++ sockets library,
please visit http://www.alhem.net/Sockets/license.html and/or
email license@alhem.net.
+
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 2
of the License, or (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
+
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Base64.h"
+
#ifdef SOCKETS_NAMESPACE
namespace SOCKETS_NAMESPACE {
#endif
+
const char *Base64::bstr =
"ABCDEFGHIJKLMNOPQ"
"RSTUVWXYZabcdefgh"
"ijklmnopqrstuvwxy"
"z0123456789+/";
+
const char Base64::rstr[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -42,16 +50,19 @@ const char Base64::rstr[] = {
0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0};
+
Base64::Base64()
{
}
+
void Base64::encode(FILE *fil, std::string& output, bool add_crlf)
{
size_t remain;
size_t i = 0;
size_t o = 0;
char input[4];
+
output = "";
remain = fread(input,1,3,fil);
while (remain > 0)
@@ -83,15 +94,18 @@ void Base64::encode(FILE *fil, std::string& output, bool add_crlf)
}
}
+
void Base64::encode(const std::string& str_in, std::string& str_out, bool add_crlf)
{
encode(str_in.c_str(), str_in.size(), str_out, add_crlf);
}
+
void Base64::encode(const char* input,size_t l,std::string& output, bool add_crlf)
{
size_t i = 0;
size_t o = 0;
+
output = "";
while (i < l)
{
@@ -122,10 +136,12 @@ void Base64::encode(const char* input,size_t l,std::string& output, bool add_crl
}
}
+
void Base64::encode(const unsigned char* input,size_t l,std::string& output,bool add_crlf)
{
size_t i = 0;
size_t o = 0;
+
output = "";
while (i < l)
{
@@ -156,10 +172,12 @@ void Base64::encode(const unsigned char* input,size_t l,std::string& output,bool
}
}
+
void Base64::decode(const std::string& input,std::string& output)
{
size_t i = 0;
size_t l = input.size();
+
output = "";
while (i < l)
{
@@ -187,11 +205,13 @@ void Base64::decode(const std::string& input,std::string& output)
}
}
+
void Base64::decode(const std::string& input, unsigned char *output, size_t& sz)
{
size_t i = 0;
size_t l = input.size();
size_t j = 0;
+
while (i < l)
{
while (i < l && (input[i] == 13 || input[i] == 10))
@@ -231,6 +251,7 @@ void Base64::decode(const std::string& input, unsigned char *output, size_t& sz)
sz = j;
}
+
size_t Base64::decode_length(const std::string& str64)
{
if (str64.empty() || str64.size() % 4)
@@ -243,8 +264,10 @@ size_t Base64::decode_length(const std::string& str64)
return l;
}
+
#ifdef SOCKETS_NAMESPACE
}
#endif
+