OSDN Git Service

onfocus, onblur option of wiki tag.
authorvisor <visor@users.sourceforge.jp>
Mon, 30 Aug 2010 16:06:59 +0000 (01:06 +0900)
committervisor <visor@users.sourceforge.jp>
Mon, 30 Aug 2010 16:06:59 +0000 (01:06 +0900)
http proxy feature. not supporting SSL.

lib/http.cc
lib/http.h
modules/ml-http.cc
wiki/wikiformat.cc
wiki/wikiformat.h

index 9527ca0..57ccfb8 100644 (file)
@@ -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"));
index b365a78..9b5eee6 100644 (file)
@@ -72,6 +72,9 @@ class  HTTPSend {
     ustring  id;
     ustring  pw;
     ustring  cookie;
+    bool  useproxy;
+    ustring  proxyid;
+    ustring  proxypw;
     std::vector<mapelem>  header_reply;
     std::vector<CookieInfo>  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);
index 6c6bd8b..916a91f 100644 (file)
@@ -11,7 +11,6 @@
 #include <iostream>
 #include <fstream>
 
-//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, &params, 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.");
index 4b99f6a..29357b4 100644 (file)
@@ -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)
index 2070f8e..4d91bc3 100644 (file)
@@ -131,6 +131,8 @@ class  WikiAttrib1 {
     ustring  id;
     std::vector<ustring>  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);