3
** Contact: xsb-contact@cs.sunysb.edu
5
** Copyright (C) The Research Foundation of SUNY, 2000
7
** XSB is free software; you can redistribute it and/or modify it under the
8
** terms of the GNU Library General Public License as published by the Free
9
** Software Foundation; either version 2 of the License, or (at your option)
12
** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
13
** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
** FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for
17
** You should have received a copy of the GNU Library General Public License
18
** along with XSB; if not, write to the Free Software Foundation,
19
** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
** $Id: libwww_util.h,v 1.12 2005/02/22 06:22:02 kifer Exp $
38
#include "basictypes.h"
39
#include "basicdefs.h"
41
#include "xsb_config.h"
42
#include "wind2unix.h"
44
#include "error_xsb.h"
46
#include "varstring_xsb.h"
48
/* XSB_LIBWWW_PACKAGE is used in http_errors.h */
49
#define XSB_LIBWWW_PACKAGE
50
#include "../prolog_includes/http_errors.h"
53
/* definitions and macros included in all files */
55
extern int total_number_of_requests;
56
extern int event_loop_runnung;
57
HTList *XML_converter=NULL, *RDF_converter=NULL, *HTML_converter=NULL;
60
#define LIBWWW_DEBUG_VERBOSE
62
#define LIBWWW_DEBUG_TERSE
63
#include "debug_xsb.h"
65
#ifdef LIBWWW_DEBUG_VERBOSE
69
#define LIBWWW_DEBUG_TERSE
72
/* special tag type that we use to wrap around text */
73
#define PCDATA_SPECIAL -77
77
#define FREE_TARGET(t) (*(t->target->isa->_free))(t->target)
79
/* Must define this, since HTStream is just a name aliased to _HTStream */
81
const HTStreamClass * isa;
84
enum request_type {FETCH, HTMLPARSE, XMLPARSE, RDFPARSE, HEADER};
85
typedef enum request_type REQUEST_TYPE;
91
typedef union hkey HKEY;
97
typedef struct hash_table HASH_TABLE;
99
typedef struct auth AUTHENTICATION;
102
char *uid; /* username */
103
char *pw; /* password */
104
AUTHENTICATION *next; /* next authorization record (used for subrequests) */
107
/* used to pass the input info to request and get output info from request back
109
struct request_context {
112
int suppress_is_default;
113
int convert2list; /* if convert pcdata to Prolog lists on exit */
114
int is_subrequest; /* In XML parsing, we might need to go to a different
115
URI to fetch an external reference. This spawns a new
116
blocking subrequest with the same context. */
117
int statusOverride; /* If set, this status code should replace the one
118
returned by libwww */
119
time_t last_modtime; /* page modtime */
120
/* data structure where we build parsed terms, etc. */
123
REQUEST_TYPE type; /* request type: html/xml parsing, fetching page */
125
time_t user_modtime; /* oldest modtime the user can tolerate */
126
prolog_term formdata;
127
AUTHENTICATION auth_info; /* list of name/pw pairs */
128
int retry; /* whether to retry authentication */
130
HASH_TABLE selected_tags_tbl;
131
HASH_TABLE suppressed_tags_tbl;
132
HASH_TABLE stripped_tags_tbl;
134
prolog_term status_term;
135
prolog_term result_params; /* additional params returned in the result */
136
prolog_term request_result; /* either the parse tree of a string containing
138
HTChunk *result_chunk; /* used only by the FETCH method. Here we get the
139
resulting page before converting it to
142
typedef struct request_context REQUEST_CONTEXT;
144
typedef void DELETE_USERDATA(void *userdata);
146
/* like strcpy, but also converts to lowercase */
147
void strcpy_lower(char *to, const char *from);
150
int add_to_htable(HKEY item, HASH_TABLE *htable);
151
int is_in_htable(const HKEY item, HASH_TABLE *htable);
154
void print_prolog_term(prolog_term term, char *message);
156
void html_register_callbacks();
157
void HTXML_newInstance (HTStream * me,
159
HTFormat target_format,
160
HTStream * target_stream,
161
XML_Parser xmlparser,
163
void libwww_newRDF_parserHandler (HTStream * me,
165
HTFormat target_format,
166
HTStream * target_stream,
169
void add_result_param(prolog_term *result_param,
170
char *functor, int cnt, ...);
171
void report_asynch_subrequest_status(HTRequest *request, int status);
172
void report_synch_subrequest_status(HTRequest *request, int status);
173
int verifyMIMEformat(HTRequest *request, REQUEST_TYPE type);
174
char *RequestID(HTRequest *request);
176
int xml_entity_termination_handler(HTRequest *request,
177
HTResponse *response,
180
REQUEST_CONTEXT *set_subrequest_context(HTRequest *request,
181
HTRequest *subrequest,
182
prolog_term result_term);
183
void setup_termination_filter(HTRequest *request, HTNetAfter *filter);
184
void set_xml_conversions(void);
185
void set_rdf_conversions(void);
186
void set_html_conversions(void);
188
#define AUTH_OR_REDIRECTION(status) \
189
((status == HT_NO_ACCESS) || (status == HT_NO_PROXY_ACCESS) \
190
|| (status == HT_REAUTH) || (status == HT_PROXY_REAUTH) \
191
|| (status == HT_SEE_OTHER) || (status == HT_PERM_REDIRECT) \
192
|| (status == HT_FOUND) || (status == HT_TEMP_REDIRECT))