Annotation of libwww/Library/src/HTReqMan.c, revision 2.59
2.1 frystyk 1: /* HTReqMan.c
2: ** REQUEST MANAGER
3: **
4: ** (c) COPYRIGHT MIT 1995.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.59 ! frystyk 6: ** @(#) $Id: HTReqMan.c,v 2.58 1996/09/13 02:05:29 frystyk Exp $
2.1 frystyk 7: **
8: ** Authors
9: ** TBL Tim Berners-Lee timbl@w3.org
10: ** JFG Jean-Francois Groff jfg@dxcern.cern.ch
11: ** DD Denis DeLaRoca (310) 825-4580 <CSP1DWD@mvs.oac.ucla.edu>
12: ** HFN Henrik Frystyk, frystyk@w3.org
13: ** History
14: ** 8 Jun 92 Telnet hopping prohibited as telnet is not secure TBL
15: ** 26 Jun 92 When over DECnet, suppressed FTP, Gopher and News. JFG
16: ** 6 Oct 92 Moved HTClientHost and HTlogfile into here. TBL
17: ** 17 Dec 92 Tn3270 added, bug fix. DD
18: ** 4 Feb 93 Access registration, Search escapes bad chars TBL
19: ** PARAMETERS TO HTSEARCH AND HTLOADRELATIVE CHANGED
20: ** 28 May 93 WAIS gateway explicit if no WAIS library linked in.
21: ** Dec 93 Bug change around, more reentrant, etc
22: ** 09 May 94 logfile renamed to HTlogfile to avoid clash with WAIS
23: ** 8 Jul 94 Insulate free() from _free structure element.
24: ** 02 Sep 95 Rewritten and spawned from HTAccess.c, HFN
25: */
26:
27: #if !defined(HT_DIRECT_WAIS) && !defined(HT_DEFAULT_WAIS_GATEWAY)
28: #define HT_DEFAULT_WAIS_GATEWAY "http://www.w3.org:8001/"
29: #endif
30:
31: /* Library include files */
2.32 frystyk 32: #include "sysdep.h"
2.40 frystyk 33: #include "WWWUtil.h"
2.1 frystyk 34: #include "HTParse.h"
35: #include "HTAlert.h"
36: #include "HTError.h"
2.2 frystyk 37: #include "HTNetMan.h"
2.39 frystyk 38: #include "HTEvent.h"
2.1 frystyk 39: #include "HTProt.h"
2.43 eric 40: #include "HTHeader.h"
2.46 frystyk 41: #include "HTLib.h"
2.1 frystyk 42: #include "HTReqMan.h" /* Implemented here */
43:
44: #ifndef HT_MAX_RELOADS
45: #define HT_MAX_RELOADS 6
46: #endif
2.13 frystyk 47:
2.1 frystyk 48: PRIVATE int HTMaxRetry = HT_MAX_RELOADS;
49:
50: struct _HTStream {
51: HTStreamClass * isa;
52: /* ... */
53: };
54:
55: /* --------------------------------------------------------------------------*/
2.59 ! frystyk 56: /* Create and delete the HTRequest Object */
2.1 frystyk 57: /* --------------------------------------------------------------------------*/
58:
2.3 frystyk 59: PUBLIC HTRequest * HTRequest_new (void)
2.1 frystyk 60: {
2.29 frystyk 61: HTRequest * me;
62: if ((me = (HTRequest *) HT_CALLOC(1, sizeof(HTRequest))) == NULL)
63: HT_OUTOFMEM("HTRequest_new()");
2.1 frystyk 64:
2.7 frystyk 65: /* Force Reload */
2.56 frystyk 66: me->reload = HT_CACHE_OK;
2.1 frystyk 67:
2.40 frystyk 68: /* Set the default user profile */
69: me->userprofile = HTLib_userProfile();
70:
2.1 frystyk 71: /* Format of output */
72: me->output_format = WWW_PRESENT; /* default it to present to user */
2.21 frystyk 73: me->debug_format = WWW_DEBUG; /* default format of error messages */
2.1 frystyk 74:
75: /* HTTP headers */
76: me->GenMask = DEFAULT_GENERAL_HEADERS;
77: me->RequestMask = DEFAULT_REQUEST_HEADERS;
2.22 frystyk 78: me->ResponseMask = DEFAULT_RESPONSE_HEADERS;
2.1 frystyk 79: me->EntityMask = DEFAULT_ENTITY_HEADERS;
80:
81: /* Default retry after value */
2.19 frystyk 82: me->priority = HT_PRIORITY_MAX;
2.1 frystyk 83:
2.54 frystyk 84: /* Default max forward value */
85: me->max_forwards = -1;
86:
2.1 frystyk 87: /* Content negotiation */
2.45 frystyk 88: me->ContentNegotiation = YES; /* Do this by default */
2.1 frystyk 89:
2.47 frystyk 90: if (CORE_TRACE) HTTrace("Request..... Created %p\n", me);
91:
2.1 frystyk 92: return me;
93: }
94:
2.28 frystyk 95: /* HTRequest_clear
96: ** ---------------
97: ** Clears all protocol specific information so that the request object
98: ** can be used for another request.
99: ** Returns YES if OK, else NO
100: */
101: PUBLIC BOOL HTRequest_clear (HTRequest * me)
102: {
103: if (me) {
104: me->error_stack = NULL;
105: me->net = NULL;
2.49 frystyk 106: me->realm = NULL;
2.31 frystyk 107: me->credentials = NULL;
2.47 frystyk 108: me->connected = NO;
2.59 ! frystyk 109: if (me->response) {
! 110: HTResponse_delete(me->response);
! 111: me->response = NULL;
! 112: }
2.28 frystyk 113: return YES;
114: }
115: return NO;
116: }
117:
2.18 frystyk 118: /* HTRequest_dup
119: ** -------------
120: ** Creates a new HTRequest object as a duplicate of the src request.
121: ** Returns YES if OK, else NO
122: */
123: PUBLIC HTRequest * HTRequest_dup (HTRequest * src)
124: {
125: HTRequest * me;
2.47 frystyk 126: if (!src) return NULL;
2.29 frystyk 127: if ((me = (HTRequest *) HT_MALLOC(sizeof(HTRequest))) == NULL)
128: HT_OUTOFMEM("HTRequest_dup");
2.18 frystyk 129: memcpy(me, src, sizeof(HTRequest));
2.47 frystyk 130: if (CORE_TRACE) HTTrace("Request..... Duplicated %p to %p\n", src, me);
2.18 frystyk 131: return me;
132: }
2.1 frystyk 133:
2.23 frystyk 134: /* HTRequest_dupInternal
135: ** ---------------------
136: ** Creates a new HTRequest object as a duplicate of the src request.
137: ** The difference to the HTRequest_dup function is that we don't copy the
138: ** error_stack and other information that the application keeps in its
139: ** copy of the request object. Otherwise it will be freed multiple times
140: ** Returns YES if OK, else NO
141: */
142: PUBLIC HTRequest * HTRequest_dupInternal (HTRequest * src)
143: {
144: HTRequest * me;
2.33 eric 145: if (!src) return 0;
2.29 frystyk 146: if ((me = (HTRequest *) HT_MALLOC(sizeof(HTRequest))) == NULL)
147: HT_OUTOFMEM("HTRequest_dup");
2.23 frystyk 148: memcpy(me, src, sizeof(HTRequest));
2.28 frystyk 149: HTRequest_clear(me);
2.23 frystyk 150: return me;
151: }
152:
2.59 ! frystyk 153: PUBLIC void HTRequest_delete (HTRequest * me)
2.1 frystyk 154: {
2.59 ! frystyk 155: if (me) {
! 156: if (CORE_TRACE) HTTrace("Request..... Delete %p\n", me);
! 157: if (me->net) HTNet_setRequest(me->net, NULL);
2.47 frystyk 158:
159: /* Should we delete the output stream? */
2.59 ! frystyk 160: if (!me->connected && me->output_stream) {
2.47 frystyk 161: if (CORE_TRACE)
162: HTTrace("Request..... Deleting dangling output stream\n");
2.59 ! frystyk 163: (*me->output_stream->isa->_free)(me->output_stream);
! 164: me->output_stream = NULL;
2.47 frystyk 165: }
166:
167: /* Clean up the error stack */
2.59 ! frystyk 168: if (me->error_stack) HTError_deleteAll(me->error_stack);
2.13 frystyk 169:
2.51 frystyk 170: /* Before and After Filters */
2.59 ! frystyk 171: if (me->afters) HTList_delete(me->afters);
! 172: if (me->befores) HTList_delete(me->befores);
2.51 frystyk 173:
2.49 frystyk 174: /* Access Authentication */
2.59 ! frystyk 175: HT_FREE(me->realm);
! 176: if (me->credentials) HTAssocList_delete(me->credentials);
2.49 frystyk 177:
2.56 frystyk 178: /* Cache control headers */
2.59 ! frystyk 179: if (me->cache_control)
! 180: HTAssocList_delete(me->cache_control);
2.57 frystyk 181:
2.59 ! frystyk 182: /* Byte ranges */
! 183: if (me->byte_ranges) HTAssocList_delete(me->byte_ranges);
2.56 frystyk 184:
185: /* Connection headers */
2.59 ! frystyk 186: if (me->connection) HTAssocList_delete(me->connection);
2.56 frystyk 187:
2.53 frystyk 188: /* Proxy information */
2.59 ! frystyk 189: HT_FREE(me->proxy);
2.53 frystyk 190:
2.49 frystyk 191: /* PEP Information */
2.59 ! frystyk 192: if (me->protocol) HTAssocList_delete(me->protocol);
! 193: if (me->protocol_request) HTAssocList_delete(me->protocol_request);
! 194: if (me->protocol_info) HTAssocList_delete(me->protocol_info);
2.49 frystyk 195:
2.59 ! frystyk 196: /* Any response object */
! 197: if (me->response) HTResponse_delete(me->response);
2.55 frystyk 198:
2.59 ! frystyk 199: HT_FREE(me);
2.1 frystyk 200: }
201: }
202:
203: /*
2.59 ! frystyk 204: ** Kill this request
2.1 frystyk 205: */
2.59 ! frystyk 206: PUBLIC BOOL HTRequest_kill(HTRequest * me)
2.1 frystyk 207: {
2.59 ! frystyk 208: return me ? HTNet_kill(me->net) : NO;
2.1 frystyk 209: }
210:
2.59 ! frystyk 211: /* --------------------------------------------------------------------------*/
! 212: /* Methods on the HTRequest Object */
! 213: /* --------------------------------------------------------------------------*/
2.1 frystyk 214:
215: /*
2.59 ! frystyk 216: ** Internal request object
2.1 frystyk 217: */
2.59 ! frystyk 218: PUBLIC BOOL HTRequest_setInternal (HTRequest * me, BOOL mode)
2.1 frystyk 219: {
2.59 ! frystyk 220: if (me) {
! 221: me->internal = mode;
! 222: return YES;
! 223: }
! 224: return NO;
2.1 frystyk 225: }
226:
2.59 ! frystyk 227: PUBLIC BOOL HTRequest_internal (HTRequest * me)
2.1 frystyk 228: {
2.59 ! frystyk 229: return (me ? me->internal : NO);
2.1 frystyk 230: }
231:
232: /*
2.59 ! frystyk 233: ** Date/time stamp when then request was issued
! 234: ** This is normally set when generating the request headers.
2.1 frystyk 235: */
2.59 ! frystyk 236: PUBLIC time_t HTRequest_date (HTRequest * me)
2.1 frystyk 237: {
2.59 ! frystyk 238: return me ? me->date : -1;
2.1 frystyk 239: }
240:
2.59 ! frystyk 241: PUBLIC BOOL HTRequest_setDate (HTRequest * me, time_t date)
2.1 frystyk 242: {
2.59 ! frystyk 243: if (me) {
! 244: me->date = date;
! 245: return YES;
2.1 frystyk 246: }
2.59 ! frystyk 247: return NO;
2.1 frystyk 248: }
249:
2.37 frystyk 250: /*
2.59 ! frystyk 251: ** Method
2.37 frystyk 252: */
2.59 ! frystyk 253: PUBLIC void HTRequest_setMethod (HTRequest * me, HTMethod method)
2.37 frystyk 254: {
2.59 ! frystyk 255: if (me) me->method = method;
2.37 frystyk 256: }
257:
2.59 ! frystyk 258: PUBLIC HTMethod HTRequest_method (HTRequest * me)
2.37 frystyk 259: {
2.59 ! frystyk 260: return me ? me->method : METHOD_INVALID;
2.37 frystyk 261: }
262:
2.1 frystyk 263: /*
2.59 ! frystyk 264: ** Priority to be inherited by all HTNet object hanging off this request
! 265: ** The priority can later be chaned by calling the HTNet object directly
2.1 frystyk 266: */
2.59 ! frystyk 267: PUBLIC BOOL HTRequest_setPriority (HTRequest * me, HTPriority priority)
2.1 frystyk 268: {
2.59 ! frystyk 269: if (me) {
! 270: me->priority = priority;
! 271: return YES;
2.1 frystyk 272: }
2.59 ! frystyk 273: return NO;
2.1 frystyk 274: }
275:
2.59 ! frystyk 276: PUBLIC HTPriority HTRequest_priority (HTRequest * me)
2.1 frystyk 277: {
2.59 ! frystyk 278: return (me ? me->priority : HT_PRIORITY_INV);
2.1 frystyk 279: }
280:
281: /*
2.59 ! frystyk 282: ** User Profile
2.1 frystyk 283: */
2.59 ! frystyk 284: PUBLIC BOOL HTRequest_setUserProfile (HTRequest * me, HTUserProfile * up)
2.1 frystyk 285: {
2.59 ! frystyk 286: if (me) {
! 287: me->userprofile = up;
! 288: return YES;
2.1 frystyk 289: }
2.59 ! frystyk 290: return NO;
2.1 frystyk 291: }
292:
2.59 ! frystyk 293: PUBLIC HTUserProfile * HTRequest_userProfile (HTRequest * me)
2.1 frystyk 294: {
2.59 ! frystyk 295: return me ? me->userprofile : NULL;
2.1 frystyk 296: }
297:
298: /*
2.59 ! frystyk 299: ** Net Object
2.9 frystyk 300: */
2.59 ! frystyk 301: PUBLIC BOOL HTRequest_setNet (HTRequest * me, HTNet * net)
2.9 frystyk 302: {
2.59 ! frystyk 303: if (me) {
! 304: me->net = net;
! 305: return YES;
2.9 frystyk 306: }
2.59 ! frystyk 307: return NO;
2.9 frystyk 308: }
309:
2.59 ! frystyk 310: PUBLIC HTNet * HTRequest_net (HTRequest * me)
2.9 frystyk 311: {
2.59 ! frystyk 312: return me ? me->net : NULL;
2.9 frystyk 313: }
314:
315: /*
2.59 ! frystyk 316: ** Response Object. If the object does not exist then create it at the
! 317: ** same time it is asked for.
2.9 frystyk 318: */
2.59 ! frystyk 319: PUBLIC HTResponse * HTRequest_response (HTRequest * me)
2.9 frystyk 320: {
2.43 eric 321: if (me) {
2.59 ! frystyk 322: if (!me->response)
! 323: me->response = HTResponse_new();
! 324: return me->response;
2.9 frystyk 325: }
2.59 ! frystyk 326: return NULL;
2.9 frystyk 327: }
328:
2.59 ! frystyk 329: PUBLIC BOOL HTRequest_setResponse (HTRequest * me, HTResponse * response)
2.9 frystyk 330: {
2.43 eric 331: if (me) {
2.59 ! frystyk 332: me->response = response;
! 333: return YES;
2.9 frystyk 334: }
2.59 ! frystyk 335: return NO;
2.43 eric 336: }
337:
2.59 ! frystyk 338: /* Error Management
! 339: ** ----------------
! 340: ** Returns the error stack if a stream is
2.1 frystyk 341: */
2.59 ! frystyk 342: PUBLIC HTList * HTRequest_error (HTRequest * me)
2.1 frystyk 343: {
2.59 ! frystyk 344: return me ? me->error_stack : NULL;
2.1 frystyk 345: }
346:
2.59 ! frystyk 347: PUBLIC void HTRequest_setError (HTRequest * me, HTList * list)
2.1 frystyk 348: {
2.59 ! frystyk 349: if (me) me->error_stack = list;
2.1 frystyk 350: }
351:
2.59 ! frystyk 352: PUBLIC BOOL HTRequest_addError (HTRequest * me,
! 353: HTSeverity severity,
! 354: BOOL ignore,
! 355: int element,
! 356: void * par,
! 357: unsigned int length,
! 358: char * where)
2.1 frystyk 359: {
2.59 ! frystyk 360: if (me) {
! 361: if (!me->error_stack) me->error_stack = HTList_new();
! 362: return HTError_add(me->error_stack, severity, ignore, element,
! 363: par, length, where);
! 364: }
! 365: return NO;
2.1 frystyk 366: }
367:
2.59 ! frystyk 368: PUBLIC BOOL HTRequest_addSystemError (HTRequest * me,
! 369: HTSeverity severity,
! 370: int errornumber,
! 371: BOOL ignore,
! 372: char * syscall)
2.1 frystyk 373: {
2.59 ! frystyk 374: if (me) {
! 375: if (!me->error_stack) me->error_stack = HTList_new();
! 376: return HTError_addSystem(me->error_stack, severity, errornumber,
! 377: ignore, syscall);
! 378: }
! 379: return NO;
2.22 frystyk 380: }
381:
382: /*
2.59 ! frystyk 383: ** Set max number of automatic reload. Default is HT_MAX_RELOADS
2.22 frystyk 384: */
2.59 ! frystyk 385: PUBLIC BOOL HTRequest_setMaxRetry (int newmax)
2.22 frystyk 386: {
2.59 ! frystyk 387: if (newmax > 0) {
! 388: HTMaxRetry = newmax;
! 389: return YES;
! 390: }
! 391: return NO;
2.22 frystyk 392: }
393:
2.59 ! frystyk 394: PUBLIC int HTRequest_maxRetry (void)
2.22 frystyk 395: {
2.59 ! frystyk 396: return HTMaxRetry;
2.22 frystyk 397: }
398:
2.59 ! frystyk 399: PUBLIC int HTRequest_retrys (HTRequest * me)
2.22 frystyk 400: {
2.59 ! frystyk 401: return me ? me->retrys : 0;
2.1 frystyk 402: }
403:
2.59 ! frystyk 404: PUBLIC BOOL HTRequest_addRetry (HTRequest * me)
2.1 frystyk 405: {
2.59 ! frystyk 406: return (me && me->retrys++);
2.1 frystyk 407: }
408:
2.18 frystyk 409: /*
2.59 ! frystyk 410: ** Should we try again?
! 411: ** --------------------
! 412: ** Returns YES if we are to retry the load, NO otherwise. We check
! 413: ** this so that we don't go into an infinte loop
2.1 frystyk 414: */
2.59 ! frystyk 415: PUBLIC BOOL HTRequest_doRetry (HTRequest * me)
2.1 frystyk 416: {
2.59 ! frystyk 417: return (me && me->retrys < HTMaxRetry-1);
2.56 frystyk 418: }
419:
2.1 frystyk 420: /*
2.59 ! frystyk 421: ** Socket mode: preemptive or non-preemptive (blocking or non-blocking)
2.40 frystyk 422: */
2.59 ! frystyk 423: PUBLIC void HTRequest_setPreemptive (HTRequest * me, BOOL mode)
2.40 frystyk 424: {
2.59 ! frystyk 425: if (me) me->preemptive = mode;
2.40 frystyk 426: }
427:
2.59 ! frystyk 428: PUBLIC BOOL HTRequest_preemptive (HTRequest * me)
2.40 frystyk 429: {
2.59 ! frystyk 430: return me ? me->preemptive : NO;
2.40 frystyk 431: }
432:
433: /*
2.59 ! frystyk 434: ** Should we use content negotiation?
2.40 frystyk 435: */
2.59 ! frystyk 436: PUBLIC void HTRequest_setNegotiation (HTRequest * me, BOOL mode)
2.40 frystyk 437: {
2.59 ! frystyk 438: if (me) me->ContentNegotiation = mode;
2.40 frystyk 439: }
440:
2.59 ! frystyk 441: PUBLIC BOOL HTRequest_negotiation (HTRequest * me)
2.40 frystyk 442: {
2.59 ! frystyk 443: return me ? me->ContentNegotiation : NO;
2.40 frystyk 444: }
445:
446: /*
2.59 ! frystyk 447: ** Set General Headers
2.1 frystyk 448: */
2.59 ! frystyk 449: PUBLIC void HTRequest_setGnHd (HTRequest * me, HTGnHd gnhd)
2.1 frystyk 450: {
2.59 ! frystyk 451: if (me) me->GenMask = gnhd;
2.1 frystyk 452: }
453:
2.59 ! frystyk 454: PUBLIC void HTRequest_addGnHd (HTRequest * me, HTGnHd gnhd)
2.1 frystyk 455: {
2.59 ! frystyk 456: if (me) me->GenMask |= gnhd;
2.1 frystyk 457: }
458:
2.59 ! frystyk 459: PUBLIC HTGnHd HTRequest_gnHd (HTRequest * me)
2.1 frystyk 460: {
2.59 ! frystyk 461: return me ? me->GenMask : 0;
2.1 frystyk 462: }
463:
464: /*
2.59 ! frystyk 465: ** Set Request Headers
2.1 frystyk 466: */
2.59 ! frystyk 467: PUBLIC void HTRequest_setRqHd (HTRequest * me, HTRqHd rqhd)
2.1 frystyk 468: {
2.59 ! frystyk 469: if (me) me->RequestMask = rqhd;
2.1 frystyk 470: }
471:
2.59 ! frystyk 472: PUBLIC void HTRequest_addRqHd (HTRequest * me, HTRqHd rqhd)
2.1 frystyk 473: {
2.59 ! frystyk 474: if (me) me->RequestMask |= rqhd;
2.1 frystyk 475: }
476:
2.59 ! frystyk 477: PUBLIC HTRqHd HTRequest_rqHd (HTRequest * me)
2.1 frystyk 478: {
2.59 ! frystyk 479: return me ? me->RequestMask : 0;
2.1 frystyk 480: }
481:
482: /*
2.59 ! frystyk 483: ** Set Response Headers
2.1 frystyk 484: */
2.59 ! frystyk 485: PUBLIC void HTRequest_setRsHd (HTRequest * me, HTRsHd rshd)
2.1 frystyk 486: {
2.59 ! frystyk 487: if (me) me->ResponseMask = rshd;
2.1 frystyk 488: }
489:
2.59 ! frystyk 490: PUBLIC void HTRequest_addRsHd (HTRequest * me, HTRsHd rshd)
2.35 frystyk 491: {
2.59 ! frystyk 492: if (me) me->ResponseMask |= rshd;
2.35 frystyk 493: }
494:
2.59 ! frystyk 495: PUBLIC HTRsHd HTRequest_rsHd (HTRequest * me)
2.35 frystyk 496: {
2.59 ! frystyk 497: return me ? me->ResponseMask : 0;
2.35 frystyk 498: }
499:
2.1 frystyk 500: /*
2.59 ! frystyk 501: ** Set Entity Headers (for the object)
2.34 hallam 502: */
2.59 ! frystyk 503: PUBLIC void HTRequest_setEnHd (HTRequest * me, HTEnHd enhd)
2.34 hallam 504: {
2.59 ! frystyk 505: if (me) me->EntityMask = enhd;
2.51 frystyk 506: }
507:
2.59 ! frystyk 508: PUBLIC void HTRequest_addEnHd (HTRequest * me, HTEnHd enhd)
2.51 frystyk 509: {
2.59 ! frystyk 510: if (me) me->EntityMask |= enhd;
2.51 frystyk 511: }
512:
2.59 ! frystyk 513: PUBLIC HTEnHd HTRequest_enHd (HTRequest * me)
2.51 frystyk 514: {
2.59 ! frystyk 515: return me ? me->EntityMask : 0;
2.34 hallam 516: }
517:
2.59 ! frystyk 518: /*
! 519: ** Extra Header Generators. list can be NULL
! 520: */
! 521: PUBLIC void HTRequest_setGenerator (HTRequest * me, HTList *generator,
! 522: BOOL override)
2.34 hallam 523: {
2.59 ! frystyk 524: if (me) {
! 525: me->generators = generator;
! 526: me->gens_local = override;
2.34 hallam 527: }
528: }
529:
2.59 ! frystyk 530: PUBLIC HTList * HTRequest_generator (HTRequest * me, BOOL *override)
2.34 hallam 531: {
2.59 ! frystyk 532: if (me) {
! 533: *override = me->gens_local;
! 534: return me->generators;
2.34 hallam 535: }
2.59 ! frystyk 536: return NULL;
2.51 frystyk 537: }
538:
2.59 ! frystyk 539: /*
! 540: ** Extra Header Parsers. list can be NULL
! 541: */
! 542: PUBLIC void HTRequest_setMIMEParseSet (HTRequest * me,
! 543: HTMIMEParseSet * parseSet, BOOL local)
2.51 frystyk 544: {
2.59 ! frystyk 545: if (me) {
! 546: me->parseSet = parseSet;
! 547: me->pars_local = local;
2.51 frystyk 548: }
2.34 hallam 549: }
550:
2.59 ! frystyk 551: PUBLIC HTMIMEParseSet * HTRequest_MIMEParseSet (HTRequest * me, BOOL * pLocal)
2.34 hallam 552: {
2.59 ! frystyk 553: if (me) {
! 554: if (pLocal) *pLocal = me->pars_local;
! 555: return me->parseSet;
2.34 hallam 556: }
557: return NULL;
558: }
559:
560: /*
2.59 ! frystyk 561: ** Accept Format Types
! 562: ** list can be NULL
2.1 frystyk 563: */
2.59 ! frystyk 564: PUBLIC void HTRequest_setConversion (HTRequest * me, HTList *type,
! 565: BOOL override)
2.1 frystyk 566: {
2.59 ! frystyk 567: if (me) {
! 568: me->conversions = type;
! 569: me->conv_local = override;
! 570: }
2.1 frystyk 571: }
572:
2.59 ! frystyk 573: PUBLIC HTList * HTRequest_conversion (HTRequest * me)
2.1 frystyk 574: {
2.59 ! frystyk 575: return me ? me->conversions : NULL;
2.1 frystyk 576: }
577:
578: /*
2.59 ! frystyk 579: ** Accept Encoding
! 580: ** list can be NULL
2.1 frystyk 581: */
2.59 ! frystyk 582: PUBLIC void HTRequest_setEncoding (HTRequest * me, HTList *enc,
! 583: BOOL override)
2.1 frystyk 584: {
2.59 ! frystyk 585: if (me) {
! 586: me->encodings = enc;
! 587: me->enc_local = override;
! 588: }
2.1 frystyk 589: }
590:
2.59 ! frystyk 591: PUBLIC HTList * HTRequest_encoding (HTRequest * me)
2.1 frystyk 592: {
2.59 ! frystyk 593: return me ? me->encodings : NULL;
2.1 frystyk 594: }
595:
596: /*
2.59 ! frystyk 597: ** Accept Transfer Encoding
! 598: ** list can be NULL
2.1 frystyk 599: */
2.59 ! frystyk 600: PUBLIC void HTRequest_setTransfer (HTRequest * me,
! 601: HTList * cte, BOOL override)
2.1 frystyk 602: {
2.59 ! frystyk 603: if (me) {
! 604: me->ctes = cte;
! 605: me->cte_local = override;
! 606: }
2.1 frystyk 607: }
608:
2.59 ! frystyk 609: PUBLIC HTList * HTRequest_transfer (HTRequest * me)
2.1 frystyk 610: {
2.59 ! frystyk 611: return me ? me->ctes : NULL;
2.47 frystyk 612: }
613:
614: /*
2.59 ! frystyk 615: ** Accept Language
! 616: ** list can be NULL
2.47 frystyk 617: */
2.59 ! frystyk 618: PUBLIC void HTRequest_setLanguage (HTRequest * me, HTList *lang,
! 619: BOOL override)
2.47 frystyk 620: {
2.59 ! frystyk 621: if (me) {
! 622: me->languages = lang;
! 623: me->lang_local = override;
! 624: }
2.47 frystyk 625: }
626:
2.59 ! frystyk 627: PUBLIC HTList * HTRequest_language (HTRequest * me)
2.47 frystyk 628: {
2.59 ! frystyk 629: return me ? me->languages : NULL;
2.1 frystyk 630: }
631:
632: /*
2.59 ! frystyk 633: ** Accept Charset
! 634: ** list can be NULL
2.1 frystyk 635: */
2.59 ! frystyk 636: PUBLIC void HTRequest_setCharset (HTRequest * me, HTList *charset,
! 637: BOOL override)
2.1 frystyk 638: {
2.59 ! frystyk 639: if (me) {
! 640: me->charsets = charset;
! 641: me->char_local = override;
! 642: }
2.1 frystyk 643: }
644:
2.59 ! frystyk 645: PUBLIC HTList * HTRequest_charset (HTRequest * me)
2.1 frystyk 646: {
2.59 ! frystyk 647: return me ? me->charsets : NULL;
2.40 frystyk 648: }
649:
650: /*
2.53 frystyk 651: ** Are we using the full URL in the request or not?
2.40 frystyk 652: */
2.59 ! frystyk 653: PUBLIC void HTRequest_setFullURI (HTRequest * me, BOOL mode)
2.40 frystyk 654: {
2.59 ! frystyk 655: if (me) me->full_uri = mode;
2.40 frystyk 656: }
657:
2.59 ! frystyk 658: PUBLIC BOOL HTRequest_fullURI (HTRequest * me)
2.40 frystyk 659: {
2.59 ! frystyk 660: return me ? me->full_uri : NO;
2.53 frystyk 661: }
662:
663: /*
664: ** Are we using a proxy or not and in that case, which one?
665: */
2.59 ! frystyk 666: PUBLIC BOOL HTRequest_setProxy (HTRequest * me, const char * proxy)
2.53 frystyk 667: {
2.59 ! frystyk 668: if (me && proxy) {
! 669: StrAllocCopy(me->proxy, proxy);
2.53 frystyk 670: return YES;
671: }
672: return NO;
673: }
674:
2.59 ! frystyk 675: PUBLIC char * HTRequest_proxy (HTRequest * me)
2.53 frystyk 676: {
2.59 ! frystyk 677: return me ? me->proxy : NULL;
2.1 frystyk 678: }
679:
2.59 ! frystyk 680: PUBLIC BOOL HTRequest_deleteProxy (HTRequest * me)
2.54 frystyk 681: {
2.59 ! frystyk 682: if (me) {
! 683: HT_FREE(me->proxy);
2.54 frystyk 684: return YES;
685: }
686: return NO;
687: }
688:
2.1 frystyk 689: /*
2.59 ! frystyk 690: ** Reload Mode
2.1 frystyk 691: */
2.59 ! frystyk 692: PUBLIC void HTRequest_setReloadMode (HTRequest * me, HTReload mode)
2.1 frystyk 693: {
2.59 ! frystyk 694: if (me) me->reload = mode;
2.1 frystyk 695: }
696:
2.59 ! frystyk 697: PUBLIC HTReload HTRequest_reloadMode (HTRequest * me)
2.23 frystyk 698: {
2.59 ! frystyk 699: return me ? me->reload : HT_CACHE_OK;
2.23 frystyk 700: }
701:
702: /*
2.59 ! frystyk 703: ** Cache control directives. The cache control can be initiated by both
! 704: ** the server and the client which is the reason for keeping two lists
2.1 frystyk 705: */
2.59 ! frystyk 706: PUBLIC BOOL HTRequest_addCacheControl (HTRequest * me,
! 707: char * token, char * value)
2.1 frystyk 708: {
2.59 ! frystyk 709: if (me) {
! 710: if (!me->cache_control) me->cache_control = HTAssocList_new();
! 711: return HTAssocList_replaceObject(me->cache_control, token, value);
! 712: }
! 713: return NO;
2.1 frystyk 714: }
715:
2.59 ! frystyk 716: PUBLIC BOOL HTRequest_deleteCacheControl (HTRequest * me)
2.1 frystyk 717: {
2.59 ! frystyk 718: if (me && me->cache_control) {
! 719: HTAssocList_delete(me->cache_control);
! 720: me->cache_control = NULL;
! 721: return YES;
! 722: }
! 723: return NO;
2.1 frystyk 724: }
725:
2.59 ! frystyk 726: PUBLIC HTAssocList * HTRequest_cacheControl (HTRequest * me)
2.11 frystyk 727: {
2.59 ! frystyk 728: return (me ? me->cache_control : NULL);
2.11 frystyk 729: }
730:
2.59 ! frystyk 731: /*
! 732: ** Byte ranges
! 733: */
! 734: PUBLIC BOOL HTRequest_deleteRange (HTRequest * me)
2.11 frystyk 735: {
2.59 ! frystyk 736: if (me && me->byte_ranges) {
! 737: HTAssocList_delete(me->byte_ranges);
! 738: me->byte_ranges = NULL;
! 739: return YES;
2.11 frystyk 740: }
741: return NO;
742: }
743:
2.59 ! frystyk 744: PUBLIC BOOL HTRequest_addRange (HTRequest * me, char * unit, char * range)
2.11 frystyk 745: {
2.59 ! frystyk 746: if (me) {
! 747: if (!me->byte_ranges) me->byte_ranges = HTAssocList_new();
! 748: return HTAssocList_replaceObject(me->byte_ranges, unit, range);
2.11 frystyk 749: }
750: return NO;
751: }
752:
2.59 ! frystyk 753: PUBLIC HTAssocList * HTRequest_range (HTRequest * me)
! 754: {
! 755: return (me ? me->byte_ranges : NULL);
! 756: }
! 757:
2.1 frystyk 758: /*
2.59 ! frystyk 759: ** Connection directives. The connection directies can be initiated by
! 760: ** both the server and the client which is the reason for keeping two
! 761: ** lists
2.1 frystyk 762: */
2.59 ! frystyk 763: PUBLIC BOOL HTRequest_addConnection (HTRequest * me,
! 764: char * token, char * value)
2.1 frystyk 765: {
2.59 ! frystyk 766: if (me) {
! 767: if (!me->connection) me->connection = HTAssocList_new();
! 768: return HTAssocList_replaceObject(me->connection, token, value);
! 769: }
! 770: return NO;
2.1 frystyk 771: }
772:
2.59 ! frystyk 773: PUBLIC BOOL HTRequest_deleteConnection (HTRequest * me)
2.57 frystyk 774: {
2.59 ! frystyk 775: if (me && me->connection) {
! 776: HTAssocList_delete(me->connection);
! 777: me->connection = NULL;
2.57 frystyk 778: return YES;
779: }
780: return NO;
781: }
782:
2.59 ! frystyk 783: PUBLIC HTAssocList * HTRequest_connection (HTRequest * me)
2.57 frystyk 784: {
2.59 ! frystyk 785: return (me ? me->connection : NULL);
2.57 frystyk 786: }
787:
2.59 ! frystyk 788: /*
! 789: ** Access Authentication Credentials
! 790: */
! 791: PUBLIC BOOL HTRequest_deleteCredentialsAll (HTRequest * me)
2.57 frystyk 792: {
2.59 ! frystyk 793: if (me && me->credentials) {
! 794: HTAssocList_delete(me->credentials);
! 795: me->credentials = NULL;
2.57 frystyk 796: return YES;
797: }
798: return NO;
799: }
800:
2.59 ! frystyk 801: PUBLIC BOOL HTRequest_addCredentials (HTRequest * me,
! 802: char * token, char * value)
2.23 frystyk 803: {
2.59 ! frystyk 804: if (me) {
! 805: if (!me->credentials) me->credentials = HTAssocList_new();
! 806: return HTAssocList_addObject(me->credentials, token, value);
! 807: }
! 808: return NO;
2.46 frystyk 809: }
810:
2.59 ! frystyk 811: PUBLIC HTAssocList * HTRequest_credentials (HTRequest * me)
2.46 frystyk 812: {
2.59 ! frystyk 813: return (me ? me->credentials : NULL);
2.23 frystyk 814: }
815:
816: /*
2.59 ! frystyk 817: ** Access Authentication Realms
2.1 frystyk 818: */
2.59 ! frystyk 819: PUBLIC BOOL HTRequest_setRealm (HTRequest * me, char * realm)
2.1 frystyk 820: {
2.59 ! frystyk 821: if (me && realm) {
! 822: StrAllocCopy(me->realm, realm);
2.1 frystyk 823: return YES;
824: }
825: return NO;
826: }
827:
2.59 ! frystyk 828: PUBLIC const char * HTRequest_realm (HTRequest * me)
2.1 frystyk 829: {
2.59 ! frystyk 830: return (me ? me->realm : NULL);
2.1 frystyk 831: }
832:
2.59 ! frystyk 833: /*
! 834: ** PEP Protocol header
! 835: */
! 836: PUBLIC BOOL HTRequest_addProtocol (HTRequest * me,
! 837: char * token, char * value)
2.52 frystyk 838: {
2.59 ! frystyk 839: if (me) {
! 840: if (!me->protocol) me->protocol = HTAssocList_new();
! 841: return HTAssocList_addObject(me->protocol, token,value);
! 842: }
! 843: return NO;
2.52 frystyk 844: }
845:
2.59 ! frystyk 846: PUBLIC BOOL HTRequest_deleteProtocolAll (HTRequest * me)
2.55 frystyk 847: {
2.59 ! frystyk 848: if (me && me->protocol) {
! 849: HTAssocList_delete(me->protocol);
! 850: me->protocol = NULL;
! 851: return YES;
! 852: }
! 853: return NO;
2.55 frystyk 854: }
855:
2.59 ! frystyk 856: PUBLIC HTAssocList * HTRequest_protocol (HTRequest * me)
2.1 frystyk 857: {
2.59 ! frystyk 858: return (me ? me->protocol : NULL);
2.54 frystyk 859: }
860:
861: /*
2.59 ! frystyk 862: ** PEP Protocol Info header
2.54 frystyk 863: */
2.59 ! frystyk 864: PUBLIC BOOL HTRequest_addProtocolInfo (HTRequest * me,
! 865: char * token, char * value)
2.54 frystyk 866: {
2.59 ! frystyk 867: if (me) {
! 868: if (!me->protocol_info) me->protocol_info = HTAssocList_new();
! 869: return HTAssocList_addObject(me->protocol_info, token,value);
2.54 frystyk 870: }
871: return NO;
872: }
873:
2.59 ! frystyk 874: PUBLIC BOOL HTRequest_deleteProtocolInfoAll (HTRequest * me)
2.9 frystyk 875: {
2.59 ! frystyk 876: if (me && me->protocol_info) {
! 877: HTAssocList_delete(me->protocol_info);
! 878: me->protocol_info = NULL;
2.9 frystyk 879: return YES;
880: }
881: return NO;
882: }
883:
2.59 ! frystyk 884: PUBLIC HTAssocList * HTRequest_protocolInfo (HTRequest * me)
2.9 frystyk 885: {
2.59 ! frystyk 886: return (me ? me->protocol_info : NULL);
2.9 frystyk 887: }
888:
2.18 frystyk 889: /*
2.59 ! frystyk 890: ** PEP Protocol request header
2.31 frystyk 891: */
2.59 ! frystyk 892: PUBLIC BOOL HTRequest_addProtocolRequest (HTRequest * me,
! 893: char * token, char * value)
2.49 frystyk 894: {
2.59 ! frystyk 895: if (me) {
! 896: if (!me->protocol_request) me->protocol_request = HTAssocList_new();
! 897: return HTAssocList_addObject(me->protocol_request, token,value);
2.49 frystyk 898: }
899: return NO;
900: }
901:
2.59 ! frystyk 902: PUBLIC BOOL HTRequest_deleteProtocolRequestAll (HTRequest * me)
2.31 frystyk 903: {
2.59 ! frystyk 904: if (me && me->protocol_request) {
! 905: HTAssocList_delete(me->protocol_request);
! 906: me->protocol_request = NULL;
! 907: return YES;
2.31 frystyk 908: }
909: return NO;
910: }
911:
2.59 ! frystyk 912: PUBLIC HTAssocList * HTRequest_protocolRequest (HTRequest * me)
2.31 frystyk 913: {
2.59 ! frystyk 914: return (me ? me->protocol_request : NULL);
2.31 frystyk 915: }
916:
917: /*
2.59 ! frystyk 918: ** Anchor
2.31 frystyk 919: */
2.59 ! frystyk 920: PUBLIC void HTRequest_setAnchor (HTRequest * me, HTAnchor *anchor)
2.31 frystyk 921: {
2.59 ! frystyk 922: if (me) {
! 923: me->anchor = HTAnchor_parent(anchor);
! 924: me->childAnchor = ((HTAnchor *) me->anchor != anchor) ?
! 925: (HTChildAnchor *) anchor : NULL;
2.49 frystyk 926: }
927: }
928:
2.59 ! frystyk 929: PUBLIC HTParentAnchor * HTRequest_anchor (HTRequest * me)
2.49 frystyk 930: {
2.59 ! frystyk 931: return me ? me->anchor : NULL;
2.31 frystyk 932: }
933:
2.59 ! frystyk 934: PUBLIC HTChildAnchor * HTRequest_childAnchor (HTRequest * me)
2.31 frystyk 935: {
2.59 ! frystyk 936: return me ? me->childAnchor : NULL;
2.31 frystyk 937: }
938:
939: /*
2.59 ! frystyk 940: ** Parent anchor for Referer field
2.18 frystyk 941: */
2.59 ! frystyk 942: PUBLIC void HTRequest_setParent (HTRequest * me, HTParentAnchor *parent)
2.18 frystyk 943: {
2.59 ! frystyk 944: if (me) me->parentAnchor = parent;
2.18 frystyk 945: }
946:
2.59 ! frystyk 947: PUBLIC HTParentAnchor * HTRequest_parent (HTRequest * me)
2.18 frystyk 948: {
2.59 ! frystyk 949: return me ? me->parentAnchor : NULL;
2.42 frystyk 950: }
951:
952: /*
2.59 ! frystyk 953: ** Output stream
2.49 frystyk 954: */
2.59 ! frystyk 955: PUBLIC void HTRequest_setOutputStream (HTRequest * me, HTStream *output)
2.49 frystyk 956: {
2.59 ! frystyk 957: if (me) me->output_stream = output;
2.49 frystyk 958: }
959:
2.59 ! frystyk 960: PUBLIC HTStream *HTRequest_outputStream (HTRequest * me)
2.49 frystyk 961: {
2.59 ! frystyk 962: return me ? me->output_stream : NULL;
2.49 frystyk 963: }
964:
965: /*
2.59 ! frystyk 966: ** Output format
2.42 frystyk 967: */
2.59 ! frystyk 968: PUBLIC void HTRequest_setOutputFormat (HTRequest * me, HTFormat format)
2.42 frystyk 969: {
2.59 ! frystyk 970: if (me) me->output_format = format;
! 971: }
! 972:
! 973: PUBLIC HTFormat HTRequest_outputFormat (HTRequest * me)
! 974: {
! 975: return me ? me->output_format : NULL;
2.42 frystyk 976: }
977:
2.59 ! frystyk 978: /*
! 979: ** Debug stream
! 980: */
! 981: PUBLIC void HTRequest_setDebugStream (HTRequest * me, HTStream *debug)
2.42 frystyk 982: {
2.59 ! frystyk 983: if (me) me->debug_stream = debug;
2.42 frystyk 984: }
985:
2.59 ! frystyk 986: PUBLIC HTStream *HTRequest_debugStream (HTRequest * me)
2.42 frystyk 987: {
2.59 ! frystyk 988: return me ? me->debug_stream : NULL;
2.42 frystyk 989: }
990:
991: /*
2.59 ! frystyk 992: ** Debug Format
2.42 frystyk 993: */
2.59 ! frystyk 994: PUBLIC void HTRequest_setDebugFormat (HTRequest * me, HTFormat format)
2.42 frystyk 995: {
2.59 ! frystyk 996: if (me) me->debug_format = format;
2.42 frystyk 997: }
998:
2.59 ! frystyk 999: PUBLIC HTFormat HTRequest_debugFormat (HTRequest * me)
2.42 frystyk 1000: {
2.59 ! frystyk 1001: return me ? me->debug_format : NULL;
2.42 frystyk 1002: }
1003:
1004: /*
2.59 ! frystyk 1005: ** Input stream
2.42 frystyk 1006: */
2.59 ! frystyk 1007: PUBLIC void HTRequest_setInputStream (HTRequest * me, HTStream *input)
2.42 frystyk 1008: {
2.59 ! frystyk 1009: if (me) me->input_stream = input;
2.42 frystyk 1010: }
1011:
2.59 ! frystyk 1012: PUBLIC HTStream *HTRequest_inputStream (HTRequest * me)
2.42 frystyk 1013: {
2.59 ! frystyk 1014: return me ? me->input_stream : NULL;
2.18 frystyk 1015: }
1016:
2.50 frystyk 1017: /*
2.59 ! frystyk 1018: ** Net before and after callbacks
2.50 frystyk 1019: */
2.59 ! frystyk 1020: PUBLIC BOOL HTRequest_addBefore (HTRequest * me, HTNetBefore * filter,
! 1021: const char * tmplate, void * param,
! 1022: int order, BOOL override)
2.50 frystyk 1023: {
2.59 ! frystyk 1024: if (me) {
! 1025: me->befores_local = override;
! 1026: if (filter) {
! 1027: if (!me->befores) me->befores = HTList_new();
! 1028: return HTNetCall_addBefore(me->befores, filter,
! 1029: tmplate, param, order);
! 1030: }
! 1031: return YES; /* It's OK to register a NULL filter */
2.50 frystyk 1032: }
1033: return NO;
1034: }
1035:
2.59 ! frystyk 1036: PUBLIC BOOL HTRequest_deleteBefore (HTRequest * me, HTNetBefore * filter)
2.50 frystyk 1037: {
2.59 ! frystyk 1038: if (me && me->befores)
! 1039: return HTNetCall_deleteBefore(me->befores, filter);
! 1040: return NO;
2.55 frystyk 1041: }
1042:
2.59 ! frystyk 1043: PUBLIC BOOL HTRequest_deleteBeforeAll (HTRequest * me)
2.57 frystyk 1044: {
2.59 ! frystyk 1045: if (me && me->befores) {
! 1046: HTNetCall_deleteBeforeAll(me->befores);
! 1047: me->befores = NULL;
! 1048: me->befores_local = NO;
! 1049: return YES;
2.57 frystyk 1050: }
1051: return NO;
1052: }
1053:
2.59 ! frystyk 1054: PUBLIC HTList * HTRequest_before (HTRequest * me, BOOL *override)
2.57 frystyk 1055: {
2.59 ! frystyk 1056: if (me) {
! 1057: *override = me->befores_local;
! 1058: return me->befores;
! 1059: }
! 1060: return NULL;
! 1061: }
! 1062:
! 1063: PUBLIC BOOL HTRequest_addAfter (HTRequest * me, HTNetAfter * filter,
! 1064: const char * tmplate, void * param,
! 1065: int status, int order, BOOL override)
! 1066: {
! 1067: if (me) {
! 1068: me->afters_local = override;
! 1069: if (filter) {
! 1070: if (!me->afters) me->afters = HTList_new();
! 1071: return HTNetCall_addAfter(me->afters, filter,
! 1072: tmplate, param, status, order);
! 1073: }
! 1074: return YES; /* It's OK to register a NULL filter */
2.57 frystyk 1075: }
1076: return NO;
1077: }
1078:
2.59 ! frystyk 1079: PUBLIC BOOL HTRequest_deleteAfter (HTRequest * me, HTNetAfter * filter)
! 1080: {
! 1081: return (me && me->afters) ?
! 1082: HTNetCall_deleteAfter(me->afters, filter) : NO;
! 1083: }
! 1084:
! 1085: PUBLIC BOOL HTRequest_deleteAfterStatus (HTRequest * me, int status)
2.57 frystyk 1086: {
2.59 ! frystyk 1087: return (me && me->afters) ?
! 1088: HTNetCall_deleteAfterStatus(me->afters, status) : NO;
2.57 frystyk 1089: }
1090:
2.59 ! frystyk 1091: PUBLIC BOOL HTRequest_deleteAfterAll (HTRequest * me)
2.55 frystyk 1092: {
2.59 ! frystyk 1093: if (me && me->afters) {
! 1094: HTNetCall_deleteAfterAll(me->afters);
! 1095: me->afters = NULL;
! 1096: me->afters_local = NO;
! 1097: return YES;
2.55 frystyk 1098: }
1099: return NO;
1100: }
1101:
2.59 ! frystyk 1102: PUBLIC HTList * HTRequest_after (HTRequest * me, BOOL *override)
2.55 frystyk 1103: {
2.59 ! frystyk 1104: if (me) {
! 1105: *override = me->afters_local;
! 1106: return me->afters;
2.55 frystyk 1107: }
2.59 ! frystyk 1108: return NULL;
! 1109: }
! 1110:
! 1111: /*
! 1112: ** Call back function for context swapping
! 1113: */
! 1114: PUBLIC void HTRequest_setCallback (HTRequest * me, HTRequestCallback *cbf)
! 1115: {
! 1116: if (me) me->callback = cbf;
2.55 frystyk 1117: }
1118:
2.59 ! frystyk 1119: PUBLIC HTRequestCallback *HTRequest_callback (HTRequest * me)
2.55 frystyk 1120: {
2.59 ! frystyk 1121: return me ? me->callback : NULL;
2.56 frystyk 1122: }
1123:
1124: /*
2.59 ! frystyk 1125: ** Context pointer to be used in context call back function
2.56 frystyk 1126: */
2.59 ! frystyk 1127: PUBLIC void HTRequest_setContext (HTRequest * me, void *context)
2.56 frystyk 1128: {
2.59 ! frystyk 1129: if (me) me->context = context;
2.56 frystyk 1130: }
1131:
2.59 ! frystyk 1132: PUBLIC void *HTRequest_context (HTRequest * me)
2.56 frystyk 1133: {
2.59 ! frystyk 1134: return me ? me->context : NULL;
! 1135: }
! 1136:
! 1137: /*
! 1138: ** Has output stream been connected to the channel? If not then we
! 1139: ** must free it explicitly when deleting the request object
! 1140: */
! 1141: PUBLIC void HTRequest_setOutputConnected (HTRequest * me, BOOL mode)
! 1142: {
! 1143: if (me) me->connected = mode;
2.56 frystyk 1144: }
1145:
2.59 ! frystyk 1146: PUBLIC BOOL HTRequest_outputConnected (HTRequest * me)
2.56 frystyk 1147: {
2.59 ! frystyk 1148: return me ? me->connected : NO;
2.56 frystyk 1149: }
1150:
1151: /*
2.59 ! frystyk 1152: ** Bytes read in this request
2.56 frystyk 1153: */
2.59 ! frystyk 1154: PUBLIC long HTRequest_bytesRead(HTRequest * me)
2.57 frystyk 1155: {
2.59 ! frystyk 1156: return me ? HTNet_bytesRead(me->net) : -1;
2.57 frystyk 1157: }
1158:
2.59 ! frystyk 1159: /*
! 1160: ** Bytes written in this request
! 1161: */
! 1162: PUBLIC long HTRequest_bytesWritten (HTRequest * me)
2.57 frystyk 1163: {
2.59 ! frystyk 1164: return me ? HTNet_bytesWritten(me->net) : -1;
! 1165: }
! 1166:
! 1167: /*
! 1168: ** Handle the max forward header value
! 1169: */
! 1170: PUBLIC BOOL HTRequest_setMaxForwards (HTRequest * me, int maxforwards)
! 1171: {
! 1172: if (me && maxforwards >= 0) {
! 1173: me->max_forwards = maxforwards;
! 1174: HTRequest_addRqHd(me, HT_C_MAX_FORWARDS); /* Turn it on */
2.57 frystyk 1175: return YES;
1176: }
1177: return NO;
1178: }
1179:
2.59 ! frystyk 1180: PUBLIC int HTRequest_maxForwards (HTRequest * me)
2.57 frystyk 1181: {
2.59 ! frystyk 1182: return me ? me->max_forwards : -1;
2.57 frystyk 1183: }
1184:
1185: /*
2.59 ! frystyk 1186: ** Source request
2.57 frystyk 1187: */
2.59 ! frystyk 1188: PUBLIC BOOL HTRequest_setSource (HTRequest * me, HTRequest * source)
2.57 frystyk 1189: {
2.59 ! frystyk 1190: if (me) {
! 1191: me->source = source;
! 1192: return YES;
2.57 frystyk 1193: }
1194: return NO;
1195: }
1196:
2.59 ! frystyk 1197: PUBLIC HTRequest * HTRequest_source (HTRequest * me)
2.57 frystyk 1198: {
2.59 ! frystyk 1199: return (me ? me->source : NULL);
! 1200: }
! 1201:
! 1202: PUBLIC BOOL HTRequest_isPostWeb (HTRequest * me)
! 1203: {
! 1204: return (me ? me->source != NULL: NO);
2.57 frystyk 1205: }
1206:
2.59 ! frystyk 1207: /*
! 1208: ** POST Call back function for sending data to the destination
! 1209: */
! 1210: PUBLIC void HTRequest_setPostCallback (HTRequest * me, HTPostCallback *cbf)
2.57 frystyk 1211: {
2.59 ! frystyk 1212: if (me) me->PostCallback = cbf;
2.57 frystyk 1213: }
1214:
2.59 ! frystyk 1215: PUBLIC HTPostCallback * HTRequest_postCallback (HTRequest * me)
2.56 frystyk 1216: {
2.59 ! frystyk 1217: return me ? me->PostCallback : NULL;
2.56 frystyk 1218: }
1219:
2.59 ! frystyk 1220: /*
! 1221: ** Entity Anchor
! 1222: */
! 1223: PUBLIC BOOL HTRequest_setEntityAnchor (HTRequest * me,
! 1224: HTParentAnchor * anchor)
2.56 frystyk 1225: {
2.59 ! frystyk 1226: if (me) {
! 1227: me->source_anchor = anchor;
2.56 frystyk 1228: return YES;
1229: }
1230: return NO;
1231: }
1232:
2.59 ! frystyk 1233: PUBLIC HTParentAnchor * HTRequest_entityAnchor (HTRequest * me)
2.56 frystyk 1234: {
2.59 ! frystyk 1235: return me ? me->source_anchor ? me->source_anchor :
! 1236: me->anchor : NULL;
2.50 frystyk 1237: }
1238:
2.1 frystyk 1239: /* ------------------------------------------------------------------------- */
1240: /* POST WEB METHODS */
1241: /* ------------------------------------------------------------------------- */
1242:
1243: /*
1244: ** Add a destination request to this source request structure so that we
1245: ** build the internal request representation of the POST web
1246: ** Returns YES if OK, else NO
1247: */
2.23 frystyk 1248: PUBLIC BOOL HTRequest_addDestination (HTRequest * src, HTRequest * dest)
2.1 frystyk 1249: {
1250: if (src && dest) {
2.23 frystyk 1251: dest->source = src->source = src;
2.1 frystyk 1252: if (!src->mainDestination) {
1253: src->mainDestination = dest;
1254: src->destRequests = 1;
2.36 frystyk 1255: if (CORE_TRACE)
2.30 eric 1256: HTTrace("POSTWeb..... Adding dest %p to src %p\n",
2.23 frystyk 1257: dest, src);
2.1 frystyk 1258: return YES;
1259: } else {
2.23 frystyk 1260: if (!src->destinations) src->destinations = HTList_new();
2.1 frystyk 1261: if (HTList_addObject(src->destinations, (void *) dest)==YES) {
1262: src->destRequests++;
2.36 frystyk 1263: if (CORE_TRACE)
2.30 eric 1264: HTTrace("POSTWeb..... Adding dest %p to src %p\n",
2.23 frystyk 1265: dest, src);
2.1 frystyk 1266: return YES;
1267: }
1268: }
1269: }
1270: return NO;
1271: }
1272:
1273: /*
1274: ** Remove a destination request from this source request structure
2.23 frystyk 1275: ** Remember only to delete the internal request objects as the other
1276: ** comes from the application!
2.1 frystyk 1277: ** Returns YES if OK, else NO
1278: */
2.23 frystyk 1279: PUBLIC BOOL HTRequest_removeDestination (HTRequest * dest)
2.1 frystyk 1280: {
1281: BOOL found=NO;
1282: if (dest && dest->source) {
1283: HTRequest *src = dest->source;
1284: if (src->mainDestination == dest) {
1285: dest->source = NULL;
1286: src->mainDestination = NULL;
1287: src->destRequests--;
1288: found = YES;
2.23 frystyk 1289: } else if (src->destinations) {
2.1 frystyk 1290: if (HTList_removeObject(src->destinations, (void *) dest)) {
1291: src->destRequests--;
1292: found = YES;
1293: }
1294: }
1295: if (found) {
2.23 frystyk 1296: if (dest->internal) HTRequest_delete(dest);
2.36 frystyk 1297: if (CORE_TRACE)
2.30 eric 1298: HTTrace("POSTWeb..... Deleting dest %p from src %p\n",
2.23 frystyk 1299: dest, src);
2.1 frystyk 1300: }
2.23 frystyk 1301: if (src->destRequests <= 0) {
2.36 frystyk 1302: if (CORE_TRACE)
2.30 eric 1303: HTTrace("POSTWeb..... terminated\n");
2.23 frystyk 1304: if (src->internal) HTRequest_delete(src);
2.1 frystyk 1305: }
1306: }
1307: return found;
1308: }
1309:
1310: /*
2.23 frystyk 1311: ** Check to see whether all destinations are ready. If so then enable the
1312: ** source as ready for reading.
1313: ** Returns YES if all dests are ready, NO otherwise
1314: */
1315: PUBLIC BOOL HTRequest_destinationsReady (HTRequest * me)
1316: {
1317: HTRequest * source = me ? me->source : NULL;
1318: if (source) {
1319: if (source->destStreams == source->destRequests) {
1320: HTNet * net = source->net;
2.36 frystyk 1321: if (CORE_TRACE)
2.30 eric 1322: HTTrace("POSTWeb..... All destinations are ready!\n");
2.23 frystyk 1323: if (net) /* Might already have finished */
2.38 eric 1324: HTEvent_register(net->sockfd, source, (SockOps) FD_READ,
2.23 frystyk 1325: net->cbf, net->priority);
1326: return YES;
1327: }
1328: }
1329: return NO;
1330: }
1331:
1332: /*
1333: ** Find the source request object and make the link between the
2.1 frystyk 1334: ** source output stream and the destination input stream. There can be
1335: ** a conversion between the two streams!
1336: ** Returns YES if link is made, NO otherwise
1337: */
2.3 frystyk 1338: PUBLIC BOOL HTRequest_linkDestination (HTRequest *dest)
2.1 frystyk 1339: {
1340: if (dest && dest->input_stream && dest->source && dest!=dest->source) {
1341: HTRequest *source = dest->source;
1342: HTStream *pipe = HTStreamStack(source->output_format,
1343: dest->input_format,
1344: dest->input_stream,
1345: dest, YES);
1346:
1347: /* Check if we are the only one - else spawn off T streams */
1348: /* @@@ We don't do this yet @@@ */
1349:
2.23 frystyk 1350: /* Now set up output stream of the source */
1351: if (source->output_stream)
1352: (*source->output_stream->isa->_free)(source->output_stream);
2.1 frystyk 1353: source->output_stream = pipe ? pipe : dest->input_stream;
1354:
2.36 frystyk 1355: if (CORE_TRACE)
2.30 eric 1356: HTTrace("POSTWeb..... Linking dest %p to src %p\n",
2.23 frystyk 1357: dest, source);
2.1 frystyk 1358: if (++source->destStreams == source->destRequests) {
1359: HTNet *net = source->net;
2.36 frystyk 1360: if (CORE_TRACE)
2.30 eric 1361: HTTrace("POSTWeb..... All destinations ready!\n");
2.1 frystyk 1362: if (net) /* Might already have finished */
2.38 eric 1363: HTEvent_register(net->sockfd, source, (SockOps) FD_READ,
2.1 frystyk 1364: net->cbf, net->priority);
1365: return YES;
1366: }
1367: }
1368: return NO;
1369: }
1370:
1371: /*
1372: ** Remove a feed stream to a destination request from this source
1373: ** request structure. When all feeds are removed the request tree is
1374: ** ready to take down and the operation can be terminated.
1375: ** Returns YES if removed, else NO
1376: */
2.3 frystyk 1377: PUBLIC BOOL HTRequest_unlinkDestination (HTRequest *dest)
2.1 frystyk 1378: {
1379: BOOL found = NO;
1380: if (dest && dest->source && dest != dest->source) {
1381: HTRequest *src = dest->source;
1382: if (src->mainDestination == dest) {
1383: src->output_stream = NULL;
1384: if (dest->input_stream)
1385: (*dest->input_stream->isa->_free)(dest->input_stream);
1386: found = YES;
1387: } else if (src->destinations) {
1388:
1389: /* LOOK THROUGH THE LIST AND FIND THE RIGHT ONE */
1390:
1391: }
1392: if (found) {
1393: src->destStreams--;
2.36 frystyk 1394: if (CORE_TRACE)
2.30 eric 1395: HTTrace("POSTWeb..... Unlinking dest %p from src %p\n",
2.23 frystyk 1396: dest, src);
2.1 frystyk 1397: return YES;
1398: }
1399: }
1400: return NO;
1401: }
1402:
1403: /*
1404: ** Removes all request structures in this PostWeb.
1405: */
2.3 frystyk 1406: PUBLIC BOOL HTRequest_removePostWeb (HTRequest *me)
2.1 frystyk 1407: {
1408: if (me && me->source) {
1409: HTRequest *source = me->source;
1410:
1411: /* Kill main destination */
1412: if (source->mainDestination)
1413: HTRequest_removeDestination(source->mainDestination);
1414:
1415: /* Kill all other destinations */
1416: if (source->destinations) {
1417: HTList *cur = source->destinations;
1418: HTRequest *pres;
1419: while ((pres = (HTRequest *) HTList_nextObject(cur)) != NULL)
1420: HTRequest_removeDestination(pres);
1421: }
1422:
1423: /* Remove source request */
1424: HTRequest_removeDestination(source);
1425: return YES;
1426: }
1427: return NO;
1428: }
1429:
1430: /*
1431: ** Kills all threads in a POST WEB connected to this request but
2.23 frystyk 1432: ** NOT this request itself. We also keep the request structures.
1433: ** Some requests might be preemptive, for example a SMTP request (when
2.1 frystyk 1434: ** that has been implemented). However, this will be handled internally
1435: ** in the load function.
1436: */
2.3 frystyk 1437: PUBLIC BOOL HTRequest_killPostWeb (HTRequest *me)
2.1 frystyk 1438: {
1439: if (me && me->source) {
1440: HTRequest *source = me->source;
2.36 frystyk 1441: if (CORE_TRACE) HTTrace("POSTWeb..... Killing\n");
2.1 frystyk 1442:
2.23 frystyk 1443: /*
1444: ** Kill source. The stream tree is now freed so we have to build
1445: ** that again. This is done in HTRequest_linkDestination()
1446: */
1447: if (me != source) {
1448: HTNet_kill(source->net);
1449: source->output_stream = NULL;
1450: }
2.1 frystyk 1451:
1452: /* Kill all other destinations */
1453: if (source->destinations) {
1454: HTList *cur = source->destinations;
1455: HTRequest *pres;
1456: while ((pres = (HTRequest *) HTList_nextObject(cur)) != NULL)
2.23 frystyk 1457: if (me != pres) HTNet_kill(pres->net);
2.1 frystyk 1458: }
2.23 frystyk 1459:
1460: /* Kill main destination */
1461: if (source->mainDestination && me != source->mainDestination)
1462: HTNet_kill(source->mainDestination->net);
2.1 frystyk 1463: return YES;
1464: }
1465: return NO;
1466: }
1467:
1468: /* --------------------------------------------------------------------------*/
1469: /* Document Loader */
1470: /* --------------------------------------------------------------------------*/
1471:
1472: /* Request a resource
1473: ** ------------------
1474: ** This is an internal routine, which has an address AND a matching
1475: ** anchor. (The public routines are called with one OR the other.)
1476: ** Returns:
1477: ** YES if request has been registered (success)
1478: ** NO an error occured
1479: */
2.59 ! frystyk 1480: PUBLIC BOOL HTLoad (HTRequest * me, BOOL recursive)
2.1 frystyk 1481: {
2.59 ! frystyk 1482: if (!me || !me->anchor) {
2.36 frystyk 1483: if (CORE_TRACE) HTTrace("Load Start.. Bad argument\n");
2.1 frystyk 1484: return NO;
1485: }
2.57 frystyk 1486:
1487: /* Make sure that we don't carry over any old physical address */
2.59 ! frystyk 1488: HTAnchor_clearPhysical(me->anchor);
2.57 frystyk 1489:
2.59 ! frystyk 1490: /* Set the default method if not already done */
! 1491: if (me->method == METHOD_INVALID) me->method = METHOD_GET;
2.57 frystyk 1492:
1493: /* Should we keep the error stack or not? */
2.59 ! frystyk 1494: if (!recursive && me->error_stack) {
! 1495: HTError_deleteAll(me->error_stack);
! 1496: me->error_stack = NULL;
! 1497: }
! 1498:
! 1499: /* Delete any old Response Object */
! 1500: if (me->response) {
! 1501: HTResponse_delete(me->response);
! 1502: me->response = NULL;
2.16 frystyk 1503: }
2.57 frystyk 1504:
1505: /*
1506: ** We set the start point of handling a request to here.
1507: ** This time will be used by the cache
1508: */
2.59 ! frystyk 1509: HTRequest_setDate(me, time(NULL));
2.57 frystyk 1510:
1511: /* Now start the Net Manager */
2.59 ! frystyk 1512: return HTNet_newClient(me);
2.1 frystyk 1513: }
1514:
Webmaster