static bool _parse(MetisTlvSkeleton *skeleton) { bool success = false; _MetisTlvFixedHeaderV1 *hdr = (_MetisTlvFixedHeaderV1 *) metisTlvSkeleton_GetPacket(skeleton); // this function should only be called for version 1 packets trapUnexpectedStateIf(hdr->version != 1, "Version not 1"); if (_goodPacketType(hdr->packetType) && hdr->headerLength >= sizeof(_MetisTlvFixedHeaderV1)) { size_t endHeaders = hdr->headerLength; size_t endPacket = htons(hdr->packetLength); if (endPacket >= endHeaders) { if (_isPacketTypeInterest((uint8_t *) hdr)) { metisTlvSkeleton_SetHopLimit(skeleton, 4, 1); } _parsePerHopV1(metisTlvSkeleton_GetPacket(skeleton), sizeof(_MetisTlvFixedHeaderV1), endHeaders, skeleton); size_t offset = _parseMessage(metisTlvSkeleton_GetPacket(skeleton), endHeaders, endPacket, skeleton); _parseValidationAlg(metisTlvSkeleton_GetPacket(skeleton), offset, endPacket, skeleton); success = true; } } return success; }
void TCParser::_parseCommand(std::vector<std::string> &items) { if (items.size() == 0) return; std::string command = items[0]; items.erase(items.begin()); // Dispatch command if (command.compare("ping") == 0) _parsePing(items); else if (command.compare("pong") == 0) _parsePong(items); else if (command.compare("status") == 0) _parseStatus(items); else if (command.compare("version") == 0) _parseVersion(items); else if (command.compare("client") == 0) _parseClient(items); else if (command.compare("profile_name") == 0) _parseProfileName(items); else if (command.compare("profile_text") == 0) _parseProfileText(items); else if (command.compare("profile_avatar_alpha") == 0) _parseProfileAvatarAlpha(items); else if (command.compare("profile_avatar") == 0) _parseProfileAvatar(items); else if (command.compare("message") == 0) _parseMessage(items); else if (command.compare("add_me") == 0) _parseAddMe(items); else if (command.compare("remove_me") == 0) _parseRemoveMe(items); else if (command.compare("filename") == 0) _parseFileName(items); else if (command.compare("filedata") == 0) _parseFileData(items); else if (command.compare("filedata_ok") == 0) _parseFileDataOk(items); else if (command.compare("filedata_error") == 0) _parseFileDataError(items); else if (command.compare("file_stop_sending") == 0) _parseFileStopSending(items); else if (command.compare("file_stop_receiving") == 0) _parseFileStopReceiving(items); else { char buffer[1024]; snprintf(buffer, sizeof(buffer), "Unknown command '%s'", command.c_str()); _parserError(tcrec_unknown_command, buffer); } }