Web Services APIs

WebSocket Support
<refentry> <refmeta> <refentrytitle>SoupForm</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>LIBSOUP-3.0 Library</refmiscinfo> </refmeta>

<refentrytitle>SoupForm</refentrytitle>

<refname>SoupForm</refname> <refpurpose>HTML form handling</refpurpose>

<refsect1> <title>Functions</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>GHashTable</returnvalue> * </entry><entry>soup_form_decode <phrase>()</phrase></entry></row> <row><entry><returnvalue>GHashTable</returnvalue> * </entry><entry>soup_form_decode_multipart <phrase>()</phrase></entry></row> <row><entry><returnvalue>char</returnvalue> * </entry><entry>soup_form_encode <phrase>()</phrase></entry></row> <row><entry><returnvalue>char</returnvalue> * </entry><entry>soup_form_encode_datalist <phrase>()</phrase></entry></row> <row><entry><returnvalue>char</returnvalue> * </entry><entry>soup_form_encode_hash <phrase>()</phrase></entry></row> <row><entry><returnvalue>char</returnvalue> * </entry><entry>soup_form_encode_valist <phrase>()</phrase></entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Types and Values</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry>#define</entry><entry>SOUP_FORM_MIME_TYPE_MULTIPART</entry></row> <row><entry>#define</entry><entry>SOUP_FORM_MIME_TYPE_URLENCODED</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1><title>Includes</title><synopsis>#include <libsoup/soup.h> </synopsis></refsect1> <refsect1> <title>Description</title> <para>libsoup contains several help methods for processing HTML forms as defined by the <ulink>the HTML 4.01 specification</ulink>.</para> </refsect1> <refsect1> <title>Functions</title> <refsect2> <title>soup_form_decode ()</title> <programlisting><returnvalue>GHashTable</returnvalue> * soup_form_decode (<parameter>const <type>char</type> *encoded_form</parameter>);</programlisting> <para>Decodes <parameter>form</parameter> , which is an urlencoded dataset as defined in the HTML 4.01 spec.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>encoded_form</para></entry> <entry><para>data of type "application/x-www-form-urlencoded"</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a hash table containing the name/value pairs from <parameter>encoded_form</parameter> , which you can free with <function>g_hash_table_destroy()</function>. </para> <para><emphasis>[element-type utf8 utf8][transfer container]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_form_decode_multipart ()</title> <programlisting><returnvalue>GHashTable</returnvalue> * soup_form_decode_multipart (<parameter><type>SoupMultipart</type> *multipart</parameter>, <parameter>const <type>char</type> *file_control_name</parameter>, <parameter><type>char</type> **filename</parameter>, <parameter><type>char</type> **content_type</parameter>, <parameter><type>GBytes</type> **file</parameter>);</programlisting> <para>Decodes the "multipart/form-data" request in <parameter>multipart</parameter> ; this is a convenience method for the case when you have a single file upload control in a form. (Or when you don't have any file upload controls, but are still using "multipart/form-data" anyway.) Pass the name of the file upload control in <parameter>file_control_name</parameter> , and <function>soup_form_decode_multipart()</function> will extract the uploaded file data into <parameter>filename</parameter> , <parameter>content_type</parameter> , and <parameter>file</parameter> . All of the other form control data will be returned (as strings, as with <function>soup_form_decode()</function>) in the returned <type>GHashTable</type>.</para> <para>You may pass <literal>NULL</literal> for <parameter>filename</parameter> , <parameter>content_type</parameter> and/or <parameter>file</parameter> if you do not care about those fields. <function>soup_form_decode_multipart()</function> may also return <literal>NULL</literal> in those fields if the client did not provide that information. You must free the returned filename and content-type with <function>g_free()</function>, and the returned file data with <function>g_bytes_unref()</function>.</para> <para>If you have a form with more than one file upload control, you will need to decode it manually, using <function>soup_multipart_new_from_message()</function> and <function>soup_multipart_get_part()</function>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>multipart</para></entry> <entry><para>a <type>SoupMultipart</type></para></entry> <entry></entry></row> <row><entry><para>file_control_name</para></entry> <entry><para>the name of the HTML file upload control, or <literal>NULL</literal>. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>filename</para></entry> <entry><para>return location for the name of the uploaded file, or <literal>NULL</literal>. </para></entry> <entry><emphasis>[out][optional]</emphasis></entry></row> <row><entry><para>content_type</para></entry> <entry><para>return location for the MIME type of the uploaded file, or <literal>NULL</literal>. </para></entry> <entry><emphasis>[out][optional]</emphasis></entry></row> <row><entry><para>file</para></entry> <entry><para>return location for the uploaded file data, or <literal>NULL</literal>. </para></entry> <entry><emphasis>[out][optional]</emphasis></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a hash table containing the name/value pairs (other than <parameter>file_control_name</parameter> ) from <parameter>msg</parameter> , which you can free with <function>g_hash_table_destroy()</function>. On error, it will return <literal>NULL</literal>. </para> <para><emphasis>[nullable][element-type utf8 utf8][transfer container]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_form_encode ()</title> <programlisting><returnvalue>char</returnvalue> * soup_form_encode (<parameter>const <type>char</type> *first_field</parameter>, <parameter>...</parameter>);</programlisting> <para>Encodes the given field names and values into a value of type "application/x-www-form-urlencoded", as defined in the HTML 4.01 spec.</para> <para>This method requires you to know the names of the form fields (or at the very least, the total number of fields) at compile time; for working with dynamic forms, use <function>soup_form_encode_hash()</function> or <function>soup_form_encode_datalist()</function>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>first_field</para></entry> <entry><para>name of the first form field</para></entry> <entry></entry></row> <row><entry><para>...</para></entry> <entry><para>value of <parameter>first_field</parameter> , followed by additional field names and values, terminated by <literal>NULL</literal>.</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the encoded form</para> <para>See also: <function>soup_message_new_from_encoded_form()</function></para> </refsect3></refsect2>
<refsect2> <title>soup_form_encode_datalist ()</title> <programlisting><returnvalue>char</returnvalue> * soup_form_encode_datalist (<parameter><type>GData</type> **form_data_set</parameter>);</programlisting> <para>Encodes <parameter>form_data_set</parameter> into a value of type "application/x-www-form-urlencoded", as defined in the HTML 4.01 spec. Unlike <function>soup_form_encode_hash()</function>, this preserves the ordering of the form elements, which may be required in some situations.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>form_data_set</para></entry> <entry><para>a datalist containing name/value pairs</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the encoded form</para> <para>See also: <function>soup_message_new_from_encoded_form()</function></para> </refsect3></refsect2>
<refsect2> <title>soup_form_encode_hash ()</title> <programlisting><returnvalue>char</returnvalue> * soup_form_encode_hash (<parameter><type>GHashTable</type> *form_data_set</parameter>);</programlisting> <para>Encodes <parameter>form_data_set</parameter> into a value of type "application/x-www-form-urlencoded", as defined in the HTML 4.01 spec.</para> <para>Note that the HTML spec states that "The control names/values are listed in the order they appear in the document." Since this method takes a hash table, it cannot enforce that; if you care about the ordering of the form fields, use <function>soup_form_encode_datalist()</function>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>form_data_set</para></entry> <entry><para>a hash table containing name/value pairs (as strings). </para></entry> <entry><emphasis>[element-type utf8 utf8]</emphasis></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the encoded form</para> <para>See also: <function>soup_message_new_from_encoded_form()</function></para> </refsect3></refsect2>
<refsect2> <title>soup_form_encode_valist ()</title> <programlisting><returnvalue>char</returnvalue> * soup_form_encode_valist (<parameter>const <type>char</type> *first_field</parameter>, <parameter><type>va_list</type> args</parameter>);</programlisting> <para>See <function>soup_form_encode()</function>. This is mostly an internal method, used by various other methods such as <function>soup_form_encode()</function>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>first_field</para></entry> <entry><para>name of the first form field</para></entry> <entry></entry></row> <row><entry><para>args</para></entry> <entry><para>pointer to additional values, as in <function>soup_form_encode()</function></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the encoded form</para> <para>See also: <function>soup_message_new_from_encoded_form()</function></para> </refsect3></refsect2> </refsect1>
<refsect1> <title>Types and Values</title> <refsect2> <title>SOUP_FORM_MIME_TYPE_MULTIPART</title> <programlisting>#define SOUP_FORM_MIME_TYPE_MULTIPART "multipart/form-data" </programlisting> <para>A macro containing the value <literal>"multipart/form-data"</literal>; the MIME type used for posting form data that contains files to be uploaded.</para> </refsect2>
<refsect2> <title>SOUP_FORM_MIME_TYPE_URLENCODED</title> <programlisting>#define SOUP_FORM_MIME_TYPE_URLENCODED "application/x-www-form-urlencoded" </programlisting> <para>A macro containing the value <literal>"application/x-www-form-urlencoded"</literal>; the default MIME type for POSTing HTML form data.</para> </refsect2> </refsect1>
<refsect1> <title>See Also</title> <para><type>SoupMultipart</type></para> </refsect1> </refentry>

