Recent

Author Topic: Brook 1.0 - A new framework for web was born  (Read 163052 times)

Giu

  • Full Member
  • ***
  • Posts: 131
Re: Brook 1.0 - A new framework for web was born
« Reply #195 on: February 25, 2014, 06:06:41 pm »
Mmm. You could try running sysinternals process monitor to see where the executable is looking for dlls...

Good idea, but it suppose it should found it.

Code: [Select]
"17:53:27,9445377","blog.exe","16148","QueryBasicInformationFile","D:\DevAux\LazComp\brook\demos\db\blog\sqlite3.dll","SUCCESS","CreationTime: 24/02/2014 16:31:42, LastAccessTime: 25/02/2014 13:40:48, LastWriteTime: 03/02/2014 21:06:00, ChangeTime: 01/01/1601 1:00:00, FileAttributes: A"

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Brook 1.0 - A new framework for web was born
« Reply #196 on: February 25, 2014, 06:41:34 pm »
So the next question is: do the bitness of the sqlite dll and the cgi exe match? Does that same dll work with regular sqldb Lazarus applications?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Giu

  • Full Member
  • ***
  • Posts: 131
Re: Brook 1.0 - A new framework for web was born
« Reply #197 on: February 25, 2014, 06:42:35 pm »
So the next question is: do the bitness of the sqlite dll and the cgi exe match? Does that same dll work with regular sqldb Lazarus applications?

It's suppose Brook uses sqldb for database connections...I mean...I suppose yes.

Silvio Clécio

  • Guest
Re: Brook 1.0 - A new framework for web was born
« Reply #198 on: February 25, 2014, 07:11:11 pm »
@Giu,

I believe you are doing something wrong in your project. Your CGI was compiled for Win 32 or 64? Your DLL is for Win 32 or 64? Your webserver runs in Win 32 or 64? I ask because you said that copied the DLL to the "system32" and "sysWow64" folders .

I see a way to you know where the problem lies: create a simple project (like a Program, and without Brook), and try to connect to a SQLite database. I'm sure this problem is not related to Brook!

