]> git.stg.codes - stg.git/commitdiff
Convertor project is renamed to "sgconv".
authorMaxim Mamontov <faust.madf@gmail.com>
Mon, 14 Jan 2013 19:01:32 +0000 (21:01 +0200)
committerMaxim Mamontov <faust.madf@gmail.com>
Mon, 14 Jan 2013 19:01:32 +0000 (21:01 +0200)
12 files changed:
projects/convertor/Makefile [deleted file]
projects/convertor/build [deleted file]
projects/convertor/convertor.conf [deleted file]
projects/convertor/main.cpp [deleted file]
projects/convertor/settings_impl.cpp [deleted file]
projects/convertor/settings_impl.h [deleted file]
projects/sgconv/Makefile [new file with mode: 0644]
projects/sgconv/build [new file with mode: 0755]
projects/sgconv/convertor.conf [new file with mode: 0644]
projects/sgconv/main.cpp [new file with mode: 0644]
projects/sgconv/settings_impl.cpp [new file with mode: 0644]
projects/sgconv/settings_impl.h [new file with mode: 0644]

diff --git a/projects/convertor/Makefile b/projects/convertor/Makefile
deleted file mode 100644 (file)
index 04c00cc..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-###############################################################################
-# $Id: Makefile,v 1.12 2009/03/03 15:49:34 faust Exp $
-###############################################################################
-
-include ../../Makefile.conf
-
-PROG = convertor
-
-SRCS = ./main.cpp \
-       ./settings_impl.cpp
-
-STGLIBS = dotconfpp \
-         conffiles \
-         logger \
-         crypto \
-          common
-
-STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS)))
-STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS)))
-
-LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD)
-
-ifeq ($(OS),linux)
-LIBS += -ldl
-else
-LIBS += -lc -liconv
-endif
-
-SEARCH_DIRS = -I ../../include
-
-OBJS = $(notdir $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRCS))))
-
-CXXFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
-CFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
-LDFLAGS += -Wl,-E $(STGLIBS_LIBS)
-
-.PHONY: all clean distclean libs plugins install uninstall
-all: libs plugins $(PROG) ../../Makefile.conf
-
-libs:
-       $(MAKE) -C $(DIR_LIBSRC)
-
-plugins: libs 
-       $(MAKE) -C $(DIR_PLUGINS)
-
-$(PROG): $(OBJS)
-       $(CXX) $^ $(LDFLAGS) $(LIBS) -o $(PROG)
-
-clean:
-       rm -f deps $(PROG) *.o tags *.*~ .OS
-       rm -f .OS
-       rm -f .store
-       rm -f .db.sql
-       rm -f core*
-       $(MAKE) -C $(DIR_LIBSRC) clean
-       $(MAKE) -C $(DIR_PLUGINS) clean
-
-distclean: clean
-       rm -f ../../Makefile.conf
-
-install: install-bin
-
-install-bin:
-ifeq ($(DEBUG), yes)
-       install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/bin/$(PROG)
-else
-       install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/bin/$(PROG)
-endif
-       $(MAKE) -C $(DIR_PLUGINS) install
-
-uninstall: uninstall-bin
-
-uninstall-bin:
-       rm -f $(PREFIX)/usr/bin/$(PROG)
-
-ifneq ($(MAKECMDGOALS),distclean)
-ifneq ($(MAKECMDGOALS),clean)
-ifneq ($(MAKECMDGOALS),uninstall)
--include deps
-endif
-endif
-endif
-
-deps:  $(SRCS) ../../Makefile.conf
-       $(MAKE) -C $(DIR_LIBSRC)
-       @>deps ;\
-       for file in $(SRCS); do\
-         echo "$$file" | grep ".c$$" > /dev/null;\
-         if [ $$? -eq 0 ];\
-         then\
-           echo "`$(CC) $(CFLAGS) -MM $$file` Makefile" >> deps ;\
-           printf '%b\n' '\t$$(CC) $(CFLAGS) -c $$<' >> deps ;\
-         else\
-           echo "`$(CXX) $(CXXFLAGS) -MM $$file` Makefile" >> deps ;\
-           printf '%b\n' '\t$$(CXX) $(CXXFLAGS) -c $$<' >> deps ;\
-         fi;\
-       done
diff --git a/projects/convertor/build b/projects/convertor/build
deleted file mode 100755 (executable)
index 471ee62..0000000
+++ /dev/null
@@ -1,291 +0,0 @@
-#!/bin/sh
-
-#   $Revision: 1.20 $
-#   $Author: faust $
-#   $Date: 2010/04/14 08:58:43 $
-######################################################
-
-OS=unknown
-sys=`uname -s`
-release=`uname -r | cut -b1`
-BUILD_DIR=`pwd`
-CONFFILE="../../Makefile.conf"
-PREFIX="/"
-BIN_MODE=0755
-DATA_MODE=0644
-DIR_MODE=0755
-OWNER=root
-VAR_DIR="./inst/var/stargazer"
-DEFS="-DDEBUG"
-MAKEOPTS="-j1"
-CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall -I/usr/local/include"
-LDFLAGS="$LDFLAGS -L/usr/local/lib"
-DEBUG="yes"
-
-if [ "$sys" = "Linux" ]
-then
-    OS=linux
-    release=""
-    MAKE="make"
-fi
-
-if [ "$sys" = "FreeBSD" ]
-then
-    case $release in
-        4) OS=bsd;;
-        5) OS=bsd5;;
-        6) OS=bsd5;;
-        7) OS=bsd7;;
-        8) OS=bsd7;;
-        9) OS=bsd7;;
-        *) OS=unknown;;
-    esac
-    MAKE="gmake"
-fi
-
-if [ "$OS" = "unknown" ]
-then 
-    echo "#############################################################################"
-    echo "# Sorry, but convertor currently supported by Linux, FreeBSD 4.x, 5.x, 6.x  #"
-    echo "#############################################################################"
-    exit 1
-fi
-
-echo "#############################################################################"
-echo "       Building convertor for $sys $release"
-echo "#############################################################################"
-
-STG_LIBS="logger.lib 
-          locker.lib
-         crypto.lib 
-         common.lib 
-         conffiles.lib
-         dotconfpp.lib"
-
-PLUGINS="store/files"
-
-if [ "$OS" = "linux" ]
-then
-    DEFS="$DEFS -DLINUX"
-    LIB_THREAD=-lpthread
-else
-    if [ "$OS" = "bsd" ]
-    then
-        DEFS="$DEFS -DFREE_BSD"
-        LIB_THREAD=-lc_r
-    else
-        DEFS="$DEFS -DFREE_BSD5"
-        if [ "$OS" = "bsd7" ]
-        then
-            LIB_THREAD=-lpthread
-        else
-            LIB_THREAD=-lc_r
-        fi
-    fi
-fi
-
-if [ -z "$CC" ]
-then
-    CC=gcc
-fi
-
-if [ -z "$CXX" ]
-then
-    CXX=g++
-fi
-
-echo -n "Checking CC... "
-$CC --version > /dev/null 2> /dev/null
-if [ $? != 0 ]
-then
-    echo "FAIL!"
-    echo "$CC not found"
-    exit;
-fi
-echo "found"
-echo -n "Checking CXX... "
-$CXX --version > /dev/null 2> /dev/null
-if [ $? != 0 ]
-then
-    echo "FAIL!"
-    echo "$CXX not found"
-    exit;
-fi
-echo "found"
-
-echo -n "Checking endianess... "
-echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
-$CC $CFLAGS $LDFLAGS -L/usr/lib/mysql -L/usr/local/lib/mysql build_check.c -o fake > /dev/null 2> /dev/null
-if [ $? != 0 ]
-then
-    echo "FAIL!"
-    echo "Endianess checking failed"
-    exit;
-else
-    ./fake
-    if [ $? = 1 ]
-    then
-        ARCH=le
-        CXXFLAGS="$CXXFLAGS -DARCH_LE"
-        CFLAGS="$CFLAGS -DARCH_LE"
-        echo "Little Endian"
-    else
-        ARCH=be
-        CXXFLAGS="$CXXFLAGS -DARCH_BE"
-        CFLAGS="$CFLAGS -DARCH_BE"
-        echo "Big Endian"
-    fi
-fi
-rm -f fake
-
-echo -n "Checking for -lfbclient... "
-$CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
-if [ $? != 0 ]
-then
-    CHECK_FBCLIENT=no
-    echo "no"
-else
-    CHECK_FBCLIENT=yes
-    echo "yes"
-fi
-rm -f fake
-
-echo -n "Checking for mysql_config... "
-MYSQL_VERSION=`mysql_config --version 2> /dev/null`
-if [ $? != 0 ]
-then
-    echo "no";
-    echo -n "Checking for -lmysqlclient... "
-    $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
-    if [ $? != 0 ]
-    then
-        CHECK_MYSQLCLIENT=no
-        echo "no"
-    else
-        CHECK_MYSQLCLIENT=yes
-        echo "yes"
-    fi
-    rm -f fake
-else
-    echo "yes"
-    echo -n "Checking for mysql_config --cflags... "
-    MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
-    if [ $? != 0 ]
-    then
-        CHECK_MYSQLCLIENT=no
-        echo "no"
-    else
-        echo "[$MYSQL_CFLAGS]"
-        echo -n "Checking for mysql_config --libs_r... "
-        MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
-        if [ $? != 0 ]
-        then
-            CHECK_MYSQLCLIENT=no
-            echo "no"
-        else
-            CHECK_MYSQLCLIENT=yes
-            echo "[$MYSQL_LDFLAGS]"
-        fi
-    fi
-fi
-
-echo -n "Checking for pg_config... "
-PG_VERSION=`pg_config --version 2> /dev/null`
-if [ $? != 0 ]
-then
-    echo "no";
-    echo -n "Checking for -lpq... "
-    $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
-    if [ $? != 0 ]
-    then
-        CHECK_PQ=no
-        echo "no"
-    else
-        CHECK_PQ=yes
-        echo "yes"
-    fi
-    rm -f fake
-else
-    echo "yes";
-    echo -n "Checking for pg_config --includedir... "
-    PG_CFLAGS=`pg_config --includedir 2> /dev/null`
-    if [ $? != 0 ]
-    then
-        CHECK_PQ=no
-        echo "no"
-    else
-        echo "[$PG_CFLAGS]"
-        echo -n "Checking for pg_config --libdir... "
-        PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
-        if [ $? != 0 ]
-        then
-            CHECK_PQ=no
-            echo "no"
-        else
-            CHECK_PQ=yes
-            echo "[$PG_LDFLAGS]"
-        fi
-    fi
-fi
-
-rm -f build_check.c
-
-if [ "$CHECK_FBCLIENT" = "yes" ]
-then
-    STG_LIBS="$STG_LIBS
-          ibpp.lib"
-    PLUGINS="$PLUGINS
-         store/firebird"
-fi
-
-if [ "$CHECK_PQ" = "yes" ]
-then
-    PLUGINS="$PLUGINS
-             store/postgresql"
-fi
-
-if [ "$CHECK_MYSQLCLIENT" = "yes" ]
-then
-    PLUGINS="$PLUGINS
-         store/mysql"
-fi
-
-echo "OS=$OS" > $CONFFILE
-echo "STG_TIME=yes" >> $CONFFILE
-echo "DEBUG=$DEBUG" >> $CONFFILE
-echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE
-echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE
-echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE
-echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE
-echo "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules" >> $CONFFILE
-echo "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins" >> $CONFFILE
-echo "ARCH=$ARCH" >> $CONFFILE
-echo "CHECK_FBCLIENT=$CHECK_FBCLIENT" >> $CONFFILE
-echo "DEFS=$DEFS" >> $CONFFILE
-echo -n "STG_LIBS=" >> $CONFFILE
-for lib in $STG_LIBS
-do
-    echo -n "$lib " >> $CONFFILE
-done
-echo "" >> $CONFFILE
-echo -n "PLUGINS=" >> $CONFFILE
-for plugin in $PLUGINS
-do
-    echo -n "$plugin " >> $CONFFILE
-done
-echo "" >> $CONFFILE
-echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
-echo "CFLAGS=$CFLAGS" >> $CONFFILE
-echo "LDFLAGS=$LDFLAGS" >> $CONFFILE
-echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
-echo "PREFIX=$PREFIX" >> $CONFFILE
-echo "BIN_MODE=$BIN_MODE" >> $CONFFILE
-echo "DATA_MODE=$DATA_MODE" >> $CONFFILE
-echo "DIR_MODE=$DIR_MODE" >> $CONFFILE
-echo "OWNER=$OWNER" >> $CONFFILE
-echo "VAR_DIR=$VAR_DIR" >> $CONFFILE
-
-mkdir -p ../stargazer/modules
-
-$MAKE $MAKEOPTS
-
diff --git a/projects/convertor/convertor.conf b/projects/convertor/convertor.conf
deleted file mode 100644 (file)
index 41e18b6..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-################################################################################
-#                   Stargazer Convertor Configuration file                     #
-################################################################################
-
-# The path to directory with server modules
-# Parameter: required
-# Value: directory path
-# Default: /usr/lib/stg
-ModulesPath = /usr/lib/stg
-
-#################################################################################
-Store module
-# Configure the module that works with the database server
-# Option - the name of the module without 'mod_' at the beginning and '.so'
-# in the end ie full name of the module mod_store_files.so
-<SourceStoreModule store_files>
-
-    # Working server directory, provides data on tariffs, users, administrators.
-    # Parameter: required
-    # Value: directory path
-    WorkDir = /var/stargazer
-
-    # Owner, group and permissions of the files of user statistics (stat)
-    # Parameter: required
-    # Values: any, supported by OS
-    ConfOwner = root
-    ConfGroup = root
-    ConfMode = 600
-
-    # Owner, group and permissions on user configuration files (conf)
-    # Parameter: required
-    # Values: any, supported by OS
-    StatOwner = root
-    StatGroup = root
-    StatMode = 640
-
-    # Owner, group and permissions for user log files (log)
-    # Parameter: required
-    # Values: any, supported by OS
-    UserLogOwner = root
-    UserLogGroup = root
-    UserLogMode = 640
-
-</SourceStoreModule>
-
-#<DestStoreModule store_firebird>
-    # Database server address
-    # Parameter: required
-    # Value: IP address or DNS name
-    # Default: localhost
-    # server = localhost
-
-    # Path to the database on the server or its alias
-    # Parameter: required
-    # Value: file path
-    # Default: /var/stg/stargazer.fdb
-    # database = /var/stg/stargazer.fdb
-
-    # Database username
-    # Parameter: required
-    # Value: any, supported by database
-    # Default: stg
-    # user = stg
-
-    # Database password
-    # Parameter: required
-    # Value: any, supported by database
-    # Default: 123456
-    # password = 123456
-#</DestStoreModule>
-
-<DestStoreModule store_postgresql>
-    # Database server address
-    # Parameter: required
-    # Value: IP address or DNS name
-    # Default: localhost
-    server = localhost
-
-    # Database name
-    # Parameter: required
-    # Value: any, supported by database
-    # Default: stargazer
-    database = stargazer
-
-    # Database username
-    # Parameter: mandatory
-    # Value: any, supported by database
-    # Default: stg
-    user = stg
-
-    # Database password
-    # Parameter: required
-    # Value: any, supported by database
-    # Default: 123456
-    password = 123456
-
-</DestStoreModule>
-
-#<DestStoreModule store_mysql>
-    # Database server address
-    # Parameter: required
-    # Value: IP address or DNS name
-    # Default: localhost
-    # dbhost = localhost
-
-    # Database name
-    # Parameter: required
-    # Value: any, supported by database
-    # Default: stg
-    # dbname = stg
-
-    # Database username
-    # Parameter: required
-    # Value: any, supported by database
-    # Default: stg
-    # dbuser = stg
-
-    # Database password
-    # Parameter: required
-    # Value: any, supported by database
-    # Default: 123456
-    # rootdbpass = 123456
-
-#</DestStoreModule>
diff --git a/projects/convertor/main.cpp b/projects/convertor/main.cpp
deleted file mode 100644 (file)
index e0679d0..0000000
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- *    This program is free software; you can redistribute it and/or modify
- *    it under the terms of the GNU General Public License as published by
- *    the Free Software Foundation; either version 2 of the License, or
- *    (at your option) any later version.
- *
- *    This program is distributed in the hope that it will be useful,
- *    but WITHOUT ANY WARRANTY; without even the implied warranty of
- *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *    GNU General Public License for more details.
- *
- *    You should have received a copy of the GNU General Public License
- *    along with this program; if not, write to the Free Software
- *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/*
- *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.11 $
- $Date: 2010/03/25 12:32:30 $
- $Author: faust $
- */
-
-#include <dlfcn.h>
-
-#include <string>
-#include <vector>
-#include <iostream>
-#include <ctime>
-#include <algorithm>
-
-#include "stg/common.h"
-#include "stg/store.h"
-#include "stg/conffiles.h"
-
-#include "stg/user_stat.h"
-#include "stg/user_conf.h"
-#include "stg/corp_conf.h"
-#include "stg/service_conf.h"
-#include "stg/admin_conf.h"
-#include "stg/tariff_conf.h"
-#include "stg/settings.h"
-#include "stg/message.h"
-
-#include "settings_impl.h"
-
-using namespace std;
-
-volatile time_t stgTime = time(NULL);
-
-int main(int argc, char **argv)
-{
-printfd(__FILE__, "Start\n");
-
-STORE * fromStore = NULL;
-STORE * toStore = NULL;
-
-SETTINGS_IMPL * settings = NULL;
-
-string modulePath;
-
-MODULE_SETTINGS fromStoreSettings;
-MODULE_SETTINGS toStoreSettings;
-
-ADMIN_CONF ac;
-USER_CONF uc;
-USER_STAT us;
-STG_MSG msg;
-TARIFF_DATA td;
-CORP_CONF cc;
-SERVICE_CONF sc;
-vector<STG_MSG_HDR> hdrs;
-
-if (argc == 2)
-    settings = new SETTINGS_IMPL(argv[1]);
-else
-    settings = new SETTINGS_IMPL();
-
-if (settings->ReadSettings())
-    {
-    printfd(__FILE__, "Error reading settings\n");
-    delete settings;
-    return -1;
-    }
-
-fromStoreSettings = settings->GetSourceStoreModuleSettings();
-toStoreSettings = settings->GetDestStoreModuleSettings();
-modulePath = settings->GetModulesPath();
-
-string sourcePlugin(modulePath + "/mod_" + fromStoreSettings.moduleName + ".so");
-string destPlugin(modulePath + "/mod_" + toStoreSettings.moduleName + ".so");
-
-void * src_lh = dlopen(sourcePlugin.c_str(), RTLD_NOW);
-if (!src_lh)
-    {
-    printfd(__FILE__, "Source storage plugin loading failed: %s\n", dlerror());
-    delete settings;
-    return -1;
-    }
-
-void * dst_lh = dlopen(destPlugin.c_str(), RTLD_NOW);
-if (!dst_lh)
-    {
-    printfd(__FILE__, "Destination storage plugin loading failed: %s\n", dlerror());
-    delete settings;
-    return -1;
-    }
-
-STORE * (*GetSourceStore)();
-STORE * (*GetDestStore)();
-GetSourceStore = (STORE * (*)())dlsym(src_lh, "GetStore");
-if (!GetSourceStore)
-    {
-    printfd(__FILE__, "Source storage plugin loading failed. GetStore not found: %s\n", dlerror());
-    delete settings;
-    return -1;
-    }
-GetDestStore = (STORE * (*)())dlsym(dst_lh, "GetStore");
-if (!GetDestStore)
-    {
-    printfd(__FILE__, "Storage plugin (firebird) loading failed. GetStore not found: %s\n", dlerror());
-    delete settings;
-    return -1;
-    }
-
-fromStore = GetSourceStore();
-toStore = GetDestStore();
-
-vector<string> entities;
-vector<string> ready;
-fromStore->SetSettings(fromStoreSettings);
-fromStore->ParseSettings();
-toStore->SetSettings(toStoreSettings);
-toStore->ParseSettings();
-
-printfd(__FILE__, "Importing admins:\n");
-entities.erase(entities.begin(), entities.end());
-ready.erase(ready.begin(), ready.end());
-if (fromStore->GetAdminsList(&entities))
-    {
-    printfd(__FILE__, "Error getting admins list: %s\n", fromStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-if (toStore->GetAdminsList(&ready))
-    {
-    printfd(__FILE__, "Error getting admins list: %s\n", toStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-
-vector<string>::const_iterator it;
-for (it = entities.begin(); it != entities.end(); ++it)
-    {
-    printfd(__FILE__, "\t - %s\n", it->c_str());
-    if (find(ready.begin(), ready.end(), *it) == ready.end())
-        if (toStore->AddAdmin(*it))
-            {
-            printfd(__FILE__, "Error adding admin: %s\n", toStore->GetStrError().c_str());
-            dlclose(src_lh);
-            dlclose(dst_lh);
-            delete settings;
-            return -1;
-            }
-    if (fromStore->RestoreAdmin(&ac, *it))
-        {
-        printfd(__FILE__, "Error getting admin's confi: %s\n", fromStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    ac.login = *it;
-    if (toStore->SaveAdmin(ac))
-        {
-        printfd(__FILE__, "Error saving admin's conf: %s\n", toStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    }
-
-printfd(__FILE__, "Importing tariffs:\n");
-entities.erase(entities.begin(), entities.end());
-ready.erase(ready.begin(), ready.end());
-if (fromStore->GetTariffsList(&entities))
-    {
-    printfd(__FILE__, "Error getting tariffs list: %s\n", fromStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-if (toStore->GetTariffsList(&ready))
-    {
-    printfd(__FILE__, "Error getting tariffs list: %s\n", toStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-
-for (it = entities.begin(); it != entities.end(); ++it)
-    {
-    printfd(__FILE__, "\t - %s\n", it->c_str());
-    if (find(ready.begin(), ready.end(), *it) == ready.end())
-        if (toStore->AddTariff(*it))
-            {
-            printfd(__FILE__, "Error adding tariff: %s\n", toStore->GetStrError().c_str());
-            dlclose(src_lh);
-            dlclose(dst_lh);
-            delete settings;
-            return -1;
-            }
-    if (fromStore->RestoreTariff(&td, *it))
-        {
-        printfd(__FILE__, "Error getting tariff's data: %s\n", fromStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    if (toStore->SaveTariff(td, *it))
-        {
-        printfd(__FILE__, "Error saving tariff's data: %s\n", toStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    }
-
-printfd(__FILE__, "Importing services:\n");
-entities.erase(entities.begin(), entities.end());
-ready.erase(ready.begin(), ready.end());
-if (fromStore->GetServicesList(&entities))
-    {
-    printfd(__FILE__, "Error getting service list: %s\n", fromStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-if (toStore->GetServicesList(&ready))
-    {
-    printfd(__FILE__, "Error getting service list: %s\n", toStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-
-for (it = entities.begin(); it != entities.end(); ++it)
-    {
-    printfd(__FILE__, "\t - %s\n", it->c_str());
-    if (find(ready.begin(), ready.end(), *it) == ready.end())
-        if (toStore->AddService(*it))
-            {
-            printfd(__FILE__, "Error adding service: %s\n", toStore->GetStrError().c_str());
-            dlclose(src_lh);
-            dlclose(dst_lh);
-            delete settings;
-            return -1;
-            }
-    if (fromStore->RestoreService(&sc, *it))
-        {
-        printfd(__FILE__, "Error getting service's data: %s\n", fromStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    if (toStore->SaveService(sc))
-        {
-        printfd(__FILE__, "Error saving service's data: %s\n", toStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    }
-
-printfd(__FILE__, "Importing corporations:\n");
-entities.erase(entities.begin(), entities.end());
-ready.erase(ready.begin(), ready.end());
-if (fromStore->GetCorpsList(&entities))
-    {
-    printfd(__FILE__, "Error getting corporations list: %s\n", fromStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-if (toStore->GetCorpsList(&ready))
-    {
-    printfd(__FILE__, "Error getting corporations list: %s\n", toStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-
-for (it = entities.begin(); it != entities.end(); ++it)
-    {
-    printfd(__FILE__, "\t - %s\n", it->c_str());
-    if (find(ready.begin(), ready.end(), *it) == ready.end())
-        if (toStore->AddCorp(*it))
-            {
-            printfd(__FILE__, "Error adding corporation: %s\n", toStore->GetStrError().c_str());
-            dlclose(src_lh);
-            dlclose(dst_lh);
-            delete settings;
-            return -1;
-            }
-    if (fromStore->RestoreCorp(&cc, *it))
-        {
-        printfd(__FILE__, "Error getting corporation's data: %s\n", fromStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    if (toStore->SaveCorp(cc))
-        {
-        printfd(__FILE__, "Error saving corporation's data: %s\n", toStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    }
-
-printfd(__FILE__, "Importing users:\n");
-entities.erase(entities.begin(), entities.end());
-ready.erase(ready.begin(), ready.end());
-if (fromStore->GetUsersList(&entities))
-    {
-    printfd(__FILE__, "Error getting users list: %s\n", fromStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-if (toStore->GetUsersList(&ready))
-    {
-    printfd(__FILE__, "Error getting users list: %s\n", toStore->GetStrError().c_str());
-    dlclose(src_lh);
-    dlclose(dst_lh);
-    delete settings;
-    return -1;
-    }
-
-sort(ready.begin(), ready.end());
-for (it = entities.begin(); it != entities.end(); ++it)
-    {
-    printfd(__FILE__, "\t - %s\n", it->c_str());
-    if (!binary_search(ready.begin(), ready.end(), *it)) {
-        if (toStore->AddUser(*it))
-            {
-            printfd(__FILE__, "Error adding user: %s\n", toStore->GetStrError().c_str());
-            dlclose(src_lh);
-            dlclose(dst_lh);
-            delete settings;
-            return -1;
-            }
-    } else {
-        printfd(__FILE__, "\t\t(adding passed)\n");
-    }
-    if (fromStore->RestoreUserConf(&uc, *it))
-        {
-        printfd(__FILE__, "Error getting user's conf: %s\n", fromStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    if (fromStore->RestoreUserStat(&us, *it))
-        {
-        printfd(__FILE__, "Error getting user's stat: %s\n", fromStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    if (toStore->SaveUserConf(uc, *it))
-        {
-        printfd(__FILE__, "Error saving user's conf: %s\n", toStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    if (toStore->SaveUserStat(us, *it))
-        {
-        printfd(__FILE__, "Error saving user's stat: %s\n", toStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    hdrs.erase(hdrs.begin(), hdrs.end());
-    if (fromStore->GetMessageHdrs(&hdrs, *it))
-        {
-        printfd(__FILE__, "Error getting user's messages: %s\n", fromStore->GetStrError().c_str());
-        dlclose(src_lh);
-        dlclose(dst_lh);
-        delete settings;
-        return -1;
-        }
-    vector<STG_MSG_HDR>::iterator mit;
-    for (mit = hdrs.begin(); mit != hdrs.end(); ++mit)
-        {
-        if (fromStore->GetMessage(mit->id, &msg, *it))
-            {
-            printfd(__FILE__, "Error getting message for a user: %s\n", fromStore->GetStrError().c_str());
-            dlclose(src_lh);
-            dlclose(dst_lh);
-            delete settings;
-            return -1;
-            }
-        printfd(__FILE__, "\t\t * %s\n", msg.text.c_str());
-        if (toStore->AddMessage(&msg, *it))
-            {
-            printfd(__FILE__, "Error adding message to a user: %s\n", toStore->GetStrError().c_str());
-            dlclose(src_lh);
-            dlclose(dst_lh);
-            delete settings;
-            return -1;
-            }
-        }
-    }
-
-dlclose(src_lh);
-dlclose(dst_lh);
-printfd(__FILE__, "Done\n");
-delete settings;
-return 0;
-}
diff --git a/projects/convertor/settings_impl.cpp b/projects/convertor/settings_impl.cpp
deleted file mode 100644 (file)
index 645865c..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- *    This program is free software; you can redistribute it and/or modify
- *    it under the terms of the GNU General Public License as published by
- *    the Free Software Foundation; either version 2 of the License, or
- *    (at your option) any later version.
- *
- *    This program is distributed in the hope that it will be useful,
- *    but WITHOUT ANY WARRANTY; without even the implied warranty of
- *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *    GNU General Public License for more details.
- *
- *    You should have received a copy of the GNU General Public License
- *    along with this program; if not, write to the Free Software
- *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/*
- *    Date: 27.10.2002
- */
-
-/*
- *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
-/*
-$Revision: 1.6 $
-$Date: 2009/06/22 16:26:54 $
-*/
-
-#include "stg/dotconfpp.h"
-#include "stg/module_settings.h"
-#include "stg/common.h"
-
-#include "settings_impl.h"
-
-int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector<PARAM_VALUE> * params)
-{
-if (!node)
-    return 0;
-
-PARAM_VALUE pv;
-
-pv.param = node->getName();
-
-if (node->getValue(1))
-    {
-    strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'.";
-    printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
-    return -1;
-    }
-
-const char * value = node->getValue(0);
-
-if (!value)
-    {
-    strError = "Module name expected.";
-    printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
-    return -1;
-    }
-
-const DOTCONFDocumentNode * childNode = node->getChildNode();
-while (childNode)
-    {
-    pv.param = childNode->getName();
-    int i = 0;
-    while ((value = childNode->getValue(i)) != NULL)
-        {
-        pv.value.push_back(value);
-        ++i;
-        }
-    params->push_back(pv);
-    pv.value.clear();
-    childNode = childNode->getNextNode();
-    }
-
-return 0;
-}
-//-----------------------------------------------------------------------------
-int SETTINGS_IMPL::ReadSettings()
-{
-const char * requiredOptions[] = {
-    "ModulesPath",
-    "SourceStoreModule",
-    "DestStoreModule",
-    NULL
-    };
-int sourceStoreModulesCount = 0;
-int destStoreModulesCount = 0;
-
-DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE);
-conf.setRequiredOptionNames(requiredOptions);
-
-if(conf.setContent(confFile.c_str()) != 0)
-    {
-    strError = "Cannot read file " + confFile + ".";
-    printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
-    return -1;
-    }
-
-const DOTCONFDocumentNode * node = conf.getFirstNode();
-
-while (node)
-    {
-    if (strcasecmp(node->getName(), "ModulesPath") == 0)
-        {
-        modulesPath = node->getValue(0);
-        }
-
-    if (strcasecmp(node->getName(), "SourceStoreModule") == 0)
-        {
-        if (node->getValue(1))
-            {
-            strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
-            printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
-            return -1;
-            }
-
-        if (sourceStoreModulesCount)
-            {
-            strError = "Should be only one source StoreModule.";
-            printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
-            return -1;
-            }
-        ++sourceStoreModulesCount;
-
-        sourceStoreModuleSettings.moduleName = node->getValue(0);
-        ParseModuleSettings(node, &sourceStoreModuleSettings.moduleParams);
-        }
-
-    if (strcasecmp(node->getName(), "DestStoreModule") == 0)
-        {
-        if (node->getValue(1))
-            {
-            strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
-            printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
-            return -1;
-            }
-
-        if (destStoreModulesCount)
-            {
-            strError = "Should be only one dest StoreModule.";
-            printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
-            return -1;
-            }
-        ++destStoreModulesCount;
-
-        destStoreModuleSettings.moduleName = node->getValue(0);
-        ParseModuleSettings(node, &destStoreModuleSettings.moduleParams);
-        }
-
-    node = node->getNextNode();
-    }
-
-return 0;
-}
-//-----------------------------------------------------------------------------
diff --git a/projects/convertor/settings_impl.h b/projects/convertor/settings_impl.h
deleted file mode 100644 (file)
index eec21d6..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
- /*
- $Revision: 1.6 $
- $Date: 2009/06/22 16:26:54 $
- */
-
-/*
- *    This program is free software; you can redistribute it and/or modify
- *    it under the terms of the GNU General Public License as published by
- *    the Free Software Foundation; either version 2 of the License, or
- *    (at your option) any later version.
- *
- *    This program is distributed in the hope that it will be useful,
- *    but WITHOUT ANY WARRANTY; without even the implied warranty of
- *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *    GNU General Public License for more details.
- *
- *    You should have received a copy of the GNU General Public License
- *    along with this program; if not, write to the Free Software
- *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/*
- *    Date: 27.10.2002
- */
-
-/*
- *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
-#ifndef SETTINGS_IMPL_H
-#define SETTINGS_IMPL_H
-
-#include <string>
-#include <vector>
-
-struct MODULE_SETTINGS;
-class DOTCONFDocumentNode;
-
-class SETTINGS_IMPL {
-public:
-    SETTINGS_IMPL() : confFile("./convertor.conf") {}
-    SETTINGS_IMPL(const std::string & cf) : confFile(cf) {}
-    ~SETTINGS_IMPL() {}
-    int ReadSettings();
-
-    std::string GetStrError() const { return strError; }
-
-    const std::string & GetConfDir() const;
-
-    const std::string & GetModulesPath() const { return modulesPath; }
-    const MODULE_SETTINGS & GetSourceStoreModuleSettings() const { return sourceStoreModuleSettings; }
-    const MODULE_SETTINGS & GetDestStoreModuleSettings() const { return destStoreModuleSettings; }
-
-private:
-    int ParseModuleSettings(const DOTCONFDocumentNode * dirNameNode, std::vector<PARAM_VALUE> * params);
-
-    std::string strError;
-    std::string modulesPath;
-    std::string confFile;
-
-    MODULE_SETTINGS sourceStoreModuleSettings;
-    MODULE_SETTINGS destStoreModuleSettings;
-};
-
-#endif
diff --git a/projects/sgconv/Makefile b/projects/sgconv/Makefile
new file mode 100644 (file)
index 0000000..04c00cc
--- /dev/null
@@ -0,0 +1,97 @@
+###############################################################################
+# $Id: Makefile,v 1.12 2009/03/03 15:49:34 faust Exp $
+###############################################################################
+
+include ../../Makefile.conf
+
+PROG = convertor
+
+SRCS = ./main.cpp \
+       ./settings_impl.cpp
+
+STGLIBS = dotconfpp \
+         conffiles \
+         logger \
+         crypto \
+          common
+
+STGLIBS_INCS = $(addprefix -I ../../stglibs/,$(addsuffix .lib/include,$(STGLIBS)))
+STGLIBS_LIBS = $(addprefix -L ../../stglibs/,$(addsuffix .lib,$(STGLIBS)))
+
+LIBS += $(addprefix -lstg,$(STGLIBS)) $(LIB_THREAD)
+
+ifeq ($(OS),linux)
+LIBS += -ldl
+else
+LIBS += -lc -liconv
+endif
+
+SEARCH_DIRS = -I ../../include
+
+OBJS = $(notdir $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(SRCS))))
+
+CXXFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
+CFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
+LDFLAGS += -Wl,-E $(STGLIBS_LIBS)
+
+.PHONY: all clean distclean libs plugins install uninstall
+all: libs plugins $(PROG) ../../Makefile.conf
+
+libs:
+       $(MAKE) -C $(DIR_LIBSRC)
+
+plugins: libs 
+       $(MAKE) -C $(DIR_PLUGINS)
+
+$(PROG): $(OBJS)
+       $(CXX) $^ $(LDFLAGS) $(LIBS) -o $(PROG)
+
+clean:
+       rm -f deps $(PROG) *.o tags *.*~ .OS
+       rm -f .OS
+       rm -f .store
+       rm -f .db.sql
+       rm -f core*
+       $(MAKE) -C $(DIR_LIBSRC) clean
+       $(MAKE) -C $(DIR_PLUGINS) clean
+
+distclean: clean
+       rm -f ../../Makefile.conf
+
+install: install-bin
+
+install-bin:
+ifeq ($(DEBUG), yes)
+       install -D -m $(BIN_MODE) -o $(OWNER) $(PROG) $(PREFIX)/usr/bin/$(PROG)
+else
+       install -D -m $(BIN_MODE) -o $(OWNER) -s $(PROG) $(PREFIX)/usr/bin/$(PROG)
+endif
+       $(MAKE) -C $(DIR_PLUGINS) install
+
+uninstall: uninstall-bin
+
+uninstall-bin:
+       rm -f $(PREFIX)/usr/bin/$(PROG)
+
+ifneq ($(MAKECMDGOALS),distclean)
+ifneq ($(MAKECMDGOALS),clean)
+ifneq ($(MAKECMDGOALS),uninstall)
+-include deps
+endif
+endif
+endif
+
+deps:  $(SRCS) ../../Makefile.conf
+       $(MAKE) -C $(DIR_LIBSRC)
+       @>deps ;\
+       for file in $(SRCS); do\
+         echo "$$file" | grep ".c$$" > /dev/null;\
+         if [ $$? -eq 0 ];\
+         then\
+           echo "`$(CC) $(CFLAGS) -MM $$file` Makefile" >> deps ;\
+           printf '%b\n' '\t$$(CC) $(CFLAGS) -c $$<' >> deps ;\
+         else\
+           echo "`$(CXX) $(CXXFLAGS) -MM $$file` Makefile" >> deps ;\
+           printf '%b\n' '\t$$(CXX) $(CXXFLAGS) -c $$<' >> deps ;\
+         fi;\
+       done
diff --git a/projects/sgconv/build b/projects/sgconv/build
new file mode 100755 (executable)
index 0000000..471ee62
--- /dev/null
@@ -0,0 +1,291 @@
+#!/bin/sh
+
+#   $Revision: 1.20 $
+#   $Author: faust $
+#   $Date: 2010/04/14 08:58:43 $
+######################################################
+
+OS=unknown
+sys=`uname -s`
+release=`uname -r | cut -b1`
+BUILD_DIR=`pwd`
+CONFFILE="../../Makefile.conf"
+PREFIX="/"
+BIN_MODE=0755
+DATA_MODE=0644
+DIR_MODE=0755
+OWNER=root
+VAR_DIR="./inst/var/stargazer"
+DEFS="-DDEBUG"
+MAKEOPTS="-j1"
+CXXFLAGS="$CXXFLAGS -ggdb3 -W -Wall -I/usr/local/include"
+LDFLAGS="$LDFLAGS -L/usr/local/lib"
+DEBUG="yes"
+
+if [ "$sys" = "Linux" ]
+then
+    OS=linux
+    release=""
+    MAKE="make"
+fi
+
+if [ "$sys" = "FreeBSD" ]
+then
+    case $release in
+        4) OS=bsd;;
+        5) OS=bsd5;;
+        6) OS=bsd5;;
+        7) OS=bsd7;;
+        8) OS=bsd7;;
+        9) OS=bsd7;;
+        *) OS=unknown;;
+    esac
+    MAKE="gmake"
+fi
+
+if [ "$OS" = "unknown" ]
+then 
+    echo "#############################################################################"
+    echo "# Sorry, but convertor currently supported by Linux, FreeBSD 4.x, 5.x, 6.x  #"
+    echo "#############################################################################"
+    exit 1
+fi
+
+echo "#############################################################################"
+echo "       Building convertor for $sys $release"
+echo "#############################################################################"
+
+STG_LIBS="logger.lib 
+          locker.lib
+         crypto.lib 
+         common.lib 
+         conffiles.lib
+         dotconfpp.lib"
+
+PLUGINS="store/files"
+
+if [ "$OS" = "linux" ]
+then
+    DEFS="$DEFS -DLINUX"
+    LIB_THREAD=-lpthread
+else
+    if [ "$OS" = "bsd" ]
+    then
+        DEFS="$DEFS -DFREE_BSD"
+        LIB_THREAD=-lc_r
+    else
+        DEFS="$DEFS -DFREE_BSD5"
+        if [ "$OS" = "bsd7" ]
+        then
+            LIB_THREAD=-lpthread
+        else
+            LIB_THREAD=-lc_r
+        fi
+    fi
+fi
+
+if [ -z "$CC" ]
+then
+    CC=gcc
+fi
+
+if [ -z "$CXX" ]
+then
+    CXX=g++
+fi
+
+echo -n "Checking CC... "
+$CC --version > /dev/null 2> /dev/null
+if [ $? != 0 ]
+then
+    echo "FAIL!"
+    echo "$CC not found"
+    exit;
+fi
+echo "found"
+echo -n "Checking CXX... "
+$CXX --version > /dev/null 2> /dev/null
+if [ $? != 0 ]
+then
+    echo "FAIL!"
+    echo "$CXX not found"
+    exit;
+fi
+echo "found"
+
+echo -n "Checking endianess... "
+echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
+$CC $CFLAGS $LDFLAGS -L/usr/lib/mysql -L/usr/local/lib/mysql build_check.c -o fake > /dev/null 2> /dev/null
+if [ $? != 0 ]
+then
+    echo "FAIL!"
+    echo "Endianess checking failed"
+    exit;
+else
+    ./fake
+    if [ $? = 1 ]
+    then
+        ARCH=le
+        CXXFLAGS="$CXXFLAGS -DARCH_LE"
+        CFLAGS="$CFLAGS -DARCH_LE"
+        echo "Little Endian"
+    else
+        ARCH=be
+        CXXFLAGS="$CXXFLAGS -DARCH_BE"
+        CFLAGS="$CFLAGS -DARCH_BE"
+        echo "Big Endian"
+    fi
+fi
+rm -f fake
+
+echo -n "Checking for -lfbclient... "
+$CC $CFLAGS $LDFLAGS build_check.c -lfbclient $LIB_THREAD -o fake > /dev/null 2> /dev/null
+if [ $? != 0 ]
+then
+    CHECK_FBCLIENT=no
+    echo "no"
+else
+    CHECK_FBCLIENT=yes
+    echo "yes"
+fi
+rm -f fake
+
+echo -n "Checking for mysql_config... "
+MYSQL_VERSION=`mysql_config --version 2> /dev/null`
+if [ $? != 0 ]
+then
+    echo "no";
+    echo -n "Checking for -lmysqlclient... "
+    $CC $CFLAGS $LDFLAGS build_check.c -lmysqlclient_r $LIB_THREAD -o fake > /dev/null 2> /dev/null
+    if [ $? != 0 ]
+    then
+        CHECK_MYSQLCLIENT=no
+        echo "no"
+    else
+        CHECK_MYSQLCLIENT=yes
+        echo "yes"
+    fi
+    rm -f fake
+else
+    echo "yes"
+    echo -n "Checking for mysql_config --cflags... "
+    MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
+    if [ $? != 0 ]
+    then
+        CHECK_MYSQLCLIENT=no
+        echo "no"
+    else
+        echo "[$MYSQL_CFLAGS]"
+        echo -n "Checking for mysql_config --libs_r... "
+        MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
+        if [ $? != 0 ]
+        then
+            CHECK_MYSQLCLIENT=no
+            echo "no"
+        else
+            CHECK_MYSQLCLIENT=yes
+            echo "[$MYSQL_LDFLAGS]"
+        fi
+    fi
+fi
+
+echo -n "Checking for pg_config... "
+PG_VERSION=`pg_config --version 2> /dev/null`
+if [ $? != 0 ]
+then
+    echo "no";
+    echo -n "Checking for -lpq... "
+    $CC $CFLAGS $LDFLAGS build_check.c -lpq $LIB_THREAD -o fake > /dev/null 2> /dev/null
+    if [ $? != 0 ]
+    then
+        CHECK_PQ=no
+        echo "no"
+    else
+        CHECK_PQ=yes
+        echo "yes"
+    fi
+    rm -f fake
+else
+    echo "yes";
+    echo -n "Checking for pg_config --includedir... "
+    PG_CFLAGS=`pg_config --includedir 2> /dev/null`
+    if [ $? != 0 ]
+    then
+        CHECK_PQ=no
+        echo "no"
+    else
+        echo "[$PG_CFLAGS]"
+        echo -n "Checking for pg_config --libdir... "
+        PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
+        if [ $? != 0 ]
+        then
+            CHECK_PQ=no
+            echo "no"
+        else
+            CHECK_PQ=yes
+            echo "[$PG_LDFLAGS]"
+        fi
+    fi
+fi
+
+rm -f build_check.c
+
+if [ "$CHECK_FBCLIENT" = "yes" ]
+then
+    STG_LIBS="$STG_LIBS
+          ibpp.lib"
+    PLUGINS="$PLUGINS
+         store/firebird"
+fi
+
+if [ "$CHECK_PQ" = "yes" ]
+then
+    PLUGINS="$PLUGINS
+             store/postgresql"
+fi
+
+if [ "$CHECK_MYSQLCLIENT" = "yes" ]
+then
+    PLUGINS="$PLUGINS
+         store/mysql"
+fi
+
+echo "OS=$OS" > $CONFFILE
+echo "STG_TIME=yes" >> $CONFFILE
+echo "DEBUG=$DEBUG" >> $CONFFILE
+echo "DIR_BUILD=$BUILD_DIR" >> $CONFFILE
+echo "DIR_LIB=\$(DIR_BUILD)/../../lib" >> $CONFFILE
+echo "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs" >> $CONFFILE
+echo "DIR_INCLUDE=\$(DIR_BUILD)/../../include" >> $CONFFILE
+echo "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules" >> $CONFFILE
+echo "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins" >> $CONFFILE
+echo "ARCH=$ARCH" >> $CONFFILE
+echo "CHECK_FBCLIENT=$CHECK_FBCLIENT" >> $CONFFILE
+echo "DEFS=$DEFS" >> $CONFFILE
+echo -n "STG_LIBS=" >> $CONFFILE
+for lib in $STG_LIBS
+do
+    echo -n "$lib " >> $CONFFILE
+done
+echo "" >> $CONFFILE
+echo -n "PLUGINS=" >> $CONFFILE
+for plugin in $PLUGINS
+do
+    echo -n "$plugin " >> $CONFFILE
+done
+echo "" >> $CONFFILE
+echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
+echo "CFLAGS=$CFLAGS" >> $CONFFILE
+echo "LDFLAGS=$LDFLAGS" >> $CONFFILE
+echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
+echo "PREFIX=$PREFIX" >> $CONFFILE
+echo "BIN_MODE=$BIN_MODE" >> $CONFFILE
+echo "DATA_MODE=$DATA_MODE" >> $CONFFILE
+echo "DIR_MODE=$DIR_MODE" >> $CONFFILE
+echo "OWNER=$OWNER" >> $CONFFILE
+echo "VAR_DIR=$VAR_DIR" >> $CONFFILE
+
+mkdir -p ../stargazer/modules
+
+$MAKE $MAKEOPTS
+
diff --git a/projects/sgconv/convertor.conf b/projects/sgconv/convertor.conf
new file mode 100644 (file)
index 0000000..41e18b6
--- /dev/null
@@ -0,0 +1,124 @@
+################################################################################
+#                   Stargazer Convertor Configuration file                     #
+################################################################################
+
+# The path to directory with server modules
+# Parameter: required
+# Value: directory path
+# Default: /usr/lib/stg
+ModulesPath = /usr/lib/stg
+
+#################################################################################
+Store module
+# Configure the module that works with the database server
+# Option - the name of the module without 'mod_' at the beginning and '.so'
+# in the end ie full name of the module mod_store_files.so
+<SourceStoreModule store_files>
+
+    # Working server directory, provides data on tariffs, users, administrators.
+    # Parameter: required
+    # Value: directory path
+    WorkDir = /var/stargazer
+
+    # Owner, group and permissions of the files of user statistics (stat)
+    # Parameter: required
+    # Values: any, supported by OS
+    ConfOwner = root
+    ConfGroup = root
+    ConfMode = 600
+
+    # Owner, group and permissions on user configuration files (conf)
+    # Parameter: required
+    # Values: any, supported by OS
+    StatOwner = root
+    StatGroup = root
+    StatMode = 640
+
+    # Owner, group and permissions for user log files (log)
+    # Parameter: required
+    # Values: any, supported by OS
+    UserLogOwner = root
+    UserLogGroup = root
+    UserLogMode = 640
+
+</SourceStoreModule>
+
+#<DestStoreModule store_firebird>
+    # Database server address
+    # Parameter: required
+    # Value: IP address or DNS name
+    # Default: localhost
+    # server = localhost
+
+    # Path to the database on the server or its alias
+    # Parameter: required
+    # Value: file path
+    # Default: /var/stg/stargazer.fdb
+    # database = /var/stg/stargazer.fdb
+
+    # Database username
+    # Parameter: required
+    # Value: any, supported by database
+    # Default: stg
+    # user = stg
+
+    # Database password
+    # Parameter: required
+    # Value: any, supported by database
+    # Default: 123456
+    # password = 123456
+#</DestStoreModule>
+
+<DestStoreModule store_postgresql>
+    # Database server address
+    # Parameter: required
+    # Value: IP address or DNS name
+    # Default: localhost
+    server = localhost
+
+    # Database name
+    # Parameter: required
+    # Value: any, supported by database
+    # Default: stargazer
+    database = stargazer
+
+    # Database username
+    # Parameter: mandatory
+    # Value: any, supported by database
+    # Default: stg
+    user = stg
+
+    # Database password
+    # Parameter: required
+    # Value: any, supported by database
+    # Default: 123456
+    password = 123456
+
+</DestStoreModule>
+
+#<DestStoreModule store_mysql>
+    # Database server address
+    # Parameter: required
+    # Value: IP address or DNS name
+    # Default: localhost
+    # dbhost = localhost
+
+    # Database name
+    # Parameter: required
+    # Value: any, supported by database
+    # Default: stg
+    # dbname = stg
+
+    # Database username
+    # Parameter: required
+    # Value: any, supported by database
+    # Default: stg
+    # dbuser = stg
+
+    # Database password
+    # Parameter: required
+    # Value: any, supported by database
+    # Default: 123456
+    # rootdbpass = 123456
+
+#</DestStoreModule>
diff --git a/projects/sgconv/main.cpp b/projects/sgconv/main.cpp
new file mode 100644 (file)
index 0000000..e0679d0
--- /dev/null
@@ -0,0 +1,446 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+ /*
+ $Revision: 1.11 $
+ $Date: 2010/03/25 12:32:30 $
+ $Author: faust $
+ */
+
+#include <dlfcn.h>
+
+#include <string>
+#include <vector>
+#include <iostream>
+#include <ctime>
+#include <algorithm>
+
+#include "stg/common.h"
+#include "stg/store.h"
+#include "stg/conffiles.h"
+
+#include "stg/user_stat.h"
+#include "stg/user_conf.h"
+#include "stg/corp_conf.h"
+#include "stg/service_conf.h"
+#include "stg/admin_conf.h"
+#include "stg/tariff_conf.h"
+#include "stg/settings.h"
+#include "stg/message.h"
+
+#include "settings_impl.h"
+
+using namespace std;
+
+volatile time_t stgTime = time(NULL);
+
+int main(int argc, char **argv)
+{
+printfd(__FILE__, "Start\n");
+
+STORE * fromStore = NULL;
+STORE * toStore = NULL;
+
+SETTINGS_IMPL * settings = NULL;
+
+string modulePath;
+
+MODULE_SETTINGS fromStoreSettings;
+MODULE_SETTINGS toStoreSettings;
+
+ADMIN_CONF ac;
+USER_CONF uc;
+USER_STAT us;
+STG_MSG msg;
+TARIFF_DATA td;
+CORP_CONF cc;
+SERVICE_CONF sc;
+vector<STG_MSG_HDR> hdrs;
+
+if (argc == 2)
+    settings = new SETTINGS_IMPL(argv[1]);
+else
+    settings = new SETTINGS_IMPL();
+
+if (settings->ReadSettings())
+    {
+    printfd(__FILE__, "Error reading settings\n");
+    delete settings;
+    return -1;
+    }
+
+fromStoreSettings = settings->GetSourceStoreModuleSettings();
+toStoreSettings = settings->GetDestStoreModuleSettings();
+modulePath = settings->GetModulesPath();
+
+string sourcePlugin(modulePath + "/mod_" + fromStoreSettings.moduleName + ".so");
+string destPlugin(modulePath + "/mod_" + toStoreSettings.moduleName + ".so");
+
+void * src_lh = dlopen(sourcePlugin.c_str(), RTLD_NOW);
+if (!src_lh)
+    {
+    printfd(__FILE__, "Source storage plugin loading failed: %s\n", dlerror());
+    delete settings;
+    return -1;
+    }
+
+void * dst_lh = dlopen(destPlugin.c_str(), RTLD_NOW);
+if (!dst_lh)
+    {
+    printfd(__FILE__, "Destination storage plugin loading failed: %s\n", dlerror());
+    delete settings;
+    return -1;
+    }
+
+STORE * (*GetSourceStore)();
+STORE * (*GetDestStore)();
+GetSourceStore = (STORE * (*)())dlsym(src_lh, "GetStore");
+if (!GetSourceStore)
+    {
+    printfd(__FILE__, "Source storage plugin loading failed. GetStore not found: %s\n", dlerror());
+    delete settings;
+    return -1;
+    }
+GetDestStore = (STORE * (*)())dlsym(dst_lh, "GetStore");
+if (!GetDestStore)
+    {
+    printfd(__FILE__, "Storage plugin (firebird) loading failed. GetStore not found: %s\n", dlerror());
+    delete settings;
+    return -1;
+    }
+
+fromStore = GetSourceStore();
+toStore = GetDestStore();
+
+vector<string> entities;
+vector<string> ready;
+fromStore->SetSettings(fromStoreSettings);
+fromStore->ParseSettings();
+toStore->SetSettings(toStoreSettings);
+toStore->ParseSettings();
+
+printfd(__FILE__, "Importing admins:\n");
+entities.erase(entities.begin(), entities.end());
+ready.erase(ready.begin(), ready.end());
+if (fromStore->GetAdminsList(&entities))
+    {
+    printfd(__FILE__, "Error getting admins list: %s\n", fromStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+if (toStore->GetAdminsList(&ready))
+    {
+    printfd(__FILE__, "Error getting admins list: %s\n", toStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+
+vector<string>::const_iterator it;
+for (it = entities.begin(); it != entities.end(); ++it)
+    {
+    printfd(__FILE__, "\t - %s\n", it->c_str());
+    if (find(ready.begin(), ready.end(), *it) == ready.end())
+        if (toStore->AddAdmin(*it))
+            {
+            printfd(__FILE__, "Error adding admin: %s\n", toStore->GetStrError().c_str());
+            dlclose(src_lh);
+            dlclose(dst_lh);
+            delete settings;
+            return -1;
+            }
+    if (fromStore->RestoreAdmin(&ac, *it))
+        {
+        printfd(__FILE__, "Error getting admin's confi: %s\n", fromStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    ac.login = *it;
+    if (toStore->SaveAdmin(ac))
+        {
+        printfd(__FILE__, "Error saving admin's conf: %s\n", toStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    }
+
+printfd(__FILE__, "Importing tariffs:\n");
+entities.erase(entities.begin(), entities.end());
+ready.erase(ready.begin(), ready.end());
+if (fromStore->GetTariffsList(&entities))
+    {
+    printfd(__FILE__, "Error getting tariffs list: %s\n", fromStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+if (toStore->GetTariffsList(&ready))
+    {
+    printfd(__FILE__, "Error getting tariffs list: %s\n", toStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+
+for (it = entities.begin(); it != entities.end(); ++it)
+    {
+    printfd(__FILE__, "\t - %s\n", it->c_str());
+    if (find(ready.begin(), ready.end(), *it) == ready.end())
+        if (toStore->AddTariff(*it))
+            {
+            printfd(__FILE__, "Error adding tariff: %s\n", toStore->GetStrError().c_str());
+            dlclose(src_lh);
+            dlclose(dst_lh);
+            delete settings;
+            return -1;
+            }
+    if (fromStore->RestoreTariff(&td, *it))
+        {
+        printfd(__FILE__, "Error getting tariff's data: %s\n", fromStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    if (toStore->SaveTariff(td, *it))
+        {
+        printfd(__FILE__, "Error saving tariff's data: %s\n", toStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    }
+
+printfd(__FILE__, "Importing services:\n");
+entities.erase(entities.begin(), entities.end());
+ready.erase(ready.begin(), ready.end());
+if (fromStore->GetServicesList(&entities))
+    {
+    printfd(__FILE__, "Error getting service list: %s\n", fromStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+if (toStore->GetServicesList(&ready))
+    {
+    printfd(__FILE__, "Error getting service list: %s\n", toStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+
+for (it = entities.begin(); it != entities.end(); ++it)
+    {
+    printfd(__FILE__, "\t - %s\n", it->c_str());
+    if (find(ready.begin(), ready.end(), *it) == ready.end())
+        if (toStore->AddService(*it))
+            {
+            printfd(__FILE__, "Error adding service: %s\n", toStore->GetStrError().c_str());
+            dlclose(src_lh);
+            dlclose(dst_lh);
+            delete settings;
+            return -1;
+            }
+    if (fromStore->RestoreService(&sc, *it))
+        {
+        printfd(__FILE__, "Error getting service's data: %s\n", fromStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    if (toStore->SaveService(sc))
+        {
+        printfd(__FILE__, "Error saving service's data: %s\n", toStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    }
+
+printfd(__FILE__, "Importing corporations:\n");
+entities.erase(entities.begin(), entities.end());
+ready.erase(ready.begin(), ready.end());
+if (fromStore->GetCorpsList(&entities))
+    {
+    printfd(__FILE__, "Error getting corporations list: %s\n", fromStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+if (toStore->GetCorpsList(&ready))
+    {
+    printfd(__FILE__, "Error getting corporations list: %s\n", toStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+
+for (it = entities.begin(); it != entities.end(); ++it)
+    {
+    printfd(__FILE__, "\t - %s\n", it->c_str());
+    if (find(ready.begin(), ready.end(), *it) == ready.end())
+        if (toStore->AddCorp(*it))
+            {
+            printfd(__FILE__, "Error adding corporation: %s\n", toStore->GetStrError().c_str());
+            dlclose(src_lh);
+            dlclose(dst_lh);
+            delete settings;
+            return -1;
+            }
+    if (fromStore->RestoreCorp(&cc, *it))
+        {
+        printfd(__FILE__, "Error getting corporation's data: %s\n", fromStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    if (toStore->SaveCorp(cc))
+        {
+        printfd(__FILE__, "Error saving corporation's data: %s\n", toStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    }
+
+printfd(__FILE__, "Importing users:\n");
+entities.erase(entities.begin(), entities.end());
+ready.erase(ready.begin(), ready.end());
+if (fromStore->GetUsersList(&entities))
+    {
+    printfd(__FILE__, "Error getting users list: %s\n", fromStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+if (toStore->GetUsersList(&ready))
+    {
+    printfd(__FILE__, "Error getting users list: %s\n", toStore->GetStrError().c_str());
+    dlclose(src_lh);
+    dlclose(dst_lh);
+    delete settings;
+    return -1;
+    }
+
+sort(ready.begin(), ready.end());
+for (it = entities.begin(); it != entities.end(); ++it)
+    {
+    printfd(__FILE__, "\t - %s\n", it->c_str());
+    if (!binary_search(ready.begin(), ready.end(), *it)) {
+        if (toStore->AddUser(*it))
+            {
+            printfd(__FILE__, "Error adding user: %s\n", toStore->GetStrError().c_str());
+            dlclose(src_lh);
+            dlclose(dst_lh);
+            delete settings;
+            return -1;
+            }
+    } else {
+        printfd(__FILE__, "\t\t(adding passed)\n");
+    }
+    if (fromStore->RestoreUserConf(&uc, *it))
+        {
+        printfd(__FILE__, "Error getting user's conf: %s\n", fromStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    if (fromStore->RestoreUserStat(&us, *it))
+        {
+        printfd(__FILE__, "Error getting user's stat: %s\n", fromStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    if (toStore->SaveUserConf(uc, *it))
+        {
+        printfd(__FILE__, "Error saving user's conf: %s\n", toStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    if (toStore->SaveUserStat(us, *it))
+        {
+        printfd(__FILE__, "Error saving user's stat: %s\n", toStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    hdrs.erase(hdrs.begin(), hdrs.end());
+    if (fromStore->GetMessageHdrs(&hdrs, *it))
+        {
+        printfd(__FILE__, "Error getting user's messages: %s\n", fromStore->GetStrError().c_str());
+        dlclose(src_lh);
+        dlclose(dst_lh);
+        delete settings;
+        return -1;
+        }
+    vector<STG_MSG_HDR>::iterator mit;
+    for (mit = hdrs.begin(); mit != hdrs.end(); ++mit)
+        {
+        if (fromStore->GetMessage(mit->id, &msg, *it))
+            {
+            printfd(__FILE__, "Error getting message for a user: %s\n", fromStore->GetStrError().c_str());
+            dlclose(src_lh);
+            dlclose(dst_lh);
+            delete settings;
+            return -1;
+            }
+        printfd(__FILE__, "\t\t * %s\n", msg.text.c_str());
+        if (toStore->AddMessage(&msg, *it))
+            {
+            printfd(__FILE__, "Error adding message to a user: %s\n", toStore->GetStrError().c_str());
+            dlclose(src_lh);
+            dlclose(dst_lh);
+            delete settings;
+            return -1;
+            }
+        }
+    }
+
+dlclose(src_lh);
+dlclose(dst_lh);
+printfd(__FILE__, "Done\n");
+delete settings;
+return 0;
+}
diff --git a/projects/sgconv/settings_impl.cpp b/projects/sgconv/settings_impl.cpp
new file mode 100644 (file)
index 0000000..645865c
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ *    Date: 27.10.2002
+ */
+
+/*
+ *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ */
+
+/*
+$Revision: 1.6 $
+$Date: 2009/06/22 16:26:54 $
+*/
+
+#include "stg/dotconfpp.h"
+#include "stg/module_settings.h"
+#include "stg/common.h"
+
+#include "settings_impl.h"
+
+int SETTINGS_IMPL::ParseModuleSettings(const DOTCONFDocumentNode * node, std::vector<PARAM_VALUE> * params)
+{
+if (!node)
+    return 0;
+
+PARAM_VALUE pv;
+
+pv.param = node->getName();
+
+if (node->getValue(1))
+    {
+    strError = "Unexpected value \'" + std::string(node->getValue(1)) + "\'.";
+    printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
+    return -1;
+    }
+
+const char * value = node->getValue(0);
+
+if (!value)
+    {
+    strError = "Module name expected.";
+    printfd(__FILE__, "SETTINGS_IMPL::ParseModuleSettings() - %s\n", strError.c_str());
+    return -1;
+    }
+
+const DOTCONFDocumentNode * childNode = node->getChildNode();
+while (childNode)
+    {
+    pv.param = childNode->getName();
+    int i = 0;
+    while ((value = childNode->getValue(i)) != NULL)
+        {
+        pv.value.push_back(value);
+        ++i;
+        }
+    params->push_back(pv);
+    pv.value.clear();
+    childNode = childNode->getNextNode();
+    }
+
+return 0;
+}
+//-----------------------------------------------------------------------------
+int SETTINGS_IMPL::ReadSettings()
+{
+const char * requiredOptions[] = {
+    "ModulesPath",
+    "SourceStoreModule",
+    "DestStoreModule",
+    NULL
+    };
+int sourceStoreModulesCount = 0;
+int destStoreModulesCount = 0;
+
+DOTCONFDocument conf(DOTCONFDocument::CASEINSENSITIVE);
+conf.setRequiredOptionNames(requiredOptions);
+
+if(conf.setContent(confFile.c_str()) != 0)
+    {
+    strError = "Cannot read file " + confFile + ".";
+    printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
+    return -1;
+    }
+
+const DOTCONFDocumentNode * node = conf.getFirstNode();
+
+while (node)
+    {
+    if (strcasecmp(node->getName(), "ModulesPath") == 0)
+        {
+        modulesPath = node->getValue(0);
+        }
+
+    if (strcasecmp(node->getName(), "SourceStoreModule") == 0)
+        {
+        if (node->getValue(1))
+            {
+            strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
+            printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
+            return -1;
+            }
+
+        if (sourceStoreModulesCount)
+            {
+            strError = "Should be only one source StoreModule.";
+            printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
+            return -1;
+            }
+        ++sourceStoreModulesCount;
+
+        sourceStoreModuleSettings.moduleName = node->getValue(0);
+        ParseModuleSettings(node, &sourceStoreModuleSettings.moduleParams);
+        }
+
+    if (strcasecmp(node->getName(), "DestStoreModule") == 0)
+        {
+        if (node->getValue(1))
+            {
+            strError = "Unexpected \'" + std::string(node->getValue(1)) + "\'.";
+            printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
+            return -1;
+            }
+
+        if (destStoreModulesCount)
+            {
+            strError = "Should be only one dest StoreModule.";
+            printfd(__FILE__, "SETTINGS_IMPL::ReadSettings() - %s\n", strError.c_str());
+            return -1;
+            }
+        ++destStoreModulesCount;
+
+        destStoreModuleSettings.moduleName = node->getValue(0);
+        ParseModuleSettings(node, &destStoreModuleSettings.moduleParams);
+        }
+
+    node = node->getNextNode();
+    }
+
+return 0;
+}
+//-----------------------------------------------------------------------------
diff --git a/projects/sgconv/settings_impl.h b/projects/sgconv/settings_impl.h
new file mode 100644 (file)
index 0000000..eec21d6
--- /dev/null
@@ -0,0 +1,65 @@
+ /*
+ $Revision: 1.6 $
+ $Date: 2009/06/22 16:26:54 $
+ */
+
+/*
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/*
+ *    Date: 27.10.2002
+ */
+
+/*
+ *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ */
+
+#ifndef SETTINGS_IMPL_H
+#define SETTINGS_IMPL_H
+
+#include <string>
+#include <vector>
+
+struct MODULE_SETTINGS;
+class DOTCONFDocumentNode;
+
+class SETTINGS_IMPL {
+public:
+    SETTINGS_IMPL() : confFile("./convertor.conf") {}
+    SETTINGS_IMPL(const std::string & cf) : confFile(cf) {}
+    ~SETTINGS_IMPL() {}
+    int ReadSettings();
+
+    std::string GetStrError() const { return strError; }
+
+    const std::string & GetConfDir() const;
+
+    const std::string & GetModulesPath() const { return modulesPath; }
+    const MODULE_SETTINGS & GetSourceStoreModuleSettings() const { return sourceStoreModuleSettings; }
+    const MODULE_SETTINGS & GetDestStoreModuleSettings() const { return destStoreModuleSettings; }
+
+private:
+    int ParseModuleSettings(const DOTCONFDocumentNode * dirNameNode, std::vector<PARAM_VALUE> * params);
+
+    std::string strError;
+    std::string modulesPath;
+    std::string confFile;
+
+    MODULE_SETTINGS sourceStoreModuleSettings;
+    MODULE_SETTINGS destStoreModuleSettings;
+};
+
+#endif