<?xml version="1.0"?> <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"> <refentry id="libidn-stringprep"> <refmeta> <refentrytitle role="top_of_page">stringprep</refentrytitle> <manvolnum>3</manvolnum> <refmiscinfo>LIBIDN Library</refmiscinfo> </refmeta> <refnamediv> <refname>stringprep</refname> <refpurpose></refpurpose> <!--[<xref linkend="desc" endterm="desc.title"/>]--> </refnamediv> <refsynopsisdiv role="synopsis"> <title role="synopsis.title">Synopsis</title> <synopsis> #define <link linkend="STRINGPREP-VERSION:CAPS">STRINGPREP_VERSION</link> enum <link linkend="Stringprep-rc">Stringprep_rc</link>; enum <link linkend="Stringprep-profile-flags">Stringprep_profile_flags</link>; enum <link linkend="Stringprep-profile-steps">Stringprep_profile_steps</link>; #define <link linkend="STRINGPREP-MAX-MAP-CHARS:CAPS">STRINGPREP_MAX_MAP_CHARS</link> struct <link linkend="Stringprep-table-element">Stringprep_table_element</link>; struct <link linkend="Stringprep-table">Stringprep_table</link>; typedef <link linkend="Stringprep-profile">Stringprep_profile</link>; struct <link linkend="Stringprep-profiles">Stringprep_profiles</link>; #define <link linkend="stringprep-nameprep">stringprep_nameprep</link> (in, maxlen) #define <link linkend="stringprep-nameprep-no-unassigned">stringprep_nameprep_no_unassigned</link>(in, maxlen) #define <link linkend="stringprep-plain">stringprep_plain</link> (in, maxlen) #define <link linkend="stringprep-kerberos5">stringprep_kerberos5</link> (in, maxlen) #define <link linkend="stringprep-xmpp-nodeprep">stringprep_xmpp_nodeprep</link> (in, maxlen) #define <link linkend="stringprep-xmpp-resourceprep">stringprep_xmpp_resourceprep</link> (in, maxlen) #define <link linkend="stringprep-iscsi">stringprep_iscsi</link> (in, maxlen) <link linkend="int">int</link> <link linkend="stringprep-4i">stringprep_4i</link> (<link linkend="uint32-t">uint32_t</link> *ucs4, <link linkend="size-t">size_t</link> *len, <link linkend="size-t">size_t</link> maxucs4len, <link linkend="Stringprep-profile-flags">Stringprep_profile_flags</link> flags, const <link linkend="Stringprep-profile">Stringprep_profile</link> *profile); <link linkend="int">int</link> <link linkend="stringprep-4zi">stringprep_4zi</link> (<link linkend="uint32-t">uint32_t</link> *ucs4, <link linkend="size-t">size_t</link> maxucs4len, <link linkend="Stringprep-profile-flags">Stringprep_profile_flags</link> flags, const <link linkend="Stringprep-profile">Stringprep_profile</link> *profile); <link linkend="int">int</link> <link linkend="stringprep">stringprep</link> (<link linkend="char">char</link> *in, <link linkend="size-t">size_t</link> maxlen, <link linkend="Stringprep-profile-flags">Stringprep_profile_flags</link> flags, const <link linkend="Stringprep-profile">Stringprep_profile</link> *profile); <link linkend="int">int</link> <link linkend="stringprep-profile">stringprep_profile</link> (const <link linkend="char">char</link> *in, <link linkend="char">char</link> **out, const <link linkend="char">char</link> *profile, <link linkend="Stringprep-profile-flags">Stringprep_profile_flags</link> flags); const <link linkend="char">char</link>* <link linkend="stringprep-strerror">stringprep_strerror</link> (<link linkend="Stringprep-rc">Stringprep_rc</link> rc); const <link linkend="char">char</link>* <link linkend="stringprep-check-version">stringprep_check_version</link> (const <link linkend="char">char</link> *req_version); <link linkend="int">int</link> <link linkend="stringprep-unichar-to-utf8">stringprep_unichar_to_utf8</link> (<link linkend="uint32-t">uint32_t</link> c, <link linkend="char">char</link> *outbuf); <link linkend="uint32-t">uint32_t</link> <link linkend="stringprep-utf8-to-unichar">stringprep_utf8_to_unichar</link> (const <link linkend="char">char</link> *p); <link linkend="uint32-t">uint32_t</link>* <link linkend="stringprep-utf8-to-ucs4">stringprep_utf8_to_ucs4</link> (const <link linkend="char">char</link> *str, <link linkend="ssize-t">ssize_t</link> len, <link linkend="size-t">size_t</link> *items_written); <link linkend="char">char</link>* <link linkend="stringprep-ucs4-to-utf8">stringprep_ucs4_to_utf8</link> (const <link linkend="uint32-t">uint32_t</link> *str, <link linkend="ssize-t">ssize_t</link> len, <link linkend="size-t">size_t</link> *items_read, <link linkend="size-t">size_t</link> *items_written); <link linkend="char">char</link>* <link linkend="stringprep-utf8-nfkc-normalize">stringprep_utf8_nfkc_normalize</link> (const <link linkend="char">char</link> *str, <link linkend="ssize-t">ssize_t</link> len); <link linkend="uint32-t">uint32_t</link>* <link linkend="stringprep-ucs4-nfkc-normalize">stringprep_ucs4_nfkc_normalize</link> (<link linkend="uint32-t">uint32_t</link> *str, <link linkend="ssize-t">ssize_t</link> len); const <link linkend="char">char</link>* <link linkend="stringprep-locale-charset">stringprep_locale_charset</link> (void); <link linkend="char">char</link>* <link linkend="stringprep-convert">stringprep_convert</link> (const <link linkend="char">char</link> *str, const <link linkend="char">char</link> *to_codeset, const <link linkend="char">char</link> *from_codeset); <link linkend="char">char</link>* <link linkend="stringprep-locale-to-utf8">stringprep_locale_to_utf8</link> (const <link linkend="char">char</link> *str); <link linkend="char">char</link>* <link linkend="stringprep-utf8-to-locale">stringprep_utf8_to_locale</link> (const <link linkend="char">char</link> *str); </synopsis> </refsynopsisdiv> <refsect1 role="desc"> <title role="desc.title">Description</title> <para> </para> </refsect1> <refsect1 role="details"> <title role="details.title">Details</title> <refsect2> <title><anchor id="STRINGPREP-VERSION:CAPS" role="macro"/>STRINGPREP_VERSION</title> <indexterm><primary>STRINGPREP_VERSION</primary></indexterm><programlisting>#define STRINGPREP_VERSION "0.6.14" </programlisting> <para> String defined via CPP denoting the header file version number. Used together with <link linkend="stringprep-check-version"><function>stringprep_check_version()</function></link> to verify header file and run-time library consistency.</para> <para> </para></refsect2> <refsect2> <title><anchor id="Stringprep-rc" role="enum"/>enum Stringprep_rc</title> <indexterm><primary>Stringprep_rc</primary></indexterm><programlisting> typedef enum { STRINGPREP_OK = 0, /* Stringprep errors. */ STRINGPREP_CONTAINS_UNASSIGNED = 1, STRINGPREP_CONTAINS_PROHIBITED = 2, STRINGPREP_BIDI_BOTH_L_AND_RAL = 3, STRINGPREP_BIDI_LEADTRAIL_NOT_RAL = 4, STRINGPREP_BIDI_CONTAINS_PROHIBITED = 5, /* Error in calling application. */ STRINGPREP_TOO_SMALL_BUFFER = 100, STRINGPREP_PROFILE_ERROR = 101, STRINGPREP_FLAG_ERROR = 102, STRINGPREP_UNKNOWN_PROFILE = 103, /* Internal errors. */ STRINGPREP_NFKC_FAILED = 200, STRINGPREP_MALLOC_ERROR = 201 } Stringprep_rc; </programlisting> <para> Enumerated return codes of <link linkend="stringprep"><function>stringprep()</function></link>, <link linkend="stringprep-profile"><function>stringprep_profile()</function></link> functions (and macros using those functions). The value 0 is guaranteed to always correspond to success.</para> <para> </para><variablelist role="enum"> <varlistentry> <term><anchor id="STRINGPREP-OK:CAPS" role="constant"/><literal>STRINGPREP_OK</literal></term> <listitem><simpara> Successful operation. This value is guaranteed to always be zero, the remaining ones are only guaranteed to hold non-zero values, for logical comparison purposes. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-CONTAINS-UNASSIGNED:CAPS" role="constant"/><literal>STRINGPREP_CONTAINS_UNASSIGNED</literal></term> <listitem><simpara> String contain unassigned Unicode code points, which is forbidden by the profile. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-CONTAINS-PROHIBITED:CAPS" role="constant"/><literal>STRINGPREP_CONTAINS_PROHIBITED</literal></term> <listitem><simpara> String contain code points prohibited by the profile. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-BIDI-BOTH-L-AND-RAL:CAPS" role="constant"/><literal>STRINGPREP_BIDI_BOTH_L_AND_RAL</literal></term> <listitem><simpara> String contain code points with conflicting bidirection category. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-BIDI-LEADTRAIL-NOT-RAL:CAPS" role="constant"/><literal>STRINGPREP_BIDI_LEADTRAIL_NOT_RAL</literal></term> <listitem><simpara> Leading and trailing character in string not of proper bidirectional category. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-BIDI-CONTAINS-PROHIBITED:CAPS" role="constant"/><literal>STRINGPREP_BIDI_CONTAINS_PROHIBITED</literal></term> <listitem><simpara> Contains prohibited code points detected by bidirectional code. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-TOO-SMALL-BUFFER:CAPS" role="constant"/><literal>STRINGPREP_TOO_SMALL_BUFFER</literal></term> <listitem><simpara> Buffer handed to function was too small. This usually indicate a problem in the calling application. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-PROFILE-ERROR:CAPS" role="constant"/><literal>STRINGPREP_PROFILE_ERROR</literal></term> <listitem><simpara> The stringprep profile was inconsistent. This usually indicate an internal error in the library. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-FLAG-ERROR:CAPS" role="constant"/><literal>STRINGPREP_FLAG_ERROR</literal></term> <listitem><simpara> The supplied flag conflicted with profile. This usually indicate a problem in the calling application. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-UNKNOWN-PROFILE:CAPS" role="constant"/><literal>STRINGPREP_UNKNOWN_PROFILE</literal></term> <listitem><simpara> The supplied profile name was not known to the library. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-NFKC-FAILED:CAPS" role="constant"/><literal>STRINGPREP_NFKC_FAILED</literal></term> <listitem><simpara> The Unicode NFKC operation failed. This usually indicate an internal error in the library. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-MALLOC-ERROR:CAPS" role="constant"/><literal>STRINGPREP_MALLOC_ERROR</literal></term> <listitem><simpara> The <link linkend="malloc"><function>malloc()</function></link> was out of memory. This is usually a fatal error. </simpara></listitem> </varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="Stringprep-profile-flags" role="enum"/>enum Stringprep_profile_flags</title> <indexterm><primary>Stringprep_profile_flags</primary></indexterm><programlisting> typedef enum { STRINGPREP_NO_NFKC = 1, STRINGPREP_NO_BIDI = 2, STRINGPREP_NO_UNASSIGNED = 4 } Stringprep_profile_flags; </programlisting> <para> Stringprep profile flags.</para> <para> </para><variablelist role="enum"> <varlistentry> <term><anchor id="STRINGPREP-NO-NFKC:CAPS" role="constant"/><literal>STRINGPREP_NO_NFKC</literal></term> <listitem><simpara> Disable the NFKC normalization, as well as selecting the non-NFKC case folding tables. Usually the profile specifies BIDI and NFKC settings, and applications should not override it unless in special situations. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-NO-BIDI:CAPS" role="constant"/><literal>STRINGPREP_NO_BIDI</literal></term> <listitem><simpara> Disable the BIDI step. Usually the profile specifies BIDI and NFKC settings, and applications should not override it unless in special situations. </simpara></listitem> </varlistentry> <varlistentry> <term><anchor id="STRINGPREP-NO-UNASSIGNED:CAPS" role="constant"/><literal>STRINGPREP_NO_UNASSIGNED</literal></term> <listitem><simpara> Make the library return with an error if string contains unassigned characters according to profile. </simpara></listitem> </varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="Stringprep-profile-steps" role="enum"/>enum Stringprep_profile_steps</title> <indexterm><primary>Stringprep_profile_steps</primary></indexterm><programlisting> typedef enum { STRINGPREP_NFKC = 1, STRINGPREP_BIDI = 2, STRINGPREP_MAP_TABLE = 3, STRINGPREP_UNASSIGNED_TABLE = 4, STRINGPREP_PROHIBIT_TABLE = 5, STRINGPREP_BIDI_PROHIBIT_TABLE = 6, STRINGPREP_BIDI_RAL_TABLE = 7, STRINGPREP_BIDI_L_TABLE = 8 } Stringprep_profile_steps; </programlisting> <para> Various steps in the stringprep algorithm. You really want to study the source code to understand this one. Only useful if you want to add another profile.</para> <para> </para></refsect2> <refsect2> <title><anchor id="STRINGPREP-MAX-MAP-CHARS:CAPS" role="macro"/>STRINGPREP_MAX_MAP_CHARS</title> <indexterm><primary>STRINGPREP_MAX_MAP_CHARS</primary></indexterm><programlisting>#define STRINGPREP_MAX_MAP_CHARS 4 </programlisting> <para> Maximum number of code points that can replace a single code point, during stringprep mapping.</para> <para> </para></refsect2> <refsect2> <title><anchor id="Stringprep-table-element" role="struct"/>struct Stringprep_table_element</title> <indexterm><primary>Stringprep_table_element</primary></indexterm><programlisting>struct Stringprep_table_element { uint32_t start; uint32_t end; /* 0 if only one character */ uint32_t map[STRINGPREP_MAX_MAP_CHARS]; /* NULL if end is not 0 */ }; </programlisting> <para> </para></refsect2> <refsect2> <title><anchor id="Stringprep-table" role="struct"/>struct Stringprep_table</title> <indexterm><primary>Stringprep_table</primary></indexterm><programlisting>struct Stringprep_table { Stringprep_profile_steps operation; Stringprep_profile_flags flags; const Stringprep_table_element *table; }; </programlisting> <para> </para></refsect2> <refsect2> <title><anchor id="Stringprep-profile" role="typedef"/>Stringprep_profile</title> <indexterm><primary>Stringprep_profile</primary></indexterm><programlisting> typedef struct Stringprep_table Stringprep_profile; </programlisting> <para> </para></refsect2> <refsect2> <title><anchor id="Stringprep-profiles" role="struct"/>struct Stringprep_profiles</title> <indexterm><primary>Stringprep_profiles</primary></indexterm><programlisting>struct Stringprep_profiles { const char *name; const Stringprep_profile *tables; }; </programlisting> <para> </para></refsect2> <refsect2> <title><anchor id="stringprep-nameprep" role="macro"/>stringprep_nameprep()</title> <indexterm><primary>stringprep_nameprep</primary></indexterm><programlisting>#define stringprep_nameprep(in, maxlen)</programlisting> <para> Prepare the input UTF-8 string according to the nameprep profile. The AllowUnassigned flag is true, use <link linkend="stringprep-nameprep-no-unassigned"><function>stringprep_nameprep_no_unassigned()</function></link> if you want a false AllowUnassigned. Returns 0 iff successful, or an error code.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>in</parameter> :</term> <listitem><simpara> input/ouput array with string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxlen</parameter> :</term> <listitem><simpara> maximum length of input/output array. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-nameprep-no-unassigned" role="macro"/>stringprep_nameprep_no_unassigned()</title> <indexterm><primary>stringprep_nameprep_no_unassigned</primary></indexterm><programlisting>#define stringprep_nameprep_no_unassigned(in, maxlen)</programlisting> <para> Prepare the input UTF-8 string according to the nameprep profile. The AllowUnassigned flag is false, use <link linkend="stringprep-nameprep"><function>stringprep_nameprep()</function></link> for true AllowUnassigned. Returns 0 iff successful, or an error code.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>in</parameter> :</term> <listitem><simpara> input/ouput array with string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxlen</parameter> :</term> <listitem><simpara> maximum length of input/output array. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-plain" role="macro"/>stringprep_plain()</title> <indexterm><primary>stringprep_plain</primary></indexterm><programlisting>#define stringprep_plain(in, maxlen)</programlisting> <para> Prepare the input UTF-8 string according to the draft SASL ANONYMOUS profile. Returns 0 iff successful, or an error code.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>in</parameter> :</term> <listitem><simpara> input/ouput array with string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxlen</parameter> :</term> <listitem><simpara> maximum length of input/output array. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-kerberos5" role="macro"/>stringprep_kerberos5()</title> <indexterm><primary>stringprep_kerberos5</primary></indexterm><programlisting>#define stringprep_kerberos5(in, maxlen)</programlisting> <para> </para><variablelist role="params"> <varlistentry><term><parameter>in</parameter> :</term> <listitem><simpara> </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxlen</parameter> :</term> <listitem><simpara> </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-xmpp-nodeprep" role="macro"/>stringprep_xmpp_nodeprep()</title> <indexterm><primary>stringprep_xmpp_nodeprep</primary></indexterm><programlisting>#define stringprep_xmpp_nodeprep(in, maxlen)</programlisting> <para> Prepare the input UTF-8 string according to the draft XMPP node identifier profile. Returns 0 iff successful, or an error code.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>in</parameter> :</term> <listitem><simpara> input/ouput array with string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxlen</parameter> :</term> <listitem><simpara> maximum length of input/output array. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-xmpp-resourceprep" role="macro"/>stringprep_xmpp_resourceprep()</title> <indexterm><primary>stringprep_xmpp_resourceprep</primary></indexterm><programlisting>#define stringprep_xmpp_resourceprep(in, maxlen)</programlisting> <para> Prepare the input UTF-8 string according to the draft XMPP resource identifier profile. Returns 0 iff successful, or an error code.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>in</parameter> :</term> <listitem><simpara> input/ouput array with string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxlen</parameter> :</term> <listitem><simpara> maximum length of input/output array. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-iscsi" role="macro"/>stringprep_iscsi()</title> <indexterm><primary>stringprep_iscsi</primary></indexterm><programlisting>#define stringprep_iscsi(in, maxlen)</programlisting> <para> Prepare the input UTF-8 string according to the draft iSCSI stringprep profile. Returns 0 iff successful, or an error code.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>in</parameter> :</term> <listitem><simpara> input/ouput array with string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxlen</parameter> :</term> <listitem><simpara> maximum length of input/output array. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-4i" role="function"/>stringprep_4i ()</title> <indexterm><primary>stringprep_4i</primary></indexterm><programlisting><link linkend="int">int</link> stringprep_4i (<link linkend="uint32-t">uint32_t</link> *ucs4, <link linkend="size-t">size_t</link> *len, <link linkend="size-t">size_t</link> maxucs4len, <link linkend="Stringprep-profile-flags">Stringprep_profile_flags</link> flags, const <link linkend="Stringprep-profile">Stringprep_profile</link> *profile);</programlisting> <para> Prepare the input UCS-4 string according to the stringprep profile, and write back the result to the input string. </para> <para> The input is not required to be zero terminated (<parameter>ucs4</parameter>[<parameter>len</parameter>] = 0). The output will not be zero terminated unless <parameter>ucs4</parameter>[<parameter>len</parameter>] = 0. Instead, see <link linkend="stringprep-4zi"><function>stringprep_4zi()</function></link> if your input is zero terminated or if you want the output to be. </para> <para> Since the stringprep operation can expand the string, <parameter>maxucs4len</parameter> indicate how large the buffer holding the string is. This function will not read or write to code points outside that size. </para> <para> The <parameter>flags</parameter> are one of <link linkend="Stringprep-profile-flags"><type>Stringprep_profile_flags</type></link> values, or 0. </para> <para> The <parameter>profile</parameter> contain the <link linkend="Stringprep-profile"><type>Stringprep_profile</type></link> instructions to perform. Your application can define new profiles, possibly re-using the generic stringprep tables that always will be part of the library, or use one of the currently supported profiles.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>ucs4</parameter> :</term> <listitem><simpara> input/output array with string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>len</parameter> :</term> <listitem><simpara> on input, length of input array with Unicode code points, on exit, length of output array with Unicode code points. </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxucs4len</parameter> :</term> <listitem><simpara> maximum length of input/output array. </simpara></listitem></varlistentry> <varlistentry><term><parameter>flags</parameter> :</term> <listitem><simpara> a <link linkend="Stringprep-profile-flags"><type>Stringprep_profile_flags</type></link> value, or 0. </simpara></listitem></varlistentry> <varlistentry><term><parameter>profile</parameter> :</term> <listitem><simpara> pointer to <link linkend="Stringprep-profile"><type>Stringprep_profile</type></link> to use. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Returns <link linkend="STRINGPREP-OK:CAPS"><literal>STRINGPREP_OK</literal></link> iff successful, or an <link linkend="Stringprep-rc"><type>Stringprep_rc</type></link> error code. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-4zi" role="function"/>stringprep_4zi ()</title> <indexterm><primary>stringprep_4zi</primary></indexterm><programlisting><link linkend="int">int</link> stringprep_4zi (<link linkend="uint32-t">uint32_t</link> *ucs4, <link linkend="size-t">size_t</link> maxucs4len, <link linkend="Stringprep-profile-flags">Stringprep_profile_flags</link> flags, const <link linkend="Stringprep-profile">Stringprep_profile</link> *profile);</programlisting> <para> Prepare the input zero terminated UCS-4 string according to the stringprep profile, and write back the result to the input string. </para> <para> Since the stringprep operation can expand the string, <parameter>maxucs4len</parameter> indicate how large the buffer holding the string is. This function will not read or write to code points outside that size. </para> <para> The <parameter>flags</parameter> are one of <link linkend="Stringprep-profile-flags"><type>Stringprep_profile_flags</type></link> values, or 0. </para> <para> The <parameter>profile</parameter> contain the <link linkend="Stringprep-profile"><type>Stringprep_profile</type></link> instructions to perform. Your application can define new profiles, possibly re-using the generic stringprep tables that always will be part of the library, or use one of the currently supported profiles.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>ucs4</parameter> :</term> <listitem><simpara> input/output array with zero terminated string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxucs4len</parameter> :</term> <listitem><simpara> maximum length of input/output array. </simpara></listitem></varlistentry> <varlistentry><term><parameter>flags</parameter> :</term> <listitem><simpara> a <link linkend="Stringprep-profile-flags"><type>Stringprep_profile_flags</type></link> value, or 0. </simpara></listitem></varlistentry> <varlistentry><term><parameter>profile</parameter> :</term> <listitem><simpara> pointer to <link linkend="Stringprep-profile"><type>Stringprep_profile</type></link> to use. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Returns <link linkend="STRINGPREP-OK:CAPS"><literal>STRINGPREP_OK</literal></link> iff successful, or an <link linkend="Stringprep-rc"><type>Stringprep_rc</type></link> error code. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep" role="function"/>stringprep ()</title> <indexterm><primary>stringprep</primary></indexterm><programlisting><link linkend="int">int</link> stringprep (<link linkend="char">char</link> *in, <link linkend="size-t">size_t</link> maxlen, <link linkend="Stringprep-profile-flags">Stringprep_profile_flags</link> flags, const <link linkend="Stringprep-profile">Stringprep_profile</link> *profile);</programlisting> <para> Prepare the input zero terminated UTF-8 string according to the stringprep profile, and write back the result to the input string. </para> <para> Note that you must convert strings entered in the systems locale into UTF-8 before using this function, see <link linkend="stringprep-locale-to-utf8"><function>stringprep_locale_to_utf8()</function></link>. </para> <para> Since the stringprep operation can expand the string, <parameter>maxlen</parameter> indicate how large the buffer holding the string is. This function will not read or write to characters outside that size. </para> <para> The <parameter>flags</parameter> are one of <link linkend="Stringprep-profile-flags"><type>Stringprep_profile_flags</type></link> values, or 0. </para> <para> The <parameter>profile</parameter> contain the <link linkend="Stringprep-profile"><type>Stringprep_profile</type></link> instructions to perform. Your application can define new profiles, possibly re-using the generic stringprep tables that always will be part of the library, or use one of the currently supported profiles.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>in</parameter> :</term> <listitem><simpara> input/ouput array with string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>maxlen</parameter> :</term> <listitem><simpara> maximum length of input/output array. </simpara></listitem></varlistentry> <varlistentry><term><parameter>flags</parameter> :</term> <listitem><simpara> a <link linkend="Stringprep-profile-flags"><type>Stringprep_profile_flags</type></link> value, or 0. </simpara></listitem></varlistentry> <varlistentry><term><parameter>profile</parameter> :</term> <listitem><simpara> pointer to <link linkend="Stringprep-profile"><type>Stringprep_profile</type></link> to use. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Returns <link linkend="STRINGPREP-OK:CAPS"><literal>STRINGPREP_OK</literal></link> iff successful, or an error code. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-profile" role="function"/>stringprep_profile ()</title> <indexterm><primary>stringprep_profile</primary></indexterm><programlisting><link linkend="int">int</link> stringprep_profile (const <link linkend="char">char</link> *in, <link linkend="char">char</link> **out, const <link linkend="char">char</link> *profile, <link linkend="Stringprep-profile-flags">Stringprep_profile_flags</link> flags);</programlisting> <para> Prepare the input zero terminated UTF-8 string according to the stringprep profile, and return the result in a newly allocated variable. </para> <para> Note that you must convert strings entered in the systems locale into UTF-8 before using this function, see <link linkend="stringprep-locale-to-utf8"><function>stringprep_locale_to_utf8()</function></link>. </para> <para> The output <parameter>out</parameter> variable must be deallocated by the caller. </para> <para> The <parameter>flags</parameter> are one of <link linkend="Stringprep-profile-flags"><type>Stringprep_profile_flags</type></link> values, or 0. </para> <para> The <parameter>profile</parameter> specifies the name of the stringprep profile to use. It must be one of the internally supported stringprep profiles.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>in</parameter> :</term> <listitem><simpara> input array with UTF-8 string to prepare. </simpara></listitem></varlistentry> <varlistentry><term><parameter>out</parameter> :</term> <listitem><simpara> output variable with pointer to newly allocate string. </simpara></listitem></varlistentry> <varlistentry><term><parameter>profile</parameter> :</term> <listitem><simpara> name of stringprep profile to use. </simpara></listitem></varlistentry> <varlistentry><term><parameter>flags</parameter> :</term> <listitem><simpara> a <link linkend="Stringprep-profile-flags"><type>Stringprep_profile_flags</type></link> value, or 0. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Returns <link linkend="STRINGPREP-OK:CAPS"><literal>STRINGPREP_OK</literal></link> iff successful, or an error code. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-strerror" role="function"/>stringprep_strerror ()</title> <indexterm><primary>stringprep_strerror</primary></indexterm><programlisting>const <link linkend="char">char</link>* stringprep_strerror (<link linkend="Stringprep-rc">Stringprep_rc</link> rc);</programlisting> <para> Convert a return code integer to a text string. This string can be used to output a diagnostic message to the user. </para> <para> STRINGPREP_OK: Successful operation. This value is guaranteed to always be zero, the remaining ones are only guaranteed to hold non-zero values, for logical comparison purposes. STRINGPREP_CONTAINS_UNASSIGNED: String contain unassigned Unicode code points, which is forbidden by the profile. STRINGPREP_CONTAINS_PROHIBITED: String contain code points prohibited by the profile. STRINGPREP_BIDI_BOTH_L_AND_RAL: String contain code points with conflicting bidirection category. STRINGPREP_BIDI_LEADTRAIL_NOT_RAL: Leading and trailing character in string not of proper bidirectional category. STRINGPREP_BIDI_CONTAINS_PROHIBITED: Contains prohibited code points detected by bidirectional code. STRINGPREP_TOO_SMALL_BUFFER: Buffer handed to function was too small. This usually indicate a problem in the calling application. STRINGPREP_PROFILE_ERROR: The stringprep profile was inconsistent. This usually indicate an internal error in the library. STRINGPREP_FLAG_ERROR: The supplied flag conflicted with profile. This usually indicate a problem in the calling application. STRINGPREP_UNKNOWN_PROFILE: The supplied profile name was not known to the library. STRINGPREP_NFKC_FAILED: The Unicode NFKC operation failed. This usually indicate an internal error in the library. STRINGPREP_MALLOC_ERROR: The <link linkend="malloc"><function>malloc()</function></link> was out of memory. This is usually a fatal error.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>rc</parameter> :</term> <listitem><simpara> a <link linkend="Stringprep-rc"><type>Stringprep_rc</type></link> return code. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Returns a pointer to a statically allocated string containing a description of the error with the return code <parameter>rc</parameter>. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-check-version" role="function"/>stringprep_check_version ()</title> <indexterm><primary>stringprep_check_version</primary></indexterm><programlisting>const <link linkend="char">char</link>* stringprep_check_version (const <link linkend="char">char</link> *req_version);</programlisting> <para> Check that the the version of the library is at minimum the requested one and return the version string; return NULL if the condition is not satisfied. If a NULL is passed to this function, no check is done, but the version string is simply returned. </para> <para> See <link linkend="STRINGPREP-VERSION:CAPS"><literal>STRINGPREP_VERSION</literal></link> for a suitable <parameter>req_version</parameter> string.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>req_version</parameter> :</term> <listitem><simpara> Required version number, or NULL. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Version string of run-time library, or NULL if the run-time library does not meet the required version number. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-unichar-to-utf8" role="function"/>stringprep_unichar_to_utf8 ()</title> <indexterm><primary>stringprep_unichar_to_utf8</primary></indexterm><programlisting><link linkend="int">int</link> stringprep_unichar_to_utf8 (<link linkend="uint32-t">uint32_t</link> c, <link linkend="char">char</link> *outbuf);</programlisting> <para> Converts a single character to UTF-8.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>c</parameter> :</term> <listitem><simpara> a ISO10646 character code </simpara></listitem></varlistentry> <varlistentry><term><parameter>outbuf</parameter> :</term> <listitem><simpara> output buffer, must have at least 6 bytes of space. If <link linkend="NULL:CAPS"><literal>NULL</literal></link>, the length will be computed and returned and nothing will be written to <parameter>outbuf</parameter>. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> number of bytes written. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-utf8-to-unichar" role="function"/>stringprep_utf8_to_unichar ()</title> <indexterm><primary>stringprep_utf8_to_unichar</primary></indexterm><programlisting><link linkend="uint32-t">uint32_t</link> stringprep_utf8_to_unichar (const <link linkend="char">char</link> *p);</programlisting> <para> Converts a sequence of bytes encoded as UTF-8 to a Unicode character. If <parameter>p</parameter> does not point to a valid UTF-8 encoded character, results are undefined.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>p</parameter> :</term> <listitem><simpara> a pointer to Unicode character encoded as UTF-8 </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the resulting character. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-utf8-to-ucs4" role="function"/>stringprep_utf8_to_ucs4 ()</title> <indexterm><primary>stringprep_utf8_to_ucs4</primary></indexterm><programlisting><link linkend="uint32-t">uint32_t</link>* stringprep_utf8_to_ucs4 (const <link linkend="char">char</link> *str, <link linkend="ssize-t">ssize_t</link> len, <link linkend="size-t">size_t</link> *items_written);</programlisting> <para> Convert a string from UTF-8 to a 32-bit fixed width representation as UCS-4, assuming valid UTF-8 input. This function does no error checking on the input.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>str</parameter> :</term> <listitem><simpara> a UTF-8 encoded string </simpara></listitem></varlistentry> <varlistentry><term><parameter>len</parameter> :</term> <listitem><simpara> the maximum length of <parameter>str</parameter> to use. If <parameter>len</parameter> < 0, then the string is nul-terminated. </simpara></listitem></varlistentry> <varlistentry><term><parameter>items_written</parameter> :</term> <listitem><simpara> location to store the number of characters in the result, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a pointer to a newly allocated UCS-4 string. This value must be freed with <link linkend="free"><function>free()</function></link>. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-ucs4-to-utf8" role="function"/>stringprep_ucs4_to_utf8 ()</title> <indexterm><primary>stringprep_ucs4_to_utf8</primary></indexterm><programlisting><link linkend="char">char</link>* stringprep_ucs4_to_utf8 (const <link linkend="uint32-t">uint32_t</link> *str, <link linkend="ssize-t">ssize_t</link> len, <link linkend="size-t">size_t</link> *items_read, <link linkend="size-t">size_t</link> *items_written);</programlisting> <para> Convert a string from a 32-bit fixed width representation as UCS-4. to UTF-8. The result will be terminated with a 0 byte.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>str</parameter> :</term> <listitem><simpara> a UCS-4 encoded string </simpara></listitem></varlistentry> <varlistentry><term><parameter>len</parameter> :</term> <listitem><simpara> the maximum length of <parameter>str</parameter> to use. If <parameter>len</parameter> < 0, then the string is terminated with a 0 character. </simpara></listitem></varlistentry> <varlistentry><term><parameter>items_read</parameter> :</term> <listitem><simpara> location to store number of characters read read, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. </simpara></listitem></varlistentry> <varlistentry><term><parameter>items_written</parameter> :</term> <listitem><simpara> location to store number of bytes written or <link linkend="NULL:CAPS"><literal>NULL</literal></link>. The value here stored does not include the trailing 0 byte. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a pointer to a newly allocated UTF-8 string. This value must be freed with <link linkend="free"><function>free()</function></link>. If an error occurs, <link linkend="NULL:CAPS"><literal>NULL</literal></link> will be returned and <parameter>error</parameter> set. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-utf8-nfkc-normalize" role="function"/>stringprep_utf8_nfkc_normalize ()</title> <indexterm><primary>stringprep_utf8_nfkc_normalize</primary></indexterm><programlisting><link linkend="char">char</link>* stringprep_utf8_nfkc_normalize (const <link linkend="char">char</link> *str, <link linkend="ssize-t">ssize_t</link> len);</programlisting> <para> Converts a string into canonical form, standardizing such issues as whether a character with an accent is represented as a base character and combining accent or as a single precomposed character. </para> <para> The normalization mode is NFKC (ALL COMPOSE). It standardizes differences that do not affect the text content, such as the above-mentioned accent representation. It standardizes the "compatibility" characters in Unicode, such as SUPERSCRIPT THREE to the standard forms (in this case DIGIT THREE). Formatting information may be lost but for most text operations such characters should be considered the same. It returns a result with composed forms rather than a maximally decomposed form.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>str</parameter> :</term> <listitem><simpara> a UTF-8 encoded string. </simpara></listitem></varlistentry> <varlistentry><term><parameter>len</parameter> :</term> <listitem><simpara> length of <parameter>str</parameter>, in bytes, or -1 if <parameter>str</parameter> is nul-terminated. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a newly allocated string, that is the NFKC normalized form of <parameter>str</parameter>. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-ucs4-nfkc-normalize" role="function"/>stringprep_ucs4_nfkc_normalize ()</title> <indexterm><primary>stringprep_ucs4_nfkc_normalize</primary></indexterm><programlisting><link linkend="uint32-t">uint32_t</link>* stringprep_ucs4_nfkc_normalize (<link linkend="uint32-t">uint32_t</link> *str, <link linkend="ssize-t">ssize_t</link> len);</programlisting> <para> Converts UCS4 string into UTF-8 and runs <link linkend="stringprep-utf8-nfkc-normalize"><function>stringprep_utf8_nfkc_normalize()</function></link>.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>str</parameter> :</term> <listitem><simpara> a Unicode string. </simpara></listitem></varlistentry> <varlistentry><term><parameter>len</parameter> :</term> <listitem><simpara> length of <parameter>str</parameter> array, or -1 if <parameter>str</parameter> is nul-terminated. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a newly allocated Unicode string, that is the NFKC normalized form of <parameter>str</parameter>. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-locale-charset" role="function"/>stringprep_locale_charset ()</title> <indexterm><primary>stringprep_locale_charset</primary></indexterm><programlisting>const <link linkend="char">char</link>* stringprep_locale_charset (void);</programlisting> <para> Find out current locale charset. The function respect the CHARSET environment variable, but typically uses nl_langinfo(CODESET) when it is supported. It fall back on "ASCII" if CHARSET isn't set and nl_langinfo isn't supported or return anything. </para> <para> Note that this function return the application's locale's preferred charset (or thread's locale's preffered charset, if your system support thread-specific locales). It does not return what the system may be using. Thus, if you receive data from external sources you cannot in general use this function to guess what charset it is encoded in. Use stringprep_convert from the external representation into the charset returned by this function, to have data in the locale encoding.</para> <para> </para><variablelist role="params"> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Return the character set used by the current locale. It will never return NULL, but use "ASCII" as a fallback. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-convert" role="function"/>stringprep_convert ()</title> <indexterm><primary>stringprep_convert</primary></indexterm><programlisting><link linkend="char">char</link>* stringprep_convert (const <link linkend="char">char</link> *str, const <link linkend="char">char</link> *to_codeset, const <link linkend="char">char</link> *from_codeset);</programlisting> <para> Convert the string from one character set to another using the system's <link linkend="iconv"><function>iconv()</function></link> function.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>str</parameter> :</term> <listitem><simpara> input zero-terminated string. </simpara></listitem></varlistentry> <varlistentry><term><parameter>to_codeset</parameter> :</term> <listitem><simpara> name of destination character set. </simpara></listitem></varlistentry> <varlistentry><term><parameter>from_codeset</parameter> :</term> <listitem><simpara> name of origin character set, as used by <parameter>str</parameter>. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Returns newly allocated zero-terminated string which is <parameter>str</parameter> transcoded into to_codeset. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-locale-to-utf8" role="function"/>stringprep_locale_to_utf8 ()</title> <indexterm><primary>stringprep_locale_to_utf8</primary></indexterm><programlisting><link linkend="char">char</link>* stringprep_locale_to_utf8 (const <link linkend="char">char</link> *str);</programlisting> <para> Convert string encoded in the locale's character set into UTF-8 by using <link linkend="stringprep-convert"><function>stringprep_convert()</function></link>.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>str</parameter> :</term> <listitem><simpara> input zero terminated string. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Returns newly allocated zero-terminated string which is <parameter>str</parameter> transcoded into UTF-8. </simpara></listitem></varlistentry> </variablelist></refsect2> <refsect2> <title><anchor id="stringprep-utf8-to-locale" role="function"/>stringprep_utf8_to_locale ()</title> <indexterm><primary>stringprep_utf8_to_locale</primary></indexterm><programlisting><link linkend="char">char</link>* stringprep_utf8_to_locale (const <link linkend="char">char</link> *str);</programlisting> <para> Convert string encoded in UTF-8 into the locale's character set by using <link linkend="stringprep-convert"><function>stringprep_convert()</function></link>.</para> <para> </para><variablelist role="params"> <varlistentry><term><parameter>str</parameter> :</term> <listitem><simpara> input zero terminated string. </simpara></listitem></varlistentry> <varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> Returns newly allocated zero-terminated string which is <parameter>str</parameter> transcoded into the locale's character set. </simpara></listitem></varlistentry> </variablelist></refsect2> </refsect1> </refentry>