1 /* property.c --- Callback property handling.
2 * Copyright (C) 2004, 2005 Simon Josefsson
4 * This file is part of GNU SASL Library.
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.
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.
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.
26 map (Gsasl_session
* sctx
, Gsasl_property prop
)
35 case GSASL_ANONYMOUS_TOKEN
:
36 p
= &sctx
->anonymous_token
;
67 case GSASL_SUGGESTED_PIN
:
68 p
= &sctx
->suggestedpin
;
71 case GSASL_GSSAPI_DISPLAY_NAME
:
72 p
= &sctx
->gssapi_display_name
;
88 * @sctx: session handle.
89 * @prop: enumerated value of Gsasl_property type, indicating the
90 * type of data in @data.
91 * @data: zero terminated character string to store.
93 * Make a copy of @data and store it in the session handle for the
94 * indicated property @prop.
96 * You can immediately deallocate @data after calling this function,
97 * without affecting the data stored in the session handle.
102 gsasl_property_set (Gsasl_session
* sctx
, Gsasl_property prop
,
105 gsasl_property_set_raw (sctx
, prop
, data
, data
? strlen (data
) : 0);
109 * gsasl_property_set_raw:
110 * @sctx: session handle.
111 * @prop: enumerated value of Gsasl_property type, indicating the
112 * type of data in @data.
113 * @data: character string to store.
114 * @len: length of character string to store.
116 * Make a copy of @len sized @data and store a zero terminated version
117 * of it in the session handle for the indicated property @prop.
119 * You can immediately deallocate @data after calling this function,
120 * without affecting the data stored in the session handle.
122 * Except for the length indicator, this function is identical to
123 * gsasl_property_set.
128 gsasl_property_set_raw (Gsasl_session
* sctx
, Gsasl_property prop
,
129 const char *data
, size_t len
)
131 char **p
= map (sctx
, prop
);
139 *p
= malloc (len
+ 1);
142 memcpy (*p
, data
, len
);
152 * gsasl_property_fast:
153 * @sctx: session handle.
154 * @prop: enumerated value of Gsasl_property type, indicating the
155 * type of data in @data.
157 * Retrieve the data stored in the session handle for given property
160 * The pointer is to live data, and must not be deallocated or
161 * modified in any way.
163 * This function will not invoke the application callback.
165 * Return value: Return property value, if known, or %NULL if no value
171 gsasl_property_fast (Gsasl_session
* sctx
, Gsasl_property prop
)
173 char **p
= map (sctx
, prop
);
182 * gsasl_property_get:
183 * @sctx: session handle.
184 * @prop: enumerated value of Gsasl_property type, indicating the
185 * type of data in @data.
187 * Retrieve the data stored in the session handle for given property
188 * @prop, possibly invoking the application callback to get the value.
190 * The pointer is to live data, and must not be deallocated or
191 * modified in any way.
193 * This function will invoke the application callback, using
194 * gsasl_callback(), when a property value is not known.
196 * If no value is known, and no callback is specified or if the
197 * callback fail to return data, and if any obsolete callback
198 * functions has been set by the application, this function will try
199 * to call these obsolete callbacks, and store the returned data as
200 * the corresponding property. This behaviour of this function will
201 * be removed when the obsolete callback interfaces are removed.
203 * Return value: Return data for property, or NULL if no value known.
208 gsasl_property_get (Gsasl_session
* sctx
, Gsasl_property prop
)
210 const char *p
= gsasl_property_fast (sctx
, prop
);
214 gsasl_callback (NULL
, sctx
, prop
);
215 p
= gsasl_property_fast (sctx
, prop
);
218 #ifndef GSASL_NO_OBSOLETE
221 Gsasl_client_callback_anonymous cb_anonymous
;
222 Gsasl_client_callback_authorization_id cb_authorization_id
;
223 Gsasl_client_callback_authentication_id cb_authentication_id
;
224 Gsasl_client_callback_password cb_password
;
225 Gsasl_client_callback_passcode cb_passcode
;
226 Gsasl_client_callback_pin cb_pin
;
227 Gsasl_client_callback_service cb_service
;
228 Gsasl_client_callback_realm cb_realm
;
230 size_t buflen
= BUFSIZ
- 1;
235 /* Call obsolete callbacks to get properties. Remove this when
236 * the obsolete callbacks are no longer supported. */
241 cb_service
= gsasl_client_callback_service_get (sctx
->ctx
);
244 res
= cb_service (sctx
, buf
, &buflen
, NULL
, 0, NULL
, 0);
248 gsasl_property_set (sctx
, prop
, buf
);
252 cb_service
= gsasl_client_callback_service_get (sctx
->ctx
);
255 res
= cb_service (sctx
, NULL
, 0, buf
, &buflen
, NULL
, 0);
259 gsasl_property_set (sctx
, prop
, buf
);
262 case GSASL_ANONYMOUS_TOKEN
:
263 cb_anonymous
= gsasl_client_callback_anonymous_get (sctx
->ctx
);
266 res
= cb_anonymous (sctx
, buf
, &buflen
);
270 gsasl_property_set (sctx
, prop
, buf
);
274 cb_authentication_id
=
275 gsasl_client_callback_authentication_id_get (sctx
->ctx
);
276 if (!cb_authentication_id
)
278 res
= cb_authentication_id (sctx
, buf
, &buflen
);
282 gsasl_property_set (sctx
, prop
, buf
);
286 cb_authorization_id
=
287 gsasl_client_callback_authorization_id_get (sctx
->ctx
);
288 if (!cb_authorization_id
)
290 res
= cb_authorization_id (sctx
, buf
, &buflen
);
294 gsasl_property_set (sctx
, prop
, buf
);
298 cb_password
= gsasl_client_callback_password_get (sctx
->ctx
);
301 res
= cb_password (sctx
, buf
, &buflen
);
305 gsasl_property_set (sctx
, prop
, buf
);
309 cb_passcode
= gsasl_client_callback_passcode_get (sctx
->ctx
);
312 res
= cb_passcode (sctx
, buf
, &buflen
);
316 gsasl_property_set (sctx
, prop
, buf
);
320 cb_pin
= gsasl_client_callback_pin_get (sctx
->ctx
);
323 res
= cb_pin (sctx
, sctx
->suggestedpin
, buf
, &buflen
);
327 gsasl_property_set (sctx
, prop
, buf
);
331 cb_realm
= gsasl_client_callback_realm_get (sctx
->ctx
);
334 res
= cb_realm (sctx
, buf
, &buflen
);
338 gsasl_property_set (sctx
, prop
, buf
);
345 p
= gsasl_property_fast (sctx
, prop
);