18 # include <stringprep.h>
27 #define JID_PORTION_SIZE 1023
44 static bool prepare(
const std::string& s, std::string& out,
const Stringprep_profile* profile )
46 if( s.empty() || s.length() > JID_PORTION_SIZE )
49 char* p =
static_cast<char*
>( calloc( JID_PORTION_SIZE,
sizeof(
char ) ) );
50 strncpy( p, s.c_str(), s.length() );
51 int rc = stringprep( p, JID_PORTION_SIZE,
static_cast<Stringprep_profile_flags
>( 0 ), profile );
52 if( rc == STRINGPREP_OK )
55 return rc == STRINGPREP_OK;
59 bool nodeprep(
const std::string& node, std::string& out )
62 return prepare( node, out, stringprep_xmpp_nodeprep );
64 if( node.length() > JID_PORTION_SIZE )
71 bool nameprep(
const std::string& domain, std::string& out )
74 return prepare( domain, out, stringprep_nameprep );
76 if( domain.length() > JID_PORTION_SIZE )
86 return prepare( resource, out, stringprep_xmpp_resourceprep );
88 if( resource.length() > JID_PORTION_SIZE )
95 bool saslprep(
const std::string& input, std::string& out )
98 return prepare( input, out, stringprep_saslprep );
100 if( input.length() > JID_PORTION_SIZE )
107 bool idna(
const std::string& domain, std::string& out )
110 if( domain.empty() || domain.length() > JID_PORTION_SIZE )
114 int rc = idna_to_ascii_8z( domain.c_str(), &prepped,
static_cast<Idna_flags
>( IDNA_USE_STD3_ASCII_RULES ) );
115 if( rc == IDNA_SUCCESS )
121 if( rc != IDNA_MALLOC_ERROR )
125 if( domain.length() > JID_PORTION_SIZE )
bool saslprep(const std::string &input, std::string &out)
bool idna(const std::string &domain, std::string &out)
bool resourceprep(const std::string &resource, std::string &out)
bool nodeprep(const std::string &node, std::string &out)
bool nameprep(const std::string &domain, std::string &out)
The namespace for the gloox library.