diff --git a/src/crypto/base64.cc b/src/crypto/base64.cc index 6d8a9d157..ae38e3ee6 100644 --- a/src/crypto/base64.cc +++ b/src/crypto/base64.cc @@ -30,8 +30,8 @@ also delete it here. */ -#include -#include +#include +#include #include "src/util/fatal_assert.h" #include "src/crypto/base64.h" diff --git a/src/crypto/base64.h b/src/crypto/base64.h index e216dc051..80de7c686 100644 --- a/src/crypto/base64.h +++ b/src/crypto/base64.h @@ -30,7 +30,7 @@ also delete it here. */ -#include +#include bool base64_decode( const char *b64, const size_t b64_len, uint8_t *raw, size_t *raw_len ); diff --git a/src/crypto/byteorder.h b/src/crypto/byteorder.h index 9148287a5..fe7e8cdd0 100644 --- a/src/crypto/byteorder.h +++ b/src/crypto/byteorder.h @@ -60,7 +60,7 @@ /* Use our fallback implementation, which is correct for any endianness. */ -#include +#include /* Make sure they aren't macros */ #undef htobe64 diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc index 10f3a03b9..62e04dab8 100644 --- a/src/crypto/crypto.cc +++ b/src/crypto/crypto.cc @@ -30,14 +30,15 @@ also delete it here. */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include +#include + #include "src/crypto/byteorder.h" #include "src/crypto/crypto.h" #include "src/crypto/base64.h" @@ -107,13 +108,13 @@ AlignedBuffer::AlignedBuffer( size_t len, const char *data ) } } -Base64Key::Base64Key( string printable_key ) +Base64Key::Base64Key( std::string printable_key ) { if ( printable_key.length() != 22 ) { throw CryptoException( "Key must be 22 letters long." ); } - string base64 = printable_key + "=="; + std::string base64 = printable_key + "=="; size_t len = 16; if ( !base64_decode( base64.data(), 24, key, &len ) ) { @@ -140,7 +141,7 @@ Base64Key::Base64Key(PRNG &prng) prng.fill( key, sizeof( key ) ); } -string Base64Key::printable_key( void ) const +std::string Base64Key::printable_key( void ) const { char base64[ 24 ]; @@ -148,11 +149,11 @@ string Base64Key::printable_key( void ) const if ( (base64[ 23 ] != '=') || (base64[ 22 ] != '=') ) { - throw CryptoException( string( "Unexpected output from base64_encode: " ) + string( base64, 24 ) ); + throw CryptoException( std::string( "Unexpected output from base64_encode: " ) + std::string( base64, 24 ) ); } base64[ 22 ] = 0; - return string( base64 ); + return std::string( base64 ); } Session::Session( Base64Key s_key ) @@ -197,7 +198,7 @@ Nonce::Nonce( const char *s_bytes, size_t len ) memcpy( bytes + 4, s_bytes, 8 ); } -const string Session::encrypt( const Message & plaintext ) +const std::string Session::encrypt( const Message & plaintext ) { const size_t pt_len = plaintext.text.size(); const int ciphertext_len = pt_len + 16; @@ -242,7 +243,7 @@ const string Session::encrypt( const Message & plaintext ) throw CryptoException( "Encrypted 2^47 blocks.", true ); } - string text( ciphertext_buffer.data(), ciphertext_len ); + std::string text( ciphertext_buffer.data(), ciphertext_len ); return plaintext.nonce.cc_str() + text; } @@ -280,7 +281,7 @@ const Message Session::decrypt( const char *str, size_t len ) throw CryptoException( "Packet failed integrity check." ); } - const Message ret( nonce, string( plaintext_buffer.data(), pt_len ) ); + const Message ret( nonce, std::string( plaintext_buffer.data(), pt_len ) ); return ret; } diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index e634d3e09..a3c26a881 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -34,11 +34,12 @@ #define CRYPTO_HPP #include "src/crypto/ae.h" -#include -#include -#include -#include + +#include +#include +#include #include +#include long int myatoi( const char *str ); @@ -46,13 +47,11 @@ long int myatoi( const char *str ); class PRNG; namespace Crypto { - using std::string; - class CryptoException : public std::exception { public: - string text; + std::string text; bool fatal; - CryptoException( string s_text, bool s_fatal = false ) + CryptoException( std::string s_text, bool s_fatal = false ) : text( s_text ), fatal( s_fatal ) {}; const char *what() const throw () { return text.c_str(); } ~CryptoException() throw () {} @@ -95,8 +94,8 @@ namespace Crypto { public: Base64Key(); /* random key */ Base64Key(PRNG &prng); - Base64Key( string printable_key ); - string printable_key( void ) const; + Base64Key( std::string printable_key ); + std::string printable_key( void ) const; unsigned char *data( void ) { return key; } }; @@ -111,7 +110,7 @@ namespace Crypto { Nonce( uint64_t val ); Nonce( const char *s_bytes, size_t len ); - string cc_str( void ) const { return string( bytes + 4, 8 ); } + std::string cc_str( void ) const { return std::string( bytes + 4, 8 ); } const char *data( void ) const { return bytes; } uint64_t val( void ) const; }; @@ -119,14 +118,14 @@ namespace Crypto { class Message { public: const Nonce nonce; - const string text; + const std::string text; Message( const char *nonce_bytes, size_t nonce_len, const char *text_bytes, size_t text_len ) : nonce( nonce_bytes, nonce_len ), text( text_bytes, text_len ) {} - Message( const Nonce & s_nonce, const string & s_text ) + Message( const Nonce & s_nonce, const std::string & s_text ) : nonce( s_nonce ), text( s_text ) {} }; @@ -150,9 +149,9 @@ namespace Crypto { Session( Base64Key s_key ); ~Session(); - const string encrypt( const Message & plaintext ); + const std::string encrypt( const Message & plaintext ); const Message decrypt( const char *str, size_t len ); - const Message decrypt( const string & ciphertext ) { + const Message decrypt( const std::string & ciphertext ) { return decrypt( ciphertext.data(), ciphertext.size() ); } diff --git a/src/crypto/ocb_internal.cc b/src/crypto/ocb_internal.cc index c25d7bd2a..0d4848cdb 100644 --- a/src/crypto/ocb_internal.cc +++ b/src/crypto/ocb_internal.cc @@ -87,8 +87,8 @@ #include "src/crypto/ae.h" #include "src/crypto/crypto.h" #include "src/util/fatal_assert.h" -#include -#include +#include +#include #if defined(HAVE_STRINGS_H) #include #endif diff --git a/src/crypto/prng.h b/src/crypto/prng.h index 693080e18..03e0b72b3 100644 --- a/src/crypto/prng.h +++ b/src/crypto/prng.h @@ -33,9 +33,9 @@ #ifndef PRNG_HPP #define PRNG_HPP -#include -#include +#include #include +#include #include "src/crypto/crypto.h" diff --git a/src/examples/benchmark.cc b/src/examples/benchmark.cc index d2f3b2ab6..1c60083e5 100644 --- a/src/examples/benchmark.cc +++ b/src/examples/benchmark.cc @@ -32,19 +32,20 @@ #include "src/include/config.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include #include #include -#include -#include -#include -#include -#include +#include #if HAVE_PTY_H #include @@ -106,9 +107,9 @@ int main( int argc, char **argv ) overlays.apply( *new_state ); /* calculate minimal difference from where we are */ - const string diff( display.new_frame( false, - *local_framebuffer, - *new_state ) ); + const std::string diff( display.new_frame( false, + *local_framebuffer, + *new_state ) ); /* make sure to use diff */ if ( diff.size() > INT_MAX ) { diff --git a/src/examples/decrypt.cc b/src/examples/decrypt.cc index 384cf58a1..5f053a89a 100644 --- a/src/examples/decrypt.cc +++ b/src/examples/decrypt.cc @@ -30,7 +30,7 @@ also delete it here. */ -#include +#include #include #include diff --git a/src/examples/encrypt.cc b/src/examples/encrypt.cc index 0957ef7ff..bba0cc3b7 100644 --- a/src/examples/encrypt.cc +++ b/src/examples/encrypt.cc @@ -30,7 +30,7 @@ also delete it here. */ -#include +#include #include #include @@ -56,7 +56,7 @@ int main( int argc, char *argv[] ) /* Encrypt message */ - string ciphertext = session.encrypt( Message( nonce, input.str() ) ); + std::string ciphertext = session.encrypt( Message( nonce, input.str() ) ); std::cerr << "Key: " << key.printable_key() << std::endl; diff --git a/src/examples/ntester.cc b/src/examples/ntester.cc index 6e3c409fe..c1660c4d5 100644 --- a/src/examples/ntester.cc +++ b/src/examples/ntester.cc @@ -30,6 +30,8 @@ also delete it here. */ +#include + #include #include @@ -38,7 +40,6 @@ #include "src/util/pty_compat.h" #include "src/network/networktransport-impl.h" #include "src/util/select.h" -#include "src/util/shared.h" using namespace Network; @@ -50,7 +51,7 @@ int main( int argc, char *argv[] ) char *port; UserStream me, remote; - typedef shared::shared_ptr > NetworkPointer; + using NetworkPointer = std::shared_ptr>; Transport *raw_n; try { if ( argc > 1 ) { diff --git a/src/examples/parse.cc b/src/examples/parse.cc index 26c4043b2..1883928d6 100644 --- a/src/examples/parse.cc +++ b/src/examples/parse.cc @@ -32,18 +32,19 @@ #include "src/include/config.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include + #include +#include #if HAVE_PTY_H #include diff --git a/src/examples/termemu.cc b/src/examples/termemu.cc index e8dd3b5f8..8921ac788 100644 --- a/src/examples/termemu.cc +++ b/src/examples/termemu.cc @@ -32,25 +32,26 @@ #include "src/include/config.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include + #include -#include -#include #include +#include +#include #include -#include +#include +#include +#include #if HAVE_PTY_H #include diff --git a/src/frontend/mosh-client.cc b/src/frontend/mosh-client.cc index 9c3db8d69..5fa703db0 100644 --- a/src/frontend/mosh-client.cc +++ b/src/frontend/mosh-client.cc @@ -33,7 +33,8 @@ #include "src/include/config.h" #include "src/include/version.h" -#include +#include + #include #include "stmclient.h" @@ -179,7 +180,7 @@ int main( int argc, char *argv[] ) char *predict_overwrite = getenv( "MOSH_PREDICTION_OVERWRITE" ); /* can be NULL */ - string key( env_key ); + std::string key( env_key ); if ( unsetenv( "MOSH_KEY" ) < 0 ) { perror( "unsetenv" ); diff --git a/src/frontend/mosh-server.cc b/src/frontend/mosh-server.cc index 38d8fc22b..cfbd1706c 100644 --- a/src/frontend/mosh-server.cc +++ b/src/frontend/mosh-server.cc @@ -33,33 +33,34 @@ #include "src/include/config.h" #include "src/include/version.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include +#include + +#include #include -#include -#include +#include +#include +#include +#include #include +#include +#include #include -#include -#include -#include +#include +#include #ifdef HAVE_UTEMPTER #include #endif #ifdef HAVE_SYSLOG #include #endif -#include -#include -#include -#include -#include #ifdef HAVE_UTMPX_H #include @@ -95,7 +96,7 @@ #include "src/network/networktransport-impl.h" -typedef Network::Transport< Terminal::Complete, Network::UserStream > ServerConnection; +using ServerConnection = Network::Transport; static void serve( int host_fd, Terminal::Complete &terminal, @@ -104,7 +105,7 @@ static void serve( int host_fd, long network_signaled_timeout ); static int run_server( const char *desired_ip, const char *desired_port, - const string &command_path, char *command_argv[], + const std::string &command_path, char *command_argv[], const int colors, unsigned int verbose, bool with_motd ); @@ -125,7 +126,7 @@ static void print_usage( FILE *stream, const char *argv0 ) static bool print_motd( const char *filename ); static void chdir_homedir( void ); static bool motd_hushed( void ); -static void warn_unattached( const string & ignore_entry ); +static void warn_unattached( const std::string & ignore_entry ); /* Simple spinloop */ static void spin( void ) @@ -142,19 +143,19 @@ static void spin( void ) } } -static string get_SSH_IP( void ) +static std::string get_SSH_IP( void ) { const char *SSH_CONNECTION = getenv( "SSH_CONNECTION" ); if ( !SSH_CONNECTION ) { /* Older sshds don't set this */ fputs( "Warning: SSH_CONNECTION not found; binding to any interface.\n", stderr ); - return string( "" ); + return std::string( "" ); } std::istringstream ss( SSH_CONNECTION ); - string dummy, local_interface_IP; + std::string dummy, local_interface_IP; ss >> dummy >> dummy >> local_interface_IP; if ( !ss ) { fputs( "Warning: Could not parse SSH_CONNECTION; binding to any interface.\n", stderr ); - return string( "" ); + return std::string( "" ); } /* Strip IPv6 prefix. */ @@ -177,14 +178,14 @@ int main( int argc, char *argv[] ) fatal_assert( argc > 0 ); const char *desired_ip = NULL; - string desired_ip_str; + std::string desired_ip_str; const char *desired_port = NULL; - string command_path; + std::string command_path; char **command_argv = NULL; int colors = 0; unsigned int verbose = 0; /* don't close stdin/stdout/stderr */ /* Will cause mosh-server not to correctly detach on old versions of sshd. */ - list locale_vars; + std::list locale_vars; /* strip off command */ for ( int i = 1; i < argc; i++ ) { @@ -249,7 +250,7 @@ int main( int argc, char *argv[] ) verbose++; break; case 'l': - locale_vars.push_back( string( optarg ) ); + locale_vars.push_back( std::string( optarg ) ); break; default: /* don't die on unknown options */ @@ -286,7 +287,7 @@ int main( int argc, char *argv[] ) /* Get shell */ char *my_argv[ 2 ]; - string shell_name; + std::string shell_name; if ( !command_argv ) { /* get shell name */ const char *shell = getenv( "SHELL" ); @@ -299,7 +300,7 @@ int main( int argc, char *argv[] ) shell = pw->pw_shell; } - string shell_path( shell ); + std::string shell_path( shell ); if ( shell_path.empty() ) { /* empty shell means Bourne shell */ shell_path = _PATH_BSHELL; } @@ -307,7 +308,7 @@ int main( int argc, char *argv[] ) command_path = shell_path; size_t shell_slash( shell_path.rfind('/') ); - if ( shell_slash == string::npos ) { + if ( shell_slash == std::string::npos ) { shell_name = shell_path; } else { shell_name = shell_path.substr(shell_slash + 1); @@ -332,11 +333,11 @@ int main( int argc, char *argv[] ) if ( !is_utf8_locale() ) { /* save details for diagnostic */ LocaleVar native_ctype = get_ctype(); - string native_charset( locale_charset() ); + std::string native_charset( locale_charset() ); /* apply locale-related environment variables from client */ clear_locale_variables(); - for ( list::const_iterator i = locale_vars.begin(); + for ( std::list::const_iterator i = locale_vars.begin(); i != locale_vars.end(); i++ ) { char *env_string = strdup( i->c_str() ); @@ -350,7 +351,7 @@ int main( int argc, char *argv[] ) set_native_locale(); if ( !is_utf8_locale() ) { LocaleVar client_ctype = get_ctype(); - string client_charset( locale_charset() ); + std::string client_charset( locale_charset() ); fprintf( stderr, "mosh-server needs a UTF-8 native locale to run.\n\n" "Unfortunately, the local environment (%s) specifies\n" @@ -377,7 +378,7 @@ int main( int argc, char *argv[] ) } static int run_server( const char *desired_ip, const char *desired_port, - const string &command_path, char *command_argv[], + const std::string &command_path, char *command_argv[], const int colors, unsigned int verbose, bool with_motd ) { /* get network idle timeout */ long network_timeout = 0; @@ -424,7 +425,7 @@ static int run_server( const char *desired_ip, const char *desired_port, /* open network */ Network::UserStream blank; - typedef shared::shared_ptr NetworkPointer; + using NetworkPointer = std::shared_ptr; NetworkPointer network( new ServerConnection( terminal, blank, desired_ip, desired_port ) ); network->set_verbose( verbose ); @@ -723,7 +724,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection & now = Network::timestamp(); uint64_t time_since_remote_state = now - network.get_latest_remote_state().timestamp; - string terminal_to_host; + std::string terminal_to_host; if ( sel.read( network_fd ) ) { /* packet received from the network */ @@ -842,7 +843,7 @@ static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection & if ( bytes_read <= 0 ) { network.start_shutdown(); } else { - terminal_to_host += terminal.act( string( buf, bytes_read ) ); + terminal_to_host += terminal.act( std::string( buf, bytes_read ) ); /* update client with new state of terminal */ network.set_current_state( terminal ); @@ -992,13 +993,13 @@ static bool motd_hushed( void ) #ifdef HAVE_UTMPX_H static bool device_exists( const char *ut_line ) { - string device_name = string( "/dev/" ) + string( ut_line ); + std::string device_name = std::string( "/dev/" ) + std::string( ut_line ); struct stat buf; return 0 == lstat( device_name.c_str(), &buf ); } #endif -static void warn_unattached( const string & ignore_entry ) +static void warn_unattached( const std::string & ignore_entry ) { #ifdef HAVE_UTMPX_H /* get username */ @@ -1009,16 +1010,16 @@ static void warn_unattached( const string & ignore_entry ) return; } - const string username( pw->pw_name ); + const std::string username( pw->pw_name ); /* look for unattached sessions */ - vector< string > unattached_mosh_servers; + std::vector< std::string > unattached_mosh_servers; while ( struct utmpx *entry = getutxent() ) { if ( (entry->ut_type == USER_PROCESS) - && (username == string( entry->ut_user )) ) { + && (username == std::string( entry->ut_user )) ) { /* does line show unattached mosh session */ - string text( entry->ut_host ); + std::string text( entry->ut_host ); if ( (text.size() >= 5) && (text.substr( 0, 5 ) == "mosh ") && (text[ text.size() - 1 ] == ']') @@ -1036,9 +1037,9 @@ static void warn_unattached( const string & ignore_entry ) printf( "\033[37;44mMosh: You have a detached Mosh session on this server (%s).\033[m\n\n", unattached_mosh_servers.front().c_str() ); } else { - string pid_string; + std::string pid_string; - for ( vector< string >::const_iterator it = unattached_mosh_servers.begin(); + for ( std::vector< std::string >::const_iterator it = unattached_mosh_servers.begin(); it != unattached_mosh_servers.end(); it++ ) { pid_string += " - " + *it + "\n"; diff --git a/src/frontend/stmclient.cc b/src/frontend/stmclient.cc index 29cb4f22c..8bec8a7a3 100644 --- a/src/frontend/stmclient.cc +++ b/src/frontend/stmclient.cc @@ -32,18 +32,19 @@ #include "src/include/config.h" +#include +#include +#include +#include +#include +#include +#include + #include -#include -#include -#include -#include -#include -#include +#include #include #include -#include -#include -#include +#include #if HAVE_PTY_H #include @@ -63,8 +64,6 @@ #include "src/network/networktransport-impl.h" -using std::wstring; - void STMClient::resume( void ) { /* Restore termios state */ @@ -84,7 +83,7 @@ void STMClient::init( void ) { if ( !is_utf8_locale() ) { LocaleVar native_ctype = get_ctype(); - string native_charset( locale_charset() ); + std::string native_charset( locale_charset() ); fprintf( stderr, "mosh-client needs a UTF-8 native locale to run.\n\n" "Unfortunately, the client's environment (%s) specifies\n" @@ -123,7 +122,7 @@ void STMClient::init( void ) /* Add our name to window title */ if ( !getenv( "MOSH_TITLE_NOPREFIX" ) ) { - overlays.set_title_prefix( wstring( L"[mosh] " ) ); + overlays.set_title_prefix( std::wstring( L"[mosh] " ) ); } /* Set terminal escape key. */ @@ -185,25 +184,25 @@ void STMClient::init( void ) snprintf(escape_key_name_buf, sizeof escape_key_name_buf, "\"%c\"", escape_key); escape_requires_lf = true; } - string tmp; - tmp = string( escape_pass_name_buf ); - wstring escape_pass_name = std::wstring(tmp.begin(), tmp.end()); - tmp = string( escape_key_name_buf ); - wstring escape_key_name = std::wstring(tmp.begin(), tmp.end()); + std::string tmp; + tmp = std::string( escape_pass_name_buf ); + std::wstring escape_pass_name = std::wstring(tmp.begin(), tmp.end()); + tmp = std::string( escape_key_name_buf ); + std::wstring escape_key_name = std::wstring(tmp.begin(), tmp.end()); escape_key_help = L"Commands: Ctrl-Z suspends, \".\" quits, " + escape_pass_name + L" gives literal " + escape_key_name; overlays.get_notification_engine().set_escape_key_string( tmp ); } wchar_t tmp[ 128 ]; swprintf( tmp, 128, L"Nothing received from server on UDP port %s.", port.c_str() ); - connecting_notification = wstring( tmp ); + connecting_notification = std::wstring( tmp ); } void STMClient::shutdown( void ) { /* Restore screen state */ - overlays.get_notification_engine().set_notification_string( wstring( L"" ) ); + overlays.get_notification_engine().set_notification_string( std::wstring( L"" ) ); overlays.get_notification_engine().server_heard( timestamp() ); - overlays.set_title_prefix( wstring( L"" ) ); + overlays.set_title_prefix( std::wstring( L"" ) ); output_new_frame(); /* Restore terminal and terminal-driver state */ @@ -246,7 +245,7 @@ void STMClient::main_init( void ) new_state = Terminal::Framebuffer( 1, 1 ); /* initialize screen */ - string init = display.new_frame( false, local_framebuffer, local_framebuffer ); + std::string init = display.new_frame( false, local_framebuffer, local_framebuffer ); swrite( STDOUT_FILENO, init.data(), init.size() ); /* open network */ @@ -277,7 +276,7 @@ void STMClient::output_new_frame( void ) overlays.apply( new_state ); /* calculate minimal difference from where we are */ - const string diff( display.new_frame( !repaint_requested, + const std::string diff( display.new_frame( !repaint_requested, local_framebuffer, new_state ) ); swrite( STDOUT_FILENO, diff.data(), diff.size() ); @@ -337,7 +336,7 @@ bool STMClient::process_user_input( int fd ) if ( quit_sequence_started ) { if ( the_byte == '.' ) { /* Quit sequence is Ctrl-^ . */ if ( net.has_remote_addr() && (!net.shutdown_in_progress()) ) { - overlays.get_notification_engine().set_notification_string( wstring( L"Exiting on user request..." ), true ); + overlays.get_notification_engine().set_notification_string( std::wstring( L"Exiting on user request..." ), true ); net.start_shutdown(); return true; } @@ -485,7 +484,7 @@ bool STMClient::main( void ) if ( !network->has_remote_addr() ) { break; } else if ( !network->shutdown_in_progress() ) { - overlays.get_notification_engine().set_notification_string( wstring( L"Exiting..." ), true ); + overlays.get_notification_engine().set_notification_string( std::wstring( L"Exiting..." ), true ); network->start_shutdown(); } } @@ -506,7 +505,7 @@ bool STMClient::main( void ) if ( !network->has_remote_addr() ) { break; } else if ( !network->shutdown_in_progress() ) { - overlays.get_notification_engine().set_notification_string( wstring( L"Signal received, shutting down..." ), true ); + overlays.get_notification_engine().set_notification_string( std::wstring( L"Signal received, shutting down..." ), true ); network->start_shutdown(); } } @@ -534,7 +533,7 @@ bool STMClient::main( void ) && (timestamp() - network->get_latest_remote_state().timestamp > 250) ) { if ( timestamp() - network->get_latest_remote_state().timestamp > 15000 ) { if ( !network->shutdown_in_progress() ) { - overlays.get_notification_engine().set_notification_string( wstring( L"Timed out waiting for server..." ), true ); + overlays.get_notification_engine().set_notification_string( std::wstring( L"Timed out waiting for server..." ), true ); network->start_shutdown(); } } else { @@ -548,7 +547,7 @@ bool STMClient::main( void ) network->tick(); - string & send_error = network->get_send_error(); + std::string & send_error = network->get_send_error(); if ( !send_error.empty() ) { overlays.get_notification_engine().set_network_error( send_error ); send_error.clear(); @@ -571,7 +570,7 @@ bool STMClient::main( void ) } else { wchar_t tmp[ 128 ]; swprintf( tmp, 128, L"Crypto exception: %s", e.what() ); - overlays.get_notification_engine().set_notification_string( wstring( tmp ) ); + overlays.get_notification_engine().set_notification_string( std::wstring( tmp ) ); } } } diff --git a/src/frontend/stmclient.h b/src/frontend/stmclient.h index 12a951255..09084ddac 100644 --- a/src/frontend/stmclient.h +++ b/src/frontend/stmclient.h @@ -33,14 +33,15 @@ #ifndef STM_CLIENT_HPP #define STM_CLIENT_HPP +#include +#include + #include #include -#include #include "src/statesync/completeterminal.h" #include "src/network/networktransport.h" #include "src/statesync/user.h" -#include "src/util/shared.h" #include "src/frontend/terminaloverlay.h" class STMClient { @@ -61,8 +62,8 @@ class STMClient { Terminal::Framebuffer local_framebuffer, new_state; Overlay::OverlayManager overlays; - typedef Network::Transport< Network::UserStream, Terminal::Complete > NetworkType; - typedef shared::shared_ptr< NetworkType > NetworkPointer; + using NetworkType = Network::Transport; + using NetworkPointer = std::shared_ptr; NetworkPointer network; Terminal::Display display; diff --git a/src/frontend/terminaloverlay.cc b/src/frontend/terminaloverlay.cc index efbdaba6b..d8a387245 100644 --- a/src/frontend/terminaloverlay.cc +++ b/src/frontend/terminaloverlay.cc @@ -31,10 +31,10 @@ */ #include -#include +#include +#include #include #include -#include #include "src/frontend/terminaloverlay.h" @@ -100,7 +100,7 @@ Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb, int row, } if ( current.contents_match( replacement ) ) { - vector::const_iterator it = original_contents.begin(); + std::vector::const_iterator it = original_contents.begin(); for ( ; it != original_contents.end(); it++ ) { if ( it->contents_match( replacement ) ) break; @@ -248,14 +248,14 @@ void NotificationEngine::apply( Framebuffer &fb ) const explanation, keystroke_str ); } - wstring string_to_draw( tmp ); + std::wstring string_to_draw( tmp ); int overlay_col = 0; Cell *combining_cell = fb.get_mutable_cell( 0, 0 ); /* We unfortunately duplicate the terminal's logic for how to render a Unicode sequence into graphemes */ - for ( wstring::const_iterator i = string_to_draw.begin(); i != string_to_draw.end(); i++ ) { + for ( std::wstring::const_iterator i = string_to_draw.begin(); i != string_to_draw.end(); i++ ) { if ( overlay_col >= fb.ds.get_width() ) { break; } @@ -339,7 +339,7 @@ void OverlayManager::apply( Framebuffer &fb ) title.apply( fb ); } -void TitleEngine::set_prefix( const wstring &s ) +void TitleEngine::set_prefix( const std::wstring &s ) { prefix = Terminal::Framebuffer::title_type( s.begin(), s.end() ); } @@ -615,7 +615,7 @@ void PredictionEngine::cull( const Framebuffer &fb ) /* NB: switching from list to another STL container could break this code. So we don't use the cursors_type typedef. */ - for ( list::iterator it = cursors.begin(); + for ( std::list::iterator it = cursors.begin(); it != cursors.end(); ) { if ( it->get_validity( fb, local_frame_acked, local_frame_late_acked ) != Pending ) { it = cursors.erase( it ); diff --git a/src/frontend/terminaloverlay.h b/src/frontend/terminaloverlay.h index 16b502950..70c64e7aa 100644 --- a/src/frontend/terminaloverlay.h +++ b/src/frontend/terminaloverlay.h @@ -38,16 +38,12 @@ #include "src/network/transportsender.h" #include "src/terminal/parser.h" +#include #include -#include namespace Overlay { using namespace Terminal; using namespace Network; - using std::deque; - using std::list; - using std::vector; - using std::wstring; enum Validity { Pending, @@ -99,8 +95,8 @@ namespace Overlay { Cell replacement; bool unknown; - vector original_contents; /* we don't give credit for correct predictions - that match the original contents */ + std::vector original_contents; /* we don't give credit for correct predictions + that match the original contents */ void apply( Framebuffer &fb, uint64_t confirmed_epoch, int row, bool flag ) const; Validity get_validity( const Framebuffer &fb, int row, uint64_t early_ack, uint64_t late_ack ) const; @@ -128,7 +124,7 @@ namespace Overlay { public: int row_num; - typedef vector overlay_cells_type; + using overlay_cells_type = std::vector; overlay_cells_type overlay_cells; void apply( Framebuffer &fb, uint64_t confirmed_epoch, bool flag ) const; @@ -141,8 +137,8 @@ namespace Overlay { private: uint64_t last_word_from_server; uint64_t last_acked_state; - string escape_key_string; - wstring message; + std::string escape_key_string; + std::wstring message; bool message_is_network_error; uint64_t message_expiration; bool show_quit_keystroke; @@ -154,12 +150,12 @@ namespace Overlay { public: void adjust_message( void ); void apply( Framebuffer &fb ) const; - const wstring &get_notification_string( void ) const { return message; } + const std::wstring &get_notification_string( void ) const { return message; } void server_heard( uint64_t s_last_word ) { last_word_from_server = s_last_word; } void server_acked( uint64_t s_last_acked ) { last_acked_state = s_last_acked; } int wait_time( void ) const; - void set_notification_string( const wstring &s_message, bool permanent = false, bool s_show_quit_keystroke = true ) + void set_notification_string( const std::wstring &s_message, bool permanent = false, bool s_show_quit_keystroke = true ) { message = s_message; if ( permanent ) { @@ -171,7 +167,7 @@ namespace Overlay { show_quit_keystroke = s_show_quit_keystroke; } - void set_escape_key_string( const string &s_name ) + void set_escape_key_string( const std::string &s_name ) { char tmp[ 128 ]; snprintf( tmp, sizeof tmp, " [To quit: %s .]", s_name.c_str() ); @@ -215,13 +211,13 @@ namespace Overlay { char last_byte; Parser::UTF8Parser parser; - typedef list overlays_type; + using overlays_type = std::list; overlays_type overlays; - typedef list cursors_type; + using cursors_type = std::list; cursors_type cursors; - typedef ConditionalOverlayRow::overlay_cells_type overlay_cells_type; + using overlay_cells_type = ConditionalOverlayRow::overlay_cells_type; uint64_t local_frame_sent, local_frame_acked, local_frame_late_acked; @@ -314,7 +310,7 @@ namespace Overlay { public: void apply( Framebuffer &fb ) const { fb.prefix_window_title( prefix ); } TitleEngine() : prefix() {} - void set_prefix( const wstring &s ); + void set_prefix( const std::wstring &s ); }; /* the overlay manager */ @@ -330,7 +326,7 @@ namespace Overlay { NotificationEngine & get_notification_engine( void ) { return notifications; } PredictionEngine & get_prediction_engine( void ) { return predictions; } - void set_title_prefix( const wstring &s ) { title.set_prefix( s ); } + void set_title_prefix( const std::wstring &s ) { title.set_prefix( s ); } OverlayManager() : notifications(), predictions(), title() {} diff --git a/src/network/compressor.cc b/src/network/compressor.cc index 2056f6baa..ec49270b2 100644 --- a/src/network/compressor.cc +++ b/src/network/compressor.cc @@ -36,24 +36,23 @@ #include "src/util/dos_assert.h" using namespace Network; -using std::string; -string Compressor::compress_str( const string &input ) +std::string Compressor::compress_str( const std::string &input ) { long unsigned int len = BUFFER_SIZE; dos_assert( Z_OK == compress( buffer, &len, reinterpret_cast( input.data() ), input.size() ) ); - return string( reinterpret_cast( buffer ), len ); + return std::string( reinterpret_cast( buffer ), len ); } -string Compressor::uncompress_str( const string &input ) +std::string Compressor::uncompress_str( const std::string &input ) { long unsigned int len = BUFFER_SIZE; dos_assert( Z_OK == uncompress( buffer, &len, reinterpret_cast( input.data() ), input.size() ) ); - return string( reinterpret_cast( buffer ), len ); + return std::string( reinterpret_cast( buffer ), len ); } /* construct on first use */ diff --git a/src/network/network.cc b/src/network/network.cc index d4168cc5a..2b11fe77f 100644 --- a/src/network/network.cc +++ b/src/network/network.cc @@ -32,6 +32,10 @@ #include "src/include/config.h" +#include +#include +#include + #include #include #ifdef HAVE_SYS_UIO_H @@ -39,9 +43,6 @@ #endif #include #include -#include -#include -#include #include #include "src/util/dos_assert.h" @@ -80,7 +81,7 @@ Packet::Packet( const Message & message ) timestamp = be16toh( data[ 0 ] ); timestamp_reply = be16toh( data[ 1 ] ); - payload = string( message.text.begin() + 2 * sizeof( uint16_t ), message.text.end() ); + payload = std::string( message.text.begin() + 2 * sizeof( uint16_t ), message.text.end() ); } /* Output from packet */ @@ -91,12 +92,12 @@ Message Packet::toMessage( void ) uint16_t ts_net[ 2 ] = { static_cast( htobe16( timestamp ) ), static_cast( htobe16( timestamp_reply ) ) }; - string timestamps = string( (char *)ts_net, 2 * sizeof( uint16_t ) ); + std::string timestamps = std::string( (char *)ts_net, 2 * sizeof( uint16_t ) ); return Message( Nonce( direction_seq ), timestamps + payload ); } -Packet Connection::new_packet( const string &s_payload ) +Packet Connection::new_packet( const std::string &s_payload ) { uint16_t outgoing_timestamp_reply = -1; @@ -391,7 +392,7 @@ Connection::Connection( const char *key_str, const char *ip, const char *port ) set_MTU( remote_addr.sa.sa_family ); } -void Connection::send( const string & s ) +void Connection::send( const std::string & s ) { if ( !has_remote_addr ) { return; @@ -399,7 +400,7 @@ void Connection::send( const string & s ) Packet px = new_packet( s ); - string p = session.encrypt( px.toMessage() ); + std::string p = session.encrypt( px.toMessage() ); ssize_t bytes_sent = sendto( sock(), p.data(), p.size(), MSG_DONTWAIT, &remote_addr.sa, remote_addr_len ); @@ -428,13 +429,13 @@ void Connection::send( const string & s ) } } -string Connection::recv( void ) +std::string Connection::recv( void ) { assert( !socks.empty() ); for ( std::deque< Socket >::const_iterator it = socks.begin(); it != socks.end(); it++ ) { - string payload; + std::string payload; try { payload = recv_one( it->fd()); } catch ( NetworkException & e ) { @@ -453,7 +454,7 @@ string Connection::recv( void ) throw NetworkException( "No packet received" ); } -string Connection::recv_one( int sock_to_recv ) +std::string Connection::recv_one( int sock_to_recv ) { /* receive source address, ECN, and payload in msghdr structure */ Addr packet_remote_addr; diff --git a/src/network/network.h b/src/network/network.h index 471aaf5e6..56c37fb97 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -33,16 +33,17 @@ #ifndef NETWORK_HPP #define NETWORK_HPP -#include +#include +#include +#include +#include #include -#include -#include +#include #include -#include #include -#include -#include -#include + +#include +#include #include "src/crypto/crypto.h" @@ -57,12 +58,12 @@ namespace Network { class NetworkException : public std::exception { public: - string function; + std::string function; int the_errno; private: - string my_what; + std::string my_what; public: - NetworkException( string s_function="", int s_errno=0) + NetworkException( std::string s_function="", int s_errno=0) : function( s_function ), the_errno( s_errno ), my_what(function + ": " + strerror(the_errno)) {} const char *what() const throw () { return my_what.c_str(); } @@ -79,10 +80,10 @@ namespace Network { const uint64_t seq; Direction direction; uint16_t timestamp, timestamp_reply; - string payload; + std::string payload; Packet( Direction s_direction, - uint16_t s_timestamp, uint16_t s_timestamp_reply, const string & s_payload ) + uint16_t s_timestamp, uint16_t s_timestamp_reply, const std::string & s_payload ) : seq( Crypto::unique() ), direction( s_direction ), timestamp( s_timestamp ), timestamp_reply( s_timestamp_reply ), payload( s_payload ) {} @@ -188,9 +189,9 @@ namespace Network { double RTTVAR; /* Error from send()/sendto(). */ - string send_error; + std::string send_error; - Packet new_packet( const string &s_payload ); + Packet new_packet( const std::string &s_payload ); void hop_port( void ); @@ -198,7 +199,7 @@ namespace Network { void prune_sockets( void ); - string recv_one( int sock_to_recv ); + std::string recv_one( int sock_to_recv ); void set_MTU( int family ); @@ -209,13 +210,13 @@ 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( const string & s ); - string recv( void ); + void send( const std::string & s ); + std::string recv( void ); const std::vector< int > fds( void ) const; int get_MTU( void ) const { return MTU; } std::string port( void ) const; - string get_key( void ) const { return key.printable_key(); } + std::string get_key( void ) const { return key.printable_key(); } bool get_has_remote_addr( void ) const { return has_remote_addr; } uint64_t timeout( void ) const; @@ -224,7 +225,7 @@ namespace Network { const Addr &get_remote_addr( void ) const { return remote_addr; } socklen_t get_remote_addr_len( void ) const { return remote_addr_len; } - string &get_send_error( void ) + std::string &get_send_error( void ) { return send_error; } diff --git a/src/network/networktransport-impl.h b/src/network/networktransport-impl.h index b3dc522f4..61c9cd7bb 100644 --- a/src/network/networktransport-impl.h +++ b/src/network/networktransport-impl.h @@ -70,7 +70,7 @@ Transport::Transport( MyState &initial_state, RemoteState template void Transport::recv( void ) { - string s( connection.recv() ); + std::string s( connection.recv() ); Fragment frag( s ); if ( fragments.add_fragment( frag ) ) { /* complete packet */ @@ -86,7 +86,7 @@ void Transport::recv( void ) connection.set_last_roundtrip_success( sender.get_sent_state_acked_timestamp() ); /* first, make sure we don't already have the new state */ - for ( typename list< TimestampedState >::iterator i = received_states.begin(); + for ( typename std::list< TimestampedState >::iterator i = received_states.begin(); i != received_states.end(); i++ ) { if ( inst.new_num() == i->num ) { @@ -96,7 +96,7 @@ void Transport::recv( void ) /* now, make sure we do have the old state */ bool found = 0; - typename list< TimestampedState >::iterator reference_state = received_states.begin(); + typename std::list< TimestampedState >::iterator reference_state = received_states.begin(); while ( reference_state != received_states.end() ) { if ( inst.old_num() == reference_state->num ) { found = true; @@ -140,7 +140,7 @@ void Transport::recv( void ) } /* Insert new state in sorted place */ - for ( typename list< TimestampedState >::iterator i = received_states.begin(); + for ( typename std::list< TimestampedState >::iterator i = received_states.begin(); i != received_states.end(); i++ ) { if ( i->num > new_state.num ) { @@ -170,9 +170,9 @@ void Transport::recv( void ) template void Transport::process_throwaway_until( uint64_t throwaway_num ) { - typename list< TimestampedState >::iterator i = received_states.begin(); + typename std::list< TimestampedState >::iterator i = received_states.begin(); while ( i != received_states.end() ) { - typename list< TimestampedState >::iterator inext = i; + typename std::list< TimestampedState >::iterator inext = i; inext++; if ( i->num < throwaway_num ) { received_states.erase( i ); @@ -184,15 +184,15 @@ void Transport::process_throwaway_until( uint64_t throwawa } template -string Transport::get_remote_diff( void ) +std::string Transport::get_remote_diff( void ) { /* find diff between last receiver state and current remote state, then rationalize states */ - string ret( received_states.back().state.diff_from( last_receiver_state ) ); + std::string ret( received_states.back().state.diff_from( last_receiver_state ) ); const RemoteState *oldest_receiver_state = &received_states.front().state; - for ( typename list< TimestampedState >::reverse_iterator i = received_states.rbegin(); + for ( typename std::list< TimestampedState >::reverse_iterator i = received_states.rbegin(); i != received_states.rend(); i++ ) { i->state.subtract( oldest_receiver_state ); diff --git a/src/network/networktransport.h b/src/network/networktransport.h index 3fcbd2229..55209d5bd 100644 --- a/src/network/networktransport.h +++ b/src/network/networktransport.h @@ -33,17 +33,16 @@ #ifndef NETWORK_TRANSPORT_HPP #define NETWORK_TRANSPORT_HPP -#include -#include -#include +#include +#include #include +#include #include #include "src/network/network.h" #include "src/network/transportsender.h" #include "transportfragment.h" - namespace Network { template class Transport @@ -59,7 +58,7 @@ namespace Network { void process_throwaway_until( uint64_t throwaway_num ); /* simple receiver */ - list< TimestampedState > received_states; + std::list< TimestampedState > received_states; uint64_t receiver_quench_timer; RemoteState last_receiver_state; /* the state we were in when user last queried state */ FragmentAssembly fragments; @@ -81,7 +80,7 @@ namespace Network { void recv( void ); /* Find diff between last receiver state and current remote state, then rationalize states. */ - string get_remote_diff( void ); + std::string get_remote_diff( void ); /* Shut down other side of connection. */ /* Illegal to change current_state after this. */ @@ -95,7 +94,7 @@ namespace Network { bool counterparty_shutdown_ack_sent( void ) const { return sender.get_counterparty_shutdown_acknowledged(); } std::string port( void ) const { return connection.port(); } - string get_key( void ) const { return connection.get_key(); } + std::string get_key( void ) const { return connection.get_key(); } MyState &get_current_state( void ) { return sender.get_current_state(); } void set_current_state( const MyState &x ) { sender.set_current_state( x ); } diff --git a/src/network/transportfragment.cc b/src/network/transportfragment.cc index f68982832..004e4d7e5 100644 --- a/src/network/transportfragment.cc +++ b/src/network/transportfragment.cc @@ -30,7 +30,7 @@ also delete it here. */ -#include +#include #include "src/crypto/byteorder.h" #include "transportfragment.h" @@ -41,23 +41,23 @@ using namespace Network; using namespace TransportBuffers; -static string network_order_string( uint16_t host_order ) +static std::string network_order_string( uint16_t host_order ) { uint16_t net_int = htobe16( host_order ); - return string( (char *)&net_int, sizeof( net_int ) ); + return std::string( (char *)&net_int, sizeof( net_int ) ); } -static string network_order_string( uint64_t host_order ) +static std::string network_order_string( uint64_t host_order ) { uint64_t net_int = htobe64( host_order ); - return string( (char *)&net_int, sizeof( net_int ) ); + return std::string( (char *)&net_int, sizeof( net_int ) ); } -string Fragment::tostring( void ) +std::string Fragment::tostring( void ) { assert( initialized ); - string ret; + std::string ret; ret += network_order_string( id ); @@ -72,12 +72,12 @@ string Fragment::tostring( void ) return ret; } -Fragment::Fragment( const string &x ) +Fragment::Fragment( const std::string &x ) : id( -1 ), fragment_num( -1 ), final( false ), initialized( true ), contents() { fatal_assert( x.size() >= frag_header_len ); - contents = string( x.begin() + frag_header_len, x.end() ); + contents = std::string( x.begin() + frag_header_len, x.end() ); uint64_t data64; uint16_t *data16 = (uint16_t *)x.data(); @@ -131,7 +131,7 @@ Instruction FragmentAssembly::get_assembly( void ) { assert( fragments_arrived == fragments_total ); - string encoded; + std::string encoded; for ( int i = 0; i < fragments_total; i++ ) { assert( fragments.at( i ).initialized ); @@ -154,7 +154,7 @@ bool Fragment::operator==( const Fragment &x ) const && ( initialized == x.initialized ) && ( contents == x.contents ); } -vector Fragmenter::make_fragments( const Instruction &inst, size_t MTU ) +std::vector Fragmenter::make_fragments( const Instruction &inst, size_t MTU ) { MTU -= Fragment::frag_header_len; if ( (inst.old_num() != last_instruction.old_num()) @@ -175,17 +175,17 @@ vector Fragmenter::make_fragments( const Instruction &inst, size_t MTU last_instruction = inst; last_MTU = MTU; - string payload = get_compressor().compress_str( inst.SerializeAsString() ); + std::string payload = get_compressor().compress_str( inst.SerializeAsString() ); uint16_t fragment_num = 0; - vector ret; + std::vector ret; while ( !payload.empty() ) { - string this_fragment; + std::string this_fragment; bool final = false; if ( payload.size() > MTU ) { - this_fragment = string( payload.begin(), payload.begin() + MTU ); - payload = string( payload.begin() + MTU, payload.end() ); + this_fragment = std::string( payload.begin(), payload.begin() + MTU ); + payload = std::string( payload.begin() + MTU, payload.end() ); } else { this_fragment = payload; payload.clear(); diff --git a/src/network/transportfragment.h b/src/network/transportfragment.h index 1e7fa92dd..ff0954227 100644 --- a/src/network/transportfragment.h +++ b/src/network/transportfragment.h @@ -33,15 +33,13 @@ #ifndef TRANSPORT_FRAGMENT_HPP #define TRANSPORT_FRAGMENT_HPP -#include -#include +#include #include +#include #include "src/protobufs/transportinstruction.pb.h" namespace Network { - using std::vector; - using std::string; using namespace TransportBuffers; class Fragment @@ -55,20 +53,20 @@ namespace Network { bool initialized; - string contents; + std::string contents; Fragment() : id( -1 ), fragment_num( -1 ), final( false ), initialized( false ), contents() {} - Fragment( uint64_t s_id, uint16_t s_fragment_num, bool s_final, const string & s_contents ) + Fragment( uint64_t s_id, uint16_t s_fragment_num, bool s_final, const std::string & s_contents ) : id( s_id ), fragment_num( s_fragment_num ), final( s_final ), initialized( true ), contents( s_contents ) {} - Fragment( const string &x ); + Fragment( const std::string &x ); - string tostring( void ); + std::string tostring( void ); bool operator==( const Fragment &x ) const; }; @@ -76,7 +74,7 @@ namespace Network { class FragmentAssembly { private: - vector fragments; + std::vector fragments; uint64_t current_id; int fragments_arrived, fragments_total; @@ -99,7 +97,7 @@ namespace Network { last_instruction.set_old_num( -1 ); last_instruction.set_new_num( -1 ); } - vector make_fragments( const Instruction &inst, size_t MTU ); + std::vector make_fragments( const Instruction &inst, size_t MTU ); uint64_t last_ack_sent( void ) const { return last_instruction.ack_num(); } }; diff --git a/src/network/transportsender-impl.h b/src/network/transportsender-impl.h index 74a3c34dd..3c8cf6ffc 100644 --- a/src/network/transportsender-impl.h +++ b/src/network/transportsender-impl.h @@ -34,16 +34,15 @@ #define TRANSPORT_SENDER_IMPL_HPP #include +#include +#include +#include +#include #include -#include -#include -#include #include "src/network/transportsender.h" #include "transportfragment.h" -#include - using namespace Network; template @@ -167,7 +166,7 @@ void TransportSender::tick( void ) /* Determine if a new diff or empty ack needs to be sent */ - string diff = current_state.diff_from( assumed_receiver_state->state ); + std::string diff = current_state.diff_from( assumed_receiver_state->state ); attempt_prospective_resend_optimization( diff ); @@ -236,7 +235,7 @@ void TransportSender::add_sent_state( uint64_t the_timestamp, uint64_t } template -void TransportSender::send_to_receiver( const string & diff ) +void TransportSender::send_to_receiver( const std::string & diff ) { uint64_t new_num; if ( current_state == sent_states.back().state ) { /* previously sent */ @@ -275,7 +274,7 @@ void TransportSender::update_assumed_receiver_state( void ) transmitted recently enough ago */ assumed_receiver_state = sent_states.begin(); - typename list< TimestampedState >::iterator i = sent_states.begin(); + typename std::list< TimestampedState >::iterator i = sent_states.begin(); i++; while ( i != sent_states.end() ) { @@ -298,7 +297,7 @@ void TransportSender::rationalize_states( void ) current_state.subtract( known_receiver_state ); - for ( typename list< TimestampedState >::reverse_iterator i = sent_states.rbegin(); + for ( typename std::list< TimestampedState >::reverse_iterator i = sent_states.rbegin(); i != sent_states.rend(); i++ ) { i->state.subtract( known_receiver_state ); @@ -306,18 +305,18 @@ void TransportSender::rationalize_states( void ) } template -const string TransportSender::make_chaff( void ) +const std::string TransportSender::make_chaff( void ) { const size_t CHAFF_MAX = 16; const size_t chaff_len = prng.uint8() % (CHAFF_MAX + 1); char chaff[ CHAFF_MAX ]; prng.fill( chaff, chaff_len ); - return string( chaff, chaff_len ); + return std::string( chaff, chaff_len ); } template -void TransportSender::send_in_fragments( const string & diff, uint64_t new_num ) +void TransportSender::send_in_fragments( const std::string & diff, uint64_t new_num ) { Instruction inst; @@ -333,10 +332,10 @@ void TransportSender::send_in_fragments( const string & diff, uint64_t shutdown_tries++; } - vector fragments = fragmenter.make_fragments( inst, connection->get_MTU() - - Network::Connection::ADDED_BYTES - - Crypto::Session::ADDED_BYTES ); - for ( vector::iterator i = fragments.begin(); + std::vector fragments = fragmenter.make_fragments( inst, connection->get_MTU() + - Network::Connection::ADDED_BYTES + - Crypto::Session::ADDED_BYTES ); + for ( std::vector::iterator i = fragments.begin(); i != fragments.end(); i++ ) { connection->send( i->tostring() ); @@ -404,13 +403,13 @@ void TransportSender::set_ack_num( uint64_t s_ack_num ) /* Investigate diff against known receiver state instead */ /* Mutates proposed_diff */ template -void TransportSender::attempt_prospective_resend_optimization( string &proposed_diff ) +void TransportSender::attempt_prospective_resend_optimization( std::string &proposed_diff ) { if ( assumed_receiver_state == sent_states.begin() ) { return; } - string resend_diff = current_state.diff_from( sent_states.front().state ); + std::string resend_diff = current_state.diff_from( sent_states.front().state ); /* We do a prophylactic resend if it would make the diff shorter, or if it would lengthen it by no more than 100 bytes and still be diff --git a/src/network/transportsender.h b/src/network/transportsender.h index 5b89e9cda..27fd2af91 100644 --- a/src/network/transportsender.h +++ b/src/network/transportsender.h @@ -44,8 +44,6 @@ #include "src/crypto/prng.h" namespace Network { - using std::list; - using std::pair; using namespace TransportBuffers; /* timing parameters */ @@ -62,11 +60,11 @@ namespace Network { private: /* helper methods for tick() */ void update_assumed_receiver_state( void ); - void attempt_prospective_resend_optimization( string &proposed_diff ); + void attempt_prospective_resend_optimization( std::string &proposed_diff ); void rationalize_states( void ); - void send_to_receiver( const string & diff ); + void send_to_receiver( const std::string & diff ); void send_empty_ack( void ); - void send_in_fragments( const string & diff, uint64_t new_num ); + void send_in_fragments( const std::string & diff, uint64_t new_num ); void add_sent_state( uint64_t the_timestamp, uint64_t num, MyState &state ); /* state of sender */ @@ -74,7 +72,7 @@ namespace Network { MyState current_state; - typedef list< TimestampedState > sent_states_type; + using sent_states_type = std::list>; sent_states_type sent_states; /* first element: known, acknowledged receiver state */ /* last element: last sent state */ @@ -106,7 +104,7 @@ namespace Network { /* chaff to disguise instruction length */ PRNG prng; - const string make_chaff( void ); + const std::string make_chaff( void ); uint64_t mindelay_clock; /* time of first pending change to current state */ diff --git a/src/statesync/completeterminal.cc b/src/statesync/completeterminal.cc index 47a5c74a3..1f8fed72a 100644 --- a/src/statesync/completeterminal.cc +++ b/src/statesync/completeterminal.cc @@ -30,12 +30,11 @@ also delete it here. */ -#include "src/statesync/completeterminal.h" -#include "src/util/fatal_assert.h" +#include #include "src/protobufs/hostinput.pb.h" - -#include +#include "src/statesync/completeterminal.h" +#include "src/util/fatal_assert.h" using namespace std; using namespace Parser; diff --git a/src/statesync/completeterminal.h b/src/statesync/completeterminal.h index 34f9a96cc..e1264621f 100644 --- a/src/statesync/completeterminal.h +++ b/src/statesync/completeterminal.h @@ -33,8 +33,8 @@ #ifndef COMPLETE_TERMINAL_HPP #define COMPLETE_TERMINAL_HPP +#include #include -#include #include "src/terminal/parser.h" #include "src/terminal/terminal.h" @@ -53,7 +53,7 @@ namespace Terminal { // outside calls to act() to keep horrible things from happening. Parser::Actions actions; - typedef std::list< std::pair > input_history_type; + using input_history_type = std::list>; input_history_type input_history; uint64_t echo_ack; diff --git a/src/statesync/user.cc b/src/statesync/user.cc index 3315c4d54..0b1073ed7 100644 --- a/src/statesync/user.cc +++ b/src/statesync/user.cc @@ -30,7 +30,7 @@ also delete it here. */ -#include +#include #include #include "src/statesync/user.h" @@ -43,12 +43,12 @@ using namespace ClientBuffers; void UserStream::subtract( const UserStream *prefix ) { - // if we are subtracting ourself from ourself, just clear the deque + // if we are subtracting ourself from ourself, just clear the std::deque if ( this == prefix ) { actions.clear(); return; } - for ( deque::const_iterator i = prefix->actions.begin(); + for ( std::deque::const_iterator i = prefix->actions.begin(); i != prefix->actions.end(); i++ ) { assert( this != prefix ); @@ -58,11 +58,11 @@ void UserStream::subtract( const UserStream *prefix ) } } -string UserStream::diff_from( const UserStream &existing ) const +std::string UserStream::diff_from( const UserStream &existing ) const { - deque::const_iterator my_it = actions.begin(); + std::deque::const_iterator my_it = actions.begin(); - for ( deque::const_iterator i = existing.actions.begin(); + for ( std::deque::const_iterator i = existing.actions.begin(); i != existing.actions.end(); i++ ) { assert( my_it != actions.end() ); @@ -80,7 +80,7 @@ string UserStream::diff_from( const UserStream &existing ) const /* can we combine this with a previous Keystroke? */ if ( (output.instruction_size() > 0) && (output.instruction( output.instruction_size() - 1 ).HasExtension( keystroke )) ) { - output.mutable_instruction( output.instruction_size() - 1 )->MutableExtension( keystroke )->mutable_keys()->append( string( &the_byte, 1 ) ); + output.mutable_instruction( output.instruction_size() - 1 )->MutableExtension( keystroke )->mutable_keys()->append( std::string( &the_byte, 1 ) ); } else { Instruction *new_inst = output.add_instruction(); new_inst->MutableExtension( keystroke )->set_keys( &the_byte, 1 ); @@ -105,14 +105,14 @@ string UserStream::diff_from( const UserStream &existing ) const return output.SerializeAsString(); } -void UserStream::apply_string( const string &diff ) +void UserStream::apply_string( const std::string &diff ) { ClientBuffers::UserMessage input; fatal_assert( input.ParseFromString( diff ) ); for ( int i = 0; i < input.instruction_size(); i++ ) { if ( input.instruction( i ).HasExtension( keystroke ) ) { - string the_bytes = input.instruction( i ).GetExtension( keystroke ).keys(); + std::string the_bytes = input.instruction( i ).GetExtension( keystroke ).keys(); for ( unsigned int loc = 0; loc < the_bytes.size(); loc++ ) { actions.push_back( UserEvent( UserByte( the_bytes.at( loc ) ) ) ); } diff --git a/src/statesync/user.h b/src/statesync/user.h index fa905e50a..a3257b63d 100644 --- a/src/statesync/user.h +++ b/src/statesync/user.h @@ -33,18 +33,14 @@ #ifndef USER_HPP #define USER_HPP +#include #include #include #include -#include #include "src/terminal/parseraction.h" namespace Network { - using std::deque; - using std::list; - using std::string; - enum UserEventType { UserByteType = 0, ResizeType = 1 @@ -70,7 +66,7 @@ namespace Network { class UserStream { private: - deque actions; + std::deque actions; public: UserStream() : actions() {} @@ -84,9 +80,9 @@ namespace Network { /* interface for Network::Transport */ void subtract( const UserStream *prefix ); - string diff_from( const UserStream &existing ) const; - string init_diff( void ) const { return diff_from( UserStream() ); }; - void apply_string( const string &diff ); + std::string diff_from( const UserStream &existing ) const; + std::string init_diff( void ) const { return diff_from( UserStream() ); }; + void apply_string( const std::string &diff ); bool operator==( const UserStream &x ) const { return actions == x.actions; } bool compare( const UserStream & ) { return false; } diff --git a/src/terminal/parser.cc b/src/terminal/parser.cc index d1f00b762..7ab3ca484 100644 --- a/src/terminal/parser.cc +++ b/src/terminal/parser.cc @@ -30,11 +30,11 @@ also delete it here. */ -#include +#include +#include +#include +#include #include -#include -#include -#include #include "src/terminal/parser.h" diff --git a/src/terminal/parser.h b/src/terminal/parser.h index f76096c29..f1876c924 100644 --- a/src/terminal/parser.h +++ b/src/terminal/parser.h @@ -36,8 +36,8 @@ /* Based on Paul Williams's parser, http://www.vt100.net/emu/dec_ansi_parser */ -#include -#include +#include +#include #include "parsertransition.h" #include "src/terminal/parseraction.h" diff --git a/src/terminal/parseraction.cc b/src/terminal/parseraction.cc index 531d2a932..4ca2b0609 100644 --- a/src/terminal/parseraction.cc +++ b/src/terminal/parseraction.cc @@ -30,8 +30,8 @@ also delete it here. */ -#include -#include +#include +#include #include "src/terminal/parseraction.h" #include "src/terminal/terminal.h" diff --git a/src/terminal/parseraction.h b/src/terminal/parseraction.h index 5a6c8ca7e..bb369808c 100644 --- a/src/terminal/parseraction.h +++ b/src/terminal/parseraction.h @@ -33,11 +33,10 @@ #ifndef PARSERACTION_HPP #define PARSERACTION_HPP +#include #include #include -#include "src/util/shared.h" - namespace Terminal { class Emulator; } @@ -59,8 +58,8 @@ namespace Parser { virtual ~Action() {}; }; - typedef shared::shared_ptr ActionPointer; - typedef std::vector Actions; + using ActionPointer = std::shared_ptr; + using Actions = std::vector; class Ignore : public Action { public: diff --git a/src/terminal/parserstate.cc b/src/terminal/parserstate.cc index 3d60170f7..094c3283d 100644 --- a/src/terminal/parserstate.cc +++ b/src/terminal/parserstate.cc @@ -30,9 +30,10 @@ also delete it here. */ +#include + #include "parserstate.h" #include "parserstatefamily.h" -#include "src/util/shared.h" using namespace Parser; @@ -42,7 +43,7 @@ Transition State::anywhere_rule( wchar_t ch ) const || ((0x80 <= ch) && (ch <= 0x8F)) || ((0x91 <= ch) && (ch <= 0x97)) || (ch == 0x99) || (ch == 0x9A) ) { - return Transition( shared::make_shared(), &family->s_Ground ); + return Transition( std::make_shared(), &family->s_Ground ); } else if ( ch == 0x9C ) { return Transition( &family->s_Ground ); } else if ( ch == 0x1B ) { @@ -93,11 +94,11 @@ static bool GLGR ( wchar_t ch ) Transition Ground::input_state_rule( wchar_t ch ) const { if ( C0_prime( ch ) ) { - return Transition( shared::make_shared< Execute >() ); + return Transition( std::make_shared() ); } if ( GLGR( ch ) ) { - return Transition( shared::make_shared< Print >() ); + return Transition( std::make_shared() ); } return Transition(); @@ -105,17 +106,17 @@ Transition Ground::input_state_rule( wchar_t ch ) const ActionPointer Escape::enter( void ) const { - return shared::make_shared< Clear >(); + return std::make_shared(); } Transition Escape::input_state_rule( wchar_t ch ) const { if ( C0_prime( ch ) ) { - return Transition( shared::make_shared< Execute >() ); + return Transition( std::make_shared() ); } if ( (0x20 <= ch) && (ch <= 0x2F) ) { - return Transition( shared::make_shared< Collect >(), &family->s_Escape_Intermediate ); + return Transition( std::make_shared(), &family->s_Escape_Intermediate ); } if ( ( (0x30 <= ch) && (ch <= 0x4F) ) @@ -124,7 +125,7 @@ Transition Escape::input_state_rule( wchar_t ch ) const || ( ch == 0x5A ) || ( ch == 0x5C ) || ( (0x60 <= ch) && (ch <= 0x7E) ) ) { - return Transition( shared::make_shared< Esc_Dispatch >(), &family->s_Ground ); + return Transition( std::make_shared(), &family->s_Ground ); } if ( ch == 0x5B ) { @@ -149,15 +150,15 @@ Transition Escape::input_state_rule( wchar_t ch ) const Transition Escape_Intermediate::input_state_rule( wchar_t ch ) const { if ( C0_prime( ch ) ) { - return Transition( shared::make_shared< Execute >() ); + return Transition( std::make_shared() ); } if ( (0x20 <= ch) && (ch <= 0x2F) ) { - return Transition( shared::make_shared< Collect >() ); + return Transition( std::make_shared() ); } if ( (0x30 <= ch) && (ch <= 0x7E) ) { - return Transition( shared::make_shared< Esc_Dispatch >(), &family->s_Ground ); + return Transition( std::make_shared(), &family->s_Ground ); } return Transition(); @@ -165,26 +166,26 @@ Transition Escape_Intermediate::input_state_rule( wchar_t ch ) const ActionPointer CSI_Entry::enter( void ) const { - return shared::make_shared< Clear >(); + return std::make_shared(); } Transition CSI_Entry::input_state_rule( wchar_t ch ) const { if ( C0_prime( ch ) ) { - return Transition( shared::make_shared< Execute >() ); + return Transition( std::make_shared() ); } if ( (0x40 <= ch) && (ch <= 0x7E) ) { - return Transition( shared::make_shared< CSI_Dispatch >(), &family->s_Ground ); + return Transition( std::make_shared(), &family->s_Ground ); } if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) { - return Transition( shared::make_shared< Param >(), &family->s_CSI_Param ); + return Transition( std::make_shared(), &family->s_CSI_Param ); } if ( (0x3C <= ch) && (ch <= 0x3F) ) { - return Transition( shared::make_shared< Collect >(), &family->s_CSI_Param ); + return Transition( std::make_shared(), &family->s_CSI_Param ); } if ( ch == 0x3A ) { @@ -192,7 +193,7 @@ Transition CSI_Entry::input_state_rule( wchar_t ch ) const } if ( (0x20 <= ch) && (ch <= 0x2F) ) { - return Transition( shared::make_shared< Collect >(), &family->s_CSI_Intermediate ); + return Transition( std::make_shared(), &family->s_CSI_Intermediate ); } return Transition(); @@ -201,11 +202,11 @@ Transition CSI_Entry::input_state_rule( wchar_t ch ) const Transition CSI_Param::input_state_rule( wchar_t ch ) const { if ( C0_prime( ch ) ) { - return Transition( shared::make_shared< Execute >() ); + return Transition( std::make_shared() ); } if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) { - return Transition( shared::make_shared< Param >() ); + return Transition( std::make_shared() ); } if ( ( ch == 0x3A ) || ( (0x3C <= ch) && (ch <= 0x3F) ) ) { @@ -213,11 +214,11 @@ Transition CSI_Param::input_state_rule( wchar_t ch ) const } if ( (0x20 <= ch) && (ch <= 0x2F) ) { - return Transition( shared::make_shared< Collect >(), &family->s_CSI_Intermediate ); + return Transition( std::make_shared(), &family->s_CSI_Intermediate ); } if ( (0x40 <= ch) && (ch <= 0x7E) ) { - return Transition( shared::make_shared< CSI_Dispatch >(), &family->s_Ground ); + return Transition( std::make_shared(), &family->s_Ground ); } return Transition(); @@ -226,15 +227,15 @@ Transition CSI_Param::input_state_rule( wchar_t ch ) const Transition CSI_Intermediate::input_state_rule( wchar_t ch ) const { if ( C0_prime( ch ) ) { - return Transition( shared::make_shared< Execute >() ); + return Transition( std::make_shared() ); } if ( (0x20 <= ch) && (ch <= 0x2F) ) { - return Transition( shared::make_shared< Collect >() ); + return Transition( std::make_shared() ); } if ( (0x40 <= ch) && (ch <= 0x7E) ) { - return Transition( shared::make_shared< CSI_Dispatch >(), &family->s_Ground ); + return Transition( std::make_shared(), &family->s_Ground ); } if ( (0x30 <= ch) && (ch <= 0x3F) ) { @@ -247,7 +248,7 @@ Transition CSI_Intermediate::input_state_rule( wchar_t ch ) const Transition CSI_Ignore::input_state_rule( wchar_t ch ) const { if ( C0_prime( ch ) ) { - return Transition( shared::make_shared< Execute >() ); + return Transition( std::make_shared() ); } if ( (0x40 <= ch) && (ch <= 0x7E) ) { @@ -259,13 +260,13 @@ Transition CSI_Ignore::input_state_rule( wchar_t ch ) const ActionPointer DCS_Entry::enter( void ) const { - return shared::make_shared< Clear >(); + return std::make_shared(); } Transition DCS_Entry::input_state_rule( wchar_t ch ) const { if ( (0x20 <= ch) && (ch <= 0x2F) ) { - return Transition( shared::make_shared< Collect >(), &family->s_DCS_Intermediate ); + return Transition( std::make_shared(), &family->s_DCS_Intermediate ); } if ( ch == 0x3A ) { @@ -273,11 +274,11 @@ Transition DCS_Entry::input_state_rule( wchar_t ch ) const } if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) { - return Transition( shared::make_shared< Param >(), &family->s_DCS_Param ); + return Transition( std::make_shared(), &family->s_DCS_Param ); } if ( (0x3C <= ch) && (ch <= 0x3F) ) { - return Transition( shared::make_shared< Collect >(), &family->s_DCS_Param ); + return Transition( std::make_shared(), &family->s_DCS_Param ); } if ( (0x40 <= ch) && (ch <= 0x7E) ) { @@ -290,7 +291,7 @@ Transition DCS_Entry::input_state_rule( wchar_t ch ) const Transition DCS_Param::input_state_rule( wchar_t ch ) const { if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) { - return Transition( shared::make_shared< Param >() ); + return Transition( std::make_shared() ); } if ( ( ch == 0x3A ) || ( (0x3C <= ch) && (ch <= 0x3F) ) ) { @@ -298,7 +299,7 @@ Transition DCS_Param::input_state_rule( wchar_t ch ) const } if ( (0x20 <= ch) && (ch <= 0x2F) ) { - return Transition( shared::make_shared< Collect >(), &family->s_DCS_Intermediate ); + return Transition( std::make_shared(), &family->s_DCS_Intermediate ); } if ( (0x40 <= ch) && (ch <= 0x7E) ) { @@ -311,7 +312,7 @@ Transition DCS_Param::input_state_rule( wchar_t ch ) const Transition DCS_Intermediate::input_state_rule( wchar_t ch ) const { if ( (0x20 <= ch) && (ch <= 0x2F) ) { - return Transition( shared::make_shared< Collect >() ); + return Transition( std::make_shared() ); } if ( (0x40 <= ch) && (ch <= 0x7E) ) { @@ -327,18 +328,18 @@ Transition DCS_Intermediate::input_state_rule( wchar_t ch ) const ActionPointer DCS_Passthrough::enter( void ) const { - return shared::make_shared< Hook >(); + return std::make_shared(); } ActionPointer DCS_Passthrough::exit( void ) const { - return shared::make_shared< Unhook >(); + return std::make_shared(); } Transition DCS_Passthrough::input_state_rule( wchar_t ch ) const { if ( C0_prime( ch ) || ( (0x20 <= ch) && (ch <= 0x7E) ) ) { - return Transition( shared::make_shared< Put >() ); + return Transition( std::make_shared() ); } if ( ch == 0x9C ) { @@ -359,18 +360,18 @@ Transition DCS_Ignore::input_state_rule( wchar_t ch ) const ActionPointer OSC_String::enter( void ) const { - return shared::make_shared< OSC_Start >(); + return std::make_shared(); } ActionPointer OSC_String::exit( void ) const { - return shared::make_shared< OSC_End >(); + return std::make_shared(); } Transition OSC_String::input_state_rule( wchar_t ch ) const { if ( (0x20 <= ch) && (ch <= 0x7F) ) { - return Transition( shared::make_shared< OSC_Put >() ); + return Transition( std::make_shared() ); } if ( (ch == 0x9C) || (ch == 0x07) ) { /* 0x07 is xterm non-ANSI variant */ diff --git a/src/terminal/parserstate.h b/src/terminal/parserstate.h index 39116e6fb..07c45737b 100644 --- a/src/terminal/parserstate.h +++ b/src/terminal/parserstate.h @@ -50,8 +50,8 @@ namespace Parser { public: void setfamily( StateFamily *s_family ) { family = s_family; } Transition input( wchar_t ch ) const; - virtual ActionPointer enter( void ) const { return shared::make_shared< Ignore >(); } - virtual ActionPointer exit( void ) const { return shared::make_shared< Ignore >(); } + virtual ActionPointer enter( void ) const { return std::make_shared(); } + virtual ActionPointer exit( void ) const { return std::make_shared(); } State() : family( NULL ) {}; virtual ~State() {}; diff --git a/src/terminal/parsertransition.h b/src/terminal/parsertransition.h index 8a5c2055f..aca909fcb 100644 --- a/src/terminal/parsertransition.h +++ b/src/terminal/parsertransition.h @@ -33,7 +33,7 @@ #ifndef PARSERTRANSITION_HPP #define PARSERTRANSITION_HPP -#include +#include #include "src/terminal/parseraction.h" @@ -58,14 +58,14 @@ namespace Parser { return *this; } - Transition( ActionPointer s_action=shared::make_shared< Ignore >(), State *s_next_state=NULL ) + Transition( ActionPointer s_action = std::make_shared(), State *s_next_state=NULL ) : action( s_action ), next_state( s_next_state ) {} // This is only ever used in the 1-argument form; // we use this instead of an initializer to // tell Coverity the object never owns *action. - Transition( State *s_next_state, ActionPointer s_action=shared::make_shared< Ignore >() ) + Transition( State *s_next_state, ActionPointer s_action = std::make_shared() ) : action( s_action ), next_state( s_next_state ) {} }; diff --git a/src/terminal/terminal.cc b/src/terminal/terminal.cc index 95a1fd85e..179847768 100644 --- a/src/terminal/terminal.cc +++ b/src/terminal/terminal.cc @@ -30,12 +30,13 @@ also delete it here. */ -#include -#include -#include -#include +#include +#include +#include #include +#include + #include "src/terminal/terminal.h" using namespace Terminal; diff --git a/src/terminal/terminal.h b/src/terminal/terminal.h index f4412ba6c..2b803d72b 100644 --- a/src/terminal/terminal.h +++ b/src/terminal/terminal.h @@ -33,10 +33,10 @@ #ifndef TERMINAL_CPP #define TERMINAL_CPP -#include -#include -#include +#include +#include #include +#include #include "src/terminal/parseraction.h" #include "src/terminal/terminalframebuffer.h" diff --git a/src/terminal/terminaldispatcher.cc b/src/terminal/terminaldispatcher.cc index 450aef3a0..4d9ce70c3 100644 --- a/src/terminal/terminaldispatcher.cc +++ b/src/terminal/terminaldispatcher.cc @@ -30,11 +30,11 @@ also delete it here. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "terminaldispatcher.h" #include "src/terminal/parseraction.h" diff --git a/src/terminal/terminaldispatcher.h b/src/terminal/terminaldispatcher.h index cc92c2e03..8dabbdc5c 100644 --- a/src/terminal/terminaldispatcher.h +++ b/src/terminal/terminaldispatcher.h @@ -66,7 +66,7 @@ namespace Terminal { bool clears_wrap_state; }; - typedef std::map dispatch_map_t; + using dispatch_map_t = std::map; class DispatchRegistry { public: diff --git a/src/terminal/terminaldisplay.cc b/src/terminal/terminaldisplay.cc index 013c6f879..a957010f9 100644 --- a/src/terminal/terminaldisplay.cc +++ b/src/terminal/terminaldisplay.cc @@ -30,7 +30,7 @@ also delete it here. */ -#include +#include #include "terminaldisplay.h" #include "src/terminal/terminalframebuffer.h" @@ -68,7 +68,7 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const if ( f.get_bell_count() != frame.last_frame.get_bell_count() ) { frame.append( '\007' ); } - typedef Terminal::Framebuffer::title_type title_type; + using title_type = Terminal::Framebuffer::title_type; /* has icon name or window title changed? */ if ( has_title && f.is_title_initialized() && @@ -160,7 +160,7 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const /* Extend rows if we've gotten a resize and new is wider than old */ if ( frame.last_frame.ds.get_width() < f.ds.get_width() ) { for ( Framebuffer::rows_type::iterator p = rows.begin(); p != rows.end(); p++ ) { - *p = make_shared( **p ); + *p = std::make_shared( **p ); (*p)->cells.resize( f.ds.get_width(), Cell( f.ds.get_background_rendition() ) ); } } @@ -169,7 +169,7 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const // get a proper blank row const size_t w = f.ds.get_width(); const color_type c = 0; - blank_row = make_shared( w, c ); + blank_row = std::make_shared( w, c ); rows.resize( f.ds.get_height(), blank_row ); } @@ -215,7 +215,7 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, const if ( blank_row.get() == NULL ) { const size_t w = f.ds.get_width(); const color_type c = 0; - blank_row = make_shared( w, c ); + blank_row = std::make_shared( w, c ); } frame.update_rendition( initial_rendition(), true ); diff --git a/src/terminal/terminaldisplayinit.cc b/src/terminal/terminaldisplayinit.cc index 3defa9dec..1888915d5 100644 --- a/src/terminal/terminaldisplayinit.cc +++ b/src/terminal/terminaldisplayinit.cc @@ -57,8 +57,8 @@ #else # error "SysV or X/Open-compatible Curses header file required" #endif -#include -#include +#include +#include using namespace Terminal; diff --git a/src/terminal/terminalframebuffer.cc b/src/terminal/terminalframebuffer.cc index 7a469a943..3a285a829 100644 --- a/src/terminal/terminalframebuffer.cc +++ b/src/terminal/terminalframebuffer.cc @@ -30,9 +30,9 @@ also delete it here. */ -#include -#include -#include +#include +#include +#include #include "src/terminal/terminalframebuffer.h" @@ -84,7 +84,7 @@ Framebuffer::Framebuffer( int s_width, int s_height ) assert( s_width > 0 ); const size_t w = s_width; const color_type c = 0; - rows = rows_type(s_height, row_pointer(make_shared( w, c ))); + rows = rows_type(s_height, row_pointer(std::make_shared( w, c ))); } Framebuffer::Framebuffer( const Framebuffer &other ) @@ -417,7 +417,7 @@ void Framebuffer::resize( int s_width, int s_height ) for ( rows_type::iterator i = rows.begin(); i != rows.end() && *i != blankrow; i++ ) { - *i = make_shared( **i ); + *i = std::make_shared( **i ); (*i)->set_wrap( false ); (*i)->cells.resize( s_width, Cell( ds.get_background_rendition() ) ); } diff --git a/src/terminal/terminalframebuffer.h b/src/terminal/terminalframebuffer.h index 430f5c111..58c766c78 100644 --- a/src/terminal/terminalframebuffer.h +++ b/src/terminal/terminalframebuffer.h @@ -33,23 +33,19 @@ #ifndef TERMINALFB_HPP #define TERMINALFB_HPP -#include -#include -#include - -#include +#include +#include +#include #include -#include #include - -#include "src/util/shared.h" +#include +#include +#include /* Terminal framebuffer */ namespace Terminal { - using shared::shared_ptr; - using shared::make_shared; - typedef uint32_t color_type; + using color_type = uint32_t; class Renditions { public: @@ -372,7 +368,7 @@ namespace Terminal { // * If no row is shared, the frame has not been modified. public: typedef std::vector title_type; - typedef shared_ptr row_pointer; + typedef std::shared_ptr row_pointer; typedef std::vector rows_type; /* can be either std::vector or std::deque */ private: @@ -387,7 +383,7 @@ namespace Terminal { { const size_t w = ds.get_width(); const color_type c = ds.get_background_rendition(); - return make_shared( w, c ); + return std::make_shared( w, c ); } public: @@ -422,7 +418,7 @@ namespace Terminal { row_pointer &mutable_row = rows.at( row ); // If the row is shared, copy it. if (!mutable_row.unique()) { - mutable_row = make_shared( *mutable_row ); + mutable_row = std::make_shared( *mutable_row ); } return mutable_row.get(); } diff --git a/src/terminal/terminalfunctions.cc b/src/terminal/terminalfunctions.cc index 212541378..31f33b0bd 100644 --- a/src/terminal/terminalfunctions.cc +++ b/src/terminal/terminalfunctions.cc @@ -30,10 +30,11 @@ also delete it here. */ -#include #include +#include #include -#include + +#include #include "terminaldispatcher.h" #include "src/terminal/terminalframebuffer.h" diff --git a/src/terminal/terminaluserinput.cc b/src/terminal/terminaluserinput.cc index f81190043..cf8125e22 100644 --- a/src/terminal/terminaluserinput.cc +++ b/src/terminal/terminaluserinput.cc @@ -30,14 +30,14 @@ also delete it here. */ -#include +#include + #include "terminaluserinput.h" using namespace Terminal; -using std::string; -string UserInput::input( const Parser::UserByte *act, - bool application_mode_cursor_keys ) +std::string UserInput::input( const Parser::UserByte *act, + bool application_mode_cursor_keys ) { /* The user will always be in application mode. If stm is not in application mode, convert user's cursor control function to an @@ -54,15 +54,15 @@ string UserInput::input( const Parser::UserByte *act, if ( act->c == 0x1b ) { /* ESC */ state = ESC; } - return string( &act->c, 1 ); + return std::string( &act->c, 1 ); case ESC: if ( act->c == 'O' ) { /* ESC O = 7-bit SS3 */ state = SS3; - return string(); + return std::string(); } state = Ground; - return string( &act->c, 1 ); + return std::string( &act->c, 1 ); case SS3: state = Ground; @@ -70,15 +70,15 @@ string UserInput::input( const Parser::UserByte *act, && (act->c >= 'A') && (act->c <= 'D') ) { char translated_cursor[ 2 ] = { '[', act->c }; - return string( translated_cursor, 2 ); + return std::string( translated_cursor, 2 ); } else { char original_cursor[ 2 ] = { 'O', act->c }; - return string( original_cursor, 2 ); + return std::string( original_cursor, 2 ); } default: assert( !"unexpected state" ); state = Ground; - return string(); + return std::string(); } } diff --git a/src/tests/base64.cc b/src/tests/base64.cc index 7d49c8822..3ee2f3c64 100644 --- a/src/tests/base64.cc +++ b/src/tests/base64.cc @@ -37,9 +37,9 @@ client and server. It does not particularly test any code written for the Mosh project. */ -#include -#include -#include +#include +#include +#include #include "src/crypto/base64.h" #include "base64_vector.h" diff --git a/src/tests/encrypt-decrypt.cc b/src/tests/encrypt-decrypt.cc index e09f0a828..9829763e9 100644 --- a/src/tests/encrypt-decrypt.cc +++ b/src/tests/encrypt-decrypt.cc @@ -34,10 +34,10 @@ messages, interspersed with some random bad ciphertexts which we need to reject. */ -#include +#include #define __STDC_FORMAT_MACROS -#include +#include #include "src/crypto/crypto.h" #include "src/crypto/prng.h" diff --git a/src/tests/inpty.cc b/src/tests/inpty.cc index f57968e99..cab63e47c 100644 --- a/src/tests/inpty.cc +++ b/src/tests/inpty.cc @@ -32,13 +32,14 @@ #include "src/include/config.h" +#include +#include +#include +#include +#include + #include #include -#include -#include -#include -#include -#include #include #include diff --git a/src/tests/is-utf8-locale.cc b/src/tests/is-utf8-locale.cc index 67ef2832e..f997a8a7c 100644 --- a/src/tests/is-utf8-locale.cc +++ b/src/tests/is-utf8-locale.cc @@ -30,7 +30,7 @@ also delete it here. */ -#include +#include #include "src/util/locale_utils.h" diff --git a/src/tests/ocb-aes.cc b/src/tests/ocb-aes.cc index 943a704b6..62c302431 100644 --- a/src/tests/ocb-aes.cc +++ b/src/tests/ocb-aes.cc @@ -37,16 +37,16 @@ client and server. It does not particularly test any code written for the Mosh project. */ -#include -#include -#include +#include +#include +#include +#include #include "src/crypto/ae.h" #include "src/crypto/crypto.h" #include "src/crypto/prng.h" #include "src/util/fatal_assert.h" #include "test_utils.h" -#include "src/util/shared.h" #define KEY_LEN 16 #define NONCE_LEN 12 @@ -61,7 +61,7 @@ static bool equal( const AlignedBuffer &a, const AlignedBuffer &b ) { && !memcmp( a.data(), b.data(), a.len() ); } -typedef shared::shared_ptr< AlignedBuffer > AlignedPointer; +using AlignedPointer = std::shared_ptr; static AlignedBuffer *get_ctx( const AlignedBuffer &key ) { AlignedBuffer *ctx_buf = new AlignedBuffer( ae_ctx_sizeof() ); diff --git a/src/tests/test_utils.cc b/src/tests/test_utils.cc index fcdb3fdc1..a51f3fee5 100644 --- a/src/tests/test_utils.cc +++ b/src/tests/test_utils.cc @@ -30,7 +30,7 @@ also delete it here. */ -#include +#include #include "test_utils.h" diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 7cd7a5054..408d5b799 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -2,4 +2,4 @@ AM_CXXFLAGS = -I$(top_srcdir)/ $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CF noinst_LIBRARIES = libmoshutil.a -libmoshutil_a_SOURCES = locale_utils.cc locale_utils.h swrite.cc swrite.h dos_assert.h fatal_assert.h select.h select.cc timestamp.h timestamp.cc pty_compat.cc pty_compat.h shared.h +libmoshutil_a_SOURCES = locale_utils.cc locale_utils.h swrite.cc swrite.h dos_assert.h fatal_assert.h select.h select.cc timestamp.h timestamp.cc pty_compat.cc pty_compat.h diff --git a/src/util/dos_assert.h b/src/util/dos_assert.h index 2eff034eb..447a75ea6 100644 --- a/src/util/dos_assert.h +++ b/src/util/dos_assert.h @@ -33,8 +33,8 @@ #ifndef DOS_ASSERT_HPP #define DOS_ASSERT_HPP -#include -#include +#include +#include #include "src/crypto/crypto.h" diff --git a/src/util/fatal_assert.h b/src/util/fatal_assert.h index 9827f7386..b3c3564e4 100644 --- a/src/util/fatal_assert.h +++ b/src/util/fatal_assert.h @@ -33,8 +33,8 @@ #ifndef FATAL_ASSERT_HPP #define FATAL_ASSERT_HPP -#include -#include +#include +#include static void fatal_error( const char *expression, const char *file, int line, const char *function ) { diff --git a/src/util/locale_utils.cc b/src/util/locale_utils.cc index e8093d528..390c297ac 100644 --- a/src/util/locale_utils.cc +++ b/src/util/locale_utils.cc @@ -32,11 +32,11 @@ #include "src/include/config.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #if HAVE_LANGINFO_H diff --git a/src/util/pty_compat.cc b/src/util/pty_compat.cc index ce543f757..ec439f589 100644 --- a/src/util/pty_compat.cc +++ b/src/util/pty_compat.cc @@ -33,14 +33,15 @@ #include "src/include/config.h" #if !defined(HAVE_FORKPTY) || !defined(HAVE_CFMAKERAW) -#include -#include -#include -#include +#include +#include +#include + #include #include #include #include +#include #include "src/util/pty_compat.h" diff --git a/src/util/select.h b/src/util/select.h index 7361a6499..e50807be7 100644 --- a/src/util/select.h +++ b/src/util/select.h @@ -33,11 +33,12 @@ #ifndef SELECT_HPP #define SELECT_HPP -#include -#include -#include +#include +#include +#include +#include + #include -#include #include "src/util/fatal_assert.h" #include "src/util/timestamp.h" diff --git a/src/util/shared.h b/src/util/shared.h deleted file mode 100644 index 4b97a5844..000000000 --- a/src/util/shared.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - Mosh: the mobile shell - Copyright 2012 Keith Winstein - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the - OpenSSL library under certain conditions as described in each - individual source file, and distribute linked combinations including - the two. - - You must obey the GNU General Public License in all respects for all - of the code used other than OpenSSL. If you modify file(s) with this - exception, you may extend this exception to your version of the - file(s), but you are not obligated to do so. If you do not wish to do - so, delete this exception statement from your version. If you delete - this exception statement from all source files in the program, then - also delete it here. -*/ - -#ifndef SHARED_HPP -#define SHARED_HPP - -#include "src/include/config.h" - -#ifdef HAVE_MEMORY -#include -#endif - -#ifdef HAVE_TR1_MEMORY -#include -#endif - -namespace shared { -#ifdef HAVE_STD_SHARED_PTR - using std::shared_ptr; - using std::make_shared; -#else -#ifdef HAVE_STD_TR1_SHARED_PTR - using std::tr1::shared_ptr; - - // make_shared emulation. - template - inline shared_ptr - make_shared() - { - return shared_ptr(new Tp()); - } - template - inline shared_ptr - make_shared(const A1& a1) - { - return shared_ptr(new Tp(a1)); - } - template - inline shared_ptr - make_shared(const A1& a1, const A2& a2) - { - return shared_ptr(new Tp(a1, a2)); - } - template - inline shared_ptr - make_shared(const A1& a1, const A2& a2, const A3& a3) - { - return shared_ptr(new Tp(a1, a2, a3)); - } - template - inline shared_ptr - make_shared(const A1& a1, const A2& a2, const A3& a3, const A4& a4) - { - return shared_ptr(new Tp(a1, a2, a3, a4)); - } -#else -#error Need a shared_ptr class. Try Boost::TR1. -#endif -#endif -} -#endif diff --git a/src/util/swrite.cc b/src/util/swrite.cc index d3c2ba0bf..bbdc4f6b4 100644 --- a/src/util/swrite.cc +++ b/src/util/swrite.cc @@ -30,9 +30,10 @@ also delete it here. */ +#include +#include + #include -#include -#include #include "src/util/swrite.h" diff --git a/src/util/timestamp.cc b/src/util/timestamp.cc index 3eaf283d8..4cbc79766 100644 --- a/src/util/timestamp.cc +++ b/src/util/timestamp.cc @@ -34,10 +34,10 @@ #include "src/util/timestamp.h" -#include +#include #if HAVE_CLOCK_GETTIME -#include +#include #endif #if HAVE_MACH_ABSOLUTE_TIME #include @@ -45,7 +45,7 @@ #endif #if HAVE_GETTIMEOFDAY #include -#include +#include #endif // On Apple systems CLOCK_MONOTONIC is unfortunately able to go diff --git a/src/util/timestamp.h b/src/util/timestamp.h index 9ba4947ef..07cf5b434 100644 --- a/src/util/timestamp.h +++ b/src/util/timestamp.h @@ -33,7 +33,7 @@ #ifndef TIMESTAMP_HPP #define TIMESTAMP_HPP -#include +#include void freeze_timestamp( void ); uint64_t frozen_timestamp( void );