Skip to content

Commit 1e265a5

Browse files
committed
constexpr/const/noexcept in remote/protocol
1 parent 86234bf commit 1e265a5

File tree

6 files changed

+52
-56
lines changed

6 files changed

+52
-56
lines changed

src/remote/proto_proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@
2828
void xdr_debug_memory (RemoteXdr*, enum xdr_op, const void*, const void*, ULONG);
2929
#endif
3030
bool_t xdr_protocol (RemoteXdr*, struct packet*);
31-
ULONG xdr_protocol_overhead (P_OP);
31+
ULONG xdr_protocol_overhead (P_OP) noexcept;
3232

3333
#endif // REMOTE_PROTO_PROTO_H

src/remote/protocol.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ static bool_t xdr_bytes(RemoteXdr* xdrs, void* bytes, ULONG size)
12061206
}
12071207

12081208

1209-
ULONG xdr_protocol_overhead(P_OP op)
1209+
ULONG xdr_protocol_overhead(P_OP op) noexcept
12101210
{
12111211
/**************************************
12121212
*
@@ -1310,7 +1310,7 @@ static bool alloc_cstring(RemoteXdr* xdrs, CSTRING* cstring)
13101310
}
13111311

13121312

1313-
void CSTRING::free(RemoteXdr* xdrs)
1313+
void CSTRING::free(RemoteXdr* xdrs) noexcept
13141314
{
13151315
/**************************************
13161316
*
@@ -1335,7 +1335,7 @@ void CSTRING::free(RemoteXdr* xdrs)
13351335
}
13361336

13371337

1338-
static bool xdr_is_client(RemoteXdr* xdrs) noexcept
1338+
static bool xdr_is_client(const RemoteXdr* xdrs) noexcept
13391339
{
13401340
const rem_port* port = xdrs->x_public;
13411341
return !(port->port_flags & PORT_server);
@@ -1577,7 +1577,7 @@ static bool_t xdr_message( RemoteXdr* xdrs, RMessage* message, const rem_fmt* fo
15771577
if (xdrs->x_op == XDR_FREE)
15781578
return TRUE;
15791579

1580-
rem_port* port = xdrs->x_public;
1580+
const rem_port* port = xdrs->x_public;
15811581

15821582
if (!message || !format)
15831583
return FALSE;

src/remote/protocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ typedef struct cstring
351351
ULONG cstr_allocated;
352352
UCHAR* cstr_address;
353353

354-
void free(RemoteXdr* xdrs = nullptr);
354+
void free(RemoteXdr* xdrs = nullptr) noexcept;
355355
} CSTRING;
356356

357357
// CVC: Only used in p_blob, p_sgmt & p_ddl, to validate constness.

src/remote/remot_proto.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Firebird
4040
struct rem_port;
4141
struct RemoteXdr : public xdr_t
4242
{
43-
RemoteXdr()
43+
RemoteXdr() noexcept
4444
: x_public(nullptr)
4545
{ }
4646

@@ -55,24 +55,24 @@ typedef bool ProtoWrite(RemoteXdr*);
5555
enum LegacyPlugin {PLUGIN_NEW = 0, PLUGIN_LEGACY, PLUGIN_TRUSTED};
5656

5757
void REMOTE_cleanup_transaction (struct Rtr *);
58-
USHORT REMOTE_compute_batch_size (rem_port*, USHORT, P_OP, const rem_fmt*);
58+
USHORT REMOTE_compute_batch_size(const rem_port*, USHORT, P_OP, const rem_fmt*) noexcept;
5959
void REMOTE_get_timeout_params(rem_port* port, Firebird::ClumpletReader* pb);
6060
struct Rrq* REMOTE_find_request (struct Rrq *, USHORT);
61-
void REMOTE_free_packet (rem_port*, struct packet *, bool = false);
61+
void REMOTE_free_packet(rem_port*, PACKET*, bool = false);
6262
struct rem_str* REMOTE_make_string (const SCHAR*);
63-
void REMOTE_release_messages (struct RMessage*);
64-
void REMOTE_release_request (struct Rrq *);
65-
void REMOTE_reset_request (struct Rrq *, struct RMessage*);
66-
void REMOTE_reset_statement (struct Rsr *);
63+
void REMOTE_release_messages(struct RMessage*) noexcept;
64+
void REMOTE_release_request(struct Rrq*) noexcept;
65+
void REMOTE_reset_request(struct Rrq*, const struct RMessage*);
66+
void REMOTE_reset_statement(struct Rsr*) noexcept;
6767
bool_t REMOTE_getbytes (RemoteXdr*, SCHAR*, unsigned);
68-
LegacyPlugin REMOTE_legacy_auth(const char* nm, int protocol);
68+
LegacyPlugin REMOTE_legacy_auth(const char* nm, int protocol) noexcept;
6969
Firebird::RefPtr<const Firebird::Config> REMOTE_get_config(const Firebird::PathName* dbName,
7070
const Firebird::string* dpb_config = NULL);
71-
void REMOTE_check_response(Firebird::IStatus* warning, Rdb* rdb, PACKET* packet, bool checkKeys = false);
71+
void REMOTE_check_response(Firebird::IStatus* warning, Rdb* rdb, const PACKET* packet, bool checkKeys = false);
7272
bool REMOTE_inflate(rem_port*, PacketReceive*, UCHAR*, SSHORT, SSHORT*);
7373
bool REMOTE_deflate(RemoteXdr*, ProtoWrite*, PacketSend*, bool flash);
7474

75-
extern signed char wcCompatible[3][3];
75+
extern const signed char wcCompatible[3][3];
7676

7777
#define HANDSHAKE_DEBUG(A)
7878
#define WIRECRYPT_DEBUG(A)

src/remote/remote.cpp

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ const ParametersSet connectParam =
124124
};
125125

126126

127-
const SLONG DUMMY_INTERVAL = 60; // seconds
128-
const int ATTACH_FAILURE_SPACE = 16 * 1024; // bytes
127+
constexpr SLONG DUMMY_INTERVAL = 60; // seconds
128+
constexpr int ATTACH_FAILURE_SPACE = 16 * 1024; // bytes
129129

130130

131131
void REMOTE_cleanup_transaction( Rtr* transaction)
@@ -172,9 +172,9 @@ void REMOTE_cleanup_transaction( Rtr* transaction)
172172
}
173173

174174

175-
USHORT REMOTE_compute_batch_size(rem_port* port,
175+
USHORT REMOTE_compute_batch_size(const rem_port* port,
176176
USHORT buffer_used, P_OP op_code,
177-
const rem_fmt* format)
177+
const rem_fmt* format) noexcept
178178
{
179179
/**************************************
180180
*
@@ -231,9 +231,9 @@ USHORT REMOTE_compute_batch_size(rem_port* port,
231231
#endif
232232

233233
const ULONG row_size = op_overhead +
234-
(port->port_flags & PORT_symmetric) ?
235-
ROUNDUP(format->fmt_length, 4) : // Same architecture connection
236-
ROUNDUP(format->fmt_net_length, 4); // Using XDR for data transfer
234+
((port->port_flags & PORT_symmetric) ?
235+
ROUNDUP(format->fmt_length, 4) : // Same architecture connection
236+
ROUNDUP(format->fmt_net_length, 4)); // Using XDR for data transfer
237237

238238
ULONG result = (port->port_protocol >= PROTOCOL_VERSION13) ?
239239
MAX_ROWS_PER_BATCH : (MAX_PACKETS_PER_BATCH * port->port_buff_size - buffer_used) / row_size;
@@ -309,7 +309,7 @@ Rrq* REMOTE_find_request(Rrq* request, USHORT level)
309309
}
310310

311311

312-
void REMOTE_free_packet( rem_port* port, PACKET * packet, bool partial)
312+
void REMOTE_free_packet(rem_port* port, PACKET* packet, bool partial)
313313
{
314314
/**************************************
315315
*
@@ -416,7 +416,7 @@ rem_str* REMOTE_make_string(const SCHAR* input)
416416
}
417417

418418

419-
void REMOTE_release_messages( RMessage* messages)
419+
void REMOTE_release_messages(RMessage* messages) noexcept
420420
{
421421
/**************************************
422422
*
@@ -446,7 +446,7 @@ void REMOTE_release_messages( RMessage* messages)
446446
}
447447

448448

449-
void REMOTE_release_request( Rrq* request)
449+
void REMOTE_release_request(Rrq* request) noexcept
450450
{
451451
/**************************************
452452
*
@@ -501,7 +501,7 @@ void REMOTE_release_request( Rrq* request)
501501
}
502502

503503

504-
void REMOTE_reset_request( Rrq* request, RMessage* active_message)
504+
void REMOTE_reset_request(Rrq* request, const RMessage* active_message)
505505
{
506506
/**************************************
507507
*
@@ -537,13 +537,11 @@ void REMOTE_reset_request( Rrq* request, RMessage* active_message)
537537
}
538538

539539
// Initialize the request status to FB_SUCCESS
540-
541-
//request->rrq_status_vector[1] = 0;
542540
request->rrqStatus.clear();
543541
}
544542

545543

546-
void REMOTE_reset_statement( Rsr* statement)
544+
void REMOTE_reset_statement(Rsr* statement) noexcept
547545
{
548546
/**************************************
549547
*
@@ -613,7 +611,7 @@ RefPtr<const Config> rem_port::getPortConfig()
613611
return port_config.hasData() ? port_config : Config::getDefaultConfig();
614612
}
615613

616-
void rem_port::unlinkParent()
614+
void rem_port::unlinkParent() noexcept
617615
{
618616
if (this->port_parent == NULL)
619617
return;
@@ -647,7 +645,7 @@ void rem_port::unlinkParent()
647645
this->port_parent = NULL;
648646
}
649647

650-
bool rem_port::accept(p_cnct* cnct)
648+
bool rem_port::accept(const p_cnct* cnct)
651649
{
652650
return (*this->port_accept)(this, cnct);
653651
}
@@ -984,7 +982,7 @@ Rbl* Rtr::createInlineBlob()
984982
return blb;
985983
};
986984

987-
void Rtr::setupInlineBlob(P_INLINE_BLOB* p_blob)
985+
void Rtr::setupInlineBlob(const P_INLINE_BLOB* p_blob)
988986
{
989987
fb_assert(p_blob->p_tran_id == this->rtr_id);
990988
fb_assert(rtr_inline_blob);
@@ -1004,7 +1002,7 @@ void Rtr::setupInlineBlob(P_INLINE_BLOB* p_blob)
10041002
}
10051003

10061004
blb->rbl_blob_id = p_blob->p_blob_id;
1007-
if (Rbl* old = rtr_blobs.locate(blb->rbl_blob_id))
1005+
if (const Rbl* old = rtr_blobs.locate(blb->rbl_blob_id))
10081006
{
10091007
// Blob with the same blob id already exists. It could be in use, or it
10101008
// could be opened by user explicitly with custom BPB - thus delete new one.
@@ -1051,16 +1049,16 @@ string rem_port::getRemoteId() const
10511049
return id;
10521050
}
10531051

1054-
LegacyPlugin REMOTE_legacy_auth(const char* nm, int p)
1052+
LegacyPlugin REMOTE_legacy_auth(const char* nm, int p) noexcept
10551053
{
1056-
const char* legacyTrusted = "WIN_SSPI";
1054+
constexpr const char* legacyTrusted = "WIN_SSPI";
10571055
if (fb_utils::stricmp(legacyTrusted, nm) == 0 &&
10581056
(p == PROTOCOL_VERSION11 || p == PROTOCOL_VERSION12))
10591057
{
10601058
return PLUGIN_TRUSTED;
10611059
}
10621060

1063-
const char* legacyAuth = "LEGACY_AUTH";
1061+
constexpr const char* legacyAuth = "LEGACY_AUTH";
10641062
if (fb_utils::stricmp(legacyAuth, nm) == 0 && p < PROTOCOL_VERSION13)
10651063
{
10661064
return PLUGIN_LEGACY;
@@ -1184,7 +1182,7 @@ void ClntAuthBlock::resetClnt(const CSTRING* listStr)
11841182
plugins.set(final.c_str());
11851183
}
11861184

1187-
RefPtr<const Config>* ClntAuthBlock::getConfig()
1185+
RefPtr<const Config>* ClntAuthBlock::getConfig() noexcept
11881186
{
11891187
return clntConfig.hasData() ? &clntConfig : NULL;
11901188
}
@@ -1213,7 +1211,7 @@ RefPtr<const Config> REMOTE_get_config(const PathName* dbName,
12131211
return config;
12141212
}
12151213

1216-
void REMOTE_check_response(IStatus* warning, Rdb* rdb, PACKET* packet, bool checkKeys)
1214+
void REMOTE_check_response(IStatus* warning, Rdb* rdb, const PACKET* packet, bool checkKeys)
12171215
{
12181216
/**************************************
12191217
*
@@ -1229,7 +1227,7 @@ void REMOTE_check_response(IStatus* warning, Rdb* rdb, PACKET* packet, bool chec
12291227
rdb->rdb_port->checkResponse(warning, packet, checkKeys);
12301228
}
12311229

1232-
void rem_port::checkResponse(IStatus* warning, PACKET* packet, bool checkKeys)
1230+
void rem_port::checkResponse(IStatus* warning, const PACKET* packet, bool checkKeys)
12331231
{
12341232
/**************************************
12351233
*
@@ -1244,7 +1242,7 @@ void rem_port::checkResponse(IStatus* warning, PACKET* packet, bool checkKeys)
12441242

12451243
// Get status vector
12461244

1247-
const ISC_STATUS success_vector[] = {isc_arg_gds, FB_SUCCESS, isc_arg_end};
1245+
constexpr ISC_STATUS success_vector[] = {isc_arg_gds, FB_SUCCESS, isc_arg_end};
12481246
const ISC_STATUS *vector = success_vector;
12491247
if (packet->p_resp.p_resp_status_vector)
12501248
{
@@ -1269,7 +1267,7 @@ void rem_port::checkResponse(IStatus* warning, PACKET* packet, bool checkKeys)
12691267

12701268
case isc_arg_cstring:
12711269
newVector.push(*vector++);
1272-
// fall down
1270+
[[fallthrough]];
12731271

12741272
default:
12751273
newVector.push(*vector++);
@@ -1291,16 +1289,16 @@ void rem_port::checkResponse(IStatus* warning, PACKET* packet, bool checkKeys)
12911289
}
12921290

12931291
if ((packet->p_operation == op_response || packet->p_operation == op_response_piggyback) &&
1294-
!vector[1])
1292+
!pktErr)
12951293
{
12961294
Arg::StatusVector s(vector);
12971295
s.copyTo(warning);
12981296
return;
12991297
}
13001298

1301-
HANDSHAKE_DEBUG(fprintf(stderr, "Raising exception %d in checkResponse\n", vector[1] ? vector[1] : isc_net_read_err));
1299+
HANDSHAKE_DEBUG(fprintf(stderr, "Raising exception %d in checkResponse\n", pktErr ? pktErr : isc_net_read_err));
13021300

1303-
if (!vector[1])
1301+
if (!pktErr)
13041302
{
13051303
Arg::Gds(isc_net_read_err).raise();
13061304
}
@@ -1451,7 +1449,7 @@ bool rem_port::tryKeyType(const KnownServerKey& srvKey, InternalCryptKey* cryptK
14511449
return false;
14521450
}
14531451

1454-
const char* SrvAuthBlock::getLogin()
1452+
const char* SrvAuthBlock::getLogin() noexcept
14551453
{
14561454
return userName.nullStr();
14571455
}
@@ -1823,7 +1821,7 @@ const void* InternalCryptKey::getDecryptKey(unsigned* length)
18231821
}
18241822

18251823

1826-
signed char wcCompatible[3][3] = {
1824+
const signed char wcCompatible[3][3] = {
18271825
/* DISABLED ENABLED REQUIRED */
18281826
/* DISABLED */ {WIRECRYPT_DISABLED, WIRECRYPT_DISABLED, WIRECRYPT_BROKEN},
18291827
/* ENABLED */ {WIRECRYPT_DISABLED, WIRECRYPT_ENABLED, WIRECRYPT_REQUIRED},

src/remote/remote.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ extern const ParametersSet dpbParam, spbParam, connectParam;
159159

160160
struct Svc : public Firebird::GlobalStorage
161161
{
162-
ServService svc_iface; // service interface
162+
ServService svc_iface; // service interface
163163
Svc() :
164164
svc_iface(NULL)
165165
{ }
@@ -342,7 +342,7 @@ struct Rtr : public Firebird::GlobalStorage, public TypedHandle<rem_type_rtr>
342342
static constexpr ISC_STATUS badHandle() noexcept { return isc_bad_trans_handle; }
343343

344344
Rbl* createInlineBlob();
345-
void setupInlineBlob(P_INLINE_BLOB* p_blob);
345+
void setupInlineBlob(const P_INLINE_BLOB* p_blob);
346346
};
347347

348348

@@ -1155,7 +1155,7 @@ class ClntAuthBlock final :
11551155
Firebird::PathName getPluginName();
11561156
void tryNewKeys(rem_port*);
11571157
void releaseKeys(unsigned from);
1158-
Firebird::RefPtr<const Firebird::Config>* getConfig();
1158+
Firebird::RefPtr<const Firebird::Config>* getConfig() noexcept;
11591159
void createCryptCallback(Firebird::ICryptKeyCallback** callback);
11601160

11611161
// Firebird::IClientBlock implementation
@@ -1229,7 +1229,7 @@ class SrvAuthBlock final :
12291229
bool hasDataForPlugin();
12301230

12311231
// Firebird::IServerBlock implementation
1232-
const char* getLogin();
1232+
const char* getLogin() noexcept;
12331233
const unsigned char* getData(unsigned int* length);
12341234
void putData(Firebird::CheckStatusWrapper* status, unsigned int length, const void* data);
12351235
Firebird::ICryptKey* newKey(Firebird::CheckStatusWrapper* status);
@@ -1531,7 +1531,7 @@ struct rem_port : public Firebird::GlobalStorage, public Firebird::RefCounted
15311531
void initCompression();
15321532
static bool checkCompression();
15331533
void linkParent(rem_port* const parent);
1534-
void unlinkParent();
1534+
void unlinkParent() noexcept;
15351535
Firebird::RefPtr<const Firebird::Config> getPortConfig();
15361536
const Firebird::RefPtr<const Firebird::Config>& getPortConfig() const;
15371537
void versionInfo(Firebird::string& version) const;
@@ -1621,9 +1621,7 @@ struct rem_port : public Firebird::GlobalStorage, public Firebird::RefCounted
16211621
}
16221622

16231623
public:
1624-
// TMN: Beginning of C++ port
1625-
// TMN: ugly, but at least a start
1626-
bool accept(p_cnct* cnct);
1624+
bool accept(const p_cnct* cnct);
16271625
void disconnect();
16281626
void force_close();
16291627
rem_port* receive(PACKET* pckt);
@@ -1743,7 +1741,7 @@ struct rem_port : public Firebird::GlobalStorage, public Firebird::RefCounted
17431741
const Firebird::UCharBuffer* findSpecificData(const Firebird::PathName& type, const Firebird::PathName& plugin);
17441742
bool tryNewKey(InternalCryptKey* cryptKey);
17451743

1746-
void checkResponse(Firebird::IStatus* warning, PACKET* packet, bool checkKeys = false);
1744+
void checkResponse(Firebird::IStatus* warning, const PACKET* packet, bool checkKeys = false);
17471745

17481746
private:
17491747
bool tryKeyType(const KnownServerKey& srvKey, InternalCryptKey* cryptKey);

0 commit comments

Comments
 (0)