comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Problem with Unbounded Strings
Date: Fri, 4 Dec 2015 23:23:50 +0100
Date: 2015-12-04T23:23:50+01:00	[thread overview]
Message-ID: <3t2zcznh7x3c$.1gg5z5cxi63r3.dlg@40tude.net> (raw)
In-Reply-To: f29cf0ba-c0a4-4b85-8a2a-6533750d08f0@googlegroups.com

On Fri, 4 Dec 2015 13:43:22 -0800 (PST), Laurent wrote:

> On Friday, 4 December 2015 21:34:59 UTC+1, Dmitry A. Kazakov  wrote:
>> On Fri, 4 Dec 2015 08:53:54 -0800 (PST), in comp.lang.ada you wrote:
>> 
>>> I don't use append?
>> 
>> No. There is nothing that is not in the buffer read already. Why would you
>> append anything?
>> 
>> In some protocols payload data are accumulated from several packets.
>> Unbounded_String is not used for that either. You want to limit the size of
>> the accumulated data to prevent DoS attacks unless the protocol limits that
>> already, as most protocols do. Simply keep the buffer in the communication
>> object, that is all.
> 
> DoS attacks? Why should I care in this case.

Corrupt files?

> I use the Unbounded Strings because I don't know in advance how many lines
> the message will be long. So I collect everything in a buffer, appending
> the following lines, so that it makes sense and when the message is
> complete, feed it to next procedure which slices of the interesting parts
> and uses them to generate a message object which I store somewhere or
> whatever if I should ever get so far.

No, the strategy is to pass lines or other parts of the message further
instead of accumulating it in the memory. Instead of this "hamster" design
I would do something like:

type Log_Parser
     (  Stream : not null access Root_Stream_Type'Class;
        Size : Positive
     )  is new Ada.Finalization.Limited_Controlled with
record
   Buffer : String (1..Size); -- Input is accumulated here
   Last : Natural; -- Current message line last character in Line_Buffer
   Stamp : Time; -- Current message's time stamp
   Line_No : Positive; -- Current message's line number
   ...
end record;

function Get_Line (Source : not null access Log_Parser) return String;
   -- reads from stream and returns Source.Buffer (1..Source.Last)

This will work with files as well. The client will call Get_Line for each
message line.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2015-12-04 22:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-04 15:49 Problem with Unbounded Strings Laurent
2015-12-04 16:04 ` Dmitry A. Kazakov
2015-12-04 16:53   ` Laurent
2015-12-04 18:00     ` Niklas Holsti
2015-12-04 21:05       ` Laurent
2015-12-04 20:34     ` Dmitry A. Kazakov
2015-12-04 21:43       ` Laurent
2015-12-04 22:23         ` Dmitry A. Kazakov [this message]
2015-12-05 10:22           ` Laurent
2015-12-05 12:19             ` Dmitry A. Kazakov
2015-12-05 13:15               ` Laurent
2015-12-04 18:08 ` Jeffrey R. Carter
2015-12-04 21:21   ` Laurent
2015-12-04 21:59     ` Simon Wright
2015-12-04 23:19       ` Laurent
2015-12-04 22:02     ` Dmitry A. Kazakov
2015-12-04 22:28     ` Jeffrey R. Carter
2015-12-04 23:35       ` Laurent
2015-12-04 23:59         ` Jeffrey R. Carter
2015-12-05 10:13           ` Laurent
2015-12-08  1:53           ` Randy Brukardt
2015-12-04 23:00     ` Ben Bacarisse
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox