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

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

Webmaster