MCPcopy Create free account
hub / github.com/apache/httpd / apprentice

Function apprentice

modules/metadata/mod_mime_magic.c:913–1021  ·  view source on GitHub ↗

* apprentice - load configuration from the magic file r * API request record */

Source from the content-addressed store, hash-verified

911 * API request record
912 */
913static int apprentice(server_rec *s, apr_pool_t *p)
914{
915 apr_file_t *f = NULL;
916 apr_status_t result;
917 char line[BUFSIZ + 1];
918 int errs = 0;
919 int lineno;
920#if MIME_MAGIC_DEBUG
921 int rule = 0;
922 struct magic *m, *prevm;
923#endif
924 magic_server_config_rec *conf = (magic_server_config_rec *)
925 ap_get_module_config(s->module_config, &mime_magic_module);
926 const char *fname = ap_server_root_relative(p, conf->magicfile);
927
928 if (!fname) {
929 ap_log_error(APLOG_MARK, APLOG_ERR, APR_EBADPATH, s, APLOGNO(01514)
930 MODNAME ": Invalid magic file path %s", conf->magicfile);
931 return -1;
932 }
933 if ((result = apr_file_open(&f, fname, APR_READ | APR_BUFFERED,
934 APR_OS_DEFAULT, p)) != APR_SUCCESS) {
935 ap_log_error(APLOG_MARK, APLOG_ERR, result, s, APLOGNO(01515)
936 MODNAME ": can't read magic file %s", fname);
937 return -1;
938 }
939
940 /* set up the magic list (empty) */
941 conf->magic = conf->last = NULL;
942
943 /* parse it */
944 for (lineno = 1; apr_file_gets(line, BUFSIZ, f) == APR_SUCCESS; lineno++) {
945 int ws_offset;
946 char *last = line + strlen(line) - 1; /* guaranteed that len >= 1 since an
947 * "empty" line contains a '\n'
948 */
949
950 /* delete newline and any other trailing whitespace */
951 while (last >= line
952 && apr_isspace(*last)) {
953 *last = '\0';
954 --last;
955 }
956
957 /* skip leading whitespace */
958 ws_offset = 0;
959 while (line[ws_offset] && apr_isspace(line[ws_offset])) {
960 ws_offset++;
961 }
962
963 /* skip blank lines */
964 if (line[ws_offset] == 0) {
965 continue;
966 }
967
968 /* comment, do not parse */
969 if (line[ws_offset] == '#')
970 continue;

Callers 1

magic_initFunction · 0.85

Calls 4

ap_get_module_configFunction · 0.85
ap_server_root_relativeFunction · 0.85
parseFunction · 0.85
ap_log_errorFunction · 0.50

Tested by

no test coverage detected