das2C
das core C utilities (v3)
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 
36 #define DASURL_SZ_SCHEME 31
37 #define DASURL_SZ_HOST 63
38 #define DASURL_SZ_PATH 127
39 #define DASURL_SZ_QUERY 511
40 #define DASURL_SZ_DATASET 63
41 #define DASURL_SZ_PORT 7
42 
43 /* Called from das_init(), no need to call directly */
44 bool das_http_init(const char* sProgName);
45 void das_http_finish(void);
46 
52 DAS_API char* das_ssl_getErr(const void* vpSsl, int nRet);
53 
54 
55 /* Recommended time out values for HTTP Connections, these settings result
56  * in an initial expectation of 2 second response, 2 retries and a max
57  * connection timeout of 18.0 seconds. Probably too generous */
58 #define DASHTTP_TO_MIN 2.0
59 #define DASHTTP_TO_MULTI 3.0
60 #define DASHTTP_TO_MAX 18.0
61 
62 
64 struct das_url {
66  char sScheme[DASURL_SZ_SCHEME+1];
68  char sHost[DASURL_SZ_HOST+1];
70  char sPath[DASURL_SZ_PATH+1];
72  char sQuery[DASURL_SZ_QUERY+1];
74  char sDataset[DASURL_SZ_DATASET+1];
75 
77  char sPort[DASURL_SZ_PORT+1];
78 };
79 
81 typedef struct das_http_response_t{
82 
86  int nSockFd;
87 
90  void* pSsl;
91 
93  int nCode;
94 
96  char* sError;
97 
99  char* sHeaders;
100 
102  char* pMime;
103 
105  char* sFilename;
106 
108  struct das_url url;
109 
110 } DasHttpResp;
111 
117 DAS_API bool das_url_toStr(const struct das_url* pUrl, char* sBuf, size_t uLen);
118 
119 
130 DAS_API void DasHttpResp_clear(DasHttpResp* pRes);
131 
138 
148 DAS_API bool DasHttpResp_init(DasHttpResp* pRes, const char* sUrl);
149 
150 
154 DAS_API bool DasHttpResp_useSsl(DasHttpResp* pRes);
155 
209 DAS_API bool das_http_getBody(
210  const char* sUrl, const char* sAgent, DasCredMngr* pMgr, DasHttpResp* pRes,
211  float rConSec
212 );
213 
256  const char* sUrl, const char* sAgent, DasCredMngr* pMgr, DasHttpResp* pRes,
257  int64_t nLimit, float rConSec
258 );
259 
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 #endif /* _das_http_h_ */
267 
A dynamic buffer with multi-dimensional array style access.
Handle storing credentials during a Das2 session and optionally save them to a file.
DAS_API 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.
DAS_API 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.
DAS_API 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.
DAS_API void DasHttpResp_freeFields(DasHttpResp *pRes)
Free any fields that contain allocated memory This will not free the pRes structure itself,...
Dynamic recursive ragged arrays.
Definition: array.h:270
Credentials manager Handles a list of login credentials and supplies these as needed for network oper...
Definition: credentials.h:117
Encapsulates the status of a HTTP resource request.
Definition: http.h:81
char * pMime
The parsed out mime-type string from the headers.
Definition: http.h:102
char * sHeaders
The full HTTP header set from the final response.
Definition: http.h:99
DAS_API void DasHttpResp_clear(DasHttpResp *pRes)
Initialize all fields in an http response to default values.
void * pSsl
The SSL Connection if using HTTPS.
Definition: http.h:90
char * sError
An error message created by the library if a problem occurred.
Definition: http.h:96
int nSockFd
The socket file descriptor that can be used to read the message body.
Definition: http.h:86
DAS_API bool DasHttpResp_init(DasHttpResp *pRes, const char *sUrl)
Initialize the das_url component of an HTTP response.
char * sFilename
The filename (if any) provided for the message body.
Definition: http.h:105
DAS_API bool DasHttpResp_useSsl(DasHttpResp *pRes)
Returns true if the response is an SSL (Secure Socket Layer) connection.
int nCode
The HTTP status code returned by the server (if any)
Definition: http.h:93
A parsed URL structure.
Definition: http.h:64
char sHost[DASURL_SZ_HOST+1]
The host string.
Definition: http.h:68
char sDataset[DASURL_SZ_DATASET+1]
The dataset identified in the query string (if any)
Definition: http.h:74
char sPort[DASURL_SZ_PORT+1]
The port number used to make the request, saved as a string.
Definition: http.h:77
char sQuery[DASURL_SZ_QUERY+1]
The query string.
Definition: http.h:72
char sPath[DASURL_SZ_PATH+1]
The path on the host.
Definition: http.h:70
DAS_API bool das_url_toStr(const struct das_url *pUrl, char *sBuf, size_t uLen)
Convert a URL structure into a string.
char sScheme[DASURL_SZ_SCHEME+1]
The scheme string.
Definition: http.h:66