Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nx-libs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dimbor
nx-libs
Commits
c6e95651
Commit
c6e95651
authored
Jun 15, 2016
by
Mike Gabriel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nxcomp/Loop.cpp: Add Unix file socket support for proxy <-> proxy connection.
parent
b23dcd10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
25 deletions
+129
-25
ChannelEndPoint.cpp
nxcomp/ChannelEndPoint.cpp
+120
-23
ChannelEndPoint.h
nxcomp/ChannelEndPoint.h
+9
-2
Loop.cpp
nxcomp/Loop.cpp
+0
-0
No files found.
nxcomp/ChannelEndPoint.cpp
View file @
c6e95651
...
...
@@ -24,6 +24,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include "ChannelEndPoint.h"
...
...
@@ -31,8 +32,21 @@
ChannelEndPoint
::
ChannelEndPoint
(
const
char
*
spec
)
:
defaultTCPPort_
(
0
),
defaultTCPInterface_
(
0
),
defaultUnixPath_
(
NULL
)
{
spec_
=
(
spec
?
strdup
(
spec
)
:
NULL
);
defaultUnixPath_
(
NULL
),
spec_
(
NULL
)
{
setSpec
(
spec
);
}
ChannelEndPoint
::~
ChannelEndPoint
()
{
char
*
unixPath
=
NULL
;
if
(
getUnixPath
(
&
unixPath
))
{
struct
stat
st
;
lstat
(
unixPath
,
&
st
);
if
(
S_ISSOCK
(
st
.
st_mode
))
unlink
(
unixPath
);
}
}
void
...
...
@@ -40,21 +54,92 @@ ChannelEndPoint::setSpec(const char *spec) {
if
(
spec_
)
free
(
spec_
);
if
(
spec
&&
strlen
(
spec
))
{
spec_
=
strdup
(
spec
);
isUnix_
=
getUnixPath
();
isTCP_
=
getTCPHostAndPort
();
}
else
{
spec_
=
NULL
;
isUnix_
=
false
;
isTCP_
=
false
;
}
}
void
ChannelEndPoint
::
setSpec
(
int
port
)
{
ChannelEndPoint
::
setSpec
(
long
port
)
{
if
(
port
>=
0
)
{
char
tmp
[
20
];
sprintf
(
tmp
,
"%d"
,
port
);
sprintf
(
tmp
,
"%
l
d"
,
port
);
setSpec
(
tmp
);
}
else
{
disable
();
}
}
void
ChannelEndPoint
::
setSpec
(
const
char
*
hostName
,
long
port
)
{
int
length
;
if
(
spec_
)
free
(
spec_
);
isUnix_
=
false
;
isTCP_
=
false
;
if
(
hostName
&&
strlen
(
hostName
)
&&
port
>=
1
)
{
length
=
snprintf
(
NULL
,
0
,
"tcp:%s:%ld"
,
hostName
,
port
);
spec_
=
(
char
*
)
calloc
(
length
+
1
,
sizeof
(
char
));
snprintf
(
spec_
,
length
+
1
,
"tcp:%s:%ld"
,
hostName
,
port
);
isTCP_
=
true
;
}
else
setSpec
((
char
*
)
NULL
);
}
bool
ChannelEndPoint
::
getSpec
(
char
**
socketUri
)
const
{
if
(
socketUri
)
*
socketUri
=
NULL
;
char
*
unixPath
=
NULL
;
char
*
hostName
=
NULL
;
long
port
=
-
1
;
char
*
newSocketUri
=
NULL
;
int
length
=
-
1
;
if
(
getUnixPath
(
&
unixPath
))
{
length
=
snprintf
(
NULL
,
0
,
"unix:%s"
,
unixPath
);
}
else
if
(
getTCPHostAndPort
(
&
hostName
,
&
port
))
{
length
=
snprintf
(
NULL
,
0
,
"tcp:%s:%ld"
,
hostName
,
port
);
}
if
(
length
>
0
)
{
newSocketUri
=
(
char
*
)
calloc
(
length
+
1
,
sizeof
(
char
));
if
(
isUnixSocket
())
snprintf
(
newSocketUri
,
length
+
1
,
"unix:%s"
,
unixPath
);
else
snprintf
(
newSocketUri
,
length
+
1
,
"tcp:%s:%ld"
,
hostName
,
port
);
if
(
socketUri
)
*
socketUri
=
strdup
(
newSocketUri
);
}
free
(
newSocketUri
);
free
(
unixPath
);
free
(
hostName
);
if
(
*
socketUri
!=
'\0'
)
return
true
;
return
false
;
}
void
ChannelEndPoint
::
setDefaultTCPPort
(
long
port
)
{
defaultTCPPort_
=
port
;
...
...
@@ -76,10 +161,12 @@ ChannelEndPoint::setDefaultUnixPath(char *path) {
}
void
ChannelEndPoint
::
disable
()
{
setSpec
(
"0"
);
}
ChannelEndPoint
::
disable
()
{
setSpec
(
"0"
);
}
bool
ChannelEndPoint
::
specIs
Port
(
long
*
port
)
const
{
ChannelEndPoint
::
get
Port
(
long
*
port
)
const
{
if
(
port
)
*
port
=
0
;
long
p
=
-
1
;
if
(
spec_
)
{
...
...
@@ -101,7 +188,7 @@ ChannelEndPoint::getUnixPath(char **unixPath) const {
long
p
;
char
*
path
=
NULL
;
if
(
specIs
Port
(
&
p
))
{
if
(
get
Port
(
&
p
))
{
if
(
p
!=
1
)
return
false
;
}
else
if
(
spec_
&&
(
strncmp
(
"unix:"
,
spec_
,
5
)
==
0
))
{
...
...
@@ -122,6 +209,11 @@ ChannelEndPoint::getUnixPath(char **unixPath) const {
return
true
;
}
bool
ChannelEndPoint
::
isUnixSocket
()
const
{
return
isUnix_
;
}
// FIXME!!!
static
const
char
*
getComputerName
()
{
...
...
@@ -158,7 +250,7 @@ ChannelEndPoint::getTCPHostAndPort(char **host, long *port) const {
if
(
host
)
*
host
=
NULL
;
if
(
port
)
*
port
=
0
;
if
(
specIs
Port
(
&
p
))
{
if
(
get
Port
(
&
p
))
{
h_len
=
0
;
}
else
if
(
spec_
&&
(
strncmp
(
"tcp:"
,
spec_
,
4
)
==
0
))
{
...
...
@@ -194,8 +286,8 @@ ChannelEndPoint::getTCPHostAndPort(char **host, long *port) const {
}
bool
ChannelEndPoint
::
enabled
()
const
{
return
(
getUnixPath
()
||
getTCPHostAndPort
())
;
ChannelEndPoint
::
isTCPSocket
()
const
{
return
isTCP_
;
}
long
ChannelEndPoint
::
getTCPPort
()
const
{
...
...
@@ -205,8 +297,15 @@ long ChannelEndPoint::getTCPPort() const {
}
bool
ChannelEndPoint
::
enabled
()
const
{
return
(
isUnixSocket
()
||
isTCPSocket
());
}
bool
ChannelEndPoint
::
validateSpec
()
{
return
(
specIsPort
()
||
getUnixPath
()
||
getTCPHostAndPort
());
isTCP_
=
getTCPHostAndPort
();
isUnix_
=
getUnixPath
();
return
(
getPort
()
||
isUnix_
||
isTCP_
);
}
ChannelEndPoint
&
ChannelEndPoint
::
operator
=
(
const
ChannelEndPoint
&
other
)
{
...
...
@@ -219,26 +318,24 @@ ChannelEndPoint &ChannelEndPoint::operator=(const ChannelEndPoint &other) {
old
=
spec_
;
spec_
=
(
other
.
spec_
?
strdup
(
other
.
spec_
)
:
NULL
);
free
(
old
);
isUnix_
=
getUnixPath
();
isTCP_
=
getTCPHostAndPort
();
return
*
this
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ChannelEndPoint
&
endPoint
)
{
if
(
endPoint
.
enabled
())
{
char
*
unixPath
,
*
host
;
long
port
;
if
(
endPoint
.
getUnixPath
(
&
unixPath
))
{
os
<<
"unix:"
<<
unixPath
;
free
(
unixPath
);
char
*
endPointSpec
=
NULL
;
if
(
endPoint
.
getSpec
(
&
endPointSpec
))
{
os
<<
endPointSpec
;
free
(
endPointSpec
);
}
else
if
(
endPoint
.
getTCPHostAndPort
(
&
host
,
&
port
))
{
os
<<
"tcp:"
<<
host
<<
":"
<<
port
;
free
(
host
);
}
else
{
else
os
<<
"(invalid)"
;
}
}
else
{
else
{
os
<<
"(disabled)"
;
}
return
os
;
...
...
nxcomp/ChannelEndPoint.h
View file @
c6e95651
...
...
@@ -33,25 +33,32 @@ class ChannelEndPoint
int
defaultTCPInterface_
;
// 0=localhost, otherwise IP of public interface.
char
*
defaultUnixPath_
;
char
*
spec_
;
bool
isUnix_
;
bool
isTCP_
;
bool
specIs
Port
(
long
*
port
=
NULL
)
const
;
bool
get
Port
(
long
*
port
=
NULL
)
const
;
public
:
ChannelEndPoint
(
const
char
*
spec
=
NULL
);
~
ChannelEndPoint
();
ChannelEndPoint
&
operator
=
(
const
ChannelEndPoint
&
other
);
bool
enabled
()
const
;
bool
disabled
()
{
return
!
enabled
();
}
void
disable
();
void
setSpec
(
const
char
*
spec
);
void
setSpec
(
int
port
);
void
setSpec
(
long
port
);
void
setSpec
(
const
char
*
hostName
,
long
port
);
bool
getSpec
(
char
**
socketUri
)
const
;
void
setDefaultTCPPort
(
long
port
);
void
setDefaultTCPInterface
(
int
publicInterface
);
void
setDefaultUnixPath
(
char
*
path
);
bool
getUnixPath
(
char
**
path
=
NULL
)
const
;
bool
isUnixSocket
()
const
;
bool
getTCPHostAndPort
(
char
**
hostname
=
NULL
,
long
*
port
=
NULL
)
const
;
long
getTCPPort
()
const
;
bool
isTCPSocket
()
const
;
bool
validateSpec
();
};
...
...
nxcomp/Loop.cpp
View file @
c6e95651
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment