monotone

monotone Mtn Source Tree

Root/botan/out_buf.cpp

1/*************************************************
2* Pipe Output Buffer Source file *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/out_buf.h>
7#include <botan/secqueue.h>
8
9namespace Botan {
10
11/*************************************************
12* Read data from a message *
13*************************************************/
14u32bit Output_Buffers::read(byte output[], u32bit length, u32bit msg)
15 {
16 SecureQueue* q = get(msg);
17 if(q)
18 return q->read(output, length);
19 return 0;
20 }
21
22/*************************************************
23* Peek at data in a message *
24*************************************************/
25u32bit Output_Buffers::peek(byte output[], u32bit length,
26 u32bit stream_offset, u32bit msg) const
27 {
28 SecureQueue* q = get(msg);
29 if(q)
30 return q->peek(output, length, stream_offset);
31 return 0;
32 }
33
34/*************************************************
35* Check available bytes in a message *
36*************************************************/
37u32bit Output_Buffers::remaining(u32bit msg) const
38 {
39 SecureQueue* q = get(msg);
40 if(q)
41 return q->size();
42 return 0;
43 }
44
45/*************************************************
46* Add a new output queue *
47*************************************************/
48void Output_Buffers::add(SecureQueue* queue)
49 {
50 if(!queue)
51 throw Internal_Error("Output_Buffers::add: Argument was NULL");
52
53 if(buffers.size() == buffers.max_size())
54 throw Internal_Error("Output_Buffers::add: No more room in container");
55
56 buffers.push_back(queue);
57 }
58
59/*************************************************
60* Retire old output queues *
61*************************************************/
62void Output_Buffers::retire()
63 {
64 while(buffers.size())
65 {
66 if(buffers[0] == 0 || buffers[0]->size() == 0)
67 {
68 buffers.pop_front();
69 offset++;
70 }
71 else
72 break;
73 }
74 }
75
76/*************************************************
77* Get a particular output queue *
78*************************************************/
79SecureQueue* Output_Buffers::get(u32bit msg) const
80 {
81 if(msg < offset)
82 return 0;
83 if(msg > message_count())
84 throw Internal_Error("Output_Buffers::get: msg > size");
85
86 return buffers[msg-offset];
87 }
88
89/*************************************************
90* Return the total number of messages *
91*************************************************/
92u32bit Output_Buffers::message_count() const
93 {
94 return (buffers.size() + offset);
95 }
96
97/*************************************************
98* Output_Buffers Constructor *
99*************************************************/
100Output_Buffers::Output_Buffers()
101 {
102 offset = 0;
103 }
104
105/*************************************************
106* Output_Buffers Destructor *
107*************************************************/
108Output_Buffers::~Output_Buffers()
109 {
110 for(u32bit j = 0; j != buffers.size(); j++)
111 delete buffers[j];
112 }
113
114}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status