bool goodnick(const string& str) { if(str.length() < 3) return false; if(!consistsOf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-123456789", str)) return false; return true; }
void hkstable::set(const string& ip, long seconds) { if(!consistsOf("abcdefghijklmnopqrstuvwxyz0123456789-.*", tolower(ip))) return; if(seconds > 86400) seconds = 86400; m_hks.enterMutex(); hks[tolower(ip)] = seconds; m_hks.leaveMutex(); }
TEST(DictionarySerializationTest, NumberAsStringsDoesntAffectObjects) { SerializationContext ctx; AmfDictionary d(true); d.insert(AmfArray(), AmfDictionary(false)); d.insert(AmfArray(std::vector<AmfInteger> { 1 }), AmfObject("", true, false)); consistsOf(std::vector<v8> { { // header 0x11, 0x05, // 2 elements 0x00 // no weak keys }, { // [] = {} 0x09, 0x01, 0x01, // empty array 0x11, 0x01, 0x00 // empty array }, { // [1] = {} 0x09, 0x03, 0x01, 0x04, 0x01, // AmfArray [1] 0x0a, 0x0b, 0x01, 0x01 // empty dynamic anonymous object } }, d.serialize(ctx)); AmfObject obj("foo", true, false); obj.addDynamicProperty("prop", AmfString("val")); AmfVector<int> vec { { 1, 2, 3 }, false }; d = AmfDictionary(true); d.insert(obj, vec); isEqual({ 0x11, 0x03, // 1 element 0x00, // no weak keys // key 0x0a, // AMF_OBJECT 0x0b, // U29O-traits | dynamic, 0 sealed properties 0x07, 0x66, 0x6f, 0x6f, // class-name "foo" // dynamic-member 0x09, 0x70, 0x72, 0x6f, 0x70, // UTF-8-vr "prop" 0x06, 0x07, 0x76, 0x61, 0x6c, // AmfString "val" 0x01, // end of object (UTF-8-empty) // value 0x0d, 0x07, 0x00, // AmfVector<int> with 3 elements 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03 }, d); }
TEST(DictionarySerializationTest, MultipleKeys) { AmfDictionary d(true, false); d.insert(AmfInteger(3), AmfBool(false)); d.insert(AmfInteger(-16384), AmfString("foo")); consistsOf(std::vector<v8> { { // header 0x11, // AMF_DICTIONARY 0x05, // 2 elements 0x00, // no weak keys }, { // "3" = false 0x06, 0x03, 0x33, 0x02, }, { // "-16384" = "foo" 0x06, 0x0D, 0x2D, 0x31, 0x36, 0x33, 0x38, 0x34, 0x06, 0x07, 0x66, 0x6F, 0x6F } }, d.serialize()); }