load.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <hooks/hooks.h>
  2. #include <map>
  3. #include <boost/foreach.hpp>
  4. #include "logger.h"
  5. #include "common.h"
  6. using namespace isc::hooks;
  7. using namespace isc::data;
  8. std::map<std::string, std::string> cm_map;
  9. std::map<std::string, std::string> option122_map;
  10. extern "C" {
  11. int loadMappging(std::string base_map_config, LibraryHandle& handle, std::map<std::string, std::string>& map){
  12. ConstElementPtr curr_map = handle.getParameter(base_map_config);
  13. if (Element::map != curr_map->getType()){
  14. LOG_ERROR(runscript_logger, RUNSCRIPT_MISTYPED_PARAM).arg(base_map_config);
  15. return 1;
  16. }
  17. std::map<std::string, ConstElementPtr> map_config = curr_map->mapValue();;
  18. std::pair<std::string, ConstElementPtr> me;
  19. BOOST_FOREACH(me, map_config) {
  20. std::string class_to_map = me.first;
  21. std::cout << me.first << "\n";
  22. ConstElementPtr table = me.second;
  23. if(table->getType() != Element::list){
  24. LOG_ERROR(runscript_logger, RUNSCRIPT_MISTYPED_PARAM).arg(base_map_config + "." + me.first);
  25. return 1;
  26. }
  27. const std::vector<ElementPtr> mac_list = table->listValue();
  28. for(int i = 0; i < mac_list.size(); i++) {
  29. ElementPtr it = mac_list[i];
  30. if(it->getType() != Element::string){
  31. LOG_ERROR(runscript_logger, RUNSCRIPT_MISTYPED_PARAM).arg(base_map_config + "." + me.first + "[" + std::to_string(i) + "]");
  32. return 1;
  33. }
  34. std::cout << mac_list[i]->stringValue() << "\n";
  35. std::string mac = mac_list[i]->stringValue();
  36. std::transform(mac.begin(), mac.end(),mac.begin(), ::toupper);
  37. map[mac] = class_to_map;
  38. }
  39. }
  40. return 0;
  41. }
  42. int load(LibraryHandle& handle)
  43. {
  44. return 0;
  45. }
  46. } // end extern "C"