📄 eap_parser.hxx
字号:
EapTypeList &tList= nak->TypeList(); if (d == NULL || d->type == EapNakDict::LegacyNak) // legacy nak { EapTypeList::iterator i; for (i=tList.begin(); i!=tList.end(); i++) { msg->copy((const char*)&(*i).type, 1); } } else // Extended nak { EapTypeList::iterator i; ACE_UINT32 vendorId, vendorType; // Set first entry (254,0,3) vendorId = (254 << 24); vendorId = ntohs(vendorId); vendorType = ntohs(3); msg->copy((const char*)&vendorId, 4); msg->copy((const char*)&vendorType, 4); // Set remaining ones. for (i=tList.begin(); i!=tList.end(); i++) { EapType t = *i; // Convert legacy type representation to vendor-specific // representation. if (t.type!=254) t = EapType(0, t.type); // Write vendor fields. vendorId = (t.vendorId && 0x00ffffff) | (t.type << 24); vendorId = ntohs(vendorId); vendorType = ntohs(t.vendorType); msg->copy((const char*)&vendorId, 4); msg->copy((const char*)&vendorType, 4); } }}/// Request/Identity parsertypedef AAAParser<AAAMessageBlock*, EapIdentity*> EapRequestIdentityParser;/// Use this function to convert raw EAP Identity request/response/// payload data (data following the Type field) to/// application-specific payload data. As a result of calling this/// function, the read pointer of the message block points to the/// end of payload.template<> inline voidEapRequestIdentityParser::parseRawToApp() { AAAMessageBlock *msg = getRawData(); EapIdentity *identity = getAppData(); size_t idStringSize = msg->size() - (msg->rd_ptr()-msg->base()); // UTF8 varidation without null-charater check. UTF8Checker check; if (check(msg->rd_ptr(), idStringSize) != 0) { EAP_LOG(LM_ERROR, "Invalid UTF8 string"); throw -1; } std::string &str = identity->Identity(); str.assign(msg->rd_ptr(), idStringSize); msg->rd_ptr(msg->end());}/// Use this function to convert /// application-specific Identity payload data to raw EAP Identity/// request/response payload data (data following the Type field). As/// a result of calling this function, the write pointer of the/// message block points to the end of payload so that the parser can/// calculate the PDU length by using ACE_Message_Block::wr_ptr() -/// ACE_Message_Block::base().template<> inline voidEapRequestIdentityParser::parseAppToRaw(){ AAAMessageBlock *msg = getRawData(); EapIdentity *identity = getAppData(); // Write type field EapResponseParser responseParser; responseParser.setRawData(msg); responseParser.setAppData(identity); responseParser.parseAppToRaw(); // EapRequestParser::parseAppToRaw(); std::string &str = identity->Identity(); UTF8Checker check; // UTF8 varidation with null-charater check. if (check(str.data(), str.size(), true) != 0) { EAP_LOG(LM_ERROR, "Invalid UTF8 string"); throw -1; } msg->copy(str.data(), str.size());}/// Request/Notification parserclass EAP_EXPORTS EapResponseIdentityParser: public EapRequestIdentityParser {};/// Request/Identity parsertypedef AAAParser<AAAMessageBlock*, EapNotification*> EapRequestNotificationParser;/// Use this function to convert raw EAP Notification request/response/// payload data (data following the Type field) to/// application-specific payload data. As a result of calling this/// function, the read pointer of the message block points to the/// end of payload.template<> inline voidEapRequestNotificationParser::parseRawToApp(){ AAAMessageBlock *msg = getRawData(); EapNotification *notification = getAppData(); size_t notificationStringSize = msg->size() - (msg->rd_ptr()-msg->base()); // UTF8 varidation without null-charater check. UTF8Checker check; if (check(msg->rd_ptr(), notificationStringSize) != 0) { EAP_LOG(LM_ERROR, "Invalid UTF8 string"); throw -1; } std::string &str = notification->Notification(); str.assign(msg->rd_ptr(), notificationStringSize); msg->rd_ptr(msg->end());}/// Use this function to convert /// application-specific Notification payload data to raw EAP/// Notification request/response payload data (data following the/// Type field). As a result of calling this function, the write/// pointer of the message block points to the end of payload so/// that the parser can calculate the PDU length by using/// ACE_Message_Block::wr_ptr() - ACE_Message_Block::base().template<> inline voidEapRequestNotificationParser::parseAppToRaw(){ AAAMessageBlock *msg = getRawData(); EapNotification *notification = getAppData(); // Write type field EapResponseParser responseParser; responseParser.setRawData(msg); responseParser.setAppData(notification); responseParser.parseAppToRaw(); // EapRequestParser::parseAppToRaw(); std::string &str = notification->Notification(); UTF8Checker check; // UTF8 varidation with null-charater check. if (check(str.data(), str.size(), true) != 0) { EAP_LOG(LM_ERROR, "Invalid UTF8 string"); throw -1; } msg->copy(str.data(), str.size());}/// Response/Notification parserclass EAP_EXPORTS EapResponseNotificationParser: public EapRequestIdentityParser {};/// Request/MD5-Challenge parsertypedef AAAParser<AAAMessageBlock*, EapMD5Challenge*> EapRequestMD5ChallengeParser;/// Use this function to convert raw EAP MD5-Challenge request data/// (data following the Type field) to application-specific payload/// data. As a result of calling this function, the read pointer of/// the message block points to the end of payload.template<> inline voidEapRequestMD5ChallengeParser::parseRawToApp(){ AAAMessageBlock *msg = getRawData(); EapMD5Challenge *md5Challenge = getAppData(); size_t contentSize = msg->size() - (msg->rd_ptr()-msg->base()); // Read the Value-Size. ACE_Byte valueSize = (ACE_Byte)*msg->rd_ptr(); msg->rd_ptr(1); // Read the Value. md5Challenge->Value().assign(msg->rd_ptr(), valueSize); msg->rd_ptr(valueSize); if (valueSize == 0) { EAP_LOG(LM_ERROR, "Empty value."); throw -1; } // Read the Name. ACE_INT16 nameLength = contentSize - (valueSize + 1); md5Challenge->Name().assign(msg->rd_ptr(), nameLength); msg->rd_ptr(nameLength);}/// Use this function to convert /// application-specific MD5-Challenge payload data to raw EAP/// MD5-Challenge request/response payload data (data following the/// Type field). As a result of calling this function, the write/// pointer of the message block points to the end of payload so/// that the parser can calculate the PDU length by using/// ACE_Message_Block::wr_ptr() - ACE_Message_Block::base().template<> inline voidEapRequestMD5ChallengeParser::parseAppToRaw(){ AAAMessageBlock *msg = getRawData(); EapMD5Challenge *md5Challenge = getAppData(); // Write type field EapResponseParser responseParser; responseParser.setRawData(msg); responseParser.setAppData(md5Challenge); responseParser.parseAppToRaw(); // EapRequestParser::parseAppToRaw(); ACE_Byte valueSize = md5Challenge->Value().size(); // Check the value size. if (valueSize == 0) { EAP_LOG(LM_ERROR, "Empty value."); throw -1; } // Write the Value-Size. msg->copy((const char*)&valueSize, sizeof(valueSize)); // Write the Value. msg->copy(md5Challenge->Value().data(), valueSize); // Write the Name. msg->copy(md5Challenge->Name().data(), md5Challenge->Name().size());}/// Request/MD5-Challenge parserclass EAP_EXPORTS EapResponseMD5ChallengeParser : public EapRequestMD5ChallengeParser {};#endif // __EAP_PARSER_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -