Annotation of libwww/Library/src/HTAccess.c, revision 1.120

1.120   ! eric        1: /*                                                                  htaccess.c
1.61      frystyk     2: **     ACCESS MANAGER
                      3: **
1.75      frystyk     4: **     (c) COPYRIGHT MIT 1995.
1.61      frystyk     5: **     Please first read the full copyright statement in the file COPYRIGH.
1.120   ! eric        6: **     @(#) $Id: HTAccess.c,v 1.119 1996/04/12 17:45:34 frystyk Exp $
1.1       timbl       7: **
                      8: ** Authors
1.79      frystyk     9: **     TBL     Tim Berners-Lee timbl@w3.org
1.4       timbl      10: **     JFG     Jean-Francois Groff jfg@dxcern.cern.ch
1.1       timbl      11: **     DD      Denis DeLaRoca (310) 825-4580  <CSP1DWD@mvs.oac.ucla.edu>
                     12: ** History
                     13: **       8 Jun 92 Telnet hopping prohibited as telnet is not secure TBL
                     14: **     26 Jun 92 When over DECnet, suppressed FTP, Gopher and News. JFG
1.42      frystyk    15: **      6 Oct 92 Moved HTClientHost and HTlogfile into here. TBL
1.1       timbl      16: **     17 Dec 92 Tn3270 added, bug fix. DD
1.2       timbl      17: **      4 Feb 93 Access registration, Search escapes bad chars TBL
1.9       timbl      18: **               PARAMETERS TO HTSEARCH AND HTLOADRELATIVE CHANGED
                     19: **     28 May 93 WAIS gateway explicit if no WAIS library linked in.
1.19      timbl      20: **        Dec 93 Bug change around, more reentrant, etc
1.42      frystyk    21: **     09 May 94 logfile renamed to HTlogfile to avoid clash with WAIS
1.114     frystyk    22: **      8 Jul 94 Insulate HT_FREE();
1.88      frystyk    23: **        Sep 95 Rewritten, HFN
1.1       timbl      24: */
                     25: 
1.68      frystyk    26: #if !defined(HT_DIRECT_WAIS) && !defined(HT_DEFAULT_WAIS_GATEWAY)
                     27: #define HT_DEFAULT_WAIS_GATEWAY "http://www.w3.org:8001/"
1.54      frystyk    28: #endif
1.8       timbl      29: 
1.67      frystyk    30: /* Library include files */
1.88      frystyk    31: #include "WWWLib.h"
1.93      frystyk    32: #include "HTReqMan.h"
                     33: #include "HTAccess.h"                                   /* Implemented here */
1.88      frystyk    34: 
1.117     frystyk    35: #ifndef W3C_VERSION
                     36: #define W3C_VERSION    "unknown"
1.99      frystyk    37: #endif
                     38: 
1.93      frystyk    39: PRIVATE char * HTAppName = NULL;         /* Application name: please supply */
                     40: PRIVATE char * HTAppVersion = NULL;    /* Application version: please supply */
1.2       timbl      41: 
1.99      frystyk    42: PRIVATE char * HTLibName = "libwww";
1.117     frystyk    43: PRIVATE char * HTLibVersion = W3C_VERSION;
1.99      frystyk    44: 
                     45: PRIVATE BOOL   HTSecure = NO;           /* Can we access local file system? */
                     46: 
1.111     frystyk    47: #define PUTBLOCK(b, l) (*target->isa->put_block)(target, b, l)
                     48: 
                     49: struct _HTStream {
                     50:     HTStreamClass * isa;
                     51: };
                     52: 
1.59      frystyk    53: /* --------------------------------------------------------------------------*/
1.61      frystyk    54: /*                Initialization and Termination of the Library             */
                     55: /* --------------------------------------------------------------------------*/
                     56: 
1.99      frystyk    57: /*     Information about the Application
                     58: **     ---------------------------------
1.93      frystyk    59: */
1.117     frystyk    60: PUBLIC const char * HTLib_appName (void)
1.93      frystyk    61: {
1.99      frystyk    62:     return HTAppName ? HTAppName : "UNKNOWN";
                     63: }
                     64: 
