2 * Copyright (C) 2011 Red Hat, Inc.
3 * Copyright (C) 2010 Nokia Corporation.
5 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
7 * This file is part of Rygel.
9 * Rygel is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Rygel is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 internal errordomain Rygel.ClientHacksError {
31 internal abstract class Rygel.ClientHacks : GLib.Object {
32 private const string CORRECT_OBJECT_ID = "ObjectID";
34 public unowned string object_id { get; protected set; }
36 protected Regex agent_regex;
38 public static ClientHacks create_for_action (ServiceAction action)
39 throws ClientHacksError {
41 return new XBoxHacks.for_action (action);
45 return new PanasonicHacks.for_action (action);
48 return new XBMCHacks.for_action (action);
51 public static ClientHacks create_for_headers (MessageHeaders headers)
52 throws ClientHacksError {
54 return new XBoxHacks.for_headers (headers);
58 return new PanasonicHacks.for_headers (headers);
61 return new XBMCHacks.for_headers (headers);
64 protected ClientHacks (string agent_pattern, MessageHeaders? headers = null)
65 throws ClientHacksError {
67 this.agent_regex = new Regex (agent_pattern,
68 RegexCompileFlags.CASELESS,
70 } catch (RegexError error) {
71 // This means subclasses did not provide a proper regular expression
72 assert_not_reached ();
75 if (headers != null) {
76 this.check_headers (headers);
79 this.object_id = CORRECT_OBJECT_ID;
82 public bool is_album_art_request (Soup.Message message) {
83 unowned string query = message.get_uri ().query;
89 var params = Soup.Form.decode (query);
90 var album_art = params.lookup ("albumArt");
92 return (album_art != null) && bool.parse (album_art);
95 public virtual void translate_container_id (MediaQueryAction action,
96 ref string container_id) {}
98 public virtual void apply (MediaItem item) {}
100 public virtual void filter_sort_criteria (ref string sort_criteria) {}
102 public virtual async MediaObjects? search
103 (SearchableContainer container,
104 SearchExpression? expression,
107 out uint total_matches,
108 Cancellable? cancellable)
110 return yield container.search (expression,
117 private void check_headers (MessageHeaders headers)
118 throws ClientHacksError {
119 var agent = headers.get_one ("User-Agent");
120 if (agent == null || !(this.agent_regex.match (agent))) {
121 throw new ClientHacksError.NA (_("Not Applicable"));