Greenbone Security Assistant  8.0.0
gsad_cmd.c
Go to the documentation of this file.
1 /* Copyright (C) 2016-2018 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 
25 #include "gsad_cmd.h"
26 
27 #include <microhttpd.h> /* for MHD_HTTP_OK */
28 #include <string.h> /* for memset */
29 
34 {
35  gboolean allow_caching;
41 };
42 
48 static void
50 {
51  data->allow_caching = FALSE;
52  data->http_status_code = MHD_HTTP_OK;
54  data->content_type_string = NULL;
55  data->content_disposition = NULL;
56  data->content_length = 0;
57 }
58 
66 {
67  cmd_response_data_t *data = g_malloc0 (sizeof (cmd_response_data_t));
69  return data;
70 }
71 
80 void
82 {
83  if (!data)
84  {
85  return;
86  }
87 
88  if (data->content_disposition)
89  {
90  g_free (data->content_disposition);
91  }
92 
93  if (data->content_type_string)
94  {
95  g_free (data->content_type_string);
96  }
97 
98  g_free (data);
99 }
100 
107 void
109  gboolean allow_caching)
110 {
111  data->allow_caching = (allow_caching != FALSE);
112 }
113 
121 gboolean
123 {
124  return data->allow_caching;
125 }
126 
133 void
136 {
137  data->content_type = content_type;
138 }
139 
149 {
150  return data->content_type;
151 }
152 
159 void
161  int http_status_code)
162 {
163  data->http_status_code = http_status_code;
164 }
165 
173 int
175 {
176  return data->http_status_code;
177 }
178 
185 void
187  gsize content_length)
188 {
189  data->content_length = content_length;
190 }
191 
199 gsize
201 {
202  return data->content_length;
203 }
204 
211 void
213  gchar *content_disposition)
214 {
215  data->content_disposition = content_disposition;
216 }
217 
225 const gchar *
227 {
228  return data->content_disposition;
229 }
230 
240 void
242  gchar *content_type_string)
243 {
245  data->content_type_string = content_type_string;
246 }
247 
254 const gchar *
256 {
257  return data->content_type_string;
258 }
int cmd_response_data_get_status_code(cmd_response_data_t *data)
Get http status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:174
gchar * content_type_string
Content type. Default is text/html
Definition: gsad_cmd.c:38
const gchar * cmd_response_data_get_content_disposition(cmd_response_data_t *data)
Get content disposition of cmd_response_data_t struct.
Definition: gsad_cmd.c:226
gchar * content_disposition
Content length of the response
Definition: gsad_cmd.c:40
content_type_t content_type
HTTP status code.
Definition: gsad_cmd.c:37
Headers for Response Data struct.
void cmd_response_data_set_content_type_string(cmd_response_data_t *data, gchar *content_type_string)
Set a content type as string.
Definition: gsad_cmd.c:241
gsize content_length
Content type as string. Default is NULL.
Definition: gsad_cmd.c:39
void cmd_response_data_set_allow_caching(cmd_response_data_t *data, gboolean allow_caching)
Set allow_caching flag of cmd_response_data_t struct.
Definition: gsad_cmd.c:108
const gchar * cmd_response_data_get_content_type_string(cmd_response_data_t *data)
Get a content type string if set.
Definition: gsad_cmd.c:255
cmd_response_data_t * cmd_response_data_new()
Allocates memory for a cmd_response_data_t sturct and initializes it.
Definition: gsad_cmd.c:65
Special marker for using content type string.
gboolean cmd_response_data_is_allow_caching(cmd_response_data_t *data)
Get allow_caching flag of cmd_response_data_t struct.
Definition: gsad_cmd.c:122
void cmd_response_data_set_content_disposition(cmd_response_data_t *data, gchar *content_disposition)
Set content disposition of cmd_response_data_t struct.
Definition: gsad_cmd.c:212
Response information for commands.
Definition: gsad_cmd.c:33
void cmd_response_data_set_content_type(cmd_response_data_t *data, content_type_t content_type)
Set content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:134
gboolean allow_caching
Definition: gsad_cmd.c:35
content_type_t cmd_response_data_get_content_type(cmd_response_data_t *data)
Get content type of cmd_response_data_t struct.
Definition: gsad_cmd.c:148
enum content_type content_type_t
void cmd_response_data_free(cmd_response_data_t *data)
Frees the memory of a cmd_response_data_t struct.
Definition: gsad_cmd.c:81
void cmd_response_data_set_content_length(cmd_response_data_t *data, gsize content_length)
Set response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:186
int http_status_code
Whether the response may be cached.
Definition: gsad_cmd.c:36
void cmd_response_data_set_status_code(cmd_response_data_t *data, int http_status_code)
Set status code of cmd_response_data_t struct.
Definition: gsad_cmd.c:160
static void cmd_response_data_init(cmd_response_data_t *data)
Initializes a cmd_response_data_t struct.
Definition: gsad_cmd.c:49
content_type
Content types.
gsize cmd_response_data_get_content_length(cmd_response_data_t *data)
Get response content length of cmd_response_data_t struct.
Definition: gsad_cmd.c:200