Browse Source

Initial Commit

release/0.19
JustinAJ 11 years ago
commit
aa1126569b
  1. 63
      .gitattributes
  2. 156
      .gitignore
  3. 32
      Jupiter.sln
  4. 179
      Jupiter/ArrayList.h
  5. 49
      Jupiter/Base64.cpp
  6. 175
      Jupiter/Base64.h
  7. 235
      Jupiter/Base64C.c
  8. 556
      Jupiter/CString.h
  9. 1203
      Jupiter/CString_Imp.h
  10. 74
      Jupiter/Command.cpp
  11. 100
      Jupiter/Command.h
  12. 276
      Jupiter/DLList.h
  13. 206
      Jupiter/File.cpp
  14. 165
      Jupiter/File.h
  15. 523
      Jupiter/Functions.c
  16. 391
      Jupiter/Functions.h
  17. 581
      Jupiter/INIFile.cpp
  18. 474
      Jupiter/INIFile.h
  19. 8
      Jupiter/IRC.cpp
  20. 54
      Jupiter/IRC.h
  21. 1743
      Jupiter/IRC_Client.cpp
  22. 874
      Jupiter/IRC_Client.h
  23. 708
      Jupiter/IRC_Numerics.h
  24. 13
      Jupiter/IRC_Server.cpp
  25. 32
      Jupiter/IRC_Server.h
  26. 60
      Jupiter/InvalidIndex.h
  27. 18
      Jupiter/Jupiter.cpp
  28. 59
      Jupiter/Jupiter.h
  29. BIN
      Jupiter/Jupiter.rc
  30. 154
      Jupiter/Jupiter.vcxproj
  31. 205
      Jupiter/Jupiter.vcxproj.filters
  32. 77
      Jupiter/List.h
  33. 282
      Jupiter/Plugin.cpp
  34. 306
      Jupiter/Plugin.h
  35. 59
      Jupiter/Queue.cpp
  36. 79
      Jupiter/Queue.h
  37. 130
      Jupiter/Rehash.cpp
  38. 147
      Jupiter/Rehash.h
  39. 216
      Jupiter/SLList.h
  40. 229
      Jupiter/SecureSocket.cpp
  41. 214
      Jupiter/SecureSocket.h
  42. 564
      Jupiter/Socket.cpp
  43. 491
      Jupiter/Socket.h
  44. 258
      Jupiter/String_Type.h
  45. 62
      Jupiter/TCPSocket.cpp
  46. 61
      Jupiter/TCPSocket.h
  47. 54
      Jupiter/Thinker.h
  48. 148
      Jupiter/Timer.cpp
  49. 191
      Jupiter/Timer.h
  50. 22
      Jupiter/UDPSocket.cpp
  51. 43
      Jupiter/UDPSocket.h
  52. 14
      Jupiter/resource.h
  53. BIN
      Release/Jupiter.lib
  54. 51
      Tester/Test.cpp
  55. 87
      Tester/Tester.vcxproj
  56. 27
      Tester/Tester.vcxproj.filters

63
.gitattributes

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

156
.gitignore

