Remmina - The GTK+ Remote Desktop Client  v1.4.33
Remmina is a remote desktop client written in GTK+, aiming to be useful for system administrators and travellers, who need to work with lots of remote computers in front of either large monitors or tiny netbooks. Remmina supports multiple network protocols in an integrated and consistent user interface. Currently RDP, VNC, NX, XDMCP and SSH are supported.
remmina_string_array.c
Go to the documentation of this file.
1 /*
2  * Remmina - The GTK+ Remote Desktop Client
3  * Copyright (C) 2009 - Vic Lee
4  * Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
5  * Copyright (C) 2016-2023 Antenore Gatta, Giovanni Panozzo
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * In addition, as a special exception, the copyright holders give
23  * permission to link the code of portions of this program with the
24  * OpenSSL library under certain conditions as described in each
25  * individual source file, and distribute linked combinations
26  * including the two.
27  * You must obey the GNU General Public License in all respects
28  * for all of the code used other than OpenSSL. * If you modify
29  * file(s) with this exception, you may extend this exception to your
30  * version of the file(s), but you are not obligated to do so. * If you
31  * do not wish to do so, delete this exception statement from your
32  * version. * If you delete this exception statement from all source
33  * files in the program, then also delete it here.
34  *
35  */
36 
37 #include <glib.h>
38 #include <gmodule.h>
39 #include <string.h>
40 #include "remmina_string_array.h"
42 
45 {
46  TRACE_CALL(__func__);
47  return g_ptr_array_new();
48 }
49 
52 {
53  TRACE_CALL(__func__);
54  RemminaStringArray *array;
55  gchar *buf, *ptr1, *ptr2;
56 
57  array = remmina_string_array_new();
58  if (!strs || strs[0] == '\0')
59  return array;
60 
61  buf = g_strdup(strs);
62  ptr1 = buf;
63  while (ptr1) {
64  ptr2 = strchr(ptr1, ',');
65  if (ptr2)
66  *ptr2++ = '\0';
67  remmina_string_array_add(array, ptr1);
68  ptr1 = ptr2;
69  }
70 
71  g_free(buf);
72 
73  return array;
74 }
75 
78 {
79  TRACE_CALL(__func__);
80  RemminaStringArray *array;
82  g_free(strs);
83  return array;
84 }
85 
86 void remmina_string_array_add(RemminaStringArray* array, const gchar *str)
87 {
88  TRACE_CALL(__func__);
89  g_ptr_array_add(array, g_strdup(str));
90 }
91 
92 gint remmina_string_array_find(RemminaStringArray* array, const gchar *str)
93 {
94  TRACE_CALL(__func__);
95  gint i;
96 
97  for (i = 0; i < array->len; i++) {
98  if (g_strcmp0(remmina_string_array_index(array, i), str) == 0)
99  return i;
100  }
101  return -1;
102 }
103 
105 {
106  TRACE_CALL(__func__);
107  g_ptr_array_remove_index(array, i);
108 }
109 
110 void remmina_string_array_remove(RemminaStringArray* array, const gchar *str)
111 {
112  TRACE_CALL(__func__);
113  gint i;
114 
115  i = remmina_string_array_find(array, str);
116  if (i >= 0) {
118  }
119 }
120 
121 void remmina_string_array_intersect(RemminaStringArray* array, const gchar *dest_strs)
122 {
123  TRACE_CALL(__func__);
124  RemminaStringArray *dest_array;
125  gint i, j;
126 
127  dest_array = remmina_string_array_new_from_string(dest_strs);
128 
129  i = 0;
130  while (i < array->len) {
131  j = remmina_string_array_find(dest_array, remmina_string_array_index(array, i));
132  if (j < 0) {
134  continue;
135  }
136  i++;
137  }
138 
139  remmina_string_array_free(dest_array);
140 }
141 
142 static gint remmina_string_array_compare_func(const gchar **a, const gchar **b)
143 {
144  TRACE_CALL(__func__);
145  return g_strcmp0(*a, *b);
146 }
147 
149 {
150  TRACE_CALL(__func__);
151  g_ptr_array_sort(array, (GCompareFunc)remmina_string_array_compare_func);
152 }
153 
154 gchar*
156 {
157  TRACE_CALL(__func__);
158  GString *gstr;
159  gint i;
160 
161  gstr = g_string_new("");
162  for (i = 0; i < array->len; i++) {
163  if (i > 0)
164  g_string_append_c(gstr, ',');
165  g_string_append(gstr, remmina_string_array_index(array, i));
166  }
167  return g_string_free(gstr, FALSE);
168 }
169 
171 {
172  TRACE_CALL(__func__);
173  g_ptr_array_foreach(array, (GFunc)g_free, NULL);
174  g_ptr_array_free(array, TRUE);
175 }
176 
static gint remmina_string_array_compare_func(const gchar **a, const gchar **b)
G_BEGIN_DECLS typedef GPtrArray RemminaStringArray
gint remmina_string_array_find(RemminaStringArray *array, const gchar *str)
gchar * remmina_string_array_to_string(RemminaStringArray *array)
void remmina_string_array_intersect(RemminaStringArray *array, const gchar *dest_strs)
void remmina_string_array_remove_index(RemminaStringArray *array, gint i)
void remmina_string_array_sort(RemminaStringArray *array)
void remmina_string_array_free(RemminaStringArray *array)
RemminaStringArray * remmina_string_array_new_from_allocated_string(gchar *strs)
RemminaStringArray * remmina_string_array_new_from_string(const gchar *strs)
RemminaStringArray * remmina_string_array_new(void)
void remmina_string_array_remove(RemminaStringArray *array, const gchar *str)
void remmina_string_array_add(RemminaStringArray *array, const gchar *str)