mike-jumper commented on a change in pull request #219: GUACAMOLE-422: Add 
timezone to client handshake
URL: https://github.com/apache/guacamole-server/pull/219#discussion_r277071384
 
 

 ##########
 File path: src/libguac/user-handshake.c
 ##########
 @@ -305,96 +379,53 @@ int guac_user_handle_connection(guac_user* user, int 
usec_timeout) {
 
     guac_parser* parser = guac_parser_alloc();
 
-    /* Get optimal screen size */
-    if (guac_parser_expect(parser, socket, usec_timeout, "size")) {
-
-        /* Log error */
-        guac_user_log_handshake_failure(user);
-        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
-                "Error reading \"size\"");
-
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Validate content of size instruction */
-    if (parser->argc < 2) {
-        guac_user_log(user, GUAC_LOG_ERROR, "Received \"size\" "
-                "instruction lacked required arguments.");
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Parse optimal screen dimensions from size instruction */
-    user->info.optimal_width  = atoi(parser->argv[0]);
-    user->info.optimal_height = atoi(parser->argv[1]);
-
-    /* If DPI given, set the user resolution */
-    if (parser->argc >= 3)
-        user->info.optimal_resolution = atoi(parser->argv[2]);
-
-    /* Otherwise, use a safe default for rough backwards compatibility */
-    else
-        user->info.optimal_resolution = 96;
-
-    /* Get supported audio formats */
-    if (guac_parser_expect(parser, socket, usec_timeout, "audio")) {
-
-        /* Log error */
-        guac_user_log_handshake_failure(user);
-        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
-                "Error reading \"audio\"");
-
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Store audio mimetypes */
-    char** audio_mimetypes = guac_copy_mimetypes(parser->argv, parser->argc);
-    user->info.audio_mimetypes = (const char**) audio_mimetypes;
-
-    /* Get supported video formats */
-    if (guac_parser_expect(parser, socket, usec_timeout, "video")) {
-
-        /* Log error */
-        guac_user_log_handshake_failure(user);
-        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
-                "Error reading \"video\"");
-
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Store video mimetypes */
-    char** video_mimetypes = guac_copy_mimetypes(parser->argv, parser->argc);
-    user->info.video_mimetypes = (const char**) video_mimetypes;
-
-    /* Get supported image formats */
-    if (guac_parser_expect(parser, socket, usec_timeout, "image")) {
-
-        /* Log error */
-        guac_user_log_handshake_failure(user);
-        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
-                "Error reading \"image\"");
-
-        guac_parser_free(parser);
-        return 1;
-    }
-
-    /* Store image mimetypes */
-    char** image_mimetypes = guac_copy_mimetypes(parser->argv, parser->argc);
-    user->info.image_mimetypes = (const char**) image_mimetypes;
-
-    /* Get args from connect instruction */
-    if (guac_parser_expect(parser, socket, usec_timeout, "connect")) {
-
-        /* Log error */
-        guac_user_log_handshake_failure(user);
-        guac_user_log_guac_error(user, GUAC_LOG_DEBUG,
-                "Error reading \"connect\"");
+    /* Handle each of the opcodes. */
+    while (1) {
 
 Review comment:
   I think the usual structure would be (pseudocode):
   
       while (instruction successfully read) {
           handle_success;
       }
   
       handle_failure;
   
   In our case, though, we have more like:
   
       while (handshake_in_progress) {
           handle_handshake_instruction;
       }
   
       this_might_be_failure_or_success;
   
   I'm not sure myself how this could be arranged as-is to remove the unbounded 
loop, given that the exit condition of the loop would be ambiguously either 
success or failure. Things might be easier/cleaner if the actual internal 
handshake handling were its own function. Then you'd end up with something like:
   
       if (init_user_with_handshake(stuff))
           handle_failure;
   
       add_user_to_connection
   
   with the actual function being the expected:
   
       while (instruction successfully read) {
   
           if (instruction_is_connect)
               return 0;
   
           handle_instruction;
       }
   
       handle_failure;
       return 1;
   
   I'm sure there's a way to rearrange the logic such that we have a net gain 
in readability, part of that readability being an explicit loop bound.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to