1 module soup.WebsocketExtension;
2 
3 private import glib.Bytes;
4 private import glib.ErrorG;
5 private import glib.GException;
6 private import glib.HashTable;
7 private import glib.Str;
8 private import gobject.ObjectG;
9 private import soup.c.functions;
10 public  import soup.c.types;
11 
12 
13 /**
14  * SoupWebsocketExtension is the base class for WebSocket extension objects.
15  *
16  * Since: 2.68
17  */
18 public class WebsocketExtension : ObjectG
19 {
20 	/** the main Gtk struct */
21 	protected SoupWebsocketExtension* soupWebsocketExtension;
22 
23 	/** Get the main Gtk struct */
24 	public SoupWebsocketExtension* getWebsocketExtensionStruct(bool transferOwnership = false)
25 	{
26 		if (transferOwnership)
27 			ownedRef = false;
28 		return soupWebsocketExtension;
29 	}
30 
31 	/** the main Gtk struct as a void* */
32 	protected override void* getStruct()
33 	{
34 		return cast(void*)soupWebsocketExtension;
35 	}
36 
37 	/**
38 	 * Sets our main struct and passes it to the parent class.
39 	 */
40 	public this (SoupWebsocketExtension* soupWebsocketExtension, bool ownedRef = false)
41 	{
42 		this.soupWebsocketExtension = soupWebsocketExtension;
43 		super(cast(GObject*)soupWebsocketExtension, ownedRef);
44 	}
45 
46 
47 	/** */
48 	public static GType getType()
49 	{
50 		return soup_websocket_extension_get_type();
51 	}
52 
53 	/**
54 	 * Configures @extension with the given @params
55 	 *
56 	 * Params:
57 	 *     connectionType = either %SOUP_WEBSOCKET_CONNECTION_CLIENT or %SOUP_WEBSOCKET_CONNECTION_SERVER
58 	 *     params = the parameters, or %NULL
59 	 *
60 	 * Returns: %TRUE if extension could be configured with the given parameters, or %FALSE otherwise
61 	 *
62 	 * Throws: GException on failure.
63 	 */
64 	public bool configure(SoupWebsocketConnectionType connectionType, HashTable params)
65 	{
66 		GError* err = null;
67 
68 		auto __p = soup_websocket_extension_configure(soupWebsocketExtension, connectionType, (params is null) ? null : params.getHashTableStruct(), &err) != 0;
69 
70 		if (err !is null)
71 		{
72 			throw new GException( new ErrorG(err) );
73 		}
74 
75 		return __p;
76 	}
77 
78 	/**
79 	 * Get the parameters strings to be included in the request header. If the extension
80 	 * doesn't include any parameter in the request, this function returns %NULL.
81 	 *
82 	 * Returns: a new allocated string with the parameters
83 	 *
84 	 * Since: 2.68
85 	 */
86 	public string getRequestParams()
87 	{
88 		auto retStr = soup_websocket_extension_get_request_params(soupWebsocketExtension);
89 
90 		scope(exit) Str.freeString(retStr);
91 		return Str.toString(retStr);
92 	}
93 
94 	/**
95 	 * Get the parameters strings to be included in the response header. If the extension
96 	 * doesn't include any parameter in the response, this function returns %NULL.
97 	 *
98 	 * Returns: a new allocated string with the parameters
99 	 *
100 	 * Since: 2.68
101 	 */
102 	public string getResponseParams()
103 	{
104 		auto retStr = soup_websocket_extension_get_response_params(soupWebsocketExtension);
105 
106 		scope(exit) Str.freeString(retStr);
107 		return Str.toString(retStr);
108 	}
109 
110 	/**
111 	 * Process a message after it's received. If the payload isn't changed the given
112 	 * @payload is just returned, otherwise g_bytes_unref() is called on the given
113 	 * @payload and a new #GBytes is returned with the new data.
114 	 *
115 	 * Extensions using reserved bits of the header will reset them in @header.
116 	 *
117 	 * Params:
118 	 *     header = the message header
119 	 *     payload = the payload data
120 	 *
121 	 * Returns: the message payload data, or %NULL in case of error
122 	 *
123 	 * Since: 2.68
124 	 *
125 	 * Throws: GException on failure.
126 	 */
127 	public Bytes processIncomingMessage(ref ubyte header, Bytes payload)
128 	{
129 		GError* err = null;
130 
131 		auto __p = soup_websocket_extension_process_incoming_message(soupWebsocketExtension, &header, (payload is null) ? null : payload.getBytesStruct(true), &err);
132 
133 		if (err !is null)
134 		{
135 			throw new GException( new ErrorG(err) );
136 		}
137 
138 		if(__p is null)
139 		{
140 			return null;
141 		}
142 
143 		return new Bytes(cast(GBytes*) __p, true);
144 	}
145 
146 	/**
147 	 * Process a message before it's sent. If the payload isn't changed the given
148 	 * @payload is just returned, otherwise g_bytes_unref() is called on the given
149 	 * @payload and a new #GBytes is returned with the new data.
150 	 *
151 	 * Extensions using reserved bits of the header will change them in @header.
152 	 *
153 	 * Params:
154 	 *     header = the message header
155 	 *     payload = the payload data
156 	 *
157 	 * Returns: the message payload data, or %NULL in case of error
158 	 *
159 	 * Since: 2.68
160 	 *
161 	 * Throws: GException on failure.
162 	 */
163 	public Bytes processOutgoingMessage(ref ubyte header, Bytes payload)
164 	{
165 		GError* err = null;
166 
167 		auto __p = soup_websocket_extension_process_outgoing_message(soupWebsocketExtension, &header, (payload is null) ? null : payload.getBytesStruct(true), &err);
168 
169 		if (err !is null)
170 		{
171 			throw new GException( new ErrorG(err) );
172 		}
173 
174 		if(__p is null)
175 		{
176 			return null;
177 		}
178 
179 		return new Bytes(cast(GBytes*) __p, true);
180 	}
181 }