dmap-share.c 54 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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Implmentation of 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
 *
 */

#include "config.h"

#include <time.h>
#include <string.h>
#include <stdlib.h>

#include <glib/gi18n.h>

33
#include <libdmapsharing/dmap.h>
34 35 36 37 38 39 40 41
#include <libdmapsharing/dmap-structure.h>

#define TYPE_OF_SERVICE "_daap._tcp"
#define STANDARD_DAAP_PORT 3689
#define STANDARD_DPAP_PORT 8770
#define DMAP_VERSION 2.0
#define DAAP_VERSION 3.0
#define DMAP_TIMEOUT 1800
42
#define DMAP_STATUS_OK 200
43 44 45 46 47 48 49 50 51

typedef enum {
	DMAP_SHARE_AUTH_METHOD_NONE              = 0,
	DMAP_SHARE_AUTH_METHOD_NAME_AND_PASSWORD = 1,
	DMAP_SHARE_AUTH_METHOD_PASSWORD          = 2
} DMAPShareAuthMethod;

enum {
	PROP_0,
52
	PROP_SERVER,
53 54 55 56
	PROP_NAME,
	PROP_PASSWORD,
	PROP_REVISION_NUMBER,
	PROP_AUTH_METHOD,
57 58
	PROP_DB,
	PROP_CONTAINER_DB,
59 60
	PROP_TRANSCODE_MIMETYPE,
	PROP_TXT_RECORDS
61 62 63 64 65 66
};

struct DMAPSharePrivate {
	gchar *name;
	guint port;
	char *password;
67 68 69 70

	/* FIXME: eventually, this should be determined dynamically, based
	 * on what client has connected and its supported mimetypes.
	 */
71
	char *transcode_mimetype;
72

73 74
	DMAPShareAuthMethod auth_method;

75
	/* mDNS/DNS-SD publishing things */
76 77 78 79
	gboolean server_active;
	gboolean published;
	DmapMdnsPublisher *publisher;

80
	/* HTTP server things */
81 82 83
	SoupServer *server;
	guint revision_number;

84 85 86
	/* The media database */
	DMAPDb *db;
	DMAPContainerDb *container_db;
87 88 89
	
	/* TXT-RECORDS published by mDNS */
	gchar **txt_records;
90

91 92 93
	GHashTable *session_ids;
};

94
/* FIXME: name this something else, as it is more than just share/bitwise now */
95 96 97
struct share_bitwise_t {
	DMAPShare *share;
	bitwise bits;
98
	GSList *id_list;
99 100 101 102 103 104 105

	/* FIXME: ick, void * is DMAPDDb * or GHashTable * 
	 * in next two fields:*/
	void *db;
	DMAPRecord *(*lookup_by_id) (void *db, guint id);

	void (*destroy) (void *);
106 107
};

108 109 110 111 112 113 114 115 116
static void dmap_share_init       (DMAPShare *share);
static void dmap_share_class_init (DMAPShareClass *klass);

G_DEFINE_ABSTRACT_TYPE (DMAPShare, dmap_share, G_TYPE_OBJECT)

#define DMAP_SHARE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
				   TYPE_DMAP_SHARE, DMAPSharePrivate))

static gboolean
117
_dmap_share_soup_auth_callback (SoupAuthDomain *auth_domain,
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
		    SoupMessage    *msg,
		    const char     *username,
		    gpointer        password,
		    DMAPShare    *share)
{
	gboolean    allowed;
	const char *path;

	path = soup_message_get_uri (msg)->path;
	g_debug ("Auth request for %s, user %s", path, username);

	allowed = !strcmp (password, share->priv->password);
	g_debug ("Auth request: %s", allowed ? "ALLOWED" : "DENIED");

	return allowed;
}

static void server_info_adapter (SoupServer *server,
				 SoupMessage *message,
				 const char *path,
				 GHashTable *query,
				 SoupClientContext *context,
				 DMAPShare *share)
{
	DMAP_SHARE_GET_CLASS (share)->server_info (share,
						   server,
						   message,
						   path,
						   query,
						   context);
}

static void content_codes_adapter (SoupServer *server,
				   SoupMessage *message,
				   const char *path,
				   GHashTable *query,
				   SoupClientContext *context,
				   DMAPShare *share)
{
	DMAP_SHARE_GET_CLASS (share)->content_codes (share,
						     server,
						     message,
						     path,
						     query,
						     context);
}

static void login_adapter (SoupServer *server,
			   SoupMessage *message,
			   const char *path,
			   GHashTable *query,
			   SoupClientContext *context,
			   DMAPShare *share)
{
	DMAP_SHARE_GET_CLASS (share)->login (share,
					     server,
					     message,
					     path,
					     query,
					     context);
}

static void logout_adapter (SoupServer *server,
			    SoupMessage *message,
			    const char *path,
			    GHashTable *query,
			    SoupClientContext *context,
			    DMAPShare *share)
{
	DMAP_SHARE_GET_CLASS (share)->logout (share,
					      server,
					      message,
					      path,
					      query,
					      context);
}

static void update_adapter (SoupServer *server,
			    SoupMessage *message,
			    const char *path,
			    GHashTable *query,
			    SoupClientContext *context,
			    DMAPShare *share)
{
	DMAP_SHARE_GET_CLASS (share)->update (share,
					      server,
					      message,
					      path,
					      query,
					      context);
}

