gint session_start_tls(Session *session) { gboolean nb_mode; nb_mode = sock_is_nonblocking_mode(session->sock); if (nb_mode) sock_set_nonblocking_mode(session->sock, FALSE); if (!ssl_init_socket_with_method(session->sock, SSL_METHOD_TLSv1)) { g_warning("can't start TLS session.\n"); if (nb_mode) sock_set_nonblocking_mode(session->sock, TRUE); return -1; } if (nb_mode) sock_set_nonblocking_mode(session->sock, session->nonblocking); return 0; }
static gint session_connect_cb(SockInfo *sock, gpointer data) { Session *session = SESSION(data); session->conn_id = 0; if (!sock) { g_warning("can't connect to server."); session->state = SESSION_ERROR; return -1; } session->sock = sock; #if USE_OPENSSL if (session->ssl_type == SSL_TUNNEL) { sock_set_nonblocking_mode(sock, FALSE); if (!ssl_init_socket(sock)) { g_warning("can't initialize SSL."); session->state = SESSION_ERROR; return -1; } } #endif sock_set_nonblocking_mode(sock, session->nonblocking); debug_print("session (%p): connected\n", session); session->state = SESSION_RECV; session->io_tag = sock_add_watch(session->sock, G_IO_IN, session_read_msg_cb, session); return 0; }
void notification_lcdproc_connect(void) { gint len, count; gchar buf[NOTIFICATION_LCDPROC_BUFFER_SIZE]; if(!notify_config.lcdproc_enabled) return; if(sock) notification_lcdproc_disconnect(); sock = sock_connect(notify_config.lcdproc_hostname, notify_config.lcdproc_port); /* * Quietly return when a connection fails; next attempt * will be made when some folder info has been changed. */ if(sock == NULL || sock->state == CONN_FAILED) { debug_print("Could not connect to LCDd\n"); if(sock && sock->state == CONN_FAILED) { sock_close(sock, TRUE); sock = NULL; } return; } else debug_print("Connected to LCDd\n"); sock_set_nonblocking_mode(sock, TRUE); /* Friendly people say "hello" first */ notification_sock_puts(sock, "hello"); /* FIXME: Ouch. Is this really the way to go? */ count = 50; len = 0; while((len <= 0) && (count-- >= 0)) { g_usleep(125000); len = sock_read(sock, buf, NOTIFICATION_LCDPROC_BUFFER_SIZE); } /* * This might not be a LCDProc server. * FIXME: check LCD size, LCDd version etc */ if (len <= 0) { debug_print("Notification plugin: Can't communicate with " "LCDd server! Are you sure that " "there is a LCDd server running on %s:%d?\n", notify_config.lcdproc_hostname, notify_config.lcdproc_port); notification_lcdproc_disconnect(); return; } notification_lcdproc_send("client_set -name \"{Claws-Mail}\""); notification_lcdproc_send("screen_add msg_counts"); notification_lcdproc_send("screen_set msg_counts -name {Claws-Mail Message Count}"); notification_lcdproc_send("widget_add msg_counts title title"); notification_lcdproc_send("widget_set msg_counts title {Claws-Mail}"); notification_lcdproc_send("widget_add msg_counts line1 string"); notification_lcdproc_send("widget_add msg_counts line2 string"); notification_lcdproc_send("widget_add msg_counts line3 string"); notification_update_msg_counts(NULL); }