chiark / gitweb /
util: make http url validity checks more generic, and move them to util.c
[elogind.git] / man / sd_journal_get_data.xml
1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3         "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6   This file is part of systemd.
7
8   Copyright 2012 Lennart Poettering
9
10   systemd is free software; you can redistribute it and/or modify it
11   under the terms of the GNU Lesser General Public License as published by
12   the Free Software Foundation; either version 2.1 of the License, or
13   (at your option) any later version.
14
15   systemd is distributed in the hope that it will be useful, but
16   WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public License
21   along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 -->
23
24 <refentry id="sd_journal_get_data">
25
26         <refentryinfo>
27                 <title>sd_journal_get_data</title>
28                 <productname>systemd</productname>
29
30                 <authorgroup>
31                         <author>
32                                 <contrib>Developer</contrib>
33                                 <firstname>Lennart</firstname>
34                                 <surname>Poettering</surname>
35                                 <email>lennart@poettering.net</email>
36                         </author>
37                 </authorgroup>
38         </refentryinfo>
39
40         <refmeta>
41                 <refentrytitle>sd_journal_get_data</refentrytitle>
42                 <manvolnum>3</manvolnum>
43         </refmeta>
44
45         <refnamediv>
46                 <refname>sd_journal_get_data</refname>
47                 <refname>sd_journal_enumerate_data</refname>
48                 <refname>sd_journal_restart_data</refname>
49                 <refname>SD_JOURNAL_FOREACH_DATA</refname>
50                 <refname>sd_journal_set_data_threshold</refname>
51                 <refname>sd_journal_get_data_threshold</refname>
52                 <refpurpose>Read data fields from the current journal entry</refpurpose>
53         </refnamediv>
54
55         <refsynopsisdiv>
56                 <funcsynopsis>
57                         <funcsynopsisinfo>#include &lt;systemd/sd-journal.h&gt;</funcsynopsisinfo>
58
59                         <funcprototype>
60                                 <funcdef>int <function>sd_journal_get_data</function></funcdef>
61                                 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
62                                 <paramdef>const char *<parameter>field</parameter></paramdef>
63                                 <paramdef>const void **<parameter>data</parameter></paramdef>
64                                 <paramdef>size_t *<parameter>length</parameter></paramdef>
65                         </funcprototype>
66
67                         <funcprototype>
68                                 <funcdef>int <function>sd_journal_enumerate_data</function></funcdef>
69                                 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
70                                 <paramdef>const void **<parameter>data</parameter></paramdef>
71                                 <paramdef>size_t *<parameter>length</parameter></paramdef>
72                         </funcprototype>
73
74                         <funcprototype>
75                                 <funcdef>void <function>sd_journal_restart_data</function></funcdef>
76                                 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
77                         </funcprototype>
78
79                         <funcprototype>
80                                 <funcdef><function>SD_JOURNAL_FOREACH_DATA</function></funcdef>
81                                 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
82                                 <paramdef>const void *<parameter>data</parameter></paramdef>
83                                 <paramdef>size_t <parameter>length</parameter></paramdef>
84                         </funcprototype>
85
86                         <funcprototype>
87                                 <funcdef>int <function>sd_journal_set_data_threshold</function></funcdef>
88                                 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
89                                 <paramdef>size_t <parameter>sz</parameter></paramdef>
90                         </funcprototype>
91
92                         <funcprototype>
93                                 <funcdef>int <function>sd_journal_get_data_threshold</function></funcdef>
94                                 <paramdef>sd_journal *<parameter>j</parameter></paramdef>
95                                 <paramdef>size_t *<parameter>sz</parameter></paramdef>
96                         </funcprototype>
97                 </funcsynopsis>
98         </refsynopsisdiv>
99
100         <refsect1>
101                 <title>Description</title>
102
103                 <para><function>sd_journal_get_data()</function> gets
104                 the data object associated with a specific field from
105                 the current journal entry. It takes four arguments:
106                 the journal context object, a string with the field
107                 name to request, plus a pair of pointers to
108                 pointer/size variables where the data object and its
109                 size shall be stored in. The field name should be an
110                 entry field name. Well-known field names are listed in
111                 <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>. The
112                 returned data is in a read-only memory map and is only
113                 valid until the next invocation of
114                 <function>sd_journal_get_data()</function> or
115                 <function>sd_journal_enumerate_data()</function>, or
116                 the read pointer is altered. Note that the data
117                 returned will be prefixed with the field name and
118                 '='. Also note that by default data fields larger than
119                 64K might get truncated to 64K. This threshold may be
120                 changed and turned off with
121                 <function>sd_journal_set_data_threshold()</function> (see
122                 below).</para>
123
124                 <para><function>sd_journal_enumerate_data()</function>
125                 may be used to iterate through all fields of the
126                 current entry. On each invocation the data for the
127                 next field is returned. The order of these fields is
128                 not defined. The data returned is in the same format
129                 as with <function>sd_journal_get_data()</function> and
130                 also follows the same life-time semantics.</para>
131
132                 <para><function>sd_journal_restart_data()</function>
133                 resets the data enumeration index to the beginning of
134                 the entry. The next invocation of
135                 <function>sd_journal_enumerate_data()</function> will return the first
136                 field of the entry again.</para>
137
138                 <para>Note that the
139                 <function>SD_JOURNAL_FOREACH_DATA()</function> macro
140                 may be used as a handy wrapper around
141                 <function>sd_journal_restart_data()</function> and
142                 <function>sd_journal_enumerate_data()</function>.</para>
143
144                 <para>Note that these functions will not work before
145                 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
146                 (or related call) has been called at least
147                 once, in order to position the read pointer at a valid entry.</para>
148
149                 <para><function>sd_journal_set_data_threshold()</function>
150                 may be used to change the data field size threshold
151                 for data returned by
152                 <function>sd_journal_get_data()</function>,
153                 <function>sd_journal_enumerate_data()</function> and
154                 <function>sd_journal_enumerate_unique()</function>. This
155                 threshold is a hint only: it indicates that the client
156                 program is interested only in the initial parts of the
157                 data fields, up to the threshold in size -- but the
158                 library might still return larger data objects. That
159                 means applications should not rely exclusively on this
160                 setting to limit the size of the data fields returned,
161                 but need to apply a explicit size limit on the
162                 returned data as well. This threshold defaults to 64K
163                 by default. To retrieve the complete data fields this
164                 threshold should be turned off by setting it to 0, so
165                 that the library always returns the complete data
166                 objects. It is recommended to set this threshold as
167                 low as possible since this relieves the library from
168                 having to decompress large compressed data objects in
169                 full.</para>
170
171                 <para><function>sd_journal_get_data_threshold()</function>
172                 returns the currently configured data field size
173                 threshold.</para>
174         </refsect1>
175
176         <refsect1>
177                 <title>Return Value</title>
178
179                 <para><function>sd_journal_get_data()</function>
180                 returns 0 on success or a negative errno-style error
181                 code. If the current entry does not include the
182                 specified field, -ENOENT is returned. If
183                 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
184                 has not been called at least once, -EADDRNOTAVAIL is
185                 returned. <function>sd_journal_enumerate_data()</function>
186                 returns a positive integer if the next field has been
187                 read, 0 when no more fields are known, or a negative
188                 errno-style error
189                 code. <function>sd_journal_restart_data()</function>
190                 returns
191                 nothing. <function>sd_journal_set_data_threshold()</function>
192                 and <function>sd_journal_get_threshold()</function>
193                 return 0 on success or a negative errno-style error
194                 code.</para>
195         </refsect1>
196
197         <refsect1>
198                 <title>Notes</title>
199
200                 <para>The <function>sd_journal_get_data()</function>,
201                 <function>sd_journal_enumerate_data()</function>,
202                 <function>sd_journal_restart_data()</function>,
203                 <function>sd_journal_set_data_threshold()</function>
204                 and
205                 <function>sd_journal_get_data_threshold()</function>
206                 interfaces are available as a shared library, which can
207                 be compiled and linked to with the
208                 <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
209                 file.</para>
210         </refsect1>
211
212         <refsect1>
213                 <title>Examples</title>
214
215                 <para>See
216                 <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>
217                 for a complete example how to use
218                 <function>sd_journal_get_data()</function>.</para>
219
220                 <para>Use the
221                 <function>SD_JOURNAL_FOREACH_DATA</function> macro to
222                 iterate through all fields of the current journal
223                 entry:</para>
224
225                 <programlisting>...
226 int print_fields(sd_journal *j) {
227         const void *data;
228         size_t length;
229         SD_JOURNAL_FOREACH_DATA(j, data, length)
230                 printf("%.*s\n", (int) length, data);
231 }
232 ...</programlisting>
233
234         </refsect1>
235
236         <refsect1>
237                 <title>See Also</title>
238
239                 <para>
240                         <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
241                         <citerefentry><refentrytitle>systemd.journal-fields</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
242                         <citerefentry><refentrytitle>sd-journal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
243                         <citerefentry><refentrytitle>sd_journal_open</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
244                         <citerefentry><refentrytitle>sd_journal_next</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
245                         <citerefentry><refentrytitle>sd_journal_get_realtime_usec</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
246                         <citerefentry><refentrytitle>sd_journal_query_unique</refentrytitle><manvolnum>3</manvolnum></citerefentry>
247                 </para>
248         </refsect1>
249
250 </refentry>