@ -0,0 +1,156 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
!packages/*/build/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
# =========================
# Windows detritus
# =========================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac desktop service store files
.DS_Store

32
Jupiter.sln

@ -0,0 +1,32 @@
๏ปฟ
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Jupiter", "Jupiter\Jupiter.vcxproj", "{367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Tester", "Tester\Tester.vcxproj", "{0F041791-1047-4C6A-A4C1-814E6957D5EB}"
ProjectSection(ProjectDependencies) = postProject
{367CBCA8-6F27-484A-BC6C-2FC087FBB0C8} = {367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Debug|Win32.ActiveCfg = Release|Win32
{367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Debug|Win32.Build.0 = Release|Win32
{367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Debug|Win32.Deploy.0 = Release|Win32
{367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Release|Win32.ActiveCfg = Release|Win32
{367CBCA8-6F27-484A-BC6C-2FC087FBB0C8}.Release|Win32.Build.0 = Release|Win32
{0F041791-1047-4C6A-A4C1-814E6957D5EB}.Debug|Win32.ActiveCfg = Debug|Win32
{0F041791-1047-4C6A-A4C1-814E6957D5EB}.Debug|Win32.Build.0 = Debug|Win32
{0F041791-1047-4C6A-A4C1-814E6957D5EB}.Release|Win32.ActiveCfg = Release|Win32
{0F041791-1047-4C6A-A4C1-814E6957D5EB}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

179
Jupiter/ArrayList.h

@ -0,0 +1,179 @@
/**
* Copyright (C) 2013-2014 Justin James.
*
* This license must be preserved.
* Any applications, libraries, or code which make any use of any
* component of this program must not be commercial, unless explicit
* permission is granted from the original author. The use of this
* program for non-profit purposes is permitted.
*
* 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.
*
* In the event that this license restricts you from making desired use of this program, contact the original author.
* Written by Justin James <justin.aj@hotmail.com>
*/
#if !defined _ARRAYLIST_H_HEADER
#define _ARRAYLIST_H_HEADER
#include "Jupiter.h"
#include "List.h"
/**
* @file ArrayList.h
* @brief Provides an array-based list implementation using the List interface.
*/
namespace Jupiter
{
/**
* @brief Provides an array-based list implementation using the List interface.
*/
template<typename T> class ArrayList : public List<T>
{
public:
/**
* @brief Gets the data at a specified index.
*
* @param index Index of the data to get.
* @return Data stored at the specified index.
*/
T *get(unsigned int index) const;
/**
* @brief Removes the data at a specified index from the list, and returns the removed data.
*
* @param n Index of the node to remove.
* @return Data removed.
*/
T *remove(unsigned int index);
/**
* @brief Adds data to the list at a specified index.
*
* @param data Data to add to the list.
* @param index Position in the list to add the data to.
*/
void add(T *data, unsigned int index);
/**
* @brief Adds data to the end of the list.
*
* @param data Data to add to the list.
*/
void add(T *data);
/**
* @brief Empties the ArrayList of all elements.
*/
void empty();
/**
* @brief Remove and deletes all elements within the ArrayList.
*/
void emptyAndDelete();
/**
* @brief Default constructor for the ArrayList class.
*/
ArrayList();
/**
* @brief Copy constructor for the ArrayList class.
*/
ArrayList(const ArrayList<T> &);
/**
* @brief Destructor for the ArrayList class.
* Note: This does not delete data added to the list.
*/
~ArrayList();
/** Access Operator */
inline T *operator[](size_t index) { return this->get(index); };
/** Private members */
private:
T **data;
unsigned int dataSize;
unsigned int expandArray();
};
}
// Implementation
const unsigned int INIT_SIZE = 8;
template<typename T> unsigned int Jupiter::ArrayList<T>::expandArray()
{
T **tmp = new T *[Jupiter::ArrayList<T>::dataSize * 2];
for (unsigned int i = 0; i < Jupiter::ArrayList<T>::dataSize; i++) tmp[i] = data[i];
delete[] Jupiter::ArrayList<T>::data;
Jupiter::ArrayList<T>::data = tmp;
Jupiter::ArrayList<T>::dataSize *= 2;
return Jupiter::ArrayList<T>::dataSize;
}
template<typename T> Jupiter::ArrayList<T>::ArrayList()
{
Jupiter::ArrayList<T>::dataSize = INIT_SIZE;
Jupiter::ArrayList<T>::data = new T*[Jupiter::ArrayList<T>::dataSize];
Jupiter::List<T>::length = 0;
}
template<typename T> Jupiter::ArrayList<T>::ArrayList(const Jupiter::ArrayList<T> &source)
{
Jupiter::ArrayList<T>::dataSize = source.dataSize;
Jupiter::ArrayList<T>::data = new T*[Jupiter::ArrayList<T>::dataSize];
Jupiter::List<T>::length = source.length;
for (unsigned int i = 0; i < Jupiter::List<T>::length; i++) Jupiter::ArrayList<T>::data[i] = source.data[i];
}
template<typename T> Jupiter::ArrayList<T>::~ArrayList()
{
delete[] Jupiter::ArrayList<T>::data;
}
template<typename T> T *Jupiter::ArrayList<T>::get(unsigned int index) const
{
return Jupiter::ArrayList<T>::data[index];
}
template<typename T> T *Jupiter::ArrayList<T>::remove(unsigned int index)
{
T *r = Jupiter::ArrayList<T>::data[index];
Jupiter::ArrayList<T>::data[index] = nullptr;
for (unsigned int i = index + 1; i < Jupiter::List<T>::length; i++) Jupiter::ArrayList<T>::data[i - 1] = Jupiter::ArrayList<T>::data[i];
Jupiter::List<T>::length--;
return r;
}
template<typename T> void Jupiter::ArrayList<T>::add(T *ndata, unsigned int index)
{
if (Jupiter::List<T>::length == Jupiter::ArrayList<T>::dataSize) Jupiter::ArrayList<T>::expandArray();
for (unsigned int i = Jupiter::List<T>::length; i > index; i--) Jupiter::ArrayList<T>::data[i] = Jupiter::ArrayList<T>::data[i - 1];
Jupiter::ArrayList<T>::data[index] = ndata;
Jupiter::List<T>::length++;
}
template<typename T> void Jupiter::ArrayList<T>::add(T *ndata)
{
Jupiter::ArrayList<T>::add(ndata, Jupiter::List<T>::length);
}
template<typename T> void Jupiter::ArrayList<T>::empty()
{
Jupiter::List<T>::length = 0;
}
template<typename T> void Jupiter::ArrayList<T>::emptyAndDelete()
{
for (unsigned int i = 0; i < Jupiter::List<T>::length; i++) delete Jupiter::ArrayList<T>::data[i];
Jupiter::List<T>::length = 0;
}
#endif // _ARRAYLIST_H_HEADER

