static void server_setup_fill_chatnet(SERVER_CONNECT_REC *conn, CHATNET_REC *chatnet) { g_return_if_fail(IS_SERVER_CONNECT(conn)); g_return_if_fail(IS_CHATNET(chatnet)); if (chatnet->nick != NULL && chatnet->nick[0] != '\0') { g_free(conn->nick); conn->nick = g_strdup(chatnet->nick);; } if (chatnet->username != NULL && chatnet->username[0] != '\0') { g_free(conn->username); conn->username = g_strdup(chatnet->username);; } if (chatnet->realname != NULL && chatnet->realname[0] != '\0') { g_free(conn->realname); conn->realname = g_strdup(chatnet->realname);; } if (chatnet->own_host != NULL) { conn_set_ip(conn, chatnet->own_host, &chatnet->own_ip4, &chatnet->own_ip6); } signal_emit("server setup fill chatnet", 2, conn, chatnet); }
static void server_setup_fill_server(SERVER_CONNECT_REC *conn, SERVER_SETUP_REC *sserver) { g_return_if_fail(IS_SERVER_CONNECT(conn)); g_return_if_fail(IS_SERVER_SETUP(sserver)); sserver->last_connect = time(NULL); if (sserver->no_proxy) g_free_and_null(conn->proxy); if (sserver->family != 0 && conn->family == 0) conn->family = sserver->family; if (sserver->port > 0 && conn->port <= 0) conn->port = sserver->port; conn->use_ssl = sserver->use_ssl; if (conn->ssl_cert == NULL && sserver->ssl_cert != NULL && sserver->ssl_cert[0] != '\0') conn->ssl_cert = g_strdup(sserver->ssl_cert); if (conn->ssl_pkey == NULL && sserver->ssl_pkey != NULL && sserver->ssl_pkey[0] != '\0') conn->ssl_pkey = g_strdup(sserver->ssl_pkey); conn->ssl_verify = sserver->ssl_verify; if (conn->ssl_cafile == NULL && sserver->ssl_cafile != NULL && sserver->ssl_cafile[0] != '\0') conn->ssl_cafile = g_strdup(sserver->ssl_cafile); if (conn->ssl_capath == NULL && sserver->ssl_capath != NULL && sserver->ssl_capath[0] != '\0') conn->ssl_capath = g_strdup(sserver->ssl_capath); server_setup_fill_reconn(conn, sserver); signal_emit("server setup fill server", 2, conn, sserver); }
static void server_reconnect_add(SERVER_CONNECT_REC *conn, time_t next_connect) { RECONNECT_REC *rec; g_return_if_fail(IS_SERVER_CONNECT(conn)); rec = g_new(RECONNECT_REC, 1); rec->tag = ++last_reconnect_tag; rec->conn = conn; rec->next_connect = next_connect; reconnects = g_slist_append(reconnects, rec); }
void server_connect_unref(SERVER_CONNECT_REC *conn) { g_return_if_fail(IS_SERVER_CONNECT(conn)); if (--conn->refcount > 0) return; if (conn->refcount < 0) { g_warning("Connection '%s' refcount = %d", conn->tag, conn->refcount); } CHAT_PROTOCOL(conn)->destroy_server_connect(conn); if (conn->connect_handle != NULL) net_disconnect(conn->connect_handle); g_free_not_null(conn->proxy); g_free_not_null(conn->proxy_string); g_free_not_null(conn->proxy_string_after); g_free_not_null(conn->proxy_password); g_free_not_null(conn->tag); g_free_not_null(conn->address); g_free_not_null(conn->chatnet); g_free_not_null(conn->own_ip4); g_free_not_null(conn->own_ip6); g_free_not_null(conn->password); g_free_not_null(conn->nick); g_free_not_null(conn->username); g_free_not_null(conn->realname); g_free_not_null(conn->tls_cert); g_free_not_null(conn->tls_pkey); g_free_not_null(conn->tls_pass); g_free_not_null(conn->tls_cafile); g_free_not_null(conn->tls_capath); g_free_not_null(conn->tls_ciphers); g_free_not_null(conn->tls_pinned_cert); g_free_not_null(conn->tls_pinned_pubkey); g_free_not_null(conn->channels); g_free_not_null(conn->away_reason); conn->type = 0; g_free(conn); }
/* Fill information to connection from server setup record */ void server_setup_fill_reconn(SERVER_CONNECT_REC *conn, SERVER_SETUP_REC *sserver) { g_return_if_fail(IS_SERVER_CONNECT(conn)); g_return_if_fail(IS_SERVER_SETUP(sserver)); if (sserver->own_host != NULL) { conn_set_ip(conn, sserver->own_host, &sserver->own_ip4, &sserver->own_ip6); } if (sserver->chatnet != NULL && conn->chatnet == NULL) conn->chatnet = g_strdup(sserver->chatnet); if (sserver->password != NULL && conn->password == NULL) conn->password = g_strdup(sserver->password); signal_emit("server setup fill reconn", 2, conn, sserver); }
/* create unique tag for server. prefer ircnet's name or generate it from server's address */ static char *server_create_tag(SERVER_CONNECT_REC *conn) { GString *str; char *tag; int num; g_return_val_if_fail(IS_SERVER_CONNECT(conn), NULL); tag = conn->chatnet != NULL && *conn->chatnet != '\0' ? g_strdup(conn->chatnet) : server_create_address_tag(conn->address); if (conn->tag != NULL && server_find_tag(conn->tag) == NULL && server_find_lookup_tag(conn->tag) == NULL && strncmp(conn->tag, tag, strlen(tag)) == 0) { /* use the existing tag if it begins with the same ID - this is useful when you have several connections to same server and you want to keep the same tags with the servers (or it would cause problems when rejoining /LAYOUT SAVEd channels). */ g_free(tag); return g_strdup(conn->tag); } /* then just append numbers after tag until unused is found.. */ str = g_string_new(tag); num = 2; while (server_find_tag(str->str) != NULL || server_find_lookup_tag(str->str) != NULL) { g_string_sprintf(str, "%s%d", tag, num); num++; } g_free(tag); tag = str->str; g_string_free(str, FALSE); return tag; }