static void databases_adapter (SoupServer *server,
			       SoupMessage *message,
			       const char *path,
			       GHashTable *query,
			       SoupClientContext *context,
			       DMAPShare *share)
{
	DMAP_SHARE_GET_CLASS (share)->databases (share,
						 server,
						 message,
						 path,
						 query,
						 context);
}

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
static void ctrl_int_adapter (SoupServer *server,
                              SoupMessage *message,
                              const char *path,
                              GHashTable *query,
                              SoupClientContext *context,
                              DMAPShare *share)
{
	DMAP_SHARE_GET_CLASS (share)->ctrl_int (share,
	                                        server,
	                                        message,
	                                        path,
	                                        query,
	                                        context);
}

240
gboolean
241
_dmap_share_server_start (DMAPShare *share)
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
{
	guint port = DMAP_SHARE_GET_CLASS (share)->get_desired_port (share);
	gboolean              password_required;

	share->priv->server = soup_server_new (SOUP_SERVER_PORT, port, NULL);
	if (share->priv->server == NULL) {
		g_warning ("Unable to start music sharing server on port %d, trying any open port", port);
		share->priv->server = soup_server_new (SOUP_SERVER_PORT, SOUP_ADDRESS_ANY_PORT, NULL);

		if (share->priv->server == NULL) {
			g_warning ("Unable to start music sharing server");
			return FALSE;
		}
	}

	share->priv->port = (guint)soup_server_get_port (share->priv->server);
	g_debug ("Started DMAP server on port %u", share->priv->port);

	password_required = (share->priv->auth_method != DMAP_SHARE_AUTH_METHOD_NONE);

	if (password_required) {
		SoupAuthDomain *auth_domain;

		auth_domain = soup_auth_domain_basic_new (SOUP_AUTH_DOMAIN_REALM, "Music Sharing",
							  SOUP_AUTH_DOMAIN_ADD_PATH, "/login",
							  SOUP_AUTH_DOMAIN_ADD_PATH, "/update",
							  SOUP_AUTH_DOMAIN_ADD_PATH, "/database",
269
							  SOUP_AUTH_DOMAIN_FILTER, _dmap_share_soup_auth_filter,
270 271
							  NULL);
		soup_auth_domain_basic_set_auth_callback (auth_domain,
272
							  (SoupAuthDomainBasicAuthCallback) _dmap_share_soup_auth_callback,
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
							  g_object_ref (share),
							  g_object_unref);
		soup_server_add_auth_domain (share->priv->server, auth_domain);
	}

	soup_server_add_handler (share->priv->server, "/server-info",
				 (SoupServerCallback) server_info_adapter,
				 share, NULL);
	soup_server_add_handler (share->priv->server, "/content-codes",
				 (SoupServerCallback) content_codes_adapter,
				 share, NULL);
	soup_server_add_handler (share->priv->server, "/login",
				 (SoupServerCallback) login_adapter,
				 share, NULL);
	soup_server_add_handler (share->priv->server, "/logout",
				 (SoupServerCallback) logout_adapter,
				 share, NULL);
	soup_server_add_handler (share->priv->server, "/update",
				 (SoupServerCallback) update_adapter,
				 share, NULL);
	soup_server_add_handler (share->priv->server, "/databases",
				 (SoupServerCallback) databases_adapter,
				 share, NULL);
296 297 298
	soup_server_add_handler (share->priv->server, "/ctrl-int",
				 (SoupServerCallback) ctrl_int_adapter,
				 share, NULL);
299 300 301 302 303 304 305 306 307 308 309
	soup_server_run_async (share->priv->server);

	/* using direct since there is no g_uint_hash or g_uint_equal */
	share->priv->session_ids = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);

	share->priv->server_active = TRUE;

	return TRUE;
}

static gboolean
310
_dmap_share_server_stop (DMAPShare *share)
311
{
W. Michael Petullo's avatar
W. Michael Petullo committed
312
	g_debug ("Stopping music sharing server on port %d", share->priv->port);
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330

	if (share->priv->server) {
		soup_server_quit (share->priv->server);
		g_object_unref (share->priv->server);
		share->priv->server = NULL;
	}

	if (share->priv->session_ids) {
		g_hash_table_destroy (share->priv->session_ids);
		share->priv->session_ids = NULL;
	}

	share->priv->server_active = FALSE;

	return TRUE;
}

gboolean
331
_dmap_share_publish_start (DMAPShare *share)
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
{
	gchar *nameprop;
	GError  *error;
	gboolean res;
	gboolean password_required;

	/* FIXME: this is done throughout dmap-share.c. Is this the best way? */
	g_object_get ((gpointer) share, "name", &nameprop, NULL);

	password_required = (share->priv->auth_method != DMAP_SHARE_AUTH_METHOD_NONE);

	error = NULL;
	res = dmap_mdns_publisher_publish (share->priv->publisher,
					      nameprop,
					      share->priv->port,
					      DMAP_SHARE_GET_CLASS (share)->get_type_of_service (share),
					      password_required,
349
					      share->priv->txt_records,
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
					      &error);

	if (res == FALSE) {
		if (error != NULL) {
			g_warning ("Unable to notify network of media sharing: %s", error->message);
			g_error_free (error);
		} else {
			g_warning ("Unable to notify network of media sharing");
		}
		return FALSE;
	} else {
		g_debug ("Published DMAP server information to mdns");
	}

	g_free (nameprop);

	return TRUE;
}

static gboolean
370
_dmap_share_publish_stop (DMAPShare *share)
371 372 373 374 375
{
	if (share->priv->publisher) {
		gboolean res;
		GError  *error;
		error = NULL;
376
		res = dmap_mdns_publisher_withdraw (share->priv->publisher, share->priv->port, &error);
377 378 379 380 381 382 383 384 385 386 387 388
		if (error != NULL) {
			g_warning ("Unable to withdraw music sharing service: %s", error->message);
			g_error_free (error);
		}
		return res;
	}

	share->priv->published = FALSE;
	return TRUE;
}

