+STATIC char * _rygel_time_for_string (char *string) {
+
+ int total_seconds;
+ unsigned int hours, minutes, seconds;
+ char *time;
+
+ total_seconds = atoi (string);
+ hours = total_seconds / 3600;
+ minutes = (total_seconds / 60) - (hours * 60);
+ seconds = total_seconds - (hours * 3600) - (minutes * 60);
+
+ asprintf (&time, "%u:%02u:%02u", hours, minutes, seconds);
+
+ return time;
+}
+
+STATIC unsigned char _rygel_start_uploading (dev_ctx_T* dev_ctx_c, char *path, char *upload_id) {
+
+ GUPnPServiceProxy *content_dir_proxy;
+ GUPnPDIDLLiteWriter *didl_writer;
+ GUPnPDIDLLiteObject *didl_object;
+ char *didl, *content_type, *mime_type, *upnp_class;
+ struct timeval tv_start, tv_now;
+
+ didl_writer = gupnp_didl_lite_writer_new (NULL);
+ didl_object = GUPNP_DIDL_LITE_OBJECT (gupnp_didl_lite_writer_add_item (didl_writer));
+
+ /* create the metadata for the file */
+ gupnp_didl_lite_object_set_parent_id (didl_object, upload_id);
+ gupnp_didl_lite_object_set_id (didl_object, "");
+ gupnp_didl_lite_object_set_restricted (didl_object, FALSE);
+ gupnp_didl_lite_object_set_title (didl_object, g_path_get_basename (path));
+ /* deduce the UPnP class from the MIME type ("audio/ogg" e.g.) */
+ content_type = g_content_type_guess (path, NULL, 0, NULL);
+ mime_type = g_content_type_get_mime_type (content_type);
+ if (strstr (mime_type, "audio/"))
+ upnp_class = strdup ("object.item.audioItem.musicTrack");
+ else if (strstr (mime_type, "video/"))
+ upnp_class = strdup ("object.item.videoItem");
+ else if (strstr (mime_type, "image/"))
+ upnp_class = strdup ("object.item.imageItem");
+ else
+ upnp_class = strdup ("object.item");
+ gupnp_didl_lite_object_set_upnp_class (didl_object, upnp_class);
+ didl = gupnp_didl_lite_writer_get_string (didl_writer);
+
+ dev_ctx_c->transfer_path = path;
+ dev_ctx_c->transfer_started = 0;
+ content_dir_proxy = GUPNP_SERVICE_PROXY (dev_ctx_c->content_dir);
+
+ gupnp_service_proxy_begin_action (content_dir_proxy, "CreateObject", _rygel_upload_cb, dev_ctx_c,
+ "ContainerID", G_TYPE_STRING, upload_id,
+ "Elements", G_TYPE_STRING, didl,
+ NULL);
+
+ gettimeofday (&tv_start, NULL);
+ gettimeofday (&tv_now, NULL);
+ while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
+
+ g_main_context_iteration (dev_ctx_c->loop, FALSE);
+
+ if (dev_ctx_c->transfer_started)
+ break;
+ gettimeofday (&tv_now, NULL);
+ }
+ if (!dev_ctx_c->transfer_started)
+ return 0;
+
+ return 1;
+}
+
+STATIC unsigned char _rygel_start_doing (dev_ctx_T* dev_ctx_c, char *uri, char *metadata, State state, char *args) {