23
24
#include<stringprep.h>
25
26
using namespace XMPP;
28
//----------------------------------------------------------------------------
30
//----------------------------------------------------------------------------
34
static bool nameprep(const QString &in, int maxbytes, QString *out)
43
StringPrepCache *that = get_instance();
45
Result *r = that->nameprep_table.find(in);
55
QCString cs = in.utf8();
57
if(stringprep(cs.data(), maxbytes, (Stringprep_profile_flags)0, stringprep_nameprep) != 0)
59
that->nameprep_table.insert(in, new Result);
63
QString norm = QString::fromUtf8(cs);
64
that->nameprep_table.insert(in, new Result(norm));
70
static bool nodeprep(const QString &in, int maxbytes, QString *out)
79
StringPrepCache *that = get_instance();
81
Result *r = that->nodeprep_table.find(in);
91
QCString cs = in.utf8();
93
if(stringprep(cs.data(), maxbytes, (Stringprep_profile_flags)0, stringprep_xmpp_nodeprep) != 0)
95
that->nodeprep_table.insert(in, new Result);
99
QString norm = QString::fromUtf8(cs);
100
that->nodeprep_table.insert(in, new Result(norm));
106
static bool resourceprep(const QString &in, int maxbytes, QString *out)
115
StringPrepCache *that = get_instance();
117
Result *r = that->resourceprep_table.find(in);
127
QCString cs = in.utf8();
129
if(stringprep(cs.data(), maxbytes, (Stringprep_profile_flags)0, stringprep_xmpp_resourceprep) != 0)
131
that->resourceprep_table.insert(in, new Result);
135
QString norm = QString::fromUtf8(cs);
136
that->resourceprep_table.insert(in, new Result(norm));
152
Result(const QString &s) : norm(new QString(s))
162
QDict<Result> nameprep_table;
163
QDict<Result> nodeprep_table;
164
QDict<Result> resourceprep_table;
166
static StringPrepCache *instance;
168
static StringPrepCache *get_instance()
171
instance = new StringPrepCache;
177
nameprep_table.setAutoDelete(true);
178
nodeprep_table.setAutoDelete(true);
179
resourceprep_table.setAutoDelete(true);
183
StringPrepCache *StringPrepCache::instance = 0;
185
//----------------------------------------------------------------------------
187
//----------------------------------------------------------------------------
211
372
bool Jid::validDomain(const QString &s, QString *norm)
213
QCString cs = s.utf8();
374
/*QCString cs = s.utf8();
215
376
if(stringprep(cs.data(), 1024, (Stringprep_profile_flags)0, stringprep_nameprep) != 0)
218
379
*norm = QString::fromUtf8(cs);
381
return StringPrepCache::nameprep(s, 1024, norm);
222
384
bool Jid::validNode(const QString &s, QString *norm)
224
QCString cs = s.utf8();
386
/*QCString cs = s.utf8();
226
388
if(stringprep(cs.data(), 1024, (Stringprep_profile_flags)0, stringprep_xmpp_nodeprep) != 0)
229
391
*norm = QString::fromUtf8(cs);
393
return StringPrepCache::nodeprep(s, 1024, norm);
233
396
bool Jid::validResource(const QString &s, QString *norm)
235
QCString cs = s.utf8();
398
/*QCString cs = s.utf8();
237
400
if(stringprep(cs.data(), 1024, (Stringprep_profile_flags)0, stringprep_xmpp_resourceprep) != 0)
240
403
*norm = QString::fromUtf8(cs);
405
return StringPrepCache::resourceprep(s, 1024, norm);