Changeset 281:012446e5b265

Show
Ignore:
Timestamp:
06/15/2008 07:33:35 PM (4 years ago)
Author:
Dmitry Nezhevenko <dion@…>
Branch:
default
Message:

Implement !net post command, reimplement HTML unescaper, add %[MODIFIERS]* syntax to alias

Location:
src
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • src/base/baseplugin.h

    r267 r281  
    2121public: 
    2222        BasePlugin(GluxiBot *parent); 
    23         ~BasePlugin(); 
     23        virtual ~BasePlugin(); 
    2424        int id() const {return pluginId;}; 
    2525        virtual QString name() const { return "BasePlugin"; }; 
  • src/base/common.cpp

    r197 r281  
    55#include <QRegExp> 
    66#include <QtDebug> 
     7#include <QUrl> 
     8#include <QTextCodec> 
     9#include <QByteArray> 
    710 
    811#ifndef Q_WS_WIN 
    912#include <sys/utsname.h> 
    1013#endif 
     14 
     15static QMap<QString, QString> htmlMap; 
     16 
     17void populateHtmlMap(); 
     18QString replaceHtmlToken(const QString& token); 
    1119 
    1220QString secsToString(int secs) 
     
    125133QString removeHtml(const QString& s) 
    126134{ 
     135        if (htmlMap.isEmpty()) 
     136                populateHtmlMap(); 
     137         
    127138        QString res=s; 
    128139        QRegExp exp("<([^>]*)>"); 
     
    146157                } 
    147158        } 
    148         res.replace("&lt;", "<"); 
    149         res.replace("&amp;", "&"); 
    150         res.replace("&gt;", ">"); 
    151         res.replace("&quot;", "\""); 
    152         res.replace("&#39;", "'"); 
    153         res.replace("&raquo;", ">>"); 
    154         res.replace("&ldquo;", "\""); 
    155         res.replace("&rdquo;", "\""); 
    156         res.replace("&rsquo;", "'"); 
    157         res.replace("&nbsp;", " "); 
     159        QRegExp patExp("&([^;]+);"); 
     160        patExp.setMinimal(true); 
     161        int ps=0; 
     162        while ((ps=patExp.indexIn(res,ps))!=-1) 
     163        { 
     164                QStringList captured=patExp.capturedTexts(); 
     165                QString v; 
     166                if (captured.count()==2) 
     167                { 
     168                        QString sub=captured[1]; 
     169                        v=replaceHtmlToken(sub); 
     170                } 
     171                res.remove(ps,patExp.matchedLength()); 
     172                if (!v.isEmpty()) 
     173                { 
     174                        res.insert(ps,v); 
     175                        ps+=v.length(); 
     176                } 
     177        } 
     178         
    158179        return removeExtraSpaces(res); 
    159180} 
    160181 
     182QString replaceHtmlToken(const QString& token) 
     183{ 
     184        if (htmlMap.contains(token)) 
     185                return htmlMap[token]; 
     186        if (token.startsWith("#")) 
     187        { 
     188                QString tInt(token); 
     189                tInt.remove(0,1); 
     190                bool ok=true; 
     191                int code=tInt.toInt(&ok); 
     192                if (ok) 
     193                        return QChar(code); 
     194                else 
     195                        return " "; 
     196        } 
     197        return QString(); 
     198} 
     199 
    161200bool isBareJidValid(const QString& jid) 
    162201{ 
    163202        QString user=jid.section('@',0,-2); 
    164         QString server=jid.section('@',-1,-1); 
    165         qDebug() << "user: " << user << "; server: " << server;  
     203        QString server=jid.section('@',-1,-1);  
    166204        if (!isServerValid(server)) 
    167205                return false; 
     
    173211        return exp.exactMatch(server); 
    174212} 
     213 
     214QString urlEncode(const QString& s, const QString& encoding) 
     215{ 
     216        QString enc=encoding.toLower(); 
     217        if (enc.isEmpty() || enc=="utf8" || enc=="utf-8") 
     218                return QString(QUrl::toPercentEncoding(s)); 
     219         
     220        QString dst; 
     221        QTextCodec* codec=QTextCodec::codecForName(encoding.toAscii()); 
     222        QByteArray arr; 
     223        if (codec) 
     224                arr=codec->fromUnicode(s); 
     225        else 
     226                arr=s.toUtf8(); 
     227        int l=arr.length(); 
     228        for (int i=0; i<l; ++i) 
     229        { 
     230                char ch=arr.at(i); 
     231                if ((ch >= 'A' && ch<='A') || (ch>='a' && ch<='a') || (ch>='0' && ch<='9')  
     232                                || ch=='~' || ch=='~' || ch=='.' || ch=='-') 
     233                { 
     234                        dst.append(ch); 
     235                } 
     236                else 
     237                { 
     238                        QString num; 
     239                        num.setNum((unsigned char)ch,16); 
     240                        num=num.rightJustified(2,QChar('0')); 
     241                        dst.append("%"+num); 
     242                } 
     243        } 
     244        return dst; 
     245} 
     246 
     247void populateHtmlMap() 
     248{ 
     249        htmlMap.insert("nbsp"," "); 
     250        htmlMap.insert("iexcl",  QChar(161)); 
     251        htmlMap.insert("cent",  QChar(162)); 
     252        htmlMap.insert("pound",  QChar(163)); 
     253        htmlMap.insert("curren",  QChar(164)); 
     254        htmlMap.insert("yen",  QChar(165)); 
     255        htmlMap.insert("brvbar",  QChar(166)); 
     256        htmlMap.insert("sect",  QChar(167)); 
     257        htmlMap.insert("uml",  QChar(168)); 
     258        htmlMap.insert("copy",  QChar(169)); 
     259        htmlMap.insert("ordf",  QChar(170)); 
     260        htmlMap.insert("laquo",  QChar(171)); 
     261        htmlMap.insert("raquo",  QChar(187)); 
     262        htmlMap.insert("not",  QChar(172)); 
     263        htmlMap.insert("shy",  QChar(173)); 
     264        htmlMap.insert("reg",  QChar(174)); 
     265        htmlMap.insert("macr",  QChar(175)); 
     266        htmlMap.insert("deg",  QChar(176)); 
     267        htmlMap.insert("plusmn",  QChar(177)); 
     268        htmlMap.insert("sup2",  QChar(178)); 
     269        htmlMap.insert("sup3",  QChar(179)); 
     270        htmlMap.insert("acute",  QChar(180)); 
     271        htmlMap.insert("micro",  QChar(181)); 
     272        htmlMap.insert("para",  QChar(182)); 
     273        htmlMap.insert("middot",  QChar(183)); 
     274        htmlMap.insert("cedil",  QChar(184)); 
     275        htmlMap.insert("sup1",  QChar(185)); 
     276        htmlMap.insert("ordm",  QChar(186)); 
     277        htmlMap.insert("frac14",  QChar(188)); 
     278        htmlMap.insert("frac12",  QChar(189)); 
     279        htmlMap.insert("frac34",  QChar(190)); 
     280        htmlMap.insert("iquest",  QChar(191)); 
     281        htmlMap.insert("Agrave",  QChar(192)); 
     282        htmlMap.insert("Aacute",  QChar(193)); 
     283        htmlMap.insert("Acirc",  QChar(194)); 
     284        htmlMap.insert("Atilde",  QChar(195)); 
     285        htmlMap.insert("Auml",  QChar(196)); 
     286        htmlMap.insert("Aring",  QChar(197)); 
     287        htmlMap.insert("AElig",  QChar(198)); 
     288        htmlMap.insert("Ccedil",  QChar(199)); 
     289        htmlMap.insert("Egrave",  QChar(200)); 
     290        htmlMap.insert("Eacute",  QChar(201)); 
     291        htmlMap.insert("Ecirc",  QChar(202)); 
     292        htmlMap.insert("Euml",  QChar(203)); 
     293        htmlMap.insert("Igrave",  QChar(204)); 
     294        htmlMap.insert("Iacute",  QChar(205)); 
     295        htmlMap.insert("Icirc",  QChar(206)); 
     296        htmlMap.insert("Iuml",  QChar(207)); 
     297        htmlMap.insert("ETH",  QChar(208)); 
     298        htmlMap.insert("Ntilde",  QChar(209)); 
     299        htmlMap.insert("Ograve",  QChar(210)); 
     300        htmlMap.insert("Oacute",  QChar(211)); 
     301        htmlMap.insert("Ocirc",  QChar(212)); 
     302        htmlMap.insert("Otilde",  QChar(213)); 
     303        htmlMap.insert("Ouml",  QChar(214)); 
     304        htmlMap.insert("times",  QChar(215)); 
     305        htmlMap.insert("Oslash",  QChar(216)); 
     306        htmlMap.insert("Ugrave",  QChar(217)); 
     307        htmlMap.insert("Uacute",  QChar(218)); 
     308        htmlMap.insert("Ucirc",  QChar(219)); 
     309        htmlMap.insert("Uuml",  QChar(220)); 
     310        htmlMap.insert("Yacute",  QChar(221)); 
     311        htmlMap.insert("THORN",  QChar(222)); 
     312        htmlMap.insert("szlig",  QChar(223)); 
     313        htmlMap.insert("agrave",  QChar(224)); 
     314        htmlMap.insert("aacute",  QChar(225)); 
     315        htmlMap.insert("acirc",  QChar(226)); 
     316        htmlMap.insert("atilde",  QChar(227)); 
     317        htmlMap.insert("auml",  QChar(228)); 
     318        htmlMap.insert("aring",  QChar(229)); 
     319        htmlMap.insert("aelig",  QChar(230)); 
     320        htmlMap.insert("ccedil",  QChar(231)); 
     321        htmlMap.insert("egrave",  QChar(232)); 
     322        htmlMap.insert("eacute",  QChar(233)); 
     323        htmlMap.insert("ecirc",  QChar(234)); 
     324        htmlMap.insert("euml",  QChar(235)); 
     325        htmlMap.insert("igrave",  QChar(236)); 
     326        htmlMap.insert("iacute",  QChar(237)); 
     327        htmlMap.insert("icirc",  QChar(238)); 
     328        htmlMap.insert("iuml",  QChar(239)); 
     329        htmlMap.insert("eth",  QChar(240)); 
     330        htmlMap.insert("ntilde",  QChar(241)); 
     331        htmlMap.insert("ograve",  QChar(242)); 
     332        htmlMap.insert("oacute",  QChar(243)); 
     333        htmlMap.insert("ocirc",  QChar(244)); 
     334        htmlMap.insert("otilde",  QChar(245)); 
     335        htmlMap.insert("ouml",  QChar(246)); 
     336        htmlMap.insert("divide",  QChar(247)); 
     337        htmlMap.insert("oslash",  QChar(248)); 
     338        htmlMap.insert("ugrave",  QChar(249)); 
     339        htmlMap.insert("uacute",  QChar(250)); 
     340        htmlMap.insert("ucirc",  QChar(251)); 
     341        htmlMap.insert("uuml",  QChar(252)); 
     342        htmlMap.insert("yacute",  QChar(253)); 
     343        htmlMap.insert("thorn",  QChar(254)); 
     344        htmlMap.insert("yuml",  QChar(255)); 
     345         
     346        htmlMap.insert("fnof",  QChar(402)); 
     347 
     348        htmlMap.insert("Alpha",  QChar(913)); 
     349        htmlMap.insert("Beta",  QChar(914)); 
     350        htmlMap.insert("Gamma",  QChar(915)); 
     351        htmlMap.insert("Delta",  QChar(916)); 
     352        htmlMap.insert("Epsilon",  QChar(917)); 
     353        htmlMap.insert("Zeta",  QChar(918)); 
     354        htmlMap.insert("Eta",  QChar(919)); 
     355        htmlMap.insert("Theta",  QChar(920)); 
     356        htmlMap.insert("Iota",  QChar(921)); 
     357        htmlMap.insert("Kappa",  QChar(922)); 
     358        htmlMap.insert("Lambda",  QChar(923)); 
     359        htmlMap.insert("Mu",  QChar(924)); 
     360        htmlMap.insert("Nu",  QChar(925)); 
     361        htmlMap.insert("Xi",  QChar(926)); 
     362        htmlMap.insert("Omicron",  QChar(927)); 
     363        htmlMap.insert("Pi",  QChar(928)); 
     364        htmlMap.insert("Rho",  QChar(929)); 
     365        htmlMap.insert("Sigma",  QChar(931)); 
     366        htmlMap.insert("Tau",  QChar(932)); 
     367        htmlMap.insert("Upsilon",  QChar(933)); 
     368        htmlMap.insert("Phi",  QChar(934)); 
     369        htmlMap.insert("Chi",  QChar(935)); 
     370        htmlMap.insert("Psi",  QChar(936)); 
     371        htmlMap.insert("Omega",  QChar(937)); 
     372        htmlMap.insert("alpha",  QChar(945)); 
     373        htmlMap.insert("beta",  QChar(946)); 
     374        htmlMap.insert("gamma",  QChar(947)); 
     375        htmlMap.insert("delta",  QChar(948)); 
     376        htmlMap.insert("epsilon",  QChar(949)); 
     377        htmlMap.insert("zeta",  QChar(950)); 
     378        htmlMap.insert("eta",  QChar(951)); 
     379        htmlMap.insert("theta",  QChar(952)); 
     380        htmlMap.insert("iota",  QChar(953)); 
     381        htmlMap.insert("kappa",  QChar(954)); 
     382        htmlMap.insert("lambda",  QChar(955)); 
     383        htmlMap.insert("mu",  QChar(956)); 
     384        htmlMap.insert("nu",  QChar(957)); 
     385        htmlMap.insert("xi",  QChar(958)); 
     386        htmlMap.insert("omicron",  QChar(959)); 
     387        htmlMap.insert("pi",  QChar(960)); 
     388        htmlMap.insert("rho",  QChar(961)); 
     389        htmlMap.insert("sigmaf",  QChar(962)); 
     390        htmlMap.insert("sigma",  QChar(963)); 
     391        htmlMap.insert("tau",  QChar(964)); 
     392        htmlMap.insert("upsilon",  QChar(965)); 
     393        htmlMap.insert("phi",  QChar(966)); 
     394        htmlMap.insert("chi",  QChar(967)); 
     395        htmlMap.insert("psi",  QChar(968)); 
     396        htmlMap.insert("omega",  QChar(969)); 
     397        htmlMap.insert("thetasy",  QChar(977)); 
     398        htmlMap.insert("upsih",  QChar(978)); 
     399        htmlMap.insert("piv",  QChar(982)); 
     400         
     401        htmlMap.insert("bull",  QChar(8226)); 
     402        htmlMap.insert("hellip",  QChar(8230)); 
     403        htmlMap.insert("prime",  QChar(8242)); 
     404        htmlMap.insert("Prime",  QChar(8243)); 
     405        htmlMap.insert("oline",  QChar(8254)); 
     406        htmlMap.insert("frasl",  QChar(8260)); 
     407         
     408        htmlMap.insert("weierp",  QChar(8472)); 
     409        htmlMap.insert("image",  QChar(8465)); 
     410        htmlMap.insert("real",  QChar(8476)); 
     411        htmlMap.insert("trade",  QChar(8482)); 
     412        htmlMap.insert("alefsym",  QChar(8501)); 
     413         
     414        htmlMap.insert("larr",  QChar(8592)); 
     415        htmlMap.insert("uarr",  QChar(8593)); 
     416        htmlMap.insert("rarr",  QChar(8594)); 
     417        htmlMap.insert("darr",  QChar(8595)); 
     418        htmlMap.insert("harr",  QChar(8596)); 
     419        htmlMap.insert("crarr",  QChar(8629)); 
     420        htmlMap.insert("lArr",  QChar(8656)); 
     421        htmlMap.insert("uArr",  QChar(8657)); 
     422        htmlMap.insert("rArr",  QChar(8658)); 
     423        htmlMap.insert("dArr",  QChar(8659)); 
     424        htmlMap.insert("hArr",  QChar(8660)); 
     425         
     426        htmlMap.insert("forall",  QChar(8704)); 
     427        htmlMap.insert("part",  QChar(8706)); 
     428        htmlMap.insert("exist",  QChar(8707)); 
     429        htmlMap.insert("empty",  QChar(8709)); 
     430        htmlMap.insert("nabla",  QChar(8711)); 
     431        htmlMap.insert("isin",  QChar(8712)); 
     432        htmlMap.insert("notin",  QChar(8713)); 
     433        htmlMap.insert("ni",  QChar(8715)); 
     434        htmlMap.insert("prod",  QChar(8719)); 
     435        htmlMap.insert("sum",  QChar(8721)); 
     436        htmlMap.insert("minus",  QChar(8722)); 
     437        htmlMap.insert("lowast",  QChar(8727)); 
     438        htmlMap.insert("radic",  QChar(8730)); 
     439        htmlMap.insert("prop",  QChar(8733)); 
     440        htmlMap.insert("infin",  QChar(8734)); 
     441        htmlMap.insert("ang",  QChar(8736)); 
     442        htmlMap.insert("and",  QChar(8743)); 
     443        htmlMap.insert("or",  QChar(8744)); 
     444        htmlMap.insert("cap",  QChar(8745)); 
     445        htmlMap.insert("cup",  QChar(8746)); 
     446        htmlMap.insert("int",  QChar(8747)); 
     447        htmlMap.insert("there4",  QChar(8756)); 
     448        htmlMap.insert("sim",  QChar(8764)); 
     449        htmlMap.insert("cong",  QChar(8773)); 
     450        htmlMap.insert("asymp",  QChar(8776)); 
     451        htmlMap.insert("ne",  QChar(8800)); 
     452        htmlMap.insert("equiv",  QChar(8801)); 
     453        htmlMap.insert("le",  QChar(8804)); 
     454        htmlMap.insert("ge",  QChar(8805)); 
     455        htmlMap.insert("sub",  QChar(8834)); 
     456        htmlMap.insert("sup",  QChar(8835)); 
     457        htmlMap.insert("nsub",  QChar(8836)); 
     458        htmlMap.insert("sube",  QChar(8838)); 
     459        htmlMap.insert("supe",  QChar(8839)); 
     460        htmlMap.insert("oplus",  QChar(8853)); 
     461        htmlMap.insert("otimes",  QChar(8855)); 
     462        htmlMap.insert("perp",  QChar(8869)); 
     463        htmlMap.insert("sdot",  QChar(8901)); 
     464 
     465        htmlMap.insert("lceil",  QChar(8968)); 
     466        htmlMap.insert("rceil",  QChar(8969)); 
     467        htmlMap.insert("lfloor",  QChar(8970)); 
     468        htmlMap.insert("rfloor",  QChar(8971)); 
     469        htmlMap.insert("lang",  QChar(9001)); 
     470        htmlMap.insert("rang",  QChar(9002)); 
     471 
     472        htmlMap.insert("loz",  QChar(9674)); 
     473 
     474        htmlMap.insert("spades",  QChar(9824)); 
     475        htmlMap.insert("clubs",  QChar(9827)); 
     476        htmlMap.insert("hearts",  QChar(9829)); 
     477        htmlMap.insert("diams",  QChar(9830)); 
     478                 
     479        htmlMap.insert("quot",  QChar(34)); 
     480        htmlMap.insert("amp",  QChar(38)); 
     481        htmlMap.insert("lt",  QChar(60)); 
     482        htmlMap.insert("gt",  QChar(62)); 
     483        htmlMap.insert("OElig",  QChar(338)); 
     484        htmlMap.insert("oelig",  QChar(339)); 
     485        htmlMap.insert("Scaron",  QChar(352)); 
     486        htmlMap.insert("scaron",  QChar(353)); 
     487        htmlMap.insert("Yuml",  QChar(376)); 
     488        htmlMap.insert("circ",  QChar(710)); 
     489        htmlMap.insert("tilde",  QChar(732)); 
     490        htmlMap.insert("ensp",  QChar(8194)); 
     491        htmlMap.insert("emsp",  QChar(8195)); 
     492        htmlMap.insert("thinsp",  QChar(8201)); 
     493        htmlMap.insert("zwnj",  QChar(8204)); 
     494        htmlMap.insert("zwj",  QChar(8205)); 
     495        htmlMap.insert("lrm",  QChar(8206)); 
     496        htmlMap.insert("rlm",  QChar(8207)); 
     497        htmlMap.insert("ndash",  QChar(8211)); 
     498        htmlMap.insert("mdash",  QChar(8212)); 
     499        htmlMap.insert("lsquo",  QChar(8216)); 
     500        htmlMap.insert("rsquo",  QChar(8217)); 
     501        htmlMap.insert("sbquo",  QChar(8218)); 
     502        htmlMap.insert("ldquo",  QChar(8220)); 
     503        htmlMap.insert("rdquo",  QChar(8221)); 
     504        htmlMap.insert("bdquo",  QChar(8222)); 
     505        htmlMap.insert("dagger",  QChar(8224)); 
     506        htmlMap.insert("Dagger",  QChar(8225)); 
     507        htmlMap.insert("permil",  QChar(8240)); 
     508        htmlMap.insert("lsaquo",  QChar(8249)); 
     509        htmlMap.insert("rsaquo",  QChar(8250)); 
     510        htmlMap.insert("euro",  QChar(8364)); 
     511} 
  • src/base/common.h

    r197 r281  
    1313bool isServerValid(const QString& server); 
    1414 
     15QString urlEncode(const QString& s, const QString& encoding); 
     16 
    1517#endif 
  • src/plugins/alias/aliasplugin.cpp

    r279 r281  
    44#include "base/rolelist.h" 
    55#include "base/messageparser.h" 
     6#include "base/common.h" 
    67 
    78#include <QList> 
    89#include <QtDebug> 
     10#include <QTextCodec> 
    911 
    1012#include <assert.h> 
     
    4446 
    4547        Alias alias=aliases.get(bot()->getStorage(s), cmd); 
    46          
     48 
    4749        if (!parser.isForMe() && !alias.isGlobal()) 
    4850        { 
     
    5052                return false; 
    5153        } 
    52          
     54 
    5355        QString res=alias.value(); 
    5456        QString firstArg=res.section(' ',0,0).toUpper(); 
     
    6769                noWrap=true; 
    6870        } 
    69          
     71 
    7072        if (!res.isEmpty()) 
    7173        { 
     
    8486 
    8587                        qDebug() << "------ Alias:\n| original: " << originalItem 
    86                         << "\n| expanded: " << item; 
     88                                        << "\n| expanded: " << item; 
    8789 
    8890                        if (item.isEmpty()) 
     
    131133                        for (int i=0; i<cnt; i++) 
    132134                                res+=QString("\n%1) %2%3=%4").arg(i+1).arg(all.values()[i].isGlobal() ? "[GLOBAL] ": "") 
    133                                         .arg(all.keys()[i].toLower()).arg(all.values()[i].value()); 
     135                                .arg(all.keys()[i].toLower()).arg(all.values()[i].value()); 
    134136                        reply(s, QString("Aliases:%1").arg(res)); 
    135137                        return true; 
     
    137139                else 
    138140                { 
    139                         Alias alias=aliases.get(bot()->getStorage(s),aliasName.toUpper()); 
     141                        Alias alias=aliases.get(bot()->getStorage(s), aliasName.toUpper()); 
    140142                        QString value=alias.value(); 
    141143                        if (!value.isNull()) 
    142144                                reply(s, QString("Alias: %1%2=%3").arg(alias.isGlobal() ? "[GLOBAL] " : "") 
    143                                                 .arg(aliasName).arg(value)); 
     145                                .arg(aliasName).arg(value)); 
    144146                        else 
    145147                                reply(s, QString("No such alias: %1").arg(aliasName)); 
     
    214216{ 
    215217        QString res=alias; 
     218        int idx=1; 
     219        int parserIdx=parser.getCurrentIndex(); 
     220        while (1) 
     221        { 
     222                int offset=0; 
     223                QString subStr=parser.nextToken(); 
     224                QString replacedStr=replacePattern(res, QString::number(idx), subStr, 
     225                                &offset); 
     226                if (replacedStr==res) 
     227                        break; 
     228                res=replacedStr; 
     229                idx++; 
     230                parserIdx++; 
     231        } 
     232        parser.setCurrentIndex(parserIdx); 
     233        int offset=0; 
     234        QString subStr=parser.joinBody(); 
     235        res=replacePattern(res, "\\*", subStr, &offset); 
     236        return res.trimmed(); 
     237} 
     238 
     239QString AliasPlugin::replacePattern(const QString& str, const QString& name, 
     240                const QString& repl, int* offset) 
     241{ 
     242        QString res=str; 
    216243        QRegExp exp; 
    217244        exp.setMinimal(false); 
    218245        exp.setCaseSensitivity(Qt::CaseInsensitive); 
    219         int idx=1; 
    220         int parserIdx=parser.getCurrentIndex(); 
     246        exp.setPattern(QString("[^\\\\]\\%(\\[[^\\]]*\\]|)")+name); 
     247 
     248        int ps=0; 
     249        if (offset) 
     250                ps=*offset; 
     251 
    221252        while (1) 
    222253        { 
    223                 bool wasRepl=false; 
    224                 int offset=0; 
    225                 exp.setPattern(QString("[^\\\\]\\%")+QString::number(idx)); 
    226                 QString subStr=parser.nextToken(); 
    227                 while (1) 
    228                 { 
    229                         int ps=exp.indexIn(res, offset); 
    230                         if (ps<0) 
    231                                 break; 
    232                         res.remove(ps+1, exp.matchedLength()-1); 
    233                         res.insert(ps+1, subStr); 
    234                         wasRepl=1; 
    235                         offset=ps+subStr.length(); 
    236                 } 
    237                 if (!wasRepl) 
    238                         break; 
    239                 idx++; 
    240         } 
    241         parser.setCurrentIndex(parserIdx); 
    242         exp.setPattern(QString("[^\\\\]\\%\\*")); 
    243         int offset=0; 
    244         QString subStr=parser.joinBody(); 
    245          
    246         while (1) 
    247         { 
    248                 int ps=exp.indexIn(res, offset); 
    249                 if (ps<0) 
    250                         break; 
    251                 res.remove(ps+1, exp.matchedLength()-1); 
    252                 res.insert(ps+1, subStr); 
    253                 offset=ps+subStr.length(); 
    254         } 
    255         return res.trimmed(); 
    256 } 
     254                int foundPos=exp.indexIn(res, ps); 
     255                if (foundPos<0) 
     256                        break; 
     257                QStringList capturedList=exp.capturedTexts(); 
     258                QString curRepl=repl; 
     259                if (capturedList.size()==2 && !capturedList[1].isEmpty()) 
     260                { 
     261                        QString flags=capturedList[1]; 
     262                        flags.remove(0, 1); 
     263                        flags.remove(flags.length()-1, 1); 
     264                        curRepl=transform(repl, flags); 
     265                } 
     266                res.remove(foundPos+1, exp.matchedLength()-1); 
     267                res.insert(foundPos+1, curRepl); 
     268                ps=foundPos+curRepl.length(); 
     269        } 
     270        if (offset) 
     271                *offset=ps; 
     272        return res; 
     273} 
     274 
     275QString AliasPlugin::transform(const QString& str, const QString& flagsTmp) 
     276{ 
     277        QString res=str; 
     278        QStringList flagsList=flagsTmp.toLower().split(','); 
     279        for (QStringList::iterator it=flagsList.begin(); it!=flagsList.end(); ++it) 
     280        { 
     281                QString flag=(*it); 
     282                if (flag=="url") 
     283                        res=urlEncode(res, "UTF-8"); 
     284                else if (flag.startsWith("url:")) 
     285                { 
     286                        QString enc=flag.section(':', 1); 
     287                        res=urlEncode(res, enc); 
     288                } 
     289                else if (flag=="lower") 
     290                        res=res.toLower(); 
     291                else if (flag=="upper") 
     292                        res=res.toUpper(); 
     293                else if (flag=="rev" || flag=="reverse") 
     294                { 
     295                        QString tmp; 
     296                        int l=res.length(); 
     297                        for (int i=l-1; i>=0; --i) 
     298                                tmp+=res[i]; 
     299                        res=tmp; 
     300                } 
     301                else if (flag.startsWith("enc:")) 
     302                { 
     303                        QString enc=flag.section(':', 1); 
     304                        QTextCodec* codec=QTextCodec::codecForName(enc.toUtf8()); 
     305                        if (codec) 
     306                        { 
     307                                res=codec->fromUnicode(res); 
     308                        } 
     309                        else 
     310                        { 
     311                                qDebug() << "No codec found for " << enc; 
     312                        } 
     313                } 
     314                else if (flag.startsWith("enc2:")) 
     315                { 
     316                        QString enc1=flag.section(':', 1, 1); 
     317                        QString enc2=flag.section(':', 2, 2); 
     318                        QTextCodec* codec1=QTextCodec::codecForName(enc1.toUtf8()); 
     319                        QTextCodec* codec2=QTextCodec::codecForName(enc2.toUtf8()); 
     320                        if (codec1 && codec2) 
     321                        { 
     322                                QByteArray arr=codec1->fromUnicode(res); 
     323                                res=codec2->toUnicode(arr); 
     324                        } 
     325                } 
     326                else if (flag=="blond") 
     327                { 
     328                        QString tmp; 
     329                        int l=res.length(); 
     330                        for (int i=0; i<l; ++i) 
     331                        { 
     332                                QChar ch=res[i]; 
     333                                if (i%2==0) 
     334                                        ch=ch.toUpper(); 
     335                                else 
     336                                        ch=ch.toLower(); 
     337                                tmp+=ch; 
     338                        } 
     339                        res=tmp; 
     340                } 
     341                else if (flag.startsWith("repl:")) 
     342                { 
     343                        QString orig=flag.section(':', 1, 1); 
     344                        QString repl=flag.section(':', 2, 2); 
     345                        res.replace(orig, repl); 
     346                } 
     347        } 
     348        return res; 
     349} 
  • src/plugins/alias/aliasplugin.h

    r153 r281  
    2626private: 
    2727        AliasList aliases; 
     28        QString replacePattern(const QString& str, const QString& name, const QString& repl, int* offset); 
    2829        QString expandAlias(const QString&alias, MessageParser parser); 
     30        QString transform(const QString& str, const QString& flags); 
    2931}; 
    3032 
  • src/plugins/net/netplugin.cpp

    r145 r281  
    1717                : BasePlugin(parent) 
    1818{ 
    19         commands << "PING" << "TRACEROUTE" << "WWW" << "XEP" << "GOOGLE" << "SVN" << "HEADERS"; 
     19        commands << "PING" << "TRACEROUTE" << "WWW" << "POST" << "XEP" << "GOOGLE" << "SVN" << "HEADERS"; 
    2020} 
    2121 
     
    6868        } 
    6969 
    70         if (cmd=="WWW" || cmd=="HEADERS") 
     70        if (cmd=="WWW" || cmd=="POST" || cmd=="HEADERS") 
    7171        { 
    7272                if (arg.isEmpty()) 
  • src/plugins/net/wwwrequest.cpp

    r180 r281  
    3232{ 
    3333        QMutexLocker locker(&deleteMutex); 
    34  
    35          
    3634        if (myDest.toUpper().startsWith("EXP")) 
    3735        { 
     
    5553                qDebug() << "|| exp=" << myExp << "  || dest=" << myDest; 
    5654        } 
    57  
    5855        QRegExp exp(myExp); 
     56         
     57        QStringList postList;    
     58        if (myCmd=="POST") 
     59        { 
     60                QString tmp=myDest; 
     61                myDest=tmp.section('\n',0,0); 
     62                postList.append(tmp.section('\n',1).replace("\n","%0D%0A")); 
     63        } 
    5964 
    6065        DirectProxy proxy(0,0,""); 
     
    6974        if (myDest.indexOf("://")<0) 
    7075                myDest="http://"+myDest; 
    71         QString res=proxy.fetch(myDest,referer,&cookies,0); 
     76         
     77        QString res; 
     78        if (postList.isEmpty()) 
     79                res=proxy.fetch(myDest,referer,&cookies,0); 
     80        else 
     81                res=proxy.fetch(myDest, referer, &cookies, &postList); 
     82         
    7283        if (proxy.headersOnly) 
    7384        { 
     
    150161                for (int i=0; i<list.count(); ++i) 
    151162                { 
    152                         QString line=removeHtml(list[i]).trimmed(); 
     163                        QString line=removeHtml(list[i]); 
     164                        if (!line.isEmpty()) 
     165                                line=line.trimmed(); 
    153166                        if (!line.isEmpty()) 
    154167                        {