WebSocket Support

<refentry> <refmeta> <refentrytitle>SoupWebsocket</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>LIBSOUP-3.0 Library</refmiscinfo> </refmeta>

<refentrytitle>SoupWebsocket</refentrytitle>

<refname>SoupWebsocket</refname> <refpurpose>The WebSocket Protocol</refpurpose>

<refsect1> <title>Functions</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_websocket_client_prepare_handshake <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_websocket_client_verify_handshake <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_websocket_server_check_handshake <phrase>()</phrase></entry></row> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_websocket_server_process_handshake <phrase>()</phrase></entry></row> <row><entry><returnvalue>SoupWebsocketConnection</returnvalue> * </entry><entry>soup_websocket_connection_new <phrase>()</phrase></entry></row> <row><entry><returnvalue>GIOStream</returnvalue> * </entry><entry>soup_websocket_connection_get_io_stream <phrase>()</phrase></entry></row> <row><entry><returnvalue>SoupWebsocketConnectionType</returnvalue> </entry><entry>soup_websocket_connection_get_connection_type <phrase>()</phrase></entry></row> <row><entry><returnvalue>GUri</returnvalue> * </entry><entry>soup_websocket_connection_get_uri <phrase>()</phrase></entry></row> <row><entry>const <returnvalue>char</returnvalue> * </entry><entry>soup_websocket_connection_get_origin <phrase>()</phrase></entry></row> <row><entry>const <returnvalue>char</returnvalue> * </entry><entry>soup_websocket_connection_get_protocol <phrase>()</phrase></entry></row> <row><entry><returnvalue>GList</returnvalue> * </entry><entry>soup_websocket_connection_get_extensions <phrase>()</phrase></entry></row> <row><entry><returnvalue>guint64</returnvalue> </entry><entry>soup_websocket_connection_get_max_incoming_payload_size <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_websocket_connection_set_max_incoming_payload_size <phrase>()</phrase></entry></row> <row><entry><returnvalue>guint</returnvalue> </entry><entry>soup_websocket_connection_get_keepalive_interval <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_websocket_connection_set_keepalive_interval <phrase>()</phrase></entry></row> <row><entry><returnvalue>SoupWebsocketState</returnvalue> </entry><entry>soup_websocket_connection_get_state <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_websocket_connection_send_text <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_websocket_connection_send_binary <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_websocket_connection_send_message <phrase>()</phrase></entry></row> <row><entry><returnvalue>void</returnvalue> </entry><entry>soup_websocket_connection_close <phrase>()</phrase></entry></row> <row><entry><returnvalue>gushort</returnvalue> </entry><entry>soup_websocket_connection_get_close_code <phrase>()</phrase></entry></row> <row><entry>const <returnvalue>char</returnvalue> * </entry><entry>soup_websocket_connection_get_close_data <phrase>()</phrase></entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Properties</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><type>SoupWebsocketConnectionType</type></entry><entry>connection-type</entry><entry>Read / Write / Construct Only</entry></row> <row><entry><type>gpointer</type></entry><entry>extensions</entry><entry>Read / Write / Construct Only</entry></row> <row><entry><type>GIOStream</type> *</entry><entry>io-stream</entry><entry>Read / Write / Construct Only</entry></row> <row><entry><type>guint</type></entry><entry>keepalive-interval</entry><entry>Read / Write / Construct</entry></row> <row><entry><type>guint64</type></entry><entry>max-incoming-payload-size</entry><entry>Read / Write / Construct</entry></row> <row><entry><type>char</type> *</entry><entry>origin</entry><entry>Read / Write / Construct Only</entry></row> <row><entry><type>char</type> *</entry><entry>protocol</entry><entry>Read / Write / Construct Only</entry></row> <row><entry><type>SoupWebsocketState</type></entry><entry>state</entry><entry>Read</entry></row> <row><entry><type>GUri</type> *</entry><entry>uri</entry><entry>Read / Write / Construct Only</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Signals</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>void</returnvalue></entry><entry>closed</entry><entry>Run First</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>closing</entry><entry>Run Last</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>error</entry><entry>Run First</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>message</entry><entry>Run First</entry></row> <row><entry><returnvalue>void</returnvalue></entry><entry>pong</entry><entry>Run First</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <anchor></anchor><refsect1> <title>Types and Values</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry></entry><entry>SoupWebsocketConnection</entry></row> <row><entry>enum</entry><entry>SoupWebsocketConnectionType</entry></row> <row><entry>enum</entry><entry>SoupWebsocketState</entry></row> <row><entry>enum</entry><entry>SoupWebsocketDataType</entry></row> <row><entry>enum</entry><entry>SoupWebsocketCloseCode</entry></row> <row><entry>enum</entry><entry>SoupWebsocketError</entry></row> <row><entry>#define</entry><entry>SOUP_WEBSOCKET_ERROR</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Object Hierarchy</title> <screen> GObject <phrase>╰──</phrase> SoupWebsocketConnection </screen> </refsect1> <refsect1><title>Includes</title><synopsis>#include <libsoup/soup.h> </synopsis></refsect1> <refsect1> <title>Description</title> <para><type>SoupWebsocketConnection</type> provides support for the <ulink>WebSocket</ulink> protocol.</para> <para>To connect to a WebSocket server, create a <type>SoupSession</type> and call <function>soup_session_websocket_connect_async()</function>. To accept WebSocket connections, create a <type>SoupServer</type> and add a handler to it with <function>soup_server_add_websocket_handler()</function>.</para> <para>(Lower-level support is available via <function>soup_websocket_client_prepare_handshake()</function> and <function>soup_websocket_client_verify_handshake()</function>, for handling the client side of the WebSocket handshake, and <function>soup_websocket_server_process_handshake()</function> for handling the server side.)</para> <para><type>SoupWebsocketConnection</type> handles the details of WebSocket communication. You can use <function>soup_websocket_connection_send_text()</function> and <function>soup_websocket_connection_send_binary()</function> to send data, and the <type>“message”</type> signal to receive data. (<type>SoupWebsocketConnection</type> currently only supports asynchronous I/O.)</para> </refsect1> <refsect1> <title>Functions</title> <refsect2> <title>soup_websocket_client_prepare_handshake ()</title> <programlisting><returnvalue>void</returnvalue> soup_websocket_client_prepare_handshake (<parameter><type>SoupMessage</type> *msg</parameter>, <parameter>const <type>char</type> *origin</parameter>, <parameter><type>char</type> **protocols</parameter>, <parameter><type>GPtrArray</type> *supported_extensions</parameter>);</programlisting> <para>Adds the necessary headers to <parameter>msg</parameter> to request a WebSocket handshake including supported WebSocket extensions. The message body and non-WebSocket-related headers are not modified.</para> <para>This is a low-level function; if you use <function>soup_session_websocket_connect_async()</function> to create a WebSocket connection, it will call this for you.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para>a <type>SoupMessage</type></para></entry> <entry></entry></row> <row><entry><para>origin</para></entry> <entry><para>the "Origin" header to set. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>protocols</para></entry> <entry><para>list of protocols to offer. </para></entry> <entry><emphasis>[nullable][array zero-terminated=1]</emphasis></entry></row> <row><entry><para>supported_extensions</para></entry> <entry><para>list of supported extension types. </para></entry> <entry><emphasis>[nullable][element-type GObject.TypeClass]</emphasis></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_websocket_client_verify_handshake ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_websocket_client_verify_handshake (<parameter><type>SoupMessage</type> *msg</parameter>, <parameter><type>GPtrArray</type> *supported_extensions</parameter>, <parameter><type>GList</type> **accepted_extensions</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>Looks at the response status code and headers in <parameter>msg</parameter> and determines if they contain a valid WebSocket handshake response (given the handshake request in <parameter>msg</parameter> 's request headers).</para> <para>If <parameter>supported_extensions</parameter> is non-<literal>NULL</literal>, extensions included in the response "Sec-WebSocket-Extensions" are verified too. Accepted extensions are returned in <parameter>accepted_extensions</parameter> parameter if non-<literal>NULL</literal>.</para> <para>This is a low-level function; if you use <function>soup_session_websocket_connect_async()</function> to create a WebSocket connection, it will call this for you.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para><type>SoupMessage</type> containing both client and server sides of a WebSocket handshake</para></entry> <entry></entry></row> <row><entry><para>supported_extensions</para></entry> <entry><para>list of supported extension types. </para></entry> <entry><emphasis>[nullable][element-type GObject.TypeClass]</emphasis></entry></row> <row><entry><para>accepted_extensions</para></entry> <entry><para>a <type>GList</type> of <type>SoupWebsocketExtension</type> objects. </para></entry> <entry><emphasis>[out][optional][element-type SoupWebsocketExtension]</emphasis></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> if <parameter>msg</parameter> contains a completed valid WebSocket handshake, <literal>FALSE</literal> and an error if not.</para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_server_check_handshake ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_websocket_server_check_handshake (<parameter><type>SoupServerMessage</type> *msg</parameter>, <parameter>const <type>char</type> *origin</parameter>, <parameter><type>char</type> **protocols</parameter>, <parameter><type>GPtrArray</type> *supported_extensions</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>Examines the method and request headers in <parameter>msg</parameter> and determines whether <parameter>msg</parameter> contains a valid handshake request.</para> <para>If <parameter>origin</parameter> is non-<literal>NULL</literal>, then only requests containing a matching "Origin" header will be accepted. If <parameter>protocols</parameter> is non-<literal>NULL</literal>, then only requests containing a compatible "Sec-WebSocket-Protocols" header will be accepted. If <parameter>supported_extensions</parameter> is non-<literal>NULL</literal>, then only requests containing valid supported extensions in "Sec-WebSocket-Extensions" header will be accepted.</para> <para>Normally <function>soup_websocket_server_process_handshake()</function> will take care of this for you, and if you use <function>soup_server_add_websocket_handler()</function> to handle accepting WebSocket connections, it will call that for you. However, this function may be useful if you need to perform more complicated validation; eg, accepting multiple different Origins, or handling different protocols depending on the path.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para><type>SoupServerMessage</type> containing the client side of a WebSocket handshake</para></entry> <entry></entry></row> <row><entry><para>origin</para></entry> <entry><para>expected Origin header. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>protocols</para></entry> <entry><para>allowed WebSocket protocols. </para></entry> <entry><emphasis>[nullable][array zero-terminated=1]</emphasis></entry></row> <row><entry><para>supported_extensions</para></entry> <entry><para>list of supported extension types. </para></entry> <entry><emphasis>[nullable][element-type GObject.TypeClass]</emphasis></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> if <parameter>msg</parameter> contained a valid WebSocket handshake, <literal>FALSE</literal> and an error if not.</para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_server_process_handshake ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_websocket_server_process_handshake (<parameter><type>SoupServerMessage</type> *msg</parameter>, <parameter>const <type>char</type> *expected_origin</parameter>, <parameter><type>char</type> **protocols</parameter>, <parameter><type>GPtrArray</type> *supported_extensions</parameter>, <parameter><type>GList</type> **accepted_extensions</parameter>);</programlisting> <para>Examines the method and request headers in <parameter>msg</parameter> and (assuming <parameter>msg</parameter> contains a valid handshake request), fills in the handshake response.</para> <para>If <parameter>expected_origin</parameter> is non-<literal>NULL</literal>, then only requests containing a matching "Origin" header will be accepted. If <parameter>protocols</parameter> is non-<literal>NULL</literal>, then only requests containing a compatible "Sec-WebSocket-Protocols" header will be accepted. If <parameter>supported_extensions</parameter> is non-<literal>NULL</literal>, then only requests containing valid supported extensions in "Sec-WebSocket-Extensions" header will be accepted. The accepted extensions will be returned in <parameter>accepted_extensions</parameter> parameter if non-<literal>NULL</literal>.</para> <para>This is a low-level function; if you use <function>soup_server_add_websocket_handler()</function> to handle accepting WebSocket connections, it will call this for you.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>msg</para></entry> <entry><para><type>SoupServerMessage</type> containing the client side of a WebSocket handshake</para></entry> <entry></entry></row> <row><entry><para>expected_origin</para></entry> <entry><para>expected Origin header. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>protocols</para></entry> <entry><para>allowed WebSocket protocols. </para></entry> <entry><emphasis>[nullable][array zero-terminated=1]</emphasis></entry></row> <row><entry><para>supported_extensions</para></entry> <entry><para>list of supported extension types. </para></entry> <entry><emphasis>[nullable][element-type GObject.TypeClass]</emphasis></entry></row> <row><entry><para>accepted_extensions</para></entry> <entry><para>a <type>GList</type> of <type>SoupWebsocketExtension</type> objects. </para></entry> <entry><emphasis>[out][optional][element-type SoupWebsocketExtension]</emphasis></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> if <parameter>msg</parameter> contained a valid WebSocket handshake request and was updated to contain a handshake response. <literal>FALSE</literal> if not.</para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_new ()</title> <programlisting><returnvalue>SoupWebsocketConnection</returnvalue> * soup_websocket_connection_new (<parameter><type>GIOStream</type> *stream</parameter>, <parameter><type>GUri</type> *uri</parameter>, <parameter><type>SoupWebsocketConnectionType</type> type</parameter>, <parameter>const <type>char</type> *origin</parameter>, <parameter>const <type>char</type> *protocol</parameter>, <parameter><type>GList</type> *extensions</parameter>);</programlisting> <para>Creates a <type>SoupWebsocketConnection</type> on <parameter>stream</parameter> with the given active <parameter>extensions</parameter> . This should be called after completing the handshake to begin using the WebSocket protocol.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>stream</para></entry> <entry><para>a <type>GIOStream</type> connected to the WebSocket server</para></entry> <entry></entry></row> <row><entry><para>uri</para></entry> <entry><para>the URI of the connection</para></entry> <entry></entry></row> <row><entry><para>type</para></entry> <entry><para>the type of connection (client/side)</para></entry> <entry></entry></row> <row><entry><para>origin</para></entry> <entry><para>the Origin of the client. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>protocol</para></entry> <entry><para>the subprotocol in use. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>extensions</para></entry> <entry><para>a <type>GList</type> of <type>SoupWebsocketExtension</type> objects. </para></entry> <entry><emphasis>[element-type SoupWebsocketExtension][transfer full]</emphasis></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> a new <type>SoupWebsocketConnection</type></para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_io_stream ()</title> <programlisting><returnvalue>GIOStream</returnvalue> * soup_websocket_connection_get_io_stream (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Get the I/O stream the WebSocket is communicating over.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the WebSocket's I/O stream. </para> <para><emphasis>[transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_connection_type ()</title> <programlisting><returnvalue>SoupWebsocketConnectionType</returnvalue> soup_websocket_connection_get_connection_type (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Get the connection type (client/server) of the connection.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the connection type</para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_uri ()</title> <programlisting><returnvalue>GUri</returnvalue> * soup_websocket_connection_get_uri (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Get the URI of the WebSocket.</para> <para>For servers this represents the address of the WebSocket, and for clients it is the address connected to.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the URI. </para> <para><emphasis>[transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_origin ()</title> <programlisting>const <returnvalue>char</returnvalue> * soup_websocket_connection_get_origin (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Get the origin of the WebSocket.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the origin, or <literal>NULL</literal>. </para> <para><emphasis>[nullable]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_protocol ()</title> <programlisting>const <returnvalue>char</returnvalue> * soup_websocket_connection_get_protocol (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Get the protocol chosen via negotiation with the peer.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the chosen protocol, or <literal>NULL</literal>. </para> <para><emphasis>[nullable]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_extensions ()</title> <programlisting><returnvalue>GList</returnvalue> * soup_websocket_connection_get_extensions (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Get the extensions chosen via negotiation with the peer.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a <type>GList</type> of <type>SoupWebsocketExtension</type> objects. </para> <para><emphasis>[element-type SoupWebsocketExtension][transfer none]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_max_incoming_payload_size ()</title> <programlisting><returnvalue>guint64</returnvalue> soup_websocket_connection_get_max_incoming_payload_size (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Gets the maximum payload size allowed for incoming packets.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the maximum payload size.</para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_set_max_incoming_payload_size ()</title> <programlisting><returnvalue>void</returnvalue> soup_websocket_connection_set_max_incoming_payload_size (<parameter><type>SoupWebsocketConnection</type> *self</parameter>, <parameter><type>guint64</type> max_incoming_payload_size</parameter>);</programlisting> <para>Sets the maximum payload size allowed for incoming packets. It does not limit the outgoing packet size.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><para>max_incoming_payload_size</para></entry> <entry><para>the maximum payload size</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_keepalive_interval ()</title> <programlisting><returnvalue>guint</returnvalue> soup_websocket_connection_get_keepalive_interval (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Gets the keepalive interval in seconds or 0 if disabled.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the keepalive interval.</para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_set_keepalive_interval ()</title> <programlisting><returnvalue>void</returnvalue> soup_websocket_connection_set_keepalive_interval (<parameter><type>SoupWebsocketConnection</type> *self</parameter>, <parameter><type>guint</type> interval</parameter>);</programlisting> <para>Sets the interval in seconds on when to send a ping message which will serve as a keepalive message. If set to 0 the keepalive message is disabled.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><para>interval</para></entry> <entry><para>the interval to send a ping message or 0 to disable it</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_state ()</title> <programlisting><returnvalue>SoupWebsocketState</returnvalue> soup_websocket_connection_get_state (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Get the current state of the WebSocket.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the state</para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_send_text ()</title> <programlisting><returnvalue>void</returnvalue> soup_websocket_connection_send_text (<parameter><type>SoupWebsocketConnection</type> *self</parameter>, <parameter>const <type>char</type> *text</parameter>);</programlisting> <para>Send a <literal>NULL</literal>-terminated text (UTF-8) message to the peer. If you need to send text messages containing <literal>NULL</literal> characters use <function>soup_websocket_connection_send_message()</function> instead.</para> <para>The message is queued to be sent and will be sent when the main loop is run.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><para>text</para></entry> <entry><para>the message contents</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_send_binary ()</title> <programlisting><returnvalue>void</returnvalue> soup_websocket_connection_send_binary (<parameter><type>SoupWebsocketConnection</type> *self</parameter>, <parameter><type>gconstpointer</type> data</parameter>, <parameter><type>gsize</type> length</parameter>);</programlisting> <para>Send a binary message to the peer. If <parameter>length</parameter> is 0, <parameter>data</parameter> may be <literal>NULL</literal>.</para> <para>The message is queued to be sent and will be sent when the main loop is run.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><para>data</para></entry> <entry><para>the message contents. </para></entry> <entry><emphasis>[array length=length][element-type guint8][nullable]</emphasis></entry></row> <row><entry><para>length</para></entry> <entry><para>the length of <parameter>data</parameter> </para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_send_message ()</title> <programlisting><returnvalue>void</returnvalue> soup_websocket_connection_send_message (<parameter><type>SoupWebsocketConnection</type> *self</parameter>, <parameter><type>SoupWebsocketDataType</type> type</parameter>, <parameter><type>GBytes</type> *message</parameter>);</programlisting> <para>Send a message of the given <parameter>type</parameter> to the peer. Note that this method, allows to send text messages containing <literal>NULL</literal> characters.</para> <para>The message is queued to be sent and will be sent when the main loop is run.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><para>type</para></entry> <entry><para>the type of message contents</para></entry> <entry></entry></row> <row><entry><para>message</para></entry> <entry><para>the message data as <type>GBytes</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_close ()</title> <programlisting><returnvalue>void</returnvalue> soup_websocket_connection_close (<parameter><type>SoupWebsocketConnection</type> *self</parameter>, <parameter><type>gushort</type> code</parameter>, <parameter>const <type>char</type> *data</parameter>);</programlisting> <para>Close the connection in an orderly fashion.</para> <para>Note that until the <type>“closed”</type> signal fires, the connection is not yet completely closed. The close message is not even sent until the main loop runs.</para> <para>The <parameter>code</parameter> and <parameter>data</parameter> are sent to the peer along with the close request. If <parameter>code</parameter> is <literal>SOUP_WEBSOCKET_CLOSE_NO_STATUS</literal> a close message with no body (without code and data) is sent. Note that the <parameter>data</parameter> must be UTF-8 valid.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><para>code</para></entry> <entry><para>close code</para></entry> <entry></entry></row> <row><entry><para>data</para></entry> <entry><para>close data. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_close_code ()</title> <programlisting><returnvalue>gushort</returnvalue> soup_websocket_connection_get_close_code (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Get the close code received from the WebSocket peer.</para> <para>This only becomes valid once the WebSocket is in the <literal>SOUP_WEBSOCKET_STATE_CLOSED</literal> state. The value will often be in the <type>SoupWebsocketCloseCode</type> enumeration, but may also be an application defined close code.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the close code or zero.</para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_connection_get_close_data ()</title> <programlisting>const <returnvalue>char</returnvalue> * soup_websocket_connection_get_close_data (<parameter><type>SoupWebsocketConnection</type> *self</parameter>);</programlisting> <para>Get the close data received from the WebSocket peer.</para> <para>This only becomes valid once the WebSocket is in the <literal>SOUP_WEBSOCKET_STATE_CLOSED</literal> state. The data may be freed once the main loop is run, so copy it if you need to keep it around.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> the close data or <literal>NULL</literal></para> </refsect3></refsect2> </refsect1>
<refsect1> <title>Types and Values</title> <refsect2> <title>SoupWebsocketConnection</title> <programlisting>typedef struct _SoupWebsocketConnection SoupWebsocketConnection;</programlisting> <para>A class representing a WebSocket connection.</para> </refsect2>
<refsect2> <title>enum SoupWebsocketConnectionType</title> <para>The type of a <type>SoupWebsocketConnection</type>.</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>SOUP_WEBSOCKET_CONNECTION_UNKNOWN</para></entry> <entry><para>unknown/invalid connection</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CONNECTION_CLIENT</para></entry> <entry><para>a client-side connection</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CONNECTION_SERVER</para></entry> <entry><para>a server-side connection</para> </entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>enum SoupWebsocketState</title> <para>The state of the WebSocket connection.</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>SOUP_WEBSOCKET_STATE_OPEN</para></entry> <entry><para>the connection is ready to send messages</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_STATE_CLOSING</para></entry> <entry><para>the connection is in the process of closing down; messages may be received, but not sent</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_STATE_CLOSED</para></entry> <entry><para>the connection is completely closed down</para> </entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>enum SoupWebsocketDataType</title> <para>The type of data contained in a <type>“message”</type> signal.</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>SOUP_WEBSOCKET_DATA_TEXT</para></entry> <entry><para>UTF-8 text</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_DATA_BINARY</para></entry> <entry><para>binary data</para> </entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>enum SoupWebsocketCloseCode</title> <para>Pre-defined close codes that can be passed to <function>soup_websocket_connection_close()</function> or received from <function>soup_websocket_connection_get_close_code()</function>. (However, other codes are also allowed.)</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>SOUP_WEBSOCKET_CLOSE_NORMAL</para></entry> <entry><para>a normal, non-error close</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_GOING_AWAY</para></entry> <entry><para>the client/server is going away</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_PROTOCOL_ERROR</para></entry> <entry><para>a protocol error occurred</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_UNSUPPORTED_DATA</para></entry> <entry><para>the endpoint received data of a type that it does not support.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_NO_STATUS</para></entry> <entry><para>reserved value indicating that no close code was present; must not be sent.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_ABNORMAL</para></entry> <entry><para>reserved value indicating that the connection was closed abnormally; must not be sent.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_BAD_DATA</para></entry> <entry><para>the endpoint received data that was invalid (eg, non-UTF-8 data in a text message).</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_POLICY_VIOLATION</para></entry> <entry><para>generic error code indicating some sort of policy violation.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_TOO_BIG</para></entry> <entry><para>the endpoint received a message that is too big to process.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_NO_EXTENSION</para></entry> <entry><para>the client is closing the connection because the server failed to negotiate a required extension.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_SERVER_ERROR</para></entry> <entry><para>the server is closing the connection because it was unable to fulfill the request.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_CLOSE_TLS_HANDSHAKE</para></entry> <entry><para>reserved value indicating that the TLS handshake failed; must not be sent.</para> </entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>enum SoupWebsocketError</title> <para>WebSocket-related errors.</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>SOUP_WEBSOCKET_ERROR_FAILED</para></entry> <entry><para>a generic error</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_ERROR_NOT_WEBSOCKET</para></entry> <entry><para>attempted to handshake with a server that does not appear to understand WebSockets.</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_ERROR_BAD_HANDSHAKE</para></entry> <entry><para>the WebSocket handshake failed because some detail was invalid (eg, incorrect accept key).</para> </entry> <entry></entry> </row> <row><entry><para>SOUP_WEBSOCKET_ERROR_BAD_ORIGIN</para></entry> <entry><para>the WebSocket handshake failed because the "Origin" header was not an allowed value.</para> </entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3></refsect2>
<refsect2> <title>SOUP_WEBSOCKET_ERROR</title> <programlisting>#define SOUP_WEBSOCKET_ERROR (soup_websocket_error_quark ()) </programlisting> <para>A <type>GError</type> domain for WebSocket-related errors. Used with <type>SoupWebsocketError</type>.</para> </refsect2> </refsect1>
<refsect1> <title>Property Details</title> <refsect2><title>The <literal>“connection-type”</literal> property</title> <programlisting> “connection-type” <type>SoupWebsocketConnectionType</type></programlisting> <para>The type of connection (client/server).</para> <para>Owner: SoupWebsocketConnection</para> <para>Flags: Read / Write / Construct Only</para> <para>Default value: SOUP_WEBSOCKET_CONNECTION_UNKNOWN</para> </refsect2>
<refsect2><title>The <literal>“extensions”</literal> property</title> <programlisting> “extensions” <type>gpointer</type></programlisting> <para>List of <type>SoupWebsocketExtension</type> objects that are active in the connection.</para> <para>Owner: SoupWebsocketConnection</para> <para>Flags: Read / Write / Construct Only</para> </refsect2>
<refsect2><title>The <literal>“io-stream”</literal> property</title> <programlisting> “io-stream” <type>GIOStream</type> *</programlisting> <para>The underlying IO stream the WebSocket is communicating over.</para> <para>The input and output streams must be pollable streams.</para> <para>Owner: SoupWebsocketConnection</para> <para>Flags: Read / Write / Construct Only</para> </refsect2>
<refsect2><title>The <literal>“keepalive-interval”</literal> property</title> <programlisting> “keepalive-interval” <type>guint</type></programlisting> <para>Interval in seconds on when to send a ping message which will serve as a keepalive message. If set to 0 the keepalive message is disabled.</para> <para>Owner: SoupWebsocketConnection</para> <para>Flags: Read / Write / Construct</para> <para>Default value: 0</para> </refsect2>
<refsect2><title>The <literal>“max-incoming-payload-size”</literal> property</title> <programlisting> “max-incoming-payload-size” <type>guint64</type></programlisting> <para>The maximum payload size for incoming packets the protocol expects or 0 to not limit it.</para> <para>Owner: SoupWebsocketConnection</para> <para>Flags: Read / Write / Construct</para> <para>Default value: 131072</para> </refsect2>
<refsect2><title>The <literal>“origin”</literal> property</title> <programlisting> “origin” <type>char</type> *</programlisting> <para>The client's Origin.</para> <para>Owner: SoupWebsocketConnection</para> <para>Flags: Read / Write / Construct Only</para> <para>Default value: NULL</para> </refsect2>
<refsect2><title>The <literal>“protocol”</literal> property</title> <programlisting> “protocol” <type>char</type> *</programlisting> <para>The chosen protocol, or <literal>NULL</literal> if a protocol was not agreed upon.</para> <para>Owner: SoupWebsocketConnection</para> <para>Flags: Read / Write / Construct Only</para> <para>Default value: NULL</para> </refsect2>
<refsect2><title>The <literal>“state”</literal> property</title> <programlisting> “state” <type>SoupWebsocketState</type></programlisting> <para>The current state of the WebSocket.</para> <para>Owner: SoupWebsocketConnection</para> <para>Flags: Read</para> <para>Default value: SOUP_WEBSOCKET_STATE_OPEN</para> </refsect2>
<refsect2><title>The <literal>“uri”</literal> property</title> <programlisting> “uri” <type>GUri</type> *</programlisting> <para>The URI of the WebSocket.</para> <para>For servers this represents the address of the WebSocket, and for clients it is the address connected to.</para> <para>Owner: SoupWebsocketConnection</para> <para>Flags: Read / Write / Construct Only</para> </refsect2> </refsect1>
<refsect1> <title>Signal Details</title> <refsect2><title>The <literal>“closed”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupWebsocketConnection</type> *self, <type>gpointer</type> user_data)</programlisting> <para>Emitted when the connection has completely closed, either due to an orderly close from the peer, one initiated via <function>soup_websocket_connection_close()</function> or a fatal error condition that caused a close.</para> <para>This signal will be emitted once.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run First</para> </refsect2>
<refsect2><title>The <literal>“closing”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupWebsocketConnection</type> *self, <type>gpointer</type> user_data)</programlisting> <para>This signal will be emitted during an orderly close.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run Last</para> </refsect2>
<refsect2><title>The <literal>“error”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupWebsocketConnection</type> *self, <type>GError</type> *error, <type>gpointer</type> user_data)</programlisting> <para>Emitted when an error occurred on the WebSocket. This may be fired multiple times. Fatal errors will be followed by the <type>“closed”</type> signal being emitted.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><para>error</para></entry> <entry><para>the error that occured</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run First</para> </refsect2>
<refsect2><title>The <literal>“message”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupWebsocketConnection</type> *self, <type>int</type> type, <type>GBytes</type> *message, <type>gpointer</type> user_data)</programlisting> <para>Emitted when we receive a message from the peer.</para> <para>As a convenience, the <parameter>message</parameter> data will always be NUL-terminated, but the NUL byte will not be included in the length count.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><para>type</para></entry> <entry><para>the type of message contents</para></entry> <entry></entry></row> <row><entry><para>message</para></entry> <entry><para>the message data</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run First</para> </refsect2>
<refsect2><title>The <literal>“pong”</literal> signal</title> <programlisting><returnvalue>void</returnvalue> user_function (<type>SoupWebsocketConnection</type> *self, <type>GBytes</type> *message, <type>gpointer</type> user_data)</programlisting> <para>Emitted when we receive a Pong frame (solicited or unsolicited) from the peer.</para> <para>As a convenience, the <parameter>message</parameter> data will always be NUL-terminated, but the NUL byte will not be included in the length count.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>self</para></entry> <entry><para>the WebSocket</para></entry> <entry></entry></row> <row><entry><para>message</para></entry> <entry><para>the application data (if any)</para></entry> <entry></entry></row> <row><entry><simpara>user_data</simpara></entry> <entry><simpara>user data set when the signal handler was connected.</simpara></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><para>Flags: Run First</para> </refsect2> </refsect1>
<refsect1> <title>See Also</title> <para>soup_session_websocket_connect_async(), <function>soup_server_add_websocket_handler()</function></para> </refsect1> </refentry>
<refentry> <refmeta> <refentrytitle>SoupWebsocketExtension</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>LIBSOUP-3.0 Library</refmiscinfo> </refmeta>

