property.c

Go to the documentation of this file.
00001 /* property.c --- Callback property handling.
00002  * Copyright (C) 2004, 2005, 2008  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 
00082     default:
00083       break;
00084     }
00085 
00086   return p;
00087 }
00088 
00104 void
00105 gsasl_property_set (Gsasl_session * sctx, Gsasl_property prop,
00106                     const char *data)
00107 {
00108   gsasl_property_set_raw (sctx, prop, data, data ? strlen (data) : 0);
00109 }
00110 
00130 void
00131 gsasl_property_set_raw (Gsasl_session * sctx, Gsasl_property prop,
00132                         const char *data, size_t len)
00133 {
00134   char **p = map (sctx, prop);
00135 
00136   if (p)
00137     {
00138       if (*p)
00139         free (*p);
00140       if (data)
00141         {
00142           *p = malloc (len + 1);
00143           if (*p)
00144             {
00145               memcpy (*p, data, len);
00146               (*p)[len] = '\0';
00147             }
00148         }
00149       else
00150         *p = NULL;
00151     }
00152 }
00153 
00173 const char *
00174 gsasl_property_fast (Gsasl_session * sctx, Gsasl_property prop)
00175 {
00176   char **p = map (sctx, prop);
00177 
00178   if (p)
00179     return *p;
00180 
00181   return NULL;
00182 }
00183 
00184 #ifndef GSASL_NO_OBSOLETE
00185 /* Declared in obsolete.c. */
00186 const char *
00187 _gsasl_obsolete_property_map (Gsasl_session * sctx, Gsasl_property prop);
00188 #endif
00189 
00216 const char *
00217 gsasl_property_get (Gsasl_session * sctx, Gsasl_property prop)
00218 {
00219   const char *p = gsasl_property_fast (sctx, prop);
00220 
00221   if (!p)
00222     {
00223       gsasl_callback (NULL, sctx, prop);
00224       p = gsasl_property_fast (sctx, prop);
00225     }
00226 
00227 #ifndef GSASL_NO_OBSOLETE
00228   if (!p)
00229     p = _gsasl_obsolete_property_map (sctx, prop);
00230 #endif
00231 
00232   return p;
00233 }

Generated on Tue Oct 21 18:28:19 2008 for gsasl by  doxygen 1.5.6