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



##########
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:
       Correct. There does not need to be a corresponding call to 
`pthread_potato_destroy()` so long as it's a statically-allocated potato.




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