LOCKING: must be called with lock taken
| 800 | |
| 801 | // LOCKING: must be called with lock taken |
| 802 | HttpBodySet * |
| 803 | HttpBodyFactory::load_body_set_from_directory(char *set_name, char *tmpl_dir) |
| 804 | { |
| 805 | DIR *dir; |
| 806 | int status; |
| 807 | struct stat stat_buf; |
| 808 | struct dirent *dirEntry; |
| 809 | char path[MAXPATHLEN + 1]; |
| 810 | static const char BASED_DEFAULT[] = "_default"; |
| 811 | |
| 812 | //////////////////////////////////////////////// |
| 813 | // ensure we can open tmpl_dir as a directory // |
| 814 | //////////////////////////////////////////////// |
| 815 | |
| 816 | Dbg(dbg_ctl_body_factory, " load_body_set_from_directory(%s)", tmpl_dir); |
| 817 | dir = opendir(tmpl_dir); |
| 818 | if (dir == nullptr) { |
| 819 | return nullptr; |
| 820 | } |
| 821 | |
| 822 | ///////////////////////////////////////////// |
| 823 | // ensure a .body_factory_info file exists // |
| 824 | ///////////////////////////////////////////// |
| 825 | |
| 826 | ink_filepath_make(path, sizeof(path), tmpl_dir, ".body_factory_info"); |
| 827 | status = stat(path, &stat_buf); |
| 828 | if ((status < 0) || !S_ISREG(stat_buf.st_mode)) { |
| 829 | Warning("Missing .body_factory_info in %s. Not loading body_factory templates", tmpl_dir); |
| 830 | closedir(dir); |
| 831 | return nullptr; |
| 832 | } |
| 833 | Dbg(dbg_ctl_body_factory, " found '%s'", path); |
| 834 | |
| 835 | ///////////////////////////////////////////////////////////////// |
| 836 | // create body set, and loop over template files, loading them // |
| 837 | ///////////////////////////////////////////////////////////////// |
| 838 | |
| 839 | HttpBodySet *body_set = new HttpBodySet; |
| 840 | body_set->init(set_name, tmpl_dir); |
| 841 | |
| 842 | Dbg(dbg_ctl_body_factory, " body_set = %p (set_name '%s', lang '%s', charset '%s')", body_set, body_set->set_name, |
| 843 | body_set->content_language, body_set->content_charset); |
| 844 | |
| 845 | while ((dirEntry = readdir(dir))) { |
| 846 | HttpBodyTemplate *tmpl; |
| 847 | size_t d_len = strlen(dirEntry->d_name); |
| 848 | |
| 849 | /////////////////////////////////////////////////////////////// |
| 850 | // all template files must have a file name of the form // |
| 851 | // - <type>#<subtype> // |
| 852 | // - <base>_<type>#<subtype> // |
| 853 | // - <base>_default [based default] // |
| 854 | // - default [global default] // |
| 855 | /////////////////////////////////////////////////////////////// |
| 856 | |
| 857 | if (!(nullptr != strchr(dirEntry->d_name, '#') || (0 == strcmp(dirEntry->d_name, "default")) || |
| 858 | (d_len >= sizeof(BASED_DEFAULT) && 0 == strcmp(dirEntry->d_name + d_len - (sizeof(BASED_DEFAULT) - 1), BASED_DEFAULT)))) { |
| 859 | continue; |
nothing calls this directly
no test coverage detected