]> www.infradead.org Git - pidgin-chime.git/commitdiff
Add meeting_authz support
authorDavid Woodhouse <dwmw@amazon.co.uk>
Sat, 11 Nov 2023 19:37:21 +0000 (19:37 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Sun, 12 Nov 2023 02:14:24 +0000 (21:14 -0500)
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
chime/chime-meeting.c
chime/chime-meeting.h

index fba2c8858c98223cbede1c6c61b139ddaba2a243..9945e6a26a453845822be45a036dd4f44c23cf70 100644 (file)
@@ -778,6 +778,74 @@ ChimeMeeting *chime_connection_lookup_meeting_by_pin_finish(ChimeConnection *sel
        return g_task_propagate_pointer(G_TASK(result), error);
 }
 
+static void meet_authz_cb(ChimeConnection *cxn, SoupMessage *msg,
+                         JsonNode *node, gpointer user_data)
+{
+       GTask *task = G_TASK(user_data);
+
+       if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code) && node) {
+               const gchar *access_req_id = NULL;
+
+               if (parse_string(node, "AccessRequestId", &access_req_id)) {
+                       g_task_return_pointer(task, g_strdup(access_req_id),
+                                             g_free);
+               } else {
+                       g_task_return_new_error(task, CHIME_ERROR,
+                                               CHIME_ERROR_BAD_RESPONSE,
+                                               _("Meeting authorisation response had no AccessRequstId"));
+               }
+       } else {
+               const gchar *reason;
+       eparse:
+               reason = msg->reason_phrase;
+
+               if (node)
+                       parse_string(node, "Message", &reason);
+
+               g_task_return_new_error(task, CHIME_ERROR,
+                                       CHIME_ERROR_NETWORK,
+                                       _("Failed to obtain meeting authorisation: %s"),
+                                       reason);
+       }
+
+       g_object_unref(task);
+}
+
+void chime_connection_meeting_authz_by_pin_async(ChimeConnection *cxn,
+                                                const gchar *pin,
+                                                GCancellable *cancellable,
+                                                GAsyncReadyCallback callback,
+                                                gpointer user_data)
+{
+       g_return_if_fail(CHIME_IS_CONNECTION(cxn));
+       ChimeConnectionPrivate *priv = chime_connection_get_private (cxn);
+
+       GTask *task = g_task_new(cxn, cancellable, callback, user_data);
+
+       JsonBuilder *jb = json_builder_new();
+       jb = json_builder_begin_object(jb);
+       jb = json_builder_set_member_name(jb, "Passcode");
+       jb = json_builder_add_string_value(jb, pin);
+       jb = json_builder_end_object(jb);
+
+       JsonNode *node = json_builder_get_root(jb);
+       SoupURI *uri = soup_uri_new_printf(priv->express_url, "/meetings/v3/meeting_authz");
+       chime_connection_queue_http_request(cxn, node, uri, "POST", meet_authz_cb, task);
+       json_node_unref(node);
+       g_object_unref(jb);
+
+}
+
+char *chime_connection_meeting_authz_by_pin_finish(ChimeConnection *self,
+                                                  GAsyncResult *result,
+                                                  GError **error)
+{
+       g_return_val_if_fail(CHIME_IS_CONNECTION(self), FALSE);
+       g_return_val_if_fail(g_task_is_valid(result, self), FALSE);
+
+       return g_task_propagate_pointer(G_TASK(result), error);
+}
+
 
 static void chime_connection_open_meeting(ChimeConnection *cxn, ChimeMeeting *meeting, GTask *task)
 {
index c2a4ae3badbfb653d945ef6981c31ee9b908f9a8..eb54caf3207d246999b6c40b41ac5be94c177dc5 100644 (file)
@@ -130,6 +130,16 @@ ChimeMeeting *chime_connection_lookup_meeting_by_pin_finish(ChimeConnection *sel
                                                            GAsyncResult *result,
                                                            GError **error);
 
+void chime_connection_meeting_authz_by_pin_async(ChimeConnection *cxn,
+                                                 const gchar *pin,
+                                                 GCancellable *cancellable,
+                                                 GAsyncReadyCallback callback,
+                                                 gpointer user_data);
+
+char *chime_connection_meeting_authz_by_pin_finish(ChimeConnection *self,
+                                                  GAsyncResult *result,
+                                                  GError **error);
+
 void chime_connection_join_meeting_async(ChimeConnection *cxn,
                                         ChimeMeeting *meeting,
                                         gboolean audio,