static void
389
_dmap_share_restart (DMAPShare *share)
390 391 392
{
	gboolean res;

393 394
	_dmap_share_server_stop (share);
	res = _dmap_share_server_start (share);
395 396
	if (res) {
		/* To update information just publish again */
397
		_dmap_share_publish_start (share);
398
	} else {
399
		_dmap_share_publish_stop (share);
400 401 402 403
	}
}

static void
404
_dmap_share_maybe_restart (DMAPShare *share)
405 406
{
	if (share->priv->published) {
407
		_dmap_share_restart (share);
408 409 410 411
	}
}

static void
412
_dmap_share_set_name (DMAPShare *share, const char  *name)
413 414 415 416 417 418 419 420 421
{
	GError *error;
	gboolean res;

	g_return_if_fail (share != NULL);

	g_free (share->priv->name);
	share->priv->name = g_strdup (name);

422 423 424 425 426 427 428 429 430 431 432
	if (share->priv->published) {
		error = NULL;
		res = dmap_mdns_publisher_rename_at_port (share->priv->publisher,
							  share->priv->port,
							  name,
							 &error);
		if (error != NULL) {
			g_warning ("Unable to change MDNS service name: %s",
				   error->message);
			g_error_free (error);
		}
433 434 435 436
	}
}

static void
437
_dmap_share_set_password (DMAPShare *share, const char  *password)
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
{
	g_return_if_fail (share != NULL);

	if (share->priv->password && password &&
	    strcmp (password, share->priv->password) == 0) {
		return;
	}

	g_free (share->priv->password);
	share->priv->password = g_strdup (password);
	if (password != NULL) {
		share->priv->auth_method = DMAP_SHARE_AUTH_METHOD_PASSWORD;
	} else {
		share->priv->auth_method = DMAP_SHARE_AUTH_METHOD_NONE;
	}

454
	_dmap_share_maybe_restart (share);
455 456 457
}

