Include internal.h for uint32_t and use it.
[libidn.git] / example3.c
blob4277d40c079540de963c1c91c8465b2e5a6db4da
1 /* example3.c Example code showing how to use Libidn.
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of GNU Libidn.
6 * GNU Libidn 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 * GNU Libidn 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 GNU Libidn; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stringprep.h> /* stringprep_locale_charset() */
26 #include <idna.h> /* idna_locale_to_ace() */
29 * Compiling using libtool and pkg-config is recommended:
31 * $ libtool cc -o example3 example3.c `pkg-config --cflags --libs libidn`
32 * $ ./example3
33 * Input domain encoded as `ISO-8859-1': www.räksmörgåsª.example
34 * Read string (length 23): 77 77 77 2e 72 e4 6b 73 6d f6 72 67 e5 73 aa 2e 65 78 61 6d 70 6c 65
35 * ACE label (length 33): 'www.xn--rksmrgsa-0zap8p.example'
36 * 77 77 77 2e 78 6e 2d 2d 72 6b 73 6d 72 67 73 61 2d 30 7a 61 70 38 70 2e 65 78 61 6d 70 6c 65
37 * $
41 int
42 main (int argc, char *argv[])
44 char buf[BUFSIZ];
45 char *p;
46 int rc;
47 size_t i;
49 printf ("Input domain encoded as `%s': ", stringprep_locale_charset ());
50 fflush (stdout);
51 fgets (buf, BUFSIZ, stdin);
52 buf[strlen (buf) - 1] = '\0';
54 printf ("Read string (length %d): ", strlen (buf));
55 for (i = 0; i < strlen (buf); i++)
56 printf ("%02x ", buf[i] & 0xFF);
57 printf ("\n");
59 rc = idna_locale_to_ace (buf, &p);
60 if (rc != IDNA_SUCCESS)
62 printf ("ToASCII() failed... %d\n", rc);
63 exit (1);
66 printf ("ACE label (length %d): '%s'\n", strlen (p), p);
67 for (i = 0; i < strlen (p); i++)
68 printf ("%02x ", p[i] & 0xFF);
69 printf ("\n");
71 free (p);
73 return 0;