• Bug#999938: trafficserver: depends on obsolete pcre3 library (2/3)

    From Yavor Doganov@21:1/5 to All on Fri Dec 29 16:00:01 2023
    [continued from previous message]

    @@ -334,31 +343,24 @@
    bool
    Pattern::compile()
    {
    - const char *errPtr; /* PCRE error */
    - int errOffset; /* PCRE error offset */
    + int errCode; /* PCRE error code */
    + PCRE2_UCHAR errPtr[120]; /* PCRE error */
    + PCRE2_SIZE errOffset; /* PCRE error offset */

    CacheKeyDebug("compiling pattern:'%s', replace: %s, replacement:'%s'", _pattern.c_str(), _replace ? "true" : "false",
    _replacement.c_str());

    - _re = pcre_compile(_pattern.c_str(), /* the pattern */
    - 0, /* options */
    - &errPtr, /* for error message */
    - &errOffset, /* for error offset */
    - nullptr); /* use default character tables */
    + _re = pcre2_compile((PCRE2_SPTR)_pattern.c_str(), /* the pattern */
    + PCRE2_ZERO_TERMINATED,
    + 0, /* options */
    + &errCode, /* for error code */
    + &errOffset, /* for error offset */
    + comp_ctxt); /* compile context */

    if (nullptr == _re) {
    - CacheKeyError("compile of regex '%s' at char %d: %s", _pattern.c_str(), errOffset, errPtr);
    -
    - return false;
    - }
    -
    - _extra = pcre_study(_re, 0, &errPtr);
    + pcre2_get_error_message(errCode, errPtr, sizeof(errPtr));
    + CacheKeyError("compile of regex '%s' at char %zu: %s", _pattern.c_str(), errOffset, errPtr);

    - if ((nullptr == _extra) && (nullptr != errPtr) && (0 != *errPtr)) {
    - CacheKeyError("failed to study regex '%s': %s", _pattern.c_str(), errPtr); -
    - pcre_free(_re);
    - _re = nullptr;
    return false;
    }

    --- trafficserver-9.2.3+ds.orig/plugins/cachekey/pattern.h
    +++ trafficserver-9.2.3+ds/plugins/cachekey/pattern.h
    @@ -24,12 +24,10 @@
    #pragma once

    #include "tscore/ink_defs.h"
    +#include "tscore/ink_memory.h"

    -#ifdef HAVE_PCRE_PCRE_H
    -#include <pcre/pcre.h>
    -#else
    -#include <pcre.h>
    -#endif
    +#define PCRE2_CODE_UNIT_WIDTH 8
    +#include <pcre2.h>

    #include "common.h"

    @@ -57,8 +55,7 @@
    bool compile();
    void pcreFree();

    - pcre *_re = nullptr; /**< @brief PCRE compiled info structure, computed during initialization */
    - pcre_extra *_extra = nullptr; /**< @brief PCRE study data block, computed during initialization */
    + pcre2_code *_re = nullptr; /**< @brief PCRE compiled info structure, computed during initialization */

    String _pattern; /**< @brief PCRE pattern string, containing PCRE patterns and capturing groups. */
    String _replacement; /**< @brief PCRE replacement string, containing $0..$9 to be replaced with content of the capturing groups */
    --- tr