2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 $Date: 2010/03/25 12:32:30 $
37 #include "settings_impl.h"
38 #include "conffiles.h"
40 #include "user_stat.h"
41 #include "user_conf.h"
42 #include "corp_conf.h"
43 #include "service_conf.h"
44 #include "admin_conf.h"
45 #include "tariff_conf.h"
47 #include "stg_message.h"
51 volatile time_t stgTime = time(NULL);
53 int main(int argc, char **argv)
55 printfd(__FILE__, "Start\n");
57 STORE * fromStore = NULL;
58 STORE * toStore = NULL;
60 SETTINGS_IMPL * settings = NULL;
64 MODULE_SETTINGS fromStoreSettings;
65 MODULE_SETTINGS toStoreSettings;
74 vector<STG_MSG_HDR> hdrs;
77 settings = new SETTINGS_IMPL(argv[1]);
79 settings = new SETTINGS_IMPL();
81 if (settings->ReadSettings())
83 printfd(__FILE__, "Error reading settings\n");
88 fromStoreSettings = settings->GetSourceStoreModuleSettings();
89 toStoreSettings = settings->GetDestStoreModuleSettings();
90 modulePath = settings->GetModulesPath();
92 string sourcePlugin(modulePath + "/mod_" + fromStoreSettings.moduleName + ".so");
93 string destPlugin(modulePath + "/mod_" + toStoreSettings.moduleName + ".so");
95 void * src_lh = dlopen(sourcePlugin.c_str(), RTLD_NOW);
98 printfd(__FILE__, "Source storage plugin loading failed: %s\n", dlerror());
103 void * dst_lh = dlopen(destPlugin.c_str(), RTLD_NOW);
106 printfd(__FILE__, "Destination storage plugin loading failed: %s\n", dlerror());
111 STORE * (*GetSourceStore)();
112 STORE * (*GetDestStore)();
113 GetSourceStore = (STORE * (*)())dlsym(src_lh, "GetStore");
116 printfd(__FILE__, "Source storage plugin loading failed. GetStore not found: %s\n", dlerror());
120 GetDestStore = (STORE * (*)())dlsym(dst_lh, "GetStore");
123 printfd(__FILE__, "Storage plugin (firebird) loading failed. GetStore not found: %s\n", dlerror());
128 fromStore = GetSourceStore();
129 toStore = GetDestStore();
131 vector<string> entities;
132 vector<string> ready;
133 fromStore->SetSettings(fromStoreSettings);
134 fromStore->ParseSettings();
135 toStore->SetSettings(toStoreSettings);
136 toStore->ParseSettings();
138 printfd(__FILE__, "Importing admins:\n");
139 entities.erase(entities.begin(), entities.end());
140 ready.erase(ready.begin(), ready.end());
141 if (fromStore->GetAdminsList(&entities))
143 printfd(__FILE__, "Error getting admins list: %s\n", fromStore->GetStrError().c_str());
149 if (toStore->GetAdminsList(&ready))
151 printfd(__FILE__, "Error getting admins list: %s\n", toStore->GetStrError().c_str());
158 vector<string>::const_iterator it;
159 for (it = entities.begin(); it != entities.end(); ++it)
161 printfd(__FILE__, "\t - %s\n", it->c_str());
162 if (find(ready.begin(), ready.end(), *it) == ready.end())
163 if (toStore->AddAdmin(*it))
165 printfd(__FILE__, "Error adding admin: %s\n", toStore->GetStrError().c_str());
171 if (fromStore->RestoreAdmin(&ac, *it))
173 printfd(__FILE__, "Error getting admin's confi: %s\n", fromStore->GetStrError().c_str());
180 if (toStore->SaveAdmin(ac))
182 printfd(__FILE__, "Error saving admin's conf: %s\n", toStore->GetStrError().c_str());
190 printfd(__FILE__, "Importing tariffs:\n");
191 entities.erase(entities.begin(), entities.end());
192 ready.erase(ready.begin(), ready.end());
193 if (fromStore->GetTariffsList(&entities))
195 printfd(__FILE__, "Error getting tariffs list: %s\n", fromStore->GetStrError().c_str());
201 if (toStore->GetTariffsList(&ready))
203 printfd(__FILE__, "Error getting tariffs list: %s\n", toStore->GetStrError().c_str());
210 for (it = entities.begin(); it != entities.end(); ++it)
212 printfd(__FILE__, "\t - %s\n", it->c_str());
213 if (find(ready.begin(), ready.end(), *it) == ready.end())
214 if (toStore->AddTariff(*it))
216 printfd(__FILE__, "Error adding tariff: %s\n", toStore->GetStrError().c_str());
222 if (fromStore->RestoreTariff(&td, *it))
224 printfd(__FILE__, "Error getting tariff's data: %s\n", fromStore->GetStrError().c_str());
230 if (toStore->SaveTariff(td, *it))
232 printfd(__FILE__, "Error saving tariff's data: %s\n", toStore->GetStrError().c_str());
240 printfd(__FILE__, "Importing services:\n");
241 entities.erase(entities.begin(), entities.end());
242 ready.erase(ready.begin(), ready.end());
243 if (fromStore->GetServicesList(&entities))
245 printfd(__FILE__, "Error getting service list: %s\n", fromStore->GetStrError().c_str());
251 if (toStore->GetServicesList(&ready))
253 printfd(__FILE__, "Error getting service list: %s\n", toStore->GetStrError().c_str());
260 for (it = entities.begin(); it != entities.end(); ++it)
262 printfd(__FILE__, "\t - %s\n", it->c_str());
263 if (find(ready.begin(), ready.end(), *it) == ready.end())
264 if (toStore->AddService(*it))
266 printfd(__FILE__, "Error adding service: %s\n", toStore->GetStrError().c_str());
272 if (fromStore->RestoreService(&sc, *it))
274 printfd(__FILE__, "Error getting service's data: %s\n", fromStore->GetStrError().c_str());
280 if (toStore->SaveService(sc))
282 printfd(__FILE__, "Error saving service's data: %s\n", toStore->GetStrError().c_str());
290 printfd(__FILE__, "Importing corporations:\n");
291 entities.erase(entities.begin(), entities.end());
292 ready.erase(ready.begin(), ready.end());
293 if (fromStore->GetCorpsList(&entities))
295 printfd(__FILE__, "Error getting corporations list: %s\n", fromStore->GetStrError().c_str());
301 if (toStore->GetCorpsList(&ready))
303 printfd(__FILE__, "Error getting corporations list: %s\n", toStore->GetStrError().c_str());
310 for (it = entities.begin(); it != entities.end(); ++it)
312 printfd(__FILE__, "\t - %s\n", it->c_str());
313 if (find(ready.begin(), ready.end(), *it) == ready.end())
314 if (toStore->AddCorp(*it))
316 printfd(__FILE__, "Error adding corporation: %s\n", toStore->GetStrError().c_str());
322 if (fromStore->RestoreCorp(&cc, *it))
324 printfd(__FILE__, "Error getting corporation's data: %s\n", fromStore->GetStrError().c_str());
330 if (toStore->SaveCorp(cc))
332 printfd(__FILE__, "Error saving corporation's data: %s\n", toStore->GetStrError().c_str());
340 printfd(__FILE__, "Importing users:\n");
341 entities.erase(entities.begin(), entities.end());
342 ready.erase(ready.begin(), ready.end());
343 if (fromStore->GetUsersList(&entities))
345 printfd(__FILE__, "Error getting users list: %s\n", fromStore->GetStrError().c_str());
351 if (toStore->GetUsersList(&ready))
353 printfd(__FILE__, "Error getting users list: %s\n", toStore->GetStrError().c_str());
360 sort(ready.begin(), ready.end());
361 for (it = entities.begin(); it != entities.end(); ++it)
363 printfd(__FILE__, "\t - %s\n", it->c_str());
364 if (!binary_search(ready.begin(), ready.end(), *it)) {
365 if (toStore->AddUser(*it))
367 printfd(__FILE__, "Error adding user: %s\n", toStore->GetStrError().c_str());
374 printfd(__FILE__, "\t\t(adding passed)\n");
376 if (fromStore->RestoreUserConf(&uc, *it))
378 printfd(__FILE__, "Error getting user's conf: %s\n", fromStore->GetStrError().c_str());
384 if (fromStore->RestoreUserStat(&us, *it))
386 printfd(__FILE__, "Error getting user's stat: %s\n", fromStore->GetStrError().c_str());
392 if (toStore->SaveUserConf(uc, *it))
394 printfd(__FILE__, "Error saving user's conf: %s\n", toStore->GetStrError().c_str());
400 if (toStore->SaveUserStat(us, *it))
402 printfd(__FILE__, "Error saving user's stat: %s\n", toStore->GetStrError().c_str());
408 hdrs.erase(hdrs.begin(), hdrs.end());
409 if (fromStore->GetMessageHdrs(&hdrs, *it))
411 printfd(__FILE__, "Error getting user's messages: %s\n", fromStore->GetStrError().c_str());
417 vector<STG_MSG_HDR>::iterator mit;
418 for (mit = hdrs.begin(); mit != hdrs.end(); ++mit)
420 if (fromStore->GetMessage(mit->id, &msg, *it))
422 printfd(__FILE__, "Error getting message for a user: %s\n", fromStore->GetStrError().c_str());
428 printfd(__FILE__, "\t\t * %s\n", msg.text.c_str());
429 if (toStore->AddMessage(&msg, *it))
431 printfd(__FILE__, "Error adding message to a user: %s\n", toStore->GetStrError().c_str());
442 printfd(__FILE__, "Done\n");