Esempio n. 1
0
void dls_upnp_create_playlist_in_any(dls_upnp_t *upnp, dls_client_t *client,
				     dls_task_t *task,
				     dls_upnp_task_complete_t cb)
{
	dls_async_task_t *cb_data = (dls_async_task_t *)task;
	dls_task_create_playlist_t *task_data;

	DLEYNA_LOG_DEBUG("Enter");

	cb_data->cb = cb;
	task_data = &task->ut.playlist;

	DLEYNA_LOG_DEBUG("Root Path: %s - Id: %s", task->target.root_path,
			 task->target.id);

	if (strcmp(task->target.id, "0")) {
		DLEYNA_LOG_WARNING("Bad path %s", task->target.path);

		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_BAD_PATH,
					     "CreatePlayListInAny must be executed on a root path");

		goto on_error;
	}

	if (!task_data->title || !*task_data->title)
		goto on_param_error;

	if (!g_variant_n_children(task_data->item_path))
		goto on_param_error;

	DLEYNA_LOG_DEBUG_NL();
	DLEYNA_LOG_DEBUG("Title = %s", task_data->title);
	DLEYNA_LOG_DEBUG("Creator = %s", task_data->creator);
	DLEYNA_LOG_DEBUG("Genre = %s", task_data->genre);
	DLEYNA_LOG_DEBUG("Desc = %s", task_data->desc);
	DLEYNA_LOG_DEBUG_NL();

	dls_device_playlist_upload(client, task, "DLNA.ORG_AnyContainer");

	DLEYNA_LOG_DEBUG("Exit");

	return;

on_param_error:

	DLEYNA_LOG_WARNING("Invalid Parameter");

	cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
				     DLEYNA_ERROR_OPERATION_FAILED,
				     "Invalid Parameter");
on_error:

	(void) g_idle_add(dls_async_task_complete, cb_data);

	DLEYNA_LOG_DEBUG("Exit failure");
}
Esempio n. 2
0
void dls_upnp_update_object(dls_upnp_t *upnp, dls_client_t *client,
			    dls_task_t *task,
			    dls_upnp_task_complete_t cb)
{
	dls_async_task_t *cb_data = (dls_async_task_t *)task;
	dls_async_update_t *cb_task_data;
	dls_upnp_prop_mask mask;
	gchar *upnp_filter = NULL;
	dls_task_update_t *task_data;

	DLEYNA_LOG_DEBUG("Enter");

	cb_data->cb = cb;
	cb_task_data = &cb_data->ut.update;
	task_data = &task->ut.update;

	DLEYNA_LOG_DEBUG("Root Path %s Id %s", task->target.root_path,
			 task->target.id);

	if (!dls_props_parse_update_filter(upnp->filter_map,
					   task_data->to_add_update,
					   task_data->to_delete,
					   &mask, &upnp_filter)) {
		DLEYNA_LOG_WARNING("Invalid Parameter");

		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_OPERATION_FAILED,
					     "Invalid Parameter");
		goto on_error;
	}

	cb_task_data->map = upnp->filter_map;

	DLEYNA_LOG_DEBUG("Filter = %s", upnp_filter);
	DLEYNA_LOG_DEBUG("Mask = 0x%"G_GUINT64_FORMAT"x", mask);

	if (mask == 0) {
		DLEYNA_LOG_WARNING("Empty Parameters");

		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_OPERATION_FAILED,
					     "Empty Parameters");

		goto on_error;
	}

	dls_device_update_object(client, task, upnp_filter);

