* parse one line from magic file, put into magic[index++] if valid */
| 1061 | * parse one line from magic file, put into magic[index++] if valid |
| 1062 | */ |
| 1063 | static int parse(server_rec *serv, apr_pool_t *p, char *l, int lineno) |
| 1064 | { |
| 1065 | struct magic *m; |
| 1066 | char *t, *s; |
| 1067 | magic_server_config_rec *conf = (magic_server_config_rec *) |
| 1068 | ap_get_module_config(serv->module_config, &mime_magic_module); |
| 1069 | |
| 1070 | /* allocate magic structure entry */ |
| 1071 | m = (struct magic *) apr_pcalloc(p, sizeof(struct magic)); |
| 1072 | |
| 1073 | /* append to linked list */ |
| 1074 | m->next = NULL; |
| 1075 | if (!conf->magic || !conf->last) { |
| 1076 | conf->magic = conf->last = m; |
| 1077 | } |
| 1078 | else { |
| 1079 | conf->last->next = m; |
| 1080 | conf->last = m; |
| 1081 | } |
| 1082 | |
| 1083 | /* set values in magic structure */ |
| 1084 | m->flag = 0; |
| 1085 | m->cont_level = 0; |
| 1086 | m->lineno = lineno; |
| 1087 | |
| 1088 | while (*l == '>') { |
| 1089 | ++l; /* step over */ |
| 1090 | m->cont_level++; |
| 1091 | } |
| 1092 | |
| 1093 | if (m->cont_level != 0 && *l == '(') { |
| 1094 | ++l; /* step over */ |
| 1095 | m->flag |= INDIR; |
| 1096 | } |
| 1097 | |
| 1098 | /* get offset, then skip over it */ |
| 1099 | m->offset = (int) strtol(l, &t, 0); |
| 1100 | if (l == t) { |
| 1101 | ap_log_error(APLOG_MARK, APLOG_ERR, 0, serv, APLOGNO(01521) |
| 1102 | MODNAME ": offset %s invalid", l); |
| 1103 | } |
| 1104 | l = t; |
| 1105 | |
| 1106 | if (m->flag & INDIR) { |
| 1107 | m->in.type = LONG; |
| 1108 | m->in.offset = 0; |
| 1109 | /* |
| 1110 | * read [.lbs][+-]nnnnn) |
| 1111 | */ |
| 1112 | if (*l == '.') { |
| 1113 | switch (*++l) { |
| 1114 | case 'l': |
| 1115 | m->in.type = LONG; |
| 1116 | break; |
| 1117 | case 's': |
| 1118 | m->in.type = SHORT; |
| 1119 | break; |
| 1120 | case 'b': |
no test coverage detected