libstringprep is a library that implement the IETF stringprep specification, used to implement e.g. IDNA. If you do not know what stringprep is, I suggest using the following resources:
The library is licensed under LGPL.
The library includes profiles for nameprep (IDN) and Kerberos 5 (draft), but adding more profiles is trivial.
More details on what's new in the library is found in the NEWS file.
libstringprep-0.0.8.tar.gz [OpenPGP signature ].
All releases can be found in release directory.
Source code is available via CVS (just press enter at the password prompt):
$ cvs -d :pserver:anoncvs@yxa.extundo.com:/home/public-cvs login
Logging in to :pserver:anoncvs@yxa.extundo.com:2401/home/public-cvs
CVS password:
$ cvs -d :pserver:anoncvs@yxa.extundo.com:/home/public-cvs co libstringprep
The CVS repository can also be access by using the HTML interface.
Read data from user, convert it to UTF-8 and then pass it to stringprep(). Example code below (it is included in the distribution as example.c). To simplify compiling, use libtool and pkg-config. For more information, see the README file in the distribution.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stringprep_nameprep.h>
/*
* Compiling using libtool and pkg-config is recommended:
*
* $ libtool cc -o example example.c `pkg-config --cflags --libs libstringprep`
* $ ./example
* Input string encoded as `ISO-8859-1': ª
* Before locale2utf8 (length 2): aa 0a
* Before stringprep (length 3): c2 aa 0a
* After stringprep (length 2): 61 0a
* $
*
*/
int main(int argc, char *argv[])
{
char buf[BUFSIZ];
char *p;
int rc, i;
printf("Input string encoded as `%s': ",
stringprep_locale_charset ());
fflush(stdout);
fgets(buf, BUFSIZ, stdin);
printf("Before locale2utf8 (length %d): ", strlen(buf));
for (i=0; i < strlen(buf); i++)
printf("%02x ", buf[i] & 0xFF);
printf("\n");
p = stringprep_locale_to_utf8 (buf);
if (p)
{
strcpy(buf, p);
free(p);
}
else
printf("Could not convert string to UTF-8, continuing anyway...\n");
printf("Before stringprep (length %d): ", strlen(buf));
for (i=0; i < strlen(buf); i++)
printf("%02x ", buf[i] & 0xFF);
printf("\n");
rc = stringprep(buf, BUFSIZ, 0, stringprep_nameprep);
if (rc != STRINGPREP_OK)
printf("Stringprep failed with rc %d...\n", rc);
else
{
printf("After stringprep (length %d): ", strlen(buf));
for (i=0; i < strlen(buf); i++)
printf("%02x ", buf[i] & 0xFF);
printf("\n");
}
return 0;
}