summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-30 21:56:00 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-30 21:56:00 +0000
commitf65f1d398804ec4702a3de691398902a0347461c (patch)
treea38ce902fa1181e9d00f4010a4abea8cf114c926 /xfa/fxfa
parente06c542ffdc7325cb3c430e59bd0d9df4ddb7776 (diff)
downloadpdfium-f65f1d398804ec4702a3de691398902a0347461c.tar.xz
Move packet information into simple parser
This CL moves the packet information into the anonymous namespace of the simple parser. There is slight duplication in that two of the namespace URIs have been copied into other files but this duplication allows for a bunch of simplification. Change-Id: I33092424ff4cb57eaf85da97a92fa6cf7b11f2ef Reviewed-on: https://pdfium-review.googlesource.com/20050 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/fxfa_basic.h8
-rw-r--r--xfa/fxfa/parser/cxfa_dataexporter.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_document.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp221
-rw-r--r--xfa/fxfa/parser/xfa_basic_data.h3
-rw-r--r--xfa/fxfa/parser/xfa_basic_data_packets.cpp54
-rw-r--r--xfa/fxfa/parser/xfa_utils.cpp24
-rw-r--r--xfa/fxfa/parser/xfa_utils.h3
8 files changed, 137 insertions, 188 deletions
diff --git a/xfa/fxfa/fxfa_basic.h b/xfa/fxfa/fxfa_basic.h
index 6094512995..0f4ea37e3f 100644
--- a/xfa/fxfa/fxfa_basic.h
+++ b/xfa/fxfa/fxfa_basic.h
@@ -97,14 +97,6 @@ enum XFA_XDPPACKET_FLAGS {
XFA_XDPPACKET_FLAGS_SUPPORTMANY = 16,
};
-struct XFA_PACKETINFO {
- uint32_t uHash;
- const wchar_t* pName;
- XFA_PacketType eName;
- const wchar_t* pURI;
- uint32_t eFlags;
-};
-
enum XFA_ATTRIBUTEENUM {
XFA_ATTRIBUTEENUM_Asterisk,
XFA_ATTRIBUTEENUM_Slash,
diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp
index 1113ba49b6..02c316d920 100644
--- a/xfa/fxfa/parser/cxfa_dataexporter.cpp
+++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp
@@ -22,6 +22,8 @@
namespace {
+constexpr const wchar_t kFormNS[] = L"http://www.xfa.org/schema/xfa-form/";
+
WideString ExportEncodeAttribute(const WideString& str) {
CFX_WideTextBuf textBuf;
int32_t iLen = str.GetLength();
@@ -402,9 +404,7 @@ void XFA_DataExporter_RegenerateFormFile(
pStream->WriteString(L"\"");
}
pStream->WriteString(L" xmlns=\"");
-
- const wchar_t* pURI = XFA_GetPacketByIndex(XFA_PacketType::Form)->pURI;
- pStream->WriteString(WideStringView(pURI, wcslen(pURI)));
+ pStream->WriteString(WideStringView(kFormNS));
WideString wsVersionNumber;
RecognizeXFAVersionNumber(
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index b23ba68a45..a737baaafb 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -25,6 +25,9 @@
namespace {
+constexpr const wchar_t kTemplateNS[] =
+ L"http://www.xfa.org/schema/xfa-template/";
+
void MergeNodeRecurse(CXFA_Document* pDocument,
CXFA_Node* pDestNodeParent,
CXFA_Node* pProtoNode) {
@@ -295,8 +298,7 @@ CFXJSE_Engine* CXFA_Document::GetScriptContext() {
XFA_VERSION CXFA_Document::RecognizeXFAVersionNumber(
const WideString& wsTemplateNS) {
- WideStringView wsTemplateURIPrefix =
- XFA_GetPacketByIndex(XFA_PacketType::Template)->pURI;
+ WideStringView wsTemplateURIPrefix(kTemplateNS);
size_t nPrefixLength = wsTemplateURIPrefix.GetLength();
if (WideStringView(wsTemplateNS.c_str(), wsTemplateNS.GetLength()) !=
wsTemplateURIPrefix) {
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp
index 67d6f80b6d..0b8153fc3a 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -31,6 +31,73 @@
namespace {
+struct PacketInfo {
+ uint32_t hash;
+ const wchar_t* name;
+ XFA_PacketType packet_type;
+ const wchar_t* uri;
+ uint32_t flags;
+};
+const PacketInfo PacketData[] = {
+ {0x0, nullptr, XFA_PacketType::User, nullptr,
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTMANY},
+ {0x811929d, L"sourceSet", XFA_PacketType::SourceSet,
+ L"http://www.xfa.org/schema/xfa-source-set/",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0xb843dba, L"pdf", XFA_PacketType::Pdf, L"http://ns.adobe.com/xdp/pdf/",
+ XFA_XDPPACKET_FLAGS_COMPLETEMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0xc56afbf, L"xdc", XFA_PacketType::Xdc, L"http://www.xfa.org/schema/xdc/",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0xc56afcc, L"xdp", XFA_PacketType::Xdp, L"http://ns.adobe.com/xdp/",
+ XFA_XDPPACKET_FLAGS_COMPLETEMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0x132a8fbc, L"xmpmeta", XFA_PacketType::Xmpmeta,
+ L"http://ns.adobe.com/xmpmeta/",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTMANY},
+ {0x48d004a8, L"xfdf", XFA_PacketType::Xfdf, L"http://ns.adobe.com/xfdf/",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0x4e1e39b6, L"config", XFA_PacketType::Config,
+ L"http://www.xfa.org/schema/xci/",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0x5473b6dc, L"localeSet", XFA_PacketType::LocaleSet,
+ L"http://www.xfa.org/schema/xfa-locale-set/",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0x6038580a, L"stylesheet", XFA_PacketType::Stylesheet,
+ L"http://www.w3.org/1999/XSL/Transform",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTMANY},
+ {0x803550fc, L"template", XFA_PacketType::Template,
+ L"http://www.xfa.org/schema/xfa-template/",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0x8b036f32, L"signature", XFA_PacketType::Signature,
+ L"http://www.w3.org/2000/09/xmldsig#",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0x99b95079, L"datasets", XFA_PacketType::Datasets,
+ L"http://www.xfa.org/schema/xfa-data/",
+ XFA_XDPPACKET_FLAGS_PREFIXMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0xcd309ff4, L"form", XFA_PacketType::Form,
+ L"http://www.xfa.org/schema/xfa-form/",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+ {0xe14c801c, L"connectionSet", XFA_PacketType::ConnectionSet,
+ L"http://www.xfa.org/schema/xfa-connection-set/",
+ XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
+};
+
+const PacketInfo* GetPacketByIndex(XFA_PacketType ePacket) {
+ return PacketData + static_cast<uint8_t>(ePacket);
+}
+
+const PacketInfo* GetPacketByName(const WideStringView& wsName) {
+ if (wsName.IsEmpty())
+ return nullptr;
+
+ uint32_t hash = FX_HashCode_GetW(wsName, false);
+ auto* elem = std::lower_bound(
+ std::begin(PacketData), std::end(PacketData), hash,
+ [](const PacketInfo& a, uint32_t hash) { return a.hash < hash; });
+ if (elem != std::end(PacketData) && elem->hash == hash)
+ return elem;
+ return nullptr;
+}
+
CFX_XMLNode* GetDocumentNode(CFX_XMLDoc* pXMLDoc,
bool bVerifyWellFormness = false) {
if (!pXMLDoc)
@@ -166,30 +233,27 @@ bool FindAttributeWithNS(CFX_XMLElement* pElement,
}
CFX_XMLNode* GetDataSetsFromXDP(CFX_XMLNode* pXMLDocumentNode) {
- if (MatchNodeName(pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::Datasets)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::Datasets)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::Datasets)->eFlags)) {
+ const PacketInfo* datasets_packet =
+ GetPacketByIndex(XFA_PacketType::Datasets);
+ if (MatchNodeName(pXMLDocumentNode, datasets_packet->name,
+ datasets_packet->uri, datasets_packet->flags)) {
return pXMLDocumentNode;
}
- if (!MatchNodeName(pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::Xdp)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::Xdp)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::Xdp)->eFlags)) {
+
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::Xdp);
+ if (!MatchNodeName(pXMLDocumentNode, packet->name, packet->uri,
+ packet->flags)) {
return nullptr;
}
+
for (CFX_XMLNode* pDatasetsNode =
pXMLDocumentNode->GetNodeItem(CFX_XMLNode::FirstChild);
pDatasetsNode;
pDatasetsNode = pDatasetsNode->GetNodeItem(CFX_XMLNode::NextSibling)) {
- if (!MatchNodeName(
- pDatasetsNode,
- XFA_GetPacketByIndex(XFA_PacketType::Datasets)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::Datasets)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::Datasets)->eFlags)) {
- continue;
+ if (MatchNodeName(pDatasetsNode, datasets_packet->name,
+ datasets_packet->uri, datasets_packet->flags)) {
+ return pDatasetsNode;
}
- return pDatasetsNode;
}
return nullptr;
}
@@ -429,10 +493,9 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket(CFX_XMLNode* pXMLDocumentNode,
CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
CFX_XMLNode* pXMLDocumentNode) {
- if (!MatchNodeName(pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::Xdp)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::Xdp)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::Xdp)->eFlags)) {
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::Xdp);
+ if (!MatchNodeName(pXMLDocumentNode, packet->name, packet->uri,
+ packet->flags)) {
return nullptr;
}
@@ -460,13 +523,12 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
pXMLDocumentNode->GetNodeItem(CFX_XMLNode::FirstChild);
pChildItem;
pChildItem = pChildItem->GetNodeItem(CFX_XMLNode::NextSibling)) {
- const XFA_PACKETINFO* pPacketInfo =
- XFA_GetPacketByIndex(XFA_PacketType::Config);
- if (!MatchNodeName(pChildItem, pPacketInfo->pName, pPacketInfo->pURI,
- pPacketInfo->eFlags)) {
+ const PacketInfo* pPacketInfo = GetPacketByIndex(XFA_PacketType::Config);
+ if (!MatchNodeName(pChildItem, pPacketInfo->name, pPacketInfo->uri,
+ pPacketInfo->flags)) {
continue;
}
- if (pXFARootNode->GetFirstChildByName(pPacketInfo->uHash))
+ if (pXFARootNode->GetFirstChildByName(pPacketInfo->hash))
return nullptr;
pXMLConfigDOMRoot = pChildItem;
@@ -490,16 +552,16 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
CFX_XMLElement* pElement = reinterpret_cast<CFX_XMLElement*>(pChildItem);
WideString wsPacketName = pElement->GetLocalTagName();
- const XFA_PACKETINFO* pPacketInfo =
- XFA_GetPacketByName(wsPacketName.AsStringView());
- if (pPacketInfo && pPacketInfo->pURI) {
- if (!MatchNodeName(pElement, pPacketInfo->pName, pPacketInfo->pURI,
- pPacketInfo->eFlags)) {
+ const PacketInfo* pPacketInfo =
+ GetPacketByName(wsPacketName.AsStringView());
+ if (pPacketInfo && pPacketInfo->uri) {
+ if (!MatchNodeName(pElement, pPacketInfo->name, pPacketInfo->uri,
+ pPacketInfo->flags)) {
pPacketInfo = nullptr;
}
}
XFA_PacketType ePacket =
- pPacketInfo ? pPacketInfo->eName : XFA_PacketType::User;
+ pPacketInfo ? pPacketInfo->packet_type : XFA_PacketType::User;
if (ePacket == XFA_PacketType::Xdp)
continue;
if (ePacket == XFA_PacketType::Datasets) {
@@ -526,8 +588,8 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
CXFA_Node* pPacketNode = ParseAsXDPPacket(pElement, ePacket);
if (pPacketNode) {
if (pPacketInfo &&
- (pPacketInfo->eFlags & XFA_XDPPACKET_FLAGS_SUPPORTONE) &&
- pXFARootNode->GetFirstChildByName(pPacketInfo->uHash)) {
+ (pPacketInfo->flags & XFA_XDPPACKET_FLAGS_SUPPORTONE) &&
+ pXFARootNode->GetFirstChildByName(pPacketInfo->hash)) {
return nullptr;
}
pXFARootNode->InsertChild(pPacketNode, nullptr);
@@ -559,10 +621,9 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Config(
CFX_XMLNode* pXMLDocumentNode,
XFA_PacketType ePacketID) {
- if (!MatchNodeName(pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::Config)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::Config)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::Config)->eFlags)) {
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::Config);
+ if (!MatchNodeName(pXMLDocumentNode, packet->name, packet->uri,
+ packet->flags)) {
return nullptr;
}
CXFA_Node* pNode =
@@ -570,9 +631,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Config(
if (!pNode)
return nullptr;
- pNode->JSNode()->SetCData(XFA_Attribute::Name,
- XFA_GetPacketByIndex(XFA_PacketType::Config)->pName,
- false, false);
+ pNode->JSNode()->SetCData(XFA_Attribute::Name, packet->name, false, false);
if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID, true))
return nullptr;
@@ -585,18 +644,16 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm(
XFA_PacketType ePacketID) {
CXFA_Node* pNode = nullptr;
if (ePacketID == XFA_PacketType::Template) {
- if (MatchNodeName(pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::Template)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::Template)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::Template)->eFlags)) {
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::Template);
+ if (MatchNodeName(pXMLDocumentNode, packet->name, packet->uri,
+ packet->flags)) {
pNode = m_pFactory->CreateNode(XFA_PacketType::Template,
XFA_Element::Template);
if (!pNode)
return nullptr;
- pNode->JSNode()->SetCData(
- XFA_Attribute::Name,
- XFA_GetPacketByIndex(XFA_PacketType::Template)->pName, false, false);
+ pNode->JSNode()->SetCData(XFA_Attribute::Name, packet->name, false,
+ false);
if (m_bDocumentParser) {
CFX_XMLElement* pXMLDocumentElement =
static_cast<CFX_XMLElement*>(pXMLDocumentNode);
@@ -610,10 +667,9 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm(
return nullptr;
}
} else if (ePacketID == XFA_PacketType::Form) {
- if (MatchNodeName(pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::Form)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::Form)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::Form)->eFlags)) {
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::Form);
+ if (MatchNodeName(pXMLDocumentNode, packet->name, packet->uri,
+ packet->flags)) {
CFX_XMLElement* pXMLDocumentElement =
static_cast<CFX_XMLElement*>(pXMLDocumentNode);
WideString wsChecksum = pXMLDocumentElement->GetString(L"checksum");
@@ -637,9 +693,8 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm(
if (!pNode)
return nullptr;
- pNode->JSNode()->SetCData(
- XFA_Attribute::Name,
- XFA_GetPacketByIndex(XFA_PacketType::Form)->pName, false, false);
+ pNode->JSNode()->SetCData(XFA_Attribute::Name, packet->name, false,
+ false);
pNode->JSNode()->SetAttribute(XFA_Attribute::Checksum,
wsChecksum.AsStringView(), false);
CXFA_Node* pTemplateRoot =
@@ -667,15 +722,14 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_TemplateForm(
CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data(
CFX_XMLNode* pXMLDocumentNode) {
CFX_XMLNode* pDatasetsXMLNode = GetDataSetsFromXDP(pXMLDocumentNode);
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::Datasets);
if (pDatasetsXMLNode) {
CXFA_Node* pNode = m_pFactory->CreateNode(XFA_PacketType::Datasets,
XFA_Element::DataModel);
if (!pNode)
return nullptr;
- pNode->JSNode()->SetCData(
- XFA_Attribute::Name,
- XFA_GetPacketByIndex(XFA_PacketType::Datasets)->pName, false, false);
+ pNode->JSNode()->SetCData(XFA_Attribute::Name, packet->name, false, false);
if (!DataLoader(pNode, pDatasetsXMLNode, false))
return nullptr;
@@ -684,9 +738,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data(
}
CFX_XMLNode* pDataXMLNode = nullptr;
- if (MatchNodeName(pXMLDocumentNode, L"data",
- XFA_GetPacketByIndex(XFA_PacketType::Datasets)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::Datasets)->eFlags)) {
+ if (MatchNodeName(pXMLDocumentNode, L"data", packet->uri, packet->flags)) {
static_cast<CFX_XMLElement*>(pXMLDocumentNode)
->RemoveAttribute(L"xmlns:xfa");
pDataXMLNode = pXMLDocumentNode;
@@ -733,54 +785,44 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_LocaleConnectionSourceSet(
XFA_PacketType ePacketID) {
CXFA_Node* pNode = nullptr;
if (ePacketID == XFA_PacketType::LocaleSet) {
- if (MatchNodeName(
- pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::LocaleSet)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::LocaleSet)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::LocaleSet)->eFlags)) {
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::LocaleSet);
+ if (MatchNodeName(pXMLDocumentNode, packet->name, packet->uri,
+ packet->flags)) {
pNode = m_pFactory->CreateNode(XFA_PacketType::LocaleSet,
XFA_Element::LocaleSet);
if (!pNode)
return nullptr;
- pNode->JSNode()->SetCData(
- XFA_Attribute::Name,
- XFA_GetPacketByIndex(XFA_PacketType::LocaleSet)->pName, false, false);
+ pNode->JSNode()->SetCData(XFA_Attribute::Name, packet->name, false,
+ false);
if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID, true))
return nullptr;
}
} else if (ePacketID == XFA_PacketType::ConnectionSet) {
- if (MatchNodeName(
- pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::ConnectionSet)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::ConnectionSet)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::ConnectionSet)->eFlags)) {
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::ConnectionSet);
+ if (MatchNodeName(pXMLDocumentNode, packet->name, packet->uri,
+ packet->flags)) {
pNode = m_pFactory->CreateNode(XFA_PacketType::ConnectionSet,
XFA_Element::ConnectionSet);
if (!pNode)
return nullptr;
- pNode->JSNode()->SetCData(
- XFA_Attribute::Name,
- XFA_GetPacketByIndex(XFA_PacketType::ConnectionSet)->pName, false,
- false);
+ pNode->JSNode()->SetCData(XFA_Attribute::Name, packet->name, false,
+ false);
if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID, true))
return nullptr;
}
} else if (ePacketID == XFA_PacketType::SourceSet) {
- if (MatchNodeName(
- pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::SourceSet)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::SourceSet)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::SourceSet)->eFlags)) {
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::SourceSet);
+ if (MatchNodeName(pXMLDocumentNode, packet->name, packet->uri,
+ packet->flags)) {
pNode = m_pFactory->CreateNode(XFA_PacketType::SourceSet,
XFA_Element::SourceSet);
if (!pNode)
return nullptr;
- pNode->JSNode()->SetCData(
- XFA_Attribute::Name,
- XFA_GetPacketByIndex(XFA_PacketType::SourceSet)->pName, false, false);
+ pNode->JSNode()->SetCData(XFA_Attribute::Name, packet->name, false,
+ false);
if (!NormalLoader(pNode, pXMLDocumentNode, ePacketID, true))
return nullptr;
}
@@ -792,10 +834,9 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_LocaleConnectionSourceSet(
CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Xdc(
CFX_XMLNode* pXMLDocumentNode) {
- if (!MatchNodeName(pXMLDocumentNode,
- XFA_GetPacketByIndex(XFA_PacketType::Xdc)->pName,
- XFA_GetPacketByIndex(XFA_PacketType::Xdc)->pURI,
- XFA_GetPacketByIndex(XFA_PacketType::Xdc)->eFlags))
+ const PacketInfo* packet = GetPacketByIndex(XFA_PacketType::Xdc);
+ if (!MatchNodeName(pXMLDocumentNode, packet->name, packet->uri,
+ packet->flags))
return nullptr;
CXFA_Node* pNode =
@@ -803,9 +844,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Xdc(
if (!pNode)
return nullptr;
- pNode->JSNode()->SetCData(XFA_Attribute::Name,
- XFA_GetPacketByIndex(XFA_PacketType::Xdc)->pName,
- false, false);
+ pNode->JSNode()->SetCData(XFA_Attribute::Name, packet->name, false, false);
pNode->SetXMLMappingNode(pXMLDocumentNode);
return pNode;
}
diff --git a/xfa/fxfa/parser/xfa_basic_data.h b/xfa/fxfa/parser/xfa_basic_data.h
index b5833ff379..60f31ca563 100644
--- a/xfa/fxfa/parser/xfa_basic_data.h
+++ b/xfa/fxfa/parser/xfa_basic_data.h
@@ -11,9 +11,6 @@
#include "xfa/fxfa/fxfa_basic.h"
-extern const XFA_PACKETINFO g_XFAPacketData[];
-extern const int32_t g_iXFAPacketCount;
-
extern const XFA_ATTRIBUTEENUMINFO g_XFAEnumData[];
extern const int32_t g_iXFAEnumCount;
diff --git a/xfa/fxfa/parser/xfa_basic_data_packets.cpp b/xfa/fxfa/parser/xfa_basic_data_packets.cpp
deleted file mode 100644
index 91e2d3cc6e..0000000000
--- a/xfa/fxfa/parser/xfa_basic_data_packets.cpp
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fxfa/parser/xfa_basic_data.h"
-
-#include "xfa/fxfa/fxfa_basic.h"
-
-const XFA_PACKETINFO g_XFAPacketData[] = {
- {0x0, nullptr, XFA_PacketType::User, nullptr,
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTMANY},
- {0x811929d, L"sourceSet", XFA_PacketType::SourceSet,
- L"http://www.xfa.org/schema/xfa-source-set/",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0xb843dba, L"pdf", XFA_PacketType::Pdf, L"http://ns.adobe.com/xdp/pdf/",
- XFA_XDPPACKET_FLAGS_COMPLETEMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0xc56afbf, L"xdc", XFA_PacketType::Xdc, L"http://www.xfa.org/schema/xdc/",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0xc56afcc, L"xdp", XFA_PacketType::Xdp, L"http://ns.adobe.com/xdp/",
- XFA_XDPPACKET_FLAGS_COMPLETEMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0x132a8fbc, L"xmpmeta", XFA_PacketType::Xmpmeta,
- L"http://ns.adobe.com/xmpmeta/",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTMANY},
- {0x48d004a8, L"xfdf", XFA_PacketType::Xfdf, L"http://ns.adobe.com/xfdf/",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0x4e1e39b6, L"config", XFA_PacketType::Config,
- L"http://www.xfa.org/schema/xci/",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0x5473b6dc, L"localeSet", XFA_PacketType::LocaleSet,
- L"http://www.xfa.org/schema/xfa-locale-set/",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0x6038580a, L"stylesheet", XFA_PacketType::Stylesheet,
- L"http://www.w3.org/1999/XSL/Transform",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTMANY},
- {0x803550fc, L"template", XFA_PacketType::Template,
- L"http://www.xfa.org/schema/xfa-template/",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0x8b036f32, L"signature", XFA_PacketType::Signature,
- L"http://www.w3.org/2000/09/xmldsig#",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0x99b95079, L"datasets", XFA_PacketType::Datasets,
- L"http://www.xfa.org/schema/xfa-data/",
- XFA_XDPPACKET_FLAGS_PREFIXMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0xcd309ff4, L"form", XFA_PacketType::Form,
- L"http://www.xfa.org/schema/xfa-form/",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
- {0xe14c801c, L"connectionSet", XFA_PacketType::ConnectionSet,
- L"http://www.xfa.org/schema/xfa-connection-set/",
- XFA_XDPPACKET_FLAGS_NOMATCH | XFA_XDPPACKET_FLAGS_SUPPORTONE},
-};
-const int32_t g_iXFAPacketCount =
- sizeof(g_XFAPacketData) / sizeof(XFA_PACKETINFO);
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index a7b31aebec..529420a93a 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -185,27 +185,3 @@ const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName(
}
return nullptr;
}
-
-const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PacketType ePacket) {
- return g_XFAPacketData + static_cast<uint8_t>(ePacket);
-}
-
-const XFA_PACKETINFO* XFA_GetPacketByName(const WideStringView& wsName) {
- if (wsName.IsEmpty())
- return nullptr;
-
- uint32_t uHash = FX_HashCode_GetW(wsName, false);
- int32_t iStart = 0;
- int32_t iEnd = g_iXFAPacketCount - 1;
- do {
- int32_t iMid = (iStart + iEnd) / 2;
- const XFA_PACKETINFO* pInfo = g_XFAPacketData + iMid;
- if (uHash == pInfo->uHash)
- return pInfo;
- if (uHash < pInfo->uHash)
- iEnd = iMid - 1;
- else
- iStart = iMid + 1;
- } while (iStart <= iEnd);
- return nullptr;
-}
diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h
index 5cd265e2b3..15b6983f9a 100644
--- a/xfa/fxfa/parser/xfa_utils.h
+++ b/xfa/fxfa/parser/xfa_utils.h
@@ -42,7 +42,4 @@ const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName(
XFA_Element eElement,
const WideStringView& wsAttributeName);
-const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PacketType ePacket);
-const XFA_PACKETINFO* XFA_GetPacketByName(const WideStringView& wsName);
-
#endif // XFA_FXFA_PARSER_XFA_UTILS_H_