diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc index d6c27aa..6bcb7c7 100644 --- a/src/crypto/crypto.cc +++ b/src/crypto/crypto.cc @@ -184,14 +184,14 @@ Nonce::Nonce( uint64_t val ) memcpy( bytes + 4, &val_net, 8 ); } -uint64_t Nonce::val( void ) +uint64_t Nonce::val( void ) const { uint64_t ret; memcpy( &ret, bytes + 4, 8 ); return be64toh( ret ); } -Nonce::Nonce( char *s_bytes, size_t len ) +Nonce::Nonce( const char *s_bytes, size_t len ) { if ( len != 8 ) { throw CryptoException( "Nonce representation must be 8 octets long." ); @@ -201,18 +201,18 @@ Nonce::Nonce( char *s_bytes, size_t len ) memcpy( bytes + 4, s_bytes, 8 ); } -Message::Message( char *nonce_bytes, size_t nonce_len, - char *text_bytes, size_t text_len ) +Message::Message( const char *nonce_bytes, size_t nonce_len, + const char *text_bytes, size_t text_len ) : nonce( nonce_bytes, nonce_len ), - text( (char *)text_bytes, text_len ) + text( text_bytes, text_len ) {} -Message::Message( Nonce s_nonce, string s_text ) +Message::Message( const Nonce & s_nonce, const string & s_text ) : nonce( s_nonce ), text( s_text ) {} -string Session::encrypt( Message plaintext ) +const string Session::encrypt( const Message & plaintext ) { const size_t pt_len = plaintext.text.size(); const int ciphertext_len = pt_len + 16; @@ -262,13 +262,13 @@ string Session::encrypt( Message plaintext ) return plaintext.nonce.cc_str() + text; } -Message Session::decrypt( string ciphertext ) +const Message Session::decrypt( const string & ciphertext ) { if ( ciphertext.size() < 24 ) { throw CryptoException( "Ciphertext must contain nonce and tag." ); } - char *str = (char *)ciphertext.data(); + const char *str = ciphertext.data(); int body_len = ciphertext.size() - 8; int pt_len = body_len - 16; @@ -297,7 +297,7 @@ Message Session::decrypt( string ciphertext ) throw CryptoException( "Packet failed integrity check." ); } - Message ret( nonce, string( plaintext_buffer.data(), pt_len ) ); + const Message ret( nonce, string( plaintext_buffer.data(), pt_len ) ); return ret; } diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index 472850a..ae51155 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -109,21 +109,21 @@ namespace Crypto { public: Nonce( uint64_t val ); - Nonce( char *s_bytes, size_t len ); + Nonce( const char *s_bytes, size_t len ); string cc_str( void ) const { return string( bytes + 4, 8 ); } const char *data( void ) const { return bytes; } - uint64_t val( void ); + uint64_t val( void ) const; }; class Message { public: - Nonce nonce; - string text; + const Nonce nonce; + const string text; - Message( char *nonce_bytes, size_t nonce_len, - char *text_bytes, size_t text_len ); - Message( Nonce s_nonce, string s_text ); + Message( const char *nonce_bytes, size_t nonce_len, + const char *text_bytes, size_t text_len ); + Message( const Nonce & s_nonce, const string & s_text ); }; class Session { @@ -145,8 +145,8 @@ namespace Crypto { Session( Base64Key s_key ); ~Session(); - string encrypt( Message plaintext ); - Message decrypt( string ciphertext ); + const string encrypt( const Message & plaintext ); + const Message decrypt( const string & ciphertext ); Session( const Session & ); Session & operator=( const Session & ); diff --git a/src/network/network.cc b/src/network/network.cc index e920a5d..347bde4 100644 --- a/src/network/network.cc +++ b/src/network/network.cc @@ -96,7 +96,7 @@ string Packet::tostring( Session *session ) return session->encrypt( Message( Nonce( direction_seq ), timestamps + payload ) ); } -Packet Connection::new_packet( string &s_payload ) +Packet Connection::new_packet( const string &s_payload ) { uint16_t outgoing_timestamp_reply = -1; @@ -391,7 +391,7 @@ Connection::Connection( const char *key_str, const char *ip, const char *port ) set_MTU( remote_addr.sa.sa_family ); } -void Connection::send( string s ) +void Connection::send( const string & s ) { if ( !has_remote_addr ) { return; diff --git a/src/network/network.h b/src/network/network.h index 677d0d0..c5f743c 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -82,7 +82,7 @@ namespace Network { string payload; Packet( Direction s_direction, - uint16_t s_timestamp, uint16_t s_timestamp_reply, string s_payload ) + uint16_t s_timestamp, uint16_t s_timestamp_reply, const string & s_payload ) : seq( Crypto::unique() ), direction( s_direction ), timestamp( s_timestamp ), timestamp_reply( s_timestamp_reply ), payload( s_payload ) {} @@ -190,7 +190,7 @@ namespace Network { bool have_send_exception; NetworkException send_exception; - Packet new_packet( string &s_payload ); + Packet new_packet( const string &s_payload ); void hop_port( void ); @@ -209,7 +209,7 @@ namespace Network { Connection( const char *desired_ip, const char *desired_port ); /* server */ Connection( const char *key_str, const char *ip, const char *port ); /* client */ - void send( string s ); + void send( const string & s ); string recv( void ); const std::vector< int > fds( void ) const; int get_MTU( void ) const { return MTU; } diff --git a/src/network/transportfragment.cc b/src/network/transportfragment.cc index ad52187..181d63e 100644 --- a/src/network/transportfragment.cc +++ b/src/network/transportfragment.cc @@ -72,7 +72,7 @@ string Fragment::tostring( void ) return ret; } -Fragment::Fragment( string &x ) +Fragment::Fragment( const string &x ) : id( -1 ), fragment_num( -1 ), final( false ), initialized( true ), contents() { diff --git a/src/network/transportfragment.h b/src/network/transportfragment.h index 9fda5a8..e5559f8 100644 --- a/src/network/transportfragment.h +++ b/src/network/transportfragment.h @@ -61,12 +61,12 @@ namespace Network { : id( -1 ), fragment_num( -1 ), final( false ), initialized( false ), contents() {} - Fragment( uint64_t s_id, uint16_t s_fragment_num, bool s_final, string s_contents ) + Fragment( uint64_t s_id, uint16_t s_fragment_num, bool s_final, const string & s_contents ) : id( s_id ), fragment_num( s_fragment_num ), final( s_final ), initialized( true ), contents( s_contents ) {} - Fragment( string &x ); + Fragment( const string &x ); string tostring( void ); diff --git a/src/network/transportsender.cc b/src/network/transportsender.cc index 01f3105..7e4d58c 100644 --- a/src/network/transportsender.cc +++ b/src/network/transportsender.cc @@ -229,7 +229,7 @@ void TransportSender::add_sent_state( uint64_t the_timestamp, uint64_t } template -void TransportSender::send_to_receiver( string diff ) +void TransportSender::send_to_receiver( const string & diff ) { uint64_t new_num; if ( current_state == sent_states.back().state ) { /* previously sent */ @@ -310,7 +310,7 @@ const string TransportSender::make_chaff( void ) } template -void TransportSender::send_in_fragments( string diff, uint64_t new_num ) +void TransportSender::send_in_fragments( const string & diff, uint64_t new_num ) { Instruction inst; diff --git a/src/network/transportsender.h b/src/network/transportsender.h index 9ad3848..ba9423c 100644 --- a/src/network/transportsender.h +++ b/src/network/transportsender.h @@ -64,9 +64,9 @@ namespace Network { void update_assumed_receiver_state( void ); void attempt_prospective_resend_optimization( string &proposed_diff ); void rationalize_states( void ); - void send_to_receiver( string diff ); + void send_to_receiver( const string & diff ); void send_empty_ack( void ); - void send_in_fragments( string diff, uint64_t new_num ); + void send_in_fragments( const string & diff, uint64_t new_num ); void add_sent_state( uint64_t the_timestamp, uint64_t num, MyState &state ); /* state of sender */ diff --git a/src/network/transportstate.h b/src/network/transportstate.h index efe3c59..9c52b69 100644 --- a/src/network/transportstate.h +++ b/src/network/transportstate.h @@ -42,7 +42,7 @@ namespace Network { uint64_t num; State state; - TimestampedState( uint64_t s_timestamp, uint64_t s_num, State &s_state ) + TimestampedState( uint64_t s_timestamp, uint64_t s_num, const State &s_state ) : timestamp( s_timestamp ), num( s_num ), state( s_state ) {} diff --git a/src/statesync/completeterminal.cc b/src/statesync/completeterminal.cc index c22c6d0..64211ff 100644 --- a/src/statesync/completeterminal.cc +++ b/src/statesync/completeterminal.cc @@ -102,7 +102,7 @@ string Complete::init_diff( void ) const return diff_from( Complete( get_fb().ds.get_width(), get_fb().ds.get_height() )); } -void Complete::apply_string( string diff ) +void Complete::apply_string( const string & diff ) { HostBuffers::HostMessage input; fatal_assert( input.ParseFromString( diff ) ); diff --git a/src/statesync/completeterminal.h b/src/statesync/completeterminal.h index cbcaa12..26e89a7 100644 --- a/src/statesync/completeterminal.h +++ b/src/statesync/completeterminal.h @@ -77,7 +77,7 @@ namespace Terminal { void subtract( const Complete * ) const {} std::string diff_from( const Complete &existing ) const; std::string init_diff( void ) const; - void apply_string( std::string diff ); + void apply_string( const std::string & diff ); bool operator==( const Complete &x ) const; bool compare( const Complete &other ) const; diff --git a/src/statesync/user.cc b/src/statesync/user.cc index 763e860..77dab8e 100644 --- a/src/statesync/user.cc +++ b/src/statesync/user.cc @@ -105,7 +105,7 @@ string UserStream::diff_from( const UserStream &existing ) const return output.SerializeAsString(); } -void UserStream::apply_string( string diff ) +void UserStream::apply_string( const string &diff ) { ClientBuffers::UserMessage input; fatal_assert( input.ParseFromString( diff ) ); diff --git a/src/statesync/user.h b/src/statesync/user.h index 5c5a295..04a3ad5 100644 --- a/src/statesync/user.h +++ b/src/statesync/user.h @@ -57,8 +57,8 @@ namespace Network { Parser::UserByte userbyte; Parser::Resize resize; - UserEvent( Parser::UserByte s_userbyte ) : type( UserByteType ), userbyte( s_userbyte ), resize( -1, -1 ) {} - UserEvent( Parser::Resize s_resize ) : type( ResizeType ), userbyte( 0 ), resize( s_resize ) {} + UserEvent( const Parser::UserByte & s_userbyte ) : type( UserByteType ), userbyte( s_userbyte ), resize( -1, -1 ) {} + UserEvent( const Parser::Resize & s_resize ) : type( ResizeType ), userbyte( 0 ), resize( s_resize ) {} UserEvent() /* default constructor required by C++11 STL */ : type( UserByteType ), @@ -79,8 +79,8 @@ namespace Network { public: UserStream() : actions() {} - void push_back( Parser::UserByte s_userbyte ) { actions.push_back( UserEvent( s_userbyte ) ); } - void push_back( Parser::Resize s_resize ) { actions.push_back( UserEvent( s_resize ) ); } + void push_back( const Parser::UserByte & s_userbyte ) { actions.push_back( UserEvent( s_userbyte ) ); } + void push_back( const Parser::Resize & s_resize ) { actions.push_back( UserEvent( s_resize ) ); } bool empty( void ) const { return actions.empty(); } size_t size( void ) const { return actions.size(); } @@ -90,7 +90,7 @@ namespace Network { void subtract( const UserStream *prefix ); string diff_from( const UserStream &existing ) const; string init_diff( void ) const { assert( false ); return string(); }; - void apply_string( string diff ); + void apply_string( const string &diff ); bool operator==( const UserStream &x ) const { return actions == x.actions; } bool compare( const UserStream & ) { return false; } diff --git a/src/terminal/terminaldispatcher.cc b/src/terminal/terminaldispatcher.cc index 2c901a6..b7c0ee9 100644 --- a/src/terminal/terminaldispatcher.cc +++ b/src/terminal/terminaldispatcher.cc @@ -170,7 +170,7 @@ DispatchRegistry & Terminal::get_global_dispatch_registry( void ) } static void register_function( Function_Type type, - std::string dispatch_chars, + const std::string & dispatch_chars, Function f ) { switch ( type ) { @@ -186,7 +186,7 @@ static void register_function( Function_Type type, } } -Function::Function( Function_Type type, std::string dispatch_chars, +Function::Function( Function_Type type, const std::string & dispatch_chars, void (*s_function)( Framebuffer *, Dispatcher * ), bool s_clears_wrap_state ) : function( s_function ), clears_wrap_state( s_clears_wrap_state ) diff --git a/src/terminal/terminaldispatcher.h b/src/terminal/terminaldispatcher.h index 5bdc479..cc92c2e 100644 --- a/src/terminal/terminaldispatcher.h +++ b/src/terminal/terminaldispatcher.h @@ -59,7 +59,7 @@ namespace Terminal { class Function { public: Function() : function( NULL ), clears_wrap_state( true ) {} - Function( Function_Type type, std::string dispatch_chars, + Function( Function_Type type, const std::string & dispatch_chars, void (*s_function)( Framebuffer *, Dispatcher * ), bool s_clears_wrap_state = true ); void (*function)( Framebuffer *, Dispatcher * ); diff --git a/src/terminal/terminaldisplay.h b/src/terminal/terminaldisplay.h index 887c93d..00b3f59 100644 --- a/src/terminal/terminaldisplay.h +++ b/src/terminal/terminaldisplay.h @@ -49,9 +49,9 @@ namespace Terminal { FrameState( const Framebuffer &s_last ); - void append( const char c ) { str.append( 1, c ); } - void append( const size_t s, const char c ) { str.append( s, c ); } - void append( const wchar_t wc ) { Cell::append_to_str( str, wc ); } + void append( char c ) { str.append( 1, c ); } + void append( size_t s, char c ) { str.append( s, c ); } + void append( wchar_t wc ) { Cell::append_to_str( str, wc ); } void append( const char * s ) { str.append( s ); } void append_string( const std::string &append ) { str.append(append); }