source: trunk/axmpp/source/xmpp-sessions.ads

Last change on this file was 323, checked in by maxim.reznik, 5 years ago

Move TLS Handshake from Session to Network

  • Property svn:keywords set to Author Date Revision
File size: 10.9 KB
Line 
1------------------------------------------------------------------------------
2-- --
3-- AXMPP Project --
4-- --
5-- XMPP Library for Ada --
6-- --
7------------------------------------------------------------------------------
8-- --
9-- Copyright © 2011-2016, Alexander Basov <coopht@gmail.com> --
10-- All rights reserved. --
11-- --
12-- Redistribution and use in source and binary forms, with or without --
13-- modification, are permitted provided that the following conditions --
14-- are met: --
15-- --
16-- * Redistributions of source code must retain the above copyright --
17-- notice, this list of conditions and the following disclaimer. --
18-- --
19-- * Redistributions in binary form must reproduce the above copyright --
20-- notice, this list of conditions and the following disclaimer in the --
21-- documentation and/or other materials provided with the distribution. --
22-- --
23-- * Neither the name of the Alexander Basov, IE nor the names of its --
24-- contributors may be used to endorse or promote products derived from --
25-- this software without specific prior written permission. --
26-- --
27-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
28-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
29-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
30-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
31-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
32-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
33-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
34-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
35-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
36-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
37-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
38-- --
39------------------------------------------------------------------------------
40-- $Revision: 323 $ $Date: 2017-03-03 08:56:48 +0000 (Fri, 03 Mar 2017) $
41------------------------------------------------------------------------------
42
43with League.Strings;
44
45with XMPP.Networks;
46with XMPP.Stream_Handlers;
47with XMPP.Raw_Handlers;
48
49with XML.SAX.Attributes;
50with XML.SAX.Content_Handlers;
51with XML.SAX.DTD_Handlers;
52with XML.SAX.Declaration_Handlers;
53with XML.SAX.Entity_Resolvers;
54with XML.SAX.Error_Handlers;
55with XML.SAX.Lexical_Handlers;
56with XML.SAX.Locators;
57with XML.SAX.Parse_Exceptions;
58with XML.SAX.Pretty_Writers;
59with XML.SAX.Simple_Readers;
60with XML.SAX.String_Output_Destinations;
61
62with XMPP.IQS;
63with XMPP.Challenges;
64with XMPP.Objects;
65with XMPP.Idle_Tasks;
66
67package XMPP.Sessions is
68
69 procedure Initialize renames XMPP.Networks.Initialize;
70 -- This procedure should be called before use of Sessions
71
72 type XMPP_Session is limited
73 new XMPP.Networks.Notification
74 and XML.SAX.Content_Handlers.SAX_Content_Handler
75 and XML.SAX.Declaration_Handlers.SAX_Declaration_Handler
76 and XML.SAX.DTD_Handlers.SAX_DTD_Handler
77 and XML.SAX.Entity_Resolvers.SAX_Entity_Resolver
78 and XML.SAX.Error_Handlers.SAX_Error_Handler
79 and XML.SAX.Lexical_Handlers.SAX_Lexical_Handler with private;
80
81 type XMPP_Session_Access is access all XMPP_Session;
82
83 -- XMPP Session API
84 -- XXX : API which should be rewritten in proper place
85
86 procedure Bind_Resource (Self : not null access XMPP_Session;
87 Resource_Id : League.Strings.Universal_String
88 := League.Strings.Empty_Universal_String);
89 -- Binds resourse with specified Resource ID.
90
91 procedure Close (Self : in out XMPP_Session);
92 -- Closes XMPP session. Application should use this function to end
93 -- data exchange with xmpp server
94
95 procedure Discover_Information (Self : in out XMPP_Session;
96 JID : League.Strings.Universal_String);
97 -- Sending request for getting disco#info
98
99 procedure Discover_Items (Self : in out XMPP_Session;
100 JID : League.Strings.Universal_String);
101 -- Sending request for getting disco#items
102
103 procedure Establish_IQ_Session (Self : not null access XMPP_Session);
104 -- Establish real XMPP Session.
105
106 procedure Join_Multi_User_Chat
107 (Self : in out XMPP_Session;
108 Room : League.Strings.Universal_String;
109 Server : League.Strings.Universal_String;
110 Nick_Name : League.Strings.Universal_String);
111 -- Enters to the multichat Room, on the Server with the specified Nick_Name
112
113 procedure Open (Self : not null access XMPP_Session);
114 -- Initiates XMPP session. Application should use this function to start
115 -- data exchange with xmpp server
116
117 procedure Request_Roster (Self : not null access XMPP_Session);
118 -- Requests roster from server
119
120 procedure Request_Version
121 (Self : not null access XMPP_Session;
122 XMPP_Entity : League.Strings.Universal_String);
123 -- Requests information about the software application
124 -- associated with an XMPP entity
125
126 procedure Set_JID (Self : in out XMPP_Session;
127 JID : League.Strings.Universal_String);
128 -- Sets jabber ID. JID should be set without hostname
129
130 procedure Send_Object (Self : not null access XMPP_Session;
131 Object : XMPP.Objects.XMPP_Object'Class);
132 -- Sends XMPP Object
133
134 procedure Set_Password (Self : in out XMPP_Session;
135 Password : League.Strings.Universal_String);
136 -- Sets passowrd for jabber account
137
138 procedure Set_Raw_Handler
139 (Self : XMPP_Session;
140 Handler : not null access XMPP.Raw_Handlers.XMPP_Raw_Handler)
141 is null;
142 -- If application whants recieve RAW XML data, it should set Raw_Handler
143
144 procedure Set_Resource (Self : not null access XMPP_Session;
145 Resource_Id : League.Strings.Universal_String);
146 -- Function sets resource name which will be binded when client
147 -- is connected to server.
148
149 procedure Set_Stream_Handler
150 (Self : not null access XMPP_Session;
151 Handler : not null access XMPP.Stream_Handlers.XMPP_Stream_Handler'Class);
152 -- Application must set stream handler for the axmpp library.
153
154 procedure Set_Host (Self : not null access XMPP_Session;
155 Host : League.Strings.Universal_String);
156 -- Sets xmpp server host
157
158 procedure Set_Port (Self : not null access XMPP_Session;
159 Port : Natural);
160 -- Sets xmpp server port
161
162private
163
164 type XMPP_Session is limited new XMPP.Networks.Notification
165 and XML.SAX.Content_Handlers.SAX_Content_Handler
166 and XML.SAX.Declaration_Handlers.SAX_Declaration_Handler
167 and XML.SAX.DTD_Handlers.SAX_DTD_Handler
168 and XML.SAX.Entity_Resolvers.SAX_Entity_Resolver
169 and XML.SAX.Error_Handlers.SAX_Error_Handler
170 and XML.SAX.Lexical_Handlers.SAX_Lexical_Handler with
171 record
172 Session_Opened : Boolean := False;
173 Stream_Handler : XMPP.Stream_Handlers.XMPP_Stream_Handler_Access;
174
175 Locator : XML.SAX.Locators.SAX_Locator;
176 Tag : League.Strings.Universal_String;
177
178 Network : aliased XMPP.Networks.Network (XMPP_Session'Unchecked_Access);
179 Reader : aliased XML.SAX.Simple_Readers.Simple_Reader;
180 Writer : XML.SAX.Pretty_Writers.XML_Pretty_Writer;
181 Output :
182 aliased XML.SAX.String_Output_Destinations.String_Output_Destination;
183
184 Stack : XMPP.Objects.Object_Vectors.Vector;
185
186 Idle_Task : XMPP.Idle_Tasks.Reader_Task;
187 Authenticated : Boolean := False;
188
189 JID : League.Strings.Universal_String;
190 Password : League.Strings.Universal_String;
191
192 Host : League.Strings.Universal_String;
193 Port : Natural := 5222;
194
195 In_IQ_Mode : Boolean := False;
196 IQ_Header : XMPP.IQS.XMPP_IQ;
197 Resource_Id : League.Strings.Universal_String
198 := League.Strings.To_Universal_String ("axmpp");
199 end record;
200
201 -- overriding from SAX.Reader
202 overriding procedure Characters
203 (Self : in out XMPP_Session;
204 Text : League.Strings.Universal_String;
205 Success : in out Boolean);
206
207 overriding procedure End_Element
208 (Self : in out XMPP_Session;
209 Namespace_URI : League.Strings.Universal_String;
210 Local_Name : League.Strings.Universal_String;
211 Qualified_Name : League.Strings.Universal_String;
212 Success : in out Boolean);
213
214 overriding function Error_String (Self : XMPP_Session)
215 return League.Strings.Universal_String;
216
217 overriding procedure Fatal_Error
218 (Self : in out XMPP_Session;
219 Occurrence : XML.SAX.Parse_Exceptions.SAX_Parse_Exception);
220
221 overriding procedure Start_Element
222 (Self : in out XMPP_Session;
223 Namespace_URI : League.Strings.Universal_String;
224 Local_Name : League.Strings.Universal_String;
225 Qualified_Name : League.Strings.Universal_String;
226 Attributes : XML.SAX.Attributes.SAX_Attributes;
227 Success : in out Boolean);
228
229 -- Overriding functions from XMPP_Network
230 overriding procedure On_Connect (Self : not null access XMPP_Session);
231
232 overriding procedure On_Disconnect (Self : not null access XMPP_Session);
233
234 overriding function Read_Data (Self : not null access XMPP_Session)
235 return Boolean;
236
237 -- Session private functions
238
239 function Is_Opened (Self : XMPP_Session) return Boolean;
240
241 procedure Open_Stream (Self : not null access XMPP_Session);
242
243 procedure Send_Wide_Wide_String (Self : in out XMPP_Session;
244 Str : Wide_Wide_String);
245
246 procedure Process_IQ (Self : in out XMPP_Session;
247 IQ : XMPP.Objects.XMPP_Object_Access);
248 -- IQ empty in case of result of session.
249
250 procedure Proceed_TLS_Auth (Self : not null access XMPP_Session);
251
252 procedure Proceed_SASL_Auth
253 (Self : not null access XMPP_Session;
254 Object : not null XMPP.Challenges.XMPP_Challenge_Access);
255
256 procedure Disconnect (Self : in out XMPP_Session);
257
258end XMPP.Sessions;
Note: See TracBrowser for help on using the repository browser.