| 1 |
/* |
| 2 |
* Copyright (C) 2014 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef __COCKPIT_WEB_RESPONSE_H__ |
| 7 |
#define __COCKPIT_WEB_RESPONSE_H__ |
| 8 |
|
| 9 |
#include <gio/gio.h> |
| 10 |
|
| 11 |
#include "cockpitwebfilter.h" |
| 12 |
|
| 13 |
G_BEGIN_DECLS |
| 14 |
|
| 15 |
#define COCKPIT_RESOURCE_PACKAGE_VALID "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-" |
| 16 |
|
| 17 |
#define COCKPIT_TYPE_WEB_RESPONSE (cockpit_web_response_get_type ()) |
| 18 |
G_DECLARE_FINAL_TYPE(CockpitWebResponse, cockpit_web_response, COCKPIT, WEB_RESPONSE, GObject) |
| 19 |
|
| 20 |
typedef enum { |
| 21 |
COCKPIT_WEB_RESPONSE_READY = 1, |
| 22 |
COCKPIT_WEB_RESPONSE_QUEUING, |
| 23 |
COCKPIT_WEB_RESPONSE_COMPLETE, |
| 24 |
COCKPIT_WEB_RESPONSE_SENT, |
| 25 |
} CockpitWebResponding; |
| 26 |
|
| 27 |
typedef enum { |
| 28 |
COCKPIT_WEB_RESPONSE_CACHE_UNSET, |
| 29 |
COCKPIT_WEB_RESPONSE_NO_CACHE, |
| 30 |
COCKPIT_WEB_RESPONSE_CACHE, |
| 31 |
} CockpitCacheType; |
| 32 |
|
| 33 |
#define COCKPIT_CHECKSUM_HEADER "X-Cockpit-Pkg-Checksum" |
| 34 |
|
| 35 |
typedef struct _CockpitWebResponse CockpitWebResponse; |
| 36 |
|
| 37 |
extern const gchar * cockpit_web_exception_escape_root; |
| 38 |
|
| 39 |
CockpitWebResponse * cockpit_web_response_new (GIOStream *io, |
| 40 |
const gchar *original_path, |
| 41 |
const gchar *path, |
| 42 |
GHashTable *in_headers, |
| 43 |
const gchar *method, |
| 44 |
const gchar *protocol); |
| 45 |
|
| 46 |
|
| 47 |
const gchar * cockpit_web_response_get_path (CockpitWebResponse *self); |
| 48 |
|
| 49 |
GIOStream * cockpit_web_response_get_stream (CockpitWebResponse *self); |
| 50 |
|
| 51 |
CockpitWebResponding cockpit_web_response_get_state (CockpitWebResponse *self); |
| 52 |
|
| 53 |
gboolean cockpit_web_response_skip_path (CockpitWebResponse *self); |
| 54 |
|
| 55 |
gchar * cockpit_web_response_pop_path (CockpitWebResponse *self); |
| 56 |
|
| 57 |
void cockpit_web_response_add_filter (CockpitWebResponse *self, |
| 58 |
CockpitWebFilter *filter); |
| 59 |
|
| 60 |
void cockpit_web_response_headers (CockpitWebResponse *self, |
| 61 |
guint status, |
| 62 |
const gchar *reason, |
| 63 |
gssize length, |
| 64 |
...) G_GNUC_NULL_TERMINATED; |
| 65 |
|
| 66 |
void cockpit_web_response_headers_full (CockpitWebResponse *self, |
| 67 |
guint status, |
| 68 |
const gchar *reason, |
| 69 |
gssize length, |
| 70 |
GHashTable *headers); |
| 71 |
|
| 72 |
gboolean cockpit_web_response_queue (CockpitWebResponse *self, |
| 73 |
GBytes *block); |
| 74 |
|
| 75 |
void cockpit_web_response_complete (CockpitWebResponse *self); |
| 76 |
|
| 77 |
void cockpit_web_response_abort (CockpitWebResponse *self); |
| 78 |
|
| 79 |
void cockpit_web_response_content (CockpitWebResponse *self, |
| 80 |
GHashTable *headers, |
| 81 |
GBytes *block, |
| 82 |
...) G_GNUC_NULL_TERMINATED; |
| 83 |
|
| 84 |
void cockpit_web_response_error_with_body (CockpitWebResponse *self, |
| 85 |
guint code, |
| 86 |
const gchar *reason, |
| 87 |
GHashTable *headers, |
| 88 |
GBytes *body); |
| 89 |
void cockpit_web_response_error (CockpitWebResponse *self, |
| 90 |
guint status, |
| 91 |
GHashTable *headers, |
| 92 |
const char *format, |
| 93 |
...) G_GNUC_PRINTF (4, 5); |
| 94 |
|
| 95 |
void cockpit_web_response_gerror (CockpitWebResponse *self, |
| 96 |
GHashTable *headers, |
| 97 |
GBytes *body, |
| 98 |
GError *error); |
| 99 |
|
| 100 |
gchar ** cockpit_web_response_resolve_roots (const gchar **roots); |
| 101 |
|
| 102 |
void cockpit_web_response_file (CockpitWebResponse *response, |
| 103 |
const gchar *escaped, |
| 104 |
const gchar **roots); |
| 105 |
|
| 106 |
void cockpit_web_response_file_or_gz (CockpitWebResponse *response, |
| 107 |
const gchar *escaped, |
| 108 |
const gchar **roots); |
| 109 |
|
| 110 |
GBytes * cockpit_web_response_negotiation (const gchar *path, |
| 111 |
GHashTable *existing, |
| 112 |
const gchar *language, |
| 113 |
gboolean *out_is_language_specific, |
| 114 |
gboolean *out_is_compressed, |
| 115 |
GError **error); |
| 116 |
|
| 117 |
const gchar * cockpit_web_response_content_type (const gchar *path); |
| 118 |
|
| 119 |
gboolean cockpit_web_should_suppress_output_error (const gchar *logname, |
| 120 |
GError *error); |
| 121 |
|
| 122 |
gboolean cockpit_web_response_is_header_value (const gchar *string); |
| 123 |
|
| 124 |
void cockpit_web_response_set_cache_type (CockpitWebResponse *self, |
| 125 |
CockpitCacheType cache_type); |
| 126 |
|
| 127 |
const gchar * cockpit_web_response_get_url_root (CockpitWebResponse *response); |
| 128 |
|
| 129 |
const gchar * cockpit_web_response_get_origin (CockpitWebResponse *response); |
| 130 |
|
| 131 |
const gchar * cockpit_web_response_get_protocol (CockpitWebResponse *response); |
| 132 |
|
| 133 |
void cockpit_web_response_template (CockpitWebResponse *response, |
| 134 |
const gchar *escaped, |
| 135 |
const gchar **roots, |
| 136 |
GHashTable *values); |
| 137 |
|
| 138 |
gchar * cockpit_web_response_security_policy (const gchar *content_security_policy, |
| 139 |
const gchar *self_origin); |
| 140 |
|
| 141 |
G_END_DECLS |
| 142 |
|
| 143 |
#endif /* __COCKPIT_RESPONSE_H__ */ |