mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
DIRLIST:Use directory listing initializer in the Gopher protocol module
This commit is contained in:
parent
94f4b2fd1d
commit
ba2b6e633a
@ -62,6 +62,12 @@ init_directory_listing(struct string *page, struct uri *uri)
|
||||
&& !add_char_to_string(&dirpath, '/'))
|
||||
goto out_of_memory;
|
||||
|
||||
if (uri->protocol == PROTOCOL_GOPHER) {
|
||||
/* A little hack to get readable Gopher names. We should find a
|
||||
* way to do it more general. */
|
||||
decode_uri_string(&dirpath);
|
||||
}
|
||||
|
||||
if (!local && !add_char_to_string(&location, '/'))
|
||||
goto out_of_memory;
|
||||
|
||||
@ -81,15 +87,19 @@ init_directory_listing(struct string *page, struct uri *uri)
|
||||
if (!add_to_string(page, "\" />\n</head>\n<body>\n<h2>"))
|
||||
goto out_of_memory;
|
||||
|
||||
/* Use module names? */
|
||||
switch (uri->protocol) {
|
||||
case PROTOCOL_FILE:
|
||||
info = "Local";
|
||||
break;
|
||||
case PROTOCOL_FSP:
|
||||
info = "FSP";
|
||||
break;
|
||||
case PROTOCOL_FTP:
|
||||
info = "FTP";
|
||||
break;
|
||||
case PROTOCOL_FSP:
|
||||
info = "FSP";
|
||||
case PROTOCOL_GOPHER:
|
||||
info = "Gopher";
|
||||
break;
|
||||
default:
|
||||
info = "?";
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "main/module.h"
|
||||
#include "network/connection.h"
|
||||
#include "network/socket.h"
|
||||
#include "protocol/common.h"
|
||||
#include "protocol/gopher/gopher.h"
|
||||
#include "protocol/protocol.h"
|
||||
#include "protocol/uri.h"
|
||||
@ -599,25 +600,15 @@ read_gopher_directory_data(struct connection *conn, struct read_buffer *rb)
|
||||
struct string buffer;
|
||||
unsigned char *end;
|
||||
|
||||
if (!init_string(&buffer))
|
||||
return S_OUT_OF_MEM;
|
||||
|
||||
if (conn->from == 0) {
|
||||
unsigned char *where = get_uri_string(conn->uri, URI_PUBLIC);
|
||||
enum connection_state state;
|
||||
|
||||
if (where) decode_uri_for_display(where);
|
||||
state = init_directory_listing(&buffer, conn->uri);
|
||||
if (state != S_OK)
|
||||
return state;
|
||||
|
||||
add_format_to_string(&buffer,
|
||||
"<html>\n"
|
||||
"<head>\n"
|
||||
"<title>Gopher menu at %s</title>\n"
|
||||
"</head>\n"
|
||||
"<body>\n"
|
||||
"<h1>Gopher menu at %s</h1>\n"
|
||||
"<pre>",
|
||||
empty_string_or_(where), empty_string_or_(where));
|
||||
|
||||
mem_free_if(where);
|
||||
} else if (!init_string(&buffer)) {
|
||||
return S_OUT_OF_MEM;
|
||||
}
|
||||
|
||||
while ((end = get_gopher_line_end(rb->data, rb->length))) {
|
||||
|
Loading…
Reference in New Issue
Block a user