]> git.saurik.com Git - apple/security.git/blob - Security/libsecurity_utilities/lib/inetreply.h
Security-57031.1.35.tar.gz
[apple/security.git] / Security / libsecurity_utilities / lib / inetreply.h
1 /*
2 * Copyright (c) 2000-2001,2003-2004,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 //
26 // inetreply - manage Internet-standard reply strings
27 //
28 // The InetReply class represents an Internet-standard reply line of the form
29 // nnn some text
30 //
31 #ifndef _H_INETREPLY
32 #define _H_INETREPLY
33
34 #include <security_utilities/utilities.h>
35 #include <cstdarg>
36
37
38 namespace Security {
39 namespace IPPlusPlus {
40
41
42 //
43 // An InetReply object represents a broken-up reply line of the form
44 // nnn(sp)text-form
45 // Note that this will take a *writable* input line buffer and munge it
46 // into shape. This means that
47 // (a) You have to keep the input line buffer alive until the InetReply dies, and
48 // (b) You can't use the input line buffer after the InetReply is constructed.
49 //
50 class InetReply {
51 public:
52 InetReply(const char *buffer);
53
54 bool valid() const { return mCode >= 0; }
55 unsigned int code() const { return mCode; }
56 operator unsigned int () const { return code(); }
57 unsigned int type() const { return mCode / 100; }
58 const char *message() const { return mMessage; }
59 bool isContinued() const { return mSeparator == '-'; }
60
61 private:
62 const char *mBuffer; // base buffer
63 int mCode; // integer code (usually nnn)
64 char mSeparator; // character after code (usually space; '-' for continued lines)
65 const char *mMessage; // rest of message
66
67 void analyze();
68
69 public:
70 //
71 // Handle FTP-style continuations: nnn- ... nnn<sp>Message
72 // Instructions for use:
73 // Continuation myCont; // in some persistent place
74 // ... get a line of reply -> const char *input ...
75 // if (myCont(input)) /* in (old) continuation */;
76 // InetReply reply(input);
77 // if (myCont(reply)) /* in (newly started) continuation */;
78 // /* not (any more) in continuation; reply has last message line
79 //
80 class Continuation {
81 public:
82 Continuation() : mActive(false) { }
83
84 bool operator () (const char *input);
85 bool operator () (const InetReply &reply);
86
87 bool active() const { return mActive; }
88
89 private:
90 bool mActive;
91 char mTestString[4];
92 };
93 };
94
95
96 } // end namespace IPPlusPlus
97 } // end namespace Security
98
99
100 #endif //_H_INETREPLY