Unify both constructors to operate on SoupMessage.
internal abstract class Rygel.ClientHacks : GLib.Object {
private const string CORRECT_OBJECT_ID = "ObjectID";
- public unowned string object_id { get; protected set; }
-
+ public unowned string object_id { get;
+ protected set;
+ default = CORRECT_OBJECT_ID; }
protected Regex agent_regex;
- public static ClientHacks create_for_action (ServiceAction action)
- throws ClientHacksError {
- try {
- return new XBoxHacks.for_action (action);
- } catch {}
-
- try {
- return new PanasonicHacks.for_action (action);
- } catch {}
-
- return new XBMCHacks.for_action (action);
- }
-
- public static ClientHacks create_for_headers (MessageHeaders headers)
- throws ClientHacksError {
- try {
- return new XBoxHacks.for_headers (headers);
- } catch {}
-
- try {
- return new PanasonicHacks.for_headers (headers);
- } catch {};
-
- return new XBMCHacks.for_headers (headers);
- }
-
- protected ClientHacks (string agent_pattern, MessageHeaders? headers = null)
+ protected ClientHacks (string agent,
+ Message? message)
throws ClientHacksError {
try {
- this.agent_regex = new Regex (agent_pattern,
+ this.agent_regex = new Regex (agent,
RegexCompileFlags.CASELESS,
0);
} catch (RegexError error) {
assert_not_reached ();
}
- if (headers != null) {
- this.check_headers (headers);
+ if (message != null) {
+ this.check_headers (message.request_headers);
}
-
- this.object_id = CORRECT_OBJECT_ID;
}
public bool is_album_art_request (Soup.Message message) {
return (album_art != null) && bool.parse (album_art);
}
+ public static ClientHacks create (Message? message)
+ throws ClientHacksError {
+ try {
+ return new PanasonicHacks (message);
+ } catch (Error error) { }
+
+ try {
+ return new XBoxHacks (message);
+ } catch (Error error) { }
+
+ return new XBMCHacks (message);
+ }
+
public virtual void translate_container_id (MediaQueryAction action,
ref string container_id) {}
this.item.id);
}
- try {
- var hack = ClientHacks.create_for_headers
- (this.msg.request_headers);
- if (hack.is_album_art_request (this.msg) &&
+ if (this.hack != null) {
+ if (this.hack.is_album_art_request (this.msg) &&
this.item is VisualItem) {
var visual_item = this.item as VisualItem;
return;
} else {
- hack.apply (this.item);
+ this.hack.apply (this.item);
}
- } catch (ClientHacksError error) {}
+ }
if (this.uri.thumbnail_index >= 0) {
if (this.item is MusicItem) {
protected HTTPItemURI uri;
public MediaItem item;
+ protected ClientHacks hack;
+
public HTTPRequest (HTTPServer http_server,
Soup.Server server,
Soup.Message msg) {
this.root_container = http_server.root_container;
this.server = server;
this.msg = msg;
+ try {
+ this.hack = ClientHacks.create (msg);
+ } catch (Error error) { }
}
public async void run () {
this.didl_writer = new DIDLLiteWriter (null);
try {
- this.hacks = ClientHacks.create_for_action (this.action);
+ this.hacks = ClientHacks.create (this.action.get_message ());
} catch { /* This just means we need no hacks, yay! */ }
}
}
}
- public PanasonicHacks () throws ClientHacksError, RegexError {
- base (AGENT);
- }
-
- public PanasonicHacks.for_action (ServiceAction action)
- throws ClientHacksError {
- unowned MessageHeaders headers = action.get_message ().request_headers;
- this.for_headers (headers);
- }
-
- public PanasonicHacks.for_headers (MessageHeaders headers)
- throws ClientHacksError {
- base (AGENT, headers);
+ public PanasonicHacks (Message? message = null) throws ClientHacksError {
+ base (AGENT, message);
}
public override void apply (MediaItem item) {
return agent_pattern;
}
- public V1Hacks () throws ClientHacksError, RegexError {
- base (generate_agent_pattern ());
- }
-
- public V1Hacks.for_action (ServiceAction action)
- throws ClientHacksError {
- unowned MessageHeaders headers = action.get_message ().request_headers;
- this.for_headers (headers);
- }
-
- public V1Hacks.for_headers (MessageHeaders headers)
- throws ClientHacksError {
- base (generate_agent_pattern (), headers);
+ public V1Hacks () throws ClientHacksError {
+ base (generate_agent_pattern (), null);
}
public void apply_on_device (RootDevice device,
// promised by developers.
private const string AGENT = ".*Platinum/.*|.*XBMC/.*";
- public XBMCHacks () throws ClientHacksError, RegexError {
- base (AGENT);
- }
-
- public XBMCHacks.for_action (ServiceAction action)
- throws ClientHacksError {
- unowned MessageHeaders headers = action.get_message ().request_headers;
- this.for_headers (headers);
- }
-
- public XBMCHacks.for_headers (MessageHeaders headers)
- throws ClientHacksError {
- base (AGENT, headers);
+ public XBMCHacks (Message? message = null) throws ClientHacksError {
+ base (AGENT, message);
}
public override void apply (MediaItem item) {
using GUPnP;
internal class Rygel.XBoxHacks : ClientHacks {
- private const string AGENT =
- ".*Xbox.*";
+ private const string AGENT = ".*Xbox.*";
private const string DMS = "urn:schemas-upnp-org:device:MediaServer";
private const string DMS_V1 = DMS + ":1";
private const string FRIENDLY_NAME_POSTFIX = ":";
private const string MODEL_VERSION = "11";
private const string CONTAINER_ID = "ContainerID";
- public XBoxHacks () throws ClientHacksError {
- base (AGENT);
- }
-
- public XBoxHacks.for_action (ServiceAction action) throws ClientHacksError {
- unowned MessageHeaders headers = action.get_message ().request_headers;
- this.for_headers (headers);
- }
+ public XBoxHacks (Message? message = null) throws ClientHacksError {
+ base (AGENT, message);
- public XBoxHacks.for_headers (MessageHeaders headers)
- throws ClientHacksError {
- base (AGENT, headers);
-
- var agent = headers.get_one ("User-Agent");
- if (agent.contains ("Xbox")) {
- this.object_id = CONTAINER_ID;
- }
+ this.object_id = CONTAINER_ID;
}
public void apply_on_device (RootDevice device,
}
public class Rygel.ClientHacks {
- public static ClientHacks create_for_headers (MessageHeaders headers) throws Error {
+ public static ClientHacks create (Message? message) throws Error {
throw new ClientHacksError.NA ("");
}