on_error:

	g_free(upnp_filter);

	if (!cb_data->action)
		(void) g_idle_add(dls_async_task_complete, cb_data);

	DLEYNA_LOG_DEBUG("Exit");
}
Esempio n. 3
0
void dlr_upnp_get_icon(dlr_upnp_t *upnp, dlr_task_t *task,
		       dlr_upnp_task_complete_t cb)
{
	dlr_device_t *device;
	dlr_async_task_t *cb_data = (dlr_async_task_t *)task;

	DLEYNA_LOG_DEBUG("Enter");

	device = dlr_device_from_path(task->path, upnp->server_udn_map);

	if (!device) {
		DLEYNA_LOG_WARNING("Cannot locate device");

		cb_data->cb = cb;
		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_OBJECT_NOT_FOUND,
					     "Cannot locate a device for the specified object");

		(void) g_idle_add(dlr_async_task_complete, cb_data);
	} else {
		dlr_device_get_icon(device, task, cb);
	}

	DLEYNA_LOG_DEBUG("Exit");
}
Esempio n. 4
0
static void prv_set_prop_wl_entries(dlr_manager_t *manager,
				    dleyna_settings_t *settings,
				    GVariant *entries,
				    GError **error)
{
	DLEYNA_LOG_DEBUG("Enter");

	if (strcmp(g_variant_get_type_string(entries), "as")) {
		DLEYNA_LOG_WARNING("Invalid parameter type. 'as' expected.");

		*error = g_error_new(DLEYNA_SERVER_ERROR,
				     DLEYNA_ERROR_BAD_QUERY,
				     "Invalid parameter type. 'as' expected.");
		goto exit;
	}

	/* If no error, the white list will be updated in the reload callack
	 * callack
	 */
	dleyna_settings_set_white_list_entries(settings, entries, error);

	if (*error == NULL) {
		dleyna_white_list_clear(manager->wl);
		dleyna_white_list_add_entries(manager->wl, entries);

		prv_wl_notify_prop(manager,
				   DLR_INTERFACE_PROP_WHITE_LIST_ENTRIES,
				   entries);
	}
exit:
	DLEYNA_LOG_DEBUG("Exit");
}
Esempio n. 5
0
void dls_upnp_cancel_upload(dls_upnp_t *upnp, dls_task_t *task)
{
	GError *error = NULL;

	DLEYNA_LOG_DEBUG("Enter");

	DLEYNA_LOG_DEBUG("Root Path %s Id %s", task->target.root_path,
			 task->target.id);

	if (strcmp(task->target.id, "0")) {
		DLEYNA_LOG_WARNING("Bad path %s", task->target.path);

		error = g_error_new(DLEYNA_SERVER_ERROR, DLEYNA_ERROR_BAD_PATH,
				    "CancelUpload must be executed on a root path");
		goto on_error;
	}

	(void) dls_device_cancel_upload(task, &error);

on_error:

	if (error) {
		dls_task_fail(task, error);
		g_error_free(error);
	} else {
		dls_task_complete(task);
	}

	DLEYNA_LOG_DEBUG("Exit");
}
Esempio n. 6
0
void dls_upnp_create_container_in_any(dls_upnp_t *upnp, dls_client_t *client,
				      dls_task_t *task,
				      dls_upnp_task_complete_t cb)
{
	dls_async_task_t *cb_data = (dls_async_task_t *)task;

	DLEYNA_LOG_DEBUG("Enter");

	cb_data->cb = cb;

	DLEYNA_LOG_DEBUG("Root Path %s Id %s", task->target.root_path,
			 task->target.id);

	if (strcmp(task->target.id, "0")) {
		DLEYNA_LOG_WARNING("Bad path %s", task->target.path);

		cb_data->error =
			g_error_new(DLEYNA_SERVER_ERROR, DLEYNA_ERROR_BAD_PATH,
				    "CreateContainerInAnyContainer must be executed on a root path");
		goto on_error;
	}

	dls_device_create_container(client, task, "DLNA.ORG_AnyContainer");

on_error:

	if (!cb_data->action)
		(void) g_idle_add(dls_async_task_complete, cb_data);

	DLEYNA_LOG_DEBUG("Exit");
}
Esempio n. 7
0
gboolean dls_server_get_object_info(const gchar *object_path,
					   gchar **root_path,
					   gchar **object_id,
					   dls_device_t **device,
					   GError **error)
{
	if (!dls_path_get_path_and_id(object_path, root_path, object_id,
				      error)) {
		DLEYNA_LOG_WARNING("Bad object %s", object_path);

		goto on_error;
	}

	*device = dls_device_from_path(*root_path,
				dls_upnp_get_device_udn_map(g_context.upnp));

	if (*device == NULL) {
		*device = dls_device_from_path(*root_path,
				dls_upnp_get_sleeping_device_udn_map(
							      g_context.upnp));
	}

	if (*device == NULL) {
		DLEYNA_LOG_WARNING("Cannot locate device for %s", *root_path);

		*error = g_error_new(DLEYNA_SERVER_ERROR,
				     DLEYNA_ERROR_OBJECT_NOT_FOUND,
				     "Cannot locate device corresponding to"
				     " the specified path");

		g_free(*root_path);
		g_free(*object_id);

		goto on_error;
	}

	return TRUE;

on_error:

	return FALSE;
}
Esempio n. 8
0
void dls_upnp_get_children(dls_upnp_t *upnp, dls_client_t *client,
			   dls_task_t *task,
			   dls_upnp_task_complete_t cb)
{
	dls_async_task_t *cb_data = (dls_async_task_t *)task;
	dls_async_bas_t *cb_task_data;
	gchar *upnp_filter = NULL;
	gchar *sort_by = NULL;

	DLEYNA_LOG_DEBUG("Enter");

	DLEYNA_LOG_DEBUG("Path: %s", task->target.path);
	DLEYNA_LOG_DEBUG("Start: %u", task->ut.get_children.start);
	DLEYNA_LOG_DEBUG("Count: %u", task->ut.get_children.count);

	cb_data->cb = cb;
	cb_task_data = &cb_data->ut.bas;

	cb_task_data->filter_mask =
		dls_props_parse_filter(upnp->filter_map,
				       task->ut.get_children.filter,
				       &upnp_filter);

	DLEYNA_LOG_DEBUG("Filter Mask 0x%"G_GUINT64_FORMAT"x",
			 cb_task_data->filter_mask);

	sort_by = dls_sort_translate_sort_string(upnp->filter_map,
						 task->ut.get_children.sort_by);
	if (!sort_by) {
		DLEYNA_LOG_WARNING("Invalid Sort Criteria");

		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_BAD_QUERY,
					     "Sort Criteria are not valid");
		goto on_error;
	}

	DLEYNA_LOG_DEBUG("Sort By %s", sort_by);

	cb_task_data->protocol_info = client->protocol_info;

	dls_device_get_children(client, task, upnp_filter, sort_by);