static void
458
_dmap_share_set_property (GObject *object,
459 460 461 462 463 464 465 466
			 guint prop_id,
			 const GValue *value,
			 GParamSpec *pspec)
{
	DMAPShare *share = DMAP_SHARE (object);

	switch (prop_id) {
	case PROP_NAME:
467
		_dmap_share_set_name (share, g_value_get_string (value));
468 469
		break;
	case PROP_PASSWORD:
470
		_dmap_share_set_password (share, g_value_get_string (value));
471
		break;
472 473 474 475 476 477 478 479 480 481
	case PROP_DB:
                share->priv->db = (DMAPDb *) g_value_get_pointer (value);
                break;
        case PROP_CONTAINER_DB:
                share->priv->container_db = (DMAPContainerDb *) g_value_get_pointer (value);
                break;
        case PROP_TRANSCODE_MIMETYPE:
		/* FIXME: get or dup? */
                share->priv->transcode_mimetype = g_value_dup_string (value);
                break;
482 483 484
        case PROP_TXT_RECORDS:
                share->priv->txt_records = g_value_dup_boxed (value);
                break;
485 486 487 488 489 490 491
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
492
_dmap_share_get_property (GObject *object,
493 494 495 496 497 498 499
			 guint prop_id,
			 GValue *value,
			 GParamSpec *pspec)
{
	DMAPShare *share = DMAP_SHARE (object);

	switch (prop_id) {
500 501 502
	case PROP_SERVER:
		g_value_set_object (value, share->priv->server);
		return;
503 504 505 506 507 508 509 510
	case PROP_NAME:
		g_value_set_string (value, share->priv->name);
		break;
	case PROP_PASSWORD:
		g_value_set_string (value, share->priv->password);
		break;
	case PROP_REVISION_NUMBER:
		g_value_set_uint (value,
511
				  _dmap_share_get_revision_number
512 513 514 515
					(DMAP_SHARE (object)));
		break;
	case PROP_AUTH_METHOD:
		g_value_set_uint (value,
516
				  _dmap_share_get_auth_method
517 518
					(DMAP_SHARE (object)));
		break;
519 520 521 522 523 524 525 526 527
	case PROP_DB:
                g_value_set_pointer (value, share->priv->db);
                break;
        case PROP_CONTAINER_DB:
                g_value_set_pointer (value, share->priv->container_db);
                break;
        case PROP_TRANSCODE_MIMETYPE:
                g_value_set_string (value, share->priv->transcode_mimetype);
                break;
528 529 530
        case PROP_TXT_RECORDS:
                g_value_set_boxed (value, share->priv->txt_records);
                break;
531 532 533 534 535 536 537
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}

static void
538
_dmap_share_finalize (GObject *object)
539 540 541
{
	DMAPShare *share = DMAP_SHARE (object);

542 543
	g_debug ("Finalizing DMAPShare");

544
	if (share->priv->published) {
545
		_dmap_share_publish_stop (share);
546 547 548
	}

	if (share->priv->server_active) {
549
		_dmap_share_server_stop (share);
550 551 552
	}

	g_free (share->priv->name);
553 554 555 556
	g_free (share->priv->password);

	g_object_unref (share->priv->db);
	g_object_unref (share->priv->container_db);
557 558
	
	g_strfreev (share->priv->txt_records);
559 560 561 562 563

	if (share->priv->publisher) {
		g_object_unref (share->priv->publisher);
	}

564
	G_OBJECT_CLASS (dmap_share_parent_class)->finalize (object);
565 566 567 568 569 570 571
}

static void
dmap_share_class_init (DMAPShareClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);

572 573
	object_class->get_property = _dmap_share_get_property;
	object_class->set_property = _dmap_share_set_property;
574
	object_class->finalize     = _dmap_share_finalize;
575 576

	/* Pure virtual methods: */
577 578
	klass->get_desired_port     = NULL;
	klass->get_type_of_service  = NULL;
579
	klass->message_add_standard_headers = NULL;
580 581 582 583
	klass->get_meta_data_map    = NULL;
	klass->add_entry_to_mlcl    = NULL;
	klass->databases_browse_xxx = NULL;
	klass->databases_items_xxx  = NULL;
584 585

	/* Virtual methods: */
586 587 588 589
	klass->content_codes  = _dmap_share_content_codes;
	klass->login          = _dmap_share_login;
	klass->logout         = _dmap_share_logout;
	klass->update         = _dmap_share_update;
590 591
	klass->published      = _dmap_share_published;
	klass->name_collision = _dmap_share_name_collision;
592
	klass->databases      = _dmap_share_databases;
593
	klass->ctrl_int       = _dmap_share_ctrl_int;
594

595 596 597 598 599 600 601 602
	g_object_class_install_property (object_class,
					 PROP_SERVER,
					 g_param_spec_object ("server",
							      "Soup Server",
							      "Soup server",
							      SOUP_TYPE_SERVER,
							      G_PARAM_READABLE));
	
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636
	g_object_class_install_property (object_class,
					 PROP_NAME,
					 g_param_spec_string ("name",
						 	    "Name",
							    "Share Name",
							    NULL,
							    G_PARAM_READWRITE));
	g_object_class_install_property (object_class,
					 PROP_PASSWORD,
					 g_param_spec_string ("password",
						      "Authentication password",
						      "Authentication password",
						      NULL,
						      G_PARAM_READWRITE));

	g_object_class_install_property (object_class,
					 PROP_REVISION_NUMBER,
					 g_param_spec_uint ("revision_number",
					 		    "Revision number",
							    "Revision number",
							    0,
							    G_MAXINT,
							    0,
							    G_PARAM_READWRITE));

	g_object_class_install_property (object_class,
					 PROP_AUTH_METHOD,
					 g_param_spec_uint ("auth_method",
					 	"Authentication method",
						"Authentication method",
						DMAP_SHARE_AUTH_METHOD_NONE,
						DMAP_SHARE_AUTH_METHOD_PASSWORD,
						0,
						G_PARAM_READWRITE));
637 638 639 640 641 642 643 644 645 646 647 648 649
	g_object_class_install_property (object_class,
                                         PROP_DB,
                                         g_param_spec_pointer ("db",
                                                              "DB",
                                                              "DB object",
                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));

        g_object_class_install_property (object_class,
                                         PROP_CONTAINER_DB,
                                         g_param_spec_pointer ("container-db",
                                                              "Container DB",
                                                              "Container DB object",
                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
650

651 652 653 654 655 656 657
	g_object_class_install_property (object_class,
                                         PROP_TRANSCODE_MIMETYPE,
                                         g_param_spec_string ("transcode-mimetype",
                                                             "Transcode mimetype",
                                                             "Set mimetype of stream after transcoding",
                                                             NULL,
                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
658 659 660 661 662 663 664 665 666
                                                             

	g_object_class_install_property (object_class,
                                         PROP_TXT_RECORDS,
                                         g_param_spec_boxed ("txt-records",
                                                             "TXT-Records",
                                                             "Set TXT-Records used for MDNS publishing",
                                                             G_TYPE_STRV,
                                                             G_PARAM_READWRITE));
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704

	g_type_class_add_private (klass, sizeof (DMAPSharePrivate));
}

static void published_adapter (DmapMdnsPublisher *publisher,
			       const char          *name,
			       DMAPShare         *share)
{
	DMAP_SHARE_GET_CLASS (share)->published (share, publisher, name);
}

static void name_collision_adapter (DmapMdnsPublisher *publisher,
				    const char          *name,
				    DMAPShare         *share)
{
	DMAP_SHARE_GET_CLASS (share)->name_collision (share, publisher, name);
}

static void
dmap_share_init (DMAPShare *share)
{
	share->priv = DMAP_SHARE_GET_PRIVATE (share);

	share->priv->revision_number = 5;
	share->priv->auth_method = DMAP_SHARE_AUTH_METHOD_NONE;
	share->priv->publisher = dmap_mdns_publisher_new ();

	g_signal_connect_object (share->priv->publisher,
				 "published",
				 G_CALLBACK (published_adapter),
				 share, 0);
	g_signal_connect_object (share->priv->publisher,
				 "name-collision",
				 G_CALLBACK (name_collision_adapter),
				 share, 0);
}

guint
705
_dmap_share_get_auth_method (DMAPShare *share)
706 707 708 709 710
{
	return share->priv->auth_method;
}

guint
711
_dmap_share_get_revision_number (DMAPShare *share)
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
{
	return share->priv->revision_number;
}



static gboolean
get_session_id (GHashTable *query,
		guint32    *id)
{
	char *session_id_str;
	guint32 session_id;

	session_id_str = g_hash_table_lookup (query, "session-id");
	if (session_id_str == NULL) {
		g_warning ("Session id not found.");
		return FALSE;
	}

	session_id = (guint32) strtoul (session_id_str, NULL, 10);
	if (id != NULL) {
		*id = session_id;
	}
	return TRUE;
}

gboolean
739
_dmap_share_get_revision_number_from_query (GHashTable *query,
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
		     guint *number)
{
	char *revision_number_str;
	guint revision_number;

	revision_number_str = g_hash_table_lookup (query, "revision-number");
	if (revision_number_str == NULL) {
		g_warning ("Client asked for an update without a rev. number");
		return FALSE;
	}

	revision_number = strtoul (revision_number_str, NULL, 10);
	if (number != NULL) {
		*number = revision_number;
	}
	return TRUE;
}

gboolean
759
_dmap_share_session_id_validate (DMAPShare       *share,
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
		     SoupClientContext *context,
		     SoupMessage       *message,
		     GHashTable        *query,
		     guint32           *id)
{
	guint32     session_id;
	gboolean    res;
	const char *addr;
	const char *remote_address;

	if (id) {
		*id = 0;
	}

	res = get_session_id (query, &session_id);
	if (! res) {
		g_warning ("Validation failed: Unable to parse session id");
		return FALSE;
	}

	/* check hash for remote address */
	addr = g_hash_table_lookup (share->priv->session_ids,
				    GUINT_TO_POINTER (session_id));
	if (addr == NULL) {
		g_warning ("Validation failed: Unable to lookup session id %u",
			   session_id);
		return FALSE;
	}

	remote_address = soup_client_context_get_host (context);
	g_debug ("Validating session id %u from %s matches %s",
		  session_id, remote_address, addr);
	if (remote_address == NULL || strcmp (addr, remote_address) != 0) {
		g_warning ("Validation failed: Remote address does not match stored address");
		return FALSE;
	}

	if (id) {
		*id = session_id;
	}

	return TRUE;
}

static guint32
session_id_generate (DMAPShare       *share,
		     SoupClientContext *context)
{
	guint32 id;

	id = g_random_int ();

	return id;
}

guint32
816
_dmap_share_session_id_create (DMAPShare       *share,
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841
		   SoupClientContext *context)
{
	guint32     id;
	const char *addr;
	char       *remote_address;

	do {
		/* create a unique session id */
		id = session_id_generate (share, context);
		g_debug ("Generated session id %u", id);

		/* if already used, try again */
		addr = g_hash_table_lookup (share->priv->session_ids,
					    GUINT_TO_POINTER (id));
	} while	(addr != NULL);

	/* store session id and remote address */
	remote_address = g_strdup (soup_client_context_get_host (context));
	g_hash_table_insert (share->priv->session_ids, GUINT_TO_POINTER (id),
			     remote_address);

	return id;
}

void
842
_dmap_share_session_id_remove (DMAPShare       *share,
843 844 845 846 847 848 849
		   SoupClientContext *context,
		   guint32            id)
{
	g_hash_table_remove (share->priv->session_ids, GUINT_TO_POINTER (id));
}

void
850
_dmap_share_message_set_from_dmap_structure (DMAPShare *share,
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
					    SoupMessage *message,
				    	    GNode *structure)
{
	gchar *resp;
	guint length;

	resp = dmap_structure_serialize (structure, &length);

	if (resp == NULL) {
		g_warning ("Serialize gave us null?\n");
		return;
	}

	soup_message_set_response (message, "application/x-dmap-tagged",
				   SOUP_MEMORY_TAKE, resp, length);

867 868
	DMAP_SHARE_GET_CLASS (share)->message_add_standard_headers (share,
								    message);
869 870 871 872 873 874

	soup_message_set_status (message, SOUP_STATUS_OK);
}


gboolean
875
_dmap_share_client_requested (bitwise bits,
876 877 878 879 880 881
		  gint field)
{
	return 0 != (bits & (((bitwise) 1) << field));
}

gboolean
882
_dmap_share_uri_is_local (const char *text_uri)
883 884 885 886 887
{
        return g_str_has_prefix (text_uri, "file://");
}

gboolean
888
_dmap_share_soup_auth_filter (SoupAuthDomain *auth_domain,
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
		  SoupMessage    *msg,
		  gpointer        user_data)
{
	const char *path;

	path = soup_message_get_uri (msg)->path;
	if (g_str_has_prefix (path, "/databases/")) {
		/* Subdirectories of /databases don't actually require
		 * authentication
		 */
		return FALSE;
	} else {
		/* Everything else in auth_domain's paths, including
		 * /databases itself, does require auth.
		 */
		return TRUE;
	}
}

void
909
_dmap_share_published (DMAPShare         *share,
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
		      DmapMdnsPublisher *publisher,
		      const char        *name)
{
	gchar *nameprop;

	g_object_get ((gpointer) share, "name", &nameprop, NULL);

        if (nameprop == NULL || name == NULL) {
		g_free (nameprop);
                return;
        }

        if (strcmp (nameprop, name) == 0) {
                g_debug ("mDNS publish successful");
                share->priv->published = TRUE;
        }

	g_free (nameprop);
}

void
931
_dmap_share_name_collision (DMAPShare         *share,
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947
			   DmapMdnsPublisher *publisher,
			   const char        *name)
{
	gchar *nameprop;
        char *new_name = "FIXME";

	g_object_get ((gpointer) share, "name", &nameprop, NULL);

        if (nameprop == NULL || name == NULL) {
		g_free (nameprop);
                return;
        }

        if (strcmp (nameprop, name) == 0) {
                g_warning ("Duplicate share name on mDNS");

948
                _dmap_share_set_name (DMAP_SHARE(share), new_name);
949 950 951 952 953 954 955 956 957
                g_free (new_name);
        }

	g_free (nameprop);

        return;
}

void
958
_dmap_share_content_codes (DMAPShare *share,
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
		  SoupServer        *server,
		  SoupMessage       *message,
		  const char        *path,
		  GHashTable        *query,
		  SoupClientContext *context)
{
/* MCCR content codes response
 * 	MSTT status
 * 	MDCL dictionary
 * 		MCNM content codes number
 * 		MCNA content codes name
 * 		MCTY content codes type
 * 	MDCL dictionary
 * 	...
 */
	const DMAPContentCodeDefinition *defs;
	guint num_defs = 0;
	guint i;
	GNode *mccr;

	g_debug ("Path is %s.", path);

	defs = dmap_content_codes (&num_defs);

	mccr = dmap_structure_add (NULL, DMAP_CC_MCCR);
	dmap_structure_add (mccr, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);

	for (i = 0; i < num_defs; i++) {
		GNode *mdcl;

		mdcl = dmap_structure_add (mccr, DMAP_CC_MDCL);
		dmap_structure_add (mdcl, DMAP_CC_MCNM, dmap_content_code_string_as_int32(defs[i].string));
		dmap_structure_add (mdcl, DMAP_CC_MCNA, defs[i].name);
		dmap_structure_add (mdcl, DMAP_CC_MCTY, (gint32) defs[i].type);
	}

995
	_dmap_share_message_set_from_dmap_structure (share, message, mccr);
996 997 998 999
	dmap_structure_destroy (mccr);
}

void
1000
_dmap_share_login (DMAPShare *share,
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
	  SoupServer        *server,
	  SoupMessage       *message,
	  const char        *path,
	  GHashTable        *query,
	  SoupClientContext *context)
{
/* MLOG login response
 * 	MSTT status
 * 	MLID session id
 */
	GNode *mlog;
	guint32 session_id;

	g_debug ("Path is %s.", path);

1016
	session_id = _dmap_share_session_id_create (share, context);
1017 1018 1019 1020 1021

	mlog = dmap_structure_add (NULL, DMAP_CC_MLOG);
	dmap_structure_add (mlog, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);
	dmap_structure_add (mlog, DMAP_CC_MLID, session_id);

1022
	_dmap_share_message_set_from_dmap_structure (share, message, mlog);
1023 1024 1025 1026
	dmap_structure_destroy (mlog);
}

void
1027
_dmap_share_logout (DMAPShare *share,
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
	   SoupServer        *server,
	   SoupMessage       *message,
	   const char        *path,
	   GHashTable        *query,
	   SoupClientContext *context)
{
	int     status;
	guint32 id;

	g_debug ("Path is %s.", path);

1039 1040
	if (_dmap_share_session_id_validate (share, context, message, query, &id)) {
		_dmap_share_session_id_remove (share, context, id);
1041 1042 1043 1044 1045 1046 1047 1048 1049 1050

		status = SOUP_STATUS_NO_CONTENT;
	} else {
		status = SOUP_STATUS_FORBIDDEN;
	}

	soup_message_set_status (message, status);
}

void
1051
_dmap_share_update (DMAPShare *share,
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062
	   SoupServer        *server,
	   SoupMessage       *message,
	   const char        *path,
	   GHashTable        *query,
	   SoupClientContext *context)
{
	guint    revision_number;
	gboolean res;

	g_debug ("Path is %s.", path);

1063
	res = _dmap_share_get_revision_number_from_query (query, &revision_number);
1064

1065
	if (res && revision_number != _dmap_share_get_revision_number (share)) {
1066 1067 1068 1069 1070 1071 1072 1073
		/* MUPD update response
		 * 	MSTT status
		 * 	MUSR server revision
		 */
		GNode *mupd;

		mupd = dmap_structure_add (NULL, DMAP_CC_MUPD);
		dmap_structure_add (mupd, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);
1074
		dmap_structure_add (mupd, DMAP_CC_MUSR, (gint32) _dmap_share_get_revision_number (share));
1075

1076
		_dmap_share_message_set_from_dmap_structure (share, message, mupd);
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
		dmap_structure_destroy (mupd);
	} else {
		/* FIXME: This seems like a bug. It just leaks the
		 * message (and socket) without ever replying.
		 */
		g_object_ref (message);
		soup_server_pause_message (server, message);
	}
}

bitwise
1088
_dmap_share_parse_meta_str (const char *attrs, struct DMAPMetaDataMap *mdm)
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102
{
	guint i;
	bitwise bits = 0;

	/* iTunes 8 uses meta=all for /databases/1/items query: */
	if (strcmp (attrs, "all") == 0) {
		bits = ~0;
	} else {
		gchar **attrsv;
	
		attrsv = g_strsplit (attrs, ",", -1);

		for (i = 0; attrsv[i]; i++) {
			guint j;
1103
			gboolean found = FALSE;
1104

1105
			for (j = 0; mdm[j].tag; j++) {
1106 1107
				if (strcmp (mdm[j].tag, attrsv[i]) == 0) {
					bits |= (((bitwise) 1) << mdm[j].md);
1108
					found = TRUE;
1109 1110
				}
			}
1111 1112 1113

			if (found == FALSE)
				g_debug ("Unknown meta request: %s", attrsv[i]);
1114 1115 1116 1117 1118 1119 1120 1121
		}
		g_strfreev (attrsv);
	}	

	return bits;
}

bitwise
1122
_dmap_share_parse_meta (GHashTable *query, struct DMAPMetaDataMap *mdm)
1123 1124 1125 1126 1127 1128 1129
{
	const gchar *attrs;

	attrs = g_hash_table_lookup (query, "meta");
	if (attrs == NULL) {
		return 0;
	}
1130
	return _dmap_share_parse_meta_str (attrs, mdm);
1131 1132 1133
}

void
1134
_dmap_share_add_playlist_to_mlcl (gpointer id, DMAPContainerRecord *record, gpointer _mb)
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
{
	/* MLIT listing item
	 * MIID item id
	 * MPER persistent item id
	 * MINM item name
	 * MIMC item count
	 */
	GNode *mlit;
	guint num_songs;
	gchar *name;
1145
	struct MLCL_Bits *mb = (struct MLCL_Bits *) _mb;
1146 1147 1148 1149

	num_songs = dmap_container_record_get_entry_count (record);
	g_object_get (record, "name", &name, NULL);

1150 1151 1152 1153 1154
	/* FIXME: ITEM_ID, etc. is defined in DAAPShare, so I can't use
	 * with _dmap_share_client_requested() here (see add_entry_to_mlcl())
	 */

	mlit = dmap_structure_add (mb->mlcl, DMAP_CC_MLIT);
1155 1156 1157 1158 1159 1160
	dmap_structure_add (mlit, DMAP_CC_MIID, dmap_container_record_get_id (record));
	/* we don't have a persistant ID for playlists, unfortunately */
	dmap_structure_add (mlit, DMAP_CC_MPER, (gint64) dmap_container_record_get_id (record));
	dmap_structure_add (mlit, DMAP_CC_MINM, name);
	dmap_structure_add (mlit, DMAP_CC_MIMC, (gint32) num_songs);

W. Michael Petullo's avatar
W. Michael Petullo committed
1161 1162 1163 1164 1165 1166 1167 1168
	/* FIXME: Is this getting music-specific? */
	dmap_structure_add (mlit, DMAP_CC_FQUESCH, 0);
	dmap_structure_add (mlit, DMAP_CC_MPCO, 0);
	dmap_structure_add (mlit, DMAP_CC_AESP, 0);
	dmap_structure_add (mlit, DMAP_CC_AEPP, 0);
	dmap_structure_add (mlit, DMAP_CC_AEPS, 0);
	dmap_structure_add (mlit, DMAP_CC_AESG, 0);

1169 1170
	g_free (name);

1171 1172
	return;
} 
1173

1174
GSList *
W. Michael Petullo's avatar
W. Michael Petullo committed
1175
_dmap_share_build_filter (gchar *filterstr)
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
{
	/* Produces a list of lists, each being a filter definition that may
	 * be one or more filter criteria.
	 */

	/* A filter string looks like (iTunes):
	 * 'daap.songgenre:Other'+'daap.songartist:Band'.
	 * or (Roku):
	 * 'daap.songgenre:Other' 'daap.songartist:Band'.
	 * or
         * 'dmap.itemid:1000'
	 * or
         * 'dmap.itemid:1000','dmap:itemid:1001'
	 * or
	 * 'daap.songgenre:Foo'+'daap.songartist:Bar'+'daap.songalbum:Baz'
	 * or (iPhoto '09)
	 * ('daap.idemid:1000','dmap:itemid:1001')
1193 1194
	 * or (DACP):
	 * ('com.apple.itunes.mediakind:1','com.apple.itunes.mediakind:32') 'daap.songartist!:'
1195 1196
         */

1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
	gchar *next_char;
	GString *value;
	//gboolean save_value;
	gboolean is_key;
	gboolean is_value;
	gboolean new_group;
	gboolean accept;
	gboolean negate;
	gint parentheses_count;
	gint quotes_count;
	FilterDefinition *def;
	
1209
	GSList *list = NULL;
1210
	GSList *filter = NULL;
1211 1212 1213

	g_debug ("Filter string is %s.", filterstr);

1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
	if (filterstr == NULL)
		return NULL;
	
	next_char = filterstr;
	
	parentheses_count = 0;
	quotes_count = 0;
	is_key = TRUE;
	is_value = FALSE;
	new_group = FALSE;
	negate = FALSE;
	value = NULL;
	def = NULL;
	
	// The query string is divided in groups of AND separated by a space,
	// each group containing queries of OR separated by comma enclosed in
	// parentheses. Queries are key, value pairs separated by ':' enclosed 
	// in quotes or not.
	// The result from this is a list of lists. Here is an example:
	// String is ('com.apple.itunes.mediakind:1','com.apple.itunes.mediakind:32') 'daap.songartist!:'
	// list:
	// |-> filter1: -> com.apple.itunes.mediakind = 1
	// |   |        -> com.apple.itunes.mediakind = 32
	// |-> filter1: -> daap.songartist! = (null)
	// This basically means that the query is (filter1 AND filter2), and
	// filter1 is (com.apple.itunes.mediakind = 1) OR (com.apple.itunes.mediakind = 32)
	while (TRUE) {
		// We check each character to see if it should be included in
		// the current value (the current value will become the query key
		// or the query value). Anything that is not a special character
		// handled below will be accepted (this means weird characters
		// might appear in names).
		// Handling of unicode characters is unknown, but as long it 
		// doesn't appear as a character handled below, it will be
		// included.
		// This parser will result in unknown behaviour on bad-formatted
		// queries (it does not check for syntax errors), but should not 
		// crash. In this way it may accept much more syntaxes then
		// other parsers.
		accept = FALSE;
		// A slash can escape characters such as ', so add the character
		// after the slash.
		if (*next_char == '\\') {
			accept = TRUE;
			next_char++;
		} else {
			switch (*next_char) {
				case '(':
1262 1263 1264 1265 1266
					if (is_value) {
						accept = TRUE;
					} else {
						parentheses_count++;
					}
1267 1268
					break;
				case ')':
1269 1270 1271 1272 1273
					if (is_value) {
						accept = TRUE;
					} else {
						parentheses_count--;
					}
1274 1275 1276 1277 1278 1279 1280 1281 1282
					break;
				case '\'':
					if (quotes_count > 0) {
						quotes_count = 0;
					} else {
						quotes_count = 1;
					}
					break;
				case ' ':
1283
					if (is_value) {
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
						accept = TRUE;
					} else {
						new_group = TRUE;
					}
					break;
				case ':':
					// Inside values, they will be included in the 
					// query string, otherwise it indicates there
					// will be a value next.
					if (is_value) {
						accept = TRUE;
					} else if (is_key) {
						is_value = TRUE;
					}
					break;
1299 1300 1301 1302 1303 1304 1305
				case '!':
					if (is_value) {
						accept = TRUE;
					} else if (is_key && value) {
						negate = TRUE;
					}
					break;
1306 1307
				case ',':
				case '+':
1308 1309 1310 1311 1312
					// Accept these characters only if inside quotes
					if (is_value) {
						accept = TRUE;
					}
					break;
1313
				case '\0':
1314
					// Never accept
1315 1316 1317
					break;
				default:
					accept = TRUE;
1318
					break;
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
			}
		}
		//g_debug ("Char: %c, Accept: %s", *next_char, accept?"TRUE":"FALSE");
		//Is the next character to be accepted?
		if (accept) {
			if (!value) {
				value = g_string_new ("");
			}
			g_string_append_c (value, *next_char);
		} else if (value != NULL && *next_char != '!') {
			// If we won't accept this character, we are ending a 
			// query key or value, so we should save them in a new
			// FilterDefinition. If is_value is TRUE, we will still
			// parse the query value, so we must keep our def around.
			// Otherwise, save it in the list of filters.
			if (!def) {
1335
				def = g_new0 (FilterDefinition, 1);
1336
			}
1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355
			if (is_key) {
				def->key = value->str;
				g_string_free (value, FALSE);
				def->negate = negate;
				negate = FALSE;
				is_key = FALSE;
			} else {
				def->value = value->str;
				g_string_free (value, FALSE);
				is_value = FALSE;
				is_key = TRUE;
			}
			value = NULL;
			if (!is_value) {
				filter = g_slist_append (filter, def);
				def = NULL;
			}
		}
		if (new_group && filter) {
1356
			list = g_slist_append (list, filter);
1357 1358
			filter = NULL;
			new_group = FALSE;
1359
		}
1360 1361 1362 1363 1364 1365 1366 1367 1368
		// Only handle \0 here so we can handle remaining values above.
		if (*next_char == '\0')
			break;
		next_char++;
	};

	// Any remaining def or filter must still be handled here.
	if (def) {
		filter = g_slist_append (filter, def);
1369
	}
1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
	
	if (filter) {
		list = g_slist_append (list, filter);
	}	

	GSList *ptr1, *ptr2;

        for (ptr1 = list; ptr1 != NULL; ptr1 = ptr1->next) {
                for (ptr2 = ptr1->data; ptr2 != NULL; ptr2 = ptr2->next) {
                	g_debug ("%s = %s", ((FilterDefinition *) ptr2->data)->key, ((FilterDefinition *) ptr2->data)->value);
                }
        }
1382 1383 1384 1385

        return list;
}

1386 1387
void
dmap_share_free_filter (GSList *filter)
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
{
        GSList *ptr1, *ptr2;

        for (ptr1 = filter; ptr1 != NULL; ptr1 = ptr1->next) {
                for (ptr2 = ptr1->data; ptr2 != NULL; ptr2 = ptr2->next) {
                        g_free (((FilterDefinition *) ptr2->data)->value);
                        g_free (ptr2->data);
                }
        }
}

1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
typedef struct {
	gchar *name;
	gint64 group_id;
	gchar *artist;
	int count;
} GroupInfo;

static void
group_items (gpointer key, DMAPRecord *record, GHashTable *groups)
{
	gchar *album, *artist;
	GroupInfo *group_info;
	gint64 group_id;
	
	g_object_get (record, "songartist", &artist, "songalbum", &album, "songalbumid", &group_id, NULL);
	if (!album) {
		g_free (artist);
		return;
	}
	group_info = g_hash_table_lookup (groups, album);
	if (!group_info) {
		group_info = g_new0 (GroupInfo, 1);
		g_hash_table_insert (groups, album, group_info);
		// They will be freed when the hash table is freed.
		group_info->name = album;
		group_info->artist = artist;
		group_info->group_id = group_id;
	} else {
		g_free (album);
		g_free (artist);
	}
	(group_info->count)++;
}

static gint
group_info_cmp (gconstpointer group1, gconstpointer group2) 
{
	return g_ascii_strcasecmp (((GroupInfo*)group1)->name, ((GroupInfo*)group2)->name);
}

1439 1440 1441 1442 1443 1444
static void
debug_param (gpointer key, gpointer val, gpointer user_data)
{
        g_debug ("%s %s", (char *) key, (char *) val);
}

1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
void
_dmap_share_ctrl_int (DMAPShare *share,
		      SoupServer        *server,
		      SoupMessage       *message,
		      const char        *path,
		      GHashTable        *query,
		      SoupClientContext *context)
{
	g_debug ("Path is %s.", path);
	if (query) {
		g_hash_table_foreach (query, debug_param, NULL);
	}
	
	g_debug ("ctrl-int not implemented");
}

1461 1462 1463 1464 1465 1466 1467 1468 1469
static void
accumulate_mlcl_size (gpointer id,
		      DMAPRecord *record,
		      gpointer mb)
{
	/* Make copy and set mlcl to NULL so real MLCL does not get changed */
	struct MLCL_Bits mb_copy = *((struct MLCL_Bits *) mb);
	mb_copy.mlcl = dmap_structure_add (NULL, DMAP_CC_MLCL);;

1470 1471 1472 1473 1474 1475 1476
	DMAP_SHARE_GET_CLASS (((struct MLCL_Bits *) mb)->user_data2)->add_entry_to_mlcl (id, record, &mb_copy);
	*((guint *) ((struct MLCL_Bits *) mb)->