diff -ruN 1.7.41_20/Makefile 1.7.41_21/Makefile --- 1.7.41_20/Makefile 2013-03-19 02:56:41.000000000 +0100 +++ 1.7.41_21/Makefile 2013-03-19 02:57:43.000000000 +0100 @@ -75,6 +75,7 @@ OBJS += vdrttxtsubshooks.o OBJS += iconpatch.o +OBJS += tinystr.o tinyxml.o tinyxmlerror.o tinyxmlparser.o submenu.o DEFINES += $(CDEFINES) INCLUDES += $(CINCLUDES) diff -ur vdr-1.7.37/device.c vdr-1.7.37/device.c --- vdr-1.7.41/device.c 2012-11-19 10:59:09.000000000 +0100 +++ vdr-1.7.41/device.c 2012-12-10 10:14:03.106016736 +0100 @@ -723,6 +723,7 @@ cChannel *channel; while ((channel = Channels.GetByNumber(n, Direction)) != NULL) { // try only channels which are currently available + if (!cStatus::MsgChannelProtected(0, channel)) // PIN PATCH if (GetDevice(channel, LIVEPRIORITY, true, true)) break; n = channel->Number() + Direction; @@ -744,6 +745,12 @@ eSetChannelResult cDevice::SetChannel(const cChannel *Channel, bool LiveView) { + // I hope 'LiveView = false' indicates a channel switch for recording, // PIN PATCH + // I really don't know, but it works ... // PIN PATCH + + if (LiveView && cStatus::MsgChannelProtected(this, Channel)) // PIN PATCH + return scrNotAvailable; // PIN PATCH + cStatus::MsgChannelSwitch(this, 0, LiveView); if (LiveView) { diff -ruN 1.7.41_20/menu.c 1.7.41_21/menu.c --- 1.7.41_20/menu.c 2013-03-19 02:56:41.000000000 +0100 +++ 1.7.41_21/menu.c 2013-03-19 21:19:43.000000000 +0100 @@ -910,6 +910,15 @@ Add(new cMenuEditBitItem( tr("VPS"), &data.flags, tfVps)); Add(new cMenuEditIntItem( tr("Priority"), &data.priority, 0, MAXPRIORITY)); Add(new cMenuEditIntItem( tr("Lifetime"), &data.lifetime, 0, MAXLIFETIME)); + if (cOsd::pinValid || !data.fskProtection) Add(new cMenuEditBoolItem(tr("Childlock"),&data.fskProtection)); + else { + char* buf = 0; + int res = 0; + res = asprintf(&buf, "%s\t%s", tr("Childlock"), data.fskProtection ? tr("yes") : tr("no")); + if (res < 0) ; // memory problems :o + Add(new cOsdItem(buf)); + free(buf); + } Add(file = new cMenuEditStrItem( tr("File"), data.file, sizeof(data.file))); SetFirstDayItem(); } @@ -2507,7 +2516,8 @@ } } } - if (*Item->Text() && !LastDir) { + if (*Item->Text() && !LastDir + && (!cStatus::MsgReplayProtected(Item->Recording(), Item->Name(), base, Item->IsDirectory(), true))) { // PIN PATCH Add(Item); LastItem = Item; if (Item->IsDirectory()) @@ -2558,6 +2568,9 @@ { cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current()); if (ri) { + if (cStatus::MsgReplayProtected(ri->Recording(), ri->Name(), base, + ri->IsDirectory()) == true) // PIN PATCH + return osContinue; // PIN PATCH if (ri->IsDirectory()) Open(); else { @@ -3602,6 +3615,12 @@ cMenuMain::cMenuMain(eOSState State) :cOsdMenu("") { + // Load Menu Configuration + cString menuXML = cString::sprintf("%s/setup/vdr-menu.%s.xml", cPlugin::ConfigDirectory(), Setup.OSDLanguage); + if (access(menuXML, 04) == -1) + menuXML = cString::sprintf("%s/setup/vdr-menu.xml", cPlugin::ConfigDirectory()); + subMenu.LoadXml(menuXML); + nrDynamicMenuEntries = 0; SetMenuCategory(mcMain); replaying = false; stopReplayItem = NULL; @@ -3647,37 +3666,60 @@ return o; } -void cMenuMain::Set(void) +void cMenuMain::Set(int current) { Clear(); SetTitle("VDR"); SetHasHotkeys(); - // Basic menu items: - - Add(new cOsdItem(hk(tr("Schedule")), osSchedule)); - Add(new cOsdItem(hk(tr("Channels")), osChannels)); - Add(new cOsdItem(hk(tr("Timers")), osTimers)); - Add(new cOsdItem(hk(tr("Recordings")), osRecordings)); - - // Plugins: + stopReplayItem = NULL; + cancelEditingItem = NULL; + stopRecordingItem = NULL; - for (int i = 0; ; i++) { - cPlugin *p = cPluginManager::GetPlugin(i); - if (p) { - const char *item = p->MainMenuEntry(); - if (item) - Add(new cMenuPluginItem(hk(item), i)); + // remember initial dynamic MenuEntries added + nrDynamicMenuEntries = Count(); + for (cSubMenuNode *node = subMenu.GetMenuTree()->First(); node; node = subMenu.GetMenuTree()->Next(node)) { + cSubMenuNode::Type type = node->GetType(); + if (type==cSubMenuNode::PLUGIN) { + const char *item = node->GetPluginMainMenuEntry(); + if (item && !cStatus::MsgPluginProtected(cPluginManager::GetPlugin(node->GetPluginIndex()), true)) + Add(new cMenuPluginItem(hk(item), node->GetPluginIndex())); } - else - break; - } - - // More basic menu items: - - Add(new cOsdItem(hk(tr("Setup")), osSetup)); - if (Commands.Count()) - Add(new cOsdItem(hk(tr("Commands")), osCommands)); + else if (type==cSubMenuNode::MENU) { + cString item = cString::sprintf("%s%s", node->GetName(), *subMenu.GetMenuSuffix()); + if (!cStatus::MsgMenuItemProtected(item, true)) + Add(new cOsdItem(hk(item), osUnknown, node)); + } + else if ((type==cSubMenuNode::COMMAND) || (type==cSubMenuNode::THREAD)) { + if (!cStatus::MsgMenuItemProtected(node->GetName(), true)) + Add(new cOsdItem(hk(node->GetName()), osUnknown, node)); + } + else if (type==cSubMenuNode::SYSTEM) { + const char *item = node->GetName(); + if (cStatus::MsgMenuItemProtected(item, true)) + ; // nothing to do ;) + else + if (strcmp(item, "Schedule") == 0) + Add(new cOsdItem(hk(tr("Schedule")), osSchedule)); + else if (strcmp(item, "Channels") == 0) + Add(new cOsdItem(hk(tr("Channels")), osChannels)); + else if (strcmp(item, "Timers") == 0) + Add(new cOsdItem(hk(tr("Timers")), osTimers)); + else if (strcmp(item, "Recordings") == 0) + Add(new cOsdItem(hk(tr("Recordings")), osRecordings)); + else if (strcmp(item, "Setup") == 0) { + cString itemSetup = cString::sprintf("%s%s", tr("Setup"), *subMenu.GetMenuSuffix()); + Add(new cOsdItem(hk(itemSetup), osSetup)); + } + else if (strcmp(item, "Commands") == 0 && Commands.Count() > 0) { + cString itemCommands = cString::sprintf("%s%s", tr("Commands"), *subMenu.GetMenuSuffix()); + Add(new cOsdItem(hk(itemCommands), osCommands)); + } + } + } + if (current >=0 && currentIndex(); + return result; } @@ -3758,6 +3815,12 @@ eOSState state = cOsdMenu::ProcessKey(Key); HadSubMenu |= HasSubMenu(); + cOsdItem* item = Get(Current()); + + if (item && item->Text() && state != osContinue && state != osUnknown && state != osBack) + if (cStatus::MsgMenuItemProtected(item->Text())) + return osContinue; + cOsdObject *menu = NULL; switch (state) { case osSchedule: @@ -3810,6 +3873,7 @@ if (item) { cPlugin *p = cPluginManager::GetPlugin(item->PluginIndex()); if (p) { + if (!cStatus::MsgPluginProtected(p)) { // PIN PATCH cOsdObject *menu = p->MainMenuAction(); if (menu) { if (menu->IsMenu()) @@ -3820,10 +3884,21 @@ } } } + } } state = osEnd; } break; + case osBack: { + int newCurrent = 0; + if (subMenu.Up(&newCurrent)) { + Set(newCurrent); + return osContinue; + } + else + return osEnd; + } + break; default: switch (Key) { case kRecord: case kRed: if (!HadSubMenu) @@ -3840,6 +3915,50 @@ case kBlue: if (!HadSubMenu) state = replaying ? osStopReplay : cReplayControl::LastReplayed() ? osReplay : osRecordings; break; + case kOk: if (state == osUnknown) { + cString buffer; + int index = Current()-nrDynamicMenuEntries; + cSubMenuNode *node = subMenu.GetNode(index); + + if (node != NULL) { + if (node->GetType() == cSubMenuNode::MENU) { + subMenu.Down(node, Current()); + } + else if (node->GetType() == cSubMenuNode::COMMAND) { + bool confirmed = true; + if (node->CommandConfirm()) { + buffer = cString::sprintf("%s?", node->GetName()); + confirmed = Interface->Confirm(buffer); + } + if (confirmed) { + const char *Result = subMenu.ExecuteCommand(node->GetCommand()); + if (Result) + return AddSubMenu(new cMenuText(node->GetName(), Result, fontFix)); + return osEnd; + } + } + else if (node->GetType() == cSubMenuNode::THREAD) { + bool confirmed = true; + if (node->CommandConfirm()) { + buffer = cString::sprintf("%s?", node->GetName()); + confirmed = Interface->Confirm(buffer); + } + if (confirmed) { + buffer = cString::sprintf("%s", node->GetCommand()); + cExecCmdThread *execcmd = new cExecCmdThread(node->GetCommand()); + if (execcmd->Start()) + dsyslog("executing command '%s'", *buffer); + else + esyslog("ERROR: can't execute command '%s'", *buffer); + return osEnd; + } + } + } + + Set(); + return osContinue; + } + break; default: break; } } @@ -3995,6 +4114,7 @@ if (Direction) { while (Channel) { Channel = Direction > 0 ? Channels.Next(Channel) : Channels.Prev(Channel); + if (!cStatus::MsgChannelProtected(0, Channel)) if (!Channel && Setup.ChannelsWrap) Channel = Direction > 0 ? Channels.First() : Channels.Last(); if (Channel && !Channel->GroupSep() && cDevice::GetDevice(Channel, LIVEPRIORITY, true, true)) @@ -4697,6 +4817,7 @@ for (int i = 0; i < MAXRECORDCONTROLS; i++) { if (!RecordControls[i]) { RecordControls[i] = new cRecordControl(device, Timer, Pause); + cStatus::MsgRecordingFile(RecordControls[i]->FileName()); // PIN PATCH return RecordControls[i]->Process(time(NULL)); } } diff -ruN 1.7.41_20/menu.h 1.7.41_21/menu.h --- 1.7.41_20/menu.h 2013-03-19 02:56:41.000000000 +0100 +++ 1.7.41_21/menu.h 2013-03-19 21:05:47.000000000 +0100 @@ -18,6 +18,7 @@ #include "menuitems.h" #include "recorder.h" #include "skins.h" +#include "submenu.h" class cMenuText : public cOsdMenu { private: @@ -102,6 +103,7 @@ class cMenuMain : public cOsdMenu { private: + int nrDynamicMenuEntries; bool replaying; cOsdItem *stopReplayItem; cOsdItem *cancelEditingItem; @@ -109,8 +111,9 @@ cOsdItem *stopRecordingItem; int recordControlsState; static cOsdObject *pluginOsdObject; - void Set(void); + void Set(int current=0); bool Update(bool Force = false); + cSubMenu subMenu; public: cMenuMain(eOSState State = osUnknown); virtual eOSState ProcessKey(eKeys Key); diff -ruN 1.7.41_20/osdbase.c 1.7.41_21/osdbase.c --- 1.7.41_20/osdbase.c 2013-03-19 02:56:41.000000000 +0100 +++ 1.7.41_21/osdbase.c 2013-03-19 21:20:43.000000000 +0100 @@ -23,6 +23,7 @@ state = State; selectable = true; fresh = true; + subMenu = 0; } cOsdItem::cOsdItem(const char *Text, eOSState State, bool Selectable) @@ -32,6 +33,17 @@ selectable = Selectable; fresh = true; SetText(Text); + subMenu = 0; +} + +cOsdItem::cOsdItem(const char *Text, eOSState State, cSubMenuNode* SubMenu) +{ + text = NULL; + state = State; + selectable = true; + fresh = true; + SetText(Text); + subMenu = SubMenu; } cOsdItem::~cOsdItem() diff -ruN 1.7.41_20/osdbase.h 1.7.41_21/osdbase.h --- 1.7.41_20/osdbase.h 2013-03-19 02:56:41.000000000 +0100 +++ 1.7.41_21/osdbase.h 2013-03-19 21:21:16.000000000 +0100 @@ -14,6 +14,7 @@ #include "osd.h" #include "skins.h" #include "tools.h" +#include "submenu.h" enum eOSState { osUnknown, osContinue, @@ -52,16 +53,20 @@ char *text; eOSState state; bool selectable; + cSubMenuNode* subMenu; protected: bool fresh; public: cOsdItem(eOSState State = osUnknown); cOsdItem(const char *Text, eOSState State = osUnknown, bool Selectable = true); + cOsdItem(const char *Text, eOSState State, cSubMenuNode* SubMenu); virtual ~cOsdItem(); bool Selectable(void) const { return selectable; } void SetText(const char *Text, bool Copy = true); void SetSelectable(bool Selectable); void SetFresh(bool Fresh); + void SetSubMenu(cSubMenuNode* SubMenu) { subMenu = SubMenu; } + cSubMenuNode* SubMenu() { return subMenu; } const char *Text(void) const { return text; } virtual void Set(void) {} virtual void SetMenuItem(cSkinDisplayMenu *DisplayMenu, int Index, bool Current, bool Selectable); diff -ruN 1.7.41_20/osd.c 1.7.41_21/osd.c --- 1.7.41_20/osd.c 2013-03-19 02:56:41.000000000 +0100 +++ 1.7.41_21/osd.c 2013-03-19 21:21:52.000000000 +0100 @@ -1623,6 +1623,8 @@ int cOsd::osdHeight = 0; cVector cOsd::Osds; cMutex cOsd::mutex; +bool cOsd::pinValid = false; + cOsd::cOsd(int Left, int Top, uint Level) { diff -ruN 1.7.41_20/osd.h 1.7.41_21/osd.h --- 1.7.41_20/osd.h 2013-03-19 02:56:41.000000000 +0100 +++ 1.7.41_21/osd.h 2013-03-19 21:07:04.000000000 +0100 @@ -926,6 +926,7 @@ ///< MyOsdDrawPixmap(Left() + pm->ViewPort().X(), Top() + pm->ViewPort().Y(), pm->Data(), w, h, h * d); ///< delete pm; ///< } + static bool pinValid; }; #define MAXOSDIMAGES 64 diff -ruN 1.7.41_20/status.c 1.7.41_21/status.c --- 1.7.41_20/status.c 2013-03-19 02:56:41.000000000 +0100 +++ 1.7.41_21/status.c 2013-03-19 21:22:43.000000000 +0100 @@ -153,3 +153,55 @@ for (cStatus *sm = statusMonitors.First(); sm; sm = statusMonitors.Next(sm)) sm->OsdEventItem(Event, Text, Index, Count); } + +bool cStatus::MsgChannelProtected(const cDevice* Device, const cChannel* Channel) // PIN PATCH +{ + for (cStatus *sm = statusMonitors.First(); sm; sm = statusMonitors.Next(sm)) + if (sm->ChannelProtected(Device, Channel) == true) + return true; + + return false; +} + +bool cStatus::MsgReplayProtected(const cRecording* Recording, const char* Name, + const char* Base, bool isDirectory, int menuView) // PIN PATCH +{ + for (cStatus *sm = statusMonitors.First(); sm; sm = statusMonitors.Next(sm)) + if (sm->ReplayProtected(Recording, Name, Base, isDirectory, menuView) == true) + return true; + return false; +} + +void cStatus::MsgRecordingFile(const char* FileName) +{ + for (cStatus *sm = statusMonitors.First(); sm; sm = statusMonitors.Next(sm)) // PIN PATCH + sm->RecordingFile(FileName); +} + +void cStatus::MsgTimerCreation(cTimer* Timer, const cEvent *Event) +{ + for (cStatus *sm = statusMonitors.First(); sm; sm = statusMonitors.Next(sm)) // PIN PATCH + sm->TimerCreation(Timer, Event); +} + +bool cStatus::MsgPluginProtected(cPlugin* Plugin, int menuView) // PIN PATCH +{ + for (cStatus *sm = statusMonitors.First(); sm; sm = statusMonitors.Next(sm)) + if (sm->PluginProtected(Plugin, menuView) == true) + return true; + return false; +} + +void cStatus::MsgUserAction(const eKeys key, const cOsdObject* Interact) // PIN PATCH +{ + for (cStatus *sm = statusMonitors.First(); sm; sm = statusMonitors.Next(sm)) + sm->UserAction(key, Interact); +} + +bool cStatus::MsgMenuItemProtected(const char* Name, int menuView) // PIN PATCH +{ + for (cStatus *sm = statusMonitors.First(); sm; sm = statusMonitors.Next(sm)) + if (sm->MenuItemProtected(Name, menuView) == true) + return true; + return false; +} diff -ruN 1.7.41_20/status.h 1.7.41_21/status.h --- 1.7.41_20/status.h 2013-03-19 02:56:41.000000000 +0100 +++ 1.7.41_21/status.h 2013-03-19 21:10:19.000000000 +0100 @@ -14,6 +14,7 @@ #include "device.h" #include "player.h" #include "tools.h" +#include "plugin.h" enum eTimerChange { tcMod, tcAdd, tcDel }; @@ -91,6 +92,23 @@ // report menu destruvtion virtual void OsdEventItem(const cEvent* Event, const char *Text, int Index, int Count) {} // The OSD displays the given single line Event as menu item at Index. + virtual bool ChannelProtected(const cDevice *Device, const cChannel* Channel) { return false; } // PIN PATCH + // Checks if a channel is protected. + virtual bool ReplayProtected(const cRecording* Recording, const char* Name, + const char* Base, bool isDirectory, int menuView = false) { return false; } // PIN PATCH + // Checks if a recording is protected. + virtual void RecordingFile(const char* FileName) {} // PIN PATCH + // The given DVB device has started recording to FileName. FileName is the name of the + // recording directory + virtual void TimerCreation(cTimer* Timer, const cEvent *Event) {} // PIN PATCH + // The given timer is created + virtual bool PluginProtected(cPlugin* Plugin, int menuView = false) { return false; } // PIN PATCH + // Checks if a plugin is protected. + virtual void UserAction(const eKeys key, const cOsdObject* Interact) {} // PIN PATCH + // report user action + virtual bool MenuItemProtected(const char* Name, int menuView = false) { return false; } // PIN PATCH + // Checks if a menu entry is protected. + public: cStatus(void); @@ -118,6 +136,14 @@ static void MsgOsdMenuDisplay(const char* kind); static void MsgOsdMenuDestroy(); static void MsgOsdEventItem(const cEvent* Event, const char *Text, int Index, int Count); + static bool MsgChannelProtected(const cDevice* Device, const cChannel* Channel); // PIN PATCH + static bool MsgReplayProtected(const cRecording* Recording, const char* Name, + const char* Base, bool isDirectory, int menuView = false); // PIN PATCH + static void MsgRecordingFile(const char* FileName); // PIN PATCH + static void MsgTimerCreation(cTimer* Timer, const cEvent *Event); // PIN PATCH + static bool MsgPluginProtected(cPlugin* Plugin, int menuView = false); // PIN PATCH + static void MsgUserAction(const eKeys key, const cOsdObject* Interact); + static bool MsgMenuItemProtected(const char* Name, int menuView = false); // PIN PATCH }; #endif //__STATUS_H diff -ruN 1.7.41_20/submenu.c 1.7.41_21/submenu.c --- 1.7.41_20/submenu.c 1970-01-01 01:00:00.000000000 +0100 +++ 1.7.41_21/submenu.c 2013-03-19 21:24:09.000000000 +0100 @@ -0,0 +1,911 @@ +/**************************************************************************** + * DESCRIPTION: + * Submenu + * + * $Id: vdr-1.3.44-Setup-0.3.0.diff,v 1.1 2006/03/04 09:58:47 ralf Exp $ + * + * Contact: ranga@teddycats.de + * + * Copyright (C) 2004, 2005 by Ralf Dotzert + * + * modified for the VDR Extensions Patch by zulu @vdr-portal + ****************************************************************************/ + +#ifndef SUBMENU_H +#include "submenu.h" +#include "plugin.h" +#include "iconpatch.h" + +static const char* TAG_SYSTEM = "system"; +static const char* TAG_PLUGIN = "plugin"; +static const char* TAG_COMMAND = "command"; +static const char* TAG_THREAD = "thread"; +static const char* TAG_MENU = "menu"; +static const char* TAG_UNDEFINED = "undefined"; +static const char* TRUE_STR = "yes"; + + +//################################################################################ +//# SubMenuNode +//################################################################################ + +cSubMenuNode::cSubMenuNode(TiXmlElement *xml, int level, cSubMenuNodes *currentMenu, cSubMenuNodes *parentMenu) +{ + init(); + _parentMenu = parentMenu; + _currentMenu = currentMenu; + _level = level; + + if (xml != NULL && xml->Type() == TiXmlNode::ELEMENT) { + const char *tag = xml->Value(); + + if (cSubMenuNode::IsType(tag) != cSubMenuNode::UNDEFINED) { + SetType(tag); + SetName(xml->Attribute("name")); + if ((_type == COMMAND) || (_type == THREAD)) { + SetCommand(xml->Attribute("execute")); + const char *confirmStr = xml->Attribute("confirm"); + if (confirmStr != NULL && strcmp(confirmStr, TRUE_STR) == 0) + _commandConfirm = true; + } + else if (_type == PLUGIN) { // Add Plugin Index + SetCustomTitle(xml->Attribute("title")); + SetPlugin(); + } + else if (_type == MENU && xml->NoChildren() == false) { + xml = xml->FirstChildElement(); + do { + cSubMenuNode *node = new cSubMenuNode(xml, level+1, &_subMenus, currentMenu); + _subMenus.Add(node); + } while ((xml=xml->NextSiblingElement()) != NULL); + } + } + } + else + throw "Invalid XML Node"; +} + +/** + * Construct new Node empty Node + * + * + */ +cSubMenuNode::cSubMenuNode(cSubMenuNodes *currentMenu, cSubMenuNodes *parentMenu) +{ + init(); + _parentMenu = parentMenu; + _currentMenu = currentMenu; + +} + + +/** + * + */ +void cSubMenuNode::init() +{ + _name = NULL; + _command = NULL; + _title = NULL; + _pluginMainMenuEntry = NULL; + _type = UNDEFINED; + _level = 0; + _parentMenu = NULL; + _currentMenu = NULL; + _pluginIndex = 0; + _commandConfirm = false; +} + + +cSubMenuNode::~ cSubMenuNode() +{ + if (_name != NULL) + free((void*)_name); + if (_command != NULL) + free((void*)_command); + if (_title != NULL) + free((void*)_title); + if (_pluginMainMenuEntry != NULL) + free((void*)_pluginMainMenuEntry); +} + +/** + * + */ +void cSubMenuNode::SetPlugin() +{ + bool found = false; + for (int i = 0; ; i++) { + cPlugin *p = cPluginManager::GetPlugin(i); + if (p) { + if (strcmp(_name, p->Name()) == 0 && p->MainMenuEntry() != NULL) { + SetPluginMainMenuEntry(p->MainMenuEntry()); + _pluginIndex = i; + found = true; + break; + } + } + else + break; + } + + if (!found) + _type = UNDEFINED; +} + + +bool cSubMenuNode::SaveXml(TiXmlElement *root) +{ + bool ok = true; + + if (root!=NULL) { + TiXmlElement *e = NULL; + switch(_type) { + case SYSTEM: + e = new TiXmlElement(TAG_SYSTEM); + e->SetAttribute("name", GetName()); + break; + case COMMAND: + e = new TiXmlElement(TAG_COMMAND); + e->SetAttribute("name", GetName()); + e->SetAttribute("execute", GetCommand()); + if (_commandConfirm) + e->SetAttribute("confirm", TRUE_STR); + break; + case THREAD: + e = new TiXmlElement(TAG_THREAD); + e->SetAttribute("name", GetName()); + e->SetAttribute("execute", GetCommand()); + if (_commandConfirm) + e->SetAttribute("confirm", TRUE_STR); + break; + case PLUGIN: + e = new TiXmlElement(TAG_PLUGIN); + e->SetAttribute("name", GetName()); + if (GetCustomTitle() != NULL && strcmp(GetCustomTitle(), "") != 0) + e->SetAttribute("title", GetCustomTitle()); + break; + case MENU: + e = new TiXmlElement(TAG_MENU); + e->SetAttribute("name", GetName()); + break; + case UNDEFINED: + default: + ok = false; + break; + } + if (ok) { + root->LinkEndChild(e); + if (HasSubMenus()) + for (cSubMenuNode *node = _subMenus.First(); node; node = _subMenus.Next(node)) + node->SaveXml(e); + } + } + + return(ok); +} + + +cSubMenuNode::Type cSubMenuNode::IsType(const char *name) +{ + Type type = UNDEFINED; + + if (strcmp(name ,TAG_SYSTEM) == 0) + type = cSubMenuNode::SYSTEM; + else if (strcmp(name ,TAG_PLUGIN) == 0) + type = cSubMenuNode::PLUGIN; + else if (strcmp(name ,TAG_COMMAND) == 0) + type = cSubMenuNode::COMMAND; + else if (strcmp(name ,TAG_THREAD) == 0) + type = cSubMenuNode::THREAD; + else if (strcmp(name ,TAG_MENU) == 0) + type = cSubMenuNode::MENU; + + return(type); +} + +void cSubMenuNode::SetType(const char *name) +{ + _type = IsType(name); +} + +void cSubMenuNode::SetType(enum Type type) +{ + _type = type; +} + + +cSubMenuNode::Type cSubMenuNode::GetType() +{ + return(_type); +} + +const char *cSubMenuNode::GetTypeAsString() +{ + const char *str=NULL; + switch(_type) { + case SYSTEM: + str = TAG_SYSTEM; + break; + case COMMAND: + str = TAG_COMMAND; + break; + case THREAD: + str = TAG_THREAD; + break; + case PLUGIN: + str = TAG_PLUGIN; + break; + case MENU: + str = TAG_MENU; + break; + case UNDEFINED: + str = TAG_UNDEFINED; + default: + break; + } + + return(str); +} + +void cSubMenuNode::SetCommand(const char *command) +{ + if (_command != NULL) + free((void*)_command); + + if (command != NULL) + _command = strdup(command); + else + _command = NULL; +} + +const char *cSubMenuNode::GetCommand() +{ + return(_command); +} + +bool cSubMenuNode::CommandConfirm() +{ + return(_commandConfirm); +} + +void cSubMenuNode::SetCommandConfirm(int val) +{ + if (val == 1) + _commandConfirm = true; + else + _commandConfirm = false; +} + +void cSubMenuNode::SetCustomTitle(const char *title) +{ + if (_title != NULL) + free((void*)_title); + + if (title != NULL) + _title = strdup(title); + else + _title = NULL; +} + +const char *cSubMenuNode::GetCustomTitle() +{ + return(_title); +} + +void cSubMenuNode::SetName(const char *name) +{ + if (_name) + free ((void*)_name); + + if (name != NULL) + _name = strdup(name); + else + _name = NULL; +} + +const char *cSubMenuNode::GetName() +{ + return(_name); +} + +int cSubMenuNode::GetLevel() +{ + return(_level); +} + +void cSubMenuNode::SetLevel(int level) +{ + _level = level; + if (HasSubMenus()) { //Adjust Levels of Subnodes + for (cSubMenuNode *node = _subMenus.First(); node; node = _subMenus.Next(node)) + node->SetLevel(level+1); + } +} + +int cSubMenuNode::GetPluginIndex() +{ + return(_pluginIndex); +} + +void cSubMenuNode::SetPluginIndex(int index) +{ + _pluginIndex = index; +} + +void cSubMenuNode::SetPluginMainMenuEntry(const char *mainMenuEntry) +{ + if (_pluginMainMenuEntry != NULL) + free((void*)_pluginMainMenuEntry); + + if (_title != NULL && strcmp(_title, "") != 0) + _pluginMainMenuEntry = strdup(_title); + else if (mainMenuEntry != NULL) + _pluginMainMenuEntry = strdup(mainMenuEntry); + else + _pluginMainMenuEntry = NULL; +} + +const char *cSubMenuNode::GetPluginMainMenuEntry() +{ + return(_pluginMainMenuEntry); +} + + +cSubMenuNodes *cSubMenuNode::GetParentMenu() +{ + return(_parentMenu); +} + +void cSubMenuNode::SetParentMenu(cSubMenuNodes *parent) +{ + _parentMenu = parent; +} + +cSubMenuNodes *cSubMenuNode::GetCurrentMenu() +{ + return(_currentMenu); +} + +void cSubMenuNode::SetCurrentMenu(cSubMenuNodes *current) +{ + _currentMenu = current; +} + + +cSubMenuNodes *cSubMenuNode::GetSubMenus() +{ + return(&_subMenus); +} + +bool cSubMenuNode::HasSubMenus() +{ + if (_subMenus.Count() > 0) + return(true); + else + return(false); +} + + +void cSubMenuNode::Print(int index) +{ + for (int i = 0; i < index; i++) + printf(" "); + + printf("Name=%s Type=%s Level=%d", _name, GetTypeAsString(), _level); + if (_type == COMMAND || _type == THREAD) + printf(" Command=%s", _command); + else if (_type == PLUGIN && _title != NULL) + printf(" Title=%s", _title); + printf("\n"); + + for (cSubMenuNode *node = _subMenus.First(); node; node = _subMenus.Next(node)) + node->Print(index+4); +} + + +//################################################################################ +//# +//################################################################################ +cSubMenu::cSubMenu() +{ + _commandResult = NULL; + _currentMenuTree = &_menuTree; + _currentParentMenuTree = NULL; + _currentParentIndex = -1; + _nodeArray = NULL; + _nrNodes = 0; +} + + +cSubMenu::~cSubMenu() +{ + if (_commandResult) + free(_commandResult); + if (_nodeArray) + free(_nodeArray); + _nrNodes = 0; +} + + +bool cSubMenu::LoadXml(cString fname) +{ + TiXmlDocument xmlDoc = TiXmlDocument(fname); + TiXmlElement *root = NULL; + cSubMenuNode *node = NULL; + + bool ok = true; + // Clear previously loaded Menu + _menuTree.Clear(); + _fname = fname; + + if ((ok = xmlDoc.LoadFile())) { + if ((root = xmlDoc.FirstChildElement("menus")) != NULL) { + cString tmp = root->Attribute("suffix"); + if (*tmp) + _menuSuffix = tmp; + else + _menuSuffix = cString::sprintf(" "); + + if ((root = root->FirstChildElement()) != NULL) { + do { + try { + node = new cSubMenuNode(root, 0, &_menuTree, NULL); + _menuTree.Add(node); + } + catch (char *message) { + esyslog("ERROR: while decoding XML Node"); + ok = false; + } + } while (ok == true && (root = root->NextSiblingElement()) != NULL); + addMissingPlugins(); + removeUndefinedNodes(); + } + } + else { + esyslog("ERROR: in %s, missing Tag \n", *fname); + ok = false; + } + } + else { + esyslog("ERROR: in %s : %s Col=%d Row=%d\n", + *fname, + xmlDoc.ErrorDesc(), + xmlDoc.ErrorCol(), + xmlDoc.ErrorRow()); + ok = false; + } + + return(ok); +} + + +bool cSubMenu::SaveXml() +{ + return(SaveXml(_fname)); +} + + +bool cSubMenu::SaveXml(cString fname) +{ + bool ok = true; + + if (*_fname) { + TiXmlDocument xml = TiXmlDocument(fname); + TiXmlComment comment; + comment.SetValue("\n\ +- VDR Menu-Configuration File\n\ +-\n\ +-\n\ +- Example:\n\ +-\n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + \n\ + ...\n\ + \n\ + \n\ + \n\ + \n\ + ...\n\ + \n\ + \n\ +"); + + TiXmlElement root("menus"); + root.SetAttribute("suffix", _menuSuffix); + for (cSubMenuNode *node = _menuTree.First(); node; node = _menuTree.Next(node)) + node->SaveXml(&root); + + if (xml.InsertEndChild(comment) != NULL && xml.InsertEndChild(root) != NULL) + ok = xml.SaveFile(fname); + } + else + ok = false; + + return(ok); +} + + +cSubMenuNodes *cSubMenu::GetMenuTree() +{ + return(_currentMenuTree); +} + + +void cSubMenu::PrintMenuTree() +{ + for (cSubMenuNode *node = _menuTree.First(); node; node = _menuTree.Next(node)) + node->Print(); +} + + +int cSubMenu::GetNrOfNodes() +{ + if (_nrNodes == 0) { + if ((_nrNodes = countNodes(&_menuTree)) > 0) { + _nodeArray = (cSubMenuNode**) malloc(sizeof(cSubMenuNode*)*_nrNodes); + int index = 0; + tree2Array(&_menuTree, index); + } + } + + return(_nrNodes); +} + + +/** + * returns the specified node within the current menu + * @param index position in the current menu + * @return node or null if not found + */ +cSubMenuNode *cSubMenu::GetNode(int index) +{ + cSubMenuNode *node = NULL; + if (_currentMenuTree == NULL || (node=_currentMenuTree->Get(index)) == NULL) + esyslog("ERROR: illegal call of cSubMenu::GetNode(%d)", index); + + return(node); +} + + +/** + * Get the specified Node + * @param index specfies the absolut indes in the list of all nodes + * @return node or NULL if not found + */ +cSubMenuNode *cSubMenu::GetAbsNode(int index) +{ + cSubMenuNode *node = NULL; + GetNrOfNodes(); + if (_nrNodes > 0 && index >= 0 && index < _nrNodes) + node = _nodeArray[index]; + + return(node); +} + + +bool cSubMenu::Down(cSubMenuNode *node, int currentIndex) +{ + bool ok = true; + if (_currentMenuTree != NULL && node && node->GetType() == cSubMenuNode::MENU) { + _currentParentMenuTree = _currentMenuTree; + _currentParentIndex = currentIndex; + _currentMenuTree = node->GetSubMenus(); + } + else { + ok = false; + esyslog("ERROR: illegal call of cSubMenu::Down"); + } + + return(ok); +} + +bool cSubMenu::Up(int *parentIndex) +{ + bool ok = true; + + if (_currentMenuTree != NULL && parentIndex != NULL) { + cSubMenuNode *node = NULL; + *parentIndex = 0; + if (_currentParentIndex >= 0) + *parentIndex = _currentParentIndex; + + _currentMenuTree = _currentParentMenuTree; + if (_currentMenuTree != NULL) + _currentParentMenuTree = _currentMenuTree->Get(0)->GetParentMenu(); + else + ok = false; + } + else { + ok = false; + esyslog("ERROR: illegal call of cSubMenu::Up()"); + } + + return(ok); +} + +const char *cSubMenu::ExecuteCommand(const char *cmd) +{ + free(_commandResult); + _commandResult = NULL; + + dsyslog("executing command '%s'", cmd); + FILE *p = popen(cmd, "r"); + if (p) { + int l = 0; + int c; + while ((c = fgetc(p)) != EOF) { + if (l % 20 == 0) + _commandResult = (char *)realloc(_commandResult, l + 21); + _commandResult[l++] = c; + } + if (_commandResult) + _commandResult[l] = 0; + pclose(p); + } + else + esyslog("ERROR: can't open pipe for command '%s'", cmd); + + return _commandResult; +} + +/** + * Move Menu Entry to new Position + * @param index index of menu entry to move + * @param toIndex index of destination + * @param where After ore before the destination index + */ +void cSubMenu::MoveMenu(int index, int toIndex, enum Where where) +{ + if (index < 0 || index > _nrNodes || // invalid index is ignored + toIndex < 0 || toIndex > _nrNodes || index == toIndex) + return; + + cSubMenuNode *srcNode = GetAbsNode(index); + cSubMenuNode *destNode = GetAbsNode(toIndex); + + if (where == cSubMenu::INTO && destNode->GetType() != cSubMenuNode::MENU) + return; + + if (where == cSubMenu::INTO) { + if (destNode->GetType() == cSubMenuNode::MENU) { + srcNode->GetCurrentMenu()->Del(srcNode, false); + srcNode->SetLevel(destNode->GetLevel()+1); + srcNode->SetParentMenu(destNode->GetCurrentMenu()); + srcNode->SetCurrentMenu(destNode->GetSubMenus()); + + destNode->GetSubMenus()->Add(srcNode); + reloadNodeArray(); + } + } + else { + srcNode->GetCurrentMenu()->Del(srcNode, false); + srcNode->SetLevel(destNode->GetLevel()); + srcNode->SetParentMenu(destNode->GetParentMenu()); + srcNode->SetCurrentMenu(destNode->GetCurrentMenu()); + + if (where == cSubMenu::BEHIND) { + destNode->GetCurrentMenu()->Add(srcNode, GetAbsNode(toIndex)); + reloadNodeArray(); + } + else { + destNode->GetCurrentMenu()->Ins(srcNode, GetAbsNode(toIndex)); + reloadNodeArray(); + } + } +} + +/** + * Create a new Menu Entry + * @param index index of destination + * @param menuTitle Titel of new Menu entry + */ +void cSubMenu::CreateMenu(int index, const char *menuTitle) +{ + if (index >= 0 && index < _nrNodes) { + cSubMenuNode *srcNode = GetAbsNode(index); + if (srcNode != NULL) { + cSubMenuNode *newNode = new cSubMenuNode(srcNode->GetParentMenu(), srcNode->GetCurrentMenu()); + newNode->SetLevel(srcNode->GetLevel()); + newNode->SetName(menuTitle); + newNode->SetType(cSubMenuNode::MENU); + newNode->SetParentMenu(srcNode->GetParentMenu()); + newNode->SetCurrentMenu(srcNode->GetCurrentMenu()); + + srcNode->GetCurrentMenu()->Add(newNode, GetAbsNode(index)); + reloadNodeArray(); + } + } +} + +/** + * delete the specified entry, or subtree if the specified entry is a menu + * @param index destion index + */ +void cSubMenu::DeleteMenu(int index) +{ + if (index >= 0 && index < _nrNodes) { + cSubMenuNode *srcNode = GetAbsNode(index); + srcNode->GetCurrentMenu()->Del(srcNode, true); + reloadNodeArray(); + } +} + + +// Private Methods + +int cSubMenu::countNodes(cSubMenuNodes *tree) +{ + int count = 0; + if (tree != NULL) { + for (cSubMenuNode *node = tree->First(); node; node = tree->Next(node)) { + count++; + if (node->HasSubMenus()) + count += countNodes(node->GetSubMenus()); + } + } + return(count); +} + + +void cSubMenu::tree2Array(cSubMenuNodes *tree, int &index) +{ + if (tree != NULL) { + for (cSubMenuNode *node = tree->First(); node; node = tree->Next(node)) { + _nodeArray[index++]=node; + if (node->HasSubMenus()) + tree2Array(node->GetSubMenus(), index); + } + } + +} + +bool cSubMenu::IsPluginInMenu(const char *name) +{ + bool found = false; + for (int i = 0; i < _nrNodes && found == false; i++) { + cSubMenuNode *node = GetAbsNode(i); + if (node != NULL && node->GetType() == cSubMenuNode::PLUGIN && strcmp(name, node->GetName()) == 0) + found = true; + } + return(found); +} + +/** + * Adds the given plugin to the Menu-Tree if not allready in List + * @param name specifies the name of the plugin + */ +void cSubMenu::AddPlugin(const char *name) +{ + if (! IsPluginInMenu(name)) { + cSubMenuNode *node = new cSubMenuNode(&_menuTree, NULL); + node->SetName(name); + node->SetType("plugin"); + node->SetPlugin(); + _menuTree.Add(node); + } +} + +void cSubMenu::addMissingPlugins() +{ + _nrNodes = GetNrOfNodes(); + for (int i = 0; ; i++) { + cPlugin *p = cPluginManager::GetPlugin(i); + if (p) + AddPlugin(p->Name()); + else + break; + } + reloadNodeArray(); +} + +/** + * Adds the given command to the Menu-Tree + * @param name specifies the name of the command + */ +void cSubMenu::CreateCommand(int index, const char *name, const char *execute, int confirm) +{ + if (index >= 0 && index < _nrNodes) { + cSubMenuNode *srcNode = GetAbsNode(index); + if (srcNode != NULL) { + cSubMenuNode *newNode = new cSubMenuNode(srcNode->GetParentMenu(), srcNode->GetCurrentMenu()); + newNode->SetLevel(srcNode->GetLevel()); + newNode->SetName(name); + newNode->SetType("command"); + newNode->SetCommand(execute); + newNode->SetCommandConfirm(confirm); + newNode->SetParentMenu(srcNode->GetParentMenu()); + newNode->SetCurrentMenu(srcNode->GetCurrentMenu()); + + srcNode->GetCurrentMenu()->Add(newNode, GetAbsNode(index)); + reloadNodeArray(); + } + } +} + +void cSubMenu::CreateThread(int index, const char *name, const char *execute, int confirm) +{ + if (index >= 0 && index < _nrNodes) { + cSubMenuNode *srcNode = GetAbsNode(index); + if (srcNode != NULL) { + cSubMenuNode *newNode = new cSubMenuNode(srcNode->GetParentMenu(), srcNode->GetCurrentMenu()); + newNode->SetLevel(srcNode->GetLevel()); + newNode->SetName(name); + newNode->SetType("thread"); + newNode->SetCommand(execute); + newNode->SetCommandConfirm(confirm); + newNode->SetParentMenu(srcNode->GetParentMenu()); + newNode->SetCurrentMenu(srcNode->GetCurrentMenu()); + + srcNode->GetCurrentMenu()->Add(newNode, GetAbsNode(index)); + reloadNodeArray(); + } + } +} + +/** + * reloads the internal Array of Nodes + */ +void cSubMenu::reloadNodeArray() +{ + if (_nrNodes > 0) + free(_nodeArray); + _nodeArray = NULL; + _nrNodes = 0; + _nrNodes = GetNrOfNodes(); +} + +/** + * remove Undefined Nodes + */ +void cSubMenu::removeUndefinedNodes() +{ + bool remove = false; + + reloadNodeArray(); + for (int i = 0; i < _nrNodes; i++) { + cSubMenuNode *node = GetAbsNode(i); + if (node != NULL && node->GetType() == cSubMenuNode::UNDEFINED) { + cSubMenuNodes *pMenu = node->GetCurrentMenu(); + pMenu->Del(node, true); + remove = true; + } + } + if (remove) + reloadNodeArray(); +} + + +/** +* Retrieves the Menutitel of the parent Menu +*/ +const char *cSubMenu::GetParentMenuTitel() +{ + const char *result = ""; + + if (_currentMenuTree != NULL && _currentParentMenuTree != NULL) { + cSubMenuNode *node = NULL; + for (int i = 0; (node = _currentParentMenuTree->Get(i)) != NULL; i++) { + if (_currentMenuTree == node->GetSubMenus()) { + result = node->GetName(); + break; + } + } + } + + return(result); +} + +#endif diff -ruN 1.7.41_20/submenu.h 1.7.41_21/submenu.h --- 1.7.41_20/submenu.h 1970-01-01 01:00:00.000000000 +0100 +++ 1.7.41_21/submenu.h 2013-03-19 21:24:26.000000000 +0100 @@ -0,0 +1,151 @@ +/**************************************************************************** + * DESCRIPTION: + * Submenu + * + * $Id: vdr-1.3.44-Setup-0.3.0.diff,v 1.1 2006/03/04 09:58:47 ralf Exp $ + * + * Contact: ranga@teddycats.de + * + * Copyright (C) 2004, 2005 by Ralf Dotzert + * + * modified for the VDR Extensions Patch by zulu @vdr-portal + ****************************************************************************/ + +#ifndef SUBMENU_H +#define SUBMENU_H + +#include "thread.h" +#include "tools.h" +#include "tinystr.h" + +class cSubMenuNode; +class cSubMenuNodes; +class cSubMenu; + + +class cSubMenuNodes : public cList {}; + +// execute cmd thread +class cExecCmdThread : public cThread { +private: + cString ExecCmd; +protected: + virtual void Action(void) { + if (system(ExecCmd) == 0) + esyslog("%s - finished", *ExecCmd); + delete(this); + }; +public: + cExecCmdThread(char *cmd) { + ExecCmd = cString::sprintf("%s", cmd); + } + cExecCmdThread(const char *cmd) { + ExecCmd = cString::sprintf("%s", cmd); + } + ~cExecCmdThread() { + }; + }; + +//################################################################################ +//# SubMenuNode +//################################################################################ +class cSubMenuNode : public cListObject { +public: + enum Type { UNDEFINED, SYSTEM, COMMAND, THREAD, PLUGIN, MENU }; + cSubMenuNode(TiXmlElement *xml, int level, cSubMenuNodes *currentMenu, cSubMenuNodes *parentMenu); + cSubMenuNode(cSubMenuNodes *currentMenu, cSubMenuNodes *parentMenu); + ~cSubMenuNode(); + bool SaveXml(TiXmlElement *root); + static cSubMenuNode::Type IsType(const char *name); + void SetType(const char *name); + void SetType(enum Type type); + void SetPlugin(); + cSubMenuNode::Type GetType(); + const char *GetTypeAsString(); + void SetCommand(const char *command); + bool CommandConfirm(); + void SetCommandConfirm(int val); + const char *GetCommand(); + void SetCustomTitle(const char *title); + const char *GetCustomTitle(); + void SetName(const char *name); + const char*GetName(); + int GetLevel(); + void SetLevel(int level); + int GetPluginIndex(); + void SetPluginIndex(int index); + void SetPluginMainMenuEntry(const char *mainMenuEntry); + const char *GetPluginMainMenuEntry(); + cSubMenuNodes *GetParentMenu(); + void SetParentMenu(cSubMenuNodes *parent); + cSubMenuNodes *GetCurrentMenu(); + void SetCurrentMenu(cSubMenuNodes *current); + cSubMenuNodes *GetSubMenus(); + bool HasSubMenus(); + void Print(int index = 0); +private: + Type _type; + int _level; + // Plugin Variables + int _pluginIndex; + const char *_pluginMainMenuEntry; + // common + const char *_name; + const char *_command; + bool _commandConfirm; + const char *_title; + cSubMenuNodes _subMenus; + cSubMenuNodes *_parentMenu; + cSubMenuNodes *_currentMenu; + void init(); + }; + + +//################################################################################ +//# SubMenu Class +//################################################################################ +class cSubMenu { +public: + cSubMenu(); + ~cSubMenu(); + enum Where { BEFORE, BEHIND, INTO}; + bool LoadXml(cString fname); + bool SaveXml(cString fname); + bool SaveXml(); + cSubMenuNodes *GetMenuTree(); + bool Up(int *ParentIndex); + bool Down(cSubMenuNode* node, int currentIndex); + int GetNrOfNodes(); + cSubMenuNode* GetAbsNode(int index); + cSubMenuNode* GetNode(int index); + void PrintMenuTree(); + bool IsPluginInMenu(const char *name); + void AddPlugin(const char *name); + void CreateCommand(int index, const char *name, const char *execute, int confirm); + void CreateThread(int index, const char *name, const char *execute, int confirm); + const char *ExecuteCommand(const char *command); + void MoveMenu(int index, int toindex, enum Where); + void CreateMenu(int index, const char *menuTitle); + void DeleteMenu(int index); + cString GetMenuSuffix() { return _menuSuffix; } + void SetMenuSuffix(char *suffix) { _menuSuffix = suffix; } + bool isTopMenu() { return (_currentParentMenuTree == NULL); } + const char *GetParentMenuTitel(); +private: + cSubMenuNodes _menuTree; + cSubMenuNodes *_currentMenuTree; + cSubMenuNodes *_currentParentMenuTree; + int _currentParentIndex; + cString _fname; + char *_commandResult; + int _nrNodes; + cSubMenuNode **_nodeArray; + cString _menuSuffix; + int countNodes(cSubMenuNodes *tree); + void tree2Array(cSubMenuNodes *tree, int &index); + void addMissingPlugins(); + void reloadNodeArray(); + void removeUndefinedNodes(); + }; + +#endif //__SUBMENU_H diff -ruN 1.7.41_20/timers.c 1.7.41_21/timers.c --- 1.7.41_20/timers.c 2013-03-16 11:37:10.000000000 +0100 +++ 1.7.41_21/timers.c 2013-03-19 21:25:40.000000000 +0100 @@ -33,6 +33,7 @@ *file = 0; aux = NULL; event = NULL; + fskProtection = 0; if (Instant) SetFlags(tfActive | tfInstant); channel = Channel ? Channel : Channels.GetByNumber(cDevice::CurrentChannel()); @@ -90,6 +91,7 @@ *file = 0; aux = NULL; event = NULL; + fskProtection = 0; if (Event->Vps() && Setup.UseVps) SetFlags(tfVps); channel = Channels.GetByChannelID(Event->ChannelID(), true); @@ -113,6 +115,7 @@ const char *Title = Event->Title(); if (!isempty(Title)) Utf8Strn0Cpy(file, Event->Title(), sizeof(file)); SetEvent(Event); + cStatus::MsgTimerCreation(this, Event); } @@ -149,6 +152,7 @@ stop = Timer.stop; priority = Timer.priority; lifetime = Timer.lifetime; + fskProtection = Timer.fskProtection; strncpy(file, Timer.file, sizeof(file)); free(aux); aux = Timer.aux ? strdup(Timer.aux) : NULL; @@ -331,6 +335,7 @@ result = false; } } + fskProtection = aux && strstr(aux, "yes"); free(channelbuffer); free(daybuffer); free(filebuffer); @@ -689,6 +694,35 @@ Matches(); // refresh start and end time } +void cTimer::SetFskProtection(int aFlag) // PIN PATCH +{ + char* p; + char* tmp = 0; + int res = 0; + + fskProtection = aFlag; + + if (fskProtection && (!aux || !strstr(aux, "yes"))) + { + // add protection info to aux + + if (aux) { tmp = strdup(aux); free(aux); } + res = asprintf(&aux, "%syes", tmp ? tmp : ""); + } + else if (!fskProtection && aux && (p = strstr(aux, "yes"))) + { + // remove protection info from aux + + res = asprintf(&tmp, "%.*s%s", (int)(p-aux), aux, p+strlen("yes")); + free(aux); + aux = strdup(tmp); + } + + if (res < 0) ; // memory problems :o + + if (tmp) + free(tmp); +} // --- cTimers --------------------------------------------------------------- cTimers Timers; diff -ruN 1.7.41_20/timers.h 1.7.41_21/timers.h --- 1.7.41_20/timers.h 2013-03-11 11:35:53.000000000 +0100 +++ 1.7.41_21/timers.h 2013-03-19 21:25:57.000000000 +0100 @@ -38,6 +38,7 @@ int start; int stop; int priority; + int fskProtection; int lifetime; mutable char file[NAME_MAX * 2 + 1]; // *2 to be able to hold 'title' and 'episode', which can each be up to 255 characters long char *aux; @@ -59,6 +60,7 @@ int Start(void) const { return start; } int Stop(void) const { return stop; } int Priority(void) const { return priority; } + int FskProtection(void) const { return fskProtection; } int Lifetime(void) const { return lifetime; } const char *File(void) const { return file; } time_t FirstDay(void) const { return weekdays ? day : 0; } @@ -95,6 +97,7 @@ void SetAux(const char *Aux); void SetDeferred(int Seconds); void SetFlags(uint Flags); + void SetFskProtection(int aFlag); void ClrFlags(uint Flags); void InvFlags(uint Flags); bool HasFlags(uint Flags) const; diff -ruN 1.7.41_20/tinystr.c 1.7.41_21/tinystr.c --- 1.7.41_20/tinystr.c 1970-01-01 01:00:00.000000000 +0100 +++ 1.7.41_21/tinystr.c 2013-03-19 20:56:34.000000000 +0100 @@ -0,0 +1,299 @@ +/* +www.sourceforge.net/projects/tinyxml +Original file by Yves Berquin. + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxml.h" + +#ifndef TIXML_USE_STL + + +#include +#include +#include + +#include "tinystr.h" + +// TiXmlString constructor, based on a C string +TiXmlString::TiXmlString (const char* instring) +{ + unsigned newlen; + char * newstring; + + if (!instring) + { + allocated = 0; + cstring = NULL; + current_length = 0; + return; + } + newlen = strlen (instring) + 1; + newstring = new char [newlen]; + memcpy (newstring, instring, newlen); + // strcpy (newstring, instring); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// TiXmlString copy constructor +TiXmlString::TiXmlString (const TiXmlString& copy) +{ + unsigned newlen; + char * newstring; + + // Prevent copy to self! + if ( © == this ) + return; + + if (! copy . allocated) + { + allocated = 0; + cstring = NULL; + current_length = 0; + return; + } + newlen = copy . length () + 1; + newstring = new char [newlen]; + // strcpy (newstring, copy . cstring); + memcpy (newstring, copy . cstring, newlen); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// TiXmlString = operator. Safe when assign own content +void TiXmlString ::operator = (const char * content) +{ + unsigned newlen; + char * newstring; + + if (! content) + { + empty_it (); + return; + } + newlen = strlen (content) + 1; + newstring = new char [newlen]; + // strcpy (newstring, content); + memcpy (newstring, content, newlen); + empty_it (); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// = operator. Safe when assign own content +void TiXmlString ::operator = (const TiXmlString & copy) +{ + unsigned newlen; + char * newstring; + + if (! copy . length ()) + { + empty_it (); + return; + } + newlen = copy . length () + 1; + newstring = new char [newlen]; + // strcpy (newstring, copy . c_str ()); + memcpy (newstring, copy . c_str (), newlen); + empty_it (); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + + +// append a const char * to an existing TiXmlString +void TiXmlString::append( const char* str, int len ) +{ + char * new_string; + unsigned new_alloc, new_size, size_suffix; + + // don't use strlen - it can overrun the len passed in! + const char* p = str; + size_suffix = 0; + + while ( *p && size_suffix < (unsigned)len ) + { + ++p; + ++size_suffix; + } + if ( !size_suffix) + return; + + new_size = length () + size_suffix + 1; + // check if we need to expand + if (new_size > allocated) + { + // compute new size + new_alloc = assign_new_size (new_size); + + // allocate new buffer + new_string = new char [new_alloc]; + new_string [0] = 0; + + // copy the previous allocated buffer into this one + if (allocated && cstring) + // strcpy (new_string, cstring); + memcpy (new_string, cstring, length ()); + + // append the suffix. It does exist, otherwize we wouldn't be expanding + // strncat (new_string, str, len); + memcpy (new_string + length (), + str, + size_suffix); + + // return previsously allocated buffer if any + if (allocated && cstring) + delete [] cstring; + + // update member variables + cstring = new_string; + allocated = new_alloc; + } + else + { + // we know we can safely append the new string + // strncat (cstring, str, len); + memcpy (cstring + length (), + str, + size_suffix); + } + current_length = new_size - 1; + cstring [current_length] = 0; +} + + +// append a const char * to an existing TiXmlString +void TiXmlString::append( const char * suffix ) +{ + char * new_string; + unsigned new_alloc, new_size; + + new_size = length () + strlen (suffix) + 1; + // check if we need to expand + if (new_size > allocated) + { + // compute new size + new_alloc = assign_new_size (new_size); + + // allocate new buffer + new_string = new char [new_alloc]; + new_string [0] = 0; + + // copy the previous allocated buffer into this one + if (allocated && cstring) + memcpy (new_string, cstring, 1 + length ()); + // strcpy (new_string, cstring); + + // append the suffix. It does exist, otherwize we wouldn't be expanding + // strcat (new_string, suffix); + memcpy (new_string + length (), + suffix, + strlen (suffix) + 1); + + // return previsously allocated buffer if any + if (allocated && cstring) + delete [] cstring; + + // update member variables + cstring = new_string; + allocated = new_alloc; + } + else + { + // we know we can safely append the new string + // strcat (cstring, suffix); + memcpy (cstring + length (), + suffix, + strlen (suffix) + 1); + } + current_length = new_size - 1; +} + +// Check for TiXmlString equuivalence +//bool TiXmlString::operator == (const TiXmlString & compare) const +//{ +// return (! strcmp (c_str (), compare . c_str ())); +//} + +//unsigned TiXmlString::length () const +//{ +// if (allocated) +// // return strlen (cstring); +// return current_length; +// return 0; +//} + + +unsigned TiXmlString::find (char tofind, unsigned offset) const +{ + char * lookup; + + if (offset >= length ()) + return (unsigned) notfound; + for (lookup = cstring + offset; * lookup; lookup++) + if (* lookup == tofind) + return lookup - cstring; + return (unsigned) notfound; +} + + +bool TiXmlString::operator == (const TiXmlString & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( strcmp( cstring, compare.cstring ) == 0 ); + } + return false; +} + + +bool TiXmlString::operator < (const TiXmlString & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( strcmp( cstring, compare.cstring ) > 0 ); + } + return false; +} + + +bool TiXmlString::operator > (const TiXmlString & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( strcmp( cstring, compare.cstring ) < 0 ); + } + return false; +} + + +#endif // TIXML_USE_STL diff -ruN 1.7.41_20/tinystr.h 1.7.41_21/tinystr.h --- 1.7.41_20/tinystr.h 1970-01-01 01:00:00.000000000 +0100 +++ 1.7.41_21/tinystr.h 2013-03-19 20:56:34.000000000 +0100 @@ -0,0 +1,242 @@ +/* +www.sourceforge.net/projects/tinyxml +Original file by Yves Berquin. + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxml.h" + + +#ifndef TIXML_USE_STL + +#ifndef TIXML_STRING_INCLUDED +#define TIXML_STRING_INCLUDED + +#ifdef _MSC_VER +#pragma warning( disable : 4786 ) // Debugger truncating names. +#endif + +#include + +/* + TiXmlString is an emulation of the std::string template. + Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. + Only the member functions relevant to the TinyXML project have been implemented. + The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase + a string and there's no more room, we allocate a buffer twice as big as we need. +*/ +class TiXmlString +{ + public : + // TiXmlString constructor, based on a string + TiXmlString (const char * instring); + + // TiXmlString empty constructor + TiXmlString () + { + allocated = 0; + cstring = NULL; + current_length = 0; + } + + // TiXmlString copy constructor + TiXmlString (const TiXmlString& copy); + + // TiXmlString destructor + ~ TiXmlString () + { + empty_it (); + } + + // Convert a TiXmlString into a classical char * + const char * c_str () const + { + if (allocated) + return cstring; + return ""; + } + + // Return the length of a TiXmlString + unsigned length () const + { + return ( allocated ) ? current_length : 0; + } + + // TiXmlString = operator + void operator = (const char * content); + + // = operator + void operator = (const TiXmlString & copy); + + // += operator. Maps to append + TiXmlString& operator += (const char * suffix) + { + append (suffix); + return *this; + } + + // += operator. Maps to append + TiXmlString& operator += (char single) + { + append (single); + return *this; + } + + // += operator. Maps to append + TiXmlString& operator += (TiXmlString & suffix) + { + append (suffix); + return *this; + } + bool operator == (const TiXmlString & compare) const; + bool operator < (const TiXmlString & compare) const; + bool operator > (const TiXmlString & compare) const; + + // Checks if a TiXmlString is empty + bool empty () const + { + return length () ? false : true; + } + + // single char extraction + const char& at (unsigned index) const + { + assert( index < length ()); + return cstring [index]; + } + + // find a char in a string. Return TiXmlString::notfound if not found + unsigned find (char lookup) const + { + return find (lookup, 0); + } + + // find a char in a string from an offset. Return TiXmlString::notfound if not found + unsigned find (char tofind, unsigned offset) const; + + /* Function to reserve a big amount of data when we know we'll need it. Be aware that this + function clears the content of the TiXmlString if any exists. + */ + void reserve (unsigned size) + { + empty_it (); + if (size) + { + allocated = size; + cstring = new char [size]; + cstring [0] = 0; + current_length = 0; + } + } + + // [] operator + char& operator [] (unsigned index) const + { + assert( index < length ()); + return cstring [index]; + } + + // Error value for find primitive + enum { notfound = 0xffffffff, + npos = notfound }; + + void append (const char *str, int len ); + + protected : + + // The base string + char * cstring; + // Number of chars allocated + unsigned allocated; + // Current string size + unsigned current_length; + + // New size computation. It is simplistic right now : it returns twice the amount + // we need + unsigned assign_new_size (unsigned minimum_to_allocate) + { + return minimum_to_allocate * 2; + } + + // Internal function that clears the content of a TiXmlString + void empty_it () + { + if (cstring) + delete [] cstring; + cstring = NULL; + allocated = 0; + current_length = 0; + } + + void append (const char *suffix ); + + // append function for another TiXmlString + void append (const TiXmlString & suffix) + { + append (suffix . c_str ()); + } + + // append for a single char. + void append (char single) + { + if ( cstring && current_length < (allocated-1) ) + { + cstring[ current_length ] = single; + ++current_length; + cstring[ current_length ] = 0; + } + else + { + char smallstr [2]; + smallstr [0] = single; + smallstr [1] = 0; + append (smallstr); + } + } + +} ; + +/* + TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. + Only the operators that we need for TinyXML have been developped. +*/ +class TiXmlOutStream : public TiXmlString +{ +public : + TiXmlOutStream () : TiXmlString () {} + + // TiXmlOutStream << operator. Maps to TiXmlString::append + TiXmlOutStream & operator << (const char * in) + { + append (in); + return (* this); + } + + // TiXmlOutStream << operator. Maps to TiXmlString::append + TiXmlOutStream & operator << (const TiXmlString & in) + { + append (in . c_str ()); + return (* this); + } +} ; + +#endif // TIXML_STRING_INCLUDED +#endif // TIXML_USE_STL diff -ruN 1.7.41_20/tinyxml.c 1.7.41_21/tinyxml.c --- 1.7.41_20/tinyxml.c 1970-01-01 01:00:00.000000000 +0100 +++ 1.7.41_21/tinyxml.c 2013-03-19 20:56:34.000000000 +0100 @@ -0,0 +1,1427 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include +#include "tinyxml.h" + +#ifdef TIXML_USE_STL +#include +#endif + + +bool TiXmlBase::condenseWhiteSpace = true; + +void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_OSTREAM* stream ) +{ + TIXML_STRING buffer; + PutString( str, &buffer ); + (*stream) << buffer; +} + +void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_STRING* outString ) +{ + int i=0; + + while( i<(int)str.length() ) + { + unsigned char c = (unsigned char) str[i]; + + if ( c == '&' + && i < ( (int)str.length() - 2 ) + && str[i+1] == '#' + && str[i+2] == 'x' ) + { + // Hexadecimal character reference. + // Pass through unchanged. + // © -- copyright symbol, for example. + // + // The -1 is a bug fix from Rob Laveaux. It keeps + // an overflow from happening if there is no ';'. + // There are actually 2 ways to exit this loop - + // while fails (error case) and break (semicolon found). + // However, there is no mechanism (currently) for + // this function to return an error. + while ( i<(int)str.length()-1 ) + { + outString->append( str.c_str() + i, 1 ); + ++i; + if ( str[i] == ';' ) + break; + } + } + else if ( c == '&' ) + { + outString->append( entity[0].str, entity[0].strLength ); + ++i; + } + else if ( c == '<' ) + { + outString->append( entity[1].str, entity[1].strLength ); + ++i; + } + else if ( c == '>' ) + { + outString->append( entity[2].str, entity[2].strLength ); + ++i; + } + else if ( c == '\"' ) + { + outString->append( entity[3].str, entity[3].strLength ); + ++i; + } + else if ( c == '\'' ) + { + outString->append( entity[4].str, entity[4].strLength ); + ++i; + } + else if ( c < 32 ) + { + // Easy pass at non-alpha/numeric/symbol + // Below 32 is symbolic. + char buf[ 32 ]; + sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); + outString->append( buf, strlen( buf ) ); + ++i; + } + else + { + //char realc = (char) c; + //outString->append( &realc, 1 ); + *outString += (char) c; // somewhat more efficient function call. + ++i; + } + } +} + + +// <-- Strange class for a bug fix. Search for STL_STRING_BUG +TiXmlBase::StringToBuffer::StringToBuffer( const TIXML_STRING& str ) +{ + buffer = new char[ str.length()+1 ]; + if ( buffer ) + { + strcpy( buffer, str.c_str() ); + } +} + + +TiXmlBase::StringToBuffer::~StringToBuffer() +{ + delete [] buffer; +} +// End strange bug fix. --> + + +TiXmlNode::TiXmlNode( NodeType _type ) : TiXmlBase() +{ + parent = 0; + type = _type; + firstChild = 0; + lastChild = 0; + prev = 0; + next = 0; +} + + +TiXmlNode::~TiXmlNode() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } +} + + +void TiXmlNode::CopyTo( TiXmlNode* target ) const +{ + target->SetValue (value.c_str() ); + target->userData = userData; +} + + +void TiXmlNode::Clear() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } + + firstChild = 0; + lastChild = 0; +} + + +TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node ) +{ + node->parent = this; + + node->prev = lastChild; + node->next = 0; + + if ( lastChild ) + lastChild->next = node; + else + firstChild = node; // it was an empty list. + + lastChild = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) +{ + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + + return LinkEndChild( node ); +} + + +TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ) +{ + if ( !beforeThis || beforeThis->parent != this ) + return 0; + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->next = beforeThis; + node->prev = beforeThis->prev; + if ( beforeThis->prev ) + { + beforeThis->prev->next = node; + } + else + { + assert( firstChild == beforeThis ); + firstChild = node; + } + beforeThis->prev = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ) +{ + if ( !afterThis || afterThis->parent != this ) + return 0; + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->prev = afterThis; + node->next = afterThis->next; + if ( afterThis->next ) + { + afterThis->next->prev = node; + } + else + { + assert( lastChild == afterThis ); + lastChild = node; + } + afterThis->next = node; + return node; +} + + +TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ) +{ + if ( replaceThis->parent != this ) + return 0; + + TiXmlNode* node = withThis.Clone(); + if ( !node ) + return 0; + + node->next = replaceThis->next; + node->prev = replaceThis->prev; + + if ( replaceThis->next ) + replaceThis->next->prev = node; + else + lastChild = node; + + if ( replaceThis->prev ) + replaceThis->prev->next = node; + else + firstChild = node; + + delete replaceThis; + node->parent = this; + return node; +} + + +bool TiXmlNode::RemoveChild( TiXmlNode* removeThis ) +{ + if ( removeThis->parent != this ) + { + assert( 0 ); + return false; + } + + if ( removeThis->next ) + removeThis->next->prev = removeThis->prev; + else + lastChild = removeThis->prev; + + if ( removeThis->prev ) + removeThis->prev->next = removeThis->next; + else + firstChild = removeThis->next; + + delete removeThis; + return true; +} + +TiXmlNode* TiXmlNode::FirstChild( const char * _value ) const +{ + TiXmlNode* node; + for ( node = firstChild; node; node = node->next ) + { + if ( node->SValue() == TIXML_STRING( _value )) + return node; + } + return 0; +} + +TiXmlNode* TiXmlNode::LastChild( const char * _value ) const +{ + TiXmlNode* node; + for ( node = lastChild; node; node = node->prev ) + { + if ( node->SValue() == TIXML_STRING (_value)) + return node; + } + return 0; +} + +TiXmlNode* TiXmlNode::IterateChildren( TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild(); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling(); + } +} + +TiXmlNode* TiXmlNode::IterateChildren( const char * val, TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild( val ); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling( val ); + } +} + +TiXmlNode* TiXmlNode::NextSibling( const char * _value ) const +{ + TiXmlNode* node; + for ( node = next; node; node = node->next ) + { + if ( node->SValue() == TIXML_STRING (_value)) + return node; + } + return 0; +} + + +TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) const +{ + TiXmlNode* node; + for ( node = prev; node; node = node->prev ) + { + if ( node->SValue() == TIXML_STRING (_value)) + return node; + } + return 0; +} + +void TiXmlElement::RemoveAttribute( const char * name ) +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( node ) + { + attributeSet.Remove( node ); + delete node; + } +} + +TiXmlElement* TiXmlNode::FirstChildElement() const +{ + TiXmlNode* node; + + for ( node = FirstChild(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const +{ + TiXmlNode* node; + + for ( node = FirstChild( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +TiXmlElement* TiXmlNode::NextSiblingElement() const +{ + TiXmlNode* node; + + for ( node = NextSibling(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) const +{ + TiXmlNode* node; + + for ( node = NextSibling( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + + +TiXmlDocument* TiXmlNode::GetDocument() const +{ + const TiXmlNode* node; + + for( node = this; node; node = node->parent ) + { + if ( node->ToDocument() ) + return node->ToDocument(); + } + return 0; +} + + +TiXmlElement::TiXmlElement (const char * _value) + : TiXmlNode( TiXmlNode::ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} + + +#ifdef TIXML_USE_STL +TiXmlElement::TiXmlElement( const std::string& _value ) + : TiXmlNode( TiXmlNode::ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} +#endif + + +TiXmlElement::TiXmlElement( const TiXmlElement& copy) + : TiXmlNode( TiXmlNode::ELEMENT ) +{ + firstChild = lastChild = 0; + copy.CopyTo( this ); +} + + +void TiXmlElement::operator=( const TiXmlElement& base ) +{ + ClearThis(); + base.CopyTo( this ); +} + + +TiXmlElement::~TiXmlElement() +{ + ClearThis(); +} + + +void TiXmlElement::ClearThis() +{ + Clear(); + while( attributeSet.First() ) + { + TiXmlAttribute* node = attributeSet.First(); + attributeSet.Remove( node ); + delete node; + } +} + + +const char * TiXmlElement::Attribute( const char * name ) const +{ + TiXmlAttribute* node = attributeSet.Find( name ); + + if ( node ) + return node->Value(); + + return 0; +} + + +const char * TiXmlElement::Attribute( const char * name, int* i ) const +{ + const char * s = Attribute( name ); + if ( i ) + { + if ( s ) + *i = atoi( s ); + else + *i = 0; + } + return s; +} + + +const char * TiXmlElement::Attribute( const char * name, double* d ) const +{ + const char * s = Attribute( name ); + if ( d ) + { + if ( s ) + *d = atof( s ); + else + *d = 0; + } + return s; +} + + +int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + return node->QueryIntValue( ival ); +} + + +int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + return node->QueryDoubleValue( dval ); +} + + +void TiXmlElement::SetAttribute( const char * name, int val ) +{ + char buf[64]; + sprintf( buf, "%d", val ); + SetAttribute( name, buf ); +} + + +void TiXmlElement::SetDoubleAttribute( const char * name, double val ) +{ + char buf[128]; + sprintf( buf, "%f", val ); + SetAttribute( name, buf ); +} + + +void TiXmlElement::SetAttribute( const char * name, const char * _value ) +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( node ) + { + node->SetValue( _value ); + return; + } + + TiXmlAttribute* attrib = new TiXmlAttribute( name, _value ); + if ( attrib ) + { + attributeSet.Add( attrib ); + } + else + { + TiXmlDocument* document = GetDocument(); + if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN ); + } +} + +void TiXmlElement::Print( FILE* cfile, int depth ) const +{ + int i; + for ( i=0; iNext() ) + { + fprintf( cfile, " " ); + attrib->Print( cfile, depth ); + } + + // There are 3 different formatting approaches: + // 1) An element without children is printed as a node + // 2) An element with only a text child is printed as text + // 3) An element with children is printed on multiple lines. + TiXmlNode* node; + if ( !firstChild ) + { + fprintf( cfile, " />" ); + } + else if ( firstChild == lastChild && firstChild->ToText() ) + { + fprintf( cfile, ">" ); + firstChild->Print( cfile, depth + 1 ); + fprintf( cfile, "", value.c_str() ); + } + else + { + fprintf( cfile, ">" ); + + for ( node = firstChild; node; node=node->NextSibling() ) + { + if ( !node->ToText() ) + { + fprintf( cfile, "\n" ); + } + node->Print( cfile, depth+1 ); + } + fprintf( cfile, "\n" ); + for( i=0; i", value.c_str() ); + } +} + +void TiXmlElement::StreamOut( TIXML_OSTREAM * stream ) const +{ + (*stream) << "<" << value; + + TiXmlAttribute* attrib; + for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) + { + (*stream) << " "; + attrib->StreamOut( stream ); + } + + // If this node has children, give it a closing tag. Else + // make it an empty tag. + TiXmlNode* node; + if ( firstChild ) + { + (*stream) << ">"; + + for ( node = firstChild; node; node=node->NextSibling() ) + { + node->StreamOut( stream ); + } + (*stream) << ""; + } + else + { + (*stream) << " />"; + } +} + + +void TiXmlElement::CopyTo( TiXmlElement* target ) const +{ + // superclass: + TiXmlNode::CopyTo( target ); + + // Element class: + // Clone the attributes, then clone the children. + TiXmlAttribute* attribute = 0; + for( attribute = attributeSet.First(); + attribute; + attribute = attribute->Next() ) + { + target->SetAttribute( attribute->Name(), attribute->Value() ); + } + + TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + target->LinkEndChild( node->Clone() ); + } +} + + +TiXmlNode* TiXmlElement::Clone() const +{ + TiXmlElement* clone = new TiXmlElement( Value() ); + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + tabsize = 4; + ClearError(); +} + +TiXmlDocument::TiXmlDocument( const char * documentName ) : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + tabsize = 4; + value = documentName; + ClearError(); +} + + +#ifdef TIXML_USE_STL +TiXmlDocument::TiXmlDocument( const std::string& documentName ) : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + tabsize = 4; + value = documentName; + ClearError(); +} +#endif + + +TiXmlDocument::TiXmlDocument( const TiXmlDocument& copy ) : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + copy.CopyTo( this ); +} + + +void TiXmlDocument::operator=( const TiXmlDocument& copy ) +{ + Clear(); + copy.CopyTo( this ); +} + + +bool TiXmlDocument::LoadFile( TiXmlEncoding encoding ) +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.buffer && LoadFile( buf.buffer, encoding ) ) + return true; + + return false; +} + + +bool TiXmlDocument::SaveFile() const +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.buffer && SaveFile( buf.buffer ) ) + return true; + + return false; +} + +bool TiXmlDocument::LoadFile( const char* filename, TiXmlEncoding encoding ) +{ + // Delete the existing data: + Clear(); + location.Clear(); + + // There was a really terrifying little bug here. The code: + // value = filename + // in the STL case, cause the assignment method of the std::string to + // be called. What is strange, is that the std::string had the same + // address as it's c_str() method, and so bad things happen. Looks + // like a bug in the Microsoft STL implementation. + // See STL_STRING_BUG above. + // Fixed with the StringToBuffer class. + value = filename; + + FILE* file = fopen( value.c_str (), "r" ); + + if ( file ) + { + // Get the file size, so we can pre-allocate the string. HUGE speed impact. + long length = 0; + fseek( file, 0, SEEK_END ); + length = ftell( file ); + fseek( file, 0, SEEK_SET ); + + // Strange case, but good to handle up front. + if ( length == 0 ) + { + fclose( file ); + return false; + } + + // If we have a file, assume it is all one big XML file, and read it in. + // The document parser may decide the document ends sooner than the entire file, however. + TIXML_STRING data; + data.reserve( length ); + + const int BUF_SIZE = 2048; + char buf[BUF_SIZE]; + + while( fgets( buf, BUF_SIZE, file ) ) + { + data += buf; + } + fclose( file ); + + Parse( data.c_str(), 0, encoding ); + + if ( Error() ) + return false; + else + return true; + } + SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); + return false; +} + +bool TiXmlDocument::SaveFile( const char * filename ) const +{ + // The old c stuff lives on... + FILE* fp = fopen( filename, "w" ); + if ( fp ) + { + Print( fp, 0 ); + fclose( fp ); + return true; + } + return false; +} + + +void TiXmlDocument::CopyTo( TiXmlDocument* target ) const +{ + TiXmlNode::CopyTo( target ); + + target->error = error; + target->errorDesc = errorDesc.c_str (); + + TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + target->LinkEndChild( node->Clone() ); + } +} + + +TiXmlNode* TiXmlDocument::Clone() const +{ + TiXmlDocument* clone = new TiXmlDocument(); + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void TiXmlDocument::Print( FILE* cfile, int depth ) const +{ + TiXmlNode* node; + for ( node=FirstChild(); node; node=node->NextSibling() ) + { + node->Print( cfile, depth ); + fprintf( cfile, "\n" ); + } +} + +void TiXmlDocument::StreamOut( TIXML_OSTREAM * out ) const +{ + TiXmlNode* node; + for ( node=FirstChild(); node; node=node->NextSibling() ) + { + node->StreamOut( out ); + + // Special rule for streams: stop after the root element. + // The stream in code will only read one element, so don't + // write more than one. + if ( node->ToElement() ) + break; + } +} + + +TiXmlAttribute* TiXmlAttribute::Next() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} + + +TiXmlAttribute* TiXmlAttribute::Previous() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} + + +void TiXmlAttribute::Print( FILE* cfile, int /*depth*/ ) const +{ + TIXML_STRING n, v; + + PutString( name, &n ); + PutString( value, &v ); + + if (value.find ('\"') == TIXML_STRING::npos) + fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); + else + fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); +} + + +void TiXmlAttribute::StreamOut( TIXML_OSTREAM * stream ) const +{ + if (value.find( '\"' ) != TIXML_STRING::npos) + { + PutString( name, stream ); + (*stream) << "=" << "'"; + PutString( value, stream ); + (*stream) << "'"; + } + else + { + PutString( name, stream ); + (*stream) << "=" << "\""; + PutString( value, stream ); + (*stream) << "\""; + } +} + +int TiXmlAttribute::QueryIntValue( int* ival ) const +{ + if ( sscanf( value.c_str(), "%d", ival ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +int TiXmlAttribute::QueryDoubleValue( double* dval ) const +{ + if ( sscanf( value.c_str(), "%lf", dval ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +void TiXmlAttribute::SetIntValue( int _value ) +{ + char buf [64]; + sprintf (buf, "%d", _value); + SetValue (buf); +} + +void TiXmlAttribute::SetDoubleValue( double _value ) +{ + char buf [64]; + sprintf (buf, "%lf", _value); + SetValue (buf); +} + +const int TiXmlAttribute::IntValue() const +{ + return atoi (value.c_str ()); +} + +const double TiXmlAttribute::DoubleValue() const +{ + return atof (value.c_str ()); +} + + +TiXmlComment::TiXmlComment( const TiXmlComment& copy ) : TiXmlNode( TiXmlNode::COMMENT ) +{ + copy.CopyTo( this ); +} + + +void TiXmlComment::operator=( const TiXmlComment& base ) +{ + Clear(); + base.CopyTo( this ); +} + + +void TiXmlComment::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i", value.c_str() ); +} + +void TiXmlComment::StreamOut( TIXML_OSTREAM * stream ) const +{ + (*stream) << ""; +} + + +void TiXmlComment::CopyTo( TiXmlComment* target ) const +{ + TiXmlNode::CopyTo( target ); +} + + +TiXmlNode* TiXmlComment::Clone() const +{ + TiXmlComment* clone = new TiXmlComment(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void TiXmlText::Print( FILE* cfile, int /*depth*/ ) const +{ + TIXML_STRING buffer; + PutString( value, &buffer ); + fprintf( cfile, "%s", buffer.c_str() ); +} + + +void TiXmlText::StreamOut( TIXML_OSTREAM * stream ) const +{ + PutString( value, stream ); +} + + +void TiXmlText::CopyTo( TiXmlText* target ) const +{ + TiXmlNode::CopyTo( target ); +} + + +TiXmlNode* TiXmlText::Clone() const +{ + TiXmlText* clone = 0; + clone = new TiXmlText( "" ); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +TiXmlDeclaration::TiXmlDeclaration( const char * _version, + const char * _encoding, + const char * _standalone ) + : TiXmlNode( TiXmlNode::DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} + + +#ifdef TIXML_USE_STL +TiXmlDeclaration::TiXmlDeclaration( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ) + : TiXmlNode( TiXmlNode::DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} +#endif + + +TiXmlDeclaration::TiXmlDeclaration( const TiXmlDeclaration& copy ) + : TiXmlNode( TiXmlNode::DECLARATION ) +{ + copy.CopyTo( this ); +} + + +void TiXmlDeclaration::operator=( const TiXmlDeclaration& copy ) +{ + Clear(); + copy.CopyTo( this ); +} + + +void TiXmlDeclaration::Print( FILE* cfile, int /*depth*/ ) const +{ + fprintf (cfile, ""); +} + +void TiXmlDeclaration::StreamOut( TIXML_OSTREAM * stream ) const +{ + (*stream) << ""; +} + + +void TiXmlDeclaration::CopyTo( TiXmlDeclaration* target ) const +{ + TiXmlNode::CopyTo( target ); + + target->version = version; + target->encoding = encoding; + target->standalone = standalone; +} + + +TiXmlNode* TiXmlDeclaration::Clone() const +{ + TiXmlDeclaration* clone = new TiXmlDeclaration(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +void TiXmlUnknown::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i", value.c_str() ); +} + + +void TiXmlUnknown::StreamOut( TIXML_OSTREAM * stream ) const +{ + (*stream) << "<" << value << ">"; // Don't use entities here! It is unknown. +} + + +void TiXmlUnknown::CopyTo( TiXmlUnknown* target ) const +{ + TiXmlNode::CopyTo( target ); +} + + +TiXmlNode* TiXmlUnknown::Clone() const +{ + TiXmlUnknown* clone = new TiXmlUnknown(); + + if ( !clone ) + return 0; + + CopyTo( clone ); + return clone; +} + + +TiXmlAttributeSet::TiXmlAttributeSet() +{ + sentinel.next = &sentinel; + sentinel.prev = &sentinel; +} + + +TiXmlAttributeSet::~TiXmlAttributeSet() +{ + assert( sentinel.next == &sentinel ); + assert( sentinel.prev == &sentinel ); +} + + +void TiXmlAttributeSet::Add( TiXmlAttribute* addMe ) +{ + assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. + + addMe->next = &sentinel; + addMe->prev = sentinel.prev; + + sentinel.prev->next = addMe; + sentinel.prev = addMe; +} + +void TiXmlAttributeSet::Remove( TiXmlAttribute* removeMe ) +{ + TiXmlAttribute* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node == removeMe ) + { + node->prev->next = node->next; + node->next->prev = node->prev; + node->next = 0; + node->prev = 0; + return; + } + } + assert( 0 ); // we tried to remove a non-linked attribute. +} + +TiXmlAttribute* TiXmlAttributeSet::Find( const char * name ) const +{ + TiXmlAttribute* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node->name == name ) + return node; + } + return 0; +} + + +#ifdef TIXML_USE_STL +TIXML_ISTREAM & operator >> (TIXML_ISTREAM & in, TiXmlNode & base) +{ + TIXML_STRING tag; + tag.reserve( 8 * 1000 ); + base.StreamIn( &in, &tag ); + + base.Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING ); + return in; +} +#endif + + +TIXML_OSTREAM & operator<< (TIXML_OSTREAM & out, const TiXmlNode & base) +{ + base.StreamOut (& out); + return out; +} + + +#ifdef TIXML_USE_STL +std::string & operator<< (std::string& out, const TiXmlNode& base ) +{ + std::ostringstream os_stream( std::ostringstream::out ); + base.StreamOut( &os_stream ); + + out.append( os_stream.str() ); + return out; +} +#endif + + +TiXmlHandle TiXmlHandle::FirstChild() const +{ + if ( node ) + { + TiXmlNode* child = node->FirstChild(); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChild( const char * value ) const +{ + if ( node ) + { + TiXmlNode* child = node->FirstChild( value ); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChildElement() const +{ + if ( node ) + { + TiXmlElement* child = node->FirstChildElement(); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChildElement( const char * value ) const +{ + if ( node ) + { + TiXmlElement* child = node->FirstChildElement( value ); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::Child( int count ) const +{ + if ( node ) + { + int i; + TiXmlNode* child = node->FirstChild(); + for ( i=0; + child && iNextSibling(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::Child( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlNode* child = node->FirstChild( value ); + for ( i=0; + child && iNextSibling( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::ChildElement( int count ) const +{ + if ( node ) + { + int i; + TiXmlElement* child = node->FirstChildElement(); + for ( i=0; + child && iNextSiblingElement(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::ChildElement( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlElement* child = node->FirstChildElement( value ); + for ( i=0; + child && iNextSiblingElement( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} diff -ruN 1.7.41_20/tinyxmlerror.c 1.7.41_21/tinyxmlerror.c --- 1.7.41_20/tinyxmlerror.c 1970-01-01 01:00:00.000000000 +0100 +++ 1.7.41_21/tinyxmlerror.c 2013-03-19 20:56:34.000000000 +0100 @@ -0,0 +1,51 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxml.h" + +// The goal of the seperate error file is to make the first +// step towards localization. tinyxml (currently) only supports +// latin-1, but at least the error messages could now be translated. +// +// It also cleans up the code a bit. +// + +const char* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] = +{ + "No error", + "Error", + "Failed to open file", + "Memory allocation failed.", + "Error parsing Element.", + "Failed to read Element name", + "Error reading Element value.", + "Error reading Attributes.", + "Error: empty tag.", + "Error reading end tag.", + "Error parsing Unknown.", + "Error parsing Comment.", + "Error parsing Declaration.", + "Error document empty.", + "Error null (0) or unexpected EOF found in input stream.", +}; diff -ruN 1.7.41_20/tinyxml.h 1.7.41_21/tinyxml.h --- 1.7.41_20/tinyxml.h 1970-01-01 01:00:00.000000000 +0100 +++ 1.7.41_21/tinyxml.h 2013-03-19 20:56:34.000000000 +0100 @@ -0,0 +1,1370 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TINYXML_INCLUDED +#define TINYXML_INCLUDED + +#ifdef _MSC_VER +#pragma warning( disable : 4530 ) +#pragma warning( disable : 4786 ) +#endif + +#include +#include +#include +#include +#include + +// Help out windows: +#if defined( _DEBUG ) && !defined( DEBUG ) +#define DEBUG +#endif + +#if defined( DEBUG ) && defined( _MSC_VER ) +#include +#define TIXML_LOG OutputDebugString +#else +#define TIXML_LOG printf +#endif + +#ifdef TIXML_USE_STL + #include + #include + #define TIXML_STRING std::string + #define TIXML_ISTREAM std::istream + #define TIXML_OSTREAM std::ostream +#else + #include "tinystr.h" + #define TIXML_STRING TiXmlString + #define TIXML_OSTREAM TiXmlOutStream +#endif + +class TiXmlDocument; +class TiXmlElement; +class TiXmlComment; +class TiXmlUnknown; +class TiXmlAttribute; +class TiXmlText; +class TiXmlDeclaration; +class TiXmlParsingData; + +const int TIXML_MAJOR_VERSION = 2; +const int TIXML_MINOR_VERSION = 3; +const int TIXML_PATCH_VERSION = 2; + +/* Internal structure for tracking location of items + in the XML file. +*/ +struct TiXmlCursor +{ + TiXmlCursor() { Clear(); } + void Clear() { row = col = -1; } + + int row; // 0 based. + int col; // 0 based. +}; + + +// Only used by Attribute::Query functions +enum +{ + TIXML_SUCCESS, + TIXML_NO_ATTRIBUTE, + TIXML_WRONG_TYPE +}; + + +// Used by the parsing routines. +enum TiXmlEncoding +{ + TIXML_ENCODING_UNKNOWN, + TIXML_ENCODING_UTF8, + TIXML_ENCODING_LEGACY +}; + +const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; + +/** TiXmlBase is a base class for every class in TinyXml. + It does little except to establish that TinyXml classes + can be printed and provide some utility functions. + + In XML, the document and elements can contain + other elements and other types of nodes. + + @verbatim + A Document can contain: Element (container or leaf) + Comment (leaf) + Unknown (leaf) + Declaration( leaf ) + + An Element can contain: Element (container or leaf) + Text (leaf) + Attributes (not on tree) + Comment (leaf) + Unknown (leaf) + + A Decleration contains: Attributes (not on tree) + @endverbatim +*/ +class TiXmlBase +{ + friend class TiXmlNode; + friend class TiXmlElement; + friend class TiXmlDocument; + +public: + TiXmlBase() : userData(0) {} + virtual ~TiXmlBase() {} + + /** All TinyXml classes can print themselves to a filestream. + This is a formatted print, and will insert tabs and newlines. + + (For an unformatted stream, use the << operator.) + */ + virtual void Print( FILE* cfile, int depth ) const = 0; + + /** The world does not agree on whether white space should be kept or + not. In order to make everyone happy, these global, static functions + are provided to set whether or not TinyXml will condense all white space + into a single space or not. The default is to condense. Note changing this + values is not thread safe. + */ + static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } + + /// Return the current white space setting. + static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } + + /** Return the position, in the original source file, of this node or attribute. + The row and column are 1-based. (That is the first row and first column is + 1,1). If the returns values are 0 or less, then the parser does not have + a row and column value. + + Generally, the row and column value will be set when the TiXmlDocument::Load(), + TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set + when the DOM was created from operator>>. + + The values reflect the initial load. Once the DOM is modified programmatically + (by adding or changing nodes and attributes) the new values will NOT update to + reflect changes in the document. + + There is a minor performance cost to computing the row and column. Computation + can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value. + + @sa TiXmlDocument::SetTabSize() + */ + int Row() const { return location.row + 1; } + int Column() const { return location.col + 1; } ///< See Row() + + void SetUserData( void* user ) { userData = user; } + void* GetUserData() { return userData; } + + // Table that returs, for a given lead byte, the total number of bytes + // in the UTF-8 sequence. + static const int utf8ByteTable[256]; + + virtual const char* Parse( const char* p, + TiXmlParsingData* data, + TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; + +protected: + + // See STL_STRING_BUG + // Utility class to overcome a bug. + class StringToBuffer + { + public: + StringToBuffer( const TIXML_STRING& str ); + ~StringToBuffer(); + char* buffer; + }; + + static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); + inline static bool IsWhiteSpace( char c ) + { + return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); + } + + virtual void StreamOut (TIXML_OSTREAM *) const = 0; + + #ifdef TIXML_USE_STL + static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag ); + static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag ); + #endif + + /* Reads an XML name into the string provided. Returns + a pointer just past the last character of the name, + or 0 if the function has an error. + */ + static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding ); + + /* Reads text. Returns a pointer past the given end tag. + Wickedly complex options, but it keeps the (sensitive) code in one place. + */ + static const char* ReadText( const char* in, // where to start + TIXML_STRING* text, // the string read + bool ignoreWhiteSpace, // whether to keep the white space + const char* endTag, // what ends this text + bool ignoreCase, // whether to ignore case in the end tag + TiXmlEncoding encoding ); // the current encoding + + // If an entity has been found, transform it into a character. + static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding ); + + // Get a character, while interpreting entities. + // The length can be from 0 to 4 bytes. + inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding ) + { + assert( p ); + if ( encoding == TIXML_ENCODING_UTF8 ) + { + *length = utf8ByteTable[ *((unsigned char*)p) ]; + assert( *length >= 0 && *length < 5 ); + } + else + { + *length = 1; + } + + if ( *length == 1 ) + { + if ( *p == '&' ) + return GetEntity( p, _value, length, encoding ); + *_value = *p; + return p+1; + } + else if ( *length ) + { + strncpy( _value, p, *length ); + return p + (*length); + } + else + { + // Not valid text. + return 0; + } + } + + // Puts a string to a stream, expanding entities as it goes. + // Note this should not contian the '<', '>', etc, or they will be transformed into entities! + static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out ); + + static void PutString( const TIXML_STRING& str, TIXML_STRING* out ); + + // Return true if the next characters in the stream are any of the endTag sequences. + // Ignore case only works for english, and should only be relied on when comparing + // to Engilish words: StringEqual( p, "version", true ) is fine. + static bool StringEqual( const char* p, + const char* endTag, + bool ignoreCase, + TiXmlEncoding encoding ); + + + enum + { + TIXML_NO_ERROR = 0, + TIXML_ERROR, + TIXML_ERROR_OPENING_FILE, + TIXML_ERROR_OUT_OF_MEMORY, + TIXML_ERROR_PARSING_ELEMENT, + TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, + TIXML_ERROR_READING_ELEMENT_VALUE, + TIXML_ERROR_READING_ATTRIBUTES, + TIXML_ERROR_PARSING_EMPTY, + TIXML_ERROR_READING_END_TAG, + TIXML_ERROR_PARSING_UNKNOWN, + TIXML_ERROR_PARSING_COMMENT, + TIXML_ERROR_PARSING_DECLARATION, + TIXML_ERROR_DOCUMENT_EMPTY, + TIXML_ERROR_EMBEDDED_NULL, + + TIXML_ERROR_STRING_COUNT + }; + static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; + + TiXmlCursor location; + + /// Field containing a generic user pointer + void* userData; + + // None of these methods are reliable for any language except English. + // Good for approximation, not great for accuracy. + static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding ); + static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding ); + inline static int ToLower( int v, TiXmlEncoding encoding ) + { + if ( encoding == TIXML_ENCODING_UTF8 ) + { + if ( v < 128 ) return tolower( v ); + return v; + } + else + { + return tolower( v ); + } + } + static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); + +private: + TiXmlBase( const TiXmlBase& ); // not implemented. + void operator=( const TiXmlBase& base ); // not allowed. + + struct Entity + { + const char* str; + unsigned int strLength; + char chr; + }; + enum + { + NUM_ENTITY = 5, + MAX_ENTITY_LENGTH = 6 + + }; + static Entity entity[ NUM_ENTITY ]; + static bool condenseWhiteSpace; +}; + + +/** The parent class for everything in the Document Object Model. + (Except for attributes). + Nodes have siblings, a parent, and children. A node can be + in a document, or stand on its own. The type of a TiXmlNode + can be queried, and it can be cast to its more defined type. +*/ +class TiXmlNode : public TiXmlBase +{ + friend class TiXmlDocument; + friend class TiXmlElement; + +public: + #ifdef TIXML_USE_STL + + /** An input stream operator, for every class. Tolerant of newlines and + formatting, but doesn't expect them. + */ + friend std::istream& operator >> (std::istream& in, TiXmlNode& base); + + /** An output stream operator, for every class. Note that this outputs + without any newlines or formatting, as opposed to Print(), which + includes tabs and new lines. + + The operator<< and operator>> are not completely symmetric. Writing + a node to a stream is very well defined. You'll get a nice stream + of output, without any extra whitespace or newlines. + + But reading is not as well defined. (As it always is.) If you create + a TiXmlElement (for example) and read that from an input stream, + the text needs to define an element or junk will result. This is + true of all input streams, but it's worth keeping in mind. + + A TiXmlDocument will read nodes until it reads a root element, and + all the children of that root element. + */ + friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); + + /// Appends the XML node or attribute to a std::string. + friend std::string& operator<< (std::string& out, const TiXmlNode& base ); + + #else + // Used internally, not part of the public API. + friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base); + #endif + + /** The types of XML nodes supported by TinyXml. (All the + unsupported types are picked up by UNKNOWN.) + */ + enum NodeType + { + DOCUMENT, + ELEMENT, + COMMENT, + UNKNOWN, + TEXT, + DECLARATION, + TYPECOUNT + }; + + virtual ~TiXmlNode(); + + /** The meaning of 'value' changes for the specific type of + TiXmlNode. + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + + The subclasses will wrap this function. + */ + const char * Value() const { return value.c_str (); } + + /** Changes the value of the node. Defined as: + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + */ + void SetValue(const char * _value) { value = _value;} + + #ifdef TIXML_USE_STL + /// STL std::string form. + void SetValue( const std::string& _value ) + { + StringToBuffer buf( _value ); + SetValue( buf.buffer ? buf.buffer : "" ); + } + #endif + + /// Delete all the children of this node. Does not affect 'this'. + void Clear(); + + /// One step up the DOM. + TiXmlNode* Parent() const { return parent; } + + TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. + TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. + + TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. + TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. + + #ifdef TIXML_USE_STL + TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. + #endif + + /** An alternate way to walk the children of a node. + One way to iterate over nodes is: + @verbatim + for( child = parent->FirstChild(); child; child = child->NextSibling() ) + @endverbatim + + IterateChildren does the same thing with the syntax: + @verbatim + child = 0; + while( child = parent->IterateChildren( child ) ) + @endverbatim + + IterateChildren takes the previous child as input and finds + the next one. If the previous child is null, it returns the + first. IterateChildren will return null when done. + */ + TiXmlNode* IterateChildren( TiXmlNode* previous ) const; + + /// This flavor of IterateChildren searches for children with a particular 'value' + TiXmlNode* IterateChildren( const char * value, TiXmlNode* previous ) const; + + #ifdef TIXML_USE_STL + TiXmlNode* IterateChildren( const std::string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. + #endif + + /** Add a new node related to this. Adds a child past the LastChild. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); + + + /** Add a new node related to this. Adds a child past the LastChild. + + NOTE: the node to be added is passed by pointer, and will be + henceforth owned (and deleted) by tinyXml. This method is efficient + and avoids an extra copy, but should be used with care as it + uses a different memory model than the other insert functions. + + @sa InsertEndChild + */ + TiXmlNode* LinkEndChild( TiXmlNode* addThis ); + + /** Add a new node related to this. Adds a child before the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ); + + /** Add a new node related to this. Adds a child after the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ); + + /** Replace a child of this node. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ); + + /// Delete a child of this node. + bool RemoveChild( TiXmlNode* removeThis ); + + /// Navigate to a sibling node. + TiXmlNode* PreviousSibling() const { return prev; } + + /// Navigate to a sibling node. + TiXmlNode* PreviousSibling( const char * ) const; + + #ifdef TIXML_USE_STL + TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. + TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Navigate to a sibling node. + TiXmlNode* NextSibling() const { return next; } + + /// Navigate to a sibling node with the given 'value'. + TiXmlNode* NextSibling( const char * ) const; + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + TiXmlElement* NextSiblingElement() const; + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + TiXmlElement* NextSiblingElement( const char * ) const; + + #ifdef TIXML_USE_STL + TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Convenience function to get through elements. + TiXmlElement* FirstChildElement() const; + + /// Convenience function to get through elements. + TiXmlElement* FirstChildElement( const char * value ) const; + + #ifdef TIXML_USE_STL + TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /** Query the type (as an enumerated value, above) of this node. + The possible types are: DOCUMENT, ELEMENT, COMMENT, + UNKNOWN, TEXT, and DECLARATION. + */ + virtual int Type() const { return type; } + + /** Return a pointer to the Document this node lives in. + Returns null if not in a document. + */ + TiXmlDocument* GetDocument() const; + + /// Returns true if this node has no children. + bool NoChildren() const { return !firstChild; } + + TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + + /** Create an exact duplicate of this node and return it. The memory must be deleted + by the caller. + */ + virtual TiXmlNode* Clone() const = 0; + +protected: + TiXmlNode( NodeType _type ); + + // Copy to the allocated object. Shared functionality between Clone, Copy constructor, + // and the assignment operator. + void CopyTo( TiXmlNode* target ) const; + + #ifdef TIXML_USE_STL + // The real work of the input operator. + virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0; + #endif + + // Figure out what is at *p, and parse it. Returns null if it is not an xml node. + TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); + + // Internal Value function returning a TIXML_STRING + const TIXML_STRING& SValue() const { return value ; } + + TiXmlNode* parent; + NodeType type; + + TiXmlNode* firstChild; + TiXmlNode* lastChild; + + TIXML_STRING value; + + TiXmlNode* prev; + TiXmlNode* next; + +private: + TiXmlNode( const TiXmlNode& ); // not implemented. + void operator=( const TiXmlNode& base ); // not allowed. +}; + + +/** An attribute is a name-value pair. Elements have an arbitrary + number of attributes, each with a unique name. + + @note The attributes are not TiXmlNodes, since they are not + part of the tinyXML document object model. There are other + suggested ways to look at this problem. +*/ +class TiXmlAttribute : public TiXmlBase +{ + friend class TiXmlAttributeSet; + +public: + /// Construct an empty attribute. + TiXmlAttribute() : TiXmlBase() + { + document = 0; + prev = next = 0; + } + + #ifdef TIXML_USE_STL + /// std::string constructor. + TiXmlAttribute( const std::string& _name, const std::string& _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + #endif + + /// Construct an attribute with a name and value. + TiXmlAttribute( const char * _name, const char * _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + + const char* Name() const { return name.c_str (); } ///< Return the name of this attribute. + const char* Value() const { return value.c_str (); } ///< Return the value of this attribute. + const int IntValue() const; ///< Return the value of this attribute, converted to an integer. + const double DoubleValue() const; ///< Return the value of this attribute, converted to a double. + + /** QueryIntValue examines the value string. It is an alternative to the + IntValue() method with richer error checking. + If the value is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. + + A specialized but useful call. Note that for success it returns 0, + which is the opposite of almost all other TinyXml calls. + */ + int QueryIntValue( int* value ) const; + /// QueryDoubleValue examines the value string. See QueryIntValue(). + int QueryDoubleValue( double* value ) const; + + void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. + void SetValue( const char* _value ) { value = _value; } ///< Set the value. + + void SetIntValue( int value ); ///< Set the value from an integer. + void SetDoubleValue( double value ); ///< Set the value from a double. + + #ifdef TIXML_USE_STL + /// STL std::string form. + void SetName( const std::string& _name ) + { + StringToBuffer buf( _name ); + SetName ( buf.buffer ? buf.buffer : "error" ); + } + /// STL std::string form. + void SetValue( const std::string& _value ) + { + StringToBuffer buf( _value ); + SetValue( buf.buffer ? buf.buffer : "error" ); + } + #endif + + /// Get the next sibling attribute in the DOM. Returns null at end. + TiXmlAttribute* Next() const; + /// Get the previous sibling attribute in the DOM. Returns null at beginning. + TiXmlAttribute* Previous() const; + + bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } + bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } + bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; } + + /* Attribute parsing starts: first letter of the name + returns: the next char after the value end quote + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + + // Prints this Attribute to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + virtual void StreamOut( TIXML_OSTREAM * out ) const; + // [internal use] + // Set the document pointer so the attribute can report errors. + void SetDocument( TiXmlDocument* doc ) { document = doc; } + +private: + TiXmlAttribute( const TiXmlAttribute& ); // not implemented. + void operator=( const TiXmlAttribute& base ); // not allowed. + + TiXmlDocument* document; // A pointer back to a document, for error reporting. + TIXML_STRING name; + TIXML_STRING value; + TiXmlAttribute* prev; + TiXmlAttribute* next; +}; + + +/* A class used to manage a group of attributes. + It is only used internally, both by the ELEMENT and the DECLARATION. + + The set can be changed transparent to the Element and Declaration + classes that use it, but NOT transparent to the Attribute + which has to implement a next() and previous() method. Which makes + it a bit problematic and prevents the use of STL. + + This version is implemented with circular lists because: + - I like circular lists + - it demonstrates some independence from the (typical) doubly linked list. +*/ +class TiXmlAttributeSet +{ +public: + TiXmlAttributeSet(); + ~TiXmlAttributeSet(); + + void Add( TiXmlAttribute* attribute ); + void Remove( TiXmlAttribute* attribute ); + + TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + TiXmlAttribute* Find( const char * name ) const; + +private: + TiXmlAttribute sentinel; +}; + + +/** The element is a container class. It has a value, the element name, + and can contain other elements, text, comments, and unknowns. + Elements also contain an arbitrary number of attributes. +*/ +class TiXmlElement : public TiXmlNode +{ +public: + /// Construct an element. + TiXmlElement (const char * in_value); + + #ifdef TIXML_USE_STL + /// std::string constructor. + TiXmlElement( const std::string& _value ); + #endif + + TiXmlElement( const TiXmlElement& ); + + void operator=( const TiXmlElement& base ); + + virtual ~TiXmlElement(); + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + */ + const char* Attribute( const char* name ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an integer, + the integer value will be put in the return 'i', if 'i' + is non-null. + */ + const char* Attribute( const char* name, int* i ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an double, + the double value will be put in the return 'd', if 'd' + is non-null. + */ + const char* Attribute( const char* name, double* d ) const; + + /** QueryIntAttribute examines the attribute - it is an alternative to the + Attribute() method with richer error checking. + If the attribute is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. If the attribute + does not exist, then TIXML_NO_ATTRIBUTE is returned. + */ + int QueryIntAttribute( const char* name, int* value ) const; + /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). + int QueryDoubleAttribute( const char* name, double* value ) const; + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char* name, const char * value ); + + #ifdef TIXML_USE_STL + const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); } + const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); } + const char* Attribute( const std::string& name, double* d ) const { return Attribute( name.c_str(), d ); } + int QueryIntAttribute( const std::string& name, int* value ) const { return QueryIntAttribute( name.c_str(), value ); } + int QueryDoubleAttribute( const std::string& name, double* value ) const { return QueryDoubleAttribute( name.c_str(), value ); } + + /// STL std::string form. + void SetAttribute( const std::string& name, const std::string& _value ) + { + StringToBuffer n( name ); + StringToBuffer v( _value ); + if ( n.buffer && v.buffer ) + SetAttribute (n.buffer, v.buffer ); + } + ///< STL std::string form. + void SetAttribute( const std::string& name, int _value ) + { + StringToBuffer n( name ); + if ( n.buffer ) + SetAttribute (n.buffer, _value); + } + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char * name, int value ); + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetDoubleAttribute( const char * name, double value ); + + /** Deletes an attribute with the given name. + */ + void RemoveAttribute( const char * name ); + #ifdef TIXML_USE_STL + void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. + #endif + + TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. + TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. + + /// Creates a new Element and returns it - the returned element is a copy. + virtual TiXmlNode* Clone() const; + // Print the Element to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /* Attribtue parsing starts: next char past '<' + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + +protected: + + void CopyTo( TiXmlElement* target ) const; + void ClearThis(); // like clear, but initializes 'this' object as well + + // Used to be public [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + virtual void StreamOut( TIXML_OSTREAM * out ) const; + + /* [internal use] + Reads the "value" of the element -- another element, or text. + This should terminate with the current end tag. + */ + const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding ); + +private: + + TiXmlAttributeSet attributeSet; +}; + + +/** An XML comment. +*/ +class TiXmlComment : public TiXmlNode +{ +public: + /// Constructs an empty comment. + TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {} + TiXmlComment( const TiXmlComment& ); + void operator=( const TiXmlComment& base ); + + virtual ~TiXmlComment() {} + + /// Returns a copy of this Comment. + virtual TiXmlNode* Clone() const; + /// Write this Comment to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + /* Attribtue parsing starts: at the ! of the !-- + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + +protected: + void CopyTo( TiXmlComment* target ) const; + + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + virtual void StreamOut( TIXML_OSTREAM * out ) const; + +private: + +}; + + +/** XML text. Contained in an element. +*/ +class TiXmlText : public TiXmlNode +{ + friend class TiXmlElement; +public: + /// Constructor. + TiXmlText (const char * initValue) : TiXmlNode (TiXmlNode::TEXT) + { + SetValue( initValue ); + } + virtual ~TiXmlText() {} + + #ifdef TIXML_USE_STL + /// Constructor. + TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT) + { + SetValue( initValue ); + } + #endif + + TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); } + void operator=( const TiXmlText& base ) { base.CopyTo( this ); } + + /// Write this text object to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + +protected : + /// [internal use] Creates a new Element and returns it. + virtual TiXmlNode* Clone() const; + void CopyTo( TiXmlText* target ) const; + + virtual void StreamOut ( TIXML_OSTREAM * out ) const; + bool Blank() const; // returns true if all white space and new lines + // [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + +private: +}; + + +/** In correct XML the declaration is the first entry in the file. + @verbatim + + @endverbatim + + TinyXml will happily read or write files without a declaration, + however. There are 3 possible attributes to the declaration: + version, encoding, and standalone. + + Note: In this version of the code, the attributes are + handled as special cases, not generic attributes, simply + because there can only be at most 3 and they are always the same. +*/ +class TiXmlDeclaration : public TiXmlNode +{ +public: + /// Construct an empty declaration. + TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {} + +#ifdef TIXML_USE_STL + /// Constructor. + TiXmlDeclaration( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ); +#endif + + /// Construct. + TiXmlDeclaration( const char* _version, + const char* _encoding, + const char* _standalone ); + + TiXmlDeclaration( const TiXmlDeclaration& copy ); + void operator=( const TiXmlDeclaration& copy ); + + virtual ~TiXmlDeclaration() {} + + /// Version. Will return an empty string if none was found. + const char *Version() const { return version.c_str (); } + /// Encoding. Will return an empty string if none was found. + const char *Encoding() const { return encoding.c_str (); } + /// Is this a standalone document? + const char *Standalone() const { return standalone.c_str (); } + + /// Creates a copy of this Declaration and returns it. + virtual TiXmlNode* Clone() const; + /// Print this declaration to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + +protected: + void CopyTo( TiXmlDeclaration* target ) const; + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + virtual void StreamOut ( TIXML_OSTREAM * out) const; + +private: + + TIXML_STRING version; + TIXML_STRING encoding; + TIXML_STRING standalone; +}; + + +/** Any tag that tinyXml doesn't recognize is saved as an + unknown. It is a tag of text, but should not be modified. + It will be written back to the XML, unchanged, when the file + is saved. + + DTD tags get thrown into TiXmlUnknowns. +*/ +class TiXmlUnknown : public TiXmlNode +{ +public: + TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {} + virtual ~TiXmlUnknown() {} + + TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); } + void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); } + + /// Creates a copy of this Unknown and returns it. + virtual TiXmlNode* Clone() const; + /// Print this Unknown to a FILE stream. + virtual void Print( FILE* cfile, int depth ) const; + + virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); + +protected: + void CopyTo( TiXmlUnknown* target ) const; + + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + virtual void StreamOut ( TIXML_OSTREAM * out ) const; + +private: + +}; + + +/** Always the top level node. A document binds together all the + XML pieces. It can be saved, loaded, and printed to the screen. + The 'value' of a document node is the xml file name. +*/ +class TiXmlDocument : public TiXmlNode +{ +public: + /// Create an empty document, that has no name. + TiXmlDocument(); + /// Create a document with a name. The name of the document is also the filename of the xml. + TiXmlDocument( const char * documentName ); + + #ifdef TIXML_USE_STL + /// Constructor. + TiXmlDocument( const std::string& documentName ); + #endif + + TiXmlDocument( const TiXmlDocument& copy ); + void operator=( const TiXmlDocument& copy ); + + virtual ~TiXmlDocument() {} + + /** Load a file using the current document value. + Returns true if successful. Will delete any existing + document data before loading. + */ + bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the current document value. Returns true if successful. + bool SaveFile() const; + /// Load a file using the given filename. Returns true if successful. + bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + /// Save a file using the given filename. Returns true if successful. + bool SaveFile( const char * filename ) const; + + #ifdef TIXML_USE_STL + bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. + { + StringToBuffer f( filename ); + return ( f.buffer && LoadFile( f.buffer, encoding )); + } + bool SaveFile( const std::string& filename ) const ///< STL std::string version. + { + StringToBuffer f( filename ); + return ( f.buffer && SaveFile( f.buffer )); + } + #endif + + /** Parse the given null terminated block of xml data. Passing in an encoding to this + method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml + to use that encoding, regardless of what TinyXml might otherwise try to detect. + */ + virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); + + /** Get the root element -- the only top level element -- of the document. + In well formed XML, there should only be one. TinyXml is tolerant of + multiple elements at the document level. + */ + TiXmlElement* RootElement() const { return FirstChildElement(); } + + /** If an error occurs, Error will be set to true. Also, + - The ErrorId() will contain the integer identifier of the error (not generally useful) + - The ErrorDesc() method will return the name of the error. (very useful) + - The ErrorRow() and ErrorCol() will return the location of the error (if known) + */ + bool Error() const { return error; } + + /// Contains a textual (english) description of the error if one occurs. + const char * ErrorDesc() const { return errorDesc.c_str (); } + + /** Generally, you probably want the error string ( ErrorDesc() ). But if you + prefer the ErrorId, this function will fetch it. + */ + const int ErrorId() const { return errorId; } + + /** Returns the location (if known) of the error. The first column is column 1, + and the first row is row 1. A value of 0 means the row and column wasn't applicable + (memory errors, for example, have no row/column) or the parser lost the error. (An + error in the error reporting, in that case.) + + @sa SetTabSize, Row, Column + */ + int ErrorRow() { return errorLocation.row+1; } + int ErrorCol() { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() + + /** By calling this method, with a tab size + greater than 0, the row and column of each node and attribute is stored + when the file is loaded. Very useful for tracking the DOM back in to + the source file. + + The tab size is required for calculating the location of nodes. If not + set, the default of 4 is used. The tabsize is set per document. Setting + the tabsize to 0 disables row/column tracking. + + Note that row and column tracking is not supported when using operator>>. + + The tab size needs to be enabled before the parse or load. Correct usage: + @verbatim + TiXmlDocument doc; + doc.SetTabSize( 8 ); + doc.Load( "myfile.xml" ); + @endverbatim + + @sa Row, Column + */ + void SetTabSize( int _tabsize ) { tabsize = _tabsize; } + + int TabSize() const { return tabsize; } + + /** If you have handled the error, it can be reset with this call. The error + state is automatically cleared if you Parse a new XML block. + */ + void ClearError() { error = false; + errorId = 0; + errorDesc = ""; + errorLocation.row = errorLocation.col = 0; + //errorLocation.last = 0; + } + + /** Dump the document to standard out. */ + void Print() const { Print( stdout, 0 ); } + + /// Print this Document to a FILE stream. + virtual void Print( FILE* cfile, int depth = 0 ) const; + // [internal use] + void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding ); + +protected : + virtual void StreamOut ( TIXML_OSTREAM * out) const; + // [internal use] + virtual TiXmlNode* Clone() const; + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + +private: + void CopyTo( TiXmlDocument* target ) const; + + bool error; + int errorId; + TIXML_STRING errorDesc; + int tabsize; + TiXmlCursor errorLocation; +}; + + +/** + A TiXmlHandle is a class that wraps a node pointer with null checks; this is + an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml + DOM structure. It is a separate utility class. + + Take an example: + @verbatim + + + + + + + @endverbatim + + Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very + easy to write a *lot* of code that looks like: + + @verbatim + TiXmlElement* root = document.FirstChildElement( "Document" ); + if ( root ) + { + TiXmlElement* element = root->FirstChildElement( "Element" ); + if ( element ) + { + TiXmlElement* child = element->FirstChildElement( "Child" ); + if ( child ) + { + TiXmlElement* child2 = child->NextSiblingElement( "Child" ); + if ( child2 ) + { + // Finally do something useful. + @endverbatim + + And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity + of such code. A TiXmlHandle checks for null pointers so it is perfectly safe + and correct to use: + + @verbatim + TiXmlHandle docHandle( &document ); + TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).Element(); + if ( child2 ) + { + // do something useful + @endverbatim + + Which is MUCH more concise and useful. + + It is also safe to copy handles - internally they are nothing more than node pointers. + @verbatim + TiXmlHandle handleCopy = handle; + @endverbatim + + What they should not be used for is iteration: + + @verbatim + int i=0; + while ( true ) + { + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).Element(); + if ( !child ) + break; + // do something + ++i; + } + @endverbatim + + It seems reasonable, but it is in fact two embedded while loops. The Child method is + a linear walk to find the element, so this code would iterate much more than it needs + to. Instead, prefer: + + @verbatim + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).Element(); + + for( child; child; child=child->NextSiblingElement() ) + { + // do something + } + @endverbatim +*/ +class TiXmlHandle +{ +public: + /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. + TiXmlHandle( TiXmlNode* node ) { this->node = node; } + /// Copy constructor + TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } + TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; } + + /// Return a handle to the first child node. + TiXmlHandle FirstChild() const; + /// Return a handle to the first child node with the given name. + TiXmlHandle FirstChild( const char * value ) const; + /// Return a handle to the first child element. + TiXmlHandle FirstChildElement() const; + /// Return a handle to the first child element with the given name. + TiXmlHandle FirstChildElement( const char * value ) const; + + /** Return a handle to the "index" child with the given name. + The first child is 0, the second 1, etc. + */ + TiXmlHandle Child( const char* value, int index ) const; + /** Return a handle to the "index" child. + The first child is 0, the second 1, etc. + */ + TiXmlHandle Child( int index ) const; + /** Return a handle to the "index" child element with the given name. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandle ChildElement( const char* value, int index ) const; + /** Return a handle to the "index" child element. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandle ChildElement( int index ) const; + + #ifdef TIXML_USE_STL + TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } + TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } + + TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } + TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } + #endif + + /// Return the handle as a TiXmlNode. This may return null. + TiXmlNode* Node() const { return node; } + /// Return the handle as a TiXmlElement. This may return null. + TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } + /// Return the handle as a TiXmlText. This may return null. + TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } + /// Return the handle as a TiXmlUnknown. This may return null; + TiXmlUnknown* Unknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } + +private: + TiXmlNode* node; +}; + + +#endif diff -ruN 1.7.41_20/tinyxmlparser.c 1.7.41_21/tinyxmlparser.c --- 1.7.41_20/tinyxmlparser.c 1970-01-01 01:00:00.000000000 +0100 +++ 1.7.41_21/tinyxmlparser.c 2013-03-19 20:56:34.000000000 +0100 @@ -0,0 +1,1492 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxml.h" +#include + +//#define DEBUG_PARSER + +// Note tha "PutString" hardcodes the same list. This +// is less flexible than it appears. Changing the entries +// or order will break putstring. +TiXmlBase::Entity TiXmlBase::entity[ NUM_ENTITY ] = +{ + { "&", 5, '&' }, + { "<", 4, '<' }, + { ">", 4, '>' }, + { """, 6, '\"' }, + { "'", 6, '\'' } +}; + +// Bunch of unicode info at: +// http://www.unicode.org/faq/utf_bom.html +// Including the basic of this table, which determines the #bytes in the +// sequence from the lead byte. 1 placed for invalid sequences -- +// although the result will be junk, pass it through as much as possible. +// Beware of the non-characters in UTF-8: +// ef bb bf (Microsoft "lead bytes") +// ef bf be +// ef bf bf + + + +const int TiXmlBase::utf8ByteTable[256] = +{ + // 0 1 2 3 4 5 6 7 8 9 a b c d e f + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 + 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte + 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid +}; + + +void TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) +{ + const unsigned long BYTE_MASK = 0xBF; + const unsigned long BYTE_MARK = 0x80; + const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; + + if (input < 0x80) + *length = 1; + else if ( input < 0x800 ) + *length = 2; + else if ( input < 0x10000 ) + *length = 3; + else if ( input < 0x200000 ) + *length = 4; + else + { *length = 0; return; } // This code won't covert this correctly anyway. + + output += *length; + + // Scary scary fall throughs. + switch (*length) + { + case 4: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 3: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 2: + --output; + *output = (char)((input | BYTE_MARK) & BYTE_MASK); + input >>= 6; + case 1: + --output; + *output = (char)(input | FIRST_BYTE_MARK[*length]); + } +} + + +/*static*/ int TiXmlBase::IsAlpha( unsigned char anyByte, TiXmlEncoding encoding ) +{ + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky trying + // to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + +// if ( encoding == TIXML_ENCODING_UTF8 ) +// { + if ( anyByte < 127 ) + return isalpha( anyByte ); + else + return 1; // What else to do? The unicode set is huge...get the english ones right. +// } +// else +// { +// return isalpha( anyByte ); +// } +} + + +/*static*/ int TiXmlBase::IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding ) +{ + // This will only work for low-ascii, everything else is assumed to be a valid + // letter. I'm not sure this is the best approach, but it is quite tricky trying + // to figure out alhabetical vs. not across encoding. So take a very + // conservative approach. + +// if ( encoding == TIXML_ENCODING_UTF8 ) +// { + if ( anyByte < 127 ) + return isalnum( anyByte ); + else + return 1; // What else to do? The unicode set is huge...get the english ones right. +// } +// else +// { +// return isalnum( anyByte ); +// } +} + + +class TiXmlParsingData +{ + friend class TiXmlDocument; + public: + void Stamp( const char* now, TiXmlEncoding encoding ); + + const TiXmlCursor& Cursor() { return cursor; } + + private: + // Only used by the document! + TiXmlParsingData( const char* start, int _tabsize, int row, int col ) + { + assert( start ); + stamp = start; + tabsize = _tabsize; + cursor.row = row; + cursor.col = col; + } + + TiXmlCursor cursor; + const char* stamp; + int tabsize; +}; + + +void TiXmlParsingData::Stamp( const char* now, TiXmlEncoding encoding ) +{ + assert( now ); + + // Do nothing if the tabsize is 0. + if ( tabsize < 1 ) + { + return; + } + + // Get the current row, column. + int row = cursor.row; + int col = cursor.col; + const char* p = stamp; + assert( p ); + + while ( p < now ) + { + // Code contributed by Fletcher Dunn: (modified by lee) + switch (*p) { + case 0: + // We *should* never get here, but in case we do, don't + // advance past the terminating null character, ever + return; + + case '\r': + // bump down to the next line + ++row; + col = 0; + // Eat the character + ++p; + + // Check for \r\n sequence, and treat this as a single character + if (*p == '\n') { + ++p; + } + break; + + case '\n': + // bump down to the next line + ++row; + col = 0; + + // Eat the character + ++p; + + // Check for \n\r sequence, and treat this as a single + // character. (Yes, this bizarre thing does occur still + // on some arcane platforms...) + if (*p == '\r') { + ++p; + } + break; + + case '\t': + // Eat the character + ++p; + + // Skip to next tab stop + col = (col / tabsize + 1) * tabsize; + break; + + case (char)(0xef): + if ( encoding == TIXML_ENCODING_UTF8 ) + { + if ( *(p+1) && *(p+2) ) + { + // In these cases, don't advance the column. These are + // 0-width spaces. + if ( *(p+1)==(char)(0xbb) && *(p+2)==(char)(0xbf) ) + p += 3; + else if ( *(p+1)==(char)(0xbf) && *(p+2)==(char)(0xbe) ) + p += 3; + else if ( *(p+1)==(char)(0xbf) && *(p+2)==(char)(0xbf) ) + p += 3; + else + { p +=3; ++col; } // A normal character. + } + } + else + { + ++p; + ++col; + } + break; + + default: + if ( encoding == TIXML_ENCODING_UTF8 ) + { + // Eat the 1 to 4 byte utf8 character. + int step = TiXmlBase::utf8ByteTable[*((unsigned char*)p)]; + if ( step == 0 ) + step = 1; // Error case from bad encoding, but handle gracefully. + p += step; + + // Just advance one column, of course. + ++col; + } + else + { + ++p; + ++col; + } + break; + } + } + cursor.row = row; + cursor.col = col; + assert( cursor.row >= -1 ); + assert( cursor.col >= -1 ); + stamp = p; + assert( stamp ); +} + + +const char* TiXmlBase::SkipWhiteSpace( const char* p, TiXmlEncoding encoding ) +{ + if ( !p || !*p ) + { + return 0; + } + if ( encoding == TIXML_ENCODING_UTF8 ) + { + while ( *p ) + { + // Skip the stupid Microsoft UTF-8 Byte order marks + if ( *(p+0)==(char) 0xef + && *(p+1)==(char) 0xbb + && *(p+2)==(char) 0xbf ) + { + p += 3; + continue; + } + else if(*(p+0)==(char) 0xef + && *(p+1)==(char) 0xbf + && *(p+2)==(char) 0xbe ) + { + p += 3; + continue; + } + else if(*(p+0)==(char) 0xef + && *(p+1)==(char) 0xbf + && *(p+2)==(char) 0xbf ) + { + p += 3; + continue; + } + + if ( IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' ) // Still using old rules for white space. + ++p; + else + break; + } + } + else + { + while ( *p && IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' ) + ++p; + } + + return p; +} + +#ifdef TIXML_USE_STL +/*static*/ bool TiXmlBase::StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag ) +{ + for( ;; ) + { + if ( !in->good() ) return false; + + int c = in->peek(); + // At this scope, we can't get to a document. So fail silently. + if ( !IsWhiteSpace( c ) || c <= 0 ) + return true; + + *tag += (char) in->get(); + } +} + +/*static*/ bool TiXmlBase::StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag ) +{ + //assert( character > 0 && character < 128 ); // else it won't work in utf-8 + while ( in->good() ) + { + int c = in->peek(); + if ( c == character ) + return true; + if ( c <= 0 ) // Silent failure: can't get document at this scope + return false; + + in->get(); + *tag += (char) c; + } + return false; +} +#endif + +const char* TiXmlBase::ReadName( const char* p, TIXML_STRING * name, TiXmlEncoding encoding ) +{ + *name = ""; + assert( p ); + + // Names start with letters or underscores. + // Of course, in unicode, tinyxml has no idea what a letter *is*. The + // algorithm is generous. + // + // After that, they can be letters, underscores, numbers, + // hyphens, or colons. (Colons are valid ony for namespaces, + // but tinyxml can't tell namespaces from names.) + if ( p && *p + && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) + { + while( p && *p + && ( IsAlphaNum( (unsigned char ) *p, encoding ) + || *p == '_' + || *p == '-' + || *p == '.' + || *p == ':' ) ) + { + (*name) += *p; + ++p; + } + return p; + } + return 0; +} + +const char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding ) +{ + // Presume an entity, and pull it out. + TIXML_STRING ent; + int i; + *length = 0; + + if ( *(p+1) && *(p+1) == '#' && *(p+2) ) + { + unsigned long ucs = 0; + unsigned delta = 0; + unsigned mult = 1; + + if ( *(p+2) == 'x' ) + { + // Hexadecimal. + if ( !*(p+3) ) return 0; + + const char* q = p+3; + q = strchr( q, ';' ); + + if ( !q || !*q ) return 0; + + delta = q-p; + --q; + + while ( *q != 'x' ) + { + if ( *q >= '0' && *q <= '9' ) + ucs += mult * (*q - '0'); + else if ( *q >= 'a' && *q <= 'f' ) + ucs += mult * (*q - 'a' + 10); + else if ( *q >= 'A' && *q <= 'F' ) + ucs += mult * (*q - 'A' + 10 ); + else + return 0; + mult *= 16; + --q; + } + } + else + { + // Decimal. + if ( !*(p+2) ) return 0; + + const char* q = p+2; + q = strchr( q, ';' ); + + if ( !q || !*q ) return 0; + + delta = q-p; + --q; + + while ( *q != '#' ) + { + if ( *q >= '0' && *q <= '9' ) + ucs += mult * (*q - '0'); + else + return 0; + mult *= 10; + --q; + } + } + if ( encoding == TIXML_ENCODING_UTF8 ) + { + // convert the UCS to UTF-8 + ConvertUTF32ToUTF8( ucs, value, length ); + } + else + { + *value = (char)ucs; + *length = 1; + } + return p + delta + 1; + } + + // Now try to match it. + for( i=0; iappend( cArr, len ); + } + } + else + { + bool whitespace = false; + + // Remove leading white space: + p = SkipWhiteSpace( p, encoding ); + while ( p && *p + && !StringEqual( p, endTag, caseInsensitive, encoding ) ) + { + if ( *p == '\r' || *p == '\n' ) + { + whitespace = true; + ++p; + } + else if ( IsWhiteSpace( *p ) ) + { + whitespace = true; + ++p; + } + else + { + // If we've found whitespace, add it before the + // new character. Any whitespace just becomes a space. + if ( whitespace ) + { + (*text) += ' '; + whitespace = false; + } + int len; + char cArr[4] = { 0, 0, 0, 0 }; + p = GetChar( p, cArr, &len, encoding ); + if ( len == 1 ) + (*text) += cArr[0]; // more efficient + else + text->append( cArr, len ); + } + } + } + return p + strlen( endTag ); +} + +#ifdef TIXML_USE_STL + +void TiXmlDocument::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ) +{ + // The basic issue with a document is that we don't know what we're + // streaming. Read something presumed to be a tag (and hope), then + // identify it, and call the appropriate stream method on the tag. + // + // This "pre-streaming" will never read the closing ">" so the + // sub-tag can orient itself. + + if ( !StreamTo( in, '<', tag ) ) + { + SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + + while ( in->good() ) + { + int tagIndex = (int) tag->length(); + while ( in->good() && in->peek() != '>' ) + { + int c = in->get(); + if ( c <= 0 ) + { + SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + break; + } + (*tag) += (char) c; + } + + if ( in->good() ) + { + // We now have something we presume to be a node of + // some sort. Identify it, and call the node to + // continue streaming. + TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); + + if ( node ) + { + node->StreamIn( in, tag ); + bool isElement = node->ToElement() != 0; + delete node; + node = 0; + + // If this is the root element, we're done. Parsing will be + // done by the >> operator. + if ( isElement ) + { + return; + } + } + else + { + SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + } + } + // We should have returned sooner. + SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); +} + +#endif + +const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) +{ + ClearError(); + + // Parse away, at the document level. Since a document + // contains nothing but other tags, most of what happens + // here is skipping white space. + if ( !p || !*p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + // Note that, for a document, this needs to come + // before the while space skip, so that parsing + // starts from the pointer we are given. + location.Clear(); + if ( prevData ) + { + location.row = prevData->cursor.row; + location.col = prevData->cursor.col; + } + else + { + location.row = 0; + location.col = 0; + } + TiXmlParsingData data( p, TabSize(), location.row, location.col ); + location = data.Cursor(); + + if ( encoding == TIXML_ENCODING_UNKNOWN ) + { + // Check for the Microsoft UTF-8 lead bytes. + if ( *(p+0) && *(p+0) == (char)(0xef) + && *(p+1) && *(p+1) == (char)(0xbb) + && *(p+2) && *(p+2) == (char)(0xbf) ) + { + encoding = TIXML_ENCODING_UTF8; + } + } + + p = SkipWhiteSpace( p, encoding ); + if ( !p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); + return 0; + } + + while ( p && *p ) + { + TiXmlNode* node = Identify( p, encoding ); + if ( node ) + { + p = node->Parse( p, &data, encoding ); + LinkEndChild( node ); + } + else + { + break; + } + + // Did we get encoding info? + if ( encoding == TIXML_ENCODING_UNKNOWN + && node->ToDeclaration() ) + { + TiXmlDeclaration* dec = node->ToDeclaration(); + const char* enc = dec->Encoding(); + assert( enc ); + + if ( *enc == 0 ) + encoding = TIXML_ENCODING_UTF8; + else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) + encoding = TIXML_ENCODING_UTF8; + else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) + encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice + else + encoding = TIXML_ENCODING_LEGACY; + } + + p = SkipWhiteSpace( p, encoding ); + } + + // All is well. + return p; +} + +void TiXmlDocument::SetError( int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding ) +{ + // The first error in a chain is more accurate - don't set again! + if ( error ) + return; + + assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); + error = true; + errorId = err; + errorDesc = errorString[ errorId ]; + + errorLocation.Clear(); + if ( pError && data ) + { + //TiXmlParsingData data( pError, prevData ); + data->Stamp( pError, encoding ); + errorLocation = data->Cursor(); + } +} + + +TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) +{ + TiXmlNode* returnNode = 0; + + p = SkipWhiteSpace( p, encoding ); + if( !p || !*p || *p != '<' ) + { + return 0; + } + + TiXmlDocument* doc = GetDocument(); + p = SkipWhiteSpace( p, encoding ); + + if ( !p || !*p ) + { + return 0; + } + + // What is this thing? + // - Elements start with a letter or underscore, but xml is reserved. + // - Comments: "; + + if ( !StringEqual( p, startTag, false, encoding ) ) + { + document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding ); + return 0; + } + p += strlen( startTag ); + p = ReadText( p, &value, false, endTag, false, encoding ); + return p; +} + + +const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) +{ + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p ) return 0; + + int tabsize = 4; + if ( document ) + tabsize = document->TabSize(); + +// TiXmlParsingData data( p, prevData ); + if ( data ) + { + data->Stamp( p, encoding ); + location = data->Cursor(); + } + // Read the name, the '=' and the value. + const char* pErr = p; + p = ReadName( p, &name, encoding ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding ); + return 0; + } + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p || *p != '=' ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + + ++p; // skip '=' + p = SkipWhiteSpace( p, encoding ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); + return 0; + } + + const char* end; + + if ( *p == '\'' ) + { + ++p; + end = "\'"; + p = ReadText( p, &value, false, end, false, encoding ); + } + else if ( *p == '"' ) + { + ++p; + end = "\""; + p = ReadText( p, &value, false, end, false, encoding ); + } + else + { + // All attribute values should be in single or double quotes. + // But this is such a common error that the parser will try + // its best, even without them. + value = ""; + while ( p && *p // existence + && !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r' // whitespace + && *p != '/' && *p != '>' ) // tag end + { + value += *p; + ++p; + } + } + return p; +} + +#ifdef TIXML_USE_STL +void TiXmlText::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( c == '<' ) + return; + if ( c <= 0 ) + { + TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + + (*tag) += (char) c; + in->get(); + } +} +#endif + +const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) +{ + value = ""; +// TiXmlParsingData data( p, prevData ); + if ( data ) + { + data->Stamp( p, encoding ); + location = data->Cursor(); + } + bool ignoreWhite = true; + + const char* end = "<"; + p = ReadText( p, &value, ignoreWhite, end, false, encoding ); + if ( p ) + return p-1; // don't truncate the '<' + return 0; +} + +#ifdef TIXML_USE_STL +void TiXmlDeclaration::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->get(); + if ( c <= 0 ) + { + TiXmlDocument* document = GetDocument(); + if ( document ) + document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); + return; + } + (*tag) += (char) c; + + if ( c == '>' ) + { + // All is well. + return; + } + } +} +#endif + +const char* TiXmlDeclaration::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding ) +{ + p = SkipWhiteSpace( p, _encoding ); + // Find the beginning, find the end, and look for + // the stuff in-between. + TiXmlDocument* document = GetDocument(); + if ( !p || !*p || !StringEqual( p, "SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding ); + return 0; + } +// TiXmlParsingData data( p, prevData ); + if ( data ) + { + data->Stamp( p, _encoding ); + location = data->Cursor(); + } + p += 5; + + version = ""; + encoding = ""; + standalone = ""; + + while ( p && *p ) + { + if ( *p == '>' ) + { + ++p; + return p; + } + + p = SkipWhiteSpace( p, _encoding ); + if ( StringEqual( p, "version", true, _encoding ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + version = attrib.Value(); + } + else if ( StringEqual( p, "encoding", true, _encoding ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + encoding = attrib.Value(); + } + else if ( StringEqual( p, "standalone", true, _encoding ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data, _encoding ); + standalone = attrib.Value(); + } + else + { + // Read over whatever it is. + while( p && *p && *p != '>' && !IsWhiteSpace( *p ) ) + ++p; + } + } + return 0; +} + +bool TiXmlText::Blank() const +{ + for ( unsigned i=0; iGetKey(!Interact || !Interact->NeedsFastResponse()); if (ISREALKEY(key)) { + cStatus::MsgUserAction(key, Interact); EITScanner.Activity(); // Cancel shutdown countdown: if (ShutdownHandler.countdown) @@ -1088,10 +1090,12 @@ cControl::Control()->Hide(); cPlugin *plugin = cPluginManager::GetPlugin(PluginName); if (plugin) { + if (!cStatus::MsgPluginProtected(plugin)) { Menu = plugin->MainMenuAction(); if (Menu) Menu->Show(); } + } else esyslog("ERROR: unknown plugin '%s'", PluginName); } @@ -1304,9 +1308,11 @@ // Instant resume of the last viewed recording: case kPlay: if (cReplayControl::LastReplayed()) { + if (cStatus::MsgReplayProtected(0, cReplayControl::LastReplayed(), 0, false) == false) { // PIN PATCH cControl::Shutdown(); cControl::Launch(new cReplayControl); } + } else DirectMainFunction(osRecordings); // no last viewed recording, so enter the Recordings menu break;