1/* poppler-form-field.h: glib interface to poppler
2 *
3 * Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
4 * Copyright (C) 2021 André Guerreiro <aguerreiro1985@gmail.com>
5 * Copyright (C) 2021, 2023 Marek Kasik <mkasik@redhat.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#ifndef __POPPLER_FORM_FIELD_H__
23#define __POPPLER_FORM_FIELD_H__
24
25#include <glib-object.h>
26#include "poppler.h"
27
28G_BEGIN_DECLS
29
30#define POPPLER_TYPE_FORM_FIELD (poppler_form_field_get_type())
31#define POPPLER_FORM_FIELD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), POPPLER_TYPE_FORM_FIELD, PopplerFormField))
32#define POPPLER_IS_FORM_FIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), POPPLER_TYPE_FORM_FIELD))
33
34/**
35 * PopplerSignatureStatus
36 * @POPPLER_SIGNATURE_VALID: signature is cryptographically valid
37 * @POPPLER_SIGNATURE_INVALID: signature is cryptographically invalid
38 * @POPPLER_SIGNATURE_DIGEST_MISMATCH: document content was changed after the signature was applied
39 * @POPPLER_SIGNATURE_DECODING_ERROR: signature CMS/PKCS7 structure is malformed
40 * @POPPLER_SIGNATURE_GENERIC_ERROR: failed to verify signature
41 * @POPPLER_SIGNATURE_NOT_FOUND: requested signature is not present in the document
42 * @POPPLER_SIGNATURE_NOT_VERIFIED: signature not yet verified
43 *
44 * Signature verification results
45 *
46 * Since: 21.12.0
47 */
48typedef enum
49{
50 POPPLER_SIGNATURE_VALID,
51 POPPLER_SIGNATURE_INVALID,
52 POPPLER_SIGNATURE_DIGEST_MISMATCH,
53 POPPLER_SIGNATURE_DECODING_ERROR,
54 POPPLER_SIGNATURE_GENERIC_ERROR,
55 POPPLER_SIGNATURE_NOT_FOUND,
56 POPPLER_SIGNATURE_NOT_VERIFIED
57} PopplerSignatureStatus;
58
59/**
60 * PopplerCertificateStatus
61 * @POPPLER_CERTIFICATE_TRUSTED: certificate is considered trusted
62 * @POPPLER_CERTIFICATE_UNTRUSTED_ISSUER: the issuer of this certificate has been marked as untrusted by the user
63 * @POPPLER_CERTIFICATE_UNKNOWN_ISSUER: this certificate trust chain has not finished in a trusted root certificate
64 * @POPPLER_CERTIFICATE_REVOKED: certificate was revoked by the issuing certificate authority
65 * @POPPLER_CERTIFICATE_EXPIRED: signing time is outside the validity bounds of this certificate
66 * @POPPLER_CERTIFICATE_GENERIC_ERROR: failed to verify certificate
67 * @POPPLER_CERTIFICATE_NOT_VERIFIED: certificate not yet verified
68 *
69 * Signature certificate verification results
70 *
71 * Since: 21.12.0
72 */
73typedef enum
74{
75 POPPLER_CERTIFICATE_TRUSTED,
76 POPPLER_CERTIFICATE_UNTRUSTED_ISSUER,
77 POPPLER_CERTIFICATE_UNKNOWN_ISSUER,
78 POPPLER_CERTIFICATE_REVOKED,
79 POPPLER_CERTIFICATE_EXPIRED,
80 POPPLER_CERTIFICATE_GENERIC_ERROR,
81 POPPLER_CERTIFICATE_NOT_VERIFIED
82} PopplerCertificateStatus;
83
84/**
85 * PopplerSignatureValidationFlags
86 * @POPPLER_SIGNATURE_VALIDATION_FLAG_VALIDATE_CERTIFICATE: Whether to validate also the certificate of the signature
87 * @POPPLER_SIGNATURE_VALIDATION_FLAG_WITHOUT_OCSP_REVOCATION_CHECK: Whether to not do OCSP (Online Certificate Status Protocol) revocation check
88 * @POPPLER_SIGNATURE_VALIDATION_FLAG_USE_AIA_CERTIFICATE_FETCH: Whether to use AIA (Authority Information Access) extension for certificate fetching
89 *
90 * Signature validation flags
91 *
92 * Since: 21.12.0
93 */
94typedef enum /*< flags >*/
95{
96 POPPLER_SIGNATURE_VALIDATION_FLAG_VALIDATE_CERTIFICATE = 1 << 0,
97 POPPLER_SIGNATURE_VALIDATION_FLAG_WITHOUT_OCSP_REVOCATION_CHECK = 1 << 1,
98 POPPLER_SIGNATURE_VALIDATION_FLAG_USE_AIA_CERTIFICATE_FETCH = 1 << 2,
99} PopplerSignatureValidationFlags;
100
101typedef enum
102{
103 POPPLER_FORM_FIELD_UNKNOWN,
104 POPPLER_FORM_FIELD_BUTTON,
105 POPPLER_FORM_FIELD_TEXT,
106 POPPLER_FORM_FIELD_CHOICE,
107 POPPLER_FORM_FIELD_SIGNATURE
108} PopplerFormFieldType;
109
110typedef enum
111{
112 POPPLER_FORM_BUTTON_PUSH,
113 POPPLER_FORM_BUTTON_CHECK,
114 POPPLER_FORM_BUTTON_RADIO
115} PopplerFormButtonType;
116
117typedef enum
118{
119 POPPLER_FORM_TEXT_NORMAL,
120 POPPLER_FORM_TEXT_MULTILINE,
121 POPPLER_FORM_TEXT_FILE_SELECT
122} PopplerFormTextType;
123
124typedef enum
125{
126 POPPLER_FORM_CHOICE_COMBO,
127 POPPLER_FORM_CHOICE_LIST
128} PopplerFormChoiceType;
129
130/**
131 * PopplerAdditionalActionType:
132 * @POPPLER_ADDITIONAL_ACTION_FIELD_MODIFIED: The action to be performed when the user modifies the field.
133 * @POPPLER_ADDITIONAL_ACTION_FORMAT_FIELD: The action to be performed before the field is formatted to
134 * display its value.
135 * @POPPLER_ADDITIONAL_ACTION_VALIDATE_FIELD: The action to be performed when the field value changes.
136 * @POPPLER_ADDITIONAL_ACTION_CALCULATE_FIELD: The action to be performed when the field needs to be
137 * recalculated.
138 *
139 * Form field additional action types to be passed to @poppler_form_field_get_additional_action
140 *
141 * Since: 0.72
142 */
143typedef enum
144{
145 POPPLER_ADDITIONAL_ACTION_FIELD_MODIFIED,
146 POPPLER_ADDITIONAL_ACTION_FORMAT_FIELD,
147 POPPLER_ADDITIONAL_ACTION_VALIDATE_FIELD,
148 POPPLER_ADDITIONAL_ACTION_CALCULATE_FIELD
149} PopplerAdditionalActionType;
150
151POPPLER_PUBLIC
152GType poppler_form_field_get_type(void) G_GNUC_CONST;
153
154POPPLER_PUBLIC
155PopplerFormFieldType poppler_form_field_get_field_type(PopplerFormField *field);
156POPPLER_PUBLIC
157gint poppler_form_field_get_id(PopplerFormField *field);
158POPPLER_PUBLIC
159gdouble poppler_form_field_get_font_size(PopplerFormField *field);
160POPPLER_PUBLIC
161gboolean poppler_form_field_is_read_only(PopplerFormField *field);
162POPPLER_PUBLIC
163gchar *poppler_form_field_get_partial_name(PopplerFormField *field);
164POPPLER_PUBLIC
165gchar *poppler_form_field_get_mapping_name(PopplerFormField *field);
166POPPLER_PUBLIC
167gchar *poppler_form_field_get_name(PopplerFormField *field);
168POPPLER_PUBLIC
169PopplerAction *poppler_form_field_get_action(PopplerFormField *field);
170POPPLER_PUBLIC
171PopplerAction *poppler_form_field_get_additional_action(PopplerFormField *field, PopplerAdditionalActionType type);
172POPPLER_PUBLIC
173gchar *poppler_form_field_get_alternate_ui_name(PopplerFormField *field);
174
175/* Button Field */
176POPPLER_PUBLIC
177PopplerFormButtonType poppler_form_field_button_get_button_type(PopplerFormField *field);
178POPPLER_PUBLIC
179gboolean poppler_form_field_button_get_state(PopplerFormField *field);
180POPPLER_PUBLIC
181void poppler_form_field_button_set_state(PopplerFormField *field, gboolean state);
182
183/* Text Field */
184POPPLER_PUBLIC
185PopplerFormTextType poppler_form_field_text_get_text_type(PopplerFormField *field);
186POPPLER_PUBLIC
187gchar *poppler_form_field_text_get_text(PopplerFormField *field);
188POPPLER_PUBLIC
189void poppler_form_field_text_set_text(PopplerFormField *field, const gchar *text);
190POPPLER_PUBLIC
191gint poppler_form_field_text_get_max_len(PopplerFormField *field);
192POPPLER_PUBLIC
193gboolean poppler_form_field_text_do_spell_check(PopplerFormField *field);
194POPPLER_PUBLIC
195gboolean poppler_form_field_text_do_scroll(PopplerFormField *field);
196POPPLER_PUBLIC
197gboolean poppler_form_field_text_is_rich_text(PopplerFormField *field);
198POPPLER_PUBLIC
199gboolean poppler_form_field_text_is_password(PopplerFormField *field);
200
201/* Choice Field */
202POPPLER_PUBLIC
203PopplerFormChoiceType poppler_form_field_choice_get_choice_type(PopplerFormField *field);
204POPPLER_PUBLIC
205gboolean poppler_form_field_choice_is_editable(PopplerFormField *field);
206POPPLER_PUBLIC
207gboolean poppler_form_field_choice_can_select_multiple(PopplerFormField *field);
208POPPLER_PUBLIC
209gboolean poppler_form_field_choice_do_spell_check(PopplerFormField *field);
210POPPLER_PUBLIC
211gboolean poppler_form_field_choice_commit_on_change(PopplerFormField *field);
212POPPLER_PUBLIC
213gint poppler_form_field_choice_get_n_items(PopplerFormField *field);
214POPPLER_PUBLIC
215gchar *poppler_form_field_choice_get_item(PopplerFormField *field, gint index);
216POPPLER_PUBLIC
217gboolean poppler_form_field_choice_is_item_selected(PopplerFormField *field, gint index);
218POPPLER_PUBLIC
219void poppler_form_field_choice_select_item(PopplerFormField *field, gint index);
220POPPLER_PUBLIC
221void poppler_form_field_choice_unselect_all(PopplerFormField *field);
222POPPLER_PUBLIC
223void poppler_form_field_choice_toggle_item(PopplerFormField *field, gint index);
224POPPLER_PUBLIC
225void poppler_form_field_choice_set_text(PopplerFormField *field, const gchar *text);
226POPPLER_PUBLIC
227gchar *poppler_form_field_choice_get_text(PopplerFormField *field);
228POPPLER_PUBLIC
229PopplerSignatureInfo *poppler_form_field_signature_validate_sync(PopplerFormField *field, PopplerSignatureValidationFlags flags, GCancellable *cancellable, GError **error);
230POPPLER_PUBLIC
231void poppler_form_field_signature_validate_async(PopplerFormField *field, PopplerSignatureValidationFlags flags, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
232POPPLER_PUBLIC
233PopplerSignatureInfo *poppler_form_field_signature_validate_finish(PopplerFormField *field, GAsyncResult *result, GError **error);
234
235/* Signature Field */
236#define POPPLER_TYPE_SIGNATURE_INFO (poppler_signature_info_get_type())
237POPPLER_PUBLIC
238GType poppler_signature_info_get_type(void) G_GNUC_CONST;
239POPPLER_PUBLIC
240PopplerSignatureInfo *poppler_signature_info_copy(const PopplerSignatureInfo *siginfo);
241POPPLER_PUBLIC
242void poppler_signature_info_free(PopplerSignatureInfo *siginfo);
243POPPLER_PUBLIC
244PopplerSignatureStatus poppler_signature_info_get_signature_status(const PopplerSignatureInfo *siginfo);
245POPPLER_PUBLIC
246PopplerCertificateStatus poppler_signature_info_get_certificate_status(const PopplerSignatureInfo *siginfo);
247POPPLER_PUBLIC
248PopplerCertificateInfo *poppler_signature_info_get_certificate_info(const PopplerSignatureInfo *siginfo);
249POPPLER_PUBLIC
250const gchar *poppler_signature_info_get_signer_name(const PopplerSignatureInfo *siginfo);
251POPPLER_PUBLIC
252GDateTime *poppler_signature_info_get_local_signing_time(const PopplerSignatureInfo *siginfo);
253
254/* Signing Data */
255#define POPPLER_TYPE_SIGNING_DATA (poppler_signing_data_get_type())
256POPPLER_PUBLIC
257GType poppler_signing_data_get_type(void) G_GNUC_CONST;
258POPPLER_PUBLIC
259PopplerSigningData *poppler_signing_data_new(void);
260POPPLER_PUBLIC
261PopplerSigningData *poppler_signing_data_copy(const PopplerSigningData *signing_data);
262POPPLER_PUBLIC
263void poppler_signing_data_free(PopplerSigningData *signing_data);
264POPPLER_PUBLIC
265void poppler_signing_data_set_destination_filename(PopplerSigningData *signing_data, const gchar *filename);
266POPPLER_PUBLIC
267const gchar *poppler_signing_data_get_destination_filename(const PopplerSigningData *signing_data);
268POPPLER_PUBLIC
269void poppler_signing_data_set_certificate_info(PopplerSigningData *signing_data, const PopplerCertificateInfo *certificate_info);
270POPPLER_PUBLIC
271const PopplerCertificateInfo *poppler_signing_data_get_certificate_info(const PopplerSigningData *signing_data);
272POPPLER_PUBLIC
273void poppler_signing_data_set_page(PopplerSigningData *signing_data, int page);
274POPPLER_PUBLIC
275int poppler_signing_data_get_page(const PopplerSigningData *signing_data);
276POPPLER_PUBLIC
277void poppler_signing_data_set_signature_text(PopplerSigningData *signing_data, const gchar *signature_text);
278POPPLER_PUBLIC
279const gchar *poppler_signing_data_get_signature_text(const PopplerSigningData *signing_data);
280POPPLER_PUBLIC
281void poppler_signing_data_set_signature_text_left(PopplerSigningData *signing_data, const gchar *signature_text_left);
282POPPLER_PUBLIC
283const gchar *poppler_signing_data_get_signature_text_left(const PopplerSigningData *signing_data);
284POPPLER_PUBLIC
285void poppler_signing_data_set_signature_rectangle(PopplerSigningData *signing_data, const PopplerRectangle *signature_rect);
286POPPLER_PUBLIC
287const PopplerRectangle *poppler_signing_data_get_signature_rectangle(const PopplerSigningData *signing_data);
288POPPLER_PUBLIC
289void poppler_signing_data_set_font_color(PopplerSigningData *signing_data, const PopplerColor *font_color);
290POPPLER_PUBLIC
291const PopplerColor *poppler_signing_data_get_font_color(const PopplerSigningData *signing_data);
292POPPLER_PUBLIC
293void poppler_signing_data_set_font_size(PopplerSigningData *signing_data, gdouble font_size);
294POPPLER_PUBLIC
295gdouble poppler_signing_data_get_font_size(const PopplerSigningData *signing_data);
296POPPLER_PUBLIC
297void poppler_signing_data_set_left_font_size(PopplerSigningData *signing_data, gdouble font_size);
298POPPLER_PUBLIC
299gdouble poppler_signing_data_get_left_font_size(const PopplerSigningData *signing_data);
300POPPLER_PUBLIC
301void poppler_signing_data_set_border_color(PopplerSigningData *signing_data, const PopplerColor *border_color);
302POPPLER_PUBLIC
303const PopplerColor *poppler_signing_data_get_border_color(const PopplerSigningData *signing_data);
304POPPLER_PUBLIC
305void poppler_signing_data_set_border_width(PopplerSigningData *signing_data, gdouble border_width);
306POPPLER_PUBLIC
307gdouble poppler_signing_data_get_border_width(const PopplerSigningData *signing_data);
308POPPLER_PUBLIC
309void poppler_signing_data_set_background_color(PopplerSigningData *signing_data, const PopplerColor *background_color);
310POPPLER_PUBLIC
311const PopplerColor *poppler_signing_data_get_background_color(const PopplerSigningData *signing_data);
312POPPLER_PUBLIC
313void poppler_signing_data_set_field_partial_name(PopplerSigningData *signing_data, const gchar *field_partial_name);
314POPPLER_PUBLIC
315const gchar *poppler_signing_data_get_field_partial_name(const PopplerSigningData *signing_data);
316POPPLER_PUBLIC
317void poppler_signing_data_set_reason(PopplerSigningData *signing_data, const gchar *reason);
318POPPLER_PUBLIC
319const gchar *poppler_signing_data_get_reason(const PopplerSigningData *signing_data);
320POPPLER_PUBLIC
321void poppler_signing_data_set_location(PopplerSigningData *signing_data, const gchar *location);
322POPPLER_PUBLIC
323const gchar *poppler_signing_data_get_location(const PopplerSigningData *signing_data);
324POPPLER_PUBLIC
325void poppler_signing_data_set_image_path(PopplerSigningData *signing_data, const gchar *image_path);
326POPPLER_PUBLIC
327const gchar *poppler_signing_data_get_image_path(const PopplerSigningData *signing_data);
328POPPLER_PUBLIC
329void poppler_signing_data_set_password(PopplerSigningData *signing_data, const gchar *password);
330POPPLER_PUBLIC
331const gchar *poppler_signing_data_get_password(const PopplerSigningData *signing_data);
332POPPLER_PUBLIC
333void poppler_signing_data_set_document_owner_password(PopplerSigningData *signing_data, const gchar *document_owner_password);
334POPPLER_PUBLIC
335const gchar *poppler_signing_data_get_document_owner_password(const PopplerSigningData *signing_data);
336POPPLER_PUBLIC
337void poppler_signing_data_set_document_user_password(PopplerSigningData *signing_data, const gchar *document_user_password);
338POPPLER_PUBLIC
339const gchar *poppler_signing_data_get_document_user_password(const PopplerSigningData *signing_data);
340
341/* Certificate Information */
342#define POPPLER_TYPE_CERTIFICATE_INFO (poppler_certificate_info_get_type())
343POPPLER_PUBLIC
344GType poppler_certificate_info_get_type(void) G_GNUC_CONST;
345PopplerCertificateInfo *poppler_certificate_info_new(void);
346POPPLER_PUBLIC
347PopplerCertificateInfo *poppler_certificate_info_copy(const PopplerCertificateInfo *certificate_info);
348POPPLER_PUBLIC
349void poppler_certificate_info_free(PopplerCertificateInfo *certificate_info);
350POPPLER_PUBLIC
351const char *poppler_certificate_info_get_id(const PopplerCertificateInfo *certificate_info);
352POPPLER_PUBLIC
353const char *poppler_certificate_info_get_subject_common_name(const PopplerCertificateInfo *certificate_info);
354POPPLER_PUBLIC
355const char *poppler_certificate_info_get_subject_organization(const PopplerCertificateInfo *certificate_info);
356POPPLER_PUBLIC
357const char *poppler_certificate_info_get_subject_email(const PopplerCertificateInfo *certificate_info);
358POPPLER_PUBLIC
359const char *poppler_certificate_info_get_issuer_common_name(const PopplerCertificateInfo *certificate_info);
360POPPLER_PUBLIC
361const char *poppler_certificate_info_get_issuer_organization(const PopplerCertificateInfo *certificate_info);
362POPPLER_PUBLIC
363const char *poppler_certificate_info_get_issuer_email(const PopplerCertificateInfo *certificate_info);
364POPPLER_PUBLIC
365GDateTime *poppler_certificate_info_get_issuance_time(const PopplerCertificateInfo *certificate_info);
366POPPLER_PUBLIC
367GDateTime *poppler_certificate_info_get_expiration_time(const PopplerCertificateInfo *certificate_info);
368POPPLER_PUBLIC
369PopplerCertificateInfo *poppler_get_certificate_info_by_id(const char *id);
370POPPLER_PUBLIC
371GList *poppler_get_available_signing_certificates(void);
372
373/* NSS */
374POPPLER_PUBLIC
375void poppler_set_nss_dir(const char *path);
376POPPLER_PUBLIC
377char *poppler_get_nss_dir(void);
378typedef char *(*PopplerNssPasswordFunc)(const gchar *text);
379POPPLER_PUBLIC
380void poppler_set_nss_password_callback(PopplerNssPasswordFunc func);
381
382G_END_DECLS
383
384#endif /* __POPPLER_FORM_FIELD_H__ */
385

source code of poppler/glib/poppler-form-field.h