From 6809f624fc8968b623d6e6741eeebf7853ed31b9 Mon Sep 17 00:00:00 2001 From: alexpeshkoff Date: Mon, 24 Mar 2008 15:28:38 +0000 Subject: [PATCH] Remote cleanup: 1. Avoid ALLR memory allocation routine (use new / delete). 2. Use common (TypedHandle) class to control consistency of handles. 3. Make ctors and dtors work - in most cases more work is needed to make them meaningful. --- src/remote/allr.cpp | 199 ------------ src/remote/allr_proto.h | 45 --- src/remote/inet.cpp | 124 ++------ src/remote/inter_proto.h | 102 +++--- src/remote/interface.cpp | 421 +++++++++++-------------- src/remote/parse_proto.h | 2 +- src/remote/parser.cpp | 15 +- src/remote/protocol.cpp | 98 +++--- src/remote/protocol.h | 6 + src/remote/remot_proto.h | 14 +- src/remote/remote.cpp | 102 ++---- src/remote/remote.h | 604 ++++++++++++++++++++++++----------- src/remote/server.cpp | 661 ++++++++++----------------------------- src/remote/xdr.cpp | 1 - src/remote/xdr.h | 5 + 15 files changed, 925 insertions(+), 1474 deletions(-) delete mode 100644 src/remote/allr.cpp delete mode 100644 src/remote/allr_proto.h diff --git a/src/remote/allr.cpp b/src/remote/allr.cpp deleted file mode 100644 index eed9dff4ba..0000000000 --- a/src/remote/allr.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * PROGRAM: JRD Remote Interface/Server - * MODULE: allr.cpp - * DESCRIPTION: Internal block allocator - * - * The contents of this file are subject to the Interbase Public - * License Version 1.0 (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.Inprise.com/IPL.html - * - * 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. - * - * The Original Code was created by Inprise Corporation - * and its predecessors. Portions created by Inprise Corporation are - * Copyright (C) Inprise Corporation. - * - * All Rights Reserved. - * Contributor(s): ______________________________________. - */ - -#include "firebird.h" -#include -#include -#include "../remote/remote.h" -#include "gen/iberror.h" -#include "../remote/allr_proto.h" -#include "../common/classes/alloc.h" - - -static const struct -{ - blk_t type; - USHORT typ_root_length; - USHORT typ_tail_length; -} REM_block_sizes[] = -{ - {type_MIN , 0, 0}, - {type_vec , sizeof(rem_vec) , sizeof(((rem_vec*) NULL)->vec_object[0])}, - {type_rdb , sizeof(rdb) , 0}, - {type_fmt , sizeof(rem_fmt) , sizeof(dsc/*((rem_fmt*) NULL)->fmt_desc[0]*/)}, - {type_rrq , sizeof(rrq) , sizeof(((rrq*) NULL)->rrq_rpt [0])}, - {type_rtr , sizeof(rtr) , 0}, - {type_str , sizeof(rem_str) , 1}, // random string block - {type_rbl , sizeof(rbl) , 1}, - {type_port , sizeof(rem_port) , 1}, - {type_msg , sizeof(message) , 1}, - {type_rsr , sizeof(rsr) , 0}, - {type_rvnt , sizeof(rvnt) , 0}, - {type_rpr , sizeof(rpr) , 0}, - {type_rmtque , sizeof(rmtque) , 0}, - - {type_MAX, 0, 0} -}; - - - -//____________________________________________________________ -// -// Allocate a block. -// -#ifdef DEBUG_GDS_ALLOC -UCHAR* ALLR_alloc_debug(ULONG size, const TEXT* FileName, ULONG LineNumber) -#else -UCHAR* ALLR_alloc(ULONG size) -#endif -{ - UCHAR* block = (UCHAR*) -#ifdef DEBUG_GDS_ALLOC - gds__alloc_debug((SLONG)size, FileName, LineNumber); -#else - gds__alloc((SLONG) size); -#endif - - if (block) - { - return block; - } - - // FREE: caller must free - usually using ALLR_free. - // NOMEM: post a user level error, if we have a status vector, - // otherwise just an error return - - Firebird::BadAlloc::raise(); - return NULL; /* compiler silencer */ -} - - -//____________________________________________________________ -// -// Allocate a block from a given pool and initialize the block. -// This is the primary block allocation routine. -// -#ifdef DEBUG_GDS_ALLOC -BLK ALLR_block_debug(UCHAR type, ULONG count, const TEXT* FileName, ULONG LineNumber) -#else -BLK ALLR_block(UCHAR type, ULONG count) -#endif -{ - if (type <= (UCHAR) type_MIN || type >= (UCHAR) type_MAX) - { - Firebird::BadAlloc::raise(); - } - - ULONG size = REM_block_sizes[type].typ_root_length; - ULONG tail = REM_block_sizes[type].typ_tail_length; - - if (tail && count > 1) { - size += (count - 1) * tail; - } - - BLK block = (BLK) -#ifdef DEBUG_GDS_ALLOC - ALLR_alloc_debug(size, FileName, LineNumber); -#else - ALLR_alloc(size); -#endif - - // NOMEM: callee handled - // FREE: caller must handle - use ALLR_free - - block->blk_type = type; - block->blk_length = size; - - size -= sizeof(struct blk); - - if (size) { - memset((char*)block + sizeof(struct blk), 0, size); - } - - return block; -} - - -//____________________________________________________________ -// -// Clone a block. -// -// Caller is responsible for free'ing the clone -// -BLK ALLR_clone(BLK block) -{ - ULONG l = block->blk_length; - BLK clone = (BLK) ALLR_alloc(l); - - // NOMEM: ALLR_alloc() handled - // FREE: caller must handle - use ALLR_free - - memcpy(clone, block, l); - return clone; -} - - -//____________________________________________________________ -// -// Free a block. -// -void ALLR_free( void *block) -{ - gds__free(block); -} - - -//____________________________________________________________ -// -// Allocate a vector. -// -rem_vec* ALLR_vector(rem_vec** ptr, ULONG count) -{ - ++count; - - rem_vec* vector = *ptr; - - if (!vector) { - vector = *ptr = (rem_vec*) ALLR_block(type_vec, count); - vector->vec_count = count; - return vector; - } - -/* If it fits, do it */ - - if (count <= vector->vec_count) - return vector; - - rem_vec* new_vector = *ptr = (rem_vec*) ALLR_block(type_vec, count); - new_vector->vec_count = count; - - blk** p = new_vector->vec_object; - blk* const* q = vector->vec_object; - const blk* const* const end = q + (int) vector->vec_count; - while (q < end) { - *p++ = *q++; - } - ALLR_free(vector); - - return new_vector; -} diff --git a/src/remote/allr_proto.h b/src/remote/allr_proto.h deleted file mode 100644 index b33e1d707e..0000000000 --- a/src/remote/allr_proto.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * PROGRAM: JRD Remote Interface/Server - * MODULE: allr_proto.h - * DESCRIPTION: Prototype header file for allr.cpp - * - * The contents of this file are subject to the Interbase Public - * License Version 1.0 (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.Inprise.com/IPL.html - * - * 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. - * - * The Original Code was created by Inprise Corporation - * and its predecessors. Portions created by Inprise Corporation are - * Copyright (C) Inprise Corporation. - * - * All Rights Reserved. - * Contributor(s): ______________________________________. - */ - -#ifndef REMOTE_ALLR_PROTO_H -#define REMOTE_ALLR_PROTO_H - -struct blk; -struct rem_vec; - -#ifdef DEBUG_GDS_ALLOC -#define ALLR_alloc(s) ALLR_alloc_debug((s), (TEXT*)__FILE__, (ULONG)__LINE__) -#define ALLR_block(s, sz) ALLR_block_debug((s), (sz), (TEXT*)__FILE__, (ULONG)__LINE__) -UCHAR* ALLR_alloc_debug(ULONG, const TEXT*, ULONG); -blk* ALLR_block_debug(UCHAR, ULONG, const TEXT*, ULONG); -#else //DEBUG_GDS_ALLOC -UCHAR* ALLR_alloc(ULONG); -blk* ALLR_block(UCHAR, ULONG); -#endif //DEBUG_GDS_ALLOC - -blk* ALLR_clone(blk*); -void ALLR_free (void *); -rem_vec* ALLR_vector (rem_vec**, ULONG); - -#endif // REMOTE_ALLR_PROTO_H - diff --git a/src/remote/inet.cpp b/src/remote/inet.cpp index 79c48a7d7a..25f43d1ead 100644 --- a/src/remote/inet.cpp +++ b/src/remote/inet.cpp @@ -247,7 +247,6 @@ static rem_port* aux_request(rem_port*, PACKET*); static int check_host(rem_port*, TEXT*, const TEXT*, const struct passwd*); static bool check_proxy(rem_port*, TEXT*, Firebird::string&); #endif // WIN_NT -static void cleanup_port(rem_port*); static void disconnect(rem_port*); static void exit_handler(void *); @@ -393,7 +392,7 @@ rem_port* INET_analyze(Firebird::PathName& file_name, /* We need to establish a connection to a remote server. Allocate the necessary blocks and get ready to go. */ - RDB rdb = (RDB) ALLR_block(type_rdb, 0); + RDB rdb = new Rdb; PACKET* packet = &rdb->rdb_packet; /* Pick up some user identification information */ @@ -531,7 +530,7 @@ rem_port* INET_analyze(Firebird::PathName& file_name, Firebird::string temp; temp.printf("%s/P%d", port->port_version->str_data, port->port_protocol & FB_PROTOCOL_MASK); - ALLR_free(port->port_version); + delete port->port_version; port->port_version = REMOTE_make_string(temp.c_str()); if (packet->p_acpt.p_acpt_architecture == ARCHITECTURE) { @@ -605,9 +604,7 @@ rem_port* INET_connect(const TEXT* name, } if (host.hasData()) { - if (port->port_connection) { - ALLR_free(port->port_connection); - } + delete port->port_connection; port->port_connection = REMOTE_make_string(host.c_str()); } else { @@ -1207,11 +1204,7 @@ static rem_port* alloc_port( rem_port* parent) INET_initialized = true; } - rem_port* port = (rem_port*) ALLR_block(type_port, INET_remote_buffer * 2); - port->port_sync = FB_NEW(*getDefaultMemoryPool()) Firebird::RefMutex(); - port->port_sync->addRef(); - port->port_type = port_inet; - port->port_state = state_pending; + rem_port* port = new rem_port(rem_port::INET, INET_remote_buffer * 2); REMOTE_get_timeout_params(port, 0); TEXT buffer[BUFFER_SMALL]; @@ -1242,25 +1235,10 @@ static rem_port* alloc_port( rem_port* parent) 0, XDR_DECODE); -#ifdef REM_SERVER - port->port_queue = FB_NEW(*getDefaultMemoryPool()) - Firebird::ObjectsArray< Firebird::Array< char > >(*getDefaultMemoryPool()); - port->port_qoffset = 0; - port->port_que_sync = FB_NEW(*getDefaultMemoryPool()) Firebird::RefMutex(); - port->port_que_sync->addRef(); -#endif - if (parent && !(parent->port_server_flags & SRVR_thread_per_port)) { Firebird::MutexLockGuard guard(port_mutex); - - port->port_parent = parent; - port->port_next = parent->port_clients; - port->port_handle = parent->port_handle; - port->port_server = parent->port_server; - port->port_server_flags = parent->port_server_flags; - - parent->port_clients = parent->port_next = port; + port->linkParent(parent); } return port; @@ -1338,10 +1316,6 @@ static rem_port* aux_connect(rem_port* port, PACKET* packet, t_event_ast ast) address.sin_family = AF_INET; address.sin_port = ((struct sockaddr_in *)(response->p_resp_data.cstr_address))->sin_port; - int optval = 1; - setsockopt((SOCKET) port->port_handle, SOL_SOCKET, SO_KEEPALIVE, - (SCHAR*) &optval, sizeof(optval)); - status = connect(n, (struct sockaddr *) &address, sizeof(address)); const int inetErrNo = INET_ERRNO; @@ -1566,12 +1540,8 @@ static bool check_proxy(rem_port* port, && (!strcmp(source_user, user_name.c_str()) || !strcmp(source_user, "*"))) { - ALLR_free(port->port_user_name); - const SLONG length = strlen(target_user); - rem_str* string = (rem_str*) ALLR_block(type_str, (int) length); - port->port_user_name = string; - string->str_length = length; - strncpy(string->str_data, target_user, length); + delete port->port_user_name; + port->port_user_name = REMOTE_make_string(target_user); user_name = target_user; result = true; break; @@ -1639,7 +1609,7 @@ static void disconnect( rem_port* port) /* If this is a sub-port, unlink it from it's parent */ bool defer_cleanup = false; - port->port_state = state_disconnected; + port->port_state = rem_port::DISCONNECTED; rem_port* parent = port->port_parent; if (parent != NULL) { @@ -1664,7 +1634,7 @@ static void disconnect( rem_port* port) gds__unregister_cleanup(exit_handler, (void *) port); if (!defer_cleanup) { - cleanup_port(port); + delete port; } #ifdef DEBUG @@ -1685,60 +1655,6 @@ static void disconnect( rem_port* port) } -static void cleanup_port( rem_port* port) -{ -/************************************** - * - * c l e a n u p _ p o r t - * - ************************************** - * - * Functional description - * Walk through the port structure freeing - * allocated memory and then free the port. - * - **************************************/ - - if (port->port_version) - ALLR_free(port->port_version); - - if (port->port_connection) - ALLR_free(port->port_connection); - - if (port->port_user_name) - ALLR_free(port->port_user_name); - - if (port->port_host) - ALLR_free(port->port_host); - - if (port->port_object_vector) - ALLR_free(port->port_object_vector); - - if (port->port_protocol_str) - ALLR_free(port->port_protocol_str); - - if (port->port_address_str) - ALLR_free(port->port_address_str); - -#ifdef DEBUG_XDR_MEMORY - if (port->port_packet_vector) - ALLR_free(port->port_packet_vector); -#endif - -#ifdef REM_SERVER - delete port->port_queue; - port->port_que_sync->release(); -#endif - -#ifdef TRUSTED_AUTH - delete port->port_trusted_auth; -#endif - - port->port_sync->release(); - ALLR_free(port); - return; -} - static void exit_handler( void *arg) { /************************************** @@ -1765,9 +1681,9 @@ static void exit_handler( void *arg) #endif for (rem_port* port = main_port; port; port = port->port_next) - if (port->port_state != state_broken) + if (port->port_state != rem_port::BROKEN) { - port->port_state = state_broken; + port->port_state = rem_port::BROKEN; shutdown((int) port->port_handle, 2); SOCLOSE((SOCKET) port->port_handle); } @@ -2101,7 +2017,7 @@ static rem_port* receive( rem_port* main_port, PACKET * packet) main_port->port_flags &= ~PORT_partial_data; if (packet->p_operation == op_exit) { - main_port->port_state = state_broken; + main_port->port_state = rem_port::BROKEN; } break; } @@ -2147,9 +2063,9 @@ static rem_port* select_multi(rem_port* main_port, UCHAR* buffer, SSHORT bufsize { if (INET_shutting_down) { - if (main_port->port_state != state_broken) + if (main_port->port_state != rem_port::BROKEN) { - main_port->port_state = state_broken; + main_port->port_state = rem_port::BROKEN; SOCKET s = (SOCKET) main_port->port_handle; shutdown(s, 2); SOCLOSE(s); @@ -2324,7 +2240,7 @@ static int select_wait( rem_port* main_port, SLCT * selct) unhook_disconnected_ports(main_port); for (rem_port* port = main_port; port; port = port->port_next) { - if (port->port_state == state_pending) + if (port->port_state == rem_port::PENDING) { /* Adjust down the port's keepalive timer. */ @@ -2592,7 +2508,7 @@ static void inet_gen_error( rem_port* port, ISC_STATUS status, ...) * save the status vector strings in a permanent place. * **************************************/ - port->port_state = state_broken; + port->port_state = rem_port::BROKEN; ISC_STATUS* status_vector = NULL; if (port->port_context != NULL) { @@ -2987,7 +2903,7 @@ static rem_port* inet_try_connect( rem_port* port = INET_connect(node_name, packet, status_vector, FALSE, &dpb); if (!port) { - ALLR_free(rdb); + delete rdb; return NULL; } @@ -2999,7 +2915,7 @@ static rem_port* inet_try_connect( inet_error(port, "receive in try_connect", isc_net_connect_err, INET_ERRNO); disconnect(port); - ALLR_free(rdb); + delete rdb; return NULL; } @@ -3475,11 +3391,11 @@ static void unhook_disconnected_ports(rem_port* main_port) Firebird::RefMutexEnsureUnlock portGuard(*port->port_sync); if (portGuard.tryEnter()) { - if (port->port_state == state_disconnected) { + if (port->port_state == rem_port::DISCONNECTED) { more = true; unhook_port(port, port->port_parent); portGuard.leave(); - cleanup_port(port); + delete port; break; } else { diff --git a/src/remote/inter_proto.h b/src/remote/inter_proto.h index d9fb679958..94058537f1 100644 --- a/src/remote/inter_proto.h +++ b/src/remote/inter_proto.h @@ -28,78 +28,78 @@ extern "C" { #endif -ISC_STATUS REM_attach_database(ISC_STATUS*, SSHORT, const SCHAR*, struct rdb**, +ISC_STATUS REM_attach_database(ISC_STATUS*, SSHORT, const SCHAR*, struct Rdb**, SSHORT, const SCHAR*, const UCHAR*); -ISC_STATUS REM_attach_service(ISC_STATUS *, USHORT, TEXT *, struct rdb **, USHORT, SCHAR *); -ISC_STATUS REM_blob_info(ISC_STATUS*, struct rbl**, SSHORT, const SCHAR*, +ISC_STATUS REM_attach_service(ISC_STATUS *, USHORT, TEXT *, struct Rdb **, USHORT, SCHAR *); +ISC_STATUS REM_blob_info(ISC_STATUS*, struct Rbl**, SSHORT, const SCHAR*, SSHORT, SCHAR*); -ISC_STATUS REM_cancel_blob(ISC_STATUS *, struct rbl **); -ISC_STATUS REM_cancel_events(ISC_STATUS *, struct rdb **, SLONG *); -ISC_STATUS REM_close_blob(ISC_STATUS *, struct rbl **); -ISC_STATUS REM_commit_transaction(ISC_STATUS *, struct rtr **); -ISC_STATUS REM_commit_retaining(ISC_STATUS *, struct rtr **); -ISC_STATUS REM_compile_request(ISC_STATUS*, struct rdb**, struct rrq**, +ISC_STATUS REM_cancel_blob(ISC_STATUS *, struct Rbl **); +ISC_STATUS REM_cancel_events(ISC_STATUS *, struct Rdb **, SLONG *); +ISC_STATUS REM_close_blob(ISC_STATUS *, struct Rbl **); +ISC_STATUS REM_commit_transaction(ISC_STATUS *, struct Rtr **); +ISC_STATUS REM_commit_retaining(ISC_STATUS *, struct Rtr **); +ISC_STATUS REM_compile_request(ISC_STATUS*, struct Rdb**, struct Rrq**, USHORT, const UCHAR*); -ISC_STATUS REM_create_blob2(ISC_STATUS*, struct rdb**, struct rtr**, - struct rbl**, BID, USHORT, const UCHAR*); -ISC_STATUS REM_create_database(ISC_STATUS*, SSHORT, const SCHAR*, struct rdb**, +ISC_STATUS REM_create_blob2(ISC_STATUS*, struct Rdb**, struct Rtr**, + struct Rbl**, BID, USHORT, const UCHAR*); +ISC_STATUS REM_create_database(ISC_STATUS*, SSHORT, const SCHAR*, struct Rdb**, SSHORT, const SCHAR*, SSHORT, const UCHAR*); -ISC_STATUS REM_database_info(ISC_STATUS*, struct rdb**, SSHORT, const SCHAR*, +ISC_STATUS REM_database_info(ISC_STATUS*, struct Rdb**, SSHORT, const SCHAR*, SSHORT, SCHAR*); -ISC_STATUS REM_ddl(ISC_STATUS*, struct rdb**, struct rtr**, +ISC_STATUS REM_ddl(ISC_STATUS*, struct Rdb**, struct Rtr**, USHORT, const UCHAR*); -ISC_STATUS REM_detach_database(ISC_STATUS *, struct rdb **); -ISC_STATUS REM_detach_service(ISC_STATUS *, struct rdb **); -ISC_STATUS REM_drop_database(ISC_STATUS *, struct rdb **); -ISC_STATUS REM_allocate_statement(ISC_STATUS *, struct rdb **, struct rsr **); -ISC_STATUS REM_execute(ISC_STATUS *, struct rtr **, struct rsr **, USHORT, UCHAR *, USHORT, USHORT, UCHAR *); -ISC_STATUS REM_execute2(ISC_STATUS *, struct rtr **, struct rsr **, USHORT, UCHAR *, USHORT, USHORT, UCHAR *, USHORT, UCHAR *, USHORT, USHORT, UCHAR *); -ISC_STATUS REM_execute_immediate(ISC_STATUS*, struct rdb**, struct rtr**, +ISC_STATUS REM_detach_database(ISC_STATUS *, struct Rdb **); +ISC_STATUS REM_detach_service(ISC_STATUS *, struct Rdb **); +ISC_STATUS REM_drop_database(ISC_STATUS *, struct Rdb **); +ISC_STATUS REM_allocate_statement(ISC_STATUS *, struct Rdb **, struct Rsr **); +ISC_STATUS REM_execute(ISC_STATUS *, struct Rtr **, struct Rsr **, USHORT, UCHAR *, USHORT, USHORT, UCHAR *); +ISC_STATUS REM_execute2(ISC_STATUS *, struct Rtr **, struct Rsr **, USHORT, UCHAR *, USHORT, USHORT, UCHAR *, USHORT, UCHAR *, USHORT, USHORT, UCHAR *); +ISC_STATUS REM_execute_immediate(ISC_STATUS*, struct Rdb**, struct Rtr**, USHORT, const TEXT*, USHORT, USHORT, const UCHAR*, USHORT, USHORT, UCHAR*); -ISC_STATUS REM_execute_immediate2(ISC_STATUS*, struct rdb**, struct rtr**, +ISC_STATUS REM_execute_immediate2(ISC_STATUS*, struct Rdb**, struct Rtr**, USHORT, const TEXT*, USHORT, USHORT, const UCHAR*, USHORT, USHORT, UCHAR*, USHORT, UCHAR*, USHORT, USHORT, UCHAR*); -ISC_STATUS REM_fetch(ISC_STATUS*, struct rsr**, USHORT, const UCHAR*, USHORT, +ISC_STATUS REM_fetch(ISC_STATUS*, struct Rsr**, USHORT, const UCHAR*, USHORT, USHORT, UCHAR*); -ISC_STATUS REM_free_statement(ISC_STATUS *, struct rsr **, USHORT); -ISC_STATUS REM_insert(ISC_STATUS *, struct rsr **, USHORT, UCHAR *, USHORT, USHORT, UCHAR *); -ISC_STATUS REM_prepare(ISC_STATUS *, struct rtr **, struct rsr **, USHORT, TEXT *, USHORT, USHORT, SCHAR *, USHORT, SCHAR *); -ISC_STATUS REM_set_cursor_name(ISC_STATUS*, struct rsr**, const TEXT*, USHORT); -ISC_STATUS REM_sql_info(ISC_STATUS*, struct rsr**, SSHORT, const SCHAR*, +ISC_STATUS REM_free_statement(ISC_STATUS *, struct Rsr **, USHORT); +ISC_STATUS REM_insert(ISC_STATUS *, struct Rsr **, USHORT, UCHAR *, USHORT, USHORT, UCHAR *); +ISC_STATUS REM_prepare(ISC_STATUS *, struct Rtr **, struct Rsr **, USHORT, TEXT *, USHORT, USHORT, SCHAR *, USHORT, SCHAR *); +ISC_STATUS REM_set_cursor_name(ISC_STATUS*, struct Rsr**, const TEXT*, USHORT); +ISC_STATUS REM_sql_info(ISC_STATUS*, struct Rsr**, SSHORT, const SCHAR*, SSHORT, SCHAR*); -ISC_STATUS REM_get_segment(ISC_STATUS *, struct rbl **, USHORT *, USHORT, UCHAR *); -ISC_STATUS REM_get_slice(ISC_STATUS*, struct rdb**, struct rtr**, BID, USHORT, +ISC_STATUS REM_get_segment(ISC_STATUS *, struct Rbl **, USHORT *, USHORT, UCHAR *); +ISC_STATUS REM_get_slice(ISC_STATUS*, struct Rdb**, struct Rtr**, BID, USHORT, const UCHAR*, USHORT, const UCHAR*, SLONG, UCHAR*, SLONG*); -ISC_STATUS REM_open_blob2(ISC_STATUS*, struct rdb**, struct rtr**, - struct rbl**, BID, USHORT, const UCHAR*); -ISC_STATUS REM_prepare_transaction(ISC_STATUS *, struct rtr **, USHORT, const UCHAR*); -ISC_STATUS REM_put_segment(ISC_STATUS*, struct rbl**, USHORT, const UCHAR*); -ISC_STATUS REM_put_slice(ISC_STATUS*, struct rdb**, struct rtr**, BID, USHORT, +ISC_STATUS REM_open_blob2(ISC_STATUS*, struct Rdb**, struct Rtr**, + struct Rbl**, BID, USHORT, const UCHAR*); +ISC_STATUS REM_prepare_transaction(ISC_STATUS *, struct Rtr **, USHORT, const UCHAR*); +ISC_STATUS REM_put_segment(ISC_STATUS*, struct Rbl**, USHORT, const UCHAR*); +ISC_STATUS REM_put_slice(ISC_STATUS*, struct Rdb**, struct Rtr**, BID, USHORT, const UCHAR*, USHORT, const UCHAR*, SLONG, UCHAR*); -ISC_STATUS REM_que_events(ISC_STATUS*, struct rdb**, SLONG*, SSHORT, +ISC_STATUS REM_que_events(ISC_STATUS*, struct Rdb**, SLONG*, SSHORT, const UCHAR*, FPTR_EVENT_CALLBACK, void*); -ISC_STATUS REM_query_service(ISC_STATUS *, struct rdb **, USHORT, SCHAR *, USHORT, SCHAR *, USHORT, SCHAR *); +ISC_STATUS REM_query_service(ISC_STATUS *, struct Rdb **, USHORT, SCHAR *, USHORT, SCHAR *, USHORT, SCHAR *); #ifdef SCROLLABLE_CURSORS -ISC_STATUS REM_receive(ISC_STATUS*, struct rrq**, USHORT, USHORT, UCHAR*, SSHORT, USHORT, ULONG); +ISC_STATUS REM_receive(ISC_STATUS*, struct Rrq**, USHORT, USHORT, UCHAR*, SSHORT, USHORT, ULONG); #else -ISC_STATUS REM_receive(ISC_STATUS *, struct rrq **, USHORT, USHORT, UCHAR *, SSHORT); +ISC_STATUS REM_receive(ISC_STATUS *, struct Rrq **, USHORT, USHORT, UCHAR *, SSHORT); #endif -ISC_STATUS REM_reconnect_transaction(ISC_STATUS*, struct rdb**, struct rtr**, +ISC_STATUS REM_reconnect_transaction(ISC_STATUS*, struct Rdb**, struct Rtr**, USHORT, const UCHAR*); -ISC_STATUS REM_release_request(ISC_STATUS *, struct rrq **); -ISC_STATUS REM_request_info(ISC_STATUS*, struct rrq**, SSHORT, SSHORT, +ISC_STATUS REM_release_request(ISC_STATUS *, struct Rrq **); +ISC_STATUS REM_request_info(ISC_STATUS*, struct Rrq**, SSHORT, SSHORT, const UCHAR*, SSHORT, UCHAR*); -ISC_STATUS REM_rollback_transaction(ISC_STATUS *, struct rtr **); -ISC_STATUS REM_seek_blob(ISC_STATUS *, struct rbl **, SSHORT, SLONG, SLONG *); -ISC_STATUS REM_send(ISC_STATUS *, struct rrq **, USHORT, USHORT, UCHAR *, SSHORT); -ISC_STATUS REM_start_and_send(ISC_STATUS *, struct rrq **, struct rtr **, USHORT, USHORT, UCHAR *, SSHORT); -ISC_STATUS REM_start_request(ISC_STATUS *, struct rrq **, struct rtr **, USHORT); -ISC_STATUS REM_start_transaction(ISC_STATUS *, struct rtr **, SSHORT, struct rdb **, SSHORT, UCHAR *); -ISC_STATUS REM_transact_request(ISC_STATUS*, struct rdb**, struct rtr**, +ISC_STATUS REM_rollback_transaction(ISC_STATUS *, struct Rtr **); +ISC_STATUS REM_seek_blob(ISC_STATUS *, struct Rbl **, SSHORT, SLONG, SLONG *); +ISC_STATUS REM_send(ISC_STATUS *, struct Rrq **, USHORT, USHORT, UCHAR *, SSHORT); +ISC_STATUS REM_start_and_send(ISC_STATUS *, struct Rrq **, struct Rtr **, USHORT, USHORT, UCHAR *, SSHORT); +ISC_STATUS REM_start_request(ISC_STATUS *, struct Rrq **, struct Rtr **, USHORT); +ISC_STATUS REM_start_transaction(ISC_STATUS *, struct Rtr **, SSHORT, struct Rdb **, SSHORT, UCHAR *); +ISC_STATUS REM_transact_request(ISC_STATUS*, struct Rdb**, struct Rtr**, USHORT, const UCHAR*, USHORT, UCHAR*, USHORT, UCHAR*); -ISC_STATUS REM_transaction_info(ISC_STATUS*, struct rtr**, SSHORT, +ISC_STATUS REM_transaction_info(ISC_STATUS*, struct Rtr**, SSHORT, const UCHAR*, SSHORT, UCHAR*); -ISC_STATUS REM_unwind_request(ISC_STATUS *, struct rrq **, USHORT); +ISC_STATUS REM_unwind_request(ISC_STATUS *, struct Rrq **, USHORT); ISC_STATUS REM_rollback_retaining(ISC_STATUS *, RTR *); ISC_STATUS REM_service_attach(ISC_STATUS*, USHORT, const TEXT*, RDB*, USHORT, diff --git a/src/remote/interface.cpp b/src/remote/interface.cpp index 3f6aeaa309..10f6343c0a 100644 --- a/src/remote/interface.cpp +++ b/src/remote/interface.cpp @@ -137,11 +137,11 @@ static bool clear_queue(rem_port*, ISC_STATUS *); static bool clear_stmt_que(rem_port*, ISC_STATUS*, RSR); static void disconnect(rem_port*); #ifdef SCROLLABLE_CURSORS -static REM_MSG dump_cache(rem_port*, ISC_STATUS *, rrq::rrq_repeat *); +static REM_MSG dump_cache(rem_port*, ISC_STATUS *, Rrq::rrq_repeat *); #endif static void enqueue_receive(rem_port*, t_rmtque_fn, - RDB, void*, rrq::rrq_repeat*); + RDB, void*, Rrq::rrq_repeat*); static void dequeue_receive(rem_port*); static THREAD_ENTRY_DECLARE event_thread(THREAD_ENTRY_PARAM); static ISC_STATUS fetch_blob(ISC_STATUS*, RSR, USHORT, const UCHAR*, USHORT, @@ -159,7 +159,7 @@ static bool init(ISC_STATUS *, rem_port*, P_OP, Firebird::PathName&, static RTR make_transaction(RDB, USHORT); static ISC_STATUS mov_dsql_message(ISC_STATUS*, const UCHAR*, const rem_fmt*, UCHAR*, const rem_fmt*); static void move_error(ISC_STATUS, ...); -static void receive_after_start(rrq*, USHORT); +static void receive_after_start(Rrq*, USHORT); static bool receive_packet(rem_port*, PACKET *, ISC_STATUS *); static bool receive_packet_noqueue(rem_port*, PACKET *, ISC_STATUS *); static bool receive_queued_packet(rem_port*, ISC_STATUS *, USHORT); @@ -167,13 +167,13 @@ static bool receive_response(RDB, PACKET *); static void release_blob(RBL); static void release_event(RVNT); static bool release_object(RDB, P_OP, USHORT); -static void release_request(rrq*); +static void release_request(Rrq*); static void release_statement(RSR *); static void release_sql_request(RSR); static void release_transaction(RTR); static ISC_STATUS return_success(RDB); #ifdef SCROLLABLE_CURSORS -static REM_MSG scroll_cache(ISC_STATUS *, rrq*, rem_port*, rrq::rrq_repeat *, +static REM_MSG scroll_cache(ISC_STATUS *, Rrq*, rem_port*, Rrq::rrq_repeat *, USHORT *, ULONG *); #endif static ISC_STATUS send_and_receive(RDB, PACKET *, ISC_STATUS *); @@ -188,12 +188,12 @@ static void zap_packet(PACKET *); static ULONG remote_event_id = 0; -#define CHECK_HANDLE(blk, type, error) if (!blk || ((BLK) blk)->blk_type != (UCHAR) type) \ +#define CHECK_HANDLE(blk, type, error) if (!blk->checkHandle()) \ return handle_error (user_status, (ISC_STATUS) error) #define NULL_CHECK(ptr, code) if (*ptr) return handle_error (user_status, (ISC_STATUS) code) -#define SET_OBJECT(rdb, object, id) REMOTE_set_object (rdb->rdb_port, (struct blk *) object, id) +#define SET_OBJECT(rdb, object, id) rdb->rdb_port->setHandle(object, id) inline bool defer_packet(rem_port* port, PACKET* packet, ISC_STATUS* status, bool sent = false) { @@ -513,7 +513,7 @@ ISC_STATUS GDS_CLOSE_BLOB(ISC_STATUS * user_status, RBL * blob_handle) try { if (!(port->port_flags & PORT_rpc) && - (blob->rbl_flags & RBL_create) && blob->rbl_ptr != blob->rbl_buffer) + (blob->rbl_flags & Rbl::CREATE) && blob->rbl_ptr != blob->rbl_buffer) { if (send_blob(user_status, blob, 0, NULL)) { return user_status[1]; @@ -621,7 +621,7 @@ ISC_STATUS GDS_COMMIT_RETAINING(ISC_STATUS * user_status, RTR * rtr_handle) ISC_STATUS GDS_COMPILE(ISC_STATUS* user_status, RDB* db_handle, - rrq** req_handle, USHORT blr_length, const UCHAR* blr) + Rrq** req_handle, USHORT blr_length, const UCHAR* blr) { /************************************** * @@ -667,7 +667,7 @@ ISC_STATUS GDS_COMPILE(ISC_STATUS* user_status, send_and_receive(rdb, packet, user_status); if (new_blr != blr) { - ALLR_free((void*) new_blr); + delete new_blr; } if (user_status[1]) { return user_status[1]; @@ -684,7 +684,7 @@ ISC_STATUS GDS_COMPILE(ISC_STATUS* user_status, } /* Allocate request block */ - rrq* request = (rrq*) ALLR_block(type_rrq, max_msg + 1); + Rrq* request = new Rrq(max_msg + 1); *req_handle = request; request->rrq_rdb = rdb; request->rrq_id = packet->p_resp.p_resp_object; @@ -706,7 +706,7 @@ ISC_STATUS GDS_COMPILE(ISC_STATUS* user_status, message->msg_prior = message; #endif - rrq::rrq_repeat * tail = request->rrq_rpt + message->msg_number; + Rrq::rrq_repeat * tail = &request->rrq_rpt[message->msg_number]; tail->rrq_message = message; tail->rrq_xdr = message; #ifdef SCROLLABLE_CURSORS @@ -781,15 +781,13 @@ ISC_STATUS GDS_CREATE_BLOB2(ISC_STATUS* user_status, if (user_status[1]) return user_status[1]; - RBL blob = (RBL) ALLR_block(type_rbl, BLOB_LENGTH); + RBL blob = new Rbl(); *blob_handle = blob; *blob_id = packet->p_resp.p_resp_blob_id; - blob->rbl_buffer_length = BLOB_LENGTH; blob->rbl_rdb = rdb; blob->rbl_rtr = transaction; blob->rbl_id = packet->p_resp.p_resp_object; - blob->rbl_ptr = blob->rbl_buffer = blob->rbl_data; - blob->rbl_flags |= RBL_create; + blob->rbl_flags |= Rbl::CREATE; SET_OBJECT(rdb, blob, blob->rbl_id); blob->rbl_next = transaction->rtr_blobs; transaction->rtr_blobs = blob; @@ -901,7 +899,7 @@ ISC_STATUS GDS_DATABASE_INFO(ISC_STATUS* user_status, * **************************************/ ISC_STATUS status; - UCHAR temp[1024]; + Firebird::HalfStaticArray temp; RDB rdb = *handle; CHECK_HANDLE(rdb, type_rdb, isc_bad_db_handle); @@ -912,12 +910,7 @@ ISC_STATUS GDS_DATABASE_INFO(ISC_STATUS* user_status, try { - UCHAR* temp_buffer = temp; - if (buffer_length > (SLONG) sizeof(temp)) { - temp_buffer = ALLR_alloc((SLONG) buffer_length); - } - /* NOMEM: ALLR_alloc handled */ - /* FREE: Normal case later in this procedure, what about error to ERROR_INIT? */ + UCHAR* temp_buffer = temp.getBuffer(buffer_length); status = info(user_status, rdb, op_info_database, rdb->rdb_id, 0, item_length, items, 0, 0, buffer_length, @@ -933,10 +926,6 @@ ISC_STATUS GDS_DATABASE_INFO(ISC_STATUS* user_status, reinterpret_cast(version.c_str()), reinterpret_cast(port->port_host->str_data), 0); } - - if (temp_buffer != temp) { - ALLR_free(temp_buffer); - } } catch (const Firebird::Exception& ex) { @@ -1175,10 +1164,10 @@ ISC_STATUS GDS_DSQL_ALLOCATE(ISC_STATUS* user_status, RSR statement; if (rdb->rdb_port->port_flags & PORT_lazy) { - *stmt_handle = statement = (RSR) ALLR_block(type_rsr, 0); + *stmt_handle = statement = new Rsr; statement->rsr_rdb = rdb; statement->rsr_id = INVALID_OBJECT; - statement->rsr_flags |= RSR_lazy; + statement->rsr_flags |= Rsr::LAZY; } else { PACKET* packet = &rdb->rdb_packet; @@ -1190,7 +1179,7 @@ ISC_STATUS GDS_DSQL_ALLOCATE(ISC_STATUS* user_status, /* Allocate SQL request block */ - statement = (RSR) ALLR_block(type_rsr, 0); + statement = new Rsr; *stmt_handle = statement; statement->rsr_rdb = rdb; statement->rsr_id = packet->p_resp.p_resp_object; @@ -1293,12 +1282,10 @@ ISC_STATUS GDS_DSQL_EXECUTE2(ISC_STATUS* user_status, // previous executions (possibly with different statement if // isc_dsql_prepare is called multiple times). // This should cure SF#919246 - if (statement->rsr_bind_format) { - ALLR_free(statement->rsr_bind_format); - statement->rsr_bind_format = NULL; - } - if (port->port_statement && port->port_statement->rsr_select_format) { - ALLR_free(port->port_statement->rsr_select_format); + delete statement->rsr_bind_format; + statement->rsr_bind_format = NULL; + if (port->port_statement) { + delete port->port_statement->rsr_select_format; port->port_statement->rsr_select_format = NULL; } @@ -1308,7 +1295,7 @@ ISC_STATUS GDS_DSQL_EXECUTE2(ISC_STATUS* user_status, REM_MSG message = PARSE_messages(in_blr, in_blr_length); if (message != (REM_MSG) - 1) { statement->rsr_bind_format = (rem_fmt*) message->msg_address; - ALLR_free(message); + delete message; } } @@ -1317,17 +1304,17 @@ ISC_STATUS GDS_DSQL_EXECUTE2(ISC_STATUS* user_status, if (out_blr_length) { if (!port->port_statement) - port->port_statement = (RSR) ALLR_block(type_rsr, 0); + port->port_statement = new Rsr; REM_MSG message = PARSE_messages(out_blr, out_blr_length); if (message != (REM_MSG) - 1) { port->port_statement->rsr_select_format = (rem_fmt*) message->msg_address; - ALLR_free(message); + delete message; } if (!port->port_statement->rsr_buffer) { - REM_MSG message2 = (REM_MSG) ALLR_block(type_msg, 0); + REM_MSG message2 = new Message(0); port->port_statement->rsr_buffer = message2; port->port_statement->rsr_message = message2; message2->msg_next = message2; @@ -1340,7 +1327,7 @@ ISC_STATUS GDS_DSQL_EXECUTE2(ISC_STATUS* user_status, REM_MSG message = 0; if (!statement->rsr_buffer) { - statement->rsr_buffer = message = (REM_MSG) ALLR_block(type_msg, 0); + statement->rsr_buffer = message = new Message(0); statement->rsr_message = message; message->msg_next = message; @@ -1355,7 +1342,7 @@ ISC_STATUS GDS_DSQL_EXECUTE2(ISC_STATUS* user_status, } message->msg_address = in_msg; - statement->rsr_flags &= ~RSR_fetched; + statement->rsr_flags &= ~Rsr::FETCHED; statement->rsr_format = statement->rsr_bind_format; stmt_clear_exception(statement); @@ -1374,7 +1361,7 @@ ISC_STATUS GDS_DSQL_EXECUTE2(ISC_STATUS* user_status, sqldata->p_sqldata_out_blr.cstr_address = out_blr; sqldata->p_sqldata_out_message_number = out_msg_type; - if (out_msg_length || !(statement->rsr_flags & RSR_defer_execute)) + if (out_msg_length || !(statement->rsr_flags & Rsr::DEFER_EXECUTE)) { if (!send_packet(port, packet, user_status)) return user_status[1]; @@ -1533,7 +1520,7 @@ ISC_STATUS GDS_DSQL_EXECUTE_IMMED2(ISC_STATUS* user_status, RSR statement = port->port_statement; if (!statement) { - statement = port->port_statement = (RSR) ALLR_block(type_rsr, 0); + statement = port->port_statement = new Rsr; } /* reset statement buffers */ @@ -1543,15 +1530,10 @@ ISC_STATUS GDS_DSQL_EXECUTE_IMMED2(ISC_STATUS* user_status, REMOTE_reset_statement(statement); - if (statement->rsr_bind_format) { - ALLR_free(statement->rsr_bind_format); - statement->rsr_bind_format = NULL; - } - - if (statement->rsr_select_format) { - ALLR_free(statement->rsr_select_format); - statement->rsr_select_format = NULL; - } + delete statement->rsr_bind_format; + statement->rsr_bind_format = NULL; + delete statement->rsr_select_format; + statement->rsr_select_format = NULL; if (in_msg_length || out_msg_length) { @@ -1560,7 +1542,7 @@ ISC_STATUS GDS_DSQL_EXECUTE_IMMED2(ISC_STATUS* user_status, REM_MSG message = PARSE_messages(in_blr, in_blr_length); if ((message) != (REM_MSG) - 1) { statement->rsr_bind_format = (rem_fmt*) message->msg_address; - ALLR_free(message); + delete message; } } if (out_blr_length) @@ -1568,7 +1550,7 @@ ISC_STATUS GDS_DSQL_EXECUTE_IMMED2(ISC_STATUS* user_status, REM_MSG message = PARSE_messages(out_blr, out_blr_length); if ((message) != (REM_MSG) - 1) { statement->rsr_select_format = (rem_fmt*) message->msg_address; - ALLR_free(message); + delete message; } } } @@ -1576,7 +1558,7 @@ ISC_STATUS GDS_DSQL_EXECUTE_IMMED2(ISC_STATUS* user_status, REM_MSG message = 0; if (!statement->rsr_buffer) { - statement->rsr_buffer = message = (REM_MSG) ALLR_block(type_msg, 0); + statement->rsr_buffer = message = new Message(0); statement->rsr_message = message; message->msg_next = message; #ifdef SCROLLABLE_CURSORS @@ -1697,11 +1679,11 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, /* On first fetch, clear the end-of-stream flag & reset the message buffers */ - if (!(statement->rsr_flags & RSR_fetched)) + if (!(statement->rsr_flags & Rsr::FETCHED)) { stmt_raise_exception(statement); - statement->rsr_flags &= ~(RSR_eof | RSR_stream_err | RSR_past_eof); + statement->rsr_flags &= ~(Rsr::EOF_SET | Rsr::STREAM_ERR | Rsr::PAST_EOF); statement->rsr_rows_pending = 0; stmt_clear_exception(statement); @@ -1719,8 +1701,8 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, } } } - else if ((statement->rsr_flags & RSR_eof) && - (statement->rsr_flags & RSR_past_eof)) + else if ((statement->rsr_flags & Rsr::EOF_SET) && + (statement->rsr_flags & Rsr::PAST_EOF)) { user_status[0] = isc_arg_gds; user_status[1] = isc_req_sync; @@ -1733,24 +1715,25 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, if (blr_length) { if (statement->rsr_user_select_format && statement->rsr_user_select_format != statement->rsr_select_format) - ALLR_free(statement->rsr_user_select_format); + { + delete statement->rsr_user_select_format; + } REM_MSG message = PARSE_messages(blr, blr_length); if (message != (REM_MSG) - 1) { statement->rsr_user_select_format = (rem_fmt*) message->msg_address; - ALLR_free(message); + delete message; } else statement->rsr_user_select_format = NULL; - if (statement->rsr_flags & RSR_fetched) + if (statement->rsr_flags & Rsr::FETCHED) blr_length = 0; else { - if (statement->rsr_select_format) - ALLR_free(statement->rsr_select_format); + delete statement->rsr_select_format; statement->rsr_select_format = statement->rsr_user_select_format; } } - if (statement->rsr_flags & RSR_blob) { + if (statement->rsr_flags & Rsr::BLOB) { status = fetch_blob(user_status, statement, blr_length, blr, msg_type, msg_length, msg); return status; @@ -1758,7 +1741,7 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, if (!statement->rsr_buffer) { - statement->rsr_buffer = (REM_MSG) ALLR_block(type_msg, 0); + statement->rsr_buffer = new Message(0); statement->rsr_message = statement->rsr_buffer; statement->rsr_message->msg_next = statement->rsr_message; #ifdef SCROLLABLE_CURSORS @@ -1776,7 +1759,7 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, /* Check to see if data is waiting. If not, solicite data. */ - if ((!(statement->rsr_flags & (RSR_eof | RSR_stream_err)) && + if ((!(statement->rsr_flags & (Rsr::EOF_SET | Rsr::STREAM_ERR)) && (!statement->rsr_message->msg_address) && (statement->rsr_rows_pending == 0)) || ( /* Low in inventory */ @@ -1791,12 +1774,10 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, block for the other end to read - and so when both attempt to write simultaenously, they end up waiting indefinetly for the other end to read */ - (port->port_type != port_pipe) && -#ifdef XNET - (port->port_type != port_xnet) && -#endif + (port->port_type != rem_port::PIPE) && + (port->port_type != rem_port::XNET) && /* We've reached eof or there was an error */ - !(statement->rsr_flags & (RSR_eof | RSR_stream_err)) && + !(statement->rsr_flags & (Rsr::EOF_SET | Rsr::STREAM_ERR)) && /* No error pending */ (!stmt_have_exception(statement) ))) { @@ -1855,10 +1836,10 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, fb_assert(statement->rsr_msgs_waiting || (statement->rsr_rows_pending > 0) || stmt_have_exception(statement) - || statement->rsr_flags & (RSR_eof)); + || statement->rsr_flags & (Rsr::EOF_SET)); while (!stmt_have_exception(statement) /* received a database error */ - &&!(statement->rsr_flags & (RSR_eof)) /* reached end of cursor */ + &&!(statement->rsr_flags & (Rsr::EOF_SET)) /* reached end of cursor */ &&!(statement->rsr_msgs_waiting >= 2) /* Have looked ahead for end of batch */ &&!(statement->rsr_rows_pending == 0)) { /* Hit end of batch */ @@ -1870,7 +1851,7 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, if (!statement->rsr_msgs_waiting) { - if (statement->rsr_flags & RSR_eof) + if (statement->rsr_flags & Rsr::EOF_SET) { // hvlad: we may have queued fetch packet but received EOF before start // handling of this packet. Handle it now. @@ -1878,17 +1859,17 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, return user_status[1]; } - // hvlad: as we processed all queued packets at code above we can leave RSR_eof flag. + // hvlad: as we processed all queued packets at code above we can leave Rsr::EOF_SET flag. // It allows us to return EOF for all subsequent isc_dsql_fetch calls until statement // will be re-executed (and without roundtrip to remote server). - //statement->rsr_flags &= ~RSR_eof; - statement->rsr_flags |= RSR_past_eof; + //statement->rsr_flags &= ~Rsr::EOF_SET; + statement->rsr_flags |= Rsr::PAST_EOF; return_success(rdb); return 100; } - if (statement->rsr_flags & RSR_stream_err) { + if (statement->rsr_flags & Rsr::STREAM_ERR) { /* The previous batch of receives ended with an error status. We're all done returning data in the local queue. @@ -1896,10 +1877,10 @@ ISC_STATUS GDS_DSQL_FETCH(ISC_STATUS* user_status, /* Stuff in the error result to the user's vector */ - statement->rsr_flags &= ~RSR_stream_err; + statement->rsr_flags &= ~Rsr::STREAM_ERR; // hvlad: prevent subsequent fetches - statement->rsr_flags |= RSR_eof | RSR_past_eof; + statement->rsr_flags |= Rsr::EOF_SET | Rsr::PAST_EOF; if (statement->rsr_status) { memcpy(user_status, statement->rsr_status->value(), @@ -1975,13 +1956,13 @@ ISC_STATUS GDS_DSQL_FREE(ISC_STATUS * user_status, RSR * stmt_handle, USHORT opt return unsupported(user_status); } - if (statement->rsr_flags & RSR_lazy) { + if (statement->rsr_flags & Rsr::LAZY) { if (option == DSQL_drop) { release_sql_request(statement); *stmt_handle = NULL; } else { - statement->rsr_flags &= ~RSR_fetched; + statement->rsr_flags &= ~Rsr::FETCHED; statement->rsr_rtr = NULL; if (!clear_queue(rdb->rdb_port, user_status)) @@ -2020,7 +2001,7 @@ ISC_STATUS GDS_DSQL_FREE(ISC_STATUS * user_status, RSR * stmt_handle, USHORT opt *stmt_handle = NULL; } else { - statement->rsr_flags &= ~RSR_fetched; + statement->rsr_flags &= ~Rsr::FETCHED; statement->rsr_rtr = NULL; if (!clear_queue(rdb->rdb_port, user_status)) @@ -2075,10 +2056,8 @@ ISC_STATUS GDS_DSQL_INSERT(ISC_STATUS * user_status, // Free existing format unconditionally. // This is also related to SF#919246 - if (statement->rsr_bind_format) { - ALLR_free(statement->rsr_bind_format); - statement->rsr_bind_format = NULL; - } + delete statement->rsr_bind_format; + statement->rsr_bind_format = NULL; /* Parse the blr describing the message, if there is any. */ @@ -2086,13 +2065,13 @@ ISC_STATUS GDS_DSQL_INSERT(ISC_STATUS * user_status, REM_MSG message = PARSE_messages(blr, blr_length); if (message != (REM_MSG) - 1) { statement->rsr_bind_format = (rem_fmt*) message->msg_address; - ALLR_free(message); + delete message; } } REM_MSG message = 0; if (!statement->rsr_buffer) { - statement->rsr_buffer = message = (REM_MSG) ALLR_block(type_msg, 0); + statement->rsr_buffer = message = new Message(0); statement->rsr_message = message; message->msg_next = message; #ifdef SCROLLABLE_CURSORS @@ -2111,7 +2090,7 @@ ISC_STATUS GDS_DSQL_INSERT(ISC_STATUS * user_status, PACKET* packet = &rdb->rdb_packet; - if (statement->rsr_flags & RSR_lazy) { + if (statement->rsr_flags & Rsr::LAZY) { packet->p_operation = op_allocate_statement; packet->p_rlse.p_rlse_object = rdb->rdb_id; @@ -2133,14 +2112,14 @@ ISC_STATUS GDS_DSQL_INSERT(ISC_STATUS * user_status, message->msg_address = NULL; - if (statement->rsr_flags & RSR_lazy) { + if (statement->rsr_flags & Rsr::LAZY) { if (!receive_response(rdb, packet)) return user_status[1]; statement->rsr_id = packet->p_resp.p_resp_object; SET_OBJECT(rdb, statement, statement->rsr_id); - statement->rsr_flags &= ~RSR_lazy; + statement->rsr_flags &= ~Rsr::LAZY; } if (!receive_response(rdb, packet)) { @@ -2218,7 +2197,7 @@ ISC_STATUS GDS_DSQL_PREPARE(ISC_STATUS * user_status, RTR * rtr_handle, RSR * st PACKET* packet = &rdb->rdb_packet; - if (statement->rsr_flags & RSR_lazy) { + if (statement->rsr_flags & Rsr::LAZY) { packet->p_operation = op_allocate_statement; packet->p_rlse.p_rlse_object = rdb->rdb_id; @@ -2241,18 +2220,18 @@ ISC_STATUS GDS_DSQL_PREPARE(ISC_STATUS * user_status, RTR * rtr_handle, RSR * st if (!send_packet(rdb->rdb_port, packet, user_status)) return user_status[1]; - statement->rsr_flags &= ~(RSR_blob | RSR_defer_execute); + statement->rsr_flags &= ~(Rsr::BLOB | Rsr::DEFER_EXECUTE); /* Set up for the response packet. */ - if (statement->rsr_flags & RSR_lazy) { + if (statement->rsr_flags & Rsr::LAZY) { if (!receive_response(rdb, packet)) return user_status[1]; statement->rsr_id = packet->p_resp.p_resp_object; SET_OBJECT(rdb, statement, statement->rsr_id); - statement->rsr_flags &= ~RSR_lazy; + statement->rsr_flags &= ~Rsr::LAZY; } P_RESP* response = &packet->p_resp; @@ -2265,16 +2244,16 @@ ISC_STATUS GDS_DSQL_PREPARE(ISC_STATUS * user_status, RTR * rtr_handle, RSR * st if (rdb->rdb_port->port_flags & PORT_lazy) { if (response->p_resp_object & STMT_BLOB) { - statement->rsr_flags |= RSR_blob; + statement->rsr_flags |= Rsr::BLOB; } if (response->p_resp_object & STMT_DEFER_EXECUTE) { - statement->rsr_flags |= RSR_defer_execute; + statement->rsr_flags |= Rsr::DEFER_EXECUTE; } } else { if (response->p_resp_object) - statement->rsr_flags |= RSR_blob; + statement->rsr_flags |= Rsr::BLOB; } response->p_resp_data = temp; @@ -2348,7 +2327,7 @@ ISC_STATUS GDS_DSQL_SET_CURSOR(ISC_STATUS* user_status, PACKET* packet = &rdb->rdb_packet; - if (statement->rsr_flags & RSR_lazy) { + if (statement->rsr_flags & Rsr::LAZY) { packet->p_operation = op_allocate_statement; packet->p_rlse.p_rlse_object = rdb->rdb_id; @@ -2369,14 +2348,14 @@ ISC_STATUS GDS_DSQL_SET_CURSOR(ISC_STATUS* user_status, return user_status[1]; } - if (statement->rsr_flags & RSR_lazy) { + if (statement->rsr_flags & Rsr::LAZY) { if (!receive_response(rdb, packet)) return user_status[1]; statement->rsr_id = packet->p_resp.p_resp_object; SET_OBJECT(rdb, statement, statement->rsr_id); - statement->rsr_flags &= ~RSR_lazy; + statement->rsr_flags &= ~Rsr::LAZY; } if (!receive_response(rdb, packet)) { @@ -2485,7 +2464,7 @@ ISC_STATUS GDS_GET_SEGMENT(ISC_STATUS * user_status, /* Handle old protocol. Also handle new protocol on a blob that has been created rather than opened. (This should yield an error.) */ - if ((port->port_flags & PORT_rpc) || (blob->rbl_flags & RBL_create)) + if ((port->port_flags & PORT_rpc) || (blob->rbl_flags & Rbl::CREATE)) { packet->p_operation = op_get_segment; segment->p_sgmt_length = buffer_length; @@ -2523,7 +2502,7 @@ ISC_STATUS GDS_GET_SEGMENT(ISC_STATUS * user_status, /* if we're already done, stop now */ - if (blob->rbl_flags & RBL_eof) { + if (blob->rbl_flags & Rbl::EOF_SET) { *v++ = isc_segstr_eof; return user_status[1]; } @@ -2568,7 +2547,7 @@ ISC_STATUS GDS_GET_SEGMENT(ISC_STATUS * user_status, incomplete read */ if (l == buffer_length && - l == blob->rbl_length && (blob->rbl_flags & RBL_segment)) + l == blob->rbl_length && (blob->rbl_flags & Rbl::SEGMENT)) { *v = isc_segment; } @@ -2593,7 +2572,7 @@ ISC_STATUS GDS_GET_SEGMENT(ISC_STATUS * user_status, segment */ if (!buffer_length || - blob->rbl_length || !(blob->rbl_flags & RBL_segment)) + blob->rbl_length || !(blob->rbl_flags & Rbl::SEGMENT)) { break; } @@ -2601,8 +2580,8 @@ ISC_STATUS GDS_GET_SEGMENT(ISC_STATUS * user_status, /* We're done with buffer. If this was the last, we're done */ - if (blob->rbl_flags & RBL_eof_pending) { - blob->rbl_flags |= RBL_eof; + if (blob->rbl_flags & Rbl::EOF_PENDING) { + blob->rbl_flags |= Rbl::EOF_SET; *v = isc_segstr_eof; break; } @@ -2624,11 +2603,7 @@ ISC_STATUS GDS_GET_SEGMENT(ISC_STATUS * user_status, if (new_size > MAX_USHORT) /* Check if we've overflown */ new_size = buffer_length; - if (blob->rbl_buffer != blob->rbl_data) - ALLR_free(blob->rbl_buffer); - blob->rbl_ptr = blob->rbl_buffer = ALLR_alloc((SLONG) new_size); - /* NOMEM: ALLR_alloc handled */ - /* FREE: in release_blob() */ + blob->rbl_ptr = blob->rbl_buffer = blob->rbl_data.getBuffer(new_size); blob->rbl_buffer_length = (USHORT) new_size; } @@ -2651,11 +2626,11 @@ ISC_STATUS GDS_GET_SEGMENT(ISC_STATUS * user_status, blob->rbl_length = response->p_resp_data.cstr_length; blob->rbl_ptr = blob->rbl_buffer; - blob->rbl_flags &= ~RBL_segment; + blob->rbl_flags &= ~Rbl::SEGMENT; if (response->p_resp_object == 1) - blob->rbl_flags |= RBL_segment; + blob->rbl_flags |= Rbl::SEGMENT; else if (response->p_resp_object == 2) - blob->rbl_flags |= RBL_eof_pending; + blob->rbl_flags |= Rbl::EOF_PENDING; } response->p_resp_data = temp; @@ -2830,15 +2805,13 @@ ISC_STATUS GDS_OPEN_BLOB2(ISC_STATUS* user_status, //p_blob->p_blob_bpb.cstr_length = 0; //p_blob->p_blob_bpb.cstr_address = NULL; - RBL blob = (RBL) ALLR_block(type_rbl, BLOB_LENGTH); + RBL blob = new Rbl; *blob_handle = blob; blob->rbl_rdb = rdb; blob->rbl_rtr = transaction; blob->rbl_id = packet->p_resp.p_resp_object; - blob->rbl_buffer_length = BLOB_LENGTH; SET_OBJECT(rdb, blob, blob->rbl_id); blob->rbl_next = transaction->rtr_blobs; - blob->rbl_ptr = blob->rbl_buffer = blob->rbl_data; transaction->rtr_blobs = blob; } catch (const Firebird::Exception& ex) @@ -2944,7 +2917,7 @@ ISC_STATUS GDS_PUT_SEGMENT(ISC_STATUS* user_status, Also handle the new protocol on a blob that has been opened rather than created. (This should yield an error.) */ - if ((port->port_flags & PORT_rpc) || !(blob->rbl_flags & RBL_create)) + if ((port->port_flags & PORT_rpc) || !(blob->rbl_flags & Rbl::CREATE)) { send_blob(user_status, blob, segment_length, segment); return user_status[1]; @@ -3186,7 +3159,7 @@ ISC_STATUS GDS_QUE_EVENTS(ISC_STATUS* user_status, ISC_STATUS GDS_RECEIVE(ISC_STATUS * user_status, - rrq** req_handle, + Rrq** req_handle, USHORT msg_type, USHORT msg_length, UCHAR * msg, SSHORT level #ifdef SCROLLABLE_CURSORS @@ -3209,7 +3182,7 @@ ISC_STATUS GDS_RECEIVE(ISC_STATUS * user_status, /* Check handles and environment, then set up error handling */ CHECK_HANDLE((*req_handle), type_rrq, isc_bad_req_handle); - rrq* request = REMOTE_find_request(*req_handle, level); + Rrq* request = REMOTE_find_request(*req_handle, level); RDB rdb = request->rrq_rdb; CHECK_HANDLE(rdb, type_rdb, isc_bad_db_handle); @@ -3220,7 +3193,7 @@ ISC_STATUS GDS_RECEIVE(ISC_STATUS * user_status, try { - rrq::rrq_repeat* tail = &request->rrq_rpt[msg_type]; + Rrq::rrq_repeat* tail = &request->rrq_rpt[msg_type]; REM_MSG message = tail->rrq_message; #ifdef SCROLLABLE_CURSORS @@ -3259,10 +3232,8 @@ ISC_STATUS GDS_RECEIVE(ISC_STATUS * user_status, block for the other end to read - and so when both attempt to write simultaenously, they end up waiting indefinetly for the other end to read */ - (port->port_type != port_pipe) && /* not named pipe on NT */ -#ifdef XNET - (port->port_type != port_xnet) && /* not named pipe on NT */ -#endif + (port->port_type != rem_port::PIPE) && /* not named pipe on NT */ + (port->port_type != rem_port::XNET) && /* not named pipe on NT */ request->rrq_max_msg <= 1))) { /* there's only one message type */ @@ -3295,29 +3266,29 @@ ISC_STATUS GDS_RECEIVE(ISC_STATUS * user_status, switch (direction) { case blr_forward: - tail->rrq_flags &= ~RRQ_backward; + tail->rrq_flags &= ~Rrq::BACKWARD; tail->rrq_absolute += - (tail->rrq_flags & RRQ_absolute_backward) ? + (tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD) ? -offset : offset; break; case blr_backward: - tail->rrq_flags |= RRQ_backward; + tail->rrq_flags |= Rrq::BACKWARD; tail->rrq_absolute += - (tail->rrq_flags & RRQ_absolute_backward) ? + (tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD) ? offset : -offset; break; case blr_bof_forward: - tail->rrq_flags &= ~RRQ_backward; - tail->rrq_flags &= ~RRQ_absolute_backward; + tail->rrq_flags &= ~Rrq::BACKWARD; + tail->rrq_flags &= ~Rrq::ABSOLUTE_BACKWARD; tail->rrq_absolute = offset; direction = blr_forward; break; case blr_eof_backward: - tail->rrq_flags |= RRQ_backward; - tail->rrq_flags |= RRQ_absolute_backward; + tail->rrq_flags |= Rrq::BACKWARD; + tail->rrq_flags |= Rrq::ABSOLUTE_BACKWARD; tail->rrq_absolute = offset; direction = blr_backward; break; @@ -3480,7 +3451,7 @@ ISC_STATUS GDS_RECONNECT(ISC_STATUS* user_status, } -ISC_STATUS GDS_RELEASE_REQUEST(ISC_STATUS * user_status, rrq** req_handle) +ISC_STATUS GDS_RELEASE_REQUEST(ISC_STATUS * user_status, Rrq** req_handle) { /************************************** * @@ -3492,7 +3463,7 @@ ISC_STATUS GDS_RELEASE_REQUEST(ISC_STATUS * user_status, rrq** req_handle) * Release a request. * **************************************/ - rrq* request = *req_handle; + Rrq* request = *req_handle; CHECK_HANDLE(request, type_rrq, isc_bad_req_handle); RDB rdb = request->rrq_rdb; @@ -3521,7 +3492,7 @@ ISC_STATUS GDS_RELEASE_REQUEST(ISC_STATUS * user_status, rrq** req_handle) ISC_STATUS GDS_REQUEST_INFO(ISC_STATUS* user_status, - rrq** req_handle, + Rrq** req_handle, SSHORT level, SSHORT item_length, const UCHAR* items, SSHORT buffer_length, UCHAR* buffer) @@ -3538,7 +3509,7 @@ ISC_STATUS GDS_REQUEST_INFO(ISC_STATUS* user_status, **************************************/ ISC_STATUS status; - rrq* request = REMOTE_find_request(*req_handle, level); + Rrq* request = REMOTE_find_request(*req_handle, level); CHECK_HANDLE(request, type_rrq, isc_bad_req_handle); RDB rdb = request->rrq_rdb; @@ -3551,8 +3522,8 @@ ISC_STATUS GDS_REQUEST_INFO(ISC_STATUS* user_status, try { /* Check for buffered message. If there is, report on it locally. */ - const rrq::rrq_repeat* tail= request->rrq_rpt; - for (const rrq::rrq_repeat* const end = tail + request->rrq_max_msg; + const Rrq::rrq_repeat* tail= request->rrq_rpt.begin(); + for (const Rrq::rrq_repeat* const end = tail + request->rrq_max_msg; tail <= end; tail++) { REM_MSG msg = tail->rrq_message; @@ -3753,7 +3724,7 @@ ISC_STATUS GDS_SEEK_BLOB(ISC_STATUS * user_status, blob->rbl_offset = *result = packet->p_resp.p_resp_blob_id.bid_quad_low; blob->rbl_length = 0; blob->rbl_fragment_length = 0; - blob->rbl_flags &= ~(RBL_eof | RBL_eof_pending | RBL_segment); + blob->rbl_flags &= ~(Rbl::EOF_SET | Rbl::EOF_PENDING | Rbl::SEGMENT); } catch (const Firebird::Exception& ex) { @@ -3765,7 +3736,7 @@ ISC_STATUS GDS_SEEK_BLOB(ISC_STATUS * user_status, ISC_STATUS GDS_SEND(ISC_STATUS * user_status, - rrq** req_handle, + Rrq** req_handle, USHORT msg_type, USHORT msg_length, UCHAR * msg, SSHORT level) { /************************************** @@ -3779,7 +3750,7 @@ ISC_STATUS GDS_SEND(ISC_STATUS * user_status, * **************************************/ CHECK_HANDLE((*req_handle), type_rrq, isc_bad_req_handle); - rrq* request = REMOTE_find_request(*req_handle, level); + Rrq* request = REMOTE_find_request(*req_handle, level); RDB rdb = request->rrq_rdb; CHECK_HANDLE(rdb, type_rdb, isc_bad_db_handle); @@ -4065,7 +4036,7 @@ ISC_STATUS GDS_SERVICE_START(ISC_STATUS * user_status, ISC_STATUS GDS_START_AND_SEND(ISC_STATUS * user_status, - rrq** req_handle, + Rrq** req_handle, RTR* rtr_handle, USHORT msg_type, USHORT msg_length, UCHAR * msg, SSHORT level) @@ -4082,7 +4053,7 @@ ISC_STATUS GDS_START_AND_SEND(ISC_STATUS * user_status, **************************************/ CHECK_HANDLE((*req_handle), type_rrq, isc_bad_req_handle); CHECK_HANDLE((*rtr_handle), type_rtr, isc_bad_trans_handle); - rrq* request = REMOTE_find_request(*req_handle, level); + Rrq* request = REMOTE_find_request(*req_handle, level); RTR transaction = *rtr_handle; RDB rdb = request->rrq_rdb; @@ -4152,7 +4123,7 @@ ISC_STATUS GDS_START_AND_SEND(ISC_STATUS * user_status, ISC_STATUS GDS_START(ISC_STATUS * user_status, - rrq** req_handle, + Rrq** req_handle, RTR* rtr_handle, USHORT level) { /************************************** @@ -4167,7 +4138,7 @@ ISC_STATUS GDS_START(ISC_STATUS * user_status, **************************************/ CHECK_HANDLE((*req_handle), type_rrq, isc_bad_req_handle); CHECK_HANDLE((*rtr_handle), type_rtr, isc_bad_trans_handle); - rrq* request = REMOTE_find_request(*req_handle, level); + Rrq* request = REMOTE_find_request(*req_handle, level); RTR transaction = *rtr_handle; RDB rdb = request->rrq_rdb; @@ -4314,7 +4285,7 @@ ISC_STATUS GDS_TRANSACT_REQUEST(ISC_STATUS* user_status, RPR procedure = port->port_rpr; if (!procedure) { - procedure = port->port_rpr = (RPR) ALLR_block(type_rpr, 0); + procedure = port->port_rpr = new rpr; } if ((*rtr_handle)->rtr_rdb != rdb) { @@ -4326,22 +4297,14 @@ ISC_STATUS GDS_TRANSACT_REQUEST(ISC_STATUS* user_status, /* Parse the blr describing the messages */ - if (procedure->rpr_in_msg) { - ALLR_free(procedure->rpr_in_msg); - procedure->rpr_in_msg = NULL; - } - if (procedure->rpr_in_format) { - ALLR_free(procedure->rpr_in_format); - procedure->rpr_in_format = NULL; - } - if (procedure->rpr_out_msg) { - ALLR_free(procedure->rpr_out_msg); - procedure->rpr_out_msg = NULL; - } - if (procedure->rpr_out_format) { - ALLR_free(procedure->rpr_out_format); - procedure->rpr_out_format = NULL; - } + delete procedure->rpr_in_msg; + procedure->rpr_in_msg = NULL; + delete procedure->rpr_in_format; + procedure->rpr_in_format = NULL; + delete procedure->rpr_out_msg; + procedure->rpr_out_msg = NULL; + delete procedure->rpr_out_format; + procedure->rpr_out_format = NULL; REM_MSG message = PARSE_messages(blr, blr_length); if (message != (REM_MSG) - 1) { @@ -4365,7 +4328,7 @@ ISC_STATUS GDS_TRANSACT_REQUEST(ISC_STATUS* user_status, default: REM_MSG temp = message; message = message->msg_next; - ALLR_free(temp); + delete temp; break; } } @@ -4456,7 +4419,7 @@ ISC_STATUS GDS_TRANSACTION_INFO(ISC_STATUS* user_status, } -ISC_STATUS GDS_UNWIND(ISC_STATUS* user_status, rrq** req_handle, USHORT level) +ISC_STATUS GDS_UNWIND(ISC_STATUS* user_status, Rrq** req_handle, USHORT level) { /************************************** * @@ -4468,7 +4431,7 @@ ISC_STATUS GDS_UNWIND(ISC_STATUS* user_status, rrq** req_handle, USHORT level) * Unwind a running request. * **************************************/ - rrq* request = REMOTE_find_request(*req_handle, level); + Rrq* request = REMOTE_find_request(*req_handle, level); CHECK_HANDLE(request, type_rrq, isc_bad_req_handle); RDB rdb = request->rrq_rdb; @@ -4514,7 +4477,7 @@ static RVNT add_event( rem_port* port) } if (!event) { - event = (RVNT) ALLR_block(type_rvnt, 0); + event = new rvnt; event->rvnt_next = rdb->rdb_events; rdb->rdb_events = event; } @@ -4875,7 +4838,7 @@ static bool batch_dsql_fetch(rem_port* port, fb_assert(que_inst->rmtque_function == batch_dsql_fetch); RDB rdb = que_inst->rmtque_rdb; - RSR statement = static_cast(que_inst->rmtque_parm); + RSR statement = static_cast(que_inst->rmtque_parm); PACKET* packet = &rdb->rdb_packet; fb_assert(port == rdb->rdb_port); @@ -4900,11 +4863,11 @@ static bool batch_dsql_fetch(rem_port* port, /* In addtion to the above we grab all the records in case of XNET as * we need to clear the queue */ bool clear_queue = false; - if (id != statement->rsr_id || port->port_type == port_xnet) { + if (id != statement->rsr_id || port->port_type == rem_port::XNET) { clear_queue = true; } - statement->rsr_flags |= RSR_fetched; + statement->rsr_flags |= Rsr::FETCHED; while (true) { /* Swallow up data. If a buffer isn't available, allocate another. */ @@ -4912,7 +4875,7 @@ static bool batch_dsql_fetch(rem_port* port, REM_MSG message = statement->rsr_buffer; if (message->msg_address) { - REM_MSG new_msg = (REM_MSG) ALLR_block(type_msg, statement->rsr_fmt_length); + REM_MSG new_msg = new Message(statement->rsr_fmt_length); statement->rsr_buffer = new_msg; new_msg->msg_next = message; @@ -4945,7 +4908,7 @@ static bool batch_dsql_fetch(rem_port* port, } if (packet->p_operation != op_fetch_response) { - statement->rsr_flags |= RSR_stream_err; + statement->rsr_flags |= Rsr::STREAM_ERR; check_response(rdb, packet); /* save the status vector in a safe place */ @@ -4966,7 +4929,7 @@ static bool batch_dsql_fetch(rem_port* port, { if (packet->p_sqldata.p_sqldata_status == 100) { - statement->rsr_flags |= RSR_eof; + statement->rsr_flags |= Rsr::EOF_SET; statement->rsr_rows_pending = 0; #ifdef DEBUG fprintf(stdout, @@ -5036,8 +4999,8 @@ static bool batch_gds_receive(rem_port* port, fb_assert(que_inst->rmtque_function == batch_gds_receive); RDB rdb = que_inst->rmtque_rdb; - rrq* request = static_cast(que_inst->rmtque_parm); - rrq::rrq_repeat* tail = que_inst->rmtque_message; + Rrq* request = static_cast(que_inst->rmtque_parm); + Rrq::rrq_repeat* tail = que_inst->rmtque_message; PACKET *packet = &rdb->rdb_packet; fb_assert(port == rdb->rdb_port); @@ -5053,7 +5016,7 @@ static bool batch_gds_receive(rem_port* port, // always clear the complete queue for XNET, as we might // have incomplete packets - if (id != request->rrq_id || port->port_type == port_xnet) { + if (id != request->rrq_id || port->port_type == rem_port::XNET) { clear_queue = true; } @@ -5071,7 +5034,7 @@ static bool batch_gds_receive(rem_port* port, if (message->msg_address) { const rem_fmt* format = tail->rrq_format; - REM_MSG new_msg = (REM_MSG) ALLR_block(type_msg, format->fmt_length); + REM_MSG new_msg = new Message(format->fmt_length); tail->rrq_xdr = new_msg; new_msg->msg_next = message; new_msg->msg_number = message->msg_number; @@ -5129,8 +5092,8 @@ static bool batch_gds_receive(rem_port* port, #ifdef SCROLLABLE_CURSORS /* at this point we've received a row into the message, so mark the message with the absolute offset */ - const bool bIsBackward = (tail->rrq_flags & RRQ_backward) != 0; - const bool bIsAbsBackward = (tail->rrq_flags & RRQ_absolute_backward) != 0; + const bool bIsBackward = (tail->rrq_flags & Rrq::BACKWARD) != 0; + const bool bIsAbsBackward = (tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD) != 0; if (bIsBackward == bIsAbsBackward) { tail->rrq_absolute++; @@ -5304,7 +5267,7 @@ static void disconnect( rem_port* port) */ - if (port->port_type != port_pipe) { + if (port->port_type != rem_port::PIPE) { packet->p_operation = op_disconnect; port->send(packet); } @@ -5326,16 +5289,13 @@ static void disconnect( rem_port* port) memory for remote database context. */ port->disconnect(); - - if (rdb) { - ALLR_free(rdb); - } + delete rdb; } #ifdef SCROLLABLE_CURSORS static REM_MSG dump_cache( - rem_port* port, ISC_STATUS * user_status, rrq::rrq_repeat * tail) + rem_port* port, ISC_STATUS * user_status, Rrq::rrq_repeat * tail) { /************************************** * @@ -5822,7 +5782,7 @@ static RTR make_transaction( RDB rdb, USHORT id) * Create a local transaction handle. * **************************************/ - RTR transaction = (RTR) ALLR_block(type_rtr, 0); + RTR transaction = new Rtr; transaction->rtr_rdb = rdb; transaction->rtr_id = id; transaction->rtr_next = rdb->rdb_transactions; @@ -5857,8 +5817,8 @@ static ISC_STATUS mov_dsql_message(ISC_STATUS* status, /* Msg 263 SQLDA missing or wrong number of variables */ } - const dsc* from_desc = from_fmt->fmt_desc; - const dsc* to_desc = to_fmt->fmt_desc; + const dsc* from_desc = from_fmt->fmt_desc.begin(); + const dsc* to_desc = to_fmt->fmt_desc.begin(); const dsc* const end_desc = to_desc + to_fmt->fmt_count; for (; to_desc < end_desc; from_desc++, to_desc++) { dsc from = *from_desc; @@ -5928,7 +5888,7 @@ static void move_error(ISC_STATUS status, ...) } -static void receive_after_start( rrq* request, USHORT msg_type) +static void receive_after_start( Rrq* request, USHORT msg_type) { /***************************************** * @@ -5955,7 +5915,7 @@ static void receive_after_start( rrq* request, USHORT msg_type) RDB rdb = request->rrq_rdb; rem_port* port = rdb->rdb_port; PACKET* packet = &rdb->rdb_packet; - rrq::rrq_repeat* tail = &request->rrq_rpt[msg_type]; + Rrq::rrq_repeat* tail = &request->rrq_rpt[msg_type]; // CVC: I commented this line because it's overwritten immediately in the loop. // REM_MSG message = tail->rrq_message; const rem_fmt* format = tail->rrq_format; @@ -5971,7 +5931,7 @@ static void receive_after_start( rrq* request, USHORT msg_type) while (true) { REM_MSG message = tail->rrq_xdr; if (message->msg_address) { - REM_MSG new_msg = (REM_MSG) ALLR_block(type_msg, format->fmt_length); + REM_MSG new_msg = new Message(format->fmt_length); tail->rrq_xdr = new_msg; new_msg->msg_next = message; new_msg->msg_number = message->msg_number; @@ -6127,7 +6087,7 @@ static bool receive_packet_noqueue(rem_port* port, RSR statement = NULL; if (bCheckResponse || bFreeStmt) { - statement = (RSR) port->port_objects[stmt_id]; + statement = port->port_objects[stmt_id]; CHECK_HANDLE(statement, type_rsr, isc_bad_req_handle); } @@ -6143,7 +6103,7 @@ static bool receive_packet_noqueue(rem_port* port, { // assign statement to transaction const OBJCT tran_id = p->packet.p_sqldata.p_sqldata_transaction; - RTR transaction = (RTR) port->port_objects[tran_id]; + RTR transaction = port->port_objects[tran_id]; statement->rsr_rtr = transaction; } } @@ -6205,7 +6165,7 @@ static void enqueue_receive(rem_port* port, t_rmtque_fn fn, RDB rdb, void* parm, - rrq::rrq_repeat* parm1) + Rrq::rrq_repeat* parm1) { /************************************** * @@ -6216,7 +6176,7 @@ static void enqueue_receive(rem_port* port, * Functional description * **************************************/ - RMTQUE que_inst = (RMTQUE) ALLR_block(type_rmtque, 0); + RMTQUE que_inst = new rmtque; /* Prepare a queue entry */ @@ -6257,7 +6217,7 @@ static void dequeue_receive( rem_port* port) /* Add queue entry onto free queue */ - ALLR_free(que_inst); + delete que_inst; } @@ -6298,7 +6258,7 @@ static void release_blob( RBL blob) **************************************/ RTR transaction = blob->rbl_rtr; RDB rdb = blob->rbl_rdb; - SET_OBJECT(rdb, NULL, blob->rbl_id); + rdb->rdb_port->releaseObject(blob->rbl_id); for (RBL* p = &transaction->rtr_blobs; *p; p = &(*p)->rbl_next) { @@ -6308,10 +6268,7 @@ static void release_blob( RBL blob) } } - if (blob->rbl_buffer != blob->rbl_data) - ALLR_free(blob->rbl_buffer); - - ALLR_free(blob); + delete blob; } @@ -6337,7 +6294,7 @@ static void release_event( RVNT event) } } - ALLR_free(event); + delete event; } @@ -6380,7 +6337,7 @@ static bool release_object(RDB rdb, } -static void release_request( rrq* request) +static void release_request( Rrq* request) { /************************************** * @@ -6393,7 +6350,7 @@ static void release_request( rrq* request) * **************************************/ RDB rdb = request->rrq_rdb; - SET_OBJECT(rdb, NULL, request->rrq_id); + rdb->rdb_port->releaseObject(request->rrq_id); REMOTE_release_request(request); } @@ -6411,23 +6368,19 @@ static void release_statement( RSR* statement) * **************************************/ - if ((*statement)->rsr_bind_format) { - ALLR_free((*statement)->rsr_bind_format); - } + delete (*statement)->rsr_bind_format; if ((*statement)->rsr_user_select_format && (*statement)->rsr_user_select_format != (*statement)->rsr_select_format) { - ALLR_free((*statement)->rsr_user_select_format); - } - if ((*statement)->rsr_select_format) { - ALLR_free((*statement)->rsr_select_format); + delete (*statement)->rsr_user_select_format; } + delete (*statement)->rsr_select_format; stmt_release_exception(*statement); REMOTE_release_messages((*statement)->rsr_message); - ALLR_free((*statement)); - (*statement) = NULL; + delete *statement; + *statement = NULL; } @@ -6444,7 +6397,7 @@ static void release_sql_request( RSR statement) * **************************************/ RDB rdb = statement->rsr_rdb; - SET_OBJECT(rdb, NULL, statement->rsr_id); + rdb->rdb_port->releaseObject(statement->rsr_id); for (RSR* p = &rdb->rdb_sql_requests; *p; p = &(*p)->rsr_next) { @@ -6471,7 +6424,7 @@ static void release_transaction( RTR transaction) * **************************************/ RDB rdb = transaction->rtr_rdb; - SET_OBJECT(rdb, NULL, transaction->rtr_id); + rdb->rdb_port->releaseObject(transaction->rtr_id); while (transaction->rtr_blobs) release_blob(transaction->rtr_blobs); @@ -6484,7 +6437,7 @@ static void release_transaction( RTR transaction) } } - ALLR_free(transaction); + delete transaction; } @@ -6522,9 +6475,9 @@ static ISC_STATUS return_success( RDB rdb) #ifdef SCROLLABLE_CURSORS static REM_MSG scroll_cache( ISC_STATUS * user_status, - rrq* request, + Rrq* request, rem_port* port, - rrq::rrq_repeat * tail, + Rrq::rrq_repeat * tail, USHORT * direction, ULONG * offset) { /************************************** @@ -6564,16 +6517,16 @@ static REM_MSG scroll_cache( for, save the last direction asked for by the next layer above */ if (*direction == blr_continue) { - if (tail->rrq_flags & RRQ_last_backward) + if (tail->rrq_flags & Rrq::LAST_BACKWARD) *direction = blr_backward; else *direction = blr_forward; } if (*direction == blr_forward || *direction == blr_bof_forward) - tail->rrq_flags &= ~RRQ_last_backward; + tail->rrq_flags &= ~Rrq::LAST_BACKWARD; else - tail->rrq_flags |= RRQ_last_backward; + tail->rrq_flags |= Rrq::LAST_BACKWARD; /* set to the last message returned to the higher level; if none, set to the first message in cache */ @@ -6586,8 +6539,8 @@ static REM_MSG scroll_cache( forward one by positioning to the first record, so decrement the offset by one */ if (*offset && - ((*direction == blr_forward) && !(tail->rrq_flags & RRQ_backward)) - || ((*direction == blr_backward) && (tail->rrq_flags & RRQ_backward))) + ((*direction == blr_forward) && !(tail->rrq_flags & Rrq::BACKWARD)) + || ((*direction == blr_backward) && (tail->rrq_flags & Rrq::BACKWARD))) { (*offset)--; } @@ -6597,8 +6550,8 @@ static REM_MSG scroll_cache( (or vice versa), the cache is unusable. */ if ( - (*direction == blr_bof_forward && (tail->rrq_flags & RRQ_absolute_backward)) - || (*direction == blr_eof_backward && !(tail->rrq_flags & RRQ_absolute_backward))) + (*direction == blr_bof_forward && (tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD)) + || (*direction == blr_eof_backward && !(tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD))) { return dump_cache(port, user_status, tail); } @@ -6616,7 +6569,7 @@ static REM_MSG scroll_cache( /* if the cache was formed in the backward direction, see if there are any packets pending which might contain the record */ - if ((tail->rrq_flags & RRQ_backward) + if ((tail->rrq_flags & Rrq::BACKWARD) && (tail->rrq_rows_pending > 0)) { tail->rrq_message = message; @@ -6661,8 +6614,8 @@ static REM_MSG scroll_cache( { if (tail->rrq_rows_pending > 0) { - if (((*direction == blr_forward) && !(tail->rrq_flags & RRQ_backward)) || - ((*direction == blr_backward) && (tail->rrq_flags & RRQ_backward))) + if (((*direction == blr_forward) && !(tail->rrq_flags & Rrq::BACKWARD)) || + ((*direction == blr_backward) && (tail->rrq_flags & Rrq::BACKWARD))) { tail->rrq_message = message; while (!message->msg_address && @@ -6686,8 +6639,8 @@ static REM_MSG scroll_cache( /* step one record forward or back, depending on whether the cache was initially formed in the forward or backward direction */ - if (((*direction == blr_forward) && !(tail->rrq_flags & RRQ_backward)) || - ((*direction == blr_backward) && (tail->rrq_flags & RRQ_backward))) + if (((*direction == blr_forward) && !(tail->rrq_flags & Rrq::BACKWARD)) || + ((*direction == blr_backward) && (tail->rrq_flags & Rrq::BACKWARD))) { message = message->msg_next; } diff --git a/src/remote/parse_proto.h b/src/remote/parse_proto.h index 3c80745dcd..5f13fe219e 100644 --- a/src/remote/parse_proto.h +++ b/src/remote/parse_proto.h @@ -24,7 +24,7 @@ #ifndef REMOTE_PARSE_PROTO_H #define REMOTE_PARSE_PROTO_H -struct message* PARSE_messages(const UCHAR*, USHORT); +struct Message* PARSE_messages(const UCHAR*, USHORT); const UCHAR* PARSE_prepare_messages(const UCHAR*, USHORT); #endif // REMOTE_PARSE_PROTO_H diff --git a/src/remote/parser.cpp b/src/remote/parser.cpp index 4f1a297e46..ba3698c176 100644 --- a/src/remote/parser.cpp +++ b/src/remote/parser.cpp @@ -67,13 +67,13 @@ REM_MSG PARSE_messages(const UCHAR* blr, USHORT blr_length) const USHORT msg_number = *blr++; USHORT count = *blr++; count += (*blr++) << 8; - rem_fmt* format = (rem_fmt*) ALLR_block(type_fmt, count); + rem_fmt* format = new rem_fmt(count); #ifdef DEBUG_REMOTE_MEMORY printf("PARSE_messages allocate format %x\n", format); #endif format->fmt_count = count; USHORT offset = 0; - for (dsc* desc = format->fmt_desc; count; --count, ++desc) { + for (dsc* desc = format->fmt_desc.begin(); count; --count, ++desc) { USHORT align = 4; switch (*blr++) { case blr_text: @@ -197,11 +197,11 @@ REM_MSG PARSE_messages(const UCHAR* blr, USHORT blr_length) default: fb_assert(FALSE); - ALLR_free(format); + delete format; while (next = message) { message = message->msg_next; - ALLR_free(next->msg_address); - ALLR_free(next); + delete next->msg_address; + delete next; } return (REM_MSG) - 1; } @@ -216,7 +216,7 @@ REM_MSG PARSE_messages(const UCHAR* blr, USHORT blr_length) } format->fmt_length = offset; format->fmt_net_length = net_length; - next = (REM_MSG) ALLR_block(type_msg, format->fmt_length); + next = new Message(format->fmt_length); #ifdef DEBUG_REMOTE_MEMORY printf("PARSE_messages allocate message %x\n", next); #endif @@ -286,8 +286,7 @@ const UCHAR* PARSE_prepare_messages(const UCHAR* blr, USHORT blr_length) case blr_d_float: if (new_blr == old_blr) { - new_blr = (UCHAR *) ALLR_alloc((SLONG) blr_length); - /* NOMEM: ALLR_alloc() handled */ + new_blr = FB_NEW(*getDefaultMemoryPool()) UCHAR[blr_length]; /* FREE: Never freed, blr_d_float is VMS specific */ #ifdef DEBUG_REMOTE_MEMORY printf diff --git a/src/remote/protocol.cpp b/src/remote/protocol.cpp index a5df27d425..468b50bf3c 100644 --- a/src/remote/protocol.cpp +++ b/src/remote/protocol.cpp @@ -901,12 +901,10 @@ static bool alloc_cstring(XDR* xdrs, if (!cstring->cstr_address) { // fb_assert(!cstring->cstr_allocated); - if (! - (cstring->cstr_address = - ALLR_alloc((SLONG) cstring->cstr_length))) - { - /* NOMEM: handled by ALLR_alloc() */ - /* FREE: in realloc case above & free_cstring() */ + try { + cstring->cstr_address = FB_NEW(*getDefaultMemoryPool()) UCHAR[cstring->cstr_length]; + } + catch (const Firebird::BadAlloc&) { return false; } @@ -933,7 +931,7 @@ static void free_cstring( XDR* xdrs, CSTRING* cstring) **************************************/ if (cstring->cstr_allocated) { - ALLR_free(cstring->cstr_address); + delete[] cstring->cstr_address; DEBUG_XDR_FREE(xdrs, cstring, cstring->cstr_address, cstring->cstr_allocated); } @@ -1186,7 +1184,7 @@ static bool_t xdr_debug_packet( XDR* xdrs, enum xdr_op xop, PACKET* packet) to start recording memory allocations for this packet. */ fb_assert(xop == XDR_ENCODE || xop == XDR_DECODE); - rem_vec* vector = ALLR_vector(&port->port_packet_vector, 0); + rem_vec* vector = A L L R _vector(&port->port_packet_vector, 0); for (i = 0; i < vector->vec_count; i++) { @@ -1201,7 +1199,7 @@ static bool_t xdr_debug_packet( XDR* xdrs, enum xdr_op xop, PACKET* packet) } if (i >= vector->vec_count) - vector = ALLR_vector(&port->port_packet_vector, i); + vector = A L L R _vector(&port->port_packet_vector, i); vector->vec_object[i] = (BLK) packet; } @@ -1286,7 +1284,7 @@ static bool_t xdr_message( XDR* xdrs, REM_MSG message, const rem_fmt* format) format->fmt_length); } - const dsc* desc = format->fmt_desc; + const dsc* desc = format->fmt_desc.begin(); for (const dsc* const end = desc + format->fmt_count; desc < end; ++desc) { if (!xdr_datum(xdrs, desc, message->msg_address)) @@ -1363,10 +1361,10 @@ static bool_t xdr_request( rem_port* port = (rem_port*) xdrs->x_public; - if (!port->port_objects || request_id >= port->port_object_vector->vec_count) + if (request_id >= port->port_objects.getCount()) return FALSE; - rrq* request = (rrq*) port->port_objects[request_id]; + Rrq* request = port->port_objects[request_id]; if (!request) return FALSE; @@ -1377,7 +1375,7 @@ static bool_t xdr_request( if (message_number > request->rrq_max_msg) return FALSE; - rrq::rrq_repeat* tail = &request->rrq_rpt[message_number]; + Rrq::rrq_repeat* tail = &request->rrq_rpt[message_number]; REM_MSG message = tail->rrq_xdr; if (!message) @@ -1424,18 +1422,16 @@ static bool_t xdr_slice( if (slice->lstr_length > slice->lstr_allocated && slice->lstr_allocated) { - ALLR_free(slice->lstr_address); + delete slice->lstr_address; DEBUG_XDR_FREE(xdrs, slice, slice->lstr_address, slice->lstr_allocated); slice->lstr_address = NULL; } if (!slice->lstr_address) { - if (! - (slice->lstr_address = - ALLR_alloc((SLONG) slice->lstr_length))) - { - /* NOMEM: handled by ALLR_alloc() */ - /* FREE: in realloc case above & XDR_FREE case of this routine */ - return FALSE; + try { + slice->lstr_address = FB_NEW(*getDefaultMemoryPool()) UCHAR[slice->lstr_length]; + } + catch (const Firebird::BadAlloc&) { + return false; } slice->lstr_allocated = slice->lstr_length; @@ -1446,7 +1442,7 @@ static bool_t xdr_slice( case XDR_FREE: if (slice->lstr_allocated) { - ALLR_free(slice->lstr_address); + delete[] slice->lstr_address; DEBUG_XDR_FREE(xdrs, slice, slice->lstr_address, slice->lstr_allocated); } slice->lstr_address = NULL; @@ -1518,16 +1514,14 @@ static bool_t xdr_sql_blr( rem_port* port = (rem_port*) xdrs->x_public; RSR statement; if (statement_id >= 0) { - if (!port->port_objects) + if (static_cast(statement_id) >= port->port_objects.getCount()) return FALSE; - if (static_cast(statement_id) >= port->port_object_vector->vec_count) - return FALSE; - if (!(statement = (RSR) port->port_objects[statement_id])) + if (!(statement = port->port_objects[statement_id])) return FALSE; } else { if (!(statement = port->port_statement)) - statement = port->port_statement = (RSR) ALLR_block(type_rsr, 0); + statement = port->port_statement = new Rsr; } if ((xdrs->x_op == XDR_ENCODE) && !direction) { @@ -1550,7 +1544,7 @@ static bool_t xdr_sql_blr( if (*fmt_ptr && ((stmt_type == TYPE_IMMEDIATE) || blr->cstr_length != 0)) { - ALLR_free(*fmt_ptr); + delete *fmt_ptr; *fmt_ptr = NULL; } @@ -1562,7 +1556,7 @@ static bool_t xdr_sql_blr( (REM_MSG) PARSE_messages(blr->cstr_address, blr->cstr_length); if (temp_msg != (REM_MSG) -1) { *fmt_ptr = (rem_fmt*) temp_msg->msg_address; - ALLR_free(temp_msg); + delete temp_msg; } } } @@ -1579,8 +1573,7 @@ static bool_t xdr_sql_blr( { REMOTE_release_messages(message); statement->rsr_fmt_length = statement->rsr_format->fmt_length; - statement->rsr_buffer = message = - (REM_MSG) ALLR_block(type_msg, statement->rsr_fmt_length); + statement->rsr_buffer = message = new Message(statement->rsr_fmt_length); statement->rsr_message = message; message->msg_next = message; #ifdef SCROLLABLE_CURSORS @@ -1611,11 +1604,9 @@ static bool_t xdr_sql_message( XDR* xdrs, SLONG statement_id) rem_port* port = (rem_port*) xdrs->x_public; if (statement_id >= 0) { - if (!port->port_objects) + if (static_cast(statement_id) >= port->port_objects.getCount()) return FALSE; - if (static_cast(statement_id) >= port->port_object_vector->vec_count) - return FALSE; - statement = (RSR) port->port_objects[statement_id]; + statement = port->port_objects[statement_id]; } else statement = port->port_statement; @@ -1744,26 +1735,18 @@ static bool_t xdr_trrq_blr( XDR* xdrs, CSTRING* blr) rem_port* port = (rem_port*) xdrs->x_public; RPR procedure = port->port_rpr; if (!procedure) - procedure = port->port_rpr = (RPR) ALLR_block(type_rpr, 0); + procedure = port->port_rpr = new rpr; /* Parse the blr describing the message. */ - if (procedure->rpr_in_msg) { - ALLR_free(procedure->rpr_in_msg); - procedure->rpr_in_msg = NULL; - } - if (procedure->rpr_in_format) { - ALLR_free(procedure->rpr_in_format); - procedure->rpr_in_format = NULL; - } - if (procedure->rpr_out_msg) { - ALLR_free(procedure->rpr_out_msg); - procedure->rpr_out_msg = NULL; - } - if (procedure->rpr_out_format) { - ALLR_free(procedure->rpr_out_format); - procedure->rpr_out_format = NULL; - } + delete procedure->rpr_in_msg; + procedure->rpr_in_msg = NULL; + delete procedure->rpr_in_format; + procedure->rpr_in_format = NULL; + delete procedure->rpr_out_msg; + procedure->rpr_out_msg = NULL; + delete procedure->rpr_out_format; + procedure->rpr_out_format = NULL; REM_MSG message = PARSE_messages(blr->cstr_address, blr->cstr_length); if (message != (REM_MSG) -1) { @@ -1788,7 +1771,7 @@ static bool_t xdr_trrq_blr( XDR* xdrs, CSTRING* blr) { REM_MSG temp = message; message = message->msg_next; - ALLR_free(temp); + delete temp; } break; } @@ -1844,7 +1827,7 @@ static RSR get_statement( XDR * xdrs, SSHORT statement_id) * **************************************/ - rsr* statement = NULL; + Rsr* statement = NULL; rem_port* port = (rem_port*) xdrs->x_public; /* if the statement ID is -1, this seems to indicate that we are @@ -1858,15 +1841,12 @@ else fb_assert(statement_id >= -1); - if ((port->port_objects) && - ((SLONG) statement_id < (SLONG) port->port_object_vector->vec_count) + if (((ULONG) statement_id < port->port_objects.getCount()) && (statement_id >= 0)) { - statement = (RSR) port->port_objects[(SLONG) statement_id]; + statement = port->port_objects[statement_id]; } -/* Check that what we found really is a statement structure */ - fb_assert(!statement || (statement->rsr_header.blk_type == type_rsr)); return statement; } diff --git a/src/remote/protocol.h b/src/remote/protocol.h index ab52f71572..c47fcadeb8 100644 --- a/src/remote/protocol.h +++ b/src/remote/protocol.h @@ -654,6 +654,12 @@ typedef struct packet { P_TRAU p_trau; /* Trusted authentication */ p_update_account p_account_update; p_authenticate p_authenticate_user; + +public: + packet() + { + memset(this, 0, sizeof(*this)); + } } PACKET; #endif // REMOTE_PROTOCOL_H diff --git a/src/remote/remot_proto.h b/src/remote/remot_proto.h index b78f116f86..a7fd9aa3d2 100644 --- a/src/remote/remot_proto.h +++ b/src/remote/remot_proto.h @@ -24,24 +24,22 @@ #ifndef REMOTE_REMOT_PROTO_H #define REMOTE_REMOT_PROTO_H -struct blk; namespace Firebird { class ClumpletReader; }; -void REMOTE_cleanup_transaction (struct rtr *); +void REMOTE_cleanup_transaction (struct Rtr *); ULONG REMOTE_compute_batch_size (rem_port*, USHORT, P_OP, const rem_fmt*); void REMOTE_get_timeout_params(rem_port* port, Firebird::ClumpletReader* pb); -struct rrq* REMOTE_find_request (struct rrq *, USHORT); +struct Rrq* REMOTE_find_request (struct Rrq *, USHORT); void REMOTE_free_packet (rem_port*, struct packet *, bool = false); struct rem_str* REMOTE_make_string (const SCHAR*); -void REMOTE_release_messages (struct message *); -void REMOTE_release_request (struct rrq *); -void REMOTE_reset_request (struct rrq *, struct message *); -void REMOTE_reset_statement (struct rsr *); +void REMOTE_release_messages (struct Message *); +void REMOTE_release_request (struct Rrq *); +void REMOTE_reset_request (struct Rrq *, struct Message *); +void REMOTE_reset_statement (struct Rsr *); void REMOTE_save_status_strings (ISC_STATUS *); -OBJCT REMOTE_set_object (rem_port*, blk*, OBJCT); bool_t REMOTE_getbytes (XDR*, SCHAR*, u_int); #endif // REMOTE_REMOT_PROTO_H diff --git a/src/remote/remote.cpp b/src/remote/remote.cpp index 19f22f7515..ca0a2502df 100644 --- a/src/remote/remote.cpp +++ b/src/remote/remote.cpp @@ -29,7 +29,6 @@ #include "../jrd/file_params.h" #include "../jrd/gdsassert.h" #include "../jrd/isc.h" -#include "../remote/allr_proto.h" #include "../remote/proto_proto.h" #include "../remote/remot_proto.h" #include "../remote/xdr_proto.h" @@ -64,14 +63,14 @@ void REMOTE_cleanup_transaction( RTR transaction) * receive while we still have something cached. * **************************************/ - for (rrq* request = transaction->rtr_rdb->rdb_requests; request; + for (Rrq* request = transaction->rtr_rdb->rdb_requests; request; request = request->rrq_next) { if (request->rrq_rtr == transaction) { REMOTE_reset_request(request, 0); request->rrq_rtr = NULL; } - for (rrq* level = request->rrq_levels; level; level = level->rrq_next) + for (Rrq* level = request->rrq_levels; level; level = level->rrq_next) if (level->rrq_rtr == transaction) { REMOTE_reset_request(level, 0); level->rrq_rtr = NULL; @@ -83,7 +82,7 @@ void REMOTE_cleanup_transaction( RTR transaction) { if (statement->rsr_rtr == transaction) { REMOTE_reset_statement(statement); - statement->rsr_flags &= ~RSR_fetched; + statement->rsr_flags &= ~Rsr::FETCHED; statement->rsr_rtr = NULL; } } @@ -220,7 +219,7 @@ const USHORT MIN_ROWS_PER_BATCH = 10; /* data rows - picked by SWAG */ } -rrq* REMOTE_find_request(rrq* request, USHORT level) +Rrq* REMOTE_find_request(Rrq* request, USHORT level) { /************************************** * @@ -245,8 +244,8 @@ rrq* REMOTE_find_request(rrq* request, USHORT level) /* This is a new level -- make up a new request block. */ - request->rrq_levels = (rrq*) ALLR_clone(&request->rrq_header); -/* NOMEM: handled by ALLR_clone, FREE: REMOTE_remove_request() */ + request->rrq_levels = request->clone(); +/* FREE: REMOTE_remove_request() */ #ifdef DEBUG_REMOTE_MEMORY printf("REMOTE_find_request allocate request %x\n", request->rrq_levels); @@ -257,13 +256,13 @@ rrq* REMOTE_find_request(rrq* request, USHORT level) /* Allocate message block for known messages */ - rrq::rrq_repeat* tail = request->rrq_rpt; - const rrq::rrq_repeat* const end = tail + request->rrq_max_msg; + Rrq::rrq_repeat* tail = request->rrq_rpt.begin(); + const Rrq::rrq_repeat* const end = tail + request->rrq_max_msg; for (; tail <= end; tail++) { const rem_fmt* format = tail->rrq_format; if (!format) continue; - REM_MSG msg = (REM_MSG) ALLR_block(type_msg, format->fmt_length); + REM_MSG msg = new Message(format->fmt_length); tail->rrq_xdr = msg; #ifdef DEBUG_REMOTE_MEMORY printf("REMOTE_find_request allocate message %x\n", msg); @@ -373,7 +372,7 @@ rem_str* REMOTE_make_string(const SCHAR* input) * **************************************/ const USHORT length = strlen(input); - rem_str* string = (rem_str*) ALLR_block(type_str, length); + rem_str* string = FB_NEW_RPT(*getDefaultMemoryPool(), length) rem_str; #ifdef DEBUG_REMOTE_MEMORY printf("REMOTE_make_string allocate string %x\n", string); #endif @@ -405,14 +404,14 @@ void REMOTE_release_messages( REM_MSG messages) printf("REMOTE_release_messages free message %x\n", temp); #endif - ALLR_free(temp); + delete temp; if (message == messages) break; } } -void REMOTE_release_request( rrq* request) +void REMOTE_release_request( Rrq* request) { /************************************** * @@ -426,7 +425,7 @@ void REMOTE_release_request( rrq* request) **************************************/ RDB rdb = request->rrq_rdb; - for (rrq** p = &rdb->rdb_requests; *p; p = &(*p)->rrq_next) + for (Rrq** p = &rdb->rdb_requests; *p; p = &(*p)->rrq_next) { if (*p == request) { *p = request->rrq_next; @@ -437,8 +436,8 @@ void REMOTE_release_request( rrq* request) /* Get rid of request and all levels */ for (;;) { - rrq::rrq_repeat* tail = request->rrq_rpt; - const rrq::rrq_repeat* const end = tail + request->rrq_max_msg; + Rrq::rrq_repeat* tail = request->rrq_rpt.begin(); + const Rrq::rrq_repeat* const end = tail + request->rrq_max_msg; for (; tail <= end; tail++) { REM_MSG message = tail->rrq_message; @@ -449,23 +448,23 @@ void REMOTE_release_request( rrq* request) ("REMOTE_release_request free format %x\n", tail->rrq_format); #endif - ALLR_free(tail->rrq_format); + delete tail->rrq_format; } REMOTE_release_messages(message); } } - rrq* next = request->rrq_levels; + Rrq* next = request->rrq_levels; #ifdef DEBUG_REMOTE_MEMORY printf("REMOTE_release_request free request %x\n", request); #endif - ALLR_free(request); + delete request; if (!(request = next)) break; } } -void REMOTE_reset_request( rrq* request, REM_MSG active_message) +void REMOTE_reset_request( Rrq* request, REM_MSG active_message) { /************************************** * @@ -479,8 +478,8 @@ void REMOTE_reset_request( rrq* request, REM_MSG active_message) * some care to avoid zapping that message. * **************************************/ - rrq::rrq_repeat* tail = request->rrq_rpt; - const rrq::rrq_repeat* const end = tail + request->rrq_max_msg; + Rrq::rrq_repeat* tail = request->rrq_rpt.begin(); + const Rrq::rrq_repeat* const end = tail + request->rrq_max_msg; for (; tail <= end; tail++) { REM_MSG message = tail->rrq_message; if (message != NULL && message != active_message) { @@ -619,59 +618,6 @@ void REMOTE_save_status_strings( ISC_STATUS* vector) } -OBJCT REMOTE_set_object(rem_port* port, BLK object, OBJCT slot) -{ -/************************************** - * - * R E M O T E _ s e t _ o b j e c t - * - ************************************** - * - * Functional description - * Set an object into the object vector. - * - **************************************/ - -/* If it fits, do it */ - - rem_vec* vector = port->port_object_vector; - if ((vector != NULL) && slot < vector->vec_count) { - vector->vec_object[slot] = object; - return slot; - } - -/* Prevent the creation of object handles that can't be - transferred by the remote protocol. */ - - if (slot + 10 > MAX_OBJCT_HANDLES) - return (OBJCT) NULL; - - rem_vec* new_vector = (rem_vec*) ALLR_block(type_vec, slot + 10); - port->port_object_vector = new_vector; -#ifdef DEBUG_REMOTE_MEMORY - printf("REMOTE_set_object allocate vector %x\n", new_vector); -#endif - port->port_objects = new_vector->vec_object; - new_vector->vec_count = slot + 10; - - if (vector) { - blk** p = new_vector->vec_object; - blk* const* q = vector->vec_object; - const blk* const* const end = q + (int) vector->vec_count; - while (q < end) - *p++ = *q++; -#ifdef DEBUG_REMOTE_MEMORY - printf("REMOTE_release_request free vector %x\n", vector); -#endif - ALLR_free(vector); - } - - new_vector->vec_object[slot] = object; - - return slot; -} - - static void cleanup_memory( void *block) { /************************************** @@ -769,13 +715,13 @@ bool_t REMOTE_getbytes (XDR * xdrs, SCHAR * buff, u_int count) } rem_port* port = (rem_port*) xdrs->x_public; Firebird::RefMutexGuard queGuard(*port->port_que_sync); - if (port->port_qoffset >= port->port_queue->getCount()) { + if (port->port_qoffset >= port->port_queue.getCount()) { port->port_flags |= PORT_partial_data; return FALSE; } - xdrs->x_handy = (*port->port_queue)[port->port_qoffset].getCount(); + xdrs->x_handy = port->port_queue[port->port_qoffset].getCount(); fb_assert(xdrs->x_handy <= port->port_buff_size); - memcpy(xdrs->x_base, (*port->port_queue)[port->port_qoffset].begin(), xdrs->x_handy); + memcpy(xdrs->x_base, port->port_queue[port->port_qoffset].begin(), xdrs->x_handy); ++port->port_qoffset; xdrs->x_private = xdrs->x_base; } diff --git a/src/remote/remote.h b/src/remote/remote.h index 9e8457c4d0..0528bc615f 100644 --- a/src/remote/remote.h +++ b/src/remote/remote.h @@ -30,7 +30,7 @@ #define REMOTE_REMOTE_H #include "../jrd/common.h" -#include "../remote/allr_proto.h" +#include "gen/iberror.h" #include "../remote/remote_def.h" #include "../jrd/ThreadData.h" #include "../common/thd.h" @@ -75,78 +75,108 @@ DEFINE_TRACE_ROUTINE(remote_trace); const int BLOB_LENGTH = 16384; #include "../remote/protocol.h" +#include "fb_blk.h" -/* Block types */ - -struct blk; - -#ifndef INCLUDE_FB_BLK -#include "../include/old_fb_blk.h" -#endif // fwd. decl. struct rem_port; -typedef struct rdb + +typedef Firebird::AutoPtr > UCharArrayAutoPtr; + + +typedef struct Rdb : public Firebird::GlobalStorage, public TypedHandle { - blk rdb_header; USHORT rdb_id; USHORT rdb_flags; FB_API_HANDLE rdb_handle; /* database handle */ rem_port* rdb_port; /* communication port */ - struct rtr* rdb_transactions; /* linked list of transactions */ - struct rrq* rdb_requests; /* compiled requests */ + struct Rtr* rdb_transactions; /* linked list of transactions */ + struct Rrq* rdb_requests; /* compiled requests */ struct rvnt* rdb_events; /* known events */ - struct rsr* rdb_sql_requests; /* SQL requests */ + struct Rsr* rdb_sql_requests; /* SQL requests */ ISC_STATUS* rdb_status_vector; PACKET rdb_packet; /* Communication structure */ + +public: + enum { + SERVICE = 1 + }; + +public: + Rdb() : + rdb_id(0), rdb_flags(0), rdb_handle(0), + rdb_port(0), rdb_transactions(0), rdb_requests(0), + rdb_events(0), rdb_sql_requests(0), rdb_status_vector(0) + { + } + + static ISC_STATUS badHandle() { return isc_bad_db_handle; } } *RDB; -// rdb_flags -const USHORT RDB_service = 1; /* structure relates to a service */ -typedef struct rtr +typedef struct Rtr : public Firebird::GlobalStorage, public TypedHandle { - blk rtr_header; - rdb* rtr_rdb; - rtr* rtr_next; - struct rbl* rtr_blobs; + Rdb* rtr_rdb; + Rtr* rtr_next; + struct Rbl* rtr_blobs; FB_API_HANDLE rtr_handle; - bool rtr_limbo; USHORT rtr_id; + bool rtr_limbo; + +public: + Rtr() : + rtr_rdb(0), rtr_next(0), rtr_blobs(0), + rtr_handle(0), rtr_id(0), rtr_limbo(0) + { } + + static ISC_STATUS badHandle() { return isc_bad_trans_handle; } } *RTR; -typedef struct rbl + +typedef struct Rbl : public Firebird::GlobalStorage, public TypedHandle { - blk rbl_header; - rdb* rbl_rdb; - rtr* rbl_rtr; - rbl* rbl_next; + Firebird::HalfStaticArray rbl_data; + Rdb* rbl_rdb; + Rtr* rbl_rtr; + Rbl* rbl_next; + UCHAR* rbl_buffer; + UCHAR* rbl_ptr; FB_API_HANDLE rbl_handle; SLONG rbl_offset; /* Apparent (to user) offset in blob */ USHORT rbl_id; USHORT rbl_flags; - UCHAR* rbl_ptr; - UCHAR* rbl_buffer; USHORT rbl_buffer_length; USHORT rbl_length; USHORT rbl_fragment_length; USHORT rbl_source_interp; /* source interp (for writing) */ USHORT rbl_target_interp; /* destination interp (for reading) */ - UCHAR rbl_data[1]; + +public: + enum { + EOF_SET = 1, + SEGMENT = 2, + EOF_PENDING = 4, + CREATE = 8 + }; + +public: + Rbl() : + rbl_data(getPool()), rbl_rdb(0), rbl_rtr(0), rbl_next(0), + rbl_buffer(rbl_data.getBuffer(BLOB_LENGTH)), rbl_ptr(rbl_buffer), rbl_handle(0), + rbl_offset(0), rbl_id(0), rbl_flags(0), + rbl_buffer_length(BLOB_LENGTH), rbl_length(0), rbl_fragment_length(0), + rbl_source_interp(0), rbl_target_interp(0) + { } + + static ISC_STATUS badHandle() { return isc_bad_segstr_handle; } } *RBL; -// rbl_flags -const USHORT RBL_eof = 1; -const USHORT RBL_segment = 2; -const USHORT RBL_eof_pending= 4; -const USHORT RBL_create = 8; -typedef struct rvnt +typedef struct rvnt : public Firebird::GlobalStorage { - blk rvnt_header; rvnt* rvnt_next; - rdb* rvnt_rdb; + Rdb* rvnt_rdb; FPTR_EVENT_CALLBACK rvnt_ast; void* rvnt_arg; SLONG rvnt_id; @@ -154,99 +184,111 @@ typedef struct rvnt rem_port* rvnt_port; /* used to id server from whence async came */ const UCHAR* rvnt_items; SSHORT rvnt_length; + +public: + rvnt() : + rvnt_next(0), rvnt_rdb(0), rvnt_ast(0), + rvnt_arg(0), rvnt_id(0), rvnt_rid(0), + rvnt_port(0), rvnt_items(0), rvnt_length(0) + { } } *RVNT; -struct rem_vec + +struct rem_str : public pool_alloc_rpt { - blk vec_header; - ULONG vec_count; - blk* vec_object[1]; -}; - -//struct rem_vcl -//{ -// blk vcl_header; -// ULONG vcl_count; -// SLONG vcl_long[1]; -//}; - -/* Random string block -- jack of all kludges */ - -struct rem_str -{ - blk str_header; USHORT str_length; SCHAR str_data[2]; }; + /* Include definition of descriptor */ #include "../jrd/dsc.h" -struct rem_fmt +struct rem_fmt : public Firebird::GlobalStorage { - blk fmt_header; USHORT fmt_length; USHORT fmt_net_length; USHORT fmt_count; USHORT fmt_version; - struct dsc fmt_desc[1]; + Firebird::Array fmt_desc; + +public: + rem_fmt(size_t rpt) : + fmt_length(0), fmt_net_length(0), fmt_count(0), + fmt_version(0), fmt_desc(getPool(), rpt) + { + fmt_desc.grow(rpt); + } }; /* Windows declares a msg structure, so rename the structure to avoid overlap problems. */ -typedef struct message +typedef struct Message : public Firebird::GlobalStorage { - blk msg_header; - message* msg_next; /* Next available message */ + Message* msg_next; /* Next available message */ #ifdef SCROLLABLE_CURSORS - message* msg_prior; /* Next available message */ + Message* msg_prior; /* Next available message */ ULONG msg_absolute; /* Absolute record number in cursor result set */ #endif - /* Please DO NOT re-arrange the order of following two fields. - This could result in alignment problems while trying to access - 'msg_buffer' as a 'long', leading to "core" drops - Sriram - 04-Jun-97 */ USHORT msg_number; /* Message number */ UCHAR* msg_address; /* Address of message */ - UCHAR msg_buffer[1]; /* Allocated message */ + UCharArrayAutoPtr msg_buffer; /* Allocated message */ + +public: + Message(size_t rpt) : + msg_next(0), +#ifdef SCROLLABLE_CURSORS + msg_prior(0), msg_absolute(0), +#endif + msg_number(0), msg_address(0), msg_buffer(FB_NEW(getPool()) UCHAR[rpt]) + { + memset(msg_buffer, 0, rpt); + } } *REM_MSG; -/* remote stored procedure request */ -typedef struct rpr +// remote stored procedure request +typedef struct rpr : public Firebird::GlobalStorage { - blk rpr_header; - rdb* rpr_rdb; - rtr* rpr_rtr; + Rdb* rpr_rdb; + Rtr* rpr_rtr; FB_API_HANDLE rpr_handle; - message* rpr_in_msg; /* input message */ - message* rpr_out_msg; /* output message */ + Message* rpr_in_msg; /* input message */ + Message* rpr_out_msg; /* output message */ rem_fmt* rpr_in_format; /* Format of input message */ rem_fmt* rpr_out_format; /* Format of output message */ + +public: + rpr() : + rpr_rdb(0), rpr_rtr(0), rpr_handle(0), + rpr_in_msg(0), rpr_out_msg(0), rpr_in_format(0), rpr_out_format(0) + { } + + //ISC_STATUS badHandle() { return ; } } *RPR; -struct rrq +struct Rrq : public Firebird::GlobalStorage, public TypedHandle { - blk rrq_header; - rdb* rrq_rdb; - rtr* rrq_rtr; - rrq* rrq_next; - rrq* rrq_levels; /* RRQ block for next level */ + Rdb* rrq_rdb; + Rtr* rrq_rtr; + Rrq* rrq_next; + Rrq* rrq_levels; /* RRQ block for next level */ FB_API_HANDLE rrq_handle; USHORT rrq_id; USHORT rrq_max_msg; USHORT rrq_level; ISC_STATUS_ARRAY rrq_status_vector; + struct rrq_repeat { rem_fmt* rrq_format; /* format for this message */ - message* rrq_message; /* beginning or end of cache, depending on whether it is client or server */ - message* rrq_xdr; /* point at which cache is read or written by xdr */ + Message* rrq_message; /* beginning or end of cache, depending on whether it is client or server */ + Message* rrq_xdr; /* point at which cache is read or written by xdr */ #ifdef SCROLLABLE_CURSORS - message* rrq_last; /* last message returned */ + Message* rrq_last; /* last message returned */ ULONG rrq_absolute; /* current offset in result set for record being read into cache */ USHORT rrq_flags; #endif @@ -255,31 +297,52 @@ struct rrq USHORT rrq_reorder_level; /* Reorder when rows_pending < this level */ USHORT rrq_batch_count; /* Count of batches in pipeline */ - } rrq_rpt[1]; -}; + }; + Firebird::Array rrq_rpt; -// rrq_flags +public: #ifdef SCROLLABLE_CURSORS -const USHORT RRQ_backward = 1; /* the cache was created in the backward direction */ -const USHORT RRQ_absolute_backward = 2; /* rrq_absolute is measured from the end of the stream */ -const USHORT RRQ_last_backward = 4; /* last time, the next level up asked for us to scroll in the backward direction */ + enum { + BACKWARD = 1, /* the cache was created in the backward direction */ + ABSOLUTE_BACKWARD = 2, /* rrq_absolute is measured from the end of the stream */ + LAST_BACKWARD = 4 /* last time, the next level up asked for us to scroll in the backward direction */ + }; #endif -/* remote SQL request */ +public: + Rrq(size_t rpt) : + rrq_rdb(0), rrq_rtr(0), rrq_next(0), rrq_levels(0), + rrq_handle(0), rrq_id(0), rrq_max_msg(0), rrq_level(0), + rrq_rpt(getPool(), rpt) + { + memset(rrq_status_vector, 0, sizeof rrq_status_vector); + rrq_rpt.grow(rpt); + } -typedef struct rsr + Rrq* clone() const + { + Rrq* rc = new Rrq(rrq_rpt.getCount()); + *rc = *this; + return rc; + } + + static ISC_STATUS badHandle() { return isc_bad_req_handle; } +}; + + +// remote SQL request +typedef struct Rsr : public Firebird::GlobalStorage, public TypedHandle { - blk rsr_header; - rsr* rsr_next; - rdb* rsr_rdb; - rtr* rsr_rtr; + Rsr* rsr_next; + Rdb* rsr_rdb; + Rtr* rsr_rtr; FB_API_HANDLE rsr_handle; rem_fmt* rsr_bind_format; /* Format of bind message */ rem_fmt* rsr_select_format; /* Format of select message */ rem_fmt* rsr_user_select_format; /* Format of user's select message */ rem_fmt* rsr_format; /* Format of current message */ - message* rsr_message; /* Next message to process */ - message* rsr_buffer; /* Next buffer to use */ + Message* rsr_message; /* Next message to process */ + Message* rsr_buffer; /* Next buffer to use */ Firebird::StatusHolder* rsr_status; /* saved status for buffered errors */ USHORT rsr_id; USHORT rsr_flags; @@ -289,17 +352,74 @@ typedef struct rsr USHORT rsr_msgs_waiting; /* count of full rsr_messages */ USHORT rsr_reorder_level; /* Trigger pipelining at this level */ USHORT rsr_batch_count; /* Count of batches in pipeline */ + +public: + enum { + FETCHED = 1, // Cleared by execute, set by fetch + EOF_SET = 2, // End-of-stream encountered + BLOB = 4, // Statement relates to blob op + NO_BATCH = 8, // Do not batch fetch rows + STREAM_ERR = 16, // There is an error pending in the batched rows + LAZY = 32, // To be allocated at the first reference + DEFER_EXECUTE = 64, // op_execute can be deferred + PAST_EOF = 128, // EOF was returned by fetch from this statement + }; + +public: + Rsr() : + rsr_next(0), rsr_rdb(0), rsr_rtr(0), rsr_handle(0), + rsr_bind_format(0), rsr_select_format(0), rsr_user_select_format(0), + rsr_format(0), rsr_message(0), rsr_buffer(0), rsr_status(0), + rsr_id(0), rsr_flags(0), rsr_fmt_length(0), + rsr_rows_pending(0), rsr_msgs_waiting(0), rsr_reorder_level(0), rsr_batch_count(0) + { } + + static ISC_STATUS badHandle() { return isc_bad_req_handle; } } *RSR; -// rsr_flags -const USHORT RSR_fetched = 1; /* Cleared by execute, set by fetch */ -const USHORT RSR_eof = 2; /* End-of-stream encountered */ -const USHORT RSR_blob = 4; /* Statement relates to blob op */ -const USHORT RSR_no_batch = 8; /* Do not batch fetch rows */ -const USHORT RSR_stream_err = 16; /* There is an error pending in the batched rows */ -const USHORT RSR_lazy = 32; /* To be allocated at the first reference */ -const USHORT RSR_defer_execute = 64; // op_execute can be deferred -const USHORT RSR_past_eof = 128; // EOF was returned by fetch from this statement + +// Makes it possible to safely store all handles in single array +class RemoteObject +{ +private: + union { + Rdb* rdb; + Rtr* rtr; + Rbl* rbl; + Rrq* rrq; + Rsr* rsr; + } ptr; + +public: + template + R* get(R* r) + { + if (! r->checkHandle()) + { + Firebird::status_exception::raise(R::badHandle(), isc_arg_end); + } + return r; + } + +public: + void operator=(Rdb* v) { ptr.rdb = v; } + void operator=(Rtr* v) { ptr.rtr = v; } + void operator=(Rbl* v) { ptr.rbl = v; } + void operator=(Rrq* v) { ptr.rrq = v; } + void operator=(Rsr* v) { ptr.rsr = v; } + +public: + operator Rdb*() { return get(ptr.rdb); } + operator Rtr*() { return get(ptr.rtr); } + operator Rbl*() { return get(ptr.rbl); } + operator Rrq*() { return get(ptr.rrq); } + operator Rsr*() { return get(ptr.rsr); } + + bool isMissing() { return ptr.rdb == NULL; } + void release() { ptr.rdb = 0; } +}; + + // will be methods of remote statement class inline void stmt_save_exception(RSR statement, const ISC_STATUS* status, bool overwrite) @@ -339,47 +459,11 @@ inline void stmt_release_exception(RSR statement) } } -enum blk_t -{ - type_MIN = 0, - type_vec, - type_rdb, - type_fmt, - type_rrq, - type_rtr, - type_str, - type_rbl, - type_port, - type_msg, - type_rsr, - type_rvnt, - type_rpr, - type_rmtque, - type_MAX -}; - - #include "../remote/xdr.h" /* Generalized port definition. */ -enum rem_port_t -{ - port_inet, /* Internet (TCP/IP) */ - port_pipe, /* Windows NT named pipe connection */ - port_xnet /* Windows NT shared memory connection */ -}; - -enum state_t -{ - state_closed, /* no connection */ - state_pending, /* connection is pending */ - state_broken, /* connection is broken */ - state_disconnected /* port is disconnected */ -}; - - #ifndef WIN_NT typedef int HANDLE; #endif /* WIN_NT */ @@ -402,7 +486,7 @@ typedef Firebird::Array PacketQueue; #ifdef TRUSTED_AUTH // delayed authentication block for trusted auth callback -class ServerAuth +class ServerAuth : public Firebird::GlobalStorage { public: typedef void Part2(rem_port*, P_OP, const char* fName, int fLen, const UCHAR* pb, int pbLen, PACKET*); @@ -417,6 +501,20 @@ public: }; #endif // TRUSTED_AUTH + +// port_flags +const USHORT PORT_symmetric = 0x0001; // Server/client archiectures are symmetic +const USHORT PORT_rpc = 0x0002; // Protocol is remote procedure call +const USHORT PORT_async = 0x0004; // Port is asynchronous channel for events +const USHORT PORT_no_oob = 0x0008; // Don't send out of band data +const USHORT PORT_disconnect = 0x0010; // Disconnect is in progress +// This is set only in inet.cpp but never tested +const USHORT PORT_not_trusted = 0x0020; // Connection is from an untrusted node +const USHORT PORT_dummy_pckt_set= 0x0040; // A dummy packet interval is set +const USHORT PORT_partial_data = 0x0080; // Physical packet doesn't contain all API packet +const USHORT PORT_lazy = 0x0100; // Deferred operations are allowed +const USHORT PORT_server = 0x0200; // Server (not client) port + /* Port itself */ class port_interface @@ -429,11 +527,30 @@ public: typedef void (*t_event_ast)(rem_port*); typedef rem_port* (*t_port_connect)(rem_port*, PACKET*, t_event_ast); -struct rem_port +struct rem_port : public Firebird::GlobalStorage { - blk port_header; - enum rem_port_t port_type; /* type of port */ - enum state_t port_state; /* state of port */ + /* port function pointers (C "emulation" of virtual functions) */ + int (*port_accept)(rem_port*, p_cnct*); + void (*port_disconnect)(rem_port*); + rem_port* (*port_receive_packet)(rem_port*, PACKET*); + XDR_INT (*port_send_packet)(rem_port*, PACKET*); + XDR_INT (*port_send_partial)(rem_port*, PACKET*); + t_port_connect port_connect; /* Establish secondary connection */ + rem_port* (*port_request)(rem_port*, PACKET*); /* Request to establish secondary connection */ + rem_port* (*port_select_multi)(rem_port*, UCHAR*, SSHORT, SSHORT*); // get packet from active port + + enum rem_port_t { + INET, /* Internet (TCP/IP) */ + PIPE, /* Windows NT named pipe connection */ + XNET /* Windows NT shared memory connection */ + } port_type; + enum state_t { + CLOSED, /* no connection */ + PENDING, /* connection is pending */ + BROKEN, /* connection is broken */ + DISCONNECTED /* port is disconnected */ + } port_state; + P_ARCH port_client_arch; /* so we can tell arch of client */ rem_port* port_clients; /* client ports */ rem_port* port_next; /* next client port */ @@ -451,26 +568,14 @@ struct rem_port HANDLE port_handle; /* handle for connection (from by OS) */ int port_channel; /* handle for connection (from by OS) */ struct linger port_linger; /* linger value as defined by SO_LINGER */ - - /* port function pointers (C "emulation" of virtual functions) */ - int (*port_accept)(rem_port*, p_cnct*); - void (*port_disconnect)(rem_port*); - rem_port* (*port_receive_packet)(rem_port*, PACKET*); - XDR_INT (*port_send_packet)(rem_port*, PACKET*); - XDR_INT (*port_send_partial)(rem_port*, PACKET*); - t_port_connect port_connect; /* Establish secondary connection */ - rem_port* (*port_request)(rem_port*, PACKET*); /* Request to establish secondary connection */ - rem_port* (*port_select_multi)(rem_port*, UCHAR*, SSHORT, SSHORT*); // get packet from active port - - rdb* port_context; + Rdb* port_context; t_event_ast port_ast; /* AST for events */ XDR port_receive; XDR port_send; #ifdef DEBUG_XDR_MEMORY - rem_vec* port_packet_vector; /* Vector of send/receive packets */ + r e m _ v e c* port_packet_vector; /* Vector of send/receive packets */ #endif - rem_vec* port_object_vector; - BLK* port_objects; + Firebird::Array port_objects; rem_str* port_version; rem_str* port_host; /* Our name */ rem_str* port_connection; /* Name of connection */ @@ -479,23 +584,155 @@ struct rem_port rem_str* port_protocol_str; // String containing protocol name for this port rem_str* port_address_str; // Protocol-specific address string for the port rpr* port_rpr; /* port stored procedure reference */ - rsr* port_statement; /* Statement for execute immediate */ + Rsr* port_statement; /* Statement for execute immediate */ rmtque* port_receive_rmtque; /* for client, responses waiting */ USHORT port_requests_queued; /* requests currently queued */ void* port_xcc; /* interprocess structure */ PacketQueue* port_deferred_packets; /* queue of deferred packets */ OBJCT port_last_object_id; /* cached last id */ #ifdef REM_SERVER - Firebird::ObjectsArray< Firebird::Array >* port_queue; + Firebird::ObjectsArray< Firebird::Array > port_queue; size_t port_qoffset; // current packet in the queue - Firebird::RefMutex* port_que_sync; + Firebird::RefMutex* const port_que_sync; #endif #ifdef TRUSTED_AUTH ServerAuth* port_trusted_auth; #endif - Firebird::RefMutex* port_sync; - UCHAR port_buffer[1]; + Firebird::RefMutex* const port_sync; + UCharArrayAutoPtr port_buffer; +public: + rem_port(rem_port_t t, size_t rpt) : + port_accept(0), port_disconnect(0), port_receive_packet(0), port_send_packet(0), + port_send_partial(0), port_connect(0), port_request(0), port_select_multi(0), + port_type(t), port_state(PENDING), + port_client_arch(arch_generic), port_clients(0), port_next(0), port_parent(0), port_async(0), + port_server(0), port_server_flags(0), port_protocol(0), port_buff_size(0), + port_flags(0), port_connect_timeout(0), port_dummy_packet_interval(0), + port_dummy_timeout(0), port_status_vector(0), port_handle(0), port_channel(0), + port_context(0), port_ast(0), +#ifdef DEBUG_XDR_MEMORY + port_packet_vector(0), +#endif + port_objects(getPool()), port_version(0), port_host(0), + port_connection(0), port_user_name(0), port_passwd(0), port_protocol_str(0), + port_address_str(0), port_rpr(0), port_statement(0), port_receive_rmtque(0), + port_requests_queued(0), port_xcc(0), port_deferred_packets(0), port_last_object_id(0), +#ifdef REM_SERVER + port_queue(getPool()), port_qoffset(0), + port_que_sync(FB_NEW(getPool()) Firebird::RefMutex()), +#endif +#ifdef TRUSTED_AUTH + port_trusted_auth(0), +#endif + port_sync(FB_NEW(getPool()) Firebird::RefMutex()), + port_buffer(FB_NEW(getPool()) UCHAR[rpt]) + { + memset (port_buffer, 0, rpt); + port_sync->addRef(); +#ifdef REM_SERVER + port_que_sync->addRef(); +#endif + } + + ~rem_port() + { + delete port_version; + delete port_connection; + delete port_user_name; + delete port_host; + delete port_protocol_str; + delete port_address_str; + +#ifdef DEBUG_XDR_MEMORY + delete port_packet_vector; +#endif + +#ifdef REM_SERVER + port_que_sync->release(); +#endif + +#ifdef TRUSTED_AUTH + delete port_trusted_auth; +#endif + + port_sync->release(); + } + + void linkParent(rem_port* parent) + { + port_parent = parent; + port_next = parent->port_clients; + port_handle = parent->port_handle; + port_server = parent->port_server; + port_server_flags = parent->port_server_flags; + + parent->port_clients = parent->port_next = this; + } + + template + void getHandle(T*& blk, OBJCT id) + { + if ((port_flags & PORT_lazy) && (id == INVALID_OBJECT)) + { + id = port_last_object_id; + } + if (id >= port_objects.getCount() || port_objects[id].isMissing()) + { + Firebird::status_exception::raise(T::badHandle(), isc_arg_end); + } + blk = port_objects[id]; + } + + template + OBJCT setHandle(T* const object, const OBJCT id) + { + if (id >= port_objects.getCount()) + { + /* Prevent the creation of object handles that can't be + transferred by the remote protocol. */ + if (id > MAX_OBJCT_HANDLES) + { + return (OBJCT)0; + } + + port_objects.grow(id + 1); + } + + port_objects[id] = object; + return id; + } + + // Allocate an object slot for an object. + template + OBJCT get_id(T* object) + { + // Reserve slot 0 so we can distinguish something from nothing. + // NOTE: prior to server version 4.5.0 id==0 COULD be used - so + // only the server side can now depend on id==0 meaning "invalid id" + unsigned int i = 1; + for (; i < port_objects.getCount(); ++i) + { + if (port_objects[i].isMissing()) + { + break; + } + } + + port_last_object_id = setHandle(object, static_cast(i)); + return port_last_object_id; + } + + void releaseObject(OBJCT id) + { + if (id != INVALID_OBJECT) + { + port_objects[id].release(); + } + } + + +public: /* TMN: Beginning of C++ port */ /* TMN: ugly, but at least a start */ int accept(p_cnct* cnct); @@ -511,15 +748,13 @@ struct rem_port bool haveRecvData() const { Firebird::RefMutexGuard queGuard(*port_que_sync); - return (port_receive.x_handy > 0 || - port_queue && (port_qoffset < port_queue->getCount())); + return ((port_receive.x_handy > 0) || (port_qoffset < port_queue.getCount())); } void clearRecvQue() { Firebird::RefMutexGuard queGuard(*port_que_sync); - if (port_queue) - port_queue->clear(); + port_queue.clear(); port_qoffset = 0; port_receive.x_private = port_receive.x_base; } @@ -548,7 +783,7 @@ struct rem_port { if (rs.save_qoffset > 0 && (rs.save_qoffset != port_qoffset)) { - Firebird::Array& q = (*port_queue)[rs.save_qoffset - 1]; + Firebird::Array& q = port_queue[rs.save_qoffset - 1]; memcpy(port_receive.x_base, q.begin(), q.getCount()); } port_qoffset = rs.save_qoffset; @@ -575,7 +810,6 @@ struct rem_port ISC_STATUS execute_statement(P_OP, P_SQLDATA*, PACKET*); ISC_STATUS fetch(P_SQLDATA*, PACKET*); ISC_STATUS fetch_blob(P_SQLDATA*, PACKET*); - OBJCT get_id(BLK); ISC_STATUS get_segment(P_SGMT*, PACKET*); ISC_STATUS get_slice(P_SLC*, PACKET*); ISC_STATUS info(P_OP, P_INFO*, PACKET*); @@ -601,34 +835,26 @@ struct rem_port ISC_STATUS transact_request(P_TRRQ *, PACKET*); }; -// port_flags -const USHORT PORT_symmetric = 0x0001; // Server/client archiectures are symmetic -const USHORT PORT_rpc = 0x0002; // Protocol is remote procedure call -const USHORT PORT_async = 0x0004; // Port is asynchronous channel for events -const USHORT PORT_no_oob = 0x0008; // Don't send out of band data -const USHORT PORT_disconnect = 0x0010; // Disconnect is in progress -// This is set only in inet.cpp but never tested -const USHORT PORT_not_trusted = 0x0020; // Connection is from an untrusted node -const USHORT PORT_dummy_pckt_set= 0x0040; // A dummy packet interval is set -const USHORT PORT_partial_data = 0x0080; // Physical packet doesn't contain all API packet -const USHORT PORT_lazy = 0x0100; // Deferred operations are allowed -const USHORT PORT_server = 0x0200; // Server (not client) port /* Queuing structure for Client batch fetches */ typedef bool (*t_rmtque_fn)(rem_port*, rmtque*, ISC_STATUS*, USHORT); -typedef struct rmtque +typedef struct rmtque : public Firebird::GlobalStorage { - blk rmtque_header; // Memory allocator header rmtque* rmtque_next; // Next entry in queue void* rmtque_parm; // What request has response in queue - rrq::rrq_repeat* rmtque_message; // What message is pending - rdb* rmtque_rdb; // What database has pending msg + Rrq::rrq_repeat* rmtque_message; // What message is pending + Rdb* rmtque_rdb; // What database has pending msg /* Fn that receives queued entry */ t_rmtque_fn rmtque_function; + +public: + rmtque() : + rmtque_next(0), rmtque_parm(0), rmtque_message(0), rmtque_rdb(0), rmtque_function(0) + { } } *RMTQUE; #endif // REMOTE_REMOTE_H diff --git a/src/remote/server.cpp b/src/remote/server.cpp index 241179eed6..f4eeb093d4 100644 --- a/src/remote/server.cpp +++ b/src/remote/server.cpp @@ -64,52 +64,6 @@ #include "../remote/proto_proto.h" // xdr_protocol_overhead() #include "../jrd/scroll_cursors.h" -/** CHECK_HANDLE checks - - if the id passwd is within the vector bounds, - that the port_object corresponding to the id is not null, - if the port_object's type matches with the expected type -**/ - -#pragma FB_COMPILER_MESSAGE("What kind of crap is this?! FIX!") - -#define CHECK_HANDLE(blk, cast, type, id, err) \ - { \ - if ((port->port_flags & PORT_lazy) && id == INVALID_OBJECT) \ - { \ - id = port->port_last_object_id; \ - } \ - if (!port->port_objects || \ - id >= port->port_object_vector->vec_count || \ - !(blk = (cast) port->port_objects [id]) || \ - ((BLK) blk)->blk_type != (UCHAR) type) \ - { \ - status_vector [0] = isc_arg_gds; \ - status_vector [1] = err; \ - status_vector [2] = isc_arg_end; \ - return port->send_response(send, 0, 0, status_vector, \ - false); \ - } \ - } - -#define CHECK_HANDLE_MEMBER(blk, cast, type, id, err) \ - { \ - if ((this->port_flags & PORT_lazy) && id == INVALID_OBJECT) \ - { \ - id = this->port_last_object_id; \ - } \ - if (!this->port_objects || \ - id >= this->port_object_vector->vec_count || \ - !(blk = (cast) this->port_objects [id]) || \ - ((BLK) blk)->blk_type != (UCHAR) type) \ - { \ - status_vector [0] = isc_arg_gds; \ - status_vector [1] = err; \ - status_vector [2] = isc_arg_end; \ - return this->send_response(sendL, 0, 0, status_vector, \ - false); \ - } \ - } - typedef struct server_req_t { @@ -120,12 +74,18 @@ typedef struct server_req_t PACKET req_receive; } *SERVER_REQ; -typedef struct srvr +typedef struct srvr : public Firebird::GlobalStorage { struct srvr* srvr_next; rem_port* srvr_parent_port; - enum rem_port_t srvr_port_type; + rem_port::rem_port_t srvr_port_type; USHORT srvr_flags; + +public: + srvr(srvr *servers, rem_port* port, USHORT flags) : + srvr_next(servers), srvr_parent_port(port), + srvr_port_type(port->port_type), srvr_flags(flags) + { } } *SRVR; namespace { @@ -168,14 +128,14 @@ static void addClumplets(Firebird::ClumpletWriter&, const ParametersSet&, const static void cancel_operation(rem_port*); #endif -static bool check_request(rrq*, USHORT, USHORT); +static bool check_request(Rrq*, USHORT, USHORT); static USHORT check_statement_type(RSR); #ifdef SCROLLABLE_CURSORS -static REM_MSG dump_cache(rrq::rrq_repeat*); +static REM_MSG dump_cache(Rrq::rrq_repeat*); #endif -static bool get_next_msg_no(rrq*, USHORT, USHORT*); +static bool get_next_msg_no(Rrq*, USHORT, USHORT*); static RTR make_transaction(RDB, FB_API_HANDLE); static bool process_packet(rem_port* port, PACKET* sendL, @@ -183,13 +143,13 @@ static bool process_packet(rem_port* port, rem_port** result); static void release_blob(RBL); static void release_event(RVNT); -static void release_request(rrq*); +static void release_request(Rrq*); static void release_statement(RSR*); static void release_sql_request(RSR); static void release_transaction(RTR); #ifdef SCROLLABLE_CURSORS -static REM_MSG scroll_cache(rrq::rrq_repeat*, USHORT *, ULONG *); +static REM_MSG scroll_cache(Rrq::rrq_repeat*, USHORT *, ULONG *); #endif static void server_ast(void*, USHORT, const UCHAR*); @@ -535,7 +495,7 @@ void SRVR_multi_thread( rem_port* main_port, USHORT flags) if (dataSize) { Firebird::RefMutexGuard queGuard(*port->port_que_sync); - memcpy(port->port_queue->add().getBuffer(dataSize), buffer, dataSize); + memcpy(port->port_queue.add().getBuffer(dataSize), buffer, dataSize); } Firebird::RefMutexEnsureUnlock portGuard(*port->port_sync); @@ -754,7 +714,7 @@ static bool accept_connection(rem_port* port, Firebird::string buffer; buffer.printf("%s/P%d", port->port_version->str_data, port->port_protocol & FB_PROTOCOL_MASK); - ALLR_free(port->port_version); + delete port->port_version; port->port_version = REMOTE_make_string(buffer.c_str()); if (architecture == ARCHITECTURE) @@ -806,10 +766,10 @@ static ISC_STATUS allocate_statement( rem_port* port, P_RLSE * allocate, PACKET* else { /* Allocate SQL request block */ - RSR statement = (RSR) ALLR_block(type_rsr, 0); + RSR statement = new Rsr; statement->rsr_rdb = rdb; statement->rsr_handle = handle; - if (statement->rsr_id = port->get_id(&statement->rsr_header)) + if (statement->rsr_id = port->get_id(statement)) { object = statement->rsr_id; statement->rsr_next = rdb->rdb_sql_requests; @@ -818,7 +778,7 @@ static ISC_STATUS allocate_statement( rem_port* port, P_RLSE * allocate, PACKET* else { object = 0; GDS_DSQL_FREE(status_vector, &statement->rsr_handle, DSQL_drop); - ALLR_free(statement); + delete statement; status_vector[0] = isc_arg_gds; status_vector[1] = isc_too_many_handles; status_vector[2] = isc_arg_end; @@ -1086,7 +1046,7 @@ static void attach_database2(rem_port* port, if (!status_vector[1]) { - RDB rdb = (RDB) ALLR_block(type_rdb, 0); + RDB rdb = new Rdb; if (rdb) { port->port_context = rdb; @@ -1272,7 +1232,7 @@ static void cancel_operation( rem_port* port) if (rdb->rdb_handle) { - if (!(rdb->rdb_flags & RDB_service)) + if (!(rdb->rdb_flags & Rdb::SERVICE)) { ISC_STATUS_ARRAY status_vector; gds__cancel_operation(status_vector, (FB_API_HANDLE*) &rdb->rdb_handle, @@ -1283,7 +1243,7 @@ static void cancel_operation( rem_port* port) #endif -static bool check_request(rrq* request, +static bool check_request(Rrq* request, USHORT incarnation, USHORT msg_number) { @@ -1406,7 +1366,7 @@ ISC_STATUS rem_port::compile(P_CMPL* compileL, PACKET* sendL) /* Allocate block and merge into data structures */ - rrq* requestL = (rrq*) ALLR_block(type_rrq, max_msg + 1); + Rrq* requestL = new Rrq(max_msg + 1); #ifdef DEBUG_REMOTE_MEMORY printf("compile(server) allocate request %x\n", request); #endif @@ -1415,7 +1375,7 @@ ISC_STATUS rem_port::compile(P_CMPL* compileL, PACKET* sendL) requestL->rrq_max_msg = max_msg; OBJCT object = 0; - if (requestL->rrq_id = this->get_id(&requestL->rrq_header)) + if (requestL->rrq_id = this->get_id(requestL)) { object = requestL->rrq_id; requestL->rrq_next = rdb->rdb_requests; @@ -1423,7 +1383,7 @@ ISC_STATUS rem_port::compile(P_CMPL* compileL, PACKET* sendL) } else { isc_release_request(status_vector, &requestL->rrq_handle); - ALLR_free(requestL); + delete requestL; status_vector[0] = isc_arg_gds; status_vector[1] = isc_too_many_handles; status_vector[2] = isc_arg_end; @@ -1437,7 +1397,7 @@ ISC_STATUS rem_port::compile(P_CMPL* compileL, PACKET* sendL) message->msg_prior = message; #endif - rrq::rrq_repeat* tail = requestL->rrq_rpt + message->msg_number; + Rrq::rrq_repeat* tail = &requestL->rrq_rpt[message->msg_number]; tail->rrq_message = message; tail->rrq_xdr = message; tail->rrq_format = (rem_fmt*) message->msg_address; @@ -1465,11 +1425,7 @@ ISC_STATUS rem_port::ddl(P_DDL* ddlL, PACKET* sendL) ISC_STATUS_ARRAY status_vector; RTR transaction; - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - ddlL->p_ddl_transaction, - isc_bad_trans_handle); + getHandle(transaction, ddlL->p_ddl_transaction); RDB rdb = this->port_context; if (bad_db(status_vector, rdb)) @@ -1529,7 +1485,7 @@ void rem_port::disconnect(PACKET* sendL, PACKET* receiveL) PACKET *packet = &rdb->rdb_packet; if ((this->port_async) && - ((this->port_type == port_xnet) || (this->port_type == port_pipe))) + ((this->port_type == rem_port::XNET) || (this->port_type == rem_port::PIPE))) { packet->p_operation = op_disconnect; this->port_async->send(packet); @@ -1538,7 +1494,7 @@ void rem_port::disconnect(PACKET* sendL, PACKET* receiveL) ISC_STATUS_ARRAY status_vector; if (rdb->rdb_handle) - if (!(rdb->rdb_flags & RDB_service)) { + if (!(rdb->rdb_flags & Rdb::SERVICE)) { #ifdef CANCEL_OPERATION /* Prevent a pending or spurious cancel from aborting a good, clean detach from the database. */ @@ -1586,23 +1542,14 @@ void rem_port::disconnect(PACKET* sendL, PACKET* receiveL) this->port_context = NULL; if (this->port_async) this->port_async->port_context = NULL; - ALLR_free(rdb); - if (this->port_object_vector) - { -#ifdef DEBUG_REMOTE_MEMORY - printf("disconnect(server) free vector %x\n", - this->port_object_vector); -#endif - ALLR_free(this->port_object_vector); - this->port_object_vector = NULL; - } + delete rdb; if (this->port_connection) { #ifdef DEBUG_REMOTE_MEMORY printf("disconnect(server) free string %x\n", this->port_connection); #endif - ALLR_free(this->port_connection); + delete this->port_connection; this->port_connection = NULL; } if (this->port_version) @@ -1611,7 +1558,7 @@ void rem_port::disconnect(PACKET* sendL, PACKET* receiveL) printf("disconnect(server) free string %x\n", this->port_version); #endif - ALLR_free(this->port_version); + delete this->port_version; this->port_version = NULL; } if (this->port_passwd) @@ -1620,7 +1567,7 @@ void rem_port::disconnect(PACKET* sendL, PACKET* receiveL) printf("disconnect(server) free string %x\n", this->port_passwd); #endif - ALLR_free(this->port_passwd); + delete this->port_passwd; this->port_passwd = NULL; } if (this->port_user_name) @@ -1629,7 +1576,7 @@ void rem_port::disconnect(PACKET* sendL, PACKET* receiveL) printf("disconnect(server) free string %x\n", this->port_user_name); #endif - ALLR_free(this->port_user_name); + delete this->port_user_name; this->port_user_name = NULL; } if (this->port_host) @@ -1638,7 +1585,7 @@ void rem_port::disconnect(PACKET* sendL, PACKET* receiveL) printf("disconnect(server) free string %x\n", this->port_host); #endif - ALLR_free(this->port_host); + delete this->port_host; this->port_host = NULL; } this->disconnect(); @@ -1695,7 +1642,7 @@ void rem_port::drop_database(P_RLSE* release, PACKET* sendL) #ifdef SCROLLABLE_CURSORS -static REM_MSG dump_cache( rrq::rrq_repeat* tail) +static REM_MSG dump_cache( Rrq::rrq_repeat* tail) { /************************************** * @@ -1739,11 +1686,7 @@ ISC_STATUS rem_port::end_blob(P_OP operation, P_RLSE * release, PACKET* sendL) RBL blob; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(blob, - RBL, - type_rbl, - release->p_rlse_object, - isc_bad_segstr_handle); + getHandle(blob, release->p_rlse_object); if (operation == op_close_blob) isc_close_blob(status_vector, &blob->rbl_handle); @@ -1814,14 +1757,10 @@ ISC_STATUS rem_port::end_request(P_RLSE * release, PACKET* sendL) * End a request. * **************************************/ - rrq* requestL; + Rrq* requestL; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(requestL, - rrq*, - type_rrq, - release->p_rlse_object, - isc_bad_req_handle); + getHandle(requestL, release->p_rlse_object); isc_release_request(status_vector, &requestL->rrq_handle); @@ -1847,11 +1786,7 @@ ISC_STATUS rem_port::end_statement(P_SQLFREE* free_stmt, PACKET* sendL) RSR statement; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(statement, - RSR, - type_rsr, - free_stmt->p_sqlfree_statement, - isc_bad_req_handle); + getHandle(statement, free_stmt->p_sqlfree_statement); GDS_DSQL_FREE(status_vector, &statement->rsr_handle, @@ -1865,7 +1800,7 @@ ISC_STATUS rem_port::end_statement(P_SQLFREE* free_stmt, PACKET* sendL) statement = NULL; } else { - statement->rsr_flags &= ~RSR_fetched; + statement->rsr_flags &= ~Rsr::FETCHED; statement->rsr_rtr = NULL; REMOTE_reset_statement(statement); statement->rsr_message = statement->rsr_buffer; @@ -1892,11 +1827,7 @@ ISC_STATUS rem_port::end_transaction(P_OP operation, P_RLSE * release, PACKET* s RTR transaction; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - release->p_rlse_object, - isc_bad_trans_handle); + getHandle(transaction, release->p_rlse_object); switch (operation) { @@ -1956,12 +1887,8 @@ ISC_STATUS rem_port::execute_immediate(P_OP op, P_SQLST * exnow, PACKET* sendL) } /** Do not call CHECK_HANDLE if this is the start of a transaction **/ - if (this->port_objects && exnow->p_sqlst_transaction) { - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - exnow->p_sqlst_transaction, - isc_bad_trans_handle); + if (exnow->p_sqlst_transaction) { + getHandle(transaction, exnow->p_sqlst_transaction); } USHORT in_msg_length = 0, out_msg_length = 0; @@ -2098,19 +2025,11 @@ ISC_STATUS rem_port::execute_statement(P_OP op, P_SQLDATA* sqldata, PACKET* send /** Do not call CHECK_HANDLE if this is the start of a transaction **/ if (sqldata->p_sqldata_transaction) { - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - sqldata->p_sqldata_transaction, - isc_bad_trans_handle); + getHandle(transaction, sqldata->p_sqldata_transaction); } RSR statement; - CHECK_HANDLE_MEMBER(statement, - RSR, - type_rsr, - sqldata->p_sqldata_statement, - isc_bad_req_handle); + getHandle(statement, sqldata->p_sqldata_statement); USHORT in_msg_length = 0, out_msg_length = 0; UCHAR* in_msg = NULL; @@ -2141,7 +2060,7 @@ ISC_STATUS rem_port::execute_statement(P_OP op, P_SQLDATA* sqldata, PACKET* send out_msg_type = 0; out_blr = NULL; } - statement->rsr_flags &= ~RSR_fetched; + statement->rsr_flags &= ~Rsr::FETCHED; FB_API_HANDLE handle = (transaction) ? transaction->rtr_handle : 0; @@ -2212,13 +2131,9 @@ ISC_STATUS rem_port::fetch(P_SQLDATA * sqldata, PACKET* sendL) RSR statement; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(statement, - RSR, - type_rsr, - sqldata->p_sqldata_statement, - isc_bad_req_handle); + getHandle(statement, sqldata->p_sqldata_statement); - if (statement->rsr_flags & RSR_blob) { + if (statement->rsr_flags & Rsr::BLOB) { return this->fetch_blob(sqldata, sendL); } @@ -2230,14 +2145,14 @@ ISC_STATUS rem_port::fetch(P_SQLDATA * sqldata, PACKET* sendL) msg_length = 0; } USHORT count = ((this->port_flags & PORT_rpc) || - (statement->rsr_flags & RSR_no_batch)) ? 1 : + (statement->rsr_flags & Rsr::NO_BATCH)) ? 1 : sqldata->p_sqldata_messages; - USHORT count2 = (statement->rsr_flags & RSR_no_batch) ? 0 : count; + USHORT count2 = (statement->rsr_flags & Rsr::NO_BATCH) ? 0 : count; /* On first fetch, clear the end-of-stream flag & reset the message buffers */ - if (!(statement->rsr_flags & RSR_fetched)) { - statement->rsr_flags &= ~(RSR_eof | RSR_stream_err); + if (!(statement->rsr_flags & Rsr::FETCHED)) { + statement->rsr_flags &= ~(Rsr::EOF_SET | Rsr::STREAM_ERR); stmt_clear_exception(statement); REM_MSG message = statement->rsr_message; if (message != NULL) { @@ -2266,19 +2181,19 @@ ISC_STATUS rem_port::fetch(P_SQLDATA * sqldata, PACKET* sendL) while (true) { /* Have we exhausted the cache & reached cursor EOF? */ - if ((statement->rsr_flags & RSR_eof) && !statement->rsr_msgs_waiting) { - statement->rsr_flags &= ~RSR_eof; + if ((statement->rsr_flags & Rsr::EOF_SET) && !statement->rsr_msgs_waiting) { + statement->rsr_flags &= ~Rsr::EOF_SET; s = 100; count2 = 0; break; } /* Have we exhausted the cache & have a pending error? */ - if ((statement->rsr_flags & RSR_stream_err) + if ((statement->rsr_flags & Rsr::STREAM_ERR) && !statement->rsr_msgs_waiting) { fb_assert(statement->rsr_status); - statement->rsr_flags &= ~RSR_stream_err; + statement->rsr_flags &= ~Rsr::STREAM_ERR; return this->send_response(sendL, 0, 0, statement->rsr_status->value(), false); @@ -2302,9 +2217,9 @@ ISC_STATUS rem_port::fetch(P_SQLDATA * sqldata, PACKET* sendL) reinterpret_cast(sqldata->p_sqldata_blr.cstr_address), sqldata->p_sqldata_message_number, msg_length, - reinterpret_cast(message->msg_buffer)); + reinterpret_cast(message->msg_buffer.operator UCHAR*())); - statement->rsr_flags |= RSR_fetched; + statement->rsr_flags |= Rsr::FETCHED; if (s) { if (s == 100 || s == 101) { @@ -2377,7 +2292,7 @@ ISC_STATUS rem_port::fetch(P_SQLDATA * sqldata, PACKET* sendL) while (next->msg_next != message) next = next->msg_next; } - message = (REM_MSG) ALLR_block(type_msg, statement->rsr_fmt_length); + message = new Message(statement->rsr_fmt_length); message->msg_number = next->msg_number; message->msg_next = next->msg_next; next->msg_next = message; @@ -2389,18 +2304,18 @@ ISC_STATUS rem_port::fetch(P_SQLDATA * sqldata, PACKET* sendL) reinterpret_cast(sqldata->p_sqldata_blr.cstr_address), sqldata->p_sqldata_message_number, msg_length, - reinterpret_cast(message->msg_buffer)); + reinterpret_cast(message->msg_buffer.operator UCHAR*())); if (s) { if (status_vector[1]) { /* If already have an error queued, don't overwrite it */ - if (!(statement->rsr_flags & RSR_stream_err)) { - statement->rsr_flags |= RSR_stream_err; + if (!(statement->rsr_flags & Rsr::STREAM_ERR)) { + statement->rsr_flags |= Rsr::STREAM_ERR; stmt_save_exception(statement, status_vector, true); } } if (s == 100) - statement->rsr_flags |= RSR_eof; + statement->rsr_flags |= Rsr::EOF_SET; break; } message->msg_address = message->msg_buffer; @@ -2427,11 +2342,7 @@ ISC_STATUS rem_port::fetch_blob(P_SQLDATA * sqldata, PACKET* sendL) RSR statement; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(statement, - RSR, - type_rsr, - sqldata->p_sqldata_statement, - isc_bad_req_handle); + getHandle(statement, sqldata->p_sqldata_statement); USHORT msg_length; if (statement->rsr_format) @@ -2459,7 +2370,7 @@ ISC_STATUS rem_port::fetch_blob(P_SQLDATA * sqldata, PACKET* sendL) reinterpret_cast(sqldata->p_sqldata_blr.cstr_address), sqldata->p_sqldata_message_number, msg_length, - reinterpret_cast(message->msg_buffer)); + reinterpret_cast(message->msg_buffer.operator UCHAR*())); if (!status_vector[1] || status_vector[1] != isc_segment || status_vector[1] != isc_segstr_eof) @@ -2476,55 +2387,7 @@ ISC_STATUS rem_port::fetch_blob(P_SQLDATA * sqldata, PACKET* sendL) } -OBJCT rem_port::get_id(BLK block) -{ -/************************************** - * - * g e t _ i d - * - ************************************** - * - * Functional description - * Allocate an object slot for an object. - * If the object vector cannot be expanded - * to accomodate the object slot then - * REMOTE_set_object() will return a NULL - * object slot. - * - **************************************/ - -/* If there isn't a vector, obvious the object goes in slot 1. - Reserve slot 0 so we can distinguish something from nothing. - NOTE: prior to server version 4.5.0 id==0 COULD be used - so - only the server side can now depend on id==0 meaning "invalid id" */ - - rem_vec* vector = this->port_object_vector; - if (!vector) { - return (this->port_last_object_id = - REMOTE_set_object(this, block, (OBJCT) 1)); - } - - // Search vector for an empty slot. If we find one, use it - - blk** p = vector->vec_object + 1; - for (const blk* const* const end = vector->vec_object + vector->vec_count; - p < end; p++) - { - if (!*p) { - *p = block; - this->port_last_object_id = (OBJCT) (p - vector->vec_object); - return this->port_last_object_id; - } - } - -/* Vector is full -- somebody will need to expand it */ - - return (this->port_last_object_id = - REMOTE_set_object(this, block, (OBJCT) vector->vec_count)); -} - - -static bool get_next_msg_no(rrq* request, +static bool get_next_msg_no(Rrq* request, USHORT incarnation, USHORT * msg_number) { @@ -2590,11 +2453,7 @@ ISC_STATUS rem_port::get_segment(P_SGMT* segment, PACKET* sendL) RBL blob; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(blob, - RBL, - type_rbl, - segment->p_sgmt_blob, - isc_bad_segstr_handle); + getHandle(blob, segment->p_sgmt_blob); UCHAR temp_buffer[BLOB_LENGTH]; USHORT buffer_length = segment->p_sgmt_length; @@ -2604,12 +2463,7 @@ ISC_STATUS rem_port::get_segment(P_SGMT* segment, PACKET* sendL) else { if (buffer_length > blob->rbl_buffer_length) { - if (blob->rbl_buffer != blob->rbl_data) { - ALLR_free(blob->rbl_buffer); - blob->rbl_buffer = blob->rbl_data; - blob->rbl_buffer_length = 1; - } - blob->rbl_buffer = ALLR_alloc((SLONG) buffer_length); + blob->rbl_buffer = blob->rbl_data.getBuffer(buffer_length); blob->rbl_buffer_length = buffer_length; } buffer = blob->rbl_buffer; @@ -2634,12 +2488,6 @@ ISC_STATUS rem_port::get_segment(P_SGMT* segment, PACKET* sendL) #ifdef DEBUG_REMOTE_MEMORY printf("get_segment(server) free buffer %x\n", buffer); #endif - if (status_vector[1] == isc_segstr_eof) - if (blob->rbl_buffer != blob->rbl_data) { - ALLR_free(blob->rbl_buffer); - blob->rbl_buffer = blob->rbl_data; - blob->rbl_buffer_length = 1; - } return status; } @@ -2688,13 +2536,6 @@ ISC_STATUS rem_port::get_segment(P_SGMT* segment, PACKET* sendL) printf("get_segment(server) free buffer %x\n", buffer); #endif - if (status_vector[1] == isc_segstr_eof) - if (blob->rbl_buffer != blob->rbl_data) { - ALLR_free(blob->rbl_buffer); - blob->rbl_buffer = blob->rbl_data; - blob->rbl_buffer_length = 1; - } - return status; } @@ -2720,29 +2561,18 @@ ISC_STATUS rem_port::get_slice(P_SLC * stuff, PACKET* sendL) return this->send_response(sendL, 0, 0, status_vector, false); } - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - stuff->p_slc_transaction, - isc_bad_trans_handle); + getHandle(transaction, stuff->p_slc_transaction); - UCHAR temp_buffer[4096]; - UCHAR* slice; - if (!stuff->p_slc_length) - slice = 0; - else { - if (stuff->p_slc_length <= sizeof(temp_buffer)) - slice = temp_buffer; - else - slice = ALLR_alloc((SLONG) stuff->p_slc_length); - } - - if (slice) { + Firebird::HalfStaticArray temp_buffer; + UCHAR* slice = 0; + if (stuff->p_slc_length) { + slice = temp_buffer.getBuffer(stuff->p_slc_length); memset(slice, 0, stuff->p_slc_length); #ifdef DEBUG_REMOTE_MEMORY printf("get_slice(server) allocate buffer %x\n", slice); #endif } + P_SLR* response = &sendL->p_slr; isc_get_slice(status_vector, &rdb->rdb_handle, &transaction->rtr_handle, @@ -2767,14 +2597,6 @@ ISC_STATUS rem_port::get_slice(P_SLC * stuff, PACKET* sendL) status = FB_SUCCESS; } - if (slice) { -#ifdef DEBUG_REMOTE_MEMORY - printf("get_slice(server) free buffer %x\n", slice); -#endif - if (slice != temp_buffer) - ALLR_free(slice); - } - return status; } @@ -2804,30 +2626,20 @@ ISC_STATUS rem_port::info(P_OP op, P_INFO * stuff, PACKET* sendL) } /* Make sure there is a suitable temporary blob buffer */ - - UCHAR* const buffer = ALLR_alloc(stuff->p_info_buffer_length); + Firebird::Array buf; + UCHAR* const buffer = buf.getBuffer(stuff->p_info_buffer_length); memset(buffer, 0, stuff->p_info_buffer_length); -#ifdef DEBUG_REMOTE_MEMORY - printf("info(server) allocate buffer %x\n", buffer); -#endif - SCHAR info[1024], *info_buffer; + Firebird::HalfStaticArray info; + SCHAR* info_buffer = 0; USHORT info_len; - UCHAR temp[1024]; - UCHAR* temp_buffer; - temp_buffer = temp; + Firebird::HalfStaticArray temp; + UCHAR* temp_buffer = 0; if (op == op_info_database) { info_len = 0; info_buffer = 0; - - if (stuff->p_info_buffer_length > sizeof(temp)) - { - temp_buffer = ALLR_alloc((SLONG) stuff->p_info_buffer_length); -#ifdef DEBUG_REMOTE_MEMORY - printf("info(server) allocate buffer %x\n", temp_buffer); -#endif - } + temp_buffer = temp.getBuffer(stuff->p_info_buffer_length); } else { @@ -2837,17 +2649,7 @@ ISC_STATUS rem_port::info(P_OP op, P_INFO * stuff, PACKET* sendL) &stuff->p_info_recv_items : &stuff->p_info_items; info_len = 1 + info_string->cstr_length; - - if (info_len > sizeof(info)) - { - info_buffer = (SCHAR*) ALLR_alloc((SLONG) info_len); -#ifdef DEBUG_REMOTE_MEMORY - ib_printf("info(server) allocate buffer %x\n", info_buffer); -#endif - } - else { - info_buffer = info; - } + info_buffer = info.getBuffer(info_len); *info_buffer = isc_info_length; memmove(info_buffer + 1, info_string->cstr_address, info_len - 1); @@ -2856,11 +2658,7 @@ ISC_STATUS rem_port::info(P_OP op, P_INFO * stuff, PACKET* sendL) USHORT info_db_len = 0; switch (op) { case op_info_blob: - CHECK_HANDLE_MEMBER(blob, - RBL, - type_rbl, - stuff->p_info_object, - isc_bad_segstr_handle); + getHandle(blob, stuff->p_info_object); isc_blob_info(status_vector, &blob->rbl_handle, info_len, info_buffer, @@ -2888,12 +2686,8 @@ ISC_STATUS rem_port::info(P_OP op, P_INFO * stuff, PACKET* sendL) case op_info_request: { - rrq* requestL; - CHECK_HANDLE_MEMBER(requestL, - rrq*, - type_rrq, - stuff->p_info_object, - isc_bad_req_handle); + Rrq* requestL; + getHandle(requestL, stuff->p_info_object); isc_request_info(status_vector, &requestL->rrq_handle, stuff->p_info_incarnation, info_len, @@ -2904,11 +2698,7 @@ ISC_STATUS rem_port::info(P_OP op, P_INFO * stuff, PACKET* sendL) } case op_info_transaction: - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - stuff->p_info_object, - isc_bad_trans_handle); + getHandle(transaction, stuff->p_info_object); isc_transaction_info(status_vector, &transaction->rtr_handle, info_len, info_buffer, @@ -2930,11 +2720,7 @@ ISC_STATUS rem_port::info(P_OP op, P_INFO * stuff, PACKET* sendL) break; case op_info_sql: - CHECK_HANDLE_MEMBER(statement, - RSR, - type_rsr, - stuff->p_info_object, - isc_bad_req_handle); + getHandle(statement, stuff->p_info_object); GDS_DSQL_SQL_INFO(status_vector, &statement->rsr_handle, @@ -2945,20 +2731,6 @@ ISC_STATUS rem_port::info(P_OP op, P_INFO * stuff, PACKET* sendL) break; } - if (temp_buffer != temp) { -#ifdef DEBUG_REMOTE_MEMORY - printf ("info(server) free buffer %x\n", temp_buffer); -#endif - ALLR_free(temp_buffer); - } - - if (info_buffer && (info_buffer != info)) { -#ifdef DEBUG_REMOTE_MEMORY - printf ("info(server) free buffer %x\n", info_buffer); -#endif - ALLR_free(info_buffer); - } - /* Send a response that includes the segment. */ USHORT response_len = @@ -2980,11 +2752,6 @@ ISC_STATUS rem_port::info(P_OP op, P_INFO * stuff, PACKET* sendL) const ISC_STATUS status = this->send_response(sendL, stuff->p_info_object, response_len, status_vector, false); -#ifdef DEBUG_REMOTE_MEMORY - printf("info(server) free buffer %x\n", buffer); -#endif - ALLR_free(buffer); - return status; } @@ -3004,11 +2771,7 @@ ISC_STATUS rem_port::insert(P_SQLDATA * sqldata, PACKET* sendL) RSR statement; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(statement, - RSR, - type_rsr, - sqldata->p_sqldata_statement, - isc_bad_req_handle); + getHandle(statement, sqldata->p_sqldata_statement); USHORT msg_length; const UCHAR* msg; @@ -3046,16 +2809,16 @@ static RTR make_transaction (RDB rdb, FB_API_HANDLE handle) * Create a local transaction handle. * **************************************/ - RTR transaction = (RTR) ALLR_block(type_rtr, 0); + RTR transaction = new Rtr; transaction->rtr_rdb = rdb; transaction->rtr_handle = handle; - if (transaction->rtr_id = rdb->rdb_port->get_id(&transaction->rtr_header)) + if (transaction->rtr_id = rdb->rdb_port->get_id(transaction)) { transaction->rtr_next = rdb->rdb_transactions; rdb->rdb_transactions = transaction; } else { - ALLR_free(transaction); + delete transaction; transaction = NULL; } @@ -3078,11 +2841,7 @@ ISC_STATUS rem_port::open_blob(P_OP op, P_BLOB* stuff, PACKET* sendL) RTR transaction; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - stuff->p_blob_transaction, - isc_bad_trans_handle); + getHandle(transaction, stuff->p_blob_transaction); RDB rdb = this->port_context; if (bad_db(status_vector, rdb)) @@ -3112,15 +2871,13 @@ ISC_STATUS rem_port::open_blob(P_OP op, P_BLOB* stuff, PACKET* sendL) if (status_vector[1]) object = 0; else { - RBL blob = (RBL) ALLR_block(type_rbl, 1); + RBL blob = new Rbl; #ifdef DEBUG_REMOTE_MEMORY printf("open_blob(server) allocate blob %x\n", blob); #endif - blob->rbl_buffer_length = 1; - blob->rbl_buffer = blob->rbl_data; blob->rbl_handle = handle; blob->rbl_rdb = rdb; - if (blob->rbl_id = this->get_id(&blob->rbl_header)) + if (blob->rbl_id = this->get_id(blob)) { object = blob->rbl_id; blob->rbl_rtr = transaction; @@ -3131,7 +2888,7 @@ ISC_STATUS rem_port::open_blob(P_OP op, P_BLOB* stuff, PACKET* sendL) { object = 0; isc_cancel_blob(status_vector, &blob->rbl_handle); - ALLR_free(blob); + delete blob; status_vector[0] = isc_arg_gds; status_vector[1] = isc_too_many_handles; status_vector[2] = isc_arg_end; @@ -3157,11 +2914,7 @@ ISC_STATUS rem_port::prepare(P_PREP * stuff, PACKET* sendL) RTR transaction; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - stuff->p_prep_transaction, - isc_bad_trans_handle); + getHandle(transaction, stuff->p_prep_transaction); if (!isc_prepare_transaction2(status_vector, &transaction->rtr_handle, stuff->p_prep_data.cstr_length, @@ -3193,33 +2946,15 @@ ISC_STATUS rem_port::prepare_statement(P_SQLST * prepareL, PACKET* sendL) /** Do not call CHECK_HANDLE if this is the start of a transaction **/ if (prepareL->p_sqlst_transaction) { - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - prepareL->p_sqlst_transaction, - isc_bad_trans_handle); + getHandle(transaction, prepareL->p_sqlst_transaction); } - CHECK_HANDLE_MEMBER(statement, - RSR, - type_rsr, - prepareL->p_sqlst_statement, - isc_bad_req_handle); + getHandle(statement, prepareL->p_sqlst_statement); - UCHAR local_buffer[1024]; - UCHAR *info, info_buffer[1024]; - UCHAR* buffer; - if (prepareL->p_sqlst_buffer_length > sizeof(local_buffer)) - buffer = ALLR_alloc((SLONG) prepareL->p_sqlst_buffer_length); - else - buffer = local_buffer; + Firebird::HalfStaticArray local_buffer, info_buffer; + UCHAR* const info = info_buffer.getBuffer(prepareL->p_sqlst_items.cstr_length + 1); + UCHAR* const buffer = local_buffer.getBuffer(prepareL->p_sqlst_buffer_length); // stuff isc_info_length in front of info items buffer - if (prepareL->p_sqlst_items.cstr_length + 1u > sizeof(info_buffer)) { - info = ALLR_alloc((SLONG) prepareL->p_sqlst_items.cstr_length + 1); - } - else { - info = info_buffer; - } *info = isc_info_length; memmove(info + 1, prepareL->p_sqlst_items.cstr_address, prepareL->p_sqlst_items.cstr_length); @@ -3260,28 +2995,22 @@ ISC_STATUS rem_port::prepare_statement(P_SQLST * prepareL, PACKET* sendL) prepareL->p_sqlst_buffer_length, reinterpret_cast(buffer)); - if (info != info_buffer) { - ALLR_free(info); - } - if (status_vector[1]) { - if (buffer != local_buffer) - ALLR_free(buffer); return this->send_response(sendL, 0, 0, status_vector, false); } REMOTE_reset_statement(statement); - statement->rsr_flags &= ~(RSR_blob | RSR_no_batch | RSR_defer_execute); + statement->rsr_flags &= ~(Rsr::BLOB | Rsr::NO_BATCH | Rsr::DEFER_EXECUTE); USHORT state = check_statement_type(statement); if (state & STMT_BLOB) { - statement->rsr_flags |= RSR_blob; + statement->rsr_flags |= Rsr::BLOB; } if (state & STMT_NO_BATCH) { - statement->rsr_flags |= RSR_no_batch; + statement->rsr_flags |= Rsr::NO_BATCH; } - if (state & STMT_DEFER_EXECUTE && (port_flags & PORT_lazy)) { - statement->rsr_flags |= RSR_defer_execute; + if ((state & STMT_DEFER_EXECUTE) && (port_flags & PORT_lazy)) { + statement->rsr_flags |= Rsr::DEFER_EXECUTE; } if (!(port_flags & PORT_lazy)) { state = (state & STMT_BLOB) ? 1 : 0; @@ -3310,10 +3039,6 @@ ISC_STATUS rem_port::prepare_statement(P_SQLST * prepareL, PACKET* sendL) status_vector, false); - if (buffer != local_buffer) { - ALLR_free(buffer); - } - return status; } @@ -3351,7 +3076,7 @@ static bool process_packet(rem_port* port, string->str_data); } if (port->port_server->srvr_flags & SRVR_multi_client) { - port->port_state = state_broken; + port->port_state = rem_port::BROKEN; } else { gds__log("SERVER/process_packet: connect reject, server exiting"); @@ -3582,11 +3307,11 @@ static bool process_packet(rem_port* port, default: gds__log("SERVER/process_packet: don't understand packet type %d", receive->p_operation); - port->port_state = state_broken; + port->port_state = rem_port::BROKEN; break; } - if (port && port->port_state == state_broken) { + if (port && port->port_state == rem_port::BROKEN) { if (!port->port_parent) { gds__log("SERVER/process_packet: broken port, server exiting", 0); port->disconnect(sendL, receive); @@ -3712,11 +3437,7 @@ ISC_STATUS rem_port::put_segment(P_OP op, P_SGMT * segment, PACKET* sendL) RBL blob; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(blob, - RBL, - type_rbl, - segment->p_sgmt_blob, - isc_bad_segstr_handle); + getHandle(blob, segment->p_sgmt_blob); const UCHAR* p = segment->p_sgmt_segment.cstr_address; USHORT length = segment->p_sgmt_segment.cstr_length; @@ -3764,11 +3485,7 @@ ISC_STATUS rem_port::put_slice(P_SLC * stuff, PACKET* sendL) RTR transaction; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - stuff->p_slc_transaction, - isc_bad_trans_handle); + getHandle(transaction, stuff->p_slc_transaction); RDB rdb = this->port_context; if (bad_db(status_vector, rdb)) @@ -3820,7 +3537,7 @@ ISC_STATUS rem_port::que_events(P_EVENT * stuff, PACKET* sendL) if (!event) { - event = (RVNT) ALLR_block(type_rvnt, 0); + event = new rvnt; #ifdef DEBUG_REMOTE_MEMORY printf("que_events(server) allocate event %x\n", event); #endif @@ -3870,13 +3587,9 @@ ISC_STATUS rem_port::receive_after_start( P_DATA* data, * Receive a message. * **************************************/ - rrq* requestL; + Rrq* requestL; - CHECK_HANDLE_MEMBER(requestL, - rrq*, - type_rrq, - data->p_data_request, - isc_bad_req_handle); + getHandle(requestL, data->p_data_request); const USHORT level = data->p_data_incarnation; requestL = REMOTE_find_request(requestL, level); @@ -3899,7 +3612,7 @@ ISC_STATUS rem_port::receive_after_start( P_DATA* data, /* Fill in packet to fool receive into thinking that it has been called directly by the client. */ - const rrq::rrq_repeat* tail = requestL->rrq_rpt + msg_number; + const Rrq::rrq_repeat* tail = &requestL->rrq_rpt[msg_number]; const rem_fmt* format = tail->rrq_format; data->p_data_message_number = msg_number; @@ -3940,12 +3653,8 @@ ISC_STATUS rem_port::receive_msg(P_DATA * data, PACKET* sendL) message control block for the request and message type. */ ISC_STATUS_ARRAY status_vector; - rrq* requestL; - CHECK_HANDLE_MEMBER(requestL, - rrq*, - type_rrq, - data->p_data_request, - isc_bad_req_handle); + Rrq* requestL; + getHandle(requestL, data->p_data_request); const USHORT level = data->p_data_incarnation; requestL = REMOTE_find_request(requestL, level); @@ -3961,7 +3670,7 @@ ISC_STATUS rem_port::receive_msg(P_DATA * data, PACKET* sendL) status_vector[2] = isc_arg_end; return this->send_response(sendL, 0, 0, status_vector, false); } - rrq::rrq_repeat* tail = requestL->rrq_rpt + msg_number; + Rrq::rrq_repeat* tail = &requestL->rrq_rpt[msg_number]; const rem_fmt* format = tail->rrq_format; /* Get ready to ship the data out */ @@ -4036,29 +3745,29 @@ ISC_STATUS rem_port::receive_msg(P_DATA * data, PACKET* sendL) switch (direction) { case blr_forward: - tail->rrq_flags &= ~RRQ_backward; + tail->rrq_flags &= ~Rrq::BACKWARD; tail->rrq_absolute += - (tail->rrq_flags & RRQ_absolute_backward) ? + (tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD) ? -offset : offset; break; case blr_backward: - tail->rrq_flags |= RRQ_backward; + tail->rrq_flags |= Rrq::BACKWARD; tail->rrq_absolute += - (tail->rrq_flags & RRQ_absolute_backward) ? + (tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD) ? offset : -offset; break; case blr_bof_forward: - tail->rrq_flags &= ~RRQ_backward; - tail->rrq_flags &= ~RRQ_absolute_backward; + tail->rrq_flags &= ~Rrq::BACKWARD; + tail->rrq_flags &= ~Rrq::ABSOLUTE_BACKWARD; tail->rrq_absolute = offset; direction = blr_forward; break; case blr_eof_backward: - tail->rrq_flags |= RRQ_backward; - tail->rrq_flags |= RRQ_absolute_backward; + tail->rrq_flags |= Rrq::BACKWARD; + tail->rrq_flags |= Rrq::ABSOLUTE_BACKWARD; tail->rrq_absolute = offset; direction = blr_backward; break; @@ -4135,7 +3844,7 @@ ISC_STATUS rem_port::receive_msg(P_DATA * data, PACKET* sendL) /* allocate a new message block and put it in the cache */ - message = (REM_MSG) ALLR_block(type_msg, format->fmt_length); + message = new Message(format->fmt_length); #ifdef DEBUG_REMOTE_MEMORY printf("receive_msg(server) allocate message %x\n", message); @@ -4178,12 +3887,12 @@ ISC_STATUS rem_port::receive_msg(P_DATA * data, PACKET* sendL) { case blr_forward: tail->rrq_absolute += - (tail->rrq_flags & RRQ_absolute_backward) ? -offset : offset; + (tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD) ? -offset : offset; break; case blr_backward: tail->rrq_absolute += - (tail->rrq_flags & RRQ_absolute_backward) ? offset : -offset; + (tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD) ? offset : -offset; break; } @@ -4213,7 +3922,7 @@ static void release_blob(RBL blob) RDB rdb = blob->rbl_rdb; RTR transaction = blob->rbl_rtr; - rdb->rdb_port->port_objects[blob->rbl_id] = NULL; + rdb->rdb_port->releaseObject(blob->rbl_id); for (RBL* p = &transaction->rtr_blobs; *p; p = &(*p)->rbl_next) { if (*p == blob) { @@ -4225,10 +3934,7 @@ static void release_blob(RBL blob) #ifdef DEBUG_REMOTE_MEMORY printf("release_blob(server) free blob %x\n", blob); #endif - if (blob->rbl_buffer != blob->rbl_data) { - ALLR_free(blob->rbl_buffer); - } - ALLR_free(blob); + delete blob; } @@ -4254,11 +3960,11 @@ static void release_event( RVNT event) } } - ALLR_free(event); + delete event; } -static void release_request( rrq* request) +static void release_request( Rrq* request) { /************************************** * @@ -4271,7 +3977,7 @@ static void release_request( rrq* request) * **************************************/ RDB rdb = request->rrq_rdb; - rdb->rdb_port->port_objects[request->rrq_id] = NULL; + rdb->rdb_port->releaseObject(request->rrq_id); REMOTE_release_request(request); } @@ -4288,15 +3994,13 @@ static void release_statement( RSR * statement) * Release a GDML or SQL statement? * **************************************/ - if ((*statement)->rsr_select_format) - ALLR_free((*statement)->rsr_select_format); - if ((*statement)->rsr_bind_format) - ALLR_free((*statement)->rsr_bind_format); + delete (*statement)->rsr_select_format; + delete (*statement)->rsr_bind_format; stmt_release_exception(*statement); REMOTE_release_messages((*statement)->rsr_message); - ALLR_free((*statement)); + delete *statement; *statement = NULL; } @@ -4314,7 +4018,7 @@ static void release_sql_request( RSR statement) * **************************************/ RDB rdb = statement->rsr_rdb; - rdb->rdb_port->port_objects[statement->rsr_id] = NULL; + rdb->rdb_port->releaseObject(statement->rsr_id); for (RSR* p = &rdb->rdb_sql_requests; *p; p = &(*p)->rsr_next) { @@ -4341,7 +4045,7 @@ static void release_transaction( RTR transaction) * **************************************/ RDB rdb = transaction->rtr_rdb; - rdb->rdb_port->port_objects[transaction->rtr_id] = NULL; + rdb->rdb_port->releaseObject(transaction->rtr_id); while (transaction->rtr_blobs) release_blob(transaction->rtr_blobs); @@ -4357,13 +4061,13 @@ static void release_transaction( RTR transaction) #ifdef DEBUG_REMOTE_MEMORY printf("release_transact(server) free transaction %x\n", transaction); #endif - ALLR_free(transaction); + delete transaction; } #ifdef SCROLLABLE_CURSORS static REM_MSG scroll_cache( - rrq::rrq_repeat* tail, + Rrq::rrq_repeat* tail, USHORT * direction, ULONG * offset) { /************************************** @@ -4398,16 +4102,16 @@ static REM_MSG scroll_cache( for, save the last direction asked for by the next layer above */ if (*direction == blr_continue) { - if (tail->rrq_flags & RRQ_last_backward) + if (tail->rrq_flags & Rrq::LAST_BACKWARD) *direction = blr_backward; else *direction = blr_forward; } if (*direction == blr_forward || *direction == blr_bof_forward) - tail->rrq_flags &= ~RRQ_last_backward; + tail->rrq_flags &= ~Rrq::LAST_BACKWARD; else - tail->rrq_flags |= RRQ_last_backward; + tail->rrq_flags |= Rrq::LAST_BACKWARD; /* set to the first message; if it has no record, this means the cache is empty and there is no point in trying to find the record here */ @@ -4421,9 +4125,9 @@ static REM_MSG scroll_cache( if ( (*direction == blr_bof_forward - && (tail->rrq_flags & RRQ_absolute_backward)) + && (tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD)) || (*direction == blr_eof_backward - && !(tail->rrq_flags & RRQ_absolute_backward))) + && !(tail->rrq_flags & Rrq::ABSOLUTE_BACKWARD))) { return dump_cache(tail); } @@ -4449,8 +4153,8 @@ static REM_MSG scroll_cache( *direction = blr_backward; } - if ((*direction == blr_forward && (tail->rrq_flags & RRQ_backward)) || - (*direction == blr_backward && !(tail->rrq_flags & RRQ_backward))) + if ((*direction == blr_forward && (tail->rrq_flags & Rrq::BACKWARD)) || + (*direction == blr_backward && !(tail->rrq_flags & Rrq::BACKWARD))) { /* lookahead cache was in opposite direction from the scroll direction, so increase the scroll amount by the amount we looked ahead, then @@ -4498,11 +4202,7 @@ ISC_STATUS rem_port::seek_blob(P_SEEK * seek, PACKET* sendL) RBL blob; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(blob, - RBL, - type_rbl, - seek->p_seek_blob, - isc_bad_segstr_handle); + getHandle(blob, seek->p_seek_blob); const SSHORT mode = seek->p_seek_mode; const SLONG offset = seek->p_seek_offset; @@ -4530,12 +4230,8 @@ ISC_STATUS rem_port::send_msg(P_DATA * data, PACKET* sendL) **************************************/ ISC_STATUS_ARRAY status_vector; - rrq* requestL; - CHECK_HANDLE_MEMBER(requestL, - rrq*, - type_rrq, - data->p_data_request, - isc_bad_req_handle); + Rrq* requestL; + getHandle(requestL, data->p_data_request); const USHORT number = data->p_data_message_number; requestL = REMOTE_find_request(requestL, data->p_data_incarnation); @@ -4704,7 +4400,7 @@ ISC_STATUS rem_port::send_response( PACKET* sendL, // there's no point in keeping the connection open if (exit_code == isc_shutdown || exit_code == isc_att_shutdown) { - this->port_state = state_broken; + this->port_state = rem_port::BROKEN; } return exit_code; @@ -4898,7 +4594,7 @@ ISC_STATUS rem_port::service_attach(const char* service_name, reinterpret_cast(spb.getBuffer())); if (!status_vector[1]) { - RDB rdb = (RDB) ALLR_block(type_rdb, 0); + RDB rdb = new Rdb; if (rdb) { this->port_context = rdb; @@ -4907,7 +4603,7 @@ ISC_STATUS rem_port::service_attach(const char* service_name, #endif rdb->rdb_port = this; rdb->rdb_handle = handle; - rdb->rdb_flags |= RDB_service; + rdb->rdb_flags |= Rdb::SERVICE; } else { @@ -4993,11 +4689,7 @@ ISC_STATUS rem_port::set_cursor(P_SQLCUR * sqlcur, PACKET* sendL) RSR statement; ISC_STATUS_ARRAY status_vector; - CHECK_HANDLE_MEMBER(statement, - RSR, - type_rsr, - sqlcur->p_sqlcur_statement, - isc_bad_req_handle); + getHandle(statement, sqlcur->p_sqlcur_statement); GDS_DSQL_SET_CURSOR(status_vector, &statement->rsr_handle, @@ -5032,12 +4724,7 @@ void set_server( rem_port* port, USHORT flags) } if (!server) { - server = (SRVR) ALLR_alloc((SLONG) sizeof(struct srvr)); - server->srvr_next = servers; - servers = server; - server->srvr_port_type = port->port_type; - server->srvr_parent_port = port; - server->srvr_flags = flags; + servers = server = new srvr(servers, port, flags); } port->port_server = server; @@ -5058,18 +4745,10 @@ ISC_STATUS rem_port::start(P_OP operation, P_DATA * data, PACKET* sendL) ISC_STATUS_ARRAY status_vector; RTR transaction; - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - data->p_data_transaction, - isc_bad_trans_handle); + getHandle(transaction, data->p_data_transaction); - rrq* requestL; - CHECK_HANDLE_MEMBER(requestL, - rrq*, - type_rrq, - data->p_data_request, - isc_bad_req_handle); + Rrq* requestL; + getHandle(requestL, data->p_data_request); requestL = REMOTE_find_request(requestL, data->p_data_incarnation); REMOTE_reset_request(requestL, 0); @@ -5102,18 +4781,10 @@ ISC_STATUS rem_port::start_and_send(P_OP operation, **************************************/ ISC_STATUS_ARRAY status_vector; RTR transaction; - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - data->p_data_transaction, - isc_bad_trans_handle); + getHandle(transaction, data->p_data_transaction); - rrq* requestL; - CHECK_HANDLE_MEMBER(requestL, - rrq*, - type_rrq, - data->p_data_request, - isc_bad_req_handle); + Rrq* requestL; + getHandle(requestL, data->p_data_request); requestL = REMOTE_find_request(requestL, data->p_data_incarnation); const USHORT number = data->p_data_message_number; @@ -5292,7 +4963,7 @@ static THREAD_ENTRY_DECLARE loopThread(THREAD_ENTRY_PARAM) { // port_sync scope Firebird::RefMutexGuard portGuard(*request->req_port->port_sync); - if (request->req_port->port_state != state_disconnected) + if (request->req_port->port_state != rem_port::DISCONNECTED) { rem_port* parent_port = request->req_port->port_server->srvr_parent_port; @@ -5484,11 +5155,7 @@ ISC_STATUS rem_port::transact_request(P_TRRQ* trrq, PACKET* sendL) ISC_STATUS_ARRAY status_vector; RTR transaction; - CHECK_HANDLE_MEMBER(transaction, - RTR, - type_rtr, - trrq->p_trrq_transaction, - isc_bad_trans_handle); + getHandle(transaction, trrq->p_trrq_transaction); RDB rdb = this->port_context; if (bad_db(status_vector, rdb)) diff --git a/src/remote/xdr.cpp b/src/remote/xdr.cpp index c7043d0ce1..7365af6a4c 100644 --- a/src/remote/xdr.cpp +++ b/src/remote/xdr.cpp @@ -29,7 +29,6 @@ #include "../remote/remote.h" #include "../remote/xdr.h" #include "../jrd/common.h" -#include "../remote/allr_proto.h" #include "../remote/proto_proto.h" #include "../remote/xdr_proto.h" #include "../jrd/gds_proto.h" diff --git a/src/remote/xdr.h b/src/remote/xdr.h index 251a54b813..b1c921879d 100644 --- a/src/remote/xdr.h +++ b/src/remote/xdr.h @@ -73,6 +73,11 @@ typedef struct xdr_t caddr_t x_private; /* pointer to private data */ caddr_t x_base; /* private used for position info */ int x_handy; /* extra private word */ + +public: + xdr_t() : + x_op(XDR_ENCODE), x_ops(0), x_public(0), x_private(0), x_base(0), x_handy(0) + { } } XDR; /* Descriminated union crud */