49
Jupiter/Base64.cpp

@ -0,0 +1,49 @@
#include "Base64.h"
#include "Functions.h"
unsigned int Jupiter::base64encode(const void *data, size_t dataLength, char *result)
{
return Jupiter_base64encode(data, dataLength, result);
}
unsigned int Jupiter::base64encode(const void *data, size_t dataLength, char *result, size_t resultSize)
{
if (resultSize < (dataLength / 3) * 4 + 5) return 0;
return Jupiter::base64encode(data, dataLength, result);
}
char *Jupiter::base64encode(const void *data, size_t dataLength)
{
size_t resultSize = (dataLength / 3) * 4 + 5;
char *result = new char[resultSize];
Jupiter::base64encode(data, dataLength, result, resultSize);
return result;
}
char *Jupiter::base64encode(const char *str)
{
return Jupiter::base64encode(str, strlen(str));
}
unsigned int Jupiter::base64decode(const char *data, size_t dataLength, unsigned char *result)
{
return Jupiter_base64decode2(data, dataLength, result);
}
unsigned int Jupiter::base64decode(const char *data, size_t dataLength, unsigned char *result, size_t resultSize)
{
if (resultSize < Jupiter_minBase64DecodeLength(data, dataLength)) return 0;
return Jupiter::base64decode(data, dataLength, result);
}
char *Jupiter::base64decode(const char *data, size_t dataLength)
{
char *result = new char[Jupiter_minBase64DecodeLength(data, dataLength) + 1];
result[Jupiter_base64decode(data, (unsigned char *)result)] = 0;
return result;
}
char *Jupiter::base64decode(const char *data)
{
return Jupiter::base64decode(data, strlen(data));
}

175
Jupiter/Base64.h

