websocket.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Sapphire backend
  3. *
  4. * Copyright (C) 2018 Alyssa Rosenzweig
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
  19. *
  20. */
  21. #ifndef __WEBSOCKET_H_
  22. #define __WEBSOCKET_H_
  23. #include <libsoup/soup.h>
  24. #include <purple.h>
  25. /* Represents a connection to a given client. Minimal state should be kept
  26. * here, since connections are device-specific, not for the client as a whole.
  27. * Essentially, just enough for the websocket metadata and a little potpourrie */
  28. typedef struct Connection {
  29. /* The reference counted connection itself */
  30. GSocketConnection *connection;
  31. GDataInputStream *distream;
  32. /* Has this connection authenticated yet? */
  33. gboolean is_authenticated;
  34. /* Subscribed conversation IDs, for which */
  35. GHashTable *subscribed_ids;
  36. } Connection;
  37. void sapphire_init_websocket(void);
  38. void sapphire_send_raw_packet(Connection *conn, const char *packet);
  39. void sapphire_broadcast_raw_packet(const char *packet);
  40. gboolean sapphire_any_connected_clients(void);
  41. void sapphire_add_buddy_icon(const gchar *name, PurpleBuddyIcon *icon);
  42. void sapphire_add_stored_image(const gchar *name, PurpleStoredImage *img);
  43. void sapphire_send_any_or_save(char *packet);
  44. #endif