LOCKING: must be called with lock taken
| 730 | |
| 731 | // LOCKING: must be called with lock taken |
| 732 | std::unique_ptr<HttpBodyFactory::BodySetTable> |
| 733 | HttpBodyFactory::load_sets_from_directory(char *set_dir) |
| 734 | { |
| 735 | DIR *dir; |
| 736 | struct dirent *dirEntry; |
| 737 | std::unique_ptr<HttpBodyFactory::BodySetTable> new_table_of_sets; |
| 738 | |
| 739 | if (set_dir == nullptr) { |
| 740 | return nullptr; |
| 741 | } |
| 742 | |
| 743 | Dbg(dbg_ctl_body_factory, "load_sets_from_directory(%s)", set_dir); |
| 744 | |
| 745 | ////////////////////////////////////////////////// |
| 746 | // try to open the requested template directory // |
| 747 | ////////////////////////////////////////////////// |
| 748 | |
| 749 | dir = opendir(set_dir); |
| 750 | if (dir == nullptr) { |
| 751 | Warning("can't open response template directory '%s' (%s)", set_dir, (strerror(errno) ? strerror(errno) : "unknown reason")); |
| 752 | Warning("no response templates --- using default error pages"); |
| 753 | return nullptr; |
| 754 | } |
| 755 | |
| 756 | new_table_of_sets.reset(new HttpBodyFactory::BodySetTable); |
| 757 | |
| 758 | ////////////////////////////////////////// |
| 759 | // loop over each language subdirectory // |
| 760 | ////////////////////////////////////////// |
| 761 | |
| 762 | while ((dirEntry = readdir(dir))) { |
| 763 | int status; |
| 764 | struct stat stat_buf; |
| 765 | char subdir[MAXPATHLEN + 1]; |
| 766 | |
| 767 | ////////////////////////////////////////////////////// |
| 768 | // ensure a subdirectory, and not starting with '.' // |
| 769 | ////////////////////////////////////////////////////// |
| 770 | |
| 771 | if ((dirEntry->d_name)[0] == '.') { |
| 772 | continue; |
| 773 | } |
| 774 | |
| 775 | ink_filepath_make(subdir, sizeof(subdir), set_dir, dirEntry->d_name); |
| 776 | status = stat(subdir, &stat_buf); |
| 777 | if (status != 0) { |
| 778 | continue; // can't stat |
| 779 | } |
| 780 | |
| 781 | if (!S_ISDIR(stat_buf.st_mode)) { |
| 782 | continue; // not a dir |
| 783 | } |
| 784 | |
| 785 | /////////////////////////////////////////////////////////// |
| 786 | // at this point, 'subdir' might be a valid template dir // |
| 787 | /////////////////////////////////////////////////////////// |
| 788 | |
| 789 | HttpBodySet *body_set = load_body_set_from_directory(dirEntry->d_name, subdir); |
nothing calls this directly
no test coverage detected