on_error:

	if (!cb_data->action)
		(void) g_idle_add(dls_async_task_complete, cb_data);

	g_free(sort_by);
	g_free(upnp_filter);

	DLEYNA_LOG_DEBUG("Exit with %s", !cb_data->action ? "FAIL" : "SUCCESS");
}
Esempio n. 9
0
void dlr_manager_set_prop(dlr_manager_t *manager,
			  dleyna_settings_t *settings,
			  dlr_task_t *task,
			  dlr_manager_task_complete_t cb)
{
	dlr_async_task_t *cb_data = (dlr_async_task_t *)task;
	dlr_task_set_prop_t *task_data = &task->ut.set_prop;
	GVariant *param = task_data->params;
	gchar *name = task_data->prop_name;
	gchar *i_name = task_data->interface_name;
	GError *error = NULL;

	DLEYNA_LOG_DEBUG("Enter");
	DLEYNA_LOG_DEBUG("Path: %s", task->path);
	DLEYNA_LOG_DEBUG("Interface %s", i_name);
	DLEYNA_LOG_DEBUG("Prop.%s", name);

	cb_data->cb = cb;

	if (strcmp(i_name, DLEYNA_SERVER_INTERFACE_MANAGER) &&
	    strcmp(i_name, "")) {
		DLEYNA_LOG_WARNING("Interface is unknown.");

		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_UNKNOWN_INTERFACE,
					     "Interface is unknown.");
		goto exit;
	}

	if (!strcmp(name, DLR_INTERFACE_PROP_NEVER_QUIT))
		prv_set_prop_never_quit(manager, settings,
					g_variant_get_boolean(param),
					&error);
	else if (!strcmp(name, DLR_INTERFACE_PROP_WHITE_LIST_ENABLED))
		prv_set_prop_wl_enabled(manager, settings,
					g_variant_get_boolean(param),
					&error);
	else if (!strcmp(name, DLR_INTERFACE_PROP_WHITE_LIST_ENTRIES))
		prv_set_prop_wl_entries(manager, settings, param, &error);
	else
		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_UNKNOWN_PROPERTY,
					     "Unknown property");

	if (error != NULL)
		cb_data->error = error;

