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