Another tip: use the latest version of Brook, 3.0. Brook 2.6.4 no more implements persistence, but offers features for a programmer to use any persistence library, like SQLdb, Zeos, dOPF (https://github.com/silvioprog/dopf), JCore (https://github.com/jcmoraisjr/jcore) etc.

In current version, Brook provides an object for each request, see a diff:

form.html:

Code: [Select]
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
 <title>Person</title>
</head>
<body>
<form action="http://localhost/cgi-bin/cgi1.bf" method="post">
  <input type="text" name="id" />
  <input type="text" name="name" />
  <input type="submit" />
</form>
</body>
</html>

Brook 2.6.4:

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  BrookAction;

type
  TMyAction = class(TBrookAction)
  public
    procedure Post; override;
  end;

implementation

procedure TMyAction.Post;
begin
  // where's validation?
  Write('ID: %d, Name: %s', [Fields['id'].AsInt64, Fields['name'].AsString]); // where's reuse?
  // where's persistence?
end;

initialization
  TMyAction.Register('/person');

end.

Brook 3.0:

Code: [Select]
unit person;

{$mode objfpc}{$H+}

interface

uses
  SysUtils;

type
  EPerson = class(Exception);

  { TPerson }

  TPerson = class
  private
    FId: Int64;
    FName: string;
  public
    procedure Validate;
    procedure Save;
  published
    property Id: Int64 read FId write FId;
    property Name: string read FName write FName;
  end;

implementation

{ TPerson }

procedure TPerson.Validate;
begin
  if Trim(FName) = '' then
    raise EPerson.Create('Name must not be empty.');
end;

procedure TPerson.Save;
begin
  // implement your persistence here, using any framework like dpof: https://github.com/silvioprog/dopf
end;

end.

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  BrookAction, person;

type
  TMyAction = class(specialize TBrookEntityAction<TPerson>)
  public
    procedure Post; override;
  end;

implementation

procedure TMyAction.Post;
begin
  Entity.Validate; // Yes, my own validation!
  Write('ID: %d, Name: %s', [Entity.Id, Entity.Name]); // Yes, I'm reusing my object!
  Entity.Save; // I love it, my persistence using OPF (like https://github.com/jcmoraisjr/jcore or https://github.com/silvioprog/dopf) or DAO!
end;

initialization
  TMyAction.Register('/person');

end.

ps1: Please see this topic: http://lists.lazarus.freepascal.org/pipermail/lazarus/2014-February/085964.html

ps2: Join to the Lazarus mailing list too, most of the guys of this forum is registered there: http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Brook 1.0 - A new framework for web was born
« Reply #199 on: February 25, 2014, 07:45:53 pm »
So the next question is: do the bitness of the sqlite dll and the cgi exe match? Does that same dll work with regular sqldb Lazarus applications?

It's suppose Brook uses sqldb for database connections...I mean...I suppose yes.

"Suppose"? That doesn't really help. Brook db connections obviously don't work for you. Checking if a regular Lazarus database application (even the FPC bug report application http://wiki.lazarus.freepascal.org/Database_bug_reporting#FreePascal) works with the sqlite dll you use will confirm if the problem lies with your Brook installation or with your sqlite dll....

Also you haven't answered the question about bitness...

(These questions are BTW exactly the ones Silvio is asking as well)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Giu

  • Full Member
  • ***
  • Posts: 131
Re: Brook 1.0 - A new framework for web was born
« Reply #200 on: February 25, 2014, 07:56:18 pm »
Didn't understood what bitness means sorry, and yes, this could be the root of the problem, because with an standard project, problem is the same. I'm reinstalling Laz but 32b to see :-[

Silvio Clécio

  • Guest
Re: Brook 1.0 - A new framework for web was born
« Reply #201 on: February 26, 2014, 05:17:13 am »
Nice. Please post your new tests. This problem does not seem to be difficult to solve. Is not karma hehe... :)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Brook 1.0 - A new framework for web was born
« Reply #202 on: February 26, 2014, 06:05:40 am »
Quote
Didn't understood what bitness means sorry
32-bit, 64-bit and so on. The bitness between your executable and dll must match, since it also defines the ABI (a little humanic way to read it: it defines how your exe should call functions residing in the dll).

Giu

  • Full Member
  • ***
  • Posts: 131
Re: Brook 1.0 - A new framework for web was born
« Reply #203 on: February 26, 2014, 09:50:11 am »
Nice. Please post your new tests. This problem does not seem to be difficult to solve. Is not karma hehe... :)

I'm sure was sqlite3.dll bitness. I'm trying now with brook from github.


Quote
32-bit, 64-bit and so on. The bitness between your executable and dll must match, since it also defines the ABI (a little humanic way to read it: it defines how your exe should call functions residing in the dll).

I understand. Was my english fault :)

CCRDude

  • Hero Member
  • *****
  • Posts: 615
Re: Brook 1.0 - A new framework for web was born
« Reply #204 on: April 29, 2014, 01:07:29 pm »
Noticed Brook this morning and got interested by its features :)

Played around with the version that's part of CodeTyphon 4.70, but that was too old, so I downloaded the latest and installed that.

Both versions needed one change (applied in two locations) in BrookRouter.pas to be able to identify actions:
Code: [Select]
      if MatchPattern(PRoute^.Pattern, ARequest.PathInfo, VRedirect,
        VNames, VValues) then
      if MatchPattern(PRoute^.Pattern, ARequest.URI, VRedirect,
        VNames, VValues) then

When debugging, ARequest.Pathinfo always was set '127.0.0.1' (or 'localhost') when browsing http://localhost/info - comparing 127.0.0.1 e.g. to /info obviously fails. Passing ARquest.URI instead, it gets compared correctly. Difficult to debug deeper to the TRequest being outside of the Brook code, within the FCL I think.

