summaryrefslogtreecommitdiff
path: root/wocky/wocky-auth-handler.h
blob: 3d8238bc79b6ea2b74da43c42759042c324edeea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

#ifndef _WOCKY_AUTH_HANDLER_H
#define _WOCKY_AUTH_HANDLER_H

#include <glib.h>

#include "wocky-stanza.h"

G_BEGIN_DECLS

#define WOCKY_TYPE_AUTH_HANDLER (wocky_auth_handler_get_type ())
#define WOCKY_AUTH_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST( \
    (obj), WOCKY_TYPE_AUTH_HANDLER, WockyAuthHandler))
#define WOCKY_IS_AUTH_HANDLER(obj) \
    (G_TYPE_CHECK_INSTANCE_TYPE((obj), WOCKY_TYPE_AUTH_HANDLER))
#define WOCKY_AUTH_HANDLER_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ( \
    (obj), WOCKY_TYPE_AUTH_HANDLER, WockyAuthHandlerIface))

typedef struct _WockyAuthHandler WockyAuthHandler;

/**
 * WockyAuthInitialResponseFunc:
 * @handler: a #WockyAuthHandler object
 * @initial_data: a #GString location to fill with the initial data, or %NULL to ignre
 * @error: an optional location for a #GError to fill, or %NULL
 *
 * Called when authentication begins, if the mechanism allows a
 * response to an implicit challenge during AUTH initiation (which, in
 * XMPP, corresponds to sending the <code>&lt;auth/&gt;</code> stanza
 * to the server).
 *
 * The function should return %TRUE on success and optionally set the
 * @initial_data to a string (allocated using g_malloc()) if there is
 * initial data to send. On error it should return %FALSE and set the
 * error
 *
 * Returns: %TRUE on success, otherwise %FALSE
 **/
typedef gboolean (*WockyAuthInitialResponseFunc) (WockyAuthHandler *handler,
    GString **initial_data,
    GError **error);

/**
 * WockyAuthChallengeFunc:
 * @handler: a #WockyAuthHandler object
 * @data: the challange string
 * @response: a location to fill with a challenge response in a #GString
 * @error: an optional location for a #GError to fill, or %NULL
 *
 * Called During authentication, when a
 * <code>&lt;challenge/&gt;</code> stanza or a
 * <code>&lt;success/&gt;</code> with data is received. The handler
 * should put response data in response (allocate using g_malloc()) if
 * appropriate. The handler is responsible for Base64-encoding
 * responses if appropriate.
 *
 * On success the handler should return %TRUE and on failure it should
 * return %FALSE and must set the error passed via @error.
 *
 * Returns: %TRUE On success, otherwise %FALSE
 **/
typedef gboolean (*WockyAuthAuthDataFunc) (
    WockyAuthHandler *handler,
    const GString *data,
    GString **response,
    GError **error);

/**
 * WockyAuthSuccessFunc:
 * @handler: a #WockyAuthHandler object
 * @error: an optional location for a #GError to fill, or %NULL
 *
 * Called when a <code>&lt;success/&gt;</code> stanza is received
 * during authentication. If no error is returned, then authentication
 * is considered finished. (Typically, an error is only raised if the
 * <code>&lt;success/&gt;</code> stanza was received earlier than
 * expected)
 *
 * Returns: %TRUE on success, otherwise %FALSE
 **/
typedef gboolean (*WockyAuthSuccessFunc) (
    WockyAuthHandler *handler,
    GError **error);

void
wocky_auth_handler_free (WockyAuthHandler *handler);

GType
wocky_auth_handler_get_type (void);

const gchar *
wocky_auth_handler_get_mechanism (WockyAuthHandler *handler);

gboolean
wocky_auth_handler_is_plain (WockyAuthHandler *handler);

gboolean
wocky_auth_handler_get_initial_response (WockyAuthHandler *handler,
    GString **initial_data,
    GError **error);

gboolean
wocky_auth_handler_handle_auth_data (
    WockyAuthHandler *handler,
    const GString *data,
    GString **response,
    GError **error);

gboolean
wocky_auth_handler_handle_success (
    WockyAuthHandler *handler,
    GError **error);

typedef struct _WockyAuthHandlerIface WockyAuthHandlerIface;

/**
 * WockyAuthHandlerIface:
 * @parent: The parent interface.
 * @mechanism: The AUTH mechanism which this handler responds to
 *   challenges for.
 * @plain: Whether the mechanism this handler handles sends secrets in
 *   plaintext.
 * @initial_response_func: Called when the initial <code>&lt;auth
 *  /&gt;</code> stanza is generated
 * @auth_data_func: Called when any authentication data from the
 *   server is received
 * @success_func: Called when a <code>&lt;success/&gt;</code> stanza
 *   is received.
 **/
struct _WockyAuthHandlerIface
{
    GTypeInterface parent;
    gchar *mechanism;
    gboolean plain;
    WockyAuthInitialResponseFunc initial_response_func;
    WockyAuthAuthDataFunc auth_data_func;
    WockyAuthSuccessFunc success_func;
};

G_END_DECLS

#endif /* defined _WOCKY_AUTH_HANDLER_H */