libdigidocpp
DDoc_p.h
Go to the documentation of this file.
1 /*
2  * libdigidocpp
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  */
19 
20 #pragma once
21 
22 #include <libdigidoc/DigiDocConfig.h>
23 #include <libdigidoc/DigiDocGen.h>
24 #include <libdigidoc/DigiDocSAXParser.h>
25 
26 #include "Document.h"
27 #include "Signature.h"
28 
29 #ifdef _WIN32
30 #include <Windows.h>
31 #else
32 #include <dlfcn.h>
33 #endif
34 
35 typedef int (*sym_calculateDataFileSizeAndDigest)( SignedDoc*, const char*, const char*, int );
36 typedef void (*sym_cleanupConfigStore)( ConfigurationStore* );
37 typedef int (*sym_convertStringToTimestamp)( const SignedDoc*, const char*, Timestamp* );
38 typedef int (*sym_createOrReplacePrivateConfigItem)(ConfigurationStore*, const char*, const char* );
39 typedef int (*sym_createSignedDoc)( SignedDoc*, const char*, const char* );
40 typedef int (*sym_DataFile_delete)( SignedDoc*, const char* );
41 typedef int (*sym_DataFile_new)( DataFile**, SignedDoc*, const char*, const char*,
42  const char*, const char*, long, const byte*, int, const char*, const char* );
43 typedef int (*sym_ddocPrepareSignature)( SignedDoc*, SignatureInfo**, const char*, const char*,
44  const char*, const char*, const char*, X509*, const char* );
45 typedef int (*sym_ddocSaxReadSignedDocFromFile)( SignedDoc**, const char*, int, long );
46 typedef X509* (*sym_ddocSigInfo_GetOCSPRespondersCert)( const SignatureInfo * );
47 typedef DigiDocMemBuf* (*sym_ddocSigInfo_GetSignatureValue_Value)( SignatureInfo* );
48 typedef X509* (*sym_ddocSigInfo_GetSignersCert)( const SignatureInfo* );
49 typedef int (*sym_ddocSigInfo_SetSignatureValue)( SignatureInfo*, const char*, long );
50 typedef int (*sym_getCountOfDataFiles)( const SignedDoc* );
51 typedef int (*sym_getCountOfSignatures)( const SignedDoc* );
52 typedef DataFile* (*sym_getDataFile)( const SignedDoc*, int );
53 typedef ErrorClass (*sym_getErrorClass)( int );
54 typedef ErrorInfo* (*sym_getErrorInfo)();
55 typedef char* (*sym_getErrorString)( int );
56 typedef SignatureInfo* (*sym_getSignature)( const SignedDoc*, int );
57 typedef void (*sym_finalizeDigiDocLib)();
58 typedef int (*sym_hasUnreadErrors)();
59 typedef void (*sym_initDigiDocLib)();
60 typedef int (*sym_initConfigStore)( const char* );
61 typedef int (*sym_notarizeSignature)( SignedDoc*, SignatureInfo* );
62 typedef int (*sym_ddocSaxExtractDataFile)( SignedDoc*, const char*,
63  const char*, const char*, const char* );
64 typedef void (*sym_setGUIVersion)( const char* );
65 typedef int (*sym_SignatureInfo_delete)( SignedDoc*, const char* );
66 typedef void (*sym_SignedDoc_free)( SignedDoc* );
67 typedef int (*sym_SignedDoc_new)( SignedDoc**, const char*, const char* );
68 typedef int (*sym_verifySignatureAndNotary)( SignedDoc*, SignatureInfo*, const char* );
69 
70 namespace digidoc
71 {
72 
74 {
75 public:
76  static void destroy();
77  static DDocLibrary *instance();
78 
79  bool ready;
80 
112 
113 private:
114  DDocLibrary();
115  ~DDocLibrary();
116 
117  bool loadSymbols();
118 
119 #ifndef LINKED_LIBDIGIDOC
120  bool load();
121  void *resolve( const char *symbol );
122  void unload();
123 #ifdef _WIN32
124  HINSTANCE h;
125 #else
126  void *h;
127 #endif
128 #endif
129 
130  unsigned int ref;
132 };
133 
134 class SignatureDDOC;
135 
137 {
138 public:
139  DDocPrivate();
140  ~DDocPrivate();
141 
143  SignedDoc *doc;
144  std::string filename;
145 
146  void loadSignatures();
147  std::vector<SignatureDDOC*> signatures;
148  std::vector<Document> documents;
149 
150  template<typename T>
151  void throwCodeError( int err, const std::string &msg, int line ) const;
152  void throwDocOpenError( int line ) const throw(BDocException);
153  template<typename T>
154  void throwError( const std::string &msg, int line, int err = -1,
156  void throwSignError( SignatureInfo *sig, int err, const std::string &msg, int line ) const throw(BDocException);
157 };
158 
160 {
161 public:
163  SignatureInfo *sig;
165 };
166 
167 }