]>
git.saurik.com Git - apple/security.git/blob - Network/file-protocol.cpp
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 // file-protocol - File protocol objects
22 #include "file-protocol.h"
23 #include "netmanager.h"
25 #include "netparameters.h"
33 // Construct the protocol object
35 FileProtocol::FileProtocol(Manager
&mgr
) : Protocol(mgr
, "file")
41 // Create a Transfer object for our protocol
43 FileProtocol::FileTransfer
*FileProtocol::makeTransfer(const Target
&target
, Operation operation
)
47 return new Reader(*this, target
);
50 return new Writer(*this, target
);
57 FileProtocol::FileTransfer::FileTransfer(FileProtocol
&proto
, const Target
&tgt
, Operation op
)
58 : Transfer(proto
, tgt
, op
)
62 int FileProtocol::FileTransfer::fileDesc() const
66 void FileProtocol::FileTransfer::transitError(const CssmCommonError
&error
)
75 FileProtocol::Reader::Reader(FileProtocol
&proto
, const Target
&tgt
)
76 : FileTransfer(proto
, tgt
, download
)
80 void FileProtocol::Reader::start()
82 open(target
.path
.c_str());
84 // notify any observer that we are under way.
85 observe(Observer::resourceFound
);
86 observe(Observer::downloading
);
89 int restartOffset
= getv
<int>(kNetworkRestartPosition
, 0);
92 size_t size
= fileSize() - restartOffset
;
95 protocol
.manager
.addIO(this);
98 void FileProtocol::Reader::transit(Event event
, char *, size_t)
100 assert(event
== autoReadDone
);
101 protocol
.manager
.removeIO(this);
109 FileProtocol::Writer::Writer(FileProtocol
&proto
, const Target
&tgt
)
110 : FileTransfer(proto
, tgt
, upload
)
114 void FileProtocol::Writer::start()
116 open(target
.path
.c_str(), O_WRONLY
| O_CREAT
);
118 // notify any observer that we are under way.
119 observe(Observer::resourceFound
);
120 observe(Observer::uploading
);
122 int restartOffset
= getv
<int>(kNetworkRestartPosition
, 0);
125 protocol
.manager
.addIO(this);
127 mode(source(), fileSize() - restartOffset
);
130 void FileProtocol::Writer::transit(Event event
, char *, size_t)
132 assert(event
== autoWriteDone
);
133 protocol
.manager
.removeIO(this);
138 } // end namespace Network
139 } // end namespace Security