-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBridge
More file actions
224 lines (221 loc) · 8.72 KB
/
Copy pathBridge
File metadata and controls
224 lines (221 loc) · 8.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* -*- c++ -*- */
///////////////////////////////////////////
// Bridge
// -------------------------------------
// file : Bridge
// author : Ben Kietzman
// begin : 2020-01-13
// copyright : Ben Kietzman
// email : ben@kietzman.org
///////////////////////////////////////////
/*! \file Bridge
* \brief Bridge Class
*/
#ifndef _COMMON_BRIDGE_
#define _COMMON_BRIDGE_
// {{{ includes
#include <ctime>
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <list>
#include <mutex>
#include <netdb.h>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <poll.h>
#include <pthread.h>
#ifdef COMMON_LINUX
#include <semaphore.h>
#endif
#include <string>
#ifdef COMMON_SOLARIS
#include <synch.h>
#endif
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <thread>
#include <vector>
using namespace std;
#include "File"
#include "Json"
#include "StringManip"
#include "Utility"
// }}}
extern "C++"
{
namespace common
{
// {{{ Bridge
//! Interfaces with Bridge.
/*!
* Provides an interfaces to Bridge.
*/
class Bridge
{
protected:
bool m_bAuthenticated;
bool m_bFailed;
bool m_bUseSecureBridge;
int m_fdSocket;
list<string> m_buffer[2];
size_t m_unThrottle;
size_t m_unUniqueID;
std::mutex m_mutexResource;
std::mutex m_mutexGetAddrInfo;
string m_strBuffer[2];
string m_strLine;
string m_strPassword;
string m_strPort;
string m_strTimeout;
string m_strUser;
string m_strUserID;
time_t m_CTime[2];
File m_file;
StringManip m_manip;
SSL *m_ssl;
SSL_CTX *m_ctx;
Utility *m_pUtility;
/*! \fn bool connect(string &strError)
* \brief Connects and registers the application to the Bridge.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool connect(string &strError);
/*! \fn bool disconnect(string &strError)
* \brief Disconnects the application from the Bridge.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool disconnect(string &strError);
/*! \fn bool getMessages(string &strError)
* \brief Receives incoming messages.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool getMessages(string &strError);
public:
Bridge(string &strError);
~Bridge();
/*! \fn void dbFree(list<map<string, string> > *result)
* \brief Frees query results.
* \param result Contains the query results.
*/
void dbFree(list<map<string, string> > *result);
/*! \fn list<map<string, string> > *dbQuery(const string strDatabase, const string strQuery, string &strError)
* \brief Sends a query request to a database.
* \param strDatabase Contains the database.
* \param strQuery Contains the query.
* \param strError Contains the error message.
* \return Returns a list of resultant rows containing maps of field/value pairs..
*/
list<map<string, string> > *dbQuery(const string strDatabase, const string strQuery, string &strError);
/*! \fn list<map<string, string> > *dbQuery(const string strDatabase, const string strQuery, unsigned long long &ullRows, string &strError)
* \brief Sends a query request to a database.
* \param strDatabase Contains the database.
* \param strQuery Contains the query.
* \param ullRows Contains the number of affected rows.
* \param strError Contains the error message.
* \return Returns a list of resultant rows containing maps of field/value pairs..
*/
list<map<string, string> > *dbQuery(const string strDatabase, const string strQuery, unsigned long long &ullRows, string &strError);
/*! \fn bool dbUpdate(const string strDatabase, const string strUpdate, string &strError)
* \brief Sends an update request to a database.
* \param strDatabase Contains the database.
* \param strQuery Contains the query.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool dbUpdate(const string strDatabase, const string strUpdate, string &strError);
/*! \fn bool dbUpdate(const string strDatabase, const string strUpdate, unsigned long long &ullID, unsigned long long &ullRows, string &strError)
* \brief Sends an update request to a database.
* \param strDatabase Contains the database.
* \param strQuery Contains the query.
* \param ullID Contains the returned ID.
* \param ullRows Contains the number of affected rows.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool dbUpdate(const string strDatabase, const string strUpdate, unsigned long long &ullID, unsigned long long &ullRows, string &strError);
/*! \fn bool application(const string strApplication, Json *ptMessage, string &strError)
* \brief Submits an application Bridge request.
* \param strApplication Contains the application.
* \param ptMessage Contains the message.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool application(const string strApplication, Json *ptMessage, string &strError);
/*! \fn bool getMessages(list<Json *> &messages, string &strError)
* \brief Receives incoming messages.
* \param messages Contains the messages.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool getMessages(list<Json *> &messages, string &strError);
/*! \fn bool passwordVerify(const string strApplication, const string strType, const string strUser, const string strPassword, string &strError)
* \brief Verifies SLA credentials.
* \param strApplication Contains the application.
* \param strType Contains the type.
* \param strUser Contains the user.
* \param strPassword Contains the password.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool passwordVerify(const string strApplication, const string strType, const string strUser, const string strPassword, string &strError);
/*! \fn bool putMessages(list<Json *> &messages, string &strError)
* \brief Sends an outgoing messages.
* \param messages Contains the messages.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool putMessages(list<Json *> &messages, string &strError);
/*! \fn bool request(Json *ptRequest, Json *ptResponse, string &strError)
* \brief Submits a Bridge request.
* \param ptRequest Contains the request.
* \param ptResponse Contains the response.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool request(Json *ptRequest, Json *ptResponse, string &strError);
/*! \fn bool request(Json *ptRequest, Json *ptResponse, time_t CTimeout, string &strError)
* \brief Submits an Bridge request.
* \param ptRequest Contains the request.
* \param ptResponse Contains the response.
* \param CTimeout Contains the timeout.
* \param strError Contains the error message.
* \return Returns a boolean true/false value.
*/
bool request(Json *ptRequest, Json *ptResponse, time_t CTimeout, string &strError);
/*! \fn void setCredentials(const string strUser, const string strPassword, const string strUserID = "")
* \brief Set the credentials.
* \param strUser Contains the user.
* \param strPassword Contains the password.
* \param strUserID Contains the user ID.
*/
void setCredentials(const string strUser, const string strPassword, const string strUserID = "");
/*! \fn void setThrottle(const size_t unThrottle)
* \brief Set the throttle.
* \param unThrottle Contains the throttle.
*/
void setThrottle(const size_t unThrottle);
/*! \fn void setTimeout(const string strTimeout)
* \brief Set the timeout.
* \param strTimeout Contains the timeout.
*/
void setTimeout(const string strTimeout);
/*! \fn void useSecureBridge(bool bUseSecureBridge)
* \brief Set the use secure bridge flag.
* \param bUseSecureBridge Contains a boolean value for the flag.
*/
void useSecureBridge(bool bUseSecureBridge);
/*! \fn Utility *utility()
* \brief Interfaces with the Utility class.
* \return Returns a pointer to the Utility class.
*/
Utility *utility();
};
// }}}
}
}
#endif