MCPcopy Create free account
hub / github.com/apache/trafficserver / load_body_set_from_directory

Method load_body_set_from_directory

src/proxy/http/HttpBodyFactory.cc:802–887  ·  view source on GitHub ↗

LOCKING: must be called with lock taken

Source from the content-addressed store, hash-verified

800
801// LOCKING: must be called with lock taken
802HttpBodySet *
803HttpBodyFactory::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;

Callers

nothing calls this directly

Calls 6

ink_filepath_makeFunction · 0.85
strcmpFunction · 0.85
set_template_by_nameMethod · 0.80
statClass · 0.70
initMethod · 0.45
load_from_fileMethod · 0.45

Tested by

no test coverage detected