mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -05:00
DIRLIST: Use directory listing initializer in the file protocol module
This commit is contained in:
parent
865af9ac4a
commit
c96cb0bbae
@ -25,6 +25,7 @@
|
|||||||
#include "intl/gettext/libintl.h"
|
#include "intl/gettext/libintl.h"
|
||||||
#include "main/module.h"
|
#include "main/module.h"
|
||||||
#include "network/connection.h"
|
#include "network/connection.h"
|
||||||
|
#include "protocol/common.h"
|
||||||
#include "protocol/file/cgi.h"
|
#include "protocol/file/cgi.h"
|
||||||
#include "protocol/file/file.h"
|
#include "protocol/file/file.h"
|
||||||
#include "protocol/uri.h"
|
#include "protocol/uri.h"
|
||||||
@ -186,12 +187,12 @@ add_dir_entries(struct directory_entry *entries, unsigned char *dirpath,
|
|||||||
* @dirpath. */
|
* @dirpath. */
|
||||||
/* Returns a connection state. S_OK if all is well. */
|
/* Returns a connection state. S_OK if all is well. */
|
||||||
static inline enum connection_state
|
static inline enum connection_state
|
||||||
list_directory(unsigned char *dirpath, struct string *page)
|
list_directory(struct connection *conn, unsigned char *dirpath,
|
||||||
|
struct string *page)
|
||||||
{
|
{
|
||||||
int show_hidden_files = get_opt_bool("protocol.file.show_hidden_files");
|
int show_hidden_files = get_opt_bool("protocol.file.show_hidden_files");
|
||||||
unsigned char *slash = dirpath;
|
|
||||||
unsigned char *pslash = ++slash;
|
|
||||||
struct directory_entry *entries;
|
struct directory_entry *entries;
|
||||||
|
enum connection_state state;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
entries = get_directory_entries(dirpath, show_hidden_files);
|
entries = get_directory_entries(dirpath, show_hidden_files);
|
||||||
@ -200,30 +201,17 @@ list_directory(unsigned char *dirpath, struct string *page)
|
|||||||
return S_OUT_OF_MEM;
|
return S_OUT_OF_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!init_string(page)) return S_OUT_OF_MEM;
|
state = init_directory_listing(page, conn->uri);
|
||||||
|
if (state != S_OK)
|
||||||
|
return S_OUT_OF_MEM;
|
||||||
|
|
||||||
add_to_string(page, "<html>\n<head><title>");
|
add_dir_entries(entries, dirpath, page);
|
||||||
add_html_to_string(page, dirpath, strlen(dirpath));
|
|
||||||
add_to_string(page, "</title>\n<base href=\"");
|
|
||||||
encode_uri_string(page, dirpath, -1, 0);
|
|
||||||
add_to_string(page, "\" />\n</head>\n<body>\n<h2>Directory /");
|
|
||||||
|
|
||||||
/* Make the directory path with links to each subdir. */
|
if (!add_to_string(page, "</pre>\n<hr>\n</body>\n</html>\n")) {
|
||||||
while ((slash = strchr(slash, '/'))) {
|
done_string(page);
|
||||||
*slash = 0;
|
return S_OUT_OF_MEM;
|
||||||
add_to_string(page, "<a href=\"");
|
|
||||||
/* FIXME: htmlesc? At least we should escape quotes. --pasky */
|
|
||||||
add_to_string(page, dirpath);
|
|
||||||
add_to_string(page, "/\">");
|
|
||||||
add_html_to_string(page, pslash, strlen(pslash));
|
|
||||||
add_to_string(page, "</a>/");
|
|
||||||
*slash = '/';
|
|
||||||
pslash = ++slash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_to_string(page, "</h2>\n<pre>");
|
|
||||||
add_dir_entries(entries, dirpath, page);
|
|
||||||
add_to_string(page, "</pre>\n<hr>\n</body>\n</html>\n");
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +265,7 @@ file_protocol_handler(struct connection *connection)
|
|||||||
redirect_location = "/";
|
redirect_location = "/";
|
||||||
state = S_OK;
|
state = S_OK;
|
||||||
} else {
|
} else {
|
||||||
state = list_directory(name.source, &page);
|
state = list_directory(connection, name.source, &page);
|
||||||
type = "text/html";
|
type = "text/html";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user