1 /* Header for DMAP (e.g., iTunes Music or iPhoto Picture) sharing
2  *
3  * Copyright (C) 2005 Charles Schmidt <cschmidt2@emich.edu>
4  *
5  * Modifications Copyright (C) 2008 W. Michael Petullo <mike@flyn.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  *
21  */
22 
23 #ifndef __DMAP_SHARE_H
24 #define __DMAP_SHARE_H
25 
26 #include <glib-object.h>
27 
28 #include <libsoup/soup.h>
29 #include <libsoup/soup-address.h>
30 #include <libsoup/soup-message.h>
31 #include <libsoup/soup-uri.h>
32 #include <libsoup/soup-server.h>
33 
34 #include <libdmapsharing/dmap-record.h>
35 #include <libdmapsharing/dmap-mdns-publisher.h>
36 #include <libdmapsharing/dmap-container-record.h>
37 
38 G_BEGIN_DECLS
39 /**
40  * DMAP_TYPE_SHARE:
41  *
42  * The type for #DMAPShare.
43  */
44 #define DMAP_TYPE_SHARE         (dmap_share_get_type ())
45 /**
46  * DMAP_SHARE:
47  * @o: Object which is subject to casting.
48  *
49  * Casts a #DMAPShare or derived pointer into a (DMAPShare*) pointer.
50  * Depending on the current debugging level, this function may invoke
51  * certain runtime checks to identify invalid casts.
52  */
53 #define DMAP_SHARE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), \
54 				 DMAP_TYPE_SHARE, DMAPShare))
55 /**
56  * DMAP_SHARE_CLASS:
57  * @k: a valid #DMAPShareClass
58  *
59  * Casts a derived #DMAPShareClass structure into a #DMAPShareClass structure.
60  */
61 #define DMAP_SHARE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), \
62 				 DMAP_TYPE_SHARE, DMAPShareClass))
63 /**
64  * IS_DMAP_SHARE:
65  * @o: Instance to check for being a %DMAP_TYPE_SHARE.
66  *
67  * Checks whether a valid #GTypeInstance pointer is of type %DMAP_TYPE_SHARE.
68  */
69 #define IS_DMAP_SHARE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), \
70 				 DMAP_TYPE_SHARE))
71 /**
72  * IS_DMAP_SHARE_CLASS:
73  * @k: a #DMAPShareClass
74  *
75  * Checks whether @k "is a" valid #DMAPShareClass structure of type
76  * %DMAP_SHARE or derived.
77  */
78 #define IS_DMAP_SHARE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), \
79 				 DMAP_TYPE_SHARE))
80 /**
81  * DMAP_SHARE_GET_CLASS:
82  * @o: a #DMAPShare instance.
83  *
84  * Get the class structure associated to a #DMAPShare instance.
85  *
86  * Returns: pointer to object class structure.
87  */
88 #define DMAP_SHARE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \
89 				 DMAP_TYPE_SHARE, DMAPShareClass))
90 #define DMAP_STATUS_OK 200
91 typedef struct DMAPSharePrivate DMAPSharePrivate;
92 
93 typedef struct
94 {
95 	GObject parent;
96 	DMAPSharePrivate *priv;
97 } DMAPShare;
98 
99 typedef struct DMAPMetaDataMap DMAPMetaDataMap;
100 
101 typedef struct
102 {
103 	GObjectClass parent;
104 
105 	/* Pure virtual methods: */
106 	  guint (*get_desired_port) (DMAPShare * share);
107 	const char *(*get_type_of_service) (DMAPShare * share);
108 	void (*message_add_standard_headers) (DMAPShare * share,
109 					      SoupMessage * msg);
110 	struct DMAPMetaDataMap *(*get_meta_data_map) (DMAPShare * share);
111 	void (*add_entry_to_mlcl) (gpointer id,
112 				   DMAPRecord * record, gpointer mb);
113 	void (*databases_browse_xxx) (DMAPShare * share,
114 				      SoupServer * server,
115 				      SoupMessage * msg,
116 				      const char *path,
117 				      GHashTable * query,
118 				      SoupClientContext * context);
119 	void (*databases_items_xxx) (DMAPShare * share,
120 				     SoupServer * server,
121 				     SoupMessage * msg,
122 				     const char *path,
123 				     GHashTable * query,
124 				     SoupClientContext * context);
125 
126 	/* Pure virtual methods: libsoup callbacks */
127 	void (*server_info) (DMAPShare * share, SoupServer * server,
128 			     SoupMessage * message, const char *path,
129 			     GHashTable * query, SoupClientContext * ctx);
130 
131 	void (*content_codes) (DMAPShare * share, SoupServer * server,
132 			       SoupMessage * message, const char *path,
133 			       GHashTable * query, SoupClientContext * ctx);
134 
135 	void (*login) (DMAPShare * share, SoupServer * server,
136 		       SoupMessage * message, const char *path,
137 		       GHashTable * query, SoupClientContext * ctx);
138 
139 	void (*logout) (DMAPShare * share, SoupServer * server,
140 			SoupMessage * message, const char *path,
141 			GHashTable * query, SoupClientContext * ctx);
142 
143 	void (*update) (DMAPShare * share, SoupServer * server,
144 			SoupMessage * message, const char *path,
145 			GHashTable * query, SoupClientContext * ctx);
146 
147 	void (*ctrl_int) (DMAPShare * share, SoupServer * server,
148 			  SoupMessage * message, const char *path,
149 			  GHashTable * query, SoupClientContext * ctx);
150 
151 	/* Virtual methods: MDNS callbacks */
152 	void (*published) (DMAPShare * share,
153 			   DMAPMdnsPublisher * publisher, const char *name);
154 
155 	void (*name_collision) (DMAPShare * share,
156 				DMAPMdnsPublisher * publisher,
157 				const char *name);
158 
159 	/* Virtual methods: */
160 	void (*databases) (DMAPShare * share,
161 			   SoupServer * server,
162 			   SoupMessage * message,
163 			   const char *path,
164 			   GHashTable * query, SoupClientContext * context);
165 } DMAPShareClass;
166 
167 struct DMAPMetaDataMap
168 {
169 	gchar *tag;
170 	guint md;
171 };
172 
173 /* FIXME: this is passed as user_data to various functions;
174  * need to rename. Also, get rid of initializations elsewhere: { NULL, 0, NULL };
175  * instead define a function to do this.
176  */
177 struct MLCL_Bits
178 {
179 	GNode *mlcl;
180 	bitwise bits;
181 	DMAPShare *share;
182 };
183 
184 GType dmap_share_get_type (void);
185 
186 /* Non-virtual methods */
187 guint _dmap_share_get_auth_method (DMAPShare * share);
188 
189 guint _dmap_share_get_revision_number (DMAPShare * share);
190 
191 gboolean _dmap_share_get_revision_number_from_query (GHashTable * query,
192 						     guint * number);
193 
194 gboolean _dmap_share_session_id_validate (DMAPShare * share,
195 					  SoupClientContext * context,
196 					  SoupMessage * msg,
197 					  GHashTable * query, guint32 * id);
198 
199 guint32 _dmap_share_session_id_create (DMAPShare * share,
200 				       SoupClientContext * ctx);
201 
202 void _dmap_share_session_id_remove (DMAPShare * share,
203 				    SoupClientContext * ctx, guint32 id);
204 
205 gboolean _dmap_share_client_requested (bitwise bits, gint field);
206 
207 gboolean _dmap_share_uri_is_local (const char *text_uri);
208 
209 gboolean _dmap_share_soup_auth_filter (SoupAuthDomain * auth_domain,
210 				       SoupMessage * msg, gpointer user_data);
211 
212 gboolean _dmap_share_server_start (DMAPShare * share);
213 
214 gboolean _dmap_share_publish_start (DMAPShare * share);
215 
216 void _dmap_share_message_set_from_dmap_structure (DMAPShare * share,
217 						  SoupMessage * message,
218 						  GNode * structure);
219 
220 bitwise _dmap_share_parse_meta (GHashTable * query,
221 				struct DMAPMetaDataMap *mdm);
222 
223 bitwise _dmap_share_parse_meta_str (const char *attrs,
224 				    struct DMAPMetaDataMap *mdm);
225 
226 void _dmap_share_add_playlist_to_mlcl (gpointer id,
227 				       DMAPContainerRecord * record,
228 				       gpointer mb);
229 
230 GSList *_dmap_share_build_filter (gchar * filterstr);
231 
232 void dmap_share_free_filter (GSList * filter);
233 
234 /* Virtual methods (libsoup callbacks with default implementation): */
235 void _dmap_share_content_codes (DMAPShare * share,
236 				SoupServer * server,
237 				SoupMessage * message,
238 				const char *path,
239 				GHashTable * query,
240 				SoupClientContext * context);
241 
242 void _dmap_share_login (DMAPShare * share,
243 			SoupServer * server,
244 			SoupMessage * message,
245 			const char *path,
246 			GHashTable * query, SoupClientContext * context);
247 
248 void _dmap_share_logout (DMAPShare * share,
249 			 SoupServer * server,
250 			 SoupMessage * message,
251 			 const char *path,
252 			 GHashTable * query, SoupClientContext * context);
253 
254 void _dmap_share_update (DMAPShare * share,
255 			 SoupServer * server,
256 			 SoupMessage * message,
257 			 const char *path,
258 			 GHashTable * query, SoupClientContext * context);
259 
260 void
261 _dmap_share_databases (DMAPShare * share,
262 		       SoupServer * server,
263 		       SoupMessage * message,
264 		       const char *path,
265 		       GHashTable * query, SoupClientContext * context);
266 
267 void _dmap_share_ctrl_int (DMAPShare * share,
268 			   SoupServer * server,
269 			   SoupMessage * message,
270 			   const char *path,
271 			   GHashTable * query, SoupClientContext * context);
272 
273 /* Virtual methods: MDNS callbacks */
274 void _dmap_share_published (DMAPShare * share,
275 			    DMAPMdnsPublisher * publisher, const char *name);
276 
277 void _dmap_share_name_collision (DMAPShare * share,
278 				 DMAPMdnsPublisher * publisher,
279 				 const char *name);
280 
281 #endif /* __DMAP_SHARE_H */
282 
283 G_END_DECLS
284