1.117     frystyk    65: PUBLIC const char * HTLib_appVersion (void)
1.99      frystyk    66: {
                     67:     return HTAppVersion ? HTAppVersion : "0.0";
1.93      frystyk    68: }
                     69: 
1.99      frystyk    70: /*     Information about libwww
                     71: **     ------------------------
                     72: */
1.117     frystyk    73: PUBLIC const char * HTLib_name (void)
1.99      frystyk    74: {
                     75:     return HTLibName ? HTLibName : "UNKNOWN";
                     76: }
                     77: 
1.117     frystyk    78: PUBLIC const char * HTLib_version (void)
1.99      frystyk    79: {
                     80:     return HTLibVersion ? HTLibVersion : "0.0";
                     81: }
                     82: 
                     83: /*     Access Local File System
                     84: **     ------------------------
                     85: **     In this mode we do not tough the local file system at all
1.93      frystyk    86: */
1.99      frystyk    87: PUBLIC BOOL HTLib_secure (void)
                     88: {
                     89:     return HTSecure;
                     90: }
                     91: 
                     92: PUBLIC void HTLib_setSecure (BOOL mode)
1.93      frystyk    93: {
1.99      frystyk    94:     HTSecure = mode;
1.93      frystyk    95: }
                     96: 
1.61      frystyk    97: /*                                                                  HTLibInit
                     98: **
                     99: **     This function initiates the Library and it MUST be called when
                    100: **     starting up an application. See also HTLibTerminate()
                    101: */
1.117     frystyk   102: PUBLIC BOOL HTLibInit (const char * AppName, const char * AppVersion)
1.61      frystyk   103: {
1.91      frystyk   104:     if (WWWTRACE)
1.115     eric      105:        HTTrace("WWWLibInit.. INITIALIZING LIBRARY OF COMMON CODE\n");
1.63      frystyk   106: 
1.93      frystyk   107:     /* Set the application name and version */
                    108:     if (AppName) {
                    109:        char *ptr;
                    110:        StrAllocCopy(HTAppName, AppName);
                    111:        ptr = HTAppName;
                    112:        while (*ptr) {
                    113:            if (WHITE(*ptr)) *ptr = '_';
                    114:            ptr++;
                    115:        }
                    116:     }
                    117:     if (AppVersion) {
                    118:        char *ptr;
                    119:        StrAllocCopy(HTAppVersion, AppVersion);
                    120:        ptr = HTAppVersion;
                    121:        while (*ptr) {
                    122:            if (WHITE(*ptr)) *ptr = '_';
                    123:            ptr++;
                    124:        }
                    125:     }
                    126: 
                    127:     HTBind_init();                                   /* Initialize bindings */
1.61      frystyk   128: 
1.62      frystyk   129: #ifdef WWWLIB_SIG
1.61      frystyk   130:     /* On Solaris (and others?) we get a BROKEN PIPE signal when connecting
1.67      frystyk   131:     ** to a port where we should get `connection refused'. We ignore this 
1.61      frystyk   132:     ** using the following function call
                    133:     */
                    134:     HTSetSignal();                                /* Set signals in library */
1.1       timbl     135: #endif
                    136: 
1.105     frystyk   137: 
1.108     frystyk   138: #ifdef _WINSOCKAPI_
1.67      frystyk   139:     /*
                    140:     ** Initialise WinSock DLL. This must also be shut down! PMH
                    141:     */
                    142:     {
                    143:         WSADATA            wsadata;
                    144:        if (WSAStartup(DESIRED_WINSOCK_VERSION, &wsadata)) {
1.91      frystyk   145:            if (WWWTRACE)
1.115     eric      146:                HTTrace("WWWLibInit.. Can't initialize WinSoc\n");
1.67      frystyk   147:             WSACleanup();
                    148:             return NO;
                    149:         }
                    150:         if (wsadata.wVersion < MINIMUM_WINSOCK_VERSION) {
1.91      frystyk   151:             if (WWWTRACE)
1.115     eric      152:                HTTrace("WWWLibInit.. Bad version of WinSoc\n");
1.67      frystyk   153:             WSACleanup();
                    154:             return NO;
                    155:         }
                    156:     }
1.108     frystyk   157: #endif /* _WINSOCKAPI_ */
1.67      frystyk   158: 
1.71      frystyk   159:     HTGetTimeZoneOffset();        /* Find offset from GMT if using mktime() */
1.70      frystyk   160:     HTTmp_setRoot(NULL);                    /* Set up default tmp directory */
1.61      frystyk   161:     return YES;
                    162: }
                    163: 
                    164: 
