dmap-share.h 8.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
/*
 * Header for DMAP (e.g., iTunes Music or iPhoto Picture) sharing
 *
 * Copyright (C) 2005 Charles Schmidt <cschmidt2@emich.edu>
 *
 * Modifications Copyright (C) 2008 W. Michael Petullo <mike@flyn.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifndef __DMAP_SHARE_H
#define __DMAP_SHARE_H

#include <glib-object.h>

#include <libsoup/soup.h>
#include <libsoup/soup-address.h>
#include <libsoup/soup-message.h>
#include <libsoup/soup-uri.h>
#include <libsoup/soup-server.h>

#include <libdmapsharing/dmap-record.h>
#include <libdmapsharing/dmap-mdns-publisher.h>
#include <libdmapsharing/dmap-container-record.h>

G_BEGIN_DECLS

41 42 43 44 45
/**
 * TYPE_DMAP_SHARE:
 *
 * The type for #DMAPShare.
 */
46
#define TYPE_DMAP_SHARE         (dmap_share_get_type ())
47 48 49 50 51 52 53 54
/**
 * DMAP_SHARE:
 * @o: Object which is subject to casting.
 *
 * Casts a #DMAPShare or derived pointer into a (DMAPShare*) pointer.
 * Depending on the current debugging level, this function may invoke
 * certain runtime checks to identify invalid casts.
 */
55 56
#define DMAP_SHARE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), \
				 TYPE_DMAP_SHARE, DMAPShare))
57 58 59 60 61 62
/**
 * DMAP_SHARE_CLASS:
 * @k: a valid #DMAPShareClass
 *
 * Casts a derived #DMAPShareClass structure into a #DMAPShareClass structure.
 */
63 64
#define DMAP_SHARE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), \
				 TYPE_DMAP_SHARE, DMAPShareClass))
65 66 67 68 69 70 71
/**
 * IS_DMAP_SHARE:
 * @o: Instance to check for being a %TYPE_DMAP_SHARE.
 *
 * Checks whether a valid #GTypeInstance pointer is of type %TYPE_DMAP_SHARE.
 */

72 73
#define IS_DMAP_SHARE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), \
				 TYPE_DMAP_SHARE))
74 75 76 77 78 79 80
/**
 * IS_DMAP_SHARE_CLASS:
 * @k: a #DMAPShareClass
 *
 * Checks whether @k "is a" valid #DMAPShareClass structure of type
 * %DMAP_SHARE or derived.
 */
81 82
#define IS_DMAP_SHARE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), \
				 TYPE_DMAP_SHARE))
83 84 85 86 87 88 89 90
/**
 * DMAP_SHARE_GET_CLASS:
 * @o: a #DMAPShare instance.
 *
 * Get the class structure associated to a #DMAPShare instance.
 *
 * Returns: pointer to object class structure.
 */
91 92 93 94
#define DMAP_SHARE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \
				 TYPE_DMAP_SHARE, DMAPShareClass))

#define DMAP_SHARE_CHUNK_SIZE 16384
95
#define DMAP_STATUS_OK 200
96 97 98 99 100 101 102 103

typedef struct DMAPSharePrivate DMAPSharePrivate;

typedef struct {
	GObject parent;
	DMAPSharePrivate *priv;
} DMAPShare;

104 105
typedef struct _DMAPMetaDataMap DMAPMetaDataMap;

106 107 108 109
typedef struct {
	GObjectClass parent;

	/* Pure virtual methods: */
110 111 112 113 114
	guint             (*get_desired_port)             (DMAPShare *share);
	const char *      (*get_type_of_service)          (DMAPShare *share);
	void              (*message_add_standard_headers) (DMAPShare *share,
							   SoupMessage *msg);
	struct DMAPMetaDataMap * (*get_meta_data_map)     (DMAPShare *share);
115
	guint32           (*add_entry_to_mlcl)            (gpointer id,
116 117 118 119 120 121 122 123 124 125 126 127 128 129
							   DMAPRecord *record,
							   gpointer mb);
	void		  (*databases_browse_xxx)	  (DMAPShare *share,
							   SoupServer *server,
							   SoupMessage *msg,
							   const char *path,
							   GHashTable *query,
							   SoupClientContext *context);
	void		  (*databases_items_xxx)	  (DMAPShare *share,
							   SoupServer *server,
							   SoupMessage *msg,
							   const char *path,
							   GHashTable *query,
							   SoupClientContext *context);
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

	/* Pure virtual methods: libsoup callbacks */
	void	  (*server_info)   (DMAPShare *share, SoupServer *server,
				    SoupMessage *message, const char *path,
				    GHashTable *query, SoupClientContext *ctx);

	void	  (*content_codes) (DMAPShare *share, SoupServer *server,
				    SoupMessage *message, const char *path,
				    GHashTable *query, SoupClientContext *ctx);

	void	  (*login)         (DMAPShare *share, SoupServer *server,
				    SoupMessage *message, const char *path,
				    GHashTable *query, SoupClientContext *ctx);

	void	  (*logout)        (DMAPShare *share, SoupServer *server,
				    SoupMessage *message, const char *path,
				    GHashTable *query, SoupClientContext *ctx);

	void	  (*update)        (DMAPShare *share, SoupServer *server,
				    SoupMessage *message, const char *path,
				    GHashTable *query, SoupClientContext *ctx);
151 152 153 154
				    
	void	  (*ctrl_int)        (DMAPShare *share, SoupServer *server,
				    SoupMessage *message, const char *path,
				    GHashTable *query, SoupClientContext *ctx);
155 156 157 158 159 160 161 162 163

	/* Virtual methods: MDNS callbacks */
	void	  (*published)	   (DMAPShare         *share,
				    DmapMdnsPublisher *publisher,
	              		    const char        *name);

	void	  (*name_collision)(DMAPShare	      *share,
				    DmapMdnsPublisher *publisher,
	              		    const char        *name);
164 165 166 167 168 169 170 171

	/* Virtual methods: */
	void	  (*databases)     (DMAPShare	      *share,
				    SoupServer        *server,
				    SoupMessage       *message,
				    const char        *path,
				    GHashTable        *query,
				    SoupClientContext *context);
172 173 174 175 176 177 178 179 180 181
} DMAPShareClass;

