Problem extending library(http/http_client)

View: New views
8 Messages — Rating Filter:   Alert me  

Problem extending library(http/http_client)

by Eckard Brauer-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

trying to do some automatic web session, I found that http_client won't
accept https: URLs, so I tried to extend it a bit.

Trying something like:

( verify(_,_,_);
  assert(verify(_,_,_)) ),
ssl_init(SSL, client, [host('www.myhost.de'),
    port(443), peer_cert(false), cert_verify_hook(verify)]),
ssl_open(SSL, In, Out),
http_get([socket(In, Out), protocol('http'), port(443),
    host('www.myhost.de'), path('/')], Data,
    [reply_header(H), connection('keep-alive')]),
close(In), close(Out),
ssl_exit(SSL).

works for me, but with the attached version of http_client.pl

http_get('https://www.myhost.de/', Data,
    [peer_cert(false), cert_verify_hook(user:verify)])

raises an exception in ssl_open/3.

Can someone please comment on this?

Eckard



my_http_client.pl (18K) Download Attachment
signature.asc (205 bytes) Download Attachment

Re: Problem extending library(http/http_client)

by Jan Wielemaker-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 26 October 2009 02:03:44 pm Eckard Brauer wrote:

> Hello,
>
> trying to do some automatic web session, I found that http_client won't
> accept https: URLs, so I tried to extend it a bit.
>
> Trying something like:
>
> ( verify(_,_,_);
>   assert(verify(_,_,_)) ),
> ssl_init(SSL, client, [host('www.myhost.de'),
>     port(443), peer_cert(false), cert_verify_hook(verify)]),
> ssl_open(SSL, In, Out),
> http_get([socket(In, Out), protocol('http'), port(443),
>     host('www.myhost.de'), path('/')], Data,
>     [reply_header(H), connection('keep-alive')]),
> close(In), close(Out),
> ssl_exit(SSL).
>
> works for me, but with the attached version of http_client.pl
>
> http_get('https://www.myhost.de/', Data,
>     [peer_cert(false), cert_verify_hook(user:verify)])
>
> raises an exception in ssl_open/3.

Well, knowing the exception surely would help, but it might be
that verify/3 is not defined?  If so, that is easily explained:
it is defined in a module and you call it in user.

        Cheers --- Jan

P.s. The way to implement this is using a hook that is filled
        by the SSL libraries in a similar fashion as used for
        the HTTP server.

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: Problem extending library(http/http_client)

by Eckard Brauer-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Jan,

thank you for responding -- but see below. For reference, the current
http_client.pl is attached.

Jan Wielemaker <J.Wielemaker@...>:

> On Monday 26 October 2009 02:03:44 pm Eckard Brauer wrote:
> > Hello,
> >
> > trying to do some automatic web session, I found that http_client
> > won't accept https: URLs, so I tried to extend it a bit.
> >
> > Trying something like:
> >
> > ( verify(_,_,_);
> >   assert(verify(_,_,_)) ),
> > ssl_init(SSL, client, [host('www.myhost.de'),
> >     port(443), peer_cert(false), cert_verify_hook(verify)]),
> > ssl_open(SSL, In, Out),
> > http_get([socket(In, Out), protocol('http'), port(443),
> >     host('www.myhost.de'), path('/')], Data,
> >     [reply_header(H), connection('keep-alive')]),
> > close(In), close(Out),
> > ssl_exit(SSL).
> >
> > works for me, but with the attached version of http_client.pl
> >
> > http_get('https://www.myhost.de/', Data,
> >     [peer_cert(false), cert_verify_hook(user:verify)])
> >
> > raises an exception in ssl_open/3.
>
> Well, knowing the exception surely would help, but it might be
> that verify/3 is not defined?  If so, that is easily explained:
> it is defined in a module and you call it in user.
Actually, it's both defined in a module and in user (and even in
http_client didn't change things... (and, listing(user:verify) shows
the implementation.

The exception I got in the debugger when doing ssl_init/3 in line 95 is:

Exception: Domain error: `connection(keep-alive)' expected, found
`ssl_option'

while Host and Port contain the correct values (443 and the host name
I used) and Options is

[ peer_cert(false),
  cert_verify_hook(user:verify),
  connection('keep-alive')
]



> P.s. The way to implement this is using a hook that is filled
> by the SSL libraries in a similar fashion as used for
> the HTTP server.

I'd be willing to change in whatever way you want it (and you explain
to me -- please keep in mind that I'm far from what one would call a
Prolog expert), do you mean that I'd rather have the connection handled
outside and passed in with Options list? Should't the TCP connection
for the http:// case handled the same way? Doesn't that make the
predicate more and more incomplete and its use complicated?

My original intention was indeed to first have a connection, either TCP
or SSL or whatever, and after that handle all protocol issues as
independent from this connection as possible. That would also allow
both SMTP and SSMTP or POP3 and POP3S protocols with single
implementations...

Kind regards!
Eckard



