diff --git a/Jupiter/HTTP_QueryString.cpp b/Jupiter/HTTP_QueryString.cpp new file mode 100644 index 0000000..6770d91 --- /dev/null +++ b/Jupiter/HTTP_QueryString.cpp @@ -0,0 +1,80 @@ +/** + * Copyright (C) 2016 Jessica James. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Written by Jessica James + */ + +#include "HTTP_QueryString.h" + +Jupiter::HTTP::QueryString::QueryString(const Jupiter::ReadableString ¶meters) : QueryString(parameters.ptr(), parameters.size()) +{ +} + +Jupiter::HTTP::QueryString::QueryString(const char *ptr, size_t str_size) : Jupiter::StringS(str_size) +{ + if (str_size < 3) // not enough room for "%XX", therefore no parameters to parse + { + Jupiter::StringType::length = str_size; + switch (str_size) + { + case 2: + str[1] = ptr[1]; + case 1: + *str = *ptr; + case 0: + // nothing to copy + return; + } + } + + const char *end = ptr + str_size - 2; + char *buf = str; + int val; + + while (ptr != end) + { + if (*ptr == '%') + { + if ((val = Jupiter_getHex(*++ptr)) != -1) + { + *buf = static_cast(val) << 4; + if ((val = Jupiter_getHex(*++ptr)) != -1) + *buf |= val; + + ++buf, ++ptr; + if (ptr > end) + { + if (ptr == end + 1) // copy 1 remaining character + { + *buf = *ptr; + ++buf; + } + Jupiter::StringType::length = buf - Jupiter::StringType::str; + return; + } + } + } + else // Copy character + { + *buf = *ptr; + ++buf, ++ptr; + } + } + + // copy last 2 characters + *buf = *ptr; + *++buf = *++ptr; + Jupiter::StringType::length = buf + 1 - str; +} \ No newline at end of file diff --git a/Jupiter/HTTP_QueryString.h b/Jupiter/HTTP_QueryString.h new file mode 100644 index 0000000..30749a7 --- /dev/null +++ b/Jupiter/HTTP_QueryString.h @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2016 Jessica James. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Written by Jessica James + */ + +#if !defined _HTTP_QUERYSTRING_H_HEADER +#define _HTTP_QUERYSTRING_H_HEADER + +#include "String.h" + +/** + * @file HTTP_QueryString.h + * @brief Provides parsing for HTTP Query Strings. + */ + +namespace Jupiter +{ + namespace HTTP + { + /** + * @brief Provides parsing for HTTP Query Strings. + */ + class JUPITER_API QueryString : public Jupiter::StringS + { + public: + QueryString() = delete; + QueryString(const Jupiter::ReadableString ¶meters); + QueryString(const char *ptr, size_t str_size); + }; + } +} + +#endif // _HTTP_QUERYSTRING_H_HEADER \ No newline at end of file diff --git a/Jupiter/Jupiter.vcxproj b/Jupiter/Jupiter.vcxproj index 7b097f2..9740265 100644 --- a/Jupiter/Jupiter.vcxproj +++ b/Jupiter/Jupiter.vcxproj @@ -185,6 +185,7 @@ + @@ -217,6 +218,7 @@ + diff --git a/Jupiter/Jupiter.vcxproj.filters b/Jupiter/Jupiter.vcxproj.filters index 96d0ab6..9f8a0d5 100644 --- a/Jupiter/Jupiter.vcxproj.filters +++ b/Jupiter/Jupiter.vcxproj.filters @@ -138,6 +138,9 @@ Source Files\HTTP + + Header Files\HTTP + @@ -269,6 +272,9 @@ Header Files\HTTP + + Header Files\HTTP + diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index dbabfba..89f8d45 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