static rpmRC tagValidate(Spec spec, rpmTag tag, const char * value) /*@*/ { const char * tagN = tagName(tag); const char * pattern = rpmExpand("%{?pattern_", tagN, "}", NULL); rpmRC ec = RPMRC_OK; if (pattern && *pattern) { miRE mire; int xx; mire = mireNew(RPMMIRE_REGEX, tag); xx = mireSetCOptions(mire, RPMMIRE_REGEX, 0, 0, NULL); if (!xx) xx = mireRegcomp(mire, pattern); if (!xx) xx = mireRegexec(mire, value, strlen(value)); if (!xx) ec = RPMRC_OK; else { rpmlog(RPMLOG_ERR, _("line %d: invalid tag value(\"%s\") %s: %s\n"), spec->lineNum, pattern, tagN, spec->line); ec = RPMRC_FAIL; } mire = mireFree(mire); } pattern = _free(pattern); return ec; }
int mireApply(miRE mire, int nmire, const char *s, size_t slen, int rc) { int i; if (slen == 0) slen = strlen(s); if (mire) for (i = 0; i < nmire; mire++, i++) { int xx = mireRegexec(mire, s, slen); /* Check if excluding or including condition applies. */ if (rc < 0 && xx < 0) continue; /* excluding: continue on negative matches. */ if (rc > 0 && xx >= 0) continue; /* including: continue on positive matches. */ /* Save 1st found termination condition and exit. */ rc = xx; break; } return rc; }
static int parseHTML(rpmtget tget) { miRE mire = tget->mires; int noffsets = 3; int offsets[3]; ssize_t nr = (tget->b != NULL ? (ssize_t)tget->nb : tgetFill(tget)); int xx; xx = mireSetEOptions(mire, offsets, noffsets); while (tget->nb > 0) { char * gbn, * hbn; char * f, * fe; char * g, * ge; char * h, * he; char * t; mode_t mode; size_t nb; offsets[0] = offsets[1] = -1; xx = mireRegexec(mire, tget->b, tget->nb); if (xx == 0 && offsets[0] != -1 && offsets[1] != -1) { /* [f:fe) contains |<a href="..."| match. */ f = tget->b + offsets[0]; fe = tget->b + offsets[1]; /* [h:he) contains the href basename. */ he = fe; if (he[-1] == '"') he--; if (he[-1] == '/') { mode = S_IFDIR | 0755; he--; } else mode = S_IFREG | 0644; h = he; while (h > f && (h[-1] != '"' && h[-1] != '/')) h--; nb = (size_t)(he - h); hbn = t = xmalloc(nb + 1 + 1); while (h < he) *t++ = *h++; if (S_ISDIR(mode)) *t++ = '/'; *t = '\0'; /* [g:ge) contains the URI basename. */ g = fe; while (*g != '>') g++; ge = ++g; while (*ge != '<') ge++; nb = (size_t)(ge - g); gbn = t = xmalloc(nb + 1 + 1); while (g < ge) *t++ = *g++; if (S_ISDIR(mode)) *t++ = '/'; *t = '\0'; /* Filter out weirdos and "." and "..". */ if (!strcmp(gbn, hbn) && strcmp(hbn, "./") && strcmp(hbn, "../")) { fprintf(stderr, "\t%s\n", gbn); xx = argvAdd(&tget->av, gbn); } gbn = _free(gbn); hbn = _free(hbn); offsets[1] += (ge - fe); tget->b += offsets[1]; tget->nb -= offsets[1]; } else { size_t nb = tget->nb; if (nr > 0) nb -= 1024; /* XXX overlap a bit if filling. */ tget->b += nb; tget->nb -= nb; } if (nr > 0) nr = tgetFill(tget); } xx = mireSetEOptions(mire, NULL, 0); return 0; }
static int is_regexp_matching(miRE mire, const char * s) /*@modifies mire @*/ { return mireRegexec(mire, s, (size_t) 0) == 0; }