]>
git.saurik.com Git - apple/security.git/blob - Network/xfercore.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // xfercore - core data transfer engine
25 #include <Security/ip++.h>
26 #include <Security/selector.h>
27 #include <Security/buffers.h>
28 #include <Security/streams.h>
31 #if defined(SOCKS_SUPPORT)
32 # include <Security/socks++.h>
33 # define TCPClientSocket SocksClientSocket
34 # define TCPServerSocket SocksServerSocket
37 using Security::Buffer
;
38 using namespace IPPlusPlus
;
45 class TransferEngine
: public Selector
{
48 virtual ~TransferEngine() { }
51 class Client
: public Selector::Client
{
52 friend class TransferEngine
;
59 invalidInput
, // error mode (invalid)
60 connecting
, // working on TCP connection
61 rawInput
, // raw chunk input (whatever's on the wire)
62 lineInput
, // Internet lines input (\r\n)
63 autoReadInput
, // bulk read to docked sink
65 autoIODone
// transiition marker
67 InputMode
mode() const { return mMode
; }
68 void mode(InputMode m
); // set (switch) mode
69 void mode(Sink
&sink
, size_t byteCount
= 0);
71 void mode(Source
&source
, size_t byteCount
= 0);
72 bool autoWriteActive() const { return mSource
; }
74 enum Event
{ // event type: (input, length) arguments
75 inputAvailable
, // input available in current mode: (data, length)
76 connectionDone
, // TCP connection event: (NULL, errno)
77 autoReadDone
, // autoReadInput has completed: (NULL, 0)
78 autoWriteDone
, // autoWriteOutput has completed: (NULL, 0)
79 endOfInput
, // end of data stream from remote end: (NULL, 0)
80 ioError
// I/O failed: (CssmCommonError *, 0)
83 virtual void transit(Event event
, char *data
= NULL
, size_t length
= 0) = 0;
84 virtual void transitError(const CssmCommonError
&error
) = 0;
85 virtual int fileDesc() const = 0;
88 // override this to implement I/O filters - default is pass-through
89 virtual size_t read(void *data
, size_t size
);
90 virtual size_t write(const void *data
, size_t size
);
91 virtual bool atEnd() const;
94 void printf(const char *format
, ...);
95 void printfe(const char *format
, ...);
96 void vprintf(const char *format
, va_list args
);
97 void vprintfe(const char *format
, va_list args
);
99 void flushOutput(bool autoFlush
= true);
104 void notify(int fd
, Type type
);
107 void rawInputTransit();
108 void lineInputTransit();
109 void autoReadInputTransit();
115 InputMode mMode
; // current mode
116 bool mAutoCopyOut
; // auto-copyout overlay mode
117 Sink
*mSink
; // sink for autoReadInput mode
118 Source
*mSource
; // source for copyout overlay mode
119 size_t mResidualReadCount
; // bytes left to autoReadInput (zero => unlimited)
120 size_t mResidualWriteCount
; // bytes left to autoCopyOut (zero => unlimited)
121 bool mAutoFlush
; // output auto-flush mode
130 void add(Client
*client
);
131 void remove(Client
*client
);
135 } // end namespace Network
136 } // end namespace Security