1707
1728
map = DMAP_SHARE_GET_CLASS (share)->get_meta_data_map (share);
1708
1729
mb.bits = _dmap_share_parse_meta (query, map);
1732
* We previously simply called foreach...add_entry_to_mlcl and later serialized the entire
1733
* structure. This has the disadvantage that the entire response must be in memory before
1734
* libsoup sends it to the client.
1736
* Now, we go through the database in multiple passes (as an interim solution):
1738
* 1. Accumulate the eventual size of the MLCL by creating and then free'ing each MLIT.
1739
* 2. Generate the DAAP preamble ending with the MLCL (with size fudged for ADBS and MLCL).
1740
* 3. Setup libsoup response headers, etc.
1741
* 4. Setup callback to transmit DAAP preamble (write_dmap_preamble)
1742
* 5. Setup callback to transmit MLIT's (write_next_mlit)
1746
/* FIXME: user_data1/2 is ugly: */
1748
mb.user_data1 = &size;
1749
mb.user_data2 = share;
1751
share_bitwise = g_new (struct share_bitwise_t, 1);
1752
share_bitwise->share = share;
1753
share_bitwise->bits = mb.bits;
1754
share_bitwise->id_list = NULL;
1756
share_bitwise->db = records;
1757
share_bitwise->lookup_by_id = g_hash_table_lookup_adapter;
1758
share_bitwise->destroy = g_hash_table_destroy;
1759
g_hash_table_foreach (records, (GHFunc) accumulate_ids, &(share_bitwise->id_list));
1760
g_hash_table_foreach (records, (GHFunc) accumulate_mlcl_size, &mb);
1762
share_bitwise->db = share->priv->db;
1763
share_bitwise->lookup_by_id = dmap_db_lookup_by_id;
1764
share_bitwise->destroy = NULL;
1765
dmap_db_foreach (share->priv->db, (GHFunc) accumulate_ids, &(share_bitwise->id_list));
1766
dmap_db_foreach (share->priv->db, (GHFunc) accumulate_mlcl_size, &mb);
1710
1770
adbs = dmap_structure_add (NULL, DMAP_CC_ADBS);
1711
1771
dmap_structure_add (adbs, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);
1712
1772
dmap_structure_add (adbs, DMAP_CC_MUTY, 0);
1713
1773
dmap_structure_add (adbs, DMAP_CC_MTCO, (gint32) num_songs);
1714
1774
dmap_structure_add (adbs, DMAP_CC_MRCO, (gint32) num_songs);
1717
/* NOTE: still uses old technique: */
1718
mb.mlcl = dmap_structure_add (adbs, DMAP_CC_MLCL); // Was shared with else before
1719
g_hash_table_foreach (records, (GHFunc) DMAP_SHARE_GET_CLASS (share)->add_entry_to_mlcl, &mb);
1720
g_hash_table_destroy (records);
1721
_dmap_share_message_set_from_dmap_structure (share, message, adbs); // Was shared with else before
1722
dmap_structure_destroy (adbs); // Was shared with else before
1725
* We previously simply called foreach...add_entry_to_mlcl and later serialized the entire
1726
* structure. This has the disadvantage that the entire response must be in memory before
1727
* libsoup sends it to the client.
1729
* Now, we go through the database in multiple passes (as an interim solution):
1731
* 1. Accumulate the eventual size of the MLCL by creating and then free'ing each MLIT.
1732
* 2. Generate the DAAP preamble ending with the MLCL (with size fudged for ADBS and MLCL).
1733
* 3. Setup libsoup response headers, etc.
1734
* 4. Setup callback to transmit DAAP preamble (write_daap_preamble)
1735
* 5. Setup callback to transmit MLIT's (write_next_mlit)
1736
* NOTE: write_next_mlit uses some tricks to iterate through all record ID's
1739
struct share_bitwise_t *share_bitwise;
1742
/* FIXME: user_data1/2 is ugly: */
1744
mb.user_data1 = &size;
1745
mb.user_data2 = share;
1746
dmap_db_foreach (share->priv->db, (GHFunc) accumulate_mlcl_size, &mb);
1749
mb.mlcl = dmap_structure_add (adbs, DMAP_CC_MLCL);
1750
dmap_structure_increase_by_predicted_size (adbs, size);
1751
dmap_structure_increase_by_predicted_size (mb.mlcl, size);
1754
soup_message_set_status (message, SOUP_STATUS_OK);
1755
soup_message_headers_set_content_length (message->response_headers, dmap_structure_get_size(adbs));
1756
/* Free memory after each chunk sent out over network. */
1757
soup_message_body_set_accumulate (message->response_body, FALSE);
1759
soup_message_headers_append (message->response_headers, "Content-Type", "application/x-daap-tagged");
1760
DMAP_SHARE_GET_CLASS (share)->message_add_standard_headers (share, message);
1763
g_signal_connect (message, "wrote_headers", G_CALLBACK (write_daap_preamble), adbs);
1766
share_bitwise = g_new (struct share_bitwise_t, 1);
1767
share_bitwise->share = share;
1768
share_bitwise->bits = mb.bits;
1769
share_bitwise->id_list = NULL;
1770
dmap_db_foreach (share->priv->db, (GHFunc) accumulate_ids, &(share_bitwise->id_list));
1771
g_signal_connect (message, "wrote_chunk", G_CALLBACK (write_next_mlit), share_bitwise);
1772
g_signal_connect (message, "finished", G_CALLBACK (chunked_message_finished), share_bitwise);
1775
mb.mlcl = dmap_structure_add (adbs, DMAP_CC_MLCL);
1776
dmap_structure_increase_by_predicted_size (adbs, size);
1777
dmap_structure_increase_by_predicted_size (mb.mlcl, size);
1780
/* Free memory after each chunk sent out over network. */
1781
soup_message_body_set_accumulate (message->response_body, FALSE);
1782
soup_message_headers_append (message->response_headers, "Content-Type", "application/x-dmap-tagged");
1783
DMAP_SHARE_GET_CLASS (share)->message_add_standard_headers (share, message);
1784
soup_message_headers_set_content_length (message->response_headers, dmap_structure_get_size(adbs));
1785
soup_message_set_status (message, SOUP_STATUS_OK);
1788
g_signal_connect (message, "wrote_headers", G_CALLBACK (write_dmap_preamble), adbs);
1791
g_signal_connect (message, "wrote_chunk", G_CALLBACK (write_next_mlit), share_bitwise);
1792
g_signal_connect (message, "finished", G_CALLBACK (chunked_message_finished), share_bitwise);
1775
1794
} else if (g_ascii_strcasecmp ("/1/containers", rest_of_path) == 0) {
1776
1795
/* APLY database playlists