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