Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-SMF
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-SMF
Commits
3937bfb1
Commit
3937bfb1
authored
Jun 04, 2021
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add error handling for Curl multi
parent
2716d4c0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
169 additions
and
113 deletions
+169
-113
src/smf_app/smf_sbi.cpp
src/smf_app/smf_sbi.cpp
+163
-107
src/smf_app/smf_sbi.hpp
src/smf_app/smf_sbi.hpp
+6
-6
No files found.
src/smf_app/smf_sbi.cpp
View file @
3937bfb1
...
...
@@ -155,14 +155,18 @@ smf_sbi::smf_sbi() {
Logger
::
smf_sbi
().
error
(
"Cannot create task TASK_SMF_SBI"
);
throw
std
::
runtime_error
(
"Cannot create task TASK_SMF_SBI"
);
}
curl_global_init
(
CURL_GLOBAL_DEFAULT
);
CURLcode
code
=
curl_global_init
(
CURL_GLOBAL_DEFAULT
);
curl_multi
=
curl_multi_init
();
handles
=
{};
headers
=
NULL
;
headers
=
nullptr
;
headers
=
curl_slist_append
(
headers
,
"Accept: application/json"
);
headers
=
curl_slist_append
(
headers
,
"Content-Type: application/json"
);
headers
=
curl_slist_append
(
headers
,
"charsets: utf-8"
);
if
((
code
<
0
)
or
(
curl_multi
==
nullptr
)
or
(
headers
==
nullptr
))
{
Logger
::
smf_sbi
().
error
(
"Cannot initialize Curl Multi Interface"
);
throw
std
::
runtime_error
(
"Cannot create task TASK_SMF_SBI"
);
}
Logger
::
smf_sbi
().
startup
(
"Started"
);
}
...
...
@@ -229,9 +233,13 @@ void smf_sbi::send_n1n2_message_transfer_request(
add_promise
(
promise_id
,
p
);
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
if
(
!
curl_create_handle
(
sm_context_res
->
res
.
get_amf_url
(),
data_str
,
str_len
,
response_data
,
pid_ptr
,
"POST"
,
true
);
pid_ptr
,
"POST"
,
true
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
;
}
// Wait for the response back
uint32_t
response_code
=
get_available_response
(
f
);
...
...
@@ -323,9 +331,13 @@ void smf_sbi::send_n1n2_message_transfer_request(
add_promise
(
promise_id
,
p
);
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
if
(
!
curl_create_handle
(
sm_session_modification
->
msg
.
get_amf_url
(),
data_str
,
str_len
,
response_data
,
pid_ptr
,
"POST"
,
true
);
response_data
,
pid_ptr
,
"POST"
,
true
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
;
}
// Wait for the response back
uint32_t
response_code
=
get_available_response
(
f
);
...
...
@@ -386,9 +398,13 @@ void smf_sbi::send_n1n2_message_transfer_request(
add_promise
(
promise_id
,
p
);
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
report_msg
->
res
.
get_amf_url
(),
data_str
,
str_len
,
response_data
,
pid_ptr
,
"POST"
,
true
);
if
(
!
curl_create_handle
(
report_msg
->
res
.
get_amf_url
(),
data_str
,
str_len
,
response_data
,
pid_ptr
,
"POST"
,
true
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
;
}
// Wait for the response back
uint32_t
httpCode
=
get_available_response
(
f
);
...
...
@@ -455,8 +471,13 @@ void smf_sbi::send_sm_context_status_notification(
add_promise
(
promise_id
,
p
);
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
sm_context_status
->
amf_status_uri
,
body
,
response_data
,
pid_ptr
,
"POST"
);
if
(
!
curl_create_handle
(
sm_context_status
->
amf_status_uri
,
body
,
response_data
,
pid_ptr
,
"POST"
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
;
}
// Wait for the response back
uint32_t
response_code
=
get_available_response
(
f
);
...
...
@@ -513,7 +534,11 @@ void smf_sbi::notify_subscribed_event(
std
::
string
url
=
i
.
get_notif_uri
();
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
url
,
body
,
response_data
,
pid_ptr
,
"POST"
);
if
(
!
curl_create_handle
(
url
,
body
,
response_data
,
pid_ptr
,
"POST"
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
;
}
// Wait for the response back
uint32_t
response_code
=
get_available_response
(
f
);
...
...
@@ -559,7 +584,11 @@ void smf_sbi::register_nf_instance(
add_promise
(
promise_id
,
p
);
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
url
,
body
,
response_data
,
pid_ptr
,
"POST"
);
if
(
!
curl_create_handle
(
url
,
body
,
response_data
,
pid_ptr
,
"POST"
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
;
}
// Wait for the response back
uint32_t
httpCode
=
get_available_response
(
f
);
...
...
@@ -639,7 +668,11 @@ void smf_sbi::update_nf_instance(
add_promise
(
promise_id
,
p
);
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
url
,
body
,
response_data
,
pid_ptr
,
"PATCH"
);
if
(
!
curl_create_handle
(
url
,
body
,
response_data
,
pid_ptr
,
"PATCH"
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
;
}
// Wait for the response back
uint32_t
httpCode
=
get_available_response
(
f
);
...
...
@@ -702,7 +735,11 @@ void smf_sbi::deregister_nf_instance(
add_promise
(
promise_id
,
p
);
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
url
,
response_data
,
pid_ptr
,
"DELETE"
);
if
(
!
curl_create_handle
(
url
,
response_data
,
pid_ptr
,
"DELETE"
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
;
}
// Wait for the response back
uint32_t
httpCode
=
get_available_response
(
f
);
...
...
@@ -750,7 +787,11 @@ void smf_sbi::subscribe_upf_status_notify(
add_promise
(
promise_id
,
p
);
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
msg
->
url
,
body
,
response_data
,
pid_ptr
,
"POST"
);
if
(
!
curl_create_handle
(
msg
->
url
,
body
,
response_data
,
pid_ptr
,
"POST"
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
;
}
// Wait for the response back
uint32_t
httpCode
=
get_available_response
(
f
);
...
...
@@ -797,7 +838,11 @@ bool smf_sbi::get_sm_data(
add_promise
(
promise_id
,
p
);
// Create a new curl easy handle and add to the multi handle
curl_create_handle
(
url
,
response_data
,
pid_ptr
,
"GET"
);
if
(
!
curl_create_handle
(
url
,
response_data
,
pid_ptr
,
"GET"
))
{
Logger
::
smf_sbi
().
warn
(
"Could not create a new handle to send message"
);
// TODO: remove promise
return
false
;
}
// Wait for the response back
uint32_t
httpCode
=
get_available_response
(
f
);
...
...
@@ -910,7 +955,7 @@ void smf_sbi::subscribe_sm_data() {
}
//------------------------------------------------------------------------------
void
smf_sbi
::
curl_create_handle
(
bool
smf_sbi
::
curl_create_handle
(
const
std
::
string
&
uri
,
const
char
*
data
,
uint32_t
data_len
,
std
::
string
&
response_data
,
uint32_t
*
promise_id
,
const
std
::
string
&
method
,
bool
is_multipart
)
{
...
...
@@ -923,7 +968,11 @@ void smf_sbi::curl_create_handle(
headers
=
curl_slist_append
(
headers
,
content_type
.
c_str
());
}
if
(
curl
)
{
if
((
curl
==
nullptr
)
or
(
headers
==
nullptr
))
{
Logger
::
smf_sbi
().
error
(
"Cannot initialize a new Curl Handle"
);
return
false
;
}
curl_easy_setopt
(
curl
,
CURLOPT_HTTPHEADER
,
headers
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
uri
.
c_str
());
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
...
...
@@ -951,23 +1000,27 @@ void smf_sbi::curl_create_handle(
// Add to the multi handle
curl_multi_add_handle
(
curl_multi
,
curl
);
handles
.
push_back
(
curl
);
}
// the curl cmd will actually be performed in perform_curl_multi
perform_curl_multi
(
0
);
// TODO: current time as parameter if curl is performed per event
return
;
return
true
;
}
//------------------------------------------------------------------------------
void
smf_sbi
::
curl_create_handle
(
bool
smf_sbi
::
curl_create_handle
(
const
std
::
string
&
uri
,
const
std
::
string
&
data
,
std
::
string
&
response_data
,
uint32_t
*
promise_id
,
const
std
::
string
&
method
)
{
headers
=
curl_slist_append
(
headers
,
"Content-Type: application/json"
);
// create handle for a curl request
CURL
*
curl
=
curl_easy_init
();
if
(
curl
)
{
if
((
curl
==
nullptr
)
or
(
headers
==
nullptr
))
{
Logger
::
smf_sbi
().
error
(
"Cannot initialize a new Curl Handle"
);
return
false
;
}
curl_easy_setopt
(
curl
,
CURLOPT_HTTPHEADER
,
headers
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
uri
.
c_str
());
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
...
...
@@ -995,22 +1048,25 @@ void smf_sbi::curl_create_handle(
// Add to the multi handle
curl_multi_add_handle
(
curl_multi
,
curl
);
handles
.
push_back
(
curl
);
}
// the curl cmd will actually be performed in perform_curl_multi
perform_curl_multi
(
0
);
// TODO: current time as parameter if curl is performed per event
return
;
return
true
;
}
//------------------------------------------------------------------------------
void
smf_sbi
::
curl_create_handle
(
bool
smf_sbi
::
curl_create_handle
(
const
std
::
string
&
uri
,
std
::
string
&
response_data
,
uint32_t
*
promise_id
,
const
std
::
string
&
method
)
{
// create handle for a curl request
CURL
*
curl
=
curl_easy_init
();
if
(
curl
)
{
if
((
curl
==
nullptr
)
or
(
headers
==
nullptr
))
{
Logger
::
smf_sbi
().
error
(
"Cannot initialize a new Curl Handle"
);
return
false
;
}
curl_easy_setopt
(
curl
,
CURLOPT_HTTPHEADER
,
headers
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
uri
.
c_str
());
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
...
...
@@ -1030,12 +1086,12 @@ void smf_sbi::curl_create_handle(
// Add to the multi handle
curl_multi_add_handle
(
curl_multi
,
curl
);
handles
.
push_back
(
curl
);
}
// the curl cmd will actually be performed in perform_curl_multi
perform_curl_multi
(
0
);
// TODO: current time as parameter if curl is performed per event
return
;
return
true
;
}
//------------------------------------------------------------------------------
...
...
src/smf_app/smf_sbi.hpp
View file @
3937bfb1
...
...
@@ -176,9 +176,9 @@ class smf_sbi {
* @param [uint32_t* ] promise_id: pointer to the promise id
* @param [const std::string&] method: HTTP method
* @param [bool] is_multipart: use multipart or json format
* @return
void
* @return
true if a handle was created successfully, otherwise return false
*/
void
curl_create_handle
(
bool
curl_create_handle
(
const
std
::
string
&
uri
,
const
char
*
data
,
uint32_t
data_len
,
std
::
string
&
response_data
,
uint32_t
*
promise_id
,
const
std
::
string
&
method
,
bool
is_multipart
);
...
...
@@ -191,9 +191,9 @@ class smf_sbi {
* @param [uint32_t* ] promise_id: pointer to the promise id
* @param [const std::string&] method: HTTP method
* @param [bool] is_multipart: use multipart or json format
* @return
void
* @return
true if a handle was created successfully, otherwise return false
*/
void
curl_create_handle
(
bool
curl_create_handle
(
const
std
::
string
&
uri
,
const
std
::
string
&
data
,
std
::
string
&
response_data
,
uint32_t
*
promise_id
,
const
std
::
string
&
method
);
...
...
@@ -204,9 +204,9 @@ class smf_sbi {
* @param [std::string &] response_data: response data
* @param [uint32_t* ] promise_id: pointer to the promise id
* @param [const std::string&] method: HTTP method
* @return
void
* @return
true if a handle was created successfully, otherwise return false
*/
void
curl_create_handle
(
bool
curl_create_handle
(
const
std
::
string
&
uri
,
std
::
string
&
response_data
,
uint32_t
*
promise_id
,
const
std
::
string
&
method
);
...
...
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