Read one line from open ap_configfile_t, strip LF, increase line number */ If custom handler does not define a getstr() function, read char by char */
| 1077 | /* Read one line from open ap_configfile_t, strip LF, increase line number */ |
| 1078 | /* If custom handler does not define a getstr() function, read char by char */ |
| 1079 | static apr_status_t ap_cfg_getline_core(char *buf, apr_size_t bufsize, |
| 1080 | apr_size_t offset, ap_configfile_t *cfp) |
| 1081 | { |
| 1082 | apr_status_t rc; |
| 1083 | /* If a "get string" function is defined, use it */ |
| 1084 | if (cfp->getstr != NULL) { |
| 1085 | char *cp; |
| 1086 | char *cbuf = buf + offset; |
| 1087 | apr_size_t cbufsize = bufsize - offset; |
| 1088 | |
| 1089 | while (1) { |
| 1090 | ++cfp->line_number; |
| 1091 | rc = cfp->getstr(cbuf, cbufsize, cfp->param); |
| 1092 | if (rc == APR_EOF) { |
| 1093 | if (cbuf != buf + offset) { |
| 1094 | *cbuf = '\0'; |
| 1095 | break; |
| 1096 | } |
| 1097 | else { |
| 1098 | return APR_EOF; |
| 1099 | } |
| 1100 | } |
| 1101 | if (rc != APR_SUCCESS) { |
| 1102 | return rc; |
| 1103 | } |
| 1104 | |
| 1105 | /* |
| 1106 | * check for line continuation, |
| 1107 | * i.e. match [^\\]\\[\r]\n only |
| 1108 | */ |
| 1109 | cp = cbuf; |
| 1110 | cp += strlen(cp); |
| 1111 | if (cp > buf && cp[-1] == LF) { |
| 1112 | cp--; |
| 1113 | if (cp > buf && cp[-1] == CR) |
| 1114 | cp--; |
| 1115 | if (cp > buf && cp[-1] == '\\') { |
| 1116 | cp--; |
| 1117 | /* |
| 1118 | * line continuation requested - |
| 1119 | * then remove backslash and continue |
| 1120 | */ |
| 1121 | cbufsize -= (cp-cbuf); |
| 1122 | cbuf = cp; |
| 1123 | continue; |
| 1124 | } |
| 1125 | } |
| 1126 | else if (cp - buf >= bufsize - 1) { |
| 1127 | return APR_ENOSPC; |
| 1128 | } |
| 1129 | break; |
| 1130 | } |
| 1131 | } else { |
| 1132 | /* No "get string" function defined; read character by character */ |
| 1133 | apr_size_t i = offset; |
| 1134 | |
| 1135 | if (bufsize < 2) { |
| 1136 | /* too small, assume caller is crazy */ |
no outgoing calls
no test coverage detected