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
26 _gsasl_gettext (const char *str
)
28 return dgettext (PACKAGE
, str
);
32 _gsasl_gettext_init ()
34 bindtextdomain(PACKAGE
, LOCALEDIR
);
35 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
36 bind_textdomain_codeset (PACKAGE
, "UTF-8");
40 #endif /* ENABLE_NLS */
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
50 * Return value: GSASL_OK iff successful, otherwise GSASL_MALLOC_ERROR.
53 gsasl_init (Gsasl_ctx
**ctx
)
58 _gsasl_gettext_init();
61 *ctx
= (Gsasl_ctx
*) malloc(sizeof(**ctx
));
63 return GSASL_MALLOC_ERROR
;
65 memset(*ctx
, 0, sizeof(**ctx
));
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));
79 (*ctx
)->client_mechs
= (_Gsasl_mechanism
*)
80 malloc (sizeof(*(*ctx
)->client_mechs
));
82 if ((*ctx
)->client_mechs
== NULL
)
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));
102 (*ctx
)->server_mechs
= (_Gsasl_mechanism
*)
103 malloc (sizeof(*(*ctx
)->server_mechs
));
105 if ((*ctx
)->server_mechs
== NULL
)
108 return GSASL_MALLOC_ERROR
;
111 (*ctx
)->server_mechs
[(*ctx
)->n_server_mechs
] =
112 _gsasl_all_mechanisms
[i
];
113 (*ctx
)->n_server_mechs
++;