libdigidocpp
ADoc.cpp
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 #include "ADoc.h"
21 
22 #include "log.h"
23 #include "Signature.h"
24 #include "XmlConf.h"
26 #include "util/File.h"
27 
28 #include <xsec/utils/XSECPlatformUtils.hpp>
29 
30 #include <openssl/conf.h>
31 #include <openssl/ssl.h>
32 
33 #include <sstream>
34 
35 namespace digidoc
36 {
37 static std::string m_appInfo = "";
38 }
39 
40 using namespace digidoc;
41 
45 std::string digidoc::appInfo() { return m_appInfo; }
46 
50 std::string digidoc::version() { return VER_STR(MAJOR_VER.MINOR_VER.RELEASE_VER.BUILD_VER); }
51 
55 void digidoc::initialize(const std::string &appInfo)
56 {
58 
59  // Initialize OpenSSL library.
60  SSL_load_error_strings();
61  SSL_library_init();
62  OPENSSL_config(0);
63 
64  // Initialize Apache Xerces library.
65  xercesc::XMLPlatformUtils::Initialize();
66 
67  // Initialize Apache XML Security library.
68  XSECPlatformUtils::Initialise();
69 
70  // Use Xml based configuration
72 
73  // Init default cert store
75 }
76 
81 {
83 
85 
86  // Terminate Apache XML Security library.
87  XSECPlatformUtils::Terminate();
88 
89  // Terminate Apache Xerces library.
90  xercesc::XMLPlatformUtils::Terminate();
91 
92  // Try to delete temporary files created with the util::File::tempFileName, tempDirectory and createTempDirectory functions.
94 
95  m_appInfo.clear();
96 }
97 
102 {
103  return ADoc::UnknownType;
104 }
105 
111 unsigned int digidoc::ADoc::newSignatureId() const
112 {
113  unsigned int id = 0;
114  while(true)
115  {
116  std::ostringstream sid;
117  sid << "S" << id;
118  bool found = false;
119  for(unsigned int i = 0; i < signatureCount(); ++i)
120  {
121  if(getSignature(i)->getId() == sid.str())
122  {
123  found = true;
124  break;
125  }
126  }
127  if(!found)
128  return id;
129  ++id;
130  }
131  return id;
132 }