mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-23 09:59:52 +03:00
255 lines
10 KiB
C
255 lines
10 KiB
C
// SoftEther VPN Source Code - Developer Edition Master Branch
|
|
// Mayaqua Kernel
|
|
//
|
|
// SoftEther VPN Server, Client and Bridge are free software under GPLv2.
|
|
//
|
|
// Copyright (c) Daiyuu Nobori.
|
|
// Copyright (c) SoftEther VPN Project, University of Tsukuba, Japan.
|
|
// Copyright (c) SoftEther Corporation.
|
|
//
|
|
// All Rights Reserved.
|
|
//
|
|
// http://www.softether.org/
|
|
//
|
|
// Author: Daiyuu Nobori, Ph.D.
|
|
// Comments: Tetsuo Sugiyama, Ph.D.
|
|
//
|
|
// This program is free software; you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License
|
|
// version 2 as published by the Free Software Foundation.
|
|
//
|
|
// 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 version 2
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
//
|
|
// THE LICENSE AGREEMENT IS ATTACHED ON THE SOURCE-CODE PACKAGE
|
|
// AS "LICENSE.TXT" FILE. READ THE TEXT FILE IN ADVANCE TO USE THE SOFTWARE.
|
|
//
|
|
//
|
|
// THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN,
|
|
// UNDER JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY,
|
|
// MERGE, PUBLISH, DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS
|
|
// SOFTWARE, THAT ANY JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS
|
|
// SOFTWARE OR ITS CONTENTS, AGAINST US (SOFTETHER PROJECT, SOFTETHER
|
|
// CORPORATION, DAIYUU NOBORI OR OTHER SUPPLIERS), OR ANY JURIDICAL
|
|
// DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND OF USING, COPYING,
|
|
// MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING, AND/OR
|
|
// SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
|
|
// CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO
|
|
// EXCLUSIVE JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO,
|
|
// JAPAN. YOU MUST WAIVE ALL DEFENSES OF LACK OF PERSONAL JURISDICTION
|
|
// AND FORUM NON CONVENIENS. PROCESS MAY BE SERVED ON EITHER PARTY IN
|
|
// THE MANNER AUTHORIZED BY APPLICABLE LAW OR COURT RULE.
|
|
//
|
|
// USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS
|
|
// YOU HAVE A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY
|
|
// CRIMINAL LAWS OR CIVIL RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS
|
|
// SOFTWARE IN OTHER COUNTRIES IS COMPLETELY AT YOUR OWN RISK. THE
|
|
// SOFTETHER VPN PROJECT HAS DEVELOPED AND DISTRIBUTED THIS SOFTWARE TO
|
|
// COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING CIVIL RIGHTS INCLUDING
|
|
// PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER COUNTRIES' LAWS OR
|
|
// CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES. WE HAVE
|
|
// NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR
|
|
// INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+
|
|
// COUNTRIES AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE
|
|
// WORLD, WITH DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY
|
|
// COUNTRIES' LAWS, REGULATIONS AND CIVIL RIGHTS TO MAKE THE SOFTWARE
|
|
// COMPLY WITH ALL COUNTRIES' LAWS BY THE PROJECT. EVEN IF YOU WILL BE
|
|
// SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A PUBLIC SERVANT IN YOUR
|
|
// COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE LIABLE TO
|
|
// RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL
|
|
// RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT
|
|
// JUST A STATEMENT FOR WARNING AND DISCLAIMER.
|
|
//
|
|
//
|
|
// SOURCE CODE CONTRIBUTION
|
|
// ------------------------
|
|
//
|
|
// Your contribution to SoftEther VPN Project is much appreciated.
|
|
// Please send patches to us through GitHub.
|
|
// Read the SoftEther VPN Patch Acceptance Policy in advance:
|
|
// http://www.softether.org/5-download/src/9.patch
|
|
//
|
|
//
|
|
// DEAR SECURITY EXPERTS
|
|
// ---------------------
|
|
//
|
|
// If you find a bug or a security vulnerability please kindly inform us
|
|
// about the problem immediately so that we can fix the security problem
|
|
// to protect a lot of users around the world as soon as possible.
|
|
//
|
|
// Our e-mail address for security reports is:
|
|
// softether-vpn-security [at] softether.org
|
|
//
|
|
// Please note that the above e-mail address is not a technical support
|
|
// inquiry address. If you need technical assistance, please visit
|
|
// http://www.softether.org/ and ask your question on the users forum.
|
|
//
|
|
// Thank you for your cooperation.
|
|
//
|
|
//
|
|
// NO MEMORY OR RESOURCE LEAKS
|
|
// ---------------------------
|
|
//
|
|
// The memory-leaks and resource-leaks verification under the stress
|
|
// test has been passed before release this source code.
|
|
|
|
|
|
// Str.h
|
|
// Header of Str.c
|
|
|
|
#ifndef STR_H
|
|
#define STR_H
|
|
|
|
// String token
|
|
struct TOKEN_LIST
|
|
{
|
|
UINT NumTokens;
|
|
char **Token;
|
|
};
|
|
|
|
// INI_ENTRY
|
|
struct INI_ENTRY
|
|
{
|
|
char *Key;
|
|
char *Value;
|
|
wchar_t *UnicodeValue;
|
|
};
|
|
|
|
// Function prototype
|
|
UINT StrLen(char *str);
|
|
UINT StrSize(char *str);
|
|
bool StrCheckLen(char *str, UINT len);
|
|
bool StrCheckSize(char *str, UINT size);
|
|
UINT StrCpy(char *dst, UINT size, char *src);
|
|
UINT StrCpyAllowOverlap(char *dst, UINT size, char *src);
|
|
UINT StrCat(char *dst, UINT size, char *src);
|
|
UINT StrCatLeft(char *dst, UINT size, char *src);
|
|
char ToLower(char c);
|
|
char ToUpper(char c);
|
|
void StrUpper(char *str);
|
|
void StrLower(char *str);
|
|
int StrCmp(char *str1, char *str2);
|
|
int StrCmpi(char *str1, char *str2);
|
|
void FormatArgs(char *buf, UINT size, char *fmt, va_list args);
|
|
void Format(char *buf, UINT size, char *fmt, ...);
|
|
char *CopyFormat(char *fmt, ...);
|
|
void Print(char *fmt, ...);
|
|
void PrintArgs(char *fmt, va_list args);
|
|
void PrintStr(char *str);
|
|
void Debug(char *fmt, ...);
|
|
void DebugArgs(char *fmt, va_list args);
|
|
UINT ToInt(char *str);
|
|
bool ToBool(char *str);
|
|
int ToInti(char *str);
|
|
void ToStr(char *str, UINT i);
|
|
void ToStri(char *str, int i);
|
|
void ToStrx(char *str, UINT i);
|
|
void ToStrx8(char *str, UINT i);
|
|
void TrimCrlf(char *str);
|
|
void Trim(char *str);
|
|
void TrimRight(char *str);
|
|
void TrimLeft(char *str);
|
|
bool GetLine(char *str, UINT size);
|
|
void FreeToken(TOKEN_LIST *tokens);
|
|
bool IsInToken(TOKEN_LIST *t, char *str);
|
|
TOKEN_LIST *ParseToken(char *src, char *separator);
|
|
void InitStringLibrary();
|
|
void FreeStringLibrary();
|
|
bool CheckStringLibrary();
|
|
bool InChar(char *string, char c);
|
|
UINT SearchStrEx(char *string, char *keyword, UINT start, bool case_sensitive);
|
|
UINT SearchStri(char *string, char *keyword, UINT start);
|
|
UINT SearchStr(char *string, char *keyword, UINT start);
|
|
UINT CalcReplaceStrEx(char *string, char *old_keyword, char *new_keyword, bool case_sensitive);
|
|
UINT ReplaceStrEx(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword, bool case_sensitive);
|
|
UINT ReplaceStr(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword);
|
|
UINT ReplaceStri(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword);
|
|
bool IsPrintableAsciiChar(char c);
|
|
bool IsPrintableAsciiStr(char *str);
|
|
void EnPrintableAsciiStr(char *str, char replace);
|
|
bool IsSafeChar(char c);
|
|
bool IsSafeStr(char *str);
|
|
void EnSafeStr(char *str, char replace);
|
|
void TruncateCharFromStr(char *str, char replace);
|
|
char *CopyStr(char *str);
|
|
void BinToStr(char *str, UINT str_size, void *data, UINT data_size);
|
|
void BinToStrW(wchar_t *str, UINT str_size, void *data, UINT data_size);
|
|
void PrintBin(void *data, UINT size);
|
|
bool StartWith(char *str, char *key);
|
|
bool EndWith(char *str, char *key);
|
|
UINT64 ToInt64(char *str);
|
|
void ToStr64(char *str, UINT64 value);
|
|
char *ReplaceFormatStringFor64(char *fmt);
|
|
TOKEN_LIST *ParseCmdLine(char *str);
|
|
TOKEN_LIST *CopyToken(TOKEN_LIST *src);
|
|
TOKEN_LIST *NullToken();
|
|
bool IsNum(char *str);
|
|
LIST *StrToStrList(char *str, UINT size);
|
|
BUF *StrListToStr(LIST *o);
|
|
void FreeStrList(LIST *o);
|
|
TOKEN_LIST *ListToTokenList(LIST *o);
|
|
LIST *TokenListToList(TOKEN_LIST *t);
|
|
bool IsEmptyStr(char *str);
|
|
void BinToStrEx(char *str, UINT str_size, void *data, UINT data_size);
|
|
void BinToStrEx2(char *str, UINT str_size, void *data, UINT data_size, char padding_char);
|
|
char *CopyBinToStrEx(void *data, UINT data_size);
|
|
char *CopyBinToStr(void *data, UINT data_size);
|
|
BUF *StrToBin(char *str);
|
|
void MacToStr(char *str, UINT size, UCHAR *mac_address);
|
|
void ToStr3(char *str, UINT size, UINT64 v);
|
|
void ToStrByte(char *str, UINT size, UINT64 v);
|
|
void ToStrByte1000(char *str, UINT size, UINT64 v);
|
|
TOKEN_LIST *UniqueToken(TOKEN_LIST *t);
|
|
char *NormalizeCrlf(char *str);
|
|
bool IsAllUpperStr(char *str);
|
|
UINT StrWidth(char *str);
|
|
char *MakeCharArray(char c, UINT count);
|
|
void MakeCharArray2(char *str, char c, UINT count);
|
|
bool StrToMac(UCHAR *mac_address, char *str);
|
|
bool IsSplitChar(char c, char *split_str);
|
|
bool GetKeyAndValue(char *str, char *key, UINT key_size, char *value, UINT value_size, char *split_str);
|
|
LIST *ReadIni(BUF *b);
|
|
INI_ENTRY *GetIniEntry(LIST *o, char *key);
|
|
void FreeIni(LIST *o);
|
|
UINT IniIntValue(LIST *o, char *key);
|
|
UINT64 IniInt64Value(LIST *o, char *key);
|
|
char *IniStrValue(LIST *o, char *key);
|
|
wchar_t *IniUniStrValue(LIST *o, char *key);
|
|
bool IniHasValue(LIST *o, char *key);
|
|
bool InStr(char *str, char *keyword);
|
|
bool InStrEx(char *str, char *keyword, bool case_sensitive);
|
|
bool InStrList(char *target_str, char *tokens, char *splitter, bool case_sensitive);
|
|
TOKEN_LIST *ParseTokenWithoutNullStr(char *str, char *split_chars);
|
|
TOKEN_LIST *ParseTokenWithNullStr(char *str, char *split_chars);
|
|
char *DefaultTokenSplitChars();
|
|
bool IsCharInStr(char *str, char c);
|
|
UINT HexTo4Bit(char c);
|
|
char FourBitToHex(UINT value);
|
|
void ToHex(char *str, UINT value);
|
|
void ToHex64(char *str, UINT64 value);
|
|
UINT HexToInt(char *str);
|
|
UINT64 HexToInt64(char *str);
|
|
UINT SearchAsciiInBinary(void *data, UINT size, char *str, bool case_sensitive);
|
|
void IntListToStr(char *str, UINT str_size, LIST *o, char *separate_str);
|
|
LIST *StrToIntList(char *str, bool sorted);
|
|
void NormalizeIntListStr(char *dst, UINT dst_size, char *src, bool sorted, char *separate_str);
|
|
void ClearStr(char *str, UINT str_size);
|
|
void SetStrCaseAccordingToBits(char *str, UINT bits);
|
|
|
|
#endif // STR_H
|
|
|