@ -0,0 +1,175 @@
/**
* Copyright (C) 2014 Justin James.
*
* This license must be preserved.
* Any applications, libraries, or code which make any use of any
* component of this program must not be commercial, unless explicit
* permission is granted from the original author. The use of this
* program for non-profit purposes is permitted.
*
* 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.
*
* In the event that this license restricts you from making desired use of this program, contact the original author.
* Written by Justin James <justin.aj@hotmail.com>
*/
#if !defined _BASE64_H_HEADER
#define _BASE64_H_HEADER
#include "Jupiter.h"
/**
* @file Base64.h
* @brief Provides C and C++ functions to encode/decode using base64.
*/
#if defined __cplusplus
#include <cstdint>
namespace Jupiter
{
/**
* @brief Encodes an input buffer into a base64 C-String.
*
* @param data Data to encode.
* @param dataLength Number of bytes to encode.
* @param result Character buffer for output.
* @return Number of bytes written to the output buffer.
*/
JUPITER_API unsigned int base64encode(const void *data, size_t dataLength, char *result);
/**
* @brief Checks if a buffer is large enough, and if so, encodes an input buffer into a base64 C-String.
*
* @param data Data to encode.
* @param dataLength Number of bytes to encode.
* @param result Character buffer for output.
* @param outputSize Size of the "result" buffer.
* @return Number of bytes written to the output buffer.
*/
JUPITER_API unsigned int base64encode(const void *data, size_t dataLength, char *result, size_t outputSize);
/**
* @brief Encodes an input C-String into a base64 C-String.
*
* @param data String to encode.
* @param dataLength Number of bytes to encode.
* @return Buffer containing the encoded base64 string.
*/
JUPITER_API char *base64encode(const void *data, size_t dataLength);
/**
* @brief Encodes an input C-String into a base64 C-String.
*
* @param data String to encode.
* @return Buffer containing the encoded base64 string.
*/
JUPITER_API char *base64encode(const char *data);
/**
* @brief Decodes an input base64 C-String into a data buffer.
*
* @param str Data to decode.
* @param result Data buffer for output.
* @return Number of bytes written to the output buffer.
*/
JUPITER_API unsigned int base64decode(const char *data, size_t dataLength, unsigned char *result, size_t resultSize);
/**
* @brief Decodes an input base64 character string into a C-String buffer.
*
* @param data Data to decode.
* @param dataLength Length of the data to decode.
* @return Number of bytes written to the output buffer.
*/
JUPITER_API unsigned int base64decode(const char *data, size_t dataLength, unsigned char *result);
/**
* @brief Decodes an input base64 character string into a C-String buffer.
*
* @param data Data to decode.
* @param dataLength Length of the data to decode.
* @return C-String containing the decoded buffer.
*/
JUPITER_API char *base64decode(const char *data, size_t dataLength);
/**
* @brief Decodes an input base64 C-String into a C-String buffer.
*
* @param str Data to decode.
* @return C-String containing the decoded buffer.
*/
JUPITER_API char *base64decode(const char *str);
}
extern "C"
{
#else
#include <stdbool.h>
#include <stdint.h>
#endif // __cplusplus
/**
* @brief Encodes an input buffer into a base64 C-String.
*
* @param data Data to encode.
* @param dataLength Number of bytes to encode.
* @param result Character buffer for output.
* @return Number of bytes written to the output buffer.
*/
JUPITER_API unsigned int Jupiter_base64encode(const void *data, size_t dataLength, char *result);
/**
* @brief Calculates the minimum buffer size to decode a specified base64 string.
* Note: This does NOT include the neccessary space for a null-terminator.
*
* @param data Data which would be decoded.
* @param inLen Length of the input string.
* @return Minimum number of bytes to fit the decoded buffer.
*/
JUPITER_API unsigned int Jupiter_minBase64DecodeLength(const char *data, size_t inLen);
/**
* @brief Checks if a buffer is a valid base64 string.
*
* @param str C-String containing data to check.
* @return True if the input buffer is a valid base64 string, false otherwise.
*/
JUPITER_API bool Jupiter_isBase64(const char *str);
/**
* @brief Checks if a buffer is a valid base64 string.
*
* @param data Buffer to check.
* @param dataLength Length of the data to check.
* @return True if the input buffer is a valid base64 string, false otherwise.
*/
JUPITER_API bool Jupiter_isBase642(const char *data, size_t dataLength);
/**
* @brief Decodes an input base64 C-String into a data buffer.
*
* @param str C-String containing data to decode.
* @param result Data buffer for output.
* @return Number of bytes written to the output buffer.
*/
JUPITER_API unsigned int Jupiter_base64decode(const char *str, unsigned char *result);
/**
* @brief Decodes an input base64 string into a data buffer.
*
* @param data Data to decode.
* @param dataLength Length of the base64 string.
* @param result Data buffer for output.
* @return Number of bytes written to the output buffer.
*/
JUPITER_API unsigned int Jupiter_base64decode2(const char *data, size_t dataLength, unsigned char *result);
#if defined __cplusplus
}
#endif
#endif _BASE64_H_HEADER

235
Jupiter/Base64C.c