<refentrytitle>SoupWebsocketExtension</refentrytitle>

<refname>SoupWebsocketExtension</refname> <refpurpose>a WebSocket extension</refpurpose>

<refsect1> <title>Functions</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><returnvalue>gboolean</returnvalue> </entry><entry>soup_websocket_extension_configure <phrase>()</phrase></entry></row> <row><entry><returnvalue>char</returnvalue> * </entry><entry>soup_websocket_extension_get_request_params <phrase>()</phrase></entry></row> <row><entry><returnvalue>char</returnvalue> * </entry><entry>soup_websocket_extension_get_response_params <phrase>()</phrase></entry></row> <row><entry><returnvalue>GBytes</returnvalue> * </entry><entry>soup_websocket_extension_process_outgoing_message <phrase>()</phrase></entry></row> <row><entry><returnvalue>GBytes</returnvalue> * </entry><entry>soup_websocket_extension_process_incoming_message <phrase>()</phrase></entry></row> </tbody> </tgroup> </informaltable> </refsect1> <anchor></anchor><anchor></anchor><refsect1> <title>Types and Values</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <tbody> <row><entry></entry><entry>SoupWebsocketExtension</entry></row> <row><entry>struct</entry><entry>SoupWebsocketExtensionClass</entry></row> <row><entry></entry><entry>SoupWebsocketExtensionDeflate</entry></row> <row><entry>#define</entry><entry>SOUP_TYPE_WEBSOCKET_EXTENSION_DEFLATE</entry></row> <row><entry></entry><entry>SoupWebsocketExtensionManager</entry></row> <row><entry>#define</entry><entry>SOUP_TYPE_WEBSOCKET_EXTENSION_MANAGER</entry></row> </tbody> </tgroup> </informaltable> </refsect1> <refsect1> <title>Object Hierarchy</title> <screen> GObject <phrase>├──</phrase> SoupWebsocketExtension <phrase>│</phrase> <phrase>╰──</phrase> SoupWebsocketExtensionDeflate <phrase>╰──</phrase> SoupWebsocketExtensionManager </screen> </refsect1> <refsect1> <title>Implemented Interfaces</title> <para> SoupWebsocketExtensionManager implements SoupSessionFeature.</para> </refsect1> <refsect1><title>Includes</title><synopsis>#include <libsoup/soup.h> </synopsis></refsect1> <refsect1> <title>Description</title> <para>SoupWebsocketExtension is the base class for WebSocket extension objects.</para> </refsect1> <refsect1> <title>Functions</title> <refsect2> <title>soup_websocket_extension_configure ()</title> <programlisting><returnvalue>gboolean</returnvalue> soup_websocket_extension_configure (<parameter><type>SoupWebsocketExtension</type> *extension</parameter>, <parameter><type>SoupWebsocketConnectionType</type> connection_type</parameter>, <parameter><type>GHashTable</type> *params</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>Configures <parameter>extension</parameter> with the given <parameter>params</parameter> </para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>extension</para></entry> <entry><para>a <type>SoupWebsocketExtension</type></para></entry> <entry></entry></row> <row><entry><para>connection_type</para></entry> <entry><para>either <literal>SOUP_WEBSOCKET_CONNECTION_CLIENT</literal> or <literal>SOUP_WEBSOCKET_CONNECTION_SERVER</literal></para></entry> <entry></entry></row> <row><entry><para>params</para></entry> <entry><para>the parameters, or <literal>NULL</literal>. </para></entry> <entry><emphasis>[nullable]</emphasis></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para> <literal>TRUE</literal> if extension could be configured with the given parameters, or <literal>FALSE</literal> otherwise</para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_extension_get_request_params ()</title> <programlisting><returnvalue>char</returnvalue> * soup_websocket_extension_get_request_params (<parameter><type>SoupWebsocketExtension</type> *extension</parameter>);</programlisting> <para>Get the parameters strings to be included in the request header. If the extension doesn't include any parameter in the request, this function returns <literal>NULL</literal>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>extension</para></entry> <entry><para>a <type>SoupWebsocketExtension</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a new allocated string with the parameters. </para> <para><emphasis>[nullable][transfer full]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_extension_get_response_params ()</title> <programlisting><returnvalue>char</returnvalue> * soup_websocket_extension_get_response_params (<parameter><type>SoupWebsocketExtension</type> *extension</parameter>);</programlisting> <para>Get the parameters strings to be included in the response header. If the extension doesn't include any parameter in the response, this function returns <literal>NULL</literal>.</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>extension</para></entry> <entry><para>a <type>SoupWebsocketExtension</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>a new allocated string with the parameters. </para> <para><emphasis>[nullable][transfer full]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_extension_process_outgoing_message ()</title> <programlisting><returnvalue>GBytes</returnvalue> * soup_websocket_extension_process_outgoing_message (<parameter><type>SoupWebsocketExtension</type> *extension</parameter>, <parameter><type>guint8</type> *header</parameter>, <parameter><type>GBytes</type> *payload</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>Process a message before it's sent. If the payload isn't changed the given <parameter>payload</parameter> is just returned, otherwise <function>g_bytes_unref()</function> is called on the given <parameter>payload</parameter> and a new <type>GBytes</type> is returned with the new data.</para> <para>Extensions using reserved bits of the header will change them in <parameter>header</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>extension</para></entry> <entry><para>a <type>SoupWebsocketExtension</type></para></entry> <entry></entry></row> <row><entry><para>header</para></entry> <entry><para>the message header. </para></entry> <entry><emphasis>[inout]</emphasis></entry></row> <row><entry><para>payload</para></entry> <entry><para>the payload data. </para></entry> <entry><emphasis>[transfer full]</emphasis></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the message payload data, or <literal>NULL</literal> in case of error. </para> <para><emphasis>[transfer full]</emphasis></para> </refsect3></refsect2>
<refsect2> <title>soup_websocket_extension_process_incoming_message ()</title> <programlisting><returnvalue>GBytes</returnvalue> * soup_websocket_extension_process_incoming_message (<parameter><type>SoupWebsocketExtension</type> *extension</parameter>, <parameter><type>guint8</type> *header</parameter>, <parameter><type>GBytes</type> *payload</parameter>, <parameter><type>GError</type> **error</parameter>);</programlisting> <para>Process a message after it's received. If the payload isn't changed the given <parameter>payload</parameter> is just returned, otherwise <function>g_bytes_unref()</function> is called on the given <parameter>payload</parameter> and a new <type>GBytes</type> is returned with the new data.</para> <para>Extensions using reserved bits of the header will reset them in <parameter>header</parameter> .</para> <refsect3> <title>Parameters</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>extension</para></entry> <entry><para>a <type>SoupWebsocketExtension</type></para></entry> <entry></entry></row> <row><entry><para>header</para></entry> <entry><para>the message header. </para></entry> <entry><emphasis>[inout]</emphasis></entry></row> <row><entry><para>payload</para></entry> <entry><para>the payload data. </para></entry> <entry><emphasis>[transfer full]</emphasis></entry></row> <row><entry><para>error</para></entry> <entry><para>return location for a <type>GError</type></para></entry> <entry></entry></row> </tbody></tgroup></informaltable> </refsect3><refsect3> <title>Returns</title> <para>the message payload data, or <literal>NULL</literal> in case of error. </para> <para><emphasis>[transfer full]</emphasis></para> </refsect3></refsect2> </refsect1>
<refsect1> <title>Types and Values</title> <refsect2> <title>SoupWebsocketExtension</title> <programlisting>typedef struct _SoupWebsocketExtension SoupWebsocketExtension;</programlisting> <para>Class for impelementing websocket extensions.</para> </refsect2>
<refsect2> <title>struct SoupWebsocketExtensionClass</title> <programlisting>struct SoupWebsocketExtensionClass { GObjectClass parent_class; const char *name; gboolean (* configure) (SoupWebsocketExtension *extension, SoupWebsocketConnectionType connection_type, GHashTable *params, GError **error); char *(* get_request_params) (SoupWebsocketExtension *extension); char *(* get_response_params) (SoupWebsocketExtension *extension); GBytes *(* process_outgoing_message) (SoupWebsocketExtension *extension, guint8 *header, GBytes *payload, GError **error); GBytes *(* process_incoming_message) (SoupWebsocketExtension *extension, guint8 *header, GBytes *payload, GError **error); }; </programlisting> <para>The class structure for the SoupWebsocketExtension.</para> <refsect3> <title>Members</title> <informaltable> <tgroup> <colspec></colspec> <colspec></colspec> <colspec></colspec> <tbody> <row><entry><para>const <type>char</type> *<structfield>name</structfield>;</para></entry> <entry><para>the name of the extension</para></entry> <entry></entry> </row> <row><entry><para><structfield>configure</structfield> ()</para></entry> <entry><para>called to configure the extension with the given parameters</para></entry> <entry></entry> </row> <row><entry><para><structfield>get_request_params</structfield> ()</para></entry> <entry><para>called by the client to build the request header. It should include the parameters string starting with ';'</para></entry> <entry></entry> </row> <row><entry><para><structfield>get_response_params</structfield> ()</para></entry> <entry><para>called by the server to build the response header. It should include the parameters string starting with ';'</para></entry> <entry></entry> </row> <row><entry><para><structfield>process_outgoing_message</structfield> ()</para></entry> <entry><para>called to process the payload data of a message before it's sent. Reserved bits of the header should be changed.</para></entry> <entry></entry> </row> <row><entry><para><structfield>process_incoming_message</structfield> ()</para></entry> <entry><para>called to process the payload data of a message after it's received. Reserved bits of the header should be cleared.</para></entry> <entry></entry> </row> </tbody></tgroup></informaltable> </refsect3> </refsect2>
<refsect2> <title>SoupWebsocketExtensionDeflate</title> <programlisting>typedef struct _SoupWebsocketExtensionDeflate SoupWebsocketExtensionDeflate;</programlisting> <para>A SoupWebsocketExtensionDeflate is a <type>SoupWebsocketExtension</type> implementing permessage-deflate (RFC 7692).</para> <para>This extension is used by default in a <type>SoupSession</type> when <type>SoupWebsocketExtensionManager</type> feature is present, and always used by <type>SoupServer</type>.</para> </refsect2>
<refsect2> <title>SOUP_TYPE_WEBSOCKET_EXTENSION_DEFLATE</title> <programlisting>#define SOUP_TYPE_WEBSOCKET_EXTENSION_DEFLATE (soup_websocket_extension_deflate_get_type ()) </programlisting> <para>A <type>GType</type> corresponding to permessage-deflate WebSocket extension.</para> </refsect2>
<refsect2> <title>SoupWebsocketExtensionManager</title> <programlisting>typedef struct _SoupWebsocketExtensionManager SoupWebsocketExtensionManager;</programlisting> <para>SoupWebsocketExtensionManager is the <type>SoupSessionFeature</type> that handles WebSockets extensions for a <type>SoupSession</type>.</para> <para>A SoupWebsocketExtensionManager is added to the session by default, and normally you don't need to worry about it at all. However, if you want to disable WebSocket extensions, you can remove the feature from the session with <function>soup_session_remove_feature_by_type()</function>, or disable it on individual requests with <function>soup_message_disable_feature()</function>.</para> </refsect2>
<refsect2> <title>SOUP_TYPE_WEBSOCKET_EXTENSION_MANAGER</title> <programlisting>#define SOUP_TYPE_WEBSOCKET_EXTENSION_MANAGER (soup_websocket_extension_manager_get_type ()) </programlisting> <para>The <type>GType</type> of <type>SoupWebsocketExtensionManager</type>; you can use this with <function>soup_session_remove_feature_by_type()</function> or <function>soup_message_disable_feature()</function>.</para> </refsect2> </refsect1>
<refsect1> <title>See Also</title> <para><type>SoupSession</type>, <type>SoupWebsocketExtensionManager</type></para> </refsect1> </refentry>