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.

118 lines
3.5 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. diff --git a/core/Makefile b/core/Makefile
  10. index c1c65fc..987bd7b 100644
  11. --- a/core/Makefile
  12. +++ b/core/Makefile
  13. @@ -16,7 +16,6 @@ SSL_CFLAGS=$(shell pkg-config --cflags openssl)
  14. SSL_LDLAGS=$(shell pkg-config --libs openssl)
  15. OBJECTS:=quasselc-connector.o quassel-core.o
  16. OBJECTS+=quassel-net.o quassel-msgs.o quassel-cmds.o
  17. -OBJECTS+=irssi/network-openssl.o
  18. OBJECTS+=quassel-fe-window.o quassel-fe-level.o quassel-cfg.o
  19. LDFLAGS ?=
  20. diff --git a/core/quassel-net.c b/core/quassel-net.c
  21. index 8a6eb55..5db7fe0 100644
  22. --- a/core/quassel-net.c
  23. +++ b/core/quassel-net.c
  24. @@ -132,10 +132,10 @@ static SERVER_REC* quassel_server_init_connect(SERVER_CONNECT_REC* conn) {
  25. ret->got = 0;
  26. server_connect_ref(SERVER_CONNECT(conn));
  27. - if(conn->use_ssl) {
  28. + if(conn->use_tls) {
  29. ret->ssl = 1;
  30. }
  31. - ret->connrec->use_ssl = 0;
  32. + ret->connrec->use_tls = 0;
  33. ret->channels_join = quassel_irssi_channels_join;
  34. ret->send_message = quassel_irssi_send_message;
  35. @@ -161,12 +161,59 @@ void quassel_net_init(CHAT_PROTOCOL_REC* rec) {
  36. signal_add_first("server connected", (SIGNAL_FUNC) sig_connected);
  37. }
  38. -GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_REC *server);
  39. +static void quassel_net_final_setup(SERVER_REC* server, GIOChannel *handle) {
  40. + quassel_login(handle, server->connrec->nick, server->connrec->password);
  41. + server->handle->handle = handle;
  42. +
  43. + server->readtag =
  44. + g_input_add(handle,
  45. + G_INPUT_READ,
  46. + (GInputFunction) quassel_parse_incoming, server);
  47. +}
  48. +
  49. +static void quassel_net_ssl_callback(SERVER_REC *server, GIOChannel *handle) {
  50. + int error;
  51. +
  52. + g_return_if_fail(IS_SERVER(server));
  53. +
  54. + error = irssi_ssl_handshake(handle);
  55. + if (error == -1) {
  56. + server->connection_lost = TRUE;
  57. + server_connect_failed(server, NULL);
  58. + return;
  59. + }
  60. + if (error & 1) {
  61. + if (server->connect_tag != -1)
  62. + g_source_remove(server->connect_tag);
  63. + server->connect_tag = g_input_add(handle, error == 1 ? G_INPUT_READ : G_INPUT_WRITE,
  64. + (GInputFunction)
  65. + quassel_net_ssl_callback,
  66. + server);
  67. + return;
  68. + }
  69. +
  70. + if (server->connect_tag != -1) {
  71. + g_source_remove(server->connect_tag);
  72. + server->connect_tag = -1;
  73. + }
  74. +
  75. + quassel_net_final_setup(server, handle);
  76. +}
  77. +
  78. void quassel_irssi_init_ack(void *arg) {
  79. Quassel_SERVER_REC *server = (Quassel_SERVER_REC*)arg;
  80. - if(!server->ssl)
  81. - goto login;
  82. - GIOChannel* ssl_handle = irssi_ssl_get_iochannel(server->handle->handle, 1337, SERVER(server));
  83. + GIOChannel* ssl_handle = net_start_ssl((SERVER_REC*)server);
  84. +
  85. + if(server->readtag != -1) {
  86. + g_source_remove(server->readtag);
  87. + server->readtag = -1;
  88. + }
  89. +
  90. + if(!server->ssl) {
  91. + quassel_net_final_setup((SERVER_REC*)server, server->handle->handle);
  92. + return;
  93. + }
  94. +
  95. int error;
  96. //That's polling, and that's really bad...
  97. while( (error=irssi_ssl_handshake(ssl_handle)) & 1) {
  98. @@ -175,10 +222,7 @@ void quassel_irssi_init_ack(void *arg) {
  99. return;
  100. }
  101. }
  102. - server->handle->handle = ssl_handle;
  103. -
  104. -login:
  105. - quassel_login(server->handle->handle, server->connrec->nick, server->connrec->password);
  106. + quassel_net_ssl_callback((SERVER_REC*)server, ssl_handle);
  107. }
  108. void quassel_irssi_init_nack(void *arg) {
  109. --
  110. 2.17.1