From: Maxim Mamontov Date: Mon, 19 Sep 2011 08:57:52 +0000 (+0300) Subject: TUT framework updated to svn version X-Git-Tag: 2.408-rc1~27 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/261442af210d652fc2c8a3d9197097982701bd16 TUT framework updated to svn version Libs headers moved to its own folders --- diff --git a/stglibs/common.lib/common.h b/stglibs/common.lib/common.h deleted file mode 100644 index ac091147..00000000 --- a/stglibs/common.lib/common.h +++ /dev/null @@ -1,245 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.32 $ - $Date: 2010/11/08 10:11:19 $ - $Author: faust $ - */ - -#ifndef common_h -#define common_h - -#ifdef __BORLANDC__ -#include -#else -#include -#endif -#include - -#include "stg/os_int.h" -#include "stg/const.h" - -#define STAT_TIME_3 (1) -#define STAT_TIME_2 (2) -#define STAT_TIME_1 (3) -#define STAT_TIME_1_2 (4) -#define STAT_TIME_1_4 (5) -#define STAT_TIME_1_6 (6) - -#define FN_STR_LEN (NAME_MAX) - -#define ST_F 0 -#define ST_B 1 -#define ST_KB 2 -#define ST_MB 3 - -//----------------------------------------------------------------------------- -const char * IntToKMG(long long a, int statType = ST_F); -const char * LogDate(time_t t); -int ParesTimeStat(const char * str); -int IsTimeStat(struct tm * t, int statTime); -/*bool IsDigit(char c); -bool IsAlpha(char c);*/ -int strtodouble2(const char * s, double &a); -int printfd(const char * __file__, const char * fmt, ...); -void Encode12(char * dst, const char * src, size_t srcLen); -void Decode21(char * dst, const char * src); - -void Encode12str(std::string & dst, const std::string & src); -void Decode21str(std::string & dst, const std::string & src); - -int ParseIPString(const char * str, uint32_t * ips, int maxIP); -void KOIToWin(const char * s1, char * s2, int l); -void WinToKOI(const char * s1, char * s2, int l); -void KOIToWin(const std::string & s1, std::string * s2); -void WinToKOI(const std::string & s1, std::string * s2); -int DaysInMonth(unsigned year, unsigned mon); -int DaysInCurrentMonth(); -int Min8(int a); -//char * inet_ntostr(unsigned long); -std::string inet_ntostring(uint32_t); -uint32_t inet_strington(const std::string & value); -int strprintf(std::string * str, const char * fmt, ...); -int ParseTariffTimeStr(const char * str, int &h1, int &m1, int &h2, int &m2); -uint32_t CalcMask(uint32_t msk); -void TouchFile(const std::string & fileName); -#ifdef WIN32 -void EncodeStr(char * str, unsigned long serial, int useHDD); -void DecodeStr(char * str, unsigned long serial, int useHDD); -#endif //WIN32 -void SwapBytes(uint16_t & value); -void SwapBytes(uint32_t & value); -void SwapBytes(uint64_t & value); -void SwapBytes(int16_t & value); -void SwapBytes(int32_t & value); -void SwapBytes(int64_t & value); - -std::string & TrimL(std::string & val); -std::string & TrimR(std::string & val); -std::string & Trim(std::string & val); - -std::string IconvString(const std::string & source, const std::string & from, const std::string & to); - -int ParseInt(const std::string & str, int * val); -int ParseUnsigned(const std::string & str, unsigned * val); -int ParseIntInRange(const std::string & str, int min, int max, int * val); -int ParseUnsignedInRange(const std::string & str, unsigned min, - unsigned max, unsigned * val); -int ParseYesNo(const std::string & str, bool * val); - -bool WaitPackets(int sd); - -//----------------------------------------------------------------------------- -template -int str2x(const std::string & str, varT & x) -{ - int pos = 0; - int minus = 1; - - if (str.empty()) - return -1; - - if (str[0] == '+') - pos++; - - if (str[0] == '-') - { - pos++; - minus = -1; - } - - if ((str[pos] < '0' || str[pos] > '9')) - return -1; - - x = str[pos++] - '0'; - - for (unsigned i = pos; i < str.size(); i++) - { - if ((str[i] < '0' || str[i] > '9')) - return -1; - - x *= 10; - x += str[i] - '0'; - } - - x*= minus; - - return 0; -} -//----------------------------------------------------------------------------- -template -const std::string & x2str(varT x, std::string & s) -{ - varT xx = x; - int pos = 1; - - x /= 10; - while (x != 0) - { - x /= 10; - pos++; - } - - if (xx < 0) - { - pos++; - s.resize(pos, 0); - s[0] = '-'; - } - else if (xx > 0) - { - s.resize(pos, 0); - } - else - { - s.resize(1, 0); - s[0] = '0'; - return s; - } - - x = xx; - - while (x != 0) - { - if (x < 0) - s[--pos] = -(x % 10) + '0'; - else - s[--pos] = x % 10 + '0'; - - x /= 10; - } - - return s; -} -//----------------------------------------------------------------------------- -template -const std::string & unsigned2str(varT x, std::string & s) -{ - varT xx = x; - int pos = 1; - - x /= 10; - while (x != 0) - { - x /= 10; - pos++; - } - - if (xx > 0) - { - s.resize(pos, 0); - } - else - { - s.resize(1, 0); - s[0] = '0'; - return s; - } - - x = xx; - - while (x != 0) - { - s[--pos] = x % 10 + '0'; - - x /= 10; - } - - return s; -} -//----------------------------------------------------------------------------- -int str2x(const std::string & str, int & x); -int str2x(const std::string & str, unsigned & x); -int str2x(const std::string & str, long & x); -int str2x(const std::string & str, unsigned long & x); -#ifndef WIN32 -int str2x(const std::string & str, long long & x); -int str2x(const std::string & str, unsigned long long & x); -#endif -//----------------------------------------------------------------------------- -const std::string & x2str(unsigned x, std::string & s); -const std::string & x2str(unsigned long x, std::string & s); -const std::string & x2str(unsigned long long x, std::string & s); -//----------------------------------------------------------------------------- -char * stg_strptime(const char *, const char *, struct tm *); -time_t stg_timegm(struct tm *); - -#endif diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h new file mode 100644 index 00000000..ac091147 --- /dev/null +++ b/stglibs/common.lib/include/stg/common.h @@ -0,0 +1,245 @@ +/* + * 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 + */ + + /* + $Revision: 1.32 $ + $Date: 2010/11/08 10:11:19 $ + $Author: faust $ + */ + +#ifndef common_h +#define common_h + +#ifdef __BORLANDC__ +#include +#else +#include +#endif +#include + +#include "stg/os_int.h" +#include "stg/const.h" + +#define STAT_TIME_3 (1) +#define STAT_TIME_2 (2) +#define STAT_TIME_1 (3) +#define STAT_TIME_1_2 (4) +#define STAT_TIME_1_4 (5) +#define STAT_TIME_1_6 (6) + +#define FN_STR_LEN (NAME_MAX) + +#define ST_F 0 +#define ST_B 1 +#define ST_KB 2 +#define ST_MB 3 + +//----------------------------------------------------------------------------- +const char * IntToKMG(long long a, int statType = ST_F); +const char * LogDate(time_t t); +int ParesTimeStat(const char * str); +int IsTimeStat(struct tm * t, int statTime); +/*bool IsDigit(char c); +bool IsAlpha(char c);*/ +int strtodouble2(const char * s, double &a); +int printfd(const char * __file__, const char * fmt, ...); +void Encode12(char * dst, const char * src, size_t srcLen); +void Decode21(char * dst, const char * src); + +void Encode12str(std::string & dst, const std::string & src); +void Decode21str(std::string & dst, const std::string & src); + +int ParseIPString(const char * str, uint32_t * ips, int maxIP); +void KOIToWin(const char * s1, char * s2, int l); +void WinToKOI(const char * s1, char * s2, int l); +void KOIToWin(const std::string & s1, std::string * s2); +void WinToKOI(const std::string & s1, std::string * s2); +int DaysInMonth(unsigned year, unsigned mon); +int DaysInCurrentMonth(); +int Min8(int a); +//char * inet_ntostr(unsigned long); +std::string inet_ntostring(uint32_t); +uint32_t inet_strington(const std::string & value); +int strprintf(std::string * str, const char * fmt, ...); +int ParseTariffTimeStr(const char * str, int &h1, int &m1, int &h2, int &m2); +uint32_t CalcMask(uint32_t msk); +void TouchFile(const std::string & fileName); +#ifdef WIN32 +void EncodeStr(char * str, unsigned long serial, int useHDD); +void DecodeStr(char * str, unsigned long serial, int useHDD); +#endif //WIN32 +void SwapBytes(uint16_t & value); +void SwapBytes(uint32_t & value); +void SwapBytes(uint64_t & value); +void SwapBytes(int16_t & value); +void SwapBytes(int32_t & value); +void SwapBytes(int64_t & value); + +std::string & TrimL(std::string & val); +std::string & TrimR(std::string & val); +std::string & Trim(std::string & val); + +std::string IconvString(const std::string & source, const std::string & from, const std::string & to); + +int ParseInt(const std::string & str, int * val); +int ParseUnsigned(const std::string & str, unsigned * val); +int ParseIntInRange(const std::string & str, int min, int max, int * val); +int ParseUnsignedInRange(const std::string & str, unsigned min, + unsigned max, unsigned * val); +int ParseYesNo(const std::string & str, bool * val); + +bool WaitPackets(int sd); + +//----------------------------------------------------------------------------- +template +int str2x(const std::string & str, varT & x) +{ + int pos = 0; + int minus = 1; + + if (str.empty()) + return -1; + + if (str[0] == '+') + pos++; + + if (str[0] == '-') + { + pos++; + minus = -1; + } + + if ((str[pos] < '0' || str[pos] > '9')) + return -1; + + x = str[pos++] - '0'; + + for (unsigned i = pos; i < str.size(); i++) + { + if ((str[i] < '0' || str[i] > '9')) + return -1; + + x *= 10; + x += str[i] - '0'; + } + + x*= minus; + + return 0; +} +//----------------------------------------------------------------------------- +template +const std::string & x2str(varT x, std::string & s) +{ + varT xx = x; + int pos = 1; + + x /= 10; + while (x != 0) + { + x /= 10; + pos++; + } + + if (xx < 0) + { + pos++; + s.resize(pos, 0); + s[0] = '-'; + } + else if (xx > 0) + { + s.resize(pos, 0); + } + else + { + s.resize(1, 0); + s[0] = '0'; + return s; + } + + x = xx; + + while (x != 0) + { + if (x < 0) + s[--pos] = -(x % 10) + '0'; + else + s[--pos] = x % 10 + '0'; + + x /= 10; + } + + return s; +} +//----------------------------------------------------------------------------- +template +const std::string & unsigned2str(varT x, std::string & s) +{ + varT xx = x; + int pos = 1; + + x /= 10; + while (x != 0) + { + x /= 10; + pos++; + } + + if (xx > 0) + { + s.resize(pos, 0); + } + else + { + s.resize(1, 0); + s[0] = '0'; + return s; + } + + x = xx; + + while (x != 0) + { + s[--pos] = x % 10 + '0'; + + x /= 10; + } + + return s; +} +//----------------------------------------------------------------------------- +int str2x(const std::string & str, int & x); +int str2x(const std::string & str, unsigned & x); +int str2x(const std::string & str, long & x); +int str2x(const std::string & str, unsigned long & x); +#ifndef WIN32 +int str2x(const std::string & str, long long & x); +int str2x(const std::string & str, unsigned long long & x); +#endif +//----------------------------------------------------------------------------- +const std::string & x2str(unsigned x, std::string & s); +const std::string & x2str(unsigned long x, std::string & s); +const std::string & x2str(unsigned long long x, std::string & s); +//----------------------------------------------------------------------------- +char * stg_strptime(const char *, const char *, struct tm *); +time_t stg_timegm(struct tm *); + +#endif diff --git a/stglibs/conffiles.lib/conffiles.h b/stglibs/conffiles.lib/conffiles.h deleted file mode 100644 index 6909c6c9..00000000 --- a/stglibs/conffiles.lib/conffiles.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Date: 27.10.2002 - */ - -/* - * Author : Boris Mikhailenko - */ - -/* - $Revision: 1.5 $ - $Date: 2009/06/22 16:00:38 $ - */ - -//--------------------------------------------------------------------------- - -#ifndef ConfFilesH -#define ConfFilesH - -#include -#include - -#include "stg/os_int.h" - -using namespace std; -//--------------------------------------------------------------------------- - -typedef bool (*StringCaseCmp_t)(const string & str1, const string & str2); - -class CONFIGFILE -{ -public: - CONFIGFILE(const string & fn, bool nook = false); - ~CONFIGFILE(); - const string & GetFileName() const; - - // æÕÎËÃÉÉ Read* ×ÏÚ×ÒÁÝÁÀÔ 0 ÐÒÉ ÕÓÐÅÛÎÏÍ ÓÞÉÔÙ×ÁÎÉÉ - // É EINVAL ÐÒÉ ÏÔÓÕÔÓ×ÉÉ ÐÁÒÁÍÅÔÒÁ É ×ÙÓÔÁ×ÌÑÀÔ defaulValue - //int ReadString(const string & param, char * val, int * maxLen, const char * defaultVal) const; - int ReadString(const string & param, string * val, const string & defaultVal) const; - int ReadTime(const string & param, time_t *, time_t) const; - int ReadShortInt(const string & param, short int *, short int) const; - int ReadInt(const string & param, int *, int) const; - int ReadLongInt(const string & param, long int *, long int) const; - int ReadLongLongInt(const string & param, int64_t *, int64_t) const; - int ReadUShortInt(const string & param, unsigned short int *, unsigned short int) const; - int ReadUInt(const string & param, unsigned int *, unsigned int) const; - int ReadULongInt(const string & param, unsigned long int *, unsigned long int) const; - int ReadULongLongInt(const string & param, uint64_t *, uint64_t) const; - int ReadDouble(const string & param, double * val, double defaultVal) const; - - void WriteString(const string & param, const char * val) { return WriteString(param, std::string(val)); } - void WriteString(const string & param, const string & val); - void WriteInt(const string & param, int64_t val); - void WriteDouble(const string & param, double val); - - int Error() const; - int Flush() const; - -private: - map param_val; - string fileName; - mutable int error; - mutable bool changed; - - int Flush(const std::string & path) const; -}; -//--------------------------------------------------------------------------- -#endif diff --git a/stglibs/conffiles.lib/include/stg/conffiles.h b/stglibs/conffiles.lib/include/stg/conffiles.h new file mode 100644 index 00000000..6909c6c9 --- /dev/null +++ b/stglibs/conffiles.lib/include/stg/conffiles.h @@ -0,0 +1,84 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Date: 27.10.2002 + */ + +/* + * Author : Boris Mikhailenko + */ + +/* + $Revision: 1.5 $ + $Date: 2009/06/22 16:00:38 $ + */ + +//--------------------------------------------------------------------------- + +#ifndef ConfFilesH +#define ConfFilesH + +#include +#include + +#include "stg/os_int.h" + +using namespace std; +//--------------------------------------------------------------------------- + +typedef bool (*StringCaseCmp_t)(const string & str1, const string & str2); + +class CONFIGFILE +{ +public: + CONFIGFILE(const string & fn, bool nook = false); + ~CONFIGFILE(); + const string & GetFileName() const; + + // æÕÎËÃÉÉ Read* ×ÏÚ×ÒÁÝÁÀÔ 0 ÐÒÉ ÕÓÐÅÛÎÏÍ ÓÞÉÔÙ×ÁÎÉÉ + // É EINVAL ÐÒÉ ÏÔÓÕÔÓ×ÉÉ ÐÁÒÁÍÅÔÒÁ É ×ÙÓÔÁ×ÌÑÀÔ defaulValue + //int ReadString(const string & param, char * val, int * maxLen, const char * defaultVal) const; + int ReadString(const string & param, string * val, const string & defaultVal) const; + int ReadTime(const string & param, time_t *, time_t) const; + int ReadShortInt(const string & param, short int *, short int) const; + int ReadInt(const string & param, int *, int) const; + int ReadLongInt(const string & param, long int *, long int) const; + int ReadLongLongInt(const string & param, int64_t *, int64_t) const; + int ReadUShortInt(const string & param, unsigned short int *, unsigned short int) const; + int ReadUInt(const string & param, unsigned int *, unsigned int) const; + int ReadULongInt(const string & param, unsigned long int *, unsigned long int) const; + int ReadULongLongInt(const string & param, uint64_t *, uint64_t) const; + int ReadDouble(const string & param, double * val, double defaultVal) const; + + void WriteString(const string & param, const char * val) { return WriteString(param, std::string(val)); } + void WriteString(const string & param, const string & val); + void WriteInt(const string & param, int64_t val); + void WriteDouble(const string & param, double val); + + int Error() const; + int Flush() const; + +private: + map param_val; + string fileName; + mutable int error; + mutable bool changed; + + int Flush(const std::string & path) const; +}; +//--------------------------------------------------------------------------- +#endif diff --git a/stglibs/crypto.lib/ag_md5.h b/stglibs/crypto.lib/ag_md5.h deleted file mode 100644 index b278f97b..00000000 --- a/stglibs/crypto.lib/ag_md5.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _MD5_H -#define _MD5_H - -#include - -#include "stg/os_int.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct MD5Context { - uint32_t buf[4]; - uint32_t bits[2]; - unsigned char in[64]; -}; - -typedef struct MD5Context MD5_CTX; - -char *crypt_make_salt(void); -void byteReverse(unsigned char*, unsigned); -void MD5Init(struct MD5Context *ctx); -void MD5Update(struct MD5Context*, char const*, unsigned); -void MD5Final(unsigned char digest[16], struct MD5Context *ctx); -void MD5Transform(uint32_t buf[4], uint32_t const in[16]); -char *libshadow_md5_crypt(const char*, const char*); -char *pw_encrypt(const char*, const char*); - -/* AG functions */ -char *make_ag_hash(time_t salt, const char *clear); -int check_ag_hash(time_t salt, const char *clear, const char *hash); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/stglibs/crypto.lib/blowfish.h b/stglibs/crypto.lib/blowfish.h deleted file mode 100644 index a8800d75..00000000 --- a/stglibs/crypto.lib/blowfish.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Author : Paul Kocher - * E-mail : pck@netcom.com - * Date : 1997 - * Description: C implementation of the Blowfish algorithm. - */ - -#ifndef BLOWFISH_H -#define BLOWFISH_H - -#include "stg/os_int.h" - -#define MAXKEYBYTES 56 /* 448 bits */ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - uint32_t P[16 + 2]; - uint32_t S[4][256]; -} BLOWFISH_CTX; - -void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen); -void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr); -void Blowfish_Decrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr); - -void EnDecodeInit(const char * key, size_t length, BLOWFISH_CTX *ctx); -void DecodeString(char * d, const char * s, BLOWFISH_CTX *ctx); -void EncodeString(char * d, const char * s, BLOWFISH_CTX *ctx); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/stglibs/crypto.lib/include/stg/ag_md5.h b/stglibs/crypto.lib/include/stg/ag_md5.h new file mode 100644 index 00000000..b278f97b --- /dev/null +++ b/stglibs/crypto.lib/include/stg/ag_md5.h @@ -0,0 +1,37 @@ +#ifndef _MD5_H +#define _MD5_H + +#include + +#include "stg/os_int.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct MD5Context { + uint32_t buf[4]; + uint32_t bits[2]; + unsigned char in[64]; +}; + +typedef struct MD5Context MD5_CTX; + +char *crypt_make_salt(void); +void byteReverse(unsigned char*, unsigned); +void MD5Init(struct MD5Context *ctx); +void MD5Update(struct MD5Context*, char const*, unsigned); +void MD5Final(unsigned char digest[16], struct MD5Context *ctx); +void MD5Transform(uint32_t buf[4], uint32_t const in[16]); +char *libshadow_md5_crypt(const char*, const char*); +char *pw_encrypt(const char*, const char*); + +/* AG functions */ +char *make_ag_hash(time_t salt, const char *clear); +int check_ag_hash(time_t salt, const char *clear, const char *hash); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stglibs/crypto.lib/include/stg/blowfish.h b/stglibs/crypto.lib/include/stg/blowfish.h new file mode 100644 index 00000000..a8800d75 --- /dev/null +++ b/stglibs/crypto.lib/include/stg/blowfish.h @@ -0,0 +1,37 @@ +/* + * Author : Paul Kocher + * E-mail : pck@netcom.com + * Date : 1997 + * Description: C implementation of the Blowfish algorithm. + */ + +#ifndef BLOWFISH_H +#define BLOWFISH_H + +#include "stg/os_int.h" + +#define MAXKEYBYTES 56 /* 448 bits */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint32_t P[16 + 2]; + uint32_t S[4][256]; +} BLOWFISH_CTX; + +void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen); +void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr); +void Blowfish_Decrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr); + +void EnDecodeInit(const char * key, size_t length, BLOWFISH_CTX *ctx); +void DecodeString(char * d, const char * s, BLOWFISH_CTX *ctx); +void EncodeString(char * d, const char * s, BLOWFISH_CTX *ctx); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/stglibs/dotconfpp.lib/dotconfpp.h b/stglibs/dotconfpp.lib/dotconfpp.h deleted file mode 100644 index 8c2a82ad..00000000 --- a/stglibs/dotconfpp.lib/dotconfpp.h +++ /dev/null @@ -1,122 +0,0 @@ -/* Copyright (C) 2003 Aleksey Krivoshey -* -* 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 -*/ - - -#ifndef DOTCONFPP_H -#define DOTCONFPP_H - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "stg/os_int.h" - -typedef void (* DOTCONFCallback) (void * data, const char * buf); - -class DOTCONFDocument; -class AsyncDNSMemPool; - -class DOTCONFDocumentNode -{ -friend class DOTCONFDocument; -private: - DOTCONFDocumentNode * previousNode; - DOTCONFDocumentNode * nextNode; - DOTCONFDocumentNode * parentNode; - DOTCONFDocumentNode * childNode; - char ** values; - int valuesCount; - char * name; - const DOTCONFDocument * document; - int lineNum; - char * fileName; - bool closed; - - void pushValue(char * _value); - -public: - DOTCONFDocumentNode(); - ~DOTCONFDocumentNode(); - - const char * getConfigurationFileName() const { return fileName; } - int getConfigurationLineNumber() const { return lineNum; } - - const DOTCONFDocumentNode * getNextNode() const { return nextNode; } - const DOTCONFDocumentNode * getPreviuosNode() const { return previousNode; } - const DOTCONFDocumentNode * getParentNode() const { return parentNode; } - const DOTCONFDocumentNode * getChildNode() const { return childNode; } - const char * getValue(int index = 0) const; - const char * getName() const { return name; } - const DOTCONFDocument * getDocument() const { return document; } -}; - -class DOTCONFDocument -{ -public: - enum CaseSensitive { CASESENSITIVE, CASEINSENSITIVE }; -protected: - AsyncDNSMemPool * mempool; -private: - DOTCONFDocumentNode * curParent; - DOTCONFDocumentNode * curPrev; - DOTCONFCallback errorCallback; - void * errorCallbackData; - int curLine; - bool quoted; - std::list nodeTree; - std::list requiredOptions; - std::list processedFiles; - FILE * file; - char * fileName; - std::list words; - int (* cmp_func)(const char *, const char *); - - int checkRequiredOptions(); - int parseLine(); - int parseFile(DOTCONFDocumentNode * _parent = NULL); - int checkConfig(const std::list::iterator & from); - int cleanupLine(char * line); - char * getSubstitution(char * macro, int lineNum); - int macroSubstitute(DOTCONFDocumentNode * tagNode, int valueIndex); - -protected: - virtual void error(int lineNum, const char * fileName, const char * fmt, ...); - -public: - DOTCONFDocument(CaseSensitive caseSensitivity = CASESENSITIVE); - virtual ~DOTCONFDocument(); - - void setErrorCallback(DOTCONFCallback _callback, void * _data) { errorCallback = _callback; errorCallbackData = _data; }; - - int setContent(const char * _fileName); - - void setRequiredOptionNames(const char ** requiredOptionNames); // !TERMINATE ARRAY WITH NULL - const DOTCONFDocumentNode * getFirstNode() const; - const DOTCONFDocumentNode * findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode = NULL, const DOTCONFDocumentNode * startNode = NULL) const; -}; - -#endif diff --git a/stglibs/dotconfpp.lib/include/stg/dotconfpp.h b/stglibs/dotconfpp.lib/include/stg/dotconfpp.h new file mode 100644 index 00000000..8c2a82ad --- /dev/null +++ b/stglibs/dotconfpp.lib/include/stg/dotconfpp.h @@ -0,0 +1,122 @@ +/* Copyright (C) 2003 Aleksey Krivoshey +* +* 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 +*/ + + +#ifndef DOTCONFPP_H +#define DOTCONFPP_H + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "stg/os_int.h" + +typedef void (* DOTCONFCallback) (void * data, const char * buf); + +class DOTCONFDocument; +class AsyncDNSMemPool; + +class DOTCONFDocumentNode +{ +friend class DOTCONFDocument; +private: + DOTCONFDocumentNode * previousNode; + DOTCONFDocumentNode * nextNode; + DOTCONFDocumentNode * parentNode; + DOTCONFDocumentNode * childNode; + char ** values; + int valuesCount; + char * name; + const DOTCONFDocument * document; + int lineNum; + char * fileName; + bool closed; + + void pushValue(char * _value); + +public: + DOTCONFDocumentNode(); + ~DOTCONFDocumentNode(); + + const char * getConfigurationFileName() const { return fileName; } + int getConfigurationLineNumber() const { return lineNum; } + + const DOTCONFDocumentNode * getNextNode() const { return nextNode; } + const DOTCONFDocumentNode * getPreviuosNode() const { return previousNode; } + const DOTCONFDocumentNode * getParentNode() const { return parentNode; } + const DOTCONFDocumentNode * getChildNode() const { return childNode; } + const char * getValue(int index = 0) const; + const char * getName() const { return name; } + const DOTCONFDocument * getDocument() const { return document; } +}; + +class DOTCONFDocument +{ +public: + enum CaseSensitive { CASESENSITIVE, CASEINSENSITIVE }; +protected: + AsyncDNSMemPool * mempool; +private: + DOTCONFDocumentNode * curParent; + DOTCONFDocumentNode * curPrev; + DOTCONFCallback errorCallback; + void * errorCallbackData; + int curLine; + bool quoted; + std::list nodeTree; + std::list requiredOptions; + std::list processedFiles; + FILE * file; + char * fileName; + std::list words; + int (* cmp_func)(const char *, const char *); + + int checkRequiredOptions(); + int parseLine(); + int parseFile(DOTCONFDocumentNode * _parent = NULL); + int checkConfig(const std::list::iterator & from); + int cleanupLine(char * line); + char * getSubstitution(char * macro, int lineNum); + int macroSubstitute(DOTCONFDocumentNode * tagNode, int valueIndex); + +protected: + virtual void error(int lineNum, const char * fileName, const char * fmt, ...); + +public: + DOTCONFDocument(CaseSensitive caseSensitivity = CASESENSITIVE); + virtual ~DOTCONFDocument(); + + void setErrorCallback(DOTCONFCallback _callback, void * _data) { errorCallback = _callback; errorCallbackData = _data; }; + + int setContent(const char * _fileName); + + void setRequiredOptionNames(const char ** requiredOptionNames); // !TERMINATE ARRAY WITH NULL + const DOTCONFDocumentNode * getFirstNode() const; + const DOTCONFDocumentNode * findNode(const char * nodeName, const DOTCONFDocumentNode * parentNode = NULL, const DOTCONFDocumentNode * startNode = NULL) const; +}; + +#endif diff --git a/stglibs/ia.lib/ia.h b/stglibs/ia.lib/ia.h deleted file mode 100644 index 9c8ea37f..00000000 --- a/stglibs/ia.lib/ia.h +++ /dev/null @@ -1,206 +0,0 @@ -/* -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation; either version 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -/* - $Author: faust $ - $Revision: 1.10 $ - $Date: 2010/03/15 12:57:24 $ -*/ - -/* -* Author : Boris Mikhailenko -*/ -//--------------------------------------------------------------------------- -#ifndef IA_AUTH_C_H -#define IA_AUTH_C_H - -#ifndef WIN32 -#include -#include -#include -#include -#else -#include -#endif - -#include -#include -#include - -#include "stg/blowfish.h" -#include "stg/ia_packets.h" - -#define IA_BIND_ERROR (1) -#define IA_SERVER_ERROR (2) -#define IA_FCNTL_ERROR (3) -#define IA_GETHOSTBYNAME_ERROR (4) - -#define IA_PROTO_VER (8) -#define IA_PROTO_PROXY_VER (101) - -using namespace std; - -typedef void (*tpStatusChangedCb)(int status, void * data); -typedef void (*tpStatChangedCb)(const LOADSTAT & stat, void * data); -typedef void (*tpCallBackInfoFn)(const string & message, int infoType, int showTime, int sendTime, void * data); -typedef void (*tpCallBackErrorFn)(const string & message, int netError, void * data); -typedef void (*tpCallBackDirNameFn)(const vector & dirName, void * data); - -//--------------------------------------------------------------------------- -class IA_CLIENT_PROT -{ -#ifdef WIN32 -friend unsigned long WINAPI RunW(void * data); -#else -friend void * RunL(void * data); -#endif - -public: - IA_CLIENT_PROT(const string & sn, uint16_t p, uint16_t localPort = 0); - ~IA_CLIENT_PROT(); - - void Start(); - void Stop(); - void GetStat(LOADSTAT * ls); - - void SetServer(const string & sn, unsigned short port); - void SetLogin(const string & login); - void SetPassword(const string & password); - void SetEnabledDirs(const bool * selectedDirs); - - void SetStatusChangedCb(tpStatusChangedCb p, void * data); - void SetStatChangedCb(tpStatChangedCb p, void * data); - void SetInfoCb(tpCallBackInfoFn p, void * data); - void SetErrorCb(tpCallBackErrorFn p, void * data); - void SetDirNameCb(tpCallBackDirNameFn p, void * data); - - int Connect(); - int Disconnect(); - int GetAuthorized() const { return phase == 3 || phase == 4; }; - int GetPhase() const { return phase; }; - int GetStatus() const; - int GetReconnect() const { return reconnect; }; - void SetReconnect(int r) { reconnect = r; }; - char GetProtoVer() const { return proxyMode ? IA_PROTO_PROXY_VER : IA_PROTO_VER; }; - void GetMessageText(string * text) const { *text = messageText; }; - void GetInfoText(string * text) const { *text = infoText; }; - int GetStrError(string * error) const; - - void SetProxyMode(bool on) { proxyMode = on; }; - bool GetProxyMode() const { return proxyMode; }; - - void SetIP(uint32_t ip) { IA_CLIENT_PROT::ip = ip; }; - uint32_t GetIP() const { return ip; }; - -private: - void Run(); - int NetRecv(); - int NetSend(int n); - bool GetNonstop() const { return nonstop; }; - void PrepareNet(); - int DeterminatePacketType(const char * buffer); - - int Process_CONN_SYN_ACK_8(const char * buffer); - int Process_ALIVE_SYN_8(const char * buffer); - int Process_DISCONN_SYN_ACK_8(const char * buffer); - int Process_FIN_8(const char * buffer); - int Process_INFO_8(const char * buffer); - int Process_ERROR(const char * buffer); - - int Prepare_CONN_SYN_8(char * buffer); - int Prepare_CONN_ACK_8(char * buffer); - int Prepare_ALIVE_ACK_8(char * buffer); - int Prepare_DISCONN_SYN_8(char * buffer); - int Prepare_DISCONN_ACK_8(char * buffer); - - void FillHdr8(char * buffer, unsigned long ip); - int Send(char * buffer, int len); - int Recv(char * buffer, int len); - - LOADSTAT stat; - int action; - int phase; - int phaseTime; - string messageText; - string infoText; - mutable string strError; - mutable int codeError; - bool nonstop; - bool isNetPrepared; - bool proxyMode; - - BLOWFISH_CTX ctxPass; - BLOWFISH_CTX ctxHdr; - - bool selectedDirs[DIR_NUM]; - - string password; - string login; - - #ifdef WIN32 - WSADATA wsaData; - #else - pthread_t thread; - #endif - - string serverName; - uint16_t port; - uint32_t ip; - uint32_t localPort; - - struct sockaddr_in servAddr; - - bool firstConnect; - int reconnect; - int sockr; - int protNum; - int userTimeout; - int aliveTimeout; - unsigned int rnd; - - tpStatusChangedCb pStatusChangedCb; - tpStatChangedCb pStatChangedCb; - tpCallBackInfoFn pInfoCb; - tpCallBackErrorFn pErrorCb; - tpCallBackDirNameFn pDirNameCb; - - void * statusChangedCbData; - void * statChangedCbData; - void * infoCbData; - void * errorCbData; - void * dirNameCbData; - - map packetTypes; - - CONN_SYN_8 * connSyn8; - CONN_SYN_ACK_8 * connSynAck8; - CONN_ACK_8 * connAck8; - ALIVE_SYN_8 * aliveSyn8; - ALIVE_ACK_8 * aliveAck8; - DISCONN_SYN_8 * disconnSyn8; - DISCONN_SYN_ACK_8 * disconnSynAck8; - DISCONN_ACK_8 * disconnAck8; - INFO_8 * info; -}; -//--------------------------------------------------------------------------- -#ifdef WIN32 -unsigned long WINAPI RunW(void *); -#else -void * RunW(void *); -#endif - -//--------------------------------------------------------------------------- -#endif //IA_AUTH_C_H diff --git a/stglibs/ia.lib/include/stg/ia.h b/stglibs/ia.lib/include/stg/ia.h new file mode 100644 index 00000000..9c8ea37f --- /dev/null +++ b/stglibs/ia.lib/include/stg/ia.h @@ -0,0 +1,206 @@ +/* +** 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 1, 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., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + $Author: faust $ + $Revision: 1.10 $ + $Date: 2010/03/15 12:57:24 $ +*/ + +/* +* Author : Boris Mikhailenko +*/ +//--------------------------------------------------------------------------- +#ifndef IA_AUTH_C_H +#define IA_AUTH_C_H + +#ifndef WIN32 +#include +#include +#include +#include +#else +#include +#endif + +#include +#include +#include + +#include "stg/blowfish.h" +#include "stg/ia_packets.h" + +#define IA_BIND_ERROR (1) +#define IA_SERVER_ERROR (2) +#define IA_FCNTL_ERROR (3) +#define IA_GETHOSTBYNAME_ERROR (4) + +#define IA_PROTO_VER (8) +#define IA_PROTO_PROXY_VER (101) + +using namespace std; + +typedef void (*tpStatusChangedCb)(int status, void * data); +typedef void (*tpStatChangedCb)(const LOADSTAT & stat, void * data); +typedef void (*tpCallBackInfoFn)(const string & message, int infoType, int showTime, int sendTime, void * data); +typedef void (*tpCallBackErrorFn)(const string & message, int netError, void * data); +typedef void (*tpCallBackDirNameFn)(const vector & dirName, void * data); + +//--------------------------------------------------------------------------- +class IA_CLIENT_PROT +{ +#ifdef WIN32 +friend unsigned long WINAPI RunW(void * data); +#else +friend void * RunL(void * data); +#endif + +public: + IA_CLIENT_PROT(const string & sn, uint16_t p, uint16_t localPort = 0); + ~IA_CLIENT_PROT(); + + void Start(); + void Stop(); + void GetStat(LOADSTAT * ls); + + void SetServer(const string & sn, unsigned short port); + void SetLogin(const string & login); + void SetPassword(const string & password); + void SetEnabledDirs(const bool * selectedDirs); + + void SetStatusChangedCb(tpStatusChangedCb p, void * data); + void SetStatChangedCb(tpStatChangedCb p, void * data); + void SetInfoCb(tpCallBackInfoFn p, void * data); + void SetErrorCb(tpCallBackErrorFn p, void * data); + void SetDirNameCb(tpCallBackDirNameFn p, void * data); + + int Connect(); + int Disconnect(); + int GetAuthorized() const { return phase == 3 || phase == 4; }; + int GetPhase() const { return phase; }; + int GetStatus() const; + int GetReconnect() const { return reconnect; }; + void SetReconnect(int r) { reconnect = r; }; + char GetProtoVer() const { return proxyMode ? IA_PROTO_PROXY_VER : IA_PROTO_VER; }; + void GetMessageText(string * text) const { *text = messageText; }; + void GetInfoText(string * text) const { *text = infoText; }; + int GetStrError(string * error) const; + + void SetProxyMode(bool on) { proxyMode = on; }; + bool GetProxyMode() const { return proxyMode; }; + + void SetIP(uint32_t ip) { IA_CLIENT_PROT::ip = ip; }; + uint32_t GetIP() const { return ip; }; + +private: + void Run(); + int NetRecv(); + int NetSend(int n); + bool GetNonstop() const { return nonstop; }; + void PrepareNet(); + int DeterminatePacketType(const char * buffer); + + int Process_CONN_SYN_ACK_8(const char * buffer); + int Process_ALIVE_SYN_8(const char * buffer); + int Process_DISCONN_SYN_ACK_8(const char * buffer); + int Process_FIN_8(const char * buffer); + int Process_INFO_8(const char * buffer); + int Process_ERROR(const char * buffer); + + int Prepare_CONN_SYN_8(char * buffer); + int Prepare_CONN_ACK_8(char * buffer); + int Prepare_ALIVE_ACK_8(char * buffer); + int Prepare_DISCONN_SYN_8(char * buffer); + int Prepare_DISCONN_ACK_8(char * buffer); + + void FillHdr8(char * buffer, unsigned long ip); + int Send(char * buffer, int len); + int Recv(char * buffer, int len); + + LOADSTAT stat; + int action; + int phase; + int phaseTime; + string messageText; + string infoText; + mutable string strError; + mutable int codeError; + bool nonstop; + bool isNetPrepared; + bool proxyMode; + + BLOWFISH_CTX ctxPass; + BLOWFISH_CTX ctxHdr; + + bool selectedDirs[DIR_NUM]; + + string password; + string login; + + #ifdef WIN32 + WSADATA wsaData; + #else + pthread_t thread; + #endif + + string serverName; + uint16_t port; + uint32_t ip; + uint32_t localPort; + + struct sockaddr_in servAddr; + + bool firstConnect; + int reconnect; + int sockr; + int protNum; + int userTimeout; + int aliveTimeout; + unsigned int rnd; + + tpStatusChangedCb pStatusChangedCb; + tpStatChangedCb pStatChangedCb; + tpCallBackInfoFn pInfoCb; + tpCallBackErrorFn pErrorCb; + tpCallBackDirNameFn pDirNameCb; + + void * statusChangedCbData; + void * statChangedCbData; + void * infoCbData; + void * errorCbData; + void * dirNameCbData; + + map packetTypes; + + CONN_SYN_8 * connSyn8; + CONN_SYN_ACK_8 * connSynAck8; + CONN_ACK_8 * connAck8; + ALIVE_SYN_8 * aliveSyn8; + ALIVE_ACK_8 * aliveAck8; + DISCONN_SYN_8 * disconnSyn8; + DISCONN_SYN_ACK_8 * disconnSynAck8; + DISCONN_ACK_8 * disconnAck8; + INFO_8 * info; +}; +//--------------------------------------------------------------------------- +#ifdef WIN32 +unsigned long WINAPI RunW(void *); +#else +void * RunW(void *); +#endif + +//--------------------------------------------------------------------------- +#endif //IA_AUTH_C_H diff --git a/stglibs/ibpp.lib/ibpp.h b/stglibs/ibpp.lib/ibpp.h deleted file mode 100644 index 37a19add..00000000 --- a/stglibs/ibpp.lib/ibpp.h +++ /dev/null @@ -1,929 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// -// File : $Id: ibpp.h,v 1.3 2007/10/28 11:17:44 nobunaga Exp $ -// Subject : IBPP public header file. This is _the_ only file you include in -// your application files when developing with IBPP. -// -/////////////////////////////////////////////////////////////////////////////// -// -// (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org) -// -// The contents of this file are subject to the IBPP License (the "License"); -// you may not use this file except in compliance with the License. You may -// obtain a copy of the License at http://www.ibpp.org or in the 'license.txt' -// file which must have been distributed along with this file. -// -// This software, distributed under the License, is distributed on an "AS IS" -// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -// License for the specific language governing rights and limitations -// under the License. -// -// Contributor(s): -// -// Olivier Mascia, main coding -// Matt Hortman, initial linux port -// Mark Jordan, design contributions -// Maxim Abrashkin, enhancement patches -// Torsten Martinsen, enhancement patches -// Michael Hieke, darwin (OS X) port, enhancement patches -// Val Samko, enhancement patches and debugging -// Mike Nordell, invaluable C++ advices -// Claudio Valderrama, help with not-so-well documented IB/FB features -// Many others, excellent suggestions, bug finding, and support -// -/////////////////////////////////////////////////////////////////////////////// -// -// COMMENTS -// Tabulations should be set every four characters when editing this file. -// -// When compiling a project using IBPP, the following defines should be made -// on the command-line (or in makefiles) according to the OS platform and -// compiler used. -// -// Select the platform: IBPP_WINDOWS | IBPP_LINUX | IBPP_DARWIN -// -/////////////////////////////////////////////////////////////////////////////// - -#ifndef __IBPP_H__ -#define __IBPP_H__ - -#if !defined(IBPP_WINDOWS) && !defined(IBPP_LINUX) && !defined(IBPP_DARWIN) -#error Please define IBPP_WINDOWS/IBPP_LINUX/IBPP_DARWIN before compiling ! -#endif - -#if !defined(__BCPLUSPLUS__) && !defined(__GNUC__) && !defined(_MSC_VER) && !defined(__DMC__) -#error Your compiler is not recognized. -#endif - -#if defined(IBPP_LINUX) || defined(IBPP_DARWIN) -#define IBPP_UNIX // IBPP_UNIX stands as a common denominator to *NIX flavours -#endif - -// IBPP is written for 32 bits systems or higher. -// The standard type 'int' is assumed to be at least 32 bits. -// And the standard type 'short' is assumed to be exactly 16 bits. -// Everywhere possible, where the exact size of an integer does not matter, -// the standard type 'int' is used. And where an exact integer size is required -// the standard exact precision types definitions of C 99 standard are used. - -#if defined(_MSC_VER) || defined(__DMC__) || defined(__BCPLUSPLUS__) -// C99 §7.18.1.1 Exact-width integer types (only those used by IBPP) -#if defined(_MSC_VER) && (_MSC_VER < 1300) // MSVC 6 should be < 1300 - typedef short int16_t; - typedef int int32_t; - typedef unsigned int uint32_t; -#else - typedef __int16 int16_t; - typedef __int32 int32_t; - typedef unsigned __int32 uint32_t; -#endif - typedef __int64 int64_t; -#else - #include // C99 (§7.18) integer types definitions -#endif - -#if !defined(_) -#define _(s) s -#endif - -#include -#include -#include - -namespace IBPP -{ - // Typically you use this constant in a call IBPP::CheckVersion as in: - // if (! IBPP::CheckVersion(IBPP::Version)) { throw .... ; } - const uint32_t Version = (2<<24) + (5<<16) + (3<<8) + 0; // Version == 2.5.3.0 - - // Dates range checking - const int MinDate = -693594; // 1 JAN 0001 - const int MaxDate = 2958464; // 31 DEC 9999 - - // Transaction Access Modes - enum TAM {amWrite, amRead}; - - // Transaction Isolation Levels - enum TIL {ilConcurrency, ilReadDirty, ilReadCommitted, ilConsistency}; - - // Transaction Lock Resolution - enum TLR {lrWait, lrNoWait}; - - // Transaction Table Reservation - enum TTR {trSharedWrite, trSharedRead, trProtectedWrite, trProtectedRead}; - - // Prepared Statement Types - enum STT {stUnknown, stUnsupported, - stSelect, stInsert, stUpdate, stDelete, stDDL, stExecProcedure, - stSelectUpdate, stSetGenerator, stSavePoint}; - - // SQL Data Types - enum SDT {sdArray, sdBlob, sdDate, sdTime, sdTimestamp, sdString, - sdSmallint, sdInteger, sdLargeint, sdFloat, sdDouble}; - - // Array Data Types - enum ADT {adDate, adTime, adTimestamp, adString, - adBool, adInt16, adInt32, adInt64, adFloat, adDouble}; - - // Database::Shutdown Modes - enum DSM {dsForce, dsDenyTrans, dsDenyAttach}; - - // Service::StartBackup && Service::StartRestore Flags - enum BRF { - brVerbose = 0x1, - // Backup flags - brIgnoreChecksums = 0x100, brIgnoreLimbo = 0x200, - brMetadataOnly = 0x400, brNoGarbageCollect = 0x800, - brNonTransportable = 0x1000, brConvertExtTables = 0x2000, - // Restore flags - brReplace = 0x10000, brDeactivateIdx = 0x20000, - brNoShadow = 0x40000, brNoValidity = 0x80000, - brPerTableCommit = 0x100000, brUseAllSpace = 0x200000 - }; - - // Service::Repair Flags - enum RPF - { - // Mandatory and mutually exclusives - rpMendRecords = 0x1, rpValidatePages = 0x2, rpValidateFull = 0x4, - // Options - rpReadOnly = 0x100, rpIgnoreChecksums = 0x200, rpKillShadows = 0x400 - }; - - // TransactionFactory Flags - enum TFF {tfIgnoreLimbo = 0x1, tfAutoCommit = 0x2, tfNoAutoUndo = 0x4}; - - /* IBPP never return any error codes. It throws exceptions. - * On database engine reported errors, an IBPP::SQLException is thrown. - * In all other cases, IBPP throws IBPP::LogicException. - * Also note that the runtime and the language might also throw exceptions - * while executing some IBPP methods. A failing new operator will throw - * std::bad_alloc, IBPP does nothing to alter the standard behaviour. - * - * std::exception - * | - * IBPP::Exception - * / \ - * IBPP::LogicException IBPP::SQLException - * | - * IBPP::WrongType - */ - - class Exception : public std::exception - { - public: - virtual const char* Origin() const throw() = 0; - virtual const char* ErrorMessage() const throw() = 0; // Deprecated, use what() - virtual const char* what() const throw() = 0; - virtual ~Exception() throw(); - }; - - class LogicException : public Exception - { - public: - virtual ~LogicException() throw(); - }; - - class SQLException : public Exception - { - public: - virtual int SqlCode() const throw() = 0; - virtual int EngineCode() const throw() = 0; - - virtual ~SQLException() throw(); - }; - - class WrongType : public LogicException - { - public: - virtual ~WrongType() throw(); - }; - - /* Classes Date, Time, Timestamp and DBKey are 'helper' classes. They help - * in retrieving or setting some special SQL types. Dates, times and dbkeys - * are often read and written as strings in SQL scripts. When programming - * with IBPP, we handle those data with these specific classes, which - * enhance their usefullness and free us of format problems (M/D/Y, D/M/Y, - * Y-M-D ?, and so on...). */ - - /* Class Date represent purely a Date (no time part specified). It is - * usefull in interactions with the SQL DATE type of Interbase. You can add - * or substract a number from a Date, that will modify it to represent the - * correct date, X days later or sooner. All the Y2K details taken into - * account. - * The full range goes from integer values IBPP::MinDate to IBPP::MaxDate - * which means from 01 Jan 0001 to 31 Dec 9999. ( Which is inherently - * incorrect as this assumes Gregorian calendar. ) */ - - class Timestamp; // Cross-reference between Timestamp, Date and Time - - class Date - { - protected: - int mDate; // The date : 1 == 1 Jan 1900 - - public: - void Clear() { mDate = MinDate - 1; }; - void Today(); - void SetDate(int year, int month, int day); - void SetDate(int dt); - void GetDate(int& year, int& month, int& day) const; - int GetDate() const { return mDate; } - int Year() const; - int Month() const; - int Day() const; - void Add(int days); - void StartOfMonth(); - void EndOfMonth(); - - Date() { Clear(); }; - Date(int dt) { SetDate(dt); } - Date(int year, int month, int day); - Date(const Date&); // Copy Constructor - Date& operator=(const Timestamp&); // Timestamp Assignment operator - Date& operator=(const Date&); // Date Assignment operator - - bool operator==(const Date& rv) const { return mDate == rv.GetDate(); } - bool operator!=(const Date& rv) const { return mDate != rv.GetDate(); } - bool operator<(const Date& rv) const { return mDate < rv.GetDate(); } - bool operator>(const Date& rv) const { return mDate > rv.GetDate(); } - - virtual ~Date() { }; - }; - - /* Class Time represent purely a Time. It is usefull in interactions - * with the SQL TIME type of Interbase. */ - - class Time - { - protected: - int mTime; // The time, in ten-thousandths of seconds since midnight - - public: - void Clear() { mTime = 0; } - void Now(); - void SetTime(int hour, int minute, int second, int tenthousandths = 0); - void SetTime(int tm); - void GetTime(int& hour, int& minute, int& second) const; - void GetTime(int& hour, int& minute, int& second, int& tenthousandths) const; - int GetTime() const { return mTime; } - int Hours() const; - int Minutes() const; - int Seconds() const; - int SubSeconds() const; // Actually tenthousandths of seconds - Time() { Clear(); } - Time(int tm) { SetTime(tm); } - Time(int hour, int minute, int second, int tenthousandths = 0); - Time(const Time&); // Copy Constructor - Time& operator=(const Timestamp&); // Timestamp Assignment operator - Time& operator=(const Time&); // Time Assignment operator - - bool operator==(const Time& rv) const { return mTime == rv.GetTime(); } - bool operator!=(const Time& rv) const { return mTime != rv.GetTime(); } - bool operator<(const Time& rv) const { return mTime < rv.GetTime(); } - bool operator>(const Time& rv) const { return mTime > rv.GetTime(); } - - virtual ~Time() { }; - }; - - /* Class Timestamp represent a date AND a time. It is usefull in - * interactions with the SQL TIMESTAMP type of Interbase. This class - * inherits from Date and Time and completely inline implements its small - * specific details. */ - - class Timestamp : public Date, public Time - { - public: - void Clear() { Date::Clear(); Time::Clear(); } - void Today() { Date::Today(); Time::Clear(); } - void Now() { Date::Today(); Time::Now(); } - - Timestamp() { Clear(); } - - Timestamp(int y, int m, int d) - { Date::SetDate(y, m, d); Time::Clear(); } - - Timestamp(int y, int mo, int d, int h, int mi, int s, int t = 0) - { Date::SetDate(y, mo, d); Time::SetTime(h, mi, s, t); } - - Timestamp(const Timestamp& rv) - : Date(rv.mDate), Time(rv.mTime) {} // Copy Constructor - - Timestamp(const Date& rv) - { mDate = rv.GetDate(); mTime = 0; } - - Timestamp(const Time& rv) - { mDate = 0; mTime = rv.GetTime(); } - - Timestamp& operator=(const Timestamp& rv) // Timestamp Assignment operator - { mDate = rv.mDate; mTime = rv.mTime; return *this; } - - Timestamp& operator=(const Date& rv) // Date Assignment operator - { mDate = rv.GetDate(); return *this; } - - Timestamp& operator=(const Time& rv) // Time Assignment operator - { mTime = rv.GetTime(); return *this; } - - bool operator==(const Timestamp& rv) const - { return (mDate == rv.GetDate()) && (mTime == rv.GetTime()); } - - bool operator!=(const Timestamp& rv) const - { return (mDate != rv.GetDate()) || (mTime != rv.GetTime()); } - - bool operator<(const Timestamp& rv) const - { return (mDate < rv.GetDate()) || - (mDate == rv.GetDate() && mTime < rv.GetTime()); } - - bool operator>(const Timestamp& rv) const - { return (mDate > rv.GetDate()) || - (mDate == rv.GetDate() && mTime > rv.GetTime()); } - - ~Timestamp() { } - }; - - /* Class DBKey can store a DBKEY, that special value which the hidden - * RDB$DBKEY can give you from a select statement. A DBKey is nothing - * specific to IBPP. It's a feature of the Firebird database engine. See its - * documentation for more information. */ - - class DBKey - { - private: - std::string mDBKey; // Stores the binary DBKey - mutable std::string mString;// String (temporary) representation of it - - public: - void Clear(); - int Size() const { return (int)mDBKey.size(); } - void SetKey(const void*, int size); - void GetKey(void*, int size) const; - const char* AsString() const; - - DBKey& operator=(const DBKey&); // Assignment operator - DBKey(const DBKey&); // Copy Constructor - DBKey() { } - ~DBKey() { } - }; - - /* Class User wraps all the information about a user that the engine can manage. */ - - class User - { - public: - std::string username; - std::string password; - std::string firstname; - std::string middlename; - std::string lastname; - uint32_t userid; // Only relevant on unixes - uint32_t groupid; // Only relevant on unixes - - private: - void copyfrom(const User& r); - - public: - void clear(); - User& operator=(const User& r) { copyfrom(r); return *this; } - User(const User& r) { copyfrom(r); } - User() : userid(0), groupid(0) { } - ~User() { }; - }; - - // Interface Wrapper - template - class Ptr - { - private: - T* mObject; - - public: - void clear() - { - if (mObject != 0) { mObject->Release(); mObject = 0; } - } - - T* intf() const { return mObject; } - T* operator->() const { return mObject; } - - bool operator==(const T* p) const { return mObject == p; } - bool operator==(const Ptr& r) const { return mObject == r.mObject; } - bool operator!=(const T* p) const { return mObject != p; } - bool operator!=(const Ptr& r) const { return mObject != r.mObject; } - - Ptr& operator=(T* p) - { - // AddRef _before_ Release gives correct behaviour on self-assigns - T* tmp = (p == 0 ? 0 : p->AddRef()); // Take care of 0 - if (mObject != 0) mObject->Release(); - mObject = tmp; return *this; - } - - Ptr& operator=(const Ptr& r) - { - // AddRef _before_ Release gives correct behaviour on self-assigns - T* tmp = (r.intf() == 0 ? 0 : r->AddRef());// Take care of 0 - if (mObject != 0) mObject->Release(); - mObject = tmp; return *this; - } - - Ptr(T* p) : mObject(p == 0 ? 0 : p->AddRef()) { } - Ptr(const Ptr& r) : mObject(r.intf() == 0 ? 0 : r->AddRef()) { } - - Ptr() : mObject(0) { } - ~Ptr() { clear(); } - }; - - // --- Interface Classes --- // - - /* Interfaces IBlob, IArray, IService, IDatabase, ITransaction and - * IStatement are at the core of IBPP. Though it is possible to program your - * applications by using theses interfaces directly (as was the case with - * IBPP 1.x), you should refrain from using them and prefer the new IBPP - * Objects Blob, Array, ... (without the I in front). Those new objects are - * typedef'd right after each interface class definition as you can read - * below. If you program using the Blob (instead of the IBlob interface - * itself), you'll never have to care about AddRef/Release and you'll never - * have to care about deleting your objects. */ - - class IBlob; typedef Ptr Blob; - class IArray; typedef Ptr Array; - class IService; typedef Ptr Service; - class IDatabase; typedef Ptr Database; - class ITransaction; typedef Ptr Transaction; - class IStatement; typedef Ptr Statement; - class IEvents; typedef Ptr Events; - class IRow; typedef Ptr Row; - - /* IBlob is the interface to the blob capabilities of IBPP. Blob is the - * object class you actually use in your programming. In Firebird, at the - * row level, a blob is merely a handle to a blob, stored elsewhere in the - * database. Blob allows you to retrieve such a handle and then read from or - * write to the blob, much in the same manner than you would do with a file. */ - - class IBlob - { - public: - virtual void Create() = 0; - virtual void Open() = 0; - virtual void Close() = 0; - virtual void Cancel() = 0; - virtual int Read(void*, int size) = 0; - virtual void Write(const void*, int size) = 0; - virtual void Info(int* Size, int* Largest, int* Segments) = 0; - - virtual void Save(const std::string& data) = 0; - virtual void Load(std::string& data) = 0; - - virtual Database DatabasePtr() const = 0; - virtual Transaction TransactionPtr() const = 0; - - virtual IBlob* AddRef() = 0; - virtual void Release() = 0; - - virtual ~IBlob() { }; - }; - - /* IArray is the interface to the array capabilities of IBPP. Array is the - * object class you actually use in your programming. With an Array object, you - * can create, read and write Interbase Arrays, as a whole or in slices. */ - - class IArray - { - public: - virtual void Describe(const std::string& table, const std::string& column) = 0; - virtual void ReadTo(ADT, void* buffer, int elemcount) = 0; - virtual void WriteFrom(ADT, const void* buffer, int elemcount) = 0; - virtual SDT ElementType() = 0; - virtual int ElementSize() = 0; - virtual int ElementScale() = 0; - virtual int Dimensions() = 0; - virtual void Bounds(int dim, int* low, int* high) = 0; - virtual void SetBounds(int dim, int low, int high) = 0; - - virtual Database DatabasePtr() const = 0; - virtual Transaction TransactionPtr() const = 0; - - virtual IArray* AddRef() = 0; - virtual void Release() = 0; - - virtual ~IArray() { }; - }; - - /* IService is the interface to the service capabilities of IBPP. Service is - * the object class you actually use in your programming. With a Service - * object, you can do some maintenance work of databases and servers - * (backup, restore, create/update users, ...) */ - - class IService - { - public: - virtual void Connect() = 0; - virtual bool Connected() = 0; - virtual void Disconnect() = 0; - - virtual void GetVersion(std::string& version) = 0; - - virtual void AddUser(const User&) = 0; - virtual void GetUser(User&) = 0; - virtual void GetUsers(std::vector&) = 0; - virtual void ModifyUser(const User&) = 0; - virtual void RemoveUser(const std::string& username) = 0; - - virtual void SetPageBuffers(const std::string& dbfile, int buffers) = 0; - virtual void SetSweepInterval(const std::string& dbfile, int sweep) = 0; - virtual void SetSyncWrite(const std::string& dbfile, bool) = 0; - virtual void SetReadOnly(const std::string& dbfile, bool) = 0; - virtual void SetReserveSpace(const std::string& dbfile, bool) = 0; - - virtual void Shutdown(const std::string& dbfile, DSM mode, int sectimeout) = 0; - virtual void Restart(const std::string& dbfile) = 0; - virtual void Sweep(const std::string& dbfile) = 0; - virtual void Repair(const std::string& dbfile, RPF flags) = 0; - - virtual void StartBackup(const std::string& dbfile, - const std::string& bkfile, BRF flags = BRF(0)) = 0; - virtual void StartRestore(const std::string& bkfile, const std::string& dbfile, - int pagesize = 0, BRF flags = BRF(0)) = 0; - - virtual const char* WaitMsg() = 0; // With reporting (does not block) - virtual void Wait() = 0; // Without reporting (does block) - - virtual IService* AddRef() = 0; - virtual void Release() = 0; - - virtual ~IService() { }; - }; - - /* IDatabase is the interface to the database connections in IBPP. Database - * is the object class you actually use in your programming. With a Database - * object, you can create/drop/connect databases. */ - - class EventInterface; // Cross-reference between EventInterface and IDatabase - - class IDatabase - { - public: - virtual const char* ServerName() const = 0; - virtual const char* DatabaseName() const = 0; - virtual const char* Username() const = 0; - virtual const char* UserPassword() const = 0; - virtual const char* RoleName() const = 0; - virtual const char* CharSet() const = 0; - virtual const char* CreateParams() const = 0; - - virtual void Info(int* ODS, int* ODSMinor, int* PageSize, - int* Pages, int* Buffers, int* Sweep, bool* Sync, - bool* Reserve) = 0; - virtual void Statistics(int* Fetches, int* Marks, - int* Reads, int* Writes) = 0; - virtual void Counts(int* Insert, int* Update, int* Delete, - int* ReadIdx, int* ReadSeq) = 0; - virtual void Users(std::vector& users) = 0; - virtual int Dialect() = 0; - - virtual void Create(int dialect) = 0; - virtual void Connect() = 0; - virtual bool Connected() = 0; - virtual void Inactivate() = 0; - virtual void Disconnect() = 0; - virtual void Drop() = 0; - - virtual IDatabase* AddRef() = 0; - virtual void Release() = 0; - - virtual ~IDatabase() { }; - }; - - /* ITransaction is the interface to the transaction connections in IBPP. - * Transaction is the object class you actually use in your programming. A - * Transaction object can be associated with more than one Database, - * allowing for distributed transactions spanning multiple databases, - * possibly located on different servers. IBPP is one among the few - * programming interfaces to Firebird that allows you to support distributed - * transactions. */ - - class ITransaction - { - public: - virtual void AttachDatabase(Database db, TAM am = amWrite, - TIL il = ilConcurrency, TLR lr = lrWait, TFF flags = TFF(0)) = 0; - virtual void DetachDatabase(Database db) = 0; - virtual void AddReservation(Database db, - const std::string& table, TTR tr) = 0; - - virtual void Start() = 0; - virtual bool Started() = 0; - virtual void Commit() = 0; - virtual void Rollback() = 0; - virtual void CommitRetain() = 0; - virtual void RollbackRetain() = 0; - - virtual ITransaction* AddRef() = 0; - virtual void Release() = 0; - - virtual ~ITransaction() { }; - }; - - /* - * Class Row can hold all the values of a row (from a SELECT for instance). - */ - - class IRow - { - public: - virtual void SetNull(int) = 0; - virtual void Set(int, bool) = 0; - virtual void Set(int, const void*, int) = 0; // byte buffers - virtual void Set(int, const char*) = 0; // c-string - virtual void Set(int, const std::string&) = 0; - virtual void Set(int, int16_t) = 0; - virtual void Set(int, int32_t) = 0; - virtual void Set(int, int64_t) = 0; - virtual void Set(int, float) = 0; - virtual void Set(int, double) = 0; - virtual void Set(int, const Timestamp&) = 0; - virtual void Set(int, const Date&) = 0; - virtual void Set(int, const Time&) = 0; - virtual void Set(int, const DBKey&) = 0; - virtual void Set(int, const Blob&) = 0; - virtual void Set(int, const Array&) = 0; - - virtual bool IsNull(int) = 0; - virtual bool Get(int, bool&) = 0; - virtual bool Get(int, void*, int&) = 0; // byte buffers - virtual bool Get(int, std::string&) = 0; - virtual bool Get(int, int16_t&) = 0; - virtual bool Get(int, int32_t&) = 0; - virtual bool Get(int, int64_t&) = 0; - virtual bool Get(int, float&) = 0; - virtual bool Get(int, double&) = 0; - virtual bool Get(int, Timestamp&) = 0; - virtual bool Get(int, Date&) = 0; - virtual bool Get(int, Time&) = 0; - virtual bool Get(int, DBKey&) = 0; - virtual bool Get(int, Blob&) = 0; - virtual bool Get(int, Array&) = 0; - - virtual bool IsNull(const std::string&) = 0; - virtual bool Get(const std::string&, bool&) = 0; - virtual bool Get(const std::string&, void*, int&) = 0; // byte buffers - virtual bool Get(const std::string&, std::string&) = 0; - virtual bool Get(const std::string&, int16_t&) = 0; - virtual bool Get(const std::string&, int32_t&) = 0; - virtual bool Get(const std::string&, int64_t&) = 0; - virtual bool Get(const std::string&, float&) = 0; - virtual bool Get(const std::string&, double&) = 0; - virtual bool Get(const std::string&, Timestamp&) = 0; - virtual bool Get(const std::string&, Date&) = 0; - virtual bool Get(const std::string&, Time&) = 0; - virtual bool Get(const std::string&, DBKey&) = 0; - virtual bool Get(const std::string&, Blob&) = 0; - virtual bool Get(const std::string&, Array&) = 0; - - virtual int ColumnNum(const std::string&) = 0; - virtual const char* ColumnName(int) = 0; - virtual const char* ColumnAlias(int) = 0; - virtual const char* ColumnTable(int) = 0; - virtual SDT ColumnType(int) = 0; - virtual int ColumnSubtype(int) = 0; - virtual int ColumnSize(int) = 0; - virtual int ColumnScale(int) = 0; - virtual int Columns() = 0; - - virtual bool ColumnUpdated(int) = 0; - virtual bool Updated() = 0; - - virtual Database DatabasePtr() const = 0; - virtual Transaction TransactionPtr() const = 0; - - virtual IRow* Clone() = 0; - virtual IRow* AddRef() = 0; - virtual void Release() = 0; - - virtual ~IRow() {}; - }; - - /* IStatement is the interface to the statements execution in IBPP. - * Statement is the object class you actually use in your programming. A - * Statement object is the work horse of IBPP. All your data manipulation - * statements will be done through it. It is also used to access the result - * set of a query (when the statement is such), one row at a time and in - * strict forward direction. */ - - class IStatement - { - public: - virtual void Prepare(const std::string&) = 0; - virtual void Execute() = 0; - virtual void Execute(const std::string&) = 0; - virtual void ExecuteImmediate(const std::string&) = 0; - virtual void CursorExecute(const std::string& cursor) = 0; - virtual void CursorExecute(const std::string& cursor, const std::string&) = 0; - virtual bool Fetch() = 0; - virtual bool Fetch(Row&) = 0; - virtual int AffectedRows() = 0; - virtual void Close() = 0; - virtual std::string& Sql() = 0; - virtual STT Type() = 0; - - virtual void SetNull(int) = 0; - virtual void Set(int, bool) = 0; - virtual void Set(int, const void*, int) = 0; // byte buffers - virtual void Set(int, const char*) = 0; // c-string - virtual void Set(int, const std::string&) = 0; - virtual void Set(int, int16_t value) = 0; - virtual void Set(int, int32_t value) = 0; - virtual void Set(int, int64_t value) = 0; - virtual void Set(int, float value) = 0; - virtual void Set(int, double value) = 0; - virtual void Set(int, const Timestamp& value) = 0; - virtual void Set(int, const Date& value) = 0; - virtual void Set(int, const Time& value) = 0; - virtual void Set(int, const DBKey& value) = 0; - virtual void Set(int, const Blob& value) = 0; - virtual void Set(int, const Array& value) = 0; - - virtual bool IsNull(int) = 0; - virtual bool Get(int, bool&) = 0; - virtual bool Get(int, void*, int&) = 0; // byte buffers - virtual bool Get(int, std::string&) = 0; - virtual bool Get(int, int16_t&) = 0; - virtual bool Get(int, int32_t&) = 0; - virtual bool Get(int, int64_t&) = 0; - virtual bool Get(int, float&) = 0; - virtual bool Get(int, double&) = 0; - virtual bool Get(int, Timestamp& value) = 0; - virtual bool Get(int, Date& value) = 0; - virtual bool Get(int, Time& value) = 0; - virtual bool Get(int, DBKey& value) = 0; - virtual bool Get(int, Blob& value) = 0; - virtual bool Get(int, Array& value) = 0; - - virtual bool IsNull(const std::string&) = 0; - virtual bool Get(const std::string&, bool&) = 0; - virtual bool Get(const std::string&, void*, int&) = 0; // byte buffers - virtual bool Get(const std::string&, std::string&) = 0; - virtual bool Get(const std::string&, int16_t&) = 0; - virtual bool Get(const std::string&, int32_t&) = 0; - virtual bool Get(const std::string&, int64_t&) = 0; - virtual bool Get(const std::string&, float&) = 0; - virtual bool Get(const std::string&, double&) = 0; - virtual bool Get(const std::string&, Timestamp& value) = 0; - virtual bool Get(const std::string&, Date& value) = 0; - virtual bool Get(const std::string&, Time& value) = 0; - virtual bool Get(const std::string&, DBKey& value) = 0; - virtual bool Get(const std::string&, Blob& value) = 0; - virtual bool Get(const std::string&, Array& value) = 0; - - virtual int ColumnNum(const std::string&) = 0; - virtual const char* ColumnName(int) = 0; - virtual const char* ColumnAlias(int) = 0; - virtual const char* ColumnTable(int) = 0; - virtual SDT ColumnType(int) = 0; - virtual int ColumnSubtype(int) = 0; - virtual int ColumnSize(int) = 0; - virtual int ColumnScale(int) = 0; - virtual int Columns() = 0; - - virtual SDT ParameterType(int) = 0; - virtual int ParameterSubtype(int) = 0; - virtual int ParameterSize(int) = 0; - virtual int ParameterScale(int) = 0; - virtual int Parameters() = 0; - - virtual void Plan(std::string&) = 0; - - virtual Database DatabasePtr() const = 0; - virtual Transaction TransactionPtr() const = 0; - - virtual IStatement* AddRef() = 0; - virtual void Release() = 0; - - virtual ~IStatement() { }; - - // DEPRECATED METHODS (WON'T BE AVAILABLE IN VERSIONS 3.x) - virtual bool Get(int, char*) = 0; // DEPRECATED - virtual bool Get(const std::string&, char*) = 0; // DEPRECATED - virtual bool Get(int, bool*) = 0; // DEPRECATED - virtual bool Get(const std::string&, bool*) = 0; // DEPRECATED - virtual bool Get(int, int16_t*) = 0; // DEPRECATED - virtual bool Get(const std::string&, int16_t*) = 0; // DEPRECATED - virtual bool Get(int, int32_t*) = 0; // DEPRECATED - virtual bool Get(const std::string&, int32_t*) = 0; // DEPRECATED - virtual bool Get(int, int64_t*) = 0; // DEPRECATED - virtual bool Get(const std::string&, int64_t*) = 0; // DEPRECATED - virtual bool Get(int, float*) = 0; // DEPRECATED - virtual bool Get(const std::string&, float*) = 0; // DEPRECATED - virtual bool Get(int, double*) = 0; // DEPRECATED - virtual bool Get(const std::string&, double*) = 0; // DEPRECATED - }; - - class IEvents - { - public: - virtual void Add(const std::string&, EventInterface*) = 0; - virtual void Drop(const std::string&) = 0; - virtual void List(std::vector&) = 0; - virtual void Clear() = 0; // Drop all events - virtual void Dispatch() = 0; // Dispatch events (calls handlers) - - virtual Database DatabasePtr() const = 0; - - virtual IEvents* AddRef() = 0; - virtual void Release() = 0; - - virtual ~IEvents() { }; - }; - - /* Class EventInterface is merely a pure interface. - * It is _not_ implemented by IBPP. It is only a base class definition from - * which your own event interface classes have to derive from. - * Please read the reference guide at http://www.ibpp.org for more info. */ - - class EventInterface - { - public: - virtual void ibppEventHandler(Events, const std::string&, int) = 0; - virtual ~EventInterface() { }; - }; - - // --- Factories --- - // These methods are the only way to get one of the above - // Interfaces. They are at the heart of how you program using IBPP. For - // instance, to get access to a database, you'll write code similar to this: - // { - // Database db = DatabaseFactory("server", "databasename", - // "user", "password"); - // db->Connect(); - // ... - // db->Disconnect(); - // } - - Service ServiceFactory(const std::string& ServerName, - const std::string& UserName, const std::string& UserPassword); - - Database DatabaseFactory(const std::string& ServerName, - const std::string& DatabaseName, const std::string& UserName, - const std::string& UserPassword, const std::string& RoleName, - const std::string& CharSet, const std::string& CreateParams); - - inline Database DatabaseFactory(const std::string& ServerName, - const std::string& DatabaseName, const std::string& UserName, - const std::string& UserPassword) - { return DatabaseFactory(ServerName, DatabaseName, UserName, UserPassword, "", "", ""); } - - Transaction TransactionFactory(Database db, TAM am = amWrite, - TIL il = ilConcurrency, TLR lr = lrWait, TFF flags = TFF(0)); - - Statement StatementFactory(Database db, Transaction tr, - const std::string& sql); - - inline Statement StatementFactory(Database db, Transaction tr) - { return StatementFactory(db, tr, ""); } - - Blob BlobFactory(Database db, Transaction tr); - - Array ArrayFactory(Database db, Transaction tr); - - Events EventsFactory(Database db); - - /* IBPP uses a self initialization system. Each time an object that may - * require the usage of the Interbase client C-API library is used, the - * library internal handling details are automatically initialized, if not - * already done. You can kick this initialization at the start of an - * application by calling IBPP::CheckVersion(). This is recommended, because - * IBPP::CheckVersion will assure you that YOUR code has been compiled - * against a compatible version of the library. */ - - bool CheckVersion(uint32_t); - int GDSVersion(); - - /* On Win32 platform, ClientLibSearchPaths() allows to setup - * one or multiple additional paths (separated with a ';') where IBPP - * will look for the client library (before the default implicit search - * locations). This is usefull for applications distributed with a 'private' - * copy of Firebird, when the registry is useless to identify the location - * from where to attempt loading the fbclient.dll / gds32.dll. - * If called, this function must be called *early* by the application, - * before *any* other function or object methods of IBPP. - * Currently, this is a NO-OP on platforms other than Win32. */ - - void ClientLibSearchPaths(const std::string&); - - /* Finally, here are some date and time conversion routines used by IBPP and - * that may be helpful at the application level. They do not depend on - * anything related to Firebird/Interbase. Just a bonus. dtoi and itod - * return false on invalid parameters or out of range conversions. */ - - bool dtoi(int date, int* py, int* pm, int* pd); - bool itod(int* pdate, int year, int month, int day); - void ttoi(int itime, int* phour, int* pminute, int* psecond, int* ptt); - void itot(int* ptime, int hour, int minute, int second = 0, int tenthousandths = 0); - -} - -#endif - -// -// EOF -// diff --git a/stglibs/ibpp.lib/include/stg/ibpp.h b/stglibs/ibpp.lib/include/stg/ibpp.h new file mode 100644 index 00000000..37a19add --- /dev/null +++ b/stglibs/ibpp.lib/include/stg/ibpp.h @@ -0,0 +1,929 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// File : $Id: ibpp.h,v 1.3 2007/10/28 11:17:44 nobunaga Exp $ +// Subject : IBPP public header file. This is _the_ only file you include in +// your application files when developing with IBPP. +// +/////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org) +// +// The contents of this file are subject to the IBPP License (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at http://www.ibpp.org or in the 'license.txt' +// file which must have been distributed along with this file. +// +// This software, distributed under the License, is distributed on an "AS IS" +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +// License for the specific language governing rights and limitations +// under the License. +// +// Contributor(s): +// +// Olivier Mascia, main coding +// Matt Hortman, initial linux port +// Mark Jordan, design contributions +// Maxim Abrashkin, enhancement patches +// Torsten Martinsen, enhancement patches +// Michael Hieke, darwin (OS X) port, enhancement patches +// Val Samko, enhancement patches and debugging +// Mike Nordell, invaluable C++ advices +// Claudio Valderrama, help with not-so-well documented IB/FB features +// Many others, excellent suggestions, bug finding, and support +// +/////////////////////////////////////////////////////////////////////////////// +// +// COMMENTS +// Tabulations should be set every four characters when editing this file. +// +// When compiling a project using IBPP, the following defines should be made +// on the command-line (or in makefiles) according to the OS platform and +// compiler used. +// +// Select the platform: IBPP_WINDOWS | IBPP_LINUX | IBPP_DARWIN +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef __IBPP_H__ +#define __IBPP_H__ + +#if !defined(IBPP_WINDOWS) && !defined(IBPP_LINUX) && !defined(IBPP_DARWIN) +#error Please define IBPP_WINDOWS/IBPP_LINUX/IBPP_DARWIN before compiling ! +#endif + +#if !defined(__BCPLUSPLUS__) && !defined(__GNUC__) && !defined(_MSC_VER) && !defined(__DMC__) +#error Your compiler is not recognized. +#endif + +#if defined(IBPP_LINUX) || defined(IBPP_DARWIN) +#define IBPP_UNIX // IBPP_UNIX stands as a common denominator to *NIX flavours +#endif + +// IBPP is written for 32 bits systems or higher. +// The standard type 'int' is assumed to be at least 32 bits. +// And the standard type 'short' is assumed to be exactly 16 bits. +// Everywhere possible, where the exact size of an integer does not matter, +// the standard type 'int' is used. And where an exact integer size is required +// the standard exact precision types definitions of C 99 standard are used. + +#if defined(_MSC_VER) || defined(__DMC__) || defined(__BCPLUSPLUS__) +// C99 §7.18.1.1 Exact-width integer types (only those used by IBPP) +#if defined(_MSC_VER) && (_MSC_VER < 1300) // MSVC 6 should be < 1300 + typedef short int16_t; + typedef int int32_t; + typedef unsigned int uint32_t; +#else + typedef __int16 int16_t; + typedef __int32 int32_t; + typedef unsigned __int32 uint32_t; +#endif + typedef __int64 int64_t; +#else + #include // C99 (§7.18) integer types definitions +#endif + +#if !defined(_) +#define _(s) s +#endif + +#include +#include +#include + +namespace IBPP +{ + // Typically you use this constant in a call IBPP::CheckVersion as in: + // if (! IBPP::CheckVersion(IBPP::Version)) { throw .... ; } + const uint32_t Version = (2<<24) + (5<<16) + (3<<8) + 0; // Version == 2.5.3.0 + + // Dates range checking + const int MinDate = -693594; // 1 JAN 0001 + const int MaxDate = 2958464; // 31 DEC 9999 + + // Transaction Access Modes + enum TAM {amWrite, amRead}; + + // Transaction Isolation Levels + enum TIL {ilConcurrency, ilReadDirty, ilReadCommitted, ilConsistency}; + + // Transaction Lock Resolution + enum TLR {lrWait, lrNoWait}; + + // Transaction Table Reservation + enum TTR {trSharedWrite, trSharedRead, trProtectedWrite, trProtectedRead}; + + // Prepared Statement Types + enum STT {stUnknown, stUnsupported, + stSelect, stInsert, stUpdate, stDelete, stDDL, stExecProcedure, + stSelectUpdate, stSetGenerator, stSavePoint}; + + // SQL Data Types + enum SDT {sdArray, sdBlob, sdDate, sdTime, sdTimestamp, sdString, + sdSmallint, sdInteger, sdLargeint, sdFloat, sdDouble}; + + // Array Data Types + enum ADT {adDate, adTime, adTimestamp, adString, + adBool, adInt16, adInt32, adInt64, adFloat, adDouble}; + + // Database::Shutdown Modes + enum DSM {dsForce, dsDenyTrans, dsDenyAttach}; + + // Service::StartBackup && Service::StartRestore Flags + enum BRF { + brVerbose = 0x1, + // Backup flags + brIgnoreChecksums = 0x100, brIgnoreLimbo = 0x200, + brMetadataOnly = 0x400, brNoGarbageCollect = 0x800, + brNonTransportable = 0x1000, brConvertExtTables = 0x2000, + // Restore flags + brReplace = 0x10000, brDeactivateIdx = 0x20000, + brNoShadow = 0x40000, brNoValidity = 0x80000, + brPerTableCommit = 0x100000, brUseAllSpace = 0x200000 + }; + + // Service::Repair Flags + enum RPF + { + // Mandatory and mutually exclusives + rpMendRecords = 0x1, rpValidatePages = 0x2, rpValidateFull = 0x4, + // Options + rpReadOnly = 0x100, rpIgnoreChecksums = 0x200, rpKillShadows = 0x400 + }; + + // TransactionFactory Flags + enum TFF {tfIgnoreLimbo = 0x1, tfAutoCommit = 0x2, tfNoAutoUndo = 0x4}; + + /* IBPP never return any error codes. It throws exceptions. + * On database engine reported errors, an IBPP::SQLException is thrown. + * In all other cases, IBPP throws IBPP::LogicException. + * Also note that the runtime and the language might also throw exceptions + * while executing some IBPP methods. A failing new operator will throw + * std::bad_alloc, IBPP does nothing to alter the standard behaviour. + * + * std::exception + * | + * IBPP::Exception + * / \ + * IBPP::LogicException IBPP::SQLException + * | + * IBPP::WrongType + */ + + class Exception : public std::exception + { + public: + virtual const char* Origin() const throw() = 0; + virtual const char* ErrorMessage() const throw() = 0; // Deprecated, use what() + virtual const char* what() const throw() = 0; + virtual ~Exception() throw(); + }; + + class LogicException : public Exception + { + public: + virtual ~LogicException() throw(); + }; + + class SQLException : public Exception + { + public: + virtual int SqlCode() const throw() = 0; + virtual int EngineCode() const throw() = 0; + + virtual ~SQLException() throw(); + }; + + class WrongType : public LogicException + { + public: + virtual ~WrongType() throw(); + }; + + /* Classes Date, Time, Timestamp and DBKey are 'helper' classes. They help + * in retrieving or setting some special SQL types. Dates, times and dbkeys + * are often read and written as strings in SQL scripts. When programming + * with IBPP, we handle those data with these specific classes, which + * enhance their usefullness and free us of format problems (M/D/Y, D/M/Y, + * Y-M-D ?, and so on...). */ + + /* Class Date represent purely a Date (no time part specified). It is + * usefull in interactions with the SQL DATE type of Interbase. You can add + * or substract a number from a Date, that will modify it to represent the + * correct date, X days later or sooner. All the Y2K details taken into + * account. + * The full range goes from integer values IBPP::MinDate to IBPP::MaxDate + * which means from 01 Jan 0001 to 31 Dec 9999. ( Which is inherently + * incorrect as this assumes Gregorian calendar. ) */ + + class Timestamp; // Cross-reference between Timestamp, Date and Time + + class Date + { + protected: + int mDate; // The date : 1 == 1 Jan 1900 + + public: + void Clear() { mDate = MinDate - 1; }; + void Today(); + void SetDate(int year, int month, int day); + void SetDate(int dt); + void GetDate(int& year, int& month, int& day) const; + int GetDate() const { return mDate; } + int Year() const; + int Month() const; + int Day() const; + void Add(int days); + void StartOfMonth(); + void EndOfMonth(); + + Date() { Clear(); }; + Date(int dt) { SetDate(dt); } + Date(int year, int month, int day); + Date(const Date&); // Copy Constructor + Date& operator=(const Timestamp&); // Timestamp Assignment operator + Date& operator=(const Date&); // Date Assignment operator + + bool operator==(const Date& rv) const { return mDate == rv.GetDate(); } + bool operator!=(const Date& rv) const { return mDate != rv.GetDate(); } + bool operator<(const Date& rv) const { return mDate < rv.GetDate(); } + bool operator>(const Date& rv) const { return mDate > rv.GetDate(); } + + virtual ~Date() { }; + }; + + /* Class Time represent purely a Time. It is usefull in interactions + * with the SQL TIME type of Interbase. */ + + class Time + { + protected: + int mTime; // The time, in ten-thousandths of seconds since midnight + + public: + void Clear() { mTime = 0; } + void Now(); + void SetTime(int hour, int minute, int second, int tenthousandths = 0); + void SetTime(int tm); + void GetTime(int& hour, int& minute, int& second) const; + void GetTime(int& hour, int& minute, int& second, int& tenthousandths) const; + int GetTime() const { return mTime; } + int Hours() const; + int Minutes() const; + int Seconds() const; + int SubSeconds() const; // Actually tenthousandths of seconds + Time() { Clear(); } + Time(int tm) { SetTime(tm); } + Time(int hour, int minute, int second, int tenthousandths = 0); + Time(const Time&); // Copy Constructor + Time& operator=(const Timestamp&); // Timestamp Assignment operator + Time& operator=(const Time&); // Time Assignment operator + + bool operator==(const Time& rv) const { return mTime == rv.GetTime(); } + bool operator!=(const Time& rv) const { return mTime != rv.GetTime(); } + bool operator<(const Time& rv) const { return mTime < rv.GetTime(); } + bool operator>(const Time& rv) const { return mTime > rv.GetTime(); } + + virtual ~Time() { }; + }; + + /* Class Timestamp represent a date AND a time. It is usefull in + * interactions with the SQL TIMESTAMP type of Interbase. This class + * inherits from Date and Time and completely inline implements its small + * specific details. */ + + class Timestamp : public Date, public Time + { + public: + void Clear() { Date::Clear(); Time::Clear(); } + void Today() { Date::Today(); Time::Clear(); } + void Now() { Date::Today(); Time::Now(); } + + Timestamp() { Clear(); } + + Timestamp(int y, int m, int d) + { Date::SetDate(y, m, d); Time::Clear(); } + + Timestamp(int y, int mo, int d, int h, int mi, int s, int t = 0) + { Date::SetDate(y, mo, d); Time::SetTime(h, mi, s, t); } + + Timestamp(const Timestamp& rv) + : Date(rv.mDate), Time(rv.mTime) {} // Copy Constructor + + Timestamp(const Date& rv) + { mDate = rv.GetDate(); mTime = 0; } + + Timestamp(const Time& rv) + { mDate = 0; mTime = rv.GetTime(); } + + Timestamp& operator=(const Timestamp& rv) // Timestamp Assignment operator + { mDate = rv.mDate; mTime = rv.mTime; return *this; } + + Timestamp& operator=(const Date& rv) // Date Assignment operator + { mDate = rv.GetDate(); return *this; } + + Timestamp& operator=(const Time& rv) // Time Assignment operator + { mTime = rv.GetTime(); return *this; } + + bool operator==(const Timestamp& rv) const + { return (mDate == rv.GetDate()) && (mTime == rv.GetTime()); } + + bool operator!=(const Timestamp& rv) const + { return (mDate != rv.GetDate()) || (mTime != rv.GetTime()); } + + bool operator<(const Timestamp& rv) const + { return (mDate < rv.GetDate()) || + (mDate == rv.GetDate() && mTime < rv.GetTime()); } + + bool operator>(const Timestamp& rv) const + { return (mDate > rv.GetDate()) || + (mDate == rv.GetDate() && mTime > rv.GetTime()); } + + ~Timestamp() { } + }; + + /* Class DBKey can store a DBKEY, that special value which the hidden + * RDB$DBKEY can give you from a select statement. A DBKey is nothing + * specific to IBPP. It's a feature of the Firebird database engine. See its + * documentation for more information. */ + + class DBKey + { + private: + std::string mDBKey; // Stores the binary DBKey + mutable std::string mString;// String (temporary) representation of it + + public: + void Clear(); + int Size() const { return (int)mDBKey.size(); } + void SetKey(const void*, int size); + void GetKey(void*, int size) const; + const char* AsString() const; + + DBKey& operator=(const DBKey&); // Assignment operator + DBKey(const DBKey&); // Copy Constructor + DBKey() { } + ~DBKey() { } + }; + + /* Class User wraps all the information about a user that the engine can manage. */ + + class User + { + public: + std::string username; + std::string password; + std::string firstname; + std::string middlename; + std::string lastname; + uint32_t userid; // Only relevant on unixes + uint32_t groupid; // Only relevant on unixes + + private: + void copyfrom(const User& r); + + public: + void clear(); + User& operator=(const User& r) { copyfrom(r); return *this; } + User(const User& r) { copyfrom(r); } + User() : userid(0), groupid(0) { } + ~User() { }; + }; + + // Interface Wrapper + template + class Ptr + { + private: + T* mObject; + + public: + void clear() + { + if (mObject != 0) { mObject->Release(); mObject = 0; } + } + + T* intf() const { return mObject; } + T* operator->() const { return mObject; } + + bool operator==(const T* p) const { return mObject == p; } + bool operator==(const Ptr& r) const { return mObject == r.mObject; } + bool operator!=(const T* p) const { return mObject != p; } + bool operator!=(const Ptr& r) const { return mObject != r.mObject; } + + Ptr& operator=(T* p) + { + // AddRef _before_ Release gives correct behaviour on self-assigns + T* tmp = (p == 0 ? 0 : p->AddRef()); // Take care of 0 + if (mObject != 0) mObject->Release(); + mObject = tmp; return *this; + } + + Ptr& operator=(const Ptr& r) + { + // AddRef _before_ Release gives correct behaviour on self-assigns + T* tmp = (r.intf() == 0 ? 0 : r->AddRef());// Take care of 0 + if (mObject != 0) mObject->Release(); + mObject = tmp; return *this; + } + + Ptr(T* p) : mObject(p == 0 ? 0 : p->AddRef()) { } + Ptr(const Ptr& r) : mObject(r.intf() == 0 ? 0 : r->AddRef()) { } + + Ptr() : mObject(0) { } + ~Ptr() { clear(); } + }; + + // --- Interface Classes --- // + + /* Interfaces IBlob, IArray, IService, IDatabase, ITransaction and + * IStatement are at the core of IBPP. Though it is possible to program your + * applications by using theses interfaces directly (as was the case with + * IBPP 1.x), you should refrain from using them and prefer the new IBPP + * Objects Blob, Array, ... (without the I in front). Those new objects are + * typedef'd right after each interface class definition as you can read + * below. If you program using the Blob (instead of the IBlob interface + * itself), you'll never have to care about AddRef/Release and you'll never + * have to care about deleting your objects. */ + + class IBlob; typedef Ptr Blob; + class IArray; typedef Ptr Array; + class IService; typedef Ptr Service; + class IDatabase; typedef Ptr Database; + class ITransaction; typedef Ptr Transaction; + class IStatement; typedef Ptr Statement; + class IEvents; typedef Ptr Events; + class IRow; typedef Ptr Row; + + /* IBlob is the interface to the blob capabilities of IBPP. Blob is the + * object class you actually use in your programming. In Firebird, at the + * row level, a blob is merely a handle to a blob, stored elsewhere in the + * database. Blob allows you to retrieve such a handle and then read from or + * write to the blob, much in the same manner than you would do with a file. */ + + class IBlob + { + public: + virtual void Create() = 0; + virtual void Open() = 0; + virtual void Close() = 0; + virtual void Cancel() = 0; + virtual int Read(void*, int size) = 0; + virtual void Write(const void*, int size) = 0; + virtual void Info(int* Size, int* Largest, int* Segments) = 0; + + virtual void Save(const std::string& data) = 0; + virtual void Load(std::string& data) = 0; + + virtual Database DatabasePtr() const = 0; + virtual Transaction TransactionPtr() const = 0; + + virtual IBlob* AddRef() = 0; + virtual void Release() = 0; + + virtual ~IBlob() { }; + }; + + /* IArray is the interface to the array capabilities of IBPP. Array is the + * object class you actually use in your programming. With an Array object, you + * can create, read and write Interbase Arrays, as a whole or in slices. */ + + class IArray + { + public: + virtual void Describe(const std::string& table, const std::string& column) = 0; + virtual void ReadTo(ADT, void* buffer, int elemcount) = 0; + virtual void WriteFrom(ADT, const void* buffer, int elemcount) = 0; + virtual SDT ElementType() = 0; + virtual int ElementSize() = 0; + virtual int ElementScale() = 0; + virtual int Dimensions() = 0; + virtual void Bounds(int dim, int* low, int* high) = 0; + virtual void SetBounds(int dim, int low, int high) = 0; + + virtual Database DatabasePtr() const = 0; + virtual Transaction TransactionPtr() const = 0; + + virtual IArray* AddRef() = 0; + virtual void Release() = 0; + + virtual ~IArray() { }; + }; + + /* IService is the interface to the service capabilities of IBPP. Service is + * the object class you actually use in your programming. With a Service + * object, you can do some maintenance work of databases and servers + * (backup, restore, create/update users, ...) */ + + class IService + { + public: + virtual void Connect() = 0; + virtual bool Connected() = 0; + virtual void Disconnect() = 0; + + virtual void GetVersion(std::string& version) = 0; + + virtual void AddUser(const User&) = 0; + virtual void GetUser(User&) = 0; + virtual void GetUsers(std::vector&) = 0; + virtual void ModifyUser(const User&) = 0; + virtual void RemoveUser(const std::string& username) = 0; + + virtual void SetPageBuffers(const std::string& dbfile, int buffers) = 0; + virtual void SetSweepInterval(const std::string& dbfile, int sweep) = 0; + virtual void SetSyncWrite(const std::string& dbfile, bool) = 0; + virtual void SetReadOnly(const std::string& dbfile, bool) = 0; + virtual void SetReserveSpace(const std::string& dbfile, bool) = 0; + + virtual void Shutdown(const std::string& dbfile, DSM mode, int sectimeout) = 0; + virtual void Restart(const std::string& dbfile) = 0; + virtual void Sweep(const std::string& dbfile) = 0; + virtual void Repair(const std::string& dbfile, RPF flags) = 0; + + virtual void StartBackup(const std::string& dbfile, + const std::string& bkfile, BRF flags = BRF(0)) = 0; + virtual void StartRestore(const std::string& bkfile, const std::string& dbfile, + int pagesize = 0, BRF flags = BRF(0)) = 0; + + virtual const char* WaitMsg() = 0; // With reporting (does not block) + virtual void Wait() = 0; // Without reporting (does block) + + virtual IService* AddRef() = 0; + virtual void Release() = 0; + + virtual ~IService() { }; + }; + + /* IDatabase is the interface to the database connections in IBPP. Database + * is the object class you actually use in your programming. With a Database + * object, you can create/drop/connect databases. */ + + class EventInterface; // Cross-reference between EventInterface and IDatabase + + class IDatabase + { + public: + virtual const char* ServerName() const = 0; + virtual const char* DatabaseName() const = 0; + virtual const char* Username() const = 0; + virtual const char* UserPassword() const = 0; + virtual const char* RoleName() const = 0; + virtual const char* CharSet() const = 0; + virtual const char* CreateParams() const = 0; + + virtual void Info(int* ODS, int* ODSMinor, int* PageSize, + int* Pages, int* Buffers, int* Sweep, bool* Sync, + bool* Reserve) = 0; + virtual void Statistics(int* Fetches, int* Marks, + int* Reads, int* Writes) = 0; + virtual void Counts(int* Insert, int* Update, int* Delete, + int* ReadIdx, int* ReadSeq) = 0; + virtual void Users(std::vector& users) = 0; + virtual int Dialect() = 0; + + virtual void Create(int dialect) = 0; + virtual void Connect() = 0; + virtual bool Connected() = 0; + virtual void Inactivate() = 0; + virtual void Disconnect() = 0; + virtual void Drop() = 0; + + virtual IDatabase* AddRef() = 0; + virtual void Release() = 0; + + virtual ~IDatabase() { }; + }; + + /* ITransaction is the interface to the transaction connections in IBPP. + * Transaction is the object class you actually use in your programming. A + * Transaction object can be associated with more than one Database, + * allowing for distributed transactions spanning multiple databases, + * possibly located on different servers. IBPP is one among the few + * programming interfaces to Firebird that allows you to support distributed + * transactions. */ + + class ITransaction + { + public: + virtual void AttachDatabase(Database db, TAM am = amWrite, + TIL il = ilConcurrency, TLR lr = lrWait, TFF flags = TFF(0)) = 0; + virtual void DetachDatabase(Database db) = 0; + virtual void AddReservation(Database db, + const std::string& table, TTR tr) = 0; + + virtual void Start() = 0; + virtual bool Started() = 0; + virtual void Commit() = 0; + virtual void Rollback() = 0; + virtual void CommitRetain() = 0; + virtual void RollbackRetain() = 0; + + virtual ITransaction* AddRef() = 0; + virtual void Release() = 0; + + virtual ~ITransaction() { }; + }; + + /* + * Class Row can hold all the values of a row (from a SELECT for instance). + */ + + class IRow + { + public: + virtual void SetNull(int) = 0; + virtual void Set(int, bool) = 0; + virtual void Set(int, const void*, int) = 0; // byte buffers + virtual void Set(int, const char*) = 0; // c-string + virtual void Set(int, const std::string&) = 0; + virtual void Set(int, int16_t) = 0; + virtual void Set(int, int32_t) = 0; + virtual void Set(int, int64_t) = 0; + virtual void Set(int, float) = 0; + virtual void Set(int, double) = 0; + virtual void Set(int, const Timestamp&) = 0; + virtual void Set(int, const Date&) = 0; + virtual void Set(int, const Time&) = 0; + virtual void Set(int, const DBKey&) = 0; + virtual void Set(int, const Blob&) = 0; + virtual void Set(int, const Array&) = 0; + + virtual bool IsNull(int) = 0; + virtual bool Get(int, bool&) = 0; + virtual bool Get(int, void*, int&) = 0; // byte buffers + virtual bool Get(int, std::string&) = 0; + virtual bool Get(int, int16_t&) = 0; + virtual bool Get(int, int32_t&) = 0; + virtual bool Get(int, int64_t&) = 0; + virtual bool Get(int, float&) = 0; + virtual bool Get(int, double&) = 0; + virtual bool Get(int, Timestamp&) = 0; + virtual bool Get(int, Date&) = 0; + virtual bool Get(int, Time&) = 0; + virtual bool Get(int, DBKey&) = 0; + virtual bool Get(int, Blob&) = 0; + virtual bool Get(int, Array&) = 0; + + virtual bool IsNull(const std::string&) = 0; + virtual bool Get(const std::string&, bool&) = 0; + virtual bool Get(const std::string&, void*, int&) = 0; // byte buffers + virtual bool Get(const std::string&, std::string&) = 0; + virtual bool Get(const std::string&, int16_t&) = 0; + virtual bool Get(const std::string&, int32_t&) = 0; + virtual bool Get(const std::string&, int64_t&) = 0; + virtual bool Get(const std::string&, float&) = 0; + virtual bool Get(const std::string&, double&) = 0; + virtual bool Get(const std::string&, Timestamp&) = 0; + virtual bool Get(const std::string&, Date&) = 0; + virtual bool Get(const std::string&, Time&) = 0; + virtual bool Get(const std::string&, DBKey&) = 0; + virtual bool Get(const std::string&, Blob&) = 0; + virtual bool Get(const std::string&, Array&) = 0; + + virtual int ColumnNum(const std::string&) = 0; + virtual const char* ColumnName(int) = 0; + virtual const char* ColumnAlias(int) = 0; + virtual const char* ColumnTable(int) = 0; + virtual SDT ColumnType(int) = 0; + virtual int ColumnSubtype(int) = 0; + virtual int ColumnSize(int) = 0; + virtual int ColumnScale(int) = 0; + virtual int Columns() = 0; + + virtual bool ColumnUpdated(int) = 0; + virtual bool Updated() = 0; + + virtual Database DatabasePtr() const = 0; + virtual Transaction TransactionPtr() const = 0; + + virtual IRow* Clone() = 0; + virtual IRow* AddRef() = 0; + virtual void Release() = 0; + + virtual ~IRow() {}; + }; + + /* IStatement is the interface to the statements execution in IBPP. + * Statement is the object class you actually use in your programming. A + * Statement object is the work horse of IBPP. All your data manipulation + * statements will be done through it. It is also used to access the result + * set of a query (when the statement is such), one row at a time and in + * strict forward direction. */ + + class IStatement + { + public: + virtual void Prepare(const std::string&) = 0; + virtual void Execute() = 0; + virtual void Execute(const std::string&) = 0; + virtual void ExecuteImmediate(const std::string&) = 0; + virtual void CursorExecute(const std::string& cursor) = 0; + virtual void CursorExecute(const std::string& cursor, const std::string&) = 0; + virtual bool Fetch() = 0; + virtual bool Fetch(Row&) = 0; + virtual int AffectedRows() = 0; + virtual void Close() = 0; + virtual std::string& Sql() = 0; + virtual STT Type() = 0; + + virtual void SetNull(int) = 0; + virtual void Set(int, bool) = 0; + virtual void Set(int, const void*, int) = 0; // byte buffers + virtual void Set(int, const char*) = 0; // c-string + virtual void Set(int, const std::string&) = 0; + virtual void Set(int, int16_t value) = 0; + virtual void Set(int, int32_t value) = 0; + virtual void Set(int, int64_t value) = 0; + virtual void Set(int, float value) = 0; + virtual void Set(int, double value) = 0; + virtual void Set(int, const Timestamp& value) = 0; + virtual void Set(int, const Date& value) = 0; + virtual void Set(int, const Time& value) = 0; + virtual void Set(int, const DBKey& value) = 0; + virtual void Set(int, const Blob& value) = 0; + virtual void Set(int, const Array& value) = 0; + + virtual bool IsNull(int) = 0; + virtual bool Get(int, bool&) = 0; + virtual bool Get(int, void*, int&) = 0; // byte buffers + virtual bool Get(int, std::string&) = 0; + virtual bool Get(int, int16_t&) = 0; + virtual bool Get(int, int32_t&) = 0; + virtual bool Get(int, int64_t&) = 0; + virtual bool Get(int, float&) = 0; + virtual bool Get(int, double&) = 0; + virtual bool Get(int, Timestamp& value) = 0; + virtual bool Get(int, Date& value) = 0; + virtual bool Get(int, Time& value) = 0; + virtual bool Get(int, DBKey& value) = 0; + virtual bool Get(int, Blob& value) = 0; + virtual bool Get(int, Array& value) = 0; + + virtual bool IsNull(const std::string&) = 0; + virtual bool Get(const std::string&, bool&) = 0; + virtual bool Get(const std::string&, void*, int&) = 0; // byte buffers + virtual bool Get(const std::string&, std::string&) = 0; + virtual bool Get(const std::string&, int16_t&) = 0; + virtual bool Get(const std::string&, int32_t&) = 0; + virtual bool Get(const std::string&, int64_t&) = 0; + virtual bool Get(const std::string&, float&) = 0; + virtual bool Get(const std::string&, double&) = 0; + virtual bool Get(const std::string&, Timestamp& value) = 0; + virtual bool Get(const std::string&, Date& value) = 0; + virtual bool Get(const std::string&, Time& value) = 0; + virtual bool Get(const std::string&, DBKey& value) = 0; + virtual bool Get(const std::string&, Blob& value) = 0; + virtual bool Get(const std::string&, Array& value) = 0; + + virtual int ColumnNum(const std::string&) = 0; + virtual const char* ColumnName(int) = 0; + virtual const char* ColumnAlias(int) = 0; + virtual const char* ColumnTable(int) = 0; + virtual SDT ColumnType(int) = 0; + virtual int ColumnSubtype(int) = 0; + virtual int ColumnSize(int) = 0; + virtual int ColumnScale(int) = 0; + virtual int Columns() = 0; + + virtual SDT ParameterType(int) = 0; + virtual int ParameterSubtype(int) = 0; + virtual int ParameterSize(int) = 0; + virtual int ParameterScale(int) = 0; + virtual int Parameters() = 0; + + virtual void Plan(std::string&) = 0; + + virtual Database DatabasePtr() const = 0; + virtual Transaction TransactionPtr() const = 0; + + virtual IStatement* AddRef() = 0; + virtual void Release() = 0; + + virtual ~IStatement() { }; + + // DEPRECATED METHODS (WON'T BE AVAILABLE IN VERSIONS 3.x) + virtual bool Get(int, char*) = 0; // DEPRECATED + virtual bool Get(const std::string&, char*) = 0; // DEPRECATED + virtual bool Get(int, bool*) = 0; // DEPRECATED + virtual bool Get(const std::string&, bool*) = 0; // DEPRECATED + virtual bool Get(int, int16_t*) = 0; // DEPRECATED + virtual bool Get(const std::string&, int16_t*) = 0; // DEPRECATED + virtual bool Get(int, int32_t*) = 0; // DEPRECATED + virtual bool Get(const std::string&, int32_t*) = 0; // DEPRECATED + virtual bool Get(int, int64_t*) = 0; // DEPRECATED + virtual bool Get(const std::string&, int64_t*) = 0; // DEPRECATED + virtual bool Get(int, float*) = 0; // DEPRECATED + virtual bool Get(const std::string&, float*) = 0; // DEPRECATED + virtual bool Get(int, double*) = 0; // DEPRECATED + virtual bool Get(const std::string&, double*) = 0; // DEPRECATED + }; + + class IEvents + { + public: + virtual void Add(const std::string&, EventInterface*) = 0; + virtual void Drop(const std::string&) = 0; + virtual void List(std::vector&) = 0; + virtual void Clear() = 0; // Drop all events + virtual void Dispatch() = 0; // Dispatch events (calls handlers) + + virtual Database DatabasePtr() const = 0; + + virtual IEvents* AddRef() = 0; + virtual void Release() = 0; + + virtual ~IEvents() { }; + }; + + /* Class EventInterface is merely a pure interface. + * It is _not_ implemented by IBPP. It is only a base class definition from + * which your own event interface classes have to derive from. + * Please read the reference guide at http://www.ibpp.org for more info. */ + + class EventInterface + { + public: + virtual void ibppEventHandler(Events, const std::string&, int) = 0; + virtual ~EventInterface() { }; + }; + + // --- Factories --- + // These methods are the only way to get one of the above + // Interfaces. They are at the heart of how you program using IBPP. For + // instance, to get access to a database, you'll write code similar to this: + // { + // Database db = DatabaseFactory("server", "databasename", + // "user", "password"); + // db->Connect(); + // ... + // db->Disconnect(); + // } + + Service ServiceFactory(const std::string& ServerName, + const std::string& UserName, const std::string& UserPassword); + + Database DatabaseFactory(const std::string& ServerName, + const std::string& DatabaseName, const std::string& UserName, + const std::string& UserPassword, const std::string& RoleName, + const std::string& CharSet, const std::string& CreateParams); + + inline Database DatabaseFactory(const std::string& ServerName, + const std::string& DatabaseName, const std::string& UserName, + const std::string& UserPassword) + { return DatabaseFactory(ServerName, DatabaseName, UserName, UserPassword, "", "", ""); } + + Transaction TransactionFactory(Database db, TAM am = amWrite, + TIL il = ilConcurrency, TLR lr = lrWait, TFF flags = TFF(0)); + + Statement StatementFactory(Database db, Transaction tr, + const std::string& sql); + + inline Statement StatementFactory(Database db, Transaction tr) + { return StatementFactory(db, tr, ""); } + + Blob BlobFactory(Database db, Transaction tr); + + Array ArrayFactory(Database db, Transaction tr); + + Events EventsFactory(Database db); + + /* IBPP uses a self initialization system. Each time an object that may + * require the usage of the Interbase client C-API library is used, the + * library internal handling details are automatically initialized, if not + * already done. You can kick this initialization at the start of an + * application by calling IBPP::CheckVersion(). This is recommended, because + * IBPP::CheckVersion will assure you that YOUR code has been compiled + * against a compatible version of the library. */ + + bool CheckVersion(uint32_t); + int GDSVersion(); + + /* On Win32 platform, ClientLibSearchPaths() allows to setup + * one or multiple additional paths (separated with a ';') where IBPP + * will look for the client library (before the default implicit search + * locations). This is usefull for applications distributed with a 'private' + * copy of Firebird, when the registry is useless to identify the location + * from where to attempt loading the fbclient.dll / gds32.dll. + * If called, this function must be called *early* by the application, + * before *any* other function or object methods of IBPP. + * Currently, this is a NO-OP on platforms other than Win32. */ + + void ClientLibSearchPaths(const std::string&); + + /* Finally, here are some date and time conversion routines used by IBPP and + * that may be helpful at the application level. They do not depend on + * anything related to Firebird/Interbase. Just a bonus. dtoi and itod + * return false on invalid parameters or out of range conversions. */ + + bool dtoi(int date, int* py, int* pm, int* pd); + bool itod(int* pdate, int year, int month, int day); + void ttoi(int itime, int* phour, int* pminute, int* psecond, int* ptt); + void itot(int* ptime, int hour, int minute, int second = 0, int tenthousandths = 0); + +} + +#endif + +// +// EOF +// diff --git a/stglibs/locker.lib/include/stg/locker.h b/stglibs/locker.lib/include/stg/locker.h new file mode 100644 index 00000000..7a8d0b8d --- /dev/null +++ b/stglibs/locker.lib/include/stg/locker.h @@ -0,0 +1,96 @@ +/* + * 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 + */ + +/* + $Revision: 1.5 $ + $Date: 2010/03/04 11:57:11 $ + $Author: faust $ +*/ + + +#ifndef STG_LOCKER_H +#define STG_LOCKER_H + +#include + +#ifdef DEBUG_LOCKER + +#include +#include +#include + +#endif + +//----------------------------------------------------------------------------- +class STG_LOCKER +{ +public: + #ifdef DEBUG_LOCKER + STG_LOCKER(pthread_mutex_t * m, const char * __file__, int __line__) + : mutex(m), + file(__file__), + line(__line__), + lockerMutex(), + lockID(0) + #else + STG_LOCKER(pthread_mutex_t * m, const char *, int) + : mutex(m) + #endif + { + mutex = m; + #ifdef DEBUG_LOCKER + pthread_mutex_lock(&lockerMutex); + file = __file__; + line = __line__; + if (id == 0) + pthread_mutex_init(&lockerMutex, NULL); + + lockID = ++id; + std::cout << "Lock: " << lockID << " " << file << ":" << line << " " << mutex << " " << pthread_self() << std::endl; + pthread_mutex_unlock(&lockerMutex); + #endif + pthread_mutex_lock(mutex); + }; + + ~STG_LOCKER() + { + pthread_mutex_unlock(mutex); + #ifdef DEBUG_LOCKER + pthread_mutex_lock(&lockerMutex); + std::cout << "Unlock: " << lockID << " " << file << ":" << line << " " << mutex << " " << pthread_self() << std::endl; + pthread_mutex_unlock(&lockerMutex); + #endif + }; +private: + STG_LOCKER(const STG_LOCKER & rvalue); + STG_LOCKER & operator=(const STG_LOCKER & rvalue); + + pthread_mutex_t * mutex; + #ifdef DEBUG_LOCKER + std::string file; + int line; + static pthread_mutex_t lockerMutex; + static long long id; + long long lockID; + #endif +}; +//----------------------------------------------------------------------------- + +#endif //STG_LOCKER_H diff --git a/stglibs/locker.lib/locker.h b/stglibs/locker.lib/locker.h deleted file mode 100644 index 7a8d0b8d..00000000 --- a/stglibs/locker.lib/locker.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - -/* - $Revision: 1.5 $ - $Date: 2010/03/04 11:57:11 $ - $Author: faust $ -*/ - - -#ifndef STG_LOCKER_H -#define STG_LOCKER_H - -#include - -#ifdef DEBUG_LOCKER - -#include -#include -#include - -#endif - -//----------------------------------------------------------------------------- -class STG_LOCKER -{ -public: - #ifdef DEBUG_LOCKER - STG_LOCKER(pthread_mutex_t * m, const char * __file__, int __line__) - : mutex(m), - file(__file__), - line(__line__), - lockerMutex(), - lockID(0) - #else - STG_LOCKER(pthread_mutex_t * m, const char *, int) - : mutex(m) - #endif - { - mutex = m; - #ifdef DEBUG_LOCKER - pthread_mutex_lock(&lockerMutex); - file = __file__; - line = __line__; - if (id == 0) - pthread_mutex_init(&lockerMutex, NULL); - - lockID = ++id; - std::cout << "Lock: " << lockID << " " << file << ":" << line << " " << mutex << " " << pthread_self() << std::endl; - pthread_mutex_unlock(&lockerMutex); - #endif - pthread_mutex_lock(mutex); - }; - - ~STG_LOCKER() - { - pthread_mutex_unlock(mutex); - #ifdef DEBUG_LOCKER - pthread_mutex_lock(&lockerMutex); - std::cout << "Unlock: " << lockID << " " << file << ":" << line << " " << mutex << " " << pthread_self() << std::endl; - pthread_mutex_unlock(&lockerMutex); - #endif - }; -private: - STG_LOCKER(const STG_LOCKER & rvalue); - STG_LOCKER & operator=(const STG_LOCKER & rvalue); - - pthread_mutex_t * mutex; - #ifdef DEBUG_LOCKER - std::string file; - int line; - static pthread_mutex_t lockerMutex; - static long long id; - long long lockID; - #endif -}; -//----------------------------------------------------------------------------- - -#endif //STG_LOCKER_H diff --git a/stglibs/logger.lib/include/stg/logger.h b/stglibs/logger.lib/include/stg/logger.h new file mode 100644 index 00000000..9fe14878 --- /dev/null +++ b/stglibs/logger.lib/include/stg/logger.h @@ -0,0 +1,47 @@ +#ifndef STG_LOGGER_H +#define STG_LOGGER_H + +#include + +#include + +const char * LogDate(time_t t); +//----------------------------------------------------------------------------- +class STG_LOGGER; +STG_LOGGER & GetStgLogger(); +//----------------------------------------------------------------------------- +class STG_LOGGER_LOCKER +{ +public: + STG_LOGGER_LOCKER(pthread_mutex_t * m) : mutex(m) { pthread_mutex_lock(mutex); }; + ~STG_LOGGER_LOCKER() { pthread_mutex_unlock(mutex); }; + +private: + STG_LOGGER_LOCKER(const STG_LOGGER_LOCKER & rvalue); + STG_LOGGER_LOCKER & operator=(const STG_LOGGER_LOCKER & rvalue); + + pthread_mutex_t * mutex; +}; +//----------------------------------------------------------------------------- +class STG_LOGGER +{ +friend STG_LOGGER & GetStgLogger(); + +public: + ~STG_LOGGER(); + void SetLogFileName(const std::string & fn); + void operator()(const char * fmt, ...); + +private: + STG_LOGGER(); + STG_LOGGER(const STG_LOGGER & rvalue); + STG_LOGGER & operator=(const STG_LOGGER & rvalue); + + const char * LogDate(time_t t); + + std::string fileName; + pthread_mutex_t mutex; +}; +//----------------------------------------------------------------------------- + +#endif //STG_LOGGER_H diff --git a/stglibs/logger.lib/logger.h b/stglibs/logger.lib/logger.h deleted file mode 100644 index 9fe14878..00000000 --- a/stglibs/logger.lib/logger.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef STG_LOGGER_H -#define STG_LOGGER_H - -#include - -#include - -const char * LogDate(time_t t); -//----------------------------------------------------------------------------- -class STG_LOGGER; -STG_LOGGER & GetStgLogger(); -//----------------------------------------------------------------------------- -class STG_LOGGER_LOCKER -{ -public: - STG_LOGGER_LOCKER(pthread_mutex_t * m) : mutex(m) { pthread_mutex_lock(mutex); }; - ~STG_LOGGER_LOCKER() { pthread_mutex_unlock(mutex); }; - -private: - STG_LOGGER_LOCKER(const STG_LOGGER_LOCKER & rvalue); - STG_LOGGER_LOCKER & operator=(const STG_LOGGER_LOCKER & rvalue); - - pthread_mutex_t * mutex; -}; -//----------------------------------------------------------------------------- -class STG_LOGGER -{ -friend STG_LOGGER & GetStgLogger(); - -public: - ~STG_LOGGER(); - void SetLogFileName(const std::string & fn); - void operator()(const char * fmt, ...); - -private: - STG_LOGGER(); - STG_LOGGER(const STG_LOGGER & rvalue); - STG_LOGGER & operator=(const STG_LOGGER & rvalue); - - const char * LogDate(time_t t); - - std::string fileName; - pthread_mutex_t mutex; -}; -//----------------------------------------------------------------------------- - -#endif //STG_LOGGER_H diff --git a/stglibs/pinger.lib/include/stg/pinger.h b/stglibs/pinger.lib/include/stg/pinger.h new file mode 100644 index 00000000..b1b77781 --- /dev/null +++ b/stglibs/pinger.lib/include/stg/pinger.h @@ -0,0 +1,132 @@ + /* + $Revision: 1.8 $ + $Date: 2008/05/10 11:59:53 $ + $Author: nobunaga $ + */ + +#ifndef PINGER_H +#define PINGER_H + +#include +#include +#include +#include + +#ifdef LINUX +#include +#include +#include +#endif + +#if defined (FREE_BSD) || defined (FREE_BSD5) +#include +#include +#include +#include +#include +#include +#endif + +#include "stg/os_int.h" + +//----------------------------------------------------------------------------- +struct ICMP_HDR +{ +uint8_t type; +uint8_t code; +uint16_t checksum; +union + { + struct + { + uint16_t id; + uint16_t sequence; + } echo; + uint32_t gateway; + struct + { + uint16_t unused; + uint16_t mtu; + } frag; + } un; +}; +//----------------------------------------------------------------------------- +struct IP_HDR +{ + uint8_t ihl:4, + version:4; + uint8_t tos; + uint16_t tot_len; + uint16_t id; + uint16_t frag_off; + uint8_t ttl; + uint8_t protocol; + uint16_t check; + uint32_t saddr; + uint32_t daddr; +}; +//----------------------------------------------------------------------------- +struct PING_IP_TIME +{ +uint32_t ip; +time_t pingTime; +}; +//----------------------------------------------------------------------------- + +#define PING_DATA_LEN (64) +//----------------------------------------------------------------------------- +struct PING_MESSAGE +{ + ICMP_HDR hdr; + char msg[PING_DATA_LEN]; +}; +//----------------------------------------------------------------------------- +class STG_PINGER +{ +public: + STG_PINGER(time_t delay = 15); + ~STG_PINGER(); + + int Start(); + int Stop(); + void AddIP(uint32_t ip); + void DelIP(uint32_t ip); + int GetPingIPNum() const; + void PrintAllIP(); + int GetIPTime(uint32_t ip, time_t * t) const; + void SetDelayTime(time_t d) { delay = d; } + time_t GetDelayTime() const { return delay; } + const std::string & GetStrError() const { return errorStr; } + +private: + uint16_t PingCheckSum(void * data, int len); + int SendPing(uint32_t ip); + uint32_t RecvPing(); + void RealAddIP(); + void RealDelIP(); + + static void * RunSendPing(void * d); + static void * RunRecvPing(void * d); + + int delay; + bool nonstop; + bool isRunningRecver; + bool isRunningSender; + int sendSocket; + int recvSocket; + pthread_t sendThread; + pthread_t recvThread; + + PING_MESSAGE pmSend; + uint32_t pid; + + std::string errorStr; + + std::multimap pingIP; + std::list ipToAdd; + std::list ipToDel; + + mutable pthread_mutex_t mutex; +}; +//----------------------------------------------------------------------------- +#endif diff --git a/stglibs/pinger.lib/pinger.h b/stglibs/pinger.lib/pinger.h deleted file mode 100644 index b1b77781..00000000 --- a/stglibs/pinger.lib/pinger.h +++ /dev/null @@ -1,132 +0,0 @@ - /* - $Revision: 1.8 $ - $Date: 2008/05/10 11:59:53 $ - $Author: nobunaga $ - */ - -#ifndef PINGER_H -#define PINGER_H - -#include -#include -#include -#include - -#ifdef LINUX -#include -#include -#include -#endif - -#if defined (FREE_BSD) || defined (FREE_BSD5) -#include -#include -#include -#include -#include -#include -#endif - -#include "stg/os_int.h" - -//----------------------------------------------------------------------------- -struct ICMP_HDR -{ -uint8_t type; -uint8_t code; -uint16_t checksum; -union - { - struct - { - uint16_t id; - uint16_t sequence; - } echo; - uint32_t gateway; - struct - { - uint16_t unused; - uint16_t mtu; - } frag; - } un; -}; -//----------------------------------------------------------------------------- -struct IP_HDR -{ - uint8_t ihl:4, - version:4; - uint8_t tos; - uint16_t tot_len; - uint16_t id; - uint16_t frag_off; - uint8_t ttl; - uint8_t protocol; - uint16_t check; - uint32_t saddr; - uint32_t daddr; -}; -//----------------------------------------------------------------------------- -struct PING_IP_TIME -{ -uint32_t ip; -time_t pingTime; -}; -//----------------------------------------------------------------------------- - -#define PING_DATA_LEN (64) -//----------------------------------------------------------------------------- -struct PING_MESSAGE -{ - ICMP_HDR hdr; - char msg[PING_DATA_LEN]; -}; -//----------------------------------------------------------------------------- -class STG_PINGER -{ -public: - STG_PINGER(time_t delay = 15); - ~STG_PINGER(); - - int Start(); - int Stop(); - void AddIP(uint32_t ip); - void DelIP(uint32_t ip); - int GetPingIPNum() const; - void PrintAllIP(); - int GetIPTime(uint32_t ip, time_t * t) const; - void SetDelayTime(time_t d) { delay = d; } - time_t GetDelayTime() const { return delay; } - const std::string & GetStrError() const { return errorStr; } - -private: - uint16_t PingCheckSum(void * data, int len); - int SendPing(uint32_t ip); - uint32_t RecvPing(); - void RealAddIP(); - void RealDelIP(); - - static void * RunSendPing(void * d); - static void * RunRecvPing(void * d); - - int delay; - bool nonstop; - bool isRunningRecver; - bool isRunningSender; - int sendSocket; - int recvSocket; - pthread_t sendThread; - pthread_t recvThread; - - PING_MESSAGE pmSend; - uint32_t pid; - - std::string errorStr; - - std::multimap pingIP; - std::list ipToAdd; - std::list ipToDel; - - mutable pthread_mutex_t mutex; -}; -//----------------------------------------------------------------------------- -#endif diff --git a/stglibs/scriptexecuter.lib/include/stg/scriptexecuter.h b/stglibs/scriptexecuter.lib/include/stg/scriptexecuter.h new file mode 100644 index 00000000..41b02a2f --- /dev/null +++ b/stglibs/scriptexecuter.lib/include/stg/scriptexecuter.h @@ -0,0 +1,19 @@ +#ifndef SCRIPT_EXECUTER_H +#define SCRIPT_EXECUTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +int ScriptExec(const char * str); +#ifdef LINUX +void Executer(int msgID, pid_t pid, char * procName); +#else +void Executer(int msgID, pid_t pid); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stglibs/scriptexecuter.lib/scriptexecuter.h b/stglibs/scriptexecuter.lib/scriptexecuter.h deleted file mode 100644 index 41b02a2f..00000000 --- a/stglibs/scriptexecuter.lib/scriptexecuter.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef SCRIPT_EXECUTER_H -#define SCRIPT_EXECUTER_H - -#ifdef __cplusplus -extern "C" { -#endif - -int ScriptExec(const char * str); -#ifdef LINUX -void Executer(int msgID, pid_t pid, char * procName); -#else -void Executer(int msgID, pid_t pid); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/stglibs/smux.lib/ANY.h b/stglibs/smux.lib/ANY.h deleted file mode 100644 index b7d92fa9..00000000 --- a/stglibs/smux.lib/ANY.h +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * Copyright (c) 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_TYPE_ANY_H -#define ASN_TYPE_ANY_H - -#include /* Implemented via OCTET STRING type */ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ANY { - uint8_t *buf; /* BER-encoded ANY contents */ - int size; /* Size of the above buffer */ - - asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */ -} ANY_t; - -extern asn_TYPE_descriptor_t asn_DEF_ANY; - -asn_struct_free_f ANY_free; -asn_struct_print_f ANY_print; -ber_type_decoder_f ANY_decode_ber; -der_type_encoder_f ANY_encode_der; -xer_type_encoder_f ANY_encode_xer; - -/****************************** - * Handy conversion routines. * - ******************************/ - -/* Convert another ASN.1 type into the ANY. This implies DER encoding. */ -int ANY_fromType(ANY_t *, asn_TYPE_descriptor_t *td, void *struct_ptr); -ANY_t *ANY_new_fromType(asn_TYPE_descriptor_t *td, void *struct_ptr); - -/* Convert the contents of the ANY type into the specified type. */ -int ANY_to_type(ANY_t *, asn_TYPE_descriptor_t *td, void **struct_ptr); - -#define ANY_fromBuf(s, buf, size) OCTET_STRING_fromBuf((s), (buf), (size)) -#define ANY_new_fromBuf(buf, size) OCTET_STRING_new_fromBuf( \ - &asn_DEF_ANY, (buf), (size)) - -#ifdef __cplusplus -} -#endif - -#endif /* ASN_TYPE_ANY_H */ diff --git a/stglibs/smux.lib/ApplicationSyntax.h b/stglibs/smux.lib/ApplicationSyntax.h deleted file mode 100644 index 90a87076..00000000 --- a/stglibs/smux.lib/ApplicationSyntax.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _ApplicationSyntax_H_ -#define _ApplicationSyntax_H_ - - -#include - -/* Including external dependencies */ -#include "NetworkAddress.h" -#include "Counter.h" -#include "Gauge.h" -#include "TimeTicks.h" -#include "Opaque.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum ApplicationSyntax_PR { - ApplicationSyntax_PR_NOTHING, /* No components present */ - ApplicationSyntax_PR_address, - ApplicationSyntax_PR_counter, - ApplicationSyntax_PR_gauge, - ApplicationSyntax_PR_ticks, - ApplicationSyntax_PR_arbitrary -} ApplicationSyntax_PR; - -/* ApplicationSyntax */ -typedef struct ApplicationSyntax { - ApplicationSyntax_PR present; - union ApplicationSyntax_u { - NetworkAddress_t address; - Counter_t counter; - Gauge_t gauge; - TimeTicks_t ticks; - Opaque_t arbitrary; - } choice; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} ApplicationSyntax_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_ApplicationSyntax; - -#ifdef __cplusplus -} -#endif - -#endif /* _ApplicationSyntax_H_ */ diff --git a/stglibs/smux.lib/AtEntry.h b/stglibs/smux.lib/AtEntry.h deleted file mode 100644 index a0aba105..00000000 --- a/stglibs/smux.lib/AtEntry.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _AtEntry_H_ -#define _AtEntry_H_ - - -#include - -/* Including external dependencies */ -#include -#include "PhysAddress.h" -#include "NetworkAddress.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* AtEntry */ -typedef struct AtEntry { - INTEGER_t atIfIndex; - PhysAddress_t atPhysAddress; - NetworkAddress_t atNetAddress; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} AtEntry_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_AtEntry; - -#ifdef __cplusplus -} -#endif - -#endif /* _AtEntry_H_ */ diff --git a/stglibs/smux.lib/BIT_STRING.h b/stglibs/smux.lib/BIT_STRING.h deleted file mode 100644 index 732e878b..00000000 --- a/stglibs/smux.lib/BIT_STRING.h +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * Copyright (c) 2003 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _BIT_STRING_H_ -#define _BIT_STRING_H_ - -#include /* Some help from OCTET STRING */ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct BIT_STRING_s { - uint8_t *buf; /* BIT STRING body */ - int size; /* Size of the above buffer */ - - int bits_unused;/* Unused trailing bits in the last octet (0..7) */ - - asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */ -} BIT_STRING_t; - -extern asn_TYPE_descriptor_t asn_DEF_BIT_STRING; - -asn_struct_print_f BIT_STRING_print; /* Human-readable output */ -asn_constr_check_f BIT_STRING_constraint; -xer_type_encoder_f BIT_STRING_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _BIT_STRING_H_ */ diff --git a/stglibs/smux.lib/BOOLEAN.h b/stglibs/smux.lib/BOOLEAN.h deleted file mode 100644 index 217d0f16..00000000 --- a/stglibs/smux.lib/BOOLEAN.h +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * Copyright (c) 2003 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _BOOLEAN_H_ -#define _BOOLEAN_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * The underlying integer may contain various values, but everything - * non-zero is capped to 0xff by the DER encoder. The BER decoder may - * yield non-zero values different from 1, beware. - */ -typedef int BOOLEAN_t; - -extern asn_TYPE_descriptor_t asn_DEF_BOOLEAN; - -asn_struct_free_f BOOLEAN_free; -asn_struct_print_f BOOLEAN_print; -ber_type_decoder_f BOOLEAN_decode_ber; -der_type_encoder_f BOOLEAN_encode_der; -xer_type_decoder_f BOOLEAN_decode_xer; -xer_type_encoder_f BOOLEAN_encode_xer; -per_type_decoder_f BOOLEAN_decode_uper; -per_type_encoder_f BOOLEAN_encode_uper; - -#ifdef __cplusplus -} -#endif - -#endif /* _BOOLEAN_H_ */ diff --git a/stglibs/smux.lib/ClosePDU.h b/stglibs/smux.lib/ClosePDU.h deleted file mode 100644 index a3d1e7a9..00000000 --- a/stglibs/smux.lib/ClosePDU.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "SMUX" - * found in "SMUX.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _ClosePDU_H_ -#define _ClosePDU_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum ClosePDU { - ClosePDU_goingDown = 0, - ClosePDU_unsupportedVersion = 1, - ClosePDU_packetFormat = 2, - ClosePDU_protocolError = 3, - ClosePDU_internalError = 4, - ClosePDU_authenticationFailure = 5 -} e_ClosePDU; - -/* ClosePDU */ -typedef INTEGER_t ClosePDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_ClosePDU; -asn_struct_free_f ClosePDU_free; -asn_struct_print_f ClosePDU_print; -asn_constr_check_f ClosePDU_constraint; -ber_type_decoder_f ClosePDU_decode_ber; -der_type_encoder_f ClosePDU_encode_der; -xer_type_decoder_f ClosePDU_decode_xer; -xer_type_encoder_f ClosePDU_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _ClosePDU_H_ */ diff --git a/stglibs/smux.lib/Counter.h b/stglibs/smux.lib/Counter.h deleted file mode 100644 index 3c770ada..00000000 --- a/stglibs/smux.lib/Counter.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _Counter_H_ -#define _Counter_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Counter */ -typedef INTEGER_t Counter_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_Counter; -asn_struct_free_f Counter_free; -asn_struct_print_f Counter_print; -asn_constr_check_f Counter_constraint; -ber_type_decoder_f Counter_decode_ber; -der_type_encoder_f Counter_encode_der; -xer_type_decoder_f Counter_decode_xer; -xer_type_encoder_f Counter_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _Counter_H_ */ diff --git a/stglibs/smux.lib/DisplayString.h b/stglibs/smux.lib/DisplayString.h deleted file mode 100644 index ac6862c2..00000000 --- a/stglibs/smux.lib/DisplayString.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _DisplayString_H_ -#define _DisplayString_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* DisplayString */ -typedef OCTET_STRING_t DisplayString_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_DisplayString; -asn_struct_free_f DisplayString_free; -asn_struct_print_f DisplayString_print; -asn_constr_check_f DisplayString_constraint; -ber_type_decoder_f DisplayString_decode_ber; -der_type_encoder_f DisplayString_encode_der; -xer_type_decoder_f DisplayString_decode_xer; -xer_type_encoder_f DisplayString_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _DisplayString_H_ */ diff --git a/stglibs/smux.lib/EgpNeighEntry.h b/stglibs/smux.lib/EgpNeighEntry.h deleted file mode 100644 index 79d3eedd..00000000 --- a/stglibs/smux.lib/EgpNeighEntry.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _EgpNeighEntry_H_ -#define _EgpNeighEntry_H_ - - -#include - -/* Including external dependencies */ -#include -#include "IpAddress.h" -#include "Counter.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* EgpNeighEntry */ -typedef struct EgpNeighEntry { - INTEGER_t egpNeighState; - IpAddress_t egpNeighAddr; - INTEGER_t egpNeighAs; - Counter_t egpNeighInMsgs; - Counter_t egpNeighInErrs; - Counter_t egpNeighOutMsgs; - Counter_t egpNeighOutErrs; - Counter_t egpNeighInErrMsgs; - Counter_t egpNeighOutErrMsgs; - Counter_t egpNeighStateUps; - Counter_t egpNeighStateDowns; - INTEGER_t egpNeighIntervalHello; - INTEGER_t egpNeighIntervalPoll; - INTEGER_t egpNeighMode; - INTEGER_t egpNeighEventTrigger; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} EgpNeighEntry_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_EgpNeighEntry; - -#ifdef __cplusplus -} -#endif - -#endif /* _EgpNeighEntry_H_ */ diff --git a/stglibs/smux.lib/Gauge.h b/stglibs/smux.lib/Gauge.h deleted file mode 100644 index f3e17c5e..00000000 --- a/stglibs/smux.lib/Gauge.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _Gauge_H_ -#define _Gauge_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Gauge */ -typedef INTEGER_t Gauge_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_Gauge; -asn_struct_free_f Gauge_free; -asn_struct_print_f Gauge_print; -asn_constr_check_f Gauge_constraint; -ber_type_decoder_f Gauge_decode_ber; -der_type_encoder_f Gauge_encode_der; -xer_type_decoder_f Gauge_decode_xer; -xer_type_encoder_f Gauge_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _Gauge_H_ */ diff --git a/stglibs/smux.lib/GetNextRequest-PDU.h b/stglibs/smux.lib/GetNextRequest-PDU.h deleted file mode 100644 index f9298ec6..00000000 --- a/stglibs/smux.lib/GetNextRequest-PDU.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _GetNextRequest_PDU_H_ -#define _GetNextRequest_PDU_H_ - - -#include - -/* Including external dependencies */ -#include "PDU.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* GetNextRequest-PDU */ -typedef PDU_t GetNextRequest_PDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_GetNextRequest_PDU; -asn_struct_free_f GetNextRequest_PDU_free; -asn_struct_print_f GetNextRequest_PDU_print; -asn_constr_check_f GetNextRequest_PDU_constraint; -ber_type_decoder_f GetNextRequest_PDU_decode_ber; -der_type_encoder_f GetNextRequest_PDU_encode_der; -xer_type_decoder_f GetNextRequest_PDU_decode_xer; -xer_type_encoder_f GetNextRequest_PDU_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _GetNextRequest_PDU_H_ */ diff --git a/stglibs/smux.lib/GetRequest-PDU.h b/stglibs/smux.lib/GetRequest-PDU.h deleted file mode 100644 index 9449451f..00000000 --- a/stglibs/smux.lib/GetRequest-PDU.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _GetRequest_PDU_H_ -#define _GetRequest_PDU_H_ - - -#include - -/* Including external dependencies */ -#include "PDU.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* GetRequest-PDU */ -typedef PDU_t GetRequest_PDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_GetRequest_PDU; -asn_struct_free_f GetRequest_PDU_free; -asn_struct_print_f GetRequest_PDU_print; -asn_constr_check_f GetRequest_PDU_constraint; -ber_type_decoder_f GetRequest_PDU_decode_ber; -der_type_encoder_f GetRequest_PDU_encode_der; -xer_type_decoder_f GetRequest_PDU_decode_xer; -xer_type_encoder_f GetRequest_PDU_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _GetRequest_PDU_H_ */ diff --git a/stglibs/smux.lib/GetResponse-PDU.h b/stglibs/smux.lib/GetResponse-PDU.h deleted file mode 100644 index 12e3fba1..00000000 --- a/stglibs/smux.lib/GetResponse-PDU.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _GetResponse_PDU_H_ -#define _GetResponse_PDU_H_ - - -#include - -/* Including external dependencies */ -#include "PDU.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* GetResponse-PDU */ -typedef PDU_t GetResponse_PDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_GetResponse_PDU; -asn_struct_free_f GetResponse_PDU_free; -asn_struct_print_f GetResponse_PDU_print; -asn_constr_check_f GetResponse_PDU_constraint; -ber_type_decoder_f GetResponse_PDU_decode_ber; -der_type_encoder_f GetResponse_PDU_encode_der; -xer_type_decoder_f GetResponse_PDU_decode_xer; -xer_type_encoder_f GetResponse_PDU_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _GetResponse_PDU_H_ */ diff --git a/stglibs/smux.lib/INTEGER.h b/stglibs/smux.lib/INTEGER.h deleted file mode 100644 index 62832b12..00000000 --- a/stglibs/smux.lib/INTEGER.h +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * Copyright (c) 2003, 2005 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _INTEGER_H_ -#define _INTEGER_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef ASN__PRIMITIVE_TYPE_t INTEGER_t; - -extern asn_TYPE_descriptor_t asn_DEF_INTEGER; - -/* Map with to integer value association */ -typedef struct asn_INTEGER_enum_map_s { - long nat_value; /* associated native integer value */ - size_t enum_len; /* strlen("tag") */ - const char *enum_name; /* "tag" */ -} asn_INTEGER_enum_map_t; - -/* This type describes an enumeration for INTEGER and ENUMERATED types */ -typedef struct asn_INTEGER_specifics_s { - asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */ - unsigned int *enum2value; /* "tag" => N; sorted by tag */ - int map_count; /* Elements in either map */ - int extension; /* This map is extensible */ - int strict_enumeration; /* Enumeration set is fixed */ -} asn_INTEGER_specifics_t; - -asn_struct_print_f INTEGER_print; -ber_type_decoder_f INTEGER_decode_ber; -der_type_encoder_f INTEGER_encode_der; -xer_type_decoder_f INTEGER_decode_xer; -xer_type_encoder_f INTEGER_encode_xer; -per_type_decoder_f INTEGER_decode_uper; -per_type_encoder_f INTEGER_encode_uper; - -/*********************************** - * Some handy conversion routines. * - ***********************************/ - -/* - * Returns 0 if it was possible to convert, -1 otherwise. - * -1/EINVAL: Mandatory argument missing - * -1/ERANGE: Value encoded is out of range for long representation - * -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()). - */ -int asn_INTEGER2long(const INTEGER_t *i, long *l); -int asn_long2INTEGER(INTEGER_t *i, long l); - -/* - * Convert the integer value into the corresponding enumeration map entry. - */ -const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value); - -#ifdef __cplusplus -} -#endif - -#endif /* _INTEGER_H_ */ diff --git a/stglibs/smux.lib/IfEntry.h b/stglibs/smux.lib/IfEntry.h deleted file mode 100644 index eb30717b..00000000 --- a/stglibs/smux.lib/IfEntry.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _IfEntry_H_ -#define _IfEntry_H_ - - -#include - -/* Including external dependencies */ -#include -#include "DisplayString.h" -#include "Gauge.h" -#include "PhysAddress.h" -#include "TimeTicks.h" -#include "Counter.h" -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* IfEntry */ -typedef struct IfEntry { - INTEGER_t ifIndex; - DisplayString_t ifDescr; - INTEGER_t ifType; - INTEGER_t ifMtu; - Gauge_t ifSpeed; - PhysAddress_t ifPhysAddress; - INTEGER_t ifAdminStatus; - INTEGER_t ifOperStatus; - TimeTicks_t ifLastChange; - Counter_t ifInOctets; - Counter_t ifInUcastPkts; - Counter_t ifInNUcastPkts; - Counter_t ifInDiscards; - Counter_t ifInErrors; - Counter_t ifInUnknownProtos; - Counter_t ifOutOctets; - Counter_t ifOutUcastPkts; - Counter_t ifOutNUcastPkts; - Counter_t ifOutDiscards; - Counter_t ifOutErrors; - Gauge_t ifOutQLen; - OBJECT_IDENTIFIER_t ifSpecific; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} IfEntry_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_IfEntry; - -#ifdef __cplusplus -} -#endif - -#endif /* _IfEntry_H_ */ diff --git a/stglibs/smux.lib/IpAddrEntry.h b/stglibs/smux.lib/IpAddrEntry.h deleted file mode 100644 index 9e36f32a..00000000 --- a/stglibs/smux.lib/IpAddrEntry.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _IpAddrEntry_H_ -#define _IpAddrEntry_H_ - - -#include - -/* Including external dependencies */ -#include "IpAddress.h" -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* IpAddrEntry */ -typedef struct IpAddrEntry { - IpAddress_t ipAdEntAddr; - INTEGER_t ipAdEntIfIndex; - IpAddress_t ipAdEntNetMask; - INTEGER_t ipAdEntBcastAddr; - long ipAdEntReasmMaxSize; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} IpAddrEntry_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_IpAddrEntry; - -#ifdef __cplusplus -} -#endif - -#endif /* _IpAddrEntry_H_ */ diff --git a/stglibs/smux.lib/IpAddress.h b/stglibs/smux.lib/IpAddress.h deleted file mode 100644 index 06c1d4a3..00000000 --- a/stglibs/smux.lib/IpAddress.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _IpAddress_H_ -#define _IpAddress_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* IpAddress */ -typedef OCTET_STRING_t IpAddress_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_IpAddress; -asn_struct_free_f IpAddress_free; -asn_struct_print_f IpAddress_print; -asn_constr_check_f IpAddress_constraint; -ber_type_decoder_f IpAddress_decode_ber; -der_type_encoder_f IpAddress_encode_der; -xer_type_decoder_f IpAddress_decode_xer; -xer_type_encoder_f IpAddress_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _IpAddress_H_ */ diff --git a/stglibs/smux.lib/IpNetToMediaEntry.h b/stglibs/smux.lib/IpNetToMediaEntry.h deleted file mode 100644 index 1eb8124f..00000000 --- a/stglibs/smux.lib/IpNetToMediaEntry.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _IpNetToMediaEntry_H_ -#define _IpNetToMediaEntry_H_ - - -#include - -/* Including external dependencies */ -#include -#include "PhysAddress.h" -#include "IpAddress.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* IpNetToMediaEntry */ -typedef struct IpNetToMediaEntry { - INTEGER_t ipNetToMediaIfIndex; - PhysAddress_t ipNetToMediaPhysAddress; - IpAddress_t ipNetToMediaNetAddress; - INTEGER_t ipNetToMediaType; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} IpNetToMediaEntry_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_IpNetToMediaEntry; - -#ifdef __cplusplus -} -#endif - -#endif /* _IpNetToMediaEntry_H_ */ diff --git a/stglibs/smux.lib/IpRouteEntry.h b/stglibs/smux.lib/IpRouteEntry.h deleted file mode 100644 index 5651a8fc..00000000 --- a/stglibs/smux.lib/IpRouteEntry.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _IpRouteEntry_H_ -#define _IpRouteEntry_H_ - - -#include - -/* Including external dependencies */ -#include "IpAddress.h" -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* IpRouteEntry */ -typedef struct IpRouteEntry { - IpAddress_t ipRouteDest; - INTEGER_t ipRouteIfIndex; - INTEGER_t ipRouteMetric1; - INTEGER_t ipRouteMetric2; - INTEGER_t ipRouteMetric3; - INTEGER_t ipRouteMetric4; - IpAddress_t ipRouteNextHop; - INTEGER_t ipRouteType; - INTEGER_t ipRouteProto; - INTEGER_t ipRouteAge; - IpAddress_t ipRouteMask; - INTEGER_t ipRouteMetric5; - OBJECT_IDENTIFIER_t ipRouteInfo; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} IpRouteEntry_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_IpRouteEntry; - -#ifdef __cplusplus -} -#endif - -#endif /* _IpRouteEntry_H_ */ diff --git a/stglibs/smux.lib/Message.h b/stglibs/smux.lib/Message.h deleted file mode 100644 index 2621d73c..00000000 --- a/stglibs/smux.lib/Message.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _Message_H_ -#define _Message_H_ - - -#include - -/* Including external dependencies */ -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum Message__version { - Message__version_version_1 = 0 -} e_Message__version; - -/* Message */ -typedef struct Message { - INTEGER_t version; - OCTET_STRING_t community; - ANY_t data; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} Message_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_Message; - -#ifdef __cplusplus -} -#endif - -#endif /* _Message_H_ */ diff --git a/stglibs/smux.lib/NULL.h b/stglibs/smux.lib/NULL.h deleted file mode 100644 index 131e7759..00000000 --- a/stglibs/smux.lib/NULL.h +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * Copyright (c) 2003 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_TYPE_NULL_H -#define ASN_TYPE_NULL_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * The value of the NULL type is meaningless: see BOOLEAN if you want to - * carry true/false semantics. - */ -typedef int NULL_t; - -extern asn_TYPE_descriptor_t asn_DEF_NULL; - -asn_struct_print_f NULL_print; -der_type_encoder_f NULL_encode_der; -xer_type_decoder_f NULL_decode_xer; -xer_type_encoder_f NULL_encode_xer; -per_type_decoder_f NULL_decode_uper; -per_type_encoder_f NULL_encode_uper; - -#ifdef __cplusplus -} -#endif - -#endif /* NULL_H */ diff --git a/stglibs/smux.lib/NativeEnumerated.h b/stglibs/smux.lib/NativeEnumerated.h deleted file mode 100644 index c59bb1ba..00000000 --- a/stglibs/smux.lib/NativeEnumerated.h +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * Copyright (c) 2004, 2005, 2006 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -/* - * This type differs from the standard ENUMERATED in that it is modelled using - * the fixed machine type (long, int, short), so it can hold only values of - * limited length. There is no type (i.e., NativeEnumerated_t, any integer type - * will do). - * This type may be used when integer range is limited by subtype constraints. - */ -#ifndef _NativeEnumerated_H_ -#define _NativeEnumerated_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern asn_TYPE_descriptor_t asn_DEF_NativeEnumerated; - -xer_type_encoder_f NativeEnumerated_encode_xer; -per_type_decoder_f NativeEnumerated_decode_uper; -per_type_encoder_f NativeEnumerated_encode_uper; - -#ifdef __cplusplus -} -#endif - -#endif /* _NativeEnumerated_H_ */ diff --git a/stglibs/smux.lib/NativeInteger.h b/stglibs/smux.lib/NativeInteger.h deleted file mode 100644 index 4e63a835..00000000 --- a/stglibs/smux.lib/NativeInteger.h +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * Copyright (c) 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -/* - * This type differs from the standard INTEGER in that it is modelled using - * the fixed machine type (long, int, short), so it can hold only values of - * limited length. There is no type (i.e., NativeInteger_t, any integer type - * will do). - * This type may be used when integer range is limited by subtype constraints. - */ -#ifndef _NativeInteger_H_ -#define _NativeInteger_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern asn_TYPE_descriptor_t asn_DEF_NativeInteger; - -asn_struct_free_f NativeInteger_free; -asn_struct_print_f NativeInteger_print; -ber_type_decoder_f NativeInteger_decode_ber; -der_type_encoder_f NativeInteger_encode_der; -xer_type_decoder_f NativeInteger_decode_xer; -xer_type_encoder_f NativeInteger_encode_xer; -per_type_decoder_f NativeInteger_decode_uper; -per_type_encoder_f NativeInteger_encode_uper; - -#ifdef __cplusplus -} -#endif - -#endif /* _NativeInteger_H_ */ diff --git a/stglibs/smux.lib/NetworkAddress.h b/stglibs/smux.lib/NetworkAddress.h deleted file mode 100644 index 8c73220b..00000000 --- a/stglibs/smux.lib/NetworkAddress.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _NetworkAddress_H_ -#define _NetworkAddress_H_ - - -#include - -/* Including external dependencies */ -#include "IpAddress.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum NetworkAddress_PR { - NetworkAddress_PR_NOTHING, /* No components present */ - NetworkAddress_PR_internet -} NetworkAddress_PR; - -/* NetworkAddress */ -typedef struct NetworkAddress { - NetworkAddress_PR present; - union NetworkAddress_u { - IpAddress_t internet; - } choice; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} NetworkAddress_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_NetworkAddress; - -#ifdef __cplusplus -} -#endif - -#endif /* _NetworkAddress_H_ */ diff --git a/stglibs/smux.lib/OBJECT_IDENTIFIER.h b/stglibs/smux.lib/OBJECT_IDENTIFIER.h deleted file mode 100644 index 2bb5d032..00000000 --- a/stglibs/smux.lib/OBJECT_IDENTIFIER.h +++ /dev/null @@ -1,139 +0,0 @@ -/*- - * Copyright (c) 2003, 2004, 2005 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _OBJECT_IDENTIFIER_H_ -#define _OBJECT_IDENTIFIER_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t; - -extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER; - -asn_struct_print_f OBJECT_IDENTIFIER_print; -asn_constr_check_f OBJECT_IDENTIFIER_constraint; -der_type_encoder_f OBJECT_IDENTIFIER_encode_der; -xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer; -xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer; - -/********************************** - * Some handy conversion routines * - **********************************/ - -/* - * This function fills an (_arcs) array with OBJECT IDENTIFIER arcs - * up to specified (_arc_slots) elements. - * - * EXAMPLE: - * void print_arcs(OBJECT_IDENTIFIER_t *oid) { - * unsigned long fixed_arcs[10]; // Try with fixed space first - * unsigned long *arcs = fixed_arcs; - * int arc_type_size = sizeof(fixed_arcs[0]); // sizeof(long) - * int arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10 - * int count; // Real number of arcs. - * int i; - * - * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, - * arc_type_size, arc_slots); - * // If necessary, reallocate arcs array and try again. - * if(count > arc_slots) { - * arc_slots = count; - * arcs = malloc(arc_type_size * arc_slots); - * if(!arcs) return; - * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, - * arc_type_size, arc_slots); - * assert(count == arc_slots); - * } - * - * // Print the contents of the arcs array. - * for(i = 0; i < count; i++) - * printf("%d\n", arcs[i]); - * - * // Avoid memory leak. - * if(arcs != fixed_arcs) free(arcs); - * } - * - * RETURN VALUES: - * -1/EINVAL: Invalid arguments (oid is missing) - * -1/ERANGE: One or more arcs have value out of array cell type range. - * >=0: Number of arcs contained in the OBJECT IDENTIFIER - * - * WARNING: The function always returns the real number of arcs, - * even if there is no sufficient (_arc_slots) provided. - */ -int OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *_oid, - void *_arcs, /* e.g., unsigned int arcs[N] */ - unsigned int _arc_type_size, /* e.g., sizeof(arcs[0]) */ - unsigned int _arc_slots /* e.g., N */); - -/* - * This functions initializes the OBJECT IDENTIFIER object with - * the given set of arcs. - * The minimum of two arcs must be present; some restrictions apply. - * RETURN VALUES: - * -1/EINVAL: Invalid arguments - * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions. - * -1/ENOMEM: Memory allocation failed - * 0: The object was initialized with new arcs. - */ -int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *_oid, - const void *_arcs, /* e.g., unsigned int arcs[N] */ - unsigned int _arc_type_size, /* e.g., sizeof(arcs[0]) */ - unsigned int _arc_slots /* e.g., N */); - -/* - * Print the specified OBJECT IDENTIFIER arc. - */ -int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, - int add, /* Arbitrary offset, required to process the first two arcs */ - asn_app_consume_bytes_f *cb, void *app_key); - -/* Same as above, but returns the number of written digits, instead of 0 */ -ssize_t OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add, - asn_app_consume_bytes_f *cb, void *app_key); - -/* - * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363"). - * No arc can exceed the (0..signed_long_max) range (typically, 0..2G if L32). - * This function is not specific to OBJECT IDENTIFIER, it may be used to parse - * the RELATIVE-OID data, or any other data consisting of dot-separated - * series of numeric values. - * - * If (oid_txt_length == -1), the strlen() will be invoked to determine the - * size of the (oid_text) string. - * - * After return, the optional (opt_oid_text_end) is set to the character after - * the last parsed one. (opt_oid_text_end) is never less than (oid_text). - * - * RETURN VALUES: - * -1: Parse error. - * >= 0: Number of arcs contained in the OBJECT IDENTIFIER. - * - * WARNING: The function always returns the real number of arcs, - * even if there is no sufficient (_arc_slots) provided. - * This is useful for (_arc_slots) value estimation. - */ -int OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length, - long arcs[], unsigned int arcs_slots, const char **opt_oid_text_end); - -/* - * Internal functions. - * Used by RELATIVE-OID implementation in particular. - */ -int OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, - signed int add, void *value, unsigned int value_size); -int OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, - const void *arcval, unsigned int arcval_size, int _prepared_order); - -#ifdef __cplusplus -} -#endif - -#endif /* _OBJECT_IDENTIFIER_H_ */ diff --git a/stglibs/smux.lib/OCTET_STRING.h b/stglibs/smux.lib/OCTET_STRING.h deleted file mode 100644 index 5150161a..00000000 --- a/stglibs/smux.lib/OCTET_STRING.h +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * Copyright (c) 2003 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _OCTET_STRING_H_ -#define _OCTET_STRING_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct OCTET_STRING { - uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */ - int size; /* Size of the buffer */ - - asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */ -} OCTET_STRING_t; - -extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING; - -asn_struct_free_f OCTET_STRING_free; -asn_struct_print_f OCTET_STRING_print; -asn_struct_print_f OCTET_STRING_print_utf8; -ber_type_decoder_f OCTET_STRING_decode_ber; -der_type_encoder_f OCTET_STRING_encode_der; -xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */ -xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */ -xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */ -xer_type_encoder_f OCTET_STRING_encode_xer; -xer_type_encoder_f OCTET_STRING_encode_xer_utf8; -per_type_decoder_f OCTET_STRING_decode_uper; -per_type_encoder_f OCTET_STRING_encode_uper; - -/****************************** - * Handy conversion routines. * - ******************************/ - -/* - * This function clears the previous value of the OCTET STRING (if any) - * and then allocates a new memory with the specified content (str/size). - * If size = -1, the size of the original string will be determined - * using strlen(str). - * If str equals to NULL, the function will silently clear the - * current contents of the OCTET STRING. - * Returns 0 if it was possible to perform operation, -1 otherwise. - */ -int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size); - -/* Handy conversion from the C string into the OCTET STRING. */ -#define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1) - -/* - * Allocate and fill the new OCTET STRING and return a pointer to the newly - * allocated object. NULL is permitted in str: the function will just allocate - * empty OCTET STRING. - */ -OCTET_STRING_t *OCTET_STRING_new_fromBuf(asn_TYPE_descriptor_t *td, - const char *str, int size); - -/**************************** - * Internally useful stuff. * - ****************************/ - -typedef struct asn_OCTET_STRING_specifics_s { - /* - * Target structure description. - */ - int struct_size; /* Size of the structure */ - int ctx_offset; /* Offset of the asn_struct_ctx_t member */ - - int subvariant; /* {0,1,2} for O-S, BIT STRING or ANY */ -} asn_OCTET_STRING_specifics_t; - -#ifdef __cplusplus -} -#endif - -#endif /* _OCTET_STRING_H_ */ diff --git a/stglibs/smux.lib/ObjectName.h b/stglibs/smux.lib/ObjectName.h deleted file mode 100644 index 256577b3..00000000 --- a/stglibs/smux.lib/ObjectName.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _ObjectName_H_ -#define _ObjectName_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* ObjectName */ -typedef OBJECT_IDENTIFIER_t ObjectName_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_ObjectName; -asn_struct_free_f ObjectName_free; -asn_struct_print_f ObjectName_print; -asn_constr_check_f ObjectName_constraint; -ber_type_decoder_f ObjectName_decode_ber; -der_type_encoder_f ObjectName_encode_der; -xer_type_decoder_f ObjectName_decode_xer; -xer_type_encoder_f ObjectName_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _ObjectName_H_ */ diff --git a/stglibs/smux.lib/ObjectSyntax.h b/stglibs/smux.lib/ObjectSyntax.h deleted file mode 100644 index 9030accb..00000000 --- a/stglibs/smux.lib/ObjectSyntax.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _ObjectSyntax_H_ -#define _ObjectSyntax_H_ - - -#include - -/* Including external dependencies */ -#include "SimpleSyntax.h" -#include "ApplicationSyntax.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum ObjectSyntax_PR { - ObjectSyntax_PR_NOTHING, /* No components present */ - ObjectSyntax_PR_simple, - ObjectSyntax_PR_application_wide -} ObjectSyntax_PR; - -/* ObjectSyntax */ -typedef struct ObjectSyntax { - ObjectSyntax_PR present; - union ObjectSyntax_u { - SimpleSyntax_t simple; - ApplicationSyntax_t application_wide; - } choice; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} ObjectSyntax_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_ObjectSyntax; - -#ifdef __cplusplus -} -#endif - -#endif /* _ObjectSyntax_H_ */ diff --git a/stglibs/smux.lib/Opaque.h b/stglibs/smux.lib/Opaque.h deleted file mode 100644 index aa8e2d5f..00000000 --- a/stglibs/smux.lib/Opaque.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _Opaque_H_ -#define _Opaque_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Opaque */ -typedef OCTET_STRING_t Opaque_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_Opaque; -asn_struct_free_f Opaque_free; -asn_struct_print_f Opaque_print; -asn_constr_check_f Opaque_constraint; -ber_type_decoder_f Opaque_decode_ber; -der_type_encoder_f Opaque_encode_der; -xer_type_decoder_f Opaque_decode_xer; -xer_type_encoder_f Opaque_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _Opaque_H_ */ diff --git a/stglibs/smux.lib/OpenPDU.h b/stglibs/smux.lib/OpenPDU.h deleted file mode 100644 index 5d7e1da6..00000000 --- a/stglibs/smux.lib/OpenPDU.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "SMUX" - * found in "SMUX.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _OpenPDU_H_ -#define _OpenPDU_H_ - - -#include - -/* Including external dependencies */ -#include "SimpleOpen.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum OpenPDU_PR { - OpenPDU_PR_NOTHING, /* No components present */ - OpenPDU_PR_simple -} OpenPDU_PR; - -/* OpenPDU */ -typedef struct OpenPDU { - OpenPDU_PR present; - union OpenPDU_u { - SimpleOpen_t simple; - } choice; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} OpenPDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_OpenPDU; - -#ifdef __cplusplus -} -#endif - -#endif /* _OpenPDU_H_ */ diff --git a/stglibs/smux.lib/PDU.h b/stglibs/smux.lib/PDU.h deleted file mode 100644 index cbc7e714..00000000 --- a/stglibs/smux.lib/PDU.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _PDU_H_ -#define _PDU_H_ - - -#include - -/* Including external dependencies */ -#include -#include "VarBindList.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum PDU__error_status { - PDU__error_status_noError = 0, - PDU__error_status_tooBig = 1, - PDU__error_status_noSuchName = 2, - PDU__error_status_badValue = 3, - PDU__error_status_readOnly = 4, - PDU__error_status_genErr = 5 -} e_PDU__error_status; - -/* PDU */ -typedef struct PDU { - INTEGER_t request_id; - INTEGER_t error_status; - INTEGER_t error_index; - VarBindList_t variable_bindings; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} PDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_PDU; - -#ifdef __cplusplus -} -#endif - -#endif /* _PDU_H_ */ diff --git a/stglibs/smux.lib/PDUs.h b/stglibs/smux.lib/PDUs.h deleted file mode 100644 index 90bb089f..00000000 --- a/stglibs/smux.lib/PDUs.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _PDUs_H_ -#define _PDUs_H_ - - -#include - -/* Including external dependencies */ -#include "GetRequest-PDU.h" -#include "GetNextRequest-PDU.h" -#include "GetResponse-PDU.h" -#include "SetRequest-PDU.h" -#include "Trap-PDU.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum PDUs_PR { - PDUs_PR_NOTHING, /* No components present */ - PDUs_PR_get_request, - PDUs_PR_get_next_request, - PDUs_PR_get_response, - PDUs_PR_set_request, - PDUs_PR_trap -} PDUs_PR; - -/* PDUs */ -typedef struct PDUs { - PDUs_PR present; - union PDUs_u { - GetRequest_PDU_t get_request; - GetNextRequest_PDU_t get_next_request; - GetResponse_PDU_t get_response; - SetRequest_PDU_t set_request; - Trap_PDU_t trap; - } choice; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} PDUs_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_PDUs; - -#ifdef __cplusplus -} -#endif - -#endif /* _PDUs_H_ */ diff --git a/stglibs/smux.lib/PhysAddress.h b/stglibs/smux.lib/PhysAddress.h deleted file mode 100644 index d6c5fa17..00000000 --- a/stglibs/smux.lib/PhysAddress.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _PhysAddress_H_ -#define _PhysAddress_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* PhysAddress */ -typedef OCTET_STRING_t PhysAddress_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_PhysAddress; -asn_struct_free_f PhysAddress_free; -asn_struct_print_f PhysAddress_print; -asn_constr_check_f PhysAddress_constraint; -ber_type_decoder_f PhysAddress_decode_ber; -der_type_encoder_f PhysAddress_encode_der; -xer_type_decoder_f PhysAddress_decode_xer; -xer_type_encoder_f PhysAddress_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _PhysAddress_H_ */ diff --git a/stglibs/smux.lib/RReqPDU.h b/stglibs/smux.lib/RReqPDU.h deleted file mode 100644 index 17f53094..00000000 --- a/stglibs/smux.lib/RReqPDU.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "SMUX" - * found in "SMUX.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _RReqPDU_H_ -#define _RReqPDU_H_ - - -#include - -/* Including external dependencies */ -#include "ObjectName.h" -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum RReqPDU__operation { - RReqPDU__operation_delete = 0, - RReqPDU__operation_readOnly = 1, - RReqPDU__operation_readWrite = 2 -} e_RReqPDU__operation; - -/* RReqPDU */ -typedef struct RReqPDU { - ObjectName_t subtree; - long priority; - INTEGER_t operation; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} RReqPDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_RReqPDU; - -#ifdef __cplusplus -} -#endif - -#endif /* _RReqPDU_H_ */ diff --git a/stglibs/smux.lib/RRspPDU.h b/stglibs/smux.lib/RRspPDU.h deleted file mode 100644 index 0d9681ac..00000000 --- a/stglibs/smux.lib/RRspPDU.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "SMUX" - * found in "SMUX.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _RRspPDU_H_ -#define _RRspPDU_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum RRspPDU { - RRspPDU_failure = -1 -} e_RRspPDU; - -/* RRspPDU */ -typedef INTEGER_t RRspPDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_RRspPDU; -asn_struct_free_f RRspPDU_free; -asn_struct_print_f RRspPDU_print; -asn_constr_check_f RRspPDU_constraint; -ber_type_decoder_f RRspPDU_decode_ber; -der_type_encoder_f RRspPDU_encode_der; -xer_type_decoder_f RRspPDU_decode_xer; -xer_type_encoder_f RRspPDU_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _RRspPDU_H_ */ diff --git a/stglibs/smux.lib/SMUX-PDUs.h b/stglibs/smux.lib/SMUX-PDUs.h deleted file mode 100644 index 84893249..00000000 --- a/stglibs/smux.lib/SMUX-PDUs.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "SMUX" - * found in "SMUX.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _SMUX_PDUs_H_ -#define _SMUX_PDUs_H_ - - -#include - -/* Including external dependencies */ -#include "OpenPDU.h" -#include "ClosePDU.h" -#include "RReqPDU.h" -#include "RRspPDU.h" -#include "PDUs.h" -#include "SOutPDU.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum SMUX_PDUs_PR { - SMUX_PDUs_PR_NOTHING, /* No components present */ - SMUX_PDUs_PR_open, - SMUX_PDUs_PR_close, - SMUX_PDUs_PR_registerRequest, - SMUX_PDUs_PR_registerResponse, - SMUX_PDUs_PR_pdus, - SMUX_PDUs_PR_commitOrRollback -} SMUX_PDUs_PR; - -/* SMUX-PDUs */ -typedef struct SMUX_PDUs { - SMUX_PDUs_PR present; - union SMUX_PDUs_u { - OpenPDU_t open; - ClosePDU_t close; - RReqPDU_t registerRequest; - RRspPDU_t registerResponse; - PDUs_t pdus; - SOutPDU_t commitOrRollback; - } choice; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} SMUX_PDUs_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_SMUX_PDUs; - -#ifdef __cplusplus -} -#endif - -#endif /* _SMUX_PDUs_H_ */ diff --git a/stglibs/smux.lib/SOutPDU.h b/stglibs/smux.lib/SOutPDU.h deleted file mode 100644 index 55e76185..00000000 --- a/stglibs/smux.lib/SOutPDU.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "SMUX" - * found in "SMUX.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _SOutPDU_H_ -#define _SOutPDU_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum SOutPDU { - SOutPDU_commit = 0, - SOutPDU_rollback = 1 -} e_SOutPDU; - -/* SOutPDU */ -typedef INTEGER_t SOutPDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_SOutPDU; -asn_struct_free_f SOutPDU_free; -asn_struct_print_f SOutPDU_print; -asn_constr_check_f SOutPDU_constraint; -ber_type_decoder_f SOutPDU_decode_ber; -der_type_encoder_f SOutPDU_encode_der; -xer_type_decoder_f SOutPDU_decode_xer; -xer_type_encoder_f SOutPDU_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _SOutPDU_H_ */ diff --git a/stglibs/smux.lib/SetRequest-PDU.h b/stglibs/smux.lib/SetRequest-PDU.h deleted file mode 100644 index 8854574c..00000000 --- a/stglibs/smux.lib/SetRequest-PDU.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _SetRequest_PDU_H_ -#define _SetRequest_PDU_H_ - - -#include - -/* Including external dependencies */ -#include "PDU.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* SetRequest-PDU */ -typedef PDU_t SetRequest_PDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_SetRequest_PDU; -asn_struct_free_f SetRequest_PDU_free; -asn_struct_print_f SetRequest_PDU_print; -asn_constr_check_f SetRequest_PDU_constraint; -ber_type_decoder_f SetRequest_PDU_decode_ber; -der_type_encoder_f SetRequest_PDU_encode_der; -xer_type_decoder_f SetRequest_PDU_decode_xer; -xer_type_encoder_f SetRequest_PDU_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _SetRequest_PDU_H_ */ diff --git a/stglibs/smux.lib/SimpleOpen.h b/stglibs/smux.lib/SimpleOpen.h deleted file mode 100644 index 5950a6c1..00000000 --- a/stglibs/smux.lib/SimpleOpen.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "SMUX" - * found in "SMUX.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _SimpleOpen_H_ -#define _SimpleOpen_H_ - - -#include - -/* Including external dependencies */ -#include -#include -#include "DisplayString.h" -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum SimpleOpen__version { - SimpleOpen__version_version_1 = 0 -} e_SimpleOpen__version; - -/* SimpleOpen */ -typedef struct SimpleOpen { - INTEGER_t version; - OBJECT_IDENTIFIER_t identity; - DisplayString_t description; - OCTET_STRING_t password; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} SimpleOpen_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_SimpleOpen; - -#ifdef __cplusplus -} -#endif - -#endif /* _SimpleOpen_H_ */ diff --git a/stglibs/smux.lib/SimpleSyntax.h b/stglibs/smux.lib/SimpleSyntax.h deleted file mode 100644 index c04f3ab2..00000000 --- a/stglibs/smux.lib/SimpleSyntax.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _SimpleSyntax_H_ -#define _SimpleSyntax_H_ - - -#include - -/* Including external dependencies */ -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum SimpleSyntax_PR { - SimpleSyntax_PR_NOTHING, /* No components present */ - SimpleSyntax_PR_number, - SimpleSyntax_PR_string, - SimpleSyntax_PR_object, - SimpleSyntax_PR_empty -} SimpleSyntax_PR; - -/* SimpleSyntax */ -typedef struct SimpleSyntax { - SimpleSyntax_PR present; - union SimpleSyntax_u { - INTEGER_t number; - OCTET_STRING_t string; - OBJECT_IDENTIFIER_t object; - NULL_t empty; - } choice; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} SimpleSyntax_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_SimpleSyntax; - -#ifdef __cplusplus -} -#endif - -#endif /* _SimpleSyntax_H_ */ diff --git a/stglibs/smux.lib/TcpConnEntry.h b/stglibs/smux.lib/TcpConnEntry.h deleted file mode 100644 index 3160e31f..00000000 --- a/stglibs/smux.lib/TcpConnEntry.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _TcpConnEntry_H_ -#define _TcpConnEntry_H_ - - -#include - -/* Including external dependencies */ -#include -#include "IpAddress.h" -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* TcpConnEntry */ -typedef struct TcpConnEntry { - INTEGER_t tcpConnState; - IpAddress_t tcpConnLocalAddress; - long tcpConnLocalPort; - IpAddress_t tcpConnRemAddress; - long tcpConnRemPort; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} TcpConnEntry_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_TcpConnEntry; - -#ifdef __cplusplus -} -#endif - -#endif /* _TcpConnEntry_H_ */ diff --git a/stglibs/smux.lib/TimeTicks.h b/stglibs/smux.lib/TimeTicks.h deleted file mode 100644 index ea92820f..00000000 --- a/stglibs/smux.lib/TimeTicks.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1155-SMI" - * found in "RFC1155-SMI.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _TimeTicks_H_ -#define _TimeTicks_H_ - - -#include - -/* Including external dependencies */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* TimeTicks */ -typedef INTEGER_t TimeTicks_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_TimeTicks; -asn_struct_free_f TimeTicks_free; -asn_struct_print_f TimeTicks_print; -asn_constr_check_f TimeTicks_constraint; -ber_type_decoder_f TimeTicks_decode_ber; -der_type_encoder_f TimeTicks_encode_der; -xer_type_decoder_f TimeTicks_decode_xer; -xer_type_encoder_f TimeTicks_encode_xer; - -#ifdef __cplusplus -} -#endif - -#endif /* _TimeTicks_H_ */ diff --git a/stglibs/smux.lib/Trap-PDU.h b/stglibs/smux.lib/Trap-PDU.h deleted file mode 100644 index d8a89e11..00000000 --- a/stglibs/smux.lib/Trap-PDU.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _Trap_PDU_H_ -#define _Trap_PDU_H_ - - -#include - -/* Including external dependencies */ -#include -#include "NetworkAddress.h" -#include -#include "TimeTicks.h" -#include "VarBindList.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Dependencies */ -typedef enum Trap_PDU__generic_trap { - Trap_PDU__generic_trap_coldStart = 0, - Trap_PDU__generic_trap_warmStart = 1, - Trap_PDU__generic_trap_linkDown = 2, - Trap_PDU__generic_trap_linkUp = 3, - Trap_PDU__generic_trap_authenticationFailure = 4, - Trap_PDU__generic_trap_egpNeighborLoss = 5, - Trap_PDU__generic_trap_enterpriseSpecific = 6 -} e_Trap_PDU__generic_trap; - -/* Trap-PDU */ -typedef struct Trap_PDU { - OBJECT_IDENTIFIER_t enterprise; - NetworkAddress_t agent_addr; - INTEGER_t generic_trap; - INTEGER_t specific_trap; - TimeTicks_t time_stamp; - VarBindList_t variable_bindings; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} Trap_PDU_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_Trap_PDU; - -#ifdef __cplusplus -} -#endif - -#endif /* _Trap_PDU_H_ */ diff --git a/stglibs/smux.lib/UdpEntry.h b/stglibs/smux.lib/UdpEntry.h deleted file mode 100644 index e4a10264..00000000 --- a/stglibs/smux.lib/UdpEntry.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1213-MIB" - * found in "RFC1213-MIB.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _UdpEntry_H_ -#define _UdpEntry_H_ - - -#include - -/* Including external dependencies */ -#include "IpAddress.h" -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* UdpEntry */ -typedef struct UdpEntry { - IpAddress_t udpLocalAddress; - long udpLocalPort; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} UdpEntry_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_UdpEntry; - -#ifdef __cplusplus -} -#endif - -#endif /* _UdpEntry_H_ */ diff --git a/stglibs/smux.lib/VarBind.h b/stglibs/smux.lib/VarBind.h deleted file mode 100644 index 63ecad5f..00000000 --- a/stglibs/smux.lib/VarBind.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _VarBind_H_ -#define _VarBind_H_ - - -#include - -/* Including external dependencies */ -#include "ObjectName.h" -#include "ObjectSyntax.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* VarBind */ -typedef struct VarBind { - ObjectName_t name; - ObjectSyntax_t value; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} VarBind_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_VarBind; - -#ifdef __cplusplus -} -#endif - -#endif /* _VarBind_H_ */ diff --git a/stglibs/smux.lib/VarBindList.h b/stglibs/smux.lib/VarBindList.h deleted file mode 100644 index 36ef1617..00000000 --- a/stglibs/smux.lib/VarBindList.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) - * From ASN.1 module "RFC1157-SNMP" - * found in "RFC1157-SNMP.asn1" - * `asn1c -fskeletons-copy` - */ - -#ifndef _VarBindList_H_ -#define _VarBindList_H_ - - -#include - -/* Including external dependencies */ -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Forward declarations */ -struct VarBind; - -/* VarBindList */ -typedef struct VarBindList { - A_SEQUENCE_OF(struct VarBind) list; - - /* Context for parsing across buffer boundaries */ - asn_struct_ctx_t _asn_ctx; -} VarBindList_t; - -/* Implementation */ -extern asn_TYPE_descriptor_t asn_DEF_VarBindList; - -#ifdef __cplusplus -} -#endif - -/* Referred external types */ -#include "VarBind.h" - -#endif /* _VarBindList_H_ */ diff --git a/stglibs/smux.lib/asn_SEQUENCE_OF.h b/stglibs/smux.lib/asn_SEQUENCE_OF.h deleted file mode 100644 index e678f034..00000000 --- a/stglibs/smux.lib/asn_SEQUENCE_OF.h +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_SEQUENCE_OF_H -#define ASN_SEQUENCE_OF_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * SEQUENCE OF is the same as SET OF with a tiny difference: - * the delete operation preserves the initial order of elements - * and thus MAY operate in non-constant time. - */ -#define A_SEQUENCE_OF(type) A_SET_OF(type) - -#define ASN_SEQUENCE_ADD(headptr, ptr) \ - asn_sequence_add((headptr), (ptr)) - -/*********************************************** - * Implementation of the SEQUENCE OF structure. - */ - -#define asn_sequence_add asn_set_add -#define asn_sequence_empty asn_set_empty - -/* - * Delete the element from the set by its number (base 0). - * This is NOT a constant-time operation. - * The order of elements is preserved. - * If _do_free is given AND the (*free) is initialized, the element - * will be freed using the custom (*free) function as well. - */ -void asn_sequence_del(void *asn_sequence_of_x, int number, int _do_free); - -/* - * Cope with different conversions requirements to/from void in C and C++. - * This is mostly useful for support library. - */ -typedef A_SEQUENCE_OF(void) asn_anonymous_sequence_; -#define _A_SEQUENCE_FROM_VOID(ptr) ((asn_anonymous_sequence_ *)(ptr)) -#define _A_CSEQUENCE_FROM_VOID(ptr) ((const asn_anonymous_sequence_ *)(ptr)) - -#ifdef __cplusplus -} -#endif - -#endif /* ASN_SEQUENCE_OF_H */ diff --git a/stglibs/smux.lib/asn_SET_OF.h b/stglibs/smux.lib/asn_SET_OF.h deleted file mode 100644 index 7edf14b5..00000000 --- a/stglibs/smux.lib/asn_SET_OF.h +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_SET_OF_H -#define ASN_SET_OF_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define A_SET_OF(type) \ - struct { \ - type **array; \ - int count; /* Meaningful size */ \ - int size; /* Allocated size */ \ - void (*free)(type *); \ - } - -#define ASN_SET_ADD(headptr, ptr) \ - asn_set_add((headptr), (ptr)) - -/******************************************* - * Implementation of the SET OF structure. - */ - -/* - * Add another structure into the set by its pointer. - * RETURN VALUES: - * 0 for success and -1/errno for failure. - */ -int asn_set_add(void *asn_set_of_x, void *ptr); - -/* - * Delete the element from the set by its number (base 0). - * This is a constant-time operation. The order of elements before the - * deleted ones is guaranteed, the order of elements after the deleted - * one is NOT guaranteed. - * If _do_free is given AND the (*free) is initialized, the element - * will be freed using the custom (*free) function as well. - */ -void asn_set_del(void *asn_set_of_x, int number, int _do_free); - -/* - * Empty the contents of the set. Will free the elements, if (*free) is given. - * Will NOT free the set itself. - */ -void asn_set_empty(void *asn_set_of_x); - -/* - * Cope with different conversions requirements to/from void in C and C++. - * This is mostly useful for support library. - */ -typedef A_SET_OF(void) asn_anonymous_set_; -#define _A_SET_FROM_VOID(ptr) ((asn_anonymous_set_ *)(ptr)) -#define _A_CSET_FROM_VOID(ptr) ((const asn_anonymous_set_ *)(ptr)) - -#ifdef __cplusplus -} -#endif - -#endif /* ASN_SET_OF_H */ diff --git a/stglibs/smux.lib/asn_application.h b/stglibs/smux.lib/asn_application.h deleted file mode 100644 index f40cd86a..00000000 --- a/stglibs/smux.lib/asn_application.h +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (c) 2004, 2006 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -/* - * Application-level ASN.1 callbacks. - */ -#ifndef _ASN_APPLICATION_H_ -#define _ASN_APPLICATION_H_ - -#include "asn_system.h" /* for platform-dependent types */ -#include "asn_codecs.h" /* for ASN.1 codecs specifics */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Generic type of an application-defined callback to return various - * types of data to the application. - * EXPECTED RETURN VALUES: - * -1: Failed to consume bytes. Abort the mission. - * Non-negative return values indicate success, and ignored. - */ -typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size, - void *application_specific_key); - -/* - * A callback of this type is called whenever constraint validation fails - * on some ASN.1 type. See "constraints.h" for more details on constraint - * validation. - * This callback specifies a descriptor of the ASN.1 type which failed - * the constraint check, as well as human readable message on what - * particular constraint has failed. - */ -typedef void (asn_app_constraint_failed_f)(void *application_specific_key, - struct asn_TYPE_descriptor_s *type_descriptor_which_failed, - const void *structure_which_failed_ptr, - const char *error_message_format, ...) GCC_PRINTFLIKE(4, 5); - -#ifdef __cplusplus -} -#endif - -#include "constr_TYPE.h" /* for asn_TYPE_descriptor_t */ - -#endif /* _ASN_APPLICATION_H_ */ diff --git a/stglibs/smux.lib/asn_codecs.h b/stglibs/smux.lib/asn_codecs.h deleted file mode 100644 index 4a251d94..00000000 --- a/stglibs/smux.lib/asn_codecs.h +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * Copyright (c) 2003, 2004, 2005 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _ASN_CODECS_H_ -#define _ASN_CODECS_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* - * This structure defines a set of parameters that may be passed - * to every ASN.1 encoder or decoder function. - * WARNING: if max_stack_size member is set, and you are calling the - * function pointers of the asn_TYPE_descriptor_t directly, - * this structure must be ALLOCATED ON THE STACK! - * If you can't always satisfy this requirement, use ber_decode(), - * xer_decode() and uper_decode() functions instead. - */ -typedef struct asn_codec_ctx_s { - /* - * Limit the decoder routines to use no (much) more stack than a given - * number of bytes. Most of decoders are stack-based, and this - * would protect against stack overflows if the number of nested - * encodings is high. - * The OCTET STRING, BIT STRING and ANY BER decoders are heap-based, - * and are safe from this kind of overflow. - * A value from getrlimit(RLIMIT_STACK) may be used to initialize - * this variable. Be careful in multithreaded environments, as the - * stack size is rather limited. - */ - size_t max_stack_size; /* 0 disables stack bounds checking */ -} asn_codec_ctx_t; - -/* - * Type of the return value of the encoding functions (der_encode, xer_encode). - */ -typedef struct asn_enc_rval_s { - /* - * Number of bytes encoded. - * -1 indicates failure to encode the structure. - * In this case, the members below this one are meaningful. - */ - ssize_t encoded; - - /* - * Members meaningful when (encoded == -1), for post mortem analysis. - */ - - /* Type which cannot be encoded */ - struct asn_TYPE_descriptor_s *failed_type; - - /* Pointer to the structure of that type */ - void *structure_ptr; -} asn_enc_rval_t; -#define _ASN_ENCODE_FAILED do { \ - asn_enc_rval_t tmp_error; \ - tmp_error.encoded = -1; \ - tmp_error.failed_type = td; \ - tmp_error.structure_ptr = sptr; \ - ASN_DEBUG("Failed to encode element %s", td->name); \ - return tmp_error; \ -} while(0) -#define _ASN_ENCODED_OK(rval) do { \ - rval.structure_ptr = 0; \ - rval.failed_type = 0; \ - return rval; \ -} while(0) - -/* - * Type of the return value of the decoding functions (ber_decode, xer_decode) - * - * Please note that the number of consumed bytes is ALWAYS meaningful, - * even if code==RC_FAIL. This is to indicate the number of successfully - * decoded bytes, hence providing a possibility to fail with more diagnostics - * (i.e., print the offending remainder of the buffer). - */ -enum asn_dec_rval_code_e { - RC_OK, /* Decoded successfully */ - RC_WMORE, /* More data expected, call again */ - RC_FAIL /* Failure to decode data */ -}; -typedef struct asn_dec_rval_s { - enum asn_dec_rval_code_e code; /* Result code */ - size_t consumed; /* Number of bytes consumed */ -} asn_dec_rval_t; -#define _ASN_DECODE_FAILED do { \ - asn_dec_rval_t tmp_error; \ - tmp_error.code = RC_FAIL; \ - tmp_error.consumed = 0; \ - ASN_DEBUG("Failed to decode element %s", td->name); \ - return tmp_error; \ -} while(0) -#define _ASN_DECODE_STARVED do { \ - asn_dec_rval_t tmp_error; \ - tmp_error.code = RC_WMORE; \ - tmp_error.consumed = 0; \ - return tmp_error; \ -} while(0) - -#ifdef __cplusplus -} -#endif - -#endif /* _ASN_CODECS_H_ */ diff --git a/stglibs/smux.lib/asn_codecs_prim.h b/stglibs/smux.lib/asn_codecs_prim.h deleted file mode 100644 index 0f683fdd..00000000 --- a/stglibs/smux.lib/asn_codecs_prim.h +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * Copyright (c) 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef ASN_CODECS_PRIM_H -#define ASN_CODECS_PRIM_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct ASN__PRIMITIVE_TYPE_s { - uint8_t *buf; /* Buffer with consecutive primitive encoding bytes */ - int size; /* Size of the buffer */ -} ASN__PRIMITIVE_TYPE_t; /* Do not use this type directly! */ - -asn_struct_free_f ASN__PRIMITIVE_TYPE_free; -ber_type_decoder_f ber_decode_primitive; -der_type_encoder_f der_encode_primitive; - -/* - * A callback specification for the xer_decode_primitive() function below. - */ -enum xer_pbd_rval { - XPBD_SYSTEM_FAILURE, /* System failure (memory shortage, etc) */ - XPBD_DECODER_LIMIT, /* Hit some decoder limitation or deficiency */ - XPBD_BROKEN_ENCODING, /* Encoding of a primitive body is broken */ - XPBD_NOT_BODY_IGNORE, /* Not a body format, but safe to ignore */ - XPBD_BODY_CONSUMED /* Body is recognized and consumed */ -}; -typedef enum xer_pbd_rval (xer_primitive_body_decoder_f) - (asn_TYPE_descriptor_t *td, void *struct_ptr, - const void *chunk_buf, size_t chunk_size); - -/* - * Specific function to decode simple primitive types. - * Also see xer_decode_general() in xer_decoder.h - */ -asn_dec_rval_t xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx, - asn_TYPE_descriptor_t *type_descriptor, - void **struct_ptr, size_t struct_size, - const char *opt_mname, - const void *buf_ptr, size_t size, - xer_primitive_body_decoder_f *prim_body_decoder -); - -#ifdef __cplusplus -} -#endif - -#endif /* ASN_CODECS_PRIM_H */ diff --git a/stglibs/smux.lib/asn_internal.h b/stglibs/smux.lib/asn_internal.h deleted file mode 100644 index 67f055a6..00000000 --- a/stglibs/smux.lib/asn_internal.h +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * Copyright (c) 2003, 2004, 2005 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -/* - * Declarations internally useful for the ASN.1 support code. - */ -#ifndef _ASN_INTERNAL_H_ -#define _ASN_INTERNAL_H_ - -#include "asn_application.h" /* Application-visible API */ - -#ifndef __NO_ASSERT_H__ /* Include assert.h only for internal use. */ -#include /* for assert() macro */ -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* Environment version might be used to avoid running with the old library */ -#define ASN1C_ENVIRONMENT_VERSION 920 /* Compile-time version */ -int get_asn1c_environment_version(void); /* Run-time version */ - -#define CALLOC(nmemb, size) calloc(nmemb, size) -#define MALLOC(size) malloc(size) -#define REALLOC(oldptr, size) realloc(oldptr, size) -#define FREEMEM(ptr) free(ptr) - -/* - * A macro for debugging the ASN.1 internals. - * You may enable or override it. - */ -#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */ -#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */ -#ifdef __GNUC__ -#define ASN_DEBUG(fmt, args...) do { \ - fprintf(stderr, fmt, ##args); \ - fprintf(stderr, " (%s:%d)\n", \ - __FILE__, __LINE__); \ - } while(0) -#else /* !__GNUC__ */ -void ASN_DEBUG_f(const char *fmt, ...); -#define ASN_DEBUG ASN_DEBUG_f -#endif /* __GNUC__ */ -#else /* EMIT_ASN_DEBUG != 1 */ -static inline void ASN_DEBUG(const char *fmt, ...) { (void)fmt; } -#endif /* EMIT_ASN_DEBUG */ -#endif /* ASN_DEBUG */ - -/* - * Invoke the application-supplied callback and fail, if something is wrong. - */ -#define __ASN_E_cbc(buf, size) (cb((buf), (size), app_key) < 0) -#define _ASN_E_CALLBACK(foo) do { \ - if(foo) goto cb_failed; \ - } while(0) -#define _ASN_CALLBACK(buf, size) \ - _ASN_E_CALLBACK(__ASN_E_cbc(buf, size)) -#define _ASN_CALLBACK2(buf1, size1, buf2, size2) \ - _ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) || __ASN_E_cbc(buf2, size2)) -#define _ASN_CALLBACK3(buf1, size1, buf2, size2, buf3, size3) \ - _ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) \ - || __ASN_E_cbc(buf2, size2) \ - || __ASN_E_cbc(buf3, size3)) - -#define _i_ASN_TEXT_INDENT(nl, level) do { \ - int __level = (level); \ - int __nl = ((nl) != 0); \ - int __i; \ - if(__nl) _ASN_CALLBACK("\n", 1); \ - for(__i = 0; __i < __level; __i++) \ - _ASN_CALLBACK(" ", 4); \ - er.encoded += __nl + 4 * __level; \ -} while(0) - -#define _i_INDENT(nl) do { \ - int __i; \ - if((nl) && cb("\n", 1, app_key) < 0) return -1; \ - for(__i = 0; __i < ilevel; __i++) \ - if(cb(" ", 4, app_key) < 0) return -1; \ -} while(0) - -/* - * Check stack against overflow, if limit is set. - */ -#define _ASN_DEFAULT_STACK_MAX (30000) -static inline int -_ASN_STACK_OVERFLOW_CHECK(asn_codec_ctx_t *ctx) { - if(ctx && ctx->max_stack_size) { - - /* ctx MUST be allocated on the stack */ - ptrdiff_t usedstack = ((char *)ctx - (char *)&ctx); - if(usedstack > 0) usedstack = -usedstack; /* grows up! */ - - /* double negative required to avoid int wrap-around */ - if(usedstack < -(ptrdiff_t)ctx->max_stack_size) { - ASN_DEBUG("Stack limit %ld reached", - (long)ctx->max_stack_size); - return -1; - } - } - return 0; -} - -#ifdef __cplusplus -} -#endif - -#endif /* _ASN_INTERNAL_H_ */ diff --git a/stglibs/smux.lib/asn_system.h b/stglibs/smux.lib/asn_system.h deleted file mode 100644 index d7ebdaa4..00000000 --- a/stglibs/smux.lib/asn_system.h +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -/* - * Miscellaneous system-dependent types. - */ -#ifndef _ASN_SYSTEM_H_ -#define _ASN_SYSTEM_H_ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* For snprintf(3) */ -#include /* For *alloc(3) */ -#include /* For memcpy(3) */ -#include /* For size_t */ -#include /* For va_start */ -#include /* for offsetof and ptrdiff_t */ - -#ifdef WIN32 - -#include -#include -#define snprintf _snprintf -#define vsnprintf _vsnprintf - -#ifdef _MSC_VER /* MSVS.Net */ -#ifndef __cplusplus -#define inline __inline -#endif -#define ssize_t SSIZE_T -typedef char int8_t; -typedef short int16_t; -typedef int int32_t; -typedef unsigned char uint8_t; -typedef unsigned short uint16_t; -typedef unsigned int uint32_t; -#define WIN32_LEAN_AND_MEAN -#include -#include -#define isnan _isnan -#define finite _finite -#define copysign _copysign -#define ilogb _logb -#endif /* _MSC_VER */ - -#else /* !WIN32 */ - -#if defined(__vxworks) -#include -#else /* !defined(__vxworks) */ - -#include /* C99 specifies this file */ -/* - * 1. Earlier FreeBSD version didn't have , - * but was present. - * 2. Sun Solaris requires for alloca(3), - * but does not have . - */ -#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_)) -#if defined(sun) -#include /* For alloca(3) */ -#include /* for finite(3) */ -#elif defined(__hpux) -#ifdef __GNUC__ -#include /* For alloca(3) */ -#else /* !__GNUC__ */ -#define inline -#endif /* __GNUC__ */ -#else -#include /* SUSv2+ and C99 specify this file, for uintXX_t */ -#endif /* defined(sun) */ -#endif - -#endif /* defined(__vxworks) */ - -#endif /* WIN32 */ - -#if __GNUC__ >= 3 -#ifndef GCC_PRINTFLIKE -#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var))) -#endif -#else -#ifndef GCC_PRINTFLIKE -#define GCC_PRINTFLIKE(fmt,var) /* nothing */ -#endif -#endif - -#ifndef offsetof /* If not defined by */ -#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0)) -#endif /* offsetof */ - -#ifndef MIN /* Suitable for comparing primitive types (integers) */ -#if defined(__GNUC__) -#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ - ((_a)<(_b)?(_a):(_b)); }) -#else /* !__GNUC__ */ -#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */ -#endif /* __GNUC__ */ -#endif /* MIN */ - -#endif /* _ASN_SYSTEM_H_ */ diff --git a/stglibs/smux.lib/ber_decoder.h b/stglibs/smux.lib/ber_decoder.h deleted file mode 100644 index 768133b6..00000000 --- a/stglibs/smux.lib/ber_decoder.h +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _BER_DECODER_H_ -#define _BER_DECODER_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ -struct asn_codec_ctx_s; /* Forward declaration */ - -/* - * The BER decoder of any type. - * This function may be invoked directly from the application. - */ -asn_dec_rval_t ber_decode(struct asn_codec_ctx_s *opt_codec_ctx, - struct asn_TYPE_descriptor_s *type_descriptor, - void **struct_ptr, /* Pointer to a target structure's pointer */ - const void *buffer, /* Data to be decoded */ - size_t size /* Size of that buffer */ - ); - -/* - * Type of generic function which decodes the byte stream into the structure. - */ -typedef asn_dec_rval_t (ber_type_decoder_f)( - struct asn_codec_ctx_s *opt_codec_ctx, - struct asn_TYPE_descriptor_s *type_descriptor, - void **struct_ptr, const void *buf_ptr, size_t size, - int tag_mode); - -/******************************* - * INTERNALLY USEFUL FUNCTIONS * - *******************************/ - -/* - * Check that all tags correspond to the type definition (as given in head). - * On return, last_length would contain either a non-negative length of the - * value part of the last TLV, or the negative number of expected - * "end of content" sequences. The number may only be negative if the - * head->last_tag_form is non-zero. - */ -asn_dec_rval_t ber_check_tags( - struct asn_codec_ctx_s *opt_codec_ctx, /* codec options */ - struct asn_TYPE_descriptor_s *type_descriptor, - asn_struct_ctx_t *opt_ctx, /* saved decoding context */ - const void *ptr, size_t size, - int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ - int last_tag_form, /* {-1,0:1}: any, primitive, constr */ - ber_tlv_len_t *last_length, - int *opt_tlv_form /* optional tag form */ - ); - -#ifdef __cplusplus -} -#endif - -#endif /* _BER_DECODER_H_ */ diff --git a/stglibs/smux.lib/ber_tlv_length.h b/stglibs/smux.lib/ber_tlv_length.h deleted file mode 100644 index 34968022..00000000 --- a/stglibs/smux.lib/ber_tlv_length.h +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * Copyright (c) 2003 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _BER_TLV_LENGTH_H_ -#define _BER_TLV_LENGTH_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef ssize_t ber_tlv_len_t; - -/* - * This function tries to fetch the length of the BER TLV value and place it - * in *len_r. - * RETURN VALUES: - * 0: More data expected than bufptr contains. - * -1: Fatal error deciphering length. - * >0: Number of bytes used from bufptr. - * On return with >0, len_r is constrained as -1..MAX, where -1 mean - * that the value is of indefinite length. - */ -ssize_t ber_fetch_length(int _is_constructed, const void *bufptr, size_t size, - ber_tlv_len_t *len_r); - -/* - * This function expects bufptr to be positioned over L in TLV. - * It returns number of bytes occupied by L and V together, suitable - * for skipping. The function properly handles indefinite length. - * RETURN VALUES: - * Standard {-1,0,>0} convention. - */ -ssize_t ber_skip_length( - struct asn_codec_ctx_s *opt_codec_ctx, /* optional context */ - int _is_constructed, const void *bufptr, size_t size); - -/* - * This function serializes the length (L from TLV) in DER format. - * It always returns number of bytes necessary to represent the length, - * it is a caller's responsibility to check the return value - * against the supplied buffer's size. - */ -size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size); - -#ifdef __cplusplus -} -#endif - -#endif /* _BER_TLV_LENGTH_H_ */ diff --git a/stglibs/smux.lib/ber_tlv_tag.h b/stglibs/smux.lib/ber_tlv_tag.h deleted file mode 100644 index 60e86686..00000000 --- a/stglibs/smux.lib/ber_tlv_tag.h +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _BER_TLV_TAG_H_ -#define _BER_TLV_TAG_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -enum asn_tag_class { - ASN_TAG_CLASS_UNIVERSAL = 0, /* 0b00 */ - ASN_TAG_CLASS_APPLICATION = 1, /* 0b01 */ - ASN_TAG_CLASS_CONTEXT = 2, /* 0b10 */ - ASN_TAG_CLASS_PRIVATE = 3 /* 0b11 */ -}; -typedef unsigned ber_tlv_tag_t; /* BER TAG from Tag-Length-Value */ - -/* - * Tag class is encoded together with tag value for optimization purposes. - */ -#define BER_TAG_CLASS(tag) ((tag) & 0x3) -#define BER_TAG_VALUE(tag) ((tag) >> 2) -#define BER_TLV_CONSTRUCTED(tagptr) (((*(const uint8_t *)tagptr)&0x20)?1:0) - -#define BER_TAGS_EQUAL(tag1, tag2) ((tag1) == (tag2)) - -/* - * Several functions for printing the TAG in the canonical form - * (i.e. "[PRIVATE 0]"). - * Return values correspond to their libc counterparts (if any). - */ -ssize_t ber_tlv_tag_snprint(ber_tlv_tag_t tag, char *buf, size_t buflen); -ssize_t ber_tlv_tag_fwrite(ber_tlv_tag_t tag, FILE *); -char *ber_tlv_tag_string(ber_tlv_tag_t tag); - - -/* - * This function tries to fetch the tag from the input stream. - * RETURN VALUES: - * 0: More data expected than bufptr contains. - * -1: Fatal error deciphering tag. - * >0: Number of bytes used from bufptr. tag_r will contain the tag. - */ -ssize_t ber_fetch_tag(const void *bufptr, size_t size, ber_tlv_tag_t *tag_r); - -/* - * This function serializes the tag (T from TLV) in BER format. - * It always returns number of bytes necessary to represent the tag, - * it is a caller's responsibility to check the return value - * against the supplied buffer's size. - */ -size_t ber_tlv_tag_serialize(ber_tlv_tag_t tag, void *bufptr, size_t size); - -#ifdef __cplusplus -} -#endif - -#endif /* _BER_TLV_TAG_H_ */ diff --git a/stglibs/smux.lib/constr_CHOICE.h b/stglibs/smux.lib/constr_CHOICE.h deleted file mode 100644 index 83404e6d..00000000 --- a/stglibs/smux.lib/constr_CHOICE.h +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (c) 2003, 2004, 2005 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _CONSTR_CHOICE_H_ -#define _CONSTR_CHOICE_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct asn_CHOICE_specifics_s { - /* - * Target structure description. - */ - int struct_size; /* Size of the target structure. */ - int ctx_offset; /* Offset of the asn_codec_ctx_t member */ - int pres_offset; /* Identifier of the present member */ - int pres_size; /* Size of the identifier (enum) */ - - /* - * Tags to members mapping table. - */ - asn_TYPE_tag2member_t *tag2el; - int tag2el_count; - - /* Canonical ordering of CHOICE elements, for PER */ - int *canonical_order; - - /* - * Extensions-related stuff. - */ - int ext_start; /* First member of extensions, or -1 */ -} asn_CHOICE_specifics_t; - -/* - * A set specialized functions dealing with the CHOICE type. - */ -asn_struct_free_f CHOICE_free; -asn_struct_print_f CHOICE_print; -asn_constr_check_f CHOICE_constraint; -ber_type_decoder_f CHOICE_decode_ber; -der_type_encoder_f CHOICE_encode_der; -xer_type_decoder_f CHOICE_decode_xer; -xer_type_encoder_f CHOICE_encode_xer; -per_type_decoder_f CHOICE_decode_uper; -per_type_encoder_f CHOICE_encode_uper; -asn_outmost_tag_f CHOICE_outmost_tag; - -#ifdef __cplusplus -} -#endif - -#endif /* _CONSTR_CHOICE_H_ */ diff --git a/stglibs/smux.lib/constr_SEQUENCE.h b/stglibs/smux.lib/constr_SEQUENCE.h deleted file mode 100644 index 5f589d5c..00000000 --- a/stglibs/smux.lib/constr_SEQUENCE.h +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _CONSTR_SEQUENCE_H_ -#define _CONSTR_SEQUENCE_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct asn_SEQUENCE_specifics_s { - /* - * Target structure description. - */ - int struct_size; /* Size of the target structure. */ - int ctx_offset; /* Offset of the asn_struct_ctx_t member */ - - /* - * Tags to members mapping table (sorted). - */ - asn_TYPE_tag2member_t *tag2el; - int tag2el_count; - - /* - * Optional members of the extensions root (roms) or additions (aoms). - * Meaningful for PER. - */ - int *oms; /* Optional MemberS */ - int roms_count; /* Root optional members count */ - int aoms_count; /* Additions optional members count */ - - /* - * Description of an extensions group. - */ - int ext_after; /* Extensions start after this member */ - int ext_before; /* Extensions stop before this member */ -} asn_SEQUENCE_specifics_t; - - -/* - * A set specialized functions dealing with the SEQUENCE type. - */ -asn_struct_free_f SEQUENCE_free; -asn_struct_print_f SEQUENCE_print; -asn_constr_check_f SEQUENCE_constraint; -ber_type_decoder_f SEQUENCE_decode_ber; -der_type_encoder_f SEQUENCE_encode_der; -xer_type_decoder_f SEQUENCE_decode_xer; -xer_type_encoder_f SEQUENCE_encode_xer; -per_type_decoder_f SEQUENCE_decode_uper; -per_type_encoder_f SEQUENCE_encode_uper; - -#ifdef __cplusplus -} -#endif - -#endif /* _CONSTR_SEQUENCE_H_ */ diff --git a/stglibs/smux.lib/constr_SEQUENCE_OF.h b/stglibs/smux.lib/constr_SEQUENCE_OF.h deleted file mode 100644 index e2272f32..00000000 --- a/stglibs/smux.lib/constr_SEQUENCE_OF.h +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * Copyright (c) 2003, 2005 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _CONSTR_SEQUENCE_OF_H_ -#define _CONSTR_SEQUENCE_OF_H_ - -#include -#include /* Implemented using SET OF */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * A set specialized functions dealing with the SEQUENCE OF type. - * Generally implemented using SET OF. - */ -#define SEQUENCE_OF_free SET_OF_free -#define SEQUENCE_OF_print SET_OF_print -#define SEQUENCE_OF_constraint SET_OF_constraint -#define SEQUENCE_OF_decode_ber SET_OF_decode_ber -#define SEQUENCE_OF_decode_xer SET_OF_decode_xer -#define SEQUENCE_OF_decode_uper SET_OF_decode_uper -der_type_encoder_f SEQUENCE_OF_encode_der; -xer_type_encoder_f SEQUENCE_OF_encode_xer; -per_type_encoder_f SEQUENCE_OF_encode_uper; - -#ifdef __cplusplus -} -#endif - -#endif /* _CONSTR_SET_OF_H_ */ diff --git a/stglibs/smux.lib/constr_SET_OF.h b/stglibs/smux.lib/constr_SET_OF.h deleted file mode 100644 index bcd09662..00000000 --- a/stglibs/smux.lib/constr_SET_OF.h +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * Copyright (c) 2003 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _CONSTR_SET_OF_H_ -#define _CONSTR_SET_OF_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct asn_SET_OF_specifics_s { - /* - * Target structure description. - */ - int struct_size; /* Size of the target structure. */ - int ctx_offset; /* Offset of the asn_struct_ctx_t member */ - - /* XER-specific stuff */ - int as_XMLValueList; /* The member type must be encoded like this */ -} asn_SET_OF_specifics_t; - -/* - * A set specialized functions dealing with the SET OF type. - */ -asn_struct_free_f SET_OF_free; -asn_struct_print_f SET_OF_print; -asn_constr_check_f SET_OF_constraint; -ber_type_decoder_f SET_OF_decode_ber; -der_type_encoder_f SET_OF_encode_der; -xer_type_decoder_f SET_OF_decode_xer; -xer_type_encoder_f SET_OF_encode_xer; -per_type_decoder_f SET_OF_decode_uper; -per_type_encoder_f SET_OF_encode_uper; - -#ifdef __cplusplus -} -#endif - -#endif /* _CONSTR_SET_OF_H_ */ diff --git a/stglibs/smux.lib/constr_TYPE.h b/stglibs/smux.lib/constr_TYPE.h deleted file mode 100644 index 95507c80..00000000 --- a/stglibs/smux.lib/constr_TYPE.h +++ /dev/null @@ -1,180 +0,0 @@ -/*- - * Copyright (c) 2003, 2004, 2005, 2006 Lev Walkin . - * All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -/* - * This file contains the declaration structure called "ASN.1 Type Definition", - * which holds all information necessary for encoding and decoding routines. - * This structure even contains pointer to these encoding and decoding routines - * for each defined ASN.1 type. - */ -#ifndef _CONSTR_TYPE_H_ -#define _CONSTR_TYPE_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ -struct asn_TYPE_member_s; /* Forward declaration */ - -/* - * This type provides the context information for various ASN.1 routines, - * primarily ones doing decoding. A member _asn_ctx of this type must be - * included into certain target language's structures, such as compound types. - */ -typedef struct asn_struct_ctx_s { - short phase; /* Decoding phase */ - short step; /* Elementary step of a phase */ - int context; /* Other context information */ - void *ptr; /* Decoder-specific stuff (stack elements) */ - ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */ -} asn_struct_ctx_t; - -#include /* Basic Encoding Rules decoder */ -#include /* Distinguished Encoding Rules encoder */ -#include /* Decoder of XER (XML, text) */ -#include /* Encoder into XER (XML, text) */ -#include /* Packet Encoding Rules decoder */ -#include /* Packet Encoding Rules encoder */ -#include /* Subtype constraints support */ - -/* - * Free the structure according to its specification. - * If (free_contents_only) is set, the wrapper structure itself (struct_ptr) - * will not be freed. (It may be useful in case the structure is allocated - * statically or arranged on the stack, yet its elements are allocated - * dynamically.) - */ -typedef void (asn_struct_free_f)( - struct asn_TYPE_descriptor_s *type_descriptor, - void *struct_ptr, int free_contents_only); -#define ASN_STRUCT_FREE(asn_DEF, ptr) (asn_DEF).free_struct(&(asn_DEF),ptr,0) -#define ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF, ptr) \ - (asn_DEF).free_struct(&(asn_DEF),ptr,1) - -/* - * Print the structure according to its specification. - */ -typedef int (asn_struct_print_f)( - struct asn_TYPE_descriptor_s *type_descriptor, - const void *struct_ptr, - int level, /* Indentation level */ - asn_app_consume_bytes_f *callback, void *app_key); - -/* - * Return the outmost tag of the type. - * If the type is untagged CHOICE, the dynamic operation is performed. - * NOTE: This function pointer type is only useful internally. - * Do not use it in your application. - */ -typedef ber_tlv_tag_t (asn_outmost_tag_f)( - struct asn_TYPE_descriptor_s *type_descriptor, - const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag); -/* The instance of the above function type; used internally. */ -asn_outmost_tag_f asn_TYPE_outmost_tag; - - -/* - * The definitive description of the destination language's structure. - */ -typedef struct asn_TYPE_descriptor_s { - char *name; /* A name of the ASN.1 type. "" in some cases. */ - char *xml_tag; /* Name used in XML tag */ - - /* - * Generalized functions for dealing with the specific type. - * May be directly invoked by applications. - */ - asn_struct_free_f *free_struct; /* Free the structure */ - asn_struct_print_f *print_struct; /* Human readable output */ - asn_constr_check_f *check_constraints; /* Constraints validator */ - ber_type_decoder_f *ber_decoder; /* Generic BER decoder */ - der_type_encoder_f *der_encoder; /* Canonical DER encoder */ - xer_type_decoder_f *xer_decoder; /* Generic XER decoder */ - xer_type_encoder_f *xer_encoder; /* [Canonical] XER encoder */ - per_type_decoder_f *uper_decoder; /* Unaligned PER decoder */ - per_type_encoder_f *uper_encoder; /* Unaligned PER encoder */ - - /*********************************************************************** - * Internally useful members. Not to be used by applications directly. * - **********************************************************************/ - - /* - * Tags that are expected to occur. - */ - asn_outmost_tag_f *outmost_tag; /* */ - ber_tlv_tag_t *tags; /* Effective tags sequence for this type */ - int tags_count; /* Number of tags which are expected */ - ber_tlv_tag_t *all_tags;/* Every tag for BER/containment */ - int all_tags_count; /* Number of tags */ - - asn_per_constraints_t *per_constraints; /* PER compiled constraints */ - - /* - * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE). - */ - struct asn_TYPE_member_s *elements; - int elements_count; - - /* - * Additional information describing the type, used by appropriate - * functions above. - */ - void *specifics; -} asn_TYPE_descriptor_t; - -/* - * This type describes an element of the constructed type, - * i.e. SEQUENCE, SET, CHOICE, etc. - */ - enum asn_TYPE_flags_e { - ATF_NOFLAGS, - ATF_POINTER = 0x01, /* Represented by the pointer */ - ATF_OPEN_TYPE = 0x02 /* ANY type, without meaningful tag */ - }; -typedef struct asn_TYPE_member_s { - enum asn_TYPE_flags_e flags; /* Element's presentation flags */ - int optional; /* Following optional members, including current */ - int memb_offset; /* Offset of the element */ - ber_tlv_tag_t tag; /* Outmost (most immediate) tag */ - int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */ - asn_TYPE_descriptor_t *type; /* Member type descriptor */ - asn_constr_check_f *memb_constraints; /* Constraints validator */ - asn_per_constraints_t *per_constraints; /* PER compiled constraints */ - int (*default_value)(int setval, void **sptr); /* DEFAULT */ - char *name; /* ASN.1 identifier of the element */ -} asn_TYPE_member_t; - -/* - * BER tag to element number mapping. - */ -typedef struct asn_TYPE_tag2member_s { - ber_tlv_tag_t el_tag; /* Outmost tag of the member */ - int el_no; /* Index of the associated member, base 0 */ - int toff_first; /* First occurence of the el_tag, relative */ - int toff_last; /* Last occurence of the el_tag, relatvie */ -} asn_TYPE_tag2member_t; - -/* - * This function is a wrapper around (td)->print_struct, which prints out - * the contents of the target language's structure (struct_ptr) into the - * file pointer (stream) in human readable form. - * RETURN VALUES: - * 0: The structure is printed. - * -1: Problem dumping the structure. - * (See also xer_fprint() in xer_encoder.h) - */ -int asn_fprint(FILE *stream, /* Destination stream descriptor */ - asn_TYPE_descriptor_t *td, /* ASN.1 type descriptor */ - const void *struct_ptr); /* Structure to be printed */ - -#ifdef __cplusplus -} -#endif - -#endif /* _CONSTR_TYPE_H_ */ diff --git a/stglibs/smux.lib/constraints.h b/stglibs/smux.lib/constraints.h deleted file mode 100644 index 5032345e..00000000 --- a/stglibs/smux.lib/constraints.h +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * Copyright (c) 2004, 2006 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _ASN1_CONSTRAINTS_VALIDATOR_H_ -#define _ASN1_CONSTRAINTS_VALIDATOR_H_ - -#include /* Platform-dependent types */ - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* - * Validate the structure according to the ASN.1 constraints. - * If errbuf and errlen are given, they shall be pointing to the appropriate - * buffer space and its length before calling this function. Alternatively, - * they could be passed as NULL's. If constraints validation fails, - * errlen will contain the actual number of bytes taken from the errbuf - * to encode an error message (properly 0-terminated). - * - * RETURN VALUES: - * This function returns 0 in case all ASN.1 constraints are met - * and -1 if one or more constraints were failed. - */ -int -asn_check_constraints(struct asn_TYPE_descriptor_s *type_descriptor, - const void *struct_ptr, /* Target language's structure */ - char *errbuf, /* Returned error description */ - size_t *errlen /* Length of the error description */ - ); - - -/* - * Generic type for constraint checking callback, - * associated with every type descriptor. - */ -typedef int (asn_constr_check_f)( - struct asn_TYPE_descriptor_s *type_descriptor, - const void *struct_ptr, - asn_app_constraint_failed_f *optional_callback, /* Log the error */ - void *optional_app_key /* Opaque key passed to a callback */ - ); - -/******************************* - * INTERNALLY USEFUL FUNCTIONS * - *******************************/ - -asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */ -asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */ - -/* - * Invoke the callback with a complete error message. - */ -#define _ASN_CTFAIL if(ctfailcb) ctfailcb - -#ifdef __cplusplus -} -#endif - -#endif /* _ASN1_CONSTRAINTS_VALIDATOR_H_ */ diff --git a/stglibs/smux.lib/der_encoder.h b/stglibs/smux.lib/der_encoder.h deleted file mode 100644 index 4e2fb06c..00000000 --- a/stglibs/smux.lib/der_encoder.h +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _DER_ENCODER_H_ -#define _DER_ENCODER_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* - * The DER encoder of any type. May be invoked by the application. - */ -asn_enc_rval_t der_encode(struct asn_TYPE_descriptor_s *type_descriptor, - void *struct_ptr, /* Structure to be encoded */ - asn_app_consume_bytes_f *consume_bytes_cb, - void *app_key /* Arbitrary callback argument */ - ); - -/* A variant of der_encode() which encodes data into the pre-allocated buffer */ -asn_enc_rval_t der_encode_to_buffer( - struct asn_TYPE_descriptor_s *type_descriptor, - void *struct_ptr, /* Structure to be encoded */ - void *buffer, /* Pre-allocated buffer */ - size_t buffer_size /* Initial buffer size (maximum) */ - ); - -/* - * Type of the generic DER encoder. - */ -typedef asn_enc_rval_t (der_type_encoder_f)( - struct asn_TYPE_descriptor_s *type_descriptor, - void *struct_ptr, /* Structure to be encoded */ - int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ - ber_tlv_tag_t tag, - asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ - void *app_key /* Arbitrary callback argument */ - ); - - -/******************************* - * INTERNALLY USEFUL FUNCTIONS * - *******************************/ - -/* - * Write out leading TL[v] sequence according to the type definition. - */ -ssize_t der_write_tags( - struct asn_TYPE_descriptor_s *type_descriptor, - size_t struct_length, - int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ - int last_tag_form, /* {0,!0}: prim, constructed */ - ber_tlv_tag_t tag, - asn_app_consume_bytes_f *consume_bytes_cb, - void *app_key - ); - -#ifdef __cplusplus -} -#endif - -#endif /* _DER_ENCODER_H_ */ diff --git a/stglibs/smux.lib/include/stg/ANY.h b/stglibs/smux.lib/include/stg/ANY.h new file mode 100644 index 00000000..b7d92fa9 --- /dev/null +++ b/stglibs/smux.lib/include/stg/ANY.h @@ -0,0 +1,48 @@ +/*- + * Copyright (c) 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_TYPE_ANY_H +#define ASN_TYPE_ANY_H + +#include /* Implemented via OCTET STRING type */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ANY { + uint8_t *buf; /* BER-encoded ANY contents */ + int size; /* Size of the above buffer */ + + asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */ +} ANY_t; + +extern asn_TYPE_descriptor_t asn_DEF_ANY; + +asn_struct_free_f ANY_free; +asn_struct_print_f ANY_print; +ber_type_decoder_f ANY_decode_ber; +der_type_encoder_f ANY_encode_der; +xer_type_encoder_f ANY_encode_xer; + +/****************************** + * Handy conversion routines. * + ******************************/ + +/* Convert another ASN.1 type into the ANY. This implies DER encoding. */ +int ANY_fromType(ANY_t *, asn_TYPE_descriptor_t *td, void *struct_ptr); +ANY_t *ANY_new_fromType(asn_TYPE_descriptor_t *td, void *struct_ptr); + +/* Convert the contents of the ANY type into the specified type. */ +int ANY_to_type(ANY_t *, asn_TYPE_descriptor_t *td, void **struct_ptr); + +#define ANY_fromBuf(s, buf, size) OCTET_STRING_fromBuf((s), (buf), (size)) +#define ANY_new_fromBuf(buf, size) OCTET_STRING_new_fromBuf( \ + &asn_DEF_ANY, (buf), (size)) + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_TYPE_ANY_H */ diff --git a/stglibs/smux.lib/include/stg/ApplicationSyntax.h b/stglibs/smux.lib/include/stg/ApplicationSyntax.h new file mode 100644 index 00000000..90a87076 --- /dev/null +++ b/stglibs/smux.lib/include/stg/ApplicationSyntax.h @@ -0,0 +1,58 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _ApplicationSyntax_H_ +#define _ApplicationSyntax_H_ + + +#include + +/* Including external dependencies */ +#include "NetworkAddress.h" +#include "Counter.h" +#include "Gauge.h" +#include "TimeTicks.h" +#include "Opaque.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum ApplicationSyntax_PR { + ApplicationSyntax_PR_NOTHING, /* No components present */ + ApplicationSyntax_PR_address, + ApplicationSyntax_PR_counter, + ApplicationSyntax_PR_gauge, + ApplicationSyntax_PR_ticks, + ApplicationSyntax_PR_arbitrary +} ApplicationSyntax_PR; + +/* ApplicationSyntax */ +typedef struct ApplicationSyntax { + ApplicationSyntax_PR present; + union ApplicationSyntax_u { + NetworkAddress_t address; + Counter_t counter; + Gauge_t gauge; + TimeTicks_t ticks; + Opaque_t arbitrary; + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} ApplicationSyntax_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_ApplicationSyntax; + +#ifdef __cplusplus +} +#endif + +#endif /* _ApplicationSyntax_H_ */ diff --git a/stglibs/smux.lib/include/stg/AtEntry.h b/stglibs/smux.lib/include/stg/AtEntry.h new file mode 100644 index 00000000..a0aba105 --- /dev/null +++ b/stglibs/smux.lib/include/stg/AtEntry.h @@ -0,0 +1,41 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _AtEntry_H_ +#define _AtEntry_H_ + + +#include + +/* Including external dependencies */ +#include +#include "PhysAddress.h" +#include "NetworkAddress.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* AtEntry */ +typedef struct AtEntry { + INTEGER_t atIfIndex; + PhysAddress_t atPhysAddress; + NetworkAddress_t atNetAddress; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} AtEntry_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_AtEntry; + +#ifdef __cplusplus +} +#endif + +#endif /* _AtEntry_H_ */ diff --git a/stglibs/smux.lib/include/stg/BIT_STRING.h b/stglibs/smux.lib/include/stg/BIT_STRING.h new file mode 100644 index 00000000..732e878b --- /dev/null +++ b/stglibs/smux.lib/include/stg/BIT_STRING.h @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2003 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BIT_STRING_H_ +#define _BIT_STRING_H_ + +#include /* Some help from OCTET STRING */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct BIT_STRING_s { + uint8_t *buf; /* BIT STRING body */ + int size; /* Size of the above buffer */ + + int bits_unused;/* Unused trailing bits in the last octet (0..7) */ + + asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */ +} BIT_STRING_t; + +extern asn_TYPE_descriptor_t asn_DEF_BIT_STRING; + +asn_struct_print_f BIT_STRING_print; /* Human-readable output */ +asn_constr_check_f BIT_STRING_constraint; +xer_type_encoder_f BIT_STRING_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _BIT_STRING_H_ */ diff --git a/stglibs/smux.lib/include/stg/BOOLEAN.h b/stglibs/smux.lib/include/stg/BOOLEAN.h new file mode 100644 index 00000000..217d0f16 --- /dev/null +++ b/stglibs/smux.lib/include/stg/BOOLEAN.h @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2003 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BOOLEAN_H_ +#define _BOOLEAN_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The underlying integer may contain various values, but everything + * non-zero is capped to 0xff by the DER encoder. The BER decoder may + * yield non-zero values different from 1, beware. + */ +typedef int BOOLEAN_t; + +extern asn_TYPE_descriptor_t asn_DEF_BOOLEAN; + +asn_struct_free_f BOOLEAN_free; +asn_struct_print_f BOOLEAN_print; +ber_type_decoder_f BOOLEAN_decode_ber; +der_type_encoder_f BOOLEAN_encode_der; +xer_type_decoder_f BOOLEAN_decode_xer; +xer_type_encoder_f BOOLEAN_encode_xer; +per_type_decoder_f BOOLEAN_decode_uper; +per_type_encoder_f BOOLEAN_encode_uper; + +#ifdef __cplusplus +} +#endif + +#endif /* _BOOLEAN_H_ */ diff --git a/stglibs/smux.lib/include/stg/ClosePDU.h b/stglibs/smux.lib/include/stg/ClosePDU.h new file mode 100644 index 00000000..a3d1e7a9 --- /dev/null +++ b/stglibs/smux.lib/include/stg/ClosePDU.h @@ -0,0 +1,48 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "SMUX" + * found in "SMUX.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _ClosePDU_H_ +#define _ClosePDU_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum ClosePDU { + ClosePDU_goingDown = 0, + ClosePDU_unsupportedVersion = 1, + ClosePDU_packetFormat = 2, + ClosePDU_protocolError = 3, + ClosePDU_internalError = 4, + ClosePDU_authenticationFailure = 5 +} e_ClosePDU; + +/* ClosePDU */ +typedef INTEGER_t ClosePDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_ClosePDU; +asn_struct_free_f ClosePDU_free; +asn_struct_print_f ClosePDU_print; +asn_constr_check_f ClosePDU_constraint; +ber_type_decoder_f ClosePDU_decode_ber; +der_type_encoder_f ClosePDU_encode_der; +xer_type_decoder_f ClosePDU_decode_xer; +xer_type_encoder_f ClosePDU_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _ClosePDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/Counter.h b/stglibs/smux.lib/include/stg/Counter.h new file mode 100644 index 00000000..3c770ada --- /dev/null +++ b/stglibs/smux.lib/include/stg/Counter.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _Counter_H_ +#define _Counter_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Counter */ +typedef INTEGER_t Counter_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Counter; +asn_struct_free_f Counter_free; +asn_struct_print_f Counter_print; +asn_constr_check_f Counter_constraint; +ber_type_decoder_f Counter_decode_ber; +der_type_encoder_f Counter_encode_der; +xer_type_decoder_f Counter_decode_xer; +xer_type_encoder_f Counter_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _Counter_H_ */ diff --git a/stglibs/smux.lib/include/stg/DisplayString.h b/stglibs/smux.lib/include/stg/DisplayString.h new file mode 100644 index 00000000..ac6862c2 --- /dev/null +++ b/stglibs/smux.lib/include/stg/DisplayString.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _DisplayString_H_ +#define _DisplayString_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* DisplayString */ +typedef OCTET_STRING_t DisplayString_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_DisplayString; +asn_struct_free_f DisplayString_free; +asn_struct_print_f DisplayString_print; +asn_constr_check_f DisplayString_constraint; +ber_type_decoder_f DisplayString_decode_ber; +der_type_encoder_f DisplayString_encode_der; +xer_type_decoder_f DisplayString_decode_xer; +xer_type_encoder_f DisplayString_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _DisplayString_H_ */ diff --git a/stglibs/smux.lib/include/stg/EgpNeighEntry.h b/stglibs/smux.lib/include/stg/EgpNeighEntry.h new file mode 100644 index 00000000..79d3eedd --- /dev/null +++ b/stglibs/smux.lib/include/stg/EgpNeighEntry.h @@ -0,0 +1,53 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _EgpNeighEntry_H_ +#define _EgpNeighEntry_H_ + + +#include + +/* Including external dependencies */ +#include +#include "IpAddress.h" +#include "Counter.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* EgpNeighEntry */ +typedef struct EgpNeighEntry { + INTEGER_t egpNeighState; + IpAddress_t egpNeighAddr; + INTEGER_t egpNeighAs; + Counter_t egpNeighInMsgs; + Counter_t egpNeighInErrs; + Counter_t egpNeighOutMsgs; + Counter_t egpNeighOutErrs; + Counter_t egpNeighInErrMsgs; + Counter_t egpNeighOutErrMsgs; + Counter_t egpNeighStateUps; + Counter_t egpNeighStateDowns; + INTEGER_t egpNeighIntervalHello; + INTEGER_t egpNeighIntervalPoll; + INTEGER_t egpNeighMode; + INTEGER_t egpNeighEventTrigger; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} EgpNeighEntry_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_EgpNeighEntry; + +#ifdef __cplusplus +} +#endif + +#endif /* _EgpNeighEntry_H_ */ diff --git a/stglibs/smux.lib/include/stg/Gauge.h b/stglibs/smux.lib/include/stg/Gauge.h new file mode 100644 index 00000000..f3e17c5e --- /dev/null +++ b/stglibs/smux.lib/include/stg/Gauge.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _Gauge_H_ +#define _Gauge_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Gauge */ +typedef INTEGER_t Gauge_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Gauge; +asn_struct_free_f Gauge_free; +asn_struct_print_f Gauge_print; +asn_constr_check_f Gauge_constraint; +ber_type_decoder_f Gauge_decode_ber; +der_type_encoder_f Gauge_encode_der; +xer_type_decoder_f Gauge_decode_xer; +xer_type_encoder_f Gauge_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _Gauge_H_ */ diff --git a/stglibs/smux.lib/include/stg/GetNextRequest-PDU.h b/stglibs/smux.lib/include/stg/GetNextRequest-PDU.h new file mode 100644 index 00000000..f9298ec6 --- /dev/null +++ b/stglibs/smux.lib/include/stg/GetNextRequest-PDU.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _GetNextRequest_PDU_H_ +#define _GetNextRequest_PDU_H_ + + +#include + +/* Including external dependencies */ +#include "PDU.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* GetNextRequest-PDU */ +typedef PDU_t GetNextRequest_PDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_GetNextRequest_PDU; +asn_struct_free_f GetNextRequest_PDU_free; +asn_struct_print_f GetNextRequest_PDU_print; +asn_constr_check_f GetNextRequest_PDU_constraint; +ber_type_decoder_f GetNextRequest_PDU_decode_ber; +der_type_encoder_f GetNextRequest_PDU_encode_der; +xer_type_decoder_f GetNextRequest_PDU_decode_xer; +xer_type_encoder_f GetNextRequest_PDU_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _GetNextRequest_PDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/GetRequest-PDU.h b/stglibs/smux.lib/include/stg/GetRequest-PDU.h new file mode 100644 index 00000000..9449451f --- /dev/null +++ b/stglibs/smux.lib/include/stg/GetRequest-PDU.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _GetRequest_PDU_H_ +#define _GetRequest_PDU_H_ + + +#include + +/* Including external dependencies */ +#include "PDU.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* GetRequest-PDU */ +typedef PDU_t GetRequest_PDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_GetRequest_PDU; +asn_struct_free_f GetRequest_PDU_free; +asn_struct_print_f GetRequest_PDU_print; +asn_constr_check_f GetRequest_PDU_constraint; +ber_type_decoder_f GetRequest_PDU_decode_ber; +der_type_encoder_f GetRequest_PDU_encode_der; +xer_type_decoder_f GetRequest_PDU_decode_xer; +xer_type_encoder_f GetRequest_PDU_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _GetRequest_PDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/GetResponse-PDU.h b/stglibs/smux.lib/include/stg/GetResponse-PDU.h new file mode 100644 index 00000000..12e3fba1 --- /dev/null +++ b/stglibs/smux.lib/include/stg/GetResponse-PDU.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _GetResponse_PDU_H_ +#define _GetResponse_PDU_H_ + + +#include + +/* Including external dependencies */ +#include "PDU.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* GetResponse-PDU */ +typedef PDU_t GetResponse_PDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_GetResponse_PDU; +asn_struct_free_f GetResponse_PDU_free; +asn_struct_print_f GetResponse_PDU_print; +asn_constr_check_f GetResponse_PDU_constraint; +ber_type_decoder_f GetResponse_PDU_decode_ber; +der_type_encoder_f GetResponse_PDU_encode_der; +xer_type_decoder_f GetResponse_PDU_decode_xer; +xer_type_encoder_f GetResponse_PDU_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _GetResponse_PDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/INTEGER.h b/stglibs/smux.lib/include/stg/INTEGER.h new file mode 100644 index 00000000..62832b12 --- /dev/null +++ b/stglibs/smux.lib/include/stg/INTEGER.h @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2003, 2005 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _INTEGER_H_ +#define _INTEGER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef ASN__PRIMITIVE_TYPE_t INTEGER_t; + +extern asn_TYPE_descriptor_t asn_DEF_INTEGER; + +/* Map with to integer value association */ +typedef struct asn_INTEGER_enum_map_s { + long nat_value; /* associated native integer value */ + size_t enum_len; /* strlen("tag") */ + const char *enum_name; /* "tag" */ +} asn_INTEGER_enum_map_t; + +/* This type describes an enumeration for INTEGER and ENUMERATED types */ +typedef struct asn_INTEGER_specifics_s { + asn_INTEGER_enum_map_t *value2enum; /* N -> "tag"; sorted by N */ + unsigned int *enum2value; /* "tag" => N; sorted by tag */ + int map_count; /* Elements in either map */ + int extension; /* This map is extensible */ + int strict_enumeration; /* Enumeration set is fixed */ +} asn_INTEGER_specifics_t; + +asn_struct_print_f INTEGER_print; +ber_type_decoder_f INTEGER_decode_ber; +der_type_encoder_f INTEGER_encode_der; +xer_type_decoder_f INTEGER_decode_xer; +xer_type_encoder_f INTEGER_encode_xer; +per_type_decoder_f INTEGER_decode_uper; +per_type_encoder_f INTEGER_encode_uper; + +/*********************************** + * Some handy conversion routines. * + ***********************************/ + +/* + * Returns 0 if it was possible to convert, -1 otherwise. + * -1/EINVAL: Mandatory argument missing + * -1/ERANGE: Value encoded is out of range for long representation + * -1/ENOMEM: Memory allocation failed (in asn_long2INTEGER()). + */ +int asn_INTEGER2long(const INTEGER_t *i, long *l); +int asn_long2INTEGER(INTEGER_t *i, long l); + +/* + * Convert the integer value into the corresponding enumeration map entry. + */ +const asn_INTEGER_enum_map_t *INTEGER_map_value2enum(asn_INTEGER_specifics_t *specs, long value); + +#ifdef __cplusplus +} +#endif + +#endif /* _INTEGER_H_ */ diff --git a/stglibs/smux.lib/include/stg/IfEntry.h b/stglibs/smux.lib/include/stg/IfEntry.h new file mode 100644 index 00000000..eb30717b --- /dev/null +++ b/stglibs/smux.lib/include/stg/IfEntry.h @@ -0,0 +1,64 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _IfEntry_H_ +#define _IfEntry_H_ + + +#include + +/* Including external dependencies */ +#include +#include "DisplayString.h" +#include "Gauge.h" +#include "PhysAddress.h" +#include "TimeTicks.h" +#include "Counter.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* IfEntry */ +typedef struct IfEntry { + INTEGER_t ifIndex; + DisplayString_t ifDescr; + INTEGER_t ifType; + INTEGER_t ifMtu; + Gauge_t ifSpeed; + PhysAddress_t ifPhysAddress; + INTEGER_t ifAdminStatus; + INTEGER_t ifOperStatus; + TimeTicks_t ifLastChange; + Counter_t ifInOctets; + Counter_t ifInUcastPkts; + Counter_t ifInNUcastPkts; + Counter_t ifInDiscards; + Counter_t ifInErrors; + Counter_t ifInUnknownProtos; + Counter_t ifOutOctets; + Counter_t ifOutUcastPkts; + Counter_t ifOutNUcastPkts; + Counter_t ifOutDiscards; + Counter_t ifOutErrors; + Gauge_t ifOutQLen; + OBJECT_IDENTIFIER_t ifSpecific; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} IfEntry_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_IfEntry; + +#ifdef __cplusplus +} +#endif + +#endif /* _IfEntry_H_ */ diff --git a/stglibs/smux.lib/include/stg/IpAddrEntry.h b/stglibs/smux.lib/include/stg/IpAddrEntry.h new file mode 100644 index 00000000..9e36f32a --- /dev/null +++ b/stglibs/smux.lib/include/stg/IpAddrEntry.h @@ -0,0 +1,43 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _IpAddrEntry_H_ +#define _IpAddrEntry_H_ + + +#include + +/* Including external dependencies */ +#include "IpAddress.h" +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* IpAddrEntry */ +typedef struct IpAddrEntry { + IpAddress_t ipAdEntAddr; + INTEGER_t ipAdEntIfIndex; + IpAddress_t ipAdEntNetMask; + INTEGER_t ipAdEntBcastAddr; + long ipAdEntReasmMaxSize; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} IpAddrEntry_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_IpAddrEntry; + +#ifdef __cplusplus +} +#endif + +#endif /* _IpAddrEntry_H_ */ diff --git a/stglibs/smux.lib/include/stg/IpAddress.h b/stglibs/smux.lib/include/stg/IpAddress.h new file mode 100644 index 00000000..06c1d4a3 --- /dev/null +++ b/stglibs/smux.lib/include/stg/IpAddress.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _IpAddress_H_ +#define _IpAddress_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* IpAddress */ +typedef OCTET_STRING_t IpAddress_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_IpAddress; +asn_struct_free_f IpAddress_free; +asn_struct_print_f IpAddress_print; +asn_constr_check_f IpAddress_constraint; +ber_type_decoder_f IpAddress_decode_ber; +der_type_encoder_f IpAddress_encode_der; +xer_type_decoder_f IpAddress_decode_xer; +xer_type_encoder_f IpAddress_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _IpAddress_H_ */ diff --git a/stglibs/smux.lib/include/stg/IpNetToMediaEntry.h b/stglibs/smux.lib/include/stg/IpNetToMediaEntry.h new file mode 100644 index 00000000..1eb8124f --- /dev/null +++ b/stglibs/smux.lib/include/stg/IpNetToMediaEntry.h @@ -0,0 +1,42 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _IpNetToMediaEntry_H_ +#define _IpNetToMediaEntry_H_ + + +#include + +/* Including external dependencies */ +#include +#include "PhysAddress.h" +#include "IpAddress.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* IpNetToMediaEntry */ +typedef struct IpNetToMediaEntry { + INTEGER_t ipNetToMediaIfIndex; + PhysAddress_t ipNetToMediaPhysAddress; + IpAddress_t ipNetToMediaNetAddress; + INTEGER_t ipNetToMediaType; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} IpNetToMediaEntry_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_IpNetToMediaEntry; + +#ifdef __cplusplus +} +#endif + +#endif /* _IpNetToMediaEntry_H_ */ diff --git a/stglibs/smux.lib/include/stg/IpRouteEntry.h b/stglibs/smux.lib/include/stg/IpRouteEntry.h new file mode 100644 index 00000000..5651a8fc --- /dev/null +++ b/stglibs/smux.lib/include/stg/IpRouteEntry.h @@ -0,0 +1,51 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _IpRouteEntry_H_ +#define _IpRouteEntry_H_ + + +#include + +/* Including external dependencies */ +#include "IpAddress.h" +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* IpRouteEntry */ +typedef struct IpRouteEntry { + IpAddress_t ipRouteDest; + INTEGER_t ipRouteIfIndex; + INTEGER_t ipRouteMetric1; + INTEGER_t ipRouteMetric2; + INTEGER_t ipRouteMetric3; + INTEGER_t ipRouteMetric4; + IpAddress_t ipRouteNextHop; + INTEGER_t ipRouteType; + INTEGER_t ipRouteProto; + INTEGER_t ipRouteAge; + IpAddress_t ipRouteMask; + INTEGER_t ipRouteMetric5; + OBJECT_IDENTIFIER_t ipRouteInfo; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} IpRouteEntry_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_IpRouteEntry; + +#ifdef __cplusplus +} +#endif + +#endif /* _IpRouteEntry_H_ */ diff --git a/stglibs/smux.lib/include/stg/Message.h b/stglibs/smux.lib/include/stg/Message.h new file mode 100644 index 00000000..2621d73c --- /dev/null +++ b/stglibs/smux.lib/include/stg/Message.h @@ -0,0 +1,46 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _Message_H_ +#define _Message_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum Message__version { + Message__version_version_1 = 0 +} e_Message__version; + +/* Message */ +typedef struct Message { + INTEGER_t version; + OCTET_STRING_t community; + ANY_t data; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Message_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Message; + +#ifdef __cplusplus +} +#endif + +#endif /* _Message_H_ */ diff --git a/stglibs/smux.lib/include/stg/NULL.h b/stglibs/smux.lib/include/stg/NULL.h new file mode 100644 index 00000000..131e7759 --- /dev/null +++ b/stglibs/smux.lib/include/stg/NULL.h @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2003 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_TYPE_NULL_H +#define ASN_TYPE_NULL_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The value of the NULL type is meaningless: see BOOLEAN if you want to + * carry true/false semantics. + */ +typedef int NULL_t; + +extern asn_TYPE_descriptor_t asn_DEF_NULL; + +asn_struct_print_f NULL_print; +der_type_encoder_f NULL_encode_der; +xer_type_decoder_f NULL_decode_xer; +xer_type_encoder_f NULL_encode_xer; +per_type_decoder_f NULL_decode_uper; +per_type_encoder_f NULL_encode_uper; + +#ifdef __cplusplus +} +#endif + +#endif /* NULL_H */ diff --git a/stglibs/smux.lib/include/stg/NativeEnumerated.h b/stglibs/smux.lib/include/stg/NativeEnumerated.h new file mode 100644 index 00000000..c59bb1ba --- /dev/null +++ b/stglibs/smux.lib/include/stg/NativeEnumerated.h @@ -0,0 +1,32 @@ +/*- + * Copyright (c) 2004, 2005, 2006 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * This type differs from the standard ENUMERATED in that it is modelled using + * the fixed machine type (long, int, short), so it can hold only values of + * limited length. There is no type (i.e., NativeEnumerated_t, any integer type + * will do). + * This type may be used when integer range is limited by subtype constraints. + */ +#ifndef _NativeEnumerated_H_ +#define _NativeEnumerated_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern asn_TYPE_descriptor_t asn_DEF_NativeEnumerated; + +xer_type_encoder_f NativeEnumerated_encode_xer; +per_type_decoder_f NativeEnumerated_decode_uper; +per_type_encoder_f NativeEnumerated_encode_uper; + +#ifdef __cplusplus +} +#endif + +#endif /* _NativeEnumerated_H_ */ diff --git a/stglibs/smux.lib/include/stg/NativeInteger.h b/stglibs/smux.lib/include/stg/NativeInteger.h new file mode 100644 index 00000000..4e63a835 --- /dev/null +++ b/stglibs/smux.lib/include/stg/NativeInteger.h @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * This type differs from the standard INTEGER in that it is modelled using + * the fixed machine type (long, int, short), so it can hold only values of + * limited length. There is no type (i.e., NativeInteger_t, any integer type + * will do). + * This type may be used when integer range is limited by subtype constraints. + */ +#ifndef _NativeInteger_H_ +#define _NativeInteger_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern asn_TYPE_descriptor_t asn_DEF_NativeInteger; + +asn_struct_free_f NativeInteger_free; +asn_struct_print_f NativeInteger_print; +ber_type_decoder_f NativeInteger_decode_ber; +der_type_encoder_f NativeInteger_encode_der; +xer_type_decoder_f NativeInteger_decode_xer; +xer_type_encoder_f NativeInteger_encode_xer; +per_type_decoder_f NativeInteger_decode_uper; +per_type_encoder_f NativeInteger_encode_uper; + +#ifdef __cplusplus +} +#endif + +#endif /* _NativeInteger_H_ */ diff --git a/stglibs/smux.lib/include/stg/NetworkAddress.h b/stglibs/smux.lib/include/stg/NetworkAddress.h new file mode 100644 index 00000000..8c73220b --- /dev/null +++ b/stglibs/smux.lib/include/stg/NetworkAddress.h @@ -0,0 +1,46 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _NetworkAddress_H_ +#define _NetworkAddress_H_ + + +#include + +/* Including external dependencies */ +#include "IpAddress.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum NetworkAddress_PR { + NetworkAddress_PR_NOTHING, /* No components present */ + NetworkAddress_PR_internet +} NetworkAddress_PR; + +/* NetworkAddress */ +typedef struct NetworkAddress { + NetworkAddress_PR present; + union NetworkAddress_u { + IpAddress_t internet; + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} NetworkAddress_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_NetworkAddress; + +#ifdef __cplusplus +} +#endif + +#endif /* _NetworkAddress_H_ */ diff --git a/stglibs/smux.lib/include/stg/OBJECT_IDENTIFIER.h b/stglibs/smux.lib/include/stg/OBJECT_IDENTIFIER.h new file mode 100644 index 00000000..2bb5d032 --- /dev/null +++ b/stglibs/smux.lib/include/stg/OBJECT_IDENTIFIER.h @@ -0,0 +1,139 @@ +/*- + * Copyright (c) 2003, 2004, 2005 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _OBJECT_IDENTIFIER_H_ +#define _OBJECT_IDENTIFIER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t; + +extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER; + +asn_struct_print_f OBJECT_IDENTIFIER_print; +asn_constr_check_f OBJECT_IDENTIFIER_constraint; +der_type_encoder_f OBJECT_IDENTIFIER_encode_der; +xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer; +xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer; + +/********************************** + * Some handy conversion routines * + **********************************/ + +/* + * This function fills an (_arcs) array with OBJECT IDENTIFIER arcs + * up to specified (_arc_slots) elements. + * + * EXAMPLE: + * void print_arcs(OBJECT_IDENTIFIER_t *oid) { + * unsigned long fixed_arcs[10]; // Try with fixed space first + * unsigned long *arcs = fixed_arcs; + * int arc_type_size = sizeof(fixed_arcs[0]); // sizeof(long) + * int arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10 + * int count; // Real number of arcs. + * int i; + * + * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, + * arc_type_size, arc_slots); + * // If necessary, reallocate arcs array and try again. + * if(count > arc_slots) { + * arc_slots = count; + * arcs = malloc(arc_type_size * arc_slots); + * if(!arcs) return; + * count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, + * arc_type_size, arc_slots); + * assert(count == arc_slots); + * } + * + * // Print the contents of the arcs array. + * for(i = 0; i < count; i++) + * printf("%d\n", arcs[i]); + * + * // Avoid memory leak. + * if(arcs != fixed_arcs) free(arcs); + * } + * + * RETURN VALUES: + * -1/EINVAL: Invalid arguments (oid is missing) + * -1/ERANGE: One or more arcs have value out of array cell type range. + * >=0: Number of arcs contained in the OBJECT IDENTIFIER + * + * WARNING: The function always returns the real number of arcs, + * even if there is no sufficient (_arc_slots) provided. + */ +int OBJECT_IDENTIFIER_get_arcs(OBJECT_IDENTIFIER_t *_oid, + void *_arcs, /* e.g., unsigned int arcs[N] */ + unsigned int _arc_type_size, /* e.g., sizeof(arcs[0]) */ + unsigned int _arc_slots /* e.g., N */); + +/* + * This functions initializes the OBJECT IDENTIFIER object with + * the given set of arcs. + * The minimum of two arcs must be present; some restrictions apply. + * RETURN VALUES: + * -1/EINVAL: Invalid arguments + * -1/ERANGE: The first two arcs do not conform to ASN.1 restrictions. + * -1/ENOMEM: Memory allocation failed + * 0: The object was initialized with new arcs. + */ +int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *_oid, + const void *_arcs, /* e.g., unsigned int arcs[N] */ + unsigned int _arc_type_size, /* e.g., sizeof(arcs[0]) */ + unsigned int _arc_slots /* e.g., N */); + +/* + * Print the specified OBJECT IDENTIFIER arc. + */ +int OBJECT_IDENTIFIER_print_arc(uint8_t *arcbuf, int arclen, + int add, /* Arbitrary offset, required to process the first two arcs */ + asn_app_consume_bytes_f *cb, void *app_key); + +/* Same as above, but returns the number of written digits, instead of 0 */ +ssize_t OBJECT_IDENTIFIER__dump_arc(uint8_t *arcbuf, int arclen, int add, + asn_app_consume_bytes_f *cb, void *app_key); + +/* + * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363"). + * No arc can exceed the (0..signed_long_max) range (typically, 0..2G if L32). + * This function is not specific to OBJECT IDENTIFIER, it may be used to parse + * the RELATIVE-OID data, or any other data consisting of dot-separated + * series of numeric values. + * + * If (oid_txt_length == -1), the strlen() will be invoked to determine the + * size of the (oid_text) string. + * + * After return, the optional (opt_oid_text_end) is set to the character after + * the last parsed one. (opt_oid_text_end) is never less than (oid_text). + * + * RETURN VALUES: + * -1: Parse error. + * >= 0: Number of arcs contained in the OBJECT IDENTIFIER. + * + * WARNING: The function always returns the real number of arcs, + * even if there is no sufficient (_arc_slots) provided. + * This is useful for (_arc_slots) value estimation. + */ +int OBJECT_IDENTIFIER_parse_arcs(const char *oid_text, ssize_t oid_txt_length, + long arcs[], unsigned int arcs_slots, const char **opt_oid_text_end); + +/* + * Internal functions. + * Used by RELATIVE-OID implementation in particular. + */ +int OBJECT_IDENTIFIER_get_single_arc(uint8_t *arcbuf, unsigned int arclen, + signed int add, void *value, unsigned int value_size); +int OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, + const void *arcval, unsigned int arcval_size, int _prepared_order); + +#ifdef __cplusplus +} +#endif + +#endif /* _OBJECT_IDENTIFIER_H_ */ diff --git a/stglibs/smux.lib/include/stg/OCTET_STRING.h b/stglibs/smux.lib/include/stg/OCTET_STRING.h new file mode 100644 index 00000000..5150161a --- /dev/null +++ b/stglibs/smux.lib/include/stg/OCTET_STRING.h @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2003 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _OCTET_STRING_H_ +#define _OCTET_STRING_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct OCTET_STRING { + uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */ + int size; /* Size of the buffer */ + + asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */ +} OCTET_STRING_t; + +extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING; + +asn_struct_free_f OCTET_STRING_free; +asn_struct_print_f OCTET_STRING_print; +asn_struct_print_f OCTET_STRING_print_utf8; +ber_type_decoder_f OCTET_STRING_decode_ber; +der_type_encoder_f OCTET_STRING_encode_der; +xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */ +xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */ +xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */ +xer_type_encoder_f OCTET_STRING_encode_xer; +xer_type_encoder_f OCTET_STRING_encode_xer_utf8; +per_type_decoder_f OCTET_STRING_decode_uper; +per_type_encoder_f OCTET_STRING_encode_uper; + +/****************************** + * Handy conversion routines. * + ******************************/ + +/* + * This function clears the previous value of the OCTET STRING (if any) + * and then allocates a new memory with the specified content (str/size). + * If size = -1, the size of the original string will be determined + * using strlen(str). + * If str equals to NULL, the function will silently clear the + * current contents of the OCTET STRING. + * Returns 0 if it was possible to perform operation, -1 otherwise. + */ +int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size); + +/* Handy conversion from the C string into the OCTET STRING. */ +#define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1) + +/* + * Allocate and fill the new OCTET STRING and return a pointer to the newly + * allocated object. NULL is permitted in str: the function will just allocate + * empty OCTET STRING. + */ +OCTET_STRING_t *OCTET_STRING_new_fromBuf(asn_TYPE_descriptor_t *td, + const char *str, int size); + +/**************************** + * Internally useful stuff. * + ****************************/ + +typedef struct asn_OCTET_STRING_specifics_s { + /* + * Target structure description. + */ + int struct_size; /* Size of the structure */ + int ctx_offset; /* Offset of the asn_struct_ctx_t member */ + + int subvariant; /* {0,1,2} for O-S, BIT STRING or ANY */ +} asn_OCTET_STRING_specifics_t; + +#ifdef __cplusplus +} +#endif + +#endif /* _OCTET_STRING_H_ */ diff --git a/stglibs/smux.lib/include/stg/ObjectName.h b/stglibs/smux.lib/include/stg/ObjectName.h new file mode 100644 index 00000000..256577b3 --- /dev/null +++ b/stglibs/smux.lib/include/stg/ObjectName.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _ObjectName_H_ +#define _ObjectName_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* ObjectName */ +typedef OBJECT_IDENTIFIER_t ObjectName_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_ObjectName; +asn_struct_free_f ObjectName_free; +asn_struct_print_f ObjectName_print; +asn_constr_check_f ObjectName_constraint; +ber_type_decoder_f ObjectName_decode_ber; +der_type_encoder_f ObjectName_encode_der; +xer_type_decoder_f ObjectName_decode_xer; +xer_type_encoder_f ObjectName_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _ObjectName_H_ */ diff --git a/stglibs/smux.lib/include/stg/ObjectSyntax.h b/stglibs/smux.lib/include/stg/ObjectSyntax.h new file mode 100644 index 00000000..9030accb --- /dev/null +++ b/stglibs/smux.lib/include/stg/ObjectSyntax.h @@ -0,0 +1,49 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _ObjectSyntax_H_ +#define _ObjectSyntax_H_ + + +#include + +/* Including external dependencies */ +#include "SimpleSyntax.h" +#include "ApplicationSyntax.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum ObjectSyntax_PR { + ObjectSyntax_PR_NOTHING, /* No components present */ + ObjectSyntax_PR_simple, + ObjectSyntax_PR_application_wide +} ObjectSyntax_PR; + +/* ObjectSyntax */ +typedef struct ObjectSyntax { + ObjectSyntax_PR present; + union ObjectSyntax_u { + SimpleSyntax_t simple; + ApplicationSyntax_t application_wide; + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} ObjectSyntax_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_ObjectSyntax; + +#ifdef __cplusplus +} +#endif + +#endif /* _ObjectSyntax_H_ */ diff --git a/stglibs/smux.lib/include/stg/Opaque.h b/stglibs/smux.lib/include/stg/Opaque.h new file mode 100644 index 00000000..aa8e2d5f --- /dev/null +++ b/stglibs/smux.lib/include/stg/Opaque.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _Opaque_H_ +#define _Opaque_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Opaque */ +typedef OCTET_STRING_t Opaque_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Opaque; +asn_struct_free_f Opaque_free; +asn_struct_print_f Opaque_print; +asn_constr_check_f Opaque_constraint; +ber_type_decoder_f Opaque_decode_ber; +der_type_encoder_f Opaque_encode_der; +xer_type_decoder_f Opaque_decode_xer; +xer_type_encoder_f Opaque_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _Opaque_H_ */ diff --git a/stglibs/smux.lib/include/stg/OpenPDU.h b/stglibs/smux.lib/include/stg/OpenPDU.h new file mode 100644 index 00000000..5d7e1da6 --- /dev/null +++ b/stglibs/smux.lib/include/stg/OpenPDU.h @@ -0,0 +1,46 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "SMUX" + * found in "SMUX.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _OpenPDU_H_ +#define _OpenPDU_H_ + + +#include + +/* Including external dependencies */ +#include "SimpleOpen.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum OpenPDU_PR { + OpenPDU_PR_NOTHING, /* No components present */ + OpenPDU_PR_simple +} OpenPDU_PR; + +/* OpenPDU */ +typedef struct OpenPDU { + OpenPDU_PR present; + union OpenPDU_u { + SimpleOpen_t simple; + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} OpenPDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_OpenPDU; + +#ifdef __cplusplus +} +#endif + +#endif /* _OpenPDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/PDU.h b/stglibs/smux.lib/include/stg/PDU.h new file mode 100644 index 00000000..cbc7e714 --- /dev/null +++ b/stglibs/smux.lib/include/stg/PDU.h @@ -0,0 +1,51 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _PDU_H_ +#define _PDU_H_ + + +#include + +/* Including external dependencies */ +#include +#include "VarBindList.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum PDU__error_status { + PDU__error_status_noError = 0, + PDU__error_status_tooBig = 1, + PDU__error_status_noSuchName = 2, + PDU__error_status_badValue = 3, + PDU__error_status_readOnly = 4, + PDU__error_status_genErr = 5 +} e_PDU__error_status; + +/* PDU */ +typedef struct PDU { + INTEGER_t request_id; + INTEGER_t error_status; + INTEGER_t error_index; + VarBindList_t variable_bindings; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} PDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_PDU; + +#ifdef __cplusplus +} +#endif + +#endif /* _PDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/PDUs.h b/stglibs/smux.lib/include/stg/PDUs.h new file mode 100644 index 00000000..90bb089f --- /dev/null +++ b/stglibs/smux.lib/include/stg/PDUs.h @@ -0,0 +1,58 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _PDUs_H_ +#define _PDUs_H_ + + +#include + +/* Including external dependencies */ +#include "GetRequest-PDU.h" +#include "GetNextRequest-PDU.h" +#include "GetResponse-PDU.h" +#include "SetRequest-PDU.h" +#include "Trap-PDU.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum PDUs_PR { + PDUs_PR_NOTHING, /* No components present */ + PDUs_PR_get_request, + PDUs_PR_get_next_request, + PDUs_PR_get_response, + PDUs_PR_set_request, + PDUs_PR_trap +} PDUs_PR; + +/* PDUs */ +typedef struct PDUs { + PDUs_PR present; + union PDUs_u { + GetRequest_PDU_t get_request; + GetNextRequest_PDU_t get_next_request; + GetResponse_PDU_t get_response; + SetRequest_PDU_t set_request; + Trap_PDU_t trap; + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} PDUs_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_PDUs; + +#ifdef __cplusplus +} +#endif + +#endif /* _PDUs_H_ */ diff --git a/stglibs/smux.lib/include/stg/PhysAddress.h b/stglibs/smux.lib/include/stg/PhysAddress.h new file mode 100644 index 00000000..d6c5fa17 --- /dev/null +++ b/stglibs/smux.lib/include/stg/PhysAddress.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _PhysAddress_H_ +#define _PhysAddress_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* PhysAddress */ +typedef OCTET_STRING_t PhysAddress_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_PhysAddress; +asn_struct_free_f PhysAddress_free; +asn_struct_print_f PhysAddress_print; +asn_constr_check_f PhysAddress_constraint; +ber_type_decoder_f PhysAddress_decode_ber; +der_type_encoder_f PhysAddress_encode_der; +xer_type_decoder_f PhysAddress_decode_xer; +xer_type_encoder_f PhysAddress_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _PhysAddress_H_ */ diff --git a/stglibs/smux.lib/include/stg/RReqPDU.h b/stglibs/smux.lib/include/stg/RReqPDU.h new file mode 100644 index 00000000..17f53094 --- /dev/null +++ b/stglibs/smux.lib/include/stg/RReqPDU.h @@ -0,0 +1,48 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "SMUX" + * found in "SMUX.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _RReqPDU_H_ +#define _RReqPDU_H_ + + +#include + +/* Including external dependencies */ +#include "ObjectName.h" +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum RReqPDU__operation { + RReqPDU__operation_delete = 0, + RReqPDU__operation_readOnly = 1, + RReqPDU__operation_readWrite = 2 +} e_RReqPDU__operation; + +/* RReqPDU */ +typedef struct RReqPDU { + ObjectName_t subtree; + long priority; + INTEGER_t operation; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} RReqPDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_RReqPDU; + +#ifdef __cplusplus +} +#endif + +#endif /* _RReqPDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/RRspPDU.h b/stglibs/smux.lib/include/stg/RRspPDU.h new file mode 100644 index 00000000..0d9681ac --- /dev/null +++ b/stglibs/smux.lib/include/stg/RRspPDU.h @@ -0,0 +1,43 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "SMUX" + * found in "SMUX.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _RRspPDU_H_ +#define _RRspPDU_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum RRspPDU { + RRspPDU_failure = -1 +} e_RRspPDU; + +/* RRspPDU */ +typedef INTEGER_t RRspPDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_RRspPDU; +asn_struct_free_f RRspPDU_free; +asn_struct_print_f RRspPDU_print; +asn_constr_check_f RRspPDU_constraint; +ber_type_decoder_f RRspPDU_decode_ber; +der_type_encoder_f RRspPDU_encode_der; +xer_type_decoder_f RRspPDU_decode_xer; +xer_type_encoder_f RRspPDU_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _RRspPDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/SMUX-PDUs.h b/stglibs/smux.lib/include/stg/SMUX-PDUs.h new file mode 100644 index 00000000..84893249 --- /dev/null +++ b/stglibs/smux.lib/include/stg/SMUX-PDUs.h @@ -0,0 +1,61 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "SMUX" + * found in "SMUX.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _SMUX_PDUs_H_ +#define _SMUX_PDUs_H_ + + +#include + +/* Including external dependencies */ +#include "OpenPDU.h" +#include "ClosePDU.h" +#include "RReqPDU.h" +#include "RRspPDU.h" +#include "PDUs.h" +#include "SOutPDU.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum SMUX_PDUs_PR { + SMUX_PDUs_PR_NOTHING, /* No components present */ + SMUX_PDUs_PR_open, + SMUX_PDUs_PR_close, + SMUX_PDUs_PR_registerRequest, + SMUX_PDUs_PR_registerResponse, + SMUX_PDUs_PR_pdus, + SMUX_PDUs_PR_commitOrRollback +} SMUX_PDUs_PR; + +/* SMUX-PDUs */ +typedef struct SMUX_PDUs { + SMUX_PDUs_PR present; + union SMUX_PDUs_u { + OpenPDU_t open; + ClosePDU_t close; + RReqPDU_t registerRequest; + RRspPDU_t registerResponse; + PDUs_t pdus; + SOutPDU_t commitOrRollback; + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} SMUX_PDUs_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_SMUX_PDUs; + +#ifdef __cplusplus +} +#endif + +#endif /* _SMUX_PDUs_H_ */ diff --git a/stglibs/smux.lib/include/stg/SOutPDU.h b/stglibs/smux.lib/include/stg/SOutPDU.h new file mode 100644 index 00000000..55e76185 --- /dev/null +++ b/stglibs/smux.lib/include/stg/SOutPDU.h @@ -0,0 +1,44 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "SMUX" + * found in "SMUX.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _SOutPDU_H_ +#define _SOutPDU_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum SOutPDU { + SOutPDU_commit = 0, + SOutPDU_rollback = 1 +} e_SOutPDU; + +/* SOutPDU */ +typedef INTEGER_t SOutPDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_SOutPDU; +asn_struct_free_f SOutPDU_free; +asn_struct_print_f SOutPDU_print; +asn_constr_check_f SOutPDU_constraint; +ber_type_decoder_f SOutPDU_decode_ber; +der_type_encoder_f SOutPDU_encode_der; +xer_type_decoder_f SOutPDU_decode_xer; +xer_type_encoder_f SOutPDU_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _SOutPDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/SetRequest-PDU.h b/stglibs/smux.lib/include/stg/SetRequest-PDU.h new file mode 100644 index 00000000..8854574c --- /dev/null +++ b/stglibs/smux.lib/include/stg/SetRequest-PDU.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _SetRequest_PDU_H_ +#define _SetRequest_PDU_H_ + + +#include + +/* Including external dependencies */ +#include "PDU.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* SetRequest-PDU */ +typedef PDU_t SetRequest_PDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_SetRequest_PDU; +asn_struct_free_f SetRequest_PDU_free; +asn_struct_print_f SetRequest_PDU_print; +asn_constr_check_f SetRequest_PDU_constraint; +ber_type_decoder_f SetRequest_PDU_decode_ber; +der_type_encoder_f SetRequest_PDU_encode_der; +xer_type_decoder_f SetRequest_PDU_decode_xer; +xer_type_encoder_f SetRequest_PDU_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _SetRequest_PDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/SimpleOpen.h b/stglibs/smux.lib/include/stg/SimpleOpen.h new file mode 100644 index 00000000..5950a6c1 --- /dev/null +++ b/stglibs/smux.lib/include/stg/SimpleOpen.h @@ -0,0 +1,48 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "SMUX" + * found in "SMUX.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _SimpleOpen_H_ +#define _SimpleOpen_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include "DisplayString.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum SimpleOpen__version { + SimpleOpen__version_version_1 = 0 +} e_SimpleOpen__version; + +/* SimpleOpen */ +typedef struct SimpleOpen { + INTEGER_t version; + OBJECT_IDENTIFIER_t identity; + DisplayString_t description; + OCTET_STRING_t password; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} SimpleOpen_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_SimpleOpen; + +#ifdef __cplusplus +} +#endif + +#endif /* _SimpleOpen_H_ */ diff --git a/stglibs/smux.lib/include/stg/SimpleSyntax.h b/stglibs/smux.lib/include/stg/SimpleSyntax.h new file mode 100644 index 00000000..c04f3ab2 --- /dev/null +++ b/stglibs/smux.lib/include/stg/SimpleSyntax.h @@ -0,0 +1,55 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _SimpleSyntax_H_ +#define _SimpleSyntax_H_ + + +#include + +/* Including external dependencies */ +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum SimpleSyntax_PR { + SimpleSyntax_PR_NOTHING, /* No components present */ + SimpleSyntax_PR_number, + SimpleSyntax_PR_string, + SimpleSyntax_PR_object, + SimpleSyntax_PR_empty +} SimpleSyntax_PR; + +/* SimpleSyntax */ +typedef struct SimpleSyntax { + SimpleSyntax_PR present; + union SimpleSyntax_u { + INTEGER_t number; + OCTET_STRING_t string; + OBJECT_IDENTIFIER_t object; + NULL_t empty; + } choice; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} SimpleSyntax_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_SimpleSyntax; + +#ifdef __cplusplus +} +#endif + +#endif /* _SimpleSyntax_H_ */ diff --git a/stglibs/smux.lib/include/stg/TcpConnEntry.h b/stglibs/smux.lib/include/stg/TcpConnEntry.h new file mode 100644 index 00000000..3160e31f --- /dev/null +++ b/stglibs/smux.lib/include/stg/TcpConnEntry.h @@ -0,0 +1,43 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _TcpConnEntry_H_ +#define _TcpConnEntry_H_ + + +#include + +/* Including external dependencies */ +#include +#include "IpAddress.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* TcpConnEntry */ +typedef struct TcpConnEntry { + INTEGER_t tcpConnState; + IpAddress_t tcpConnLocalAddress; + long tcpConnLocalPort; + IpAddress_t tcpConnRemAddress; + long tcpConnRemPort; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} TcpConnEntry_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_TcpConnEntry; + +#ifdef __cplusplus +} +#endif + +#endif /* _TcpConnEntry_H_ */ diff --git a/stglibs/smux.lib/include/stg/TimeTicks.h b/stglibs/smux.lib/include/stg/TimeTicks.h new file mode 100644 index 00000000..ea92820f --- /dev/null +++ b/stglibs/smux.lib/include/stg/TimeTicks.h @@ -0,0 +1,38 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1155-SMI" + * found in "RFC1155-SMI.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _TimeTicks_H_ +#define _TimeTicks_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* TimeTicks */ +typedef INTEGER_t TimeTicks_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_TimeTicks; +asn_struct_free_f TimeTicks_free; +asn_struct_print_f TimeTicks_print; +asn_constr_check_f TimeTicks_constraint; +ber_type_decoder_f TimeTicks_decode_ber; +der_type_encoder_f TimeTicks_encode_der; +xer_type_decoder_f TimeTicks_decode_xer; +xer_type_encoder_f TimeTicks_encode_xer; + +#ifdef __cplusplus +} +#endif + +#endif /* _TimeTicks_H_ */ diff --git a/stglibs/smux.lib/include/stg/Trap-PDU.h b/stglibs/smux.lib/include/stg/Trap-PDU.h new file mode 100644 index 00000000..d8a89e11 --- /dev/null +++ b/stglibs/smux.lib/include/stg/Trap-PDU.h @@ -0,0 +1,57 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _Trap_PDU_H_ +#define _Trap_PDU_H_ + + +#include + +/* Including external dependencies */ +#include +#include "NetworkAddress.h" +#include +#include "TimeTicks.h" +#include "VarBindList.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Dependencies */ +typedef enum Trap_PDU__generic_trap { + Trap_PDU__generic_trap_coldStart = 0, + Trap_PDU__generic_trap_warmStart = 1, + Trap_PDU__generic_trap_linkDown = 2, + Trap_PDU__generic_trap_linkUp = 3, + Trap_PDU__generic_trap_authenticationFailure = 4, + Trap_PDU__generic_trap_egpNeighborLoss = 5, + Trap_PDU__generic_trap_enterpriseSpecific = 6 +} e_Trap_PDU__generic_trap; + +/* Trap-PDU */ +typedef struct Trap_PDU { + OBJECT_IDENTIFIER_t enterprise; + NetworkAddress_t agent_addr; + INTEGER_t generic_trap; + INTEGER_t specific_trap; + TimeTicks_t time_stamp; + VarBindList_t variable_bindings; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} Trap_PDU_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_Trap_PDU; + +#ifdef __cplusplus +} +#endif + +#endif /* _Trap_PDU_H_ */ diff --git a/stglibs/smux.lib/include/stg/UdpEntry.h b/stglibs/smux.lib/include/stg/UdpEntry.h new file mode 100644 index 00000000..e4a10264 --- /dev/null +++ b/stglibs/smux.lib/include/stg/UdpEntry.h @@ -0,0 +1,39 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1213-MIB" + * found in "RFC1213-MIB.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _UdpEntry_H_ +#define _UdpEntry_H_ + + +#include + +/* Including external dependencies */ +#include "IpAddress.h" +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* UdpEntry */ +typedef struct UdpEntry { + IpAddress_t udpLocalAddress; + long udpLocalPort; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} UdpEntry_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_UdpEntry; + +#ifdef __cplusplus +} +#endif + +#endif /* _UdpEntry_H_ */ diff --git a/stglibs/smux.lib/include/stg/VarBind.h b/stglibs/smux.lib/include/stg/VarBind.h new file mode 100644 index 00000000..63ecad5f --- /dev/null +++ b/stglibs/smux.lib/include/stg/VarBind.h @@ -0,0 +1,39 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _VarBind_H_ +#define _VarBind_H_ + + +#include + +/* Including external dependencies */ +#include "ObjectName.h" +#include "ObjectSyntax.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* VarBind */ +typedef struct VarBind { + ObjectName_t name; + ObjectSyntax_t value; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} VarBind_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_VarBind; + +#ifdef __cplusplus +} +#endif + +#endif /* _VarBind_H_ */ diff --git a/stglibs/smux.lib/include/stg/VarBindList.h b/stglibs/smux.lib/include/stg/VarBindList.h new file mode 100644 index 00000000..36ef1617 --- /dev/null +++ b/stglibs/smux.lib/include/stg/VarBindList.h @@ -0,0 +1,43 @@ +/* + * Generated by asn1c-0.9.21 (http://lionet.info/asn1c) + * From ASN.1 module "RFC1157-SNMP" + * found in "RFC1157-SNMP.asn1" + * `asn1c -fskeletons-copy` + */ + +#ifndef _VarBindList_H_ +#define _VarBindList_H_ + + +#include + +/* Including external dependencies */ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* Forward declarations */ +struct VarBind; + +/* VarBindList */ +typedef struct VarBindList { + A_SEQUENCE_OF(struct VarBind) list; + + /* Context for parsing across buffer boundaries */ + asn_struct_ctx_t _asn_ctx; +} VarBindList_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_VarBindList; + +#ifdef __cplusplus +} +#endif + +/* Referred external types */ +#include "VarBind.h" + +#endif /* _VarBindList_H_ */ diff --git a/stglibs/smux.lib/include/stg/asn_SEQUENCE_OF.h b/stglibs/smux.lib/include/stg/asn_SEQUENCE_OF.h new file mode 100644 index 00000000..e678f034 --- /dev/null +++ b/stglibs/smux.lib/include/stg/asn_SEQUENCE_OF.h @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_SEQUENCE_OF_H +#define ASN_SEQUENCE_OF_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * SEQUENCE OF is the same as SET OF with a tiny difference: + * the delete operation preserves the initial order of elements + * and thus MAY operate in non-constant time. + */ +#define A_SEQUENCE_OF(type) A_SET_OF(type) + +#define ASN_SEQUENCE_ADD(headptr, ptr) \ + asn_sequence_add((headptr), (ptr)) + +/*********************************************** + * Implementation of the SEQUENCE OF structure. + */ + +#define asn_sequence_add asn_set_add +#define asn_sequence_empty asn_set_empty + +/* + * Delete the element from the set by its number (base 0). + * This is NOT a constant-time operation. + * The order of elements is preserved. + * If _do_free is given AND the (*free) is initialized, the element + * will be freed using the custom (*free) function as well. + */ +void asn_sequence_del(void *asn_sequence_of_x, int number, int _do_free); + +/* + * Cope with different conversions requirements to/from void in C and C++. + * This is mostly useful for support library. + */ +typedef A_SEQUENCE_OF(void) asn_anonymous_sequence_; +#define _A_SEQUENCE_FROM_VOID(ptr) ((asn_anonymous_sequence_ *)(ptr)) +#define _A_CSEQUENCE_FROM_VOID(ptr) ((const asn_anonymous_sequence_ *)(ptr)) + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_SEQUENCE_OF_H */ diff --git a/stglibs/smux.lib/include/stg/asn_SET_OF.h b/stglibs/smux.lib/include/stg/asn_SET_OF.h new file mode 100644 index 00000000..7edf14b5 --- /dev/null +++ b/stglibs/smux.lib/include/stg/asn_SET_OF.h @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_SET_OF_H +#define ASN_SET_OF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define A_SET_OF(type) \ + struct { \ + type **array; \ + int count; /* Meaningful size */ \ + int size; /* Allocated size */ \ + void (*free)(type *); \ + } + +#define ASN_SET_ADD(headptr, ptr) \ + asn_set_add((headptr), (ptr)) + +/******************************************* + * Implementation of the SET OF structure. + */ + +/* + * Add another structure into the set by its pointer. + * RETURN VALUES: + * 0 for success and -1/errno for failure. + */ +int asn_set_add(void *asn_set_of_x, void *ptr); + +/* + * Delete the element from the set by its number (base 0). + * This is a constant-time operation. The order of elements before the + * deleted ones is guaranteed, the order of elements after the deleted + * one is NOT guaranteed. + * If _do_free is given AND the (*free) is initialized, the element + * will be freed using the custom (*free) function as well. + */ +void asn_set_del(void *asn_set_of_x, int number, int _do_free); + +/* + * Empty the contents of the set. Will free the elements, if (*free) is given. + * Will NOT free the set itself. + */ +void asn_set_empty(void *asn_set_of_x); + +/* + * Cope with different conversions requirements to/from void in C and C++. + * This is mostly useful for support library. + */ +typedef A_SET_OF(void) asn_anonymous_set_; +#define _A_SET_FROM_VOID(ptr) ((asn_anonymous_set_ *)(ptr)) +#define _A_CSET_FROM_VOID(ptr) ((const asn_anonymous_set_ *)(ptr)) + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_SET_OF_H */ diff --git a/stglibs/smux.lib/include/stg/asn_application.h b/stglibs/smux.lib/include/stg/asn_application.h new file mode 100644 index 00000000..f40cd86a --- /dev/null +++ b/stglibs/smux.lib/include/stg/asn_application.h @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2004, 2006 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * Application-level ASN.1 callbacks. + */ +#ifndef _ASN_APPLICATION_H_ +#define _ASN_APPLICATION_H_ + +#include "asn_system.h" /* for platform-dependent types */ +#include "asn_codecs.h" /* for ASN.1 codecs specifics */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Generic type of an application-defined callback to return various + * types of data to the application. + * EXPECTED RETURN VALUES: + * -1: Failed to consume bytes. Abort the mission. + * Non-negative return values indicate success, and ignored. + */ +typedef int (asn_app_consume_bytes_f)(const void *buffer, size_t size, + void *application_specific_key); + +/* + * A callback of this type is called whenever constraint validation fails + * on some ASN.1 type. See "constraints.h" for more details on constraint + * validation. + * This callback specifies a descriptor of the ASN.1 type which failed + * the constraint check, as well as human readable message on what + * particular constraint has failed. + */ +typedef void (asn_app_constraint_failed_f)(void *application_specific_key, + struct asn_TYPE_descriptor_s *type_descriptor_which_failed, + const void *structure_which_failed_ptr, + const char *error_message_format, ...) GCC_PRINTFLIKE(4, 5); + +#ifdef __cplusplus +} +#endif + +#include "constr_TYPE.h" /* for asn_TYPE_descriptor_t */ + +#endif /* _ASN_APPLICATION_H_ */ diff --git a/stglibs/smux.lib/include/stg/asn_codecs.h b/stglibs/smux.lib/include/stg/asn_codecs.h new file mode 100644 index 00000000..4a251d94 --- /dev/null +++ b/stglibs/smux.lib/include/stg/asn_codecs.h @@ -0,0 +1,109 @@ +/*- + * Copyright (c) 2003, 2004, 2005 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _ASN_CODECS_H_ +#define _ASN_CODECS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * This structure defines a set of parameters that may be passed + * to every ASN.1 encoder or decoder function. + * WARNING: if max_stack_size member is set, and you are calling the + * function pointers of the asn_TYPE_descriptor_t directly, + * this structure must be ALLOCATED ON THE STACK! + * If you can't always satisfy this requirement, use ber_decode(), + * xer_decode() and uper_decode() functions instead. + */ +typedef struct asn_codec_ctx_s { + /* + * Limit the decoder routines to use no (much) more stack than a given + * number of bytes. Most of decoders are stack-based, and this + * would protect against stack overflows if the number of nested + * encodings is high. + * The OCTET STRING, BIT STRING and ANY BER decoders are heap-based, + * and are safe from this kind of overflow. + * A value from getrlimit(RLIMIT_STACK) may be used to initialize + * this variable. Be careful in multithreaded environments, as the + * stack size is rather limited. + */ + size_t max_stack_size; /* 0 disables stack bounds checking */ +} asn_codec_ctx_t; + +/* + * Type of the return value of the encoding functions (der_encode, xer_encode). + */ +typedef struct asn_enc_rval_s { + /* + * Number of bytes encoded. + * -1 indicates failure to encode the structure. + * In this case, the members below this one are meaningful. + */ + ssize_t encoded; + + /* + * Members meaningful when (encoded == -1), for post mortem analysis. + */ + + /* Type which cannot be encoded */ + struct asn_TYPE_descriptor_s *failed_type; + + /* Pointer to the structure of that type */ + void *structure_ptr; +} asn_enc_rval_t; +#define _ASN_ENCODE_FAILED do { \ + asn_enc_rval_t tmp_error; \ + tmp_error.encoded = -1; \ + tmp_error.failed_type = td; \ + tmp_error.structure_ptr = sptr; \ + ASN_DEBUG("Failed to encode element %s", td->name); \ + return tmp_error; \ +} while(0) +#define _ASN_ENCODED_OK(rval) do { \ + rval.structure_ptr = 0; \ + rval.failed_type = 0; \ + return rval; \ +} while(0) + +/* + * Type of the return value of the decoding functions (ber_decode, xer_decode) + * + * Please note that the number of consumed bytes is ALWAYS meaningful, + * even if code==RC_FAIL. This is to indicate the number of successfully + * decoded bytes, hence providing a possibility to fail with more diagnostics + * (i.e., print the offending remainder of the buffer). + */ +enum asn_dec_rval_code_e { + RC_OK, /* Decoded successfully */ + RC_WMORE, /* More data expected, call again */ + RC_FAIL /* Failure to decode data */ +}; +typedef struct asn_dec_rval_s { + enum asn_dec_rval_code_e code; /* Result code */ + size_t consumed; /* Number of bytes consumed */ +} asn_dec_rval_t; +#define _ASN_DECODE_FAILED do { \ + asn_dec_rval_t tmp_error; \ + tmp_error.code = RC_FAIL; \ + tmp_error.consumed = 0; \ + ASN_DEBUG("Failed to decode element %s", td->name); \ + return tmp_error; \ +} while(0) +#define _ASN_DECODE_STARVED do { \ + asn_dec_rval_t tmp_error; \ + tmp_error.code = RC_WMORE; \ + tmp_error.consumed = 0; \ + return tmp_error; \ +} while(0) + +#ifdef __cplusplus +} +#endif + +#endif /* _ASN_CODECS_H_ */ diff --git a/stglibs/smux.lib/include/stg/asn_codecs_prim.h b/stglibs/smux.lib/include/stg/asn_codecs_prim.h new file mode 100644 index 00000000..0f683fdd --- /dev/null +++ b/stglibs/smux.lib/include/stg/asn_codecs_prim.h @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_CODECS_PRIM_H +#define ASN_CODECS_PRIM_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ASN__PRIMITIVE_TYPE_s { + uint8_t *buf; /* Buffer with consecutive primitive encoding bytes */ + int size; /* Size of the buffer */ +} ASN__PRIMITIVE_TYPE_t; /* Do not use this type directly! */ + +asn_struct_free_f ASN__PRIMITIVE_TYPE_free; +ber_type_decoder_f ber_decode_primitive; +der_type_encoder_f der_encode_primitive; + +/* + * A callback specification for the xer_decode_primitive() function below. + */ +enum xer_pbd_rval { + XPBD_SYSTEM_FAILURE, /* System failure (memory shortage, etc) */ + XPBD_DECODER_LIMIT, /* Hit some decoder limitation or deficiency */ + XPBD_BROKEN_ENCODING, /* Encoding of a primitive body is broken */ + XPBD_NOT_BODY_IGNORE, /* Not a body format, but safe to ignore */ + XPBD_BODY_CONSUMED /* Body is recognized and consumed */ +}; +typedef enum xer_pbd_rval (xer_primitive_body_decoder_f) + (asn_TYPE_descriptor_t *td, void *struct_ptr, + const void *chunk_buf, size_t chunk_size); + +/* + * Specific function to decode simple primitive types. + * Also see xer_decode_general() in xer_decoder.h + */ +asn_dec_rval_t xer_decode_primitive(asn_codec_ctx_t *opt_codec_ctx, + asn_TYPE_descriptor_t *type_descriptor, + void **struct_ptr, size_t struct_size, + const char *opt_mname, + const void *buf_ptr, size_t size, + xer_primitive_body_decoder_f *prim_body_decoder +); + +#ifdef __cplusplus +} +#endif + +#endif /* ASN_CODECS_PRIM_H */ diff --git a/stglibs/smux.lib/include/stg/asn_internal.h b/stglibs/smux.lib/include/stg/asn_internal.h new file mode 100644 index 00000000..67f055a6 --- /dev/null +++ b/stglibs/smux.lib/include/stg/asn_internal.h @@ -0,0 +1,111 @@ +/*- + * Copyright (c) 2003, 2004, 2005 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * Declarations internally useful for the ASN.1 support code. + */ +#ifndef _ASN_INTERNAL_H_ +#define _ASN_INTERNAL_H_ + +#include "asn_application.h" /* Application-visible API */ + +#ifndef __NO_ASSERT_H__ /* Include assert.h only for internal use. */ +#include /* for assert() macro */ +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* Environment version might be used to avoid running with the old library */ +#define ASN1C_ENVIRONMENT_VERSION 920 /* Compile-time version */ +int get_asn1c_environment_version(void); /* Run-time version */ + +#define CALLOC(nmemb, size) calloc(nmemb, size) +#define MALLOC(size) malloc(size) +#define REALLOC(oldptr, size) realloc(oldptr, size) +#define FREEMEM(ptr) free(ptr) + +/* + * A macro for debugging the ASN.1 internals. + * You may enable or override it. + */ +#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */ +#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */ +#ifdef __GNUC__ +#define ASN_DEBUG(fmt, args...) do { \ + fprintf(stderr, fmt, ##args); \ + fprintf(stderr, " (%s:%d)\n", \ + __FILE__, __LINE__); \ + } while(0) +#else /* !__GNUC__ */ +void ASN_DEBUG_f(const char *fmt, ...); +#define ASN_DEBUG ASN_DEBUG_f +#endif /* __GNUC__ */ +#else /* EMIT_ASN_DEBUG != 1 */ +static inline void ASN_DEBUG(const char *fmt, ...) { (void)fmt; } +#endif /* EMIT_ASN_DEBUG */ +#endif /* ASN_DEBUG */ + +/* + * Invoke the application-supplied callback and fail, if something is wrong. + */ +#define __ASN_E_cbc(buf, size) (cb((buf), (size), app_key) < 0) +#define _ASN_E_CALLBACK(foo) do { \ + if(foo) goto cb_failed; \ + } while(0) +#define _ASN_CALLBACK(buf, size) \ + _ASN_E_CALLBACK(__ASN_E_cbc(buf, size)) +#define _ASN_CALLBACK2(buf1, size1, buf2, size2) \ + _ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) || __ASN_E_cbc(buf2, size2)) +#define _ASN_CALLBACK3(buf1, size1, buf2, size2, buf3, size3) \ + _ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) \ + || __ASN_E_cbc(buf2, size2) \ + || __ASN_E_cbc(buf3, size3)) + +#define _i_ASN_TEXT_INDENT(nl, level) do { \ + int __level = (level); \ + int __nl = ((nl) != 0); \ + int __i; \ + if(__nl) _ASN_CALLBACK("\n", 1); \ + for(__i = 0; __i < __level; __i++) \ + _ASN_CALLBACK(" ", 4); \ + er.encoded += __nl + 4 * __level; \ +} while(0) + +#define _i_INDENT(nl) do { \ + int __i; \ + if((nl) && cb("\n", 1, app_key) < 0) return -1; \ + for(__i = 0; __i < ilevel; __i++) \ + if(cb(" ", 4, app_key) < 0) return -1; \ +} while(0) + +/* + * Check stack against overflow, if limit is set. + */ +#define _ASN_DEFAULT_STACK_MAX (30000) +static inline int +_ASN_STACK_OVERFLOW_CHECK(asn_codec_ctx_t *ctx) { + if(ctx && ctx->max_stack_size) { + + /* ctx MUST be allocated on the stack */ + ptrdiff_t usedstack = ((char *)ctx - (char *)&ctx); + if(usedstack > 0) usedstack = -usedstack; /* grows up! */ + + /* double negative required to avoid int wrap-around */ + if(usedstack < -(ptrdiff_t)ctx->max_stack_size) { + ASN_DEBUG("Stack limit %ld reached", + (long)ctx->max_stack_size); + return -1; + } + } + return 0; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _ASN_INTERNAL_H_ */ diff --git a/stglibs/smux.lib/include/stg/asn_system.h b/stglibs/smux.lib/include/stg/asn_system.h new file mode 100644 index 00000000..d7ebdaa4 --- /dev/null +++ b/stglibs/smux.lib/include/stg/asn_system.h @@ -0,0 +1,104 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * Miscellaneous system-dependent types. + */ +#ifndef _ASN_SYSTEM_H_ +#define _ASN_SYSTEM_H_ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include /* For snprintf(3) */ +#include /* For *alloc(3) */ +#include /* For memcpy(3) */ +#include /* For size_t */ +#include /* For va_start */ +#include /* for offsetof and ptrdiff_t */ + +#ifdef WIN32 + +#include +#include +#define snprintf _snprintf +#define vsnprintf _vsnprintf + +#ifdef _MSC_VER /* MSVS.Net */ +#ifndef __cplusplus +#define inline __inline +#endif +#define ssize_t SSIZE_T +typedef char int8_t; +typedef short int16_t; +typedef int int32_t; +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; +#define WIN32_LEAN_AND_MEAN +#include +#include +#define isnan _isnan +#define finite _finite +#define copysign _copysign +#define ilogb _logb +#endif /* _MSC_VER */ + +#else /* !WIN32 */ + +#if defined(__vxworks) +#include +#else /* !defined(__vxworks) */ + +#include /* C99 specifies this file */ +/* + * 1. Earlier FreeBSD version didn't have , + * but was present. + * 2. Sun Solaris requires for alloca(3), + * but does not have . + */ +#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_)) +#if defined(sun) +#include /* For alloca(3) */ +#include /* for finite(3) */ +#elif defined(__hpux) +#ifdef __GNUC__ +#include /* For alloca(3) */ +#else /* !__GNUC__ */ +#define inline +#endif /* __GNUC__ */ +#else +#include /* SUSv2+ and C99 specify this file, for uintXX_t */ +#endif /* defined(sun) */ +#endif + +#endif /* defined(__vxworks) */ + +#endif /* WIN32 */ + +#if __GNUC__ >= 3 +#ifndef GCC_PRINTFLIKE +#define GCC_PRINTFLIKE(fmt,var) __attribute__((format(printf,fmt,var))) +#endif +#else +#ifndef GCC_PRINTFLIKE +#define GCC_PRINTFLIKE(fmt,var) /* nothing */ +#endif +#endif + +#ifndef offsetof /* If not defined by */ +#define offsetof(s, m) ((ptrdiff_t)&(((s *)0)->m) - (ptrdiff_t)((s *)0)) +#endif /* offsetof */ + +#ifndef MIN /* Suitable for comparing primitive types (integers) */ +#if defined(__GNUC__) +#define MIN(a,b) ({ __typeof a _a = a; __typeof b _b = b; \ + ((_a)<(_b)?(_a):(_b)); }) +#else /* !__GNUC__ */ +#define MIN(a,b) ((a)<(b)?(a):(b)) /* Unsafe variant */ +#endif /* __GNUC__ */ +#endif /* MIN */ + +#endif /* _ASN_SYSTEM_H_ */ diff --git a/stglibs/smux.lib/include/stg/ber_decoder.h b/stglibs/smux.lib/include/stg/ber_decoder.h new file mode 100644 index 00000000..768133b6 --- /dev/null +++ b/stglibs/smux.lib/include/stg/ber_decoder.h @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BER_DECODER_H_ +#define _BER_DECODER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ +struct asn_codec_ctx_s; /* Forward declaration */ + +/* + * The BER decoder of any type. + * This function may be invoked directly from the application. + */ +asn_dec_rval_t ber_decode(struct asn_codec_ctx_s *opt_codec_ctx, + struct asn_TYPE_descriptor_s *type_descriptor, + void **struct_ptr, /* Pointer to a target structure's pointer */ + const void *buffer, /* Data to be decoded */ + size_t size /* Size of that buffer */ + ); + +/* + * Type of generic function which decodes the byte stream into the structure. + */ +typedef asn_dec_rval_t (ber_type_decoder_f)( + struct asn_codec_ctx_s *opt_codec_ctx, + struct asn_TYPE_descriptor_s *type_descriptor, + void **struct_ptr, const void *buf_ptr, size_t size, + int tag_mode); + +/******************************* + * INTERNALLY USEFUL FUNCTIONS * + *******************************/ + +/* + * Check that all tags correspond to the type definition (as given in head). + * On return, last_length would contain either a non-negative length of the + * value part of the last TLV, or the negative number of expected + * "end of content" sequences. The number may only be negative if the + * head->last_tag_form is non-zero. + */ +asn_dec_rval_t ber_check_tags( + struct asn_codec_ctx_s *opt_codec_ctx, /* codec options */ + struct asn_TYPE_descriptor_s *type_descriptor, + asn_struct_ctx_t *opt_ctx, /* saved decoding context */ + const void *ptr, size_t size, + int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ + int last_tag_form, /* {-1,0:1}: any, primitive, constr */ + ber_tlv_len_t *last_length, + int *opt_tlv_form /* optional tag form */ + ); + +#ifdef __cplusplus +} +#endif + +#endif /* _BER_DECODER_H_ */ diff --git a/stglibs/smux.lib/include/stg/ber_tlv_length.h b/stglibs/smux.lib/include/stg/ber_tlv_length.h new file mode 100644 index 00000000..34968022 --- /dev/null +++ b/stglibs/smux.lib/include/stg/ber_tlv_length.h @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2003 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BER_TLV_LENGTH_H_ +#define _BER_TLV_LENGTH_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef ssize_t ber_tlv_len_t; + +/* + * This function tries to fetch the length of the BER TLV value and place it + * in *len_r. + * RETURN VALUES: + * 0: More data expected than bufptr contains. + * -1: Fatal error deciphering length. + * >0: Number of bytes used from bufptr. + * On return with >0, len_r is constrained as -1..MAX, where -1 mean + * that the value is of indefinite length. + */ +ssize_t ber_fetch_length(int _is_constructed, const void *bufptr, size_t size, + ber_tlv_len_t *len_r); + +/* + * This function expects bufptr to be positioned over L in TLV. + * It returns number of bytes occupied by L and V together, suitable + * for skipping. The function properly handles indefinite length. + * RETURN VALUES: + * Standard {-1,0,>0} convention. + */ +ssize_t ber_skip_length( + struct asn_codec_ctx_s *opt_codec_ctx, /* optional context */ + int _is_constructed, const void *bufptr, size_t size); + +/* + * This function serializes the length (L from TLV) in DER format. + * It always returns number of bytes necessary to represent the length, + * it is a caller's responsibility to check the return value + * against the supplied buffer's size. + */ +size_t der_tlv_length_serialize(ber_tlv_len_t len, void *bufptr, size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* _BER_TLV_LENGTH_H_ */ diff --git a/stglibs/smux.lib/include/stg/ber_tlv_tag.h b/stglibs/smux.lib/include/stg/ber_tlv_tag.h new file mode 100644 index 00000000..60e86686 --- /dev/null +++ b/stglibs/smux.lib/include/stg/ber_tlv_tag.h @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _BER_TLV_TAG_H_ +#define _BER_TLV_TAG_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +enum asn_tag_class { + ASN_TAG_CLASS_UNIVERSAL = 0, /* 0b00 */ + ASN_TAG_CLASS_APPLICATION = 1, /* 0b01 */ + ASN_TAG_CLASS_CONTEXT = 2, /* 0b10 */ + ASN_TAG_CLASS_PRIVATE = 3 /* 0b11 */ +}; +typedef unsigned ber_tlv_tag_t; /* BER TAG from Tag-Length-Value */ + +/* + * Tag class is encoded together with tag value for optimization purposes. + */ +#define BER_TAG_CLASS(tag) ((tag) & 0x3) +#define BER_TAG_VALUE(tag) ((tag) >> 2) +#define BER_TLV_CONSTRUCTED(tagptr) (((*(const uint8_t *)tagptr)&0x20)?1:0) + +#define BER_TAGS_EQUAL(tag1, tag2) ((tag1) == (tag2)) + +/* + * Several functions for printing the TAG in the canonical form + * (i.e. "[PRIVATE 0]"). + * Return values correspond to their libc counterparts (if any). + */ +ssize_t ber_tlv_tag_snprint(ber_tlv_tag_t tag, char *buf, size_t buflen); +ssize_t ber_tlv_tag_fwrite(ber_tlv_tag_t tag, FILE *); +char *ber_tlv_tag_string(ber_tlv_tag_t tag); + + +/* + * This function tries to fetch the tag from the input stream. + * RETURN VALUES: + * 0: More data expected than bufptr contains. + * -1: Fatal error deciphering tag. + * >0: Number of bytes used from bufptr. tag_r will contain the tag. + */ +ssize_t ber_fetch_tag(const void *bufptr, size_t size, ber_tlv_tag_t *tag_r); + +/* + * This function serializes the tag (T from TLV) in BER format. + * It always returns number of bytes necessary to represent the tag, + * it is a caller's responsibility to check the return value + * against the supplied buffer's size. + */ +size_t ber_tlv_tag_serialize(ber_tlv_tag_t tag, void *bufptr, size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* _BER_TLV_TAG_H_ */ diff --git a/stglibs/smux.lib/include/stg/constr_CHOICE.h b/stglibs/smux.lib/include/stg/constr_CHOICE.h new file mode 100644 index 00000000..83404e6d --- /dev/null +++ b/stglibs/smux.lib/include/stg/constr_CHOICE.h @@ -0,0 +1,57 @@ +/*- + * Copyright (c) 2003, 2004, 2005 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _CONSTR_CHOICE_H_ +#define _CONSTR_CHOICE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct asn_CHOICE_specifics_s { + /* + * Target structure description. + */ + int struct_size; /* Size of the target structure. */ + int ctx_offset; /* Offset of the asn_codec_ctx_t member */ + int pres_offset; /* Identifier of the present member */ + int pres_size; /* Size of the identifier (enum) */ + + /* + * Tags to members mapping table. + */ + asn_TYPE_tag2member_t *tag2el; + int tag2el_count; + + /* Canonical ordering of CHOICE elements, for PER */ + int *canonical_order; + + /* + * Extensions-related stuff. + */ + int ext_start; /* First member of extensions, or -1 */ +} asn_CHOICE_specifics_t; + +/* + * A set specialized functions dealing with the CHOICE type. + */ +asn_struct_free_f CHOICE_free; +asn_struct_print_f CHOICE_print; +asn_constr_check_f CHOICE_constraint; +ber_type_decoder_f CHOICE_decode_ber; +der_type_encoder_f CHOICE_encode_der; +xer_type_decoder_f CHOICE_decode_xer; +xer_type_encoder_f CHOICE_encode_xer; +per_type_decoder_f CHOICE_decode_uper; +per_type_encoder_f CHOICE_encode_uper; +asn_outmost_tag_f CHOICE_outmost_tag; + +#ifdef __cplusplus +} +#endif + +#endif /* _CONSTR_CHOICE_H_ */ diff --git a/stglibs/smux.lib/include/stg/constr_SEQUENCE.h b/stglibs/smux.lib/include/stg/constr_SEQUENCE.h new file mode 100644 index 00000000..5f589d5c --- /dev/null +++ b/stglibs/smux.lib/include/stg/constr_SEQUENCE.h @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _CONSTR_SEQUENCE_H_ +#define _CONSTR_SEQUENCE_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct asn_SEQUENCE_specifics_s { + /* + * Target structure description. + */ + int struct_size; /* Size of the target structure. */ + int ctx_offset; /* Offset of the asn_struct_ctx_t member */ + + /* + * Tags to members mapping table (sorted). + */ + asn_TYPE_tag2member_t *tag2el; + int tag2el_count; + + /* + * Optional members of the extensions root (roms) or additions (aoms). + * Meaningful for PER. + */ + int *oms; /* Optional MemberS */ + int roms_count; /* Root optional members count */ + int aoms_count; /* Additions optional members count */ + + /* + * Description of an extensions group. + */ + int ext_after; /* Extensions start after this member */ + int ext_before; /* Extensions stop before this member */ +} asn_SEQUENCE_specifics_t; + + +/* + * A set specialized functions dealing with the SEQUENCE type. + */ +asn_struct_free_f SEQUENCE_free; +asn_struct_print_f SEQUENCE_print; +asn_constr_check_f SEQUENCE_constraint; +ber_type_decoder_f SEQUENCE_decode_ber; +der_type_encoder_f SEQUENCE_encode_der; +xer_type_decoder_f SEQUENCE_decode_xer; +xer_type_encoder_f SEQUENCE_encode_xer; +per_type_decoder_f SEQUENCE_decode_uper; +per_type_encoder_f SEQUENCE_encode_uper; + +#ifdef __cplusplus +} +#endif + +#endif /* _CONSTR_SEQUENCE_H_ */ diff --git a/stglibs/smux.lib/include/stg/constr_SEQUENCE_OF.h b/stglibs/smux.lib/include/stg/constr_SEQUENCE_OF.h new file mode 100644 index 00000000..e2272f32 --- /dev/null +++ b/stglibs/smux.lib/include/stg/constr_SEQUENCE_OF.h @@ -0,0 +1,33 @@ +/*- + * Copyright (c) 2003, 2005 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _CONSTR_SEQUENCE_OF_H_ +#define _CONSTR_SEQUENCE_OF_H_ + +#include +#include /* Implemented using SET OF */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * A set specialized functions dealing with the SEQUENCE OF type. + * Generally implemented using SET OF. + */ +#define SEQUENCE_OF_free SET_OF_free +#define SEQUENCE_OF_print SET_OF_print +#define SEQUENCE_OF_constraint SET_OF_constraint +#define SEQUENCE_OF_decode_ber SET_OF_decode_ber +#define SEQUENCE_OF_decode_xer SET_OF_decode_xer +#define SEQUENCE_OF_decode_uper SET_OF_decode_uper +der_type_encoder_f SEQUENCE_OF_encode_der; +xer_type_encoder_f SEQUENCE_OF_encode_xer; +per_type_encoder_f SEQUENCE_OF_encode_uper; + +#ifdef __cplusplus +} +#endif + +#endif /* _CONSTR_SET_OF_H_ */ diff --git a/stglibs/smux.lib/include/stg/constr_SET_OF.h b/stglibs/smux.lib/include/stg/constr_SET_OF.h new file mode 100644 index 00000000..bcd09662 --- /dev/null +++ b/stglibs/smux.lib/include/stg/constr_SET_OF.h @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2003 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _CONSTR_SET_OF_H_ +#define _CONSTR_SET_OF_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct asn_SET_OF_specifics_s { + /* + * Target structure description. + */ + int struct_size; /* Size of the target structure. */ + int ctx_offset; /* Offset of the asn_struct_ctx_t member */ + + /* XER-specific stuff */ + int as_XMLValueList; /* The member type must be encoded like this */ +} asn_SET_OF_specifics_t; + +/* + * A set specialized functions dealing with the SET OF type. + */ +asn_struct_free_f SET_OF_free; +asn_struct_print_f SET_OF_print; +asn_constr_check_f SET_OF_constraint; +ber_type_decoder_f SET_OF_decode_ber; +der_type_encoder_f SET_OF_encode_der; +xer_type_decoder_f SET_OF_decode_xer; +xer_type_encoder_f SET_OF_encode_xer; +per_type_decoder_f SET_OF_decode_uper; +per_type_encoder_f SET_OF_encode_uper; + +#ifdef __cplusplus +} +#endif + +#endif /* _CONSTR_SET_OF_H_ */ diff --git a/stglibs/smux.lib/include/stg/constr_TYPE.h b/stglibs/smux.lib/include/stg/constr_TYPE.h new file mode 100644 index 00000000..95507c80 --- /dev/null +++ b/stglibs/smux.lib/include/stg/constr_TYPE.h @@ -0,0 +1,180 @@ +/*- + * Copyright (c) 2003, 2004, 2005, 2006 Lev Walkin . + * All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +/* + * This file contains the declaration structure called "ASN.1 Type Definition", + * which holds all information necessary for encoding and decoding routines. + * This structure even contains pointer to these encoding and decoding routines + * for each defined ASN.1 type. + */ +#ifndef _CONSTR_TYPE_H_ +#define _CONSTR_TYPE_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ +struct asn_TYPE_member_s; /* Forward declaration */ + +/* + * This type provides the context information for various ASN.1 routines, + * primarily ones doing decoding. A member _asn_ctx of this type must be + * included into certain target language's structures, such as compound types. + */ +typedef struct asn_struct_ctx_s { + short phase; /* Decoding phase */ + short step; /* Elementary step of a phase */ + int context; /* Other context information */ + void *ptr; /* Decoder-specific stuff (stack elements) */ + ber_tlv_len_t left; /* Number of bytes left, -1 for indefinite */ +} asn_struct_ctx_t; + +#include /* Basic Encoding Rules decoder */ +#include /* Distinguished Encoding Rules encoder */ +#include /* Decoder of XER (XML, text) */ +#include /* Encoder into XER (XML, text) */ +#include /* Packet Encoding Rules decoder */ +#include /* Packet Encoding Rules encoder */ +#include /* Subtype constraints support */ + +/* + * Free the structure according to its specification. + * If (free_contents_only) is set, the wrapper structure itself (struct_ptr) + * will not be freed. (It may be useful in case the structure is allocated + * statically or arranged on the stack, yet its elements are allocated + * dynamically.) + */ +typedef void (asn_struct_free_f)( + struct asn_TYPE_descriptor_s *type_descriptor, + void *struct_ptr, int free_contents_only); +#define ASN_STRUCT_FREE(asn_DEF, ptr) (asn_DEF).free_struct(&(asn_DEF),ptr,0) +#define ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF, ptr) \ + (asn_DEF).free_struct(&(asn_DEF),ptr,1) + +/* + * Print the structure according to its specification. + */ +typedef int (asn_struct_print_f)( + struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_ptr, + int level, /* Indentation level */ + asn_app_consume_bytes_f *callback, void *app_key); + +/* + * Return the outmost tag of the type. + * If the type is untagged CHOICE, the dynamic operation is performed. + * NOTE: This function pointer type is only useful internally. + * Do not use it in your application. + */ +typedef ber_tlv_tag_t (asn_outmost_tag_f)( + struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_ptr, int tag_mode, ber_tlv_tag_t tag); +/* The instance of the above function type; used internally. */ +asn_outmost_tag_f asn_TYPE_outmost_tag; + + +/* + * The definitive description of the destination language's structure. + */ +typedef struct asn_TYPE_descriptor_s { + char *name; /* A name of the ASN.1 type. "" in some cases. */ + char *xml_tag; /* Name used in XML tag */ + + /* + * Generalized functions for dealing with the specific type. + * May be directly invoked by applications. + */ + asn_struct_free_f *free_struct; /* Free the structure */ + asn_struct_print_f *print_struct; /* Human readable output */ + asn_constr_check_f *check_constraints; /* Constraints validator */ + ber_type_decoder_f *ber_decoder; /* Generic BER decoder */ + der_type_encoder_f *der_encoder; /* Canonical DER encoder */ + xer_type_decoder_f *xer_decoder; /* Generic XER decoder */ + xer_type_encoder_f *xer_encoder; /* [Canonical] XER encoder */ + per_type_decoder_f *uper_decoder; /* Unaligned PER decoder */ + per_type_encoder_f *uper_encoder; /* Unaligned PER encoder */ + + /*********************************************************************** + * Internally useful members. Not to be used by applications directly. * + **********************************************************************/ + + /* + * Tags that are expected to occur. + */ + asn_outmost_tag_f *outmost_tag; /* */ + ber_tlv_tag_t *tags; /* Effective tags sequence for this type */ + int tags_count; /* Number of tags which are expected */ + ber_tlv_tag_t *all_tags;/* Every tag for BER/containment */ + int all_tags_count; /* Number of tags */ + + asn_per_constraints_t *per_constraints; /* PER compiled constraints */ + + /* + * An ASN.1 production type members (members of SEQUENCE, SET, CHOICE). + */ + struct asn_TYPE_member_s *elements; + int elements_count; + + /* + * Additional information describing the type, used by appropriate + * functions above. + */ + void *specifics; +} asn_TYPE_descriptor_t; + +/* + * This type describes an element of the constructed type, + * i.e. SEQUENCE, SET, CHOICE, etc. + */ + enum asn_TYPE_flags_e { + ATF_NOFLAGS, + ATF_POINTER = 0x01, /* Represented by the pointer */ + ATF_OPEN_TYPE = 0x02 /* ANY type, without meaningful tag */ + }; +typedef struct asn_TYPE_member_s { + enum asn_TYPE_flags_e flags; /* Element's presentation flags */ + int optional; /* Following optional members, including current */ + int memb_offset; /* Offset of the element */ + ber_tlv_tag_t tag; /* Outmost (most immediate) tag */ + int tag_mode; /* IMPLICIT/no/EXPLICIT tag at current level */ + asn_TYPE_descriptor_t *type; /* Member type descriptor */ + asn_constr_check_f *memb_constraints; /* Constraints validator */ + asn_per_constraints_t *per_constraints; /* PER compiled constraints */ + int (*default_value)(int setval, void **sptr); /* DEFAULT */ + char *name; /* ASN.1 identifier of the element */ +} asn_TYPE_member_t; + +/* + * BER tag to element number mapping. + */ +typedef struct asn_TYPE_tag2member_s { + ber_tlv_tag_t el_tag; /* Outmost tag of the member */ + int el_no; /* Index of the associated member, base 0 */ + int toff_first; /* First occurence of the el_tag, relative */ + int toff_last; /* Last occurence of the el_tag, relatvie */ +} asn_TYPE_tag2member_t; + +/* + * This function is a wrapper around (td)->print_struct, which prints out + * the contents of the target language's structure (struct_ptr) into the + * file pointer (stream) in human readable form. + * RETURN VALUES: + * 0: The structure is printed. + * -1: Problem dumping the structure. + * (See also xer_fprint() in xer_encoder.h) + */ +int asn_fprint(FILE *stream, /* Destination stream descriptor */ + asn_TYPE_descriptor_t *td, /* ASN.1 type descriptor */ + const void *struct_ptr); /* Structure to be printed */ + +#ifdef __cplusplus +} +#endif + +#endif /* _CONSTR_TYPE_H_ */ diff --git a/stglibs/smux.lib/include/stg/constraints.h b/stglibs/smux.lib/include/stg/constraints.h new file mode 100644 index 00000000..5032345e --- /dev/null +++ b/stglibs/smux.lib/include/stg/constraints.h @@ -0,0 +1,63 @@ +/*- + * Copyright (c) 2004, 2006 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _ASN1_CONSTRAINTS_VALIDATOR_H_ +#define _ASN1_CONSTRAINTS_VALIDATOR_H_ + +#include /* Platform-dependent types */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * Validate the structure according to the ASN.1 constraints. + * If errbuf and errlen are given, they shall be pointing to the appropriate + * buffer space and its length before calling this function. Alternatively, + * they could be passed as NULL's. If constraints validation fails, + * errlen will contain the actual number of bytes taken from the errbuf + * to encode an error message (properly 0-terminated). + * + * RETURN VALUES: + * This function returns 0 in case all ASN.1 constraints are met + * and -1 if one or more constraints were failed. + */ +int +asn_check_constraints(struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_ptr, /* Target language's structure */ + char *errbuf, /* Returned error description */ + size_t *errlen /* Length of the error description */ + ); + + +/* + * Generic type for constraint checking callback, + * associated with every type descriptor. + */ +typedef int (asn_constr_check_f)( + struct asn_TYPE_descriptor_s *type_descriptor, + const void *struct_ptr, + asn_app_constraint_failed_f *optional_callback, /* Log the error */ + void *optional_app_key /* Opaque key passed to a callback */ + ); + +/******************************* + * INTERNALLY USEFUL FUNCTIONS * + *******************************/ + +asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */ +asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */ + +/* + * Invoke the callback with a complete error message. + */ +#define _ASN_CTFAIL if(ctfailcb) ctfailcb + +#ifdef __cplusplus +} +#endif + +#endif /* _ASN1_CONSTRAINTS_VALIDATOR_H_ */ diff --git a/stglibs/smux.lib/include/stg/der_encoder.h b/stglibs/smux.lib/include/stg/der_encoder.h new file mode 100644 index 00000000..4e2fb06c --- /dev/null +++ b/stglibs/smux.lib/include/stg/der_encoder.h @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _DER_ENCODER_H_ +#define _DER_ENCODER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * The DER encoder of any type. May be invoked by the application. + */ +asn_enc_rval_t der_encode(struct asn_TYPE_descriptor_s *type_descriptor, + void *struct_ptr, /* Structure to be encoded */ + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key /* Arbitrary callback argument */ + ); + +/* A variant of der_encode() which encodes data into the pre-allocated buffer */ +asn_enc_rval_t der_encode_to_buffer( + struct asn_TYPE_descriptor_s *type_descriptor, + void *struct_ptr, /* Structure to be encoded */ + void *buffer, /* Pre-allocated buffer */ + size_t buffer_size /* Initial buffer size (maximum) */ + ); + +/* + * Type of the generic DER encoder. + */ +typedef asn_enc_rval_t (der_type_encoder_f)( + struct asn_TYPE_descriptor_s *type_descriptor, + void *struct_ptr, /* Structure to be encoded */ + int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ + ber_tlv_tag_t tag, + asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ + void *app_key /* Arbitrary callback argument */ + ); + + +/******************************* + * INTERNALLY USEFUL FUNCTIONS * + *******************************/ + +/* + * Write out leading TL[v] sequence according to the type definition. + */ +ssize_t der_write_tags( + struct asn_TYPE_descriptor_s *type_descriptor, + size_t struct_length, + int tag_mode, /* {-1,0,1}: IMPLICIT, no, EXPLICIT */ + int last_tag_form, /* {0,!0}: prim, constructed */ + ber_tlv_tag_t tag, + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key + ); + +#ifdef __cplusplus +} +#endif + +#endif /* _DER_ENCODER_H_ */ diff --git a/stglibs/smux.lib/include/stg/per_decoder.h b/stglibs/smux.lib/include/stg/per_decoder.h new file mode 100644 index 00000000..26aaf594 --- /dev/null +++ b/stglibs/smux.lib/include/stg/per_decoder.h @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2005 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _PER_DECODER_H_ +#define _PER_DECODER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * Unaligned PER decoder of any ASN.1 type. May be invoked by the application. + */ +asn_dec_rval_t uper_decode(struct asn_codec_ctx_s *opt_codec_ctx, + struct asn_TYPE_descriptor_s *type_descriptor, /* Type to decode */ + void **struct_ptr, /* Pointer to a target structure's pointer */ + const void *buffer, /* Data to be decoded */ + size_t size, /* Size of data buffer */ + int skip_bits, /* Number of unused leading bits, 0..7 */ + int unused_bits /* Number of unused tailing bits, 0..7 */ + ); + + +/* + * Type of the type-specific PER decoder function. + */ +typedef asn_dec_rval_t (per_type_decoder_f)(asn_codec_ctx_t *opt_codec_ctx, + struct asn_TYPE_descriptor_s *type_descriptor, + asn_per_constraints_t *constraints, + void **struct_ptr, + asn_per_data_t *per_data + ); + +#ifdef __cplusplus +} +#endif + +#endif /* _PER_DECODER_H_ */ diff --git a/stglibs/smux.lib/include/stg/per_encoder.h b/stglibs/smux.lib/include/stg/per_encoder.h new file mode 100644 index 00000000..9ac130b7 --- /dev/null +++ b/stglibs/smux.lib/include/stg/per_encoder.h @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2006 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _PER_ENCODER_H_ +#define _PER_ENCODER_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * Unaligned PER encoder of any ASN.1 type. May be invoked by the application. + */ +asn_enc_rval_t uper_encode(struct asn_TYPE_descriptor_s *type_descriptor, + void *struct_ptr, /* Structure to be encoded */ + asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */ + void *app_key /* Arbitrary callback argument */ +); + +/* A variant of uper_encode() which encodes data into the existing buffer */ +asn_enc_rval_t uper_encode_to_buffer( + struct asn_TYPE_descriptor_s *type_descriptor, + void *struct_ptr, /* Structure to be encoded */ + void *buffer, /* Pre-allocated buffer */ + size_t buffer_size /* Initial buffer size (max) */ +); + + +/* + * Type of the generic PER encoder function. + */ +typedef asn_enc_rval_t (per_type_encoder_f)( + struct asn_TYPE_descriptor_s *type_descriptor, + asn_per_constraints_t *constraints, + void *struct_ptr, + asn_per_outp_t *per_output +); + +#ifdef __cplusplus +} +#endif + +#endif /* _PER_ENCODER_H_ */ diff --git a/stglibs/smux.lib/include/stg/per_support.h b/stglibs/smux.lib/include/stg/per_support.h new file mode 100644 index 00000000..420bb83c --- /dev/null +++ b/stglibs/smux.lib/include/stg/per_support.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2005, 2006 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _PER_SUPPORT_H_ +#define _PER_SUPPORT_H_ + +#include /* Platform-specific types */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Pre-computed PER constraints. + */ +typedef struct asn_per_constraint_s { + enum asn_per_constraint_flags { + APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */ + APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */ + APC_CONSTRAINED = 0x2, /* Fully constrained */ + APC_EXTENSIBLE = 0x4 /* May have extension */ + } flags; + int range_bits; /* Full number of bits in the range */ + int effective_bits; /* Effective bits */ + long lower_bound; /* "lb" value */ + long upper_bound; /* "ub" value */ +} asn_per_constraint_t; +typedef struct asn_per_constraints_s { + asn_per_constraint_t value; + asn_per_constraint_t size; +} asn_per_constraints_t; + +/* + * This structure describes a position inside an incoming PER bit stream. + */ +typedef struct asn_per_data_s { + const uint8_t *buffer; /* Pointer to the octet stream */ + size_t nboff; /* Bit offset to the meaningful bit */ + size_t nbits; /* Number of bits in the stream */ +} asn_per_data_t; + +/* + * Extract a small number of bits (<= 31) from the specified PER data pointer. + * This function returns -1 if the specified number of bits could not be + * extracted due to EOD or other conditions. + */ +int32_t per_get_few_bits(asn_per_data_t *per_data, int get_nbits); + +/* + * Extract a large number of bits from the specified PER data pointer. + * This function returns -1 if the specified number of bits could not be + * extracted due to EOD or other conditions. + */ +int per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int right_align, + int get_nbits); + +/* + * Get the length "n" from the Unaligned PER stream. + */ +ssize_t uper_get_length(asn_per_data_t *pd, + int effective_bound_bits, + int *repeat); + +/* + * Get the normally small non-negative whole number. + */ +ssize_t uper_get_nsnnwn(asn_per_data_t *pd); + +/* + * This structure supports forming PER output. + */ +typedef struct asn_per_outp_s { + uint8_t *buffer; /* Pointer into the (tmpspace) */ + size_t nboff; /* Bit offset to the meaningful bit */ + size_t nbits; /* Number of bits left in (tmpspace) */ + uint8_t tmpspace[32]; /* Preliminary storage to hold data */ + int (*outper)(const void *data, size_t size, void *op_key); + void *op_key; /* Key for (outper) data callback */ + size_t flushed_bytes; /* Bytes already flushed through (outper) */ +} asn_per_outp_t; + +/* Output a small number of bits (<= 31) */ +int per_put_few_bits(asn_per_outp_t *per_data, uint32_t bits, int obits); + +/* Output a large number of bits */ +int per_put_many_bits(asn_per_outp_t *po, const uint8_t *src, int put_nbits); + +/* + * Put the length "n" to the Unaligned PER stream. + * This function returns the number of units which may be flushed + * in the next units saving iteration. + */ +ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length); + +/* + * Put the normally small non-negative whole number. + */ +int uper_put_nsnnwn(asn_per_outp_t *po, int n); + +#ifdef __cplusplus +} +#endif + +#endif /* _PER_SUPPORT_H_ */ diff --git a/stglibs/smux.lib/include/stg/xer_decoder.h b/stglibs/smux.lib/include/stg/xer_decoder.h new file mode 100644 index 00000000..cf0d846f --- /dev/null +++ b/stglibs/smux.lib/include/stg/xer_decoder.h @@ -0,0 +1,106 @@ +/*- + * Copyright (c) 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _XER_DECODER_H_ +#define _XER_DECODER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* + * The XER decoder of any ASN.1 type. May be invoked by the application. + */ +asn_dec_rval_t xer_decode(struct asn_codec_ctx_s *opt_codec_ctx, + struct asn_TYPE_descriptor_s *type_descriptor, + void **struct_ptr, /* Pointer to a target structure's pointer */ + const void *buffer, /* Data to be decoded */ + size_t size /* Size of data buffer */ + ); + +/* + * Type of the type-specific XER decoder function. + */ +typedef asn_dec_rval_t (xer_type_decoder_f)(asn_codec_ctx_t *opt_codec_ctx, + struct asn_TYPE_descriptor_s *type_descriptor, + void **struct_ptr, + const char *opt_mname, /* Member name */ + const void *buf_ptr, size_t size + ); + +/******************************* + * INTERNALLY USEFUL FUNCTIONS * + *******************************/ + +/* + * Generalized function for decoding the primitive values. + * Used by more specialized functions, such as OCTET_STRING_decode_xer_utf8 + * and others. This function should not be used by applications, as its API + * is subject to changes. + */ +asn_dec_rval_t xer_decode_general(asn_codec_ctx_t *opt_codec_ctx, + asn_struct_ctx_t *ctx, /* Type decoder context */ + void *struct_key, /* Treated as opaque pointer */ + const char *xml_tag, /* Expected XML tag name */ + const void *buf_ptr, size_t size, + int (*opt_unexpected_tag_decoder) + (void *struct_key, const void *chunk_buf, size_t chunk_size), + ssize_t (*body_receiver) + (void *struct_key, const void *chunk_buf, size_t chunk_size, + int have_more) + ); + + +/* + * Fetch the next XER (XML) token from the stream. + * The function returns the number of bytes occupied by the chunk type, + * returned in the _ch_type. The _ch_type is only set (and valid) when + * the return value is greater than 0. + */ + typedef enum pxer_chunk_type { + PXER_TAG, /* Complete XER tag */ + PXER_TEXT, /* Plain text between XER tags */ + PXER_COMMENT /* A comment, may be part of */ + } pxer_chunk_type_e; +ssize_t xer_next_token(int *stateContext, + const void *buffer, size_t size, pxer_chunk_type_e *_ch_type); + +/* + * This function checks the buffer against the tag name is expected to occur. + */ + typedef enum xer_check_tag { + XCT_BROKEN = 0, /* The tag is broken */ + XCT_OPENING = 1, /* This is the tag */ + XCT_CLOSING = 2, /* This is the tag */ + XCT_BOTH = 3, /* This is the tag */ + XCT__UNK__MASK = 4, /* Mask of everything unexpected */ + XCT_UNKNOWN_OP = 5, /* Unexpected tag */ + XCT_UNKNOWN_CL = 6, /* Unexpected tag */ + XCT_UNKNOWN_BO = 7 /* Unexpected tag */ + } xer_check_tag_e; +xer_check_tag_e xer_check_tag(const void *buf_ptr, int size, + const char *need_tag); + +/* + * Check whether this buffer consists of entirely XER whitespace characters. + * RETURN VALUES: + * 1: Whitespace or empty string + * 0: Non-whitespace + */ +int xer_is_whitespace(const void *chunk_buf, size_t chunk_size); + +/* + * Skip the series of anticipated extensions. + */ +int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth); + +#ifdef __cplusplus +} +#endif + +#endif /* _XER_DECODER_H_ */ diff --git a/stglibs/smux.lib/include/stg/xer_encoder.h b/stglibs/smux.lib/include/stg/xer_encoder.h new file mode 100644 index 00000000..055e73c0 --- /dev/null +++ b/stglibs/smux.lib/include/stg/xer_encoder.h @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _XER_ENCODER_H_ +#define _XER_ENCODER_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct asn_TYPE_descriptor_s; /* Forward declaration */ + +/* Flags used by the xer_encode() and (*xer_type_encoder_f), defined below */ +enum xer_encoder_flags_e { + /* Mode of encoding */ + XER_F_BASIC = 0x01, /* BASIC-XER (pretty-printing) */ + XER_F_CANONICAL = 0x02 /* Canonical XER (strict rules) */ +}; + +/* + * The XER encoder of any type. May be invoked by the application. + */ +asn_enc_rval_t xer_encode(struct asn_TYPE_descriptor_s *type_descriptor, + void *struct_ptr, /* Structure to be encoded */ + enum xer_encoder_flags_e xer_flags, + asn_app_consume_bytes_f *consume_bytes_cb, + void *app_key /* Arbitrary callback argument */ + ); + +/* + * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC) + * output into the chosen file pointer. + * RETURN VALUES: + * 0: The structure is printed. + * -1: Problem printing the structure. + * WARNING: No sensible errno value is returned. + */ +int xer_fprint(FILE *stream, struct asn_TYPE_descriptor_s *td, void *sptr); + +/* + * Type of the generic XER encoder. + */ +typedef asn_enc_rval_t (xer_type_encoder_f)( + struct asn_TYPE_descriptor_s *type_descriptor, + void *struct_ptr, /* Structure to be encoded */ + int ilevel, /* Level of indentation */ + enum xer_encoder_flags_e xer_flags, + asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ + void *app_key /* Arbitrary callback argument */ + ); + +#ifdef __cplusplus +} +#endif + +#endif /* _XER_ENCODER_H_ */ diff --git a/stglibs/smux.lib/include/stg/xer_support.h b/stglibs/smux.lib/include/stg/xer_support.h new file mode 100644 index 00000000..8b01944a --- /dev/null +++ b/stglibs/smux.lib/include/stg/xer_support.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2003, 2004 X/IO Labs, xiolabs.com. + * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef _XER_SUPPORT_H_ +#define _XER_SUPPORT_H_ + +#include /* Platform-specific types */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Types of data transferred to the application. + */ +typedef enum { + PXML_TEXT, /* Plain text between XML tags. */ + PXML_TAG, /* A tag, starting with '<'. */ + PXML_COMMENT, /* An XML comment, including "". */ + /* + * The following chunk types are reported if the chunk + * terminates the specified XML element. + */ + PXML_TAG_END, /* Tag ended */ + PXML_COMMENT_END /* Comment ended */ +} pxml_chunk_type_e; + +/* + * Callback function that is called by the parser when parsed data is + * available. The _opaque is the pointer to a field containing opaque user + * data specified in pxml_create() call. The chunk type is _type and the text + * data is the piece of buffer identified by _bufid (as supplied to + * pxml_feed() call) starting at offset _offset and of _size bytes size. + * The chunk is NOT '\0'-terminated. + */ +typedef int (pxml_callback_f)(pxml_chunk_type_e _type, + const void *_chunk_data, size_t _chunk_size, void *_key); + +/* + * Parse the given buffer as it were a chunk of XML data. + * Invoke the specified callback each time the meaninful data is found. + * This function returns number of bytes consumed from the bufer. + * It will always be lesser than or equal to the specified _size. + * The next invocation of this function must account the difference. + */ +ssize_t pxml_parse(int *_stateContext, const void *_buf, size_t _size, + pxml_callback_f *cb, void *_key); + +#ifdef __cplusplus +} +#endif + +#endif /* _XER_SUPPORT_H_ */ diff --git a/stglibs/smux.lib/per_decoder.h b/stglibs/smux.lib/per_decoder.h deleted file mode 100644 index 26aaf594..00000000 --- a/stglibs/smux.lib/per_decoder.h +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * Copyright (c) 2005 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _PER_DECODER_H_ -#define _PER_DECODER_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* - * Unaligned PER decoder of any ASN.1 type. May be invoked by the application. - */ -asn_dec_rval_t uper_decode(struct asn_codec_ctx_s *opt_codec_ctx, - struct asn_TYPE_descriptor_s *type_descriptor, /* Type to decode */ - void **struct_ptr, /* Pointer to a target structure's pointer */ - const void *buffer, /* Data to be decoded */ - size_t size, /* Size of data buffer */ - int skip_bits, /* Number of unused leading bits, 0..7 */ - int unused_bits /* Number of unused tailing bits, 0..7 */ - ); - - -/* - * Type of the type-specific PER decoder function. - */ -typedef asn_dec_rval_t (per_type_decoder_f)(asn_codec_ctx_t *opt_codec_ctx, - struct asn_TYPE_descriptor_s *type_descriptor, - asn_per_constraints_t *constraints, - void **struct_ptr, - asn_per_data_t *per_data - ); - -#ifdef __cplusplus -} -#endif - -#endif /* _PER_DECODER_H_ */ diff --git a/stglibs/smux.lib/per_encoder.h b/stglibs/smux.lib/per_encoder.h deleted file mode 100644 index 9ac130b7..00000000 --- a/stglibs/smux.lib/per_encoder.h +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * Copyright (c) 2006 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _PER_ENCODER_H_ -#define _PER_ENCODER_H_ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* - * Unaligned PER encoder of any ASN.1 type. May be invoked by the application. - */ -asn_enc_rval_t uper_encode(struct asn_TYPE_descriptor_s *type_descriptor, - void *struct_ptr, /* Structure to be encoded */ - asn_app_consume_bytes_f *consume_bytes_cb, /* Data collector */ - void *app_key /* Arbitrary callback argument */ -); - -/* A variant of uper_encode() which encodes data into the existing buffer */ -asn_enc_rval_t uper_encode_to_buffer( - struct asn_TYPE_descriptor_s *type_descriptor, - void *struct_ptr, /* Structure to be encoded */ - void *buffer, /* Pre-allocated buffer */ - size_t buffer_size /* Initial buffer size (max) */ -); - - -/* - * Type of the generic PER encoder function. - */ -typedef asn_enc_rval_t (per_type_encoder_f)( - struct asn_TYPE_descriptor_s *type_descriptor, - asn_per_constraints_t *constraints, - void *struct_ptr, - asn_per_outp_t *per_output -); - -#ifdef __cplusplus -} -#endif - -#endif /* _PER_ENCODER_H_ */ diff --git a/stglibs/smux.lib/per_support.h b/stglibs/smux.lib/per_support.h deleted file mode 100644 index 420bb83c..00000000 --- a/stglibs/smux.lib/per_support.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2005, 2006 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _PER_SUPPORT_H_ -#define _PER_SUPPORT_H_ - -#include /* Platform-specific types */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Pre-computed PER constraints. - */ -typedef struct asn_per_constraint_s { - enum asn_per_constraint_flags { - APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */ - APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */ - APC_CONSTRAINED = 0x2, /* Fully constrained */ - APC_EXTENSIBLE = 0x4 /* May have extension */ - } flags; - int range_bits; /* Full number of bits in the range */ - int effective_bits; /* Effective bits */ - long lower_bound; /* "lb" value */ - long upper_bound; /* "ub" value */ -} asn_per_constraint_t; -typedef struct asn_per_constraints_s { - asn_per_constraint_t value; - asn_per_constraint_t size; -} asn_per_constraints_t; - -/* - * This structure describes a position inside an incoming PER bit stream. - */ -typedef struct asn_per_data_s { - const uint8_t *buffer; /* Pointer to the octet stream */ - size_t nboff; /* Bit offset to the meaningful bit */ - size_t nbits; /* Number of bits in the stream */ -} asn_per_data_t; - -/* - * Extract a small number of bits (<= 31) from the specified PER data pointer. - * This function returns -1 if the specified number of bits could not be - * extracted due to EOD or other conditions. - */ -int32_t per_get_few_bits(asn_per_data_t *per_data, int get_nbits); - -/* - * Extract a large number of bits from the specified PER data pointer. - * This function returns -1 if the specified number of bits could not be - * extracted due to EOD or other conditions. - */ -int per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int right_align, - int get_nbits); - -/* - * Get the length "n" from the Unaligned PER stream. - */ -ssize_t uper_get_length(asn_per_data_t *pd, - int effective_bound_bits, - int *repeat); - -/* - * Get the normally small non-negative whole number. - */ -ssize_t uper_get_nsnnwn(asn_per_data_t *pd); - -/* - * This structure supports forming PER output. - */ -typedef struct asn_per_outp_s { - uint8_t *buffer; /* Pointer into the (tmpspace) */ - size_t nboff; /* Bit offset to the meaningful bit */ - size_t nbits; /* Number of bits left in (tmpspace) */ - uint8_t tmpspace[32]; /* Preliminary storage to hold data */ - int (*outper)(const void *data, size_t size, void *op_key); - void *op_key; /* Key for (outper) data callback */ - size_t flushed_bytes; /* Bytes already flushed through (outper) */ -} asn_per_outp_t; - -/* Output a small number of bits (<= 31) */ -int per_put_few_bits(asn_per_outp_t *per_data, uint32_t bits, int obits); - -/* Output a large number of bits */ -int per_put_many_bits(asn_per_outp_t *po, const uint8_t *src, int put_nbits); - -/* - * Put the length "n" to the Unaligned PER stream. - * This function returns the number of units which may be flushed - * in the next units saving iteration. - */ -ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length); - -/* - * Put the normally small non-negative whole number. - */ -int uper_put_nsnnwn(asn_per_outp_t *po, int n); - -#ifdef __cplusplus -} -#endif - -#endif /* _PER_SUPPORT_H_ */ diff --git a/stglibs/smux.lib/xer_decoder.h b/stglibs/smux.lib/xer_decoder.h deleted file mode 100644 index cf0d846f..00000000 --- a/stglibs/smux.lib/xer_decoder.h +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * Copyright (c) 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _XER_DECODER_H_ -#define _XER_DECODER_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* - * The XER decoder of any ASN.1 type. May be invoked by the application. - */ -asn_dec_rval_t xer_decode(struct asn_codec_ctx_s *opt_codec_ctx, - struct asn_TYPE_descriptor_s *type_descriptor, - void **struct_ptr, /* Pointer to a target structure's pointer */ - const void *buffer, /* Data to be decoded */ - size_t size /* Size of data buffer */ - ); - -/* - * Type of the type-specific XER decoder function. - */ -typedef asn_dec_rval_t (xer_type_decoder_f)(asn_codec_ctx_t *opt_codec_ctx, - struct asn_TYPE_descriptor_s *type_descriptor, - void **struct_ptr, - const char *opt_mname, /* Member name */ - const void *buf_ptr, size_t size - ); - -/******************************* - * INTERNALLY USEFUL FUNCTIONS * - *******************************/ - -/* - * Generalized function for decoding the primitive values. - * Used by more specialized functions, such as OCTET_STRING_decode_xer_utf8 - * and others. This function should not be used by applications, as its API - * is subject to changes. - */ -asn_dec_rval_t xer_decode_general(asn_codec_ctx_t *opt_codec_ctx, - asn_struct_ctx_t *ctx, /* Type decoder context */ - void *struct_key, /* Treated as opaque pointer */ - const char *xml_tag, /* Expected XML tag name */ - const void *buf_ptr, size_t size, - int (*opt_unexpected_tag_decoder) - (void *struct_key, const void *chunk_buf, size_t chunk_size), - ssize_t (*body_receiver) - (void *struct_key, const void *chunk_buf, size_t chunk_size, - int have_more) - ); - - -/* - * Fetch the next XER (XML) token from the stream. - * The function returns the number of bytes occupied by the chunk type, - * returned in the _ch_type. The _ch_type is only set (and valid) when - * the return value is greater than 0. - */ - typedef enum pxer_chunk_type { - PXER_TAG, /* Complete XER tag */ - PXER_TEXT, /* Plain text between XER tags */ - PXER_COMMENT /* A comment, may be part of */ - } pxer_chunk_type_e; -ssize_t xer_next_token(int *stateContext, - const void *buffer, size_t size, pxer_chunk_type_e *_ch_type); - -/* - * This function checks the buffer against the tag name is expected to occur. - */ - typedef enum xer_check_tag { - XCT_BROKEN = 0, /* The tag is broken */ - XCT_OPENING = 1, /* This is the tag */ - XCT_CLOSING = 2, /* This is the tag */ - XCT_BOTH = 3, /* This is the tag */ - XCT__UNK__MASK = 4, /* Mask of everything unexpected */ - XCT_UNKNOWN_OP = 5, /* Unexpected tag */ - XCT_UNKNOWN_CL = 6, /* Unexpected tag */ - XCT_UNKNOWN_BO = 7 /* Unexpected tag */ - } xer_check_tag_e; -xer_check_tag_e xer_check_tag(const void *buf_ptr, int size, - const char *need_tag); - -/* - * Check whether this buffer consists of entirely XER whitespace characters. - * RETURN VALUES: - * 1: Whitespace or empty string - * 0: Non-whitespace - */ -int xer_is_whitespace(const void *chunk_buf, size_t chunk_size); - -/* - * Skip the series of anticipated extensions. - */ -int xer_skip_unknown(xer_check_tag_e tcv, ber_tlv_len_t *depth); - -#ifdef __cplusplus -} -#endif - -#endif /* _XER_DECODER_H_ */ diff --git a/stglibs/smux.lib/xer_encoder.h b/stglibs/smux.lib/xer_encoder.h deleted file mode 100644 index 055e73c0..00000000 --- a/stglibs/smux.lib/xer_encoder.h +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * Copyright (c) 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _XER_ENCODER_H_ -#define _XER_ENCODER_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct asn_TYPE_descriptor_s; /* Forward declaration */ - -/* Flags used by the xer_encode() and (*xer_type_encoder_f), defined below */ -enum xer_encoder_flags_e { - /* Mode of encoding */ - XER_F_BASIC = 0x01, /* BASIC-XER (pretty-printing) */ - XER_F_CANONICAL = 0x02 /* Canonical XER (strict rules) */ -}; - -/* - * The XER encoder of any type. May be invoked by the application. - */ -asn_enc_rval_t xer_encode(struct asn_TYPE_descriptor_s *type_descriptor, - void *struct_ptr, /* Structure to be encoded */ - enum xer_encoder_flags_e xer_flags, - asn_app_consume_bytes_f *consume_bytes_cb, - void *app_key /* Arbitrary callback argument */ - ); - -/* - * The variant of the above function which dumps the BASIC-XER (XER_F_BASIC) - * output into the chosen file pointer. - * RETURN VALUES: - * 0: The structure is printed. - * -1: Problem printing the structure. - * WARNING: No sensible errno value is returned. - */ -int xer_fprint(FILE *stream, struct asn_TYPE_descriptor_s *td, void *sptr); - -/* - * Type of the generic XER encoder. - */ -typedef asn_enc_rval_t (xer_type_encoder_f)( - struct asn_TYPE_descriptor_s *type_descriptor, - void *struct_ptr, /* Structure to be encoded */ - int ilevel, /* Level of indentation */ - enum xer_encoder_flags_e xer_flags, - asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ - void *app_key /* Arbitrary callback argument */ - ); - -#ifdef __cplusplus -} -#endif - -#endif /* _XER_ENCODER_H_ */ diff --git a/stglibs/smux.lib/xer_support.h b/stglibs/smux.lib/xer_support.h deleted file mode 100644 index 8b01944a..00000000 --- a/stglibs/smux.lib/xer_support.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2003, 2004 X/IO Labs, xiolabs.com. - * Copyright (c) 2003, 2004 Lev Walkin . All rights reserved. - * Redistribution and modifications are permitted subject to BSD license. - */ -#ifndef _XER_SUPPORT_H_ -#define _XER_SUPPORT_H_ - -#include /* Platform-specific types */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Types of data transferred to the application. - */ -typedef enum { - PXML_TEXT, /* Plain text between XML tags. */ - PXML_TAG, /* A tag, starting with '<'. */ - PXML_COMMENT, /* An XML comment, including "". */ - /* - * The following chunk types are reported if the chunk - * terminates the specified XML element. - */ - PXML_TAG_END, /* Tag ended */ - PXML_COMMENT_END /* Comment ended */ -} pxml_chunk_type_e; - -/* - * Callback function that is called by the parser when parsed data is - * available. The _opaque is the pointer to a field containing opaque user - * data specified in pxml_create() call. The chunk type is _type and the text - * data is the piece of buffer identified by _bufid (as supplied to - * pxml_feed() call) starting at offset _offset and of _size bytes size. - * The chunk is NOT '\0'-terminated. - */ -typedef int (pxml_callback_f)(pxml_chunk_type_e _type, - const void *_chunk_data, size_t _chunk_size, void *_key); - -/* - * Parse the given buffer as it were a chunk of XML data. - * Invoke the specified callback each time the meaninful data is found. - * This function returns number of bytes consumed from the bufer. - * It will always be lesser than or equal to the specified _size. - * The next invocation of this function must account the difference. - */ -ssize_t pxml_parse(int *_stateContext, const void *_buf, size_t _size, - pxml_callback_f *cb, void *_key); - -#ifdef __cplusplus -} -#endif - -#endif /* _XER_SUPPORT_H_ */ diff --git a/stglibs/srvconf.lib/include/stg/netunit.h b/stglibs/srvconf.lib/include/stg/netunit.h new file mode 100644 index 00000000..e288df86 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/netunit.h @@ -0,0 +1,125 @@ +/* + * 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 + */ + + /* + $Revision: 1.6 $ + $Date: 2010/02/11 12:32:53 $ + $Author: faust $ + */ + +#ifndef NetUnitH +#define NetUnitH + +#include +#include +#include + +#include +#include + +#include "stg/blowfish.h" + +#define STG_HEADER "SG04" +#define OK_HEADER "OKHD" +#define ERR_HEADER "ERHD" +#define OK_LOGIN "OKLG" +#define ERR_LOGIN "ERLG" +#define OK_LOGINS "OKLS" +#define ERR_LOGINS "ERLS" + +// äÌÉÎÎÁ ÛÉÆÒÕÅÍÏÇÏ É ÐÅÒÅÄÁ×ÁÅÍÏÇ ÚÁ ÏÄÉÎ ÒÁÚ ÂÌÏËÁ ÉÎÆÏÒÍÁÃÉÉ +#define ENC_MSG_LEN (8) + +#define MAX_ERR_STR_LEN (64) + +typedef int(*RxCallback_t)(void *, std::list *); + +enum status +{ +st_ok = 0, +st_conn_fail, +st_send_fail, +st_recv_fail, +st_header_err, +st_login_err, +st_logins_err, +st_data_err, +st_unknown_err, +st_dns_err, +st_xml_parse_error, +st_data_error +}; + +enum CONF_STATE +{ +confHdr = 0, +confLogin, +confLoginCipher, +confData +}; +//--------------------------------------------------------------------------- +class NETTRANSACT +{ +public: + NETTRANSACT(); + int Transact(const char * data); + const std::string & GetError() const; + + void SetRxCallback(void * data, RxCallback_t); + + void SetServer(const char * serverName); + void SetServerPort(short unsigned p); + + void SetLogin(const char * l); + void SetPassword(const char * p); + //////////////////////////////////////////// + int Connect(); + int Disconnect(); + void Reset(); +private: + int TxHeader(); + int RxHeaderAnswer(); + + int TxLogin(); + int RxLoginAnswer(); + + int TxLoginS(); + int RxLoginSAnswer(); + + int TxData(const char * text); + int TxData(char * data); + int RxDataAnswer(); + + void Encrypt(char * d, const char * s, BLOWFISH_CTX *ctx); + void EnDecryptInit(const char * passwd, int passwdLen, BLOWFISH_CTX *ctx); + void Decrypt(char * d, const char * s, BLOWFISH_CTX *ctx); + + std::string server; + short unsigned port; + std::string login; + std::string password; + int outerSocket; + std::list answerList; + RxCallback_t RxCallBack; + void * dataRxCallBack; + std::string errorMsg; +}; +//--------------------------------------------------------------------------- +#endif diff --git a/stglibs/srvconf.lib/include/stg/servconf.h b/stglibs/srvconf.lib/include/stg/servconf.h new file mode 100644 index 00000000..67c2f248 --- /dev/null +++ b/stglibs/srvconf.lib/include/stg/servconf.h @@ -0,0 +1,293 @@ +/* + * 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 + */ + + /* + $Revision: 1.10 $ + $Date: 2009/03/17 09:52:35 $ + $Author: faust $ + */ + +#ifndef SERVCONF_H +#define SERVCONF_H + +#include + +#include +#include + +#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); + +#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: + SERVCONF(); + void SetServer(const char * server); + void SetPort(uint16_t port); + + 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); + + 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 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); + +private: + PARSER * currParser; + + PARSER_GET_USERS parserGetUsers; + PARSER_GET_USER parserGetUser; + PARSER_GET_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; + + friend int AnsRecv(void * data, std::list * list); +}; +//----------------------------------------------------------------------------- + +#endif /* _SERVCONF_H_ */ diff --git a/stglibs/srvconf.lib/netunit.h b/stglibs/srvconf.lib/netunit.h deleted file mode 100644 index e288df86..00000000 --- a/stglibs/srvconf.lib/netunit.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.6 $ - $Date: 2010/02/11 12:32:53 $ - $Author: faust $ - */ - -#ifndef NetUnitH -#define NetUnitH - -#include -#include -#include - -#include -#include - -#include "stg/blowfish.h" - -#define STG_HEADER "SG04" -#define OK_HEADER "OKHD" -#define ERR_HEADER "ERHD" -#define OK_LOGIN "OKLG" -#define ERR_LOGIN "ERLG" -#define OK_LOGINS "OKLS" -#define ERR_LOGINS "ERLS" - -// äÌÉÎÎÁ ÛÉÆÒÕÅÍÏÇÏ É ÐÅÒÅÄÁ×ÁÅÍÏÇ ÚÁ ÏÄÉÎ ÒÁÚ ÂÌÏËÁ ÉÎÆÏÒÍÁÃÉÉ -#define ENC_MSG_LEN (8) - -#define MAX_ERR_STR_LEN (64) - -typedef int(*RxCallback_t)(void *, std::list *); - -enum status -{ -st_ok = 0, -st_conn_fail, -st_send_fail, -st_recv_fail, -st_header_err, -st_login_err, -st_logins_err, -st_data_err, -st_unknown_err, -st_dns_err, -st_xml_parse_error, -st_data_error -}; - -enum CONF_STATE -{ -confHdr = 0, -confLogin, -confLoginCipher, -confData -}; -//--------------------------------------------------------------------------- -class NETTRANSACT -{ -public: - NETTRANSACT(); - int Transact(const char * data); - const std::string & GetError() const; - - void SetRxCallback(void * data, RxCallback_t); - - void SetServer(const char * serverName); - void SetServerPort(short unsigned p); - - void SetLogin(const char * l); - void SetPassword(const char * p); - //////////////////////////////////////////// - int Connect(); - int Disconnect(); - void Reset(); -private: - int TxHeader(); - int RxHeaderAnswer(); - - int TxLogin(); - int RxLoginAnswer(); - - int TxLoginS(); - int RxLoginSAnswer(); - - int TxData(const char * text); - int TxData(char * data); - int RxDataAnswer(); - - void Encrypt(char * d, const char * s, BLOWFISH_CTX *ctx); - void EnDecryptInit(const char * passwd, int passwdLen, BLOWFISH_CTX *ctx); - void Decrypt(char * d, const char * s, BLOWFISH_CTX *ctx); - - std::string server; - short unsigned port; - std::string login; - std::string password; - int outerSocket; - std::list answerList; - RxCallback_t RxCallBack; - void * dataRxCallBack; - std::string errorMsg; -}; -//--------------------------------------------------------------------------- -#endif diff --git a/stglibs/srvconf.lib/servconf.h b/stglibs/srvconf.lib/servconf.h deleted file mode 100644 index 67c2f248..00000000 --- a/stglibs/srvconf.lib/servconf.h +++ /dev/null @@ -1,293 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* - * Author : Boris Mikhailenko - */ - - /* - $Revision: 1.10 $ - $Date: 2009/03/17 09:52:35 $ - $Author: faust $ - */ - -#ifndef SERVCONF_H -#define SERVCONF_H - -#include - -#include -#include - -#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); - -#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: - SERVCONF(); - void SetServer(const char * server); - void SetPort(uint16_t port); - - 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); - - 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 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); - -private: - PARSER * currParser; - - PARSER_GET_USERS parserGetUsers; - PARSER_GET_USER parserGetUser; - PARSER_GET_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; - - friend int AnsRecv(void * data, std::list * list); -}; -//----------------------------------------------------------------------------- - -#endif /* _SERVCONF_H_ */ diff --git a/tests/tut.h b/tests/tut.h deleted file mode 100644 index 22859cdd..00000000 --- a/tests/tut.h +++ /dev/null @@ -1,2 +0,0 @@ - -#include diff --git a/tests/tut/tut.hpp b/tests/tut/tut.hpp index 93233a6a..52f9643c 100644 --- a/tests/tut/tut.hpp +++ b/tests/tut/tut.hpp @@ -1,5 +1,6 @@ #ifndef TUT_H_GUARD #define TUT_H_GUARD +#include #include #include @@ -9,11 +10,6 @@ #include #include #include -#include - -#if defined(linux) -#define TUT_USE_POSIX -#endif #include "tut_exception.hpp" #include "tut_result.hpp" @@ -35,6 +31,9 @@ namespace tut { +template +class test_group; + /** * Test object. Contains data test run upon and default test method * implementation. Inherited from Data to allow tests to @@ -43,12 +42,29 @@ namespace tut template class test_object : public Data, public test_object_posix { + template + friend class test_group; + + void set_test_group(const char *group) + { + current_test_group_ = group; + } + + void set_test_id(int current_test_id) + { + current_test_id_ = current_test_id; + } + public: /** * Default constructor */ test_object() + : called_method_was_a_dummy_test_(false), + current_test_id_(0), + current_test_name_(), + current_test_group_() { } @@ -62,9 +78,9 @@ public: return current_test_name_; } - void set_test_id(int current_test_id) + const std::string& get_test_group() const { - current_test_id_ = current_test_id; + return current_test_group_; } int get_test_id() const @@ -86,13 +102,17 @@ public: * Used to detect usused test numbers and avoid unnecessary * test object creation which may be time-consuming depending * on operations described in Data::Data() and Data::~Data(). - * TODO: replace with throwing special exception from default test. */ bool called_method_was_a_dummy_test_; + virtual ~test_object() + { + } + private: int current_test_id_; std::string current_test_name_; + std::string current_test_group_; }; @@ -126,6 +146,9 @@ struct tests_registerer template class test_group : public group_base, public test_group_posix { + test_group(const test_group&); + void operator=(const test_group&); + const char* name_; typedef void (test_object::*testmethod)(); @@ -139,13 +162,15 @@ class test_group : public group_base, public test_group_posix tests tests_; tests_iterator current_test_; - enum seh_result - { - SEH_OK, - SEH_CTOR, - SEH_TEST, - SEH_DUMMY - }; + enum seh_result + { + SEH_OK, +#if defined(TUT_USE_SEH) + SEH_CTOR, + SEH_TEST, +#endif + SEH_DUMMY + }; /** * Exception-in-destructor-safe smart-pointer class. @@ -201,11 +226,16 @@ class test_group : public group_base, public test_group_posix { try { +#if defined(TUT_USE_SEH) if (delete_obj() == false) { throw warning("destructor of test object raised" " an SEH exception"); } +#else + bool d = delete_obj(); + assert(d && "delete failed with SEH disabled: runtime bug?"); +#endif } catch (const std::exception& ex) { @@ -268,7 +298,9 @@ public: * Creates and registers test group with specified name. */ test_group(const char* name) - : name_(name) + : name_(name), + tests_(), + current_test_() { // register itself runner.get().register_group(name_,this); @@ -281,7 +313,9 @@ public: * This constructor is used in self-test run only. */ test_group(const char* name, test_runner& another_runner) - : name_(name) + : name_(name), + tests_(), + current_test_() { // register itself another_runner.register_group(name_, this); @@ -367,22 +401,23 @@ public: try { switch (run_test_seh_(ti->second, obj, current_test_name, ti->first)) - { - case SEH_CTOR: - throw bad_ctor("seh"); - break; - - case SEH_TEST: - throw seh("seh"); - break; - - case SEH_DUMMY: - tr.result = test_result::dummy; - break; - - case SEH_OK: - // ok - break; + { +#if defined(TUT_USE_SEH) + case SEH_CTOR: + throw bad_ctor("seh"); + break; + + case SEH_TEST: + throw seh("seh"); + break; +#endif + case SEH_DUMMY: + tr.result = test_result::dummy; + break; + + case SEH_OK: + // ok + break; } } catch (const rethrown& ex) @@ -393,13 +428,13 @@ public: catch (const tut_error& ex) { tr.result = ex.result(); - tr.exception_typeid = typeid(ex).name(); + tr.exception_typeid = ex.type(); tr.message = ex.what(); } catch (const std::exception& ex) { tr.result = test_result::ex; - tr.exception_typeid = typeid(ex).name(); + tr.exception_typeid = type_name(ex); tr.message = ex.what(); } catch (...) @@ -433,12 +468,12 @@ public: __try { #endif - if (obj.get() == 0) - { - reset_holder_(obj); - } + if (obj.get() == 0) + { + reset_holder_(obj); + } - obj->called_method_was_a_dummy_test_ = false; + obj->called_method_was_a_dummy_test_ = false; #if defined(TUT_USE_SEH) @@ -446,6 +481,7 @@ public: { #endif obj.get()->set_test_id(current_test_id); + obj.get()->set_test_group(name_); (obj.get()->*tm)(); #if defined(TUT_USE_SEH) } @@ -456,20 +492,20 @@ public: } #endif - if (obj->called_method_was_a_dummy_test_) - { - // do not call obj.release(); reuse object - return SEH_DUMMY; - } + if (obj->called_method_was_a_dummy_test_) + { + // do not call obj.release(); reuse object + return SEH_DUMMY; + } - current_test_name = obj->get_test_name(); - obj.permit_throw(); - obj.release(); + current_test_name = obj->get_test_name(); + obj.permit_throw(); + obj.release(); #if defined(TUT_USE_SEH) } __except(handle_seh_(::GetExceptionCode())) { - return SEH_CTOR; + return SEH_CTOR; } #endif return SEH_OK; @@ -531,5 +567,5 @@ inline int handle_seh_(DWORD excode) #endif } -#endif +#endif // TUT_H_GUARD diff --git a/tests/tut/tut_assert.hpp b/tests/tut/tut_assert.hpp index 7ee44bc2..c1959012 100644 --- a/tests/tut/tut_assert.hpp +++ b/tests/tut/tut_assert.hpp @@ -1,29 +1,34 @@ #ifndef TUT_ASSERT_H_GUARD #define TUT_ASSERT_H_GUARD +#include -#include "tut_exception.hpp" #include #include +#include +#include +#include #if defined(TUT_USE_POSIX) #include #include #endif +#include "tut_exception.hpp" + namespace tut { namespace detail { template - std::ostream &msg_prefix(std::ostream &str, const M &msg) + std::ostringstream &msg_prefix(std::ostringstream &str, const M &msg) { - std::stringstream ss; + std::ostringstream ss; ss << msg; if(!ss.str().empty()) { - str << ss.rdbuf() << ": "; + str << msg << ": "; } return str; @@ -83,7 +88,7 @@ void ensure_not(const M& msg, bool cond) * Tests two objects for being equal. * Throws if false. * - * NB: both T and Q must have operator << defined somewhere, or + * NB: both LHS and RHS must have operator << defined somewhere, or * client code will not compile at all! */ template @@ -91,42 +96,128 @@ void ensure_equals(const M& msg, const LHS& actual, const RHS& expected) { if (expected != actual) { - std::stringstream ss; + std::ostringstream ss; detail::msg_prefix(ss,msg) - << "expected '" + << "expected `" << expected - << "' actual '" + << "` actual `" << actual - << '\''; + << "`"; throw failure(ss.str()); } } -template -void ensure_equals(const LHS& actual, const RHS& expected) +/** + * Tests two pointers for being equal. + * Throws if false. + * + * NB: both T and Q must have operator << defined somewhere, or + * client code will not compile at all! + */ +template +void ensure_equals(const M& msg, const LHS * const actual, const RHS * const expected) { - ensure_equals("Values are not equal", actual, expected); + if (expected != actual) + { + std::ostringstream ss; + detail::msg_prefix(ss,msg) + << "expected `" + << (void*)expected + << "` actual `" + << (void*)actual + << "`"; + throw failure(ss.str()); + } } template -void ensure_equals(const M& msg, const double& actual, const double& expected, - const double& epsilon = std::numeric_limits::epsilon()) +void ensure_equals(const M& msg, const double& actual, const double& expected, const double& epsilon) { const double diff = actual - expected; - if ( !((diff <= epsilon) && (diff >= -epsilon )) ) + if ( (actual != expected) && !((diff <= epsilon) && (diff >= -epsilon )) ) { - std::stringstream ss; + std::ostringstream ss; detail::msg_prefix(ss,msg) << std::scientific << std::showpoint << std::setprecision(16) - << "expected " << expected - << " actual " << actual - << " with precision " << epsilon; + << "expected `" << expected + << "` actual `" << actual + << "` with precision `" << epsilon << "`"; throw failure(ss.str()); } } + +template +void ensure_equals(const M& msg, const double& actual, const double& expected) +{ + ensure_equals(msg, actual, expected, std::numeric_limits::epsilon()); +} + +template +void ensure_equals(const LHS& actual, const RHS& expected) +{ + ensure_equals("Values are not equal", actual, expected); +} + + +template +void ensure_equals(const std::string &msg, + const LhsIterator &lhs_begin, const LhsIterator &lhs_end, + const RhsIterator &rhs_begin, const RhsIterator &rhs_end) +{ + typename std::iterator_traits::difference_type lhs_size = std::distance(lhs_begin, lhs_end); + typename std::iterator_traits::difference_type rhs_size = std::distance(rhs_begin, rhs_end); + + if(lhs_size < rhs_size) + { + ensure_equals(msg + ": range is too short", lhs_size, rhs_size); + } + + if(lhs_size > rhs_size) + { + ensure_equals(msg + ": range is too long", lhs_size, rhs_size); + } + + assert(lhs_size == rhs_size); + + LhsIterator lhs_i = lhs_begin; + RhsIterator rhs_i = rhs_begin; + while( (lhs_i != lhs_end) && (rhs_i != rhs_end) ) + { + if(*lhs_i != *rhs_i) + { + std::ostringstream ss; + detail::msg_prefix(ss,msg) + << "expected `" << *rhs_i + << "` actual `" << *lhs_i + << "` at offset " << std::distance(lhs_begin, lhs_i); + throw failure(ss.str()); + } + + lhs_i++; + rhs_i++; + } + + assert(lhs_i == lhs_end); + assert(rhs_i == rhs_end); +} + +template +void ensure_equals(const LhsIterator &lhs_begin, const LhsIterator &lhs_end, + const RhsIterator &rhs_begin, const RhsIterator &rhs_end) +{ + ensure_equals("Ranges are not equal", lhs_begin, lhs_end, rhs_begin, rhs_end); +} + +template +void ensure_equals(const LhsType *lhs_begin, const LhsType *lhs_end, + const RhsType *rhs_begin, const RhsType *rhs_end) +{ + ensure_equals("Ranges are not equal", lhs_begin, lhs_end, rhs_begin, rhs_end); +} + /** * Tests two objects for being at most in given distance one from another. * Borders are excluded. @@ -143,15 +234,15 @@ void ensure_distance(const M& msg, const T& actual, const T& expected, const T& { if (expected-distance >= actual || expected+distance <= actual) { - std::stringstream ss; + std::ostringstream ss; detail::msg_prefix(ss,msg) - << " expected (" + << " expected `" << expected-distance - << " - " + << "` - `" << expected+distance - << ") actual '" + << "` actual `" << actual - << '\''; + << "`"; throw failure(ss.str()); } } @@ -169,7 +260,7 @@ void ensure_errno(const M& msg, bool cond) { #if defined(TUT_USE_POSIX) char e[512]; - std::stringstream ss; + std::ostringstream ss; detail::msg_prefix(ss,msg) << strerror_r(errno, e, sizeof(e)); throw failure(ss.str()); @@ -193,6 +284,20 @@ void fail(const M& msg) throw failure(msg); } +/** + * Mark test case as known failure and skip execution. + */ +void skip(const char* msg = "") +{ + throw skipped(msg); +} + +template +void skip(const M& msg) +{ + throw skipped(msg); +} + } // end of namespace } diff --git a/tests/tut/tut_config.hpp b/tests/tut/tut_config.hpp new file mode 100644 index 00000000..d698c1c8 --- /dev/null +++ b/tests/tut/tut_config.hpp @@ -0,0 +1,6 @@ +#ifndef TUT_CONFIG_H_GUARD +#define TUT_CONFIG_H_GUARD + +#define TUT_USE_RTTI 1 + +#endif diff --git a/tests/tut/tut_console_reporter.hpp b/tests/tut/tut_console_reporter.hpp index 3c3739be..33856db8 100644 --- a/tests/tut/tut_console_reporter.hpp +++ b/tests/tut/tut_console_reporter.hpp @@ -1,6 +1,5 @@ #ifndef TUT_CONSOLE_REPORTER #define TUT_CONSOLE_REPORTER - #include #include @@ -17,29 +16,32 @@ std::ostream& operator<<(std::ostream& os, const tut::test_result& tr) { switch(tr.result) { - case tut::test_result::ok: - os << '.'; - break; - case tut::test_result::fail: - os << '[' << tr.test << "=F]"; - break; - case tut::test_result::ex_ctor: - os << '[' << tr.test << "=C]"; - break; - case tut::test_result::ex: - os << '[' << tr.test << "=X]"; - break; - case tut::test_result::warn: - os << '[' << tr.test << "=W]"; - break; - case tut::test_result::term: - os << '[' << tr.test << "=T]"; - break; - case tut::test_result::rethrown: - os << '[' << tr.test << "=P]"; - break; - case tut::test_result::dummy: - assert(!"Should never be called"); + case tut::test_result::ok: + os << '.'; + break; + case tut::test_result::fail: + os << '[' << tr.test << "=F]"; + break; + case tut::test_result::ex_ctor: + os << '[' << tr.test << "=C]"; + break; + case tut::test_result::ex: + os << '[' << tr.test << "=X]"; + break; + case tut::test_result::warn: + os << '[' << tr.test << "=W]"; + break; + case tut::test_result::term: + os << '[' << tr.test << "=T]"; + break; + case tut::test_result::rethrown: + os << '[' << tr.test << "=P]"; + break; + case tut::test_result::skipped: + os << '[' << tr.test << "=S]"; + break; + case tut::test_result::dummy: + throw tut::tut_error("console reporter called for dummy test result"); } return os; @@ -60,6 +62,8 @@ class console_reporter : public tut::callback not_passed_list not_passed; std::ostream& os; + console_reporter(const console_reporter &); + console_reporter &operator=(const console_reporter &); public: int ok_count; @@ -67,15 +71,33 @@ public: int failures_count; int terminations_count; int warnings_count; + int skipped_count; console_reporter() - : os(std::cout) + : current_group(), + not_passed(), + os(std::cout), + ok_count(0), + exceptions_count(0), + failures_count(0), + terminations_count(0), + warnings_count(0), + skipped_count(0) { init(); } console_reporter(std::ostream& out) - : os(out) + : current_group(), + not_passed(), + os(out), + ok_count(0), + exceptions_count(0), + failures_count(0), + terminations_count(0), + warnings_count(0), + skipped_count(0) + { init(); } @@ -114,11 +136,15 @@ public: case test_result::term: terminations_count++; break; + case test_result::skipped: + skipped_count++; + break; case tut::test_result::dummy: - assert(!"Should never be called"); + assert( (tr.result != tut::test_result::dummy) && "Should never be called"); } // switch - if (tr.result != tut::test_result::ok) + if ( (tr.result != tut::test_result::ok) && + (tr.result != tut::test_result::skipped) ) { not_passed.push_back(tr); } @@ -181,12 +207,12 @@ public: { if (tr.result == test_result::fail) { - os << " failed assertion: \"" << tr.message << "\"" + os << " failed assertion: `" << tr.message << "`" << std::endl; } else { - os << " message: \"" << tr.message << "\"" + os << " message: `" << tr.message << "`" << std::endl; } } @@ -214,11 +240,17 @@ public: { os << " warnings:" << warnings_count; } + os << " ok:" << ok_count; + + if(skipped_count > 0) + { + os << " skipped:" << skipped_count; + } os << std::endl; } - bool all_ok() const + virtual bool all_ok() const { return not_passed.empty(); } @@ -232,6 +264,7 @@ private: failures_count = 0; terminations_count = 0; warnings_count = 0; + skipped_count = 0; not_passed.clear(); } }; diff --git a/tests/tut/tut_cppunit_reporter.hpp b/tests/tut/tut_cppunit_reporter.hpp index 3b9f38c1..62646b09 100644 --- a/tests/tut/tut_cppunit_reporter.hpp +++ b/tests/tut/tut_cppunit_reporter.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace tut { @@ -16,72 +17,60 @@ namespace tut */ class cppunit_reporter : public tut::callback { - private: - std::vector failed_tests; - std::vector passed_tests; - std::string filename; + std::vector failed_tests_; + std::vector passed_tests_; + const std::string filename_; + std::auto_ptr stream_; - std::string encode(const std::string & text) - { - std::string out; - for (unsigned int i=0; i': - out += ">"; - break; - case '&': - out += "&"; - break; - case '\'': - out += "'"; - break; - case '"': - out += """; - break; - default: - out += c; - } - } - - return out; - } + cppunit_reporter(const cppunit_reporter &); + cppunit_reporter &operator=(const cppunit_reporter &); public: + explicit cppunit_reporter(const std::string &filename = "testResult.xml") + : failed_tests_(), + passed_tests_(), + filename_(filename), + stream_(new std::ofstream(filename_.c_str())) + { + if (!stream_->good()) { + throw tut_error("Cannot open output file `" + filename_ + "`"); + } + } - cppunit_reporter(const std::string & _filename = "") + explicit cppunit_reporter(std::ostream &stream) + : failed_tests_(), + passed_tests_(), + filename_(), + stream_(&stream) { - setFilename(_filename); } - void setFilename(const std::string & _filename) + ~cppunit_reporter() { - if (_filename == "") - { - filename = "testResult.xml"; - } - else + if(filename_.empty()) { - filename = _filename; + stream_.release(); } } void run_started() { - failed_tests.clear(); - passed_tests.clear(); + failed_tests_.clear(); + passed_tests_.clear(); } void test_completed(const tut::test_result& tr) { - if (tr.result == test_result::ok) { - passed_tests.push_back(tr); - } else { - failed_tests.push_back(tr); + assert(tr.result != test_result::dummy ); + if ( (tr.result == test_result::ok) || + (tr.result == test_result::skipped) ) + { + passed_tests_.push_back(tr); + } + else + { + failed_tests_.push_back(tr); } } @@ -91,23 +80,18 @@ public: int failures = 0; std::string failure_type; std::string failure_msg; - std::ofstream xmlfile; - - xmlfile.open(filename.c_str(), std::ios::in | std::ios::trunc); - if (!xmlfile.is_open()) { - throw (std::runtime_error("Cannot open file for output")); - } - /* *********************** header ***************************** */ - xmlfile << "" << std::endl - << "" << std::endl; + *stream_ << "" << std::endl + << "" << std::endl; - /* *********************** failed tests ***************************** */ - if (failed_tests.size() > 0) { - xmlfile << " " << std::endl; + if (failed_tests_.size() > 0) + { + *stream_ << " " << std::endl; - for (unsigned int i=0; i" << std::endl - << " " << encode(failed_tests[i].group) + "::" + encode(failed_tests[i].name) << "" << std::endl - << " " << failure_type << "" << std::endl - << " " << std::endl - << " Unknown" << std::endl - << " Unknown" << std::endl - << " " << std::endl - << " " << encode(failure_msg + failed_tests[i].message) << "" << std::endl - << " " << std::endl; + *stream_ << " " << std::endl + << " " << encode(failed_tests_[i].group) + "::" + encode(failed_tests_[i].name) << "" << std::endl + << " " << failure_type << "" << std::endl + << " " << std::endl + << " Unknown" << std::endl + << " Unknown" << std::endl + << " " << std::endl + << " " << encode(failure_msg + failed_tests_[i].message) << "" << std::endl + << " " << std::endl; } - xmlfile << " " << std::endl; + *stream_ << " " << std::endl; } /* *********************** passed tests ***************************** */ - if (passed_tests.size() > 0) { - xmlfile << " " << std::endl; - - for (unsigned int i=0; i" << std::endl - << " " << encode(passed_tests[i].group) + "::" + encode(passed_tests[i].name) << "" << std::endl - << " " << std::endl; + if (passed_tests_.size() > 0) { + *stream_ << " " << std::endl; + + for (unsigned int i=0; i" << std::endl + << " " << encode(passed_tests_[i].group) + "::" + encode(passed_tests_[i].name) << "" << std::endl + << " " << std::endl; } - xmlfile << " " << std::endl; + *stream_ << " " << std::endl; } /* *********************** statistics ***************************** */ - xmlfile << " " << std::endl - << " " << (failed_tests.size() + passed_tests.size()) << "" << std::endl - << " " << failed_tests.size() << "" << std::endl - << " " << errors << "" << std::endl - << " " << failures << "" << std::endl - << " " << std::endl; + *stream_ << " " << std::endl + << " " << (failed_tests_.size() + passed_tests_.size()) << "" << std::endl + << " " << failed_tests_.size() << "" << std::endl + << " " << errors << "" << std::endl + << " " << failures << "" << std::endl + << " " << std::endl; /* *********************** footer ***************************** */ - xmlfile << "" << std::endl; - - xmlfile.close(); + *stream_ << "" << std::endl; } - bool all_ok() const + virtual bool all_ok() const { - return failed_tests.empty(); - }; + return failed_tests_.empty(); + } + /** + * \brief Encodes text to XML + * XML-reserved characters (e.g. "<") are encoded according to specification + * @param text text to be encoded + * @return encoded string + */ + static std::string encode(const std::string & text) + { + std::string out; + + for (unsigned int i=0; i': + out += ">"; + break; + case '&': + out += "&"; + break; + case '\'': + out += "'"; + break; + case '"': + out += """; + break; + default: + out += c; + } + } + return out; + } }; } diff --git a/tests/tut/tut_exception.hpp b/tests/tut/tut_exception.hpp index c5c88cb2..1ebea341 100644 --- a/tests/tut/tut_exception.hpp +++ b/tests/tut/tut_exception.hpp @@ -12,7 +12,7 @@ namespace tut */ struct tut_error : public std::exception { - tut_error(const std::string& msg) + explicit tut_error(const std::string& msg) : err_msg(msg) { } @@ -22,6 +22,11 @@ struct tut_error : public std::exception return test_result::ex; } + virtual std::string type() const + { + return "tut::tut_error"; + } + const char* what() const throw() { return err_msg.c_str(); @@ -32,8 +37,9 @@ struct tut_error : public std::exception } private: + void operator=(const tut_error &); - std::string err_msg; + const std::string err_msg; }; /** @@ -41,23 +47,48 @@ private: */ struct no_such_group : public tut_error { - no_such_group(const std::string& grp) + explicit no_such_group(const std::string& grp) : tut_error(grp) { } + virtual std::string type() const + { + return "tut::no_such_group"; + } + ~no_such_group() throw() { } }; +/** + * Test not found exception. + */ +struct no_such_test : public tut_error +{ + explicit no_such_test(const std::string& grp) + : tut_error(grp) + { + } + + virtual std::string type() const + { + return "tut::no_such_test"; + } + + ~no_such_test() throw() + { + } +}; + /** * Internal exception to be throwed when * test constructor has failed. */ struct bad_ctor : public tut_error { - bad_ctor(const std::string& msg) + explicit bad_ctor(const std::string& msg) : tut_error(msg) { } @@ -67,6 +98,11 @@ struct bad_ctor : public tut_error return test_result::ex_ctor; } + virtual std::string type() const + { + return "tut::bad_ctor"; + } + ~bad_ctor() throw() { } @@ -77,7 +113,7 @@ struct bad_ctor : public tut_error */ struct failure : public tut_error { - failure(const std::string& msg) + explicit failure(const std::string& msg) : tut_error(msg) { } @@ -87,6 +123,11 @@ struct failure : public tut_error return test_result::fail; } + virtual std::string type() const + { + return "tut::failure"; + } + ~failure() throw() { } @@ -97,7 +138,7 @@ struct failure : public tut_error */ struct warning : public tut_error { - warning(const std::string& msg) + explicit warning(const std::string& msg) : tut_error(msg) { } @@ -107,6 +148,11 @@ struct warning : public tut_error return test_result::warn; } + virtual std::string type() const + { + return "tut::warning"; + } + ~warning() throw() { } @@ -117,7 +163,7 @@ struct warning : public tut_error */ struct seh : public tut_error { - seh(const std::string& msg) + explicit seh(const std::string& msg) : tut_error(msg) { } @@ -127,6 +173,11 @@ struct seh : public tut_error return test_result::term; } + virtual std::string type() const + { + return "tut::seh"; + } + ~seh() throw() { } @@ -147,6 +198,11 @@ struct rethrown : public failure return test_result::rethrown; } + virtual std::string type() const + { + return "tut::rethrown"; + } + ~rethrown() throw() { } @@ -154,6 +210,28 @@ struct rethrown : public failure const test_result tr; }; +struct skipped : public tut_error +{ + explicit skipped(const std::string& msg) + : tut_error(msg) + { + } + + virtual test_result::result_type result() const + { + return test_result::skipped; + } + + virtual std::string type() const + { + return "tut::skipped"; + } + + ~skipped() throw() + { + } +}; + } #endif diff --git a/tests/tut/tut_fpt.hpp b/tests/tut/tut_fpt.hpp new file mode 100644 index 00000000..e8df8b06 --- /dev/null +++ b/tests/tut/tut_fpt.hpp @@ -0,0 +1,185 @@ +/** + * @brief Additional ensures for scientific/engineering applications. + * @author Joerg + * @date 07/04/2008 + */ +#ifndef TUT_Float_H_GUARD +#define TUT_Float_H_GUARD + +#include +#include + +namespace tut +{ + namespace detail + { + template + struct If + { + typedef Else type; + }; + + template + struct If + { + typedef Then type; + }; + + template + struct fpt_traits + { + struct StdNumericLimitsNotAvailable {}; + static const StdNumericLimitsNotAvailable static_check[ std::numeric_limits::is_specialized ]; + + static const T zero; + + typedef typename If::is_integer, + double, + T>::type Result; + + static T abs(const T &arg) + { + if(arg < zero) + return zero - arg; + else + return arg; + } + + static T sig(const T &arg) + { + if(arg < zero) + return -1; + else + return 1; + } + + static inline Result div(const Result &number, const T &divisor) + { + static_cast(static_check); + + if(number == zero && divisor == zero) + return std::numeric_limits::quiet_NaN(); + + if(number == zero) + return zero; + + if(divisor == zero) + return sig(number) * std::numeric_limits::infinity(); + + assert(zero < number); + assert(zero < divisor); + + // Avoid underflow + if(static_cast(1) < abs(divisor)) + { + // number / divisor < min <=> number < min * divisor + if( abs(number) < abs(divisor) * std::numeric_limits::min()) + { + return sig(divisor) * sig(number) * std::numeric_limits::min(); + } + } + + // Avoid overflow + if( abs(divisor) < static_cast(1)) + { + // number / divisor > max <=> number > max * divisor + if( abs(divisor) * std::numeric_limits::max() < abs(number)) + { + return sig(divisor) * sig(number) * std::numeric_limits::max(); + } + } + + return number / divisor; + } + }; + + template + const typename fpt_traits::StdNumericLimitsNotAvailable + fpt_traits::static_check[ std::numeric_limits::is_specialized ] = { {} }; + + template + const T fpt_traits::zero = static_cast(0); + + template + bool check_tolerance(T actual, T expected, U fraction) + { + typename fpt_traits::Result diff = fpt_traits::div( fpt_traits::abs( expected - actual ), + fpt_traits::abs( expected ) ); + + return (diff == fraction) || (diff < fraction); + } + + } // namespace detail + + template + void ensure_close(const char* msg, const T& actual, const T& expected, const U& tolerance ) + { + typedef detail::fpt_traits Traits; + + typename Traits::Result fraction = Traits::div( Traits::abs(static_cast(tolerance)), + static_cast(100) ); + if( !detail::check_tolerance(actual, expected, fraction) ) + { + std::ostringstream ss; + ss << ( msg ? msg : "" ) + << ( msg ? ": " : "" ) + << "expected `" + << expected + << "` and actual `" + << actual + << "` differ more than " + << tolerance + << "%"; + throw failure( ss.str().c_str() ); + } + } + + template + void ensure_close(const T& actual, const T& expected, const Tolerance& tolerance ) + { + ensure_close( 0, actual, expected, tolerance ); + } + + template + void ensure_close_fraction(const char* msg, const T& actual, const T& expected, const U& fraction) + { + typedef char StdNumericLimitsNotAvailable; + const StdNumericLimitsNotAvailable static_check[ std::numeric_limits::is_specialized ] = { 0 }; + static_cast(static_check); + + typedef typename detail::If::is_integer, + double, + U>::type Tolerance; + + if( !detail::check_tolerance(actual, expected, fraction) ) + { + std::ostringstream ss; + ss << ( msg ? msg : "" ) + << ( msg ? ": " : "" ) + << "expected `" + << expected + << "` and actual `" + << actual + << "` differ more than fraction `" + << fraction + << "`"; + throw failure( ss.str().c_str() ); + } + } + + template + void ensure_close_fraction( const char* msg, const T& actual, const T& expected, const int& tolerance ) + { + ensure_close(msg, actual, expected, double(tolerance)); + } + + template< typename T, typename Tolerance> + void ensure_close_fraction(const T& actual, const T& expected, const Tolerance& fraction) + { + ensure_close_fraction( 0, actual, expected, fraction ); + } + +} // namespace tut + +#endif + diff --git a/tests/tut/tut_macros.hpp b/tests/tut/tut_macros.hpp new file mode 100644 index 00000000..ed517d66 --- /dev/null +++ b/tests/tut/tut_macros.hpp @@ -0,0 +1,63 @@ +#ifndef TUT_MACROS_HPP +#define TUT_MACROS_HPP + +#include + +#ifdef ensure_THROW +#error ensure_THROW macro is already defined +#endif + +/** Helper macros to ensure that a call throws exception. + * \code + * #include + * ensure_THROW( this_function_should_throw_bad_alloc(), std::bad_alloc ); + * \endcode + */ +#define ensure_THROW( x, e ) \ +try \ +{ \ + x; \ + fail(#x " has not thrown expected exception " #e); \ +} \ +catch(const e &) \ +{ \ +} \ +catch(const std::exception &ex) \ +{ \ + fail( std::string(#x " has thrown unexpected exception ")+tut::type_name(ex)+": "+ex.what()); \ +} \ +catch(...) \ +{ \ + fail(#x " has thrown unexpected unknown exception"); \ +} + +#ifdef ensure_NO_THROW +#error ensure_NO_THROW macro is already defined +#endif + +/** Helper macro to ensure a call does not throw any exceptions. + * \code + * #include + * ensure_NO_THROW( this_function_should_never_throw() ); + * \endcode + */ +#define ensure_NO_THROW( x ) \ +try \ +{ \ + x; \ +} \ +catch(const std::exception &ex) \ +{ \ + fail( std::string(#x " has thrown unexpected exception ")+tut::type_name(ex)+": "+ex.what()); \ +} \ +catch(...) \ +{ \ + fail(#x " has thrown unexpected unknown exception"); \ +} + +#ifdef __COUNTER__ +#define TUT_TESTCASE(object) template<> template<> void object::test<__COUNTER__>() +#endif + +#endif + diff --git a/tests/tut/tut_main.hpp b/tests/tut/tut_main.hpp new file mode 100644 index 00000000..c6955bb2 --- /dev/null +++ b/tests/tut/tut_main.hpp @@ -0,0 +1,111 @@ +#ifndef TUT_MAIN_H +#define TUT_MAIN_H + +#include +#include +#include +#include +#include + +namespace tut +{ + +/** Helper function to make test binaries simpler. + * + * Example of basic usage follows. + * + * @code + * namespace tut { test_runner_singleton runner; } + * + * int main(int argc, char **argv) + * { + * if( tut_main(argc, argv) ) + * return 0; + * else + * return -1; + * } + * @endcode + * + * It is also possible to do some generic initialization before + * running any tests and cleanup before exiting application. + * Note that tut_main can throw tut::no_such_group or tut::no_such_test. + * + * @code + * namespace tut { test_runner_singleton runner; } + * + * int main(int argc, char **argv) + * { + * tut::xml_reporter reporter; + * tut::runner.get().insert_callback(&reporter); + * + * MyInit(); + * try + * { + * tut_main(argc, argv); + * } + * catch(const tut::tut_error &ex) + * { + * std::cerr << "TUT error: " << ex.what() << std::endl; + * } + * MyCleanup(); + * } + * @endcode + */ +inline bool tut_main(int argc, const char * const * const argv, std::ostream &os = std::cerr) +{ + std::stringstream usage; + usage << "Usage: " << argv[0] << " [group] [testcase]" << std::endl; + groupnames gr = runner.get().list_groups(); + usage << "Available test groups:" << std::endl; + for(groupnames::const_iterator i = gr.begin(); i != gr.end(); ++i) + { + usage << " " << *i << std::endl; + } + + if(argc>1) + { + if(std::string(argv[1]) == "-h" || + std::string(argv[1]) == "--help" || + std::string(argv[1]) == "/?" || + argc > 3) + { + os << usage.rdbuf(); + return false; + } + } + + // Check command line options. + switch(argc) + { + case 1: + runner.get().run_tests(); + break; + + case 2: + runner.get().run_tests(argv[1]); + break; + + case 3: + { + char *end; + int t = strtol(argv[2], &end, 10); + if(end != argv[2] + strlen(argv[2])) + { + throw no_such_test("`" + std::string(argv[2]) + "` should be a number"); + } + + test_result tr; + if(!runner.get().run_test(argv[1], t, tr) || tr.result == test_result::dummy) + { + throw no_such_test("No testcase `" + std::string(argv[2]) + "` in group `" + argv[1] + "`"); + } + } + break; + } + + return true; +} // tut_main() + +} + +#endif diff --git a/tests/tut/tut_posix.hpp b/tests/tut/tut_posix.hpp index 89a71305..c7cfe57a 100644 --- a/tests/tut/tut_posix.hpp +++ b/tests/tut/tut_posix.hpp @@ -1,5 +1,6 @@ #ifndef TUT_FORK_H_GUARD #define TUT_FORK_H_GUARD +#include #if defined(TUT_USE_POSIX) #include @@ -44,7 +45,7 @@ private: if(tr.result != test_result::ok) { - std::stringstream ss; + std::ostringstream ss; ss << int(tr.result) << "\n" << tr.group << "\n" << tr.test << "\n" @@ -57,6 +58,10 @@ private: ensure_errno("write() failed", w == size); } } + + virtual ~test_group_posix() + { + } }; template @@ -126,7 +131,8 @@ public: * Default constructor */ test_object_posix() - : pipe_(-1) + : pids_(), + pipe_(-1) { } @@ -142,7 +148,7 @@ public: if(!pids_.empty()) { - std::stringstream ss; + std::ostringstream ss; // in parent, reap children for(std::map::iterator i = pids_.begin(); i != pids_.end(); ++i) @@ -226,7 +232,7 @@ private: else { // cannot kill, we are in trouble - std::stringstream ss; + std::ostringstream ss; char e[1024]; ss << "child " << pid << " could not be killed with SIGTERM, " << strerror_r(errno, e, sizeof(e)) << std::endl; fail(ss.str()); @@ -257,7 +263,7 @@ private: } else { - std::stringstream ss; + std::ostringstream ss; char e[1024]; ss << "child " << pid << " could not be killed with SIGKILL, " << strerror_r(errno, e, sizeof(e)) << std::endl; fail(ss.str()); @@ -269,7 +275,7 @@ private: ensure_equals("child process exists after SIGKILL", ::kill(pid, 0), -1); - std::stringstream ss; + std::ostringstream ss; ss << "child " << pid << " had to be killed with SIGKILL"; fail(ss.str()); } @@ -361,7 +367,7 @@ private: { if(WIFSIGNALED(status)) { - std::stringstream ss; + std::ostringstream ss; ss << "child killed by signal " << WTERMSIG(status) << ": expected exit with code " << exit_status; @@ -372,7 +378,7 @@ private: { if(WEXITSTATUS(status) != exit_status) { - std::stringstream ss; + std::ostringstream ss; ss << "child exited, expected '" << exit_status << "' actual '" @@ -385,7 +391,7 @@ private: if(WIFSTOPPED(status)) { - std::stringstream ss; + std::ostringstream ss; ss << "child stopped by signal " << WTERMSIG(status) << ": expected exit with code " << exit_status; throw failure(ss.str().c_str()); @@ -398,7 +404,7 @@ private: { if(WTERMSIG(status) != signal) { - std::stringstream ss; + std::ostringstream ss; ss << "child killed by signal, expected '" << signal << "' actual '" @@ -410,7 +416,7 @@ private: if(WIFEXITED(status)) { - std::stringstream ss; + std::ostringstream ss; ss << "child exited with code " << WEXITSTATUS(status) << ": expected signal " << signal; @@ -419,7 +425,7 @@ private: if(WIFSTOPPED(status)) { - std::stringstream ss; + std::ostringstream ss; ss << "child stopped by signal " << WTERMSIG(status) << ": expected kill by signal " << signal; @@ -453,6 +459,9 @@ namespace tut struct test_object_posix { + virtual ~test_object_posix() + { + } }; struct test_group_posix @@ -461,6 +470,10 @@ struct test_group_posix void send_result_(const T*, const test_result &) { } + + virtual ~test_group_posix() + { + } }; } // namespace tut diff --git a/tests/tut/tut_restartable.hpp b/tests/tut/tut_restartable.hpp index eb6eb00e..9f929234 100644 --- a/tests/tut/tut_restartable.hpp +++ b/tests/tut/tut_restartable.hpp @@ -186,7 +186,7 @@ bool deserialize(std::istream& is, tut::test_result& tr) } return true; } -}; +} /** * Restartable test runner wrapper. @@ -207,11 +207,12 @@ public: */ restartable_wrapper(const std::string& dir = ".") : runner_(runner.get()), - dir_(dir) + callbacks_(), + dir_(dir), + log_( dir + '/' + "log.tut" ), + jrn_( dir + '/' + "journal.tut" ) { // dozen: it works, but it would be better to use system path separator - jrn_ = dir_ + '/' + "journal.tut"; - log_ = dir_ + '/' + "log.tut"; } /** diff --git a/tests/tut/tut_result.hpp b/tests/tut/tut_result.hpp index 5731802c..e9607859 100644 --- a/tests/tut/tut_result.hpp +++ b/tests/tut/tut_result.hpp @@ -1,11 +1,42 @@ #ifndef TUT_RESULT_H_GUARD #define TUT_RESULT_H_GUARD +#include #include +#if defined(TUT_USE_RTTI) +#if (defined(_MSC_VER) && !defined(_CPPRTTI)) || (defined(__GNUC__) && !defined(__GXX_RTTI)) +#undef TUT_USE_RTTI +#endif +#endif + +#if defined(TUT_USE_RTTI) +#include +#endif + namespace tut { +#if defined(TUT_USE_RTTI) +template +inline std::string type_name(const T& t) +{ + return typeid(t).name(); +} +#else +template +inline std::string type_name(const T& t) +{ + return "Unknown type, RTTI disabled"; +} + +inline std::string type_name(const std::exception&) +{ + return "Unknown std::exception, RTTI disabled"; +} +#endif + + #if defined(TUT_USE_POSIX) struct test_result_posix { @@ -14,11 +45,18 @@ struct test_result_posix { } + virtual ~test_result_posix() + { + } + pid_t pid; }; #else struct test_result_posix { + virtual ~test_result_posix() + { + } }; #endif @@ -46,22 +84,19 @@ struct test_result : public test_result_posix std::string name; /** - * ok - test finished successfully - * fail - test failed with ensure() or fail() methods - * ex - test throwed an exceptions - * warn - test finished successfully, but test destructor throwed - * term - test forced test application to terminate abnormally + * result of a test */ enum result_type { - ok, - fail, - ex, - warn, - term, - ex_ctor, - rethrown, - dummy + ok, ///< test finished successfully + fail, ///< test failed with ensure() or fail() methods + ex, ///< test throwed an exceptions + warn, ///< test finished successfully, but test destructor throwed + term, ///< test forced test application to terminate abnormally + ex_ctor, ///< + rethrown, ///< + skipped, ///< + dummy ///< }; result_type result; @@ -76,8 +111,12 @@ struct test_result : public test_result_posix * Default constructor. */ test_result() - : test(0), - result(ok) + : group(), + test(0), + name(), + result(ok), + message(), + exception_typeid() { } @@ -89,7 +128,9 @@ struct test_result : public test_result_posix : group(grp), test(pos), name(test_name), - result(res) + result(res), + message(), + exception_typeid() { } @@ -104,7 +145,7 @@ struct test_result : public test_result_posix name(test_name), result(res), message(ex.what()), - exception_typeid(typeid(ex).name()) + exception_typeid(type_name(ex)) { } @@ -122,6 +163,10 @@ struct test_result : public test_result_posix exception_typeid(ex_typeid) { } + + virtual ~test_result() + { + } }; } diff --git a/tests/tut/tut_runner.hpp b/tests/tut/tut_runner.hpp index 33ffe423..3803046e 100644 --- a/tests/tut/tut_runner.hpp +++ b/tests/tut/tut_runner.hpp @@ -62,24 +62,27 @@ struct callback * Called when a group started * @param name Name of the group */ - virtual void group_started(const std::string& /*name*/) + virtual void group_started(const std::string& name) { + (void)name; } /** * Called when a test finished. * @param tr Test results. */ - virtual void test_completed(const test_result& /*tr*/) + virtual void test_completed(const test_result& tr) { + (void)tr; } /** * Called when a group is completed * @param name Name of the group */ - virtual void group_completed(const std::string& /*name*/) + virtual void group_completed(const std::string& name) { + (void)name; } /** @@ -88,6 +91,11 @@ struct callback virtual void run_completed() { } + + virtual bool all_ok() const + { + return true; + } private: callback(const callback &); void operator=(const callback&); @@ -111,11 +119,15 @@ public: * Constructor */ test_runner() + : groups_(), + callbacks_() { } /** * Stores another group for getting by name. + * @param name new group object + * @param gr new callback object */ void register_group(const std::string& name, group_base* gr) { @@ -127,15 +139,16 @@ public: if (groups_.find(name) != groups_.end()) { std::string msg("attempt to add already existent group " + name); - // this exception terminates application so we use cerr also - // TODO: should this message appear in stream? - std::cerr << msg << std::endl; throw tut_error(msg); } groups_.insert( std::make_pair(name, gr) ); } + /** + * Stores one callback object. + * @param cb new callback object + */ void set_callback(callback *cb) { clear_callbacks(); @@ -143,7 +156,8 @@ public: } /** - * Stores callback object. + * Add callback object. + * @param cb new callback object */ void insert_callback(callback* cb) { @@ -153,11 +167,18 @@ public: } } + /** + * Remove callback object. + * @param cb callback to remove + */ void erase_callback(callback* cb) { callbacks_.erase(cb); } + /** + * Remove all callback objects. + */ void clear_callbacks() { callbacks_.clear(); @@ -165,12 +186,17 @@ public: /** * Returns callback list. + * @return callback list */ const callbacks &get_callbacks() const { return callbacks_; } + /** + * Set callback list. + * @param cb new callback list + */ void set_callbacks(const callbacks &cb) { callbacks_ = cb; @@ -178,23 +204,20 @@ public: /** * Returns list of known test groups. + * @return groups list */ const groupnames list_groups() const { groupnames ret; - const_iterator i = groups_.begin(); - const_iterator e = groups_.end(); - while (i != e) + for(const_iterator i = groups_.begin(); i != groups_.end(); ++i) { ret.push_back(i->first); - ++i; } return ret; } /** * Runs all tests in all groups. - * @param callback Callback object if exists; null otherwise */ void run_tests() const { @@ -216,6 +239,7 @@ public: /** * Runs all tests in specified group. + * @param group_name group to test */ void run_tests(const std::string& group_name) const { @@ -236,6 +260,10 @@ public: /** * Runs one test in specified group. + * @param group_name group to test + * @param n run case in test + * @param tr result of this case + * @return true if test is ok, otherwise false */ bool run_test(const std::string& group_name, int n, test_result &tr) const { @@ -356,4 +384,5 @@ extern test_runner_singleton runner; } -#endif +#endif // TUT_RUNNER_H_GUARD + diff --git a/tests/tut/tut_xml_reporter.hpp b/tests/tut/tut_xml_reporter.hpp index 8a9d5dec..d0c301dd 100644 --- a/tests/tut/tut_xml_reporter.hpp +++ b/tests/tut/tut_xml_reporter.hpp @@ -1,16 +1,9 @@ -/* - * tut_xml_reporter.hpp - * - * ECOS Library. IPT CS R&D CET ECOS Copyright 2008 Nokia - * Siemens Networks. All right - * - * - */ - #ifndef TUT_XML_REPORTER #define TUT_XML_REPORTER - +#include #include +#include +#include #include #include #include @@ -26,62 +19,12 @@ namespace tut */ class xml_reporter : public tut::callback { -protected: typedef std::vector TestResults; typedef std::map TestGroups; - TestGroups all_tests; /// holds all test results - std::string filename; /// filename base - - /** - * \brief Initializes object - * Resets counters and clears all stored test results. - */ - virtual void init() - { - ok_count = 0; - exceptions_count = 0; - failures_count = 0; - terminations_count = 0; - warnings_count = 0; - all_tests.clear(); - } - - /** - * \brief Encodes text to XML - * XML-reserved characters (e.g. "<") are encoded according to specification - * @param text text to be encoded - * @return encoded string - */ - virtual std::string encode(const std::string & text) - { - std::string out; - - for (unsigned int i=0; i': - out += ">"; - break; - case '&': - out += "&"; - break; - case '\'': - out += "'"; - break; - case '"': - out += """; - break; - default: - out += c; - } - } - - return out; - } + TestGroups all_tests_; /// holds all test results + const std::string filename_; /// filename base + std::auto_ptr stream_; /** * \brief Builds "testcase" XML entity with given parameters @@ -91,7 +34,7 @@ protected: * @param failure_msg failure message to be reported (empty, if test passed) * @return string with \ entity */ - virtual std::string xml_build_testcase(const tut::test_result & tr, const std::string & failure_type, + std::string xml_build_testcase(const tut::test_result & tr, const std::string & failure_type, const std::string & failure_msg, int pid = 0) { using std::endl; @@ -99,17 +42,18 @@ protected: std::ostringstream out; - if (tr.result == test_result::ok) + if ( (tr.result == test_result::ok) || + (tr.result == test_result::skipped) ) { - out << " "; + out << " "; } else { - string err_msg = encode(failure_msg + tr.message); + string err_msg = cppunit_reporter::encode(failure_msg + tr.message); string tag; // determines tag name: "failure" or "error" if ( tr.result == test_result::fail || tr.result == test_result::warn || - tr.result == test_result::ex || tr.result == test_result::ex_ctor ) + tr.result == test_result::ex || tr.result == test_result::ex_ctor || tr.result == test_result::rethrown ) { tag = "failure"; } @@ -118,16 +62,18 @@ protected: tag = "error"; } - out << " " << endl; - out << " <" << tag << " message=\"" << err_msg << "\"" << " type=\"" << failure_type << "\""; + out << " " << endl; + out << " <" << tag << " message=\"" << err_msg << "\"" << " type=\"" << failure_type << "\""; #if defined(TUT_USE_POSIX) if(pid != getpid()) { out << " child=\"" << pid << "\""; } +#else + (void)pid; #endif out << ">" << err_msg << "" << endl; - out << " "; + out << " "; } return out.str(); @@ -140,17 +86,17 @@ protected: * @param failures number of failures to be reported * @param total total number of tests to be reported * @param name test suite name - * @param testcases encoded XML string containing testcases + * @param testcases cppunit_reporter::encoded XML string containing testcases * @return string with \ entity */ - virtual std::string xml_build_testsuite(int errors, int failures, int total, + std::string xml_build_testsuite(int errors, int failures, int total, const std::string & name, const std::string & testcases) { std::ostringstream out; - out << "" << std::endl; + out << " " << std::endl; out << testcases; - out << ""; + out << " "; return out.str(); } @@ -165,39 +111,39 @@ public: /** * \brief Default constructor * @param filename base filename - * @see setFilenameBase */ - xml_reporter(const std::string & _filename = "") + xml_reporter(const std::string & filename) + : all_tests_(), + filename_(filename), + stream_(new std::ofstream(filename_.c_str())), + ok_count(0), + exceptions_count(0), + failures_count(0), + terminations_count(0), + warnings_count(0) { - init(); - setFilenameBase(_filename); + if (!stream_->good()) { + throw tut_error("Cannot open output file `" + filename_ + "`"); + } } - /** - * \brief Sets filename base for output - * @param _filename filename base - * Example usage: - * @code - * xml_reporter reporter; - * reporter.setFilenameBase("my_xml"); - * @endcode - * The above code will instruct reporter to create my_xml_1.xml file for the first test group, - * my_xml_2.xml file for the second, and so on. - */ - virtual void setFilenameBase(const std::string & _filename) + xml_reporter(std::ostream & stream) + : all_tests_(), + filename_(), + stream_(&stream), + ok_count(0), + exceptions_count(0), + failures_count(0), + terminations_count(0), + warnings_count(0) { - if (_filename == "") - { - filename = "testResult"; - } - else - { - if (_filename.length() > 200) - { - throw(std::runtime_error("Filename too long!")); - } + } - filename = _filename; + ~xml_reporter() + { + if(filename_.empty()) + { + stream_.release(); } } @@ -207,7 +153,12 @@ public: */ virtual void run_started() { - init(); + ok_count = 0; + exceptions_count = 0; + failures_count = 0; + terminations_count = 0; + warnings_count = 0; + all_tests_.clear(); } /** @@ -219,6 +170,7 @@ public: // update global statistics switch (tr.result) { case test_result::ok: + case test_result::skipped: ok_count++; break; case test_result::fail: @@ -235,60 +187,52 @@ public: case test_result::term: terminations_count++; break; + case tut::test_result::dummy: + assert(!"Should never be called"); } // switch // add test result to results table - (all_tests[tr.group]).push_back(tr); + all_tests_[tr.group].push_back(tr); } /** * \brief Callback function * This function is called when all tests are completed. It generates XML output - * to file(s). File name base can be set with \ref setFilenameBase. + * to file(s). File name base can be set with constructor. */ virtual void run_completed() { - using std::endl; - using std::string; - - static int number = 1; // results file sequence number (testResult_.xml) + /* *********************** header ***************************** */ + *stream_ << "" << std::endl; + *stream_ << "" << std::endl; // iterate over all test groups - TestGroups::const_iterator tgi; - for (tgi = all_tests.begin(); tgi != all_tests.end(); ++tgi) { + for (TestGroups::const_iterator tgi = all_tests_.begin(); tgi != all_tests_.end(); ++tgi) + { /* per-group statistics */ int passed = 0; // passed in single group int exceptions = 0; // exceptions in single group int failures = 0; // failures in single group int terminations = 0; // terminations in single group int warnings = 0; // warnings in single group - int errors = 0; // errors in single group + int errors = 0; // errors in single group - /* generate output filename */ - char fn[256]; - sprintf(fn, "%s_%d.xml", filename.c_str(), number++); - - std::ofstream xmlfile; - xmlfile.open(fn, std::ios::in | std::ios::trunc); - if (!xmlfile.is_open()) { - throw (std::runtime_error("Cannot open file for output")); - } - - /* *********************** header ***************************** */ - xmlfile << "" << endl; // output is written to string stream buffer, because JUnit format tag // contains statistics, which aren't known yet std::ostringstream out; // iterate over all test cases in the current test group - TestResults::const_iterator tri; - for (tri = (*tgi).second.begin(); tri != (*tgi).second.end(); ++tri) { - string failure_type; // string describing the failure type - string failure_msg; // a string with failure message + const TestResults &results = tgi->second; + for (TestResults::const_iterator tri = results.begin(); tri != results.end(); ++tri) + { + std::string failure_type; // string describing the failure type + std::string failure_msg; // a string with failure message - switch ((*tri).result) { + switch (tri->result) + { case test_result::ok: + case test_result::skipped: passed++; break; case test_result::fail: @@ -298,7 +242,7 @@ public: break; case test_result::ex: failure_type = "Assertion"; - failure_msg = "Thrown exception: " + (*tri).exception_typeid + '\n'; + failure_msg = "Thrown exception: " + tri->exception_typeid + '\n'; exceptions++; break; case test_result::warn: @@ -313,28 +257,27 @@ public: break; case test_result::ex_ctor: failure_type = "Assertion"; - failure_msg = "Constructor has thrown an exception: " + (*tri).exception_typeid + '\n'; + failure_msg = "Constructor has thrown an exception: " + tri->exception_typeid + ".\n"; exceptions++; break; case test_result::rethrown: failure_type = "Assertion"; - failure_msg = "Child failed"; + failure_msg = "Child failed.\n"; failures++; break; default: failure_type = "Error"; failure_msg = "Unknown test status, this should have never happened. " - "You may just have found a BUG in TUT XML reporter, please report it immediately.\n"; + "You may just have found a bug in TUT, please report it immediately.\n"; errors++; break; } // switch #if defined(TUT_USE_POSIX) - out << xml_build_testcase(*tri, failure_type, failure_msg, (*tri).pid) << endl; + out << xml_build_testcase(*tri, failure_type, failure_msg, tri->pid) << std::endl; #else - out << xml_build_testcase(*tri, failure_type, failure_msg) << endl; + out << xml_build_testcase(*tri, failure_type, failure_msg) << std::endl; #endif - } // iterate over all test cases // calculate per-group statistics @@ -342,9 +285,10 @@ public: int stat_failures = failures + warnings + exceptions; int stat_all = stat_errors + stat_failures + passed; - xmlfile << xml_build_testsuite(stat_errors, stat_failures, stat_all, (*tgi).first/* name */, out.str()/* testcases */) << endl; - xmlfile.close(); + *stream_ << xml_build_testsuite(stat_errors, stat_failures, stat_all, (*tgi).first/* name */, out.str()/* testcases */) << std::endl; } // iterate over all test groups + + *stream_ << "" << std::endl; } /** diff --git a/tests/tut_reporter.h b/tests/tut_reporter.h deleted file mode 100644 index e568635a..00000000 --- a/tests/tut_reporter.h +++ /dev/null @@ -1,5 +0,0 @@ - -#include -#include -#include -#include diff --git a/tests/tut_restartable.h b/tests/tut_restartable.h deleted file mode 100644 index c7897797..00000000 --- a/tests/tut_restartable.h +++ /dev/null @@ -1,2 +0,0 @@ - -#include