This patch adds some minor functionality, and tidies up the treatment
of the login_session variable.
-----------
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().
-----------
As I worked on this patch, I noticed that there is no simple way
to log out, and then a thought occurred to me. What happens if
we're logged in and then we log in again, possibly with a different
username and/or password? What if the second login is unsuccessful
-- does the first login remain in effect? Or do things just get
terribly confused?
I don't see any obvious attempt to log out from a previous login,
but I also don't know what such an attempt would look like if it
were there.
Scott McKellar
*** trunk/src/srfsh/srfsh.c 2007-07-22 08:32:35.000000000 -0500
--- trunk-mod/src/srfsh/srfsh.c 2007-07-22 09:15:40.000000000 -0500
***************
*** 182,187 ****
--- 182,188 ----
write_history(history_file);
free(request);
+ free(login_session);
osrf_system_shutdown();
return 0;
***************
*** 394,405 ****
jsonObjectGetKey(jsonObjectGetKey(x,"payload"), "authtoken"));
authtime = jsonObjectGetNumber(
jsonObjectGetKey(jsonObjectGetKey(x,"payload"), "authtime"));
! if(authtoken) login_session = strdup(authtoken);
! else login_session = NULL;
}
else login_session = NULL;
! printf("Login Session: %s. Session timeout: %f\n", login_session, authtime );
return 1;
--- 395,409 ----
jsonObjectGetKey(jsonObjectGetKey(x,"payload"), "authtoken"));
authtime = jsonObjectGetNumber(
jsonObjectGetKey(jsonObjectGetKey(x,"payload"), "authtime"));
! 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 ? login_session : "(none)"), authtime );
return 1;
***************
*** 463,470 ****
}
}
if(!strcmp(variable,"login")) {
! printf("login session = %s\n", login_session );
return 1;
}
--- 467,485 ----
}
}
+ 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 ? login_session : "(none)" );
return 1;
}