Greenbone Security Assistant  9.0.1
gsad_gmp_arguments.c
Go to the documentation of this file.
1 /* Copyright (C) 2019 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #include "gsad_gmp_arguments.h"
21 
24 {
25  return g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
26 }
27 
28 void
30 {
31  g_hash_table_ref (arguments);
32 }
33 
34 void
36 {
37  if (arguments != NULL)
38  {
39  g_hash_table_unref (arguments);
40  }
41 }
42 
43 void
44 gmp_arguments_add (gmp_arguments_t *arguments, const gchar *key,
45  const gchar *value)
46 {
47  g_hash_table_insert (arguments, g_strdup (key), g_strdup (value));
48 }
49 
50 gchar *
52 {
53  if (arguments == NULL)
54  {
55  return g_strdup ("");
56  }
57 
58  GHashTableIter iter;
59  const gchar *key = NULL, *value = NULL;
60  gchar *escaped_value;
61  GString *argumentslist;
62 
63  argumentslist = g_string_new (NULL);
64 
65  g_hash_table_iter_init (&iter, arguments);
66  while (g_hash_table_iter_next (&iter, (gpointer *) &key, (gpointer *) &value))
67  {
68  escaped_value = g_markup_escape_text (value, -1);
69 
70  g_string_append_printf (argumentslist, "%s=\"%s\" ", key, escaped_value);
71 
72  g_free (escaped_value);
73  }
74 
75  gchar *retval = argumentslist->str;
76 
77  g_string_free (argumentslist, FALSE);
78 
79  return retval;
80 }
81 
82 gboolean
83 gmp_arguments_has (gmp_arguments_t *arguments, const gchar *key)
84 {
85  return g_hash_table_contains (arguments, (gconstpointer *) key);
86 }
gmp_arguments_ref
void gmp_arguments_ref(gmp_arguments_t *arguments)
Definition: gsad_gmp_arguments.c:29
gsad_gmp_arguments.h
gmp_arguments_add
void gmp_arguments_add(gmp_arguments_t *arguments, const gchar *key, const gchar *value)
Definition: gsad_gmp_arguments.c:44
gmp_arguments_string
gchar * gmp_arguments_string(gmp_arguments_t *arguments)
Definition: gsad_gmp_arguments.c:51
gmp_arguments_has
gboolean gmp_arguments_has(gmp_arguments_t *arguments, const gchar *key)
Definition: gsad_gmp_arguments.c:83
gmp_arguments_t
GHashTable gmp_arguments_t
Definition: gsad_gmp_arguments.h:24
gmp_arguments_free
void gmp_arguments_free(gmp_arguments_t *arguments)
Definition: gsad_gmp_arguments.c:35
gmp_arguments_new
gmp_arguments_t * gmp_arguments_new()
Definition: gsad_gmp_arguments.c:23