aboutsummaryrefslogtreecommitdiffstats
path: root/indep.c
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2003-02-05 16:43:56 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2003-02-05 16:43:56 +0000
commite312638d0c8d64fe85db128d0eb8c3885a8bfe88 (patch)
tree8ffc104ec0f6eef6aae2eea58ff34d882547d065 /indep.c
parent[w3m-dev 03729] buf fix of reAnchorNewsheader() (diff)
downloadw3m-e312638d0c8d64fe85db128d0eb8c3885a8bfe88.tar.gz
w3m-e312638d0c8d64fe85db128d0eb8c3885a8bfe88.zip
[w3m-dev 03730] display decoded URL
* anchor.c (link_list_panel): support DecodeURL * display.c (make_lastline_link): support DecodeURL * etc.c (url_unquote_conv): added * fm.h (DecodeURL): added * history.c (historyBuffer): support DecodeURL * indep.c (QUOTE_MAP): added (HTML_QUOTE_MAP): added (html_quote_char): deleted (url_quote): use is_url_quote (file_quote): use is_file_quote (is_url_safe): deleted (Str_form_quote): use is_url_unsafe (Str_url_unquote): add safe args (is_shell_safe): delete (shell_quote): use is_shell_unsafe * indep.h (QUOTE_MAP): added (HTML_QUOTE_MAP): added (HTML_QUOTE_MASK): added (SHELL_UNSAFE_MASK): added (URL_QUOTE_MASK): added (FILE_QUOTE_MASK): added (URL_UNSAFE_MASK): added (GET_QUOTE_TYPE): added (is_html_quote): added (is_shell_unsafe): added (is_url_quote): added (is_file_quote): added (is_url_unsafe): added (html_quote_char): added (html_quote_char): deleted (Str_url_unquote): added safe (form_unquote): Str_url_unquote changes * linein.c (_prev): support DecodeURL (_next): ditto * main.c (goURL0): support DecodeURL (_peekURL): ditto (curURL): ditto * map.c (follow_map_panel): support DecodeURL (append_map_info): ditto (append_link_info): ditto (append_frame_info): ditto (page_info_panel): ditto * menu.c (initSelectMenu): delete SCM_LOCAL_CGI support DecodeURL (initSelTabMenu): delete SCM_LOCAL_CGI support DecodeURL (link_menu): support DecodeURL * parsetagx.c (parse_tag): is_html_quote * proto.h (url_unquote_conv): added * rc.c (CMT_DECODE_URL): added (params1): add decode_url * url.c (openURL): Str_url_unquote non safe From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat (limited to 'indep.c')
-rw-r--r--indep.c101
1 files changed, 46 insertions, 55 deletions
diff --git a/indep.c b/indep.c
index 9e1f0de..a9d8d8b 100644
--- a/indep.c
+++ b/indep.c
@@ -1,4 +1,4 @@
-/* $Id: indep.c,v 1.30 2003/01/17 17:07:00 ukai Exp $ */
+/* $Id: indep.c,v 1.31 2003/02/05 16:43:57 ukai Exp $ */
#include "fm.h"
#include <stdio.h>
#include <pwd.h>
@@ -11,6 +11,45 @@
#include "myctype.h"
#include "entity.h"
+unsigned char QUOTE_MAP[0x100] = {
+/* NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI */
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+/* DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US */
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+/* SPC ! " # $ % & ' ( ) * + , - . / */
+ 24, 72, 76, 40, 8, 40, 41, 72, 72, 72, 72, 40, 72, 8, 0, 64,
+/* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 72, 74, 72, 75, 40,
+/* @ A B C D E F G H I J K L M N O */
+ 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* P Q R S T U V W X Y Z [ \ ] ^ _ */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 72, 72, 72, 72, 0,
+/* ` a b c d e f g h i j k l m n o */
+ 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+/* p q r s t u v w x y z { | } ~ DEL */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 72, 72, 72, 72, 24,
+
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
+};
+
+char *HTML_QUOTE_MAP[] = {
+ NULL,
+ "&amp;",
+ "&lt;",
+ "&gt;",
+ "&quot;",
+ NULL,
+ NULL,
+ NULL,
+};
+
clen_t
strtoclen(const char *s)
{
@@ -445,22 +484,6 @@ getescapecmd(char **s)
}
char *
-html_quote_char(char c)
-{
- switch (c) {
- case '&':
- return "&amp;";
- case '<':
- return "&lt;";
- case '>':
- return "&gt;";
- case '"':
- return "&quot;";
- }
- return NULL;
-}
-
-char *
html_quote(char *str)
{
Str tmp = NULL;
@@ -522,7 +545,7 @@ url_quote(char *str)
char *p;
for (p = str; *p; p++) {
- if (IS_CNTRL(*p) || *p == ' ' || !IS_ASCII(*p)) {
+ if (is_url_quote(*p)) {
if (tmp == NULL)
tmp = Strnew_charp_n(str, (int)(p - str));
Strcat_char(tmp, '%');
@@ -547,8 +570,7 @@ file_quote(char *str)
char buf[4];
for (p = str; *p; p++) {
- if (IS_CNTRL(*p) || *p == ' ' || !IS_ASCII(*p) || *p == '+' ||
- *p == ':' || *p == '#' || *p == '?' || *p == '&' || *p == '%') {
+ if (is_file_quote(*p)) {
if (tmp == NULL)
tmp = Strnew_charp_n(str, (int)(p - str));
sprintf(buf, "%%%02X", (unsigned char)*p);
@@ -593,22 +615,6 @@ file_unquote(char *str)
return str;
}
-/* rfc1808 safe */
-static int
-is_url_safe(char c)
-{
- switch (c) {
- /* safe */
- case '$':
- case '-':
- case '_':
- case '.':
- return 1;
- default:
- return IS_ALNUM(c);
- }
-}
-
Str
Str_form_quote(Str x)
{
@@ -622,7 +628,7 @@ Str_form_quote(Str x)
tmp = Strnew_charp_n(x->ptr, (int)(p - x->ptr));
Strcat_char(tmp, '+');
}
- else if (!is_url_safe(*p)) {
+ else if (is_url_unsafe(*p)) {
if (tmp == NULL)
tmp = Strnew_charp_n(x->ptr, (int)(p - x->ptr));
sprintf(buf, "%%%02X", (unsigned char)*p);
@@ -640,7 +646,7 @@ Str_form_quote(Str x)
Str
-Str_url_unquote(Str x, int is_form)
+Str_url_unquote(Str x, int is_form, int safe)
{
Str tmp = NULL;
char *p = x->ptr, *ep = x->ptr + x->length, *q;
@@ -657,7 +663,7 @@ Str_url_unquote(Str x, int is_form)
else if (*p == '%') {
q = p;
c = url_unquote_char(&q);
- if (c >= 0) {
+ if (c >= 0 && (!safe || !IS_ASCII(c) || !is_file_quote(c))) {
if (tmp == NULL)
tmp = Strnew_charp_n(x->ptr, (int)(p - x->ptr));
Strcat_char(tmp, (char)c);
@@ -674,21 +680,6 @@ Str_url_unquote(Str x, int is_form)
return x;
}
-static int
-is_shell_safe(char c)
-{
- switch (c) {
- /* safe */
- case '/':
- case '.':
- case '_':
- case ':':
- return 1;
- default:
- return IS_ALNUM(c) || (c & 0x80);
- }
-}
-
char *
shell_quote(char *str)
{
@@ -696,7 +687,7 @@ shell_quote(char *str)
char *p;
for (p = str; *p; p++) {
- if (!is_shell_safe(*p)) {
+ if (is_shell_unsafe(*p)) {
if (tmp == NULL)
tmp = Strnew_charp_n(str, (int)(p - str));
Strcat_char(tmp, '\\');