Initial release, version 0.0.0.
[gsasl.git] / lib / init.c
blobfc62397551606cc9c449be812e7030740830e9e0
1 /* init.c entry point for libgsasl
2 * Copyright (C) 2002 Simon Josefsson
4 * This file is part of libgsasl.
6 * Libgsasl is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * Libgsasl 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 along with libgsasl; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "internal.h"
24 #if ENABLE_NLS
25 char *
26 _gsasl_gettext (const char *str)
28 return dgettext (PACKAGE, str);
31 void
32 _gsasl_gettext_init ()
34 bindtextdomain(PACKAGE, LOCALEDIR);
35 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
36 bind_textdomain_codeset (PACKAGE, "UTF-8");
37 #endif
38 textdomain (PACKAGE);
40 #endif /* ENABLE_NLS */
42 /**
43 * gsasl_init:
44 * @ctx: pointer to libgsasl handle.
46 * This functions initializes libgsasl. The handle pointed to by ctx
47 * is valid for use with other libgsasl functions iff this function is
48 * successful.
50 * Return value: GSASL_OK iff successful, otherwise GSASL_MALLOC_ERROR.
51 **/
52 int
53 gsasl_init (Gsasl_ctx **ctx)
55 int i;
57 #if ENABLE_NLS
58 _gsasl_gettext_init();
59 #endif
61 *ctx = (Gsasl_ctx*) malloc(sizeof(**ctx));
62 if (*ctx == NULL)
63 return GSASL_MALLOC_ERROR;
65 memset(*ctx, 0, sizeof(**ctx));
67 i = 0;
68 while (_gsasl_all_mechanisms[i].name)
70 if (_gsasl_all_mechanisms[i].client.init &&
71 _gsasl_all_mechanisms[i].client.init(*ctx) == GSASL_OK)
73 if ((*ctx)->client_mechs)
74 (*ctx)->client_mechs = (_Gsasl_mechanism*)
75 realloc ((*ctx)->client_mechs,
76 sizeof(*(*ctx)->client_mechs) *
77 ((*ctx)->n_client_mechs + 1));
78 else
79 (*ctx)->client_mechs = (_Gsasl_mechanism*)
80 malloc (sizeof(*(*ctx)->client_mechs));
82 if ((*ctx)->client_mechs == NULL)
84 gsasl_done(*ctx);
85 return GSASL_MALLOC_ERROR;
88 (*ctx)->client_mechs[(*ctx)->n_client_mechs] =
89 _gsasl_all_mechanisms[i];
90 (*ctx)->n_client_mechs++;
93 if (_gsasl_all_mechanisms[i].server.init &&
94 _gsasl_all_mechanisms[i].server.init(*ctx) == GSASL_OK)
96 if ((*ctx)->server_mechs)
97 (*ctx)->server_mechs = (_Gsasl_mechanism*)
98 realloc ((*ctx)->server_mechs,
99 sizeof(*(*ctx)->server_mechs) *
100 ((*ctx)->n_server_mechs + 1));
101 else
102 (*ctx)->server_mechs = (_Gsasl_mechanism*)
103 malloc (sizeof(*(*ctx)->server_mechs));
105 if ((*ctx)->server_mechs == NULL)
107 gsasl_done(*ctx);
108 return GSASL_MALLOC_ERROR;
111 (*ctx)->server_mechs[(*ctx)->n_server_mechs] =
112 _gsasl_all_mechanisms[i];
113 (*ctx)->n_server_mechs++;
116 i++;
119 return GSASL_OK;