<link linkend="stargazer.set_user_cash"><function>stargazer.set_user_cash</function></link>,
<link linkend="stargazer.chg_user_tariff"><function>stargazer.chg_user_tariff</function></link>
<link linkend="stargazer.get_online_ips"><function>stargazer.get_online_ips</function></link>
+ <link linkend="stargazer.get_user_auth_by"><function>stargazer.get_user_auth_by</function></link>
</para>
</refsect1>
</refentry>
<link linkend="stargazer.set_user_cash"><function>stargazer.set_user_cash</function></link>,
<link linkend="stargazer.chg_user_tariff"><function>stargazer.chg_user_tariff</function></link>
<link linkend="stargazer.get_online_ips"><function>stargazer.get_online_ips</function></link>
+ <link linkend="stargazer.get_user_auth_by"><function>stargazer.get_user_auth_by</function></link>
</para>
</refsect1>
</refentry>
<link linkend="stargazer.set_user_cash"><function>stargazer.set_user_cash</function></link>,
<link linkend="stargazer.chg_user_tariff"><function>stargazer.chg_user_tariff</function></link>
<link linkend="stargazer.get_online_ips"><function>stargazer.get_online_ips</function></link>
+ <link linkend="stargazer.get_user_auth_by"><function>stargazer.get_user_auth_by</function></link>
</para>
</refsect1>
</refentry>
<link linkend="stargazer.set_user_cash"><function>stargazer.set_user_cash</function></link>,
<link linkend="stargazer.chg_user_tariff"><function>stargazer.chg_user_tariff</function></link>
<link linkend="stargazer.get_online_ips"><function>stargazer.get_online_ips</function></link>
+ <link linkend="stargazer.get_user_auth_by"><function>stargazer.get_user_auth_by</function></link>
</para>
</refsect1>
</refentry>
<link linkend="stargazer.set_user_cash"><function>stargazer.set_user_cash</function></link>,
<link linkend="stargazer.chg_user_tariff"><function>stargazer.chg_user_tariff</function></link>
<link linkend="stargazer.get_online_ips"><function>stargazer.get_online_ips</function></link>
+ <link linkend="stargazer.get_user_auth_by"><function>stargazer.get_user_auth_by</function></link>
</para>
</refsect1>
</refentry>
<link linkend="stargazer.set_user_cash"><function>stargazer.set_user_cash</function></link>,
<link linkend="stargazer.chg_user_tariff"><function>stargazer.chg_user_tariff</function></link>
<link linkend="stargazer.get_online_ips"><function>stargazer.get_online_ips</function></link>
+ <link linkend="stargazer.get_user_auth_by"><function>stargazer.get_user_auth_by</function></link>
</para>
</refsect1>
</refentry>
<link linkend="stargazer.add_user_cash"><function>stargazer.add_user_cash</function></link>,
<link linkend="stargazer.chg_user_tariff"><function>stargazer.chg_user_tariff</function></link>
<link linkend="stargazer.get_online_ips"><function>stargazer.get_online_ips</function></link>
+ <link linkend="stargazer.get_user_auth_by"><function>stargazer.get_user_auth_by</function></link>
</para>
</refsect1>
</refentry>
<link linkend="stargazer.add_user_cash"><function>stargazer.add_user_cash</function></link>,
<link linkend="stargazer.set_user_cash"><function>stargazer.set_user_cash</function></link>
<link linkend="stargazer.get_online_ips"><function>stargazer.get_online_ips</function></link>
+ <link linkend="stargazer.get_user_auth_by"><function>stargazer.get_user_auth_by</function></link>
</para>
</refsect1>
</refentry>
<link linkend="stargazer.add_user_cash"><function>stargazer.add_user_cash</function></link>,
<link linkend="stargazer.set_user_cash"><function>stargazer.set_user_cash</function></link>
<link linkend="stargazer.chg_user_tariff"><function>stargazer.chg_user_tariff</function></link>
+ <link linkend="stargazer.get_user_auth_by"><function>stargazer.get_user_auth_by</function></link>
+ </para>
+ </refsect1>
+ </refentry>
+ <refentry id="stargazer.get_user_auth_by">
+ <refmeta>
+ <refentrytitle>stargazer.get_user_auth_by</refentrytitle>
+ </refmeta>
+ <refnamediv>
+ <refname>stargazer.get_user_auth_by</refname>
+ <refpurpose>Получение списка авторизаторов которыми авторизован пользователь</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <funcsynopsis>
+ <funcprototype>
+ <funcdef><function>stargazer.get_user_auth_by</function></funcdef>
+ <paramdef>string <parameter>cookie</parameter></paramdef>
+ <paramdef>string <parameter>login</parameter></paramdef>
+ </funcprototype>
+ </funcsynopsis>
+ </refsynopsisdiv>
+ <refsect1>
+ <title>Description</title>
+ <para>Метод <function>stargazer.get_user_auth_by</function> позволяет получить список авторизаторов которыми в данный момент авторизован пользователь.</para>
+ <variablelist>
+ <varlistentry>
+ <term>string <parameter>cookie</parameter></term>
+ <listitem>
+ <para>Авторизационный cookie. Для авторизации в системе используется метод <function><link linkend="stargazer.login">stargazer.login</link></function></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>string <parameter>login</parameter></term>
+ <listitem>
+ <para>Логин пользователя</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ <refsect2>
+ <title>Return Value</title>
+ <para>Возвращает структуру:</para>
+ <variablelist>
+ <varlistentry>
+ <term>bool <structfield>result</structfield></term>
+ <listitem>
+ <para>Результат операции. true - успешно, false - неудача (неправильный или устаревший cookie).</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>array of strings <structfield>auths</structfield></term>
+ <listitem>
+ <para>Список авторизаторов которыми авторизован пользователь.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect2>
+ </refsect1>
+ <refsect1>
+ <title>See also</title>
+ <para>
+ <link linkend="stargazer.get_users"><function>stargazer.get_users</function></link>,
+ <link linkend="stargazer.get_user"><function>stargazer.get_user</function></link>,
+ <link linkend="stargazer.add_user"><function>stargazer.add_user</function></link>,
+ <link linkend="stargazer.chg_user"><function>stargazer.chg_user</function></link>,
+ <link linkend="stargazer.del_user"><function>stargazer.del_user</function></link>,
+ <link linkend="stargazer.add_user_cash"><function>stargazer.add_user_cash</function></link>,
+ <link linkend="stargazer.set_user_cash"><function>stargazer.set_user_cash</function></link>
+ <link linkend="stargazer.chg_user_tariff"><function>stargazer.chg_user_tariff</function></link>
+ <link linkend="stargazer.get_online_ips"><function>stargazer.get_online_ips</function></link>
</para>
</refsect1>
</refentry>
#include <stdint.h>
#endif
-#ifdef FREE_BSD5
+#if defined(FREE_BSD5) || defined(DARWIN)
#include <inttypes.h>
#endif
#ifndef USER_H
#define USER_H
-#include <ctime>
-#include <string>
-
-#include "os_int.h"
#include "notifer.h"
#include "message.h"
#include "tariff.h"
#include "user_traff.h"
+#include "os_int.h"
+
+#include <vector>
+#include <string>
+
+#include <ctime>
class USER_PROPERTIES;
class AUTH;
virtual bool GetConnected() const = 0;
virtual time_t GetConnectedModificationTime() const = 0;
+ virtual const std::string & GetLastDisconnectReason() const = 0;
virtual int GetAuthorized() const = 0;
- /*virtual int Authorize(uint32_t ip,
- uint32_t enabledDirs,
- const AUTH * auth) = 0;
- virtual void Unauthorize(const AUTH * auth) = 0;*/
+ virtual time_t GetAuthorizedModificationTime() const = 0;
+
virtual bool IsAuthorizedBy(const AUTH * auth) const = 0;
+ virtual std::vector<std::string> GetAuthorizers() const = 0;
virtual int AddMessage(STG_MSG * msg) = 0;
std::string GetIpStr() const;
bool IsIPInIPS(uint32_t ip) const;
bool OnlyOneIP() const;
- int Count() const;
+ bool IsAnyIP() const;
+ size_t Count() const;
void Add(const IP_MASK &im);
void Erase();
}
//-----------------------------------------------------------------------------
inline
-int USER_IPS::Count() const
+size_t USER_IPS::Count() const
{
-return static_cast<int>(ips.size());
+return ips.size();
}
//-----------------------------------------------------------------------------
inline
}
//-----------------------------------------------------------------------------
inline
+bool USER_IPS::IsAnyIP() const
+{
+ return !ips.empty() && ips.front().ip == 0;
+}
+//-----------------------------------------------------------------------------
+inline
void USER_IPS::Add(const IP_MASK &im)
{
ips.push_back(im);
public:
virtual ~USERS() {}
virtual int FindByName(const std::string & login, USER_PTR * user) = 0;
+ virtual int FindByName(const std::string & login, CONST_USER_PTR * user) const = 0;
virtual bool TariffInUse(const std::string & tariffName) const = 0;
virtual int FindByIPIdx(uint32_t ip, USER_PTR * user) const = 0;
virtual bool IsIPInIndex(uint32_t ip) const = 0;
+ virtual bool IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const = 0;
virtual int OpenSearch() = 0;
virtual int SearchNext(int handle, USER_PTR * u) = 0;
if [ "$OS" = "unknown" ]
then
- echo "#############################################################################"
- echo "# Sorry, but rlm_stg currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #"
- echo "#############################################################################"
+ printf "#############################################################################\n"
+ printf "# Sorry, but rlm_stg currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n"
+ printf "#############################################################################\n"
exit 1
fi
-echo "#############################################################################"
-echo " Building rlm_stg for $sys $release"
-echo "#############################################################################"
+printf "#############################################################################\n"
+printf " Building rlm_stg for $sys $release\n"
+printf "#############################################################################\n"
STG_LIBS="crypto.lib common.lib"
CXX=g++
fi
-echo -n "Checking CC... "
+printf "Checking CC... "
$CC --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CC not found"
+ printf "FAIL!\n"
+ printf "$CC not found\n"
exit;
fi
-echo "found"
-echo -n "Checking CXX... "
+printf "found\n"
+printf "Checking CXX... "
$CXX --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CXX not found"
+ printf "FAIL!\n"
+ printf "$CXX not found\n"
exit;
fi
-echo "found"
+printf "found\n"
-echo -n "Checking endianess... "
-echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
+printf "Checking endianess... "
+printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "Endianess checking failed"
+ printf "FAIL!\n"
+ printf "Endianess checking failed\n"
exit;
else
./fake
ARCH=le
CXXFLAGS="$CXXFLAGS -DARCH_LE"
CFLAGS="$CFLAGS -DARCH_LE"
- echo "Little Endian"
+ printf "Little Endian\n"
else
ARCH=be
CXXFLAGS="$CXXFLAGS -DARCH_BE"
CFLAGS="$CFLAGS -DARCH_BE"
- echo "Big Endian"
+ printf "Big Endian\n"
fi
fi
rm -f fake
-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 "ARCH=$ARCH" >> $CONFFILE
-echo "DEFS=$DEFS" >> $CONFFILE
-echo -n "STG_LIBS=" >> $CONFFILE
+printf "OS=$OS\n" > $CONFFILE
+printf "STG_TIME=yes\n" >> $CONFFILE
+printf "DEBUG=$DEBUG\n" >> $CONFFILE
+printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
+printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
+printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
+printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
+printf "ARCH=$ARCH\n" >> $CONFFILE
+printf "DEFS=$DEFS\n" >> $CONFFILE
+printf "STG_LIBS=" >> $CONFFILE
for lib in $STG_LIBS
do
- echo -n "$lib " >> $CONFFILE
+ printf "$lib " >> $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
+printf "\n" >> $CONFFILE
+printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
+printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
+printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
+printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
+printf "PREFIX=$PREFIX\n" >> $CONFFILE
+printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
+printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
+printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
+printf "OWNER=$OWNER\n" >> $CONFFILE
$MAKE $MAKEOPTS
if [ "$OS" = "unknown" ]
then
- echo "#############################################################################"
- echo "# Sorry, but rscriptd currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #"
- echo "#############################################################################"
+ printf "#############################################################################\n"
+ printf "# Sorry, but rscriptd currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n"
+ printf "#############################################################################\n"
exit 1
fi
-echo "#############################################################################"
-echo " Building rscriptd for $sys $release"
-echo "#############################################################################"
+printf "#############################################################################\n"
+printf " Building rscriptd for $sys $release\n"
+printf "#############################################################################\n"
STG_LIBS="logger.lib
locker.lib
CXX=g++
fi
-echo -n "Checking CC... "
+printf "Checking CC... "
$CC --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CC not found"
+ printf "FAIL!\n"
+ printf "$CC not found\n"
exit;
fi
-echo "found"
-echo -n "Checking CXX... "
+printf "found\n"
+printf "Checking CXX... "
$CXX --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CXX not found"
+ printf "FAIL!\n"
+ printf "$CXX not found\n"
exit;
fi
-echo "found"
+printf "found\n"
-echo -n "Checking endianess... "
-echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
+printf "Checking endianess... "
+printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "Endianess checking failed"
+ printf "FAIL!\n"
+ printf "Endianess checking failed\n"
exit;
else
./fake
ARCH=le
CXXFLAGS="$CXXFLAGS -DARCH_LE"
CFLAGS="$CFLAGS -DARCH_LE"
- echo "Little Endian"
+ printf "Little Endian\n"
else
ARCH=be
CXXFLAGS="$CXXFLAGS -DARCH_BE"
CFLAGS="$CFLAGS -DARCH_BE"
- echo "Big Endian"
+ printf "Big Endian\n"
fi
fi
rm -f fake
rm -f build_check.c
-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 "ARCH=$ARCH" >> $CONFFILE
-echo "DEFS=$DEFS" >> $CONFFILE
-echo -n "STG_LIBS=" >> $CONFFILE
+printf "OS=$OS\n" > $CONFFILE
+printf "STG_TIME=yes\n" >> $CONFFILE
+printf "DEBUG=$DEBUG\n" >> $CONFFILE
+printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
+printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
+printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
+printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
+printf "ARCH=$ARCH\n" >> $CONFFILE
+printf "DEFS=$DEFS\n" >> $CONFFILE
+printf "STG_LIBS=" >> $CONFFILE
for lib in $STG_LIBS
do
- echo -n "$lib " >> $CONFFILE
+ printf "$lib " >> $CONFFILE
done
-echo "" >> $CONFFILE
-echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
-echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
-echo "CFLAGS=$CFLAGS" >> $CONFFILE
-echo "LDFLAGS=$LDFLAGS" >> $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
+printf "\n" >> $CONFFILE
+printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
+printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
+printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
+printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
+printf "PREFIX=$PREFIX\n" >> $CONFFILE
+printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
+printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
+printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
+printf "OWNER=$OWNER\n" >> $CONFFILE
$MAKE $MAKEOPTS
if [ "$OS" = "unknown" ]
then
- echo "#############################################################################"
- echo "# Sorry, but sgauth currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #"
- echo "#############################################################################"
+ printf "#############################################################################\n"
+ printf "# Sorry, but sgauth currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n"
+ printf "#############################################################################\n"
exit 1
fi
-echo "#############################################################################"
-echo " Building sgauth for $sys $release"
-echo "#############################################################################"
+printf "#############################################################################\n"
+printf " Building sgauth for $sys $release\n"
+printf "#############################################################################\n"
STG_LIBS="crypto.lib
common.lib
CXX=g++
fi
-echo -n "Checking CC... "
+printf "Checking CC... "
$CC --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CC not found"
+ printf "FAIL!\n"
+ printf "$CC not found\n"
exit;
fi
-echo "found"
-echo -n "Checking CXX... "
+printf "found\n"
+printf "Checking CXX... "
$CXX --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CXX not found"
+ printf "FAIL!\n"
+ printf "$CXX not found\n"
exit;
fi
-echo "found"
+printf "found\n"
-echo -n "Checking endianess... "
-echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
+printf "Checking endianess... "
+printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "Endianess checking failed"
+ printf "FAIL!\n"
+ printf "Endianess checking failed\n"
exit;
else
./fake
ARCH=le
CXXFLAGS="$CXXFLAGS -DARCH_LE"
CFLAGS="$CFLAGS -DARCH_LE"
- echo "Little Endian"
+ printf "Little Endian\n"
else
ARCH=be
CXXFLAGS="$CXXFLAGS -DARCH_BE"
CFLAGS="$CFLAGS -DARCH_BE"
- echo "Big Endian"
+ printf "Big Endian\n"
fi
fi
rm -f fake
rm -f build_check.c
-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 "ARCH=$ARCH" >> $CONFFILE
-echo "DEFS=$DEFS" >> $CONFFILE
-echo -n "STG_LIBS=" >> $CONFFILE
+printf "OS=$OS\n" > $CONFFILE
+printf "STG_TIME=yes\n" >> $CONFFILE
+printf "DEBUG=$DEBUG\n" >> $CONFFILE
+printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
+printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
+printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
+printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
+printf "ARCH=$ARCH\n" >> $CONFFILE
+printf "DEFS=$DEFS\n" >> $CONFFILE
+printf "STG_LIBS=" >> $CONFFILE
for lib in $STG_LIBS
do
- echo -n "$lib " >> $CONFFILE
+ printf "$lib " >> $CONFFILE
done
-echo "" >> $CONFFILE
-echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
-echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
-echo "CFLAGS=$CFLAGS" >> $CONFFILE
-echo "LDFLAGS=$LDFLAGS" >> $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
+printf "\n" >> $CONFFILE
+printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
+printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
+printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
+printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
+printf "PREFIX=$PREFIX\n" >> $CONFFILE
+printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
+printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
+printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
+printf "OWNER=$OWNER\n" >> $CONFFILE
$MAKE $MAKEOPTS
if [ "$OS" = "unknown" ]
then
- echo "################################################################################"
- echo "# Sorry, but sgauthstress currently supported by Linux, FreeBSD 4.x-8.x #"
- echo "################################################################################"
+ printf "################################################################################\n"
+ printf "# Sorry, but sgauthstress currently supported by Linux, FreeBSD 4.x-8.x #\n"
+ printf "################################################################################\n"
exit 1
fi
-echo "#############################################################################"
-echo " Building sgauthstress for $sys $release"
-echo "#############################################################################"
+printf "#############################################################################\n"
+printf " Building sgauthstress for $sys $release\n"
+printf "#############################################################################\n"
STG_LIBS="logger.lib
locker.lib
CXX=g++
fi
-echo -n "Checking CC... "
+printf "Checking CC... "
$CC --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CC not found"
+ printf "FAIL!\n"
+ printf "$CC not found\n"
exit;
fi
-echo "found"
-echo -n "Checking CXX... "
+printf "found\n"
+printf "Checking CXX... "
$CXX --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CXX not found"
+ printf "FAIL!\n"
+ printf "$CXX not found\n"
exit;
fi
-echo "found"
+printf "found\n"
-echo -n "Checking endianess... "
-echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
+printf "Checking endianess... "
+printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "Endianess checking failed"
+ printf "FAIL!\n"
+ printf "Endianess checking failed\n"
exit;
else
./fake
ARCH=le
CXXFLAGS="$CXXFLAGS -DARCH_LE"
CFLAGS="$CFLAGS -DARCH_LE"
- echo "Little Endian"
+ printf "Little Endian\n"
else
ARCH=be
CXXFLAGS="$CXXFLAGS -DARCH_BE"
CFLAGS="$CFLAGS -DARCH_BE"
- echo "Big Endian"
+ printf "Big Endian\n"
fi
fi
rm -f fake
rm -f build_check.c
-echo -n "Checking for -lfbclient... "
+printf "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"
+ printf "no\n"
else
CHECK_FBCLIENT=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
-echo -n "Checking for mysql_config... "
+printf "Checking for mysql_config... "
MYSQL_VERSION=`mysql_config --version 2> /dev/null`
if [ $? != 0 ]
then
- echo "no";
- echo -n "Checking for -lmysqlclient... "
+ printf "no\n";
+ printf "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"
+ printf "no\n"
else
CHECK_MYSQLCLIENT=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
else
- echo "yes"
- echo -n "Checking for mysql_config --cflags... "
+ printf "yes\n"
+ printf "Checking for mysql_config --cflags... "
MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
if [ $? != 0 ]
then
CHECK_MYSQLCLIENT=no
- echo "no"
+ printf "no\n"
else
- echo "[$MYSQL_CFLAGS]"
- echo -n "Checking for mysql_config --libs_r... "
+ printf "[$MYSQL_CFLAGS]\n"
+ printf "Checking for mysql_config --libs_r... "
MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
if [ $? != 0 ]
then
CHECK_MYSQLCLIENT=no
- echo "no"
+ printf "no\n"
else
CHECK_MYSQLCLIENT=yes
- echo "[$MYSQL_LDFLAGS]"
+ printf "[$MYSQL_LDFLAGS]\n"
fi
fi
fi
-echo -n "Checking for pg_config... "
+printf "Checking for pg_config... "
PG_VERSION=`pg_config --version 2> /dev/null`
if [ $? != 0 ]
then
- echo "no";
- echo -n "Checking for -lpq... "
+ printf "no\n";
+ printf "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"
+ printf "no\n"
else
CHECK_PQ=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
else
- echo "yes";
- echo -n "Checking for pg_config --includedir... "
+ printf "yes\n";
+ printf "Checking for pg_config --includedir... "
PG_CFLAGS=`pg_config --includedir 2> /dev/null`
if [ $? != 0 ]
then
CHECK_PQ=no
- echo "no"
+ printf "no\n"
else
- echo "[$PG_CFLAGS]"
- echo -n "Checking for pg_config --libdir... "
+ printf "[$PG_CFLAGS]\n"
+ printf "Checking for pg_config --libdir... "
PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
if [ $? != 0 ]
then
CHECK_PQ=no
- echo "no"
+ printf "no\n"
else
CHECK_PQ=yes
- echo "[$PG_LDFLAGS]"
+ printf "[$PG_LDFLAGS]\n"
fi
fi
fi
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 "DEFS=$DEFS" >> $CONFFILE
-echo -n "STG_LIBS=" >> $CONFFILE
+printf "OS=$OS\n" > $CONFFILE
+printf "STG_TIME=yes\n" >> $CONFFILE
+printf "DEBUG=$DEBUG\n" >> $CONFFILE
+printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
+printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
+printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
+printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
+printf "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules\n" >> $CONFFILE
+printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE
+printf "ARCH=$ARCH\n" >> $CONFFILE
+printf "DEFS=$DEFS\n" >> $CONFFILE
+printf "STG_LIBS=" >> $CONFFILE
for lib in $STG_LIBS
do
- echo -n "$lib " >> $CONFFILE
+ printf "$lib " >> $CONFFILE
done
-echo "" >> $CONFFILE
-echo -n "PLUGINS=" >> $CONFFILE
+printf "\n" >> $CONFFILE
+printf "PLUGINS=" >> $CONFFILE
for plugin in $PLUGINS
do
- echo -n "$plugin " >> $CONFFILE
+ printf "$plugin " >> $CONFFILE
done
-echo "" >> $CONFFILE
-echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
-echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
-echo "CFLAGS=$CFLAGS" >> $CONFFILE
-echo "LDFLAGS=$LDFLAGS" >> $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
+printf "\n" >> $CONFFILE
+printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
+printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
+printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
+printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
+printf "PREFIX=$PREFIX\n" >> $CONFFILE
+printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
+printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
+printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
+printf "OWNER=$OWNER\n" >> $CONFFILE
$MAKE $MAKEOPTS
CXXFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
CFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
-LDFLAGS += -Wl,-E $(STGLIBS_LIBS)
+LDFLAGS += $(STGLIBS_LIBS)
+
+ifneq ($(OS),darwin)
+LDFLAGS += -Wl,-E
+endif
.PHONY: all clean distclean libs install uninstall install-bin install-data uninstall-bin uninstall-data
all: libs $(PROG) ../../Makefile.conf
MAKE="gmake"
fi
+if [ "$sys" = "Darwin" ]
+then
+ OS=darwin
+ ETC_DIR="./inst/freebsd/etc/stargazer"
+ MAKE="gmake"
+fi
+
if [ "$OS" = "unknown" ]
then
- echo "#############################################################################"
- echo "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #"
- echo "#############################################################################"
+ printf "#############################################################################\n"
+ printf "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n"
+ printf "#############################################################################\n"
exit 1
fi
-echo "#############################################################################"
-echo " Building sgconf for $sys $release"
-echo "#############################################################################"
+printf "#############################################################################\n"
+printf " Building sgconf for $sys $release\n"
+printf "#############################################################################\n"
STG_LIBS="conffiles.lib
crypto.lib
then
DEFS="$DEFS -DFREE_BSD"
else
- DEFS="$DEFS -DFREE_BSD5"
if [ "$OS" = "bsd7" ]
then
+ DEFS="$DEFS -DFREE_BSD5"
LIB_THREAD=-lpthread
else
- LIB_THREAD=-lc_r
+ if [ "$OS" == "darwin" ]
+ then
+ DEFS="$DEFS -DDARWIN"
+ LIB_THREAD=-lpthread
+ else
+ LIB_THREAD=-lc_r
+ fi
fi
fi
fi
CXX=g++
fi
-echo -n "Checking CC... "
+printf "Checking CC... "
$CC --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CC not found"
+ printf "FAIL!\n"
+ printf "$CC not found\n"
exit;
fi
-echo "found"
-echo -n "Checking CXX... "
+printf "found\n"
+printf "Checking CXX... "
$CXX --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CXX not found"
+ printf "FAIL!\n"
+ printf "$CXX not found\n"
exit;
fi
-echo "found"
+printf "found\n"
-echo -n "Checking endianess... "
-echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
+printf "Checking endianess... "
+printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "Endianess checking failed"
+ printf "FAIL!\n"
+ printf "Endianess checking failed\n"
exit;
else
./fake
ARCH=le
CXXFLAGS="$CXXFLAGS -DARCH_LE"
CFLAGS="$CFLAGS -DARCH_LE"
- echo "Little Endian"
+ printf "Little Endian\n"
else
ARCH=be
CXXFLAGS="$CXXFLAGS -DARCH_BE"
CFLAGS="$CFLAGS -DARCH_BE"
- echo "Big Endian"
+ printf "Big Endian\n"
fi
fi
rm -f fake
-echo -n "Checking for -lexpat... "
-echo "int main() { return 0; }" > build_check.c
+printf "Checking for -lexpat... "
+printf "int main() { return 0; }\n" > build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
CHECK_EXPAT=no
- echo "no"
+ printf "no\n"
else
CHECK_EXPAT=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
rm -f build_check.c
if [ "$CHECK_EXPAT" != "yes" ]
then
- echo "-lexpat not found!"
+ printf "-lexpat not found!\n"
exit 1
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 "ARCH=$ARCH" >> $CONFFILE
-echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE
-echo "DEFS=$DEFS" >> $CONFFILE
-echo -n "STG_LIBS=" >> $CONFFILE
+printf "OS=$OS\n" > $CONFFILE
+printf "STG_TIME=yes\n" >> $CONFFILE
+printf "DEBUG=$DEBUG\n" >> $CONFFILE
+printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
+printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
+printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
+printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
+printf "ARCH=$ARCH\n" >> $CONFFILE
+printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
+printf "DEFS=$DEFS\n" >> $CONFFILE
+printf "STG_LIBS=" >> $CONFFILE
for lib in $STG_LIBS
do
- echo -n "$lib " >> $CONFFILE
+ printf "$lib " >> $CONFFILE
done
-echo "" >> $CONFFILE
-echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
-echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
-echo "CFLAGS=$CFLAGS" >> $CONFFILE
-echo "LDFLAGS=$LDFLAGS" >> $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
+printf "\n" >> $CONFFILE
+printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
+printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
+printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
+printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
+printf "PREFIX=$PREFIX\n" >> $CONFFILE
+printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
+printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
+printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
+printf "OWNER=$OWNER\n" >> $CONFFILE
$MAKE $MAKEOPTS
*/
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <locale.h>
-#include <langinfo.h>
-#include <iostream>
-#include <iconv.h>
-
-#include "stg/common.h"
#include "sg_error_codes.h"
#include "common_sg.h"
#include "version_sg.h"
-using namespace std;
+#include "stg/common.h"
+
+#include <iostream>
+#include <vector>
+
+#include <cstdio>
+#include <cstring>
+#include <cstdlib>
+#include <cerrno>
+#include <clocale>
+
+#include <langinfo.h>
+#include <iconv.h>
const int usageConf = 0;
const int usageInfo = 1;
const int TO_KOI8 = 0;
const int FROM_KOI8 = 1;
//-----------------------------------------------------------------------------
-struct GetUserCbData
+struct ResultData
+{
+ bool result;
+ std::string reason;
+};
+//-----------------------------------------------------------------------------
+struct GetUserData
{
- void * data;
- bool * result;
+ GetUserData(REQUEST & req, bool res) : request(req), result(res) {}
+ REQUEST & request;
+ bool result;
+ std::string reason;
};
//---------------------------------------------------------------------------
struct HelpParams
{
- string setActionName;
- string getActionName;
- string valueName;
- string valueParam;
+ std::string setActionName;
+ std::string getActionName;
+ std::string valueName;
+ std::string valueParam;
};
//---------------------------------------------------------------------------
void Usage(int usageType)
{"set credit expire", "get credit expire", "-E", "<credit_expire_date>"},
{"set password", "get password", "-o", "<new_password>"},
{"set prepaid traffic", "get prepaid traffic", "-e", "<prepaid>"},
- {"set IP-addresses", "get IP-addresses", "-I", "<*|ip_addr[,ip_addr...]>"},
+ {"set IP-addresses", "get IP-addresses", "-I", "<*|ip_addr[,ip_addr...]>"},
{"set name", "get name", "-A", "<name>"},
{"set note", "get note", "-N", "<note>"},
{"set street address", "get street address", "-D", "<address>"},
printf("To get userdata<0...9> use:\n");
printf("sgconf get -s <server> -p <port> -a <admin> -w <admin_pass> -u <user> --ud0 [--ud1 ...]\n\n");
+printf("To get user's authorizers list use:\n");
+printf("sgconf get -s <server> -p <port> -a <admin> -w <admin_pass> -u <user> --authorized-by\n\n");
+
printf("To send message use:\n");
printf("sgconf set -s <server> -p <port> -a <admin> -w <admin_pass> -u <user> -m <message>\n\n");
int port;
if (str2x(p, port) != 0)
{
- printf("Incorresct server port %s\n", p);
+ printf("Incorrect server port %s\n", p);
exit(NETWORK_ERR_CODE);
}
return (short)port;
{
if (CheckLogin(adm))
{
- printf("Incorresct admin login %s\n", adm);
+ printf("Incorrect admin login %s\n", adm);
exit(PARAMETER_PARSING_ERR_CODE);
}
return adm;
{
if (CheckLogin(usr))
{
- printf("Incorresct user login %s\n", usr);
+ printf("Incorrect user login %s\n", usr);
exit(PARAMETER_PARSING_ERR_CODE);
}
return usr;
}
//-----------------------------------------------------------------------------
-void ConvertKOI8(const string & src, string * dst, int encType)
+void ConvertKOI8(const std::string & src, std::string * dst, int encType)
{
iconv_t cd;
char * ob = new char[src.size() * 2 + 1];
delete[] ib;
}
//-----------------------------------------------------------------------------
-void ConvertFromKOI8(const string & src, string * dst)
+void ConvertFromKOI8(const std::string & src, std::string * dst)
{
ConvertKOI8(src, dst, FROM_KOI8);
}
//-----------------------------------------------------------------------------
-void ConvertToKOI8(const string & src, string * dst)
+void SendMessageCallback(bool result, const std::string & reason, void * d)
{
-ConvertKOI8(src, dst, TO_KOI8);
+ResultData * data = static_cast<ResultData *>(d);
+data->result = result;
+data->reason = reason;
}
//-----------------------------------------------------------------------------
-int RecvSetUserAnswer(const char * ans, void * d)
+void RecvSetUserAnswer(bool result, const std::string & reason, void * d)
{
-GetUserCbData * gucbd;
-gucbd = (GetUserCbData *)d;
-
-bool * result = gucbd->result;
+ResultData * data = static_cast<ResultData *>(d);
+data->result = result;
+data->reason = reason;
+}
+//-----------------------------------------------------------------------------
+void RecvAuthByData(bool result, const std::string & reason,
+ const PARSER_AUTH_BY::INFO & list, void * d)
+{
+ResultData * data = static_cast<ResultData *>(d);
+data->result = result;
+data->reason = reason;
-//REQUEST * req = (REQUEST *)gucbd->data;
+if (!result)
+ return;
-//printf("ans=%s\n", ans);
-if (strcasecmp("Ok", ans) == 0)
- *result = true;
-else
- *result = false;
+for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
+ std::cout << *it << "\n";
-return 0;
+std::cout << std::endl;
}
//-----------------------------------------------------------------------------
struct StringReqParams
{
- string name;
- RESETABLE<string> reqParam;
- string * value;
+ std::string name;
+ RESETABLE<std::string> reqParam;
+ const std::string * value;
};
//-----------------------------------------------------------------------------
-void RecvUserData(USERDATA * ud, void * d)
+void GetUserCallback(bool result, const std::string& reason, const PARSER_GET_USER::INFO & info, void * d)
{
-GetUserCbData * gucbd;
-gucbd = (GetUserCbData *)d;
-
-bool * result = gucbd->result;
+GetUserData * data = static_cast<GetUserData *>(d);
+data->result = false;
+data->reason = reason;
-REQUEST * req = (REQUEST *)gucbd->data;
+if (!result)
+ return;
-if (ud->login == "")
+if (info.login == "")
{
- *result = false;
+ data->result = false;
+ data->reason = "Invalid login.";
return;
}
-if (!req->cash.res_empty())
- cout << "cash=" << ud->cash << endl;
+if (!data->request.cash.res_empty())
+ cout << "cash = " << info.cash << endl;
-if (!req->credit.res_empty())
- cout << "credit=" << ud->credit << endl;
+if (!data->request.credit.res_empty())
+ cout << "credit = " << info.credit << endl;
-if (!req->creditExpire.res_empty())
+if (!data->request.creditExpire.res_empty())
{
char buf[32];
struct tm brokenTime;
- time_t tt = ud->creditExpire;
+ time_t tt = info.creditExpire;
brokenTime.tm_wday = 0;
brokenTime.tm_yday = 0;
strftime(buf, 32, "%Y-%m-%d", &brokenTime);
- cout << "creditExpire=" << buf << endl;
+ cout << "creditExpire = " << buf << endl;
}
-if (!req->down.res_empty())
- cout << "down=" << ud->down << endl;
+if (!data->request.down.res_empty())
+ cout << "down = " << info.down << endl;
-if (!req->passive.res_empty())
- cout << "passive=" << ud->passive << endl;
+if (!data->request.passive.res_empty())
+ cout << "passive = " << info.passive << endl;
-if (!req->disableDetailStat.res_empty())
- cout << "disableDetailStat=" << ud->disableDetailStat << endl;
+if (!data->request.disableDetailStat.res_empty())
+ cout << "disableDetailStat = " << info.disableDetailStat << endl;
-if (!req->alwaysOnline.res_empty())
- cout << "alwaysOnline=" << ud->alwaysOnline << endl;
+if (!data->request.alwaysOnline.res_empty())
+ cout << "alwaysOnline = " << info.alwaysOnline << endl;
-if (!req->prepaidTraff.res_empty())
- cout << "prepaidTraff=" << ud->prepaidTraff << endl;
+if (!data->request.prepaidTraff.res_empty())
+ cout << "prepaidTraff = " << info.prepaidTraff << endl;
for (int i = 0; i < DIR_NUM; i++)
{
- if (!req->u[i].res_empty())
- cout << "u" << i << "=" << ud->stat.mu[i] << endl;
- if (!req->d[i].res_empty())
- cout << "d" << i << "=" << ud->stat.md[i] << endl;
+ if (!data->request.sessionUpload[i].res_empty())
+ cout << "session upload for dir " << i << " = " << info.stat.su[i] << endl;
+ if (!data->request.sessionDownload[i].res_empty())
+ cout << "session download for dir " << i << "=" << info.stat.sd[i] << endl;
+ }
+
+for (int i = 0; i < DIR_NUM; i++)
+ {
+ if (!data->request.monthUpload[i].res_empty())
+ cout << "month upload for dir " << i << " = " << info.stat.mu[i] << endl;
+ if (!data->request.monthDownload[i].res_empty())
+ cout << "month download for dir " << i << " = " << info.stat.md[i] << endl;
}
for (int i = 0; i < USERDATA_NUM; i++)
{
- if (!req->ud[i].res_empty())
+ if (!data->request.userData[i].res_empty())
{
- string str;
- ConvertFromKOI8(ud->userData[i], &str);
- cout << "userdata" << i << "=" << str << endl;
+ std::string str;
+ ConvertFromKOI8(info.userData[i], &str);
+ cout << "user data " << i << " = " << str << endl;
}
}
StringReqParams strReqParams[] =
{
- {"note", req->note, &ud->note},
- {"name", req->name, &ud->name},
- {"address", req->address, &ud->address},
- {"email", req->email, &ud->email},
- {"phone", req->phone, &ud->phone},
- {"group", req->group, &ud->group},
- {"tariff", req->tariff, &ud->tariff},
- {"password", req->usrPasswd, &ud->password},
- {"ip", req->ips, &ud->ips} // IP-address of user
+ {"note", data->request.note, &info.note},
+ {"name", data->request.name, &info.name},
+ {"address", data->request.address, &info.address},
+ {"email", data->request.email, &info.email},
+ {"phone", data->request.phone, &info.phone},
+ {"group", data->request.group, &info.group},
+ {"tariff", data->request.tariff, &info.tariff},
+ {"password", data->request.usrPasswd, &info.password},
+ {"ip", data->request.ips, &info.ips} // IP-address of user
};
for (unsigned i = 0; i < sizeof(strReqParams) / sizeof(StringReqParams); i++)
{
{
string str;
ConvertFromKOI8(*strReqParams[i].value, &str);
- cout << strReqParams[i].name << "=" << str << endl;
+ cout << strReqParams[i].name << " = " << str << endl;
}
}
-*result = true;
+data->result = true;
}
//-----------------------------------------------------------------------------
-int ProcessSetUser(const std::string &server,
- int port,
- const std::string &admLogin,
- const std::string &admPasswd,
- const std::string &str,
- void * data,
- bool isMessage)
+bool ProcessSetUser(const std::string & server,
+ int port,
+ const std::string & admLogin,
+ const std::string & admPasswd,
+ const std::string & str)
{
SERVCONF sc;
-bool result = false;
-
-
-sc.SetServer(server.c_str()); // õÓÔÁÎÁ×ÌÉ×ÁÅÍ ÉÍÑ ÓÅÒ×ÅÒÁ Ó ËÏÔÏÒÇÏ ÚÁÂÉÒÁÔØ ÉÎÆÕ
-sc.SetPort(port); // ÁÄÍÉÎÓËÉÊ ÐÏÒÔ ÓÅÒ×ÅÒÁÐÏÒÔ
-sc.SetAdmLogin(admLogin.c_str()); // ÷ÙÓÔÁ×ÌÑÅÍ ÌÏÇÉÎ É ÐÁÒÏÌØ ÁÄÍÉÎÁ
+sc.SetServer(server.c_str());
+sc.SetPort(port);
+sc.SetAdmLogin(admLogin.c_str());
sc.SetAdmPassword(admPasswd.c_str());
-// TODO Good variable name :)
-GetUserCbData gucbd;
-
-gucbd.data = data;
-gucbd.result = &result;
+ResultData data;
+sc.SetChgUserCallback(RecvSetUserAnswer, &data);
+int res = sc.ChgUser(str.c_str());
-if (isMessage)
+if (res == st_ok && data.result)
{
- sc.SetSendMessageCb(RecvSetUserAnswer, &gucbd);
- sc.MsgUser(str.c_str());
+ printf("Ok\n");
+ return false;
}
+
+printf("Error\n");
+if (res != st_ok)
+ printf("%s\n", sc.GetStrError().c_str());
else
- {
- sc.SetChgUserCb(RecvSetUserAnswer, &gucbd);
- sc.ChgUser(str.c_str());
- }
+ printf("%s\n", data.reason.c_str());
+return true;
+}
+//-----------------------------------------------------------------------------
+bool ProcessSendMessage(const std::string & server, uint16_t port,
+ const std::string & login, const std::string & password,
+ const std::string & requestString)
+{
+SERVCONF sc;
+
+sc.SetServer(server.c_str());
+sc.SetPort(port);
+sc.SetAdmLogin(login.c_str());
+sc.SetAdmPassword(password.c_str());
-if (result)
+ResultData data;
+sc.SetSendMessageCallback(SendMessageCallback, &data);
+int res = sc.SendMessage(requestString.c_str());
+
+if (res == st_ok && data.result)
{
printf("Ok\n");
- return 0;
+ return true;
}
+
+printf("Error\n");
+if (res != st_ok)
+ printf("%s\n", sc.GetStrError().c_str());
else
+ printf("%s\n", data.reason.c_str());
+return false;
+}
+//-----------------------------------------------------------------------------
+bool ProcessGetUser(const std::string &server,
+ int port,
+ const std::string &admLogin,
+ const std::string &admPasswd,
+ const std::string &login,
+ REQUEST & request)
+{
+SERVCONF sc;
+
+sc.SetServer(server.c_str());
+sc.SetPort(port);
+sc.SetAdmLogin(admLogin.c_str());
+sc.SetAdmPassword(admPasswd.c_str());
+
+GetUserData data(request, false);
+
+sc.SetGetUserCallback(GetUserCallback, &data);
+bool res = (sc.GetUser(login.c_str()) == st_ok);
+
+if (res && data.result)
{
- printf("Error\n");
- return -1;
+ printf("Ok\n");
+ return true;
}
-return 0;
+printf("Error\n");
+if (!res)
+ printf("%s\n", sc.GetStrError().c_str());
+else
+ printf("%s\n", data.reason.c_str());
+return false;
}
//-----------------------------------------------------------------------------
-int ProcessGetUser(const std::string &server,
+bool ProcessAuthBy(const std::string &server,
int port,
const std::string &admLogin,
const std::string &admPasswd,
- const std::string &login,
- void * data)
+ const std::string &login)
{
SERVCONF sc;
-bool result = false;
-
-sc.SetServer(server.c_str()); // õÓÔÁÎÁ×ÌÉ×ÁÅÍ ÉÍÑ ÓÅÒ×ÅÒÁ Ó ËÏÔÏÒÇÏ ÚÁÂÉÒÁÔØ ÉÎÆÕ
-sc.SetPort(port); // ÁÄÍÉÎÓËÉÊ ÐÏÒÔ ÓÅÒ×ÅÒÁÐÏÒÔ
-sc.SetAdmLogin(admLogin.c_str()); // ÷ÙÓÔÁ×ÌÑÅÍ ÌÏÇÉÎ É ÐÁÒÏÌØ ÁÄÍÉÎÁ
+sc.SetServer(server.c_str());
+sc.SetPort(port);
+sc.SetAdmLogin(admLogin.c_str());
sc.SetAdmPassword(admPasswd.c_str());
-// TODO Good variable name :)
-GetUserCbData gucbd;
-
-gucbd.data = data;
-gucbd.result = &result;
+ResultData data;
+sc.SetAuthByCallback(RecvAuthByData, &data);
+bool res = (sc.AuthBy(login.c_str()) == st_ok);
-sc.SetGetUserDataRecvCb(RecvUserData, &gucbd);
-sc.GetUser(login.c_str());
-
-if (result)
+if (res && data.result)
{
printf("Ok\n");
- return 0;
- }
-else
- {
- printf("Error\n");
- return -1;
+ return true;
}
-return 0;
+printf("Error\n");
+if (!res)
+ printf("%s\n", sc.GetStrError().c_str());
+else
+ printf("%s\n", data.reason.c_str());
+return false;
}
//-----------------------------------------------------------------------------
#ifndef COMMON_SG_H
#define COMMON_SG_H
-#include <string>
-
#include "stg/servconf.h"
#include "request.h"
+#include <string>
+
void UsageConf();
void UsageInfo();
void ConvertFromKOI8(const std::string & src, std::string * dst);
void ConvertToKOI8(const std::string & src, std::string * dst);
-int ProcessGetUser(const std::string &server,
- int port,
- const std::string &admLogin,
- const std::string &admPasswd,
- const std::string &login,
- void * data);
+bool ProcessGetUser(const std::string & server,
+ int port,
+ const std::string & admLogin,
+ const std::string & admPasswd,
+ const std::string & login,
+ REQUEST & request);
-int ProcessSetUser(const std::string &server,
+bool ProcessAuthBy(const std::string & server,
int port,
- const std::string &admLogin,
- const std::string &admPasswd,
- const std::string &str,
- void * data,
- bool isMessage = false);
+ const std::string & admLogin,
+ const std::string & admPasswd,
+ const std::string & login);
-#endif
+bool ProcessSetUser(const std::string & server,
+ int port,
+ const std::string & admLogin,
+ const std::string & admPasswd,
+ const std::string & str);
+bool ProcessSendMessage(const std::string & server, uint16_t port,
+ const std::string & login, const std::string & password,
+ const std::string & requestString);
+
+#endif
#include "common_sg.h"
#include "sg_error_codes.h"
-using namespace std;
+namespace
+{
+
+template <typename T>
+struct ARRAY_TYPE;
+
+template <typename T>
+struct ARRAY_TYPE<T[]>
+{
+typedef T type;
+};
+
+template <typename T, size_t N>
+struct ARRAY_TYPE<T[N]>
+{
+typedef T type;
+};
+
+template <typename T>
+bool SetArrayItem(T & array, const char * index, const typename ARRAY_TYPE<T>::type & value)
+{
+size_t pos = 0;
+if (str2x(index, pos))
+ return false;
+array[pos] = value;
+return true;
+}
+
+} // namespace anonymous
time_t stgTime;
{"passive", 0, 0, 'i'}, //passive
{"disable-stat",0, 0, 'S'}, //disable detail stat
{"always-online",0, 0, 'O'}, //always online
-{"u0", 0, 0, 500}, //U0
-{"u1", 0, 0, 501}, //U1
-{"u2", 0, 0, 502}, //U2
-{"u3", 0, 0, 503}, //U3
-{"u4", 0, 0, 504}, //U4
-{"u5", 0, 0, 505}, //U5
-{"u6", 0, 0, 506}, //U6
-{"u7", 0, 0, 507}, //U7
-{"u8", 0, 0, 508}, //U8
-{"u9", 0, 0, 509}, //U9
-{"d0", 0, 0, 600}, //D0
-{"d1", 0, 0, 601}, //D1
-{"d2", 0, 0, 602}, //D2
-{"d3", 0, 0, 603}, //D3
-{"d4", 0, 0, 604}, //D4
-{"d5", 0, 0, 605}, //D5
-{"d6", 0, 0, 606}, //D6
-{"d7", 0, 0, 607}, //D7
-{"d8", 0, 0, 608}, //D8
-{"d9", 0, 0, 609}, //D9
-
-{"ud0", 0, 0, 700}, //UserData0
-{"ud1", 0, 0, 701}, //UserData1
-{"ud2", 0, 0, 702}, //UserData2
-{"ud3", 0, 0, 703}, //UserData3
-{"ud4", 0, 0, 704}, //UserData4
-{"ud5", 0, 0, 705}, //UserData5
-{"ud6", 0, 0, 706}, //UserData6
-{"ud7", 0, 0, 707}, //UserData7
-{"ud8", 0, 0, 708}, //UserData8
-{"ud9", 0, 0, 709}, //UserData9
+{"session-upload", 1, 0, 500}, //SU0
+{"session-download", 1, 0, 501}, //SD0
+{"month-upload", 1, 0, 502}, //MU0
+{"month-download", 1, 0, 503}, //MD0
+
+{"user-data", 1, 0, 700}, //UserData0
{"prepaid", 0, 0, 'e'}, //prepaid traff
{"create", 0, 0, 'n'}, //create
{"email", 0, 0, 'L'}, //emaiL
{"phone", 0, 0, 'P'}, //phone
{"group", 0, 0, 'G'}, //Group
-{"ip", 0, 0, 'I'}, //IP-address of user
+{"ip", 0, 0, 'I'}, //IP-address of user
+{"authorized-by",0, 0, 800}, //always online
{0, 0, 0, 0}};
{"passive", 1, 0, 'i'}, //passive
{"disable-stat",1, 0, 'S'}, //disable detail stat
{"always-online",1, 0, 'O'}, //always online
-{"u0", 1, 0, 500}, //U0
-{"u1", 1, 0, 501}, //U1
-{"u2", 1, 0, 502}, //U2
-{"u3", 1, 0, 503}, //U3
-{"u4", 1, 0, 504}, //U4
-{"u5", 1, 0, 505}, //U5
-{"u6", 1, 0, 506}, //U6
-{"u7", 1, 0, 507}, //U7
-{"u8", 1, 0, 508}, //U8
-{"u9", 1, 0, 509}, //U9
-{"d0", 1, 0, 600}, //D0
-{"d1", 1, 0, 601}, //D1
-{"d2", 1, 0, 602}, //D2
-{"d3", 1, 0, 603}, //D3
-{"d4", 1, 0, 604}, //D4
-{"d5", 1, 0, 605}, //D5
-{"d6", 1, 0, 606}, //D6
-{"d7", 1, 0, 607}, //D7
-{"d8", 1, 0, 608}, //D8
-{"d9", 1, 0, 609}, //D9
-
-{"ud0", 1, 0, 700}, //UserData
-{"ud1", 1, 0, 701}, //UserData1
-{"ud2", 1, 0, 702}, //UserData2
-{"ud3", 1, 0, 703}, //UserData3
-{"ud4", 1, 0, 704}, //UserData4
-{"ud5", 1, 0, 705}, //UserData5
-{"ud6", 1, 0, 706}, //UserData6
-{"ud7", 1, 0, 707}, //UserData7
-{"ud8", 1, 0, 708}, //UserData8
-{"ud9", 1, 0, 709}, //UserData9
+{"session-upload", 1, 0, 500}, //U0
+{"session-download", 1, 0, 501}, //U1
+{"month-upload", 1, 0, 502}, //U2
+{"month-download", 1, 0, 503}, //U3
+
+{"user-data", 1, 0, 700}, //UserData
{"prepaid", 1, 0, 'e'}, //prepaid traff
{"create", 1, 0, 'n'}, //create
int dPresent = false;
for (int i = 0; i < DIR_NUM; i++)
{
- if (!req->u[i].res_empty())
+ if (!req->monthUpload[i].res_empty())
+ {
+ if (!uPresent && !dPresent)
+ {
+ sprintf(str, "<traff ");
+ strcat(r, str);
+ uPresent = true;
+ }
+
+ stringstream ss;
+ ss << req->monthUpload[i].const_data();
+ //sprintf(str, "MU%d=\"%lld\" ", i, req->u[i].const_data());
+ sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str());
+ strcat(r, str);
+ }
+ if (!req->monthDownload[i].res_empty())
+ {
+ if (!uPresent && !dPresent)
+ {
+ sprintf(str, "<traff ");
+ strcat(r, str);
+ dPresent = true;
+ }
+
+ stringstream ss;
+ ss << req->monthDownload[i].const_data();
+ sprintf(str, "MD%d=\"%s\" ", i, ss.str().c_str());
+ strcat(r, str);
+ }
+ if (!req->sessionUpload[i].res_empty())
{
if (!uPresent && !dPresent)
{
}
stringstream ss;
- ss << req->u[i].const_data();
+ ss << req->sessionUpload[i].const_data();
//sprintf(str, "MU%d=\"%lld\" ", i, req->u[i].const_data());
sprintf(str, "MU%d=\"%s\" ", i, ss.str().c_str());
strcat(r, str);
}
- if (!req->d[i].res_empty())
+ if (!req->sessionDownload[i].res_empty())
{
if (!uPresent && !dPresent)
{
}
stringstream ss;
- ss << req->d[i].const_data();
+ ss << req->sessionDownload[i].const_data();
sprintf(str, "MD%d=\"%s\" ", i, ss.str().c_str());
strcat(r, str);
}
for (int i = 0; i < USERDATA_NUM; i++)
{
- if (!req->ud[i].res_empty())
+ if (!req->userData[i].res_empty())
{
string ud;
- Encode12str(ud, req->ud[i]);
+ Encode12str(ud, req->userData[i]);
sprintf(str, "<userdata%d value=\"%s\"/>", i, ud.c_str());
strcat(r, str);
}
//-----------------------------------------------------------------------------
int CheckParameters(REQUEST * req)
{
-int u = false;
-int d = false;
-int ud = false;
-int a = !req->admLogin.res_empty()
+bool su = false;
+bool sd = false;
+bool mu = false;
+bool md = false;
+bool ud = false;
+bool a = !req->admLogin.res_empty()
&& !req->admPasswd.res_empty()
&& !req->server.res_empty()
&& !req->port.res_empty()
&& !req->login.res_empty();
-int b = !req->cash.res_empty()
+bool b = !req->cash.res_empty()
|| !req->setCash.res_empty()
|| !req->credit.res_empty()
|| !req->prepaidTraff.res_empty()
for (int i = 0; i < DIR_NUM; i++)
{
- if (req->u[i].res_empty())
+ if (req->sessionUpload[i].res_empty())
{
- u = true;
+ su = true;
break;
}
}
for (int i = 0; i < DIR_NUM; i++)
{
- if (req->d[i].res_empty())
+ if (req->sessionDownload[i].res_empty())
{
- d = true;
+ sd = true;
break;
}
}
for (int i = 0; i < DIR_NUM; i++)
{
- if (req->ud[i].res_empty())
+ if (req->monthUpload[i].res_empty())
+ {
+ mu = true;
+ break;
+ }
+ }
+
+for (int i = 0; i < DIR_NUM; i++)
+ {
+ if (req->monthDownload[i].res_empty())
+ {
+ md = true;
+ break;
+ }
+ }
+
+for (int i = 0; i < DIR_NUM; i++)
+ {
+ if (req->userData[i].res_empty())
{
ud = true;
break;
//printf("a=%d, b=%d, u=%d, d=%d ud=%d\n", a, b, u, d, ud);
-return a && (b || u || d || ud);
+return a && (b || su || sd || mu || md || ud);
}
//-----------------------------------------------------------------------------
int CheckParametersGet(REQUEST * req)
return CheckParameters(req);
}
//-----------------------------------------------------------------------------
-int mainGet(int argc, char **argv)
+bool mainGet(int argc, char **argv)
{
int c;
REQUEST req;
case 'G': //Group
req.group = " ";
break;
-
- case 'I': //IP-address of user
- req.ips = " ";
- break;
+
+ case 'I': //IP-address of user
+ req.ips = " ";
+ break;
case 'S': //Detail stat status
req.disableDetailStat = " ";
break;
case 500: //U
+ SetArrayItem(req.sessionUpload, optarg, 1);
+ //req.sessionUpload[optarg] = 1;
+ break;
case 501:
+ SetArrayItem(req.sessionDownload, optarg, 1);
+ //req.sessionDownload[optarg] = 1;
+ break;
case 502:
+ SetArrayItem(req.monthUpload, optarg, 1);
+ //req.monthUpload[optarg] = 1;
+ break;
case 503:
- case 504:
- case 505:
- case 506:
- case 507:
- case 508:
- case 509:
- //printf("U%d\n", c - 500);
- req.u[c - 500] = 1;
- break;
-
- case 600: //D
- case 601:
- case 602:
- case 603:
- case 604:
- case 605:
- case 606:
- case 607:
- case 608:
- case 609:
- //printf("D%d\n", c - 600);
- req.d[c - 600] = 1;
+ SetArrayItem(req.monthDownload, optarg, 1);
+ //req.monthDownload[optarg] = 1;
break;
case 700: //UserData
- case 701:
- case 702:
- case 703:
- case 704:
- case 705:
- case 706:
- case 707:
- case 708:
- case 709:
- //printf("UD%d\n", c - 700);
- req.ud[c - 700] = " ";
+ SetArrayItem(req.userData, optarg, std::string(" "));
+ //req.userData[optarg] = " ";
+ break;
+
+ case 800:
+ req.authBy = true;
break;
case '?':
case ':':
- //printf ("Unknown option \n");
missedOptionArg = true;
break;
exit(PARAMETER_PARSING_ERR_CODE);
}
-return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, &req);
+if (req.authBy)
+ return ProcessAuthBy(req.server, req.port, req.admLogin, req.admPasswd, req.login);
+else
+ return ProcessGetUser(req.server, req.port, req.admLogin, req.admPasswd, req.login, req);
}
//-----------------------------------------------------------------------------
-int mainSet(int argc, char **argv)
+bool mainSet(int argc, char **argv)
{
string str;
break;
case 500: //U
+ SetArrayItem(req.sessionUpload, optarg, ParseTraff(argv[optind++]));
+ //req.sessionUpload[optarg] = ParseTraff(argv[optind++]);
+ break;
case 501:
+ SetArrayItem(req.sessionDownload, optarg, ParseTraff(argv[optind++]));
+ //req.sessionDownload[optarg] = ParseTraff(argv[optind++]);
+ break;
case 502:
+ SetArrayItem(req.monthUpload, optarg, ParseTraff(argv[optind++]));
+ //req.monthUpload[optarg] = ParseTraff(argv[optind++]);
+ break;
case 503:
- case 504:
- case 505:
- case 506:
- case 507:
- case 508:
- case 509:
- //printf("U%d\n", c - 500);
- req.u[c - 500] = ParseTraff(optarg);
- break;
-
- case 600: //D
- case 601:
- case 602:
- case 603:
- case 604:
- case 605:
- case 606:
- case 607:
- case 608:
- case 609:
- //printf("D%d\n", c - 600);
- req.d[c - 600] = ParseTraff(optarg);
+ SetArrayItem(req.monthDownload, optarg, ParseTraff(argv[optind++]));
+ //req.monthDownload[optarg] = ParseTraff(argv[optind++]);
break;
case 700: //UserData
- case 701:
- case 702:
- case 703:
- case 704:
- case 705:
- case 706:
- case 707:
- case 708:
- case 709:
- ParseAnyString(optarg, &str);
- //printf("UD%d\n", c - 700);
- req.ud[c - 700] = str;
+ ParseAnyString(argv[optind++], &str);
+ SetArrayItem(req.userData, optarg, str);
+ //req.userData[optarg] = str;
break;
case '?':
- //printf("Missing option argument\n");
missedOptionArg = true;
break;
case ':':
- //printf("Missing option argument\n");
missedOptionArg = true;
break;
memset(rstr, 0, rLen);
CreateRequestSet(&req, rstr);
-return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr, NULL, isMessage);
+if (isMessage)
+ return ProcessSendMessage(req.server, req.port, req.admLogin, req.admPasswd, rstr);
+
+return ProcessSetUser(req.server, req.port, req.admLogin, req.admPasswd, rstr);
}
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
else if (strcmp(argv[1], "set") == 0)
{
//printf("set\n");
- return mainSet(argc - 1, argv + 1);
+ if (mainSet(argc - 1, argv + 1) )
+ return 0;
+ return -1;
}
else
{
REQUEST()
: chgTariff(false),
createUser(false),
- deleteUser(false)
+ deleteUser(false),
+ authBy(false)
{
for (int i = 0; i < DIR_NUM; i++)
{
- u[i].reset();
- d[i].reset();
+ sessionUpload[i].reset();
+ sessionDownload[i].reset();
+ monthUpload[i].reset();
+ monthDownload[i].reset();
}
for (int i = 0; i < USERDATA_NUM; i++)
- ud[i].reset();
+ userData[i].reset();
}
RESETABLE<string> server;
string message;
bool createUser;
bool deleteUser;
+bool authBy;
RESETABLE<string> usrMsg;
RESETABLE<double> credit;
RESETABLE<bool> alwaysOnline;
RESETABLE<double> prepaidTraff;
-RESETABLE<int64_t> u[DIR_NUM];
-RESETABLE<int64_t> d[DIR_NUM];
+RESETABLE<int64_t> sessionUpload[DIR_NUM];
+RESETABLE<int64_t> sessionDownload[DIR_NUM];
-RESETABLE<string> ud[USERDATA_NUM];
+RESETABLE<int64_t> monthUpload[DIR_NUM];
+RESETABLE<int64_t> monthDownload[DIR_NUM];
+
+RESETABLE<string> userData[USERDATA_NUM];
RESETABLE<string> note;
RESETABLE<string> name;
if [ "$OS" = "unknown" ]
then
- echo "#############################################################################"
- echo "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #"
- echo "#############################################################################"
+ printf "#############################################################################\n"
+ printf "# Sorry, but sgconf currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n"
+ printf "#############################################################################\n"
exit 1
fi
-echo "#############################################################################"
-echo " Building sgconf for $sys $release"
-echo "#############################################################################"
+printf "#############################################################################\n"
+printf " Building sgconf for $sys $release\n"
+printf "#############################################################################\n"
STG_LIBS="conffiles.lib
crypto.lib
CXX=g++
fi
-echo -n "Checking CC... "
+printf "Checking CC... "
$CC --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CC not found"
+ printf "FAIL!\n"
+ printf "$CC not found\n"
exit;
fi
-echo "found"
-echo -n "Checking CXX... "
+printf "found\n"
+printf "Checking CXX... "
$CXX --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CXX not found"
+ printf "FAIL!\n"
+ printf "$CXX not found\n"
exit;
fi
-echo "found"
+printf "found\n"
-echo -n "Checking endianess... "
-echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
+printf "Checking endianess... "
+printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "Endianess checking failed"
+ printf "FAIL!\n"
+ printf "Endianess checking failed\n"
exit;
else
./fake
ARCH=le
CXXFLAGS="$CXXFLAGS -DARCH_LE"
CFLAGS="$CFLAGS -DARCH_LE"
- echo "Little Endian"
+ printf "Little Endian\n"
else
ARCH=be
CXXFLAGS="$CXXFLAGS -DARCH_BE"
CFLAGS="$CFLAGS -DARCH_BE"
- echo "Big Endian"
+ printf "Big Endian\n"
fi
fi
rm -f fake
-echo -n "Checking for -lexpat... "
-echo "int main() { return 0; }" > build_check.c
+printf "Checking for -lexpat... "
+printf "int main() { return 0; }\n" > build_check.c
$CC $CXXFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
CHECK_EXPAT=no
- echo "no"
+ printf "no\n"
else
CHECK_EXPAT=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
rm -f build_check.c
if [ "$CHECK_EXPAT" != "yes" ]
then
- echo "-lexpat not found!"
+ printf "-lexpat not found!\n"
exit 1
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 "ARCH=$ARCH" >> $CONFFILE
-echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE
-echo "DEFS=$DEFS" >> $CONFFILE
-echo -n "STG_LIBS=" >> $CONFFILE
+printf "OS=$OS\n" > $CONFFILE
+printf "STG_TIME=yes\n" >> $CONFFILE
+printf "DEBUG=$DEBUG\n" >> $CONFFILE
+printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
+printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
+printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
+printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
+printf "ARCH=$ARCH\n" >> $CONFFILE
+printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
+printf "DEFS=$DEFS\n" >> $CONFFILE
+printf "STG_LIBS=" >> $CONFFILE
for lib in $STG_LIBS
do
- echo -n "$lib " >> $CONFFILE
+ printf "$lib " >> $CONFFILE
done
-echo "" >> $CONFFILE
-echo "LIB_THREAD=$LIB_THREAD" >> $CONFFILE
-echo "CXXFLAGS=$CXXFLAGS" >> $CONFFILE
-echo "CFLAGS=$CFLAGS" >> $CONFFILE
-echo "LDFLAGS=$LDFLAGS" >> $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
+printf "\n" >> $CONFFILE
+printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
+printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
+printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
+printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
+printf "PREFIX=$PREFIX\n" >> $CONFFILE
+printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
+printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
+printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
+printf "OWNER=$OWNER\n" >> $CONFFILE
$MAKE $MAKEOPTS
if [ "$OS" = "unknown" ]
then
- echo "#############################################################################"
- echo "# Sorry, but sgconv currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #"
- echo "#############################################################################"
+ printf "#############################################################################\n"
+ printf "# Sorry, but sgconv currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n"
+ printf "#############################################################################\n"
exit 1
fi
-echo "#############################################################################"
-echo " Building sgconv for $sys $release"
-echo "#############################################################################"
+printf "#############################################################################\n"
+printf " Building sgconv for $sys $release\n"
+printf "#############################################################################\n"
STG_LIBS="logger.lib
locker.lib
CXX=g++
fi
-echo -n "Checking CC... "
+printf "Checking CC... "
$CC --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CC not found"
+ printf "FAIL!\n"
+ printf "$CC not found\n"
exit;
fi
-echo "found"
-echo -n "Checking CXX... "
+printf "found\n"
+printf "Checking CXX... "
$CXX --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CXX not found"
+ printf "FAIL!\n"
+ printf "$CXX not found\n"
exit;
fi
-echo "found"
+printf "found\n"
-echo -n "Checking endianess... "
-echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
+printf "Checking endianess... "
+printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > 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"
+ printf "FAIL!\n"
+ printf "Endianess checking failed\n"
exit;
else
./fake
ARCH=le
CXXFLAGS="$CXXFLAGS -DARCH_LE"
CFLAGS="$CFLAGS -DARCH_LE"
- echo "Little Endian"
+ printf "Little Endian\n"
else
ARCH=be
CXXFLAGS="$CXXFLAGS -DARCH_BE"
CFLAGS="$CFLAGS -DARCH_BE"
- echo "Big Endian"
+ printf "Big Endian\n"
fi
fi
rm -f fake
-echo -n "Checking for -lfbclient... "
+printf "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"
+ printf "no\n"
else
CHECK_FBCLIENT=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
-echo -n "Checking for mysql_config... "
+printf "Checking for mysql_config... "
MYSQL_VERSION=`mysql_config --version 2> /dev/null`
if [ $? != 0 ]
then
- echo "no";
- echo -n "Checking for -lmysqlclient... "
+ printf "no\n";
+ printf "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"
+ printf "no\n"
else
CHECK_MYSQLCLIENT=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
else
- echo "yes"
- echo -n "Checking for mysql_config --cflags... "
+ printf "yes\n"
+ printf "Checking for mysql_config --cflags... "
MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
if [ $? != 0 ]
then
CHECK_MYSQLCLIENT=no
- echo "no"
+ printf "no\n"
else
- echo "[$MYSQL_CFLAGS]"
- echo -n "Checking for mysql_config --libs_r... "
+ printf "[$MYSQL_CFLAGS]\n"
+ printf "Checking for mysql_config --libs_r... "
MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
if [ $? != 0 ]
then
CHECK_MYSQLCLIENT=no
- echo "no"
+ printf "no\n"
else
CHECK_MYSQLCLIENT=yes
- echo "[$MYSQL_LDFLAGS]"
+ printf "[$MYSQL_LDFLAGS]\n"
fi
fi
fi
-echo -n "Checking for pg_config... "
+printf "Checking for pg_config... "
PG_VERSION=`pg_config --version 2> /dev/null`
if [ $? != 0 ]
then
- echo "no";
- echo -n "Checking for -lpq... "
+ printf "no\n";
+ printf "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"
+ printf "no\n"
else
CHECK_PQ=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
else
- echo "yes";
- echo -n "Checking for pg_config --includedir... "
+ printf "yes\n";
+ printf "Checking for pg_config --includedir... "
PG_CFLAGS=`pg_config --includedir 2> /dev/null`
if [ $? != 0 ]
then
CHECK_PQ=no
- echo "no"
+ printf "no\n"
else
- echo "[$PG_CFLAGS]"
- echo -n "Checking for pg_config --libdir... "
+ printf "[$PG_CFLAGS]\n"
+ printf "Checking for pg_config --libdir... "
PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
if [ $? != 0 ]
then
CHECK_PQ=no
- echo "no"
+ printf "no\n"
else
CHECK_PQ=yes
- echo "[$PG_LDFLAGS]"
+ printf "[$PG_LDFLAGS]\n"
fi
fi
fi
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
+printf "OS=$OS\n" > $CONFFILE
+printf "STG_TIME=yes\n" >> $CONFFILE
+printf "DEBUG=$DEBUG\n" >> $CONFFILE
+printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
+printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
+printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
+printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
+printf "DIR_MOD=\$(DIR_BUILD)/../stargazer/modules\n" >> $CONFFILE
+printf "DIR_PLUGINS=\$(DIR_BUILD)/../stargazer/plugins\n" >> $CONFFILE
+printf "ARCH=$ARCH\n" >> $CONFFILE
+printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
+printf "DEFS=$DEFS\n" >> $CONFFILE
+printf "STG_LIBS=" >> $CONFFILE
for lib in $STG_LIBS
do
- echo -n "$lib " >> $CONFFILE
+ printf "$lib " >> $CONFFILE
done
-echo "" >> $CONFFILE
-echo -n "PLUGINS=" >> $CONFFILE
+printf "\n" >> $CONFFILE
+printf "PLUGINS=" >> $CONFFILE
for plugin in $PLUGINS
do
- echo -n "$plugin " >> $CONFFILE
+ printf "$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
+printf "\n" >> $CONFFILE
+printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
+printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
+printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
+printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
+printf "PREFIX=$PREFIX\n" >> $CONFFILE
+printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
+printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
+printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
+printf "OWNER=$OWNER\n" >> $CONFFILE
+printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
mkdir -p ../stargazer/modules
CXXFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
CFLAGS += $(DEFS) $(STGLIBS_INCS) $(SEARCH_DIRS)
+
+ifneq ($(OS),darwin)
LDFLAGS += -Wl,-E $(STGLIBS_LIBS)
+endif
+
+LDFLAGS += $(STGLIBS_LIBS)
.PHONY: all clean distclean libs plugins install uninstall install-bin install-data
all: libs plugins $(PROG)
MAKE="gmake"
fi
+if [ "$sys" = "Darwin" ]
+then
+ OS=darwin
+ ETC_DIR="./inst/freebsd/etc/stargazer"
+ MAKE="gmake"
+fi
+
if [ "$OS" = "unknown" ]
then
- echo "#############################################################################"
- echo "# Sorry, but stargazer currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #"
- echo "#############################################################################"
+ printf "#############################################################################\n"
+ printf "# Sorry, but stargazer currently supported by Linux, FreeBSD 4.x, 5.x, 6.x #\n"
+ printf "#############################################################################\n"
exit 1
fi
-echo "#############################################################################"
-echo " Building STG 2.4 for $sys $release"
-echo "#############################################################################"
+printf "#############################################################################\n"
+printf " Building STG 2.4 for $sys $release\n"
+printf "#############################################################################\n"
STG_LIBS="logger.lib
locker.lib
DEFS="$DEFS -DFREE_BSD"
LIB_THREAD=-lc_r
else
- DEFS="$DEFS -DFREE_BSD5"
if [ "$OS" = "bsd7" ]
then
+ DEFS="$DEFS -DFREE_BSD5"
LIB_THREAD=-lpthread
else
- LIB_THREAD=-lc_r
+ if [ "$OS" == "darwin" ]
+ then
+ DEFS="$DEFS -DDARWIN"
+ LIB_THREAD=-lpthread
+ else
+ LIB_THREAD=-lc_r
+ fi
fi
fi
PLUGINS="$PLUGINS
CXX=g++
fi
-echo -n "Checking CC... "
+printf "Checking CC... "
$CC --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CC not found"
+ printf "FAIL!\n"
+ printf "$CC not found\n"
exit;
fi
-echo "found"
-echo -n "Checking CXX... "
+printf "found\n"
+printf "Checking CXX... "
$CXX --version > /dev/null 2> /dev/null
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "$CXX not found"
+ printf "FAIL!\n"
+ printf "$CXX not found\n"
exit;
fi
-echo "found"
+printf "found\n"
-echo -n "Checking endianess... "
-echo "int main() { int probe = 0x00000001; return *(char *)&probe; }" > build_check.c
+printf "Checking endianess... "
+printf "int main() { int probe = 0x00000001; return *(char *)&probe; }\n" > build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -o fake
if [ $? != 0 ]
then
- echo "FAIL!"
- echo "Endianess checking failed"
+ printf "FAIL!\n"
+ printf "Endianess checking failed\n"
exit;
else
./fake
ARCH=le
CXXFLAGS="$CXXFLAGS -DARCH_LE"
CFLAGS="$CFLAGS -DARCH_LE"
- echo "Little Endian"
+ printf "Little Endian\n"
else
ARCH=be
CXXFLAGS="$CXXFLAGS -DARCH_BE"
CFLAGS="$CFLAGS -DARCH_BE"
- echo "Big Endian"
+ printf "Big Endian\n"
fi
fi
rm -f fake
-echo -n "Checking for -lexpat... "
-echo "int main() { return 0; }" > build_check.c
+printf "Checking for -lexpat... "
+printf "int main() { return 0; }\n" > build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
CHECK_EXPAT=no
- echo "no"
+ printf "no\n"
else
CHECK_EXPAT=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
-echo -n "Checking for -lfbclient... "
+printf "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"
+ printf "no\n"
else
CHECK_FBCLIENT=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
-echo -n "Checking for mysql_config... "
+printf "Checking for mysql_config... "
MYSQL_VERSION=`mysql_config --version 2> /dev/null`
if [ $? != 0 ]
then
- echo "no";
- echo -n "Checking for -lmysqlclient... "
+ printf "no\n";
+ printf "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"
+ printf "no\n"
else
CHECK_MYSQLCLIENT=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
else
- echo "yes"
- echo -n "Checking for mysql_config --cflags... "
+ printf "yes\n"
+ printf "Checking for mysql_config --cflags... "
MYSQL_CFLAGS=`mysql_config --cflags 2> /dev/null`
if [ $? != 0 ]
then
CHECK_MYSQLCLIENT=no
- echo "no"
+ printf "no\n"
else
- echo "[$MYSQL_CFLAGS]"
- echo -n "Checking for mysql_config --libs_r... "
+ printf "[$MYSQL_CFLAGS]\n"
+ printf "Checking for mysql_config --libs_r... "
MYSQL_LDFLAGS=`mysql_config --libs_r 2> /dev/null`
if [ $? != 0 ]
then
CHECK_MYSQLCLIENT=no
- echo "no"
+ printf "no\n"
else
CHECK_MYSQLCLIENT=yes
- echo "[$MYSQL_LDFLAGS]"
+ printf "[$MYSQL_LDFLAGS]\n"
fi
fi
fi
-echo -n "Checking for pg_config... "
+printf "Checking for pg_config... "
PG_VERSION=`pg_config --version 2> /dev/null`
if [ $? != 0 ]
then
- echo "no";
- echo -n "Checking for -lpq... "
+ printf "no\n";
+ printf "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"
+ printf "no\n"
else
CHECK_PQ=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
else
- echo "yes";
- echo -n "Checking for pg_config --includedir... "
+ printf "yes\n";
+ printf "Checking for pg_config --includedir... "
PG_CFLAGS=`pg_config --includedir 2> /dev/null`
if [ $? != 0 ]
then
CHECK_PQ=no
- echo "no"
+ printf "no\n"
else
- echo "[$PG_CFLAGS]"
- echo -n "Checking for pg_config --libdir... "
+ printf "[$PG_CFLAGS]\n"
+ printf "Checking for pg_config --libdir... "
PG_LDFLAGS=`pg_config --libdir 2> /dev/null`
if [ $? != 0 ]
then
CHECK_PQ=no
- echo "no"
+ printf "no\n"
else
CHECK_PQ=yes
- echo "[$PG_LDFLAGS]"
+ printf "[$PG_LDFLAGS]\n"
fi
fi
fi
-echo -n "Checking for xmlrpc-c-config... "
+printf "Checking for xmlrpc-c-config... "
XMLRPCC_VERSION=`xmlrpc-c-config $XMLRPC_FEATURES --version 2> /dev/null`
if [ $? != 0 ]
then
- echo "no";
- echo -n "Checking for -lxmlrpc... "
+ printf "no\n";
+ printf "Checking for -lxmlrpc... "
$CC $CFLAGS $LDFLAGS build_check.c -lxmlrpc $LIB_THREAD -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
CHECK_XMLRPC=no
- echo "no"
+ printf "no\n"
else
CHECK_XMLRPC=yes
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
elif [ "$XMLRPCC_VERSION" \< "$MIN_XMLRPCC_VERSION" ]
then
- echo "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)";
+ printf "no (need at least $MIN_XMLRPCC_VERSION, actual $XMLRPCC_VERSION)\n";
CHECK_XMLRPC=no
else
- echo "yes (version $XMLRPCC_VERSION)";
- echo -n "Checking for xmlrpc-c-config --cflags... "
+ printf "yes (version $XMLRPCC_VERSION)\n";
+ printf "Checking for xmlrpc-c-config --cflags... "
XMLRPC_CFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --cflags 2> /dev/null`
if [ $? != 0 ]
then
CHECK_XMLRPC=no
- echo "no"
+ printf "no\n"
else
- echo "[$XMLRPC_CFLAGS]"
- echo -n "Checking for xmlrpc-c-config --libs... "
+ printf "[$XMLRPC_CFLAGS]\n"
+ printf "Checking for xmlrpc-c-config --libs... "
XMLRPC_LDFLAGS=`xmlrpc-c-config $XMLRPC_FEATURES --libs 2> /dev/null`
if [ $? != 0 ]
then
CHECK_XMLRPC=no
- echo "no"
+ printf "no\n"
else
CHECK_XMLRPC=yes
- echo "[$XMLRPC_LDFLAGS]"
+ printf "[$XMLRPC_LDFLAGS]\n"
fi
fi
fi
if [ "$OS" = "linux" ]
then
- echo -n "Checking for linux/netfilter_ipv4/ip_queue.h... "
- echo "#include <linux/types.h>" > build_check.c
- echo "#include <linux/netfilter_ipv4/ip_queue.h>" >> build_check.c
- echo "int main() { return 0; }" >> build_check.c
+ printf "Checking for linux/netfilter_ipv4/ip_queue.h... "
+ printf "#include <linux/types.h>\n" > build_check.c
+ printf "#include <linux/netfilter_ipv4/ip_queue.h>\n" >> build_check.c
+ printf "int main() { return 0; }\n" >> build_check.c
$CC $CFLAGS $LDFLAGS build_check.c -lexpat -o fake > /dev/null 2> /dev/null
if [ $? != 0 ]
then
CHECK_IP_QUEUE_H=no
- echo "no"
+ printf "no\n"
else
CHECK_IP_QUEUE_H=yes
DEFS="$DEFS -DHAS_IP_QUEUE_H"
PLUGINS="$PLUGINS
capture/ipq_linux"
- echo "yes"
+ printf "yes\n"
fi
rm -f fake
fi
if [ "$CHECK_EXPAT" != "yes" ]
then
- echo "-lexpat not found!"
+ printf "-lexpat not found!\n"
exit 1
fi
configuration/rpcconfig"
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)/modules" >> $CONFFILE
-echo "DIR_PLUGINS=\$(DIR_BUILD)/plugins" >> $CONFFILE
-echo "ARCH=$ARCH" >> $CONFFILE
-echo "CHECK_EXPAT=$CHECK_EXPAT" >> $CONFFILE
-echo "CHECK_FBCLIENT=$CHECK_FBCLIENT" >> $CONFFILE
-echo "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT" >> $CONFFILE
-echo "CHECK_PQ=$CHECK_PQ" >> $CONFFILE
-echo "CHECK_XMLRPC=$CHECK_XMLRPC" >> $CONFFILE
-echo "DEFS=$DEFS" >> $CONFFILE
-echo -n "STG_LIBS=" >> $CONFFILE
+printf "OS=$OS\n" > $CONFFILE
+printf "STG_TIME=yes\n" >> $CONFFILE
+printf "DEBUG=$DEBUG\n" >> $CONFFILE
+printf "DIR_BUILD=$BUILD_DIR\n" >> $CONFFILE
+printf "DIR_LIB=\$(DIR_BUILD)/../../lib\n" >> $CONFFILE
+printf "DIR_LIBSRC=\$(DIR_BUILD)/../../stglibs\n" >> $CONFFILE
+printf "DIR_INCLUDE=\$(DIR_BUILD)/../../include\n" >> $CONFFILE
+printf "DIR_MOD=\$(DIR_BUILD)/modules\n" >> $CONFFILE
+printf "DIR_PLUGINS=\$(DIR_BUILD)/plugins\n" >> $CONFFILE
+printf "ARCH=$ARCH\n" >> $CONFFILE
+printf "CHECK_EXPAT=$CHECK_EXPAT\n" >> $CONFFILE
+printf "CHECK_FBCLIENT=$CHECK_FBCLIENT\n" >> $CONFFILE
+printf "CHECK_MYSQLCLIENT=$CHECK_MYSQLCLIENT\n" >> $CONFFILE
+printf "CHECK_PQ=$CHECK_PQ\n" >> $CONFFILE
+printf "CHECK_XMLRPC=$CHECK_XMLRPC\n" >> $CONFFILE
+printf "DEFS=$DEFS\n" >> $CONFFILE
+printf "STG_LIBS=" >> $CONFFILE
for lib in $STG_LIBS
do
- echo -n "$lib " >> $CONFFILE
+ printf "$lib " >> $CONFFILE
done
-echo "" >> $CONFFILE
-echo -n "PLUGINS=" >> $CONFFILE
+printf "\n" >> $CONFFILE
+printf "PLUGINS=" >> $CONFFILE
for plugin in $PLUGINS
do
- echo -n "$plugin " >> $CONFFILE
+ printf "$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
-echo "ETC_DIR=$ETC_DIR" >> $CONFFILE
+printf "\n" >> $CONFFILE
+printf "CXXFLAGS=$CXXFLAGS\n" >> $CONFFILE
+printf "CFLAGS=$CFLAGS\n" >> $CONFFILE
+printf "LDFLAGS=$LDFLAGS\n" >> $CONFFILE
+printf "LIB_THREAD=$LIB_THREAD\n" >> $CONFFILE
+printf "PREFIX=$PREFIX\n" >> $CONFFILE
+printf "BIN_MODE=$BIN_MODE\n" >> $CONFFILE
+printf "DATA_MODE=$DATA_MODE\n" >> $CONFFILE
+printf "DIR_MODE=$DIR_MODE\n" >> $CONFFILE
+printf "OWNER=$OWNER\n" >> $CONFFILE
+printf "VAR_DIR=$VAR_DIR\n" >> $CONFFILE
+printf "ETC_DIR=$ETC_DIR\n" >> $CONFFILE
mkdir -p modules
then
$MAKE $MAKEOPTS
else
- echo -e "\n\n\nDebug build. Type $MAKE explicitly"
+ printf "\n\n\nDebug build. Type $MAKE explicitly\n"
fi
}
}
//-----------------------------------------------------------------------------
-#ifdef LINUX
+#if defined(LINUX) || defined(DARWIN)
int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings)
#else
int StartScriptExecuter(char *, int msgKey, int * msgID, SETTINGS_IMPL * settings)
case 0:
delete settings;
-#ifdef LINUX
+#if defined(LINUX) || defined(DARWIN)
Executer(*msgID, executerPid, procName);
#else
Executer(*msgID, executerPid);
default:
if (executersPid.empty()) {
-#ifdef LINUX
+#if defined(LINUX) || defined(DARWIN)
Executer(*msgID, executerPid, NULL);
#else
Executer(*msgID, executerPid);
LN = ln
STGLIBS_INCS = $(addprefix -I ../../../../../stglibs/,$(addsuffix .lib/include,$(STGLIBS)))
-STGLIBS_LIBS = $(addprefix -L ../../../../../stglibs/,$(addsuffix .lib,$(STGLIBS)))
+STGLIBS_PATHS = $(addprefix -L ../../../../../stglibs/,$(addsuffix .lib,$(STGLIBS)))
-LIBS += $(addprefix -lstg,$(STGLIBS))
+STGLIBS_LIBS = $(addprefix -lstg,$(STGLIBS))
CXXFLAGS += -fPIC $(STGLIBS_INCS)
CFLAGS += -fPIC $(STGLIBS_INCS)
+
+ifneq ($(OS),darwin)
LDFLAGS += -shared -Wl,-rpath,$(PREFIX)/usr/lib/stg
+else
+LDFLAGS += -dynamiclib -undefined suppress -flat_namespace -Wl,-rpath,$(PREFIX)/usr/lib/stg
+endif
all: $(PROG)
$(PROG): $(OBJS)
- $(CXX) $^ $(STGLIBS_LIBS) $(LIBS) $(LDFLAGS) -o $(PROG)
+ $(CXX) $^ $(STGLIBS_PATHS) $(STGLIBS_LIBS) $(LIBS) $(LDFLAGS) -o $(PROG)
$(LN) -fs "`pwd`/$(PROG)" $(DIR_MOD)/$(PROG)
clean:
SRCS = ./ao.cpp
-STGLIBS = common \
+STGLIBS = scriptexecuter \
logger \
locker \
- scriptexecuter
+ common
include ../../Makefile.in
if (bd->fd < 0)
{
errorStr = "Can't capture packets. Open bpf device for " + bd->iface + " error.";
- logger("Cannot open device for interface '%s': %s", bd->iface, strerror(errno));
+ logger("Cannot open device for interface '%s': %s", bd->iface.c_str(), strerror(errno));
printfd(__FILE__, "Cannot open BPF device\n");
return -1;
}
if (ioctl(bd->fd, BIOCSBLEN, (caddr_t)&l) < 0)
{
errorStr = bd->iface + " BIOCSBLEN " + std::string(strerror(errno));
- logger("ioctl (BIOCSBLEN) error for interface '%s': %s", db->iface, strerror(errno));
+ logger("ioctl (BIOCSBLEN) error for interface '%s': %s", bd->iface.c_str(), strerror(errno));
printfd(__FILE__, "ioctl failed: '%s'\n", errorStr.c_str());
return -1;
}
if (ioctl(bd->fd, BIOCSETIF, (caddr_t)&ifr) < 0)
{
errorStr = bd->iface + " BIOCSETIF " + std::string(strerror(errno));
- logger("ioctl (BIOCSETIF) error for interface '%s': %s", db->iface, strerror(errno));
+ logger("ioctl (BIOCSETIF) error for interface '%s': %s", bd->iface.c_str(), strerror(errno));
printfd(__FILE__, "ioctl failed: '%s'\n", errorStr.c_str());
return -1;
}
if (ioctl(bd->fd, BIOCIMMEDIATE, &im) < 0)
{
errorStr = bd->iface + " BIOCIMMEDIATE " + std::string(strerror(errno));
- logger("ioctl (BIOCIMMEDIATE) error for interface '%s': %s", db->iface, strerror(errno));
+ logger("ioctl (BIOCIMMEDIATE) error for interface '%s': %s", bd->iface.c_str(), strerror(errno));
printfd(__FILE__, "ioctl failed: '%s'\n", errorStr.c_str());
return -1;
}
users
));
rpcRegistry.addMethod("stargazer.get_online_ips", methodGetOnlinIPsPtr);
+
+xmlrpc_c::methodPtr const methodGetUserAuthByPtr(new METHOD_GET_USER_AUTH_BY(
+ this,
+ users
+ ));
+rpcRegistry.addMethod("stargazer.get_user_auth_by", methodGetUserAuthByPtr);
}
{
USER_IPS ips;
ips = StrToIPS(xmlrpc_c::value_string(it->second));
+
+ for (size_t i = 0; i < ips.Count(); ++i)
+ {
+ CONST_USER_PTR user;
+ uint32_t ip = ips[i].ip;
+ if (users.IsIPInUse(ip, login, &user))
+ {
+ printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
+ return true;
+ }
+ }
+
if (!ptr->GetProperty().ips.Set(ips,
admin,
login,
class USER_HELPER
{
public:
- USER_HELPER(USER_PTR & p)
- : ptr(p)
+ USER_HELPER(USER_PTR & p, USERS & us)
+ : ptr(p),
+ users(us)
{
}
TARIFFS * tariffs);
private:
USER_PTR & ptr;
+ USERS & users;
};
#endif
return;
}
-USER_HELPER uhelper(u);
+USER_HELPER uhelper(u, *users);
if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd)
{
xmlrpc_c::value info;
- USER_HELPER uhelper(u);
+ USER_HELPER uhelper(u, *users);
uhelper.GetUserInfo(&info, hidePassword);
return;
}
-USER_HELPER uhelper(u);
+USER_HELPER uhelper(u, *users);
if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd)
{
return false;
}
+
+void METHOD_GET_USER_AUTH_BY::execute(xmlrpc_c::paramList const & paramList,
+ xmlrpc_c::value * const retvalPtr)
+{
+std::string cookie = paramList.getString(0);
+std::string login = paramList.getString(1);
+paramList.verifyEnd(2);
+
+std::map<std::string, xmlrpc_c::value> structVal;
+ADMIN_INFO adminInfo;
+
+if (config->GetAdminInfo(cookie, &adminInfo))
+ {
+ structVal["result"] = xmlrpc_c::value_boolean(false);
+ *retvalPtr = xmlrpc_c::value_struct(structVal);
+ return;
+ }
+
+USER_PTR u;
+
+if (users->FindByName(login, &u))
+ {
+ structVal["result"] = xmlrpc_c::value_boolean(false);
+ *retvalPtr = xmlrpc_c::value_struct(structVal);
+ return;
+ }
+
+std::vector<std::string> list(u->GetAuthorizers());
+std::vector<xmlrpc_c::value> authList;
+for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
+ authList.push_back(xmlrpc_c::value_string(*it));
+*retvalPtr = xmlrpc_c::value_array(authList);
+}
bool ParseNet(const std::string & net, IP_MASK & ipm) const;
};
+class METHOD_GET_USER_AUTH_BY : public xmlrpc_c::method {
+public:
+ METHOD_GET_USER_AUTH_BY(RPC_CONFIG * c,
+ USERS * u)
+ : config(c),
+ users(u)
+ {
+ }
+
+ void execute(xmlrpc_c::paramList const & paramList,
+ xmlrpc_c::value * const retvalP);
+
+private:
+ METHOD_GET_USER_AUTH_BY(const METHOD_GET_ONLINE_IPS & rvalue);
+ METHOD_GET_USER_AUTH_BY & operator=(const METHOD_GET_ONLINE_IPS & rvalue);
+
+ RPC_CONFIG * config;
+ USERS * users;
+};
+
#endif
./configproto.cpp \
./parser.cpp \
./parser_tariff.cpp \
- ./parser_admin.cpp
+ ./parser_admin.cpp \
+ ./parser_auth_by.cpp \
+ ./parser_user_info.cpp
LIBS += -lexpat \
$(LIB_THREAD)
$Author: faust $
*/
+#include "configproto.h"
#include <unistd.h>
-#include "configproto.h"
-
//-----------------------------------------------------------------------------
void ParseXMLStart(void *data, const char *el, const char **attr)
{
}
//-----------------------------------------------------------------------------
CONFIGPROTO::CONFIGPROTO(PLUGIN_LOGGER & l)
- : answerList(),
- requestList(),
- adminIP(0),
- adminLogin(),
- adminPassword(),
+ : adminIP(0),
port(0),
- thrReciveSendConf(),
nonstop(true),
state(0),
currAdmin(NULL),
logger(l),
listenSocket(-1),
- parserGetServInfo(),
- parserGetUsers(),
- parserGetUser(),
- parserChgUser(),
- parserAddUser(),
- parserDelUser(),
- parserCheckUser(),
- parserSendMessage(),
- parserGetAdmins(),
- parserAddAdmin(),
- parserDelAdmin(),
- parserChgAdmin(),
- parserGetTariffs(),
- parserAddTariff(),
- parserDelTariff(),
- parserChgTariff(),
admins(NULL),
- currParser(NULL),
- dataParser(),
- xmlParser(),
- errorStr()
+ currParser(NULL)
{
dataParser.push_back(&parserGetServInfo);
dataParser.push_back(&parserDelUser);
dataParser.push_back(&parserCheckUser);
dataParser.push_back(&parserSendMessage);
+dataParser.push_back(&parserAuthBy);
+dataParser.push_back(&parserUserInfo);
dataParser.push_back(&parserGetTariffs);
dataParser.push_back(&parserAddTariff);
return 0;
}
//-----------------------------------------------------------------------------
-void CONFIGPROTO::SetPort(uint16_t p)
-{
-port = p;
-}
-//-----------------------------------------------------------------------------
void CONFIGPROTO::SetAdmins(ADMINS * a)
{
admins = a;
for (size_t i = 0; i < dataParser.size(); i++)
- {
dataParser[i]->SetAdmins(a);
- }
-
}
//-----------------------------------------------------------------------------
void CONFIGPROTO::SetUsers(USERS * u)
{
for (size_t i = 0; i < dataParser.size(); i++)
- {
dataParser[i]->SetUsers(u);
- }
-
}
//-----------------------------------------------------------------------------
void CONFIGPROTO::SetTariffs(TARIFFS * t)
{
for (size_t i = 0; i < dataParser.size(); i++)
- {
dataParser[i]->SetTariffs(t);
- }
}
//-----------------------------------------------------------------------------
void CONFIGPROTO::SetStore(STORE * s)
{
for (size_t i = 0; i < dataParser.size(); i++)
- {
dataParser[i]->SetStore(s);
- }
}
//-----------------------------------------------------------------------------
void CONFIGPROTO::SetStgSettings(const SETTINGS * s)
{
for (size_t i = 0; i < dataParser.size(); i++)
- {
dataParser[i]->SetStgSettings(s);
- }
}
//-----------------------------------------------------------------------------
#ifndef CONFIGPROTO_H
#define CONFIGPROTO_H
-#include <expat.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <string>
-#include <list>
+#include "parser_auth_by.h"
+#include "parser_user_info.h"
#include "stg/users.h"
#include "stg/admins.h"
#include "stg/logger.h"
#include "parser.h"
+#include <string>
+#include <list>
+
+#include <expat.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
#define STG_HEADER "SG04"
#define OK_HEADER "OKHD"
#define ERR_HEADER "ERHD"
CONFIGPROTO(PLUGIN_LOGGER & l);
~CONFIGPROTO();
- void SetPort(uint16_t port);
+ void SetPort(uint16_t p) { port = p; }
void SetAdmins(ADMINS * a);
void SetUsers(USERS * u);
void SetTariffs(TARIFFS * t);
PARSER_DEL_USER parserDelUser;
PARSER_CHECK_USER parserCheckUser;
PARSER_SEND_MESSAGE parserSendMessage;
+ PARSER_AUTH_BY parserAuthBy;
+ PARSER_USER_INFO parserUserInfo;
PARSER_GET_ADMINS parserGetAdmins;
PARSER_ADD_ADMIN parserAddAdmin;
if (users->FindByName(login, &u))
{
- s = "<user result=\"error\"/>";
- answerList->push_back(s);
+ answerList->push_back("<user result=\"error\" reason=\"User not found.\"/>");
return;
}
strprintf(&s, "<CreditExpire value=\"%ld\" />", u->GetProperty().creditExpire.Get());
answerList->push_back(s);
+s = "<AuthorizedBy>";
+std::vector<std::string> list(u->GetAuthorizers());
+for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
+ s += "<Auth name=\"" + *it + "\"/>";
+s += "</AuthorizedBy>";
+answerList->push_back(s);
+
strprintf(&s, "</user>");
answerList->push_back(s);
}
{
printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n");
GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", currAdmin->GetLogStr().c_str());
+ res = -1;
return -1;
}
+for (size_t i = 0; i < ucr->ips.const_data().Count(); ++i)
+ {
+ CONST_USER_PTR user;
+ uint32_t ip = ucr->ips.const_data().operator[](i).ip;
+ if (users->IsIPInUse(ip, login, &user))
+ {
+ printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
+ GetStgLogger()("%s trying to assign an IP %s to '%s' that is currently in use by '%s'", currAdmin->GetLogStr().c_str(), inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
+ res = -1;
+ return -1;
+ }
+ }
+
if (!ucr->ips.res_empty())
if (!u->GetProperty().ips.Set(ucr->ips.const_data(), currAdmin, login, store))
res = -1;
break;
case res_params_error:
printfd(__FILE__, "res_params_error\n");
- answerList->push_back("<SendMessageResult value=\"Parameters error\"/>");
+ answerList->push_back("<SendMessageResult value=\"Parameters error.\"/>");
break;
case res_unknown:
printfd(__FILE__, "res_unknown\n");
- answerList->push_back("<SendMessageResult value=\"Unknown user\"/>");
+ answerList->push_back("<SendMessageResult value=\"Unknown user.\"/>");
break;
default:
printfd(__FILE__, "res_default\n");
answerList->push_back("<DelUser value=\"ok\"/>");
}
//-----------------------------------------------------------------------------
-/*void PARSERDELUSER::CreateAnswer(char * mes)
-{
-//answerList->clear();
-answerList->erase(answerList->begin(), answerList->end());
-
-char str[255];
-sprintf(str, "<DelUser value=\"%s\"/>", mes);
-answerList->push_back(str);
-}*/
-//-----------------------------------------------------------------------------
// CHECK USER
// <checkuser login="vasya" password=\"123456\"/>
//-----------------------------------------------------------------------------
int PARSER_CHECK_USER::ParseStart(void *, const char *el, const char **attr)
{
-result = false;
-
if (strcasecmp(el, "CheckUser") == 0)
{
if (attr[0] == NULL || attr[1] == NULL
|| attr[2] == NULL || attr[3] == NULL)
{
- result = false;
- CreateAnswer();
+ CreateAnswer("Invalid parameters.");
printfd(__FILE__, "PARSER_CHECK_USER - attr err\n");
return 0;
}
USER_PTR user;
if (users->FindByName(attr[1], &user))
{
- result = false;
- CreateAnswer();
+ CreateAnswer("User not found.");
printfd(__FILE__, "PARSER_CHECK_USER - login err\n");
return 0;
}
if (strcmp(user->GetProperty().password.Get().c_str(), attr[3]))
{
- result = false;
- CreateAnswer();
+ CreateAnswer("Wrong password.");
printfd(__FILE__, "PARSER_CHECK_USER - passwd err\n");
return 0;
}
- result = true;
- CreateAnswer();
+ CreateAnswer(NULL);
return 0;
}
return -1;
return -1;
}
//-----------------------------------------------------------------------------
-void PARSER_CHECK_USER::CreateAnswer()
+void PARSER_CHECK_USER::CreateAnswer(const char * error)
{
-if (result)
- answerList->push_back("<CheckUser value=\"Ok\"/>");
+if (error)
+ answerList->push_back(std::string("<CheckUser value=\"Err\" reason=\"") + error + "\"/>");
else
- answerList->push_back("<CheckUser value=\"Err\"/>");
+ answerList->push_back("<CheckUser value=\"Ok\"/>");
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
#ifndef PARSER_H
#define PARSER_H
-#include <list>
-#include <string>
-#include <vector>
-
#include "stg/resetable.h"
#include "stg/const.h"
#include "stg/store.h"
#include "stg/users.h"
#include "stg/message.h"
+#include <list>
+#include <string>
+#include <vector>
+
class TARIFFS;
class SETTINGS;
virtual ~BASE_PARSER() {}
virtual int ParseStart(void *data, const char *el, const char **attr) = 0;
virtual int ParseEnd(void *data, const char *el) = 0;
- virtual void CreateAnswer() = 0;
- virtual void SetAnswerList(std::list<std::string> * ansList) { answerList = ansList; }
- virtual void SetUsers(USERS * u) { users = u; }
- virtual void SetAdmins(ADMINS * a) { admins = a; }
- virtual void SetTariffs(TARIFFS * t) { tariffs = t; }
- virtual void SetStore(STORE * s) { store = s; }
- virtual void SetStgSettings(const SETTINGS * s) { settings = s; }
+ void SetAnswerList(std::list<std::string> * ansList) { answerList = ansList; }
+
+ void SetUsers(USERS * u) { users = u; }
+ void SetAdmins(ADMINS * a) { admins = a; }
+ void SetTariffs(TARIFFS * t) { tariffs = t; }
+ void SetStore(STORE * s) { store = s; }
+ void SetStgSettings(const SETTINGS * s) { settings = s; }
- virtual void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; }
- virtual std::string & GetStrError() { return strError; }
- virtual void Reset() { answerList->clear(); depth = 0; }
+ void SetCurrAdmin(ADMIN & cua) { currAdmin = &cua; }
+ std::string & GetStrError() { return strError; }
+ void Reset() { answerList->clear(); depth = 0; }
protected:
BASE_PARSER(const BASE_PARSER & rvalue);
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
+
+private:
void CreateAnswer();
};
//-----------------------------------------------------------------------------
PARSER_ADD_ADMIN() : BASE_PARSER(), adminToAdd() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
+
private:
std::string adminToAdd;
+
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------
class PARSER_DEL_ADMIN: public BASE_PARSER {
PARSER_DEL_ADMIN() : BASE_PARSER(), adminToDel() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
+
private:
- int CheckAttr(const char **attr);
std::string adminToDel;
+
+ int CheckAttr(const char **attr);
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------
class PARSER_CHG_ADMIN: public BASE_PARSER {
PARSER_CHG_ADMIN() : BASE_PARSER(), login(), password(), privAsString() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
+
private:
RESETABLE<std::string> login;
RESETABLE<std::string> password;
RESETABLE<std::string> privAsString;
+
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------
class PARSER_GET_SERVER_INFO: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
+
+private:
void CreateAnswer();
};
//-----------------------------------------------------------------------------
~PARSER_GET_USER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
+
private:
std::string login;
+
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------
class PARSER_GET_USERS: public BASE_PARSER {
PARSER_GET_USERS() : BASE_PARSER(), lastUserUpdateTime(0), lastUpdateFound(false) {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
+
private:
time_t lastUserUpdateTime;
bool lastUpdateFound;
+
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------
class PARSER_GET_TARIFFS: public BASE_PARSER {
public:
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
+
+private:
void CreateAnswer();
};
//-----------------------------------------------------------------------------
PARSER_ADD_TARIFF() : BASE_PARSER(), tariffToAdd() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
+
private:
std::string tariffToAdd;
+
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------
class PARSER_DEL_TARIFF: public BASE_PARSER {
PARSER_DEL_TARIFF() : BASE_PARSER(), tariffToDel() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
+
private:
std::string tariffToDel;
+
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------
class PARSER_CHG_TARIFF: public BASE_PARSER {
PARSER_CHG_TARIFF() : BASE_PARSER(), td() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
+
private:
+ TARIFF_DATA_RES td;
+
int ParseSlashedIntParams(int paramsNum, const std::string & s, int * params);
int ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params);
int CheckTariffData();
int AplayChanges();
-
- TARIFF_DATA_RES td;
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------/
class PARSER_ADD_USER: public BASE_PARSER {
~PARSER_ADD_USER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
- void Reset();
+
private:
- int CheckUserData();
std::string login;
+
+ int CheckUserData();
+ void CreateAnswer();
+ void Reset();
};
//-----------------------------------------------------------------------------
class PARSER_CHG_USER: public BASE_PARSER {
~PARSER_CHG_USER();
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
- void Reset();
-private:
- PARSER_CHG_USER(const PARSER_CHG_USER & rvalue);
- PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue);
-
- std::string EncChar2String(const char *);
- int AplayChanges();
+private:
USER_STAT_RES * usr;
USER_CONF_RES * ucr;
RESETABLE<uint64_t> * upr;
std::string login;
bool cashMustBeAdded;
int res;
+
+ PARSER_CHG_USER(const PARSER_CHG_USER & rvalue);
+ PARSER_CHG_USER & operator=(const PARSER_CHG_USER & rvalue);
+
+ std::string EncChar2String(const char *);
+ int AplayChanges();
+ void CreateAnswer();
+ void Reset();
};
//-----------------------------------------------------------------------------
class PARSER_DEL_USER: public BASE_PARSER {
PARSER_DEL_USER() : BASE_PARSER(), res(0), u(NULL) {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
private:
+ int res;
+ USER * u;
+
PARSER_DEL_USER(const PARSER_DEL_USER & rvalue);
PARSER_DEL_USER & operator=(const PARSER_DEL_USER & rvalue);
- int res;
- USER * u;
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------
class PARSER_CHECK_USER: public BASE_PARSER {
public:
- PARSER_CHECK_USER() : BASE_PARSER(), result(false) {}
+ PARSER_CHECK_USER() : BASE_PARSER() {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
+
private:
- bool result;
+ void CreateAnswer(const char * error);
};
//-----------------------------------------------------------------------------
class PARSER_SEND_MESSAGE: public BASE_PARSER {
PARSER_SEND_MESSAGE() : BASE_PARSER(), logins(), result(0), msg(), u(NULL) {}
int ParseStart(void *data, const char *el, const char **attr);
int ParseEnd(void *data, const char *el);
- void CreateAnswer();
-private:
- PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue);
- PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue);
-
- int ParseLogins(const char * logins);
+private:
enum {res_ok, res_params_error, res_unknown};
std::vector<std::string> logins;
int result;
STG_MSG msg;
USER * u;
+
+ PARSER_SEND_MESSAGE(const PARSER_SEND_MESSAGE & rvalue);
+ PARSER_SEND_MESSAGE & operator=(const PARSER_SEND_MESSAGE & rvalue);
+
+ int ParseLogins(const char * logins);
+ void CreateAnswer();
};
//-----------------------------------------------------------------------------
#endif //PARSER_H
--- /dev/null
+#include "parser_auth_by.h"
+
+int PARSER_AUTH_BY::ParseStart(void * /*data*/, const char *el, const char **attr)
+{
+if (strcasecmp(el, "GetUserAuthBy") == 0)
+ {
+ if (attr[0] && attr[1])
+ login = attr[1];
+ else
+ {
+ login.erase(login.begin(), login.end());
+ return -1;
+ }
+ return 0;
+ }
+return -1;
+}
+
+int PARSER_AUTH_BY::ParseEnd(void * /*data*/, const char *el)
+{
+if (strcasecmp(el, "GetUserAuthBy") == 0)
+ {
+ CreateAnswer();
+ return 0;
+ }
+return -1;
+}
+
+void PARSER_AUTH_BY::CreateAnswer()
+{
+answerList->erase(answerList->begin(), answerList->end());
+
+USER_PTR u;
+if (users->FindByName(login, &u))
+ {
+ answerList->push_back("<AuthorizedBy result=\"error\" reason=\"User not found.\"/>");
+ return;
+ }
+
+std::string s = "<AuthorizedBy result=\"ok\">";
+std::vector<std::string> list(u->GetAuthorizers());
+for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
+ s += "<Auth name=\"" + *it + "\"/>";
+s += "</AuthorizedBy>";
+answerList->push_back(s);
+}
--- /dev/null
+#ifndef __STG_PARSER_AUTH_BY_H__
+#define __STG_PARSER_AUTH_BY_H__
+
+#include <string>
+
+#include "parser.h"
+
+class PARSER_AUTH_BY : public BASE_PARSER {
+public:
+ int ParseStart(void *data, const char *el, const char **attr);
+ int ParseEnd(void *data, const char *el);
+ void CreateAnswer();
+
+private:
+ std::string login;
+};
+
+#endif
--- /dev/null
+/*
+ * 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>
+ */
+
+#include "parser_user_info.h"
+
+#include "stg/user.h"
+#include "stg/common.h"
+
+#include <strings.h> // strcasecmp
+
+int PARSER_USER_INFO::ParseStart(void * /*data*/, const char *el, const char **attr)
+{
+login.clear();
+if (strcasecmp(el, "GetUserInfo") != 0)
+ return -1;
+
+if (!attr[0] || !attr[1] || strcasecmp(attr[0], "login") != 0)
+ return -1;
+
+login = attr[1];
+return 0;
+}
+
+int PARSER_USER_INFO::ParseEnd(void * /*data*/, const char *el)
+{
+if (strcasecmp(el, "GetUserInfo") != 0)
+ return -1;
+
+CreateAnswer();
+return 0;
+}
+
+void PARSER_USER_INFO::CreateAnswer()
+{
+answerList->clear();
+
+CONST_USER_PTR u;
+if (users->FindByName(login, &u))
+ {
+ answerList->push_back("<UserInfo result=\"error\"/>");
+ return;
+ }
+
+std::string s = "<UserInfo lastAuthTime=\"" + x2str(u->GetAuthorizedModificationTime()) + "\"" +
+ " lastDisconnectTime=\"" + x2str(u->GetConnectedModificationTime()) + "\"" +
+ " connected=\"" + (u->GetConnected() ? "true" : "false") + "\"" +
+ " lastDisconnectReason=\"" + u->GetLastDisconnectReason() + "\">";
+std::vector<std::string> list(u->GetAuthorizers());
+for (std::vector<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
+ s += "<Auth name=\"" + *it + "\"/>";
+s += "</UserInfo>";
+answerList->push_back(s);
+}
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __STG_PARSER_USER_INFO_H__
+#define __STG_PARSER_USER_INFO_H__
+
+#include "parser.h"
+
+#include <string>
+
+class PARSER_USER_INFO : public BASE_PARSER {
+public:
+ int ParseStart(void *data, const char *el, const char **attr);
+ int ParseEnd(void *data, const char *el);
+
+private:
+ std::string login;
+
+ void CreateAnswer();
+};
+
+#endif
*
*******************************************************************/
-#include <unistd.h> // close
+#include "configproto.h"
+
+#include "stg/blowfish.h"
#include <cerrno>
#include <csignal>
#include <cstdio> // snprintf
-#include "stg/blowfish.h"
-#include "configproto.h"
+#include <unistd.h> // close
#ifndef ENODATA
// FreeBSD 4.* - suxx
&outerAddrLen);
if (!nonstop)
- {
break;
- }
if (outerSocket < 0)
{
- logger("accept error: %s", strerror(errno));
+ logger("accept error: %s", strerror(errno));
printfd(__FILE__, "accept failed\n");
continue;
}
ssize_t ret = recv(sock, &buf[pos], static_cast<int>(stgHdrLen) - static_cast<int>(pos), 0);
if (ret <= 0)
{
- if (ret < 0)
- logger("recv error: %s", strerror(errno));
+ if (ret < 0)
+ logger("recv error: %s", strerror(errno));
state = confHdr;
return -1;
}
if (ret <= 0)
{
// Error in network
- logger("recv error: %s", strerror(errno));
+ logger("recv error: %s", strerror(errno));
state = confHdr;
return ENODATA;
}
{
// Network error
printfd(__FILE__, "recv error: '%s'\n", strerror(errno));
- logger("recv error: %s", strerror(errno));
+ logger("recv error: %s", strerror(errno));
state = confHdr;
return ENODATA;
}
char login[ADM_LOGIN_LEN + 1];
for (size_t i = 0; i < ADM_LOGIN_LEN / 8; i++)
- {
DecodeString(login + i * 8, loginS + i * 8, &ctx);
- }
if (currAdmin == admins->GetNoAdmin())
{
if (ret < 0)
{
// Network error
- logger("recv error: %s", strerror(errno));
+ logger("recv error: %s", strerror(errno));
printfd(__FILE__, "recv error: '%s'\n", strerror(errno));
return -1;
}
if (n % 8 == 0)
{
EncodeString(buffS, buff, &ctx);
- int ret = static_cast<int>(send(sock, buffS, 8, 0));
- if (ret < 0)
- {
+ if (send(sock, buffS, 8, 0) < 0)
return -1;
- }
}
}
k = 0;// new node
authorizedUsers.end(),
UpdateRouter(*this));
+logger("%s reloaded successfully.", rsSettings.GetMapFileName().c_str());
+printfd(__FILE__, "REMOTE_SCRIPT::Reload() %s reloaded successfully.\n");
+
return 0;
}
//-----------------------------------------------------------------------------
return -1;
if (Start())
return -1;
+if (!needReconnect)
+ {
+ printfd(__FILE__, "SMUX reconnected succesfully.\n");
+ logger("Reconnected successfully.");
+ }
return 0;
}
st->Execute();
st->Prepare("insert into tb_allowed_ip (fk_user, ip, mask) values (?, ?, ?)");
- for(i = 0; i < conf.ips.Count(); i++)
+ for(size_t i = 0; i < conf.ips.Count(); i++)
{
st->Set(1, uid);
st->Set(2, (int32_t)conf.ips[i].ip);
*
*/
-#include <string>
-#include <vector>
-#include <algorithm>
-
-#include <libpq-fe.h>
+#include "postgresql_store.h"
#include "stg/module_settings.h"
#include "stg/plugin_creator.h"
-#include "postgresql_store_utils.h"
-#include "postgresql_store.h"
+
+#include <libpq-fe.h>
+
+#include <string>
+#include <vector>
namespace
{
int POSTGRESQL_STORE::ParseSettings()
{
std::vector<PARAM_VALUE>::iterator i;
-std::string s;
for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i)
{
- s = i->param;
- std::transform(s.begin(), s.end(), s.begin(), ToLower());
- if (s == "server")
- {
+ std::string param(ToLower(i->param));
+ if (param == "server")
server = *(i->value.begin());
- }
- if (s == "database")
- {
+ else if (param == "database")
database = *(i->value.begin());
- }
- if (s == "user")
- {
+ else if (param == "user")
user = *(i->value.begin());
- }
- if (s == "password")
- {
+ else if (param == "password")
password = *(i->value.begin());
- }
- if (s == "retries")
- {
+ else if (param == "retries")
if (str2x(*(i->value.begin()), retries))
{
strError = "Invalid 'retries' value";
printfd(__FILE__, "POSTGRESQL_STORE::ParseSettings(): '%s'\n", strError.c_str());
return -1;
}
- }
}
clientEncoding = "KOI8";
PQclear(result);
-for (int i = 0; i < ips.Count(); ++i)
+for (size_t i = 0; i < ips.Count(); ++i)
{
std::ostringstream query;
query << "INSERT INTO tb_allowed_ip "
*
*/
+#include "postgresql_store.h"
+
+#include "stg/common.h"
+
#include <string>
#include <ctime>
#include <libpq-fe.h>
-#include "stg/common.h"
-#include "postgresql_store.h"
-
extern volatile time_t stgTime;
int POSTGRESQL_STORE::StartTransaction() const
char * buf = new char[(value.length() << 1) + 1];
PQescapeStringConn(connection,
- buf,
- value.c_str(),
- value.length(),
- &error);
+ buf,
+ value.c_str(),
+ value.length(),
+ &error);
if (error)
{
std::string POSTGRESQL_STORE::Int2TS(time_t ts) const
{
-char buf[32];
struct tm brokenTime;
brokenTime.tm_wday = 0;
gmtime_r(&ts, &brokenTime);
+char buf[32];
strftime(buf, 32, "%Y-%m-%d %H:%M:%S", &brokenTime);
return buf;
else
{
time_t curTime = stgTime;
- /*time(&curTime);*/
-
localtime_r(&curTime, &brokenTime);
}
date = buf;
}
-
+++ /dev/null
-#ifndef POSTGRESQL_UTILS_STORE_H
-#define POSTGRESQL_UTILS_STORE_H
-
-#include <functional>
-
-struct ToLower : public std::unary_function<char, char>
-{
-char operator() (char c) const { return static_cast<char>(std::tolower(c)); }
-};
-
-#endif
FreeRules();
ReadRules();
-printfd(__FILE__, "TRAFFCOUNTER_IMPL::Reload() - Reload rules successfull.\n");
-WriteServLog("TRAFFCOUNTER: Reload rules successfull.");
+printfd(__FILE__, "TRAFFCOUNTER_IMPL::Reload() - Reloaded rules successfully.\n");
+WriteServLog("TRAFFCOUNTER: Reloaded rules successfully.");
return 0;
}
//-----------------------------------------------------------------------------
#define _GNU_SOURCE
#endif
-#include <pthread.h>
-#include <unistd.h> // access
-
-#include <cassert>
-#include <cstdlib>
-#include <cmath>
+#include "user_impl.h"
+#include "settings_impl.h"
+#include "stg_timer.h"
#include "stg/users.h"
#include "stg/common.h"
#include "stg/tariff.h"
#include "stg/tariffs.h"
#include "stg/admin.h"
-#include "user_impl.h"
-#include "settings_impl.h"
-#include "stg_timer.h"
+
+#include <algorithm>
+#include <functional>
+
+#include <cassert>
+#include <cstdlib>
+#include <cmath>
+
+#include <pthread.h>
+#include <unistd.h> // access
#ifdef USE_ABSTRACT_SETTINGS
USER_IMPL::USER_IMPL(const SETTINGS * s,
property(s->GetScriptsDir()),
WriteServLog(GetStgLogger()),
lastScanMessages(0),
- login(),
id(0),
__connected(0),
connected(__connected),
- enabledDirs(),
- userIDGenerator(),
__currIP(0),
currIP(__currIP),
lastIPForDisconnect(0),
store(st),
tariffs(t),
tariff(NULL),
- traffStat(),
- traffStatSaved(),
settings(s),
- authorizedBy(),
- messages(),
+ authorizedModificationTime(0),
deleted(false),
lastWriteStat(0),
lastWriteDetailedStat(0),
userdata7(property.userdata7),
userdata8(property.userdata8),
userdata9(property.userdata9),
- sessionUpload(),
- sessionDownload(),
passiveNotifier(this),
tariffNotifier(this),
cashNotifier(this),
- ipNotifier(this),
- mutex(),
- errorStr()
+ ipNotifier(this)
{
password = "*_EMPTY_PASSWORD_*";
tariffName = NO_TARIFF_NAME;
property(s->GetScriptsDir()),
WriteServLog(GetStgLogger()),
lastScanMessages(0),
- login(),
id(0),
__connected(0),
connected(__connected),
- enabledDirs(),
- userIDGenerator(),
__currIP(0),
currIP(__currIP),
lastIPForDisconnect(0),
store(st),
tariffs(t),
tariff(NULL),
- traffStat(),
- traffStatSaved(),
settings(s),
- authorizedBy(),
- messages(),
+ authorizedModificationTime(0),
deleted(false),
lastWriteStat(0),
lastWriteDetailedStat(0),
userdata7(property.userdata7),
userdata8(property.userdata8),
userdata9(property.userdata9),
- sessionUpload(),
- sessionDownload(),
passiveNotifier(this),
disabledNotifier(this),
tariffNotifier(this),
cashNotifier(this),
- ipNotifier(this),
- mutex(),
- errorStr()
+ ipNotifier(this)
{
password = "*_EMPTY_PASSWORD_*";
tariffName = NO_TARIFF_NAME;
id(u.id),
__connected(0),
connected(__connected),
- enabledDirs(),
userIDGenerator(u.userIDGenerator),
__currIP(u.__currIP),
currIP(__currIP),
traffStat(u.traffStat),
traffStatSaved(u.traffStatSaved),
settings(u.settings),
- authorizedBy(),
+ authorizedModificationTime(u.authorizedModificationTime),
messages(u.messages),
deleted(u.deleted),
lastWriteStat(u.lastWriteStat),
disabledNotifier(this),
tariffNotifier(this),
cashNotifier(this),
- ipNotifier(this),
- mutex(),
- errorStr()
+ ipNotifier(this)
{
if (&u == this)
return;
}
}
+if (authorizedBy.empty())
+ authorizedModificationTime = stgTime;
authorizedBy.insert(auth);
ScanMessage();
if (authorizedBy.empty())
{
+ authorizedModificationTime = stgTime;
lastIPForDisconnect = currIP;
currIP = 0; // DelUser in traffcounter
return;
return authorizedBy.find(auth) != authorizedBy.end();
}
//-----------------------------------------------------------------------------
+std::vector<std::string> USER_IMPL::GetAuthorizers() const
+{
+ std::vector<std::string> list;
+ std::transform(authorizedBy.begin(), authorizedBy.end(), std::back_inserter(list), std::mem_fun(&AUTH::GetVersion));
+ return list;
+}
+//-----------------------------------------------------------------------------
void USER_IMPL::Connect(bool fakeConnect)
{
/*
if (!fakeDisconnect)
{
+ lastDisconnectReason = reason;
std::string scriptOnDisonnect = settings->GetScriptsDir() + "/OnDisconnect";
if (access(scriptOnDisonnect.c_str(), X_OK) == 0)
#ifndef USER_IMPL_H
#define USER_IMPL_H
-#include <ctime>
-#include <list>
-#include <string>
-#include <set>
-
#include "stg/user.h"
-#include "stg/os_int.h"
-#include "stg/const.h"
#include "stg/user_stat.h"
#include "stg/user_conf.h"
#include "stg/user_ips.h"
#include "stg/auth.h"
#include "stg/message.h"
#include "stg/noncopyable.h"
+#include "stg/os_int.h"
+#include "stg/const.h"
+
+#include <list>
+#include <vector>
+#include <string>
+#include <set>
+
+#include <ctime>
//-----------------------------------------------------------------------------
class TARIFF;
bool GetConnected() const { return connected; }
time_t GetConnectedModificationTime() const { return connected.ModificationTime(); }
+ const std::string & GetLastDisconnectReason() const { return lastDisconnectReason; }
int GetAuthorized() const { return static_cast<int>(authorizedBy.size()); }
+ time_t GetAuthorizedModificationTime() const { return authorizedModificationTime; }
int Authorize(uint32_t ip, uint32_t enabledDirs, const AUTH * auth);
void Unauthorize(const AUTH * auth);
bool IsAuthorizedBy(const AUTH * auth) const;
+ std::vector<std::string> GetAuthorizers() const;
int AddMessage(STG_MSG * msg);
int id;
bool __connected;
USER_PROPERTY<bool> connected;
+ std::string lastDisconnectReason;
bool enabledDirs[DIR_NUM];
#endif
std::set<const AUTH *> authorizedBy;
+ time_t authorizedModificationTime;
std::list<STG_MSG> messages;
//-----------------------------------------------------------------------------
int USERS_IMPL::FindByNameNonLock(const std::string & login, user_iter * user)
{
-std::map<std::string, user_iter>::iterator iter;
-iter = loginIndex.find(login);
-if (iter != loginIndex.end())
- {
- if (user)
- *user = iter->second;
- return 0;
- }
-return -1;
+const std::map<std::string, user_iter>::const_iterator iter(loginIndex.find(login));
+if (iter == loginIndex.end())
+ return -1;
+if (user)
+ *user = iter->second;
+return 0;
+}
+//-----------------------------------------------------------------------------
+int USERS_IMPL::FindByNameNonLock(const std::string & login, const_user_iter * user) const
+{
+const std::map<std::string, user_iter>::const_iterator iter(loginIndex.find(login));
+if (iter == loginIndex.end())
+ return -1;
+if (user)
+ *user = iter->second;
+return 0;
}
//-----------------------------------------------------------------------------
int USERS_IMPL::FindByName(const std::string & login, USER_PTR * user)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
user_iter u;
-int res = FindByNameNonLock(login, &u);
-if (res)
+if (FindByNameNonLock(login, &u))
+ return -1;
+*user = &(*u);
+return 0;
+}
+//-----------------------------------------------------------------------------
+int USERS_IMPL::FindByName(const std::string & login, CONST_USER_PTR * user) const
+{
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+const_user_iter u;
+if (FindByNameNonLock(login, &u))
return -1;
*user = &(*u);
return 0;
return it != ipIndex.end();
}
//-----------------------------------------------------------------------------
+bool USERS_IMPL::IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const
+{
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::list<USER_IMPL>::const_iterator iter;
+iter = users.begin();
+while (iter != users.end())
+ {
+ if (iter->GetLogin() != login &&
+ !iter->GetProperty().ips.Get().IsAnyIP() &&
+ iter->GetProperty().ips.Get().IsIPInIPS(ip))
+ {
+ if (user != NULL)
+ *user = &(*iter);
+ return true;
+ }
+ ++iter;
+ }
+return false;
+}
+//-----------------------------------------------------------------------------
void USERS_IMPL::AddNotifierUserAdd(NOTIFIER_BASE<USER_PTR> * n)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
virtual ~USERS_IMPL();
int FindByName(const std::string & login, USER_PTR * user);
+ int FindByName(const std::string & login, CONST_USER_PTR * user) const;
bool TariffInUse(const std::string & tariffName) const;
int FindByIPIdx(uint32_t ip, USER_PTR * user) const;
int FindByIPIdx(uint32_t ip, USER_IMPL ** user) const;
bool IsIPInIndex(uint32_t ip) const;
+ bool IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const;
int OpenSearch();
int SearchNext(int handler, USER_PTR * user);
bool FindByIPIdx(uint32_t ip, user_iter & iter) const;
int FindByNameNonLock(const std::string & login, user_iter * user);
+ int FindByNameNonLock(const std::string & login, const_user_iter * user) const;
void RealDelUser();
void ProcessActions();
return TrimR(TrimL(val));
}
//---------------------------------------------------------------------------
+std::string ToLower(const std::string & value)
+{
+ std::string res;
+ for (std::string::size_type pos = 0; pos < value.length(); ++pos)
+ res += tolower(value[pos]);
+ return res;
+}
+//---------------------------------------------------------------------------
+std::string ToUpper(const std::string & value)
+{
+ std::string res;
+ for (std::string::size_type pos = 0; pos < value.length(); ++pos)
+ res += toupper(value[pos]);
+ return res;
+}
+//---------------------------------------------------------------------------
#ifdef WIN32
static int is_leap(unsigned y)
{
std::string & TrimR(std::string & val);
std::string & Trim(std::string & val);
+std::string ToLower(const std::string & value);
+std::string ToUpper(const std::string & value);
+
std::string IconvString(const std::string & source, const std::string & from, const std::string & to);
int ParseInt(const std::string & str, int * val);
template <typename varT>
const std::string & x2str(varT x, std::string & s);
template <typename varT>
+std::string x2str(varT x) { std::string s; return x2str(x, s); }
+template <typename varT>
const std::string & unsigned2str(varT x, std::string & s);
+template <typename varT>
+std::string unsigned2str(varT x) { std::string s; return unsigned2str(x, s); }
//-----------------------------------------------------------------------------
template <typename varT>
x += str[i] - '0';
}
- x*= minus;
+ x *= minus;
return 0;
}
#define MAXKEYBYTES 56 /* 448 bits */
#ifdef __cplusplus
+#include <cstddef> // size_t
extern "C" {
+#else
+#include <stddef.h> // size_t
#endif
typedef struct {
#include <netinet/ip_icmp.h>
#endif
-#if defined (FREE_BSD) || defined (FREE_BSD5)
+#if defined (FREE_BSD) || defined (FREE_BSD5) || defined(DARWIN)
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#endif
int ScriptExec(const char * str);
-#ifdef LINUX
+#if defined(LINUX) || defined(DARWIN)
void Executer(int msgID, pid_t pid, char * procName);
#else
void Executer(int msgID, pid_t pid);
return 0;
}
//-----------------------------------------------------------------------------
-#ifdef LINUX
+#if defined(LINUX) || defined(DARWIN)
void Executer(int msgID, pid_t pid, char * procName)
#else
void Executer(int msgID, pid_t pid)
return;
nonstop = 1;
-#ifdef LINUX
+#if defined(LINUX) || defined(DARWIN)
memset(procName, 0, strlen(procName));
strcpy(procName, "stg-exec");
#else
-lstgcrypto
LIBS = -lexpat
-SRCS = netunit.cpp \
- parser.cpp \
+SRCS = netunit.cpp \
+ property_parsers.cpp \
+ parser_auth_by.cpp \
+ parser_server_info.cpp \
+ parser_check_user.cpp \
+ parser_get_user.cpp \
+ parser_get_users.cpp \
+ parser_chg_user.cpp \
+ parser_send_message.cpp \
servconf.cpp
INCS = servconf.h \
netunit.h
LIB_INCS = -I ../common.lib/include \
- -I ../crypto.lib/include
+ -I ../crypto.lib/include
include ../Makefile.in
#ifndef NetUnitH
#define NetUnitH
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include "stg/blowfish.h"
#include <list>
#include <string>
-#include "stg/blowfish.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
#define STG_HEADER "SG04"
#define OK_HEADER "OKHD"
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_H__
+
+class PARSER
+{
+public:
+ virtual ~PARSER() {}
+ virtual int ParseStart(const char *el, const char **attr) = 0;
+ virtual void ParseEnd(const char *el) = 0;
+};
+
+#endif
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_AUTH_BY_H__
+
+#include "parser.h"
+
+#include <vector>
+#include <string>
+
+class PARSER_AUTH_BY: public PARSER
+{
+public:
+ typedef std::vector<std::string> INFO;
+ typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+ PARSER_AUTH_BY();
+ int ParseStart(const char *el, const char **attr);
+ void ParseEnd(const char *el);
+ void SetCallback(CALLBACK f, void * data);
+private:
+ CALLBACK callback;
+ void * data;
+ int depth;
+ bool parsingAnswer;
+ INFO info;
+ std::string error;
+};
+
+#endif
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_CHECK_USER_H__
+
+#include "parser.h"
+
+#include <string>
+
+class PARSER_CHECK_USER: public PARSER
+{
+public:
+ typedef int (* CALLBACK)(bool result, const std::string & reason, void * data);
+
+ PARSER_CHECK_USER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+private:
+ CALLBACK callback;
+ void * data;
+ int depth;
+
+ void ParseAnswer(const char * el, const char ** attr);
+};
+
+#endif
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_CHG_USER_H__
+
+#include "parser.h"
+
+#include <string>
+
+class PARSER_CHG_USER: public PARSER
+{
+public:
+ typedef void (* CALLBACK)(bool result, const std::string& reason, void * data);
+
+ PARSER_CHG_USER();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+private:
+ CALLBACK callback;
+ void * data;
+ int depth;
+
+ void ParseAnswer(const char * el, const char ** attr);
+};
+
+#endif
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_GET_USER_H__
+
+#include "parser.h"
+
+#include "property_parsers.h"
+
+#include "stg/os_int.h"
+#include "stg/const.h"
+
+#include <string>
+
+#include <ctime>
+
+class PARSER_GET_USER: public PARSER
+{
+public:
+ struct STAT
+ {
+ long long su[DIR_NUM];
+ long long sd[DIR_NUM];
+ long long mu[DIR_NUM];
+ long long md[DIR_NUM];
+ double freeMb;
+ };
+
+ struct INFO
+ {
+ std::string login;
+ std::string password;
+ double cash;
+ double credit;
+ time_t creditExpire;
+ double lastCash;
+ double prepaidTraff;
+ int down;
+ int passive;
+ int disableDetailStat;
+ int connected;
+ int alwaysOnline;
+ uint32_t ip;
+ std::string ips;
+ std::string tariff;
+ std::string group;
+ std::string note;
+ std::string email;
+ std::string name;
+ std::string address;
+ std::string phone;
+ STAT stat;
+ std::string userData[USERDATA_NUM];
+ };
+
+ typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+ PARSER_GET_USER();
+ virtual ~PARSER_GET_USER();
+ int ParseStart(const char *el, const char **attr);
+ void ParseEnd(const char *el);
+ void SetCallback(CALLBACK f, void * data);
+private:
+ PROPERTY_PARSERS propertyParsers;
+ CALLBACK callback;
+ void * data;
+ INFO info;
+ int depth;
+ bool parsingAnswer;
+ std::string error;
+
+ void ParseUser(const char *el, const char **attr);
+ void ParseUserParams(const char *el, const char **attr);
+};
+
+#endif
--- /dev/null
+
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_GET_USERS_H__
+
+#include "parser.h"
+
+#include "parser_get_user.h"
+
+#include <vector>
+
+class PARSER_GET_USERS: public PARSER
+{
+public:
+ typedef std::vector<PARSER_GET_USER::INFO> INFO;
+ typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+ PARSER_GET_USERS();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+private:
+ CALLBACK callback;
+ void * data;
+ PARSER_GET_USER userParser;
+ INFO info;
+ int depth;
+ bool parsingAnswer;
+ std::string error;
+
+ void AddUser(const PARSER_GET_USER::INFO & userInfo);
+ void SetError(const std::string & e) { error = e; }
+
+ static void UserCallback(bool result, const std::string& reason, const PARSER_GET_USER::INFO & info, void * data);
+};
+
+#endif
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_SEND_MESSAGE_H__
+
+#include "parser.h"
+
+#include <string>
+
+class PARSER_SEND_MESSAGE: public PARSER
+{
+public:
+ typedef void (* CALLBACK)(bool result, const std::string& reason, void * data);
+
+ PARSER_SEND_MESSAGE();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+private:
+ CALLBACK callback;
+ void * data;
+ int depth;
+
+ void ParseAnswer(const char * el, const char ** attr);
+};
+
+#endif
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__
+#define __STG_STGLIBS_SRVCONF_PARSER_SERVER_INFO_H__
+
+#include "parser.h"
+
+#include "property_parsers.h"
+#include "stg/const.h"
+
+#include <string>
+
+class PARSER_SERVER_INFO: public PARSER
+{
+public:
+ struct INFO
+ {
+ std::string version;
+ int tariffNum;
+ int tariffType;
+ int usersNum;
+ std::string uname;
+ int dirNum;
+ std::string dirName[DIR_NUM];
+ };
+ typedef void (* CALLBACK)(bool result, const std::string & reason, const INFO & info, void * data);
+
+ PARSER_SERVER_INFO();
+ int ParseStart(const char * el, const char ** attr);
+ void ParseEnd(const char * el);
+ void SetCallback(CALLBACK f, void * data);
+private:
+ PROPERTY_PARSERS propertyParsers;
+ CALLBACK callback;
+ void * data;
+ int depth;
+ bool parsingAnswer;
+ INFO info;
+ std::string error;
+};
+
+#endif
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__
+#define __STG_STGLIBS_SRVCONF_PROPERTY_PARSERS_H__
+
+#include <map>
+#include <string>
+
+#include "stg/common.h"
+
+class BASE_PROPERTY_PARSER
+{
+ public:
+ virtual ~BASE_PROPERTY_PARSER() {}
+ virtual bool Parse(const char ** attr) = 0;
+};
+
+template <typename T>
+class PROPERTY_PARSER : public BASE_PROPERTY_PARSER
+{
+ public:
+ typedef bool (* FUNC)(const char **, T &);
+ PROPERTY_PARSER(T & v, FUNC f) : value(v), func(f) {}
+ virtual bool Parse(const char ** attr) { return func(attr, value); }
+ private:
+ T & value;
+ FUNC func;
+};
+
+typedef std::map<std::string, BASE_PROPERTY_PARSER *> PROPERTY_PARSERS;
+
+bool CheckValue(const char ** attr);
+
+template <typename T>
+inline
+bool GetValue(const char ** attr, T & value)
+{
+if (CheckValue(attr))
+ if (str2x(attr[1], value) < 0)
+ return false;
+return true;
+}
+
+template <>
+inline
+bool GetValue<std::string>(const char ** attr, std::string & value)
+{
+if (!CheckValue(attr))
+ return false;
+value = attr[1];
+return true;
+}
+
+template <>
+inline
+bool GetValue<double>(const char ** attr, double & value)
+{
+if (CheckValue(attr))
+ if (strtodouble2(attr[1], value))
+ return false;
+return true;
+}
+
+bool GetEncodedValue(const char ** attr, std::string & value);
+
+bool GetIPValue(const char ** attr, uint32_t& value);
+
+template <typename T>
+void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func = GetValue<T>);
+
+template <typename T>
+inline
+void AddParser(PROPERTY_PARSERS & parsers, const std::string & name, T & value, const typename PROPERTY_PARSER<T>::FUNC & func)
+{
+ parsers.insert(std::make_pair(ToLower(name), new PROPERTY_PARSER<T>(value, func)));
+}
+
+bool TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr);
+
+#endif
#ifndef SERVCONF_H
#define SERVCONF_H
-#include <expat.h>
+#include "netunit.h"
-#include <list>
-#include <string>
+#include "stg/parser_auth_by.h"
+#include "stg/parser_server_info.h"
+#include "stg/parser_check_user.h"
+#include "stg/parser_get_user.h"
+#include "stg/parser_get_users.h"
+#include "stg/parser_chg_user.h"
+#include "stg/parser_send_message.h"
#include "stg/os_int.h"
#include "stg/const.h"
-#include "netunit.h"
-void Start(void *data, const char *el, const char **attr);
-void End(void *data, const char *el);
+#include <list>
+#include <vector>
+#include <string>
+
+#include <expat.h>
+
+void Start(void * data, const char * el, const char ** attr);
+void End(void * data, const char * el);
#define MAX_ERR_STR_LEN (64)
#define IP_STRING_LEN (255)
-#define UNAME_LEN (256)
-#define SERV_VER_LEN (64)
-#define DIRNAME_LEN (16)
-//-----------------------------------------------------------------------------
-struct STAT
-{
- long long su[DIR_NUM];
- long long sd[DIR_NUM];
- long long mu[DIR_NUM];
- long long md[DIR_NUM];
- double freeMb;
-};
-//-----------------------------------------------------------------------------
-struct SERVERINFO
-{
- std::string version;
- int tariffNum;
- int tariffType;
- int usersNum;
- std::string uname;
- int dirNum;
- std::string dirName[DIR_NUM];
-};
-//-----------------------------------------------------------------------------
-struct USERDATA
-{
- std::string login;
- std::string password;
- double cash;
- double credit;
- time_t creditExpire;
- double lastCash;
- double prepaidTraff;
- int down;
- int passive;
- int disableDetailStat;
- int connected;
- int alwaysOnline;
- uint32_t ip;
- std::string ips;
- std::string tariff;
- std::string iface;
- std::string group;
- std::string note;
- std::string email;
- std::string name;
- std::string address;
- std::string phone;
- STAT stat;
- std::string userData[USERDATA_NUM];
-
- struct USERDATA * next;
-};
-//-----------------------------------------------------------------------------
-typedef void(*RecvUserDataCb_t)(USERDATA * ud, void * data);
-typedef void(*RecvServerInfoDataCb_t)(SERVERINFO * si, void * data);
-typedef int(*RecvChgUserCb_t)(const char * asnwer, void * data);
-typedef int(*RecvCheckUserCb_t)(const char * answer, void * data);
-typedef int(*RecvSendMessageCb_t)(const char * answer, void * data);
-//-----------------------------------------------------------------------------
struct ADMINDATA
{
char login[ADM_LOGIN_LEN];
};
//-----------------------------------------------------------------------------
-class PARSER
-{
-public:
- PARSER() {}
- virtual ~PARSER() {}
- virtual int ParseStart(const char *el, const char **attr) = 0;
- virtual void ParseEnd(const char *el) = 0;
-};
-//-----------------------------------------------------------------------------
-class PARSER_CHG_USER: public PARSER
-{
-public:
- PARSER_CHG_USER();
- int ParseStart(const char *el, const char **attr);
- void ParseEnd(const char *el);
- void ParseAnswer(const char *el, const char **attr);
- void SetChgUserRecvCb(RecvChgUserCb_t, void * data);
-private:
- RecvChgUserCb_t RecvChgUserCb;
- void * chgUserCbData;
- int depth;
- bool error;
-};
-//-----------------------------------------------------------------------------
-class PARSER_CHECK_USER: public PARSER
-{
-public:
- PARSER_CHECK_USER();
- int ParseStart(const char *el, const char **attr);
- void ParseEnd(const char *el);
- void ParseAnswer(const char *el, const char **attr);
- void SetCheckUserRecvCb(RecvCheckUserCb_t, void * data);
-private:
- RecvCheckUserCb_t RecvCheckUserCb;
- void * checkUserCbData;
- int depth;
- bool error;
-};
-//-----------------------------------------------------------------------------
-class PARSER_GET_USERS: public PARSER
-{
-public:
- PARSER_GET_USERS();
- int ParseStart(const char *el, const char **attr);
- void ParseEnd(const char *el);
- void ParseUsers(const char *el, const char **attr);
- void ParseUser(const char *el, const char **attr);
- void ParseUserParams(const char *el, const char **attr);
- void ParseUserLoadStat(const char * el, const char ** attr);
- void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
-private:
- RecvUserDataCb_t RecvUserDataCb;
- void * userDataCb;
- USERDATA user;
- int depth;
- bool error;
-};
-//-----------------------------------------------------------------------------
-class PARSER_GET_USER: public PARSER
-{
-public:
- PARSER_GET_USER();
- int ParseStart(const char *el, const char **attr);
- void ParseEnd(const char *el);
- void ParseUsers(const char *el, const char **attr);
- void ParseUser(const char *el, const char **attr);
- void ParseUserParams(const char *el, const char **attr);
- void ParseUserLoadStat(const char * el, const char ** attr);
- void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
-private:
- RecvUserDataCb_t RecvUserDataCb;
- void * userDataCb;
- USERDATA user;
- int depth;
- bool error;
-};
-//-----------------------------------------------------------------------------
-class PARSER_GET_SERVER_INFO: public PARSER
-{
-public:
- PARSER_GET_SERVER_INFO();
- int ParseStart(const char *el, const char **attr);
- void ParseEnd(const char *el);
- void ParseServerInfo(const char *el, const char **attr);
- bool GetError();
- void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
-private:
- void ParseUname(const char ** attr);
- void ParseServerVersion(const char ** attr);
- void ParseUsersNum(const char ** attr);
- void ParseTariffsNum(const char ** attr);
- void ParseTariffType(const char ** attr);
- void ParseDirNum(const char **attr);
- void ParseDirName(const char **attr, int d);
-
- RecvServerInfoDataCb_t RecvServerInfoDataCb;
- void * serverInfoDataCb;
- int depth;
- bool error;
- SERVERINFO serverInfo;
-};
-//-----------------------------------------------------------------------------
-class PARSER_SEND_MESSAGE: public PARSER
-{
-public:
- PARSER_SEND_MESSAGE();
- int ParseStart(const char *el, const char **attr);
- void ParseEnd(const char *el);
- void ParseAnswer(const char *el, const char **attr);
- void SetSendMessageRecvCb(RecvSendMessageCb_t, void * data);
-private:
- RecvSendMessageCb_t RecvSendMessageCb;
- void * sendMessageCbData;
- int depth;
- bool error;
-};
-//-----------------------------------------------------------------------------
class SERVCONF
{
public:
void SetAdmLogin(const char * login);
void SetAdmPassword(const char * password);
- void SetUserDataRecvCb(RecvUserDataCb_t, void * data);
- void SetServerInfoRecvCb(RecvServerInfoDataCb_t, void * data);
- void SetChgUserCb(RecvChgUserCb_t, void * data);
- void SetCheckUserCb(RecvCheckUserCb_t, void * data);
- void SetGetUserDataRecvCb(RecvUserDataCb_t, void * data);
- void SetSendMessageCb(RecvSendMessageCb_t, void * data);
+ void SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data);
+ void SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data);
+ void SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data);
+ void SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data);
+ void SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data);
+ void SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data);
+ void SetSendMessageCallback(PARSER_SEND_MESSAGE::CALLBACK f, void * data);
int GetUsers();
int GetUser(const char * login);
int ChgUser(const char * request);
- // TODO: Remove this shit!
- int MsgUser(const char * request);
- int SendMessage(const char * login, const char * message, int prio);
- int GetServerInfo();
+ int AuthBy(const char * login);
+ int SendMessage(const char * request);
+ int ServerInfo();
int CheckUser(const char * login, const char * password);
const std::string & GetStrError() const;
- int GetError();
- int Start(const char *el, const char **attr);
- void End(const char *el);
+ int Start(const char * el, const char ** attr);
+ void End(const char * el);
private:
PARSER * currParser;
PARSER_GET_USERS parserGetUsers;
PARSER_GET_USER parserGetUser;
- PARSER_GET_SERVER_INFO parserServerInfo;
+ PARSER_AUTH_BY parserAuthBy;
+ PARSER_SERVER_INFO parserServerInfo;
PARSER_CHG_USER parserChgUser;
PARSER_CHECK_USER parserCheckUser;
PARSER_SEND_MESSAGE parserSendMessage;
NETTRANSACT nt;
- int parseDepth;
std::string errorMsg;
- int error;
XML_Parser parser;
- RecvUserDataCb_t RecvUserDataCb;
- RecvUserDataCb_t RecvGetUserDataCb;
- RecvServerInfoDataCb_t RecvServerInfoDataCb;
- RecvChgUserCb_t RecvChgUserCb;
- RecvCheckUserCb_t RecvCheckUserCb;
- RecvSendMessageCb_t RecvSendMessageCb;
-
- void * getUserDataDataCb;
- void * getUsersDataDataCb;
- void * getServerInfoDataCb;
- void * chgUserDataCb;
- void * checkUserDataCb;
- void * sendMessageDataCb;
+ int Exec(const char * request);
friend int AnsRecv(void * data, std::list<std::string> * list);
};
*/
//---------------------------------------------------------------------------
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <unistd.h>
+
+#include "stg/netunit.h"
+#include "stg/common.h"
#include <cstdio>
+#include <cerrno>
#include <cstring>
-#include "stg/netunit.h"
-#include "stg/common.h"
+#include <netdb.h>
+#include <arpa/inet.h>
+#include <unistd.h>
//---------------------------------------------------------------------------
ret = recv(outerSocket, buffer, strlen(OK_HEADER), 0);
if (ret <= 0)
{
+ printf("Receive header answer error: '%s'\n", strerror(errno));
errorMsg = RECV_HEADER_ANSWER_ERROR;
return st_recv_fail;
}
ret = recv(outerSocket, buffer, strlen(OK_LOGIN), 0);
if (ret <= 0)
{
+ printf("Receive login answer error: '%s'\n", strerror(errno));
errorMsg = RECV_LOGIN_ANSWER_ERROR;
return st_recv_fail;
}
ret = recv(outerSocket, buffer, strlen(OK_LOGINS), 0);
if (ret <= 0)
{
+ printf("Receive secret login answer error: '%s'\n", strerror(errno));
errorMsg = RECV_LOGIN_ANSWER_ERROR;
return st_recv_fail;
}
ret = recv(outerSocket, &bufferS[n++], 1, 0);
if (ret <= 0)
{
+ printf("Receive data error: '%s'\n", strerror(errno));
close(outerSocket);
errorMsg = RECV_DATA_ANSWER_ERROR;
return st_recv_fail;
Decrypt(buffer, bufferS, &ctx);
buffer[ENC_MSG_LEN] = 0;
+ printf("%s", buffer);
+
answerList.push_back(buffer);
for (int j = 0; j < ENC_MSG_LEN; j++)
{
if (buffer[j] == 0)
{
+ printf("\n");
if (RxCallBack)
if (st_ok != RxCallBack(dataRxCallBack, &answerList))
- {
return st_xml_parse_error;
- }
return st_ok;
}
}
+++ /dev/null
-/*
- * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
- */
-
- /*
- $Revision: 1.18 $
- $Date: 2010/08/04 00:40:00 $
- $Author: faust $
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string>
-
-#include "stg/common.h"
-#include "stg/const.h"
-#include "stg/servconf.h"
-
-using namespace std;
-
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PARSER_GET_USERS::PARSER_GET_USERS()
- : RecvUserDataCb(NULL),
- userDataCb(NULL),
- user(),
- depth(0),
- error(false)
-{
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_USERS::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- {
- ParseUsers(el, attr);
- }
-
-if (depth == 2)
- {
- ParseUser(el, attr);
- }
-
-if (depth == 3)
- {
- ParseUserParams(el, attr);
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::ParseEnd(const char *)
-{
-depth--;
-if (depth == 1)
- {
- if (RecvUserDataCb)
- {
- RecvUserDataCb(&user, userDataCb);
- }
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::ParseUsers(const char * el, const char ** attr)
-{
-if (strcasecmp(el, "users") == 0)
- {
- if (*attr != NULL)
- return;
- return;
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::ParseUser(const char * el, const char ** attr)
-{
-if (el && attr[0])
- {
- if (strcasecmp(el, "user") != 0)
- {
- return;
- }
-
- if (strcasecmp(attr[0], "login") != 0)
- {
- return;
- }
- user.login = attr[1];
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::ParseUserParams(const char * el, const char ** attr)
-{
-if (strcasecmp(el, "cash") == 0)
- {
- if (strtodouble2(attr[1], user.cash) < 0)
- {
- return;
- }
- }
-
-/*if (strcasecmp(el, "LastCash") == 0)
- {
- if (strtodouble2(attr[1], user.lastCash) < 0)
- {
- MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
- return 0;
- }
- }*/
-
-/*if (strcasecmp(el, "LastActivityTime") == 0)
- {
- if (strtol(attr[1], user.lastActivityTime) < 0)
- {
- MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
- return 0;
- }
- }*/
-
-
-/*if (strcasecmp(el, "LastTimeCash") == 0)
- {
- if (strtol(attr[1], user.lastTimeCash) < 0)
- {
- MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
- return 0;
- }
- }*/
-
-/*if (strcasecmp(el, "CashExpire") == 0)
- {
- if (strtol(attr[1], user.cashExpire) < 0)
- {
- MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
- return 0;
- }
- }*/
-
-if (strcasecmp(el, "credit") == 0)
- {
- if (strtodouble2(attr[1], user.credit) < 0)
- {
- return;
- }
- }
-
-if (strcasecmp(el, "creditExpire") == 0)
- {
- if (str2x(attr[1], user.creditExpire) < 0)
- {
- return;
- }
- }
-
-/*if (strcasecmp(el, "freemb") == 0)
- {
- if (strtodouble2(attr[1], user.freeMb) < 0)
- {
- MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
- return 0;
- }
- }*/
-
-if (strcasecmp(el, "down") == 0)
- {
- if (str2x(attr[1], user.down) < 0)
- {
- return;
- }
- }
-
-if (strcasecmp(el, "passive") == 0)
- {
- if (str2x(attr[1], user.passive) < 0)
- {
- return;
- }
- }
-
-if (strcasecmp(el, "disableDetailStat") == 0)
- {
- if (str2x(attr[1], user.disableDetailStat) < 0)
- {
- return;
- }
- }
-
-
-if (strcasecmp(el, "status") == 0)
- {
- if (str2x(attr[1], user.connected) < 0)
- {
- return;
- }
- }
-
-if (strcasecmp(el, "aonline") == 0)
- {
- if (str2x(attr[1], user.alwaysOnline) < 0)
- {
- return;
- }
- }
-
-if (strcasecmp(el, "currip") == 0)
- {
- user.ip = inet_addr(attr[1]);
- }
-
-if (strcasecmp(el, "ip") == 0)
- {
- user.ips = attr[1];
- }
-
-
-if (strcasecmp(el, "tariff") == 0)
- {
- //KOIToWin(user.tariff, *(attr+1), TARIFF_LEN);
- user.tariff = attr[1];
- return;
- }
-
-if (strcasecmp(el, "password") == 0)
- {
- user.password = *(attr+1);
- return;
- }
-
-if (strcasecmp(el, "iface") == 0)
- {
- user.iface = attr[1];
- return;
- }
-
-/*if (strcasecmp(el, "name") == 0)
- {
- / *char nameEnc[REALNM_LEN * 2 + 1];
- char name[REALNM_LEN];
- strncpy(nameEnc, attr[1], REALNM_LEN * 2 + 1);
- Decode21(name, nameEnc);
- KOIToWin(user.realName, name, REALNM_LEN);* /
- Decode21str(user.realName, attr[1]);
- return;
- }*/
-
-if (strcasecmp(el, "address") == 0)
- {
- /*char addressEnc[ADDR_LEN * 2 + 1];
- char address[ADDR_LEN];
- strncpy(addressEnc, attr[1], ADDR_LEN * 2 + 1);
- Decode21(address, addressEnc);
- KOIToWin(user.address, address, ADDR_LEN);*/
- Decode21str(user.address, attr[1]);
- return;
- }
-
-if (strcasecmp(el, "phone") == 0)
- {
- /*char phoneEnc[PHONE_LEN * 2 + 1];
- char phone[PHONE_LEN];
- strncpy(phoneEnc, attr[1], PHONE_LEN * 2 + 1);
- Decode21(phone, phoneEnc);
- KOIToWin(user.phone, phone, PHONE_LEN);*/
- Decode21str(user.phone, attr[1]);
- return;
- }
-
-if (strcasecmp(el, "note") == 0)
- {
- /*char noteEnc[NOTE_LEN * 2 + 1];
- char note[NOTE_LEN];
- strncpy(noteEnc, attr[1], NOTE_LEN * 2 + 1);*/
- //KOIToWin(user.note, note, NOTE_LEN);
- //user.note = note;
- Decode21str(user.note, attr[1]);
- return;
- }
-
-if (strcasecmp(el, "email") == 0)
- {
- /*char emailEnc[EMAIL_LEN * 2 + 1];
- char email[EMAIL_LEN];
- strncpy(emailEnc, attr[1], EMAIL_LEN * 2 + 1);
- Decode21(email, emailEnc);
- //KOIToWin(user.email, email, EMAIL_LEN);
- user.email = email;*/
- Decode21str(user.email, attr[1]);
- return;
- }
-
-if (strcasecmp(el, "group") == 0)
- {
- /*char groupEnc[GROUP_LEN * 2 + 1];
- char group[GROUP_LEN];
- strncpy(groupEnc, attr[1], GROUP_LEN * 2 + 1);
- Decode21(group, groupEnc);
- //KOIToWin(user.group, group, GROUP_LEN);
- user.group = group;*/
- Decode21str(user.group, attr[1]);
- return;
- }
-
-if (strcasecmp(el, "traff") == 0)
- {
- ParseUserLoadStat(el, attr);
- return;
- }
-
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::ParseUserLoadStat(const char *, const char ** attr)
-{
-int i = 0;
-char dir[6];
-while (attr[i])
- {
- for (int j = 0; j < DIR_NUM; j++)
- {
- sprintf(dir, "MU%d", j);
- if (strcasecmp(dir, attr[i]) == 0)
- {
- str2x(attr[i+1], user.stat.mu[j]);
- break;
- }
- }
- for (int j = 0; j < DIR_NUM; j++)
- {
- sprintf(dir, "MD%d", j);
- if (strcasecmp(dir, attr[i]) == 0)
- {
- str2x(attr[i+1], user.stat.md[j]);
- break;
- }
- }
- for (int j = 0; j < DIR_NUM; j++)
- {
- sprintf(dir, "SU%d", j);
- if (strcasecmp(dir, attr[i]) == 0)
- {
- str2x(attr[i+1], user.stat.su[j]);
- break;
- }
- }
- for (int j = 0; j < DIR_NUM; j++)
- {
- sprintf(dir, "SD%d", j);
- if (strcasecmp(dir, attr[i]) == 0)
- {
- str2x(attr[i+1], user.stat.sd[j]);
- break;
- }
- }
- i+=2;
- }
-return;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USERS::SetUserDataRecvCb(RecvUserDataCb_t f, void * data)
-{
-RecvUserDataCb = f;
-userDataCb = data;
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PARSER_GET_USER::PARSER_GET_USER()
- : RecvUserDataCb(NULL),
- userDataCb(NULL),
- user(),
- depth(0),
- error(false)
-{
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_USER::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- {
- ParseUser(el, attr);
- }
-
-if (depth == 2)
- {
- ParseUserParams(el, attr);
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USER::ParseEnd(const char *)
-{
-depth--;
-if (depth == 0)
- {
- if (RecvUserDataCb)
- {
- RecvUserDataCb(&user, userDataCb);
- }
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USER::ParseUser(const char * el, const char ** attr)
-{
-if (strcasecmp(el, "user") == 0)
- {
- if (strcasecmp(attr[1], "error") == 0)
- user.login = "";
- return;
- }
-}
-//-----------------------------------------------------------------------------
-struct ParsedStringParams
-{
-string * param;
-string paramName;
-};
-//-----------------------------------------------------------------------------
-struct ParsedDoubleParams
-{
-double * param;
-string paramName;
-};
-//-----------------------------------------------------------------------------
-void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)
-{
-//printf("PARSER_GET_USER::ParseUserParams el=%s attr[1]=%s\n", el, attr[1]);
-
-if (strcasecmp(el, "login") == 0)
- {
- user.login = attr[1];
- }
-
-
-/*if (strcasecmp(el, "LastActivityTime") == 0)
- {
- if (strtol(attr[1], user.lastActivityTime) < 0)
- {
- MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
- return 0;
- }
- }
-
-
-if (strcasecmp(el, "LastTimeCash") == 0)
- {
- if (strtol(attr[1], user.lastTimeCash) < 0)
- {
- MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
- return 0;
- }
- }
-
-if (strcasecmp(el, "CashExpire") == 0)
- {
- if (strtol(attr[1], user.cashExpire) < 0)
- {
- MessageDlg("Error in answer", mtError, TMsgDlgButtons() << mbOK, 0);
- return 0;
- }
- }
-*/
-
-if (strcasecmp(el, "down") == 0)
- {
- if (str2x(attr[1], user.down) < 0)
- {
- return;
- }
- }
-
-if (strcasecmp(el, "passive") == 0)
- {
- if (str2x(attr[1], user.passive) < 0)
- {
- return;
- }
- }
-
-if (strcasecmp(el, "disableDetailStat") == 0)
- {
- if (str2x(attr[1], user.disableDetailStat) < 0)
- {
- return;
- }
- }
-
-
-if (strcasecmp(el, "status") == 0)
- {
- if (str2x(attr[1], user.connected) < 0)
- {
- return;
- }
- }
-
-if (strcasecmp(el, "aonline") == 0)
- {
- if (str2x(attr[1], user.alwaysOnline) < 0)
- {
- return;
- }
- }
-
-if (strcasecmp(el, "currip") == 0)
- {
- user.ip = inet_addr(attr[1]);
- }
-
-if (strcasecmp(el, "creditExpire") == 0)
- {
- if (str2x(attr[1], user.creditExpire) < 0)
- {
- return;
- }
- }
-
-for (int i = 0; i < USERDATA_NUM; i++)
- {
- string num;
- x2str(i, num);
- string udName = "UserData" + num;
- if (strcasecmp(el, udName.c_str()) == 0)
- {
- Decode21str(user.userData[i], attr[1]);
- return;
- }
- }
-
-ParsedStringParams psp[] =
-{
- {&user.ips, "ip"},
- {&user.tariff, "tariff"},
- {&user.password, "password"},
- {&user.iface, "iface"},
-};
-
-for (unsigned i = 0; i < sizeof(psp)/sizeof(ParsedStringParams); i++)
- {
- if (strcasecmp(el, psp[i].paramName.c_str()) == 0)
- {
- *psp[i].param = attr[1];
- return;
- }
- }
-
-ParsedStringParams pspEnc[] =
-{
- {&user.note, "note"},
- {&user.email, "email"},
- {&user.group, "group"},
- {&user.name, "name"},
- {&user.address, "address"},
- {&user.phone, "phone"}
-};
-
-for (unsigned i = 0; i < sizeof(pspEnc)/sizeof(ParsedStringParams); i++)
- {
- if (strcasecmp(el, pspEnc[i].paramName.c_str()) == 0)
- {
- Decode21str(*pspEnc[i].param, attr[1]);
- return;
- }
- }
-
-ParsedDoubleParams pdp[] =
-{
- {&user.cash, "cash"},
- {&user.credit, "credit"},
- {&user.lastCash, "lastCash"},
- {&user.prepaidTraff, "freemb"},
-};
-
-for (unsigned i = 0; i < sizeof(pdp)/sizeof(ParsedDoubleParams); i++)
- {
- if (strcasecmp(el, pdp[i].paramName.c_str()) == 0)
- {
- strtodouble2(attr[1], *pdp[i].param);
- return;
- }
- }
-
-if (strcasecmp(el, "traff") == 0)
- {
- ParseUserLoadStat(el, attr);
- return;
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USER::ParseUserLoadStat(const char *, const char ** attr)
-{
-int i = 0;
-char dir[6];
-while (attr[i])
- {
- for (int j = 0; j < DIR_NUM; j++)
- {
- sprintf(dir, "MU%d", j);
- if (strcasecmp(dir, attr[i]) == 0)
- {
- str2x(attr[i+1], user.stat.mu[j]);
- break;
- }
- }
- for (int j = 0; j < DIR_NUM; j++)
- {
- sprintf(dir, "MD%d", j);
- if (strcasecmp(dir, attr[i]) == 0)
- {
- str2x(attr[i+1], user.stat.md[j]);
- break;
- }
- }
- for (int j = 0; j < DIR_NUM; j++)
- {
- sprintf(dir, "SU%d", j);
- if (strcasecmp(dir, attr[i]) == 0)
- {
- str2x(attr[i+1], user.stat.su[j]);
- break;
- }
- }
- for (int j = 0; j < DIR_NUM; j++)
- {
- sprintf(dir, "SD%d", j);
- if (strcasecmp(dir, attr[i]) == 0)
- {
- str2x(attr[i+1], user.stat.sd[j]);
- break;
- }
- }
- i+=2;
- }
-return;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_USER::SetUserDataRecvCb(RecvUserDataCb_t f, void * data)
-{
-RecvUserDataCb = f;
-userDataCb = data;
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PARSER_GET_SERVER_INFO::PARSER_GET_SERVER_INFO()
- : RecvServerInfoDataCb(NULL),
- serverInfoDataCb(NULL),
- depth(0),
- error(false),
- serverInfo()
-{
-}
-//-----------------------------------------------------------------------------
-int PARSER_GET_SERVER_INFO::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- {
- if (strcasecmp(el, "ServerInfo") != 0)
- {
- //printf("%s\n", el);
- }
- }
-else
- {
- if (depth == 2)
- {
- if (strcasecmp(el, "uname") == 0)
- {
- ParseUname(attr);
- return 0;
- }
- if (strcasecmp(el, "version") == 0)
- {
- ParseServerVersion(attr);
- return 0;
- }
- if (strcasecmp(el, "tariff") == 0)
- {
- ParseTariffType(attr);
- return 0;
- }
- if (strcasecmp(el, "dir_num") == 0)
- {
- ParseDirNum(attr);
- return 0;
- }
- if (strcasecmp(el, "users_num") == 0)
- {
- ParseUsersNum(attr);
- return 0;
- }
- if (strcasecmp(el, "tariff_num") == 0)
- {
- ParseTariffsNum(attr);
- return 0;
- }
-
- for (int j = 0; j < DIR_NUM; j++)
- {
- char str[16];
- sprintf(str, "dir_name_%d", j);
- if (strcasecmp(el, str) == 0)
- {
- ParseDirName(attr, j);
- }
- }
-
- }
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::ParseEnd(const char *)
-{
-depth--;
-if (depth == 0)
- {
- RecvServerInfoDataCb(&serverInfo, serverInfoDataCb);
- }
-}
-//-----------------------------------------------------------------------------
-/*void PARSER_GET_SERVER_INFO::ParseServerInfo(const char * el, const char ** attr)
- {
- }*/
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data)
-{
-RecvServerInfoDataCb = f;
-serverInfoDataCb = data;
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::ParseUname(const char ** attr)
-{
-if (strcmp(*attr, "value") == 0)
- serverInfo.uname = attr[1];
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::ParseServerVersion(const char ** attr)
-{
-if (strcmp(*attr, "value") == 0)
- serverInfo.version = attr[1];
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::ParseUsersNum(const char ** attr)
-{
-if (strcmp(*attr, "value") == 0)
- {
- if (str2x(attr[1], serverInfo.usersNum) < 0)
- {
- serverInfo.usersNum = -1;
- return;
- }
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::ParseTariffsNum(const char ** attr)
-{
-if (strcmp(*attr, "value") == 0)
- {
- if (str2x(attr[1], serverInfo.tariffNum) < 0)
- {
- serverInfo.tariffNum = -1;
- return;
- }
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::ParseTariffType(const char ** attr)
-{
-if (strcmp(*attr, "value") == 0)
- {
- if (str2x(attr[1], serverInfo.tariffType) < 0)
- {
- serverInfo.tariffType = -1;
- return;
- }
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::ParseDirNum(const char **attr)
-{
-if (strcasecmp(*attr, "value") == 0)
- {
- if (str2x(attr[1], serverInfo.dirNum) < 0)
- {
- serverInfo.dirNum = -1;
- return;
- }
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_GET_SERVER_INFO::ParseDirName(const char **attr, int d)
-{
-if (strcmp(attr[0], "value") == 0)
- {
- char str[2*DIRNAME_LEN + 1];
- Decode21(str, attr[1]);
- serverInfo.dirName[d] = str;
- }
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PARSER_CHG_USER::PARSER_CHG_USER()
- : RecvChgUserCb(NULL),
- chgUserCbData(NULL),
- depth(0),
- error(false)
-{
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHG_USER::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- {
- if (strcasecmp(el, "SetUser") == 0)
- {
- ParseAnswer(el, attr);
- }
- else if (strcasecmp(el, "DelUser") == 0)
- {
- ParseAnswer(el, attr);
- }
- else if (strcasecmp(el, "AddUser") == 0)
- {
- ParseAnswer(el, attr);
- }
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHG_USER::ParseEnd(const char *)
-{
-depth--;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHG_USER::ParseAnswer(const char *, const char **attr)
-{
-if (RecvChgUserCb)
- {
- RecvChgUserCb(attr[1], chgUserCbData);
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHG_USER::SetChgUserRecvCb(RecvChgUserCb_t f, void * data)
-{
-RecvChgUserCb = f;
-chgUserCbData = data;
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PARSER_CHECK_USER::PARSER_CHECK_USER()
- : RecvCheckUserCb(NULL),
- checkUserCbData(NULL),
- depth(0),
- error(false)
-{
-}
-//-----------------------------------------------------------------------------
-int PARSER_CHECK_USER::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- {
- if (strcasecmp(el, "CheckUser") == 0)
- {
- //printf("el=%s attr[0]=%s attr[1]=%s\n", el, attr[0], attr[1]);
- ParseAnswer(el, attr);
- }
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHECK_USER::ParseEnd(const char *)
-{
-depth--;
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr)
-{
-if (RecvCheckUserCb)
- {
- RecvCheckUserCb(attr[1], checkUserCbData);
- }
-}
-//-----------------------------------------------------------------------------
-void PARSER_CHECK_USER::SetCheckUserRecvCb(RecvCheckUserCb_t f, void * data)
-{
-RecvCheckUserCb = f;
-checkUserCbData = data;
-}
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-//-----------------------------------------------------------------------------
-PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE()
- : RecvSendMessageCb(NULL),
- sendMessageCbData(NULL),
- depth(0),
- error(false)
-{
-}
-//-----------------------------------------------------------------------------
-int PARSER_SEND_MESSAGE::ParseStart(const char *el, const char **attr)
-{
-depth++;
-if (depth == 1)
- {
- if (strcasecmp(el, "SendMessageResult") == 0)
- {
- ParseAnswer(el, attr);
- }
- }
-return 0;
-}
-//-----------------------------------------------------------------------------
-void PARSER_SEND_MESSAGE::ParseEnd(const char *)
-{
-depth--;
-}
-//-----------------------------------------------------------------------------
-void PARSER_SEND_MESSAGE::ParseAnswer(const char *, const char **attr)
-{
-if (RecvSendMessageCb)
- RecvSendMessageCb(attr[1], sendMessageCbData);
-}
-//-----------------------------------------------------------------------------
-void PARSER_SEND_MESSAGE::SetSendMessageRecvCb(RecvSendMessageCb_t f, void * data)
-{
-RecvSendMessageCb = f;
-sendMessageCbData = data;
-}
-//-----------------------------------------------------------------------------
--- /dev/null
+/*
+ * 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>
+ */
+
+#include "stg/parser_auth_by.h"
+
+#include <cstddef>
+
+#include <strings.h> // strcasecmp
+
+PARSER_AUTH_BY::PARSER_AUTH_BY()
+ : callback(NULL),
+ data(NULL),
+ depth(0),
+ parsingAnswer(false)
+{
+}
+//-----------------------------------------------------------------------------
+int PARSER_AUTH_BY::ParseStart(const char *el, const char **attr)
+{
+depth++;
+if (depth == 1)
+ {
+ if (strcasecmp(el, "AuthorizedBy") == 0)
+ if (attr && attr[0] && attr[1])
+ {
+ if (strcasecmp(attr[1], "error") == 0)
+ {
+ if (attr[2] && attr[3])
+ error = attr[3];
+ else
+ error = "User not found.";
+ }
+ else
+ parsingAnswer = true;
+ }
+ }
+else
+ {
+ if (depth == 2)
+ {
+ if (parsingAnswer && strcasecmp(el, "Auth") == 0)
+ {
+ if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "name") == 0)
+ info.push_back(attr[1]);
+ return 0;
+ }
+ }
+ }
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_AUTH_BY::ParseEnd(const char * /*el*/)
+{
+depth--;
+if (depth == 0)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ info.clear();
+ error.clear();
+ }
+}
+//-----------------------------------------------------------------------------
+void PARSER_AUTH_BY::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "stg/parser_check_user.h"
+
+#include <cstddef>
+
+#include <strings.h>
+
+PARSER_CHECK_USER::PARSER_CHECK_USER()
+ : callback(NULL),
+ data(NULL),
+ depth(0)
+{
+}
+//-----------------------------------------------------------------------------
+int PARSER_CHECK_USER::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1)
+ if (strcasecmp(el, "CheckUser") == 0)
+ ParseAnswer(el, attr);
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_CHECK_USER::ParseEnd(const char *)
+{
+depth--;
+}
+//-----------------------------------------------------------------------------
+void PARSER_CHECK_USER::ParseAnswer(const char *, const char **attr)
+{
+if (!callback)
+ return;
+if (attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0)
+ callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data);
+else
+ callback(false, "Invalid response.", data);
+}
+//-----------------------------------------------------------------------------
+void PARSER_CHECK_USER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "stg/parser_chg_user.h"
+
+#include <cstddef>
+
+#include <strings.h>
+
+PARSER_CHG_USER::PARSER_CHG_USER()
+ : callback(NULL),
+ data(NULL),
+ depth(0)
+{
+}
+//-----------------------------------------------------------------------------
+int PARSER_CHG_USER::ParseStart(const char *el, const char **attr)
+{
+depth++;
+if (depth == 1)
+ {
+ if (strcasecmp(el, "SetUser") == 0)
+ ParseAnswer(el, attr);
+ else if (strcasecmp(el, "DelUser") == 0)
+ ParseAnswer(el, attr);
+ else if (strcasecmp(el, "AddUser") == 0)
+ ParseAnswer(el, attr);
+ }
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_CHG_USER::ParseEnd(const char *)
+{
+depth--;
+}
+//-----------------------------------------------------------------------------
+void PARSER_CHG_USER::ParseAnswer(const char * /*el*/, const char ** attr)
+{
+if (!callback)
+ return;
+if (attr && attr[0] && attr[1])
+ callback(strcasecmp(attr[1], "ok") == 0, attr[2] && attr[3] ? attr[3] : "", data);
+else
+ callback(false, "Invalid response.", data);
+}
+//-----------------------------------------------------------------------------
+void PARSER_CHG_USER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "stg/parser_get_user.h"
+
+#include "stg/common.h"
+
+#include <map>
+#include <utility>
+#include <cstddef>
+
+#include <strings.h>
+
+template <>
+bool GetValue<PARSER_GET_USER::STAT>(const char ** attr, PARSER_GET_USER::STAT & value)
+{
+if (!attr)
+ return false;
+std::map<std::string, long long *> props;
+for (size_t i = 0; i < DIR_NUM; ++i)
+ {
+ props.insert(std::pair<std::string, long long *>("su" + x2str(i), &value.su[i]));
+ props.insert(std::pair<std::string, long long *>("sd" + x2str(i), &value.sd[i]));
+ props.insert(std::pair<std::string, long long *>("mu" + x2str(i), &value.mu[i]));
+ props.insert(std::pair<std::string, long long *>("md" + x2str(i), &value.md[i]));
+ }
+size_t pos = 0;
+while (attr[pos])
+ {
+ std::string name(ToLower(attr[pos++]));
+ std::map<std::string, long long *>::iterator it(props.find(name));
+ if (it != props.end())
+ if (str2x(attr[pos++], *it->second) < 0)
+ return false;
+ }
+return true;
+}
+
+PARSER_GET_USER::PARSER_GET_USER()
+ : callback(NULL),
+ data(NULL),
+ depth(0),
+ parsingAnswer(false)
+{
+ AddParser(propertyParsers, "login", info.login);
+ AddParser(propertyParsers, "password", info.password);
+ AddParser(propertyParsers, "cash", info.cash);
+ AddParser(propertyParsers, "credit", info.credit);
+ AddParser(propertyParsers, "creditExpire", info.creditExpire);
+ AddParser(propertyParsers, "lastCash", info.lastCash);
+ AddParser(propertyParsers, "prepaidTraff", info.prepaidTraff);
+ AddParser(propertyParsers, "down", info.down);
+ AddParser(propertyParsers, "passive", info.passive);
+ AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat);
+ AddParser(propertyParsers, "connected", info.connected);
+ AddParser(propertyParsers, "alwaysOnline", info.alwaysOnline);
+ AddParser(propertyParsers, "currIP", info.ip, GetIPValue);
+ AddParser(propertyParsers, "ip", info.ips);
+ AddParser(propertyParsers, "tariff", info.tariff);
+ AddParser(propertyParsers, "group", info.group, GetEncodedValue);
+ AddParser(propertyParsers, "note", info.note, GetEncodedValue);
+ AddParser(propertyParsers, "email", info.email, GetEncodedValue);
+ AddParser(propertyParsers, "name", info.name, GetEncodedValue);
+ AddParser(propertyParsers, "address", info.address, GetEncodedValue);
+ AddParser(propertyParsers, "phone", info.phone, GetEncodedValue);
+ AddParser(propertyParsers, "traff", info.stat);
+
+ for (size_t i = 0; i < USERDATA_NUM; ++i)
+ AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue);
+}
+//-----------------------------------------------------------------------------
+PARSER_GET_USER::~PARSER_GET_USER()
+{
+ PROPERTY_PARSERS::iterator it(propertyParsers.begin());
+ while (it != propertyParsers.end())
+ delete (it++)->second;
+}
+//-----------------------------------------------------------------------------
+int PARSER_GET_USER::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1)
+ ParseUser(el, attr);
+
+if (depth == 2 && parsingAnswer)
+ ParseUserParams(el, attr);
+
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_GET_USER::ParseEnd(const char * /*el*/)
+{
+depth--;
+if (depth == 0 && parsingAnswer)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ error.clear();
+ parsingAnswer = false;
+ }
+}
+//-----------------------------------------------------------------------------
+void PARSER_GET_USER::ParseUser(const char * el, const char ** attr)
+{
+if (strcasecmp(el, "user") == 0)
+ if (attr && attr[0] && attr[1])
+ {
+ if (strcasecmp(attr[1], "error") == 0)
+ {
+ if (attr[2] && attr[3])
+ error = attr[3];
+ else
+ error = "User not found.";
+ }
+ else
+ parsingAnswer = true;
+ }
+ else
+ parsingAnswer = true;
+}
+//-----------------------------------------------------------------------------
+void PARSER_GET_USER::ParseUserParams(const char * el, const char ** attr)
+{
+if (!TryParse(propertyParsers, ToLower(el), attr))
+ error = "Invalid parameter.";
+}
+//-----------------------------------------------------------------------------
+void PARSER_GET_USER::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "stg/parser_get_users.h"
+
+#include <cstddef>
+
+#include <strings.h>
+
+PARSER_GET_USERS::PARSER_GET_USERS()
+ : callback(NULL),
+ data(NULL),
+ depth(0),
+ parsingAnswer(false)
+{
+ userParser.SetCallback(&PARSER_GET_USERS::UserCallback, this);
+}
+//-----------------------------------------------------------------------------
+int PARSER_GET_USERS::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1 && strcasecmp(el, "users") == 0)
+ parsingAnswer = true;
+
+if (depth > 1 && parsingAnswer)
+ userParser.ParseStart(el, attr);
+
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_GET_USERS::ParseEnd(const char * el)
+{
+depth--;
+if (depth > 0 && parsingAnswer)
+ userParser.ParseEnd(el);
+
+if (depth == 0 && parsingAnswer)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ error.clear();
+ info.clear();
+ parsingAnswer = false;
+ }
+}
+//-----------------------------------------------------------------------------
+void PARSER_GET_USERS::AddUser(const PARSER_GET_USER::INFO & userInfo)
+{
+info.push_back(userInfo);
+}
+//-----------------------------------------------------------------------------
+void PARSER_GET_USERS::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
+//-----------------------------------------------------------------------------
+void PARSER_GET_USERS::UserCallback(bool result, const std::string & error, const PARSER_GET_USER::INFO & info, void * data)
+{
+ PARSER_GET_USERS * parser = static_cast<PARSER_GET_USERS *>(data);
+ if (!result)
+ parser->SetError(error);
+ else
+ parser->AddUser(info);
+}
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "stg/parser_send_message.h"
+
+#include <cstddef>
+
+#include <strings.h>
+
+PARSER_SEND_MESSAGE::PARSER_SEND_MESSAGE()
+ : callback(NULL),
+ data(NULL),
+ depth(0)
+{
+}
+//-----------------------------------------------------------------------------
+int PARSER_SEND_MESSAGE::ParseStart(const char * el, const char ** attr)
+{
+depth++;
+if (depth == 1)
+ if (strcasecmp(el, "SendMessageResult") == 0)
+ ParseAnswer(el, attr);
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_SEND_MESSAGE::ParseEnd(const char * /*el*/)
+{
+depth--;
+}
+//-----------------------------------------------------------------------------
+void PARSER_SEND_MESSAGE::ParseAnswer(const char * /*el*/, const char **attr)
+{
+if (!callback)
+ return;
+if (attr && attr[0] && attr[1])
+ callback(strcasecmp(attr[1], "ok") == 0, attr[1], data);
+else
+ callback(false, "Invalid response.", data);
+}
+//-----------------------------------------------------------------------------
+void PARSER_SEND_MESSAGE::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * 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 : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ */
+
+#include "stg/parser_server_info.h"
+
+#include "stg/common.h"
+
+#include <cstdio> // sprintf
+#include <cstddef>
+
+#include <strings.h>
+
+namespace
+{
+
+const size_t UNAME_LEN = 256;
+const size_t SERV_VER_LEN = 64;
+const size_t DIRNAME_LEN = 16;
+
+}
+
+PARSER_SERVER_INFO::PARSER_SERVER_INFO()
+ : callback(NULL),
+ data(NULL),
+ depth(0),
+ parsingAnswer(false)
+{
+ AddParser(propertyParsers, "uname", info.uname);
+ AddParser(propertyParsers, "version", info.version);
+ AddParser(propertyParsers, "tariff", info.tariffType);
+ AddParser(propertyParsers, "dir_num", info.dirNum);
+ AddParser(propertyParsers, "users_num", info.usersNum);
+ AddParser(propertyParsers, "tariff_num", info.tariffNum);
+
+ for (size_t i = 0; i < DIR_NUM; i++)
+ AddParser(propertyParsers, "dir_name_" + x2str(i), info.dirName[i], GetEncodedValue);
+}
+//-----------------------------------------------------------------------------
+int PARSER_SERVER_INFO::ParseStart(const char *el, const char **attr)
+{
+depth++;
+if (depth == 1)
+ if (strcasecmp(el, "ServerInfo") == 0)
+ parsingAnswer = true;
+else
+ if (depth == 2 && parsingAnswer)
+ if (!TryParse(propertyParsers, ToLower(el), attr))
+ error = "Invalid parameter.";
+return 0;
+}
+//-----------------------------------------------------------------------------
+void PARSER_SERVER_INFO::ParseEnd(const char * /*el*/)
+{
+depth--;
+if (depth == 0 && parsingAnswer)
+ {
+ if (callback)
+ callback(error.empty(), error, info, data);
+ error.clear();
+ parsingAnswer = false;
+ }
+}
+//-----------------------------------------------------------------------------
+void PARSER_SERVER_INFO::SetCallback(CALLBACK f, void * d)
+{
+callback = f;
+data = d;
+}
--- /dev/null
+/*
+ * 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>
+ */
+
+#include "stg/property_parsers.h"
+
+#include <strings.h>
+
+bool CheckValue(const char ** attr)
+{
+return attr && attr[0] && attr[1] && strcasecmp(attr[0], "value") == 0;
+}
+
+bool GetEncodedValue(const char ** attr, std::string & value)
+{
+if (!CheckValue(attr))
+ return false;
+Decode21str(value, attr[1]);
+return true;
+}
+
+bool GetIPValue(const char ** attr, uint32_t & value)
+{
+if (!CheckValue(attr))
+ return false;
+std::string ip(attr[1]);
+value = inet_strington(attr[1]);
+if (value == 0 && ip != "0.0.0.0")
+ return false;
+return true;
+}
+
+bool TryParse(PROPERTY_PARSERS & parsers, const std::string & name, const char ** attr)
+{
+ PROPERTY_PARSERS::iterator it(parsers.find(name));
+ if (it != parsers.end())
+ return it->second->Parse(attr);
+ return true; // Assume that non-existing params are ok.
+}
* Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
*/
- /*
- $Revision: 1.8 $
- $Date: 2010/08/04 00:40:38 $
- $Author: faust $
- */
-
-#include <cstdio>
-#include <cstring>
+#include "stg/servconf.h"
#include "stg/common.h"
-#include "stg/servconf.h"
-using namespace std;
+#include <cstdio>
+#include <cstring>
//-----------------------------------------------------------------------------
-int AnsRecv(void * data, list<string> * list1)
+int AnsRecv(void * data, std::list<std::string> * list1)
{
-//NODE * node;
-SERVCONF * sc;
-char ans[ENC_MSG_LEN + 1];
-int len, done = 0;
-
-sc = (SERVCONF*)data;
+SERVCONF * sc = static_cast<SERVCONF *>(data);
XML_ParserReset(sc->parser, NULL);
XML_SetElementHandler(sc->parser, Start, End);
XML_SetUserData(sc->parser, data);
+char ans[ENC_MSG_LEN + 1];
+int len, done = 0;
+
//loop parsing
-list<string>::iterator node;
+std::list<std::string>::iterator node;
node = list1->begin();
-if (node == list1->end())
- {
- return st_ok;
- }
-
while (node != list1->end())
{
strncpy(ans, node->c_str(), ENC_MSG_LEN);
ans[ENC_MSG_LEN] = 0;
- //printf("---> %s\n", ans);
len = strlen(ans);
if (XML_Parse(sc->parser, ans, len, done) == XML_STATUS_ERROR)
strprintf(&sc->errorMsg, "XML parse error at line %d: %s",
static_cast<int>(XML_GetCurrentLineNumber(sc->parser)),
XML_ErrorString(XML_GetErrorCode(sc->parser)));
+ printf("%s\n", sc->errorMsg.c_str());
return st_xml_parse_error;
}
++node;
-
}
-return 0;
+return st_ok;
}
//-----------------------------------------------------------------------------
void Start(void *data, const char *el, const char **attr)
{
-SERVCONF * sc;
-sc = (SERVCONF*)data;
+SERVCONF * sc = static_cast<SERVCONF *>(data);
sc->Start(el, attr);
}
//-----------------------------------------------------------------------------
-void End(void *data, const char *el)
+void End(void * data, const char * el)
{
-SERVCONF * sc;
-sc = (SERVCONF*)data;
+SERVCONF * sc = static_cast<SERVCONF *>(data);
sc->End(el);
}
//-----------------------------------------------------------------------------
SERVCONF::SERVCONF()
- : currParser(NULL),
- parseDepth(0),
- error(0),
- RecvUserDataCb(NULL),
- RecvGetUserDataCb(NULL),
- RecvServerInfoDataCb(NULL),
- RecvChgUserCb(NULL),
- RecvCheckUserCb(NULL),
- RecvSendMessageCb(NULL),
- getUserDataDataCb(NULL),
- getUsersDataDataCb(NULL),
- getServerInfoDataCb(NULL),
- chgUserDataCb(NULL),
- checkUserDataCb(NULL),
- sendMessageDataCb(NULL)
+ : currParser(NULL)
{
parser = XML_ParserCreate(NULL);
+nt.SetRxCallback(this, AnsRecv);
}
//-----------------------------------------------------------------------------
void SERVCONF::SetServer(const char * server)
{
char request[255];
snprintf(request, 255, "<GetUser login=\"%s\"/>", l);
-int ret;
currParser = &parserGetUser;
-((PARSER_GET_USER*)currParser)->SetUserDataRecvCb(RecvGetUserDataCb, getUserDataDataCb);
-
-nt.Reset();
-nt.SetRxCallback(this, AnsRecv);
-if ((ret = nt.Connect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Transact(request)) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Disconnect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-
-return st_ok;
+return Exec(request);
}
//-----------------------------------------------------------------------------
-int SERVCONF::GetUsers()
+int SERVCONF::AuthBy(const char * l)
{
-char request[] = "<GetUsers/>";
-int ret;
-
-currParser = &parserGetUsers;
-((PARSER_GET_USERS*)currParser)->SetUserDataRecvCb(RecvUserDataCb, getUsersDataDataCb);
-
-nt.Reset();
-nt.SetRxCallback(this, AnsRecv);
+char request[255];
+snprintf(request, 255, "<GetUserAuthBy login=\"%s\"/>", l);
-if ((ret = nt.Connect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Transact(request)) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Disconnect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
+currParser = &parserAuthBy;
-return st_ok;
+return Exec(request);
}
//-----------------------------------------------------------------------------
-int SERVCONF::SendMessage(const char * login, const char * message, int prio)
+int SERVCONF::GetUsers()
{
-char request[1000];
-char msg[500];
-Encode12(msg, message, strlen(message));
-snprintf(request, 1000, "<Message login=\"%s\" priority=\"%d\" text=\"%s\"/>", login, prio, msg);
-int ret;
-
-currParser = &parserSendMessage;
-parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb);
-
-nt.Reset();
-nt.SetRxCallback(this, AnsRecv);
+char request[] = "<GetUsers/>";
-if ((ret = nt.Connect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Transact(request)) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Disconnect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
+currParser = &parserGetUsers;
-return st_ok;
+return Exec(request);
}
//-----------------------------------------------------------------------------
-int SERVCONF::GetServerInfo()
+int SERVCONF::ServerInfo()
{
char request[] = "<GetServerInfo/>";
-int ret;
currParser = &parserServerInfo;
-((PARSER_GET_SERVER_INFO*)currParser)->SetServerInfoRecvCb(RecvServerInfoDataCb, getServerInfoDataCb);
-
-nt.Reset();
-nt.SetRxCallback(this, AnsRecv);
-if ((ret = nt.Connect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Transact(request)) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Disconnect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-
-return st_ok;
+return Exec(request);
}
//-----------------------------------------------------------------------------
int SERVCONF::ChgUser(const char * request)
{
-int ret;
-
currParser = &parserChgUser;
-((PARSER_CHG_USER*)currParser)->SetChgUserRecvCb(RecvChgUserCb, chgUserDataCb);
-nt.Reset();
-nt.SetRxCallback(this, AnsRecv);
-
-if ((ret = nt.Connect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Transact(request)) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Disconnect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-
-return st_ok;
+return Exec(request);
}
//-----------------------------------------------------------------------------
-// TODO: remove this shit!
-//-----------------------------------------------------------------------------
-int SERVCONF::MsgUser(const char * request)
+int SERVCONF::SendMessage(const char * request)
{
-int ret;
-
currParser = &parserSendMessage;
-parserSendMessage.SetSendMessageRecvCb(RecvSendMessageCb, sendMessageDataCb);
-
-nt.Reset();
-nt.SetRxCallback(this, AnsRecv);
-if ((ret = nt.Connect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Transact(request)) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Disconnect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-
-return st_ok;
+return Exec(request);
}
//-----------------------------------------------------------------------------
int SERVCONF::CheckUser(const char * login, const char * password)
{
char request[255];
snprintf(request, 255, "<CheckUser login=\"%s\" password=\"%s\"/>", login, password);
-int ret;
currParser = &parserCheckUser;
-((PARSER_CHECK_USER*)currParser)->SetCheckUserRecvCb(RecvCheckUserCb, checkUserDataCb);
-
-nt.Reset();
-nt.SetRxCallback(this, AnsRecv);
-
-if ((ret = nt.Connect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Transact(request)) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-if ((ret = nt.Disconnect()) != st_ok)
- {
- errorMsg = nt.GetError();
- return ret;
- }
-return st_ok;
+return Exec(request);
}
//-----------------------------------------------------------------------------
-int SERVCONF::Start(const char *el, const char **attr)
+int SERVCONF::Start(const char * el, const char ** attr)
{
currParser->ParseStart(el, attr);
return 0;
}
//-----------------------------------------------------------------------------
-void SERVCONF::End(const char *el)
+void SERVCONF::End(const char * el)
{
currParser->ParseEnd(el);
}
//-----------------------------------------------------------------------------
-void SERVCONF::SetUserDataRecvCb(RecvUserDataCb_t f, void * data)
+void SERVCONF::SetGetUsersCallback(PARSER_GET_USERS::CALLBACK f, void * data)
+{
+parserGetUsers.SetCallback(f, data);
+}
+//-----------------------------------------------------------------------------
+void SERVCONF::SetGetUserCallback(PARSER_GET_USER::CALLBACK f, void * data)
{
-RecvUserDataCb = f;
-getUsersDataDataCb = data;
+parserGetUser.SetCallback(f, data);
}
//-----------------------------------------------------------------------------
-void SERVCONF::SetGetUserDataRecvCb(RecvUserDataCb_t f, void * data)
+void SERVCONF::SetAuthByCallback(PARSER_AUTH_BY::CALLBACK f, void * data)
{
-RecvGetUserDataCb = f; //GET_USER
-getUserDataDataCb = data;
+parserAuthBy.SetCallback(f, data);
}
//-----------------------------------------------------------------------------
-void SERVCONF::SetServerInfoRecvCb(RecvServerInfoDataCb_t f, void * data)
+void SERVCONF::SetServerInfoCallback(PARSER_SERVER_INFO::CALLBACK f, void * data)
{
-RecvServerInfoDataCb = f;
-getServerInfoDataCb = data;
+parserServerInfo.SetCallback(f, data);
}
//-----------------------------------------------------------------------------
-void SERVCONF::SetChgUserCb(RecvChgUserCb_t f, void * data)
+void SERVCONF::SetChgUserCallback(PARSER_CHG_USER::CALLBACK f, void * data)
{
-RecvChgUserCb = f;
-chgUserDataCb = data;
+parserChgUser.SetCallback(f, data);
}
//-----------------------------------------------------------------------------
-void SERVCONF::SetCheckUserCb(RecvCheckUserCb_t f, void * data)
+void SERVCONF::SetCheckUserCallback(PARSER_CHECK_USER::CALLBACK f, void * data)
{
-RecvCheckUserCb = f;
-checkUserDataCb = data;
+parserCheckUser.SetCallback(f, data);
}
//-----------------------------------------------------------------------------
-void SERVCONF::SetSendMessageCb(RecvSendMessageCb_t f, void * data)
+void SERVCONF::SetSendMessageCallback(PARSER_SEND_MESSAGE::CALLBACK f, void * data)
{
-RecvSendMessageCb = f;
-sendMessageDataCb = data;
+parserSendMessage.SetCallback(f, data);
}
//-----------------------------------------------------------------------------
const std::string & SERVCONF::GetStrError() const
return errorMsg;
}
//-----------------------------------------------------------------------------
-int SERVCONF::GetError()
+int SERVCONF::Exec(const char * request)
{
-int e = error;
-error = 0;
-return e;
+nt.Reset();
+
+int ret = 0;
+if ((ret = nt.Connect()) != st_ok)
+ {
+ errorMsg = nt.GetError();
+ return ret;
+ }
+if ((ret = nt.Transact(request)) != st_ok)
+ {
+ errorMsg = nt.GetError();
+ return ret;
+ }
+if ((ret = nt.Disconnect()) != st_ok)
+ {
+ errorMsg = nt.GetError();
+ return ret;
+ }
+
+return st_ok;
}
-//-----------------------------------------------------------------------------