annotate src/daap/xmms2-daap/daap_cmd.c @ 2595:cde42a37ccf6

More indentation cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 21 May 2008 02:27:01 +0300
parents 776dd8fc2b38
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1407
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
1 /** @file daap_cmd.c
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
2 * Wrapper functions for issuing DAAP commands.
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
3 *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
4 * Copyright (C) 2006-2007 XMMS2 Team
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
5 *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
8 * as published by the Free Software Foundation; either version 2
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
9 * of the License, or (at your option) any later version.
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
10 *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
14 * GNU General Public License for more details.
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
15 */
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
16
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
17 #include "daap_cmd.h"
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
18 #include "daap_conn.h"
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
19
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
20 static cc_data_t *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
21 daap_request_data (GIOChannel *chan, const gchar *path, gchar *host, guint request_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
22 static gboolean
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
23 daap_request_stream (GIOChannel *chan, gchar *path, gchar *host,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
24 guint request_id, guint *size);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
25 static gchar *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
26 daap_url_append_meta (gchar *url, GSList *meta_list);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
27
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
28 guint
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
29 daap_command_login (gchar *host, gint port, guint request_id ) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
30 GIOChannel *chan;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
31 cc_data_t *cc_data;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
32
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
33 guint session_id = 0;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
34
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
35 chan = daap_open_connection (host, port);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
36 if (!chan) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
37 g_print("Connection to server failed! "
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
38 "Please make sure the url is of the form:\n"
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
39 "daap://ip[:port]/[song]");
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
40 return 0;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
41 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
42
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
43 cc_data = daap_request_data (chan, "/login", host, request_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
44 if (cc_data) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
45 session_id = cc_data->session_id;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
46 cc_data_free (cc_data);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
47 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
48
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
49 g_io_channel_shutdown (chan, TRUE, NULL);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
50 g_io_channel_unref (chan);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
51
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
52 return session_id;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
53 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
54
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
55 guint
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
56 daap_command_update (gchar *host, gint port, guint session_id, guint request_id)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
57 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
58 GIOChannel *chan;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
59 gchar *request;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
60 cc_data_t *cc_data;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
61 guint revision_id = 0;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
62
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
63 chan = daap_open_connection (host, port);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
64 if (!chan) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
65 return 0;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
66 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
67
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
68 request = g_strdup_printf ("/update?session-id=%d", session_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
69
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
70 cc_data = daap_request_data (chan, request, host, request_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
71 if (cc_data) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
72 revision_id = cc_data->revision_id;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
73 cc_data_free (cc_data);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
74 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
75
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
76 g_free (request);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
77 g_io_channel_shutdown (chan, TRUE, NULL);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
78 g_io_channel_unref (chan);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
79
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
80 return revision_id;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
81 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
82
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
83 gboolean
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
84 daap_command_logout (gchar *host, gint port, guint session_id, guint request_id)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
85 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
86 GIOChannel *chan;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
87 gchar *request;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
88
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
89 chan = daap_open_connection (host, port);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
90 if (!chan) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
91 return FALSE;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
92 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
93
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
94 request = g_strdup_printf ("/logout?session-id=%d", session_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
95
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
96 /* there is no cc_data generated, so we don't need to store it anywhere */
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
97 daap_request_data (chan, request, host, request_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
98
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
99 g_free (request);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
100 g_io_channel_shutdown (chan, TRUE, NULL);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
101 g_io_channel_unref (chan);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
102
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
103 return TRUE;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
104 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
105
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
106 GSList *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
107 daap_command_db_list (gchar *host, gint port, guint session_id,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
108 guint revision_id, guint request_id)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
109 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
110 GIOChannel *chan;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
111 gchar *request;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
112 cc_data_t *cc_data;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
113 GSList *db_id_list = NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
114
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
115 chan = daap_open_connection (host, port);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
116 if (!chan) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
117 return NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
118 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
119
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
120 request = g_strdup_printf ("/databases?session-id=%d&revision-id=%d",
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
121 session_id, revision_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
122
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
123 cc_data = daap_request_data (chan, request, host, request_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
124 g_free (request);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
125 if (cc_data) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
126 db_id_list = cc_record_list_deep_copy (cc_data->record_list);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
127 cc_data_free (cc_data);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
128 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
129
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
130 g_io_channel_shutdown (chan, TRUE, NULL);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
131 g_io_channel_unref (chan);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
132
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
133 return db_id_list;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
134 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
135
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
136 GSList *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
137 daap_command_song_list (gchar *host, gint port, guint session_id,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
138 guint revision_id, guint request_id, gint db_id)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
139 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
140 GIOChannel *chan;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
141 gchar *request;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
142 cc_data_t *cc_data;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
143
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
144 GSList * song_list;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
145 GSList * meta_items = NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
146
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
147 chan = daap_open_connection (host, port);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
148 if (!chan) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
149 return NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
150 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
151
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
152 meta_items = g_slist_prepend (meta_items, g_strdup ("dmap.itemid"));
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
153 meta_items = g_slist_prepend (meta_items, g_strdup ("dmap.itemname"));
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
154 meta_items = g_slist_prepend (meta_items, g_strdup ("daap.songartist"));
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
155 meta_items = g_slist_prepend (meta_items, g_strdup ("daap.songformat"));
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
156 meta_items = g_slist_prepend (meta_items, g_strdup ("daap.songtracknumber"));
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
157 meta_items = g_slist_prepend (meta_items, g_strdup ("daap.songalbum"));
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
158
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
159 request = g_strdup_printf ("/databases/%d/items?"
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
160 "session-id=%d&revision-id=%d",
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
161 db_id, session_id, revision_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
162
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
163 if (meta_items) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
164 request = daap_url_append_meta (request, meta_items);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
165 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
166
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
167 cc_data = daap_request_data (chan, request, host, request_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
168 song_list = cc_record_list_deep_copy (cc_data->record_list);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
169
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
170 g_free (request);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
171 cc_data_free (cc_data);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
172 g_io_channel_shutdown (chan, TRUE, NULL);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
173 g_io_channel_unref (chan);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
174 g_slist_foreach (meta_items, (GFunc) g_free, NULL);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
175 g_slist_free (meta_items);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
176
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
177 return song_list;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
178 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
179
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
180 GIOChannel *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
181 daap_command_init_stream (gchar *host, gint port, guint session_id,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
182 guint revision_id, guint request_id,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
183 gint dbid, gchar *song, guint *filesize)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
184 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
185 GIOChannel *chan;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
186 gchar *request;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
187 gboolean ok;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
188
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
189 chan = daap_open_connection (host, port);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
190 if (!chan) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
191 return NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
192 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
193
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
194 request = g_strdup_printf ("/databases/%d/items%s"
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
195 "?session-id=%d",
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
196 dbid, song, session_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
197
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
198 ok = daap_request_stream (chan, request, host, request_id, filesize);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
199 g_free (request);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
200
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
201 if (!ok) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
202 return NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
203 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
204
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
205 return chan;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
206 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
207
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
208 static cc_data_t *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
209 daap_request_data (GIOChannel *chan, const gchar *path, gchar *host, guint request_id)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
210 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
211 guint status;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
212 gchar *request, *header = NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
213 cc_data_t *retval;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
214
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
215 request = daap_generate_request (path, host, request_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
216 daap_send_request (chan, request);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
217 g_free (request);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
218
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
219 daap_receive_header (chan, &header);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
220 if (!header) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
221 return NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
222 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
223
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
224 status = get_server_status (header);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
225
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
226 switch (status) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
227 case UNKNOWN_SERVER_STATUS:
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
228 case HTTP_BAD_REQUEST:
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
229 case HTTP_FORBIDDEN:
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
230 case HTTP_NO_CONTENT:
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
231 case HTTP_NOT_FOUND:
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
232 retval = NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
233 break;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
234 case HTTP_OK:
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
235 default:
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
236 retval = daap_handle_data (chan, header);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
237 break;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
238 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
239 g_free (header);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
240
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
241 return retval;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
242 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
243
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
244 static gboolean
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
245 daap_request_stream (GIOChannel *chan, gchar *path, gchar *host,
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
246 guint request_id, guint *size)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
247 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
248 guint status;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
249 gchar *request, *header = NULL;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
250
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
251 request = daap_generate_request (path, host, request_id);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
252 daap_send_request (chan, request);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
253 g_free (request);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
254
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
255 daap_receive_header (chan, &header);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
256 if (!header) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
257 return FALSE;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
258 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
259
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
260 status = get_server_status (header);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
261 if (HTTP_OK != status) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
262 g_free (header);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
263 return FALSE;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
264 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
265
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
266 *size = get_data_length (header);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
267
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
268 g_free (header);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
269
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
270 return TRUE;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
271 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
272
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
273 static gchar *
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
274 daap_url_append_meta (gchar *url, GSList *meta_list)
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
275 {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
276 gchar * tmpurl;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
277
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
278 tmpurl = url;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
279 url = g_strdup_printf ("%s&meta=%s", url, (gchar *) meta_list->data);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
280 g_free (tmpurl);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
281 meta_list = g_slist_next (meta_list);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
282
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
283 for ( ; meta_list != NULL; meta_list = g_slist_next (meta_list)) {
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
284 tmpurl = url;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
285 url = g_strdup_printf ("%s,%s", url, (gchar *) meta_list->data);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
286 g_free (tmpurl);
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
287 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
288
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
289 return url;
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
290 }
776dd8fc2b38 DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
291