~burner/xsb/debianized-xsb

« back to all changes in this revision

Viewing changes to packages/libwww/cc/libwww_util.h

  • Committer: Michael R. Head
  • Date: 2006-09-06 22:11:55 UTC
  • Revision ID: burner@n23-20060906221155-7e398d23438a7ee4
Add the files from the 3.0.1 release package

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* File:      libwww_util.h
 
2
** Author(s): kifer
 
3
** Contact:   xsb-contact@cs.sunysb.edu
 
4
** 
 
5
** Copyright (C) The Research Foundation of SUNY, 2000
 
6
** 
 
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)
 
10
** any later version.
 
11
** 
 
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
 
15
** more details.
 
16
** 
 
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.
 
20
**
 
21
** $Id: libwww_util.h,v 1.12 2005/02/22 06:22:02 kifer Exp $
 
22
** 
 
23
*/
 
24
 
 
25
 
 
26
 
 
27
#include "WWWLib.h"
 
28
#include "WWWHTTP.h"
 
29
#include "WWWInit.h"
 
30
#include "HTAABrow.h"
 
31
#include "WWWApp.h"
 
32
#include "WWWXML.h"
 
33
#include "HTUtils.h"
 
34
#include "HTTPReq.h"
 
35
#include <stdio.h>
 
36
#include <string.h>
 
37
#include <time.h>
 
38
#include "basictypes.h"
 
39
#include "basicdefs.h"
 
40
#include "auxlry.h"
 
41
#include "xsb_config.h"
 
42
#include "wind2unix.h"
 
43
#include "cell_xsb.h"
 
44
#include "error_xsb.h"
 
45
#include "cinterf.h"
 
46
#include "varstring_xsb.h"
 
47
 
 
48
/* XSB_LIBWWW_PACKAGE is used in http_errors.h */
 
49
#define XSB_LIBWWW_PACKAGE
 
50
#include "../prolog_includes/http_errors.h"
 
51
 
 
52
 
 
53
/* definitions and macros included in all files */
 
54
 
 
55
extern int total_number_of_requests;
 
56
extern int event_loop_runnung;
 
57
HTList *XML_converter=NULL, *RDF_converter=NULL, *HTML_converter=NULL;
 
58
 
 
59
/*
 
60
#define LIBWWW_DEBUG_VERBOSE
 
61
#define LIBWWW_DEBUG
 
62
#define LIBWWW_DEBUG_TERSE
 
63
#include "debug_xsb.h"
 
64
*/
 
65
#ifdef LIBWWW_DEBUG_VERBOSE
 
66
#define LIBWWW_DEBUG
 
67
#endif
 
68
#ifdef LIBWWW_DEBUG
 
69
#define LIBWWW_DEBUG_TERSE
 
70
#endif
 
71
 
 
72
/* special tag type that we use to wrap around text */
 
73
#define PCDATA_SPECIAL    -77
 
74
 
 
75
 
 
76
/* from HTTP.c */
 
77
#define FREE_TARGET(t)  (*(t->target->isa->_free))(t->target)
 
78
 
 
79
/* Must define this, since HTStream is just a name aliased to _HTStream */
 
80
struct _HTStream {
 
81
    const HTStreamClass *       isa;
 
82
};
 
83
 
 
84
enum request_type {FETCH, HTMLPARSE, XMLPARSE, RDFPARSE, HEADER};
 
85
typedef enum request_type REQUEST_TYPE;
 
86
 
 
87
union hkey {
 
88
  int intkey;
 
89
  char *strkey;
 
90
};
 
91
typedef union hkey HKEY;
 
92
struct hash_table {
 
93
  int          size;
 
94
  REQUEST_TYPE type;
 
95
  HKEY         *table;
 
96
};
 
97
typedef struct hash_table HASH_TABLE;
 
98
 
 
99
typedef struct auth AUTHENTICATION;
 
100
struct auth {
 
101
  char           *realm;
 
102
  char           *uid;   /* username */
 
103
  char           *pw;    /* password */
 
104
  AUTHENTICATION *next;  /* next authorization record (used for subrequests) */
 
105
};
 
106
 
 
107
/* used to pass the input info to request and get output info from request back
 
108
   to the Prolog side*/
 
109
struct request_context {
 
110
  int  request_id;
 
111
  int  subrequest_id;
 
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. */
 
121
  void *userdata;
 
122
  /* input */
 
123
  REQUEST_TYPE type;        /* request type: html/xml parsing, fetching page */
 
124
  int  timeout;
 
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 */
 
129
  HTMethod   method;
 
130
  HASH_TABLE selected_tags_tbl;
 
131
  HASH_TABLE suppressed_tags_tbl;
 
132
  HASH_TABLE stripped_tags_tbl;
 
133
  /* output */
 
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
 
137
                                 the HTML page */
 
138
  HTChunk     *result_chunk;  /* used only by the FETCH method. Here we get the
 
139
                                 resulting page before converting it to
 
140
                                 prolog_term */
 
141
};
 
142
typedef struct request_context REQUEST_CONTEXT;
 
143
 
 
144
typedef void DELETE_USERDATA(void *userdata);
 
145
 
 
146
/* like strcpy, but also converts to lowercase */
 
147
void strcpy_lower(char *to, const char *from);
 
148
 
 
149
 
 
150
int add_to_htable(HKEY item, HASH_TABLE *htable);
 
151
int is_in_htable(const HKEY item, HASH_TABLE *htable);
 
152
 
 
153
 
 
154
void print_prolog_term(prolog_term term, char *message);
 
155
 
 
156
void html_register_callbacks();
 
157
void HTXML_newInstance (HTStream *              me,
 
158
                        HTRequest *             request,
 
159
                        HTFormat                target_format,
 
160
                        HTStream *              target_stream,
 
161
                        XML_Parser              xmlparser,
 
162
                        void *                  context);
 
163
void libwww_newRDF_parserHandler (HTStream *            me,
 
164
                                  HTRequest *           request,
 
165
                                  HTFormat              target_format,
 
166
                                  HTStream *            target_stream,
 
167
                                  HTRDF *               rdfparser,
 
168
                                  void *                context);
 
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);
 
175
 
 
176
int xml_entity_termination_handler(HTRequest   *request,
 
177
                                   HTResponse  *response,
 
178
                                   void      *param,
 
179
                                   int       status);
 
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);
 
187
 
 
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))