exit:
	(void) g_idle_add(dlr_async_task_complete, cb_data);
	DLEYNA_LOG_DEBUG("Exit");
}
Esempio n. 10
0
void dls_upnp_create_playlist(dls_upnp_t *upnp, dls_client_t *client,
			      dls_task_t *task,
			      dls_upnp_task_complete_t cb)
{
	dls_async_task_t *cb_data = (dls_async_task_t *)task;
	dls_task_create_playlist_t *task_data;

	DLEYNA_LOG_DEBUG("Enter");

	cb_data->cb = cb;
	task_data = &task->ut.playlist;

	DLEYNA_LOG_DEBUG("Root Path: %s - Id: %s", task->target.root_path,
			 task->target.id);

	if (!task_data->title || !*task_data->title)
		goto on_param_error;

	if (!g_variant_n_children(task_data->item_path))
		goto on_param_error;

	DLEYNA_LOG_DEBUG_NL();
	DLEYNA_LOG_DEBUG("Title = %s", task_data->title);
	DLEYNA_LOG_DEBUG("Creator = %s", task_data->creator);
	DLEYNA_LOG_DEBUG("Genre = %s", task_data->genre);
	DLEYNA_LOG_DEBUG("Desc = %s", task_data->desc);
	DLEYNA_LOG_DEBUG_NL();

	dls_device_playlist_upload(client, task, task->target.id);

	DLEYNA_LOG_DEBUG("Exit");

	return;

on_param_error:

	DLEYNA_LOG_WARNING("Invalid Parameter");

	cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
				     DLEYNA_ERROR_OPERATION_FAILED,
				     "Invalid Parameter");

	(void) g_idle_add(dls_async_task_complete, cb_data);

	DLEYNA_LOG_DEBUG("Exit failure");
}
Esempio n. 11
0
void dls_upnp_upload_to_any(dls_upnp_t *upnp, dls_client_t *client,
			    dls_task_t *task,
			    dls_upnp_task_complete_t cb)
{
	dls_async_task_t *cb_data = (dls_async_task_t *)task;
	dls_async_upload_t *cb_task_data;

	DLEYNA_LOG_DEBUG("Enter");

	cb_data->cb = cb;
	cb_task_data = &cb_data->ut.upload;

	DLEYNA_LOG_DEBUG("Root Path %s Id %s", task->target.root_path,
			 task->target.id);

	if (strcmp(task->target.id, "0")) {
		DLEYNA_LOG_WARNING("Bad path %s", task->target.path);

		cb_data->error =
			g_error_new(DLEYNA_SERVER_ERROR, DLEYNA_ERROR_BAD_PATH,
				    "UploadToAnyContainer must be executed on a root path");
		goto on_error;
	}

	if (!prv_compute_mime_and_class(task, cb_task_data, &cb_data->error))
		goto on_error;

	DLEYNA_LOG_DEBUG("MIME Type %s", cb_task_data->mime_type);
	DLEYNA_LOG_DEBUG("Object class %s", cb_task_data->object_class);

	dls_device_upload(client, task, "DLNA.ORG_AnyContainer");

on_error:

	if (!cb_data->action)
		(void) g_idle_add(dls_async_task_complete, cb_data);

	DLEYNA_LOG_DEBUG("Exit");
}
Esempio n. 12
0
void dlr_manager_get_prop(dlr_manager_t *manager,
			  dleyna_settings_t *settings,
			  dlr_task_t *task,
			  dlr_manager_task_complete_t cb)
{
	dlr_async_task_t *cb_data = (dlr_async_task_t *)task;
	dlr_task_get_prop_t *task_data = &task->ut.get_prop;
	gchar *i_name = task_data->interface_name;
	gchar *name = task_data->prop_name;

	DLEYNA_LOG_DEBUG("Enter");
	DLEYNA_LOG_DEBUG("Path: %s", task->path);
	DLEYNA_LOG_DEBUG("Interface %s", i_name);
	DLEYNA_LOG_DEBUG("Prop.%s", name);

	cb_data->cb = cb;

	if (!strcmp(i_name, DLEYNA_SERVER_INTERFACE_MANAGER) ||
	    !strcmp(i_name, "")) {
		cb_data->task.result = prv_get_prop(settings, name);

		if (!cb_data->task.result)
			cb_data->error = g_error_new(
						DLEYNA_SERVER_ERROR,
						DLEYNA_ERROR_UNKNOWN_PROPERTY,
						"Unknown property");
	} else {
		DLEYNA_LOG_WARNING("Interface is unknown.");

		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_UNKNOWN_INTERFACE,
					     "Interface is unknown.");
	}

	(void) g_idle_add(dlr_async_task_complete, cb_data);

	DLEYNA_LOG_DEBUG("Exit");
}
Esempio n. 13
0
static dld_device_t *prv_get_and_check_device(dld_upnp_t *upnp,
					      dld_task_t *task,
					      dld_upnp_task_complete_t cb)
{
	dld_device_t *device;
	dld_async_task_t *cb_data = (dld_async_task_t *)task;

	device = dld_device_from_path(task->path, upnp->device_udn_map);

	if (!device) {
		DLEYNA_LOG_WARNING("Cannot locate device");

		cb_data->cb = cb;
		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_OBJECT_NOT_FOUND,
					     "Cannot locate a device for the "
					     "specified object");

		(void) g_idle_add(dld_async_task_complete, cb_data);
	}

	return device;
}
Esempio n. 14
0
static const gchar *prv_get_device_id(const gchar *object, GError **error)
{
	dlr_device_t *device;

	device = dlr_device_from_path(object,
				dlr_upnp_get_server_udn_map(g_context.upnp));


	if (!device) {
		DLEYNA_LOG_WARNING("Cannot locate device for %s", object);

		*error = g_error_new(DLEYNA_SERVER_ERROR,
				     DLEYNA_ERROR_OBJECT_NOT_FOUND,
				     "Cannot locate device corresponding to the specified path");
		goto on_error;
	}

	return device->path;

on_error:

	return NULL;
}
Esempio n. 15
0
void dlr_manager_get_all_props(dlr_manager_t *manager,
			       dleyna_settings_t *settings,
			       dlr_task_t *task,
			       dlr_manager_task_complete_t cb)
{
	dlr_async_task_t *cb_data = (dlr_async_task_t *)task;
	dlr_task_get_props_t *task_data = &task->ut.get_props;
	gchar *i_name = task_data->interface_name;
	GVariantBuilder vb;

	DLEYNA_LOG_DEBUG("Enter");
	DLEYNA_LOG_DEBUG("Path: %s", task->path);
	DLEYNA_LOG_DEBUG("Interface %s", i_name);

	cb_data->cb = cb;

	g_variant_builder_init(&vb, G_VARIANT_TYPE("a{sv}"));

	if (!strcmp(i_name, DLEYNA_SERVER_INTERFACE_MANAGER) ||
	    !strcmp(i_name, "")) {
		prv_add_all_props(settings, &vb);

		cb_data->task.result = g_variant_ref_sink(
						g_variant_builder_end(&vb));
	} else {
		DLEYNA_LOG_WARNING("Interface is unknown.");

		cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_UNKNOWN_INTERFACE,
					     "Interface is unknown.");
	}

	(void) g_idle_add(dlr_async_task_complete, cb_data);

	DLEYNA_LOG_DEBUG("Exit");
}
Esempio n. 16
0
static void prv_remove_device(dld_upnp_t *upnp, const gchar *ip_address,
			      const char *udn)
{
	dld_device_t *device;
	unsigned int i;
	dld_device_context_t *context;
	gboolean subscribed;
	gboolean under_construction = FALSE;
	prv_device_new_ct_t *priv_t;
	gboolean construction_ctx = FALSE;
	const dleyna_task_queue_key_t *queue_id;

	DLEYNA_LOG_DEBUG("Enter");

	device = g_hash_table_lookup(upnp->device_udn_map, udn);

	if (!device) {
		priv_t = g_hash_table_lookup(upnp->device_uc_map, udn);

		if (priv_t) {
			device = priv_t->device;
			under_construction = TRUE;
		}
	}

	if (!device) {
		DLEYNA_LOG_WARNING("Device not found. Ignoring");
		goto on_error;
	}

	for (i = 0; i < device->contexts->len; ++i) {
		context = g_ptr_array_index(device->contexts, i);
		if (!strcmp(context->ip_address, ip_address))
			break;
	}

	if (i < device->contexts->len) {
		subscribed = (context->bms.subscribed);

		if (under_construction)
			construction_ctx = !strcmp(context->ip_address,
						   priv_t->ip_address);

		(void) g_ptr_array_remove_index(device->contexts, i);

		if (device->contexts->len == 0) {
			if (!under_construction) {
				DLEYNA_LOG_DEBUG(
					"Last Context lost. Delete device");

				upnp->lost_device(device->path);
				g_hash_table_remove(upnp->device_udn_map, udn);
			} else {
				DLEYNA_LOG_WARNING(
				       "Device under construction. Cancelling");

				dleyna_task_processor_cancel_queue(
							priv_t->queue_id);
			}
		} else if (under_construction && construction_ctx) {
			DLEYNA_LOG_WARNING(
				"Device under construction. Switching context");

			/* Cancel previous contruction task chain */
			g_hash_table_remove(priv_t->upnp->device_uc_map,
					    priv_t->udn);
			dleyna_task_queue_set_finally(
						priv_t->queue_id,
						prv_device_context_switch_end);
			dleyna_task_processor_cancel_queue(priv_t->queue_id);

			/* Create a new construction task chain */
			context = dld_device_get_context(device);
			queue_id = prv_create_device_queue(&priv_t);
			prv_update_device_context(priv_t, upnp, udn, device,
						  context->ip_address,
						  queue_id);

			/* Start tasks from current construction step */
			dld_device_construct(device, context, upnp->connection,
					     upnp->interface_info, queue_id);
		} else if (subscribed && !device->timeout_id) {
			DLEYNA_LOG_DEBUG("Subscribe on new context");

			device->timeout_id = g_timeout_add_seconds(1,
					prv_subscribe_to_service_changes,
					device);
		}
	}

on_error:

	DLEYNA_LOG_DEBUG("Exit");

	return;
}
Esempio n. 17
0
static void prv_server_unavailable_cb(GUPnPControlPoint *cp,
				      GUPnPDeviceProxy *proxy,
				      gpointer user_data)
{
	dls_upnp_t *upnp = user_data;
	const char *udn;
	dls_device_t *device;
	const gchar *ip_address;
	unsigned int i;
	dls_device_context_t *context;
	gboolean subscribed;
	gboolean under_construction = FALSE;
	prv_device_new_ct_t *priv_t;

	DLEYNA_LOG_DEBUG("Enter");

	udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy);
	if (!udn)
		goto on_error;

	ip_address = gupnp_context_get_host_ip(
		gupnp_control_point_get_context(cp));

	DLEYNA_LOG_DEBUG("UDN %s", udn);
	DLEYNA_LOG_DEBUG("IP Address %s", ip_address);

	device = g_hash_table_lookup(upnp->server_udn_map, udn);

	if (!device) {
		priv_t = g_hash_table_lookup(upnp->server_uc_map, udn);

		if (priv_t) {
			device = priv_t->device;
			under_construction = TRUE;
		}
	}

	if (!device) {
		DLEYNA_LOG_WARNING("Device not found. Ignoring");
		goto on_error;
	}

	for (i = 0; i < device->contexts->len; ++i) {
		context = g_ptr_array_index(device->contexts, i);
		if (!strcmp(context->ip_address, ip_address))
			break;
	}

	if (i >= device->contexts->len)
		goto on_error;

	subscribed = context->subscribed;

	(void) g_ptr_array_remove_index(device->contexts, i);

	if (device->contexts->len == 0) {
		if (!under_construction) {
			DLEYNA_LOG_DEBUG("Last Context lost. Delete device");
			upnp->lost_server(device->path, upnp->user_data);
			g_hash_table_remove(upnp->server_udn_map, udn);
		} else {
			DLEYNA_LOG_WARNING(
				"Device under construction. Cancelling");

			dleyna_task_processor_cancel_queue(priv_t->queue_id);
		}
	} else if (subscribed && !device->timeout_id) {
		DLEYNA_LOG_DEBUG("Subscribe on new context");

		device->timeout_id = g_timeout_add_seconds(1,
				prv_subscribe_to_contents_change,
				device);
	}

