Jane Liu | 53aafa9 | 2017-07-12 19:55:02 -0400 | [diff] [blame] | 1 | // Copyright 2017 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PUBLIC_FPDF_ATTACHMENT_H_ |
| 6 | #define PUBLIC_FPDF_ATTACHMENT_H_ |
| 7 | |
| 8 | // NOLINTNEXTLINE(build/include) |
| 9 | #include "fpdfview.h" |
| 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif // __cplusplus |
| 14 | |
| 15 | // Experimental API. |
| 16 | // Get the number of embedded files in |document|. |
| 17 | // |
| 18 | // document - handle to a document. |
| 19 | // |
| 20 | // Returns the number of embedded files in |document|. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 21 | DLLEXPORT int STDCALL FPDFDoc_GetAttachmentCount(FPDF_DOCUMENT document); |
Jane Liu | 53aafa9 | 2017-07-12 19:55:02 -0400 | [diff] [blame] | 22 | |
| 23 | // Experimental API. |
Jane Liu | 54a4214 | 2017-07-24 16:40:54 -0400 | [diff] [blame] | 24 | // Add an embedded file with |name| in |document|. If |name| is empty, or if |
| 25 | // |name| is the name of a existing embedded file in |document|, or if |
| 26 | // |document|'s embedded file name tree is too deep (i.e. |document| has too |
| 27 | // many embedded files already), then a new attachment will not be added. |
| 28 | // |
| 29 | // document - handle to a document. |
| 30 | // name - name of the new attachment. |
| 31 | // |
| 32 | // Returns a handle to the new attachment object, or NULL on failure. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 33 | DLLEXPORT FPDF_ATTACHMENT STDCALL FPDFDoc_AddAttachment(FPDF_DOCUMENT document, |
| 34 | FPDF_WIDESTRING name); |
Jane Liu | 54a4214 | 2017-07-24 16:40:54 -0400 | [diff] [blame] | 35 | |
| 36 | // Experimental API. |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 37 | // Get the embedded attachment at |index| in |document|. Note that the returned |
| 38 | // attachment handle is only valid while |document| is open. |
Jane Liu | 53aafa9 | 2017-07-12 19:55:02 -0400 | [diff] [blame] | 39 | // |
| 40 | // document - handle to a document. |
| 41 | // index - the index of the requested embedded file. |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 42 | // |
| 43 | // Returns the handle to the attachment object, or NULL on failure. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 44 | DLLEXPORT FPDF_ATTACHMENT STDCALL FPDFDoc_GetAttachment(FPDF_DOCUMENT document, |
| 45 | int index); |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 46 | |
| 47 | // Experimental API. |
Jane Liu | f63e813 | 2017-07-25 18:11:27 -0400 | [diff] [blame] | 48 | // Delete the embedded attachment at |index| in |document|. Note that this does |
| 49 | // not remove the attachment data from the PDF file; it simply removes the |
| 50 | // file's entry in the embedded files name tree so that it does not appear in |
| 51 | // the attachment list. This behavior may change in the future. |
| 52 | // |
| 53 | // document - handle to a document. |
| 54 | // index - the index of the embedded file to be deleted. |
| 55 | // |
| 56 | // Returns true if successful. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 57 | DLLEXPORT FPDF_BOOL STDCALL FPDFDoc_DeleteAttachment(FPDF_DOCUMENT document, |
| 58 | int index); |
Jane Liu | f63e813 | 2017-07-25 18:11:27 -0400 | [diff] [blame] | 59 | |
| 60 | // Experimental API. |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 61 | // Get the name of the |attachment| file. |buffer| is only modified if |buflen| |
| 62 | // is longer than the length of the file name. On errors, |buffer| is unmodified |
| 63 | // and the returned length is 0. |
| 64 | // |
| 65 | // attachment - handle to an attachment. |
| 66 | // buffer - buffer for holding the file name, encoded in UTF16-LE. |
| 67 | // buflen - length of the buffer. |
Jane Liu | 53aafa9 | 2017-07-12 19:55:02 -0400 | [diff] [blame] | 68 | // |
| 69 | // Returns the length of the file name. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 70 | DLLEXPORT unsigned long STDCALL |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 71 | FPDFAttachment_GetName(FPDF_ATTACHMENT attachment, |
| 72 | void* buffer, |
| 73 | unsigned long buflen); |
| 74 | |
| 75 | // Experimental API. |
| 76 | // Check if the params dictionary of |attachment| has |key| as a key. |
| 77 | // |
| 78 | // attachment - handle to an attachment. |
| 79 | // key - the key to look for. |
| 80 | // |
| 81 | // Returns true if |key| exists. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 82 | DLLEXPORT FPDF_BOOL STDCALL FPDFAttachment_HasKey(FPDF_ATTACHMENT attachment, |
| 83 | FPDF_WIDESTRING key); |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 84 | |
| 85 | // Experimental API. |
| 86 | // Get the type of the value corresponding to |key| in the params dictionary of |
| 87 | // the embedded |attachment|. |
| 88 | // |
| 89 | // attachment - handle to an attachment. |
| 90 | // key - the key to look for. |
| 91 | // |
| 92 | // Returns the type of the dictionary value. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 93 | DLLEXPORT FPDF_OBJECT_TYPE STDCALL |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 94 | FPDFAttachment_GetValueType(FPDF_ATTACHMENT attachment, FPDF_WIDESTRING key); |
| 95 | |
| 96 | // Experimental API. |
Jane Liu | 54a4214 | 2017-07-24 16:40:54 -0400 | [diff] [blame] | 97 | // Set the string value corresponding to |key| in the params dictionary of the |
| 98 | // embedded file |attachment|, overwriting the existing value if any. The value |
| 99 | // type should be FPDF_OBJECT_STRING after this function call succeeds. |
| 100 | // |
| 101 | // attachment - handle to an attachment. |
| 102 | // key - the key to the dictionary entry, encoded in UTF16-LE. |
| 103 | // value - the string value to be set, encoded in UTF16-LE. |
| 104 | // |
| 105 | // Returns true if successful. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 106 | DLLEXPORT FPDF_BOOL STDCALL |
Jane Liu | 54a4214 | 2017-07-24 16:40:54 -0400 | [diff] [blame] | 107 | FPDFAttachment_SetStringValue(FPDF_ATTACHMENT attachment, |
| 108 | FPDF_WIDESTRING key, |
| 109 | FPDF_WIDESTRING value); |
| 110 | |
| 111 | // Experimental API. |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 112 | // Get the string value corresponding to |key| in the params dictionary of the |
| 113 | // embedded file |attachment|. |buffer| is only modified if |buflen| is longer |
| 114 | // than the length of the string value. Note that if |key| does not exist in the |
| 115 | // dictionary or if |key|'s corresponding value in the dictionary is not a |
| 116 | // string (i.e. the value is not of type FPDF_OBJECT_STRING or |
| 117 | // FPDF_OBJECT_NAME), then an empty string would be copied to |buffer| and the |
| 118 | // return value would be 2. On other errors, nothing would be added to |buffer| |
| 119 | // and the return value would be 0. |
| 120 | // |
| 121 | // attachment - handle to an attachment. |
| 122 | // key - the key to the requested string value. |
Jane Liu | 54a4214 | 2017-07-24 16:40:54 -0400 | [diff] [blame] | 123 | // buffer - buffer for holding the string value encoded in UTF16-LE. |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 124 | // buflen - length of the buffer. |
| 125 | // |
| 126 | // Returns the length of the dictionary value string. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 127 | DLLEXPORT unsigned long STDCALL |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 128 | FPDFAttachment_GetStringValue(FPDF_ATTACHMENT attachment, |
| 129 | FPDF_WIDESTRING key, |
| 130 | void* buffer, |
| 131 | unsigned long buflen); |
| 132 | |
| 133 | // Experimental API. |
Jane Liu | 54a4214 | 2017-07-24 16:40:54 -0400 | [diff] [blame] | 134 | // Set the file data of |attachment|, overwriting the existing file data if any. |
| 135 | // The creation date and checksum will be updated, while all other dictionary |
| 136 | // entries will be deleted. Note that only contents with |len| smaller than |
| 137 | // INT_MAX is supported. |
| 138 | // |
| 139 | // attachment - handle to an attachment. |
| 140 | // contents - buffer holding the file data to be written in raw bytes. |
| 141 | // len - length of file data. |
| 142 | // |
| 143 | // Returns true if successful. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 144 | DLLEXPORT FPDF_BOOL STDCALL FPDFAttachment_SetFile(FPDF_ATTACHMENT attachment, |
| 145 | FPDF_DOCUMENT document, |
| 146 | const void* contents, |
| 147 | const unsigned long len); |
Jane Liu | 54a4214 | 2017-07-24 16:40:54 -0400 | [diff] [blame] | 148 | |
| 149 | // Experimental API. |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 150 | // Get the file data of |attachment|. |buffer| is only modified if |buflen| is |
| 151 | // longer than the length of the file. On errors, |buffer| is unmodified and the |
| 152 | // returned length is 0. |
| 153 | // |
| 154 | // attachment - handle to an attachment. |
Jane Liu | 54a4214 | 2017-07-24 16:40:54 -0400 | [diff] [blame] | 155 | // buffer - buffer for holding the file data in raw bytes. |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 156 | // buflen - length of the buffer. |
| 157 | // |
| 158 | // Returns the length of the file. |
Henrique Nakashima | 7e805d1 | 2017-08-10 15:13:19 +0000 | [diff] [blame] | 159 | DLLEXPORT unsigned long STDCALL |
Jane Liu | 18ae06d | 2017-07-18 10:15:16 -0400 | [diff] [blame] | 160 | FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment, |
| 161 | void* buffer, |
| 162 | unsigned long buflen); |
Jane Liu | 53aafa9 | 2017-07-12 19:55:02 -0400 | [diff] [blame] | 163 | |
| 164 | #ifdef __cplusplus |
| 165 | } // extern "C" |
| 166 | #endif // __cplusplus |
| 167 | |
| 168 | #endif // PUBLIC_FPDF_ATTACHMENT_H_ |