]> www.infradead.org Git - pidgin-chime.git/commitdiff
Unbreak websocket connect
authorDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 12 Sep 2017 02:54:40 +0000 (19:54 -0700)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Tue, 12 Sep 2017 02:54:44 +0000 (19:54 -0700)
And make it slightly easier to submit requests with the session_token,
which we'll need for screen shares AFAICT.

chime-call-audio.c
chime-connection-private.h
chime-juggernaut.c
chime-websocket-connection.h
chime-websocket.c

index 6f009f5b74f4d52d3da5e280dcf8d311482b7547..64a8d44f056a75b1e0b9501dbb47a165ae5ffcc5 100644 (file)
@@ -233,7 +233,7 @@ static void audio_ws_connect_cb(GObject *obj, GAsyncResult *res, gpointer _task)
        ChimeCall *call = CHIME_CALL(g_task_get_task_data(task));
 
        GError *error = NULL;
-       SoupWebsocketConnection *ws = soup_session_websocket_connect_finish(SOUP_SESSION(obj), res, &error);
+       SoupWebsocketConnection *ws = chime_connection_websocket_connect_finish(CHIME_CONNECTION(obj), res, &error);
        if (!ws) {
                g_task_return_error(task, error);
                return;
@@ -270,8 +270,8 @@ void chime_connection_join_call_audio_async(ChimeConnection *cxn,
        SoupMessage *msg = soup_message_new_from_uri("GET", uri);
        soup_uri_free(uri);
 
-       soup_session_websocket_connect_async(priv->soup_sess, msg, NULL, NULL, NULL,
-                                            audio_ws_connect_cb, task);
+       chime_connection_websocket_connect_async(cxn, msg, NULL, NULL, NULL,
+                                                audio_ws_connect_cb, task);
 }
 
 ChimeCallAudio *chime_connection_join_call_audio_finish(ChimeConnection *self,
index a62f668a45a9c150cc4487818ac37ea55793105f..53b8a8ca3f8907dd418bd25593cf0370fc4b2683 100644 (file)
@@ -40,8 +40,6 @@
 #define soup_websocket_connection_send_text chime_websocket_connection_send_text
 #define soup_websocket_connection_send_binary chime_websocket_connection_send_binary
 #define soup_websocket_connection_close chime_websocket_connection_close
-#define soup_session_websocket_connect_async chime_session_websocket_connect_async
-#define soup_session_websocket_connect_finish chime_session_websocket_connect_finish
 #define SoupWebsocketConnection ChimeWebsocketConnection
 #endif
 
@@ -163,6 +161,22 @@ typedef struct {
 
 #define chime_debug(...) do { if (getenv("CHIME_DEBUG")) printf(__VA_ARGS__); } while (0)
 
+/* chime-websocket.c */
+/* Like the soup_session_ variants, but with the auth retry */
+void
+chime_connection_websocket_connect_async (ChimeConnection      *cxn,
+                                         SoupMessage          *msg,
+                                         const char           *origin,
+                                         char                **protocols,
+                                         GCancellable         *cancellable,
+                                         GAsyncReadyCallback   callback,
+                                         gpointer              user_data);
+
+SoupWebsocketConnection *
+chime_connection_websocket_connect_finish (ChimeConnection  *cxn,
+                                          GAsyncResult     *result,
+                                          GError          **error);
+
 /* chime-connection.c */
 void chime_connection_fail(ChimeConnection *cxn, gint code,
                           const gchar *format, ...);
index 1da28a8342c015edeb9aca55e4b7fc02b3c9d44f..ef3bda79477d9f6da6bff18b1adcec7f0ab5f617 100644 (file)
@@ -230,11 +230,11 @@ static void send_resubscribe_message(ChimeConnection *cxn)
 
 static void jugg_ws_connect_cb(GObject *obj, GAsyncResult *res, gpointer _cxn)
 {
-       ChimeConnection *cxn = CHIME_CONNECTION(_cxn);
+       ChimeConnection *cxn = CHIME_CONNECTION(obj);
        ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn);
        GError *error = NULL;
 
-       priv->ws_conn = soup_session_websocket_connect_finish(SOUP_SESSION(obj), res, &error);
+       priv->ws_conn = chime_connection_websocket_connect_finish(cxn, res, &error);
        if (!priv->ws_conn) {
                chime_connection_fail(cxn, CHIME_ERROR_NETWORK,
                                      _("Failed to establish WebSocket connection: %s\n"),
@@ -257,8 +257,6 @@ static void jugg_ws_connect_cb(GObject *obj, GAsyncResult *res, gpointer _cxn)
 
        if (priv->subscriptions)
                send_resubscribe_message(cxn);
-
-       g_object_unref(cxn);
 }
 
 static void ws_key_cb(ChimeConnection *cxn, SoupMessage *msg, JsonNode *node, gpointer _unused)
@@ -295,8 +293,8 @@ static void ws_key_cb(ChimeConnection *cxn, SoupMessage *msg, JsonNode *node, gp
        msg = soup_message_new_from_uri("GET", uri);
        soup_uri_free(uri);
 
-       soup_session_websocket_connect_async(priv->soup_sess, msg, NULL, NULL, NULL,
-                                            jugg_ws_connect_cb, cxn);
+       chime_connection_websocket_connect_async(cxn, msg, NULL, NULL, NULL,
+                                                jugg_ws_connect_cb, cxn);
 }
 
 
index a48a510677b3aae1000e3b5c75edb2d89b840ae8..2c390b14325b24aea9413eb25b209c0c2d10eef9 100644 (file)
@@ -105,21 +105,6 @@ void                chime_websocket_connection_set_keepalive_interval (ChimeWebs
                                                                       guint                    interval);
 
 
-/* These are from soup-session.c, modified in chime-websocket.c */
-void
-chime_session_websocket_connect_async (SoupSession          *session,
-                                      SoupMessage          *msg,
-                                      const char           *origin,
-                                      char                **protocols,
-                                      GCancellable         *cancellable,
-                                      GAsyncReadyCallback   callback,
-                                      gpointer              user_data);
-
-ChimeWebsocketConnection *
-chime_session_websocket_connect_finish (SoupSession      *session,
-                                       GAsyncResult     *result,
-                                       GError          **error);
-
 G_END_DECLS
 
 #endif /* __CHIME_WEBSOCKET_CONNECTION_H__ */
index d5f8b2f96ea05f312eefc5e82804ac7ad0d6e508..c86b7906c972278ef758da8b60f94a84e71f241b 100644 (file)
@@ -1,5 +1,3 @@
-#ifndef USE_LIBSOUP_WEBSOCKETS
-
 /* Lifted from soup-session.c */
 
 #include <libsoup/soup.h>
@@ -28,9 +26,8 @@ static void
 websocket_connect_async_stop (SoupMessage *msg, gpointer user_data)
 {
        GTask *task = G_TASK(user_data);
-       SoupSession *sess = SOUP_SESSION(g_task_get_task_data (task));
-       GIOStream *stream;
-       ChimeWebsocketConnection *client;
+       ChimeConnection *cxn = CHIME_CONNECTION(g_task_get_task_data (task));
+       ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn);
        GError *error = NULL;
 
        /* Disconnect websocket_connect_async_stop() handler. */
@@ -39,12 +36,12 @@ websocket_connect_async_stop (SoupMessage *msg, gpointer user_data)
 
        g_object_ref(msg);
        if (soup_websocket_client_verify_handshake (msg, &error)) {
-               stream = soup_session_steal_connection (sess, msg);
-               client = chime_websocket_connection_new (stream,
-                                                        soup_message_get_uri (msg),
-                                                        SOUP_WEBSOCKET_CONNECTION_CLIENT,
-                                                        soup_message_headers_get_one (msg->request_headers, "Origin"),
-                                                        soup_message_headers_get_one (msg->response_headers, "Sec-WebSocket-Protocol"));
+               GIOStream *stream = soup_session_steal_connection (priv->soup_sess, msg);
+               ChimeWebsocketConnection *client = chime_websocket_connection_new (stream,
+                                soup_message_get_uri (msg),
+                                SOUP_WEBSOCKET_CONNECTION_CLIENT,
+                                soup_message_headers_get_one (msg->request_headers, "Origin"),
+                                soup_message_headers_get_one (msg->response_headers, "Sec-WebSocket-Protocol"));
                g_object_unref (stream);
 
                g_task_return_pointer (task, client, g_object_unref);
@@ -88,28 +85,28 @@ websocket_connect_async_stop (SoupMessage *msg, gpointer user_data)
  * Since: 2.50
  */
 void
-chime_session_websocket_connect_async (SoupSession          *session,
-                                      SoupMessage          *msg,
-                                      const char           *origin,
-                                      char                **protocols,
-                                      GCancellable         *cancellable,
-                                      GAsyncReadyCallback   callback,
-                                      gpointer              user_data)
+chime_connection_websocket_connect_async (ChimeConnection      *cxn,
+                                         SoupMessage          *msg,
+                                         const char           *origin,
+                                         char                **protocols,
+                                         GCancellable         *cancellable,
+                                         GAsyncReadyCallback   callback,
+                                         gpointer              user_data)
 {
-       GTask *task;
-
-       g_return_if_fail (SOUP_IS_SESSION (session));
+       g_return_if_fail (CHIME_IS_CONNECTION (cxn));
        g_return_if_fail (SOUP_IS_MESSAGE (msg));
 
+       ChimeConnectionPrivate *priv = CHIME_CONNECTION_GET_PRIVATE (cxn);
+
        soup_websocket_client_prepare_handshake (msg, origin, protocols);
 
-       task = g_task_new (session, cancellable, callback, user_data);
-       g_task_set_task_data (task, g_object_ref(session), g_object_unref);
+       GTask *task = g_task_new (cxn, cancellable, callback, user_data);
+       g_task_set_task_data (task, g_object_ref(cxn), g_object_unref);
 
        soup_message_add_status_code_handler (msg, "got-informational",
                                              SOUP_STATUS_SWITCHING_PROTOCOLS,
                                              G_CALLBACK (websocket_connect_async_stop), task);
-       soup_session_queue_message(session, msg, websocket_connect_async_complete, task);
+       soup_session_queue_message(priv->soup_sess, msg, websocket_connect_async_complete, task);
 }
 
 /**
@@ -129,14 +126,13 @@ chime_session_websocket_connect_async (SoupSession          *session,
  * Since: 2.50
  */
 ChimeWebsocketConnection *
-chime_session_websocket_connect_finish (SoupSession      *session,
-                                      GAsyncResult     *result,
-                                      GError          **error)
+chime_connection_websocket_connect_finish (ChimeConnection  *cxn,
+                                          GAsyncResult     *result,
+                                          GError          **error)
 {
-       g_return_val_if_fail (SOUP_IS_SESSION (session), NULL);
-       g_return_val_if_fail (g_task_is_valid (result, session), NULL);
+       g_return_val_if_fail (CHIME_IS_CONNECTION (cxn), NULL);
+       g_return_val_if_fail (g_task_is_valid (result, cxn), NULL);
 
        return g_task_propagate_pointer (G_TASK (result), error);
 }
 
-#endif