@ -0,0 +1,235 @@
#include "Base64.h"
unsigned int Jupiter_base64encode(const void *data_buf, size_t dataLength, char *result)
{
const char base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const uint8_t *data = (const uint8_t *)data_buf;
char *resultPtr = result;
uint32_t n = 0;
int padCount = dataLength % 3;
uint8_t n0, n1, n2, n3;
/* increment over the length of the string, three characters at a time */
for (size_t x = 0; x < dataLength; x += 3)
{
/* these three 8-bit (ASCII) characters become one 24-bit number */
n = data[x] << 16;
if ((x + 1) < dataLength) n += data[x + 1] << 8;
if ((x + 2) < dataLength) n += data[x + 2];
/* this 24-bit number gets separated into four 6-bit numbers */
n0 = (uint8_t)(n >> 18) & 63;
n1 = (uint8_t)(n >> 12) & 63;
n2 = (uint8_t)(n >> 6) & 63;
n3 = (uint8_t)n & 63;
/*
* if we have one byte available, then its encoding is spread
* out over two characters
*/
*resultPtr = base64chars[n0];
resultPtr++;
*resultPtr = base64chars[n1];
resultPtr++;
/*
* if we have only two bytes available, then their encoding is
* spread out over three chars
*/
if ((x + 1) < dataLength)
{
*resultPtr = base64chars[n2];
resultPtr++;
}
/*
* if we have all three bytes available, then their encoding is spread
* out over four characters
*/
if ((x + 2) < dataLength)
{
*resultPtr = base64chars[n3];
resultPtr++;
}
}
/*
* create and add padding that is required if we did not have a multiple of 3
* number of characters available
*/
if (padCount > 0)
{
while (padCount < 3)
{
*resultPtr = '=';
resultPtr++;
padCount++;
}
}
*resultPtr = 0;
return resultPtr - result;
}
static const unsigned char Jupiter_base64DecodeTable[256] = {
66, 66, 66, 66, 66, 66, 66, 66, 66, 64, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 62, 66, 66, 66, 63, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 66, 66, 66, 65, 66, 66, 66, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 66, 66, 66, 66, 66, 66, 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, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
66, 66, 66, 66, 66, 66
};
unsigned int Jupiter_minBase64DecodeLength(const char *data, size_t inLen)
{
if (inLen == 0) return 0;
data += inLen - 1;
if (*data == '=')
{
data--;
if (*data == '=') return inLen / 4 * 3 - 2;
return inLen / 4 * 3 - 1;
}
return inLen / 4 * 3;
}
bool Jupiter_isBase64(const char *in)
{
while (*in != 0)
{
switch (Jupiter_base64DecodeTable[*in++])
{
case 66:
return false;
default:
break;
}
}
return true;
}
bool Jupiter_isBase642(const char *in, size_t inLen)
{
if (inLen % 4 != 0)
{
return false;
}
const char *end = in + inLen;
while (in != end)
{
switch (Jupiter_base64DecodeTable[*in++])
{
case 66:
return false;
default:
break;
}
}
return true;
}
/** Disable warning 4244 */
#if defined _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4244) // conversion from 'size_t' to 'unsigned char', possible loss of data
#endif
unsigned int Jupiter_base64decode(const char *in, unsigned char *out)
{
unsigned char *outOrig = out;
size_t buf = 1;
while (*in != 0)
{
unsigned char c = Jupiter_base64DecodeTable[*in++];
switch (c)
{
case 66:
/* invalid input */
return 0;
case 65:
/* pad character, end of data */
goto endLoop;
case 64:
break;
default:
buf = buf << 6 | c;
/* If the buffer is full, split it into bytes */
if (buf & 0x1000000)
{
*out++ = buf >> 16;
*out++ = buf >> 8;
*out++ = buf;
buf = 1;
}
break;
}
}
endLoop:
if (buf & 0x40000)
{
*out++ = buf >> 10;
*out++ = buf >> 2;
}
else if (buf & 0x1000) *out++ = buf >> 4;
return out - outOrig;
}
unsigned int Jupiter_base64decode2(const char *in, size_t inLen, unsigned char *out)
{
unsigned char *outOrig = out;
const char *end = in + inLen;
size_t buf = 1;
while (in != end)
{
unsigned char c = Jupiter_base64DecodeTable[*in++];
switch (c)
{
case 66:
/* invalid input */
return false;
case 65:
/* pad character, end of data */
in = end;
case 64:
break;
default:
buf = buf << 6 | c;
/* If the buffer is full, split it into bytes */
if (buf & 0x1000000)
{
*out++ = buf >> 16;
*out++ = buf >> 8;
*out++ = buf;
buf = 1;
}
break;
}
}
if (buf & 0x40000)
{
*out++ = buf >> 10;
*out++ = buf >> 2;
}
else if (buf & 0x1000) *out++ = buf >> 4;
return out - outOrig;
}
/** Re-enable warning */
#if defined _MSC_VER
#pragma warning(pop)
#endif

556
Jupiter/CString.h

