diff options
author | Dan Winship <danw@src.gnome.org> | 2009-02-15 21:28:28 +0000 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2009-02-15 21:28:28 +0000 |
commit | 536a7b8130533a107f5a50962287b64b0838ef81 (patch) | |
tree | fbd2d4196d3f7b6e65ac6724d9c893b37a6f175b /docs | |
parent | b477db091070bcfe9d3b11cf072c9e4b1794fb8a (diff) | |
download | libsoup-536a7b8130533a107f5a50962287b64b0838ef81.tar.gz libsoup-536a7b8130533a107f5a50962287b64b0838ef81.tar.bz2 libsoup-536a7b8130533a107f5a50962287b64b0838ef81.zip |
Updates: Mention SoupSessionFeature (and link to SoupLogger,
* docs/reference/client-howto.xml: Updates: Mention
SoupSessionFeature (and link to SoupLogger, SoupCookieJar, and
SoupProxyResolverGNOME specifically). Mention forms and XML-RPC
support. Mention header-parsing methods. Give a concrete example
of connecting to SoupMessage signals. Document the (minimal)
thread-safety guarantees
* docs/reference/build-howto.xml: basic notes on pkg-config and
#include usage.
svn path=/trunk/; revision=1238
Diffstat (limited to 'docs')
-rw-r--r-- | docs/reference/Makefile.am | 6 | ||||
-rw-r--r-- | docs/reference/build-howto.xml | 105 | ||||
-rw-r--r-- | docs/reference/client-howto.xml | 223 | ||||
-rw-r--r-- | docs/reference/libsoup-2.4-docs.sgml | 1 | ||||
-rw-r--r-- | docs/reference/server-howto.xml | 12 |
5 files changed, 298 insertions, 49 deletions
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am index 527e7e93..0f22d4ae 100644 --- a/docs/reference/Makefile.am +++ b/docs/reference/Makefile.am @@ -41,7 +41,11 @@ IGNORE_HFILES= soup.h soup-marshal.h soup-enum-types.h \ HTML_IMAGES = # Extra XML files that are included by $(DOC_MAIN_SGML_FILE). -content_files = client-howto.xml server-howto.xml porting-2.2-2.4.xml +content_files = \ + build-howto.xml \ + client-howto.xml \ + server-howto.xml \ + porting-2.2-2.4.xml # Other files to distribute. extra_files = diff --git a/docs/reference/build-howto.xml b/docs/reference/build-howto.xml new file mode 100644 index 00000000..7c8e0deb --- /dev/null +++ b/docs/reference/build-howto.xml @@ -0,0 +1,105 @@ +<?xml version="1.0"?> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" + "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> +<refentry id="libsoup-build-howto"> +<refmeta> +<refentrytitle>Compiling with libsoup</refentrytitle> +<manvolnum>3</manvolnum> +<refmiscinfo>LIBSOUP Library</refmiscinfo> +</refmeta> + +<refnamediv> +<refname>Compiling with libsoup</refname><refpurpose>Notes on compiling</refpurpose> +</refnamediv> + +<refsect2> +<title>Using pkg-config</title> + +<para> +Like other GNOME libraries, <application>libsoup</application> uses +<application>pkg-config</application> to provide compiler options. The +package name is "<literal>libsoup-2.4</literal>". So in your +<literal>configure</literal> script, you might specify something like: +</para> + +<informalexample><programlisting> +PKG_CHECK_MODULES(LIBSOUP, [libsoup-2.4 >= 2.26]) +AC_SUBST(LIBSOUP_CFLAGS) +AC_SUBST(LIBSOUP_LIBS) +</programlisting></informalexample> + +<para> +The "<literal>2.4</literal>" in the package name is the "API version" +(indicating "the version of the <application>libsoup</application> API +that first appeared in version 2.4") and is essentially just part of +the package name. +</para> + +<para> +If you are using any of the GNOME-specific features of +<application>libsoup</application> (such as automatic proxy +configuration), you must require +"<literal>libsoup-gnome-2.4</literal>" instead: +</para> + +<informalexample><programlisting> +PKG_CHECK_MODULES(LIBSOUP, [libsoup-gnome-2.4 >= 2.26]) +AC_SUBST(LIBSOUP_CFLAGS) +AC_SUBST(LIBSOUP_LIBS) +</programlisting></informalexample> + +<para> +You can also make <application>libsoup-gnome</application> an optional +dependency: +</para> + +<informalexample><programlisting> +PKG_CHECK_MODULES(LIBSOUP_GNOME, + [libsoup-gnome-2.4 >= 2.26], + [LIBSOUP_CFLAGS="$LIBSOUP_GNOME_CFLAGS" + LIBSOUP_LIBS="$LIBSOUP_GNOME_LIBS" + AC_DEFINE(HAVE_LIBSOUP_GNOME, 1, [Have libsoup-gnome])], + [PKG_CHECK_MODULES(LIBSOUP, [libsoup-2.4 >= 2.26])]) +AC_SUBST(LIBSOUP_CFLAGS) +AC_SUBST(LIBSOUP_LIBS) +</programlisting></informalexample> + +<para> +This will allow the application to be built with either plain +<application>libsoup</application> or with +<application>libsoup-gnome</application>, and it will define the C +preprocessor symbol <literal>HAVE_LIBSOUP_GNOME</literal> if +<application>libsoup-gnome</application> features are available. +</para> + +</refsect2> + +<refsect2> +<title>Headers</title> + +<para> +Code using <application>libsoup</application> should do: +</para> + +<informalexample><programlisting> +#include <libsoup/libsoup.h> +</programlisting></informalexample> + +<para> +or, for <application>libsoup-gnome</application>: +</para> + +<informalexample><programlisting> +#include <libsoup/libsoup-gnome.h> +</programlisting></informalexample> + +<para> +Including individual headers besides the two main header files is not +recommended. You may include both <literal>libsoup.h</literal> and +<literal>libsoup-gnome.h</literal> (though this is not required; the +latter automatically includes the former). +</para> + +</refsect2> + +</refentry> diff --git a/docs/reference/client-howto.xml b/docs/reference/client-howto.xml index 24ee0461..ef7fb59d 100644 --- a/docs/reference/client-howto.xml +++ b/docs/reference/client-howto.xml @@ -58,14 +58,7 @@ you can specify various additional options: <variablelist> <varlistentry> - <term><link linkend="SOUP-SESSION-PROXY-URI:CAPS"><literal>SOUP_SESSION_PROXY_URI</literal></link></term> - <listitem><para> - Tells the session to use an HTTP proxy rather than - directly connecting to HTTP servers. - </para></listitem> - </varlistentry> - <varlistentry> - <term><link linkend="SOUP-SESSION-MAX-CONNS:CAPS"><literal>SOUP_SESSION_MAX_CONNS</literal></link></term> + <term><link linkend="SOUP-SESSION-MAX-CONNS--CAPS"><literal>SOUP_SESSION_MAX_CONNS</literal></link></term> <listitem><para> Allows you to set the maximum total number of connections the session will have open at one time. (Once it reaches @@ -75,7 +68,7 @@ you can specify various additional options: </para></listitem> </varlistentry> <varlistentry> - <term><link linkend="SOUP-SESSION-MAX-CONNS-PER-HOST:CAPS"><literal>SOUP_SESSION_MAX_CONNS_PER_HOST</literal></link></term> + <term><link linkend="SOUP-SESSION-MAX-CONNS-PER-HOST--CAPS"><literal>SOUP_SESSION_MAX_CONNS_PER_HOST</literal></link></term> <listitem><para> Allows you to set the maximum total number of connections the session will have open <emphasis>to a single @@ -83,7 +76,7 @@ you can specify various additional options: </para></listitem> </varlistentry> <varlistentry> - <term><link linkend="SOUP-SESSION-USE-NTLM:CAPS"><literal>SOUP_SESSION_USE_NTLM</literal></link></term> + <term><link linkend="SOUP-SESSION-USE-NTLM--CAPS"><literal>SOUP_SESSION_USE_NTLM</literal></link></term> <listitem><para> If <literal>TRUE</literal>, then Microsoft NTLM authentication will be used if available (and will be @@ -96,7 +89,7 @@ you can specify various additional options: </para></listitem> </varlistentry> <varlistentry> - <term><link linkend="SOUP-SESSION-SSL-CA-FILE:CAPS"><literal>SOUP_SESSION_SSL_CA_FILE</literal></link></term> + <term><link linkend="SOUP-SESSION-SSL-CA-FILE--CAPS"><literal>SOUP_SESSION_SSL_CA_FILE</literal></link></term> <listitem><para> Points to a file containing certificates for recognized SSL Certificate Authorities. If this is set, then HTTPS @@ -106,12 +99,23 @@ you can specify various additional options: </para></listitem> </varlistentry> <varlistentry> - <term><link linkend="SOUP-SESSION-ASYNC-CONTEXT:CAPS"><literal>SOUP_SESSION_ASYNC_CONTEXT</literal></link></term> + <term><link linkend="SOUP-SESSION-ASYNC-CONTEXT--CAPS"><literal>SOUP_SESSION_ASYNC_CONTEXT</literal></link></term> <listitem><para> - A <link linkend="GMainContext">GMainContext</link> which - the session will use for asynchronous operations. This can - be set if you want to use a <type>SoupSessionAsync</type> - in a thread other than the main thread. + A <link + linkend="GMainContext"><type>GMainContext</type>type></link> + which the session will use for asynchronous operations. + This can be set if you want to use a + <type>SoupSessionAsync</type> in a thread other than the + main thread. + </para></listitem> + </varlistentry> + <varlistentry> + <term><link linkend="SOUP-SESSION-ADD-FEATURE--CAPS"><literal>SOUP_SESSION_ADD_FEATURE</literal></link> and <link linkend="SOUP-SESSION-ADD-FEATURE-BY-TYPE--CAPS"><literal>SOUP_SESSION_ADD_FEATURE_BY_TYPE</literal></link></term> + <listitem><para> + These allow you to specify <link + linkend="SoupSessionFeature"><type>SoupSessionFeature</type></link>s + (discussed <link linkend="session-features">below</link>) + to add at construct-time. </para></listitem> </varlistentry> </variablelist> @@ -125,13 +129,98 @@ which take no arguments. </refsect2> +<refsect2 id="session-features"> +<title>Session features</title> + +<para> +Additional session functionality is provided as <link +linkend="SoupSessionFeature"><type>SoupSessionFeature</type></link>s, +which can be added to a session, via the <link +linkend="SOUP-SESSION-ADD-FEATURE--CAPS"><literal>SOUP_SESSION_ADD_FEATURE</literal></link> +and <link +linkend="SOUP-SESSION-ADD-FEATURE-BY-TYPE--CAPS"><literal>SOUP_SESSION_ADD_FEATURE_BY_TYPE</literal></link> +options at session-construction-time, or afterward via the <link +linkend="soup-session-add-feature"><function>soup_session_add_feature</function></link> +and <link +linkend="soup-session-add-feature-by-type"><function>soup_session_add_feature_by_type</function></link> +functions. Some of the features available in +<application>libsoup</application> are: +</para> + +<variablelist> + <varlistentry> + <term><link linkend="SoupLogger"><type>SoupLogger</type></link></term> + <listitem><para> + A debugging aid, which logs all of libsoup's HTTP traffic + to <literal>stdout</literal> (or another place you specify). + </para></listitem> + </varlistentry> + <varlistentry> + <term><link linkend="SoupCookieJar"><type>SoupCookieJar</type></link> and <link linkend="SoupCookieJarText"><type>SoupCookieJarText</type></link></term> + <listitem><para> + Support for HTTP cookies. <type>SoupCookieJar</type> + provides non-persistent cookie storage, while + <type>SoupCookieJarText</type> uses a text file to keep + track of cookies between sessions. + </para></listitem> + </varlistentry> +</variablelist> + +<para> +And in <application>libsoup-gnome</application>: +</para> + +<variablelist> + <varlistentry> + <term><link linkend="SOUP-TYPE-PROXY-RESOLVER-GNOME--CAPS"><type>SoupProxyResolverGNOME</type></link></term> + <listitem><para> + A feature that automatically determines the correct HTTP + proxy to use for requests. + </para></listitem> + </varlistentry> + <varlistentry> + <term><link linkend="SoupCookieJarSqlite"><type>SoupCookieJarSqlite</type></link></term> + <listitem><para> + Support for HTTP cookies stored in an + <application>SQLite</application> database. + </para></listitem> + </varlistentry> +</variablelist> + +<para> +Use the "add_feature_by_type" property/function to add features that +don't require any configuration (such as <link +linkend="SOUP-TYPE-PROXY-RESOLVER-GNOME--CAPS"><type>SoupProxyResolverGNOME</type></link>), +and the "add_feature" property/function to add features that must be +constructed first (such as <link +linkend="SoupLogger"><type>SoupLogger</type></link>). For example, an +application might do something like the following: +</para> + +<informalexample><programlisting> + session = soup_session_async_new_with_options ( +#ifdef HAVE_LIBSOUP_GNOME + SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_PROXY_RESOLVER_GNOME, +#endif + NULL); + if (debug_level) { + SoupLogger *logger; + + logger = soup_logger_new (debug_level, -1); + soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger)); + g_object_unref (logger); + } +</programlisting></informalexample> + +</refsect2> + <refsect2> <title>Creating and Sending SoupMessages</title> <para> Once you have a session, you do HTTP traffic using <link -linkend="SoupMessage">SoupMessage</link>. In the simplest case, you -only need to create the message and it's ready to send: +linkend="SoupMessage"><type>SoupMessage</type></link>. In the simplest +case, you only need to create the message and it's ready to send: </para> <informalexample><programlisting> @@ -158,12 +247,20 @@ request headers and body of the message: </programlisting></informalexample> <para> +(Although this is a bad example, because +<application>libsoup</application> actually has convenience methods +for dealing with <link linkend="libsoup-24-HTML-Form-Support">HTML +forms</link>, as well as <link +linkend="libsoup-24-XMLRPC-Support">XML-RPC</link>.) +</para> + +<para> You can also use <link linkend="soup-message-set-flags"><function>soup_message_set_flags</function></link> to change some default behaviors. For example, by default, <type>SoupSession</type> automatically handles responses from the server that redirect to another URL. If you would like to handle these -yourself, you can set the <link linkend="SOUP-MESSAGE-NO-REDIRECT:CAPS"><literal>SOUP_MESSAGE_NO_REDIRECT</literal></link> +yourself, you can set the <link linkend="SOUP-MESSAGE-NO-REDIRECT--CAPS"><literal>SOUP_MESSAGE_NO_REDIRECT</literal></link> flag. </para> @@ -188,11 +285,11 @@ it will run the main loop itself until the message is complete.) </para> <para> -The return value from <function>soup_session_send</function> is a -<link linkend="soup-status">soup status code</link>, indicating either -a transport error that prevented the message from being sent, or the -HTTP status that was returned by the server in response to the -message. (The status is also available as +The return value from <function>soup_session_send_message</function> +is a <link linkend="soup-status">libsoup status code</link>, +indicating either a transport error that prevented the message from +being sent, or the HTTP status that was returned by the server in +response to the message. (The status is also available as <literal>msg->status_code</literal>.) </para> @@ -228,12 +325,26 @@ passed to <function>soup_session_queue_message</function>. </para> <para> +<link +linkend="soup-session-queue-message"><function>soup_session_queue_message</function></link> +steals a reference to the message object, and unrefs it after the last +callback is invoked on it. So in the usual case, messages sent +asynchronously will be automatically freed for you without you needing +to do anything. (Of course, this wouldn't work when using the synchronous +API, since you will usually need continue working with the message +after calling <link +linkend="soup-session-send-message"><function>soup_session_send_message</function></link>, +so in that case, you must unref it explicitly when you are done with +it.) +</para> + +<para> (If you use <link linkend="soup-session-queue-message"><function>soup_session_queue_message</function></link> with a <link linkend="SoupSessionSync"><type>SoupSessionSync</type></link>, the message will be sent in another thread, with the callback eventually -being invoked in the session's <link linkend="SOUP-SESSION-ASYNC-CONTEXT:CAPS"><literal>SOUP_SESSION_ASYNC_CONTEXT</literal></link>.) +being invoked in the session's <link linkend="SOUP-SESSION-ASYNC-CONTEXT--CAPS"><literal>SOUP_SESSION_ASYNC_CONTEXT</literal></link>.) </para> </refsect3> @@ -260,17 +371,20 @@ The response body (if any) is in the </para> <para> -If you send the message with <link -linkend="soup-session-queue-message"><function>soup_session_queue_message</function></link>, -<application>libsoup</application> will steal a reference to the -message object, and unref the message after the last callback is -invoked on it. So in the usual case, messages will be automatically -freed for you without you needing to do anything. Of course, this -won't work when using the synchronous API, since you will usually need -continue working with the message after calling <link -linkend="soup-session-send-message"><function>soup_session_send_message</function></link>, -so in that case, you must unref it explicitly when you are done with -it. +<link +linkend="SoupMessageHeaders"><type>SoupMessageHeaders</type></link> +automatically parses several important headers in +<structfield>response_headers</structfield> for you and provides +specialized accessors for them. Eg, <link +linkend="soup-message-headers-get-content-type"><function>soup_message_headers_get_content_type</function></link>. +There are several generic methods such as <link +linkend="soup-header-parse-param-list"><function>soup_header_parse_param_list</function></link> +(for parsing an attribute-list-type header) and <link +linkend="soup-header-contains"><function>soup_header_contains</function></link> +(for quickly testing if a list-type header contains a particular +token). These handle the various syntactical oddities of parsing HTTP +headers much better than functions like +<function>g_strsplit</function> or <function>strstr</function>. </para> </refsect2> @@ -279,10 +393,13 @@ it. <title>Intermediate/Automatic Processing</title> <para> -You can also connect to various <literal>SoupMessage</literal> signals -to do processing at intermediate stages of HTTP I/O. -<literal>SoupMessage</literal> also provides two convenience methods, -<link +You can also connect to various <type>SoupMessage</type> signals to do +processing at intermediate stages of HTTP I/O. Eg, the <link +linkend="SoupMessage-got-chunk"><literal>got-chunk</literal></link> +signal is emitted as each piece of the response body is read (allowing +you to provide progress information when receiving a large response, +for example). <type>SoupMessage</type> also provides two convenience +methods, <link linkend="soup-message-add-header-handler"><function>soup_message_add_header_handler</function></link>, and <link linkend="soup-message-add-status-code-handler"><function>soup_message_add_status_code_handler</function></link>, @@ -332,8 +449,7 @@ return the message to the application with its 401 or 407 status.) If the server doesn't accept the username and password provided, the session will emit <link linkend="SoupSession-authenticate">authenticate</link> again, with the -<literal>retrying</literal> parameter set to <link -linkend="TRUE:CAPS"><literal>TRUE</literal></link>. This lets the +<literal>retrying</literal> parameter set to <literal>TRUE</literal>. This lets the application know that the information it provided earlier was incorrect, and gives it a chance to try again. If this username/password pair also doesn't work, the session will contine to @@ -361,6 +477,29 @@ to resume the paused message. </refsect2> <refsect2> +<title>Multi-threaded usage</title> + +<para> +The only explicitly thread-safe operations in +<application>libsoup</application> are <link +linkend="SoupSessionSync"><type>SoupSessionSync</type></link>'s +implementations of the <link +linkend="SoupSession"><type>SoupSession</type></link> methods. So +after creating a <type>SoupSessionSync</type>, you can call <link +linkend="soup-session-send-message"><function>soup_session_send_message</function></link> +and <link +linkend="soup-session-cancel-message"><function>soup_session_cancel_message</function></link> +on it from any thread. But, eg, while the session is processing a +message, you should not call any <link +linkend="SoupMessage"><type>SoupMessage</type></link> methods on it +from any thread other than the one in which it is being sent. (That +is, you should not call any <type>SoupMessage</type> methods on it +except from a message or session callback or signal handler.) +</para> + +</refsect2> + +<refsect2> <title>Sample Programs</title> <para> diff --git a/docs/reference/libsoup-2.4-docs.sgml b/docs/reference/libsoup-2.4-docs.sgml index 0b0b3269..aef4d9d3 100644 --- a/docs/reference/libsoup-2.4-docs.sgml +++ b/docs/reference/libsoup-2.4-docs.sgml @@ -8,6 +8,7 @@ <chapter> <title>Tutorial</title> + <xi:include href="build-howto.xml"/> <xi:include href="client-howto.xml"/> <xi:include href="server-howto.xml"/> <xi:include href="porting-2.2-2.4.xml"/> diff --git a/docs/reference/server-howto.xml b/docs/reference/server-howto.xml index 76c19182..0a9a53d9 100644 --- a/docs/reference/server-howto.xml +++ b/docs/reference/server-howto.xml @@ -30,7 +30,7 @@ various additional options: <variablelist> <varlistentry> - <term><link linkend="SOUP-SERVER-PORT:CAPS"><literal>SOUP_SERVER_PORT</literal></link></term> + <term><link linkend="SOUP-SERVER-PORT--CAPS"><literal>SOUP_SERVER_PORT</literal></link></term> <listitem><para> The TCP port to listen on. If <literal>0</literal> (or left unspecified), some unused port will be selected for @@ -39,7 +39,7 @@ various additional options: </para></listitem> </varlistentry> <varlistentry> - <term><link linkend="SOUP-SERVER-INTERFACE:CAPS"><literal>SOUP_SERVER_INTERFACE</literal></link></term> + <term><link linkend="SOUP-SERVER-INTERFACE--CAPS"><literal>SOUP_SERVER_INTERFACE</literal></link></term> <listitem><para> A <link linkend="SoupAddress"><type>SoupAddress</type></link>, specifying the IP address of the network interface to run @@ -48,7 +48,7 @@ various additional options: </para></listitem> </varlistentry> <varlistentry> - <term><link linkend="SOUP-SERVER-SSL-CERT-FILE:CAPS"><literal>SOUP_SERVER_SSL_CERT_FILE</literal></link></term> + <term><link linkend="SOUP-SERVER-SSL-CERT-FILE--CAPS"><literal>SOUP_SERVER_SSL_CERT_FILE</literal></link></term> <listitem><para> Points to a file containing an SSL certificate to use. If this is set, then the server will speak HTTPS; otherwise @@ -56,7 +56,7 @@ various additional options: </para></listitem> </varlistentry> <varlistentry> - <term><link linkend="SOUP-SERVER-SSL-KEY-FILE:CAPS"><literal>SOUP_SERVER_SSL_KEY_FILE</literal></link></term> + <term><link linkend="SOUP-SERVER-SSL-KEY-FILE--CAPS"><literal>SOUP_SERVER_SSL_KEY_FILE</literal></link></term> <listitem><para> Points to a file containing the private key for the <literal>SOUP_SERVER_SSL_CERT_FILE</literal>. (It may @@ -64,7 +64,7 @@ various additional options: </para></listitem> </varlistentry> <varlistentry> - <term><link linkend="SOUP-SERVER-ASYNC-CONTEXT:CAPS"><literal>SOUP_SERVER_ASYNC_CONTEXT</literal></link></term> + <term><link linkend="SOUP-SERVER-ASYNC-CONTEXT--CAPS"><literal>SOUP_SERVER_ASYNC_CONTEXT</literal></link></term> <listitem><para> A <link linkend="GMainContext"><type>GMainContext</type></link> which the server will use for asynchronous operations. This can @@ -73,7 +73,7 @@ various additional options: </para></listitem> </varlistentry> <varlistentry> - <term><link linkend="SOUP-SERVER-RAW-PATHS:CAPS"><literal>SOUP_SERVER_RAW_PATHS</literal></link></term> + <term><link linkend="SOUP-SERVER-RAW-PATHS--CAPS"><literal>SOUP_SERVER_RAW_PATHS</literal></link></term> <listitem><para> Set this to <literal>TRUE</literal> if you don't want <application>libsoup</application> to decode %-encoding |