NCBI C++ ToolKit
nst_protocol_utils.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef NETSTORAGE_PROTOCOL_UTILS__HPP
2 #define NETSTORAGE_PROTOCOL_UTILS__HPP
3 
4 /* $Id: nst_protocol_utils.hpp 71295 2016-02-24 18:47:52Z satskyse $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Sergey Satskiy
30  *
31  * File Description: NetStorage communication protocol utils
32  *
33  */
34 
35 
36 #include <string>
39 
40 
42 
43 class CSocket;
44 
45 
46 const string kStatusOK = "OK";
47 const string kStatusError = "ERROR";
48 const string kMessageTypeReply = "REPLY";
49 
50 // Scope for errors and warnings
51 const string kScopeStdException = "std::exception";
52 const string kScopeUnknownException = "unknown_exception";
53 const string kScopeIMessage = "IMessage";
54 const string kScopeLogic = "logic";
55 
56 
57 
58 // Stores the parsed common fields of the incoming messages
60 {
62  m_SerialNumber(-1)
63  {}
64 
65  string m_MessageType;
67 };
68 
69 
70 // ICache settings which may appear in various requests
72 {
73  string m_ServiceName;
74  string m_CacheName;
75 };
76 
77 
78 // User key which may appear in various requests
79 struct SUserKey
80 {
81  string m_UniqueID;
82  string m_AppDomain;
83 };
84 
85 
86 
87 void SetSessionAndIPAndPHID(const CJsonNode & message,
88  const CSocket & peer);
89 
91 ExtractCommonFields(const CJsonNode & message);
92 
94 ExtractStorageFlags(const CJsonNode & message);
95 
97 ExtractICacheSettings(const CJsonNode & message);
98 
100 ExtractUserKey(const CJsonNode & message);
101 
102 
103 CJsonNode
104 CreateResponseMessage(Int8 serial_number);
105 
106 CJsonNode
107 CreateErrorResponseMessage(Int8 serial_number,
108  Int8 error_code,
109  const string & error_message,
110  const string & scope,
111  Int8 sub_code);
112 
113 void
114 AppendWarning(CJsonNode & message,
115  Int8 code,
116  const string & warning_message,
117  const string & scope,
118  Int8 sub_code);
119 
120 void
121 AppendError(CJsonNode & message,
122  Int8 code,
123  const string & error_message,
124  const string & scope,
125  Int8 sub_code,
126  bool update_status = true);
127 
128 
129 CJsonNode
130 CreateIssue(Int8 error_code,
131  const string & error_message,
132  const string & scope,
133  Int8 sub_code);
134 
135 
136 // true => all the values are filled
137 // false => error_sub_code has not been filled
138 bool GetReplyMessageProperties(const exception & ex,
139  string * error_scope,
140  Int8 * error_code,
141  unsigned int * error_sub_code);
142 
143 
145 
146 #endif
147 
JSON node abstraction.
CSocket::
unsigned TNetStorageFlags
Bitwise OR of ENetStorageFlags.
Definition: netstorage.hpp:147
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const string kMessageTypeReply
CJsonNode CreateIssue(Int8 error_code, const string &error_message, const string &scope, Int8 sub_code)
TNetStorageFlags ExtractStorageFlags(const CJsonNode &message)
const string kScopeIMessage
const string kStatusError
bool GetReplyMessageProperties(const exception &ex, string *error_scope, Int8 *error_code, unsigned int *error_sub_code)
CJsonNode CreateResponseMessage(Int8 serial_number)
CJsonNode CreateErrorResponseMessage(Int8 serial_number, Int8 error_code, const string &error_message, const string &scope, Int8 sub_code)
const string kStatusOK
void AppendError(CJsonNode &message, Int8 code, const string &error_message, const string &scope, Int8 sub_code, bool update_status=true)
const string kScopeStdException
SUserKey ExtractUserKey(const CJsonNode &message)
const string kScopeUnknownException
const string kScopeLogic
void AppendWarning(CJsonNode &message, Int8 code, const string &warning_message, const string &scope, Int8 sub_code)
void SetSessionAndIPAndPHID(const CJsonNode &message, const CSocket &peer)
SCommonRequestArguments ExtractCommonFields(const CJsonNode &message)
SICacheSettings ExtractICacheSettings(const CJsonNode &message)
Definition: inftrees.h:24
Modified on Tue Jul 23 17:57:58 2024 by modify_doxy.py rev. 669887