struct DMAPMetaDataMap {
        gchar *tag;
	guint md;
};

GType    dmap_share_get_type (void);

/* Non-virtual methods */
182
guint    _dmap_share_get_auth_method (DMAPShare *share);
183

184
guint    _dmap_share_get_revision_number (DMAPShare *share);
185

186
gboolean _dmap_share_get_revision_number_from_query (GHashTable *query,
187 188
						    guint *number);

189
gboolean _dmap_share_session_id_validate (DMAPShare *share,
190 191 192 193
					 SoupClientContext *context, 
					 SoupMessage *msg, GHashTable *query,
					 guint32 *id);

194
guint32  _dmap_share_session_id_create (DMAPShare *share,
195 196
				       SoupClientContext *ctx);

197
void     _dmap_share_session_id_remove (DMAPShare *share,
198 199 200
				       SoupClientContext *ctx,
				       guint32 id);

201
gboolean _dmap_share_client_requested (bitwise bits, gint field);
202

203
gboolean _dmap_share_uri_is_local (const char *text_uri);
204

205
gboolean _dmap_share_soup_auth_filter (SoupAuthDomain *auth_domain,
206 207
				      SoupMessage *msg, gpointer user_data);

208
gboolean _dmap_share_server_start  (DMAPShare *share);
209

210
gboolean _dmap_share_publish_start (DMAPShare *share);
211

212
void     _dmap_share_message_set_from_dmap_structure (DMAPShare *share,
213 214 215
						     SoupMessage *message,
						     GNode *structure);

216
bitwise  _dmap_share_parse_meta (GHashTable *query,
217
				struct DMAPMetaDataMap *mdm);
218

219
bitwise  _dmap_share_parse_meta_str (const char *attrs,
220
				    struct DMAPMetaDataMap *mdm);
221

222 223
void _dmap_share_add_playlist_to_mlcl (gpointer id,
				       DMAPContainerRecord *record,
224
				       gpointer mb);
225

W. Michael Petullo's avatar
W. Michael Petullo committed
226 227
GSList * _dmap_share_build_filter (gchar *filterstr);

W. Michael Petullo's avatar
W. Michael Petullo committed
228 229
void dmap_share_free_filter (GSList *filter);

230
/* Virtual methods (libsoup callbacks with default implementation): */
231
void _dmap_share_content_codes (DMAPShare *share,
232 233 234 235 236 237
		  SoupServer        *server,
		  SoupMessage       *message,
		  const char        *path,
		  GHashTable        *query,
		  SoupClientContext *context);

238
void _dmap_share_login (DMAPShare *share,
239 240 241 242 243 244
		  SoupServer        *server,
		  SoupMessage       *message,
		  const char        *path,
		  GHashTable        *query,
		  SoupClientContext *context);

245
void _dmap_share_logout (DMAPShare *share,
246 247 248 249 250 251
		  SoupServer        *server,
		  SoupMessage       *message,
		  const char        *path,
		  GHashTable        *query,
		  SoupClientContext *context);

252
void _dmap_share_update (DMAPShare *share,
253 254 255 256 257 258
		  SoupServer        *server,
		  SoupMessage       *message,
		  const char        *path,
		  GHashTable        *query,
		  SoupClientContext *context);

259 260 261 262 263 264 265 266 267 268 269 270 271 272
void
_dmap_share_databases (DMAPShare *share,
                       SoupServer        *server,
		       SoupMessage       *message,
		       const char        *path,
		       GHashTable        *query,
		       SoupClientContext *context);

void _dmap_share_ctrl_int (DMAPShare         *share,
		           SoupServer        *server,
		           SoupMessage       *message,
		           const char        *path,
		           GHashTable        *query,
		           SoupClientContext *context);
273 274

/* Virtual methods: MDNS callbacks */
275
void _dmap_share_published     (DMAPShare         *share,
276 277 278
			       DmapMdnsPublisher *publisher,
			       const char        *name);

279
void _dmap_share_name_collision(DMAPShare         *share,
280 281 282
			       DmapMdnsPublisher *publisher,
			       const char        *name);

283

284 285 286
#endif /* __DMAP_SHARE_H */

G_END_DECLS