@ -0,0 +1,556 @@
/**
* Copyright (C) 2013-2014 Justin James.
*
* This license must be preserved.
* Any applications, libraries, or code which make any use of any
* component of this program must not be commercial, unless explicit
* permission is granted from the original author. The use of this
* program for non-profit purposes is permitted.
*
* 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.
*
* In the event that this license restricts you from making desired use of this program, contact the original author.
* Written by Justin James <justin.aj@hotmail.com>
*/
#if !defined _CSTRING_H_HEADER
#define _CSTRING_H_HEADER
#include <stdarg.h>
#include "String_Type.h"
/**
* @file CString.h
* @brief Defines the base CString_Type, as well as a series of CString types.
* Note: Functions which take "case" or "wildcards" into consideration will only function
* for types char and wchar_t; inputs with other types will simply return false.
*/
namespace Jupiter
{
/**
* @brief Provides the basis for CString classes by providing the implementations for many abstract methods in String_Type.
* Note: This is an abstract type.
*
* @param T Element type which the CString will store. Defaults to char.
*/
template<typename T = char> class CString_Type : public String_Type<T>
{
public:
/**
* @brief Returns the C-Style string behind the CString.
*
* @return C-Style string that the CString represents.
*/
const T *c_str() const;
/**
* @brief Returns the number of elements in the CString.
*
* @return Number of elements in the string.
*/
size_t size() const;
/**
* @brief Compares another string against the CString.
*
* @param in String to compare against.
* @return 0 if the strings are equal, negative if the first mismatched character is greater in the CString, or positive if it's less.
*/
int compare(const String_Type<T> &in) const;
int compare(const std::basic_string<T> &in) const;
int compare(const T *in) const;
int compare(const T in) const;
/**
* @brief Checks if the strings are equal.
* Note: Case sensitive.
*
* @param in String to compare against.
* @return True if the contents of the strings are equal, false otherwise.
*/
bool equals(const String_Type<T> &in) const;
bool equals(const std::basic_string<T> &in) const;
bool equals(const T *in) const;
bool equals(const T in) const;
/**
* @brief Checks if the strings are equal.
* Note: Case insensitive. Returns false for any type other than char and wchar_t.
*
* @param in String to compare against.
* @return True if the contents of the strings are equal, false otherwise.
*/
bool equalsi(const String_Type<T> &in) const;
bool equalsi(const std::basic_string<T> &in) const;
bool equalsi(const T *in) const;
bool equalsi(const T in) const;
/**
* @brief Checks if the CString matches a wildcard format.
* Note: Case sensitive. Returns false for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @return True if the CString matches the wildcard format, false otherwise.
*/
bool match(const String_Type<T> &format) const;
bool match(const std::basic_string<T> &format) const;
bool match(const T *format) const;
/**
* @brief Checks if the CString matches a wildcard format.
* Note: Case insensitive. Returns false for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @return True if the CString matches the wildcard format, false otherwise.
*/
bool matchi(const String_Type<T> &format) const;
bool matchi(const std::basic_string<T> &format) const;
bool matchi(const T *format) const;
/**
* @brief Sets the CString's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param ... Inputs to match the format specifiers.
* @return Number of characters written.
*/
virtual size_t format(const String_Type<T> &format, ...);
virtual size_t format(const std::basic_string<T> &format, ...);
virtual size_t format(const T *format, ...);
virtual size_t vformat(const T *format, va_list args) = 0;
/**
* @brief Appends to a CString's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param ... Inputs to match the format specifiers.
* @return Number of characters written.
*/
virtual size_t aformat(const String_Type<T> &format, ...);
virtual size_t aformat(const std::basic_string<T> &format, ...);
virtual size_t aformat(const T *format, ...);
virtual size_t avformat(const T *format, va_list args) = 0;
/**
* @brief Counts the number of token deliminated words.
*
* @param whitespace A string of tokens used to deliminate words.
* @return Number of words found.
*/
unsigned int wordCount(const T *whitespace) const;
/**
* @brief Truncates the string by a specified number of elements.
*
* @param n Number of elements to remove from the tail.
* @return New size of the CString.
*/
size_t truncate(size_t n);
/**
* @brief Fetches an element from the string.
*
* @param index Index of the element to return.
* @return The element located at the specified index.
*/
T &get(size_t index) const;
/**
* @brief Shifts the string pointer to the left.
*
* @param length Number of elements to shift
* @return Number of elements shifted to the left.
*/
size_t shiftLeft(size_t length);
/**
* @brief Shifts the string pointer to the right.
*
* @param length Number of elements to shift
* @return Number of elements shifted.
*/
size_t shiftRight(size_t length);
/**
* @brief Removes the first instance of an element from the string.
*
* @param value Value of the element to remove.
* @return True if an element was removed, false otherwise.
*/
bool remove(T &value);
/**
* @brief Checks if the string contains an element with the specified value.
*
* @param value Value of the element to search for.
* @return True if a match is found, false otherwise.
*/
bool contains(const T &value);
/** Access Operator */
inline T &operator[](size_t pos) { return Jupiter::CString_Type<T>::curr[pos]; };
/** Assignment Operators */
inline CString_Type<T> &operator=(const CString_Type<T> &right) { this->set(right); return *this; };
inline CString_Type<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; };
inline CString_Type<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline CString_Type<T> &operator=(const T *right) { this->set(right); return *this; };
inline CString_Type<T> &operator=(const T right) { this->set(right); return *this; };
protected:
T *base; /** Base pointer for the underlying C-style string */
T *curr; /** Active pointer for the underlying C-style string */
size_t strLen; /** Length of underlying C-style string */
};
/**
* @brief Provides a "strict" CString implementation that's more optimized for minimal memory usage.
* Note: This recreates the underlying C-style string with every concatenation.
*
* @param T Element type which the CString will store. Defaults to char.
*/
template<typename T = char> class CString_Strict : public CString_Type<T>
{
public:
/**
* @brief Sets the CString's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param args Inputs to match the format specifiers.
* @return Number of characters written.
*/
size_t vformat(const T *format, va_list args);
/**
* @brief Appends to a CString's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param args Inputs to match the format specifiers.
* @return Number of characters written.
*/
size_t avformat(const T *format, va_list args);
/**
* @brief Sets the CString's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param ... Inputs to match the format specifiers.
* @return String containing the new format.
*/
static CString_Strict Format(const T *format, ...);
/**
* @brief Creates a partial copy of the string.
*
* @param pos Position in the string to start copying from.
* @param length Number of characters to copy.
* @return String containing a partial copy of the original string.
*/
CString_Strict<T> substring(size_t pos, size_t length) const;
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
CString_Strict<T> getWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static CString_Strict<T> getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
*
* @param in C-Style string to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static CString_Strict<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
CString_Strict<T> gotoWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static CString_Strict<T> gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace);
/**
* @brief Copies the data from the input string to the CString.
*
* @param in String containing the data to be copied.
* @return New size of the CString.
*/
size_t set(const String_Type<T> &in);
size_t set(const std::basic_string<T> &in);
size_t set(const T *in);
size_t set(const T in);
/**
* @brief Sets the string buffer.
* Note: This class will free the buffer for you when it's done.
*
* @param in New buffer to be used.
* @return The length of the string.
*/
size_t setString(T *in);
/**
* @brief Sets the string buffer.
* Note: This class will free the buffer for you when it's done. DO NOT DELETE THE INPUT BUFFER.
* Note: This method is unique to the CString_Strict template class, and does not appear in CString_Loose.
*
* @param in New buffer to be used.
* @param size At least the number of characters in the buffer, not including the null-terminator.
* @return The length of the string.
*/
size_t setString(T *in, size_t size);
/**
* @brief Copies the data from the input string and concatenates it to the end of CString.
*
* @param in String containing the data to be concatenated.
* @return New size of the CString.
*/
size_t concat(const String_Type<T> &in);
size_t concat(const std::basic_string<T> &in);
size_t concat(const T *in);
size_t concat(const T in);
/** Default Constructor */
CString_Strict();
/** Copy Constructors */
CString_Strict(const CString_Strict &in);
CString_Strict(const String_Type<T> &in);
CString_Strict(const std::basic_string<T> &in);
CString_Strict(const T *in);
CString_Strict(const T in);
/** Destructor */
virtual ~CString_Strict();
/** Assignment Operators */
inline CString_Strict<T> &operator=(const CString_Strict<T> &right) { this->set(right); return *this; };
inline CString_Strict<T> &operator=(const CString_Type<T> &right) { this->set(right); return *this; };
inline CString_Strict<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; };
inline CString_Strict<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline CString_Strict<T> &operator=(const T *right) { this->set(right); return *this; };
inline CString_Strict<T> &operator=(const T right) { this->set(right); return *this; };
};
/**
* @brief Provides a "loose" CString implementation that's more optimized for repeated concatenations.
* Note: The underlying C-style string will always have a size which is a power of 2, but no fewer than 8 elements.
*
* @param T Element type which the CString will store. Defaults to char.
*/
template<typename T = char> class CString_Loose : public CString_Type<T>
{
public:
/**
* @brief Sets the CString's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param ... Inputs to match the format specifiers.
* @return Number of characters written.
*/
size_t vformat(const T *format, va_list args);
/**
* @brief Appends to a CString's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param ... Inputs to match the format specifiers.
* @return Number of characters written.
*/
size_t avformat(const T *format, va_list args);
/**
* @brief Sets the CString's contents based on the format string and input variables.
* Note: Format specifiers similar to printf. Returns 0 for any type other than char and wchar_t.
*
* @param format Format that the string is compared against.
* @param ... Inputs to match the format specifiers.
* @return String containing the new format.
*/
static CString_Loose<T> Format(const T *format, ...);
/**
* @brief Creates a partial copy of the string.
*
* @param pos Position in the string to start copying from.
* @param length Number of characters to copy.
* @return String containing a partial copy of the original string.
*/
CString_Loose<T> substring(size_t pos, size_t length) const;
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
CString_Loose<T> getWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
* Useful when the input string's type isn't known.
*
* @param in String to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static CString_Loose<T> getWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
* Useful when the input string's type isn't known.
*
* @param in C-Style string to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static CString_Loose<T> getWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
CString_Loose<T> gotoWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static CString_Loose<T> gotoWord(const Jupiter::String_Type<T> &in, size_t pos, const T *whitespace);
/**
* @brief Copies the data from the input string to the CString.
*
* @param in String containing the data to be copied.
* @return New size of the CString.
*/
size_t set(const CString_Loose &in);
size_t set(const String_Type<T> &in);
size_t set(const std::basic_string<T> &in);
size_t set(const T *in);
size_t set(const T in);
/**
* @brief Copies the data from the input string and concatenats it to the end of CString.
*
* @param in String containing the data to be concatenated.
* @return New size of the CString.
*/
size_t concat(const String_Type<T> &in);
size_t concat(const std::basic_string<T> &in);
size_t concat(const T *in);
size_t concat(const T in);
/** Default constructor */
CString_Loose();
/** Copy Constructors */
CString_Loose(const CString_Loose &in);
CString_Loose(const String_Type<T> &in);
CString_Loose(const std::basic_string<T> &in);
CString_Loose(const T *in);
CString_Loose(const T in);
/** Destructor */
virtual ~CString_Loose();
static const size_t start_size = 8; /** Starting size for loose CStrings. */
/** Assignment Operators */
inline CString_Loose<T> &operator=(const CString_Loose<T> &right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const CString_Type<T> &right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const String_Type<T> &right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const std::basic_string<T> &right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const T *right) { this->set(right); return *this; };
inline CString_Loose<T> &operator=(const T right) { this->set(right); return *this; };
protected:
size_t strSize; /** Size of underlying C-string buffer */
};
/** Definition of a Loose CString. */
typedef CString_Loose<char> CStringL;
/** Definition of a Loose Wide CString */
typedef CString_Loose<wchar_t> WCStringL;
/** Definition of a Strict CString. */
typedef CString_Strict<char> CStringS;
/** Definition of a Strict Wide CString */
typedef CString_Strict<wchar_t> WCStringS;
/** Definition of a CString. */
typedef CStringL CString;
/** Definition of a Wide CString */
typedef WCStringL WCString;
/** Generic CString Type */
typedef CString_Type<char> CStringType;
/** Generic Wide CString Type */
typedef CString_Type<wchar_t> WCStringType;
/** Empty String constants */
static const Jupiter::CStringS emptyCStringS;
static const Jupiter::CStringS emptyCStringL;
static const Jupiter::CStringS &emptyCString = emptyCStringS;
static const Jupiter::CStringS &emptyString = emptyCString;
}
/** Implementation for CString_Type, CString_Strict, and CString_Loose. Very scary. */
#include "CString_IMP.h"
#endif // _CSTRING_H_HEADER

