diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2012-05-01 15:37:40 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2012-05-01 15:37:40 +0000 |
commit | 8cd02da424dc7238c1ee39339699cc8a7f98ef22 (patch) | |
tree | ecbf475cdc88d506a34800ba87c04e41e4166a07 | |
parent | 655182a52d4ccb65952e3ee6f8409d9a6ed9ba90 (diff) |
Added a "K5" feature to handle transparent proxies (Brent Palmer)
-rw-r--r-- | src/htshelp.c | 5 | ||||
-rw-r--r-- | src/htsparse.c | 50 |
2 files changed, 52 insertions, 3 deletions
diff --git a/src/htshelp.c b/src/htshelp.c index 050dbd2..676ed46 100644 --- a/src/htshelp.c +++ b/src/htshelp.c @@ -461,7 +461,7 @@ void help(char* app,int more) { infomsg(" %D cached delayed type check, don't wait for remote type during updates, to speedup them (%D0 wait, * %D1 don't wait)"); infomsg(" %M generate a RFC MIME-encapsulated full-archive (.mht)"); infomsg(" LN long names (L1 *long names / L0 8-3 conversion / L2 ISO9660 compatible)"); - infomsg(" KN keep original links (e.g. http://www.adr/link) (K0 *relative link, K absolute links, K4 original links, K3 absolute URI links)"); + infomsg(" KN keep original links (e.g. http://www.adr/link) (K0 *relative link, K absolute links, K4 original links, K3 absolute URI links, K5 transparent proxy link)"); infomsg(" x replace external html links by error pages"); infomsg(" %x do not include any password for external password protected websites (%x0 include)"); infomsg(" %q *include query string for local files (useless, for information purpose only) (%q0 don't include)"); @@ -605,8 +605,9 @@ void help(char* app,int more) { infomsg("Details: Option K"); infomsg(" K0 foo.cgi?q=45 -> foo4B54.html?q=45 (relative URI, default)"); infomsg(" K -> http://www.foobar.com/folder/foo.cgi?q=45 (absolute URL)"); - infomsg(" K4 -> foo.cgi?q=45 (original URL)"); infomsg(" K3 -> /folder/foo.cgi?q=45 (absolute URI)"); + infomsg(" K4 -> foo.cgi?q=45 (original URL)"); + infomsg(" K5 -> http://www.foobar.com/folder/foo4B54.html?q=45 (transparent proxy URL)"); infomsg(""); infomsg("Shortcuts:"); infomsg("--mirror <URLs> *make a mirror of site(s) (default)"); diff --git a/src/htsparse.c b/src/htsparse.c index d5784bd..7e6bbc4 100644 --- a/src/htsparse.c +++ b/src/htsparse.c @@ -2494,7 +2494,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) { } lastsaved=eadr-1; // dernier écrit+1 (enfin euh apres on fait un ++ alors hein) /* */ - } else if (opt->urlmode >= 4) { // ne rien faire dans tous les cas! + } else if (opt->urlmode == 4) { // ne rien faire! /* */ /* leave the link 'as is' */ /* Sinon, dépend de interne/externe */ @@ -2745,6 +2745,54 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) { } lastsaved=eadr-1; // dernier écrit+1 (enfin euh apres on fait un ++ alors hein) } + else if (opt->urlmode==5) { // transparent proxy URL + char BIGSTK tempo[HTS_URLMAXSIZE*2]; + const char *uri; + int i; + char *pos; + + if ((opt->getmode & 1) && (ptr>0)) { // ecrire les html + if (!link_has_authority(adr)) { + HT_ADD("http://"); + } else { + char* aut = strstr(adr, "//"); + if (aut) { + char tmp[256]; + tmp[0]='\0'; + strncatbuff(tmp, adr, (int) (aut - adr)); // scheme + HT_ADD(tmp); // Protocol + HT_ADD("//"); + } + } + + // filename is taken as URI (ex: "C:\My Website\www.example.com\foo4242.html) + uri = save; + + // .. after stripping the path prefix (ex: "www.example.com\foo4242.html) + if (strnotempty(StringBuff(opt->path_html))) { + uri += StringLength(opt->path_html); + for( ; uri[0] == '/' || uri[0] == '\\' ; uri++) ; + } + + // and replacing all \ by / (ex: "www.example.com/foo4242.html) + strcpybuff(tempo, uri); + for(i = 0 ; tempo[i] != '\0' ; i++) { + if (tempo[i] == '\\') { + tempo[i] = '/'; + } + } + + // put original query string if any (ex: "www.example.com/foo4242.html?q=45) + pos = strchr(fil, '?'); + if (pos != NULL) { + strcatbuff(tempo, pos); + } + + // write it + HT_ADD_HTMLESCAPED(tempo); + } + lastsaved=eadr-1; // dernier écrit+1 (enfin euh apres on fait un ++ alors hein) + } else if (opt->urlmode==2) { // RELATIF char BIGSTK tempo[HTS_URLMAXSIZE*2]; tempo[0]='\0'; |