ACSMDownloader

ACSMDownloader Commit Details

Date:2021-04-10 20:59:02 (3 months 17 days ago)
Author:Grégory Soutadé
Commit:3b59516bfd2c3124e3f60b900019bfaeca5ea41d
Parents: 053d6375b871a31abf17c8bdfd973241d12724cd
Message:Add first RMSDK implementation

Changes:
Ainclude/rmsdk_wrapper.h (full)
Minclude/log.h (1 diff)
Minclude/rmsdk/dp_io.h (2 diffs)

File differences

include/log.h
1313
1414
1515
16
1617
#define LOG(lvl, msg) if (lvl <= verbose) std::cout << msg << std::endl;
#define LOG_FUNC() LOG(TRACE, __FUNCTION__)
#endif
include/rmsdk/dp_io.h
4747
4848
4949
50
51
50
51
5252
5353
5454
......
9191
9292
9393
94
94
9595
9696
9797
public:
#ifdef RMSDK_10_0
virtual void strfn0(void) = 0;
virtual void strfn1(void) = 0;
virtual void streamfn0(void) = 0;
virtual void streamfn1(void) = 0;
#endif
virtual void release() = 0;
virtual void setStreamClient( StreamClient * receiver ) = 0;
public:
#ifdef RMSDK_10_0
virtual void fn0() = 0;
virtual void mockpartitionfn0() = 0;
#endif
virtual dpdev::Device * getDevice() = 0;
virtual int getIndex() = 0;
include/rmsdk_wrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
#ifndef RMSDK_WRAPPER_H
#define RMSDK_WRAPPER_H
#include <iostream>
#include <dp_all.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QEventLoop>
#include <QCoreApplication>
#include <QFile>
#include <log.h>
class MockDevice;
namespace adept {
class DRMProcessorImpl;
class DRMProviderImpl {
protected:
virtual ~DRMProviderImpl() = 0;
public:
virtual dp::String getInterfaceID();
virtual dp::String getOptionalInterface(char const*) = 0;
virtual DRMProcessorImpl * createDRMProcessor( dpdrm::DRMProcessorClient * client, MockDevice * device );
};
class DRMProcessorImpl
{
protected:
virtual ~DRMProcessorImpl() {}
public:
virtual dp::String getInterfaceID() = 0;
virtual dp::String getOptionalInterface(char const*) = 0;
virtual void release() = 0;
virtual dp::list<dpdrm::Activation> getActivations() = 0;
virtual void setUser(dp::String const&) = 0;
virtual void setPartition(dpio::Partition*) = 0;
virtual void reset() = 0;
virtual unsigned int initWorkflows(unsigned int, dp::Data const&) = 0;
virtual unsigned int initSignInWorkflowCommon(unsigned int) = 0;
virtual unsigned int initSignInWorkflow(unsigned int, dp::String const&, dp::String const&, dp::Data const&) = 0;
virtual unsigned int initLoanReturnWorkflow(dp::String const&) = 0;
virtual unsigned int initUpdateLoansWorkflow(dp::String const&, dp::String const&) = 0;
virtual unsigned int initJoinAccountsWorkflow(dp::String const&, dp::String const&, dp::String const&) = 0;
virtual void startWorkflows(unsigned int) = 0;
virtual void providePasshash(dp::Data const&) = 0;
virtual void provideInput(dp::Data const&) = 0;
virtual void provideConfirmation(dp::String const&, int) = 0;
virtual void transferLoanTokensFrom(dpdev::Device*) = 0;
virtual void transferCredentialsFrom(dpdev::Device*, dp::String const&, bool) = 0;
virtual dp::list<dpdrm::FulfillmentItem> getFulfillmentItems() = 0;
virtual dp::String getFulfillmentID() = 0;
virtual bool isReturnable() = 0;
virtual int addPasshash(dp::String const&, dp::Data const&) = 0;
virtual int removePasshash(dp::String const&, dp::Data const&) = 0;
virtual dp::Data calculatePasshash(dp::String const&, dp::String const&) = 0;
virtual void getInterfaceVersion() = 0;
virtual void getResourceStream(dp::String const&, unsigned int) = 0;
virtual void canContinueProcessing(int) = 0;
virtual void reportLoadingState(int) = 0;
virtual void reportDocumentError(dp::String const&) = 0;
virtual void reportErrorListChange() = 0;
virtual void requestLicense(dp::String const&, dp::String const&, dp::Data const&) = 0;
virtual void requestDocumentPassword() = 0;
virtual void documentSerialized() = 0;
virtual void reportStateError(uft::String const&) = 0;
virtual void reportProcessError(uft::String const&) = 0;
virtual void setURLString(uft::String const&) = 0;
virtual void getURLString() = 0;
virtual void changeURL(uft::String const&) = 0;
void operatorAuthResp(uft::String const&, uft::Buffer const&);
};
};
namespace rmsdk{
adept::DRMProviderImpl* getProvider();
};
class MockDRMProcessorClient: public dpdrm::DRMProcessorClient
{
public:
virtual ~MockDRMProcessorClient() {}
virtual void mockclientfn0() {LOG_FUNC();}
virtual void mockclientfn1() {LOG_FUNC();}
virtual void workflowFinished(unsigned int workflow, const dp::String& str)
{
LOG(INFO, "Workflow finished " << workflow << " " << str.utf8());
}
virtual void workflowsDone( unsigned int workflows, const dp::Data& followUp )
{
LOG(INFO, "Workflows done " << workflows);
if (followUp.data())
LOG(INFO, "Workflows done " << followUp.data());
}
virtual void requestInput( const dp::Data& inputXHTML ) {LOG_FUNC();}
virtual void requestConfirmation( const dp::String& code )
{
LOG_FUNC();
LOG(INFO, code.utf8());
}
virtual void reportWorkflowProgress( unsigned int workflow, const dp::String& title, double progress )
{
LOG(WARN, "Progress " << workflow << " " << title.utf8() << " " << progress << " %%");
}
virtual void reportWorkflowError( unsigned int workflow, const dp::String& errorCode )
{
LOG(ERROR, "Workflow error " << workflow << " " << errorCode.utf8());
}
};
class MockPartition : public dpio::Partition
{
public:
MockPartition(dpdev::Device * owningDevice, int index,
const dp::String& name, const dp::String& type,
const dp::String& rootFolderURL, const dp::String& docFolderURL,
const dp::String& tempFolderURL):
device(owningDevice), index(index), name(name), type(type),
rootFolderURL(rootFolderURL), docFolderURL(docFolderURL),
tempFolderURL(tempFolderURL)
{
}
virtual void mockpartitionfn0() {LOG_FUNC();}
virtual void * getOptionalInterface( const char * name ) {LOG_FUNC(); return 0;}
virtual dpdev::Device * getDevice() {LOG_FUNC(); return device;}
virtual int getIndex() {LOG_FUNC(); return index;}
virtual dp::String getPartitionName() {LOG_FUNC(); return name;}
virtual dp::String getPartitionType() {LOG_FUNC(); return type;}
virtual dp::String getRootURL() {LOG_FUNC(); return rootFolderURL;}
virtual dp::String getDocumentFolderURL() {LOG_FUNC(); return docFolderURL;}
virtual dp::String getTemporaryFolderURL() {LOG_FUNC(); return tempFolderURL;}
virtual dpio::Stream * readFile( const dp::String& fileURL, dpio::StreamClient * client, unsigned int caps )
{
LOG_FUNC();
return 0;
}
virtual void createUniqueFile( const dp::String& baseURL, const dp::String& suffix, dp::Callback * callback )
{
LOG_FUNC();
}
virtual void writeFile( const dp::String& fileURL, dpio::Stream * streamToWrite, dp::Callback * callback )
{
LOG_FUNC();
std::cout << fileURL.utf8() << std::endl;
QFile file(fileURL.utf8());
dp::Data data = streamToWrite->readSynchronousStream(streamToWrite);
LOG(DEBUG, "Read from stream " << data.length() << " bytes");
bool ret = file.open(QIODevice::WriteOnly|QIODevice::Truncate);
if (!ret)
{
LOG(ERROR, "Unable to open file " << fileURL.utf8());
return;
}
else
LOG(WARN, "Write file " << fileURL.utf8());
file.write((const char*)data.data(), data.length());
file.close();
}
virtual void removeFile( const dp::String& fileURL, dp::Callback * callback )
{
LOG_FUNC();
}
private:
dpdev::Device * device;
int index;
dp::String name;
dp::String type;
dp::String rootFolderURL;
dp::String docFolderURL;
dp::String tempFolderURL;
};
class MockProvider : public dpdev::DeviceProvider
{
public:
MockProvider(dpdev::Device * device):device(device) {}
dp::String getIdentifier() {LOG_FUNC(); return "MockProvider";}
virtual int getIndex() {LOG_FUNC(); return 0;}
virtual dpdev::Device * getDevice( int index ){
LOG_FUNC();
if (index == 0)
return device;
else
return 0;
}
virtual bool mount( const dp::String& rootURL, const dp::String& name, const dp::String& type )
{
LOG(INFO, "Mount " << rootURL.utf8() << " " << name.utf8() << " " << type.utf8());
return true;
}
virtual bool unmount( const dp::String& rootURL )
{
LOG_FUNC();
std::cout << rootURL.utf8() << std::endl;
return true;
}
virtual void mockproviderfn0(void) {LOG_FUNC();}
virtual void mockproviderfn1(void) {LOG_FUNC();}
virtual void mockproviderfn2(void) {LOG_FUNC();}
virtual void mockproviderfn3(void) {LOG_FUNC();}
private:
dpdev::Device* device;
};
class MockDevice : public dpdev::Device
{
private:
unsigned char *_activationRecord;
int _activationRecordLength;
public:
MockDevice(dpdrm::DRMProcessorClient* processorClient) :deviceProvider(0), processorClient(processorClient) {
partition = new MockPartition(this, 0, "root", "Fixed", "/home/soutade/kobo/mock/root", "/home/soutade/kobo/mock/root/doc", "/home/soutade/kobo/mock/root/tmp");
_activationRecord = (unsigned char*)malloc(15*1024);
int fd = open("root/activation.xml", O_RDONLY);
_activationRecordLength = read(fd, _activationRecord, 15*1024);
close (fd);
dp::setVersionInfo("hobbes", "9.2.38311");
dp::setVersionInfo("clientVersion", "Boo Reader");
dp::setVersionInfo("clientOS", "Linux 2.6.32 armv7l");
dp::setVersionInfo("clientLocale", "fr");
}
void setProvider(dpdev::DeviceProvider* deviceProvider)
{this->deviceProvider=deviceProvider;}
void setProcessorClient(dpdrm::DRMProcessorClient* processorClient)
{this->processorClient=processorClient;}
virtual void * getOptionalInterface( const char * name ) {LOG_FUNC(); return 0;}
virtual void prepareDeviceKey() {LOG_FUNC();}
virtual dpdev::DeviceProvider * getProvider() {LOG_FUNC();return deviceProvider;}
virtual int getIndex() {LOG_FUNC();return 0;}
virtual dp::String getDeviceName();
virtual dp::Data getDeviceKey();
virtual dp::String getDeviceType();
virtual dp::Data getFingerprint();
virtual dp::Data getPrivatedeviceKey(void) {
LOG_FUNC();
// devkey.bin
const unsigned char userid[] = {
0x50, 0xae, 0x74, 0xde, 0x45, 0xb0, 0x8e, 0xf1, 0xe8, 0x2a, 0x40, 0xe8,
0x87, 0xd8, 0xad, 0x29
};
return dp::Data(userid, sizeof(userid));
}
virtual dp::Data getActivationRecord();
virtual void setActivationRecord( const dp::Data& data );
virtual dpio::Partition * getPartition( int index );
virtual dp::String getVersionInfo( const dp::String& name );
virtual bool isTrusted() {LOG_FUNC();return false;};
private:
dpdev::DeviceProvider* deviceProvider;
dpdrm::DRMProcessorClient* processorClient;
dpio::Partition* partition;
};
dp::String MockDevice::getDeviceName() {
LOG_FUNC();
return "Cybook Gen5";}
dp::String MockDevice::getDeviceType() {
LOG_FUNC();
return "mobile";}
dp::Data MockDevice::getFingerprint() {
LOG_FUNC();
// "dXK7MBnU3f4g5F15uogDRMADpgM=" From device.xml
static unsigned char fingerprint[] =
{
0x75, 0x72, 0xbb, 0x30, 0x19, 0xd4, 0xdd, 0xfe, 0x20, 0xe4, 0x5d, 0x79,
0xba, 0x88, 0x03, 0x44, 0xc0, 0x03, 0xa6, 0x03
};
return dp::Data(fingerprint, sizeof(fingerprint));
}
dp::Data MockDevice::getDeviceKey() {
LOG_FUNC();
const unsigned char privateLicenceKey[] = {
0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
0x02, 0x61, 0x30, 0x82, 0x02, 0x5d, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81,
0x00, 0xcc, 0x8c, 0x5b, 0x5c, 0x13, 0x0f, 0x82, 0x8c, 0x7e, 0x7f, 0xe9,
0x18, 0xbe, 0x04, 0x66, 0x33, 0xfb, 0xe2, 0x4c, 0x1a, 0x06, 0x9f, 0xb0,
0x21, 0x14, 0xcc, 0x5d, 0x78, 0x7c, 0x81, 0xa0, 0x90, 0x80, 0xeb, 0x08,
0xaf, 0x56, 0x97, 0x59, 0xa5, 0x97, 0x92, 0x07, 0x12, 0xae, 0xef, 0x5c,
0xba, 0xe2, 0x3e, 0x28, 0x90, 0x99, 0xb5, 0x48, 0x1e, 0x4c, 0xcc, 0x2f,
0x29, 0x4e, 0xb3, 0x86, 0xf2, 0x3e, 0x2e, 0xe4, 0xab, 0x6e, 0x86, 0xca,
0x36, 0xe7, 0x2b, 0xe7, 0xcd, 0x36, 0x38, 0xc3, 0xb3, 0x93, 0x12, 0x6b,
0x59, 0xb1, 0x18, 0xde, 0x0b, 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xdb, 0xeb, 0x6c, 0xd1, 0x02, 0x40,
0x6d, 0xc2, 0xd5, 0xe5, 0xb1, 0x5b, 0xfa, 0xd7, 0xbd, 0xd3, 0xa7, 0x07,
0xd5, 0x36, 0x97, 0x20, 0xad, 0x03, 0x24, 0x48, 0xb3, 0x3d, 0x97, 0x16,
0x1e, 0x67, 0x14, 0x94, 0x4e, 0x14, 0x42, 0xd8, 0x09, 0xc4, 0x05, 0x64,
0xf0, 0x8c, 0xe0, 0x97, 0xf6, 0x68, 0xbb, 0x1e, 0x03, 0x64, 0xcb, 0xf9,
0x81, 0x2c, 0x49, 0x5e, 0x97, 0x8d, 0x63, 0x21, 0x37, 0x1d, 0x99, 0xbb,
0xf6, 0x1f, 0x64, 0x57, 0x02, 0x41, 0x00, 0xd9, 0xf9, 0x98, 0x3a, 0x99,
0xcf, 0xda, 0xf3, 0x9d, 0xb3, 0xb6, 0x1e, 0x72, 0x52, 0x33, 0xe8, 0x35,
0x26, 0x4b, 0x12, 0xb3, 0x0f, 0xde, 0x72, 0x68, 0x35, 0xf8, 0xea, 0xec,
0xc7, 0xc9, 0x97, 0x0c, 0x3e, 0x66, 0x3e, 0x09, 0x59, 0x28, 0x1f, 0xdd,
0x49, 0xe8, 0x39, 0x47, 0xcb, 0x44, 0x43, 0x36, 0x54, 0x30, 0x23, 0x72,
0x7a, 0x60, 0xc1, 0x5c, 0x3c, 0x59, 0x60, 0x30, 0x9d, 0x99, 0xb4
};
return dp::Data(privateLicenceKey, sizeof(privateLicenceKey));
}
dp::Data MockDevice::getActivationRecord() {
LOG_FUNC();
return dp::Data(_activationRecord, _activationRecordLength);
}
void MockDevice::setActivationRecord( const dp::Data& data ) {
LOG_FUNC();
free(_activationRecord);
_activationRecordLength = data.length();
_activationRecord = (unsigned char*)malloc(_activationRecordLength);
memcpy(_activationRecord, data.data(), _activationRecordLength);
LOG(DEBUG, "New activation record :" << std::endl << _activationRecord);
}
dpio::Partition * MockDevice::getPartition( int index ) {
LOG_FUNC();
return partition;
}
dp::String MockDevice::getVersionInfo( const dp::String& name ) {
LOG_FUNC();
LOG(DEBUG, ">>> " << name.utf8());
dp::String res = dp::getVersionInfo(name);
return res;
//return dp::String("3.19.5761");//"9.2.38311";
const char* verName = name.utf8();
if (!strcmp(verName, dp::String("hobbes").utf8()))
//return dp::String("9.2.38311");
return dp::String("<adept:version name=\"hobbes\" value=\"9.2.38311\">");
if (!strcmp(verName, dp::String("clientVersion").utf8()))
return dp::String("<adept:version name=\"clientVersion\" value=\"Boo Reader\">");
// return dp::String("Boo Reader");
if (!strcmp(verName, dp::String("clientOS").utf8()))
return dp::String("<adept:version name=\"clientOS\" value=\"Linux 2.6.32 armv7l\">");
// return dp::String("Linux 2.6.32 armv7l");
if (!strcmp(verName, dp::String("clientLocale").utf8()))
return dp::String("<adept:version name=\"clientLocale\" value=\"fr\">");
// return dp::String("fr");
else
std::cout << "UNKNOWN" << std::endl;
return dp::String("0");
}
class MockLibrary: public dplib::Library
{
virtual dpio::Partition * getPartition() {
LOG_FUNC();
return 0;
}
virtual bool isLoaded() {
LOG_FUNC();
return true;
}
virtual dp::ref<dplib::ContentRecord> createContentRecord( const dp::String& contentURL )
{
LOG_FUNC();
return 0;
}
virtual dp::ref<dplib::ContentRecord> cloneContentRecord( const dp::ref<dplib::ContentRecord>& existingCR, const dp::String& newContentURL )
{
LOG_FUNC();
return 0;
}
virtual dp::ref<dplib::ContentRecord> getContentRecordByURL( const dp::String& url )
{
LOG_FUNC();
return 0;
}
virtual void removeContentRecord( const dp::ref<dplib::ContentRecord>& contentRecord )
{
LOG_FUNC();
}
virtual dp::list<dplib::ContentTag> getTags( const dp::ref<dplib::ContentTag>& parent )
{
LOG_FUNC();
return 0;
}
virtual dp::list<dplib::ContentRecord> getContentRecords( const dp::ref<dplib::ContentTag>& tag )
{
LOG_FUNC();
return 0;
}
virtual dp::ref<dplib::ContentTag> getTagByID( const dp::String& tag )
{
LOG_FUNC();
return 0;
}
virtual void removeTag( const dp::ref<dplib::ContentTag>& tag )
{
LOG_FUNC();
}
virtual void addListener( dplib::LibraryListener * listener )
{
LOG_FUNC();
}
virtual void removeListener( dplib::LibraryListener * listener )
{
LOG_FUNC();
}
};
class MockStream : public dpio::Stream {
public:
MockStream(const dp::String& method, const dp::String& url, dpio::StreamClient * client,
dpio::Stream* postData):
method(method), url(url), client(client)
{
LOG(INFO, "New stream " << method.utf8() << " " << url.utf8());
QNetworkRequest request(QUrl(url.utf8()));
request.setRawHeader("Accept", "*/*");
request.setRawHeader("Content-Type", "application/vnd.adobe.adept+xml");
request.setRawHeader("User-Agent", "book2png");
if (postData)
{
dp::Data data = dpio::Stream::readSynchronousStream(postData);
LOG(DEBUG, "Len " << data.length());
LOG(DEBUG, "data " << data.data());
reply = networkManager.post(request, QByteArray((const char*)data.data(), data.length()));
}
else
{
reply = networkManager.get(request);
}
}
virtual void streamfn0(void) {LOG_FUNC();}
virtual void streamfn1(void) {LOG_FUNC();}
virtual void release() {LOG_FUNC();}
virtual void setStreamClient( dpio::StreamClient * receiver )
{
LOG_FUNC();
client = receiver;
}
virtual unsigned int getCapabilities()
{
LOG_FUNC();
return dpio::SC_SYNCHRONOUS;
}
virtual void requestInfo()
{
LOG_FUNC();
int argc = 0;
QCoreApplication app(argc,0);
while (!reply->isFinished())
app.processEvents();
app.quit();
requestBytes(0, -1);
}
virtual void requestBytes( size_t offset, size_t len )
{
LOG_FUNC();
LOG(DEBUG, "Offset " << offset << ", Len " << len);
if (!client)
{
LOG(ERROR, "Error, No client");
return;
}
size_t bytes = (size_t)reply->bytesAvailable();
QByteArray _replyData = reply->readAll();
const unsigned char* replyData = (const unsigned char*)_replyData.constData();
LOG(DEBUG, "Reply " << bytes << " bytes");
if (reply->hasRawHeader("Content-Type"))
client->propertyReady("Content-Type", reply->rawHeader("Content-Type").constData());
if (reply->hasRawHeader("Content-Length"))
client->propertyReady("Content-Length", reply->rawHeader("Content-Length").constData());
client->totalLengthReady(bytes);
client->bytesReady(0, dp::Data(replyData, bytes), true);
}
virtual void reportWriteError( const dp::String& error )
{
LOG_FUNC();
}
virtual void requestBytes2( size_t offset, size_t len, void* param0, dpio::StreamClient * client)
{
LOG_FUNC();
setStreamClient(client);
requestBytes(offset, len);
}
virtual void streamfn2() {LOG_FUNC();}
virtual void streamfn3() {LOG_FUNC();}
virtual void streamfn4() {LOG_FUNC();}
private:
dp::String method;
dp::String url;
dpio::StreamClient * client;
QNetworkAccessManager networkManager;
QNetworkReply *reply;
};
namespace adept {
template<typename T>
class UrlLoader : public dputils::GuardedStream
{
private:
T processor;
};
};
class MockNetProvider : public dpnet::NetProvider
{
virtual dpio::Stream * open( const dp::String& method, const dp::String& url, dpio::StreamClient * client,
unsigned int cap, dpio::Stream * dataToPost = 0 ) {
LOG(INFO, "New net stream " << method.utf8() << " " << url.utf8());
return 0;
}
virtual void netfn0() {LOG_FUNC();}
virtual void netfn1() {LOG_FUNC();}
virtual void netfn2() {LOG_FUNC();}
virtual dpio::Stream * netfn3(dp::String const& method, dp::String const& url, adept::UrlLoader<void*> * client, unsigned int param1, dpio::Stream* stream) {
LOG_FUNC();
return new MockStream(method, url, (dpio::StreamClient*)(client), stream);
}
virtual void netfn4() {LOG_FUNC();}
virtual void netfn5() {LOG_FUNC();}
};
#endif

Archive Download the corresponding diff file

Branches