示例#1
0
void
korva_upnp_file_server_unhost_file_for_peer (KorvaUPnPFileServer *self,
                                             GFile               *file,
                                             const char          *peer)
{
    KorvaUPnPHostData *data;

    data = g_hash_table_lookup (self->priv->host_data, file);
    if (data == NULL) {
        return;
    }

    korva_upnp_host_data_remove_peer (data, peer);
    if (!korva_upnp_host_data_has_peers (data)) {
        char *id, *uri;

        id = korva_upnp_host_data_get_id (data);
        g_hash_table_remove (self->priv->id_map, id);
        g_free (id);

        file = korva_upnp_host_data_get_file (data);
        uri = g_file_get_uri (file);
        g_debug ("File '%s' no longer shared to any peer, removing…",
                 uri);
        g_free (uri);
        g_object_unref (file);

        g_hash_table_remove (self->priv->host_data, file);
    }
}
示例#2
0
void
korva_upnp_file_server_unhost_by_peer (KorvaUPnPFileServer *self,
                                       const char          *peer)
{
    GHashTableIter iter;
    KorvaUPnPHostData *value;
    char *key;

    g_hash_table_iter_init (&iter, self->priv->host_data);
    while (g_hash_table_iter_next (&iter, (gpointer) & key, (gpointer) & value)) {
        korva_upnp_host_data_remove_peer (value, peer);
        if (!korva_upnp_host_data_has_peers (value)) {
            char *id, *uri;
            GFile *file;

            id = korva_upnp_host_data_get_id (value);
            g_hash_table_remove (self->priv->id_map, id);
            g_free (id);

            file = korva_upnp_host_data_get_file (value);
            uri = g_file_get_uri (file);
            g_debug ("File '%s' no longer shared to any peer, removing…",
                     uri);
            g_free (uri);
            g_object_unref (file);

            g_hash_table_iter_remove (&iter);
        }
    }
}
示例#3
0
static void
korva_upnp_file_server_on_host_data_timeout (KorvaUPnPFileServer *self,
                                             KorvaUPnPHostData   *data)
{
    char *id;
    GFile *file;

    file = korva_upnp_host_data_get_file (data);
    id = korva_upnp_host_data_get_id (data);

    g_hash_table_remove (self->priv->id_map, id);
    g_hash_table_remove (self->priv->host_data, file);

    g_object_unref (file);
    g_free (id);
}
示例#4
0
/**
 * korva_upnp_host_data_get_uri:
 *
 * Create a HTTP URL for this :file.
 *
 * @self: An instance of #KorvaUPnPHostData
 * @iface: IP address of the network interface the HTTP server is running on.
 * @port: TCP port the HTTP server is listening on.
 *
 * Returns: (transfer full): A new string containing the uri. Free after use.
 */
char *
korva_upnp_host_data_get_uri (KorvaUPnPHostData *self, const char *iface, guint port)
{
    char *hash, *result;
    const char *ext;

    hash = korva_upnp_host_data_get_id (self);

    ext = korva_upnp_host_data_get_extension (self);

    result = g_strdup_printf ("http://%s:%u/item/%s.%s",
                              iface,
                              port,
                              hash,
                              ext);

    g_free (hash);

    return result;
}
示例#5
0
static void
korva_upnp_file_server_on_metadata_query_run_done (GObject      *sender,
                                                   GAsyncResult *res,
                                                   gpointer      user_data)
{
    QueryMetaData *data = (QueryMetaData *) user_data;
    GSimpleAsyncResult *result = data->result;
    HostFileResult *result_data;
    guint port;
    GError *error = NULL;

    if (!korva_upnp_metadata_query_run_finish (KORVA_UPNP_METADATA_QUERY (sender),
                                               res,
                                               &error)) {
        if (error->domain != KORVA_CONTROLLER1_ERROR) {
            int code;
            code = error->code;

            g_error_free (error);
            error = NULL;
            if (code == G_IO_ERROR_NOT_FOUND) {
                error = g_error_new_literal (KORVA_CONTROLLER1_ERROR,
                                             KORVA_CONTROLLER1_ERROR_FILE_NOT_FOUND,
                                             "File not found");
            } else {
                error = g_error_new_literal (KORVA_CONTROLLER1_ERROR,
                                             KORVA_CONTROLLER1_ERROR_NOT_ACCESSIBLE,
                                             "File not accessible");
            }
        }

        g_simple_async_result_take_error (data->result, error);
        g_object_unref (data->data);

        goto out;
    }

    g_signal_connect_swapped (data->data,
                              "timeout",
                              G_CALLBACK (korva_upnp_file_server_on_host_data_timeout),
                              data->self);

    g_hash_table_insert (data->self->priv->host_data,
                         korva_upnp_host_data_get_file (data->data),
                         data->data);
    g_hash_table_insert (data->self->priv->id_map,
                         korva_upnp_host_data_get_id (data->data),
                         korva_upnp_host_data_get_file (data->data));

    port = soup_server_get_port (data->self->priv->http_server);

    result_data = g_new0 (HostFileResult, 1);
    result_data->params = korva_upnp_host_data_get_meta_data (data->data);
    result_data->uri = korva_upnp_host_data_get_uri (data->data, data->iface, port);

    g_simple_async_result_set_op_res_gpointer (result, result_data, g_free);

    data->result = NULL;

out:
    g_free (data->iface);
    data->iface = NULL;

    g_simple_async_result_complete_in_idle (result);
    g_object_unref (result);
    g_object_unref (sender);
    g_slice_free (QueryMetaData, data);
}