on_error:

	DLEYNA_LOG_DEBUG("Exit");
	DLEYNA_LOG_DEBUG_NL();

	return;
}
Esempio n. 18
0
static void prv_compute_mime_and_dlna_header(const gchar *filename,
					     gchar **mime_type,
					     gchar **dlna_header,
					     GError **error)
{
	gchar *uri;
	GString *header;
	GUPnPDLNAProfile *profile;
	GUPnPDLNAProfileGuesser *guesser;
	gboolean relaxed_mode = TRUE;
	gboolean extended_mode = TRUE;
	const char *profile_name;
	const char *dlna_mime_type;
	GUPnPDLNAOperation operation;
	GUPnPDLNAFlags flags;
	GUPnPDLNAConversion conversion;
	gchar *content_type = NULL;

	*mime_type = NULL;

	*dlna_header = NULL;

	*error = NULL;

	header = g_string_new("");

	guesser = gupnp_dlna_profile_guesser_new(relaxed_mode, extended_mode);

	uri = g_filename_to_uri(filename, NULL, error);
	if (uri == NULL) {
		DLEYNA_LOG_WARNING("Unable to convert filename: %s", filename);

		if (*error) {
			DLEYNA_LOG_WARNING("Error: %s", (*error)->message);

			g_error_free(*error);
			*error = NULL;
		}

		goto on_error;
	}

	profile = gupnp_dlna_profile_guesser_guess_profile_sync(guesser,
								uri,
								5000,
								NULL,
								error);
	if (profile == NULL) {
		DLEYNA_LOG_WARNING("Unable to guess profile for URI: %s", uri);

		if (*error) {
			DLEYNA_LOG_WARNING("Error: %s", (*error)->message);

			g_error_free(*error);
			*error = NULL;
		}

		goto on_error;
	}

	profile_name = gupnp_dlna_profile_get_name(profile);
	if (profile_name != NULL)
		g_string_append_printf(header, "DLNA.ORG_PN=%s;", profile_name);

	operation = GUPNP_DLNA_OPERATION_RANGE;
	g_string_append_printf(header, "DLNA.ORG_OP=%.2x;", operation);

	conversion = GUPNP_DLNA_CONVERSION_NONE;
	g_string_append_printf(header, "DLNA.ORG_CI=%.2x;", conversion);

	dlna_mime_type = gupnp_dlna_profile_get_mime(profile);
	if (dlna_mime_type != NULL) {
		*mime_type = g_strdup(dlna_mime_type);

		flags = GUPNP_DLNA_FLAGS_BACKGROUND_TRANSFER_MODE;
		flags |= GUPNP_DLNA_FLAGS_CONNECTION_STALL;
		flags |= GUPNP_DLNA_FLAGS_DLNA_V15;

		if (g_content_type_is_a(dlna_mime_type, "image/*")) {
			flags |= GUPNP_DLNA_FLAGS_INTERACTIVE_TRANSFER_MODE;
		} else if (g_content_type_is_a(dlna_mime_type, "audio/*") ||
			   g_content_type_is_a(dlna_mime_type, "video/*")) {
			flags |= GUPNP_DLNA_FLAGS_STREAMING_TRANSFER_MODE;
		} else {
			DLEYNA_LOG_WARNING("Unsupported Mime Type: %s",
					   dlna_mime_type);

			goto on_error;
		}

		g_string_append_printf(header, "DLNA.ORG_FLAGS=%.8x", flags);
		g_string_append_printf(header, "000000000000000000000000");
	} else {
		DLEYNA_LOG_WARNING("Unable to discover mime_type");
	}

on_error:

	if (*mime_type == NULL) {
		content_type = g_content_type_guess(filename, NULL, 0, NULL);

		if (content_type != NULL) {
			*mime_type = g_content_type_get_mime_type(content_type);

			if (*mime_type == NULL)
				*error = g_error_new(DLEYNA_SERVER_ERROR,
						     DLEYNA_ERROR_BAD_MIME,
						     "Unable to determine MIME Type for %s",
						     filename);

			g_free(content_type);
		} else {
			*error = g_error_new(DLEYNA_SERVER_ERROR,
					     DLEYNA_ERROR_BAD_MIME,
					     "Unable to determine Content Type for %s",
					     filename);
		}
	}

	DLEYNA_LOG_DEBUG("contentFeatures.dlna.org: %s", header->str);

	g_object_unref(guesser);

	g_free(uri);

	if (*mime_type)
		*dlna_header = g_string_free(header, FALSE);
	else
		(void) g_string_free(header, TRUE);

	return;
}
Esempio n. 19
0
static gboolean prv_compute_mime_and_class(dls_task_t *task,
					   dls_async_upload_t *cb_task_data,
					   GError **error)
{
	gchar *content_type = NULL;

	if (!g_file_test(task->ut.upload.file_path,
			 G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS)) {
		DLEYNA_LOG_WARNING(
			"File %s does not exist or is not a regular file",
			task->ut.upload.file_path);

		*error = g_error_new(DLEYNA_SERVER_ERROR,
				     DLEYNA_ERROR_OBJECT_NOT_FOUND,
				     "File %s does not exist or is not a regular file",
				     task->ut.upload.file_path);
		goto on_error;
	}

	content_type = g_content_type_guess(task->ut.upload.file_path, NULL, 0,
					    NULL);

	if (!content_type) {
		DLEYNA_LOG_WARNING("Unable to determine Content Type for %s",
				   task->ut.upload.file_path);

		*error = g_error_new(DLEYNA_SERVER_ERROR, DLEYNA_ERROR_BAD_MIME,
				     "Unable to determine Content Type for %s",
				     task->ut.upload.file_path);
		goto on_error;
	}

	cb_task_data->mime_type = g_content_type_get_mime_type(content_type);
	g_free(content_type);

	if (!cb_task_data->mime_type) {
		DLEYNA_LOG_WARNING("Unable to determine MIME Type for %s",
				   task->ut.upload.file_path);

		*error = g_error_new(DLEYNA_SERVER_ERROR, DLEYNA_ERROR_BAD_MIME,
				     "Unable to determine MIME Type for %s",
				     task->ut.upload.file_path);
		goto on_error;
	}

	if (g_content_type_is_a(cb_task_data->mime_type, "image/*")) {
		cb_task_data->object_class = "object.item.imageItem";
	} else if (g_content_type_is_a(cb_task_data->mime_type, "audio/*")) {
		cb_task_data->object_class = "object.item.audioItem";
	} else if (g_content_type_is_a(cb_task_data->mime_type, "video/*")) {
		cb_task_data->object_class = "object.item.videoItem";
	} else {
		DLEYNA_LOG_WARNING("Unsupported MIME Type %s",
				   cb_task_data->mime_type);

		*error = g_error_new(DLEYNA_SERVER_ERROR, DLEYNA_ERROR_BAD_MIME,
				     "Unsupported MIME Type %s",
				     cb_task_data->mime_type);
		goto on_error;
	}

	return TRUE;

on_error:

	return FALSE;
}
Esempio n. 20
0
static void prv_server_unavailable_cb(GUPnPControlPoint *cp,
				      GUPnPDeviceProxy *proxy,
				      gpointer user_data)
{
	dls_upnp_t *upnp = user_data;
	const char *udn;
	dls_device_t *device;
	const gchar *ip_address;
	unsigned int i;
	dls_device_context_t *context;
	gboolean subscribed;
	gboolean construction_ctx = FALSE;
	gboolean under_construction = FALSE;
	prv_device_new_ct_t *priv_t;
	const dleyna_task_queue_key_t *queue_id;

	DLEYNA_LOG_DEBUG("Enter");

	udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy);

	ip_address = gupnp_context_get_host_ip(
		gupnp_control_point_get_context(cp));

	if (!udn || !ip_address)
		goto on_error;

	DLEYNA_LOG_DEBUG("UDN %s", udn);
	DLEYNA_LOG_DEBUG("IP Address %s", ip_address);

	device = g_hash_table_lookup(upnp->server_udn_map, udn);

	if (!device) {
		priv_t = g_hash_table_lookup(upnp->server_uc_map, udn);

		if (priv_t) {
			device = priv_t->device;
			under_construction = TRUE;
		}
	}

	if (!device) {
		DLEYNA_LOG_WARNING("Device not found. Ignoring");
		goto on_error;
	}

	for (i = 0; i < device->contexts->len; ++i) {
		context = g_ptr_array_index(device->contexts, i);
		if (!strcmp(context->ip_address, ip_address))
			break;
	}

	if (i >= device->contexts->len)
		goto on_error;

	subscribed = context->subscribed;
	if (under_construction)
		construction_ctx = !strcmp(context->ip_address,
					   priv_t->ip_address);

	(void) g_ptr_array_remove_index(device->contexts, i);

	if (device->contexts->len == 0) {
		if (!under_construction) {
			DLEYNA_LOG_DEBUG("Last Context lost. Delete device");
			upnp->lost_server(device->path, upnp->user_data);
			g_hash_table_remove(upnp->server_udn_map, udn);
		} else {
			DLEYNA_LOG_WARNING(
				"Device under construction. Cancelling");

			dleyna_task_processor_cancel_queue(priv_t->queue_id);
		}
	} else if (under_construction && construction_ctx) {
		DLEYNA_LOG_WARNING(
			"Device under construction. Switching context");

		/* Cancel previous contruction task chain */
		g_hash_table_remove(priv_t->upnp->server_uc_map, priv_t->udn);
		dleyna_task_queue_set_finally(priv_t->queue_id,
					      prv_device_context_switch_end);
		dleyna_task_processor_cancel_queue(priv_t->queue_id);

		/* Create a new construction task chain */
		context = dls_device_get_context(device, NULL);
		queue_id = prv_create_device_queue(&priv_t);
		prv_update_device_context(priv_t, upnp, udn, device,
					  context->ip_address, queue_id);

		/* Start tasks from current construction step */
		dls_device_construct(device,
				     context,
				     upnp->connection,
				     upnp->interface_info,
				     upnp->property_map,
				     queue_id);

	} else if (subscribed && !device->timeout_id) {
		DLEYNA_LOG_DEBUG("Subscribe on new context");

		device->timeout_id = g_timeout_add_seconds(1,
				prv_subscribe_to_contents_change,
				device);
	}

on_error:

	DLEYNA_LOG_DEBUG("Exit");
	DLEYNA_LOG_DEBUG_NL();

	return;
}