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 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
/*
* $Id$
*
* This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
* project.
*
* Copyright (C) 1998-2012 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __HTTP_CLIENT_H__
#define __HTTP_CLIENT_H__
#ifdef _SSL
#include <openssl/rsa.h>
#include <openssl/crypto.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/pkcs12.h>
#include <openssl/safestack.h>
#include <openssl/bio.h>
#include <openssl/asn1.h>
#include <openssl/md5.h>
#define MD5Init MD5_Init
#define MD5Update MD5_Update
#define MD5Final MD5_Final
#else
#include "util/md5.h"
#endif /* _SSL */
#ifndef _WI_STRLIKE_H
#include "strlike.h"
#endif
#define HC_AUTH_DIGEST 1 /* Digest */
#define HC_AUTH_BASIC 2 /* Basic */
/* Hook dispatch queues */
/*
* TODO:
* Add separate hooks for transfer encoding/decoding
*
*
*/
#define HTTP_CLI_NO_HOOKS 11
#define HC_HTTP_TO 0
#define HC_HTTP_ERROR 1
#define HC_HTTP_CONN_PRE 2
#define HC_HTTP_CONN_ERR 3
#define HC_HTTP_CONN_POST 4
#define HC_HTTP_REQ_PRE 5
#define HC_HTTP_REQ_POST 6
#define HC_HTTP_RESP_MALF 7
#define HC_HTTP_READ_ERR 8
#define HC_HTTP_WRITE_ERR 9
#define HC_CTX_DESTRUCTOR 10 /* context destructor hook */
/* Hook/event handler return values */
#define HC_RET_RETRY 1 /* Retry connection */
#define HC_RET_OK 0
#define HC_RET_ERR_CONT -1 /* Continue hook function dispatch */
#define HC_RET_ERR_ABORT -2 /* Abort hook function dispatch */
/* Flags */
#define HC_F_ABORT (uint32)0x0001
#define HC_F_RETRY (uint32)0x0002
#define HC_F_CONNECTED (uint32)0x0010
#define HC_F_REQ_SENT (uint32)0x0020
#define HC_F_REPLY_READ (uint32)0x0040
#define HC_F_HDRS_READ (uint32)0x0080
#define HC_F_BODY_READ (uint32)0x0100
/* States */
#define HC_STATE_INIT 1
#define HC_STATE_REQ_SENT 2
#define HC_STATE_READ_RESP 3
#define HC_STATE_READ_RESP_HDRS 5
#define HC_STATE_READ_RESP_BODY 6
#define HC_STATE_ERR_CLEANUP 666
/* event handler queue for HTTP replies */
typedef struct http_resp_evt_q_s
{
int hreq_http_resp;
dk_set_t hreq_evt_q;
} http_resp_evt_q_t;
/* offsets from http_methods described in http.c */
#define HC_METHOD_NONE 0
#define HC_METHOD_GET 1
#define HC_METHOD_HEAD 2
#define HC_METHOD_POST 3
#define HC_METHOD_PUT 4
#define HC_METHOD_DELETE 5
#define HC_METHOD_OPTIONS 6
/* WebDAV methods */
#define HC_METHOD_PROPFIND 7
#define HC_METHOD_PROPPATCH 8
#define HC_METHOD_COPY 9
#define HC_METHOD_MOVE 10
#define HC_METHOD_LOCK 11
#define HC_METHOD_UNLOCK 12
#define HC_METHOD_MKCOL 13
#define HA_ALGORITHM_MD5 1
#define HA_ALGORITHM_MD5_SESS 2
#define HA_QOP_NONE 0
#define HA_QOP_AUTH 1
#define HA_QOP_AUTH_INT 2
typedef struct http_cli_proxy_s
{
caddr_t hcp_proxy;
int hcp_socks_ver;
int hcp_resolve;
caddr_t hcp_user;
caddr_t hcp_pass;
} http_cli_proxy_t;
/* HTTP Client context */
typedef struct http_cli_ctx_s
{
int hcctx_state;
uint32 hcctx_flags;
int hcctx_auth_type; /* 1 - DIGEST, 2 - BASIC */
int hcctx_nc;
int hcctx_http_maj;
int hcctx_http_min;
int hcctx_respcode;
int hcctx_is_chunked;
int hcctx_is_gzip;
int hcctx_keep_alive;
int hcctx_close;
int hcctx_retry_count;
int hcctx_retry_max;
int hcctx_method;
int hcctx_algorithm;
long hcctx_req_start_time;
long hcctx_req_time_msec;
long hcctx_peer_max_timeout;
int hcctx_no_cached;
uint32 hcctx_timeout;
caddr_t hcctx_digest_uri;
caddr_t hcctx_qop;
caddr_t hcctx_ua_id;
caddr_t hcctx_host;
caddr_t hcctx_domain;
caddr_t hcctx_realm;
caddr_t hcctx_nonce;
caddr_t hcctx_cnonce;
caddr_t hcctx_opaque;
caddr_t hcctx_stale;
caddr_t hcctx_user;
caddr_t hcctx_pass;
caddr_t hcctx_url;
caddr_t hcctx_uri;
caddr_t hcctx_err;
http_cli_proxy_t hcctx_proxy;
caddr_t hcctx_req_ctype;
int hcctx_http_out_cached;
dk_session_t * hcctx_http_out;
dk_session_t * hcctx_pub_req_hdrs;
dk_session_t * hcctx_prv_req_hdrs;
dk_session_t * hcctx_req_body;
char hcctx_resp_content_is_strses;
char hcctx_resp_content_len_recd;
long hcctx_resp_content_length;
caddr_t hcctx_response;
dk_set_t hcctx_resp_hdrs;
caddr_t hcctx_resp_body;
#ifdef _SSL
SSL * hcctx_ssl;
SSL_CTX * hcctx_ssl_ctx;
SSL_METHOD * hcctx_ssl_method;
caddr_t hcctx_pkcs12_file;
caddr_t hcctx_cert_pass;
caddr_t hcctx_ca_certs;
char hcctx_ssl_insecure;
#endif
dk_set_t hcctx_resp_evts; /* HTTP Resp evt queues */
int hcctx_resp_evt_ret;
dk_set_t hcctx_hooks [HTTP_CLI_NO_HOOKS]; /* hook dispatch queues */
int hcctx_hook_ret;
caddr_t * hcctx_qst;
int hcctx_redirects;
} http_cli_ctx;
typedef int HC_RET;
typedef HC_RET (*http_cli_handler_fn)(http_cli_ctx *,
caddr_t params,
caddr_t ret_val,
caddr_t err_ret);
/*
* event handler frame
* fn - function pointer
* pm - address of params to the handler
* rt - address of return value
* er - error return
*
*
*/
typedef struct http_cli_handler_frame_s
{
http_cli_handler_fn fn;
caddr_t pm;
caddr_t rt;
caddr_t er;
} http_cli_handler_frame_t;
HC_RET http_cli_hook_dispatch (http_cli_ctx *, int);
HC_RET http_cli_resp_evt_dispatch (http_cli_ctx *, int);
http_cli_ctx * http_cli_ctx_init (void);
HC_RET http_cli_ctx_free (http_cli_ctx *);
void http_cli_inst_hook (http_cli_ctx *, int, http_cli_handler_frame_t *);
void http_cli_push_resp_evt (http_cli_ctx *, int, http_cli_handler_frame_t *);
char* http_cli_get_method_string (http_cli_ctx *);
char* http_cli_get_resp_hdr (http_cli_ctx *, char *);
HC_RET http_cli_connect (http_cli_ctx *);
HC_RET http_cli_send_req (http_cli_ctx *);
HC_RET http_cli_read_resp (http_cli_ctx *);
HC_RET http_cli_parse_resp_hdr (http_cli_ctx *, char*, int);
HC_RET http_cli_read_resp_hdrs (http_cli_ctx *);
HC_RET http_cli_read_resp_body (http_cli_ctx *);
void http_cli_calc_md5 (caddr_t, caddr_t, int);
caddr_t http_cli_auth_new_cnonce (void);
HC_RET http_cli_init_std_auth (http_cli_ctx *, caddr_t, caddr_t);
HC_RET http_cli_calc_auth_digest (http_cli_ctx *, caddr_t, caddr_t, caddr_t);
HC_RET http_cli_calc_auth_basic (http_cli_ctx *, caddr_t, caddr_t, caddr_t);
char* next_delim (char*, char*);
char* skip_attr (char*, char*);
char* skip_lwsp (char*, char*);
char* str_end (char*, char*);
HC_RET http_cli_parse_authorize_headers (http_cli_ctx *);
HC_RET http_cli_std_handle_auth (http_cli_ctx *, caddr_t, caddr_t, caddr_t);
http_cli_ctx *http_cli_std_init (char *, caddr_t *);
HC_RET http_cli_std_hdrs (http_cli_ctx *);
HC_RET http_cli_add_req_hdr (http_cli_ctx *, char *);
HC_RET http_cli_main (http_cli_ctx *);
HC_RET http_cli_send_request (http_cli_ctx *);
HC_RET http_cli_read_response (http_cli_ctx *);
HC_RET http_cli_set_http_10 (http_cli_ctx *);
HC_RET http_cli_set_http_11 (http_cli_ctx *);
HC_RET http_cli_set_auth (http_cli_ctx *, caddr_t, caddr_t);
HC_RET http_cli_set_target_host (http_cli_ctx *, caddr_t);
HC_RET http_cli_set_req_content_type (http_cli_ctx *, caddr_t);
HC_RET http_cli_set_retries (http_cli_ctx *, int);
HC_RET http_cli_set_ua_id (http_cli_ctx *, caddr_t);
HC_RET http_cli_set_authtype (http_cli_ctx *, int);
HC_RET http_cli_set_method (http_cli_ctx *, int);
caddr_t http_cli_get_err (http_cli_ctx *);
HC_RET http_cli_ssl_cert (http_cli_ctx *, caddr_t);
HC_RET http_cli_ssl_cert_pass (http_cli_ctx *, caddr_t);
int http_cli_target_is_proxy_exception (char *);
#endif /* __HTTP_CLIENT_H__ */
|