Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
connection.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 
21 /*
22  * connection.h
23  *
24  * Created on: 16 Mar 2015
25  * Author: billy
26  *
27  * @brief A datatype to encapsulate Server-Client connections.
28  * @addto@group network_group
29  * @{
30  */
31 
32 #ifndef CONNECTION_H_
33 #define CONNECTION_H_
34 
35 
36 #include "typedefs.h"
37 #include "byte_buffer.h"
38 #include "curl_tools.h"
39 #include "network_library.h"
40 #include "jansson.h"
41 
47 typedef enum
48 {
51 
54 
58 
59 
65 typedef struct Connection
66 {
68  uint32 co_id;
69 
72 } Connection;
73 
74 
75 
76 
84 typedef struct WebConnection
85 {
88 
91 
93  char *wc_uri_s;
95 
96 
97 #ifdef __cplusplus
98 extern "C"
99 {
100 #endif
101 
102 
103 
111 GRASSROOTS_NETWORK_API Connection *AllocateWebServerConnection (const char * const full_uri_s, CurlMode curl_mode);
112 
113 
122 
123 
131 GRASSROOTS_NETWORK_API const char *GetConnectionData (Connection *connection_p);
132 
133 
141 
142 
151 GRASSROOTS_NETWORK_API const char *MakeRemoteJsonCallViaConnection (Connection *connection_p, const json_t *req_p);
152 
153 
154 
158 GRASSROOTS_NETWORK_API bool SetConnectionCredentials (Connection *connection_p, const char *username_s, const char *password_s);
159 
160 
162 
163 
165 
166 
167 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 
176 #endif /* CONNECTION_H_ */
Connection::AllocateWebServerConnection
Connection * AllocateWebServerConnection(const char *const full_uri_s, CurlMode curl_mode)
Allocate a WebConnection to a Server.
Connection::FreeConnection
void FreeConnection(Connection *connection_p)
Free a Connection.
Connection::co_type
ConnectionType co_type
The ConnectionType for this Connection.
Definition: connection.h:71
CurlMode
CurlMode
An enum specifying where any resultant data from running a CurlTool will be stored.
Definition: curl_tools.h:41
Connection::AllocaterRawClientConnection
Connection * AllocaterRawClientConnection(int server_socket_fd)
Allocate a RawConnection to a Client.
Connection::SetConnectionCredentials
bool SetConnectionCredentials(Connection *connection_p, const char *username_s, const char *password_s)
GRASSROOTS_NETWORK_API
#define GRASSROOTS_NETWORK_API
Definition: network_library.h:46
CurlTool
A tool for making http(s) requests and responses.
Definition: curl_tools.h:74
network_library.h
InitConnection
bool InitConnection(Connection *connection_p, ConnectionType type)
ReleaseConnection
void ReleaseConnection(Connection *connection_p)
CT_NUM_TYPES
The number of possible ConnectionTypes.
Definition: connection.h:56
WebConnection
A Connection that uses http(s) communication.
Definition: connection.h:84
typedefs.h
Connection
The base class for building a Server-Client connection.
Definition: connection.h:65
WebConnection::wc_curl_p
CurlTool * wc_curl_p
The CurlTool that encapsulates the web-based calls.
Definition: connection.h:90
byte_buffer.h
CT_RAW
A raw socket-based connection.
Definition: connection.h:50
WebConnection::wc_base
Connection wc_base
The base Connection.
Definition: connection.h:87
Connection::co_id
uint32 co_id
The internal id for this Connection.
Definition: connection.h:68
WebConnection::wc_uri_s
char * wc_uri_s
The URI that the WebConnection is to.
Definition: connection.h:93
curl_tools.h
Connection::GetConnectionData
const char * GetConnectionData(Connection *connection_p)
Get the data stored in a Connection's buffer.
Connection::MakeRemoteJsonCallViaConnection
const char * MakeRemoteJsonCallViaConnection(Connection *connection_p, const json_t *req_p)
Send JSON-based data over a Connection.
ConnectionType
ConnectionType
An enumeration listing the different types of Connections.
Definition: connection.h:47
CT_WEB
A connection using http(s)
Definition: connection.h:53