You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.3 KiB

  1. From 19e810405789a35b92026b56ea49d01a3f544b07 Mon Sep 17 00:00:00 2001
  2. From: Pierre-Hugues Husson <phh@phh.me>
  3. Date: Tue, 17 Jan 2017 23:09:24 +0100
  4. Subject: [PATCH] Get compatible with potential irssi abi 8, and drop polling
  5. ---
  6. core/Makefile | 1 -
  7. core/quassel-net.c | 64 ++++++++++++++++++++++++++++++++++++++--------
  8. 2 files changed, 53 insertions(+), 10 deletions(-)
  9. --- a/core/Makefile
  10. +++ b/core/Makefile
  11. @@ -16,7 +16,6 @@ SSL_CFLAGS=$(shell pkg-config --cflags o
  12. SSL_LDLAGS=$(shell pkg-config --libs openssl)
  13. OBJECTS:=quasselc-connector.o quassel-core.o
  14. OBJECTS+=quassel-net.o quassel-msgs.o quassel-cmds.o
  15. -OBJECTS+=irssi/network-openssl.o
  16. OBJECTS+=quassel-fe-window.o quassel-fe-level.o quassel-cfg.o
  17. LDFLAGS ?=
  18. --- a/core/quassel-net.c
  19. +++ b/core/quassel-net.c
  20. @@ -132,10 +132,10 @@ static SERVER_REC* quassel_server_init_c
  21. ret->got = 0;
  22. server_connect_ref(SERVER_CONNECT(conn));
  23. - if(conn->use_ssl) {
  24. + if(conn->use_tls) {
  25. ret->ssl = 1;
  26. }
  27. - ret->connrec->use_ssl = 0;
  28. + ret->connrec->use_tls = 0;
  29. ret->channels_join = quassel_irssi_channels_join;
  30. ret->send_message = quassel_irssi_send_message;
  31. @@ -161,12 +161,59 @@ void quassel_net_init(CHAT_PROTOCOL_REC*
  32. signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
  33. }
  34. -GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_REC *server);
  35. +static void quassel_net_final_setup(SERVER_REC* server, GIOChannel *handle) {
  36. + quassel_login(handle, server->connrec->nick, server->connrec->password);
  37. + server->handle->handle = handle;
  38. +
  39. + server->readtag =
  40. + g_input_add(handle,
  41. + G_INPUT_READ,
  42. + (GInputFunction) quassel_parse_incoming, server);
  43. +}
  44. +
  45. +static void quassel_net_ssl_callback(SERVER_REC *server, GIOChannel *handle) {
  46. + int error;
  47. +
  48. + g_return_if_fail(IS_SERVER(server));
  49. +
  50. + error = irssi_ssl_handshake(handle);
  51. + if (error == -1) {
  52. + server->connection_lost = TRUE;
  53. + server_connect_failed(server, NULL);
  54. + return;
  55. + }
  56. + if (error & 1) {
  57. + if (server->connect_tag != -1)
  58. + g_source_remove(server->connect_tag);
  59. + server->connect_tag = g_input_add(handle, error == 1 ? G_INPUT_READ : G_INPUT_WRITE,
  60. + (GInputFunction)
  61. + quassel_net_ssl_callback,
  62. + server);
  63. + return;
  64. + }
  65. +
  66. + if (server->connect_tag != -1) {
  67. + g_source_remove(server->connect_tag);
  68. + server->connect_tag = -1;
  69. + }
  70. +
  71. + quassel_net_final_setup(server, handle);
  72. +}
  73. +
  74. void quassel_irssi_init_ack(void *arg) {
  75. Quassel_SERVER_REC *server = (Quassel_SERVER_REC*)arg;
  76. - if(!server->ssl)
  77. - goto login;
  78. - GIOChannel* ssl_handle = irssi_ssl_get_iochannel(server->handle->handle, 1337, SERVER(server));
  79. + GIOChannel* ssl_handle = net_start_ssl((SERVER_REC*)server);
  80. +
  81. + if(server->readtag != -1) {
  82. + g_source_remove(server->readtag);
  83. + server->readtag = -1;
  84. + }
  85. +
  86. + if(!server->ssl) {
  87. + quassel_net_final_setup((SERVER_REC*)server, server->handle->handle);
  88. + return;
  89. + }
  90. +
  91. int error;
  92. //That's polling, and that's really bad...
  93. while( (error=irssi_ssl_handshake(ssl_handle)) & 1) {
  94. @@ -175,10 +222,7 @@ void quassel_irssi_init_ack(void *arg) {
  95. return;
  96. }
  97. }
  98. - server->handle->handle = ssl_handle;
  99. -
  100. -login:
  101. - quassel_login(server->handle->handle, server->connrec->nick, server->connrec->password);
  102. + quassel_net_ssl_callback((SERVER_REC*)server, ssl_handle);
  103. }
  104. void quassel_irssi_init_nack(void *arg) {