65924b7e3f78f52e6ec5a0d9b1eb844f285e48e2
[moonshot-ui.git] / libmoonshot / libmoonshot.h
1 /* libmoonshot - Moonshot client library
2  * Copyright (c) 2011, JANET(UK)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * 3. Neither the name of JANET(UK) nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * Author: Sam Thursfield <samthursfield@codethink.co.uk>
33  */
34
35 #ifndef __LIBMOONSHOT_H
36 #define __LIBMOONSHOT_H
37
38 typedef enum {
39     MOONSHOT_ERROR_UNABLE_TO_START_SERVICE,
40     MOONSHOT_ERROR_NO_IDENTITY_SELECTED,
41     MOONSHOT_ERROR_OS_ERROR,
42     MOONSHOT_ERROR_IPC_ERROR
43 } MoonshotErrorCode;
44
45 typedef struct {
46     MoonshotErrorCode  code;
47     char              *message;
48 } MoonshotError;
49
50 void moonshot_error_free (MoonshotError *error);
51
52 /**
53  * moonshot_get_identity:
54  * @nai: Name and issuer constraint for the required identity, or %NULL.
55  * @password: Password for the identity, or %NULL.
56  * @service: Service constraint for the required identity, or %NULL.
57  * @nai_out: A pointer to a string which receives the name and issuer of the
58  *       selected identity.
59  * @password_out: A pointer to a string which receives the password.
60  * @server_certificate_hash_out: Receives a hash of the identity server's
61  *                           certificate, or %NULL.
62  * @ca_certificate_out: The CA certificate, if @server_certificate_hash was
63  *                      %NULL.
64  * @subject_name_constraint_out: Set if @ca_certificate is set, otherwise %NULL.
65  * @subject_alt_name_constraint_out: Set if @ca_certificate is set, otherwise
66  *                                   %NULL.
67  * @error: Return location for a #MoonshotError, or %NULL.
68  *
69  * This function calls the Moonshot server to request an ID card. The server
70  * will be activated if it is not already running. The user interface will be
71  * displayed if there is more than one matching identity and the user will be
72  * asked to select one.
73  *
74  * There are two types of trust anchor that may be returned. If
75  * @server_certificate_hash is non-empty, the remaining parameters will be
76  * empty. Otherwise, the @ca_certificate parameter and the subject name
77  * constraints will be returned.
78  *
79  * Error reporting is handled by a simple mechanism similar to #GError. If
80  * an error occurs, a #MoonshotError object will be stored at *@error, with
81  * a code and message string. This must be freed using moonshot_error_free().
82  *
83  * Return value: %TRUE if an identity was successfully selected, %FALSE on
84  *               failure.
85  */
86 int moonshot_get_identity (const char     *nai,
87                            const char     *password,
88                            const char     *service,
89                            char          **nai_out,
90                            char          **password_out,
91                            char          **server_certificate_hash_out,
92                            char          **ca_certificate_out,
93                            char          **subject_name_constraint_out,
94                            char          **subject_alt_name_constraint_out,
95                            MoonshotError **error);
96
97 #endif