replacement does not accept blank/spaces

Asked by JBelinchon

Hi, I am playing arround with the example:

loadable_modules /usr/local/lib/ecap_adapter_modifying.so
ecap_enable on
ecap_service ecapModifier respmod_precache \
    uri=ecap://e-cap.org/ecap/services/sample/modifying \
    victim=the \
    replacement=a
adaptation_access ecapModifier allow all

if I set something like this: replacement=a a (a string with a space) I get a malformed adaptation service configuration error when restarting Squid.

Any clue about how to fix this issue.

On the other hand the example with replacement-src, inject/replace the content of the file on top of the victim text.
Is there any way to doit the other way arround, I mean inject/replace the contect of the file AFTER the victim test.?

I have been reviwing the file adapter_modifying.cc and the function:

const std::string Adapter::Service::loadReplacement(const std::string &fname) {
        std::fstream input(fname.c_str(), std::ios_base::in);
        if (!input) {
                throw libecap::TextException(CfgErrorPrefix + "cannot open " +
                        "replacement-src file " + fname + " for reading: " + strerror(errno));
        }

        std::stringstream buf;
        buf << input.rdbuf(); // possibly slow but definitely simple
        if (input.bad()) {
                throw libecap::TextException(CfgErrorPrefix + "cannot read " +
                        "replacement-src file " + fname + ": " + strerror(errno));
        }
        return buf.str(); // may be empty
}

Could you please give me a clue about how to modify the fuction to append the contect of the file fname AFTER the victim string.

Thanks in advance and sorry my poor english. I am Spanish ;)

Question information

Language:
English Edit question
Status:
Answered
For:
eCAP Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

Have you tried
replacement=a\ a

Revision history for this message
JBelinchon (chuchete) said :
#2

With replacement=a\ a I still get the same error

/etc/squid/squid.conf:7989: malformed adaptation service configuration

Enviado desde Correo para Windows 10

De: Manfred Hampl
Enviado: jueves, 21 de diciembre de 2017 11:12
Para: <email address hidden>
Asunto: Re: [Question #662019]: replacement does not accept blank/spaces

Your question #662019 on eCAP changed:
https://answers.launchpad.net/ecap/+question/662019

    Status: Open => Needs information

Manfred Hampl requested more information:
Have you tried
replacement=a\ a

--
To answer this request for more information, you can either reply to
this email or enter your reply at the following page:
https://answers.launchpad.net/ecap/+question/662019

You received this question notification because you asked the question.

Revision history for this message
Manfred Hampl (m-hampl) said :
#3

Try

replacement="a a"
or
replacement=a%20a

(based on last paragraph in http://www.squid-cache.org/Doc/config/external_acl_type/ )

Revision history for this message
JBelinchon (chuchete) said :
#4

Hi, with a%20a Squid does not fail starting, but then the victim text is replaced by the string “a%20ª” and in in my HTML page I see a%20 instead a a.

If for example I want to replace <script> by <script src>, If I use %20 as space what I get is <script%20src>

Regards

Enviado desde Correo para Windows 10

De: Manfred Hampl
Enviado: jueves, 21 de diciembre de 2017 12:42
Para: <email address hidden>
Asunto: Re: [Question #662019]: replacement does not accept blank/spaces

Your question #662019 on eCAP changed:
https://answers.launchpad.net/ecap/+question/662019

    Status: Open => Answered

Manfred Hampl proposed the following answer:
Try

replacement="a a"
or
replacement=a%20a

(based on last paragraph in http://www.squid-
cache.org/Doc/config/external_acl_type/ )

--
If this answers your question, please go to the following page to let us
know that it is solved:
https://answers.launchpad.net/ecap/+question/662019/+confirm?answer_id=2

If you still need help, you can reply to this email or go to the
following page to enter your feedback:
https://answers.launchpad.net/ecap/+question/662019

You received this question notification because you asked the question.

Revision history for this message
Manfred Hampl (m-hampl) said :
#5

Does
replacement="a a"
work?

Revision history for this message
JBelinchon (chuchete) said :
#6

Sorry I didn't confirm that in my last email, it doesn't work either

Enviado desde Correo para Windows 10

De: Manfred Hampl
Enviado: jueves, 21 de diciembre de 2017 14:52
Para: <email address hidden>
Asunto: Re: [Question #662019]: replacement does not accept blank/spaces

Your question #662019 on eCAP changed:
https://answers.launchpad.net/ecap/+question/662019

    Status: Open => Needs information

Manfred Hampl requested more information:
Does
replacement="a a"
work?

--
To answer this request for more information, you can either reply to
this email or enter your reply at the following page:
https://answers.launchpad.net/ecap/+question/662019

You received this question notification because you asked the question.

Revision history for this message
Manfred Hampl (m-hampl) said :
#7

It seems that you can only work with replacement-src then.

What do you get for
...
        victim = the \
        replacement-src =/directory/and/filename

where /directory/and/filename (to be adapted to your needs) points to a file that contains nothing but:
a a

Revision history for this message
JBelinchon (chuchete) said :
#8

"replacement-src" works just fine, but in my case using "replacement-src" replace the text before the string on "victim".

I would need the behaviour of "replacement-src" be the other way arround. I mean, I need the text be replace after the text on "victim". This sis way I decided to give a try to the "replace" method "

Enviado desde Correo para Windows 10

De: Manfred Hampl
Enviado: jueves, 21 de diciembre de 2017 15:37
Para: <email address hidden>
Asunto: Re: [Question #662019]: replacement does not accept blank/spaces

Your question #662019 on eCAP changed:
https://answers.launchpad.net/ecap/+question/662019

    Status: Open => Needs information

Manfred Hampl requested more information:
It seems that you can only work with replacement-src then.

What do you get for
...
        victim = the \
        replacement-src =/directory/and/filename

where /directory/and/filename (to be adapted to your needs) points to a file that contains nothing but:
a a

--
To answer this request for more information, you can either reply to
this email or enter your reply at the following page:
https://answers.launchpad.net/ecap/+question/662019

You received this question notification because you asked the question.

Revision history for this message
Alex Rousskov (rousskov) said :
#9

> if I set replacement=a a (a string with a space) I get a malformed adaptation service configuration error when restarting Squid.

This problem is about Squid, not eCAP in general. Squid cannot guess that your replacement value includes a space -- it stops parsing after it sees the first parameter delimiter (which is any whitespace). I do not recall whether Squid supports quoted arguments in this context, but it does not hurt to try to use quoted "a a" and see what happens, as Manfred Hampl has suggested.

Using replacement-src is also a good workaround that must work (assuming your file name does not have spaces in it).

> using "replacement-src" replace the text before the string on "victim"

This statement is incorrect. The sample adapter replaces the victim text with the replacement text. There is no "before" or "after" in this context. To replace X with Y, the sample adapter essentially removes X and then inserts Y in the position where X used to start.

If you want to preserve X while replacing it with Y, then replace X with XY or YX. In other words, use a replacement text that contains the victim text in the right position. AFAICT, the adapter will not try to replace X inside the replacement text (XY or YX).

Finally, you seem to be paying too much attention to the sample adapter -- it is not suitable for production use because its victim search algorithm is too dumb for most applications and because it does not handle commit content encodings such as gzip.

Can you help with this problem?

Provide an answer of your own, or ask JBelinchon for more information if necessary.

To post a message you must log in.