gsasl  2.2.0
About: GNU SASL is an implementation of the Simple Authentication and Security Layer (SASL).
  Fossies Dox: gsasl-2.2.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
callback.c
Go to the documentation of this file.
1/* callback.c --- Callback handling.
2 * Copyright (C) 2002-2022 Simon Josefsson
3 *
4 * This file is part of GNU SASL Library.
5 *
6 * GNU SASL Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * GNU SASL Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License License along with GNU SASL Library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "internal.h"
24
25/**
26 * gsasl_callback_set:
27 * @ctx: handle received from gsasl_init().
28 * @cb: pointer to function implemented by application.
29 *
30 * Store the pointer to the application provided callback in the
31 * library handle. The callback will be used, via gsasl_callback(),
32 * by mechanisms to discover various parameters (such as username and
33 * passwords). The callback function will be called with a
34 * Gsasl_property value indicating the requested behaviour. For
35 * example, for %GSASL_ANONYMOUS_TOKEN, the function is expected to
36 * invoke gsasl_property_set(@CTX, %GSASL_ANONYMOUS_TOKEN, "token")
37 * where "token" is the anonymous token the application wishes the
38 * SASL mechanism to use. See the manual for the meaning of all
39 * parameters.
40 *
41 * Since: 0.2.0
42 **/
43void
45{
46 ctx->cb = cb;
47}
48
49/**
50 * gsasl_callback:
51 * @ctx: handle received from gsasl_init(), may be NULL to derive it
52 * from @sctx.
53 * @sctx: session handle.
54 * @prop: enumerated value of Gsasl_property type.
55 *
56 * Invoke the application callback. The @prop value indicate what the
57 * callback is expected to do. For example, for
58 * %GSASL_ANONYMOUS_TOKEN, the function is expected to invoke
59 * gsasl_property_set(@SCTX, %GSASL_ANONYMOUS_TOKEN, "token") where
60 * "token" is the anonymous token the application wishes the SASL
61 * mechanism to use. See the manual for the meaning of all
62 * parameters.
63 *
64 * Return value: Returns whatever the application callback returns, or
65 * %GSASL_NO_CALLBACK if no application was known.
66 *
67 * Since: 0.2.0
68 **/
69int
71{
72 if (ctx == NULL && sctx == NULL)
73 return GSASL_NO_CALLBACK;
74
75 if (ctx == NULL)
76 ctx = sctx->ctx;
77
78 if (ctx->cb)
79 return ctx->cb (ctx, sctx, prop);
80
81 return GSASL_NO_CALLBACK;
82}
83
84/**
85 * gsasl_callback_hook_set:
86 * @ctx: libgsasl handle.
87 * @hook: opaque pointer to application specific data.
88 *
89 * Store application specific data in the libgsasl handle.
90 *
91 * The application data can be later (for instance, inside a callback)
92 * be retrieved by calling gsasl_callback_hook_get(). This is
93 * normally used by the application to maintain a global state between
94 * the main program and callbacks.
95 *
96 * Since: 0.2.0
97 **/
98void
99gsasl_callback_hook_set (Gsasl * ctx, void *hook)
100{
101 ctx->application_hook = hook;
102}
103
104/**
105 * gsasl_callback_hook_get:
106 * @ctx: libgsasl handle.
107 *
108 * Retrieve application specific data from libgsasl handle.
109 *
110 * The application data is set using gsasl_callback_hook_set(). This
111 * is normally used by the application to maintain a global state
112 * between the main program and callbacks.
113 *
114 * Return value: Returns the application specific data, or NULL.
115 *
116 * Since: 0.2.0
117 **/
118void *
120{
121 return ctx->application_hook;
122}
123
124/**
125 * gsasl_session_hook_set:
126 * @sctx: libgsasl session handle.
127 * @hook: opaque pointer to application specific data.
128 *
129 * Store application specific data in the libgsasl session handle.
130 *
131 * The application data can be later (for instance, inside a callback)
132 * be retrieved by calling gsasl_session_hook_get(). This is normally
133 * used by the application to maintain a per-session state between the
134 * main program and callbacks.
135 *
136 * Since: 0.2.14
137 **/
138void
140{
141 sctx->application_hook = hook;
142}
143
144/**
145 * gsasl_session_hook_get:
146 * @sctx: libgsasl session handle.
147 *
148 * Retrieve application specific data from libgsasl session handle.
149 *
150 * The application data is set using gsasl_callback_hook_set(). This
151 * is normally used by the application to maintain a per-session state
152 * between the main program and callbacks.
153 *
154 * Return value: Returns the application specific data, or NULL.
155 *
156 * Since: 0.2.14
157 **/
158void *
160{
161 return sctx->application_hook;
162}
void * gsasl_callback_hook_get(Gsasl *ctx)
Definition: callback.c:119
void * gsasl_session_hook_get(Gsasl_session *sctx)
Definition: callback.c:159
void gsasl_callback_set(Gsasl *ctx, Gsasl_callback_function cb)
Definition: callback.c:44
void gsasl_session_hook_set(Gsasl_session *sctx, void *hook)
Definition: callback.c:139
int gsasl_callback(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
Definition: callback.c:70
void gsasl_callback_hook_set(Gsasl *ctx, void *hook)
Definition: callback.c:99
int(* Gsasl_callback_function)(Gsasl *ctx, Gsasl_session *sctx, Gsasl_property prop)
Definition: gsasl.h:286
@ GSASL_NO_CALLBACK
Definition: gsasl.h:142
Gsasl_property
Definition: gsasl.h:222
void * application_hook
Definition: internal.h:58
Gsasl * ctx
Definition: internal.h:54
Definition: internal.h:41
void * application_hook
Definition: internal.h:48
Gsasl_callback_function cb
Definition: internal.h:47