ACSMDownloader

ACSMDownloader Git Source Tree

Root/src/main.cpp

Source at commit 1f582f55f35b3a6898ced8d388e043ee81168bd1 created 4 months 21 days ago.
By Grégory Soutadé, First clean working version
1#include <unistd.h>
2#include <getopt.h>
3
4#include <iostream>
5#include <log.h>
6
7#include <QFile>
8#include <QCoreApplication>
9
10#include <dp.h>
11#include <rmsdk_wrapper.h>
12
13#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
14
15int verbose = INFO;
16
17static char* deviceFile = 0;
18static char* activationFile = 0;
19static char* devicekeyFile = 0;
20static char* acsmFile = 0;
21static char* outputFile = 0;
22
23class ACSMDownloader
24{
25public:
26 ACSMDownloader(QCoreApplication* app):
27app(app)
28 {
29
30 }
31
32 static void* run(void* param)
33 {
34ACSMDownloader* _this;
35
36LOG_FUNC();
37
38int ret = dp::platformInit(0xFFFFFFFF);
39
40if (ret) {
41 LOG(ERROR, "Error platform init " << ret);
42 _this->app->exit(ret);
43 return (void*)ret;
44}
45
46dp::cryptRegisterOpenSSL();
47dp::documentRegisterEPUB();
48dp::documentRegisterPDF();
49
50LOG(DEBUG, "Create Adobe objects");
51
52MockDRMProcessorClient processorClient(outputFile);
53MockDevice device(&processorClient, deviceFile, activationFile, devicekeyFile);
54MockProvider provider(&device);
55device.setProvider(&provider);
56dpdev::DeviceProvider::addProvider(&provider);
57
58MockNetProvider netProvider;
59dpnet::NetProvider::setProvider(&netProvider);
60
61adept::DRMProviderImpl* _prov = rmsdk::getProvider();
62
63LOG(DEBUG, "Create DRM Processor");
64adept::DRMProcessorImpl* drmprocessor = _prov->createDRMProcessor(&processorClient, &device);
65
66processorClient.setProcessor(drmprocessor);
67
68unsigned char* buffer;
69int buffer_size;
70MockDevice::readFile(acsmFile, &buffer, &buffer_size, true);
71
72LOG(DEBUG, "Init workflow ");
73
74drmprocessor->initWorkflows(WORKFLOW_AUTH_SIGN_IN|WORKFLOW_FULFILLMENT|WORKFLOW_DOWNLOAD|WORKFLOW_NOTIFICATION, dp::Data(buffer, buffer_size));
75
76LOG(DEBUG, "Start work");
77int res = drmprocessor->startWorkflows(WORKFLOW_AUTH_SIGN_IN|WORKFLOW_FULFILLMENT|WORKFLOW_DOWNLOAD|WORKFLOW_NOTIFICATION);
78delete[] buffer;
79
80LOG(DEBUG, "Bye bye");
81
82_this->app->exit(0);
83
84return 0;
85 }
86
87private:
88 QCoreApplication* app;
89};
90
91static QString findFile(char* filename)
92{
93 QFile file;
94 QString path = filename;
95
96 file.setFileName(path);
97
98 if (!file.exists())
99 {
100path = QString("./adobe-digital-editions directory/") + filename;
101file.setFileName(path);
102if (!file.exists())
103{
104 path = QString("./.adobe-digital-editions directory/") + filename;
105 file.setFileName(path);
106 if (!file.exists())
107return QString("");
108}
109 }
110
111 return path;
112}
113
114static void usage(void)
115{
116 std::cout << "Download EPUB file from ACSM request file" << std::endl;
117
118 std::cout << "Usage: ./acsmdownloader [(-d|--device-file) device.xml] [(-a|--activation-file) activation.xml] [(-o|--output-file) output.epub] [(-v|--verbose)] [(-h|--help)] (-k|--device-key-file) devkey.bin (-f|--acsm-file) file.acsm" << std::endl << std::endl;
119
120 std::cout << " " << "-d|--device-file" << "\t" << "device.xml file from ereader" << std::endl;
121 std::cout << " " << "-a|--activation-file" << "\t" << "activation.xml file from ereader" << std::endl;
122 std::cout << " " << "-k|--device-key-file" << "\t" << "private device key file (eg devkey.bin) from ereader" << std::endl;
123 std::cout << " " << "-o|--output-file" << "\t" << "Optional output epub filename" << std::endl;
124 std::cout << " " << "-f|--acsm-file" << "\t" << "ACSM request file for epub download" << std::endl;
125 std::cout << " " << "-v|--verbose" << "\t\t" << "Increase verbosity, can be set multiple times" << std::endl;
126 std::cout << " " << "-h|--help" << "\t\t" << "This help" << std::endl;
127
128 std::cout << std::endl;
129 std::cout << "Device file and activation file are optional. If not set, they are looked into :" << std::endl;
130 std::cout << " * Current directory" << std::endl;
131 std::cout << " * adobe-digital-editions directory" << std::endl;
132 std::cout << " * .adobe-digital-editions directory" << std::endl;
133}
134
135int main(int argc, char** argv)
136{
137 int c;
138
139 char** files[] = {&devicekeyFile, &acsmFile};
140
141 while (1) {
142int this_option_optind = optind ? optind : 1;
143int option_index = 0;
144static struct option long_options[] = {
145 {"device-file", required_argument, 0, 'd' },
146 {"activation-file", required_argument, 0, 'a' },
147 {"device-key-file", required_argument, 0, 'k' },
148 {"output-file", required_argument, 0, 'o' },
149 {"acsm-file", required_argument, 0, 'f' },
150 {"verbose", no_argument, 0, 'v' },
151 {"help", no_argument, 0, 'h' },
152 {0, 0, 0, 0 }
153};
154
155c = getopt_long(argc, argv, "d:a:k:o:f:vh",
156 long_options, &option_index);
157if (c == -1)
158 break;
159
160switch (c) {
161case 'd':
162 deviceFile = optarg;
163 break;
164case 'a':
165 activationFile = optarg;
166 break;
167case 'k':
168 devicekeyFile = optarg;
169 break;
170case 'f':
171 acsmFile = optarg;
172 break;
173case 'o':
174 outputFile = optarg;
175 break;
176case 'v':
177 verbose++;
178 break;
179case 'h':
180 usage();
181 return 0;
182 break;
183default:
184 usage();
185 return -1;
186}
187 }
188
189 if (!devicekeyFile || !acsmFile)
190 {
191usage();
192return -1;
193 }
194
195 QString _deviceFile = findFile(deviceFile);
196 QString _activationFile = findFile(activationFile);
197
198 if (!_deviceFile.size())
199 {
200deviceFile = (deviceFile) ?: (char*)"device.xml";
201LOG(ERROR, "Error : " << deviceFile << " not found");
202return -1;
203 }
204
205 if (!_activationFile.size())
206 {
207activationFile = (activationFile) ?: (char*)"activation.xml";
208LOG(ERROR, "Error : " << activationFile << " not found");
209return -1;
210 }
211
212 QFile file;
213 int i;
214 for (i=0; i<ARRAY_SIZE(files); i++)
215 {
216file.setFileName(*files[i]);
217if (!file.exists())
218{
219 LOG(ERROR, "Error : " << *files[i] << " doesn't exists");
220 return -1;
221}
222 }
223
224 LOG(INFO, "RMSDK Version " << dp::getVersionInfo("hobbes").utf8());
225
226 QCoreApplication app(argc, argv);
227
228 ACSMDownloader downloader(&app);
229 pthread_t thread;
230 pthread_create(&thread, NULL, ACSMDownloader::run, (void*)&downloader);
231
232 return app.exec();
233}

Archive Download this file

Branches