1.90      frystyk   165: /*     HTLibTerminate
                    166: **     --------------
1.117     frystyk   167: **     This function HT_FREEs memory kept by the Library and should be called
1.63      frystyk   168: **     before exit of an application (if you are on a PC platform)
1.61      frystyk   169: */
1.101     frystyk   170: PUBLIC BOOL HTLibTerminate (void)
1.61      frystyk   171: {
1.116     frystyk   172:     if (WWWTRACE) HTTrace("WWWLibTerm.. Cleaning up LIBRARY OF COMMON CODE\n");
                    173: 
                    174:     HT_FREE(HTAppName);                /* Freed thanks to Wade Ogden <wade@ebt.com> */
                    175:     HT_FREE(HTAppVersion);
                    176: 
1.101     frystyk   177:     HTAtom_deleteAll();                                         /* Remove the atoms */
                    178:     HTDNS_deleteAll();                         /* Remove the DNS host cache */
                    179:     HTAnchor_deleteAll(NULL);          /* Delete anchors and drop hyperdocs */
1.73      frystyk   180: 
1.81      frystyk   181:     HTProtocol_deleteAll();  /* Remove bindings between access and protocols */
1.73      frystyk   182:     HTBind_deleteAll();            /* Remove bindings between suffixes, media types */
                    183: 
1.77      frystyk   184:     HTFreeHostName();                      /* Free up some internal strings */
1.63      frystyk   185:     HTFreeMailAddress();
1.118     eric      186:     HTTmp_freeRoot();
1.67      frystyk   187: 
1.108     frystyk   188: #ifdef _WINSOCKAPI_
1.67      frystyk   189:     WSACleanup();
1.105     frystyk   190: #endif
                    191: 
1.61      frystyk   192:     return YES;
                    193: }
                    194: 
1.59      frystyk   195: /* --------------------------------------------------------------------------*/
1.104     frystyk   196: /*                             Load Access functions                        */
1.59      frystyk   197: /* --------------------------------------------------------------------------*/
1.33      luotonen  198: 
1.90      frystyk   199: /*     Request a document
                    200: **     -----------------
                    201: **     Private version that requests a document from the request manager
                    202: **     Returns YES if request accepted, else NO
1.88      frystyk   203: */
1.101     frystyk   204: PRIVATE BOOL HTLoadDocument (HTRequest * request, BOOL recursive)
1.88      frystyk   205: {
                    206:     if (PROT_TRACE) {
1.90      frystyk   207:        HTParentAnchor *anchor = HTRequest_anchor(request);
                    208:        char * full_address = HTAnchor_address((HTAnchor *) anchor);
1.115     eric      209:        HTTrace("HTAccess.... Accessing document %s\n", full_address);
1.114     frystyk   210:        HT_FREE(full_address);
1.88      frystyk   211:     }
1.96      frystyk   212:     return HTLoad(request, recursive);
1.58      frystyk   213: }
1.1       timbl     214: 
                    215: 
1.90      frystyk   216: /*     Request a document from absolute name
                    217: **     -------------------------------------
                    218: **     Request a document referencd by an absolute URL.
                    219: **     Returns YES if request accepted, else NO
                    220: */
