Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-NRF
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
Operations
Operations
Metrics
Environments
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
OpenXG
OpenXG-NRF
Commits
aae8130e
Unverified
Commit
aae8130e
authored
Sep 08, 2021
by
kharade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
query string parsing added
parent
da873b4a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
17 deletions
+50
-17
src/api-server/nrf-http2-server.cpp
src/api-server/nrf-http2-server.cpp
+29
-16
src/api-server/nrf-http2-server.h
src/api-server/nrf-http2-server.h
+5
-1
src/common/utils/string.cpp
src/common/utils/string.cpp
+14
-0
src/common/utils/string.hpp
src/common/utils/string.hpp
+2
-0
No files found.
src/api-server/nrf-http2-server.cpp
View file @
aae8130e
...
...
@@ -31,6 +31,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/thread.hpp>
#include <boost/thread/future.hpp>
#include <regex>
#include <nlohmann/json.hpp>
#include <string>
...
...
@@ -69,11 +70,29 @@ void nrf_http2_server::start() {
if
(
request
.
method
().
compare
(
"GET"
)
==
0
)
{
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
nFProfile
);
std
::
vector
<
std
::
string
>
split_result
;
std
::
vector
<
std
::
string
>
split_query
;
boost
::
split
(
split_result
,
request
.
uri
().
path
,
boost
::
is_any_of
(
"/"
));
boost
::
split
(
split_query
,
request
.
uri
().
path
,
boost
::
is_any_of
(
"?"
));
if
(
split_result
.
size
()
==
5
)
{
// Read the profile of given NF Instance
nfInstanceID
=
split_result
[
split_result
.
size
()
-
1
].
c_str
();
this
->
get_nf_instance_handler
(
nfInstanceID
,
response
);
}
if
(
split_result
.
size
()
==
4
)
{
// Retrieves a collection of NF Instances
std
::
string
querystring
=
split_query
[
split_query
.
size
()
-
1
].
c_str
();
std
::
string
nfType
=
util
::
get_query_param
(
querystring
,
"nf-type"
);
uint32_t
limit
=
atoi
(
util
::
get_query_param
(
querystring
,
"limit"
).
c_str
());
this
->
get_nf_instances_handler
(
nfType
,
limit
,
response
);
}
}
if
(
request
.
method
().
compare
(
"PATCH"
)
==
0
&&
len
>
0
)
{
std
::
vector
<
PatchItem
>
patchItem
;
nlohmann
::
json
::
parse
(
msg
.
c_str
()).
get_to
(
patchItem
);
...
...
@@ -218,21 +237,15 @@ void nrf_http2_server::get_nf_instance_handler(
}
void
nrf_http2_server
::
get_nf_instances_handler
(
const
std
::
string
&
nfInstanceID
,
const
response
&
response
)
{
const
std
::
string
&
nfType
,
const
uint32_t
&
limit
,
const
response
&
response
)
{
Logger
::
nrf_sbi
().
info
(
"Got a request to retrieve a collection of NF Instances"
);
std
::
string
nf_type
=
{};
// if (!nfType.isEmpty()) {
// nf_type = nfType.get();
// Logger::nrf_sbi().debug("\tNF type: %s", nf_type.c_str());
// }
if
(
!
nfType
.
empty
())
Logger
::
nrf_sbi
().
debug
(
"
\t
NF type: %s"
,
nfType
.
c_str
());
uint32_t
limit_item
=
0
;
// if (!limit.isEmpty()) {
// limit_item = limit.get();
// Logger::nrf_sbi().debug("\tLimit number of items: %d", limit_item);
// }
if
(
limit
>
0
)
Logger
::
nrf_sbi
().
debug
(
"
\t
Limit number of items: %d"
,
limit
);
int
http_code
=
0
;
ProblemDetails
problem_details
=
{};
...
...
@@ -242,7 +255,7 @@ void nrf_http2_server::get_nf_instances_handler(
std
::
vector
<
std
::
string
>
uris
=
{};
m_nrf_app
->
handle_get_nf_instances
(
nf
_type
,
uris
,
limit_item
,
http_code
,
2
,
problem_details
);
nf
Type
,
uris
,
limit
,
http_code
,
2
,
problem_details
);
if
(
http_code
!=
HTTP_STATUS_CODE_200_OK
)
{
to_json
(
json_data
,
problem_details
);
...
...
@@ -255,7 +268,7 @@ void nrf_http2_server::get_nf_instances_handler(
h
.
emplace
(
"location"
,
header_value
{
m_address
+
NNRF_NFM_BASE
+
nrf_cfg
.
sbi_api_version
+
"/nf-instances/"
+
nfInstanceID
});
"/nf-instances/"
});
h
.
emplace
(
"content-type"
,
header_value
{
content_type
});
response
.
write_head
(
http_code
,
h
);
response
.
end
();
...
...
@@ -422,7 +435,7 @@ void nrf_http2_server::search_nf_instances_handler(
Logger
::
nrf_sbi
().
info
(
"Got a request to discover the set of NF instances that satisfies a "
"number of input query parameters"
);
// ToDo
std
::
string
target_nf_type
=
{};
// if (!targetNfType.isEmpty()) {
// target_nf_type = targetNfType.get();
...
...
src/api-server/nrf-http2-server.h
View file @
aae8130e
...
...
@@ -31,6 +31,8 @@
#define FILE_NRF_HTTP2_SERVER_SEEN
#include "conversions.hpp"
#include "string.hpp"
//#include "nrf.h"
#include "nrf_app.hpp"
#include "uint_generator.hpp"
...
...
@@ -54,7 +56,8 @@ class nrf_http2_server {
void
get_nf_instance_handler
(
const
std
::
string
&
nfInstanceID
,
const
response
&
response
);
void
get_nf_instances_handler
(
const
std
::
string
&
nfInstanceID
,
const
response
&
response
);
const
std
::
string
&
nfType
,
const
uint32_t
&
limit
,
const
response
&
response
);
void
update_instance_handler
(
const
std
::
string
&
nfInstanceID
,
const
std
::
vector
<
PatchItem
>&
patchItem
,
const
response
&
response
);
...
...
@@ -67,6 +70,7 @@ class nrf_http2_server {
const
std
::
string
&
subscriptionID
,
const
response
&
response
);
void
search_nf_instances_handler
(
const
SubscriptionData
&
subscriptionData
,
const
response
&
response
);
void
access_token_request_handler
(
const
SubscriptionData
&
subscriptionData
,
const
response
&
response
);
void
stop
();
...
...
src/common/utils/string.cpp
View file @
aae8130e
...
...
@@ -25,6 +25,7 @@
#include <cctype>
#include <locale>
#include <stdarg.h>
#include <regex>
template
<
class
T
>
class
Buffer
{
...
...
@@ -86,3 +87,16 @@ std::string& util::rtrim(std::string& s) {
std
::
string
&
util
::
trim
(
std
::
string
&
s
)
{
return
util
::
ltrim
(
util
::
rtrim
(
s
));
}
// extract query param from given querystring
std
::
string
&
util
::
get_query_param
(
std
::
string
&
querystring
,
std
::
string
param
)
{
std
::
regex
reList
(
"([^=]*)=([^&]*)&?"
);
std
::
string
tmp
=
param
;
std
::
for_each
(
std
::
sregex_iterator
(
querystring
.
begin
(),
querystring
.
end
(),
reList
),
std
::
sregex_iterator
(),
[
param
](
std
::
smatch
const
&
match
)
{
std
::
string
qs_match_1
=
match
[
1
].
str
();
if
(
qs_match_1
==
param
)
return
match
[
2
].
str
();
});
}
\ No newline at end of file
src/common/utils/string.hpp
View file @
aae8130e
...
...
@@ -39,5 +39,7 @@ std::string& ltrim(std::string& s);
std
::
string
&
rtrim
(
std
::
string
&
s
);
// trim from both ends
std
::
string
&
trim
(
std
::
string
&
s
);
// extract query param from given querystring
std
::
string
&
get_query_param
(
std
::
string
&
querystring
,
std
::
string
param
);
}
// namespace util
#endif
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