my_http_client.pl (18K) Download Attachment
signature.asc (205 bytes) Download Attachment

Strange solution to linear programming problem

by Mihai Fonoage :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everyone,

I have the following linear problem:

post_constraints -->
        constraint([x1] = 1),
        constraint([x2] =< 1),
        constraint([x3] =< 1),
        constraint([x4] =< 1),

        constraint([x1, -(1)*x4] =0 ),
        constraint([-(2)*x4, x3, x2] >= 0),

        constraint(integral(x1)),
        constraint(integral(x2)),
        constraint(integral(x3)),
        constraint(integral(x4)).

model(S) :- gen_state(S0), post_constraints(S0,S1),
minimize([x1,x2,x3,x4],S1,S).

When I run with the command:

model(S), variable_value(S,x1,Val1), variable_value(S,x2,Val2),
variable_value(S,x3,Val3), variable_value(S,x4,Val4), print(Val1),
print(Val2), print(Val3), print(Val4).

I get Val1 = Val2 = Val3 = Val4 = 0. This violates the first constraint that
specifies x1 = 1. The solution should be that all variables are 1. Is my
understanding incorrect?

Thank you,
Mihai Fonoage


_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: Strange solution to linear programming problem

by Markus Triska-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Mihai,

"Mihai Fonoage" <mfonoage@...> writes:

> I get Val1 = Val2 = Val3 = Val4 = 0. This violates the first
> constraint that specifies x1 = 1. The solution should be that all
> variables are 1. Is my understanding incorrect?

No, library(simplex) is incorrect for equalities! I will try to correct
this error. Please consider library(clpq) as a possible alternative for
library(simplex) in the meantime. library(simplex)'s transportation/4
and assignment/2 are not affected by this problem.

Thank you and all the best,
Markus
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

RE: Strange solution to linear programming problem

by Mihai Fonoage :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for letting me know Markus.

Sincerely,
Mihai Fonoage

-----Original Message-----
From: Markus Triska [mailto:markus.triska@...]
Sent: Sunday, November 01, 2009 4:07 PM
To: Mihai Fonoage
Cc: swi-prolog@...
Subject: Re: [SWIPL] Strange solution to linear programming problem

Hi Mihai,

"Mihai Fonoage" <mfonoage@...> writes:

> I get Val1 = Val2 = Val3 = Val4 = 0. This violates the first
> constraint that specifies x1 = 1. The solution should be that all
> variables are 1. Is my understanding incorrect?

No, library(simplex) is incorrect for equalities! I will try to correct
this error. Please consider library(clpq) as a possible alternative for
library(simplex) in the meantime. library(simplex)'s transportation/4
and assignment/2 are not affected by this problem.

Thank you and all the best,
Markus

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

Re: Strange solution to linear programming problem

by Markus Triska-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Mihai,

"Mihai Fonoage" <mfonoage@...> writes:

> I get Val1 = Val2 = Val3 = Val4 = 0. This violates the first constraint that
> specifies x1 = 1. The solution should be that all variables are 1.

I fixed this problem in development version V5.9.1-16-g2b79790 (you can
simply copy simplex.pl from git). You now get the solution you said:

   %?- model(S), maplist(variable_value(S), [x1,x2,x3,x4], Vs).
   %@ Vs = [1, 1, 1, 1].

Thank you for reporting this issue, please let me know if you find or
need anything else from the simplex library. There's definitely a lot of
room for improvement (for example, revised and dual simplex methods).
I'm building a growing collection of test cases for this library and
will gladly support all contributors with these tests and benchmarks.

Thank you and all the best,
Markus
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

RE: Strange solution to linear programming problem

by Mihai Fonoage :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Markus,

Thanks for solving the issue. If anything comes to mind, I will appreciate
your input.

Mihai Fonoage

-----Original Message-----
From: swi-prolog-admin@...
[mailto:swi-prolog-admin@...] On Behalf Of Markus Triska
Sent: Saturday, November 14, 2009 8:32 AM
To: Mihai Fonoage
Cc: swi-prolog@...
Subject: Re: [SWIPL] Strange solution to linear programming problem

Hi Mihai,

"Mihai Fonoage" <mfonoage@...> writes:

> I get Val1 = Val2 = Val3 = Val4 = 0. This violates the first constraint
that
> specifies x1 = 1. The solution should be that all variables are 1.

I fixed this problem in development version V5.9.1-16-g2b79790 (you can
simply copy simplex.pl from git). You now get the solution you said:

   %?- model(S), maplist(variable_value(S), [x1,x2,x3,x4], Vs).
   %@ Vs = [1, 1, 1, 1].

Thank you for reporting this issue, please let me know if you find or
need anything else from the simplex library. There's definitely a lot of
room for improvement (for example, revised and dual simplex methods).
I'm building a growing collection of test cases for this library and
will gladly support all contributors with these tests and benchmarks.

Thank you and all the best,
Markus
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog