All Classes Namespaces Functions Variables Enumerations Enumerator Pages
protocol.h
1 /*
2  Copyright (c) 2014 by Elvis Angelaccio
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in
12  all copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  THE SOFTWARE.
21 */
22 
23 #ifndef PROTOCOL_H
24 #define PROTOCOL_H
25 
26 #include <string>
27 #include <stdexcept>
28 
29 namespace net
30 {
31 
33  typedef enum
34  {
35  UNSPECIFIED_COMMAND,
36  INSERT,
37  REMOVE,
38  GET,
39  SEARCH,
40  SPECLIST
41 
42  } Command;
43 
45  typedef enum
46  {
47  OK,
48  WRONG_AUTH,
49  INCOMPLETE_SET,
50  NO_SUCH_SPEC,
51  TOO_MUCH_DATA,
52  NO_SUCH_SET,
53  WRONG_TYPE,
54  UNKNOWN_NAME,
55  UNKNOWN_FIELD,
56  GENERIC_ERROR=99,
57  UNSPECIFIED_CODE
58 
59  } ResponseCode;
60 
61 
62  /* Commands strings */
63  const std::string INSERT_CMD = "INSERT";
64  const std::string REMOVE_CMD = "REMOVE";
65  const std::string GET_CMD = "GET";
66  const std::string SEARCH_CMD = "SEARCH";
67  const std::string SPECLIST_CMD = "SPECLIST";
68 
69  /* Return codes strings */
70  const std::string OK_CODE = "0";
71  const std::string WRONG_AUTH_CODE = "1";
72  const std::string INCOMPLETE_SET_CODE = "2";
73  const std::string NO_SUCH_SPEC_CODE = "3";
74  const std::string TOO_MUCH_DATA_CODE = "4";
75  const std::string NO_SUCH_SET_CODE = "5";
76  const std::string WRONG_TYPE_CODE = "6";
77  const std::string UNKNOWN_NAME_CODE = "7";
78  const std::string UNKNOWN_FIELD_CODE = "8";
79  const std::string GENERIC_ERROR_CODE = "99";
80 
81  /* Return codes messages */
82  const std::string OK_MSG = "OK";
83  const std::string WRONG_AUTH_MSG = "Wrong authentication";
84  const std::string INCOMPLETE_SET_MSG = "Incomplete set";
85  const std::string NO_SUCH_SPEC_MSG = "No such specifier";
86  const std::string TOO_MUCH_DATA_MSG = "Too much data";
87  const std::string NO_SUCH_SET_MSG = "No such set";
88  const std::string WRONG_TYPE_MSG = "Wrong type";
89  const std::string UNKNOWN_NAME_MSG = "Unknown name";
90  const std::string UNKNOWN_FIELD_MSG = "Unknown field";
91  const std::string GENERIC_ERROR_MSG = "Generic error";
92 
93  /* Syntax strings */
94 
95  const std::string FILE_ACK = "ACK";
97  const std::string DSS_MARKER = "DSS";
98  const std::string SD_MARKER = "SD";
99  const std::string DI_MARKER = "DI";
100  const std::string DIFILES_MARKER = "DIFILES";
101  const std::string FOUND_MARKER = "FOUND";
102 
103  const std::string SN_SPECIAL_KEY = "SequenceNumber";
107  class ProtocolSyntaxError : public std::runtime_error
108  {
109  public:
110  ProtocolSyntaxError(const std::string& msg) : std::runtime_error(msg) {}
111  };
112 }
113 
114 
115 #endif
Definition: protocol.h:107
const std::string DSS_MARKER
Definition: protocol.h:97
Definition: client_protocol.cpp:725
Command
Definition: protocol.h:33
ResponseCode
Definition: protocol.h:45