Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
UERANSIM
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
UERANSIM
Commits
735cd3b1
Commit
735cd3b1
authored
Feb 11, 2021
by
aligungr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AssertNodeName added to common utils
parent
dd943245
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletion
+33
-1
src/utils/common.cpp
src/utils/common.cpp
+23
-1
src/utils/common.hpp
src/utils/common.hpp
+10
-0
No files found.
src/utils/common.cpp
View file @
735cd3b1
...
@@ -8,11 +8,11 @@
...
@@ -8,11 +8,11 @@
#include "common.hpp"
#include "common.hpp"
#include <atomic>
#include <atomic>
#include <cassert>
#include <chrono>
#include <chrono>
#include <random>
#include <random>
#include <regex>
#include <regex>
#include <sstream>
#include <sstream>
#include <stdexcept>
#include <thread>
#include <thread>
#include <unistd.h>
#include <unistd.h>
...
@@ -273,3 +273,25 @@ bool utils::IsRoot()
...
@@ -273,3 +273,25 @@ bool utils::IsRoot()
{
{
return
geteuid
()
==
0
;
return
geteuid
()
==
0
;
}
}
void
utils
::
AssertNodeName
(
const
std
::
string
&
str
)
{
if
(
str
.
length
()
<=
2
)
throw
std
::
runtime_error
(
"Node name assertion failed: string'"
+
str
+
"' is too short"
);
if
(
str
.
length
()
>
1024
)
throw
std
::
runtime_error
(
"Node name assertion failed: string'"
+
str
+
"' is too long"
);
for
(
char
c
:
str
)
{
if
(
c
>=
'0'
&&
c
<=
'9'
)
continue
;
if
(
c
>=
'a'
&&
c
<=
'z'
)
continue
;
if
(
c
>=
'A'
&&
c
<=
'Z'
)
continue
;
if
(
c
==
'-'
||
c
==
'_'
)
continue
;
throw
std
::
runtime_error
(
"Node name assertion failed: string '"
+
str
+
"' contains illegal character: "
+
std
::
string
(
1
,
c
));
}
}
src/utils/common.hpp
View file @
735cd3b1
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
#include "octet.hpp"
#include "octet.hpp"
#include "octet_string.hpp"
#include "octet_string.hpp"
#include "time_stamp.hpp"
#include "time_stamp.hpp"
#include <iomanip>
#include <string>
#include <string>
#include <vector>
#include <vector>
...
@@ -31,6 +32,7 @@ int ParseInt(const char *str);
...
@@ -31,6 +32,7 @@ int ParseInt(const char *str);
uint64_t
Random64
();
uint64_t
Random64
();
void
Sleep
(
int
ms
);
void
Sleep
(
int
ms
);
bool
IsRoot
();
bool
IsRoot
();
void
AssertNodeName
(
const
std
::
string
&
str
);
template
<
typename
T
>
template
<
typename
T
>
inline
void
ClearAndDelete
(
std
::
vector
<
T
*>
&
vector
)
inline
void
ClearAndDelete
(
std
::
vector
<
T
*>
&
vector
)
...
@@ -40,4 +42,12 @@ inline void ClearAndDelete(std::vector<T *> &vector)
...
@@ -40,4 +42,12 @@ inline void ClearAndDelete(std::vector<T *> &vector)
vector
.
clear
();
vector
.
clear
();
}
}
template
<
typename
T
>
static
std
::
string
IntToHex
(
T
i
)
{
std
::
stringstream
stream
;
stream
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
sizeof
(
T
)
*
2
)
<<
std
::
hex
<<
i
;
return
stream
.
str
();
}
}
// namespace utils
}
// namespace utils
\ No newline at end of file
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