Skip to content

Commit

Permalink
Themed menus: clean up processing of includes.
Browse files Browse the repository at this point in the history
Removes the ephemeral m_recursionLevel field from MenuBase, and
handles the guarding against infinite include recursion through method
arguments.  Refs #11533.
  • Loading branch information
stichnot committed May 17, 2013
1 parent d0966af commit 8ad2c1d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
39 changes: 24 additions & 15 deletions mythtv/libs/libmythtv/tv_play.cpp
Expand Up @@ -10876,9 +10876,19 @@ void TV::HandleOSDInfo(PlayerContext *ctx, QString action)
}

bool MenuBase::Load(const QString &filename,
const QString &menuname,
const char *translationContext,
const QString &keyBindingContext)
const QString &menuname,
const char *translationContext,
const QString &keyBindingContext)
{
return LoadHelper(filename, menuname, translationContext,
keyBindingContext, 0);
}

bool MenuBase::LoadHelper(const QString &filename,
const QString &menuname,
const char *translationContext,
const QString &keyBindingContext,
int includeLevel)
{
bool result = false;

Expand All @@ -10901,7 +10911,7 @@ bool MenuBase::Load(const QString &filename,
result = true;
QDomElement root = GetRoot();
m_menuName = Translate(root.attribute("text", menuname));
ProcessIncludes(root);
ProcessIncludes(root, includeLevel);
}
else
{
Expand All @@ -10919,9 +10929,9 @@ bool MenuBase::Load(const QString &filename,
return result;
}

void MenuBase::ProcessIncludes(QDomElement &root)
void MenuBase::ProcessIncludes(QDomElement &root, int includeLevel)
{
const int maxRecursion = 10;
const int maxInclude = 10;
for (QDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling())
{
if (n.isElement())
Expand All @@ -10932,21 +10942,20 @@ void MenuBase::ProcessIncludes(QDomElement &root)
QString include = e.attribute("file", "");
if (include.isEmpty())
continue;
int level = m_recursionLevel + 1;
if (level > maxRecursion)
if (includeLevel >= maxInclude)
{
LOG(VB_GENERAL, LOG_ERR,
QString("Maximum include depth (%1) "
"exceeded for %2")
.arg(maxRecursion).arg(include));
.arg(maxInclude).arg(include));
return;
}
MenuBase menu;
menu.m_recursionLevel = level;
if (menu.Load(include,
include, // fallback menu name is filename
m_translationContext,
m_keyBindingContext))
if (menu.LoadHelper(include,
include, // fallback menu name is filename
m_translationContext,
m_keyBindingContext,
includeLevel + 1))
{
QDomNode newChild = menu.GetRoot();
newChild = m_document->importNode(newChild, true);
Expand All @@ -10956,7 +10965,7 @@ void MenuBase::ProcessIncludes(QDomElement &root)
}
else if (e.tagName() == "menu")
{
ProcessIncludes(e);
ProcessIncludes(e, includeLevel + 1);
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions mythtv/libs/libmythtv/tv_play.h
Expand Up @@ -225,8 +225,7 @@ class MenuItemDisplayer
class MenuBase
{
public:
MenuBase() : m_document(NULL), m_translationContext(""),
m_recursionLevel(0) {}
MenuBase() : m_document(NULL), m_translationContext("") {}
~MenuBase();
bool Load(const QString &filename,
const QString &menuname,
Expand All @@ -246,12 +245,16 @@ class MenuBase
return m_keyBindingContext;
}
private:
void ProcessIncludes(QDomElement &root);
bool LoadHelper(const QString &filename,
const QString &menuname,
const char *translationContext,
const QString &keyBindingContext,
int includeLevel);
void ProcessIncludes(QDomElement &root, int includeLevel);
QDomDocument *m_document;
const char *m_translationContext;
QString m_menuName;
QString m_keyBindingContext;
int m_recursionLevel; // guard against infinite recursion
};

/**
Expand Down

0 comments on commit 8ad2c1d

Please sign in to comment.