1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-23 01:49:53 +03:00

OpenVPN: merge OvsParseOptions() and OvsParsePeerInfo() into a single function

This commit is contained in:
Davide Beatrici 2018-04-05 22:28:23 +02:00
parent 86c82b8ccf
commit 970e217380
2 changed files with 11 additions and 43 deletions

View File

@ -707,7 +707,7 @@ void OvsBeginIPCAsyncConnectionIfEmpty(OPENVPN_SERVER *s, OPENVPN_SESSION *se, O
// if the option --push-peer-info is enabled.
// It also sends all of the client's environment
// variables whose names start with "UV_".
pi = OvsParsePeerInfo(c->ClientKey.PeerInfo);
pi = OvsParseData(c->ClientKey.PeerInfo, OPENVPN_DATA_PEERINFO);
// Check presence of custom hostname
if (OvsHasEntry(pi, "UV_HOSTNAME"))
@ -832,7 +832,7 @@ void OvsSetupSessionParameters(OPENVPN_SERVER *s, OPENVPN_SESSION *se, OPENVPN_C
StrCpy(opt_str, sizeof(opt_str), s->Cedar->OpenVPNDefaultClientOption);
}
o = OvsParseOptions(opt_str);
o = OvsParseData(opt_str, OPENVPN_DATA_OPTIONS);
if (se->Mode == OPENVPN_MODE_UNKNOWN)
{
@ -984,13 +984,13 @@ MD *OvsGetMd(char *name)
return m;
}
// Parse the option string
LIST *OvsParseOptions(char *str)
// Parse data string
LIST *OvsParseData(char *str, int type)
{
LIST *o = NewListFast(NULL);
TOKEN_LIST *t;
t = ParseTokenWithoutNullStr(str, ",");
t = ParseTokenWithoutNullStr(str, type == OPENVPN_DATA_OPTIONS ? "," : "\n");
if (t != NULL)
{
UINT i;
@ -1002,42 +1002,7 @@ LIST *OvsParseOptions(char *str)
char *line = t->Token[i];
Trim(line);
if (GetKeyAndValue(line, key, sizeof(key), value, sizeof(value), " \t"))
{
INI_ENTRY *e = ZeroMalloc(sizeof(INI_ENTRY));
e->Key = CopyStr(key);
e->Value = CopyStr(value);
Add(o, e);
}
}
FreeToken(t);
}
return o;
}
// Parse the peer info string
LIST *OvsParsePeerInfo(char *str)
{
LIST *o = NewListFast(NULL);
TOKEN_LIST *t;
t = ParseTokenWithoutNullStr(str, "\n");
if (t != NULL)
{
UINT i;
for (i = 0;i < t->NumTokens;i++)
{
char key[MAX_SIZE];
char value[MAX_SIZE];
char *line = t->Token[i];
Trim(line);
if (GetKeyAndValue(line, key, sizeof(key), value, sizeof(value), "=\t"))
if (GetKeyAndValue(line, key, sizeof(key), value, sizeof(value), type == OPENVPN_DATA_OPTIONS ? " \t" : "=\t"))
{
INI_ENTRY *e = ZeroMalloc(sizeof(INI_ENTRY));

View File

@ -190,6 +190,10 @@
#define OPENVPN_MODE_L2 1 // TAP (Ethernet)
#define OPENVPN_MODE_L3 2 // TUN (IP)
// Data
#define OPENVPN_DATA_OPTIONS 0
#define OPENVPN_DATA_PEERINFO 1
//// Type
@ -361,8 +365,7 @@ void OvsSetupSessionParameters(OPENVPN_SERVER *s, OPENVPN_SESSION *se, OPENVPN_C
BUF *OvsBuildKeyMethod2(OPENVPN_KEY_METHOD_2 *d);
void OvsWriteStringToBuf(BUF *b, char *str, UINT max_size);
LIST *OvsParseOptions(char *str);
LIST *OvsParsePeerInfo(char *str);
LIST *OvsParseData(char *str, int type);
void OvsFreeList(LIST *o);
LIST *OvsNewList();
void OvsAddEntry(LIST *o, char *key, char *value);