doc: System message case 11 and XML document
[libisds.git] / src / isds.h
blob5d52df6ec419605c86f23890d57b2e654ef67049
1 #ifndef __ISDS_ISDS_H__
2 #define __ISDS_ISDS_H__
4 /* Public interface for libisds.
5 * Private declarations in isds_priv.h. */
7 #include <stdlib.h> /* For size_t */
8 #include <time.h> /* For struct tm */
9 #include <sys/time.h> /* For struct timeval */
10 #include <libxml/tree.h> /* Gor xmlDoc and xmlNodePtr */
12 #ifdef __cplusplus /* For C++ linker sake */
13 extern "C" {
14 #endif
16 /* _deprecated macro marks library symbols as deprecated. Application should
17 * avoid using such function as soon as possible. */
18 #if defined(__GNUC__)
19 #define _deprecated __attribute__((deprecated))
20 #else
21 #define _deprecated
22 #endif
24 /* Service locators */
25 /* Base URL of production ISDS instance */
26 extern const char isds_locator[]; /* Without client certificate auth. */
27 extern const char isds_cert_locator[]; /* With client certificate auth. */
28 extern const char isds_otp_locator[]; /* With OTP authentication */
29 /* Base URL of testing ISDS instance */
30 extern const char isds_testing_locator[]; /* Without client certificate */
31 extern const char isds_cert_testing_locator[]; /* With client certificate */
32 extern const char isds_otp_testing_locator[]; /* With OTP authentication */
35 struct isds_ctx; /* Context for specific ISDS box */
37 typedef enum {
38 IE_SUCCESS = 0, /* No error, just for C convenience (0 means Ok) */
39 IE_ERROR, /* Unspecified error */
40 IE_NOTSUP,
41 IE_INVAL,
42 IE_INVALID_CONTEXT,
43 IE_NOT_LOGGED_IN,
44 IE_CONNECTION_CLOSED,
45 IE_TIMED_OUT,
46 IE_NOEXIST,
47 IE_NOMEM,
48 IE_NETWORK,
49 IE_HTTP,
50 IE_SOAP,
51 IE_XML,
52 IE_ISDS,
53 IE_ENUM,
54 IE_DATE,
55 IE_2BIG,
56 IE_2SMALL,
57 IE_NOTUNIQ,
58 IE_NOTEQUAL,
59 IE_PARTIAL_SUCCESS,
60 IE_ABORTED
61 } isds_error;
63 typedef enum {
64 ILL_NONE = 0,
65 ILL_CRIT = 10,
66 ILL_ERR = 20,
67 ILL_WARNING = 30,
68 ILL_INFO = 40,
69 ILL_DEBUG = 50,
70 ILL_ALL = 100
71 } isds_log_level;
73 typedef enum {
74 ILF_NONE = 0x0,
75 ILF_HTTP = 0x1,
76 ILF_SOAP = 0x2,
77 ILF_ISDS = 0x4,
78 ILF_FILE = 0x8,
79 ILF_SEC = 0x10,
80 ILF_XML = 0x20,
81 ILF_ALL = 0xFF
82 } isds_log_facility;
84 /* Return text description of ISDS error */
85 const char *isds_strerror(const isds_error error);
87 /* libisds options */
88 typedef enum {
89 IOPT_TLS_VERIFY_SERVER, /* _Bool: Verify server identity?
90 Default value is true. */
91 IOPT_TLS_CA_FILE, /* char *: File name with CA certificates.
92 Default value depends on cryptographic
93 library. */
94 IOPT_TLS_CA_DIRECTORY, /* char *: Directory name with CA certificates.
95 Default value depends on cryptographic
96 library. */
97 IOPT_TLS_CRL_FILE, /* char *: File name with CRL in PEM format.
98 Default value depends on cryptographic
99 library. */
100 IOPT_NORMALIZE_MIME_TYPE, /* _Bool: Normalize MIME type values?
101 Default value is false. */
102 } isds_option;
104 /* TLS libisds options */
105 typedef enum {
106 ITLS_VERIFY_SERVER, /* _Bool: Verify server identity? */
107 ITLS_CA_FILE, /* char *: File name with CA certificates */
108 ITLS_CA_DIRECTORY, /* char *: Directory name with CA certificates */
109 ITLS_CRL_FILE /* char *: File name with CRL in PEM format */
110 } isds_tls_option;
112 /* Cryptographic material encoding */
113 typedef enum {
114 PKI_FORMAT_PEM, /* PEM format */
115 PKI_FORMAT_DER, /* DER format */
116 PKI_FORMAT_ENG /* Stored in crypto engine */
117 } isds_pki_format;
119 /* Public key crypto material to authenticate client */
120 struct isds_pki_credentials {
121 char *engine; /* String identifier of crypto engine to use
122 (where key is stored). Use NULL for no engine */
123 isds_pki_format certificate_format; /* Certificate format */
124 char *certificate; /* Path to client certificate, or certificate
125 nickname in case of NSS as curl back-end,
126 or key slot identifier inside crypto engine.
127 Some crypto engines can pair certificate with
128 key automatically (NULL value) */
129 isds_pki_format key_format; /* Private key format */
130 char *key; /* Path to client private key, or key identifier
131 in case of used engine */
132 char *passphrase; /* Zero terminated string with password for
133 decrypting private key, or engine PIN.
134 Use NULL for no pass-phrase or question by
135 engine. */
138 /* One-time password authentication method */
139 typedef enum {
140 OTP_HMAC = 0, /* HMAC-based OTP method */
141 OTP_TIME /* Time-based OTP method */
142 } isds_otp_method;
144 /* One-time passwed authentication resolution */
145 typedef enum {
146 OTP_RESOLUTION_SUCCESS = 0, /* Authentication succeded */
147 OTP_RESOLUTION_UNKNOWN, /* Status is unkown */
148 OTP_RESOLUTION_BAD_AUTHENTICATION, /* Bad log-in, retry */
149 OTP_RESOLUTION_ACCESS_BLOCKED, /* Access blocked for 60 minutes
150 (brute force attack detected) */
151 OTP_RESOLUTION_PASSWORD_EXPIRED, /* Password has expired.
152 ???: OTP or regular password
153 expired? */
154 OTP_RESOLUTION_TO_FAST, /* OTP cannot be sent repeatedly
155 at this rate (minimal delay
156 depends on TOTP window setting) */
157 OTP_RESOLUTION_UNAUTHORIZED, /* User name is not allowed to
158 access requested URI */
159 OTP_RESOLUTION_TOTP_SENT, /* OTP has been generated and sent by
160 ISDS */
161 OTP_RESOLUTION_TOTP_NOT_SENT, /* OTP could not been sent.
162 Retry later. */
163 } isds_otp_resolution;
165 /* One-time password to authenticate client */
166 struct isds_otp {
167 /* Input members */
168 isds_otp_method method; /* Select OTP method to use */
169 char *otp_code; /* One-time password to use. Pass NULL,
170 if you do not know it yet (e.g. in case
171 of first phase of time-based OTP to
172 request new code from ISDS.) */
173 /* Output members */
174 isds_otp_resolution resolution; /* Fine-grade resolution of OTP
175 authentication attempt. */
178 /* Box type */
179 typedef enum {
180 DBTYPE_SYSTEM = 0, /* This is special sender value for messages
181 sent by ISDS. */
182 DBTYPE_OVM = 10,
183 DBTYPE_OVM_NOTAR = 11,
184 DBTYPE_OVM_EXEKUT = 12,
185 DBTYPE_OVM_REQ = 13,
186 DBTYPE_PO = 20,
187 DBTYPE_PO_ZAK = 21,
188 DBTYPE_PO_REQ = 22,
189 DBTYPE_PFO = 30,
190 DBTYPE_PFO_ADVOK = 31,
191 DBTYPE_PFO_DANPOR = 32,
192 DBTYPE_PFO_INSSPR = 33,
193 DBTYPE_FO = 40
194 } isds_DbType;
196 /* Box status from point of view of accessibility */
197 typedef enum {
198 DBSTATE_ACCESSIBLE = 1,
199 DBSTATE_TEMP_UNACCESSIBLE = 2,
200 DBSTATE_NOT_YET_ACCESSIBLE = 3,
201 DBSTATE_PERM_UNACCESSIBLE = 4,
202 DBSTATE_REMOVED = 5
203 } isds_DbState;
205 /* User permissions from point of view of ISDS.
206 * Instances can be bitmaps of any discrete values. */
207 typedef enum {
208 PRIVIL_READ_NON_PERSONAL = 0x1, /* Can download and read messages with
209 dmPersonalDelivery == false */
210 PRIVIL_READ_ALL = 0x2, /* Can download and read messages with
211 dmPersonalDelivery == true */
212 PRIVIL_CREATE_DM = 0x4, /* Can create and sent messages,
213 can download outgoing (sent) messages */
214 PRIVIL_VIEW_INFO = 0x8, /* Can list messages and data about
215 post and delivery */
216 PRIVIL_SEARCH_DB = 0x10, /* Can search for boxes */
217 PRIVIL_OWNER_ADM = 0x20, /* Can administer his box (add/remove
218 permitted users and theirs
219 permissions) */
220 PRIVIL_READ_VAULT = 0x40, /* Can read message stored in data safe */
221 PRIVIL_ERASE_VAULT = 0x80 /* Can delete messages from data safe */
222 } isds_priviledges;
224 /* Message status */
225 typedef enum {
226 MESSAGESTATE_SENT = 0x2, /* Message has been put into ISDS */
227 MESSAGESTATE_STAMPED = 0x4, /* Message stamped by TSA */
228 MESSAGESTATE_INFECTED = 0x8, /* Message included viruses,
229 infected document has been removed */
230 MESSAGESTATE_DELIVERED = 0x10, /* Message delivered
231 (dmDeliveryTime stored) */
232 MESSAGESTATE_SUBSTITUTED = 0x20, /* Message delivered through fiction,
233 dmAcceptanceTime stored */
234 MESSAGESTATE_RECEIVED = 0x40, /* Message accepted (by user log-in or
235 user explicit request),
236 dmAcceptanceTime stored */
237 MESSAGESTATE_READ = 0x80, /* Message has been read by user */
238 MESSAGESTATE_UNDELIVERABLE = 0x100, /* Message could not been delivered
239 (e.g. recipient box has been made
240 inaccessible meantime) */
241 MESSAGESTATE_REMOVED = 0x200, /* Message content deleted */
242 MESSAGESTATE_IN_SAFE = 0x400 /* Message stored in data safe */
244 } isds_message_status;
245 #define MESSAGESTATE_ANY 0x7FE /* Union of all isds_message_status
246 values */
248 /* Hash algorithm types */
249 typedef enum {
250 HASH_ALGORITHM_MD5,
251 HASH_ALGORITHM_SHA_1,
252 HASH_ALGORITHM_SHA_224,
253 HASH_ALGORITHM_SHA_256,
254 HASH_ALGORITHM_SHA_384,
255 HASH_ALGORITHM_SHA_512,
256 } isds_hash_algorithm;
258 /* Buffer storage strategy.
259 * How function should embed application provided buffer into raw element of
260 * output structure. */
261 typedef enum {
262 BUFFER_DONT_STORE, /* Don't fill raw member */
263 BUFFER_COPY, /* Copy buffer content into newly allocated raw */
264 BUFFER_MOVE /* Just copy pointer.
265 But leave deallocation to isds_*_free(). */
266 } isds_buffer_strategy;
268 /* Hash value storage */
269 struct isds_hash {
270 isds_hash_algorithm algorithm; /* Hash algorithm */
271 size_t length; /* Hash value length in bytes */
272 void *value; /* Hash value */
275 /* Name of person */
276 struct isds_PersonName {
277 char *pnFirstName;
278 char *pnMiddleName;
279 char *pnLastName;
280 char *pnLastNameAtBirth;
283 /* Date and place of birth */
284 struct isds_BirthInfo {
285 struct tm *biDate; /* Date of Birth in local time at birth place,
286 only tm_year, tm_mon and tm_mday carry sane
287 value */
288 char *biCity;
289 char *biCounty; /* German: Bezirk, Czech: okres */
290 char *biState;
293 /* Post address */
294 struct isds_Address {
295 char *adCity;
296 char *adStreet;
297 char *adNumberInStreet;
298 char *adNumberInMunicipality;
299 char *adZipCode;
300 char *adState;
303 /* Data about box and his owner.
304 * NULL pointer means undefined value */
305 struct isds_DbOwnerInfo {
306 char *dbID; /* Box ID [Max. 7 chars] */
307 isds_DbType *dbType; /* Box Type */
308 char *ic; /* ID */
309 struct isds_PersonName *personName; /* Name of person */
310 char *firmName; /* Name of firm */
311 struct isds_BirthInfo *birthInfo; /* Birth of person */
312 struct isds_Address *address; /* Post address */
313 char *nationality;
314 char *email;
315 char *telNumber;
316 char *identifier; /* External box identifier for data
317 provider (OVM, PO, maybe PFO)
318 [Max. 20 chars] */
319 char *registryCode; /* PFO External registry code
320 [Max. 5 chars] */
321 long int *dbState; /* Box state; 1 <=> active box;
322 long int because xsd:integer
323 TODO: enum? */
324 _Bool *dbEffectiveOVM; /* Box has OVM role (§ 5a) */
325 _Bool *dbOpenAddressing; /* Non-OVM Box is free to receive
326 messages from anybody */
329 /* User type */
330 typedef enum {
331 USERTYPE_PRIMARY, /* Owner of the box */
332 USERTYPE_ENTRUSTED, /* User with limited access to the box */
333 USERTYPE_ADMINISTRATOR, /* User to manage ENTRUSTED_USERs */
334 USERTYPE_OFFICIAL, /* ??? */
335 USERTYPE_OFFICIAL_CERT, /* ??? */
336 USERTYPE_LIQUIDATOR /* Company liquidator */
337 } isds_UserType;
339 /* Data about user.
340 * NULL pointer means undefined value */
341 struct isds_DbUserInfo {
342 char *userID; /* User ID [Min. 6, max. 12 characters] */
343 isds_UserType *userType; /* User type */
344 long int *userPrivils; /* Set of user permissions */
345 struct isds_PersonName *personName; /* Name of the person */
346 struct isds_Address *address; /* Post address */
347 struct tm *biDate; /* Date of birth in local time,
348 only tm_year, tm_mon and tm_mday carry sane
349 value */
350 char *ic; /* ID of a supervising firm [Max. 8 chars] */
351 char *firmName; /* Name of a supervising firm
352 [Max. 100 chars] */
353 char *caStreet; /* Street and number of contact address */
354 char *caCity; /* Czech City of contact address */
355 char *caZipCode; /* Post office code of contact address */
356 char *caState; /* Abbreviated country of contact address;
357 Implicit value is "CZ"; Optional. */
360 /* Message event type */
361 typedef enum {
362 EVENT_UKNOWN, /* Event unknown to this library */
363 EVENT_ACCEPTED_BY_RECIPIENT, /* Message has been delivered and accepted
364 by recipient action */
365 EVENT_ACCEPTED_BY_FICTION, /* Message has been delivered, acceptance
366 timed out, considered as accepted */
367 EVENT_UNDELIVERABLE, /* Recipient box made inaccessible,
368 thus message is undeliverable */
369 EVENT_COMMERCIAL_ACCEPTED, /* Recipient confirmed acceptance of
370 commercial message */
371 EVENT_ENTERED_SYSTEM, /* Message entered ISDS, i.e. has been just
372 sent by sender */
373 EVENT_DELIVERED, /* Message has been delivered */
374 EVENT_PRIMARY_LOGIN, /* Primary user has logged in */
375 EVENT_ENTRUSTED_LOGIN, /* Entrusted user with capability to read
376 has logged in */
377 EVENT_SYSCERT_LOGIN /* Application authenticated by `system'
378 certificate has logged in */
379 } isds_event_type;
381 /* Message event
382 * All members are optional as specification states so. */
383 struct isds_event {
384 struct timeval *time; /* When the event occurred */
385 isds_event_type *type; /* Type of the event */
386 char *description; /* Human readable event description
387 generated by ISDS (Czech) */
390 /* Message envelope
391 * Be ware that the string length constraints are forced only on output
392 * members transmitted to ISDS. The other direction (downloaded from ISDS)
393 * can break these rules. It should not happen, but nobody knows how much
394 * incompatible new version of ISDS protocol will be. This is the gold
395 * Internet rule: be strict on what you put, be tolerant on what you get. */
396 struct isds_envelope {
397 /* Following members apply to incoming messages only: */
398 char *dmID; /* Message ID.
399 Maximal length is 20 characters. */
400 char *dbIDSender; /* Box ID of sender.
401 Special value "aaaaaaa" means sent by
402 ISDS.
403 Maximal length is 7 characters. */
404 char *dmSender; /* Sender name;
405 Maximal length is 100 characters. */
406 char *dmSenderAddress; /* Postal address of sender;
407 Maximal length is 100 characters. */
408 long int *dmSenderType; /* Gross Box type of sender
409 TODO: isds_DbType ? */
410 char *dmRecipient; /* Recipient name;
411 Maximal length is 100 characters. */
412 char *dmRecipientAddress; /* Postal address of recipient;
413 Maximal length is 100 characters. */
414 _Bool *dmAmbiguousRecipient; /* Recipient has OVM role */
416 /* Following members are assigned by ISDS in different phases of message
417 * life cycle. */
418 unsigned long int *dmOrdinal; /* Ordinal number in list of
419 incoming/outgoing messages */
420 isds_message_status *dmMessageStatus; /* Message state */
421 long int *dmAttachmentSize; /* Size of message documents in
422 kilobytes (rounded). */
423 struct timeval *dmDeliveryTime; /* Time of delivery into a box
424 NULL, if message has not been
425 delivered yet */
426 struct timeval *dmAcceptanceTime; /* Time of acceptance of the message
427 by an user. NULL if message has not
428 been accepted yet. */
429 struct isds_hash *hash; /* Message hash.
430 This is hash of isds:dmDM subtree. */
431 void *timestamp; /* Qualified time stamp; Optional. */
432 size_t timestamp_length; /* Length of timestamp in bytes */
433 struct isds_list *events; /* Events message passed trough;
434 List of isds_event's. */
437 /* Following members apply to both outgoing and incoming messages: */
438 char *dmSenderOrgUnit; /* Organisation unit of sender as string;
439 Optional. */
440 long int *dmSenderOrgUnitNum; /* Organisation unit of sender as number;
441 Optional. */
442 char *dbIDRecipient; /* Box ID of recipient; Mandatory.
443 Maximal length is 7 characters. */
444 char *dmRecipientOrgUnit; /* Organisation unit of recipient as
445 string; Optional. */
446 long int *dmRecipientOrgUnitNum; /* Organisation unit of recipient as
447 number; Optional. */
448 char *dmToHands; /* Person in recipient organisation;
449 Optional. */
450 char *dmAnnotation; /* Subject (title) of the message.
451 Maximal length is 255 characters. */
452 char *dmRecipientRefNumber; /* Czech: číslo jednací příjemce; Optional.
453 Maximal length is 50 characters. */
454 char *dmSenderRefNumber; /* Czech: číslo jednací odesílatele;
455 Optional. Maximal length is 50 chars. */
456 char *dmRecipientIdent; /* Czech: spisová značka příjemce; Optional.
457 Maximal length is 50 characters. */
458 char *dmSenderIdent; /* Czech: spisová značka odesílatele;
459 Optional. Maximal length is 50 chars. */
461 /* Act addressing in Czech Republic:
462 * Point (Paragraph) § Section Law/Year Coll. */
463 long int *dmLegalTitleLaw; /* Number of act mandating authority */
464 long int *dmLegalTitleYear; /* Year of act issue mandating authority */
465 char *dmLegalTitleSect; /* Section of act mandating authority.
466 Czech: paragraf */
467 char *dmLegalTitlePar; /* Paragraph of act mandating authority.
468 Czech: odstavec */
469 char *dmLegalTitlePoint; /* Point of act mandating authority.
470 Czech: písmeno */
472 _Bool *dmPersonalDelivery; /* If true, only person with higher
473 privileges can read this message */
474 _Bool *dmAllowSubstDelivery; /* Allow delivery through fiction.
475 I.e. Even if recipient did not read this
476 message, message is considered as
477 delivered after (currently) 10 days.
478 This is delivery through fiction.
479 Applies only to OVM dbType sender. */
480 char *dmType; /* Message type:
481 "V" is public message
482 "K" is commercial message
483 Default value for outgoing message is "V"
484 Length: Exact 1 UTF-8 character if
485 defined;
486 As 2010-05-20, used as output only. */
488 /* Following members apply to outgoing messages only: */
489 _Bool *dmOVM; /* OVM sending mode.
490 Non-OVM dbType boxes that has
491 dbEffectiveOVM == true MUST select
492 between true (OVM mode) and
493 false (non-OVM mode).
494 Optional; Implicit value is true. */
495 _Bool *dmPublishOwnID; /* Allow sender to express his name shall
496 be available to recipient by
497 isds_get_message_sender(). Sender type
498 will be always available.
499 Optional; Default value is false. */
503 /* Document type from point of hierarchy */
504 typedef enum {
505 FILEMETATYPE_MAIN, /* Main document */
506 FILEMETATYPE_ENCLOSURE, /* Appendix */
507 FILEMETATYPE_SIGNATURE, /* Digital signature of other document */
508 FILEMETATYPE_META /* XML document for ESS (electronic
509 document information system) purposes */
510 } isds_FileMetaType;
512 /* Document */
513 struct isds_document {
514 _Bool is_xml; /* True if document is ISDS XML document.
515 False if document is ISDS binary
516 document. */
517 xmlNodePtr xml_node_list; /* XML node-set presenting current XML
518 document content. This is pointer to
519 first node of the document in
520 isds_message.xml tree. Use `children'
521 and `next' members to iterate the
522 document.
523 It will be NULL if document is empty.
524 Valid only if is_xml is true. */
525 void *data; /* Document content.
526 The encoding and interpretation depends
527 on dmMimeType.
528 Valid only if is_xml is false. */
529 size_t data_length; /* Length of the data in bytes.
530 Valid only if is_xml is false. */
532 char *dmMimeType; /* MIME type of data; Mandatory. */
533 isds_FileMetaType dmFileMetaType; /* Document type to create hierarchy */
534 char *dmFileGuid; /* Message-local document identifier;
535 Optional. */
536 char *dmUpFileGuid; /* Reference to upper document identifier
537 (dmFileGuid); Optional. */
538 char *dmFileDescr; /* Document name (title). E.g. file name;
539 Mandatory. */
540 char *dmFormat; /* Reference to XML form definition;
541 Defines how to interpret XML document;
542 Optional. */
545 /* Raw message representation content type.
546 * This is necessary to distinguish between different representations without
547 * expensive repeated detection.
548 * Infix explanation:
549 * PLAIN_SIGNED data are XML with namespace mangled to signed alternative
550 * CMS_SIGNED data are XML with signed namespace encapsulated in CMS */
551 typedef enum {
552 RAWTYPE_INCOMING_MESSAGE,
553 RAWTYPE_PLAIN_SIGNED_INCOMING_MESSAGE,
554 RAWTYPE_CMS_SIGNED_INCOMING_MESSAGE,
555 RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE,
556 RAWTYPE_CMS_SIGNED_OUTGOING_MESSAGE,
557 RAWTYPE_DELIVERYINFO,
558 RAWTYPE_PLAIN_SIGNED_DELIVERYINFO,
559 RAWTYPE_CMS_SIGNED_DELIVERYINFO
560 } isds_raw_type;
562 /* Message */
563 struct isds_message {
564 void *raw; /* Raw message in XML format as send to or
565 from the ISDS. You can use it to store
566 local copy. This is binary buffer. */
567 size_t raw_length; /* Length of raw message in bytes */
568 isds_raw_type raw_type; /* Content type of raw representation
569 Meaningful only with non-NULL raw
570 member */
571 xmlDocPtr xml; /* Parsed XML document with attached ISDS
572 message XML documents.
573 Can be NULL. May be freed AFTER deallocating
574 documents member structure. */
575 struct isds_envelope *envelope; /* Message envelope */
576 struct isds_list *documents; /* List of isds_document's.
577 Valid message must contain exactly one
578 document of type FILEMETATYPE_MAIN and
579 can contain any number of other type
580 documents. Total size of documents
581 must not exceed 10 MB. */
584 /* Message copy recipient and assigned message ID */
585 struct isds_message_copy {
586 /* Input members defined by application */
587 char *dbIDRecipient; /* Box ID of recipient; Mandatory.
588 Maximal length is 7 characters. */
589 char *dmRecipientOrgUnit; /* Organisation unit of recipient as
590 string; Optional. */
591 long int *dmRecipientOrgUnitNum; /* Organisation unit of recipient as
592 number; Optional. */
593 char *dmToHands; /* Person in recipient organisation;
594 Optional. */
596 /* Output members returned from ISDS */
597 isds_error error; /* libisds compatible error of delivery to o ne recipient */
598 char *dmStatus; /* Error description returned by ISDS;
599 Optional. */
600 char *dmID; /* Assigned message ID; Meaningful only
601 for error == IE_SUCCESS */
604 /* Message state change event */
605 struct isds_message_status_change {
606 char *dmID; /* Message ID. */
607 isds_message_status *dmMessageStatus; /* Message state */
608 struct timeval *time; /* When the state changed */
611 /* General linked list */
612 struct isds_list {
613 struct isds_list *next; /* Next list item,
614 or NULL if current is last */
615 void *data; /* Payload */
616 void (*destructor) (void **); /* Payload deallocator;
617 Use NULL to have static data member. */
620 /* External box approval */
621 struct isds_approval {
622 _Bool approved; /* True if request for box has been
623 approved out of ISDS */
624 char *refference; /* Identifier of the approval */
627 /* Message sender type.
628 * Similar but not equivalent to isds_UserType. */
629 typedef enum {
630 SENDERTYPE_PRIMARY, /* Owner of the box */
631 SENDERTYPE_ENTRUSTED, /* User with limited access to the box */
632 SENDERTYPE_ADMINISTRATOR, /* User to manage ENTRUSTED_USERs */
633 SENDERTYPE_OFFICIAL, /* ISDS; sender of system message */
634 SENDERTYPE_VIRTUAL, /* An application (e.g. document
635 information system) */
636 SENDERTYPE_OFFICIAL_CERT, /* ???; Non-normative */
637 SENDERTYPE_LIQUIDATOR /* Liquidator of the company; Non-normative */
638 } isds_sender_type;
640 /* Digital delivery of credentials */
641 struct isds_credentials_delivery {
642 /* Input members */
643 char *email; /* e-mail address where to send
644 notification with link to service where
645 user can get know his new credentials */
646 /* Output members */
647 char *token; /* token user needs to use to authorize on
648 the web server to view his new
649 credentials. */
650 char *new_user_name; /* user's log-in name that ISDS created/
651 changed up on a call. */
654 /* Initialize ISDS library.
655 * Global function, must be called before other functions.
656 * If it fails you can not use ISDS library and must call isds_cleanup() to
657 * free partially initialized global variables. */
658 isds_error isds_init(void);
660 /* Deinitialize ISDS library.
661 * Global function, must be called as last library function. */
662 isds_error isds_cleanup(void);
664 /* Return version string of this library. Version of dependencies can be
665 * embedded. Do no try to parse it. You must free it. */
666 char *isds_version(void);
668 /* Create ISDS context.
669 * Each context can be used for different sessions to (possibly) different
670 * ISDS server with different credentials.
671 * Returns new context, or NULL */
672 struct isds_ctx *isds_ctx_create(void);
674 /* Destroy ISDS context and free memory.
675 * @context will be NULLed on success. */
676 isds_error isds_ctx_free(struct isds_ctx **context);
678 /* Return long message text produced by library function, e.g. detailed error
679 * message. Returned pointer is only valid until new library function is
680 * called for the same context. Could be NULL, especially if NULL context is
681 * supplied. Return string is locale encoded. */
682 char *isds_long_message(const struct isds_ctx *context);
684 /* Set logging up.
685 * @facilities is bit mask of isds_log_facility values,
686 * @level is verbosity level. */
687 void isds_set_logging(const unsigned int facilities,
688 const isds_log_level level);
690 /* Function provided by application libisds will call to pass log message.
691 * The message is usually locale encoded, but raw strings (UTF-8 usually) can
692 * occur when logging raw communication with ISDS servers. Infixed zero byte
693 * is not excluded, but should not present. Use @length argument to get real
694 * length of the message.
695 * TODO: We will try to fix the encoding issue
696 * @facility is log message class
697 * @level is log message severity
698 * @message is string with zero byte terminator. This can be any arbitrary
699 * chunk of a sentence with or without new line, a sentence can be splitted
700 * into more messages. However it should not happen. If you discover message
701 * without new line, report it as a bug.
702 * @length is size of @message string in bytes excluding trailing zero
703 * @data is pointer that will be passed unchanged to this function at run-time
704 * */
705 typedef void (*isds_log_callback)(
706 isds_log_facility facility, isds_log_level level,
707 const char *message, int length, void *data);
709 /* Register callback function libisds calls when new global log message is
710 * produced by library. Library logs to stderr by default.
711 * @callback is function provided by application libisds will call. See type
712 * definition for @callback argument explanation. Pass NULL to revert logging to
713 * default behaviour.
714 * @data is application specific data @callback gets as last argument */
715 void isds_set_log_callback(isds_log_callback callback, void *data);
717 /* Set timeout in milliseconds for each network job like connecting to server
718 * or sending message. Use 0 to disable timeout limits. */
719 isds_error isds_set_timeout(struct isds_ctx *context,
720 const unsigned int timeout);
722 /* Function provided by application libisds will call with
723 * following five arguments. Value zero of any argument means the value is
724 * unknown.
725 * @upload_total is expected total upload,
726 * @upload_current is cumulative current upload progress
727 * @dowload_total is expected total download
728 * @download_current is cumulative current download progress
729 * @data is pointer that will be passed unchanged to this function at run-time
730 * @return 0 to continue HTTP transfer, or non-zero to abort transfer */
731 typedef int (*isds_progress_callback)(
732 double upload_total, double upload_current,
733 double download_total, double download_current,
734 void *data);
736 /* Register callback function libisds calls periodically during HTTP data
737 * transfer.
738 * @context is session context
739 * @callback is function provided by application libisds will call. See type
740 * definition for @callback argument explanation.
741 * @data is application specific data @callback gets as last argument */
742 isds_error isds_set_progress_callback(struct isds_ctx *context,
743 isds_progress_callback callback, void *data);
745 /* Change context settings.
746 * @context is context which setting will be applied to
747 * @option is name of option. It determines the type of last argument. See
748 * isds_option definition for more info.
749 * @... is value of new setting. Type is determined by @option
750 * */
751 isds_error isds_set_opt(struct isds_ctx *context, const isds_option option,
752 ...);
754 /* Connect and log into ISDS server.
755 * All required arguments will be copied, you do not have to keep them after
756 * that.
757 * ISDS supports six different authentication methods. Exact method is
758 * selected on @username, @password, @pki_credentials, and @otp arguments:
759 * - If @pki_credentials == NULL, @username and @password must be supplied
760 * and then
761 * - If @otp == NULL, simple authentication by username and password will
762 * be proceeded.
763 * - If @otp != NULL, authentication by username and password and OTP
764 * will be used.
765 * - If @pki_credentials != NULL, then
766 * - If @username == NULL, only certificate will be used
767 * - If @username != NULL, then
768 * - If @password == NULL, then certificate will be used and
769 * @username shifts meaning to box ID. This is used for hosted
770 * services.
771 * - Otherwise all three arguments will be used.
772 * Please note, that different cases require different certificate type
773 * (system qualified one or commercial non qualified one). This library
774 * does not check such political issues. Please see ISDS Specification
775 * for more details.
776 * @url is base address of ISDS web service. Pass extern isds_locator
777 * variable to use production ISDS instance without client certificate
778 * authentication (or extern isds_cert_locator with client certificate
779 * authentication or extern isds_otp_locators with OTP authentication).
780 * Passing NULL has the same effect, autoselection between isds_locator,
781 * isds_cert_locator, and isds_otp_locator is performed in addition. You can
782 * pass extern isds_testing_locator (or isds_cert_testing_locator or
783 * isds_otp_testing_locator) variable to select testing instance.
784 * @username is user name of ISDS user or box ID
785 * @password is user's secret password
786 * @pki_credentials defines public key cryptographic material to use in client
787 * authentication.
788 * @otp selects one-time password authentication method to use, defines OTP
789 * code (if known) and returns fine grade resolution of OTP procedure.
790 * @return:
791 * IE_SUCCESS if authentication succeeds
792 * IE_NOT_LOGGED_IN if authentication fails. If OTP authentication has been
793 * requested, fine grade reason will be set into @otp->resolution. Error
794 * message from server can be obtained by isds_long_message() call.
795 * IE_PARTIAL_SUCCESS if time-based OTP authentication has been requested and
796 * server has sent OTP code through side channel. Application is expected to
797 * fill the code into @otp->otp_code, keep other arguments unchanged, and retry
798 * this call to complete second phase of TOTP authentication;
799 * or other appropriate error. */
800 isds_error isds_login(struct isds_ctx *context, const char *url,
801 const char *username, const char *password,
802 const struct isds_pki_credentials *pki_credentials,
803 struct isds_otp *otp);
805 /* Log out from ISDS server and close connection. */
806 isds_error isds_logout(struct isds_ctx *context);
808 /* Verify connection to ISDS is alive and server is responding.
809 * Sent dummy request to ISDS and expect dummy response. */
810 isds_error isds_ping(struct isds_ctx *context);
812 /* Get data about logged in user and his box. */
813 isds_error isds_GetOwnerInfoFromLogin(struct isds_ctx *context,
814 struct isds_DbOwnerInfo **db_owner_info);
816 /* Get data about logged in user. */
817 isds_error isds_GetUserInfoFromLogin(struct isds_ctx *context,
818 struct isds_DbUserInfo **db_user_info);
820 /* Get expiration time of current password
821 * @context is session context
822 * @expiration is automatically reallocated time when password expires. If
823 * password expiration is disables, NULL will be returned. In case of error
824 * it will be nulled too. */
825 isds_error isds_get_password_expiration(struct isds_ctx *context,
826 struct timeval **expiration);
828 /* Change user password in ISDS.
829 * User must supply old password, new password will takes effect after some
830 * time, current session can continue. Password must fulfill some constraints.
831 * @context is session context
832 * @old_password is current password.
833 * @new_password is requested new password
834 * @otp auxiliary data required if one-time password authentication is in use,
835 * defines OTP code (if known) and returns fine grade resolution of OTP
836 * procedure. Pass NULL, if one-time password authentication is not needed.
837 * Please note the @otp argument must much OTP method used at log-in time. See
838 * isds_login() function for more details.
839 * @return IE_SUCCESS, if password has been changed. Or returns appropriate
840 * error code. It can return IE_PARTIAL_SUCCESS if OTP is in use and server is
841 * awaiting OTP code that has been delivered by side channel to the user. */
842 isds_error isds_change_password(struct isds_ctx *context,
843 const char *old_password, const char *new_password,
844 struct isds_otp *otp);
846 /* Create new box.
847 * @context is session context
848 * @box is box description to create including single primary user (in case of
849 * FO box type). It outputs box ID assigned by ISDS in dbID element.
850 * @users is list of struct isds_DbUserInfo (primary users in case of non-FO
851 * box, or contact address of PFO box owner)
852 * @former_names is optional former name of box owner. Pass NULL if you don't care.
853 * @upper_box_id is optional ID of supper box if currently created box is
854 * subordinated.
855 * @ceo_label is optional title of OVM box owner (e.g. mayor)
856 * @credentials_delivery is NULL if new password should be delivered off-line
857 * to box owner. It is valid pointer if owner should obtain new password on-line
858 * on dedicated web server. Then input @credentials_delivery.email value is
859 * his e-mail address he must provide to dedicated web server together
860 * with output reallocated @credentials_delivery.token member. Output
861 * member @credentials_delivery.new_user_name is unused up on this call.
862 * @approval is optional external approval of box manipulation
863 * @refnumber is reallocated serial number of request assigned by ISDS. Use
864 * NULL, if you don't care.*/
865 isds_error isds_add_box(struct isds_ctx *context,
866 struct isds_DbOwnerInfo *box, const struct isds_list *users,
867 const char *former_names, const char *upper_box_id,
868 const char *ceo_label,
869 struct isds_credentials_delivery *credentials_delivery,
870 const struct isds_approval *approval, char **refnumber);
872 /* Notify ISDS about new PFO entity.
873 * This function has no real effect.
874 * @context is session context
875 * @box is PFO description including single primary user.
876 * @users is list of struct isds_DbUserInfo (contact address of PFO box owner)
877 * @former_names is optional undocumented string. Pass NULL if you don't care.
878 * @upper_box_id is optional ID of supper box if currently created box is
879 * subordinated.
880 * @ceo_label is optional title of OVM box owner (e.g. mayor)
881 * @approval is optional external approval of box manipulation
882 * @refnumber is reallocated serial number of request assigned by ISDS. Use
883 * NULL, if you don't care.*/
884 isds_error isds_add_pfoinfo(struct isds_ctx *context,
885 const struct isds_DbOwnerInfo *box, const struct isds_list *users,
886 const char *former_names, const char *upper_box_id,
887 const char *ceo_label, const struct isds_approval *approval,
888 char **refnumber);
890 /* Remove given box permanently.
891 * @context is session context
892 * @box is box description to delete
893 * @since is date of box owner cancellation. Only tm_year, tm_mon and tm_mday
894 * carry sane value.
895 * @approval is optional external approval of box manipulation
896 * @refnumber is reallocated serial number of request assigned by ISDS. Use
897 * NULL, if you don't care.*/
898 isds_error isds_delete_box(struct isds_ctx *context,
899 const struct isds_DbOwnerInfo *box, const struct tm *since,
900 const struct isds_approval *approval, char **refnumber);
902 /* Undocumented function.
903 * @context is session context
904 * @box is box description to delete
905 * @approval is optional external approval of box manipulation
906 * @refnumber is reallocated serial number of request assigned by ISDS. Use
907 * NULL, if you don't care.*/
908 isds_error isds_delete_box_promptly(struct isds_ctx *context,
909 const struct isds_DbOwnerInfo *box,
910 const struct isds_approval *approval, char **refnumber);
912 /* Update data about given box.
913 * @context is session context
914 * @old_box current box description
915 * @new_box are updated data about @old_box
916 * @approval is optional external approval of box manipulation
917 * @refnumber is reallocated serial number of request assigned by ISDS. Use
918 * NULL, if you don't care.*/
919 isds_error isds_UpdateDataBoxDescr(struct isds_ctx *context,
920 const struct isds_DbOwnerInfo *old_box,
921 const struct isds_DbOwnerInfo *new_box,
922 const struct isds_approval *approval, char **refnumber);
924 /* Get data about all users assigned to given box.
925 * @context is session context
926 * @box_id is box ID
927 * @users is automatically reallocated list of struct isds_DbUserInfo */
928 isds_error isds_GetDataBoxUsers(struct isds_ctx *context, const char *box_id,
929 struct isds_list **users);
931 /* Update data about user assigned to given box.
932 * @context is session context
933 * @box is box identification
934 * @old_user identifies user to update
935 * @new_user are updated data about @old_user
936 * @refnumber is reallocated serial number of request assigned by ISDS. Use
937 * NULL, if you don't care.*/
938 isds_error isds_UpdateDataBoxUser(struct isds_ctx *context,
939 const struct isds_DbOwnerInfo *box,
940 const struct isds_DbUserInfo *old_user,
941 const struct isds_DbUserInfo *new_user,
942 char **refnumber);
944 /* Undocumented function.
945 * @context is session context
946 * @box_id is UTF-8 encoded box identifier
947 * @token is UTF-8 encoded temporary password
948 * @user_id outputs UTF-8 encoded reallocated user identifier
949 * @password outpus UTF-8 encoded reallocated user password
950 * Output arguments will be nulled in case of error */
951 isds_error isds_activate(struct isds_ctx *context,
952 const char *box_id, const char *token,
953 char **user_id, char **password);
955 /* Reset credentials of user assigned to given box.
956 * @context is session context
957 * @box is box identification
958 * @user identifies user to reset password
959 * @fee_paid is true if fee has been paid, false otherwise
960 * @approval is optional external approval of box manipulation
961 * @credentials_delivery is NULL if new password should be delivered off-line
962 * to the user. It is valid pointer if user should obtain new password on-line
963 * on dedicated web server. Then input @credentials_delivery.email value is
964 * user's e-mail address user must provide to dedicated web server together
965 * with @credentials_delivery.token. The output reallocated token user needs
966 * to use to authorize on the web server to view his new password. Output
967 * reallocated @credentials_delivery.new_user_name is user's log-in name that
968 * ISDS changed up on this call. (No reason why server could change the name
969 * is known now.)
970 * @refnumber is reallocated serial number of request assigned by ISDS. Use
971 * NULL, if you don't care.*/
972 isds_error isds_reset_password(struct isds_ctx *context,
973 const struct isds_DbOwnerInfo *box,
974 const struct isds_DbUserInfo *user,
975 const _Bool fee_paid, const struct isds_approval *approval,
976 struct isds_credentials_delivery *credentials_delivery,
977 char **refnumber);
979 /* Assign new user to given box.
980 * @context is session context
981 * @box is box identification
982 * @user defines new user to add
983 * @credentials_delivery is NULL if new user's password should be delivered
984 * off-line to the user. It is valid pointer if user should obtain new
985 * password on-line on dedicated web server. Then input
986 * @credentials_delivery.email value is user's e-mail address user must
987 * provide to dedicated web server together with @credentials_delivery.token.
988 * The output reallocated token user needs to use to authorize on the web
989 * server to view his new password. Output reallocated
990 * @credentials_delivery.new_user_name is user's log-in name that ISDS
991 * assingned up on this call.
992 * @approval is optional external approval of box manipulation
993 * @refnumber is reallocated serial number of request assigned by ISDS. Use
994 * NULL, if you don't care.*/
995 isds_error isds_add_user(struct isds_ctx *context,
996 const struct isds_DbOwnerInfo *box, const struct isds_DbUserInfo *user,
997 struct isds_credentials_delivery *credentials_delivery,
998 const struct isds_approval *approval, char **refnumber);
1000 /* Remove user assigned to given box.
1001 * @context is session context
1002 * @box is box identification
1003 * @user identifies user to remove
1004 * @approval is optional external approval of box manipulation
1005 * @refnumber is reallocated serial number of request assigned by ISDS. Use
1006 * NULL, if you don't care.*/
1007 isds_error isds_delete_user(struct isds_ctx *context,
1008 const struct isds_DbOwnerInfo *box, const struct isds_DbUserInfo *user,
1009 const struct isds_approval *approval, char **refnumber);
1011 /* Get list of boxes in ZIP archive.
1012 * @context is session context
1013 * @list_identifier is UTF-8 encoded string identifying boxes of interrest.
1014 * System recognizes following values currently: ALL (all boxes), UPG
1015 * (effectively OVM boxes), OVM (OVM gross type boxes), OPN (boxes allowing
1016 * receiving commercial messages). This argument is a string because
1017 * specification states new values can appear in the future. Not all list
1018 * types are available to all users.
1019 * @buffer is automatically reallocated memory to store the list of boxes. The
1020 * list is zipped CSV file.
1021 * @buffer_length is size of @buffer data in bytes.
1022 * In case of error @buffer will be freed and @buffer_length will be
1023 * undefined.*/
1024 isds_error isds_get_box_list_archive(struct isds_ctx *context,
1025 const char *list_identifier, void **buffer, size_t *buffer_length);
1027 /* Find boxes suiting given criteria.
1028 * @context is ISDS session context.
1029 * @criteria is filter. You should fill in at least some members.
1030 * @boxes is automatically reallocated list of isds_DbOwnerInfo structures,
1031 * possibly empty. Input NULL or valid old structure.
1032 * @return:
1033 * IE_SUCCESS if search succeeded, @boxes contains useful data
1034 * IE_NOEXIST if no such box exists, @boxes will be NULL
1035 * IE_2BIG if too much boxes exist and server truncated the results, @boxes
1036 * contains still valid data
1037 * other code if something bad happens. @boxes will be NULL. */
1038 isds_error isds_FindDataBox(struct isds_ctx *context,
1039 const struct isds_DbOwnerInfo *criteria,
1040 struct isds_list **boxes);
1042 /* Get status of a box.
1043 * @context is ISDS session context.
1044 * @box_id is UTF-8 encoded box identifier as zero terminated string
1045 * @box_status is return value of box status.
1046 * @return:
1047 * IE_SUCCESS if box has been found and its status retrieved
1048 * IE_NOEXIST if box is not known to ISDS server
1049 * or other appropriate error.
1050 * You can use isds_DbState to enumerate box status. However out of enum
1051 * range value can be returned too. This is feature because ISDS
1052 * specification leaves the set of values open.
1053 * Be ware that status DBSTATE_REMOVED is signaled as IE_SUCCESS. That means
1054 * the box has been deleted, but ISDS still lists its former existence. */
1055 isds_error isds_CheckDataBox(struct isds_ctx *context, const char *box_id,
1056 long int *box_status);
1058 /* Switch box into state where box can receive commercial messages (off by
1059 * default)
1060 * @context is ISDS session context.
1061 * @box_id is UTF-8 encoded box identifier as zero terminated string
1062 * @allow is true for enable, false for disable commercial messages income
1063 * @approval is optional external approval of box manipulation
1064 * @refnumber is reallocated serial number of request assigned by ISDS. Use
1065 * NULL, if you don't care. */
1066 isds_error isds_switch_commercial_receiving(struct isds_ctx *context,
1067 const char *box_id, const _Bool allow,
1068 const struct isds_approval *approval, char **refnumber);
1070 /* Switch box into / out of state where non-OVM box can act as OVM (e.g. force
1071 * message acceptance). This is just a box permission. Sender must apply
1072 * such role by sending each message.
1073 * @context is ISDS session context.
1074 * @box_id is UTF-8 encoded box identifier as zero terminated string
1075 * @allow is true for enable, false for disable OVM role permission
1076 * @approval is optional external approval of box manipulation
1077 * @refnumber is reallocated serial number of request assigned by ISDS. Use
1078 * NULL, if you don't care. */
1079 isds_error isds_switch_effective_ovm(struct isds_ctx *context,
1080 const char *box_id, const _Bool allow,
1081 const struct isds_approval *approval, char **refnumber);
1083 /* Switch box accessibility state on request of box owner.
1084 * Despite the name, owner must do the request off-line. This function is
1085 * designed for such off-line meeting points (e.g. Czech POINT).
1086 * @context is ISDS session context.
1087 * @box identifies box to switch accessibility state.
1088 * @allow is true for making accessible, false to disallow access.
1089 * @approval is optional external approval of box manipulation
1090 * @refnumber is reallocated serial number of request assigned by ISDS. Use
1091 * NULL, if you don't care. */
1092 isds_error isds_switch_box_accessibility_on_owner_request(
1093 struct isds_ctx *context, const struct isds_DbOwnerInfo *box,
1094 const _Bool allow, const struct isds_approval *approval,
1095 char **refnumber);
1097 /* Disable box accessibility on law enforcement (e.g. by prison) since exact
1098 * date.
1099 * @context is ISDS session context.
1100 * @box identifies box to switch accessibility state.
1101 * @since is date since accessibility has been denied. This can be past too.
1102 * Only tm_year, tm_mon and tm_mday carry sane value.
1103 * @approval is optional external approval of box manipulation
1104 * @refnumber is reallocated serial number of request assigned by ISDS. Use
1105 * NULL, if you don't care. */
1106 isds_error isds_disable_box_accessibility_externaly(
1107 struct isds_ctx *context, const struct isds_DbOwnerInfo *box,
1108 const struct tm *since, const struct isds_approval *approval,
1109 char **refnumber);
1111 /* Send a message via ISDS to a recipient
1112 * @context is session context
1113 * @outgoing_message is message to send; Some members are mandatory (like
1114 * dbIDRecipient), some are optional and some are irrelevant (especially data
1115 * about sender). Included pointer to isds_list documents must contain at
1116 * least one document of FILEMETATYPE_MAIN. This is read-write structure, some
1117 * members will be filled with valid data from ISDS. Exact list of write
1118 * members is subject to change. Currently dmID is changed.
1119 * @return ISDS_SUCCESS, or other error code if something goes wrong. */
1120 isds_error isds_send_message(struct isds_ctx *context,
1121 struct isds_message *outgoing_message);
1123 /* Send a message via ISDS to a multiple recipients
1124 * @context is session context
1125 * @outgoing_message is message to send; Some members are mandatory,
1126 * some are optional and some are irrelevant (especially data
1127 * about sender). Data about recipient will be substituted by ISDS from
1128 * @copies. Included pointer to isds_list documents must
1129 * contain at least one document of FILEMETATYPE_MAIN.
1130 * @copies is list of isds_message_copy structures addressing all desired
1131 * recipients. This is read-write structure, some members will be filled with
1132 * valid data from ISDS (message IDs, error codes, error descriptions).
1133 * @return
1134 * ISDS_SUCCESS if all messages have been sent
1135 * ISDS_PARTIAL_SUCCESS if sending of some messages has failed (failed and
1136 * succeeded messages can be identified by copies->data->error),
1137 * or other error code if something other goes wrong. */
1138 isds_error isds_send_message_to_multiple_recipients(struct isds_ctx *context,
1139 const struct isds_message *outgoing_message,
1140 struct isds_list *copies);
1142 /* Get list of outgoing (already sent) messages.
1143 * Any criterion argument can be NULL, if you don't care about it.
1144 * @context is session context. Must not be NULL.
1145 * @from_time is minimal time and date of message sending inclusive.
1146 * @to_time is maximal time and date of message sending inclusive
1147 * @dmSenderOrgUnitNum is the same as isds_envelope.dmSenderOrgUnitNum
1148 * @status_filter is bit field of isds_message_status values. Use special
1149 * value MESSAGESTATE_ANY to signal you don't care. (It's defined as union of
1150 * all values, you can use bit-wise arithmetic if you want.)
1151 * @offset is index of first message we are interested in. First message is 1.
1152 * Set to 0 (or 1) if you don't care.
1153 * @number is maximal length of list you want to get as input value, outputs
1154 * number of messages matching these criteria. Can be NULL if you don't care
1155 * (applies to output value either).
1156 * @messages is automatically reallocated list of isds_message's. Be ware that
1157 * it returns only brief overview (envelope and some other fields) about each
1158 * message, not the complete message. FIXME: Specify exact fields.
1159 * The list is sorted by delivery time in ascending order.
1160 * Use NULL if you don't care about the meta data (useful if you want to know
1161 * only the @number). If you provide &NULL, list will be allocated on heap,
1162 * if you provide pointer to non-NULL, list will be freed automatically at
1163 * first. Also in case of error the list will be NULLed.
1164 * @return IE_SUCCESS or appropriate error code. */
1165 isds_error isds_get_list_of_sent_messages(struct isds_ctx *context,
1166 const struct timeval *from_time, const struct timeval *to_time,
1167 const long int *dmSenderOrgUnitNum, const unsigned int status_filter,
1168 const unsigned long int offset, unsigned long int *number,
1169 struct isds_list **messages);
1171 /* Get list of incoming (addressed to you) messages.
1172 * Any criterion argument can be NULL, if you don't care about it.
1173 * @context is session context. Must not be NULL.
1174 * @from_time is minimal time and date of message sending inclusive.
1175 * @to_time is maximal time and date of message sending inclusive
1176 * @dmRecipientOrgUnitNum is the same as isds_envelope.dmRecipientOrgUnitNum
1177 * @status_filter is bit field of isds_message_status values. Use special
1178 * value MESSAGESTATE_ANY to signal you don't care. (It's defined as union of
1179 * all values, you can use bit-wise arithmetic if you want.)
1180 * @offset is index of first message we are interested in. First message is 1.
1181 * Set to 0 (or 1) if you don't care.
1182 * @number is maximal length of list you want to get as input value, outputs
1183 * number of messages matching these criteria. Can be NULL if you don't care
1184 * (applies to output value either).
1185 * @messages is automatically reallocated list of isds_message's. Be ware that
1186 * it returns only brief overview (envelope and some other fields) about each
1187 * message, not the complete message. FIXME: Specify exact fields.
1188 * Use NULL if you don't care about the meta data (useful if you want to know
1189 * only the @number). If you provide &NULL, list will be allocated on heap,
1190 * if you provide pointer to non-NULL, list will be freed automatically at
1191 * first. Also in case of error the list will be NULLed.
1192 * @return IE_SUCCESS or appropriate error code. */
1193 isds_error isds_get_list_of_received_messages(struct isds_ctx *context,
1194 const struct timeval *from_time, const struct timeval *to_time,
1195 const long int *dmRecipientOrgUnitNum,
1196 const unsigned int status_filter,
1197 const unsigned long int offset, unsigned long int *number,
1198 struct isds_list **messages);
1200 /* Get list of sent message state changes.
1201 * Any criterion argument can be NULL, if you don't care about it.
1202 * @context is session context. Must not be NULL.
1203 * @from_time is minimal time and date of status changes inclusive
1204 * @to_time is maximal time and date of status changes inclusive
1205 * @changed_states is automatically reallocated list of
1206 * isds_message_status_change's. If you provide &NULL, list will be allocated
1207 * on heap, if you provide pointer to non-NULL, list will be freed
1208 * automatically at first. Also in case of error the list will be NULLed.
1209 * XXX: The list item ordering is not specified.
1210 * XXX: Server provides only `recent' changes.
1211 * @return IE_SUCCESS or appropriate error code. */
1212 isds_error isds_get_list_of_sent_message_state_changes(
1213 struct isds_ctx *context,
1214 const struct timeval *from_time, const struct timeval *to_time,
1215 struct isds_list **changed_states);
1217 /* Download incoming message envelope identified by ID.
1218 * @context is session context
1219 * @message_id is message identifier (you can get them from
1220 * isds_get_list_of_received_messages())
1221 * @message is automatically reallocated message retrieved from ISDS.
1222 * It will miss documents per se. Use isds_get_received_message(), if you are
1223 * interested in documents (content) too.
1224 * Returned hash and timestamp require documents to be verifiable. */
1225 isds_error isds_get_received_envelope(struct isds_ctx *context,
1226 const char *message_id, struct isds_message **message);
1228 /* Download signed delivery info-sheet of given message identified by ID.
1229 * @context is session context
1230 * @message_id is message identifier (you can get them from
1231 * isds_get_list_of_{sent,received}_messages())
1232 * @message is automatically reallocated message retrieved from ISDS.
1233 * It will miss documents per se. Use isds_get_signed_received_message(),
1234 * if you are interested in documents (content). OTOH, only this function
1235 * can get list events message has gone through. */
1236 isds_error isds_get_signed_delivery_info(struct isds_ctx *context,
1237 const char *message_id, struct isds_message **message);
1239 /* Load delivery info of any format from buffer.
1240 * @context is session context
1241 * @raw_type advertises format of @buffer content. Only delivery info types
1242 * are accepted.
1243 * @buffer is DER encoded PKCS#7 structure with signed delivery info. You can
1244 * retrieve such data from message->raw after calling
1245 * isds_get_signed_delivery_info().
1246 * @length is length of buffer in bytes.
1247 * @message is automatically reallocated message parsed from @buffer.
1248 * @strategy selects how buffer will be attached into raw isds_message member.
1249 * */
1250 isds_error isds_load_delivery_info(struct isds_ctx *context,
1251 const isds_raw_type raw_type,
1252 const void *buffer, const size_t length,
1253 struct isds_message **message, const isds_buffer_strategy strategy);
1255 /* Download delivery info-sheet of given message identified by ID.
1256 * @context is session context
1257 * @message_id is message identifier (you can get them from
1258 * isds_get_list_of_{sent,received}_messages())
1259 * @message is automatically reallocated message retrieved from ISDS.
1260 * It will miss documents per se. Use isds_get_received_message(), if you are
1261 * interested in documents (content). OTOH, only this function can get list
1262 * of events message has gone through. */
1263 isds_error isds_get_delivery_info(struct isds_ctx *context,
1264 const char *message_id, struct isds_message **message);
1266 /* Download incoming message identified by ID.
1267 * @context is session context
1268 * @message_id is message identifier (you can get them from
1269 * isds_get_list_of_received_messages())
1270 * @message is automatically reallocated message retrieved from ISDS */
1271 isds_error isds_get_received_message(struct isds_ctx *context,
1272 const char *message_id, struct isds_message **message);
1274 /* Load message of any type from buffer.
1275 * @context is session context
1276 * @raw_type defines content type of @buffer. Only message types are allowed.
1277 * @buffer is message raw representation. Format (CMS, plain signed,
1278 * message direction) is defined in @raw_type. You can retrieve such data
1279 * from message->raw after calling isds_get_[signed]{received,sent}_message().
1280 * @length is length of buffer in bytes.
1281 * @message is automatically reallocated message parsed from @buffer.
1282 * @strategy selects how buffer will be attached into raw isds_message member.
1283 * */
1284 isds_error isds_load_message(struct isds_ctx *context,
1285 const isds_raw_type raw_type, const void *buffer, const size_t length,
1286 struct isds_message **message, const isds_buffer_strategy strategy);
1288 /* Determine type of raw message or delivery info according some heuristics.
1289 * It does not validate the raw blob.
1290 * @context is session context
1291 * @raw_type returns content type of @buffer. Valid only if exit code of this
1292 * function is IE_SUCCESS. The pointer must be valid. This is no automatically
1293 * reallocated memory.
1294 * @buffer is message raw representation.
1295 * @length is length of buffer in bytes. */
1296 isds_error isds_guess_raw_type(struct isds_ctx *context,
1297 isds_raw_type *raw_type, const void *buffer, const size_t length);
1299 /* Download signed incoming message identified by ID.
1300 * @context is session context
1301 * @message_id is message identifier (you can get them from
1302 * isds_get_list_of_received_messages())
1303 * @message is automatically reallocated message retrieved from ISDS. The raw
1304 * member will be filled with PKCS#7 structure in DER format. */
1305 isds_error isds_get_signed_received_message(struct isds_ctx *context,
1306 const char *message_id, struct isds_message **message);
1308 /* Download signed outgoing message identified by ID.
1309 * @context is session context
1310 * @message_id is message identifier (you can get them from
1311 * isds_get_list_of_sent_messages())
1312 * @message is automatically reallocated message retrieved from ISDS. The raw
1313 * member will be filled with PKCS#7 structure in DER format. */
1314 isds_error isds_get_signed_sent_message(struct isds_ctx *context,
1315 const char *message_id, struct isds_message **message);
1317 /* Get type and name of user who sent a message identified by ID.
1318 * @context is session context
1319 * @message_id is message identifier
1320 * @sender_type is pointer to automatically allocated type of sender detected
1321 * from @raw_sender_type string. If @raw_sender_type is unknown to this
1322 * library or to the server, NULL will be returned. Pass NULL if you don't
1323 * care about it.
1324 * @raw_sender_type is automatically reallocated UTF-8 string describing
1325 * sender type or NULL if not known to server. Pass NULL if you don't care.
1326 * @sender_name is automatically reallocated UTF-8 name of user who sent the
1327 * message, or NULL if not known to ISDS. Pass NULL if you don't care. */
1328 isds_error isds_get_message_sender(struct isds_ctx *context,
1329 const char *message_id, isds_sender_type **sender_type,
1330 char **raw_sender_type, char **sender_name);
1332 /* Retrieve hash of message identified by ID stored in ISDS.
1333 * @context is session context
1334 * @message_id is message identifier
1335 * @hash is automatically reallocated message hash downloaded from ISDS.
1336 * Message must exist in system and must not be deleted. */
1337 isds_error isds_download_message_hash(struct isds_ctx *context,
1338 const char *message_id, struct isds_hash **hash);
1340 /* Compute hash of message from raw representation and store it into envelope.
1341 * Original hash structure will be destroyed in envelope.
1342 * @context is session context
1343 * @message is message carrying raw XML message blob
1344 * @algorithm is desired hash algorithm to use */
1345 isds_error isds_compute_message_hash(struct isds_ctx *context,
1346 struct isds_message *message, const isds_hash_algorithm algorithm);
1348 /* Compare two hashes.
1349 * @h1 is first hash
1350 * @h2 is another hash
1351 * @return
1352 * IE_SUCCESS if hashes equal
1353 * IE_NOTUNIQ if hashes are comparable, but they don't equal
1354 * IE_ENUM if not comparable, but both structures defined
1355 * IE_INVAL if some of the structures are undefined (NULL)
1356 * IE_ERROR if internal error occurs */
1357 isds_error isds_hash_cmp(const struct isds_hash *h1,
1358 const struct isds_hash *h2);
1360 /* Check message has gone through ISDS by comparing message hash stored in
1361 * ISDS and locally computed hash. You must provide message with valid raw
1362 * member (do not use isds_load_message(..., BUFFER_DONT_STORE)).
1363 * This is convenient wrapper for isds_download_message_hash(),
1364 * isds_compute_message_hash(), and isds_hash_cmp() sequence.
1365 * @context is session context
1366 * @message is message with valid raw and envelope member; envelope->hash
1367 * member will be changed during function run. Use envelope on heap only.
1368 * @return
1369 * IE_SUCCESS if message originates in ISDS
1370 * IE_NOTEQUAL if message is unknown to ISDS
1371 * other code for other errors */
1372 isds_error isds_verify_message_hash(struct isds_ctx *context,
1373 struct isds_message *message);
1375 /* Submit CMS signed message to ISDS to verify its originality. This is
1376 * stronger form of isds_verify_message_hash() because ISDS does more checks
1377 * than simple one (potentialy old weak) hash comparison.
1378 * @context is session context
1379 * @message is memory with raw CMS signed message bit stream
1380 * @length is @message size in bytes
1381 * @return
1382 * IE_SUCCESS if message originates in ISDS
1383 * IE_NOTEQUAL if message is unknown to ISDS
1384 * other code for other errors */
1385 isds_error isds_authenticate_message(struct isds_ctx *context,
1386 const void *message, size_t length);
1388 /* Mark message as read. This is a transactional commit function to acknowledge
1389 * to ISDS the message has been downloaded and processed by client properly.
1390 * @context is session context
1391 * @message_id is message identifier. */
1392 isds_error isds_mark_message_read(struct isds_ctx *context,
1393 const char *message_id);
1395 /* Mark message as received by recipient. This is applicable only to
1396 * commercial message. Use envelope->dmType message member to distinguish
1397 * commercial message from government message. Government message is
1398 * received automatically (by law), commercial message on recipient request.
1399 * @context is session context
1400 * @message_id is message identifier. */
1401 isds_error isds_mark_message_received(struct isds_ctx *context,
1402 const char *message_id);
1404 /* Send bogus request to ISDS.
1405 * Just for test purposes */
1406 isds_error isds_bogus_request(struct isds_ctx *context);
1408 /* Send document for authorized conversion into Czech POINT system.
1409 * This is public anonymous service, no log-in necessary. Special context is
1410 * used to reuse keep-a-live HTTPS connection.
1411 * @context is Czech POINT session context. DO NOT use context connected to
1412 * ISDS server. Use new context or context used by this function previously.
1413 * @document is document to convert. Only data, data_length, dmFileDescr and
1414 * is_xml members are significant. Be ware that not all document formats can be
1415 * converted (signed PDF 1.3 and higher only (2010-02 state)).
1416 * @id is reallocated identifier assigned by Czech POINT system to
1417 * your document on submit. Use is to tell it to Czech POINT officer.
1418 * @date is reallocated document submit date (submitted documents
1419 * expires after some period). Only tm_year, tm_mon and tm_mday carry sane
1420 * value. */
1421 isds_error czp_convert_document(struct isds_ctx *context,
1422 const struct isds_document *document,
1423 char **id, struct tm **date);
1425 /* Close possibly opened connection to Czech POINT document deposit.
1426 * @context is Czech POINT session context. */
1427 isds_error czp_close_connection(struct isds_ctx *context);
1429 /* Send request for new box creation in testing ISDS instance.
1430 * It's not possible to request for a production box currently, as it
1431 * communicates via e-mail.
1432 * XXX: This function does not work either. Server complains about invalid
1433 * e-mail address.
1434 * XXX: Remove context->type hacks in isds.c and validator.c when removing
1435 * this function
1436 * @context is special session context for box creation request. DO NOT use
1437 * standard context as it could reveal your password. Use fresh new context or
1438 * context previously used by this function.
1439 * @box is box description to create including single primary user (in case of
1440 * FO box type). It outputs box ID assigned by ISDS in dbID element.
1441 * @users is list of struct isds_DbUserInfo (primary users in case of non-FO
1442 * box, or contact address of PFO box owner). The email member is mandatory as
1443 * it will be used to deliver credentials.
1444 * @former_names is optional undocumented string. Pass NULL if you don't care.
1445 * @approval is optional external approval of box manipulation
1446 * @refnumber is reallocated serial number of request assigned by ISDS. Use
1447 * NULL, if you don't care.*/
1448 isds_error isds_request_new_testing_box(struct isds_ctx *context,
1449 struct isds_DbOwnerInfo *box, const struct isds_list *users,
1450 const char *former_names, const struct isds_approval *approval,
1451 char **refnumber);
1453 /* Search for document by document ID in list of documents. IDs are compared
1454 * as UTF-8 string.
1455 * @documents is list of isds_documents
1456 * @id is document identifier
1457 * @return first matching document or NULL. */
1458 const struct isds_document *isds_find_document_by_id(
1459 const struct isds_list *documents, const char *id);
1461 /* Normalize @mime_type to be proper MIME type.
1462 * ISDS servers pass invalid MIME types (e.g. "pdf"). This function tries to
1463 * guess regular MIME type (e.g. "application/pdf").
1464 * @mime_type is UTF-8 encoded MIME type to fix
1465 * @return original @mime_type if no better interpretation exists, or array to
1466 * constant static UTF-8 encoded string with proper MIME type. */
1467 char *isds_normalize_mime_type(const char* mime_type);
1469 /* Deallocate structure isds_pki_credentials and NULL it.
1470 * Pass-phrase is discarded.
1471 * @pki credentials to to free */
1472 void isds_pki_credentials_free(struct isds_pki_credentials **pki);
1474 /* Free isds_list with all member data.
1475 * @list list to free, on return will be NULL */
1476 void isds_list_free(struct isds_list **list);
1478 /* Deallocate structure isds_hash and NULL it.
1479 * @hash hash to to free */
1480 void isds_hash_free(struct isds_hash **hash);
1482 /* Deallocate structure isds_DbOwnerInfo recursively and NULL it */
1483 void isds_DbOwnerInfo_free(struct isds_DbOwnerInfo **db_owner_info);
1485 /* Deallocate structure isds_DbUserInfo recursively and NULL it */
1486 void isds_DbUserInfo_free(struct isds_DbUserInfo **db_user_info);
1488 /* Deallocate struct isds_event recursively and NULL it */
1489 void isds_event_free(struct isds_event **event);
1491 /* Deallocate struct isds_envelope recursively and NULL it */
1492 void isds_envelope_free(struct isds_envelope **envelope);
1494 /* Deallocate struct isds_document recursively and NULL it */
1495 void isds_document_free(struct isds_document **document);
1497 /* Deallocate struct isds_message recursively and NULL it */
1498 void isds_message_free(struct isds_message **message);
1500 /* Deallocate struct isds_message_copy recursively and NULL it */
1501 void isds_message_copy_free(struct isds_message_copy **copy);
1503 /* Deallocate struct isds_message_status_change recursively and NULL it */
1504 void isds_message_status_change_free(
1505 struct isds_message_status_change **message_status_change);
1507 /* Deallocate struct isds_approval recursively and NULL it */
1508 void isds_approval_free(struct isds_approval **approval);
1510 /* Deallocate struct isds_credentials_delivery recursively and NULL it.
1511 * The email string is deallocated too. */
1512 void isds_credentials_delivery_free(
1513 struct isds_credentials_delivery **credentials_delivery);
1515 /* Copy structure isds_PersonName recursively */
1516 struct isds_PersonName *isds_PersonName_duplicate(
1517 const struct isds_PersonName *template);
1519 /* Copy structure isds_Address recursively */
1520 struct isds_Address *isds_Address_duplicate(
1521 const struct isds_Address *template);
1523 /* Copy structure isds_DbOwnerInfo recursively */
1524 struct isds_DbOwnerInfo *isds_DbOwnerInfo_duplicate(
1525 const struct isds_DbOwnerInfo *template);
1527 /* Copy structure isds_DbUserInfo recursively */
1528 struct isds_DbUserInfo *isds_DbUserInfo_duplicate(
1529 const struct isds_DbUserInfo *template);
1531 #ifdef __cplusplus /* For C++ linker sake */
1533 #endif
1535 #endif