summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfattachment.cpp
diff options
context:
space:
mode:
authorJane Liu <janeliulwq@google.com>2017-07-12 19:55:02 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-13 14:07:05 +0000
commit53aafa99985e93c527ea2803400f250025cc7f01 (patch)
treed7a9597118a377baf9fe296b42d7baa48cca1ee0 /fpdfsdk/fpdfattachment.cpp
parent0b6e9aed1756d19ed812895208be5cae5633325b (diff)
downloadpdfium-53aafa99985e93c527ea2803400f250025cc7f01.tar.xz
Basic APIs and test for retrieving embedded attachment count and name
1. Added APIs for retrieving embedded attachment count and file name. * Added an embedder test testing them. Bug=pdfium:174 Change-Id: I181b8e0b81495d8a7fd8c3f79dbbc0f907f5e3fd Reviewed-on: https://pdfium-review.googlesource.com/7490 Commit-Queue: Jane Liu <janeliulwq@google.com> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfattachment.cpp')
-rw-r--r--fpdfsdk/fpdfattachment.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/fpdfsdk/fpdfattachment.cpp b/fpdfsdk/fpdfattachment.cpp
new file mode 100644
index 0000000000..d8713bb2e1
--- /dev/null
+++ b/fpdfsdk/fpdfattachment.cpp
@@ -0,0 +1,47 @@
+// Copyright 2017 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.
+
+#include "public/fpdf_attachment.h"
+
+#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfdoc/cpdf_filespec.h"
+#include "core/fpdfdoc/cpdf_nametree.h"
+#include "fpdfsdk/fsdk_define.h"
+
+DLLEXPORT int STDCALL FPDFDoc_GetAttachmentCount(FPDF_DOCUMENT document) {
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc)
+ return 0;
+
+ return CPDF_NameTree(pDoc, "EmbeddedFiles").GetCount();
+}
+
+DLLEXPORT unsigned long STDCALL
+FPDFDoc_GetAttachmentName(FPDF_DOCUMENT document,
+ int index,
+ void* buffer,
+ unsigned long buflen) {
+ CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document);
+ if (!pDoc || index < 0)
+ return 0;
+
+ CPDF_NameTree nameTree(pDoc, "EmbeddedFiles");
+ if (static_cast<size_t>(index) >= nameTree.GetCount())
+ return 0;
+
+ CFX_ByteString csName;
+ CPDF_Object* pFile = nameTree.LookupValueAndName(index, &csName);
+ if (!pFile)
+ return 0;
+
+ CFX_WideString name;
+ CPDF_FileSpec filespec(pFile);
+ filespec.GetFileName(&name);
+ CFX_ByteString encodedName = name.UTF16LE_Encode();
+ unsigned long len = encodedName.GetLength();
+ if (buffer && buflen >= len)
+ memcpy(buffer, encodedName.c_str(), len);
+
+ return len;
+}