static gboolean client_allowed (RemoteDisplayHost *host, SoupClientContext *client) { RemoteDisplayHostPrivate *priv = GET_PRIVATE (host); GSocketAddress *remote_sock; GInetAddress *remote_addr; remote_sock = soup_client_context_get_remote_address (client); remote_addr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (remote_sock)); return g_inet_address_equal (remote_addr, priv->remote_address); }
gboolean __g_socket_address_equal (GSocketAddress * a, GSocketAddress * b) { GInetSocketAddress *ia, *ib; GInetAddress *iaa, *iab; ia = G_INET_SOCKET_ADDRESS (a); ib = G_INET_SOCKET_ADDRESS (b); if (g_inet_socket_address_get_port (ia) != g_inet_socket_address_get_port (ib)) return FALSE; iaa = g_inet_socket_address_get_address (ia); iab = g_inet_socket_address_get_address (ib); return g_inet_address_equal (iaa, iab); }
void lllp_next_song_cb(GObject *listener, GAsyncResult *res, gpointer pstore_library) { GtkListStore *store_library = GTK_LIST_STORE(pstore_library); gboolean valid = FALSE; GSocketConnection *connection; GSocketClient *player_client; GSocketAddress *address; GSocket *socket; GInputStream *stream; GOutputStream *output_stream; GInetAddress *inet_address; GInetAddress *player_with_the_song; GtkTreeIter iter; gchar *player_with_the_song_char; struct force_vector_s force_vector; gchar *remote_file; gint random_number; gsize count = 0; int i; struct force_vector_s rand_force_vector; connection = g_socket_listener_accept_finish(G_SOCKET_LISTENER(listener), res, NULL, NULL); address = g_socket_connection_get_remote_address(connection, NULL); inet_address = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(address)); socket = g_socket_connection_get_socket(connection); stream = g_io_stream_get_input_stream(G_IO_STREAM(connection)); g_input_stream_read_all(stream, &force_vector, sizeof(force_vector), NULL, NULL, NULL); valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store_library), &iter); while(valid == TRUE) { valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store_library), &iter); count++; } gint rand; float distance = 100, old_distance = 100; float treshold = 0.95; float treshold_distance = 4.0; do { /* TO FUNCTIONALIZE */ rand = g_random_int_range(0, count); if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store_library), &iter)) { for(i = 0; i < rand - 1; ++i) { gtk_tree_model_iter_next(GTK_TREE_MODEL(store_library), &iter); } gtk_tree_model_get(GTK_TREE_MODEL(store_library), &iter, FORCE_AMP, &rand_force_vector.amplitude, FORCE_ATK, &rand_force_vector.attack, FORCE_FREQ, &rand_force_vector.frequency, FORCE_TEMPO, &rand_force_vector.tempo, -1); } treshold -= 0.01; treshold_distance += 0.01; } while((bl_cosine_similarity(rand_force_vector, force_vector) < treshold) || ((distance = bl_distance(rand_force_vector, force_vector)) > treshold_distance)); gtk_tree_model_get(GTK_TREE_MODEL(store_library), &iter, AFILE, &remote_file, INET_ADDRESS, &player_with_the_song_char, -1); player_with_the_song = g_inet_address_new_from_string(player_with_the_song_char); if(g_inet_address_equal(player_with_the_song, inet_address) == TRUE) { rand_force_vector.attack = rand_force_vector.frequency = rand_force_vector.tempo = rand_force_vector.amplitude = 0; player_client = g_socket_client_new(); connection = g_socket_client_connect_to_host(player_client, g_inet_address_to_string(inet_address), 5353, NULL, NULL); output_stream = g_io_stream_get_output_stream(G_IO_STREAM(connection)); g_output_stream_write_all(output_stream, &rand_force_vector, sizeof(rand_force_vector), &count, NULL, NULL); g_io_stream_close(G_IO_STREAM(connection), NULL, NULL); g_socket_listener_accept_async(G_SOCKET_LISTENER(listener), NULL, lllp_next_song_cb, store_library); return; } player_client = g_socket_client_new(); connection = g_socket_client_connect_to_host(player_client, g_inet_address_to_string(inet_address), 5353, NULL, NULL); output_stream = g_io_stream_get_output_stream(G_IO_STREAM(connection)); g_output_stream_write_all(output_stream, &rand_force_vector, sizeof(rand_force_vector), &count, NULL, NULL); g_io_stream_close(G_IO_STREAM(connection), NULL, NULL); player_with_the_song_char = g_inet_address_to_string(player_with_the_song); connection = g_socket_client_connect_to_host(player_client, player_with_the_song_char, 19144, NULL, NULL); printf("%p\n", connection); output_stream = g_io_stream_get_output_stream(G_IO_STREAM(connection)); count = strlen(g_inet_address_to_string(inet_address)) + 1; g_output_stream_write_all(output_stream, &count, sizeof(gsize), NULL, NULL, NULL); g_output_stream_write_all(output_stream, g_inet_address_to_string(inet_address), count, NULL, NULL, NULL); count = strlen(remote_file) + 1; g_output_stream_write_all(output_stream, &count, sizeof(gsize), NULL, NULL, NULL); g_output_stream_write_all(output_stream, remote_file, count, NULL, NULL, NULL); g_output_stream_close(output_stream, NULL, NULL); g_socket_listener_accept_async(G_SOCKET_LISTENER(listener), NULL, lllp_next_song_cb, store_library); }