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
zzha zzha
OpenXG-RAN
Commits
c239d99f
Commit
c239d99f
authored
Mar 17, 2022
by
frtabu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tested init with front end
parent
f1e87cab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
common/utils/websrv/websrv.c
common/utils/websrv/websrv.c
+46
-0
No files found.
common/utils/websrv/websrv.c
View file @
c239d99f
...
...
@@ -29,6 +29,7 @@
* \note
* \warning
*/
#include <libgen.h>
#include <jansson.h>
#include <ulfius.h>
#include "common/config/config_userapi.h"
...
...
@@ -92,6 +93,37 @@ static void callback_stream_free(void * cls) {
}
}
FILE
*
websrv_getfile
(
char
*
filename
,
struct
_u_response
*
response
)
{
FILE
*
f
=
fopen
(
filename
,
"rb"
);
int
length
;
if
(
f
)
{
fseek
(
f
,
0
,
SEEK_END
);
length
=
ftell
(
f
);
fseek
(
f
,
0
,
SEEK_SET
);
LOG_I
(
UTIL
,
"websrv sending %d bytes from %s
\n
"
,
length
,
filename
);
}
else
{
LOG_E
(
UTIL
,
"websrv couldn't open %s
\n
"
,
filename
);
return
NULL
;
}
int
ust
=
ulfius_add_header_to_response
(
response
,
"content-type"
,
"text/html"
);
if
(
ust
!=
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
"
,
ust
);
fclose
(
f
);
return
NULL
;
}
ust
=
ulfius_set_stream_response
(
response
,
200
,
callback_stream
,
callback_stream_free
,
length
,
1024
,
f
);
if
(
ust
!=
U_OK
)
{
LOG_E
(
UTIL
,
"websrv ulfius_set_stream_response error %d
\n
"
,
ust
);
fclose
(
f
);
return
NULL
;
}
return
f
;
}
/* callback processing main ((initial) url (<address>/<websrvparams.url> */
int
websrv_callback_get_mainurl
(
const
struct
_u_request
*
request
,
struct
_u_response
*
response
,
void
*
user_data
)
{
...
...
@@ -124,6 +156,20 @@ 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
);
char
*
tmpurl
=
strdup
(
websrvparams
.
url
);
char
*
srvdir
=
dirname
(
tmpurl
);
if
(
srvdir
==
NULL
)
{
LOG_E
(
UTIL
,
"Cannot extract dir name from %s requested file is %s
\n
"
,
websrvparams
.
url
,
request
->
http_url
);
return
U_CALLBACK_ERROR
;
}
char
*
fpath
=
malloc
(
strlen
(
request
->
http_url
)
+
strlen
(
srvdir
)
+
2
);
sprintf
(
fpath
,
"%s/%s"
,
srvdir
,
request
->
http_url
);
FILE
*
f
=
websrv_getfile
(
fpath
,
response
)
;
free
(
fpath
);
free
(
tmpurl
);
if
(
f
==
NULL
)
return
U_CALLBACK_ERROR
;
return
U_CALLBACK_CONTINUE
;
}
...
...
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