]> git.stg.codes - stg.git/blob - stglibs/ibpp.lib/_rb.cpp
Merge branch 'stg-2.409-radius'
[stg.git] / stglibs / ibpp.lib / _rb.cpp
1 ///////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //      File    : $Id: _rb.cpp,v 1.2 2009/03/19 20:00:27 faust Exp $\r
4 //      Subject : IBPP, internal RB class implementation\r
5 //\r
6 ///////////////////////////////////////////////////////////////////////////////\r
7 //\r
8 //      (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)\r
9 //\r
10 //      The contents of this file are subject to the IBPP License (the "License");\r
11 //      you may not use this file except in compliance with the License.  You may\r
12 //      obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'\r
13 //      file which must have been distributed along with this file.\r
14 //\r
15 //      This software, distributed under the License, is distributed on an "AS IS"\r
16 //      basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the\r
17 //      License for the specific language governing rights and limitations\r
18 //      under the License.\r
19 //\r
20 ///////////////////////////////////////////////////////////////////////////////\r
21 //\r
22 //      COMMENTS\r
23 //      * RB == Result Block/Buffer, see Interbase 6.0 C-API\r
24 //      * Tabulations should be set every four characters when editing this file.\r
25 //\r
26 ///////////////////////////////////////////////////////////////////////////////\r
27 \r
28 #ifdef _MSC_VER\r
29 #pragma warning(disable: 4786 4996)\r
30 #ifndef _DEBUG\r
31 #pragma warning(disable: 4702)\r
32 #endif\r
33 #endif\r
34 \r
35 #include "_ibpp.h"\r
36 \r
37 #ifdef HAS_HDRSTOP\r
38 #pragma hdrstop\r
39 #endif\r
40 \r
41 #include <cstring>\r
42 \r
43 using namespace ibpp_internals;\r
44 \r
45 char* RB::FindToken(char token)\r
46 {\r
47         char* p = mBuffer;\r
48 \r
49         while (*p != isc_info_end)\r
50         {\r
51                 int len;\r
52 \r
53                 if (*p == token) return p;\r
54                 len = (*gds.Call()->m_vax_integer)(p+1, 2);\r
55                 p += (len + 3);\r
56         }\r
57 \r
58         return 0;\r
59 }\r
60 \r
61 char* RB::FindToken(char token, char subtoken)\r
62 {\r
63         char* p = mBuffer;\r
64 \r
65         while (*p != isc_info_end)\r
66         {\r
67                 int len;\r
68 \r
69                 if (*p == token)\r
70                 {\r
71                         // Found token, now find subtoken\r
72                         int inlen = (*gds.Call()->m_vax_integer)(p+1, 2);\r
73                         p += 3;\r
74                         while (inlen > 0)\r
75                         {\r
76                                 if (*p == subtoken) return p;\r
77                                 len = (*gds.Call()->m_vax_integer)(p+1, 2);\r
78                                 p += (len + 3);\r
79                                 inlen -= (len + 3);\r
80                         }\r
81                         return 0;\r
82                 }\r
83                 len = (*gds.Call()->m_vax_integer)(p+1, 2);\r
84                 p += (len + 3);\r
85         }\r
86 \r
87         return 0;\r
88 }\r
89 \r
90 int RB::GetValue(char token)\r
91 {\r
92         int value;\r
93         int len;\r
94         char* p = FindToken(token);\r
95 \r
96         if (p == 0)\r
97                 throw LogicExceptionImpl("RB::GetValue", _("Token not found."));\r
98 \r
99         len = (*gds.Call()->m_vax_integer)(p+1, 2);\r
100         if (len == 0) value = 0;\r
101         else value = (*gds.Call()->m_vax_integer)(p+3, (short)len);\r
102 \r
103         return value;\r
104 }\r
105 \r
106 int RB::GetCountValue(char token)\r
107 {\r
108         // Specifically used on tokens like isc_info_insert_count and the like\r
109         // which return detailed counts per relation. We sum up the values.\r
110         int value;\r
111         int len;\r
112         char* p = FindToken(token);\r
113 \r
114         if (p == 0)\r
115                 throw LogicExceptionImpl("RB::GetCountValue", _("Token not found."));\r
116 \r
117         // len is the number of bytes in the following array\r
118         len = (*gds.Call()->m_vax_integer)(p+1, 2);\r
119         p += 3;\r
120         value = 0;\r
121         while (len > 0)\r
122         {\r
123                 // Each array item is 6 bytes : 2 bytes for the relation_id which\r
124                 // we skip, and 4 bytes for the count value which we sum up accross\r
125                 // all tables.\r
126                 value += (*gds.Call()->m_vax_integer)(p+2, 4);\r
127                 p += 6;\r
128                 len -= 6;\r
129         }\r
130 \r
131         return value;\r
132 }\r
133 \r
134 int RB::GetValue(char token, char subtoken)\r
135 {\r
136         int value;\r
137         int len;\r
138         char* p = FindToken(token, subtoken);\r
139 \r
140         if (p == 0)\r
141                 throw LogicExceptionImpl("RB::GetValue", _("Token/Subtoken not found."));\r
142 \r
143         len = (*gds.Call()->m_vax_integer)(p+1, 2);\r
144         if (len == 0) value = 0;\r
145         else value = (*gds.Call()->m_vax_integer)(p+3, (short)len);\r
146 \r
147         return value;\r
148 }\r
149 \r
150 bool RB::GetBool(char token)\r
151 {\r
152         int value;\r
153         char* p = FindToken(token);\r
154 \r
155         if (p == 0)\r
156                 throw LogicExceptionImpl("RB::GetBool", _("Token not found."));\r
157 \r
158         value = (*gds.Call()->m_vax_integer)(p+1, 4);\r
159 \r
160         return value == 0 ? false : true;\r
161 }\r
162 \r
163 int RB::GetString(char token, std::string& data)\r
164 {\r
165         int len;\r
166         char* p = FindToken(token);\r
167 \r
168         if (p == 0)\r
169                 throw LogicExceptionImpl("RB::GetString", _("Token not found."));\r
170 \r
171         len = (*gds.Call()->m_vax_integer)(p+1, 2);\r
172         data = std::string(p+3, len);\r
173         return len;\r
174 }\r
175 \r
176 void RB::Reset()\r
177 {\r
178         delete [] mBuffer;\r
179         mBuffer = new char [mSize];\r
180         memset(mBuffer, 255, mSize);\r
181 }\r
182 \r
183 RB::RB()\r
184 {\r
185         mSize = 1024;\r
186         mBuffer = new char [1024];\r
187         memset(mBuffer, 255, mSize);\r
188 }\r
189 \r
190 RB::RB(int Size)\r
191 {\r
192         mSize = Size;\r
193         mBuffer = new char [Size];\r
194         memset(mBuffer, 255, mSize);\r
195 }\r
196 \r
197 RB::~RB()\r
198 {\r
199         try { delete [] mBuffer; }\r
200                 catch (...) { }\r
201 }\r
202 \r
203 //\r
204 //      EOF\r
205 //\r