Mark local functions as static

This helps to catch unused functions like the former mosh_read_line,
allows the compiler to make better inlining decisions, and reduces the
binary size a bit.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg
2014-04-23 16:31:27 -04:00
committed by John Hood
parent a52b095f50
commit cd2ae36f36
7 changed files with 88 additions and 88 deletions
+6 -6
View File
@@ -63,9 +63,9 @@
const size_t buf_size = 1024; const size_t buf_size = 1024;
void emulate_terminal( int fd ); static void emulate_terminal( int fd );
int copy( int src, int dest ); static int copy( int src, int dest );
int vt_parser( int fd, Parser::UTF8Parser *parser ); static int vt_parser( int fd, Parser::UTF8Parser *parser );
int main( int argc __attribute__((unused)), int main( int argc __attribute__((unused)),
char *argv[] __attribute__((unused)), char *argv[] __attribute__((unused)),
@@ -135,7 +135,7 @@ int main( int argc __attribute__((unused)),
return 0; return 0;
} }
void emulate_terminal( int fd ) static void emulate_terminal( int fd )
{ {
Parser::UTF8Parser parser; Parser::UTF8Parser parser;
@@ -166,7 +166,7 @@ void emulate_terminal( int fd )
} }
} }
int copy( int src, int dest ) static int copy( int src, int dest )
{ {
char buf[ buf_size ]; char buf[ buf_size ];
@@ -181,7 +181,7 @@ int copy( int src, int dest )
return swrite( dest, buf, bytes_read ); return swrite( dest, buf, bytes_read );
} }
int vt_parser( int fd, Parser::UTF8Parser *parser ) static int vt_parser( int fd, Parser::UTF8Parser *parser )
{ {
char buf[ buf_size ]; char buf[ buf_size ];
+3 -3
View File
@@ -70,7 +70,7 @@
const size_t buf_size = 16384; const size_t buf_size = 16384;
void emulate_terminal( int fd ); static void emulate_terminal( int fd );
int main( void ) int main( void )
{ {
@@ -158,7 +158,7 @@ int main( void )
} }
/* Print a frame if the last frame was more than 1/50 seconds ago */ /* Print a frame if the last frame was more than 1/50 seconds ago */
bool tick( Terminal::Framebuffer &state, Terminal::Framebuffer &new_frame, static bool tick( Terminal::Framebuffer &state, Terminal::Framebuffer &new_frame,
const Terminal::Display &display ) const Terminal::Display &display )
{ {
static bool initialized = false; static bool initialized = false;
@@ -207,7 +207,7 @@ bool tick( Terminal::Framebuffer &state, Terminal::Framebuffer &new_frame,
assume the previous frame was sent to the real terminal. assume the previous frame was sent to the real terminal.
*/ */
void emulate_terminal( int fd ) static void emulate_terminal( int fd )
{ {
/* get current window size */ /* get current window size */
struct winsize window_size; struct winsize window_size;
+2 -2
View File
@@ -70,7 +70,7 @@
# error "SysV or X/Open-compatible Curses header file required" # error "SysV or X/Open-compatible Curses header file required"
#endif #endif
void usage( const char *argv0 ) { static void usage( const char *argv0 ) {
fprintf( stderr, "mosh-client (%s) [build %s]\n", PACKAGE_STRING, BUILD_VERSION ); fprintf( stderr, "mosh-client (%s) [build %s]\n", PACKAGE_STRING, BUILD_VERSION );
fprintf( stderr, "Copyright 2012 Keith Winstein <mosh-devel@mit.edu>\n" ); fprintf( stderr, "Copyright 2012 Keith Winstein <mosh-devel@mit.edu>\n" );
fprintf( stderr, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\n" ); fprintf( stderr, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\n" );
@@ -78,7 +78,7 @@ void usage( const char *argv0 ) {
fprintf( stderr, "Usage: %s IP PORT\n %s -c\n", argv0, argv0 ); fprintf( stderr, "Usage: %s IP PORT\n %s -c\n", argv0, argv0 );
} }
void print_colorcount( void ) static void print_colorcount( void )
{ {
/* check colors */ /* check colors */
setupterm((char *)0, 1, (int *)0); setupterm((char *)0, 1, (int *)0);
+16 -16
View File
@@ -91,28 +91,28 @@
typedef Network::Transport< Terminal::Complete, Network::UserStream > ServerConnection; typedef Network::Transport< Terminal::Complete, Network::UserStream > ServerConnection;
void serve( int host_fd, static void serve( int host_fd,
Terminal::Complete &terminal, Terminal::Complete &terminal,
ServerConnection &network ); ServerConnection &network );
int run_server( const char *desired_ip, const char *desired_port, static int run_server( const char *desired_ip, const char *desired_port,
const string &command_path, char *command_argv[], const string &command_path, char *command_argv[],
const int colors, bool verbose, bool with_motd ); const int colors, bool verbose, bool with_motd );
using namespace std; using namespace std;
void print_usage( const char *argv0 ) static void print_usage( const char *argv0 )
{ {
fprintf( stderr, "Usage: %s new [-s] [-v] [-i LOCALADDR] [-p PORT[:PORT2]] [-c COLORS] [-l NAME=VALUE] [-- COMMAND...]\n", argv0 ); fprintf( stderr, "Usage: %s new [-s] [-v] [-i LOCALADDR] [-p PORT[:PORT2]] [-c COLORS] [-l NAME=VALUE] [-- COMMAND...]\n", argv0 );
} }
void print_motd( void ); static void print_motd( void );
void chdir_homedir( void ); static void chdir_homedir( void );
bool motd_hushed( void ); static bool motd_hushed( void );
void warn_unattached( const string & ignore_entry ); static void warn_unattached( const string & ignore_entry );
/* Simple spinloop */ /* Simple spinloop */
void spin( void ) static void spin( void )
{ {
static unsigned int spincount = 0; static unsigned int spincount = 0;
spincount++; spincount++;
@@ -126,7 +126,7 @@ void spin( void )
} }
} }
string get_SSH_IP( void ) static string get_SSH_IP( void )
{ {
const char *SSH_CONNECTION = getenv( "SSH_CONNECTION" ); const char *SSH_CONNECTION = getenv( "SSH_CONNECTION" );
if ( !SSH_CONNECTION ) { /* Older sshds don't set this */ if ( !SSH_CONNECTION ) { /* Older sshds don't set this */
@@ -327,7 +327,7 @@ int main( int argc, char *argv[] )
} }
} }
int run_server( const char *desired_ip, const char *desired_port, static int run_server( const char *desired_ip, const char *desired_port,
const string &command_path, char *command_argv[], const string &command_path, char *command_argv[],
const int colors, bool verbose, bool with_motd ) { const int colors, bool verbose, bool with_motd ) {
/* get initial window size */ /* get initial window size */
@@ -521,7 +521,7 @@ int run_server( const char *desired_ip, const char *desired_port,
return 0; return 0;
} }
void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network ) static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network )
{ {
/* prepare to poll for events */ /* prepare to poll for events */
Select &sel = Select::get_instance(); Select &sel = Select::get_instance();
@@ -746,7 +746,7 @@ void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network
} }
/* OpenSSH prints the motd on startup, so we will too */ /* OpenSSH prints the motd on startup, so we will too */
void print_motd( void ) static void print_motd( void )
{ {
FILE *motd = fopen( "/etc/motd", "r" ); FILE *motd = fopen( "/etc/motd", "r" );
if ( !motd ) { if ( !motd ) {
@@ -770,7 +770,7 @@ void print_motd( void )
fclose( motd ); fclose( motd );
} }
void chdir_homedir( void ) static void chdir_homedir( void )
{ {
struct passwd *pw = getpwuid( geteuid() ); struct passwd *pw = getpwuid( geteuid() );
if ( pw == NULL ) { if ( pw == NULL ) {
@@ -787,21 +787,21 @@ void chdir_homedir( void )
} }
} }
bool motd_hushed( void ) static bool motd_hushed( void )
{ {
/* must be in home directory already */ /* must be in home directory already */
struct stat buf; struct stat buf;
return (0 == lstat( ".hushlogin", &buf )); return (0 == lstat( ".hushlogin", &buf ));
} }
bool device_exists( const char *ut_line ) static bool device_exists( const char *ut_line )
{ {
string device_name = string( "/dev/" ) + string( ut_line ); string device_name = string( "/dev/" ) + string( ut_line );
struct stat buf; struct stat buf;
return (0 == lstat( device_name.c_str(), &buf )); return (0 == lstat( device_name.c_str(), &buf ));
} }
void warn_unattached( const string & ignore_entry ) static void warn_unattached( const string & ignore_entry )
{ {
#ifdef HAVE_UTMPX_H #ifdef HAVE_UTMPX_H
/* get username */ /* get username */
+35 -35
View File
@@ -50,7 +50,7 @@ static void clearline( Framebuffer *fb, int row, int start, int end )
} }
/* erase in line */ /* erase in line */
void CSI_EL( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_EL( Framebuffer *fb, Dispatcher *dispatch )
{ {
switch ( dispatch->getparam( 0, 0 ) ) { switch ( dispatch->getparam( 0, 0 ) ) {
case 0: /* default: active position to end of line, inclusive */ case 0: /* default: active position to end of line, inclusive */
@@ -68,7 +68,7 @@ void CSI_EL( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_EL( CSI, "K", CSI_EL ); static Function func_CSI_EL( CSI, "K", CSI_EL );
/* erase in display */ /* erase in display */
void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) { static void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) {
switch ( dispatch->getparam( 0, 0 ) ) { switch ( dispatch->getparam( 0, 0 ) ) {
case 0: /* active position to end of screen, inclusive */ case 0: /* active position to end of screen, inclusive */
clearline( fb, -1, fb->ds.get_cursor_col(), fb->ds.get_width() - 1 ); clearline( fb, -1, fb->ds.get_cursor_col(), fb->ds.get_width() - 1 );
@@ -93,7 +93,7 @@ void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) {
static Function func_CSI_ED( CSI, "J", CSI_ED ); static Function func_CSI_ED( CSI, "J", CSI_ED );
/* cursor movement -- relative and absolute */ /* cursor movement -- relative and absolute */
void CSI_cursormove( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_cursormove( Framebuffer *fb, Dispatcher *dispatch )
{ {
int num = dispatch->getparam( 0, 1 ); int num = dispatch->getparam( 0, 1 );
@@ -127,7 +127,7 @@ static Function func_CSI_cursormove_H( CSI, "H", CSI_cursormove );
static Function func_CSI_cursormove_f( CSI, "f", CSI_cursormove ); static Function func_CSI_cursormove_f( CSI, "f", CSI_cursormove );
/* device attributes */ /* device attributes */
void CSI_DA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch ) static void CSI_DA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch )
{ {
dispatch->terminal_to_host.append( "\033[?62c" ); /* plain vt220 */ dispatch->terminal_to_host.append( "\033[?62c" ); /* plain vt220 */
} }
@@ -135,7 +135,7 @@ void CSI_DA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch )
static Function func_CSI_DA( CSI, "c", CSI_DA ); static Function func_CSI_DA( CSI, "c", CSI_DA );
/* secondary device attributes */ /* secondary device attributes */
void CSI_SDA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch ) static void CSI_SDA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch )
{ {
dispatch->terminal_to_host.append( "\033[>1;10;0c" ); /* plain vt220 */ dispatch->terminal_to_host.append( "\033[>1;10;0c" ); /* plain vt220 */
} }
@@ -143,7 +143,7 @@ void CSI_SDA( Framebuffer *fb __attribute((unused)), Dispatcher *dispatch )
static Function func_CSI_SDA( CSI, ">c", CSI_SDA ); static Function func_CSI_SDA( CSI, ">c", CSI_SDA );
/* screen alignment diagnostic */ /* screen alignment diagnostic */
void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
for ( int y = 0; y < fb->ds.get_height(); y++ ) { for ( int y = 0; y < fb->ds.get_height(); y++ ) {
for ( int x = 0; x < fb->ds.get_width(); x++ ) { for ( int x = 0; x < fb->ds.get_width(); x++ ) {
@@ -156,7 +156,7 @@ void Esc_DECALN( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
static Function func_Esc_DECALN( ESCAPE, "#8", Esc_DECALN ); static Function func_Esc_DECALN( ESCAPE, "#8", Esc_DECALN );
/* line feed */ /* line feed */
void Ctrl_LF( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Ctrl_LF( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->move_rows_autoscroll( 1 ); fb->move_rows_autoscroll( 1 );
} }
@@ -168,7 +168,7 @@ static Function func_Ctrl_VT( CONTROL, "\x0b", Ctrl_LF );
static Function func_Ctrl_FF( CONTROL, "\x0c", Ctrl_LF ); static Function func_Ctrl_FF( CONTROL, "\x0c", Ctrl_LF );
/* carriage return */ /* carriage return */
void Ctrl_CR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Ctrl_CR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->ds.move_col( 0 ); fb->ds.move_col( 0 );
} }
@@ -176,7 +176,7 @@ void Ctrl_CR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
static Function func_Ctrl_CR( CONTROL, "\x0d", Ctrl_CR ); static Function func_Ctrl_CR( CONTROL, "\x0d", Ctrl_CR );
/* backspace */ /* backspace */
void Ctrl_BS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Ctrl_BS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->ds.move_col( -1, true ); fb->ds.move_col( -1, true );
} }
@@ -184,7 +184,7 @@ void Ctrl_BS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
static Function func_Ctrl_BS( CONTROL, "\x08", Ctrl_BS ); static Function func_Ctrl_BS( CONTROL, "\x08", Ctrl_BS );
/* reverse index -- like a backwards line feed */ /* reverse index -- like a backwards line feed */
void Ctrl_RI( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Ctrl_RI( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->move_rows_autoscroll( -1 ); fb->move_rows_autoscroll( -1 );
} }
@@ -192,7 +192,7 @@ void Ctrl_RI( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
static Function func_Ctrl_RI( CONTROL, "\x8D", Ctrl_RI ); static Function func_Ctrl_RI( CONTROL, "\x8D", Ctrl_RI );
/* newline */ /* newline */
void Ctrl_NEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Ctrl_NEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->ds.move_col( 0 ); fb->ds.move_col( 0 );
fb->move_rows_autoscroll( 1 ); fb->move_rows_autoscroll( 1 );
@@ -201,7 +201,7 @@ void Ctrl_NEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
static Function func_Ctrl_NEL( CONTROL, "\x85", Ctrl_NEL ); static Function func_Ctrl_NEL( CONTROL, "\x85", Ctrl_NEL );
/* horizontal tab */ /* horizontal tab */
void Ctrl_HT( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Ctrl_HT( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
int col = fb->ds.get_next_tab(); int col = fb->ds.get_next_tab();
if ( col == -1 ) { /* no tabs, go to end of line */ if ( col == -1 ) { /* no tabs, go to end of line */
@@ -219,7 +219,7 @@ void Ctrl_HT( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
static Function func_Ctrl_HT( CONTROL, "\x09", Ctrl_HT, false ); static Function func_Ctrl_HT( CONTROL, "\x09", Ctrl_HT, false );
/* horizontal tab set */ /* horizontal tab set */
void Ctrl_HTS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Ctrl_HTS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->ds.set_tab(); fb->ds.set_tab();
} }
@@ -227,7 +227,7 @@ void Ctrl_HTS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
static Function func_Ctrl_HTS( CONTROL, "\x88", Ctrl_HTS ); static Function func_Ctrl_HTS( CONTROL, "\x88", Ctrl_HTS );
/* tabulation clear */ /* tabulation clear */
void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch )
{ {
int param = dispatch->getparam( 0, 0 ); int param = dispatch->getparam( 0, 0 );
switch ( param ) { switch ( param ) {
@@ -285,7 +285,7 @@ void set_if_available( bool *mode, bool value )
} }
/* set private mode */ /* set private mode */
void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch )
{ {
for ( int i = 0; i < dispatch->param_count(); i++ ) { for ( int i = 0; i < dispatch->param_count(); i++ ) {
int param = dispatch->getparam( i, 0 ); int param = dispatch->getparam( i, 0 );
@@ -300,7 +300,7 @@ void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch )
} }
/* clear private mode */ /* clear private mode */
void CSI_DECRM( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_DECRM( Framebuffer *fb, Dispatcher *dispatch )
{ {
for ( int i = 0; i < dispatch->param_count(); i++ ) { for ( int i = 0; i < dispatch->param_count(); i++ ) {
int param = dispatch->getparam( i, 0 ); int param = dispatch->getparam( i, 0 );
@@ -327,7 +327,7 @@ static bool *get_ANSI_mode( int param, Framebuffer *fb ) {
} }
/* set mode */ /* set mode */
void CSI_SM( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_SM( Framebuffer *fb, Dispatcher *dispatch )
{ {
for ( int i = 0; i < dispatch->param_count(); i++ ) { for ( int i = 0; i < dispatch->param_count(); i++ ) {
bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb ); bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb );
@@ -338,7 +338,7 @@ void CSI_SM( Framebuffer *fb, Dispatcher *dispatch )
} }
/* clear mode */ /* clear mode */
void CSI_RM( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_RM( Framebuffer *fb, Dispatcher *dispatch )
{ {
for ( int i = 0; i < dispatch->param_count(); i++ ) { for ( int i = 0; i < dispatch->param_count(); i++ ) {
bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb ); bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb );
@@ -352,7 +352,7 @@ static Function func_CSI_SM( CSI, "h", CSI_SM );
static Function func_CSI_RM( CSI, "l", CSI_RM ); static Function func_CSI_RM( CSI, "l", CSI_RM );
/* set top and bottom margins */ /* set top and bottom margins */
void CSI_DECSTBM( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_DECSTBM( Framebuffer *fb, Dispatcher *dispatch )
{ {
int top = dispatch->getparam( 0, 1 ); int top = dispatch->getparam( 0, 1 );
int bottom = dispatch->getparam( 1, fb->ds.get_height() ); int bottom = dispatch->getparam( 1, fb->ds.get_height() );
@@ -371,14 +371,14 @@ void CSI_DECSTBM( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_DECSTMB( CSI, "r", CSI_DECSTBM ); static Function func_CSI_DECSTMB( CSI, "r", CSI_DECSTBM );
/* terminal bell */ /* terminal bell */
void Ctrl_BEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) { static void Ctrl_BEL( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) {
fb->ring_bell(); fb->ring_bell();
} }
static Function func_Ctrl_BEL( CONTROL, "\x07", Ctrl_BEL ); static Function func_Ctrl_BEL( CONTROL, "\x07", Ctrl_BEL );
/* select graphics rendition -- e.g., bold, blinking, etc. */ /* select graphics rendition -- e.g., bold, blinking, etc. */
void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch )
{ {
/* We need to special-case the handling of CSI [34]8 ; 5 ; Ps m, /* We need to special-case the handling of CSI [34]8 ; 5 ; Ps m,
because Ps of 0 in that case does not mean reset to default, even because Ps of 0 in that case does not mean reset to default, even
@@ -404,12 +404,12 @@ void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_SGR( CSI, "m", CSI_SGR, false ); /* changing renditions doesn't clear wrap flag */ static Function func_CSI_SGR( CSI, "m", CSI_SGR, false ); /* changing renditions doesn't clear wrap flag */
/* save and restore cursor */ /* save and restore cursor */
void Esc_DECSC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Esc_DECSC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->ds.save_cursor(); fb->ds.save_cursor();
} }
void Esc_DECRC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Esc_DECRC( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->ds.restore_cursor(); fb->ds.restore_cursor();
} }
@@ -418,7 +418,7 @@ static Function func_Esc_DECSC( ESCAPE, "7", Esc_DECSC );
static Function func_Esc_DECRC( ESCAPE, "8", Esc_DECRC ); static Function func_Esc_DECRC( ESCAPE, "8", Esc_DECRC );
/* device status report -- e.g., cursor position (used by resize) */ /* device status report -- e.g., cursor position (used by resize) */
void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch )
{ {
int param = dispatch->getparam( 0, 0 ); int param = dispatch->getparam( 0, 0 );
@@ -439,7 +439,7 @@ void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_DSR( CSI, "n", CSI_DSR ); static Function func_CSI_DSR( CSI, "n", CSI_DSR );
/* insert line */ /* insert line */
void CSI_IL( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_IL( Framebuffer *fb, Dispatcher *dispatch )
{ {
int lines = dispatch->getparam( 0, 1 ); int lines = dispatch->getparam( 0, 1 );
@@ -455,7 +455,7 @@ void CSI_IL( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_IL( CSI, "L", CSI_IL ); static Function func_CSI_IL( CSI, "L", CSI_IL );
/* delete line */ /* delete line */
void CSI_DL( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_DL( Framebuffer *fb, Dispatcher *dispatch )
{ {
int lines = dispatch->getparam( 0, 1 ); int lines = dispatch->getparam( 0, 1 );
@@ -471,7 +471,7 @@ void CSI_DL( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_DL( CSI, "M", CSI_DL ); static Function func_CSI_DL( CSI, "M", CSI_DL );
/* insert characters */ /* insert characters */
void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch )
{ {
int cells = dispatch->getparam( 0, 1 ); int cells = dispatch->getparam( 0, 1 );
@@ -483,7 +483,7 @@ void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_ICH( CSI, "@", CSI_ICH ); static Function func_CSI_ICH( CSI, "@", CSI_ICH );
/* delete character */ /* delete character */
void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch )
{ {
int cells = dispatch->getparam( 0, 1 ); int cells = dispatch->getparam( 0, 1 );
@@ -495,7 +495,7 @@ void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_DCH( CSI, "P", CSI_DCH ); static Function func_CSI_DCH( CSI, "P", CSI_DCH );
/* line position absolute */ /* line position absolute */
void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch )
{ {
int row = dispatch->getparam( 0, 1 ); int row = dispatch->getparam( 0, 1 );
fb->ds.move_row( row - 1 ); fb->ds.move_row( row - 1 );
@@ -504,7 +504,7 @@ void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_VPA( CSI, "d", CSI_VPA ); static Function func_CSI_VPA( CSI, "d", CSI_VPA );
/* character position absolute */ /* character position absolute */
void CSI_HPA( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_HPA( Framebuffer *fb, Dispatcher *dispatch )
{ {
int col = dispatch->getparam( 0, 1 ); int col = dispatch->getparam( 0, 1 );
fb->ds.move_col( col - 1 ); fb->ds.move_col( col - 1 );
@@ -514,7 +514,7 @@ static Function func_CSI_CHA( CSI, "G", CSI_HPA ); /* ECMA-48 name: CHA */
static Function func_CSI_HPA( CSI, "\x60", CSI_HPA ); /* ECMA-48 name: HPA */ static Function func_CSI_HPA( CSI, "\x60", CSI_HPA ); /* ECMA-48 name: HPA */
/* erase character */ /* erase character */
void CSI_ECH( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_ECH( Framebuffer *fb, Dispatcher *dispatch )
{ {
int num = dispatch->getparam( 0, 1 ); int num = dispatch->getparam( 0, 1 );
int limit = fb->ds.get_cursor_col() + num - 1; int limit = fb->ds.get_cursor_col() + num - 1;
@@ -528,7 +528,7 @@ void CSI_ECH( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_ECH( CSI, "X", CSI_ECH ); static Function func_CSI_ECH( CSI, "X", CSI_ECH );
/* reset to initial state */ /* reset to initial state */
void Esc_RIS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void Esc_RIS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->reset(); fb->reset();
} }
@@ -536,7 +536,7 @@ void Esc_RIS( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
static Function func_Esc_RIS( ESCAPE, "c", Esc_RIS ); static Function func_Esc_RIS( ESCAPE, "c", Esc_RIS );
/* soft reset */ /* soft reset */
void CSI_DECSTR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) ) static void CSI_DECSTR( Framebuffer *fb, Dispatcher *dispatch __attribute((unused)) )
{ {
fb->soft_reset(); fb->soft_reset();
} }
@@ -575,7 +575,7 @@ void Dispatcher::OSC_dispatch( const Parser::OSC_End *act, Framebuffer *fb )
} }
/* scroll down or terminfo indn */ /* scroll down or terminfo indn */
void CSI_SD( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_SD( Framebuffer *fb, Dispatcher *dispatch )
{ {
fb->scroll( dispatch->getparam( 0, 1 ) ); fb->scroll( dispatch->getparam( 0, 1 ) );
} }
@@ -583,7 +583,7 @@ void CSI_SD( Framebuffer *fb, Dispatcher *dispatch )
static Function func_CSI_SD( CSI, "S", CSI_SD ); static Function func_CSI_SD( CSI, "S", CSI_SD );
/* scroll up or terminfo rin */ /* scroll up or terminfo rin */
void CSI_SU( Framebuffer *fb, Dispatcher *dispatch ) static void CSI_SU( Framebuffer *fb, Dispatcher *dispatch )
{ {
fb->scroll( -dispatch->getparam( 0, 1 ) ); fb->scroll( -dispatch->getparam( 0, 1 ) );
} }
+3 -3
View File
@@ -56,7 +56,7 @@ bool verbose = false;
#define NONCE_FMT "%016"PRIx64 #define NONCE_FMT "%016"PRIx64
std::string random_payload( void ) { static std::string random_payload( void ) {
const size_t len = prng.uint32() % MESSAGE_SIZE_MAX; const size_t len = prng.uint32() % MESSAGE_SIZE_MAX;
char *buf = new char[len]; char *buf = new char[len];
prng.fill( buf, len ); prng.fill( buf, len );
@@ -66,7 +66,7 @@ std::string random_payload( void ) {
return payload; return payload;
} }
void test_bad_decrypt( Session &decryption_session ) { static void test_bad_decrypt( Session &decryption_session ) {
std::string bad_ct = random_payload(); std::string bad_ct = random_payload();
bool got_exn = false; bool got_exn = false;
@@ -87,7 +87,7 @@ void test_bad_decrypt( Session &decryption_session ) {
} }
/* Generate a single key and initial nonce, then perform some encryptions. */ /* Generate a single key and initial nonce, then perform some encryptions. */
void test_one_session( void ) { static void test_one_session( void ) {
Base64Key key; Base64Key key;
Session encryption_session( key ); Session encryption_session( key );
Session decryption_session( key ); Session decryption_session( key );
+8 -8
View File
@@ -55,24 +55,24 @@ using Crypto::AlignedBuffer;
bool verbose = false; bool verbose = false;
bool equal( const AlignedBuffer &a, const AlignedBuffer &b ) { static bool equal( const AlignedBuffer &a, const AlignedBuffer &b ) {
return ( a.len() == b.len() ) return ( a.len() == b.len() )
&& !memcmp( a.data(), b.data(), a.len() ); && !memcmp( a.data(), b.data(), a.len() );
} }
AlignedBuffer *get_ctx( const AlignedBuffer &key ) { static AlignedBuffer *get_ctx( const AlignedBuffer &key ) {
AlignedBuffer *ctx_buf = new AlignedBuffer( ae_ctx_sizeof() ); AlignedBuffer *ctx_buf = new AlignedBuffer( ae_ctx_sizeof() );
fatal_assert( ctx_buf ); fatal_assert( ctx_buf );
fatal_assert( AE_SUCCESS == ae_init( (ae_ctx *)ctx_buf->data(), key.data(), key.len(), NONCE_LEN, TAG_LEN ) ); fatal_assert( AE_SUCCESS == ae_init( (ae_ctx *)ctx_buf->data(), key.data(), key.len(), NONCE_LEN, TAG_LEN ) );
return ctx_buf; return ctx_buf;
} }
void scrap_ctx( AlignedBuffer *ctx_buf ) { static void scrap_ctx( AlignedBuffer *ctx_buf ) {
fatal_assert( AE_SUCCESS == ae_clear( (ae_ctx *)ctx_buf->data() ) ); fatal_assert( AE_SUCCESS == ae_clear( (ae_ctx *)ctx_buf->data() ) );
delete ctx_buf; delete ctx_buf;
} }
void test_encrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, static void test_encrypt( const AlignedBuffer &key, const AlignedBuffer &nonce,
const AlignedBuffer &plaintext, const AlignedBuffer &assoc, const AlignedBuffer &plaintext, const AlignedBuffer &assoc,
const AlignedBuffer &expected_ciphertext ) { const AlignedBuffer &expected_ciphertext ) {
AlignedBuffer *ctx_buf = get_ctx( key ); AlignedBuffer *ctx_buf = get_ctx( key );
@@ -97,7 +97,7 @@ void test_encrypt( const AlignedBuffer &key, const AlignedBuffer &nonce,
scrap_ctx( ctx_buf ); scrap_ctx( ctx_buf );
} }
void test_decrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, static void test_decrypt( const AlignedBuffer &key, const AlignedBuffer &nonce,
const AlignedBuffer &ciphertext, const AlignedBuffer &assoc, const AlignedBuffer &ciphertext, const AlignedBuffer &assoc,
const AlignedBuffer &expected_plaintext, const AlignedBuffer &expected_plaintext,
bool valid ) { bool valid ) {
@@ -129,7 +129,7 @@ void test_decrypt( const AlignedBuffer &key, const AlignedBuffer &nonce,
scrap_ctx( ctx_buf ); scrap_ctx( ctx_buf );
} }
void test_vector( const char *key_p, const char *nonce_p, static void test_vector( const char *key_p, const char *nonce_p,
size_t assoc_len, const char *assoc_p, size_t assoc_len, const char *assoc_p,
size_t plaintext_len, const char *plaintext_p, size_t plaintext_len, const char *plaintext_p,
size_t ciphertext_len, const char *ciphertext_p ) { size_t ciphertext_len, const char *ciphertext_p ) {
@@ -172,7 +172,7 @@ void test_vector( const char *key_p, const char *nonce_p,
#define TEST_VECTOR( _key, _nonce, _assoc, _pt, _ct ) \ #define TEST_VECTOR( _key, _nonce, _assoc, _pt, _ct ) \
test_vector( _key, _nonce, sizeof(_assoc)-1, _assoc, sizeof(_pt)-1, _pt, sizeof(_ct)-1, _ct ) test_vector( _key, _nonce, sizeof(_assoc)-1, _assoc, sizeof(_pt)-1, _pt, sizeof(_ct)-1, _ct )
void test_all_vectors( void ) { static void test_all_vectors( void ) {
/* Test vectors from http://tools.ietf.org/html/draft-krovetz-ocb-03#appendix-A */ /* Test vectors from http://tools.ietf.org/html/draft-krovetz-ocb-03#appendix-A */
const char ietf_key[] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"; const char ietf_key[] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F";
@@ -463,7 +463,7 @@ void test_all_vectors( void ) {
/* http://tools.ietf.org/html/draft-krovetz-ocb-03#appendix-A /* http://tools.ietf.org/html/draft-krovetz-ocb-03#appendix-A
also specifies an iterative test algorithm, which we implement here. */ also specifies an iterative test algorithm, which we implement here. */
void test_iterative( void ) { static void test_iterative( void ) {
/* Key is always all zeros */ /* Key is always all zeros */
AlignedBuffer key( KEY_LEN ); AlignedBuffer key( KEY_LEN );
memset( key.data(), 0, KEY_LEN ); memset( key.data(), 0, KEY_LEN );