Annotation of libwww/Library/src/HTReqMan.c, revision 2.80

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

Webmaster