core: Split out DIDL parsing in ItemCreator
authorJens Georg <mail@jensge.org>
Thu, 16 Feb 2012 11:35:40 +0000 (13:35 +0200)
committerJens Georg <mail@jensge.org>
Tue, 21 Feb 2012 13:41:44 +0000 (15:41 +0200)
src/rygel/rygel-item-creator.vala

index 80f1642..1cecd90 100644 (file)
@@ -68,56 +68,7 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
     public async void run () {
         try {
             this.parse_args ();
-
-            this.didl_parser.item_available.connect ((didl_item) => {
-                    this.didl_item = didl_item;
-            });
-
-            try {
-                this.didl_parser.parse_didl (this.elements);
-            } catch (Error parse_err) {
-                throw new ContentDirectoryError.BAD_METADATA ("Bad metadata");
-            }
-
-            if (this.didl_item == null) {
-                var message = _("No items in DIDL-Lite from client: '%s'");
-
-                throw new ItemCreatorError.PARSE (message, this.elements);
-            }
-
-            if (didl_item.id == null || didl_item.id != "") {
-                throw new ContentDirectoryError.BAD_METADATA
-                                        ("@id must be set to \"\" in " +
-                                         "CreateItem");
-            }
-
-            if ((didl_item.title == null)) {
-                throw new ContentDirectoryError.BAD_METADATA
-                                        ("dc:title must be set in " +
-                                         "CreateItem");
-            }
-
-            // FIXME: Is this check really necessary?
-            if ((didl_item.dlna_managed &
-                (OCMFlags.UPLOAD |
-                 OCMFlags.CREATE_CONTAINER |
-                 OCMFlags.UPLOAD_DESTROYABLE)) != 0) {
-                throw new ContentDirectoryError.BAD_METADATA
-                                        ("Flags that must not be set " +
-                                         "were found in 'dlnaManaged'");
-            }
-
-            if (didl_item.upnp_class == null ||
-                didl_item.upnp_class == "" ||
-                !didl_item.upnp_class.has_prefix ("object.item")) {
-                throw new ContentDirectoryError.BAD_METADATA
-                                        ("Invalid upnp:class given ");
-            }
-
-            if (didl_item.restricted) {
-                throw new ContentDirectoryError.INVALID_ARGS
-                                        ("Cannot create restricted item");
-            }
+            this.parse_didl ();
 
             var container = yield this.fetch_container ();
 
@@ -232,6 +183,58 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
         }
     }
 
+    private void parse_didl () throws Error {
+        this.didl_parser.item_available.connect ((didl_item) => {
+            this.didl_item = didl_item;
+        });
+
+        try {
+            this.didl_parser.parse_didl (this.elements);
+        } catch (Error parse_err) {
+            throw new ContentDirectoryError.BAD_METADATA ("Bad metadata");
+        }
+
+        if (this.didl_item == null) {
+            var message = _("No items in DIDL-Lite from client: '%s'");
+
+            throw new ItemCreatorError.PARSE (message, this.elements);
+        }
+
+        if (didl_item.id == null || didl_item.id != "") {
+            throw new ContentDirectoryError.BAD_METADATA
+                                        ("@id must be set to \"\" in " +
+                                         "CreateItem");
+        }
+
+        if ((didl_item.title == null)) {
+            throw new ContentDirectoryError.BAD_METADATA
+                                    ("dc:title must be set in " +
+                                     "CreateItem");
+        }
+
+        // FIXME: Is this check really necessary?
+        if ((didl_item.dlna_managed &
+            (OCMFlags.UPLOAD |
+             OCMFlags.CREATE_CONTAINER |
+             OCMFlags.UPLOAD_DESTROYABLE)) != 0) {
+            throw new ContentDirectoryError.BAD_METADATA
+                                        ("Flags that must not be set " +
+                                         "were found in 'dlnaManaged'");
+        }
+
+        if (didl_item.upnp_class == null ||
+            didl_item.upnp_class == "" ||
+            !didl_item.upnp_class.has_prefix ("object.item")) {
+            throw new ContentDirectoryError.BAD_METADATA
+                                        ("Invalid upnp:class given ");
+        }
+
+        if (didl_item.restricted) {
+            throw new ContentDirectoryError.INVALID_ARGS
+                                        ("Cannot create restricted item");
+        }
+    }
+
     private void generalize_upnp_class (ref string upnp_class) {
         char *needle = upnp_class.rstr_len (-1, ".");
         if (needle != null) {