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 $
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"
46 #include "module_settings.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 * settings = NULL;
64 MODULE_SETTINGS fromStoreSettings;
65 MODULE_SETTINGS toStoreSettings;
74 vector<STG_MSG_HDR> hdrs;
75 vector<STG_MSG_HDR>::iterator mit;
81 settings = new SETTINGS(argv[1]);
83 settings = new SETTINGS();
85 if (settings->ReadSettings())
87 printfd(__FILE__, "Error reading settings\n");
92 fromStoreSettings = settings->GetSourceStoreModuleSettings();
93 toStoreSettings = settings->GetDestStoreModuleSettings();
94 modulePath = settings->GetModulesPath();
96 string sourcePlugin(modulePath + "/mod_" + fromStoreSettings.moduleName + ".so");
97 string destPlugin(modulePath + "/mod_" + toStoreSettings.moduleName + ".so");
99 src_lh = dlopen(sourcePlugin.c_str(), RTLD_NOW);
102 printfd(__FILE__, "Source storage plugin loading failed: %s\n", dlerror());
107 dst_lh = dlopen(destPlugin.c_str(), RTLD_NOW);
110 printfd(__FILE__, "Destination storage plugin loading failed: %s\n", dlerror());
115 STORE * (*GetSourceStore)();
116 STORE * (*GetDestStore)();
117 GetSourceStore = (STORE * (*)())dlsym(src_lh, "GetStore");
120 printfd(__FILE__, "Source storage plugin loading failed. GetStore not found: %s\n", dlerror());
124 GetDestStore = (STORE * (*)())dlsym(dst_lh, "GetStore");
127 printfd(__FILE__, "Storage plugin (firebird) loading failed. GetStore not found: %s\n", dlerror());
132 fromStore = GetSourceStore();
133 toStore = GetDestStore();
135 vector<string> entities;
136 vector<string> ready;
137 vector<string>::const_iterator it;
138 fromStore->SetSettings(fromStoreSettings);
139 fromStore->ParseSettings();
140 toStore->SetSettings(toStoreSettings);
141 toStore->ParseSettings();
143 printfd(__FILE__, "Importing admins:\n");
144 entities.erase(entities.begin(), entities.end());
145 ready.erase(ready.begin(), ready.end());
146 if (fromStore->GetAdminsList(&entities))
148 printfd(__FILE__, "Error getting admins list: %s\n", fromStore->GetStrError().c_str());
154 if (toStore->GetAdminsList(&ready))
156 printfd(__FILE__, "Error getting admins list: %s\n", toStore->GetStrError().c_str());
162 for (it = entities.begin(); it != entities.end(); ++it)
164 printfd(__FILE__, "\t - %s\n", it->c_str());
165 if (find(ready.begin(), ready.end(), *it) == ready.end())
166 if (toStore->AddAdmin(*it))
168 printfd(__FILE__, "Error adding admin: %s\n", toStore->GetStrError().c_str());
174 if (fromStore->RestoreAdmin(&ac, *it))
176 printfd(__FILE__, "Error getting admin's confi: %s\n", fromStore->GetStrError().c_str());
183 if (toStore->SaveAdmin(ac))
185 printfd(__FILE__, "Error saving admin's conf: %s\n", toStore->GetStrError().c_str());
193 printfd(__FILE__, "Importing tariffs:\n");
194 entities.erase(entities.begin(), entities.end());
195 ready.erase(ready.begin(), ready.end());
196 if (fromStore->GetTariffsList(&entities))
198 printfd(__FILE__, "Error getting tariffs list: %s\n", fromStore->GetStrError().c_str());
204 if (toStore->GetTariffsList(&ready))
206 printfd(__FILE__, "Error getting tariffs list: %s\n", toStore->GetStrError().c_str());
212 for (it = entities.begin(); it != entities.end(); ++it)
214 printfd(__FILE__, "\t - %s\n", it->c_str());
215 if (find(ready.begin(), ready.end(), *it) == ready.end())
216 if (toStore->AddTariff(*it))
218 printfd(__FILE__, "Error adding tariff: %s\n", toStore->GetStrError().c_str());
224 if (fromStore->RestoreTariff(&td, *it))
226 printfd(__FILE__, "Error getting tariff's data: %s\n", fromStore->GetStrError().c_str());
232 if (toStore->SaveTariff(td, *it))
234 printfd(__FILE__, "Error saving tariff's data: %s\n", toStore->GetStrError().c_str());
242 printfd(__FILE__, "Importing services:\n");
243 entities.erase(entities.begin(), entities.end());
244 ready.erase(ready.begin(), ready.end());
245 if (fromStore->GetServicesList(&entities))
247 printfd(__FILE__, "Error getting service list: %s\n", fromStore->GetStrError().c_str());
253 if (toStore->GetServicesList(&ready))
255 printfd(__FILE__, "Error getting service list: %s\n", toStore->GetStrError().c_str());
261 for (it = entities.begin(); it != entities.end(); ++it)
263 printfd(__FILE__, "\t - %s\n", it->c_str());
264 if (find(ready.begin(), ready.end(), *it) == ready.end())
265 if (toStore->AddService(*it))
267 printfd(__FILE__, "Error adding service: %s\n", toStore->GetStrError().c_str());
273 if (fromStore->RestoreService(&sc, *it))
275 printfd(__FILE__, "Error getting service's data: %s\n", fromStore->GetStrError().c_str());
281 if (toStore->SaveService(sc))
283 printfd(__FILE__, "Error saving service's data: %s\n", toStore->GetStrError().c_str());
291 printfd(__FILE__, "Importing corporations:\n");
292 entities.erase(entities.begin(), entities.end());
293 ready.erase(ready.begin(), ready.end());
294 if (fromStore->GetCorpsList(&entities))
296 printfd(__FILE__, "Error getting corporations list: %s\n", fromStore->GetStrError().c_str());
302 if (toStore->GetCorpsList(&ready))
304 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());
359 sort(ready.begin(), ready.end());
360 for (it = entities.begin(); it != entities.end(); ++it)
362 printfd(__FILE__, "\t - %s\n", it->c_str());
363 if (!binary_search(ready.begin(), ready.end(), *it)) {
364 if (toStore->AddUser(*it))
366 printfd(__FILE__, "Error adding user: %s\n", toStore->GetStrError().c_str());
373 printfd(__FILE__, "\t\t(adding passed)\n");
375 if (fromStore->RestoreUserConf(&uc, *it))
377 printfd(__FILE__, "Error getting user's conf: %s\n", fromStore->GetStrError().c_str());
383 if (fromStore->RestoreUserStat(&us, *it))
385 printfd(__FILE__, "Error getting user's stat: %s\n", fromStore->GetStrError().c_str());
391 if (toStore->SaveUserConf(uc, *it))
393 printfd(__FILE__, "Error saving user's conf: %s\n", toStore->GetStrError().c_str());
399 if (toStore->SaveUserStat(us, *it))
401 printfd(__FILE__, "Error saving user's stat: %s\n", toStore->GetStrError().c_str());
407 hdrs.erase(hdrs.begin(), hdrs.end());
408 if (fromStore->GetMessageHdrs(&hdrs, *it))
410 printfd(__FILE__, "Error getting user's messages: %s\n", fromStore->GetStrError().c_str());
416 for (mit = hdrs.begin(); mit != hdrs.end(); ++mit)
418 if (fromStore->GetMessage(mit->id, &msg, *it))
420 printfd(__FILE__, "Error getting message for a user: %s\n", fromStore->GetStrError().c_str());
426 printfd(__FILE__, "\t\t * %s\n", msg.text.c_str());
427 if (toStore->AddMessage(&msg, *it))
429 printfd(__FILE__, "Error adding message to a user: %s\n", toStore->GetStrError().c_str());
441 printfd(__FILE__, "Done\n");