[rygel] core: Split out DIDL parsing in ItemCreator



commit 8c7fa7e1ad8b5f3a265b5b82ef313adc4980e910
Author: Jens Georg <mail jensge org>
Date:   Thu Feb 16 13:35:40 2012 +0200

    core: Split out DIDL parsing in ItemCreator

 src/rygel/rygel-item-creator.vala |  103 +++++++++++++++++++------------------
 1 files changed, 53 insertions(+), 50 deletions(-)
---
diff --git a/src/rygel/rygel-item-creator.vala b/src/rygel/rygel-item-creator.vala
index 80f1642..1cecd90 100644
--- a/src/rygel/rygel-item-creator.vala
+++ b/src/rygel/rygel-item-creator.vala
@@ -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) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]