property.c

Go to the documentation of this file.
00001 /* property.c --- Callback property handling.
00002  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010  Simon Josefsson
00003  *
00004  * This file is part of GNU SASL Library.
00005  *
00006  * GNU SASL Library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License
00008  * as published by the Free Software Foundation; either version 2.1 of
00009  * the License, or (at your option) any later version.
00010  *
00011  * GNU SASL Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License License along with GNU SASL Library; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "internal.h"
00024 
00025 static char **
00026 map (Gsasl_session * sctx, Gsasl_property prop)
00027 {
00028   char **p = NULL;
00029 
00030   if (!sctx)
00031     return NULL;
00032 
00033   switch (prop)
00034     {
00035     case GSASL_ANONYMOUS_TOKEN:
00036       p = &sctx->anonymous_token;
00037       break;
00038 
00039     case GSASL_SERVICE:
00040       p = &sctx->service;
00041       break;
00042 
00043     case GSASL_HOSTNAME:
00044       p = &sctx->hostname;
00045       break;
00046 
00047     case GSASL_AUTHID:
00048       p = &sctx->authid;
00049       break;
00050 
00051     case GSASL_AUTHZID:
00052       p = &sctx->authzid;
00053       break;
00054 
00055     case GSASL_PASSWORD:
00056       p = &sctx->password;
00057       break;
00058 
00059     case GSASL_PASSCODE:
00060       p = &sctx->passcode;
00061       break;
00062 
00063     case GSASL_PIN:
00064       p = &sctx->pin;
00065       break;
00066 
00067     case GSASL_SUGGESTED_PIN:
00068       p = &sctx->suggestedpin;
00069       break;
00070 
00071     case GSASL_GSSAPI_DISPLAY_NAME:
00072       p = &sctx->gssapi_display_name;
00073       break;
00074 
00075     case GSASL_REALM:
00076       p = &sctx->realm;
00077       break;
00078 
00079     case GSASL_DIGEST_MD5_HASHED_PASSWORD:
00080       p = &sctx->digest_md5_hashed_password;
00081       break;
00082 
00083     case GSASL_QOPS:
00084       p = &sctx->qops;
00085       break;
00086 
00087     case GSASL_QOP:
00088       p = &sctx->qop;
00089       break;
00090 
00091     case GSASL_SCRAM_ITER:
00092       p = &sctx->scram_iter;
00093       break;
00094 
00095     case GSASL_SCRAM_SALT:
00096       p = &sctx->scram_salt;
00097       break;
00098 
00099     case GSASL_SCRAM_SALTED_PASSWORD:
00100       p = &sctx->scram_salted_password;
00101       break;
00102 
00103     case GSASL_SAML20_IDP_IDENTIFIER:
00104       p = &sctx->saml20_idp_identifier;
00105       break;
00106 
00107     case GSASL_SAML20_REDIRECT_URL:
00108       p = &sctx->saml20_redirect_url;
00109       break;
00110 
00111       /* If you add anything here, remember to change change
00112          gsasl_finish() in xfinish.c and Gsasl_session in
00113          internal.h.  */
00114 
00115     default:
00116       break;
00117     }
00118 
00119   return p;
00120 }
00121 
00137 void
00138 gsasl_property_set (Gsasl_session * sctx, Gsasl_property prop,
00139                     const char *data)
00140 {
00141   gsasl_property_set_raw (sctx, prop, data, data ? strlen (data) : 0);
00142 }
00143 
00163 void
00164 gsasl_property_set_raw (Gsasl_session * sctx, Gsasl_property prop,
00165                         const char *data, size_t len)
00166 {
00167   char **p = map (sctx, prop);
00168 
00169   if (p)
00170     {
00171       free (*p);
00172       if (data)
00173         {
00174           *p = malloc (len + 1);
00175           if (*p)
00176             {
00177               memcpy (*p, data, len);
00178               (*p)[len] = '\0';
00179             }
00180         }
00181       else
00182         *p = NULL;
00183     }
00184 }
00185 
00205 const char *
00206 gsasl_property_fast (Gsasl_session * sctx, Gsasl_property prop)
00207 {
00208   char **p = map (sctx, prop);
00209 
00210   if (p)
00211     return *p;
00212 
00213   return NULL;
00214 }
00215 
00242 const char *
00243 gsasl_property_get (Gsasl_session * sctx, Gsasl_property prop)
00244 {
00245   const char *p = gsasl_property_fast (sctx, prop);
00246 
00247   if (!p)
00248     {
00249       gsasl_callback (NULL, sctx, prop);
00250       p = gsasl_property_fast (sctx, prop);
00251     }
00252 
00253 #ifndef GSASL_NO_OBSOLETE
00254   if (!p)
00255     p = _gsasl_obsolete_property_map (sctx, prop);
00256 #endif
00257 
00258   return p;
00259 }