libdas2
das2 core C utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
http.h
Go to the documentation of this file.
1 /* Copyright (C) 2017 Chris Piker <chris-piker@uiowa.edu>
2  *
3  * This file is part of libdas2, the Core Das2 C Library.
4  *
5  * Libdas2 is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Lesser General Public License version 2.1 as published
7  * by the Free Software Foundation.
8  *
9  * Libdas2 is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * version 2.1 along with libdas2; if not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef _das_http_h_
19 #define _das_http_h_
20 
21 #include <stdbool.h>
22 
23 #include <das2/array.h>
24 #include <das2/credentials.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
41 #define DASURL_SZ_SCHEME 31
42 #define DASURL_SZ_HOST 63
43 #define DASURL_SZ_PATH 127
44 #define DASURL_SZ_QUERY 511
45 #define DASURL_SZ_DATASET 63
46 
47 /* Called from das_init(), no need to call directly */
48 bool das_http_init(const char* sProgName);
49 
55 char* das_ssl_getErr(const void* vpSsl, int nRet);
56 
57 
58 /* Recommended time out values for HTTP Connections, these settings result
59  * in an initial expectation of 2 second response, 2 retries and a max
60  * connection timeout of 18.0 seconds. Probably too generous */
61 #define DASHTTP_TO_MIN 2.0
62 #define DASHTTP_TO_MULTI 3.0
63 #define DASHTTP_TO_MAX 18.0
64 
65 
67 struct das_url {
69  char sScheme[DASURL_SZ_SCHEME+1];
71  char sHost[DASURL_SZ_HOST+1];
73  char sPath[DASURL_SZ_PATH+1];
75  char sQuery[DASURL_SZ_QUERY+1];
77  char sDataset[DASURL_SZ_DATASET+1];
78 
80  char sPort[8];
81 };
82 
84 typedef struct das_http_response_t{
85 
89  int nSockFd;
90 
93  void* pSsl;
94 
96  int nCode;
97 
99  char* sError;
100 
102  char* sHeaders;
103 
105  char* pMime;
106 
108  char* sFilename;
109 
111  struct das_url url;
112 
113 } DasHttpResp;
114 
120 bool das_url_toStr(const struct das_url* pUrl, char* sBuf, size_t uLen);
121 
122 
133 void DasHttpResp_clear(DasHttpResp* pRes);
134 
141 
151 bool DasHttpResp_init(DasHttpResp* pRes, const char* sUrl);
152 
153 
157 bool DasHttpResp_useSsl(DasHttpResp* pRes);
158 
216 bool das_http_getBody(
217  const char* sUrl, const char* sAgent, DasCredMngr* pMgr, DasHttpResp* pRes,
218  float rConSec
219 );
220 
263  const char* sUrl, const char* sAgent, DasCredMngr* pMgr, DasHttpResp* pRes,
264  int64_t nLimit, float rConSec
265 );
266 
269 #ifdef __cplusplus
270 }
271 #endif
272 
273 #endif /* _das_http_h_ */
274 
void DasHttpResp_clear(DasHttpResp *pRes)
Initialize all fields in an http response to default values.
char * pMime
The parsed out mime-type string from the headers.
Definition: http.h:105
char sScheme[DASURL_SZ_SCHEME+1]
The scheme string.
Definition: http.h:69
char sDataset[DASURL_SZ_DATASET+1]
The dataset identified in the query string (if any)
Definition: http.h:77
char sPath[DASURL_SZ_PATH+1]
The path on the host.
Definition: http.h:73
Credentials manager Handles a list of login credentials and supplies these as needed for network oper...
Definition: credentials.h:94
Encapsulates the status of a HTTP resource request.
Definition: http.h:84
char sPort[8]
The port number used to make the request, saved as a string.
Definition: http.h:80
A dynamic buffer with multi-dimensional array style access.
char sHost[DASURL_SZ_HOST+1]
The host string.
Definition: http.h:71
bool DasHttpResp_useSsl(DasHttpResp *pRes)
Returns true if the response is an SSL (Secure Socket Layer) connection.
char * sError
An error message created by the library if a problem occurred.
Definition: http.h:99
char * sHeaders
The full HTTP header set from the final response.
Definition: http.h:102
int nSockFd
The socket file descriptor that can be used to read the message body.
Definition: http.h:89
Handle storing credentials during a Das2 session and optionally save them to a file.
bool DasHttpResp_init(DasHttpResp *pRes, const char *sUrl)
Initialize the das_url component of an HTTP response.
void * pSsl
The SSL Connection if using HTTPS.
Definition: http.h:93
DasAry * das_http_readUrl(const char *sUrl, const char *sAgent, DasCredMngr *pMgr, DasHttpResp *pRes, int64_t nLimit, float rConSec)
Read all the bytes for a URL into a byte array.
void DasHttpResp_freeFields(DasHttpResp *pRes)
Free any fields that contain allocated memory This will not free the pRes structure itself...
char sQuery[DASURL_SZ_QUERY+1]
The query string.
Definition: http.h:75
char * sFilename
The filename (if any) provided for the message body.
Definition: http.h:108
char * das_ssl_getErr(const void *vpSsl, int nRet)
Get a new string allocated on the heap explaining an SSL error or NULL in nRet == 0...
bool das_url_toStr(const struct das_url *pUrl, char *sBuf, size_t uLen)
Convert a URL structure into a string.
A parsed URL structure.
Definition: http.h:67
bool das_http_getBody(const char *sUrl, const char *sAgent, DasCredMngr *pMgr, DasHttpResp *pRes, float rConSec)
Get a socket positioned at the start of a remote resource.
int nCode
The HTTP status code returned by the server (if any)
Definition: http.h:96
Dynamic recursive ragged arrays.
Definition: array.h:193