1. Fixed a bug whereby the display of request results was not showing up
authorscottmk <scottmk@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 10 Nov 2009 22:50:14 +0000 (22:50 +0000)
committerscottmk <scottmk@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 10 Nov 2009 22:50:14 +0000 (22:50 +0000)
when pretty-printing was turned off.  We were calling jsonObjectGetString()
when we should have been calling jsonObjectToJSON(), and thereby getting
NULL instead of a usable string, for any but the most trivial of results.

Also: applied some minor refinements to nearby code.

2. In handle_request(): eliminated a couple of superfluous variables.

3. Corrected an erroneous statement in the help message.  Request output
passes through less when raw_print is false, not when it's true.

4. Tidied up the white space here and there.

M    src/srfsh/srfsh.c

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1848 9efc2488-bf62-4759-914b-345cdb29e865

src/srfsh/srfsh.c

index e99d5cc..b3013f5 100644 (file)
@@ -703,12 +703,10 @@ static int handle_request( const osrfStringArray* cmd_array, int relay ) {
        if(!client)
                return 1;
 
-       const char* word_1 = osrfStringArrayGetString( cmd_array, 1 );
-       const char* word_2 = osrfStringArrayGetString( cmd_array, 2 );
+       const char* server = osrfStringArrayGetString( cmd_array, 1 );
+       const char* method = osrfStringArrayGetString( cmd_array, 2 );
 
-       if( word_1 ) {
-               const char* server = word_1;
-               const char* method = word_2;
+       if( server ) {
                int i;
                growing_buffer* buffer = NULL;
                if( !relay ) {
@@ -823,17 +821,18 @@ int send_request( const char* server,
        
                                if( pretty_print ) {
                                        char* j = jsonObjectToJSON(omsg->_result_content);
-                                       //content = json_printer(j); 
-                                       content = jsonFormatString(j);
-                                       free(j);
+                                       if( j ) {
+                                               content = jsonFormatString(j);
+                                               free(j);
+                                       } else
+                                               content = strdup( "(null)" );
                                } else {
-                                       const char * temp_content = jsonObjectGetString(omsg->_result_content);
-                                       if( ! temp_content )
-                                               temp_content = "[null]";
-                                       content = strdup( temp_content );
+                                       content = jsonObjectToJSON(omsg->_result_content);
+                                       if( ! content )
+                                               content = strdup( "(null)" );
                                }
-                               
-                               printf( "\nReceived Data: %s\n", content ); 
+
+                               printf( "\nReceived Data: %s\n", content );
                                free(content);
        
                        } else {
@@ -860,24 +859,24 @@ int send_request( const char* server,
        
                                if( pretty_print && omsg->_result_content ) {
                                        char* j = jsonObjectToJSON(omsg->_result_content);
-                                       //content = json_printer(j); 
-                                       content = jsonFormatString(j);
-                                       free(j);
+                                       if( j ) {
+                                               content = jsonFormatString(j);
+                                               free(j);
+                                       } else
+                                               content = strdup( "(null)" );
                                } else {
-                                       const char * temp_content = jsonObjectGetString(omsg->_result_content);
-                                       if( temp_content )
-                                               content = strdup( temp_content );
-                                       else
-                                               content = NULL;
+                                       content = jsonObjectToJSON(omsg->_result_content);
+                                       if( ! content )
+                                               content = strdup( "(null)" );
                                }
 
-                               buffer_add( resp_buffer, "\nReceived Data: " ); 
+                               buffer_add( resp_buffer, "\nReceived Data: " );
                                buffer_add( resp_buffer, content );
-                               buffer_add( resp_buffer, "\n" );
+                               buffer_add_char( resp_buffer, '\n' );
                                free(content);
-       
+
                        } else {
-       
+
                                buffer_add( resp_buffer, "\nReceived Exception:\nName: " );
                                buffer_add( resp_buffer, omsg->status_name );
                                buffer_add( resp_buffer, "\nStatus: " );
@@ -906,7 +905,7 @@ int send_request( const char* server,
        fprintf(less, "Request Time in seconds: %.6f\n", end - start );
        fputs("------------------------------------\n", less);
 
-       pclose(less); 
+       pclose(less);
 
        osrf_app_session_request_finish( session, req_id );
 
@@ -1026,8 +1025,8 @@ static int print_help( void ) {
                        "       - To view the session id later, enter: print login\n"
                        "---------------------------------------------------------------------------------\n"
                        "\n"
-                       "Note: long output is piped through 'less' when the 'raw_print' variable is true.\n"
-                       "To search in 'less', type: /<search>\n"
+                       "Note: long output is piped through 'less' unless the 'raw_print' variable\n"
+                       "is true.  To search in 'less', type: /<search>\n"
                        "---------------------------------------------------------------------------------\n"
                        "\n",
                        stdout );