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