Libstringprep


Introduction

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.

What's new

More details on what's new in the library is found in the NEWS file.

Download

libstringprep-0.0.8.tar.gz [OpenPGP signature ].

All releases can be found in release directory.

Development

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.

How to use it

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;
}

Simon Josefsson
$Id: index.html,v 1.21 2002/12/28 11:38:19 jas Exp $