Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
3dd26868
Commit
3dd26868
authored
Apr 02, 2015
by
Jeroen Vreeken
Browse files
Sort directories alphabetically in the http servers
parent
c3a5c415
Changes
1
Hide whitespace changes
Inline
Side-by-side
console/console/console_httpd.c
View file @
3dd26868
...
...
@@ -630,8 +630,8 @@ int list_dir(struct libwebsocket_context *context, struct libwebsocket *wsi, cha
{
unsigned
char
*
outdata
=
malloc
(
1000
);
size_t
pos
=
0
;
DIR
*
dir
;
struct
dirent
*
dirent
;
struct
dirent
**
namelist
;
int
n
,
i
;
unsigned
char
*
h
=
outdata
;
char
*
server
=
"console_httpd libwebsockets"
;
char
*
type
=
"text/html"
;
...
...
@@ -655,29 +655,26 @@ int list_dir(struct libwebsocket_context *context, struct libwebsocket *wsi, cha
outdata
=
NULL
;
pos
=
0
;
dir
=
opendir
(
resource_path
);
printf
(
"dir: %p
\n
"
,
dir
);
while
(
dir
)
{
n
=
scandir
(
resource_path
,
&
namelist
,
NULL
,
alphasort
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
errno
=
0
;
if
((
dirent
=
readdir
(
dir
))
!=
NULL
)
{
if
(
dirent
->
d_type
!=
DT_REG
)
{
printf
(
"%s is not a regular file
\n
"
,
dirent
->
d_name
);
continue
;
}
char
*
line
;
asprintf
(
&
line
,
"<a href='%s'>%s</a><br>
\n
"
,
dirent
->
d_name
,
dirent
->
d_name
);
outdata
=
realloc
(
outdata
,
pos
+
strlen
(
line
)
+
1
);
strcpy
((
char
*
)
outdata
+
pos
,
line
);
pos
+=
strlen
(
line
);
free
(
line
);
}
else
{
closedir
(
dir
);
dir
=
NULL
;
if
(
namelist
[
i
]
->
d_type
!=
DT_REG
)
{
printf
(
"%s is not a regular file
\n
"
,
namelist
[
i
]
->
d_name
);
continue
;
}
char
*
line
;
asprintf
(
&
line
,
"<a href='%s'>%s</a><br>
\n
"
,
namelist
[
i
]
->
d_name
,
namelist
[
i
]
->
d_name
);
outdata
=
realloc
(
outdata
,
pos
+
strlen
(
line
)
+
1
);
strcpy
((
char
*
)
outdata
+
pos
,
line
);
pos
+=
strlen
(
line
);
free
(
line
);
}
if
(
n
>=
0
)
free
(
namelist
);
if
(
!
lws_send_pipe_choked
(
wsi
))
libwebsocket_write
(
wsi
,
outdata
,
pos
,
LWS_WRITE_HTTP
);
...
...
Write
Preview
Supports
Markdown
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