From 41c6deee4688894819fc97f4547794b8dfa86a16 Mon Sep 17 00:00:00 2001 From: miker Date: Mon, 23 Jul 2007 17:44:46 +0000 Subject: [PATCH] Patch from Scott McKellar providing: 1. In handle_print(), I added the ability to display the value of raw_print. If we can display pretty_print, we should be able to display raw_print. 2. In a couple of places we display the value of login_session. However if we aren't logged in, we end up passing NULL to printf(), thereby invoking undefined behavior. Apparently glibc responds by printing "(null)". I contrived explicitly to print "(none)" rather than rely on glibc. 3. Since login_session is assigned from strdup() if not NULL, I added a free() for it in a couple of places: one at the end of main(), and one just before the assignment from strdup(). git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1057 9efc2488-bf62-4759-914b-345cdb29e865 --- src/srfsh/srfsh.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/srfsh/srfsh.c b/src/srfsh/srfsh.c index 72f40b1..de6f125 100644 --- a/src/srfsh/srfsh.c +++ b/src/srfsh/srfsh.c @@ -182,6 +182,7 @@ int main( int argc, char* argv[] ) { write_history(history_file); free(request); + free(login_session); osrf_system_shutdown(); return 0; @@ -394,12 +395,15 @@ static int handle_login( char* words[]) { jsonObjectGetKey(jsonObjectGetKey(x,"payload"), "authtoken")); authtime = jsonObjectGetNumber( jsonObjectGetKey(jsonObjectGetKey(x,"payload"), "authtime")); - if(authtoken) login_session = strdup(authtoken); - else login_session = NULL; + if(authtoken) { + free(login_session); + login_session = strdup(authtoken); + } else login_session = NULL; } else login_session = NULL; - printf("Login Session: %s. Session timeout: %f\n", login_session, authtime ); + printf("Login Session: %s. Session timeout: %f\n", + (login_session ? login_session : "(none)"), authtime ); return 1; @@ -463,8 +467,19 @@ static int handle_print( char* words[]) { } } + if(!strcmp(variable,"raw_print")) { + if(raw_print) { + printf("raw_print = true\n"); + return 1; + } else { + printf("raw_print = false\n"); + return 1; + } + } + if(!strcmp(variable,"login")) { - printf("login session = %s\n", login_session ); + printf("login session = %s\n", + login_session ? login_session : "(none)" ); return 1; } -- 2.43.2