1.117     frystyk   221: PUBLIC BOOL HTLoadAbsolute (const char * url, HTRequest* request)
1.90      frystyk   222: {
                    223:     if (url && request) {
                    224:        HTAnchor * anchor = HTAnchor_findAddress(url);
                    225:        HTRequest_setAnchor(request, anchor);
                    226:        return HTLoadDocument(request, NO);
                    227:     }
                    228:     return NO;
                    229: }
                    230: 
                    231: 
                    232: /*     Request a document from absolute name to stream
                    233: **     -----------------------------------------------
                    234: **     Request a document referencd by an absolute URL and sending the data
                    235: **     down a stream. This is _excactly_ the same as HTLoadAbsolute as
                    236: **     the ourputstream is specified using the function
                    237: **     HTRequest_setOutputStream(). 'filter' is ignored!
                    238: **     Returns YES if request accepted, else NO
                    239: */
1.117     frystyk   240: PUBLIC BOOL HTLoadToStream (const char * url, BOOL filter, HTRequest *request)
1.90      frystyk   241: {
                    242:     return HTLoadAbsolute(url, request);
                    243: }
                    244: 
                    245: 
                    246: /*     Request a document from relative name
                    247: **     -------------------------------------
                    248: **     Request a document referenced by a relative URL. The relative URL is 
                    249: **     made absolute by resolving it relative to the address of the 'base' 
                    250: **     anchor.
                    251: **     Returns YES if request accepted, else NO
                    252: */
