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
e1c9d4df
Commit
e1c9d4df
authored
Jan 23, 2021
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup
parent
c63a4711
Changes
28
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
28 changed files
with
3352 additions
and
3275 deletions
+3352
-3275
src/api-server/api/SMContextsCollectionApi.cpp
src/api-server/api/SMContextsCollectionApi.cpp
+2
-1
src/api-server/impl/IndividualSMContextApiImpl.cpp
src/api-server/impl/IndividualSMContextApiImpl.cpp
+2
-2
src/api-server/impl/IndividualSubscriptionDocumentApiImpl.cpp
...api-server/impl/IndividualSubscriptionDocumentApiImpl.cpp
+0
-1
src/api-server/impl/NFStatusNotifyApiImpl.h
src/api-server/impl/NFStatusNotifyApiImpl.h
+0
-1
src/api-server/impl/PDUSessionsCollectionApiImpl.cpp
src/api-server/impl/PDUSessionsCollectionApiImpl.cpp
+0
-1
src/api-server/smf-http2-server.cpp
src/api-server/smf-http2-server.cpp
+6
-4
src/common/3gpp_23.003.h
src/common/3gpp_23.003.h
+1
-1
src/common/3gpp_29.502.h
src/common/3gpp_29.502.h
+5
-5
src/common/endpoint.hpp
src/common/endpoint.hpp
+23
-40
src/common/logger.hpp
src/common/logger.hpp
+60
-100
src/common/serializable.hpp
src/common/serializable.hpp
+3
-3
src/common/utils/3gpp_conversions.cpp
src/common/utils/3gpp_conversions.cpp
+1
-2
src/common/utils/bstr/bsafe.c
src/common/utils/bstr/bsafe.c
+49
-44
src/common/utils/bstr/bsafe.h
src/common/utils/bstr/bsafe.h
+10
-10
src/common/utils/bstr/bstrlib.c
src/common/utils/bstr/bstrlib.c
+945
-899
src/common/utils/bstr/bstrwrap.cpp
src/common/utils/bstr/bstrwrap.cpp
+1326
-1302
src/common/utils/bstr/bstrwrap.h
src/common/utils/bstr/bstrwrap.h
+325
-312
src/common/utils/bstr/buniutil.c
src/common/utils/bstr/buniutil.c
+158
-153
src/common/utils/bstr/buniutil.h
src/common/utils/bstr/buniutil.h
+6
-5
src/common/utils/bstr/utf8util.c
src/common/utils/bstr/utf8util.c
+205
-190
src/common/utils/bstr/utf8util.h
src/common/utils/bstr/utf8util.h
+21
-15
src/common/utils/mime_parser.cpp
src/common/utils/mime_parser.cpp
+1
-1
src/nas/mm/msg/AuthenticationReject.c
src/nas/mm/msg/AuthenticationReject.c
+2
-1
src/nas/sm/msg/PDUSessionEstablishmentAccept.c
src/nas/sm/msg/PDUSessionEstablishmentAccept.c
+2
-2
src/oai_smf/main.cpp
src/oai_smf/main.cpp
+58
-55
src/oai_smf/options.cpp
src/oai_smf/options.cpp
+103
-83
src/oai_smf/options.hpp
src/oai_smf/options.hpp
+35
-39
src/smf_app/smf_pco.cpp
src/smf_app/smf_pco.cpp
+3
-3
No files found.
src/api-server/api/SMContextsCollectionApi.cpp
View file @
e1c9d4df
...
...
@@ -69,7 +69,8 @@ void SMContextsCollectionApi::setupRoutes() {
using
namespace
Pistache
::
Rest
;
Routes
::
Post
(
*
router
,
base
+
smf_cfg
.
sbi_api_version
+
NSMF_PDU_SESSION_SM_CONTEXT_CREATE_URL
,
*
router
,
base
+
smf_cfg
.
sbi_api_version
+
NSMF_PDU_SESSION_SM_CONTEXT_CREATE_URL
,
Routes
::
bind
(
&
SMContextsCollectionApi
::
post_sm_contexts_handler
,
this
));
// Default handler, called when a route is not found
...
...
src/api-server/impl/IndividualSMContextApiImpl.cpp
View file @
e1c9d4df
...
...
@@ -180,8 +180,8 @@ void IndividualSMContextApiImpl::update_sm_context(
* TS 23.502 */
// TODO: Existing PDU session, step 3, SUPI, DNN, S-NSSAIs, SM Context ID, AMF
// ID, Request Type, N1 SM Container (PDU Session Establishment Request), User
// location, Access Type, RAT Type, PEI step 15. (SM Context ID -> SCID, N2
SM,
// Request Type)(Initial Request)
// location, Access Type, RAT Type, PEI step 15. (SM Context ID -> SCID, N2
//
SM,
Request Type)(Initial Request)
// TODO: verify why Request Type is not define in smContextUpdateData
/* AMF-initiated with a release indication to request the release of the PDU
* Session (step 3.d, section 4.3.4.2@3GPP TS 23.502)*/
...
...
src/api-server/impl/IndividualSubscriptionDocumentApiImpl.cpp
View file @
e1c9d4df
...
...
@@ -32,7 +32,6 @@
* contact@openairinterface.org
*/
#include "IndividualSubscriptionDocumentApiImpl.h"
namespace
oai
{
...
...
src/api-server/impl/NFStatusNotifyApiImpl.h
View file @
e1c9d4df
...
...
@@ -38,7 +38,6 @@
* contact@openairinterface.org
*/
#ifndef NF_STATUS_NOTIFY_API_IMPL_H_
#define NF_STATUS_NOTIFY_API_IMPL_H_
...
...
src/api-server/impl/PDUSessionsCollectionApiImpl.cpp
View file @
e1c9d4df
...
...
@@ -32,7 +32,6 @@
* contact@openairinterface.org
*/
#include "PDUSessionsCollectionApiImpl.h"
namespace
oai
{
...
...
src/api-server/smf-http2-server.cpp
View file @
e1c9d4df
...
...
@@ -225,7 +225,8 @@ void smf_http2_server::start() {
return
;
}
}
else
if
(
method
.
compare
(
"release"
)
==
0
)
{
// smContextReleaseData
}
else
if
(
method
.
compare
(
"release"
)
==
0
)
{
// smContextReleaseData
Logger
::
smf_api_server
().
info
(
"Handle Release SM Context Request from AMF"
);
...
...
@@ -293,7 +294,8 @@ void smf_http2_server::create_sm_contexts_handler(
// set api root to be used as location header in HTTP response
sm_context_req_msg
.
set_api_root
(
// m_address + ":" + std::to_string(m_port) +
NSMF_PDU_SESSION_BASE
+
smf_cfg
.
sbi_api_version
+
NSMF_PDU_SESSION_SM_CONTEXT_CREATE_URL
);
NSMF_PDU_SESSION_BASE
+
smf_cfg
.
sbi_api_version
+
NSMF_PDU_SESSION_SM_CONTEXT_CREATE_URL
);
// supi
supi_t
supi
=
{.
length
=
0
};
...
...
@@ -474,8 +476,8 @@ void smf_http2_server::update_sm_context_handler(
* TS 23.502 */
// TODO: Existing PDU session, step 3, SUPI, DNN, S-NSSAIs, SM Context ID, AMF
// ID, Request Type, N1 SM Container (PDU Session Establishment Request), User
// location, Access Type, RAT Type, PEI step 15. (SM Context ID -> SCID, N2
SM,
// Request Type)(Initial Request)
// location, Access Type, RAT Type, PEI step 15. (SM Context ID -> SCID, N2
//
SM,
Request Type)(Initial Request)
// TODO: verify why Request Type is not define in smContextUpdateData
/* AMF-initiated with a release indication to request the release of the PDU
* Session (step 3.d, section 4.3.4.2@3GPP TS 23.502)*/
...
...
src/common/3gpp_23.003.h
View file @
e1c9d4df
src/common/3gpp_29.502.h
View file @
e1c9d4df
src/common/endpoint.hpp
View file @
e1c9d4df
...
...
@@ -3,9 +3,9 @@
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
file
*
except in compliance with the License.
*
You may obtain a copy of the
License at
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*
file except in compliance with the License. You may obtain a copy of the
*License at
*
* http://www.openairinterface.org/?page_id=698
*
...
...
@@ -41,35 +41,22 @@ class endpoint {
struct
sockaddr_storage
addr_storage
;
socklen_t
addr_storage_len
;
endpoint
()
:
addr_storage
(),
addr_storage_len
(
sizeof
(
struct
sockaddr_storage
))
{
}
;
endpoint
(
const
endpoint
&
e
)
:
addr_storage
(
e
.
addr_storage
),
addr_storage_len
(
e
.
addr_storage_len
)
{
}
;
endpoint
(
const
struct
sockaddr_storage
&
addr
,
const
socklen_t
len
)
:
addr_storage
(
addr
),
addr_storage_len
(
len
)
{
}
;
endpoint
(
const
struct
in_addr
&
addr
,
const
uint16_t
port
)
{
struct
sockaddr_in
*
addr_in
=
(
struct
sockaddr_in
*
)
&
addr_storage
;
:
addr_storage
(),
addr_storage_len
(
sizeof
(
struct
sockaddr_storage
)){};
endpoint
(
const
endpoint
&
e
)
:
addr_storage
(
e
.
addr_storage
),
addr_storage_len
(
e
.
addr_storage_len
){};
endpoint
(
const
struct
sockaddr_storage
&
addr
,
const
socklen_t
len
)
:
addr_storage
(
addr
),
addr_storage_len
(
len
){};
endpoint
(
const
struct
in_addr
&
addr
,
const
uint16_t
port
)
{
struct
sockaddr_in
*
addr_in
=
(
struct
sockaddr_in
*
)
&
addr_storage
;
addr_in
->
sin_family
=
AF_INET
;
addr_in
->
sin_port
=
htons
(
port
);
addr_in
->
sin_addr
.
s_addr
=
addr
.
s_addr
;
addr_storage_len
=
sizeof
(
struct
sockaddr_in
);
}
;
};
endpoint
(
const
struct
in6_addr
&
addr6
,
const
uint16_t
port
)
{
struct
sockaddr_in6
*
addr_in6
=
(
struct
sockaddr_in6
*
)
&
addr_storage
;
endpoint
(
const
struct
in6_addr
&
addr6
,
const
uint16_t
port
)
{
struct
sockaddr_in6
*
addr_in6
=
(
struct
sockaddr_in6
*
)
&
addr_storage
;
addr_in6
->
sin6_family
=
AF_INET6
;
addr_in6
->
sin6_port
=
htons
(
port
);
addr_in6
->
sin6_flowinfo
=
0
;
...
...
@@ -77,31 +64,27 @@ class endpoint {
addr_in6
->
sin6_scope_id
=
0
;
addr_storage_len
=
sizeof
(
struct
sockaddr_in6
);
}
;
};
uint16_t
port
()
const
{
return
ntohs
(((
struct
sockaddr_in
*
)
&
addr_storage
)
->
sin_port
);
}
sa_family_t
family
()
const
{
return
addr_storage
.
ss_family
;
}
sa_family_t
family
()
const
{
return
addr_storage
.
ss_family
;
}
std
::
string
toString
()
const
{
std
::
string
str
;
if
(
addr_storage
.
ss_family
==
AF_INET
)
{
struct
sockaddr_in
*
addr_in
=
(
struct
sockaddr_in
*
)
&
addr_storage
;
struct
sockaddr_in
*
addr_in
=
(
struct
sockaddr_in
*
)
&
addr_storage
;
str
.
append
(
conv
::
toString
(
addr_in
->
sin_addr
));
str
.
append
(
":"
).
append
(
std
::
to_string
(
ntohs
(
addr_in
->
sin_port
)));
}
else
if
(
addr_storage
.
ss_family
==
AF_INET6
)
{
struct
sockaddr_in6
*
addr_in6
=
(
struct
sockaddr_in6
*
)
&
addr_storage
;
struct
sockaddr_in6
*
addr_in6
=
(
struct
sockaddr_in6
*
)
&
addr_storage
;
str
.
append
(
conv
::
toString
(
addr_in6
->
sin6_addr
));
str
.
append
(
":"
).
append
(
std
::
to_string
(
ntohs
(
addr_in6
->
sin6_port
)));
}
return
str
;
}
};
#endif
src/common/logger.hpp
View file @
e1c9d4df
...
...
@@ -21,144 +21,104 @@
#include <stdexcept>
#include <vector>
//#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error", "critical", "off" };
#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info ", "start", "warn ", "error", "off " };
//#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info", "warning", "error",
//"critical", "off" };
#define SPDLOG_LEVEL_NAMES \
{"trace", "debug", "info ", "start", "warn ", "error", "off "};
#define SPDLOG_ENABLE_SYSLOG
#include "spdlog/spdlog.h"
class
LoggerException
:
public
std
::
runtime_error
{
public:
explicit
LoggerException
(
const
char
*
m
)
:
std
::
runtime_error
(
m
)
{
}
explicit
LoggerException
(
const
std
::
string
&
m
)
:
std
::
runtime_error
(
m
)
{
}
explicit
LoggerException
(
const
char
*
m
)
:
std
::
runtime_error
(
m
)
{}
explicit
LoggerException
(
const
std
::
string
&
m
)
:
std
::
runtime_error
(
m
)
{}
};
class
_Logger
{
public:
_Logger
(
const
char
*
category
,
std
::
vector
<
spdlog
::
sink_ptr
>
&
sinks
,
const
char
*
pattern
);
void
trace
(
const
char
*
format
,
...);
void
trace
(
const
std
::
string
&
format
,
...);
void
debug
(
const
char
*
format
,
...);
void
debug
(
const
std
::
string
&
format
,
...);
void
info
(
const
char
*
format
,
...);
void
info
(
const
std
::
string
&
format
,
...);
void
startup
(
const
char
*
format
,
...);
void
startup
(
const
std
::
string
&
format
,
...);
void
warn
(
const
char
*
format
,
...);
void
warn
(
const
std
::
string
&
format
,
...);
void
error
(
const
char
*
format
,
...);
void
error
(
const
std
::
string
&
format
,
...);
_Logger
(
const
char
*
category
,
std
::
vector
<
spdlog
::
sink_ptr
>&
sinks
,
const
char
*
pattern
);
void
trace
(
const
char
*
format
,
...);
void
trace
(
const
std
::
string
&
format
,
...);
void
debug
(
const
char
*
format
,
...);
void
debug
(
const
std
::
string
&
format
,
...);
void
info
(
const
char
*
format
,
...);
void
info
(
const
std
::
string
&
format
,
...);
void
startup
(
const
char
*
format
,
...);
void
startup
(
const
std
::
string
&
format
,
...);
void
warn
(
const
char
*
format
,
...);
void
warn
(
const
std
::
string
&
format
,
...);
void
error
(
const
char
*
format
,
...);
void
error
(
const
std
::
string
&
format
,
...);
private:
_Logger
();
enum
_LogType
{
_ltTrace
,
_ltDebug
,
_ltInfo
,
_ltStartup
,
_ltWarn
,
_ltError
};
enum
_LogType
{
_ltTrace
,
_ltDebug
,
_ltInfo
,
_ltStartup
,
_ltWarn
,
_ltError
};
void
log
(
_LogType
lt
,
const
char
*
format
,
va_list
&
args
);
void
log
(
_LogType
lt
,
const
char
*
format
,
va_list
&
args
);
spdlog
::
logger
m_log
;
};
class
Logger
{
public:
static
void
init
(
const
char
*
app
,
const
bool
log_stdout
,
const
bool
log_rot_file
)
{
static
void
init
(
const
char
*
app
,
const
bool
log_stdout
,
const
bool
log_rot_file
)
{
singleton
().
_init
(
app
,
log_stdout
,
log_rot_file
);
}
static
void
init
(
const
std
::
string
&
app
,
const
bool
log_stdout
,
const
bool
log_rot_file
)
{
static
void
init
(
const
std
::
string
&
app
,
const
bool
log_stdout
,
const
bool
log_rot_file
)
{
init
(
app
.
c_str
(),
log_stdout
,
log_rot_file
);
}
static
_Logger
&
async_cmd
()
{
return
*
singleton
().
m_async_cmd
;
}
static
_Logger
&
itti
()
{
return
*
singleton
().
m_itti
;
}
static
_Logger
&
smf_app
()
{
return
*
singleton
().
m_smf_app
;
}
static
_Logger
&
system
()
{
return
*
singleton
().
m_system
;
}
static
_Logger
&
udp
()
{
return
*
singleton
().
m_udp
;
}
static
_Logger
&
pfcp
()
{
return
*
singleton
().
m_pfcp
;
}
static
_Logger
&
pfcp_switch
()
{
return
*
singleton
().
m_pfcp_switch
;
}
static
_Logger
&
async_cmd
()
{
return
*
singleton
().
m_async_cmd
;
}
static
_Logger
&
itti
()
{
return
*
singleton
().
m_itti
;
}
static
_Logger
&
smf_app
()
{
return
*
singleton
().
m_smf_app
;
}
static
_Logger
&
system
()
{
return
*
singleton
().
m_system
;
}
static
_Logger
&
udp
()
{
return
*
singleton
().
m_udp
;
}
static
_Logger
&
pfcp
()
{
return
*
singleton
().
m_pfcp
;
}
static
_Logger
&
pfcp_switch
()
{
return
*
singleton
().
m_pfcp_switch
;
}
static
_Logger
&
smf_n1
()
{
return
*
singleton
().
m_smf_n1
;
}
static
_Logger
&
smf_n2
()
{
return
*
singleton
().
m_smf_n2
;
}
static
_Logger
&
smf_n4
()
{
return
*
singleton
().
m_smf_n4
;
}
static
_Logger
&
smf_n10
()
{
return
*
singleton
().
m_smf_n10
;
}
static
_Logger
&
smf_n11
()
{
return
*
singleton
().
m_smf_n11
;
}
static
_Logger
&
smf_api_server
()
{
return
*
singleton
().
m_smf_api_server
;
}
static
_Logger
&
smf_n1
()
{
return
*
singleton
().
m_smf_n1
;
}
static
_Logger
&
smf_n2
()
{
return
*
singleton
().
m_smf_n2
;
}
static
_Logger
&
smf_n4
()
{
return
*
singleton
().
m_smf_n4
;
}
static
_Logger
&
smf_n10
()
{
return
*
singleton
().
m_smf_n10
;
}
static
_Logger
&
smf_n11
()
{
return
*
singleton
().
m_smf_n11
;
}
static
_Logger
&
smf_api_server
()
{
return
*
singleton
().
m_smf_api_server
;
}
private:
static
Logger
*
m_singleton
;
static
Logger
*
m_singleton
;
static
Logger
&
singleton
()
{
if
(
!
m_singleton
)
m_singleton
=
new
Logger
();
if
(
!
m_singleton
)
m_singleton
=
new
Logger
();
return
*
m_singleton
;
}
Logger
()
{
}
~
Logger
()
{
}
Logger
()
{}
~
Logger
()
{}
void
_init
(
const
char
*
app
,
const
bool
log_stdout
,
const
bool
log_rot_file
);
void
_init
(
const
char
*
app
,
const
bool
log_stdout
,
const
bool
log_rot_file
);
std
::
vector
<
spdlog
::
sink_ptr
>
m_sinks
;
std
::
string
m_pattern
;
_Logger
*
m_async_cmd
;
_Logger
*
m_itti
;
_Logger
*
m_smf_app
;
_Logger
*
m_system
;
_Logger
*
m_udp
;
_Logger
*
m_pfcp
;
_Logger
*
m_pfcp_switch
;
_Logger
*
m_smf_n1
;
_Logger
*
m_smf_n2
;
_Logger
*
m_smf_n4
;
_Logger
*
m_smf_n10
;
_Logger
*
m_smf_n11
;
_Logger
*
m_smf_api_server
;
_Logger
*
m_async_cmd
;
_Logger
*
m_itti
;
_Logger
*
m_smf_app
;
_Logger
*
m_system
;
_Logger
*
m_udp
;
_Logger
*
m_pfcp
;
_Logger
*
m_pfcp_switch
;
_Logger
*
m_smf_n1
;
_Logger
*
m_smf_n2
;
_Logger
*
m_smf_n4
;
_Logger
*
m_smf_n10
;
_Logger
*
m_smf_n11
;
_Logger
*
m_smf_api_server
;
};
#endif // __LOGGER_H
src/common/serializable.hpp
View file @
e1c9d4df
...
...
@@ -34,9 +34,9 @@
class
stream_serializable
{
public:
virtual
void
dump_to
(
std
::
ostream
&
os
)
=
0
;
virtual
void
load_from
(
std
::
istream
&
is
)
=
0
;
//virtual ~serializable() = 0;
virtual
void
dump_to
(
std
::
ostream
&
os
)
=
0
;
virtual
void
load_from
(
std
::
istream
&
is
)
=
0
;
//
virtual ~serializable() = 0;
};
#endif
/* FILE_SERIALIZABLE_HPP_SEEN */
src/common/utils/3gpp_conversions.cpp
View file @
e1c9d4df
...
...
@@ -148,7 +148,6 @@ void xgpp_conv::pco_core_to_nas(
void
xgpp_conv
::
sm_context_create_data_from_openapi
(
const
oai
::
smf_server
::
model
::
SmContextMessage
&
scd
,
smf
::
pdu_session_create_sm_context_request
&
pcr
)
{
Logger
::
smf_app
().
debug
(
"Convert SmContextMessage (OpenAPI) to "
"pdu_session_create_sm_context_request"
);
...
...
@@ -156,7 +155,7 @@ void xgpp_conv::sm_context_create_data_from_openapi(
oai
::
smf_server
::
model
::
SmContextCreateData
context_data
=
scd
.
getJsonData
();
std
::
string
n1_sm_msg
=
scd
.
getBinaryDataN1SmMessage
();
//N1 SM Message
//
N1 SM Message
pcr
.
set_n1_sm_message
(
n1_sm_msg
);
Logger
::
smf_app
().
debug
(
"N1 SM message: %s"
,
n1_sm_msg
.
c_str
());
...
...
src/common/utils/bstr/bsafe.c
View file @
e1c9d4df
...
...
@@ -20,57 +20,62 @@
static
int
bsafeShouldExit
=
1
;
char
*
strcpy
(
char
*
dst
,
const
char
*
src
);
char
*
strcat
(
char
*
dst
,
const
char
*
src
);
char
*
strcpy
(
char
*
dst
,
const
char
*
src
);
char
*
strcat
(
char
*
dst
,
const
char
*
src
);
char
*
strcpy
(
char
*
dst
,
const
char
*
src
)
{
char
*
strcpy
(
char
*
dst
,
const
char
*
src
)
{
(
void
)
dst
;
(
void
)
src
;
fprintf
(
stderr
,
"bsafe error: strcpy() is not safe, use bstrcpy instead.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
fprintf
(
stderr
,
"bsafe error: strcpy() is not safe, use bstrcpy instead.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
return
NULL
;
}
char
*
strcat
(
char
*
dst
,
const
char
*
src
)
{
char
*
strcat
(
char
*
dst
,
const
char
*
src
)
{
(
void
)
dst
;
(
void
)
src
;
fprintf
(
stderr
,
"bsafe error: strcat() is not safe, use bstrcat instead.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
fprintf
(
stderr
,
"bsafe error: strcat() is not safe, use bstrcat instead.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
return
NULL
;
}
#if !defined
(__GNUC__) && (!defined(_MSC_VER) || (_MSC_VER <= 1310))
char
*
(
gets
)
(
char
*
buf
)
{
#if !defined(__GNUC__) && (!defined(_MSC_VER) || (_MSC_VER <= 1310))
char
*
(
gets
)(
char
*
buf
)
{
(
void
)
buf
;
fprintf
(
stderr
,
"bsafe error: gets() is not safe, use bgets.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
fprintf
(
stderr
,
"bsafe error: gets() is not safe, use bgets.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
return
NULL
;
}
#endif
char
*
(
strncpy
)
(
char
*
dst
,
const
char
*
src
,
size_t
n
)
{
char
*
(
strncpy
)(
char
*
dst
,
const
char
*
src
,
size_t
n
)
{
(
void
)
dst
;
(
void
)
src
;
(
void
)
n
;
fprintf
(
stderr
,
"bsafe error: strncpy() is not safe, use bmidstr instead.
\n
"
);
//
if (bsafeShouldExit) exit (-1);
fprintf
(
stderr
,
"bsafe error: strncpy() is not safe, use bmidstr instead.
\n
"
);
//
if (bsafeShouldExit) exit (-1);
return
NULL
;
}
char
*
(
strncat
)
(
char
*
dst
,
const
char
*
src
,
size_t
n
)
{
char
*
(
strncat
)(
char
*
dst
,
const
char
*
src
,
size_t
n
)
{
(
void
)
dst
;
(
void
)
src
;
(
void
)
n
;
fprintf
(
stderr
,
"bsafe error: strncat() is not safe, use bstrcat then btrunc
\n\t
or cstr2tbstr, btrunc then bstrcat instead.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
fprintf
(
stderr
,
"bsafe error: strncat() is not safe, use bstrcat then btrunc
\n\t
or "
"cstr2tbstr, btrunc then bstrcat instead.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
return
NULL
;
}
char
*
(
strtok
)
(
char
*
s1
,
const
char
*
s2
)
{
char
*
(
strtok
)(
char
*
s1
,
const
char
*
s2
)
{
(
void
)
s1
;
(
void
)
s2
;
fprintf
(
stderr
,
"bsafe error: strtok() is not safe, use bsplit or bsplits instead.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
fprintf
(
stderr
,
"bsafe error: strtok() is not safe, use bsplit or bsplits instead.
\n
"
);
if
(
bsafeShouldExit
)
exit
(
-
1
);
return
NULL
;
}
/*
...
...
src/common/utils/bstr/bsafe.h
View file @
e1c9d4df
...
...
@@ -21,20 +21,20 @@
extern
"C"
{
#endif
#if !defined
(__GNUC__) && (!defined(_MSC_VER) || (_MSC_VER <= 1310))
#if !defined(__GNUC__) && (!defined(_MSC_VER) || (_MSC_VER <= 1310))
/* This is caught in the linker, so its not necessary for gcc. */
extern
char
*
(
gets
)
(
char
*
buf
);
extern
char
*
(
gets
)(
char
*
buf
);
#endif
extern
char
*
(
strncpy
)
(
char
*
dst
,
const
char
*
src
,
size_t
n
);
extern
char
*
(
strncat
)
(
char
*
dst
,
const
char
*
src
,
size_t
n
);
extern
char
*
(
strtok
)
(
char
*
s1
,
const
char
*
s2
);
//extern char * (strdup) (const char *s);
extern
char
*
(
strncpy
)(
char
*
dst
,
const
char
*
src
,
size_t
n
);
extern
char
*
(
strncat
)(
char
*
dst
,
const
char
*
src
,
size_t
n
);
extern
char
*
(
strtok
)(
char
*
s1
,
const
char
*
s2
);
//
extern char * (strdup) (const char *s);
#undef strcpy
#undef strcat
#define strcpy(a,
b) bsafe_strcpy(a,b)
#define strcat(a,
b) bsafe_strcat(a,b)
#define strcpy(a,
b) bsafe_strcpy(a, b)
#define strcat(a,
b) bsafe_strcat(a, b)
#ifdef __cplusplus
}
...
...
src/common/utils/bstr/bstrlib.c
View file @
e1c9d4df
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/common/utils/bstr/bstrwrap.cpp
View file @
e1c9d4df
This diff is collapsed.
Click to expand it.
src/common/utils/bstr/bstrwrap.h
View file @
e1c9d4df
This diff is collapsed.
Click to expand it.
src/common/utils/bstr/buniutil.c
View file @
e1c9d4df
...
...
@@ -23,13 +23,12 @@
* Scan string and return 1 if its entire contents is entirely UTF8 code
* points. Otherwise return 0.
*/
int
buIsUTF8Content
(
const_bstring
bu
)
{
struct
utf8Iterator
iter
;
int
buIsUTF8Content
(
const_bstring
bu
)
{
struct
utf8Iterator
iter
;
if
(
NULL
==
bdata
(
bu
))
return
0
;
for
(
utf8IteratorInit
(
&
iter
,
bu
->
data
,
bu
->
slen
);
iter
.
next
<
iter
.
slen
;)
{
if
(
0
>=
utf8IteratorGetNextCodePoint
(
&
iter
,
-
1
))
return
0
;
if
(
NULL
==
bdata
(
bu
))
return
0
;
for
(
utf8IteratorInit
(
&
iter
,
bu
->
data
,
bu
->
slen
);
iter
.
next
<
iter
.
slen
;)
{
if
(
0
>=
utf8IteratorGetNextCodePoint
(
&
iter
,
-
1
))
return
0
;
}
return
1
;
}
...
...
@@ -43,16 +42,18 @@ struct utf8Iterator iter;
* target array ucs2. If any code point in bu is unparsable, it will be
* translated to errCh.
*/
int
buGetBlkUTF16
(
/* @out */
cpUcs2
*
ucs2
,
int
len
,
cpUcs4
errCh
,
const_bstring
bu
,
int
pos
)
{
struct
tagbstring
t
;
struct
utf8Iterator
iter
;
cpUcs4
ucs4
;
int
i
,
j
;
int
buGetBlkUTF16
(
/* @out */
cpUcs2
*
ucs2
,
int
len
,
cpUcs4
errCh
,
const_bstring
bu
,
int
pos
)
{
struct
tagbstring
t
;
struct
utf8Iterator
iter
;
cpUcs4
ucs4
;
int
i
,
j
;
if
(
!
isLegalUnicodeCodePoint
(
errCh
))
errCh
=
UNICODE__CODE_POINT__REPLACEMENT_CHARACTER
;
if
(
NULL
==
ucs2
||
0
>=
len
||
NULL
==
bdata
(
bu
)
||
0
>
pos
)
return
BSTR_ERR
;
if
(
!
isLegalUnicodeCodePoint
(
errCh
))
errCh
=
UNICODE__CODE_POINT__REPLACEMENT_CHARACTER
;
if
(
NULL
==
ucs2
||
0
>=
len
||
NULL
==
bdata
(
bu
)
||
0
>
pos
)
return
BSTR_ERR
;
for
(
j
=
0
,
i
=
0
;
j
<
bu
->
slen
;
j
++
)
{
for
(
j
=
0
,
i
=
0
;
j
<
bu
->
slen
;
j
++
)
{
if
(
0x80
!=
(
0xC0
&
bu
->
data
[
j
]))
{
if
(
i
>=
pos
)
break
;
i
++
;
...
...
@@ -63,11 +64,12 @@ int i, j;
t
.
data
=
bu
->
data
+
j
;
t
.
slen
=
bu
->
slen
-
j
;
utf8IteratorInit
(
&
iter
,
t
.
data
,
t
.
slen
);
utf8IteratorInit
(
&
iter
,
t
.
data
,
t
.
slen
);
ucs4
=
BSTR_ERR
;
for
(
i
=
0
;
0
<
len
&&
iter
.
next
<
iter
.
slen
&&
0
<=
(
ucs4
=
utf8IteratorGetNextCodePoint
(
&
iter
,
errCh
));
i
++
)
{
for
(
i
=
0
;
0
<
len
&&
iter
.
next
<
iter
.
slen
&&
0
<=
(
ucs4
=
utf8IteratorGetNextCodePoint
(
&
iter
,
errCh
));
i
++
)
{
if
(
ucs4
<
0x10000
)
{
*
ucs2
++
=
(
cpUcs2
)
ucs4
;
len
--
;
...
...
@@ -77,8 +79,8 @@ int i, j;
len
--
;
}
else
{
long
y
=
ucs4
-
0x10000
;
ucs2
[
0
]
=
(
cpUcs2
)
(
0xD800
|
(
y
>>
10
));
ucs2
[
1
]
=
(
cpUcs2
)
(
0xDC00
|
(
y
&
0x03FF
));
ucs2
[
0
]
=
(
cpUcs2
)
(
0xD800
|
(
y
>>
10
));
ucs2
[
1
]
=
(
cpUcs2
)
(
0xDC00
|
(
y
&
0x03FF
));
len
-=
2
;
ucs2
+=
2
;
i
++
;
...
...
@@ -90,7 +92,7 @@ int i, j;
len
--
;
}
utf8IteratorUninit
(
&
iter
);
utf8IteratorUninit
(
&
iter
);
if
(
0
>
ucs4
)
return
BSTR_ERR
;
return
i
;
}
...
...
@@ -118,17 +120,18 @@ UTF-32: U-000000 - U-10FFFF
* valid code point, then this translation will halt upon the first error
* and return BSTR_ERR. Otherwise BSTR_OK is returned.
*/
int
buAppendBlkUcs4
(
bstring
b
,
const
cpUcs4
*
bu
,
int
len
,
cpUcs4
errCh
)
{
int
i
,
oldSlen
;
int
buAppendBlkUcs4
(
bstring
b
,
const
cpUcs4
*
bu
,
int
len
,
cpUcs4
errCh
)
{
int
i
,
oldSlen
;
if
(
NULL
==
bu
||
NULL
==
b
||
0
>
len
||
0
>
(
oldSlen
=
blengthe
(
b
,
-
1
)))
return
BSTR_ERR
;
if
(
!
isLegalUnicodeCodePoint
(
errCh
))
errCh
=
~
0
;
if
(
NULL
==
bu
||
NULL
==
b
||
0
>
len
||
0
>
(
oldSlen
=
blengthe
(
b
,
-
1
)))
return
BSTR_ERR
;
if
(
!
isLegalUnicodeCodePoint
(
errCh
))
errCh
=
~
0
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
for
(
i
=
0
;
i
<
len
;
i
++
)
{
unsigned
char
c
[
6
];
cpUcs4
v
=
bu
[
i
];
if
(
!
isLegalUnicodeCodePoint
(
v
))
{
if
(
!
isLegalUnicodeCodePoint
(
v
))
{
if
(
~
0
==
errCh
)
{
b
->
slen
=
oldSlen
;
return
BSTR_ERR
;
...
...
@@ -137,22 +140,22 @@ int i, oldSlen;
}
if
(
v
<
0x80
)
{
if
(
BSTR_OK
!=
bconchar
(
b
,
(
char
)
v
))
{
if
(
BSTR_OK
!=
bconchar
(
b
,
(
char
)
v
))
{
b
->
slen
=
oldSlen
;
return
BSTR_ERR
;
}
}
else
if
(
v
<
0x800
)
{
c
[
0
]
=
(
unsigned
char
)
(
(
v
>>
6
)
+
0xc0
);
c
[
1
]
=
(
unsigned
char
)
((
v
&
0x3f
)
+
0x80
);
if
(
BSTR_OK
!=
bcatblk
(
b
,
c
,
2
))
{
c
[
0
]
=
(
unsigned
char
)
((
v
>>
6
)
+
0xc0
);
c
[
1
]
=
(
unsigned
char
)
((
v
&
0x3f
)
+
0x80
);
if
(
BSTR_OK
!=
bcatblk
(
b
,
c
,
2
))
{
b
->
slen
=
oldSlen
;
return
BSTR_ERR
;
}
}
else
if
(
v
<
0x10000
)
{
c
[
0
]
=
(
unsigned
char
)
(
(
v
>>
12
)
+
0xe0
);
c
[
0
]
=
(
unsigned
char
)
((
v
>>
12
)
+
0xe0
);
c
[
1
]
=
(
unsigned
char
)
(((
v
>>
6
)
&
0x3f
)
+
0x80
);
c
[
2
]
=
(
unsigned
char
)
((
v
&
0x3f
)
+
0x80
);
if
(
BSTR_OK
!=
bcatblk
(
b
,
c
,
3
))
{
c
[
2
]
=
(
unsigned
char
)
((
v
&
0x3f
)
+
0x80
);
if
(
BSTR_OK
!=
bcatblk
(
b
,
c
,
3
))
{
b
->
slen
=
oldSlen
;
return
BSTR_ERR
;
}
...
...
@@ -161,11 +164,11 @@ int i, oldSlen;
if (v < 0x200000)
#endif
{
c
[
0
]
=
(
unsigned
char
)
(
(
v
>>
18
)
+
0xf0
);
c
[
0
]
=
(
unsigned
char
)
((
v
>>
18
)
+
0xf0
);
c
[
1
]
=
(
unsigned
char
)
(((
v
>>
12
)
&
0x3f
)
+
0x80
);
c
[
2
]
=
(
unsigned
char
)
(((
v
>>
6
)
&
0x3f
)
+
0x80
);
c
[
3
]
=
(
unsigned
char
)
((
v
&
0x3f
)
+
0x80
);
if
(
BSTR_OK
!=
bcatblk
(
b
,
c
,
4
))
{
c
[
3
]
=
(
unsigned
char
)
((
v
&
0x3f
)
+
0x80
);
if
(
BSTR_OK
!=
bcatblk
(
b
,
c
,
4
))
{
b
->
slen
=
oldSlen
;
return
BSTR_ERR
;
}
...
...
@@ -198,7 +201,8 @@ int i, oldSlen;
return
BSTR_OK
;
}
#define endSwap(cs,mode) ((mode) ? ((((cs) & 0xFF) << 8) | (((cs) >> 8) & 0xFF)) : (cs))
#define endSwap(cs, mode) \
((mode) ? ((((cs) &0xFF) << 8) | (((cs) >> 8) & 0xFF)) : (cs))
#define TEMP_UCS4_BUFFER_SIZE (64)
/* int buAppendBlkUTF16 (bstring bu, const cpUcs2* utf16, int len,
...
...
@@ -212,12 +216,13 @@ int i, oldSlen;
* set to 0, it will be filled in with the BOM as read from the first
* character if it is a BOM.
*/
int
buAppendBlkUTF16
(
bstring
bu
,
const
cpUcs2
*
utf16
,
int
len
,
cpUcs2
*
bom
,
cpUcs4
errCh
)
{
cpUcs4
buff
[
TEMP_UCS4_BUFFER_SIZE
];
int
cc
,
i
,
sm
,
oldSlen
;
int
buAppendBlkUTF16
(
bstring
bu
,
const
cpUcs2
*
utf16
,
int
len
,
cpUcs2
*
bom
,
cpUcs4
errCh
)
{
cpUcs4
buff
[
TEMP_UCS4_BUFFER_SIZE
];
int
cc
,
i
,
sm
,
oldSlen
;
if
(
NULL
==
bdata
(
bu
)
||
NULL
==
utf16
||
len
<
0
)
return
BSTR_ERR
;
if
(
!
isLegalUnicodeCodePoint
(
errCh
))
errCh
=
~
0
;
if
(
!
isLegalUnicodeCodePoint
(
errCh
))
errCh
=
~
0
;
if
(
len
==
0
)
return
BSTR_OK
;
oldSlen
=
bu
->
slen
;
...
...
@@ -242,9 +247,9 @@ int cc, i, sm, oldSlen;
}
cc
=
0
;
for
(;
i
<
len
;
i
++
)
{
for
(;
i
<
len
;
i
++
)
{
cpUcs4
c
,
v
;
v
=
endSwap
(
utf16
[
i
],
sm
);
v
=
endSwap
(
utf16
[
i
],
sm
);
if
((
v
|
0x7FF
)
==
0xDFFF
)
{
/* Deal with surrogate pairs */
if
(
v
>=
0xDC00
||
i
>=
len
)
{
...
...
@@ -257,18 +262,18 @@ int cc, i, sm, oldSlen;
v
=
errCh
;
}
else
{
i
++
;
if
((
c
=
endSwap
(
utf16
[
i
],
sm
)
-
0xDC00
)
>
0x3FF
)
goto
ErrMode
;
if
((
c
=
endSwap
(
utf16
[
i
],
sm
)
-
0xDC00
)
>
0x3FF
)
goto
ErrMode
;
v
=
((
v
-
0xD800
)
<<
10
)
+
c
+
0x10000
;
}
}
buff
[
cc
]
=
v
;
cc
++
;
if
(
cc
>=
TEMP_UCS4_BUFFER_SIZE
)
{
if
(
0
>
buAppendBlkUcs4
(
bu
,
buff
,
cc
,
errCh
))
goto
ErrReturn
;
if
(
0
>
buAppendBlkUcs4
(
bu
,
buff
,
cc
,
errCh
))
goto
ErrReturn
;
cc
=
0
;
}
}
if
(
cc
>
0
&&
0
>
buAppendBlkUcs4
(
bu
,
buff
,
cc
,
errCh
))
goto
ErrReturn
;
if
(
cc
>
0
&&
0
>
buAppendBlkUcs4
(
bu
,
buff
,
cc
,
errCh
))
goto
ErrReturn
;
return
BSTR_OK
;
}
src/common/utils/bstr/buniutil.h
View file @
e1c9d4df
...
...
@@ -22,16 +22,17 @@
extern
"C"
{
#endif
extern
int
buIsUTF8Content
(
const_bstring
bu
);
extern
int
buAppendBlkUcs4
(
bstring
b
,
const
cpUcs4
*
bu
,
int
len
,
cpUcs4
errCh
);
extern
int
buIsUTF8Content
(
const_bstring
bu
);
extern
int
buAppendBlkUcs4
(
bstring
b
,
const
cpUcs4
*
bu
,
int
len
,
cpUcs4
errCh
);
/* For those unfortunate enough to be stuck supporting UTF16. */
extern
int
buGetBlkUTF16
(
/* @out */
cpUcs2
*
ucs2
,
int
len
,
cpUcs4
errCh
,
const_bstring
bu
,
int
pos
);
extern
int
buAppendBlkUTF16
(
bstring
bu
,
const
cpUcs2
*
utf16
,
int
len
,
cpUcs2
*
bom
,
cpUcs4
errCh
);
extern
int
buGetBlkUTF16
(
/* @out */
cpUcs2
*
ucs2
,
int
len
,
cpUcs4
errCh
,
const_bstring
bu
,
int
pos
);
extern
int
buAppendBlkUTF16
(
bstring
bu
,
const
cpUcs2
*
utf16
,
int
len
,
cpUcs2
*
bom
,
cpUcs4
errCh
);
#ifdef __cplusplus
}
#endif
#endif
/* BSTRLIB_UNICODE_UTILITIES */
src/common/utils/bstr/utf8util.c
View file @
e1c9d4df
...
...
@@ -18,14 +18,18 @@
#ifdef __cplusplus
#define NULL 0
#else
#define NULL
((void *)
0)
#define NULL
((void*)
0)
#endif
#endif
/* Surrogate range is wrong, there is a maximum, the BOM alias is illegal and 0xFFFF is illegal */
#define isLegalUnicodeCodePoint(v) ((((v) < 0xD800L) || ((v) > 0xDFFFL)) && (((unsigned long)(v)) <= 0x0010FFFFL) && (((v)|0x1F0001) != 0x1FFFFFL))
/* Surrogate range is wrong, there is a maximum, the BOM alias is illegal and
* 0xFFFF is illegal */
#define isLegalUnicodeCodePoint(v) \
((((v) < 0xD800L) || ((v) > 0xDFFFL)) && \
(((unsigned long) (v)) <= 0x0010FFFFL) && (((v) | 0x1F0001) != 0x1FFFFFL))
void
utf8IteratorInit
(
struct
utf8Iterator
*
iter
,
unsigned
char
*
data
,
int
slen
)
{
void
utf8IteratorInit
(
struct
utf8Iterator
*
iter
,
unsigned
char
*
data
,
int
slen
)
{
if
(
iter
)
{
iter
->
data
=
data
;
iter
->
slen
=
(
iter
->
data
&&
slen
>=
0
)
?
slen
:
-
1
;
...
...
@@ -35,7 +39,7 @@ void utf8IteratorInit (struct utf8Iterator* iter, unsigned char* data, int slen)
}
}
void
utf8IteratorUninit
(
struct
utf8Iterator
*
iter
)
{
void
utf8IteratorUninit
(
struct
utf8Iterator
*
iter
)
{
if
(
iter
)
{
iter
->
data
=
NULL
;
iter
->
slen
=
-
1
;
...
...
@@ -43,7 +47,8 @@ void utf8IteratorUninit (struct utf8Iterator* iter) {
}
}
int
utf8ScanBackwardsForCodePoint
(
unsigned
char
*
msg
,
int
len
,
int
pos
,
cpUcs4
*
out
)
{
int
utf8ScanBackwardsForCodePoint
(
unsigned
char
*
msg
,
int
len
,
int
pos
,
cpUcs4
*
out
)
{
cpUcs4
v1
,
v2
,
v3
,
v4
,
x
;
int
ret
;
if
(
NULL
==
msg
||
len
<
0
||
(
unsigned
)
pos
>=
(
unsigned
)
len
)
{
...
...
@@ -57,29 +62,30 @@ int utf8ScanBackwardsForCodePoint (unsigned char* msg, int len, int pos, cpUcs4*
}
else
if
(
msg
[
pos
]
<
0xC0
)
{
if
(
0
==
pos
)
return
-
__LINE__
;
ret
=
-
__LINE__
;
if
(
msg
[
pos
-
1
]
>=
0xC1
&&
msg
[
pos
-
1
]
<
0xF8
)
{
if
(
msg
[
pos
-
1
]
>=
0xC1
&&
msg
[
pos
-
1
]
<
0xF8
)
{
pos
--
;
ret
=
1
;
}
else
{
if
(
1
==
pos
)
return
-
__LINE__
;
if
((
msg
[
pos
-
1
]
|
0x3F
)
!=
0xBF
)
return
-
__LINE__
;
if
(
msg
[
pos
-
2
]
>=
0xE0
&&
msg
[
pos
-
2
]
<
0xF8
)
{
if
((
msg
[
pos
-
1
]
|
0x3F
)
!=
0xBF
)
return
-
__LINE__
;
if
(
msg
[
pos
-
2
]
>=
0xE0
&&
msg
[
pos
-
2
]
<
0xF8
)
{
pos
-=
2
;
ret
=
2
;
}
else
{
if
(
2
==
pos
)
return
-
__LINE__
;
if
((
msg
[
pos
-
2
]
|
0x3F
)
!=
0xBF
)
return
-
__LINE__
;
if
((
msg
[
pos
-
3
]
|
0x07
)
==
0xF7
)
{
if
((
msg
[
pos
-
2
]
|
0x3F
)
!=
0xBF
)
return
-
__LINE__
;
if
((
msg
[
pos
-
3
]
|
0x07
)
==
0xF7
)
{
pos
-=
3
;
ret
=
3
;
}
else
return
-
__LINE__
;
}
else
return
-
__LINE__
;
}
}
}
if
(
msg
[
pos
]
<
0xE0
)
{
if
(
pos
+
1
>=
len
)
return
-
__LINE__
;
v1
=
msg
[
pos
]
&
~
0xE0
;
v2
=
msg
[
pos
+
1
]
&
~
0xC0
;
v2
=
msg
[
pos
+
1
]
&
~
0xC0
;
v1
=
(
v1
<<
6
)
+
v2
;
if
(
v1
<
0x80
)
return
-
__LINE__
;
*
out
=
v1
;
...
...
@@ -88,8 +94,8 @@ int utf8ScanBackwardsForCodePoint (unsigned char* msg, int len, int pos, cpUcs4*
if
(
msg
[
pos
]
<
0xF0
)
{
if
(
pos
+
2
>=
len
)
return
-
__LINE__
;
v1
=
msg
[
pos
]
&
~
0xF0
;
v2
=
msg
[
pos
+
1
]
&
~
0xC0
;
v3
=
msg
[
pos
+
2
]
&
~
0xC0
;
v2
=
msg
[
pos
+
1
]
&
~
0xC0
;
v3
=
msg
[
pos
+
2
]
&
~
0xC0
;
v1
=
(
v1
<<
12
)
+
(
v2
<<
6
)
+
v3
;
if
(
v1
<
0x800
)
return
-
__LINE__
;
if
(
!
isLegalUnicodeCodePoint
(
v1
))
return
-
__LINE__
;
...
...
@@ -101,9 +107,9 @@ int utf8ScanBackwardsForCodePoint (unsigned char* msg, int len, int pos, cpUcs4*
if
(
pos
+
3
>=
len
)
return
-
__LINE__
;
v1
=
msg
[
pos
]
&
~
0xF8
;
v2
=
msg
[
pos
+
1
]
&
~
0xC0
;
v3
=
msg
[
pos
+
2
]
&
~
0xC0
;
v4
=
msg
[
pos
+
3
]
&
~
0xC0
;
v2
=
msg
[
pos
+
1
]
&
~
0xC0
;
v3
=
msg
[
pos
+
2
]
&
~
0xC0
;
v4
=
msg
[
pos
+
3
]
&
~
0xC0
;
v1
=
(
v1
<<
18
)
+
(
v2
<<
12
)
+
(
v3
<<
6
)
+
v4
;
if
(
v1
<
0x10000
)
return
-
__LINE__
;
if
(
!
isLegalUnicodeCodePoint
(
v1
))
return
-
__LINE__
;
...
...
@@ -130,10 +136,11 @@ U-04000000 - U-7FFFFFFF: 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
*
* iter->data + iter->next points at the characters that will be read next.
*
* iter->error is boolean indicating whether or not last read contained an error.
* iter->error is boolean indicating whether or not last read contained an
* error.
*/
cpUcs4
utf8IteratorGetNextCodePoint
(
struct
utf8Iterator
*
iter
,
cpUcs4
errCh
)
{
unsigned
char
*
chrs
;
cpUcs4
utf8IteratorGetNextCodePoint
(
struct
utf8Iterator
*
iter
,
cpUcs4
errCh
)
{
unsigned
char
*
chrs
;
unsigned
char
c
,
d
,
e
;
long
v
;
int
i
,
ofs
;
...
...
@@ -143,7 +150,8 @@ cpUcs4 utf8IteratorGetNextCodePoint (struct utf8Iterator* iter, cpUcs4 errCh) {
iter
->
start
=
iter
->
slen
;
return
errCh
;
}
if
(
NULL
==
iter
->
data
||
iter
->
next
<
0
||
utf8IteratorNoMore
(
iter
))
return
errCh
;
if
(
NULL
==
iter
->
data
||
iter
->
next
<
0
||
utf8IteratorNoMore
(
iter
))
return
errCh
;
chrs
=
iter
->
data
+
iter
->
next
;
iter
->
error
=
0
;
...
...
@@ -167,7 +175,8 @@ cpUcs4 utf8IteratorGetNextCodePoint (struct utf8Iterator* iter, cpUcs4 errCh) {
c
=
(
unsigned
char
)
((
unsigned
)
chrs
[
1
]
-
0x080
);
d
=
(
unsigned
char
)
((
unsigned
)
chrs
[
2
]
-
0x080
);
v
+=
(
c
<<
6u
)
+
d
;
if
((
c
|
d
)
>=
0x40
||
v
<
0x800
||
!
isLegalUnicodeCodePoint
(
v
))
goto
ErrMode
;
if
((
c
|
d
)
>=
0x40
||
v
<
0x800
||
!
isLegalUnicodeCodePoint
(
v
))
goto
ErrMode
;
ofs
=
3
;
}
else
if
(
c
<
0xF8
)
{
if
(
iter
->
next
>=
iter
->
slen
+
3
)
goto
ErrMode
;
...
...
@@ -176,13 +185,15 @@ cpUcs4 utf8IteratorGetNextCodePoint (struct utf8Iterator* iter, cpUcs4 errCh) {
d
=
(
unsigned
char
)
((
unsigned
)
chrs
[
2
]
-
0x080
);
e
=
(
unsigned
char
)
((
unsigned
)
chrs
[
3
]
-
0x080
);
v
+=
(
c
<<
12u
)
+
(
d
<<
6u
)
+
e
;
if
((
c
|
d
|
e
)
>=
0x40
||
v
<
0x10000
||
!
isLegalUnicodeCodePoint
(
v
))
goto
ErrMode
;
if
((
c
|
d
|
e
)
>=
0x40
||
v
<
0x10000
||
!
isLegalUnicodeCodePoint
(
v
))
goto
ErrMode
;
ofs
=
4
;
}
else
{
/* 5 and 6 byte encodings are invalid */
ErrMode:
;
iter
->
error
=
1
;
v
=
errCh
;
for
(
i
=
iter
->
next
+
1
;
i
<
iter
->
slen
;
i
++
)
if
((
iter
->
data
[
i
]
&
0xC0
)
!=
0x80
)
break
;
for
(
i
=
iter
->
next
+
1
;
i
<
iter
->
slen
;
i
++
)
if
((
iter
->
data
[
i
]
&
0xC0
)
!=
0x80
)
break
;
ofs
=
i
-
iter
->
next
;
}
...
...
@@ -198,10 +209,11 @@ cpUcs4 utf8IteratorGetNextCodePoint (struct utf8Iterator* iter, cpUcs4 errCh) {
*
* iter->data + iter->next points at the characters that will be read next.
*
* iter->error is boolean indicating whether or not last read contained an error.
* iter->error is boolean indicating whether or not last read contained an
* error.
*/
cpUcs4
utf8IteratorGetCurrCodePoint
(
struct
utf8Iterator
*
iter
,
cpUcs4
errCh
)
{
unsigned
char
*
chrs
;
cpUcs4
utf8IteratorGetCurrCodePoint
(
struct
utf8Iterator
*
iter
,
cpUcs4
errCh
)
{
unsigned
char
*
chrs
;
unsigned
char
c
,
d
,
e
;
long
v
;
...
...
@@ -210,7 +222,8 @@ cpUcs4 utf8IteratorGetCurrCodePoint (struct utf8Iterator* iter, cpUcs4 errCh) {
iter
->
start
=
iter
->
slen
;
return
errCh
;
}
if
(
NULL
==
iter
->
data
||
iter
->
next
<
0
||
utf8IteratorNoMore
(
iter
))
return
errCh
;
if
(
NULL
==
iter
->
data
||
iter
->
next
<
0
||
utf8IteratorNoMore
(
iter
))
return
errCh
;
chrs
=
iter
->
data
+
iter
->
next
;
iter
->
error
=
0
;
...
...
@@ -231,7 +244,8 @@ cpUcs4 utf8IteratorGetCurrCodePoint (struct utf8Iterator* iter, cpUcs4 errCh) {
c
=
(
unsigned
char
)
((
unsigned
)
chrs
[
1
]
-
0x080
);
d
=
(
unsigned
char
)
((
unsigned
)
chrs
[
2
]
-
0x080
);
v
+=
(
c
<<
6u
)
+
d
;
if
((
c
|
d
)
>=
0x40
||
v
<
0x800
||
!
isLegalUnicodeCodePoint
(
v
))
goto
ErrMode
;
if
((
c
|
d
)
>=
0x40
||
v
<
0x800
||
!
isLegalUnicodeCodePoint
(
v
))
goto
ErrMode
;
}
else
if
(
c
<
0xF8
)
{
if
(
iter
->
next
>=
iter
->
slen
+
3
)
goto
ErrMode
;
v
=
(
c
<<
18lu
)
-
(
0x0F0
<<
18u
);
...
...
@@ -239,7 +253,8 @@ cpUcs4 utf8IteratorGetCurrCodePoint (struct utf8Iterator* iter, cpUcs4 errCh) {
d
=
(
unsigned
char
)
((
unsigned
)
chrs
[
2
]
-
0x080
);
e
=
(
unsigned
char
)
((
unsigned
)
chrs
[
3
]
-
0x080
);
v
+=
(
c
<<
12lu
)
+
(
d
<<
6u
)
+
e
;
if
((
c
|
d
|
e
)
>=
0x40
||
v
<
0x10000
||
!
isLegalUnicodeCodePoint
(
v
))
goto
ErrMode
;
if
((
c
|
d
|
e
)
>=
0x40
||
v
<
0x10000
||
!
isLegalUnicodeCodePoint
(
v
))
goto
ErrMode
;
}
else
{
/* 5 and 6 byte encodings are invalid */
ErrMode:
;
iter
->
error
=
1
;
...
...
src/common/utils/bstr/utf8util.h
View file @
e1c9d4df
...
...
@@ -38,7 +38,9 @@ typedef unsigned char cpUcs2;
#error This compiler is not supported
#endif
#define isLegalUnicodeCodePoint(v) ((((v) < 0xD800L) || ((v) > 0xDFFFL)) && (((unsigned long)(v)) <= 0x0010FFFFL) && (((v)|0x1F0001) != 0x1FFFFFL))
#define isLegalUnicodeCodePoint(v) \
((((v) < 0xD800L) || ((v) > 0xDFFFL)) && \
(((unsigned long) (v)) <= 0x0010FFFFL) && (((v) | 0x1F0001) != 0x1FFFFFL))
struct
utf8Iterator
{
unsigned
char
*
data
;
...
...
@@ -49,11 +51,15 @@ struct utf8Iterator {
#define utf8IteratorNoMore(it) (!(it) || (it)->next >= (it)->slen)
extern
void
utf8IteratorInit
(
struct
utf8Iterator
*
iter
,
unsigned
char
*
data
,
int
slen
);
extern
void
utf8IteratorUninit
(
struct
utf8Iterator
*
iter
);
extern
cpUcs4
utf8IteratorGetNextCodePoint
(
struct
utf8Iterator
*
iter
,
cpUcs4
errCh
);
extern
cpUcs4
utf8IteratorGetCurrCodePoint
(
struct
utf8Iterator
*
iter
,
cpUcs4
errCh
);
extern
int
utf8ScanBackwardsForCodePoint
(
unsigned
char
*
msg
,
int
len
,
int
pos
,
cpUcs4
*
out
);
extern
void
utf8IteratorInit
(
struct
utf8Iterator
*
iter
,
unsigned
char
*
data
,
int
slen
);
extern
void
utf8IteratorUninit
(
struct
utf8Iterator
*
iter
);
extern
cpUcs4
utf8IteratorGetNextCodePoint
(
struct
utf8Iterator
*
iter
,
cpUcs4
errCh
);
extern
cpUcs4
utf8IteratorGetCurrCodePoint
(
struct
utf8Iterator
*
iter
,
cpUcs4
errCh
);
extern
int
utf8ScanBackwardsForCodePoint
(
unsigned
char
*
msg
,
int
len
,
int
pos
,
cpUcs4
*
out
);
#ifdef __cplusplus
}
...
...
src/common/utils/mime_parser.cpp
View file @
e1c9d4df
src/nas/mm/msg/AuthenticationReject.c
View file @
e1c9d4df
...
...
@@ -44,7 +44,8 @@ int decode_authentication_reject(
case
AUTHENTICATION_REJECT_EAP_MESSAGE_IEI
:
// if((decoded_result = decode_message_type
// (&authentication_reject->messagetype,
// AUTHENTICATION_REJECT_EAP_MESSAGE_IEI, buffer+decoded,len-decoded))<0)
// AUTHENTICATION_REJECT_EAP_MESSAGE_IEI,
// buffer+decoded,len-decoded))<0)
if
((
decoded_result
=
decode_eap_message
(
&
authentication_reject
->
eapmessage
,
AUTHENTICATION_REJECT_EAP_MESSAGE_IEI
,
buffer
+
decoded
,
...
...
src/nas/sm/msg/PDUSessionEstablishmentAccept.c
View file @
e1c9d4df
...
...
@@ -222,8 +222,8 @@ int encode_pdu_session_establishment_accept(
else
encoded
+=
encoded_result
;
// TODO: In Wireshark Version 3.2.2 (Git commit a3efece3d640), SSC Mode (4
// bit) + PDU session type (4 bit) = 1 byte, so disable encode SSC Mode for
the
// moment, Should be verified later
// bit) + PDU session type (4 bit) = 1 byte, so disable encode SSC Mode for
//
the
moment, Should be verified later
/* if((encoded_result = encode_ssc_mode
(pdu_session_establishment_accept->sscmode, 0,
buffer+encoded,len-encoded))<0) return encoded_result; else encoded +=
...
...
src/oai_smf/main.cpp
View file @
e1c9d4df
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "async_shell_cmd.hpp"
#include "common_defs.h"
...
...
@@ -41,35 +40,35 @@ using namespace util;
using
namespace
std
;
using
namespace
oai
::
smf_server
::
api
;
itti_mw
*
itti_inst
=
nullptr
;
async_shell_cmd
*
async_shell_cmd_inst
=
nullptr
;
smf_app
*
smf_app_inst
=
nullptr
;
itti_mw
*
itti_inst
=
nullptr
;
async_shell_cmd
*
async_shell_cmd_inst
=
nullptr
;
smf_app
*
smf_app_inst
=
nullptr
;
smf_config
smf_cfg
;
SMFApiServer
*
smf_api_server_1
=
nullptr
;
smf_http2_server
*
smf_api_server_2
=
nullptr
;
SMFApiServer
*
smf_api_server_1
=
nullptr
;
smf_http2_server
*
smf_api_server_2
=
nullptr
;
void
send_heartbeat_to_tasks
(
const
uint32_t
sequence
);
//------------------------------------------------------------------------------
void
send_heartbeat_to_tasks
(
const
uint32_t
sequence
)
{
itti_msg_ping
*
itti_msg
=
new
itti_msg_ping
(
TASK_SMF_APP
,
TASK_ALL
,
sequence
);
void
send_heartbeat_to_tasks
(
const
uint32_t
sequence
)
{
itti_msg_ping
*
itti_msg
=
new
itti_msg_ping
(
TASK_SMF_APP
,
TASK_ALL
,
sequence
);
std
::
shared_ptr
<
itti_msg_ping
>
i
=
std
::
shared_ptr
<
itti_msg_ping
>
(
itti_msg
);
int
ret
=
itti_inst
->
send_broadcast_msg
(
i
);
if
(
RETURNok
!=
ret
)
{
Logger
::
smf_app
().
error
(
"Could not send ITTI message %s to task TASK_ALL"
,
i
->
get_msg_name
());
Logger
::
smf_app
().
error
(
"Could not send ITTI message %s to task TASK_ALL"
,
i
->
get_msg_name
());
}
}
//------------------------------------------------------------------------------
void
my_app_signal_handler
(
int
s
)
{
void
my_app_signal_handler
(
int
s
)
{
std
::
cout
<<
"Caught signal "
<<
s
<<
std
::
endl
;
Logger
::
system
().
startup
(
"exiting"
);
Logger
::
system
().
startup
(
"exiting"
);
itti_inst
->
send_terminate_msg
(
TASK_SMF_APP
);
itti_inst
->
wait_tasks_end
();
std
::
cout
<<
"Freeing Allocated memory..."
<<
std
::
endl
;
if
(
async_shell_cmd_inst
)
delete
async_shell_cmd_inst
;
async_shell_cmd_inst
=
nullptr
;
if
(
async_shell_cmd_inst
)
delete
async_shell_cmd_inst
;
async_shell_cmd_inst
=
nullptr
;
std
::
cout
<<
"Async Shell CMD memory done."
<<
std
::
endl
;
if
(
smf_api_server_1
)
{
smf_api_server_1
->
shutdown
();
...
...
@@ -82,29 +81,29 @@ void my_app_signal_handler(int s)
smf_api_server_2
=
nullptr
;
}
std
::
cout
<<
"SMF API Server memory done."
<<
std
::
endl
;
if
(
itti_inst
)
delete
itti_inst
;
itti_inst
=
nullptr
;
if
(
itti_inst
)
delete
itti_inst
;
itti_inst
=
nullptr
;
std
::
cout
<<
"ITTI memory done."
<<
std
::
endl
;
if
(
smf_app_inst
)
delete
smf_app_inst
;
smf_app_inst
=
nullptr
;
if
(
smf_app_inst
)
delete
smf_app_inst
;
smf_app_inst
=
nullptr
;
std
::
cout
<<
"SMF APP memory done."
<<
std
::
endl
;
std
::
cout
<<
"Freeing Allocated memory done"
<<
std
::
endl
;
exit
(
0
);
}
//------------------------------------------------------------------------------
int
main
(
int
argc
,
char
**
argv
)
{
srand
(
time
(
NULL
));
int
main
(
int
argc
,
char
**
argv
)
{
srand
(
time
(
NULL
));
// Command line options
if
(
!
Options
::
parse
(
argc
,
argv
)
)
{
if
(
!
Options
::
parse
(
argc
,
argv
))
{
std
::
cout
<<
"Options::parse() failed"
<<
std
::
endl
;
return
1
;
}
// Logger
Logger
::
init
(
"smf"
,
Options
::
getlogStdout
()
,
Options
::
getlogRotFilelog
());
Logger
::
init
(
"smf"
,
Options
::
getlogStdout
()
,
Options
::
getlogRotFilelog
());
Logger
::
smf_app
().
startup
(
"Options parsed"
);
Logger
::
smf_app
().
startup
(
"Options parsed"
);
struct
sigaction
sigIntHandler
;
sigIntHandler
.
sa_handler
=
my_app_signal_handler
;
...
...
@@ -121,7 +120,8 @@ int main(int argc, char **argv)
itti_inst
->
start
(
smf_cfg
.
itti
.
itti_timer_sched_params
);
// system command
async_shell_cmd_inst
=
new
async_shell_cmd
(
smf_cfg
.
itti
.
async_cmd_sched_params
);
async_shell_cmd_inst
=
new
async_shell_cmd
(
smf_cfg
.
itti
.
async_cmd_sched_params
);
// SMF application layer
smf_app_inst
=
new
smf_app
(
Options
::
getlibconfigConfig
());
...
...
@@ -129,26 +129,29 @@ int main(int argc, char **argv)
// PID file
// Currently hard-coded value. TODO: add as config option.
string
pid_file_name
=
get_exe_absolute_path
(
"/var/run"
,
smf_cfg
.
instance
);
if
(
!
is_pid_file_lock_success
(
pid_file_name
.
c_str
()))
{
Logger
::
smf_app
().
error
(
"Lock PID file %s failed
\n
"
,
pid_file_name
.
c_str
());
exit
(
-
EDEADLK
);
if
(
!
is_pid_file_lock_success
(
pid_file_name
.
c_str
()))
{
Logger
::
smf_app
().
error
(
"Lock PID file %s failed
\n
"
,
pid_file_name
.
c_str
());
exit
(
-
EDEADLK
);
}
//SMF Pistache API server (HTTP1)
Pistache
::
Address
addr
(
std
::
string
(
inet_ntoa
(
*
((
struct
in_addr
*
)
&
smf_cfg
.
sbi
.
addr4
)))
,
Pistache
::
Port
(
smf_cfg
.
sbi
.
port
));
// SMF Pistache API server (HTTP1)
Pistache
::
Address
addr
(
std
::
string
(
inet_ntoa
(
*
((
struct
in_addr
*
)
&
smf_cfg
.
sbi
.
addr4
))),
Pistache
::
Port
(
smf_cfg
.
sbi
.
port
));
smf_api_server_1
=
new
SMFApiServer
(
addr
,
smf_app_inst
);
smf_api_server_1
->
init
(
2
);
//smf_api_server_1->start();
//
smf_api_server_1->start();
std
::
thread
smf_http1_manager
(
&
SMFApiServer
::
start
,
smf_api_server_1
);
//SMF NGHTTP API server (HTTP2)
smf_api_server_2
=
new
smf_http2_server
(
conv
::
toString
(
smf_cfg
.
sbi
.
addr4
),
smf_cfg
.
sbi_http2_port
,
smf_app_inst
);
//smf_api_server_2->start();
// SMF NGHTTP API server (HTTP2)
smf_api_server_2
=
new
smf_http2_server
(
conv
::
toString
(
smf_cfg
.
sbi
.
addr4
),
smf_cfg
.
sbi_http2_port
,
smf_app_inst
);
// smf_api_server_2->start();
std
::
thread
smf_http2_manager
(
&
smf_http2_server
::
start
,
smf_api_server_2
);
smf_http1_manager
.
join
();
smf_http2_manager
.
join
();
FILE
*
fp
=
NULL
;
FILE
*
fp
=
NULL
;
std
::
string
filename
=
fmt
::
format
(
"/tmp/smf_{}.status"
,
getpid
());
fp
=
fopen
(
filename
.
c_str
(),
"w+"
);
fprintf
(
fp
,
"STARTED
\n
"
);
...
...
src/oai_smf/options.cpp
View file @
e1c9d4df
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iostream>
#include <stdlib.h>
...
...
@@ -28,78 +27,100 @@ std::string Options::m_libconfigcfg;
bool
Options
::
m_log_rot_file_log
;
bool
Options
::
m_log_stdout
;
void
Options
::
help
()
{
void
Options
::
help
()
{
std
::
cout
<<
std
::
endl
<<
"Usage: smf [OPTIONS]..."
<<
std
::
endl
<<
" -h, --help Print help and exit"
<<
std
::
endl
<<
" -c, --libconfigcfg filename Read the application configuration from this file."
<<
std
::
endl
<<
" -o, --stdoutlog Send the application logs to STDOUT fd."
<<
std
::
endl
<<
" -r, --rotatelog Send the application logs to local file (in current working directory)."
<<
std
::
endl
;
<<
" -c, --libconfigcfg filename Read the application "
"configuration from this file."
<<
std
::
endl
<<
" -o, --stdoutlog Send the application logs to "
"STDOUT fd."
<<
std
::
endl
<<
" -r, --rotatelog Send the application logs to "
"local file (in current working directory)."
<<
std
::
endl
;
}
bool
Options
::
parse
(
int
argc
,
char
**
argv
){
bool
Options
::
parse
(
int
argc
,
char
**
argv
)
{
bool
ret
=
true
;
ret
=
parseInputOptions
(
argc
,
argv
);
ret
=
parseInputOptions
(
argc
,
argv
);
ret
&=
validateOptions
();
return
ret
;
}
bool
Options
::
validateOptions
(){
return
(
(
options
&
libconfigcfg
)
);
bool
Options
::
validateOptions
()
{
return
((
options
&
libconfigcfg
));
}
bool
Options
::
parseInputOptions
(
int
argc
,
char
**
argv
)
{
bool
Options
::
parseInputOptions
(
int
argc
,
char
**
argv
)
{
int
c
;
int
option_index
=
0
;
bool
result
=
true
;
struct
option
long_options
[]
=
{
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"libconfigcfg"
,
required_argument
,
NULL
,
'f'
},
{
"stdoutlog"
,
no_argument
,
NULL
,
'o'
},
{
"rotatelog"
,
no_argument
,
NULL
,
'r'
},
{
NULL
,
0
,
NULL
,
0
}
};
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"libconfigcfg"
,
required_argument
,
NULL
,
'f'
},
{
"stdoutlog"
,
no_argument
,
NULL
,
'o'
},
{
"rotatelog"
,
no_argument
,
NULL
,
'r'
},
{
NULL
,
0
,
NULL
,
0
}};
// Loop on arguments
while
(
1
)
{
c
=
getopt_long
(
argc
,
argv
,
"horc:"
,
long_options
,
&
option_index
);
if
(
c
==
-
1
)
break
;
// Exit from the loop.
switch
(
c
)
{
case
'h'
:
{
help
();
exit
(
0
);
break
;
}
case
'c'
:
{
m_libconfigcfg
=
optarg
;
options
|=
libconfigcfg
;
break
;
}
case
'o'
:
{
m_log_stdout
=
true
;
options
|=
log_stdout
;
break
;
}
case
'r'
:
{
m_log_rot_file_log
=
true
;
options
|=
log_rot_file_log
;
break
;
}
while
(
1
)
{
c
=
getopt_long
(
argc
,
argv
,
"horc:"
,
long_options
,
&
option_index
);
if
(
c
==
-
1
)
break
;
// Exit from the loop.
switch
(
c
)
{
case
'h'
:
{
help
();
exit
(
0
);
break
;
}
case
'c'
:
{
m_libconfigcfg
=
optarg
;
options
|=
libconfigcfg
;
break
;
}
case
'o'
:
{
m_log_stdout
=
true
;
options
|=
log_stdout
;
break
;
}
case
'r'
:
{
m_log_rot_file_log
=
true
;
options
|=
log_rot_file_log
;
break
;
}
case
'?'
:
{
switch
(
optopt
)
{
case
'c'
:
{
std
::
cout
<<
"Option -l (libconfig config) requires an argument"
<<
std
::
endl
;
break
;
}
case
'o'
:
{
std
::
cout
<<
"Option -o do not requires an argument, can be also set with option -r."
<<
std
::
endl
;
break
;
}
case
'r'
:
{
std
::
cout
<<
"Option -r do not requires an argument, can be also set with option -o."
<<
std
::
endl
;
break
;
}
default:
{
std
::
cout
<<
"Unrecognized option ["
<<
c
<<
"]"
<<
std
::
endl
;
break
;
}
case
'?'
:
{
switch
(
optopt
)
{
case
'c'
:
{
std
::
cout
<<
"Option -l (libconfig config) requires an argument"
<<
std
::
endl
;
break
;
}
case
'o'
:
{
std
::
cout
<<
"Option -o do not requires an argument, can be also "
"set with option -r."
<<
std
::
endl
;
break
;
}
case
'r'
:
{
std
::
cout
<<
"Option -r do not requires an argument, can be also "
"set with option -o."
<<
std
::
endl
;
break
;
}
default:
{
std
::
cout
<<
"Unrecognized option ["
<<
c
<<
"]"
<<
std
::
endl
;
break
;
}
}
result
=
false
;
break
;
}
default:
{
default:
{
std
::
cout
<<
"Unrecognized option ["
<<
c
<<
"]"
<<
std
::
endl
;
result
=
false
;
}
...
...
@@ -107,4 +128,3 @@ bool Options::parseInputOptions( int argc, char **argv )
}
return
result
;
}
src/oai_smf/options.hpp
View file @
e1c9d4df
/*
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright (c) 2017 Sprint
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __OPTIONS_H
#define __OPTIONS_H
...
...
@@ -20,22 +20,18 @@
#include <stdint.h>
#include <string>
class
Options
{
public:
static
bool
parse
(
int
argc
,
char
**
argv
);
static
bool
parseInputOptions
(
int
argc
,
char
**
argv
);
class
Options
{
public:
static
bool
parse
(
int
argc
,
char
**
argv
);
static
bool
parseInputOptions
(
int
argc
,
char
**
argv
);
static
bool
parseJson
();
static
bool
validateOptions
();
static
const
std
::
string
&
getlibconfigConfig
()
{
return
m_libconfigcfg
;
}
static
const
bool
&
getlogRotFilelog
()
{
return
m_log_rot_file_log
;
}
static
const
bool
&
getlogStdout
()
{
return
m_log_stdout
;
}
private:
static
const
std
::
string
&
getlibconfigConfig
()
{
return
m_libconfigcfg
;
}
static
const
bool
&
getlogRotFilelog
()
{
return
m_log_rot_file_log
;
}
static
const
bool
&
getlogStdout
()
{
return
m_log_stdout
;
}
private:
enum
OptionsSelected
{
libconfigcfg
=
0x01
,
log_stdout
=
0x02
,
...
...
src/smf_app/smf_pco.cpp
View file @
e1c9d4df
...
...
@@ -53,9 +53,9 @@ int smf_app::pco_push_protocol_or_container_id(
pco_item
.
length_of_protocol_id_contents
=
poc_id
->
length_of_protocol_id_contents
;
pco_item
.
protocol_id_contents
=
poc_id
->
protocol_id_contents
;
// assert(pco_item.length_of_protocol_id_contents ==
// pco_item.protocol_id_contents.size());
// pco_item.protocol_id_contents = nullptr;
// assert(pco_item.length_of_protocol_id_contents ==
// pco_item.protocol_id_contents.size());
// pco_item.protocol_id_contents = nullptr;
pco
.
protocol_or_container_ids
.
push_back
(
pco_item
);
pco
.
num_protocol_or_container_id
+=
1
;
...
...
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