Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-RAN
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
Michael Black
OpenXG-RAN
Commits
a3ac83a1
Commit
a3ac83a1
authored
Apr 06, 2022
by
frtabu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add OPTIONS http method support, used before POST by frontend.
parent
5ef05129
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
+27
-4
common/utils/websrv/websrv.c
common/utils/websrv/websrv.c
+27
-4
No files found.
common/utils/websrv/websrv.c
View file @
a3ac83a1
...
...
@@ -145,7 +145,7 @@ int websrv_callback_get_mainurl(const struct _u_request * request, struct _u_res
}
int
websrv_callback_default
(
const
struct
_u_request
*
request
,
struct
_u_response
*
response
,
void
*
user_data
)
{
LOG_I
(
UTIL
,
"Requested file is: %s
\n
"
,
request
->
http_url
);
LOG_I
(
UTIL
,
"Requested file is: %s
%s
\n
"
,
request
->
http_verb
,
request
->
http_url
);
if
(
request
->
map_post_body
!=
NULL
)
for
(
int
i
=
0
;
i
<
u_map_count
(
request
->
map_post_body
)
;
i
++
)
LOG_I
(
UTIL
,
"POST parameter %i %s : %s
\n
"
,
i
,
u_map_enum_keys
(
request
->
map_post_body
)[
i
],
u_map_enum_values
(
request
->
map_post_body
)[
i
]
);
...
...
@@ -165,8 +165,25 @@ int websrv_callback_get_mainurl(const struct _u_request * request, struct _u_res
return
U_CALLBACK_CONTINUE
;
}
/* callback processing module url (<address>/oaisoftmodem/module/variables), post method */
int
websrv_callback_okset_softmodemvar
(
const
struct
_u_request
*
request
,
struct
_u_response
*
response
,
void
*
user_data
)
{
LOG_I
(
UTIL
,
"websrv : callback_okset_softmodemvar received %s %s
\n
"
,
request
->
http_verb
,
request
->
http_url
);
for
(
int
i
=
0
;
i
<
u_map_count
(
request
->
map_header
)
;
i
++
)
LOG_I
(
UTIL
,
"header variable %i %s : %s
\n
"
,
i
,
u_map_enum_keys
(
request
->
map_header
)[
i
],
u_map_enum_values
(
request
->
map_header
)[
i
]
);
int
us
=
ulfius_add_header_to_response
(
response
,
"Access-Control-Request-Method"
,
"POST"
);
if
(
us
!=
U_OK
){
ulfius_set_string_body_response
(
response
,
501
,
"Internal server error (ulfius_add_header_to_response)"
);
LOG_E
(
UTIL
,
"websrv cannot set response header type ulfius error %d
\n
"
,
us
);
}
us
=
ulfius_add_header_to_response
(
response
,
"Access-Control-Allow-Headers"
,
"content-type"
);
us
=
ulfius_set_empty_body_response
(
response
,
200
);
if
(
us
!=
U_OK
){
ulfius_set_string_body_response
(
response
,
501
,
"Internal server error (ulfius_set_empty_body_response)"
);
LOG_E
(
UTIL
,
"websrv cannot set empty body response ulfius error %d
\n
"
,
us
);
}
return
U_CALLBACK_CONTINUE
;
}
int
websrv_callback_set_softmodemvar
(
const
struct
_u_request
*
request
,
struct
_u_response
*
response
,
void
*
user_data
)
{
LOG_I
(
UTIL
,
"websrv : callback_set_softmodem
cmd received %s
\n
"
,
request
->
http_url
);
LOG_I
(
UTIL
,
"websrv : callback_set_softmodem
var received %s %s
\n
"
,
request
->
http_verb
,
request
->
http_url
);
json_error_t
jserr
;
json_t
*
jsbody
=
ulfius_get_json_body_request
(
request
,
&
jserr
);
if
(
jsbody
==
NULL
)
{
...
...
@@ -177,7 +194,7 @@ int websrv_callback_set_softmodemvar(const struct _u_request * request, struct _
}
// cmdparser_t * modulestruct = (cmdparser_t *)user_data;
ulfius_set_empty_body_response
(
response
,
200
);
return
U_CALLBACK_CO
NTINU
E
;
return
U_CALLBACK_CO
MPLET
E
;
}
/* callback processing module url (<address>/oaisoftmodem/module/variables), get method*/
...
...
@@ -352,16 +369,22 @@ int websrv_callback_get_softmodemstatus(const struct _u_request * request, struc
// default_endpoint declaration
ulfius_set_default_endpoint
(
websrvparams
.
instance
,
&
websrv_callback_default
,
NULL
);
int
status
=
ulfius_add_endpoint_by_val
(
websrvparams
.
instance
,
"
POST"
,
"oaisoftmodem"
,
"/variables"
,
0
,
&
websrv_callback_
set_softmodemvar
,
NULL
);
int
status
=
ulfius_add_endpoint_by_val
(
websrvparams
.
instance
,
"
OPTIONS"
,
"oaisoftmodem"
,
"variables"
,
1
,
&
websrv_callback_ok
set_softmodemvar
,
NULL
);
if
(
status
!=
U_OK
)
{
LOG_E
(
UTIL
,
"websrv cannot add endpoint oaisoftmodem/variables
\n
"
);
}
ulfius_add_endpoint_by_val
(
websrvparams
.
instance
,
"POST"
,
"oaisoftmodem"
,
"variables"
,
0
,
&
websrv_callback_set_softmodemvar
,
NULL
);
for
(
int
i
=
0
;
telnetparams
->
CmdParsers
[
i
].
var
!=
NULL
&&
telnetparams
->
CmdParsers
[
i
].
cmd
!=
NULL
;
i
++
)
{
char
prefixurl
[
TELNET_CMD_MAXSIZE
+
20
];
snprintf
(
prefixurl
,
TELNET_CMD_MAXSIZE
+
19
,
"oaisoftmodem/%s"
,
telnetparams
->
CmdParsers
[
i
].
module
);
LOG_I
(
UTIL
,
"websrv add endpoints %s/[variables or commands]
\n
"
,
prefixurl
);
ulfius_add_endpoint_by_val
(
websrvparams
.
instance
,
"GET"
,
prefixurl
,
"variables"
,
0
,
&
websrv_callback_get_softmodemvar
,
&
(
telnetparams
->
CmdParsers
[
i
])
);
ulfius_add_endpoint_by_val
(
websrvparams
.
instance
,
"GET"
,
prefixurl
,
"commands"
,
0
,
&
websrv_callback_get_softmodemcmd
,
&
(
telnetparams
->
CmdParsers
[
i
])
);
status
=
ulfius_add_endpoint_by_val
(
websrvparams
.
instance
,
"OPTIONS"
,
prefixurl
,
"variables"
,
0
,
&
websrv_callback_okset_softmodemvar
,
&
(
telnetparams
->
CmdParsers
[
i
])
);
if
(
status
!=
U_OK
)
{
LOG_E
(
UTIL
,
"websrv cannot add endpoint %s/variables
\n
"
,
prefixurl
);}
ulfius_add_endpoint_by_val
(
websrvparams
.
instance
,
"POST"
,
prefixurl
,
"variables"
,
0
,
&
websrv_callback_set_softmodemvar
,
&
(
telnetparams
->
CmdParsers
[
i
])
);
}
// Start the framework
ret
=
U_ERROR
;
...
...
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