From 4fc9ae69a714973e6a779e0149495ce3258b601c Mon Sep 17 00:00:00 2001 From: Derek Weitzel Date: Mon, 2 Oct 2023 13:16:57 -0500 Subject: [PATCH] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- test/asynch.cc | 119 +++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/test/asynch.cc b/test/asynch.cc index e9a4e64..0c57e70 100644 --- a/test/asynch.cc +++ b/test/asynch.cc @@ -8,9 +8,8 @@ #include "../src/scitokens.h" void -usage( const char * self ) { - fprintf( stderr, "usage: %s encoded-scitoken\n", self ); -} +void usage(const char *self) { + fprintf(stderr, "usage: %s encoded-scitoken\n", self); void void print_claim(SciToken &token, const char *claim) { @@ -23,7 +22,7 @@ void print_claim(SciToken &token, const char *claim) { return; } fprintf( stdout, "%s = %s\n", claim, value ); -} + fprintf(stdout, "%s = %s\n", claim, value); int main(int argc, char **argv) { @@ -34,91 +33,93 @@ int main(int argc, char **argv) { const char *encoded = argv[1]; int rv; char * error; - SciToken token; + char *error; - // Set the cache to the CWD while testing. char cache_path[FILENAME_MAX]; if( getcwd(cache_path, sizeof(cache_path)) == NULL ) { - fprintf( stderr, "Failed to determine cwd, aborting.\n" ); - exit( -5 ); - } + if (getcwd(cache_path, sizeof(cache_path)) == NULL) { + fprintf(stderr, "Failed to determine cwd, aborting.\n"); + exit(-5); const char * key = "keycache.cache_home"; - rv = scitoken_config_set_str( key, cache_path, & error ); - if( rv != 0 ) { - fprintf( stderr, "Failed to set %s: %s, aborting.\n", key, cache_path ); - exit( -5 ); - } + const char *key = "keycache.cache_home"; + rv = scitoken_config_set_str(key, cache_path, &error); + if (rv != 0) { + fprintf(stderr, "Failed to set %s: %s, aborting.\n", key, cache_path); + exit(-5); - // Asynchronous API. SciTokenStatus status; rv = scitoken_deserialize_start( - encoded, & token, NULL, & status, & error - ); - if( rv != 0 ) { - fprintf( stderr, "scitoken_deserialize_start() failed: %s\n", error ); - exit( -2 ); - } + rv = scitoken_deserialize_start(encoded, &token, NULL, &status, &error); + if (rv != 0) { + fprintf(stderr, "scitoken_deserialize_start() failed: %s\n", error); + exit(-2); if( status == NULL ) { - fprintf( stderr, "scitoken_deserialize_start() returned a token\n" ); - exit( 1 ); - } + if (status == NULL) { + fprintf(stderr, "scitoken_deserialize_start() returned a token\n"); + exit(1); - do { fd_set * read_fds = NULL; - rv = scitoken_status_get_read_fd_set( & status, & read_fds, & error ); - if( rv != 0 ) { - fprintf( stderr, "scitoken_status_get_read_fd_set() failed: %s\n", error ); - exit( -2 ); - } + fd_set *read_fds = NULL; + rv = scitoken_status_get_read_fd_set(&status, &read_fds, &error); + if (rv != 0) { + fprintf(stderr, "scitoken_status_get_read_fd_set() failed: %s\n", + error); + exit(-2); fd_set * write_fds = NULL; - rv = scitoken_status_get_write_fd_set( & status, & write_fds, & error ); - if( rv != 0 ) { - fprintf( stderr, "scitoken_status_get_write_fd_set() failed: %s\n", error ); - exit( -2 ); - } + fd_set *write_fds = NULL; + rv = scitoken_status_get_write_fd_set(&status, &write_fds, &error); + if (rv != 0) { + fprintf(stderr, "scitoken_status_get_write_fd_set() failed: %s\n", + error); + exit(-2); fd_set * except_fds = NULL; - rv = scitoken_status_get_exc_fd_set( & status, & except_fds, & error ); - if( rv != 0 ) { - fprintf( stderr, "scitoken_status_get_exc_fd_set() failed: %s\n", error ); - exit( -2 ); - } + fd_set *except_fds = NULL; + rv = scitoken_status_get_exc_fd_set(&status, &except_fds, &error); + if (rv != 0) { + fprintf(stderr, "scitoken_status_get_exc_fd_set() failed: %s\n", + error); + exit(-2); int max_fds; rv = scitoken_status_get_max_fd( & status, & max_fds, & error ); - if( rv != 0 ) { - fprintf( stderr, "scitoken_status_get_max_fds() failed: %s\n", error ); - exit( -2 ); - } + rv = scitoken_status_get_max_fd(&status, &max_fds, &error); + if (rv != 0) { + fprintf(stderr, "scitoken_status_get_max_fds() failed: %s\n", + error); + exit(-2); struct timeval time_out{1, 0}; - int s = select( max_fds + 1, read_fds, write_fds, except_fds, & time_out ); - if( s == -1 ) { - fprintf( stderr, "select() failed: %s (%d)\n", strerror(errno), errno ); - exit( -4 ); - } else if( s == 0 ) { - fprintf( stderr, "select() timed out, checking for progress.\n" ); - } + struct timeval time_out { + 1, 0 + }; + int s = select(max_fds + 1, read_fds, write_fds, except_fds, &time_out); + if (s == -1) { + fprintf(stderr, "select() failed: %s (%d)\n", strerror(errno), + errno); + exit(-4); + } else if (s == 0) { + fprintf(stderr, "select() timed out, checking for progress.\n"); fprintf( stderr, "Calling scitoken_deserialize_continue()...\n" ); - rv = scitoken_deserialize_continue( & token, & status, & error ); - if( rv != 0 ) { - fprintf( stderr, "scitoken_deserialize_continue() failed: %s\n", error ); - exit( -3 ); - } + fprintf(stderr, "Calling scitoken_deserialize_continue()...\n"); + rv = scitoken_deserialize_continue(&token, &status, &error); + if (rv != 0) { + fprintf(stderr, "scitoken_deserialize_continue() failed: %s\n", + error); + exit(-3); } while( status != NULL ); - - + } while (status != NULL); print_claim(token, "ver"); print_claim(token, "aud"); print_claim(token, "iss"); print_claim(token, "jti"); scitoken_destroy( token ); - return 0; + scitoken_destroy(token); }