1.117     frystyk   253: PUBLIC BOOL HTLoadRelative (const char *       relative,
1.90      frystyk   254:                            HTParentAnchor *    base,
                    255:                            HTRequest *         request)
                    256: {
                    257:     BOOL status = NO;
                    258:     if (relative && base && request) {
                    259:        char * rel = NULL;
                    260:        char * full_url = NULL;
                    261:        char * base_url = HTAnchor_address((HTAnchor *) base);
                    262:        StrAllocCopy(rel, relative);
                    263:        full_url = HTParse(HTStrip(rel), base_url,
                    264:                         PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
                    265:        status = HTLoadAbsolute(full_url, request);
1.114     frystyk   266:        HT_FREE(rel);
                    267:        HT_FREE(full_url);
                    268:        HT_FREE(base_url);
1.90      frystyk   269:     }
                    270:     return status;
                    271: }
                    272: 
                    273: 
                    274: /*     Request an anchor
                    275: **     -----------------
                    276: **     Request the document referenced by the anchor
                    277: **     Returns YES if request accepted, else NO
                    278: */
                    279: PUBLIC BOOL HTLoadAnchor (HTAnchor * anchor, HTRequest * request)
                    280: {
                    281:     if (anchor && request) {
                    282:        HTRequest_setAnchor(request, anchor);
                    283:        return HTLoadDocument(request, NO);
                    284:     }
                    285:     return NO;
                    286: }
                    287: 
                    288: 
                    289: /*     Request an anchor
                    290: **     -----------------
                    291: **     Same as HTLoadAnchor but any information in the Error Stack in the 
                    292: **     request object is kept, so that any error messages in one 
1.52      frystyk   293: **     This function is almost identical to HTLoadAnchor, but it doesn't
                    294: **     clear the error stack so that the information in there is kept.
1.90      frystyk   295: **     Returns YES if request accepted, else NO
                    296: */
                    297: PUBLIC BOOL HTLoadAnchorRecursive (HTAnchor * anchor, HTRequest * request)
                    298: {
                    299:     if (anchor && request) {
                    300:        HTRequest_setAnchor(request, anchor);
                    301:         return HTLoadDocument(request, YES);
                    302:     }
                    303:     return NO;
                    304: }
                    305: 
                    306: 
                    307: /*     Search an Anchor
                    308: **     ----------------
                    309: **     Performs a keyword search on word given by the user. Adds the keyword
                    310: **     to the end of the current address and attempts to open the new address.
                    311: **     The list of keywords must be a space-separated list and spaces will
                    312: **     be converted to '+' before the request is issued.
                    313: **     Search can also be performed by HTLoadAbsolute() etc.
                    314: **     Returns YES if request accepted, else NO
                    315: */
1.117     frystyk   316: PUBLIC BOOL HTSearch (const char *     keywords,
1.90      frystyk   317:                      HTParentAnchor *  base,
                    318:                      HTRequest *       request)
                    319: {
1.99      frystyk   320:     BOOL status = NO;
1.90      frystyk   321:     if (keywords && base && request) {
                    322:        char *base_url = HTAnchor_address((HTAnchor *) base);
                    323:        if (*keywords) {
                    324:            char *plus;
                    325:            StrAllocCat(base_url, "?");
                    326:            StrAllocCat(base_url, keywords);
                    327:            plus = strchr(base_url, '?');
                    328:            while (*plus) {
                    329:                if (*plus == ' ') *plus = '+';
                    330:                plus++;
                    331:            }
1.2       timbl     332:        }
1.99      frystyk   333:        status = HTLoadAbsolute(base_url, request);
1.114     frystyk   334:        HT_FREE(base_url);
1.90      frystyk   335:     }
1.99      frystyk   336:     return status;
1.2       timbl     337: }
                    338: 
                    339: 
1.90      frystyk   340: /*     Search a document from absolute name
                    341: **     ------------------------------------
                    342: **     Request a document referencd by an absolute URL appended with the
                    343: **     keywords given. The URL can NOT contain any fragment identifier!
                    344: **     The list of keywords must be a space-separated list and spaces will
                    345: **     be converted to '+' before the request is issued.
                    346: **     Returns YES if request accepted, else NO
                    347: */
1.117     frystyk   348: PUBLIC BOOL HTSearchAbsolute (const char *     keywords,
                    349:                              const char *      url,
1.90      frystyk   350:                              HTRequest *       request)
                    351: {
                    352:     if (url && request) {
                    353:        HTAnchor * anchor = HTAnchor_findAddress(url);
                    354:        return HTSearch(keywords, HTAnchor_parent(anchor), request);
                    355:     }
                    356:     return NO;
1.57      howcome   357: }
                    358: 
1.70      frystyk   359: /* --------------------------------------------------------------------------*/
1.104     frystyk   360: /*                             Post Access Functions                        */
1.70      frystyk   361: /* --------------------------------------------------------------------------*/
                    362: 
1.90      frystyk   363: /*     Copy an anchor
1.70      frystyk   364: **     --------------
1.90      frystyk   365: **     Fetch the URL (possibly local file URL) and send it using either PUT
                    366: **     or POST to the remote destination using HTTP. The caller can decide the
                    367: **     exact method used and which HTTP header fields to transmit by setting
                    368: **     the user fields in the request structure.
1.92      frystyk   369: **     If posting to NNTP then we can't dispatch at this level but must pass
                    370: **     the source anchor to the news module that then takes all the refs
                    371: **     to NNTP and puts into the "newsgroups" header
1.90      frystyk   372: **     Returns YES if request accepted, else NO
1.70      frystyk   373: */
1.109     frystyk   374: PUBLIC BOOL HTCopyAnchor (HTAnchor * src_anchor, HTRequest * main_dest)
1.80      frystyk   375: { 
1.106     frystyk   376:     HTRequest * src_req;
                    377:     HTList * cur;
1.109     frystyk   378:     if (!src_anchor || !main_dest) {
1.115     eric      379:        if (WWWTRACE) HTTrace("Copy........ BAD ARGUMENT\n");
1.90      frystyk   380:        return NO;
1.109     frystyk   381:     }
1.70      frystyk   382: 
1.112     frystyk   383:     /* Set the source anchor */
                    384:     main_dest->source_anchor = HTAnchor_parent(src_anchor);
                    385: 
1.80      frystyk   386:     /* Build the POST web if not already there */
1.109     frystyk   387:     if (!main_dest->source) {
                    388:        src_req = HTRequest_dupInternal(main_dest);       /* Get a duplicate */
1.80      frystyk   389:        HTAnchor_clearHeader((HTParentAnchor *) src_anchor);
1.109     frystyk   390:        src_req->method = METHOD_GET;
1.85      frystyk   391:        src_req->reload = HT_MEM_REFRESH;
1.104     frystyk   392:        src_req->output_stream = NULL;
1.80      frystyk   393:        src_req->output_format = WWW_SOURCE;     /* We want source (for now) */
                    394: 
                    395:        /* Set up the main link in the source anchor */
                    396:        {
1.106     frystyk   397:            HTLink * main_link = HTAnchor_mainLink((HTAnchor *) src_anchor);
                    398:            HTAnchor *main_anchor = HTLink_destination(main_link);
                    399:            HTMethod method = HTLink_method(main_link);
1.85      frystyk   400:            if (!main_link || method==METHOD_INVALID) {
1.91      frystyk   401:                if (WWWTRACE)
1.115     eric      402:                    HTTrace("Copy Anchor. No destination found or unspecified method\n");
1.80      frystyk   403:                HTRequest_delete(src_req);
1.90      frystyk   404:                return NO;
1.80      frystyk   405:            }
1.109     frystyk   406:            main_dest->GenMask |= HT_G_DATE;             /* Send date header */
                    407:            main_dest->reload = HT_CACHE_REFRESH;
                    408:            main_dest->method = method;
                    409:            main_dest->input_format = WWW_SOURCE;
                    410:            HTRequest_addDestination(src_req, main_dest);
                    411:            if (HTLoadAnchor(main_anchor, main_dest) == NO)
                    412:                return NO;
1.80      frystyk   413:        }
1.78      frystyk   414: 
1.80      frystyk   415:        /* For all other links in the source anchor */
1.106     frystyk   416:        if ((cur = HTAnchor_subLinks(src_anchor))) {
                    417:            HTLink * pres;
1.109     frystyk   418:            while ((pres = (HTLink *) HTList_nextObject(cur))) {
1.106     frystyk   419:                HTAnchor *dest = HTLink_destination(pres);
                    420:                HTMethod method = HTLink_method(pres);
1.80      frystyk   421:                HTRequest *dest_req;
                    422:                if (!dest || method==METHOD_INVALID) {
1.91      frystyk   423:                    if (WWWTRACE)
1.115     eric      424:                        HTTrace("Copy Anchor. Bad anchor setup %p\n",
1.80      frystyk   425:                                dest);
1.90      frystyk   426:                    return NO;
1.80      frystyk   427:                }
1.109     frystyk   428:                dest_req = HTRequest_dupInternal(main_dest);
1.107     frystyk   429:                dest_req->GenMask |= HT_G_DATE;          /* Send date header */
1.85      frystyk   430:                dest_req->reload = HT_CACHE_REFRESH;
1.80      frystyk   431:                dest_req->method = method;
1.104     frystyk   432:                dest_req->output_stream = NULL;
                    433:                dest_req->output_format = WWW_SOURCE;
1.109     frystyk   434:                HTRequest_addDestination(src_req, dest_req);
1.104     frystyk   435: 
1.90      frystyk   436:                if (HTLoadAnchor(dest, dest_req) == NO)
                    437:                    return NO;
1.80      frystyk   438:            }
                    439:        }
                    440:     } else {                    /* Use the existing Post Web and restart it */
1.109     frystyk   441:        src_req = main_dest->source;
1.80      frystyk   442:        if (src_req->mainDestination)
1.109     frystyk   443:            if (HTLoadDocument(main_dest, NO) == NO)
1.90      frystyk   444:                return NO;
1.80      frystyk   445:        if (src_req->destinations) {
1.106     frystyk   446:            HTRequest * pres;
                    447:            cur = HTAnchor_subLinks(src_anchor);
1.80      frystyk   448:            while ((pres = (HTRequest *) HTList_nextObject(cur)) != NULL) {
1.90      frystyk   449:                if (HTLoadDocument(pres, NO) == NO)
                    450:                    return NO;
1.80      frystyk   451:            }
                    452:        }
1.78      frystyk   453:     }
                    454: 
1.80      frystyk   455:     /* Now open the source */
                    456:     return HTLoadAnchor(src_anchor, src_req);
1.70      frystyk   457: }
                    458: 
                    459: 
1.90      frystyk   460: /*     Upload an Anchor
1.70      frystyk   461: **     ----------------
1.111     frystyk   462: **     This function can be used to send data along with a request to a remote
                    463: **     server. It can for example be used to POST form data to a remote HTTP
                    464: **     server - or it can be used to post a newsletter to a NNTP server. In
                    465: **     either case, you pass a callback function which the request calls when
                    466: **     the remote destination is ready to accept data. In this callback
                    467: **     you get the current request object and a stream into where you can 
                    468: **     write data. It is very important that you return the value returned
                    469: **     by this stream to the Library so that it knows what to do next. The
                    470: **     reason is that the outgoing stream might block or an error may
                    471: **     occur and in that case the Library must know about it. The source
                    472: **     anchor represents the data object in memory and it points to 
                    473: **     the destination anchor by using the POSTWeb method. The source anchor
                    474: **     contains metainformation about the data object in memory and the 
                    475: **     destination anchor represents the reponse from the remote server.
1.90      frystyk   476: **     Returns YES if request accepted, else NO
                    477: */
1.111     frystyk   478: PUBLIC BOOL HTUploadAnchor (HTAnchor *         source_anchor,
                    479:                            HTRequest *         request,
                    480:                            HTPostCallback *    callback)
                    481: {
                    482:     HTLink * link = HTAnchor_mainLink((HTAnchor *) source_anchor);
                    483:     HTAnchor * dest_anchor = HTLink_destination(link);
                    484:     HTMethod method = HTLink_method(link);
                    485:     if (!link || method==METHOD_INVALID || !callback) {
                    486:        if (WWWTRACE)
1.115     eric      487:            HTTrace("Upload...... No destination found or unspecified method\n");
1.90      frystyk   488:        return NO;
1.109     frystyk   489:     }
1.111     frystyk   490:     request->GenMask |= HT_G_DATE;                      /* Send date header */
                    491:     request->reload = HT_CACHE_REFRESH;
                    492:     request->method = method;
                    493:     request->source_anchor = HTAnchor_parent(source_anchor);
                    494:     request->PostCallback = callback;
                    495:     return HTLoadAnchor(dest_anchor, request);
                    496: }
                    497: 
                    498: /*     POST Callback Handler
                    499: **     ---------------------
                    500: **     If you do not want to handle the stream interface on your own, you
                    501: **     can use this function which writes the source anchor hyperdoc to the
                    502: **     target stream for the anchor upload and also handles the return value
                    503: **     from the stream. If you don't want to write the source anchor hyperdoc
                    504: **     then you can register your own callback function that can get the data
                    505: **     you want.
                    506: */
                    507: PUBLIC int HTUpload_callback (HTRequest * request, HTStream * target)
                    508: {
1.115     eric      509:     if (WWWTRACE) HTTrace("Uploading... from callback function\n");
1.111     frystyk   510:     if (!request || !request->source_anchor || !target) return HT_ERROR;
                    511:     {
                    512:        int status;
                    513:        HTParentAnchor * source = request->source_anchor;
                    514:        char * document = (char *) HTAnchor_document(request->source_anchor);
                    515:        int len = HTAnchor_length(source);
                    516:        if (len < 0) {
                    517:            len = strlen(document);
                    518:            HTAnchor_setLength(source, len);
                    519:        }
                    520:        status = (*target->isa->put_block)(target, document, len);
                    521:        if (status == HT_OK)
                    522:            return (*target->isa->flush)(target);
                    523:        if (status == HT_WOULD_BLOCK) {
1.115     eric      524:            if (PROT_TRACE)HTTrace("POST Anchor. Target WOULD BLOCK\n");
1.111     frystyk   525:            return HT_WOULD_BLOCK;
                    526:        } else if (status == HT_PAUSE) {
1.115     eric      527:            if (PROT_TRACE) HTTrace("POST Anchor. Target PAUSED\n");
1.111     frystyk   528:            return HT_PAUSE;
                    529:        } else if (status > 0) {              /* Stream specific return code */
                    530:            if (PROT_TRACE)
1.115     eric      531:                HTTrace("POST Anchor. Target returns %d\n", status);
1.111     frystyk   532:            return status;
1.120   ! eric      533:        } else {                                     /* we have a real error */
1.115     eric      534:            if (PROT_TRACE) HTTrace("POST Anchor. Target ERROR\n");
1.111     frystyk   535:            return status;
                    536:        }
1.70      frystyk   537:     }
1.1       timbl     538: }

Webmaster