char * reAnchorNewsheader(Buffer *buf) { Line *l; char *p, *p1, *p2; static char *header_mid[] = { "Message-Id:", "References:", "In-Reply-To:", NULL }; static char *header_group[] = { "Newsgroups:", NULL }; char **header, **q; int i, search = FALSE; if (!buf || !buf->firstLine) return NULL; for (i = 0; i <= 1; i++) { if (i == 0) { regexCompile("<[!-;=?-~]+@[a-zA-Z0-9\\.\\-_]+>", 1); header = header_mid; } else { regexCompile("[a-zA-Z0-9\\.\\-_]+", 1); header = header_group; } for (l = buf->firstLine; l != NULL && l->real_linenumber == 0; l = l->next) { if (l->bpos) continue; p = l->lineBuf; if (!IS_SPACE(*p)) { search = FALSE; for (q = header; *q; q++) { if (!strncasecmp(p, *q, strlen(*q))) { search = TRUE; p = strchr(p, ':') + 1; break; } } } if (!search) continue; for (;;) { if (regexMatch(p, &l->lineBuf[l->size] - p, p == l->lineBuf) == 1) { matchedPosition(&p1, &p2); p = reAnchorPos(buf, l, p1, p2, _put_anchor_news); } else break; } } } reseq_anchor(buf); return NULL; }
/* returns error message if any */ static char * reAnchorAny(Buffer *buf, char *re, Anchor *(*anchorproc) (Buffer *, char *, char *, int, int)) { Line *l; char *p = NULL, *p1, *p2; if (re == NULL || *re == '\0') { return NULL; } if ((re = regexCompile(re, 1)) != NULL) { return re; } for (l = MarkAllPages ? buf->firstLine : buf->topLine; l != NULL && (MarkAllPages || l->linenumber < buf->topLine->linenumber + LASTLINE); l = l->next) { if (p && l->bpos) goto next_line; p = l->lineBuf; for (;;) { if (regexMatch(p, &l->lineBuf[l->size] - p, p == l->lineBuf) == 1) { matchedPosition(&p1, &p2); p = reAnchorPos(buf, l, p1, p2, anchorproc); } else break; } next_line: if (MarkAllPages && l->next == NULL && buf->pagerSource && !(buf->bufferprop & BP_CLOSE)) getNextPage(buf, PagerMax); } return NULL; }
static void checkTermRegex(struct hgFindSpec *hfs) /* Make sure termRegex compiles OK. */ { if (isNotEmpty(hfs->termRegex)) { char buf[256]; safef(buf, sizeof(buf), "hfsPolish: search %s: termRegex", hfs->searchName); // Discard returned compiled expression (void) regexCompile(hfs->termRegex, buf, (REG_EXTENDED | REG_ICASE | REG_NOSUB)); } }
static void checkTermRegex(struct hgFindSpec *hfs) /* Make sure termRegex compiles OK. */ { if (isNotEmpty(hfs->termRegex)) { char buf[256]; safef(buf, sizeof(buf), "hfsPolish: search %s: termRegex", hfs->searchName); const regex_t *compiledExp = regexCompile(hfs->termRegex, buf, (REG_EXTENDED | REG_ICASE | REG_NOSUB)); compiledExp = NULL; // Avoid compiler warning about unused variable / return value } }
static char * domain_match(char *host, char *domain) { int m0, m1; /* [RFC 2109] s. 2, "domain-match", case 1 * (both are IP and identical) */ regexCompile("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+", 0); m0 = regexMatch(host, -1, 1); m1 = regexMatch(domain, -1, 1); if (m0 && m1) { if (strcasecmp(host, domain) == 0) return host; } else if (!m0 && !m1) { int offset; char *domain_p; /* * "." match all domains (w3m only), * and ".local" match local domains ([DRAFT 12] s. 2) */ if (strcasecmp(domain, ".") == 0 || strcasecmp(domain, ".local") == 0) { offset = strlen(host); domain_p = &host[offset]; if (domain[1] == '\0' || contain_no_dots(host, domain_p)) return domain_p; } /* * special case for domainName = .hostName * see nsCookieService.cpp in Firefox. */ else if (domain[0] == '.' && strcasecmp(host, &domain[1]) == 0) { return host; } /* [RFC 2109] s. 2, cases 2, 3 */ else { offset = (domain[0] != '.') ? 0 : strlen(host) - strlen(domain); domain_p = &host[offset]; if (offset >= 0 && strcasecmp(domain_p, domain) == 0) return domain_p; } } return NULL; }