<div dir="ltr">Hi Daniel, <div><br></div><div>Thank you for clarifying how subst_hf works!</div><div><br></div><div>Regarding the size, it does in fact go over the 1024 limit, in this setup we are using firebase tokens which are 1162 characters long, and what I'm trying to do is to prefix the value we receive with some more characters, for a total of 1178 characters.</div><div><br></div><div>So something along:</div><div><br></div><div><div>subst_hf("X-myheader", "/^(.*)/myprefix \1/", "a")</div></div><div><br></div><div><br></div><div>Would it be possible to expose that define for REPLACE_BUFFER_SIZE as a modparam to be configurable? </div><div><br></div><div>Thanks for looking into this!</div><div><br></div><div>Best, </div><div>Joel.</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 5, 2021 at 4:17 AM Daniel-Constantin Mierla <<a href="mailto:miconda@gmail.com">miconda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>Regarding:</p>
    <p>"""<br>
      Oct  4 10:44:44 kamailio-n1 kamailio[20324]: ERROR: <core>
      [core/re.c:363]: replace_build(): Buffer too small<br>
      """<br>
    </p>
    <p>That seems to be related to the define of REPLACE_BUFFER_SIZE,
      which is 1024. Changing it requires to recompile kamailio. Is the
      value to be set bigger than 1024?<br>
    </p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div>On 05.10.21 10:05, Daniel-Constantin
      Mierla wrote:<br>
    </div>
    <blockquote type="cite">
      
      <p>Hello,</p>
      <p>the regular expressions in textops have to be POSIX format
        (extended, iirc), the remark for perl/sed-like was referring to
        the format being '/match/replace/flags' that is common for Perl
        scripting and sed parameters.</p>
      <p>Practically textops uses the regex functions from libc, does
        not depend on libpcre that offers PCRE format for expressions.</p>
      <p>The regex supports matching with PCRE and dialplan offers a way
        to do substitutions by matching with PCRE library.</p>
      <p>I updated the readme of textops to reflect somehow better the
        above.</p>
      <p>Cheers,<br>
        Daniel<br>
      </p>
      <div>On 04.10.21 19:50, Joel Serrano
        wrote:<br>
      </div>
      <blockquote type="cite">
        
        <div dir="ltr">So now when combined with subst_hf to actually
          edit the header value, I'm getting this error:
          <div><br>
          </div>
          <div>Oct  4 10:44:44 kamailio-n1 kamailio[20324]: ERROR:
            <core> [core/re.c:363]: replace_build(): Buffer too
            small<br>
            Oct  4 10:44:44 kamailio-n1 kamailio[20324]: ERROR: textops
            [textops.c:3110]: subst_hf_f(): textops subst_run failed<br>
          </div>
          <div><br>
          </div>
          <div>Can anyone remind me the name of the parameter I have to
            adjust to increase the buffer size?</div>
          <div><br>
          </div>
          <div>Thanks, </div>
          <div>Joel.</div>
        </div>
        <br>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Mon, Oct 4, 2021 at 10:46
            AM Joel Serrano <<a href="mailto:joel@textplus.com" target="_blank">joel@textplus.com</a>> wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
            <div dir="ltr">Update:
              <div><br>
              </div>
              <div>I managed to achieve it using the "regex" module with
                "pcre_match()", that will take negative lookahead
                nicely.</div>
              <div><br>
              </div>
              <div><br>
              </div>
            </div>
            <br>
            <div class="gmail_quote">
              <div dir="ltr" class="gmail_attr">On Mon, Oct 4, 2021 at
                10:18 AM Joel Serrano <<a href="mailto:joel@textplus.com" target="_blank">joel@textplus.com</a>>
                wrote:<br>
              </div>
              <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
                <div dir="ltr">Hey guys, 
                  <div><br>
                  </div>
                  <div>I'm trying to do a replacement regex using
                    subst_hf but I can't seem to get the format right
                    and the docs are confusing.</div>
                  <div><br>
                  </div>
                  <div>
                    <div><b>subst_hf: </b>docs say it uses perl-like
                      regex (as I understand it, that would mean PCRE).
                      Docs also say in the 'subexp' param that it uses
                      the same format as <b>subst.</b><br>
                    </div>
                    <div><b><br>
                      </b></div>
                    <div><b>subst: </b>at the beginning it says it uses
                      perl or sed format, but in the '/re/repl/flags'
                      param it says that sed format.</div>
                  </div>
                  <div><br>
                  </div>
                  <div><a href="https://www.kamailio.org/docs/modules/devel/modules/textops.html#textops.f.subst_hf" target="_blank">https://www.kamailio.org/docs/modules/devel/modules/textops.html#textops.f.subst_hf</a><br>
                  </div>
                  <div><br>
                  </div>
                  <div>
                    <div style="color:rgb(0,0,0);font-family:Helvetica,Arial,sans-serif;font-size:15px">
                      <div>
                        <div>
                          <h3 style="margin:1em 0px 0.75em;padding:0px 0px 5px 5px;color:rgb(107,83,68);font-family:Scada,Helvetica,sans-serif;font-size:20px;line-height:28px;font-style:italic">4.20.  <code>subst_hf(hf,
                              subexp, flags)</code></h3>
                        </div>
                      </div>
                    </div>
                    <p style="font-family:Helvetica,Arial,sans-serif;text-align:justify;font-size:15px"><font color="#ff0000">Perl-like substitutions</font><span style="color:rgb(0,0,0)"> in the body of a
                        header field.</span></p>
                    <p style="font-family:Helvetica,Arial,sans-serif;text-align:justify;color:rgb(0,0,0);font-size:15px">Meaning
                      of the parameters is as follows:</p>
                    <div style="font-family:Helvetica,Arial,sans-serif;font-size:15px">
                      <ul type="disc">
                        <li style="color:rgb(0,0,0)">
                          <p style="text-align:justify"><span><em>hf</em></span> -
                            header field name.</p>
                        </li>
                        <li>
                          <p style="text-align:justify"><span style="color:rgb(0,0,0)"><em>subexp</em></span><font color="#000000"> - substitution expression
                            </font><font color="#ff0000">in the same
                              format as of the 'subst' function</font><font color="#000000"> parameter.</font></p>
                        </li>
                        <li style="color:rgb(0,0,0)">
                          <p style="text-align:justify"><span><em>flags</em></span> -
                            control flags - it has to be one of: a - all
                            headers matching the name; f - only first
                            header matching the name; l - only the last
                            header matching the name.</p>
                        </li>
                      </ul>
                    </div>
                  </div>
                  <div><br>
                  </div>
                  <div>
                    <div style="color:rgb(0,0,0);font-family:Helvetica,Arial,sans-serif;font-size:15px">
                      <div>
                        <div>
                          <h3 style="margin:1em 0px 0.75em;padding:0px 0px 5px 5px;color:rgb(107,83,68);font-family:Scada,Helvetica,sans-serif;font-size:20px;line-height:28px;font-style:italic">4.16.  <code>subst('/re/repl/flags')</code></h3>
                        </div>
                      </div>
                    </div>
                    <p style="font-family:Helvetica,Arial,sans-serif;text-align:justify;font-size:15px"><span style="color:rgb(0,0,0)">Replaces re with repl (</span><font color="#ff0000">sed or perl like</font><font color="#000000">).</font></p>
                    <p style="font-family:Helvetica,Arial,sans-serif;text-align:justify;color:rgb(0,0,0);font-size:15px">Meaning
                      of the parameters is as follows:</p>
                    <div style="font-family:Helvetica,Arial,sans-serif;font-size:15px">
                      <ul type="disc">
                        <li>
                          <p style="text-align:justify"><span style="color:rgb(0,0,0)"><em>'/re/repl/flags'</em></span><font color="#000000"> - </font><font color="#ff0000">sed like regular
                              expression</font><font color="#000000">.
                              flags can be a combination of i (case
                              insensitive), g (global) or s (match
                              newline don't treat it as end of line).</font></p>
                          <p style="color:rgb(0,0,0);text-align:justify">'re'
                            - is regular expression</p>
                          <p style="color:rgb(0,0,0);text-align:justify">'repl'
                            - is replacement string - may contain
                            pseudo-variables</p>
                          <p style="color:rgb(0,0,0);text-align:justify">'flags'
                            - substitution flags (i - ignore case, g -
                            global)</p>
                        </li>
                      </ul>
                    </div>
                  </div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div>I'm trying to use this:</div>
                  <div><br>
                  </div>
                  <div>subst_hf("X-myheader", "/^(?!string1
                    |example2-|text3 )(.*)/myprefix \1/", "a")<br>
                  </div>
                  <div><br>
                  </div>
                  <div>In an online tester using PCRE, the format is
                    correct, but Kamailio doesn't like it:</div>
                  <div><br>
                  </div>
                  <div>Oct  4 09:29:16 cops-n1 cops[15957]: ERROR:
                    <core> [core/re.c:285]: subst_parser(): bad
                    regular expression
                    ^(?!string1 |example2-|text3 )(.*) in
                    /^(?!string1 |example2-|text3 )(.*)/myprefix \1/<br>
                  </div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div>If I remove the negative lookahead chars (?!)
                    then kamailio doesn't complain but the regex doesn't
                    do what I want.</div>
                  <div><br>
                  </div>
                  <div>Does this mean that Kamailio won't support
                    negative lookahead for subst regex replacements?</div>
                  <div><br>
                  </div>
                  <div>What I'm trying to achieve is something along:</div>
                  <div><br>
                  </div>
                  <div>"If the value of the header Myheader doesn't
                    start with ABC, DEF or HIJ, then prefix it with XYZ"</div>
                  <div><br>
                  </div>
                  <div>Any suggestions/ideas on how to achieve this?</div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div>Thanks, </div>
                  <div>Joel.</div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                  <div><br>
                  </div>
                </div>
              </blockquote>
            </div>
          </blockquote>
        </div>
        <br>
        <fieldset></fieldset>
        <pre>__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
  * <a href="mailto:sr-users@lists.kamailio.org" target="_blank">sr-users@lists.kamailio.org</a>
Important: keep the mailing list in the recipients, do not reply only to the sender!
Edit mailing list options or unsubscribe:
  * <a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
      </blockquote>
      <pre cols="72">-- 
Daniel-Constantin Mierla -- <a href="http://www.asipto.com" target="_blank">www.asipto.com</a>
<a href="http://www.twitter.com/miconda" target="_blank">www.twitter.com/miconda</a> -- <a href="http://www.linkedin.com/in/miconda" target="_blank">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - Online
Nov 08-11, 2021 (Europe Timezone) - Nov 22-25, 2021 (America Timezone)
  * <a href="https://www.asipto.com/sw/kamailio-advanced-training-online/" target="_blank">https://www.asipto.com/sw/kamailio-advanced-training-online/</a></pre>
    </blockquote>
    <pre cols="72">-- 
Daniel-Constantin Mierla -- <a href="http://www.asipto.com" target="_blank">www.asipto.com</a>
<a href="http://www.twitter.com/miconda" target="_blank">www.twitter.com/miconda</a> -- <a href="http://www.linkedin.com/in/miconda" target="_blank">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - Online
Nov 08-11, 2021 (Europe Timezone) - Nov 22-25, 2021 (America Timezone)
  * <a href="https://www.asipto.com/sw/kamailio-advanced-training-online/" target="_blank">https://www.asipto.com/sw/kamailio-advanced-training-online/</a></pre>
  </div>

</blockquote></div>