That's Lazarus as Typhon IDE 4.7, using FPC 2.7.1, svn-rev 43727, with the Brook download from an hour ago.

My second issue that I wasn't able to fix yet is that Files is empty:
Code: [Select]
   { TSubmitAction }

   TSubmitAction = class(TBrookAction)
   public
      procedure Post; override;
   end;

implementation

{ TSubmitAction }
procedure TSubmitAction.Post;
var
   cID: Int64;
   fUploaded: TBrookUploadedFile;
begin
   Write('<html>');
   Write('<head>');
   Write('<title>submission</title>');
   Write('</head>');
   Write('<body>');
   try
      cID := StrToInt64Def(Self.Params.Values['id'], 0);
      if Self.Files.Count = 0 then begin
         Write('<p>' + IntToStr(cID) + ' - no attached file found.' + '</p>');
      end else begin
         fUploaded := Files.First;
         Write('<p>' + IntToStr(cID) + ' - filesize: ' + IntToStr(fUploaded.Size) + '</p>');
      end;
      Write('<a href="/info">back</a>');
   except
      on E: Exception do begin
         Write('[-] error handling is work in progress');
      end;
   end;
   Write('</body>');
   Write('</html>');
end;

I do upload the file using form output of another action
Code: [Select]
{ TInfoAction }

procedure TInfoAction.Get;
begin
   Write('<html>');
   Write('<head>');
   Write('<title>info</title>');
   Write('</head>');
   Write('<body>');
   Write('<form method="POST" action="/submit?id=10" enctype="multipart/form-data">');
   Write('<input type="file" />');
   Write('<input type="submit" />');
   Write('</form>');
   Write('</body>');
   Write('</html>');
end;           
Both registered this way:
Code: [Select]
initialization
   TSubmitAction.Register('/submit', rmPost);
   TInfoAction.Register('/info?id', rmGet, True);

end.

I always get Files.Count = 0. What am I doing wrong?

CCRDude

  • Hero Member
  • *****
  • Posts: 615
Re: Brook 1.0 - A new framework for web was born
« Reply #205 on: May 05, 2014, 07:04:48 pm »
Giving myself an answer: input needed to have name="something" set in HTML to have httpdefs from FCL recognize the submitted file.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Brook 1.0 - A new framework for web was born
« Reply #206 on: May 06, 2014, 01:14:18 am »
Quote
Giving myself an answer: input needed to have name="something" set in HTML to have httpdefs from FCL recognize the submitted file.
This is a bug I submitted years ago, some browsers don't send unnamed fields, some send with empty names. FCL automatically assigns a unique name, but the field will be unaccessible, just to avoid a crash (which was the bug).

cryptkeeper

  • Newbie
  • Posts: 2
Re: Brook 1.0 - A new framework for web was born
« Reply #207 on: May 10, 2014, 03:22:28 pm »
Hello guys
I just installed Brook framework from git repository. I tried install additional packages (brokers) for greyhond and zeosdb, but it seems, that some units are missing: BrookDatabase, BrookDBAction, BrookTable, BrookQuery and others needed for database support.
It's because are some big changes in Brook framework core or is something wrong with git repository?

regards

Silvio Clécio

  • Guest
Re: Brook 1.0 - A new framework for web was born
« Reply #208 on: May 14, 2014, 01:21:55 am »

aradeonas

  • Hero Member
  • *****
  • Posts: 824
Re: Brook 1.0 - A new framework for web was born
« Reply #209 on: May 26, 2014, 06:19:42 pm »
Hi
I check Brook demos but with db demos I get HTTP method not allowed for the requested resource.
i found http://lists.lazarus.freepascal.org/pipermail/lazarus/2014-February/086014.html but it does not help.
Idea?
thanks

 

TinyPortal © 2005-2018