mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Local file browsing works under Windows. It is done lame way.
In protocol/common.c length of string is known, so pass it instead of -1 to encode_uri_string. Introduced encode_win32_uri_string, because there were problems with : and \ in base href.
This commit is contained in:
parent
8fa2b8180e
commit
1f747b2299
@ -83,7 +83,14 @@ init_directory_listing(struct string *page, struct uri *uri)
|
||||
|| !add_string_to_string(page, &location))
|
||||
goto out_of_memory;
|
||||
|
||||
encode_uri_string(page, dirpath.source, -1, 0);
|
||||
#ifdef CONFIG_OS_WIN32
|
||||
/* Stupid. ':' and '\\' are encoded and base href with them
|
||||
* doesn't "work". */
|
||||
if (local)
|
||||
encode_win32_uri_string(page, dirpath.source, dirpath.length);
|
||||
else
|
||||
#endif
|
||||
encode_uri_string(page, dirpath.source, dirpath.length, 0);
|
||||
|
||||
if (!add_to_string(page, "\" />\n</head>\n<body>\n<h2>"))
|
||||
goto out_of_memory;
|
||||
|
@ -102,7 +102,7 @@ add_dir_entry(struct directory_entry *entry, struct string *page,
|
||||
add_string_to_string(page, &uri_encoded_name);
|
||||
|
||||
if (entry->attrib[0] == 'd') {
|
||||
add_char_to_string(page, '/');
|
||||
add_char_to_string(page, CHAR_DIR_SEP);
|
||||
|
||||
#ifdef FS_UNIX_SOFTLINKS
|
||||
} else if (entry->attrib[0] == 'l') {
|
||||
|
@ -568,6 +568,9 @@ add_uri_to_string(struct string *string, struct uri *uri,
|
||||
"URI_FILENAME should be used alone %d", components);
|
||||
|
||||
if (wants(URI_PATH) && !is_uri_dir_sep(uri, *filename)) {
|
||||
#ifdef CONFIG_OS_WIN32
|
||||
if (uri->protocol != PROTOCOL_FILE)
|
||||
#endif
|
||||
/* FIXME: Add correct separator */
|
||||
add_char_to_string(string, '/');
|
||||
}
|
||||
@ -1334,6 +1337,29 @@ encode_uri_string(struct string *string, unsigned char *name, int namelen,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
encode_win32_uri_string(struct string *string, unsigned char *name, int namelen)
|
||||
{
|
||||
unsigned char n[4];
|
||||
unsigned char *end;
|
||||
|
||||
n[0] = '%';
|
||||
n[3] = '\0';
|
||||
|
||||
if (namelen < 0) namelen = strlen(name);
|
||||
|
||||
for (end = name + namelen; name < end; name++) {
|
||||
if (safe_char(*name) || *name == ':' || *name == '\\') {
|
||||
add_char_to_string(string, *name);
|
||||
} else {
|
||||
/* Hex it. */
|
||||
n[1] = hx((((int) *name) & 0xF0) >> 4);
|
||||
n[2] = hx(((int) *name) & 0xF);
|
||||
add_bytes_to_string(string, n, sizeof(n) - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* This function is evil, it modifies its parameter. */
|
||||
/* XXX: but decoded string is _never_ longer than encoded string so it's an
|
||||
* efficient way to do that, imho. --Zas */
|
||||
|
@ -281,6 +281,9 @@ int get_uri_port(struct uri *uri);
|
||||
void encode_uri_string(struct string *string, unsigned char *name, int namelen,
|
||||
int convert_slashes);
|
||||
|
||||
/* special version for Windows directory listing */
|
||||
void encode_win32_uri_string(struct string *string, unsigned char *name, int namelen);
|
||||
|
||||
void decode_uri_string(struct string *string);
|
||||
void decode_uri(unsigned char *uristring);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user