necouchman commented on a change in pull request #297:
URL: https://github.com/apache/guacamole-server/pull/297#discussion_r451067213



##########
File path: src/libguac/argv.c
##########
@@ -0,0 +1,350 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "config.h"
+
+#include "guacamole/argv.h"
+#include "guacamole/client.h"
+#include "guacamole/protocol.h"
+#include "guacamole/socket.h"
+#include "guacamole/stream.h"
+#include "guacamole/string.h"
+#include "guacamole/user.h"
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * The state of an argument that will be automatically processed. Note that
+ * this is distinct from the state of an argument value that is currently being
+ * processed. Argument value states are dynamically-allocated and scoped by the
+ * associated guac_stream.
+ */
+typedef struct guac_argv_state {
+
+    /**
+     * The name of the argument.
+     */
+    char name[GUAC_ARGV_MAX_NAME_LENGTH];
+
+    /**
+     * Whether at least one value for this argument has been received since it
+     * was registered.
+     */
+    int received;
+
+    /**
+     * Bitwise OR of all option flags that should affect processing of this
+     * argument.
+     */
+    int options;
+
+    /**
+     * The callback that should be invoked when a new value for the associated
+     * argument has been received. If the GUAC_ARGV_OPTION_ONCE flag is set,
+     * the callback will be invoked at most once.
+     */
+    guac_argv_callback* callback;
+
+    /**
+     * The arbitrary data that should be passed to the callback.
+     */
+    void* data;
+
+} guac_argv_state;
+
+/**
+ * The current state of automatic processing of "argv" streams.
+ */
+typedef struct guac_argv_await_state {
+
+    /**
+     * Whether automatic argument processing has been stopped via a call to
+     * guac_argv_stop().
+     */
+    int stopped;
+
+    /**
+     * The total number of arguments registered.
+     */
+    unsigned int num_registered;
+
+    /**
+     * All registered arguments and their corresponding callbacks.
+     */
+    guac_argv_state registered[GUAC_ARGV_MAX_REGISTERED];
+
+    /**
+     * Lock which protects multi-threaded access to this entire state
+     * structure, including the condition that signals specific modifications
+     * to the structure.
+     */
+    pthread_mutex_t lock;
+
+    /**
+     * Condition which is signalled whenever the overall state of "argv"
+     * processing changes, either through the receipt of a new argument value
+     * or due to a call to guac_argv_stop().
+     */
+    pthread_cond_t changed;
+
+} guac_argv_await_state;
+
+/**
+ * The value or current status of a connection parameter received over an
+ * "argv" stream.
+ */
+typedef struct guac_argv {
+
+    /**
+     * The state of the specific setting being updated.
+     */
+    guac_argv_state* state;
+
+    /**
+     * The mimetype of the data being received.
+     */
+    char mimetype[GUAC_ARGV_MAX_MIMETYPE_LENGTH];
+
+    /**
+     * Buffer space for containing the received argument value.
+     */
+    char buffer[GUAC_ARGV_MAX_LENGTH];
+
+    /**
+     * The number of bytes received so far.
+     */
+    int length;
+
+} guac_argv;
+
+/**
+ * Statically-allocated, shared state of the guac_argv_*() family of functions.
+ */
+static guac_argv_await_state await_state = {
+    .lock = PTHREAD_MUTEX_INITIALIZER,
+    .changed = PTHREAD_COND_INITIALIZER
+};

Review comment:
       I'm guessing statically allocated `mutex`/`cond` don't have to be 
`free`d?  Or is it just assumed that it'll be freed when the process is shut 
down?

##########
File path: src/libguac/argv.c
##########
@@ -0,0 +1,350 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "config.h"
+
+#include "guacamole/argv.h"
+#include "guacamole/client.h"
+#include "guacamole/protocol.h"
+#include "guacamole/socket.h"
+#include "guacamole/stream.h"
+#include "guacamole/string.h"
+#include "guacamole/user.h"
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * The state of an argument that will be automatically processed. Note that
+ * this is distinct from the state of an argument value that is currently being
+ * processed. Argument value states are dynamically-allocated and scoped by the
+ * associated guac_stream.
+ */
+typedef struct guac_argv_state {
+
+    /**
+     * The name of the argument.
+     */
+    char name[GUAC_ARGV_MAX_NAME_LENGTH];
+
+    /**
+     * Whether at least one value for this argument has been received since it
+     * was registered.
+     */
+    int received;
+
+    /**
+     * Bitwise OR of all option flags that should affect processing of this
+     * argument.
+     */
+    int options;
+
+    /**
+     * The callback that should be invoked when a new value for the associated
+     * argument has been received. If the GUAC_ARGV_OPTION_ONCE flag is set,
+     * the callback will be invoked at most once.
+     */
+    guac_argv_callback* callback;
+
+    /**
+     * The arbitrary data that should be passed to the callback.
+     */
+    void* data;
+
+} guac_argv_state;
+
+/**
+ * The current state of automatic processing of "argv" streams.
+ */
+typedef struct guac_argv_await_state {
+
+    /**
+     * Whether automatic argument processing has been stopped via a call to
+     * guac_argv_stop().
+     */
+    int stopped;
+
+    /**
+     * The total number of arguments registered.
+     */
+    unsigned int num_registered;

Review comment:
       I must just be missing it, but where is this variable initialized?  I 
see the static allocation of .lock and .changed, but I don't see that this is 
ever set to zero?  Or does that happen automatically during the static 
allocation below?

##########
File path: src/protocols/telnet/user.c
##########
@@ -92,7 +92,7 @@ int guac_telnet_user_join_handler(guac_user* user, int argc, 
char** argv) {
         user->pipe_handler = guac_telnet_pipe_handler;
 
         /* Updates to connection parameters */
-        user->argv_handler = guac_telnet_argv_handler;
+        user->argv_handler = guac_argv_handler;

Review comment:
       Looks like this is consistently changed to the `guac_argv_handler` for 
all of the protocols - does it make sense to continue to allow this to be 
configurable, or is it something that should be changed in the `guac_user` code 
such that `guac_argv_handler` is always what is called?
   
   I'm good with it either way, just curious - I'm all for leaving things 
flexible/configurable, just wasn't sure if the new `argv` code is intended to 
be the new flexible/configurable framework that is always referred to, or if 
there are foreseeable situations where you'd still want to change that?




----------------------------------------------------------------
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]


Reply via email to