1 /* 2 * Copyright (C) 2006-2021 Registro.br. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 1. Redistribution of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY REGISTRO.BR ``AS IS AND ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 * WARRANTIE OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 16 * EVENT SHALL REGISTRO.BR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 18 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 19 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 21 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 22 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 23 * DAMAGE. 24 */ 25 /* $Id$ */ 26 /** @file Response.H 27 * @brief EPP Response Class 28 */ 29 30 #ifndef __RESPONSE_H__ 31 #define __RESPONSE_H__ 32 33 #include <string> 34 #include <list> 35 #include <map> 36 37 #include "libepp_nicbr.H" 38 #include "StrUtil.H" 39 40 using std::string; 41 using std::list; 42 using std::map; 43 44 LIBEPP_NICBR_NS_BEGIN 45 46 /// EPP Response Class 47 class Response 48 { 49 public: 50 /// Result Codes - See RFC 3730 - Session 3 51 enum ResultCode { 52 UNSET = -1, 53 OK = 1000, 54 OK_ACTION_PENDING = 1001, 55 OK_NO_MESSAGES = 1300, 56 OK_ACK_DEQUEUE = 1301, 57 OK_ENDING_SESSION = 1500, 58 UNKNOWN_COMMAND = 2000, 59 COMMAND_SYNTAX_ERROR = 2001, 60 COMMAND_USE_ERROR = 2002, 61 PARAMETER_MISSING = 2003, 62 PARAMETER_RANGE_ERROR = 2004, 63 PARAMETER_SYNTAX_ERROR = 2005, 64 UNIMPLEMENTED_VERSION = 2100, 65 UNIMPLEMENTED_COMMAND = 2101, 66 UNIMPLEMENTED_OPTION = 2102, 67 UNIMPLEMENTED_EXTENSION = 2103, 68 BILLING_FAILURE = 2104, 69 NOT_RENEWABLE = 2105, 70 NOT_TRANSFERABLE = 2106, 71 AUTHENTICATION_ERROR = 2200, 72 AUTHORIZATION_ERROR = 2201, 73 INVALID_AUTHORIZATION_INFO = 2202, 74 PENDING_TRANSFER = 2300, 75 NOT_PENDING_TRANSFER = 2301, 76 OBJECT_EXISTS = 2302, 77 OBJECT_DOESNT_EXIST = 2303, 78 STATUS_PROHIBITS_OPERATION = 2304, 79 ASSOCIATION_PROHIBITS_OPERATION = 2305, 80 PARAMETER_POLICY_ERROR = 2306, 81 UNIMPLEMENTED_SERVICE = 2307, 82 DATA_MGMT_POLICY_VIOLATION = 2308, 83 COMMAND_FAILED = 2400, 84 COMMAND_FAILED_CLOSING_CONN = 2500, 85 AUTHENTICATION_ERROR_CLOSING_CONN = 2501, 86 SESSION_LIMIT_EXCEEDED = 2502 87 }; 88 89 struct ResultExtValue { 90 string value; 91 string xmlns; 92 string reason; 93 }; 94 95 struct ResultInfo { 96 string msg; 97 list<ResultExtValue> ext_values; 98 }; 99 100 /// Default constructor 101 Response(bool reset = true) 102 { 103 if (reset) { 104 this->reset(); 105 } 106 } 107 108 /// Sets the client transaction ID 109 /** 110 @param clTRID Client transacion ID 111 */ set_clTRID(const string & clTRID)112 void set_clTRID(const string &clTRID) { _clTRID = clTRID; } 113 114 /// Sets the server transaction ID 115 /** 116 @param svTRID Server transacion ID 117 */ set_svTRID(const string & svTRID)118 void set_svTRID(const string &svTRID) { _svTRID = svTRID; } 119 120 /// Sets the result message language 121 /** 122 @param result_lang Result message language 123 */ set_result_lang(const string & result_lang)124 void set_result_lang(const string &result_lang) 125 { 126 _result_lang = result_lang; 127 } 128 129 /// Sets a result element 130 /** 131 @param code Result code 132 @param msg Response text 133 @param value value sub-element of extValue 134 @param xmlns value sub-element's attribute 135 @param reason reason sub-element of extValue 136 */ 137 void insert_result(const ResultCode &code, const string &msg, 138 const string &value = "", const string &xmlns = "", 139 const string &reason = "") 140 { 141 _result_list[code].msg = msg; 142 143 if (xmlns != "" || reason != "") { 144 struct ResultExtValue extValue; 145 if (value != "") { 146 extValue.value = value; 147 } else { 148 extValue.value = "<xml>Description unavailable</xml>"; 149 } 150 extValue.xmlns = xmlns; 151 extValue.reason = reason; 152 _result_list[code].ext_values.push_back(extValue); 153 } 154 } 155 156 /// Returns the client transaction ID 157 /** 158 @return Client transacion ID 159 */ get_clTRID()160 string get_clTRID() const { return _clTRID; } 161 162 /// Returns the servers transaction ID 163 /** 164 @return Server transacion ID 165 */ get_svTRID()166 string get_svTRID() const { return _svTRID; } 167 168 /// Returns the result message language 169 /** 170 @return Result message language 171 */ get_result_lang()172 string get_result_lang() { return _result_lang; } 173 174 /// Returns the list of result elements 175 /** 176 @return List of result elements 177 */ get_result_list()178 map<ResultCode, ResultInfo> get_result_list() const 179 { 180 return _result_list; 181 } 182 183 /// reset attributes reset()184 void reset() 185 { 186 _clTRID = ""; 187 _svTRID = ""; 188 _result_lang = "en"; 189 _result_list.clear(); 190 } 191 192 /// virtual destructor ~Response()193 virtual ~Response() {} 194 195 protected: 196 /// Client transaction ID 197 string _clTRID; 198 199 /// Server transaction ID 200 string _svTRID; 201 202 /// Result language 203 string _result_lang; 204 205 /// Result elements list 206 map<ResultCode, ResultInfo> _result_list; 207 }; 208 209 LIBEPP_NICBR_NS_END 210 #endif //__RESPONSE_H__ 211