]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/inetreply.h
Security-28.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / inetreply.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
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
8 * using this file.
9 *
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.
16 */
17
18
19 //
20 // inetreply - manage Internet-standard reply strings
21 //
22 // The InetReply class represents an Internet-standard reply line of the form
23 // nnn some text
24 //
25 #ifndef _H_INETREPLY
26 #define _H_INETREPLY
27
28 #include <Security/utilities.h>
29 #include <cstdarg>
30
31
32 namespace Security {
33 namespace IPPlusPlus {
34
35
36 //
37 // An InetReply object represents a broken-up reply line of the form
38 // nnn(sp)text-form
39 // Note that this will take a *writable* input line buffer and munge it
40 // into shape. This means that
41 // (a) You have to keep the input line buffer alive until the InetReply dies, and
42 // (b) You can't use the input line buffer after the InetReply is constructed.
43 //
44 class InetReply {
45 public:
46 InetReply(const char *buffer);
47
48 bool valid() const { return mCode >= 0; }
49 unsigned int code() const { return mCode; }
50 operator unsigned int () const { return code(); }
51 unsigned int type() const { return mCode / 100; }
52 const char *message() const { return mMessage; }
53 bool isContinued() const { return mSeparator == '-'; }
54
55 private:
56 const char *mBuffer; // base buffer
57 int mCode; // integer code (usually nnn)
58 char mSeparator; // character after code (usually space; '-' for continued lines)
59 const char *mMessage; // rest of message
60
61 void analyze();
62
63 public:
64 //
65 // Handle FTP-style continuations: nnn- ... nnn<sp>Message
66 // Instructions for use:
67 // Continuation myCont; // in some persistent place
68 // ... get a line of reply -> const char *input ...
69 // if (myCont(input)) /* in (old) continuation */;
70 // InetReply reply(input);
71 // if (myCont(reply)) /* in (newly started) continuation */;
72 // /* not (any more) in continuation; reply has last message line
73 //
74 class Continuation {
75 public:
76 Continuation() : mActive(false) { }
77
78 bool operator () (const char *input);
79 bool operator () (const InetReply &reply);
80
81 bool active() const { return mActive; }
82
83 private:
84 bool mActive;
85 char mTestString[4];
86 };
87 };
88
89
90 } // end namespace IPPlusPlus
91 } // end namespace Security
92
93
94 #endif //_H_INETREPLY