// Ryzom - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . #include "stdpch.h" #include "nel/gui/group_html.h" using namespace NLMISC; namespace NLGUI { /// the cookie value for session identification (nel cookie) std::string CurrentCookie; /// store all cookies we receive and resent them depending of the domain std::map > HTTPCookies; std::string HTTPCurrentDomain; // The current domain that will be used to get which cookies to send // *************************************************************************** // Some DTD table // Here, modify the DTD table to change the HTML parser (add new tags for examples) #undef HTML_ATTR #define HTML_ATTR(a,b) { (char*) #b } HTAttr a_attr[] = { HTML_ATTR(A,ACCESSKEY), HTML_ATTR(A,CHARSET), HTML_ATTR(A,CLASS), HTML_ATTR(A,COORDS), HTML_ATTR(A,DIR), HTML_ATTR(A,HREF), HTML_ATTR(A,HREFLANG), HTML_ATTR(A,ID), HTML_ATTR(A,NAME), HTML_ATTR(A,REL), HTML_ATTR(A,REV), HTML_ATTR(A,SHAPE), HTML_ATTR(A,STYLE), HTML_ATTR(A,TABINDEX), HTML_ATTR(A,TARGET), HTML_ATTR(A,TYPE), HTML_ATTR(A,TITLE), HTML_ATTR(A,Z_ACTION_CATEGORY), HTML_ATTR(A,Z_ACTION_PARAMS), HTML_ATTR(A,Z_ACTION_SHORTCUT), { 0 } }; HTAttr table_attr[] = { HTML_ATTR(TABLE,ALIGN), HTML_ATTR(TABLE,BGCOLOR), HTML_ATTR(TABLE,BORDER), HTML_ATTR(TABLE,BORDERCOLOR), HTML_ATTR(TABLE,CELLPADDING), HTML_ATTR(TABLE,CELLSPACING), HTML_ATTR(TABLE,CLASS), HTML_ATTR(TABLE,DIR), HTML_ATTR(TABLE,FRAME), HTML_ATTR(TABLE,ID), HTML_ATTR(TABLE,L_MARGIN), HTML_ATTR(TABLE,LANG), HTML_ATTR(TABLE,NOWRAP), HTML_ATTR(TABLE,RULES), HTML_ATTR(TABLE,SUMMARY), HTML_ATTR(TABLE,STYLE), HTML_ATTR(TABLE,TITLE), HTML_ATTR(TABLE,VALIGN), HTML_ATTR(TABLE,WIDTH), { 0 } }; HTAttr tr_attr[] = { HTML_ATTR(TR,ALIGN), HTML_ATTR(TR,BGCOLOR), HTML_ATTR(TR,L_MARGIN), HTML_ATTR(TR,NOWRAP), HTML_ATTR(TR,VALIGN), { 0 } }; HTAttr td_attr[] = { HTML_ATTR(TD,ABBR), HTML_ATTR(TD,ALIGN), HTML_ATTR(TD,AXIS), HTML_ATTR(TD,BGCOLOR), HTML_ATTR(TD,CHAR), HTML_ATTR(TD,CHAROFF), HTML_ATTR(TD,CLASS), HTML_ATTR(TD,COLSPAN), HTML_ATTR(TD,DIR), HTML_ATTR(TD,ID), HTML_ATTR(TD,HEADERS), HTML_ATTR(TD,HEIGHT), HTML_ATTR(TD,L_MARGIN), HTML_ATTR(TD,LANG), HTML_ATTR(TD,NOWRAP), HTML_ATTR(TD,ROWSPAN), HTML_ATTR(TD,SCOPE), HTML_ATTR(TD,STYLE), HTML_ATTR(TD,TITLE), HTML_ATTR(TD,VALIGN), HTML_ATTR(TD,WIDTH), { 0 } }; HTAttr img_attr[] = { HTML_ATTR(IMG,ALIGN), HTML_ATTR(IMG,ALT), HTML_ATTR(IMG,BORDER), HTML_ATTR(IMG,CLASS), HTML_ATTR(IMG,DIR), HTML_ATTR(IMG,GLOBAL_COLOR), HTML_ATTR(IMG,HEIGHT), HTML_ATTR(IMG,HSPACE), HTML_ATTR(IMG,ID), HTML_ATTR(IMG,ISMAP), HTML_ATTR(IMG,LANG), HTML_ATTR(IMG,LONGDESC), HTML_ATTR(IMG,SRC), HTML_ATTR(IMG,STYLE), HTML_ATTR(IMG,TITLE), HTML_ATTR(IMG,USEMAP), HTML_ATTR(IMG,VSPACE), HTML_ATTR(IMG,WIDTH), { 0 } }; HTAttr input_attr[] = { HTML_ATTR(INPUT,ACCEPT), HTML_ATTR(INPUT,ACCESSKEY), HTML_ATTR(INPUT,ALIGN), HTML_ATTR(INPUT,ALT), HTML_ATTR(INPUT,CHECKED), HTML_ATTR(INPUT,CLASS), HTML_ATTR(INPUT,DIR), HTML_ATTR(INPUT,DISABLED), HTML_ATTR(INPUT,GLOBAL_COLOR), HTML_ATTR(INPUT,ID), HTML_ATTR(INPUT,LANG), HTML_ATTR(INPUT,MAXLENGTH), HTML_ATTR(INPUT,NAME), HTML_ATTR(INPUT,READONLY), HTML_ATTR(INPUT,SIZE), HTML_ATTR(INPUT,SRC), HTML_ATTR(INPUT,STYLE), HTML_ATTR(INPUT,TABINDEX), HTML_ATTR(INPUT,TITLE), HTML_ATTR(INPUT,TYPE), HTML_ATTR(INPUT,USEMAP), HTML_ATTR(INPUT,VALUE), HTML_ATTR(INPUT,Z_BTN_TMPL), HTML_ATTR(INPUT,Z_INPUT_TMPL), HTML_ATTR(INPUT,Z_INPUT_WIDTH), { 0 } }; HTAttr textarea_attr[] = { HTML_ATTR(TEXTAREA,CLASS), HTML_ATTR(TEXTAREA,COLS), HTML_ATTR(TEXTAREA,DIR), HTML_ATTR(TEXTAREA,DISABLED), HTML_ATTR(TEXTAREA,ID), HTML_ATTR(TEXTAREA,LANG), HTML_ATTR(TEXTAREA,MAXLENGTH), HTML_ATTR(TEXTAREA,NAME), HTML_ATTR(TEXTAREA,READONLY), HTML_ATTR(TEXTAREA,ROWS), HTML_ATTR(TEXTAREA,STYLE), HTML_ATTR(TEXTAREA,TABINDEX), HTML_ATTR(TEXTAREA,TITLE), HTML_ATTR(TEXTAREA,Z_INPUT_TMPL), { 0 } }; HTAttr p_attr[] = { HTML_ATTR(P,QUICK_HELP_CONDITION), HTML_ATTR(P,QUICK_HELP_EVENTS), HTML_ATTR(P,QUICK_HELP_LINK), HTML_ATTR(P,NAME), { 0 } }; HTAttr div_attr[] = { HTML_ATTR(DIV,CLASS), HTML_ATTR(DIV,ID), HTML_ATTR(DIV,NAME), HTML_ATTR(DIV,STYLE), { 0 } }; HTAttr span_attr[] = { HTML_ATTR(SPAN,CLASS), HTML_ATTR(SPAN,ID), HTML_ATTR(SPAN,STYLE), { 0 } }; // *************************************************************************** // Read a width HTML parameter. "100" or "100%". Returns true if percent (0 ~ 1) else false bool getPercentage (sint32 &width, float &percent, const char *str) { // Percent ? const char *percentChar; if ((percentChar = strchr (str, '%')) != NULL) { std::string toto = str; toto = toto.substr (0, percentChar - str); fromString(toto, percent); percent /= 100.f; return true; } else { fromString(str, width); return false; } } // *************************************************************************** CRGBA getColor (const char *color) { if (strlen (color) != 7 && strlen (color) != 9 ) return CRGBA::White; char tmp[3] = {0,0,0}; CRGBA dst; int value; tmp[0] = color[1]; tmp[1] = color[2]; sscanf (tmp, "%x", &value); dst.R = uint8(value); tmp[0] = color[3]; tmp[1] = color[4]; sscanf (tmp, "%x", &value); dst.G = uint8(value); tmp[0] = color[5]; tmp[1] = color[6]; sscanf (tmp, "%x", &value); dst.B = uint8(value); if (strlen (color) == 9) { tmp[0] = color[7]; tmp[1] = color[8]; sscanf (tmp, "%x", &value); dst.A = uint8(value); } else { // extension to html ; try to parse an additional alpha dst.A = 255; } return dst; } void initLibWWW() { static bool initialized = false; if (!initialized) { // Change the HTML DTD SGML_dtd *HTML_DTD = HTML_dtd (); HTML_DTD->tags[HTML_TABLE].attributes = table_attr; HTML_DTD->tags[HTML_TABLE].number_of_attributes = sizeof(table_attr) / sizeof(HTAttr) - 1; HTML_DTD->tags[HTML_TR].attributes = tr_attr; HTML_DTD->tags[HTML_TR].number_of_attributes = sizeof(tr_attr) / sizeof(HTAttr) - 1; HTML_DTD->tags[HTML_TD].attributes = td_attr; HTML_DTD->tags[HTML_TD].number_of_attributes = sizeof(td_attr) / sizeof(HTAttr) - 1; HTML_DTD->tags[HTML_IMG].attributes = img_attr; HTML_DTD->tags[HTML_IMG].number_of_attributes = sizeof(img_attr) / sizeof(HTAttr) - 1; HTML_DTD->tags[HTML_INPUT].attributes = input_attr; HTML_DTD->tags[HTML_INPUT].number_of_attributes = sizeof(input_attr) / sizeof(HTAttr) - 1; HTML_DTD->tags[HTML_TEXTAREA].attributes = textarea_attr; HTML_DTD->tags[HTML_TEXTAREA].number_of_attributes = sizeof(textarea_attr) / sizeof(HTAttr) - 1; HTML_DTD->tags[HTML_P].attributes = p_attr; HTML_DTD->tags[HTML_P].number_of_attributes = sizeof(p_attr) / sizeof(HTAttr) - 1; HTML_DTD->tags[HTML_A].attributes = a_attr; HTML_DTD->tags[HTML_A].number_of_attributes = sizeof(a_attr) / sizeof(HTAttr) - 1; //HTML_DTD->tags[HTML_I].attributes = a_attr; HTML_DTD->tags[HTML_I].number_of_attributes = 0; HTML_DTD->tags[HTML_DIV].attributes = div_attr; HTML_DTD->tags[HTML_DIV].number_of_attributes = sizeof(div_attr) / sizeof(HTAttr) - 1; HTML_DTD->tags[HTML_SPAN].attributes = span_attr; HTML_DTD->tags[HTML_SPAN].number_of_attributes = sizeof(span_attr) / sizeof(HTAttr) - 1; // Initialized initialized = true; } } // *************************************************************************** }