mike-jumper commented on code in PR #358:
URL: https://github.com/apache/guacamole-server/pull/358#discussion_r1016893339
##########
src/libguac/client.c:
##########
@@ -701,6 +739,116 @@ int guac_client_owner_supports_required(guac_client*
client) {
}
+/**
+ * A callback function that is invokved by guac_client_owner_notify_join() to
+ * notify the owner of a connection that another user has joined the
+ * connection, returning zero if the message is sent successfully, or non-zero
+ * if an error occurs.
+ *
+ * @param user
+ * The user to send the notification to, which will be the owner of the
+ * connection.
+ *
+ * @param data
+ * The data provided to the callback, which is the user that is joining the
+ * connection.
+ *
+ * @return
+ * Zero if the message is sent successfully to the owner, otherwise
+ * non-zero, cast as a void*.
+ */
+static void* guac_client_owner_notify_join_callback(guac_user* user, void*
data) {
+
+ const guac_user* joiner = (const guac_user *) data;
+
+ if (user == NULL)
+ return (void*) ((intptr_t) -1);
+
+ char* owner = "owner";
+ if (user->info.name != NULL)
+ owner = (char *) user->info.name;
+
+ char* joinName = "anonymous";
+ if (joiner->info.name != NULL)
+ joinName = (char *) joiner->info.name;
+
+ guac_user_log(user, GUAC_LOG_DEBUG, "Notifying owner \"%s\" of \"%s\"
joining.", owner, joinName);
+
+ /* Send required parameters to owner. */
Review Comment:
Is this copypasta from `guac_client_owner_send_required_callback()`?
##########
src/libguac/client.c:
##########
@@ -701,6 +739,116 @@ int guac_client_owner_supports_required(guac_client*
client) {
}
+/**
+ * A callback function that is invokved by guac_client_owner_notify_join() to
+ * notify the owner of a connection that another user has joined the
+ * connection, returning zero if the message is sent successfully, or non-zero
+ * if an error occurs.
+ *
+ * @param user
+ * The user to send the notification to, which will be the owner of the
+ * connection.
+ *
+ * @param data
+ * The data provided to the callback, which is the user that is joining the
+ * connection.
+ *
+ * @return
+ * Zero if the message is sent successfully to the owner, otherwise
+ * non-zero, cast as a void*.
+ */
+static void* guac_client_owner_notify_join_callback(guac_user* user, void*
data) {
+
+ const guac_user* joiner = (const guac_user *) data;
+
+ if (user == NULL)
+ return (void*) ((intptr_t) -1);
+
+ char* owner = "owner";
+ if (user->info.name != NULL)
+ owner = (char *) user->info.name;
+
+ char* joinName = "anonymous";
+ if (joiner->info.name != NULL)
+ joinName = (char *) joiner->info.name;
+
+ guac_user_log(user, GUAC_LOG_DEBUG, "Notifying owner \"%s\" of \"%s\"
joining.", owner, joinName);
+
+ /* Send required parameters to owner. */
+ const char* args[] = { (const char*)joinName, NULL };
+ return (void*) ((intptr_t) guac_protocol_send_msg(user->socket,
GUAC_MESSAGE_USER_JOINED, args));
+
+}
+
+int guac_client_owner_notify_join(guac_client* client, guac_user* joiner) {
+
+ /* Don't send msg instruction if client does not support it. */
+ if (!guac_client_owner_supports_msg(client)) {
+ guac_client_log(client, GUAC_LOG_DEBUG,
+ "Client does not support the \"msg\" instruction and "
+ "will not be notified of the user joining the
connection.");
+ return -1;
+ }
+
+ return (int) ((intptr_t) guac_client_for_owner(client,
guac_client_owner_notify_join_callback, joiner));
+
+}
+
+/**
+ * A callback function that is invokved by guac_client_owner_notify_leave() to
+ * notify the owner of a connection that another user has left the connection,
+ * returning zero if the message is sent successfully, or non-zero
+ * if an error occurs.
+ *
+ * @param user
+ * The user to send the notification to, which will be the owner of the
+ * connection.
+ *
+ * @param data
+ * The data provided to the callback, which is the user that is leaving the
+ * connection.
+ *
+ * @return
+ * Zero if the message is sent successfully to the owner, otherwise
+ * non-zero, cast as a void*.
+ */
+static void* guac_client_owner_notify_leave_callback(guac_user* user, void*
data) {
+
+ const guac_user* quitter = (const guac_user *) data;
+
+ if (user == NULL)
+ return (void*) ((intptr_t) -1);
+
+ char* ownerName = "owner";
+ if (user->info.name != NULL)
+ ownerName = (char *) user->info.name;
+
+ char* quitterName = "anonymous";
+ if (quitter->info.name != NULL)
+ quitterName = (char *) quitter->info.name;
+
+ guac_user_log(user, GUAC_LOG_DEBUG, "Notifying owner \"%s\" of \"%s\"
leaving.", ownerName, quitterName);
+
+ /* Send required parameters to owner. */
Review Comment:
Same here - copypasta from `guac_client_owner_send_required_callback()`?
##########
src/libguac/client.c:
##########
@@ -701,6 +739,116 @@ int guac_client_owner_supports_required(guac_client*
client) {
}
+/**
+ * A callback function that is invokved by guac_client_owner_notify_join() to
+ * notify the owner of a connection that another user has joined the
+ * connection, returning zero if the message is sent successfully, or non-zero
+ * if an error occurs.
+ *
+ * @param user
+ * The user to send the notification to, which will be the owner of the
+ * connection.
+ *
+ * @param data
+ * The data provided to the callback, which is the user that is joining the
+ * connection.
+ *
+ * @return
+ * Zero if the message is sent successfully to the owner, otherwise
+ * non-zero, cast as a void*.
+ */
+static void* guac_client_owner_notify_join_callback(guac_user* user, void*
data) {
+
+ const guac_user* joiner = (const guac_user *) data;
+
+ if (user == NULL)
+ return (void*) ((intptr_t) -1);
+
+ char* owner = "owner";
+ if (user->info.name != NULL)
+ owner = (char *) user->info.name;
+
+ char* joinName = "anonymous";
+ if (joiner->info.name != NULL)
+ joinName = (char *) joiner->info.name;
+
+ guac_user_log(user, GUAC_LOG_DEBUG, "Notifying owner \"%s\" of \"%s\"
joining.", owner, joinName);
+
+ /* Send required parameters to owner. */
+ const char* args[] = { (const char*)joinName, NULL };
Review Comment:
While I agree it makes sense to log something human-readable in the event
this is missing ("anonymous", "owner"), I think the value we send via `msg` for
`GUAC_MESSAGE_USER_JOINED` and `GUAC_MESSAGES_USER_LEFT` should be strictly the
value we receive, or perhaps empty string if `NULL`. If an implementation were
to assign its own meaning to the literal `"anonymous"` and send it voluntarily
via `name`, then this automatically-assigned value would collide with that.
##########
src/libguac/client.c:
##########
@@ -701,6 +739,116 @@ int guac_client_owner_supports_required(guac_client*
client) {
}
+/**
+ * A callback function that is invokved by guac_client_owner_notify_join() to
+ * notify the owner of a connection that another user has joined the
+ * connection, returning zero if the message is sent successfully, or non-zero
+ * if an error occurs.
+ *
+ * @param user
+ * The user to send the notification to, which will be the owner of the
+ * connection.
+ *
+ * @param data
+ * The data provided to the callback, which is the user that is joining the
+ * connection.
+ *
+ * @return
+ * Zero if the message is sent successfully to the owner, otherwise
+ * non-zero, cast as a void*.
+ */
+static void* guac_client_owner_notify_join_callback(guac_user* user, void*
data) {
+
+ const guac_user* joiner = (const guac_user *) data;
+
+ if (user == NULL)
+ return (void*) ((intptr_t) -1);
+
+ char* owner = "owner";
+ if (user->info.name != NULL)
+ owner = (char *) user->info.name;
+
+ char* joinName = "anonymous";
+ if (joiner->info.name != NULL)
+ joinName = (char *) joiner->info.name;
+
+ guac_user_log(user, GUAC_LOG_DEBUG, "Notifying owner \"%s\" of \"%s\"
joining.", owner, joinName);
+
+ /* Send required parameters to owner. */
+ const char* args[] = { (const char*)joinName, NULL };
Review Comment:
For `GUAC_MESSAGE_USER_JOINED` and `GUAC_MESSAGES_USER_LEFT`, thoughts on
including the unique ID automatically assigned by guacd? For example:
```
const char* args[] = { joiner->user_id, (const char*) joinName, NULL };
```
In the event that an implementation assigns the same human-readable name to
two or more users of a connection, including the unique ID would allow the
receiving client to reliably differentiate between them.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]