@@ -140,7 +140,7 @@ void SignatureSiVa::validate(const string &policy) const
140
140
}
141
141
142
142
143
- SiVaContainer::SiVaContainer (const string &path, const string &ext, bool useHashCode)
143
+ SiVaContainer::SiVaContainer (const string &path, const string &ext, bool useHashCode, bool offline )
144
144
: d(new Private)
145
145
{
146
146
DEBUG (" SiVaContainer::SiVaContainer(%s, %s, %d)" , path.c_str (), ext.c_str (), useHashCode);
@@ -159,6 +159,10 @@ SiVaContainer::SiVaContainer(const string &path, const string &ext, bool useHash
159
159
d->dataFiles .push_back (new DataFilePrivate (move (ifs), File::fileName (path), " application/pdf" , File::fileName (path)));
160
160
}
161
161
162
+ if (offline) {
163
+ return ;
164
+ }
165
+
162
166
XMLByte buf[48 *100 ];
163
167
string b64;
164
168
is->clear ();
@@ -185,6 +189,7 @@ SiVaContainer::SiVaContainer(const string &path, const string &ext, bool useHash
185
189
Connect::Result r = Connect (url, " POST" , 0 , {}, CONF (verifyServiceCerts)).exec ({
186
190
{" Content-Type" , " application/json;charset=UTF-8" }
187
191
}, (const unsigned char *)req.c_str (), req.size ());
192
+ req.clear ();
188
193
189
194
if (!r.isOK () && !r.isStatusCode (" 400" ))
190
195
THROW (" Failed to send request to SiVa" );
@@ -254,7 +259,7 @@ SiVaContainer::SiVaContainer(const string &path, const string &ext, bool useHash
254
259
for (const json &error: signature.value <json>(" errors" , {}))
255
260
{
256
261
string message = error[" content" ];
257
- if (message.find (" Bad digest for DataFile" ) == 0 && useHashCode)
262
+ if (message.find (" Bad digest for DataFile" ) != string::npos && useHashCode)
258
263
THROW (message.c_str ());
259
264
s->_exceptions .emplace_back (EXCEPTION_PARAMS (message.c_str ()));
260
265
}
@@ -265,7 +270,7 @@ SiVaContainer::SiVaContainer(const string &path, const string &ext, bool useHash
265
270
if (message == " X509IssuerName has none or invalid namespace: null" ||
266
271
message == " X509SerialNumber has none or invalid namespace: null" )
267
272
ex.setCode (Exception::IssuerNameSpaceWarning);
268
- else if (message.find (" Bad digest for DataFile" ) == 0 )
273
+ else if (message.find (" Bad digest for DataFile" ) != string::npos )
269
274
ex.setCode (Exception::DataFileNameSpaceWarning);
270
275
else if (message == " Old and unsupported format: SK-XML version: 1.0" )
271
276
continue ;
@@ -277,10 +282,8 @@ SiVaContainer::SiVaContainer(const string &path, const string &ext, bool useHash
277
282
278
283
SiVaContainer::~SiVaContainer ()
279
284
{
280
- for (const Signature *s: d->signatures )
281
- delete s;
282
- for (const DataFile *f: d->dataFiles )
283
- delete f;
285
+ for_each (d->signatures .cbegin (), d->signatures .cend (), default_delete<Signature>());
286
+ for_each (d->dataFiles .cbegin (), d->dataFiles .cend (), default_delete<DataFile>());
284
287
delete d;
285
288
}
286
289
@@ -314,30 +317,28 @@ vector<DataFile *> SiVaContainer::dataFiles() const
314
317
return d->dataFiles ;
315
318
}
316
319
317
- unique_ptr<Container> SiVaContainer::openInternal (const string &path)
320
+ unique_ptr<Container> SiVaContainer::openInternal (const string &path, OpenFlags flags )
318
321
{
319
322
static const set<string> supported = {" PDF" , " DDOC" };
320
323
string ext = File::fileExtension (path);
321
324
transform (ext.begin (), ext.end (), ext.begin (), ::toupper);
322
325
if (!supported.count (ext))
323
326
return {};
324
327
try {
325
- return unique_ptr<Container>(new SiVaContainer (path, ext, true ));
328
+ return unique_ptr<Container>(new SiVaContainer (path, ext, true , flags & OpenOffline ));
326
329
} catch (const Exception &e) {
327
- if (e.msg ().find (" Bad digest for DataFile" ) == 0 )
328
- return unique_ptr<Container>(new SiVaContainer (path, ext, false ));
330
+ if (e.msg ().find (" Bad digest for DataFile" ) != string::npos )
331
+ return unique_ptr<Container>(new SiVaContainer (path, ext, false , flags & OpenOffline ));
329
332
throw ;
330
333
}
331
334
}
332
335
333
336
stringstream* SiVaContainer::parseDDoc (istream &is, bool useHashCode)
334
337
{
335
- auto transcode = [](const XMLCh *chr) {
336
- return xsd::cxx::xml::transcode<char >(chr);
337
- };
338
+ using xsd::cxx::xml::transcode;
339
+ using cpXMLCh = const XMLCh*;
338
340
try
339
341
{
340
- using cpXMLCh = const XMLCh*;
341
342
unique_ptr<DOMDocument> dom (SecureDOMParser ().parseIStream (is));
342
343
DOMNodeList *nodeList = dom->getElementsByTagName (cpXMLCh (u" DataFile" ));
343
344
for (XMLSize_t i = 0 ; i < nodeList->getLength (); ++i)
@@ -354,7 +355,9 @@ stringstream* SiVaContainer::parseDDoc(istream &is, bool useHashCode)
354
355
if (const XMLCh *b64 = item->getTextContent ())
355
356
{
356
357
d->dataFiles .push_back (new DataFilePrivate (unique_ptr<istream>(new stringstream (base64_decode (b64))),
357
- transcode (item->getAttribute (cpXMLCh (u" Filename" ))), transcode (item->getAttribute (cpXMLCh (u" MimeType" ))), transcode (item->getAttribute (cpXMLCh (u" Id" )))));
358
+ transcode<char >(item->getAttribute (cpXMLCh (u" Filename" ))),
359
+ transcode<char >(item->getAttribute (cpXMLCh (u" MimeType" ))),
360
+ transcode<char >(item->getAttribute (cpXMLCh (u" Id" )))));
358
361
}
359
362
360
363
if (!useHashCode)
@@ -387,7 +390,7 @@ stringstream* SiVaContainer::parseDDoc(istream &is, bool useHashCode)
387
390
catch (const XMLException& e)
388
391
{
389
392
try {
390
- string result = transcode (e.getMessage ());
393
+ string result = transcode< char > (e.getMessage ());
391
394
THROW (" Failed to parse DDoc XML: %s" , result.c_str ());
392
395
} catch (const xsd::cxx::xml::invalid_utf16_string & /* ex */ ) {
393
396
THROW (" Failed to parse DDoc XML." );
@@ -396,7 +399,7 @@ stringstream* SiVaContainer::parseDDoc(istream &is, bool useHashCode)
396
399
catch (const DOMException& e)
397
400
{
398
401
try {
399
- string result = transcode (e.getMessage ());
402
+ string result = transcode< char > (e.getMessage ());
400
403
THROW (" Failed to parse DDoc XML: %s" , result.c_str ());
401
404
} catch (const xsd::cxx::xml::invalid_utf16_string & /* ex */ ) {
402
405
THROW (" Failed to parse DDoc XML." );
0 commit comments