Codebase list virt-viewer / 905d84b
foreign-menu: Check if storage domain is active for data center This last patch of the series is where we actually check if the storage domain is active in the data center the VM is associated with. It makes use of g_strv_contains(), which is available only in glib version 2.44. Compatibility code has been added if building against older versions than required. Related: https://bugzilla.redhat.com/show_bug.cgi?id=1427467 https://bugzilla.redhat.com/show_bug.cgi?id=1428401 Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com> Eduardo Lima (Etrunko) 6 years ago
4 changed file(s) with 101 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
5353
5454 libvirt_viewer_la_SOURCES = \
5555 $(BUILT_SOURCES) \
56 glib-compat.h \
57 glib-compat.c \
5658 virt-viewer-auth.h \
5759 virt-viewer-auth.c \
5860 virt-viewer-app.h \
0 /*
1 * This library is free software; you can redistribute it and/or
2 * modify it under the terms of the GNU Lesser General Public
3 * License as published by the Free Software Foundation; either
4 * version 2 of the License, or (at your option) any later version.
5 *
6 * This library is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * Lesser General Public License for more details.
10 *
11 * You should have received a copy of the GNU Lesser General Public
12 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
13 */
14 #include <config.h>
15
16 #include "glib-compat.h"
17
18 #if !GLIB_CHECK_VERSION(2,44,0)
19 gboolean
20 g_strv_contains (const gchar * const *strv,
21 const gchar *str)
22 {
23 g_return_val_if_fail (strv != NULL, FALSE);
24 g_return_val_if_fail (str != NULL, FALSE);
25
26 for (; *strv != NULL; strv++)
27 {
28 if (g_str_equal (str, *strv))
29 return TRUE;
30 }
31
32 return FALSE;
33 }
34 #endif
0 /*
1 * Virt Viewer: A virtual machine console viewer
2 *
3 * Copyright (C) 2017 Red Hat, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Author: Eduardo Lima (Etrunko) <etrunko@redhat.com>
20 */
21
22 #include <config.h>
23
24 #ifndef GLIB_COMPAT_H
25 #define GLIB_COMPAT_H 1
26
27 #include <glib.h>
28
29 G_BEGIN_DECLS
30
31 #if !GLIB_CHECK_VERSION(2,44,0)
32 gboolean g_strv_contains (const gchar * const *strv,
33 const gchar *str);
34 #endif
35
36 G_END_DECLS
37
38 #endif // GLIB_COMPAT_H
2828
2929 #include "ovirt-foreign-menu.h"
3030 #include "virt-viewer-util.h"
31 #include "glib-compat.h"
3132
3233 typedef enum {
3334 STATE_0,
620621 cdroms_fetched_cb, task);
621622 }
622623
624 #ifdef HAVE_OVIRT_DATA_CENTER
625 static gboolean storage_domain_attached_to_data_center(OvirtStorageDomain *domain,
626 OvirtDataCenter *data_center)
627 {
628 GStrv data_center_ids;
629 char *data_center_guid;
630 gboolean match;
631
632 g_object_get(domain, "data-center-ids", &data_center_ids, NULL);
633 g_object_get(data_center, "guid", &data_center_guid, NULL);
634 match = g_strv_contains((const gchar * const *) data_center_ids, data_center_guid);
635 g_strfreev(data_center_ids);
636 g_free(data_center_guid);
637
638 return match;
639 }
640 #endif
641
623642
624643 static void storage_domains_fetched_cb(GObject *source_object,
625644 GAsyncResult *result,
654673 if (state != OVIRT_STORAGE_DOMAIN_STATE_ACTIVE) {
655674 continue;
656675 }
676
677 #ifdef HAVE_OVIRT_DATA_CENTER
678 if (!storage_domain_attached_to_data_center(domain, menu->priv->data_center)) {
679 continue;
680 }
681 #endif
657682
658683 file_collection = ovirt_storage_domain_get_files(domain);
659684 if (file_collection != NULL) {