/* */ #include "ExtensionMessageRegistry.h" #include #include namespace aria2 { ExtensionMessageRegistry::ExtensionMessageRegistry() : extensions_(MAX_EXTENSION) { } ExtensionMessageRegistry::~ExtensionMessageRegistry() {} namespace { const char* EXTENSION_NAMES[] = {"ut_metadata", "ut_pex", nullptr}; } // namespace uint8_t ExtensionMessageRegistry::getExtensionMessageID(int key) const { assert(key < MAX_EXTENSION); return extensions_[key]; } const char* ExtensionMessageRegistry::getExtensionName(uint8_t id) const { int i; if (id == 0) { return nullptr; } for (i = 0; i < MAX_EXTENSION; ++i) { if (extensions_[i] == id) { break; } } return EXTENSION_NAMES[i]; } void ExtensionMessageRegistry::setExtensionMessageID(int key, uint8_t id) { assert(key < MAX_EXTENSION); extensions_[key] = id; } void ExtensionMessageRegistry::removeExtension(int key) { assert(key < MAX_EXTENSION); extensions_[key] = 0; } void ExtensionMessageRegistry::setExtensions(const Extensions& extensions) { extensions_ = extensions; } const char* strBtExtension(int key) { if (key >= ExtensionMessageRegistry::MAX_EXTENSION) { return nullptr; } else { return EXTENSION_NAMES[key]; } } int keyBtExtension(const char* name) { int i; for (i = 0; i < ExtensionMessageRegistry::MAX_EXTENSION; ++i) { if (strcmp(EXTENSION_NAMES[i], name) == 0) { break; } } return i; } } // namespace aria2