From: visor Date: Mon, 30 Aug 2010 16:06:59 +0000 (+0900) Subject: onfocus, onblur option of wiki tag. X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=7e0c83d14fda9a894244b98ec6c796dba491dcae;p=hmh%2Fhhml.git onfocus, onblur option of wiki tag. http proxy feature. not supporting SSL. --- diff --git a/lib/http.cc b/lib/http.cc index 9527ca0..57ccfb8 100644 --- a/lib/http.cc +++ b/lib/http.cc @@ -337,6 +337,11 @@ ustring HTTPSend::query () { idpw.assign (id).append (uColon).append (pw); q.append (CharConst ("Authorization: Basic ")).append (base64Encode (idpw.begin (), idpw.end ())).append (uCRLF); } + if (proxyid.length () > 0) { + ustring idpw; + idpw.assign (proxyid).append (uColon).append (proxypw); + q.append (CharConst ("Proxy-Authorization: Basic ")).append (base64Encode (idpw.begin (), idpw.end ())).append (uCRLF); + } if (fpost) q.append (CharConst ("Content-Length: ")).append (to_ustring (params.length ())).append (uCRLF); q.append (CharConst ("Connection: close\r\n\r\n")); diff --git a/lib/http.h b/lib/http.h index b365a78..9b5eee6 100644 --- a/lib/http.h +++ b/lib/http.h @@ -72,6 +72,9 @@ class HTTPSend { ustring id; ustring pw; ustring cookie; + bool useproxy; + ustring proxyid; + ustring proxypw; std::vector header_reply; std::vector cookie_reply; int responseCode; @@ -80,6 +83,7 @@ class HTTPSend { status = HTTP_INIT; fpost = false; responseCode = 0; + useproxy = false; }; virtual ~HTTPSend () {}; virtual bool submit (TcpClient& client, TcpBuf& buf); diff --git a/modules/ml-http.cc b/modules/ml-http.cc index 6c6bd8b..916a91f 100644 --- a/modules/ml-http.cc +++ b/modules/ml-http.cc @@ -11,7 +11,6 @@ #include #include -//static void location_sub (MNode* arg, ustring& url, MlEnv* mlenv) { static void location_sub (ustring& url, MNode* arg, MlEnv* mlenv) { MNodePtr p; MNode* a; @@ -20,9 +19,6 @@ static void location_sub (ustring& url, MNode* arg, MlEnv* mlenv) { umatch m; static uregex re ("^[a-z]{1,6}://[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(:[0-9]{1,5})?/"); -// if (!arg) -// throw (uErrorWrongNumber); -// url = eval_text1 (arg->car (), mlenv); if (usearch (url, m, re)) { uiterator e = url.end (); str = ustring (m[0].second, e); @@ -30,7 +26,6 @@ static void location_sub (ustring& url, MNode* arg, MlEnv* mlenv) { } else { url = urlencode (url); } -// nextNode (arg); c = 0; while (arg) { @@ -72,13 +67,24 @@ static void url_sub (const ustring& url, HTTPSend& http) { b = str.begin (); e = str.end (); if (usearch (b, e, m, re)) { - http.proto = ustring (m[1].first, m[1].second); - http.host = ustring (m[2].first, m[2].second); - if (m[4].matched) - http.port = ustring (m[5].first, m[5].second); - else - http.port.resize (0); - http.path = urlencode (ustring (m[0].second - 1, e)); + if (http.useproxy) { + if (match (m[1].first, m[1].second, uHttps)) { + throw (ustring (CharConst ("proxy connection of SSL protocol not implemented."))); + } else { + http.proto = uHttp; + http.path = str; + if (http.port.empty ()) + http.port.assign (CharConst ("80")); + } + } else { + http.proto = ustring (m[1].first, m[1].second); + http.host = ustring (m[2].first, m[2].second); + if (m[4].matched) + http.port = ustring (m[5].first, m[5].second); + else + http.port.resize (0); + http.path = urlencode (ustring (m[0].second - 1, e)); + } } else { // throw (str + ": bad URL."); http.proto.resize (0); @@ -284,24 +290,41 @@ MNode* ml_http_get (MNode* cell, MlEnv* mlenv) { {CharConst ("pw"), false}, {CharConst ("query"), false}, {CharConst ("cookie"), false}, + {CharConst ("proxy-host"), false}, + {CharConst ("proxy-port"), false}, + {CharConst ("proxy-id"), false}, + {CharConst ("proxy-password"), false}, + {CharConst ("proxy-pw"), false}, {NULL, 0, 0} }; setParams (arg, 1, ¶ms, kwlist, &keywords, &rest); url = eval_str (params[0], mlenv); - if (keywords[0]) + if (keywords[0]) // post obj.http.fpost = eval_bool (keywords[0], mlenv); - if (keywords[1]) - obj.http.id = eval_str (keywords[1], mlenv); - if (keywords[2]) - obj.http.pw = eval_str (keywords[2], mlenv); - if (keywords[3]) - obj.http.pw = eval_str (keywords[3], mlenv); - if (keywords[4]) + if (keywords[1]) // id + obj.http.id = omitCtrl (eval_str (keywords[1], mlenv)); + if (keywords[2]) // password + obj.http.pw = omitCtrl (eval_str (keywords[2], mlenv)); + if (keywords[3]) // pw + obj.http.pw = omitCtrl (eval_str (keywords[3], mlenv)); + if (keywords[4]) // query query = eval (keywords[4], mlenv); - if (keywords[5]) + if (keywords[5]) // cookie cookie = eval (keywords[5], mlenv); - + if (keywords[6]) { // proxy-host + obj.http.host = omitNonAsciiWord (eval_str (keywords[6], mlenv)); + obj.http.useproxy = true; + } + if (keywords[7]) // proxy-port + obj.http.port = omitNonAsciiWord (eval_str (keywords[7], mlenv)); + if (keywords[8]) // proxyid + obj.http.proxyid = omitCtrl (eval_str (keywords[8], mlenv)); + if (keywords[9]) // proxypassword + obj.http.proxypw = omitCtrl (eval_str (keywords[9], mlenv)); + if (keywords[10]) // proxypw + obj.http.proxypw = omitCtrl (eval_str (keywords[10], mlenv)); + url_sub (url, obj.http); if (obj.http.proto.empty ()) { throw (obj.http.path + ": bad URL."); diff --git a/wiki/wikiformat.cc b/wiki/wikiformat.cc index 4b99f6a..29357b4 100644 --- a/wiki/wikiformat.cc +++ b/wiki/wikiformat.cc @@ -128,6 +128,16 @@ bool WikiAttrib1::readAttrib1 (WikiMotorObjVec* cell, bool& rc) { wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n")); ferr = true; } + } else if (wiki->paramOnFocusCheck (key)) { + if (! checkScript (vval, onfocus, ferr)) { + wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n")); + ferr = true; + } + } else if (wiki->paramOnBlurCheck (key)) { + if (! checkScript (vval, onblur, ferr)) { + wiki->errorMsg.append (cell->dump ()).append (CharConst (": link script error.\n")); + ferr = true; + } } else if ((selector & SEL_TARGET) && wiki->paramTargetCheck (key)) { wiki->paramTargetBody (key, vval.textOut (wiki), target, ferr); } else if (readAttribMore (key, vval, ferr)) { @@ -321,6 +331,8 @@ void WikiAttrib1::output (MotorOutput* out) { wiki->outputID (out, id); wiki->outputClass (out, classlist); wiki->outputSubmitScript (out, CharConst ("onClick"), onclick); + wiki->outputSubmitScript (out, CharConst ("onFocus"), onfocus); + wiki->outputSubmitScript (out, CharConst ("onBlur"), onblur); wiki->outputName (out, CharConst ("target"), target); // wiki->outputName (out, CharConst ("size"), elsize); wiki->outputFlag (out, CharConst ("multiple"), fmultiple); @@ -2350,6 +2362,14 @@ bool WikiFormat::paramOnClickCheck (const ustring& name) { return match (name, CharConst ("onclick")); } +bool WikiFormat::paramOnFocusCheck (const ustring& name) { + return match (name, CharConst ("onfocus")); +} + +bool WikiFormat::paramOnBlurCheck (const ustring& name) { + return match (name, CharConst ("onblur")); +} + void WikiFormat::outputName (MotorOutput* out, const char* name, size_t len, const ustring& val, bool cond) { if (! cond || val.length () > 0) out->out_raw (uSPC) diff --git a/wiki/wikiformat.h b/wiki/wikiformat.h index 2070f8e..4d91bc3 100644 --- a/wiki/wikiformat.h +++ b/wiki/wikiformat.h @@ -131,6 +131,8 @@ class WikiAttrib1 { ustring id; std::vector classlist; ustring onclick; + ustring onfocus; + ustring onblur; ustring target; // int32_t elsize; bool fmultiple; @@ -670,6 +672,8 @@ class WikiFormat { virtual bool paramTargetCheck (const ustring& key); virtual void paramTargetBody (const ustring& key, const ustring& value, ustring& var, bool& ferr); virtual bool paramOnClickCheck (const ustring& name); + virtual bool paramOnFocusCheck (const ustring& name); + virtual bool paramOnBlurCheck (const ustring& name); virtual void outputName (MotorOutput* out, const char* name, size_t len, const ustring& val, bool cond = true); virtual void outputName (MotorOutput* out, const char* name, size_t len, long val, bool cond = true); virtual void outputFlag (MotorOutput* out, const char* name, size_t len, bool flag);