1 | /* |
2 | * The contents of this file are subject to the Initial |
3 | * Developer's Public License Version 1.0 (the "License"); |
4 | * you may not use this file except in compliance with the |
5 | * License. You may obtain a copy of the License at |
6 | * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
7 | * |
8 | * Software distributed under the License is distributed AS IS, |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. |
10 | * See the License for the specific language governing rights |
11 | * and limitations under the License. |
12 | * |
13 | * The Original Code was created by Claudio Valderrama on 25-Dec-2003 |
14 | * for the Firebird Open Source RDBMS project. |
15 | * |
16 | * Copyright (c) 2003 Claudio Valderrama |
17 | * and all contributors signed below. |
18 | * |
19 | * All Rights Reserved. |
20 | * Contributor(s): ______________________________________. |
21 | * |
22 | * Nickolay Samofatov <nickolay@broadviewsoftware.com> |
23 | */ |
24 | |
25 | |
26 | // ===================================== |
27 | // Utility functions |
28 | |
29 | #ifndef INCLUDE_UTILS_PROTO_H |
30 | #define INCLUDE_UTILS_PROTO_H |
31 | |
32 | #include <string.h> |
33 | #include "../common/classes/fb_string.h" |
34 | #include "../common/classes/array.h" |
35 | #include "gen/iberror.h" |
36 | #include "firebird/Provider.h" |
37 | |
38 | #ifdef SFIO |
39 | #include <stdio.h> |
40 | #endif |
41 | |
42 | namespace fb_utils |
43 | { |
44 | char* copy_terminate(char* dest, const char* src, size_t bufsize); |
45 | char* exact_name(char* const str); |
46 | inline void exact_name(Firebird::string& str) |
47 | { |
48 | str.rtrim(); |
49 | } |
50 | char* exact_name_limit(char* const str, size_t bufsize); |
51 | bool implicit_domain(const char* domain_name); |
52 | bool implicit_integrity(const char* integ_name); |
53 | bool implicit_pk(const char* pk_name); |
54 | int name_length(const TEXT* const name); |
55 | bool readenv(const char* env_name, Firebird::string& env_value); |
56 | bool readenv(const char* env_name, Firebird::PathName& env_value); |
57 | int snprintf(char* buffer, size_t count, const char* format...); |
58 | char* cleanup_passwd(char* arg); |
59 | inline char* get_passwd(char* arg) |
60 | { |
61 | return cleanup_passwd(arg); |
62 | } |
63 | typedef char* arg_string; |
64 | |
65 | // Warning: Only wrappers: |
66 | |
67 | // ******************** |
68 | // s t r i c m p |
69 | // ******************** |
70 | // Abstraction of incompatible routine names |
71 | // for case insensitive comparison. |
72 | inline int stricmp(const char* a, const char* b) |
73 | { |
74 | #if defined(HAVE_STRCASECMP) |
75 | return ::strcasecmp(a, b); |
76 | #elif defined(HAVE_STRICMP) |
77 | return ::stricmp(a, b); |
78 | #else |
79 | #error dont know how to compare strings case insensitive on this system |
80 | #endif |
81 | } |
82 | |
83 | |
84 | // ******************** |
85 | // s t r n i c m p |
86 | // ******************** |
87 | // Abstraction of incompatible routine names |
88 | // for counted length and case insensitive comparison. |
89 | inline int strnicmp(const char* a, const char* b, size_t count) |
90 | { |
91 | #if defined(HAVE_STRNCASECMP) |
92 | return ::strncasecmp(a, b, count); |
93 | #elif defined(HAVE_STRNICMP) |
94 | return ::strnicmp(a, b, count); |
95 | #else |
96 | #error dont know how to compare counted length strings case insensitive on this system |
97 | #endif |
98 | } |
99 | |
100 | #ifdef WIN_NT |
101 | bool prefix_kernel_object_name(char* name, size_t bufsize); |
102 | bool isGlobalKernelPrefix(); |
103 | #endif |
104 | |
105 | Firebird::PathName get_process_name(); |
106 | SLONG genUniqueId(); |
107 | |
108 | void getCwd(Firebird::PathName& pn); |
109 | |
110 | void inline init_status(ISC_STATUS* status) |
111 | { |
112 | status[0] = isc_arg_gds; |
113 | status[1] = FB_SUCCESS; |
114 | status[2] = isc_arg_end; |
115 | } |
116 | |
117 | void inline init_status(Firebird::IStatus* status) |
118 | { |
119 | status->init(); |
120 | } |
121 | |
122 | unsigned int copyStatus(ISC_STATUS* const to, const unsigned int space, |
123 | const ISC_STATUS* const from, const unsigned int count) throw(); |
124 | |
125 | unsigned int statusLength(const ISC_STATUS* const status) throw(); |
126 | |
127 | enum FetchPassResult { |
128 | FETCH_PASS_OK, |
129 | FETCH_PASS_FILE_OPEN_ERROR, |
130 | FETCH_PASS_FILE_READ_ERROR, |
131 | FETCH_PASS_FILE_EMPTY |
132 | }; |
133 | FetchPassResult fetchPassword(const Firebird::PathName& name, const char*& password); |
134 | |
135 | // Returns current value of performance counter |
136 | SINT64 query_performance_counter(); |
137 | |
138 | // Returns frequency of performance counter in Hz |
139 | SINT64 query_performance_frequency(); |
140 | |
141 | void get_process_times(SINT64 &userTime, SINT64 &sysTime); |
142 | |
143 | void exactNumericToStr(SINT64 value, int scale, Firebird::string& target, bool append = false); |
144 | |
145 | // Returns true if called from firebird build process (appr. environment is set) |
146 | bool bootBuild(); |
147 | |
148 | // Add appropriate file prefix. |
149 | Firebird::PathName getPrefix(unsigned prefType, const char* name); |
150 | |
151 | // moves DB path information (from limbo transaction) to another buffer |
152 | void getDbPathInfo(unsigned int& itemsLength, const unsigned char*& items, |
153 | unsigned int& bufferLength, unsigned char*& buffer, |
154 | Firebird::Array<unsigned char>& newItemsBuffer, const Firebird::PathName& dbpath); |
155 | |
156 | // returns true if passed info items work with running svc thread |
157 | bool isRunningCheck(const UCHAR* items, unsigned int length); |
158 | |
159 | // converts bytes to BASE64 representation |
160 | void base64(Firebird::string& b64, const Firebird::UCharBuffer& bin); |
161 | |
162 | // generate random string in BASE64 representation |
163 | void random64(Firebird::string& randomValue, size_t length); |
164 | |
165 | void logAndDie(const char* text); |
166 | |
167 | // Returns next offset value |
168 | unsigned sqlTypeToDsc(unsigned prevOffset, unsigned sqlType, unsigned sqlLength, |
169 | unsigned* dtype, unsigned* len, unsigned* offset, unsigned* nullOffset); |
170 | } // namespace fb_utils |
171 | |
172 | #endif // INCLUDE_UTILS_PROTO_H |
173 | |