STORE 'file' scheme loader: refactor the treatment of matches
[openssl.git] / doc / man3 / OSSL_STORE_open.pod
1 =pod
2
3 =head1 NAME
4
5 OSSL_STORE_CTX, OSSL_STORE_post_process_info_fn, OSSL_STORE_open,
6 OSSL_STORE_ctrl, OSSL_STORE_load, OSSL_STORE_eof, OSSL_STORE_error,
7 OSSL_STORE_close - Types and functions to read objects from a URI
8
9 =head1 SYNOPSIS
10
11  #include <openssl/store.h>
12  
13  typedef struct ossl_store_ctx_st OSSL_STORE_CTX;
14
15  typedef OSSL_STORE_INFO *(*OSSL_STORE_post_process_info_fn)(OSSL_STORE_INFO *,
16                                                              void *);
17
18  OSSL_STORE_CTX *OSSL_STORE_open(const char *uri, const UI_METHOD *ui_method,
19                                  void *ui_data,
20                                  OSSL_STORE_post_process_info_fn post_process,
21                                  void *post_process_data);
22  int OSSL_STORE_ctrl(OSSL_STORE_CTX *ctx, int cmd, ... /* args */);
23  OSSL_STORE_INFO *OSSL_STORE_load(OSSL_STORE_CTX *ctx);
24  int OSSL_STORE_eof(OSSL_STORE_CTX *ctx);
25  int OSSL_STORE_error(OSSL_STORE_CTX *ctx);
26  int OSSL_STORE_close(OSSL_STORE_CTX *ctx);
27
28 =head1 DESCRIPTION
29
30 These functions help the application to fetch supported objects (see
31 L<OSSL_STORE_INFO(3)/SUPPORTED OBJECTS> for information on which those are)
32 from a given URI (see L</SUPPORTED SCHEMES> for more information on
33 the supported URI schemes).
34 The general method to do so is to "open" the URI using OSSL_STORE_open(),
35 read each available and supported object using OSSL_STORE_load() as long as
36 OSSL_STORE_eof() hasn't been reached, and finish it off with OSSL_STORE_close().
37
38 The retrieved information is stored in a B<OSSL_STORE_INFO>, which is further
39 described in L<OSSL_STORE_INFO(3)>.
40
41 =head2 Types
42
43 B<OSSL_STORE_CTX> is a context variable that holds all the internal
44 information for OSSL_STORE_open(), OSSL_STORE_load(), OSSL_STORE_eof() and
45 OSSL_STORE_close() to work together.
46
47 =head2 Functions
48
49 OSSL_STORE_open() takes a uri or path B<uri>, password UI method
50 B<ui_method> with associated data B<ui_data>, and post processing
51 callback B<post_process> with associated data B<post_process_data>,
52 opens a channel to the data located at that URI and returns a
53 B<OSSL_STORE_CTX> with all necessary internal information.
54 The given B<ui_method> and B<ui_data_data> will be reused by all
55 functions that use B<OSSL_STORE_CTX> when interaction is needed.
56 The given B<post_process> and B<post_process_data> will be reused by
57 OSSL_STORE_load() to manipulate or drop the value to be returned.
58
59 OSSL_STORE_ctrl() takes a B<OSSL_STORE_CTX>, and command number B<cmd> and
60 more arguments not specified here.
61 The available command numbers and arguments they each take depends on
62 the loader that's used and is documented together with that loader.
63
64 OSSL_STORE_load() takes a B<OSSL_STORE_CTX>, tries to load the next available
65 object and return it wrapped with  B<OSSL_STORE_INFO>.
66
67 OSSL_STORE_eof() takes a B<OSSL_STORE_CTX> and checks if we've reached the end
68 of data.
69
70 OSSL_STORE_error() takes a B<OSSL_STORE_CTX> and checks if an error occured in
71 the last OSSL_STORE_load() call.
72 Note that it may still be meaningful to try and load more objects, unless
73 OSSL_STORE_eof() shows that the end of data has been reached.
74
75 OSSL_STORE_close() takes a B<OSSL_STORE_CTX>, closes the channel that was opened
76 by OSSL_STORE_open() and frees all other information that was stored in the
77 B<OSSL_STORE_CTX>, as well as the B<OSSL_STORE_CTX> itself.
78
79 =head1 SUPPORTED SCHEMES
80
81 The basic supported scheme is B<file:>.
82 Any other scheme can be added dynamically, using
83 OSSL_STORE_register_loader().
84
85 =head1 NOTES
86
87 When unsure whether a given string contains a simple file or directory
88 reference, or if it's a full blown URI, the question is how to figure
89 that out.
90 One way is to try OSSL_STORE_open_file() and if that fails, try
91 OSSL_STORE_open().
92 The other way is the other way around.
93 Either way you choose, there are corner cases,
94 F<file:/foo/bar/cookie.txt> might very will be a simple file reference
95 on a system that supports the notion of volumes.
96
97 This manual won't tell you which way is better, that's up to each
98 application developer to decide on their own.
99 However, there are some tools that can be used together with
100 OSSL_STORE_open() to determine if any failure is caused by an unparsable
101 URI, or if it's a different error (such as memory allocation
102 failures); if the URI was parsable but the scheme unregistered, the
103 top error will have the reason C<OSSL_STORE_R_UNREGISTERED_SCHEME>.
104 If you decide to use OSSL_STORE_open() with OSSL_STORE_open_file() as a
105 fallback, those reasons can be good tools to decide if the fallback
106 should be taken or not.
107
108 =head1 RETURN VALUES
109
110 OSSL_STORE_open() returns a pointer to a B<OSSL_STORE_CTX> on success, or
111 B<NULL> on failure.
112
113 OSSL_STORE_load() returns a pointer to a B<OSSL_STORE_INFO> on success, or
114 B<NULL> on error or when end of data is reached.
115 Use OSSL_STORE_error() and OSSL_STORE_eof() to determine the meaning of a
116 returned B<NULL>.
117
118 OSSL_STORE_eof() returns 1 if the end of data has been reached, otherwise
119 0.
120
121 OSSL_STORE_error() returns 1 if an error occured in a OSSL_STORE_load() call,
122 otherwise 0.
123
124 OSSL_STORE_ctrl() and OSSL_STORE_close() returns 1 on success, or 0 on failure.
125
126 =head1 SEE ALSO
127
128 L<ossl_store(7)>, L<OSSL_STORE_INFO(3)>, L<OSSL_STORE_register_loader(3)>
129
130 =head1 HISTORY
131
132 OSSL_STORE_CTX(), OSSL_STORE_post_process_info_fn(), OSSL_STORE_open(),
133 OSSL_STORE_ctrl(), OSSL_STORE_load(), OSSL_STORE_eof() and OSSL_STORE_close()
134 were added to OpenSSL 1.1.1.
135
136 =head1 COPYRIGHT
137
138 Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
139
140 Licensed under the OpenSSL license (the "License").  You may not use
141 this file except in compliance with the License.  You can obtain a copy
142 in the file LICENSE in the source distribution or at
143 L<https://www.openssl.org/source/license.html>.
144
145 =cut