2017-01-08 26 views
0

我正在嘗試編寫一個簡單的Ada(帶AWS)程序來將數據發佈到服務器。 curl命令工作如下,成功登錄後,在返回JSON有效響應:AWS.Client引發PROGRAM_ERROR:aws-client.adb:543敲定異常

curl -XPOST -d '{"type":"m.login.password", "user":"xxx", "password": "xxxxxxxxxx"}' "https://matrix.org/_matrix/client/r0/login" 

我的Ada程序:

with Ada.Exceptions; use Ada.Exceptions; 
with Ada.Text_Io;  use Ada.Text_IO; 

with AWS.Client; 
with AWS.Communication.Client; 
with AWS.MIME; 
with AWS.Net; 
with AWS.Response; 

use AWS; 


procedure Communicate is 

    Result : Response.Data; 
    Data : String := "{""type"":""m.login.password"", ""user"":""xxx"", ""password"": ""xxxxxxxxxx""}"; 

begin 

    Result := Client.Post 
     (URL => "https://matrix.org/_matrix/client/r0/login", 
     Data => Data, 
     Content_Type => AWS.MIME.Application_JSON) ; 

    Put_Line (Response.Message_Body (Result)) ; 

end Communicate; 

異常升高。我無法弄清楚這段代碼有什麼問題。

$ ./Communicate 

raised PROGRAM_ERROR : aws-client.adb:543 finalize/adjust raised exception 

測試代碼,你可以在http://matrix.org創建一個帳戶,並更換登錄憑證。

感謝。

阿德里安

+0

您的AWS是否包含SSL支持? FWIW,我在AWS.NET.SSL中的'/users/bauhaus/src/aws/src/core/aws-client.adb:210'調用'initialize'處看到相同的消息和調試點(aws-net-ssl__dummy .adb:148),該軟件包聲稱「每次使用此接口都會引發Program_Error異常。」 – B98

+0

如何檢查AWS是否包含SSL支持? –

+0

事實上,也就是在安裝之後,我首先看看libaws所需的其他庫。例如,通過在Mac上運行'xcrun dyldinfo -dylibs'或在GNU/Linux上運行'ldd'。 (第二個列表是libgnutls。)否則,應該有一些包含該信息的安裝過程的日誌。 – B98

回答

1

一些小的改動(主要是因爲我不喜歡的編譯器警告),以及適應於AWS的是Debian /傑西版本後,我得到它的工作。

這裏的改編版:

with Ada.Text_IO;  use Ada.Text_IO; 

with AWS.Client; 
-- with AWS.MIME; 
with AWS.Response; 

use AWS; 

procedure Communicate is 

    Result : Response.Data; 
    Data : constant String := 
         "{""type"":""m.login.password"", ""user"":""xxx"", " & 
         """password"": ""xxxxxxxxxx""}"; 

begin 
    Result := Client.Post 
     (URL   => "https://matrix.org/_matrix/client/r0/login", 
     Data   => Data, 
     Content_Type => "application/json"); 
    -- Content_Type => AWS.MIME.Application_JSON); 

    Put_Line (Response.Message_Body (Result)); 
end Communicate; 

這裏是我的項目文件:

with "aws"; 

project Communicate is 
    for Main use ("communicate"); 

    package Builder is 
     for Default_Switches ("Ada") 
     use ("-m"); 
    end Builder; 

    package Compiler is 
     for Default_Switches ("Ada") 
     use ("-fstack-check", -- Generate stack checking code (part of Ada) 
      "-gnata",  -- Enable assertions   (part of Ada) 
      "-gnato13",  -- Overflow checking   (part of Ada) 
      "-gnatf",      -- Full, verbose error messages 
      "-gnatwa",      -- All optional warnings 
      "-gnatVa",      -- All validity checks 
      "-gnaty3abcdefhiklmnoOprstux", -- Style checks 
      "-gnatwe",      -- Treat warnings as errors 
      "-gnat2012",     -- Use Ada 2012 
      "-Wall",      -- All GCC warnings 
      "-O2");      -- Optimise (level 2/3) 
    end Compiler; 
end Communicate; 

我建搭配方案:

% gprbuild -P communicate 
gnatgcc -c -fstack-check -gnata -gnato13 -gnatf -gnatwa -gnatVa -gnaty3abcdefhiklmnoOprstux -gnatwe -gnat2012 -Wall -O2 communicate.adb 
gprbind communicate.bexch 
gnatbind communicate.ali 
gnatgcc -c b__communicate.adb 
gnatgcc communicate.o -L/usr/lib/x86_64-linux-gnu -lgnutls -lz -llber -lldap -lpthread -o communicate 
% 

然後用測試

% ./communicate 
{"errcode":"M_FORBIDDEN","error":"Invalid password"} 
% 

看起來問題存在於您的AWS版本/安裝中。

+0

它不起作用。我懷疑@ B98所指的是什麼。 –

0

通過使用MacPorts中的gnutls構建AWS解決了問題。 Apple自OS X Lion以來不推薦使用OpenSSL,並使用CommonCrypto,因此現代macOS不包含OpenSSL。解決方案是從Mac端口或Home Brew下載並安裝OpenSSL或gnutls。

另一個問題是蘋果公司自El Capitan以來推出了SIP(系統完整性保護)。啓用S​​IP後,具有管理員權限的用戶無法更改/ usr/include和/ usr/lib中的內容。

Mac端口安裝到/ opt/local,因此我引用了/ opt/local/include和/ opt/local/lib,以便AWS可以使用OpenSSL或gnutls進行構建。