20 # include "../config.h.win"
21 #elif defined( _WIN32_WCE )
22 # include "../config.h.win"
28 # include <stringprep.h>
32 #define JID_PORTION_SIZE 1023
49 static std::string prepare(
const std::string& s,
const Stringprep_profile* profile )
51 if( s.empty() || s.length() > JID_PORTION_SIZE )
54 std::string preppedString;
55 char* p =
static_cast<char*
>( calloc( JID_PORTION_SIZE,
sizeof(
char ) ) );
56 strncpy( p, s.c_str(), s.length() );
57 if( stringprep( p, JID_PORTION_SIZE, (Stringprep_profile_flags)0, profile ) == STRINGPREP_OK )
64 std::string
nodeprep(
const std::string& node )
67 return prepare( node, stringprep_xmpp_nodeprep );
73 std::string
nameprep(
const std::string& domain )
76 return prepare( domain, stringprep_nameprep );
85 return prepare( resource, stringprep_xmpp_resourceprep );
91 std::string
idna(
const std::string& domain )
94 if( domain.empty() || domain.length() > JID_PORTION_SIZE )
97 std::string preppedString;
99 int rc = idna_to_ascii_8z( domain.c_str(), &prepped, (Idna_flags)0 );
100 if( rc == IDNA_SUCCESS )
101 preppedString = prepped;
102 if( rc != IDNA_MALLOC_ERROR )
104 return preppedString;