1203
Jupiter/CString_Imp.h

File diff suppressed because it is too large

74
Jupiter/Command.cpp

@ -0,0 +1,74 @@
/**
* Copyright (C) 2013-2014 Justin James.
*
* This license must be preserved.
* Any applications, libraries, or code which make any use of any
* component of this program must not be commercial, unless explicit
* permission is granted from the original author. The use of this
* program for non-profit purposes is permitted.
*
* 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.
*
* In the event that this license restricts you from making desired use of this program, contact the original author.
* Written by Justin James <justin.aj@hotmail.com>
*/
#include <cstring>
#include "ArrayList.h"
#include "Functions.h"
#include "Command.h"
struct Jupiter::Command::Data
{
public:
Jupiter::ArrayList<Jupiter::CString_Strict<char>> triggers;
};
Jupiter::Command::Command()
{
Jupiter::Command::data_ = new Jupiter::Command::Data();
}
Jupiter::Command::Command(const Command &command)
{
Jupiter::Command::data_ = new Jupiter::Command::Data();
Jupiter::CStringS *trigger;
for (int i = command.data_->triggers.size() - 1; i >= 0; i--)
{
trigger = new Jupiter::CStringS(*command.data_->triggers.get(i));
Jupiter::Command::data_->triggers.add(trigger);
}
}
Jupiter::Command::~Command()
{
for (int i = Jupiter::Command::data_->triggers.size() - 1; i >= 0; i--) delete Jupiter::Command::data_->triggers.remove(i);
delete Jupiter::Command::data_;
}
// Command Functions
void Jupiter::Command::addTrigger(const char *trigger)