Annotation of Amaya/amaya/query.c, revision 1.224

1.14      cvs         1: /*
                      2:  *
                      3:  *  (c) COPYRIGHT MIT and INRIA, 1996.
                      4:  *  Please first read the full copyright statement in file COPYRIGHT.
1.156     cvs         5:  * 
1.14      cvs         6:  */
1.4       cvs         7: 
1.19      cvs         8: /*
1.83      cvs         9:  * query.c : contains all the functions for requesting and publishing
1.19      cvs        10:  * URLs via libwww. It handles any eventual HTTP error code
                     11:  * (redirection, authentication needed, not found, etc.)
                     12:  *
1.69      cvs        13:  * Author: J. Kahan
1.92      cvs        14:  *         J. Kahan/R. Guetari Windows 95/NT routines
1.19      cvs        15:  */
1.17      cvs        16: 
1.44      cvs        17: #ifndef AMAYA_JAVA
                     18: 
1.116     cvs        19: /* defines to include elsewhere
                     20: *********************************/
                     21: 
1.185     cvs        22: #ifdef _WINDOWS
                     23: #include <string.h>
1.130     cvs        24: #endif /* !_WINDOWS */
1.116     cvs        25: #define AMAYA_WWW_CACHE
1.168     cvs        26: #define AMAYA_LOST_UPDATE
1.116     cvs        27: 
1.223     cvs        28: #ifdef _WINDOWS
                     29: #      define CACHE_DIR_NAME CUSTEXT("\\libwww-cache\\")
                     30: #else
                     31: #      define CACHE_DIR_NAME CUSTEXT("/libwww-cache/")
                     32: #endif
1.198     cvs        33: 
1.216     cvs        34: /* libwww default parameters */
1.176     cvs        35: #define DEFAULT_CACHE_SIZE 10
                     36: #define DEFAULT_MAX_CACHE_ENTRY_SIZE 3
1.177     cvs        37: #define DEFAULT_MAX_SOCKET 32
1.176     cvs        38: #define DEFAULT_DNS_TIMEOUT 1800L
1.151     cvs        39: #define DEFAULT_PERSIST_TIMEOUT 60L
1.165     cvs        40: #define DEFAULT_NET_EVENT_TIMEOUT 60000
1.216     cvs        41: /* defines the priority for image content negotiation */
                     42: #define IMAGE_ACCEPT_NEGOTIATION "*/*;q=0.1,image/*,image/gif,image/jpeg,image/png"
1.116     cvs        43: 
1.12      cvs        44: /* Amaya includes  */
1.25      cvs        45: #define THOT_EXPORT extern
1.4       cvs        46: #include "amaya.h"
1.214     cvs        47: #include "init_f.h"
1.130     cvs        48: #include <sys/types.h>
1.70      cvs        49: #include <fcntl.h>
1.140     cvs        50: #include "HTEvtLst.h"
1.157     cvs        51: #include "HTAABrow.h"
1.223     cvs        52: #include "ustring.h"
1.7       cvs        53: 
1.141     cvs        54: #if defined(__svr4__) || defined (_AIX)
1.4       cvs        55: #define CATCH_SIG
                     56: #endif
                     57: 
                     58: /* local structures coming from libwww and which are
1.17      cvs        59:    not found in any .h file
1.7       cvs        60:  */
1.68      cvs        61: 
1.7       cvs        62: struct _HTStream
                     63:   {
1.15      cvs        64:      const HTStreamClass *isa;
                     65:      FILE               *fp;
1.45      cvs        66:      BOOL                leave_open;   /* Close file when TtaFreeMemory? */
1.15      cvs        67:      char               *end_command;  /* Command to execute       */
                     68:      BOOL                remove_on_close;      /* Remove file?             */
                     69:      char               *filename;     /* Name of file             */
                     70:      HTRequest          *request;      /* saved for callback       */
                     71:      HTRequestCallback  *callback;
1.7       cvs        72:   };
                     73: 
1.15      cvs        74: 
1.7       cvs        75: struct _HTError
                     76:   {
                     77:      HTErrorElement      element;      /* Index number into HTError */
                     78:      HTSeverity          severity;     /* A la VMS */
                     79:      BOOL                ignore;       /* YES if msg should not go to user */
                     80:      void               *par;  /* Explanation, e.g. filename  */
                     81:      int                 length;       /* For copying by generic routine */
                     82:      char               *where;        /* Which function */
                     83:   };
                     84: 
1.4       cvs        85: /* Type definitions and global variables etc. local to this module */
                     86: 
1.17      cvs        87: /*----------------------------------------------------------------------*/
                     88: 
1.4       cvs        89: /*** private variables ***/
1.17      cvs        90: 
1.4       cvs        91: static HTList      *converters = NULL; /* List of global converters */
1.27      cvs        92: static HTList      *acceptTypes = NULL; /* List of types for the Accept header */
1.193     cvs        93: static HTList      *acceptLanguages = NULL; /* List of language priorities for the Accept header */
1.151     cvs        94: static HTList      *transfer_encodings = NULL;
                     95: static HTList      *content_encodings = NULL;
1.207     cvs        96: /* List of domains where we can do a safe PUT redirect */
                     97: static HTList      *safeput_list = NULL;
                     98: 
1.16      cvs        99: static int          object_counter = 0;        /* loaded objects counter */
1.191     cvs       100: static  ThotBool    AmayaAlive_flag; /* set to 1 if the application is active;
1.140     cvs       101:                                        0 if we have killed */
1.191     cvs       102: static  ThotBool    CanDoStop_flag; /* set to 1 if we can do a stop, 0
1.140     cvs       103:                                       if we're inside a critical section */
1.214     cvs       104: static  ThotBool    UserAborted_flag; /* set to 1 if we're processing a user
                    105:                                         induced stop request operation */
1.128     cvs       106: #ifdef  AMAYA_WWW_CACHE
1.130     cvs       107: static int          fd_cachelock; /* open handle to the .lock cache file */
                    108: #endif /* AMAYA_WWW_CACHE */
1.4       cvs       109: 
1.15      cvs       110: #include "answer_f.h"
                    111: #include "query_f.h"
                    112: #include "AHTURLTools_f.h"
                    113: #include "AHTBridge_f.h"
                    114: #include "AHTMemConv_f.h"
                    115: #include "AHTFWrite_f.h"
1.4       cvs       116: 
1.116     cvs       117: /* prototypes */
                    118: 
                    119: #ifdef __STDC__
1.223     cvs       120: static void RecCleanCache (CharUnit* dirname);
1.123     cvs       121: #ifdef _WINDOWS
1.70      cvs       122: int WIN_Activate_Request (HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar*);
1.116     cvs       123: #endif /* _WINDOWS */
1.207     cvs       124: static void SafePut_init (void);
                    125: static void SafePut_delete (void);
                    126: static ThotBool SafePut_query (char *url);
                    127: 
1.70      cvs       128: #else
1.128     cvs       129: static void RecCleanCache (/* char *dirname */);
1.123     cvs       130: #ifdef _WINDOWS
1.128     cvs       131: int WIN_Activate_Request (/* HTRequest* , HTAlertOpcode, int, const char*, void*, HTAlertPar* */);
1.116     cvs       132: #endif /* _WINDOWS */
1.207     cvs       133: static void SafePut_init (/* void */);
                    134: static void SafePut_delete (/* void */);
                    135: static ThotBool SafePut_query (/* char *url */);
1.70      cvs       136: #endif /* __STDC__ */
1.116     cvs       137: 
1.15      cvs       138: 
1.130     cvs       139: #ifdef AMAYA_WWW_CACHE
                    140: /***************************************************************
                    141:  lock functions, used to avoid concurrent use of the cache
                    142:  Mostly based on W. Richard Stevens' APUE book.
                    143:  ***************************************************************/
                    144: /*----------------------------------------------------------------------
                    145:   set_cachelock
                    146:   sets a write lock on filename. 
                    147:   Returns -1 in case of failure, otherwise, it'll open a handle on
                    148:   filename and fd_cachelock will take its value.
                    149:   ----------------------------------------------------------------------*/
                    150: #ifdef __STDC__
1.223     cvs       151: static int set_cachelock (CharUnit* filename)
1.130     cvs       152: #else        
                    153: static int set_cachelock (filename)
1.223     cvs       154: CharUniut* filename;
1.130     cvs       155: #endif /* __STDC__ */
                    156: {
1.188     cvs       157:   int status;
1.130     cvs       158: #ifdef _WINDOWS
1.188     cvs       159: 
                    160:   status = TtaFileExist (filename);
                    161:   return ((status) ? 0 : -1);
1.130     cvs       162: #else
                    163:   struct flock lock;
                    164:  
                    165:   lock.l_type = F_WRLCK;
                    166:   lock.l_start = 0;
                    167:   lock.l_whence = SEEK_SET;
                    168:   lock.l_len = 0;
                    169:   
                    170:   fd_cachelock = open (filename, O_WRONLY);
                    171:   
                    172:   if (fd_cachelock == -1)
                    173:     status = -1;
                    174:   else
                    175:     status = fcntl(fd_cachelock, F_SETLK, &lock);
                    176:   
                    177:   if (status == -1)
1.190     cvs       178:     {
1.179     cvs       179:       if (fd_cachelock > 0)
1.190     cvs       180:          close (fd_cachelock);
1.179     cvs       181:       fd_cachelock = 0;
1.178     cvs       182:     }
1.130     cvs       183:   return (status);
                    184: #endif /* _WINDOWS */
                    185: }
                    186: 
                    187: /*----------------------------------------------------------------------
                    188:   clear_cachelock
                    189:   remove the write lock set on a filename.
                    190:   It'll close the fd handle on filename and reset *fd to 0.
                    191:   ----------------------------------------------------------------------*/
                    192: #ifdef __STDC__
                    193: static int clear_cachelock (void)
                    194: #else        
                    195: static int clear_cachelock ()
                    196: int *fd;
                    197: #endif /* __STDC__ */
                    198: {
                    199: #ifdef _WINDOWS
                    200:   return 0;
                    201: #else
                    202:   int status;
                    203: 
1.178     cvs       204:   if (!fd_cachelock)
1.130     cvs       205:     return (-1);
                    206:  
1.178     cvs       207:   status = close (fd_cachelock);
1.130     cvs       208:   fd_cachelock = 0;
                    209: 
                    210:   return (status);
                    211: #endif /* _WINDOWS */
                    212: }
                    213: 
                    214: /*----------------------------------------------------------------------
                    215:   test_cachelock
                    216:   returns 0 if a fd is not locked by other process, otherwise 
                    217:   returns the pid of the process who has the lock
                    218:   ----------------------------------------------------------------------*/
                    219: #ifdef __STDC__
1.223     cvs       220: static int test_cachelock (CharUnit* filename)
1.130     cvs       221: #else
                    222: static int test_cachelock (filename)
1.223     cvs       223: CharUnit*  filename;
1.198     cvs       224: #endif /* __STDC__ */
1.130     cvs       225: {
                    226: #ifdef _WINDOWS
1.185     cvs       227:   /* if the lock is set, we can't unlink the file under Windows */
1.188     cvs       228:   if (!TtaFileUnlink (filename))
                    229:     return 0;
                    230:   else
1.185     cvs       231:     return -1;
1.130     cvs       232: #else
                    233:   struct flock lock;
                    234:   int fd, status;
                    235: 
                    236:   lock.l_type = F_WRLCK;
                    237:   lock.l_start = 0;
                    238:   lock.l_whence = SEEK_SET;
                    239:   lock.l_len = 0;
                    240: 
                    241:   fd = open (filename, O_WRONLY);
                    242: 
                    243:   if (fd < 0)
                    244:     return (-1);
                    245:   /* is this file locked ? */
                    246:   status = fcntl (fd,  F_GETLK, &lock);
                    247:   close (fd);
                    248: 
                    249:   if (status < 0)
                    250:     return (-1);
                    251: 
                    252:   if (lock.l_type == F_UNLCK)
                    253:     return (0); /* false, region is not locked by another proc */
                    254:   return (lock.l_pid); /* true, return pid of lock owner */
                    255: #endif /* _WINDOWS */
                    256: }
                    257: 
                    258: #endif /* AMAYA_WWW_CACHE */
                    259: 
1.15      cvs       260: /*----------------------------------------------------------------------
1.17      cvs       261:   GetDocIdStatus
                    262:   gets the status associated to a docid                         
1.15      cvs       263:   ----------------------------------------------------------------------*/
                    264: #ifdef __STDC__
                    265: AHTDocId_Status    *GetDocIdStatus (int docid, HTList * documents)
                    266: #else
                    267: AHTDocID_Status    *GetDocIdStatus (docid, documents)
                    268: int                 docid;
                    269: HTList             *documents;
                    270: 
                    271: #endif
                    272: {
                    273:    AHTDocId_Status    *me;
                    274:    HTList             *cur;
                    275: 
                    276:    if (documents)
                    277:      {
                    278:        cur = documents;
                    279: 
                    280:        while ((me = (AHTDocId_Status *) HTList_nextObject (cur)))
                    281:          {
                    282:             if (me->docid == docid)
                    283:                return (me);
1.18      cvs       284:          }
                    285:      }
1.15      cvs       286:    return (AHTDocId_Status *) NULL;
                    287: 
                    288: }
                    289: 
1.5       cvs       290: /*----------------------------------------------------------------------
1.27      cvs       291:   AHTGuessAtom_for
                    292:   Converts an Amaya type descriptor into the equivalent MIME type.
                    293:   ----------------------------------------------------------------------*/
                    294: #ifdef __STDC__
1.198     cvs       295: static  HTAtom *AHTGuessAtom_for (STRING urlName, PicType contentType)
1.27      cvs       296: #else
                    297: static  HTAtom *AHTGuessAtom_for (urlName, contentType)
1.198     cvs       298: STRING  urlName;
1.27      cvs       299: PicType contentType;
                    300: #endif
                    301: {
                    302:  HTAtom           *atom;
1.198     cvs       303:  STRING            filename;
1.160     cvs       304:  HTEncoding        enc = NULL;
                    305:  HTEncoding        cte = NULL;
                    306:  HTLanguage        lang = NULL;
1.50      cvs       307:  double            quality = 1.0;
1.27      cvs       308: 
                    309:  switch (contentType)
                    310:    {
                    311:     case xbm_type:
                    312:       atom = HTAtom_for("image/xbm");
                    313:       break;
                    314:     case eps_type:
1.35      cvs       315:       atom = HTAtom_for("application/postscript");
1.27      cvs       316:       break;
                    317:    case xpm_type:
                    318:       atom = HTAtom_for("image/xpm");
                    319:      break;
                    320:     case gif_type:
                    321:       atom = HTAtom_for("image/gif");
                    322:       break;
                    323:     case jpeg_type:
                    324:       atom = HTAtom_for("image/jpeg");
                    325:       break;
                    326:     case png_type:
                    327:       atom = HTAtom_for("image/png");
                    328:       break;
                    329:    case unknown_type:
                    330:    default:
                    331:      /* 
                    332:      ** Amaya could not detect the type, so 
                    333:      ** we try to use the filename's suffix to do so.
                    334:      */
1.198     cvs       335:      filename = AmayaParseUrl (urlName, _EMPTYSTR_, AMAYA_PARSE_PATH | AMAYA_PARSE_PUNCTUATION);
                    336:      HTBind_getFormat (WideChar2ISO (filename), &atom, &enc, &cte, &lang, &quality);
1.45      cvs       337:      TtaFreeMemory (filename);
1.27      cvs       338:      if (atom ==  WWW_UNKNOWN)
                    339:         /*
                    340:         ** we could not identify the suffix, so we assign it
                    341:         ** a default type
                    342:         */
                    343:         atom = HTAtom_for ("text/html");
                    344:      break;
                    345:    }
                    346: 
                    347:  return atom;
                    348: }
                    349: 
                    350: /*----------------------------------------------------------------------
1.17      cvs       351:   AHTReqContext_new
                    352:   create a new Amaya Context Object and update the global Amaya
                    353:   request status.
1.5       cvs       354:   ----------------------------------------------------------------------*/
1.4       cvs       355: #ifdef __STDC__
                    356: static AHTReqContext *AHTReqContext_new (int docid)
                    357: #else
                    358: static AHTReqContext *AHTReqContext_new (docid)
                    359: int                 docid;
                    360: 
                    361: #endif
                    362: {
                    363:    AHTReqContext      *me;
                    364:    AHTDocId_Status    *docid_status;
                    365: 
                    366:    if ((me = (AHTReqContext *) TtaGetMemory (sizeof (AHTReqContext))) == NULL)
1.116     cvs       367:      outofmem (__FILE__, "AHTReqContext_new");
                    368: 
                    369:    /* clear the structure */
                    370:    memset ((void *) me, 0, sizeof (AHTReqContext));
1.4       cvs       371: 
1.81      cvs       372:    /* Bind the Context object together with the Request Object */
                    373:    me->request = HTRequest_new ();
                    374:   
1.80      cvs       375:    /* clean the associated file structure) */
1.79      cvs       376:    HTRequest_setOutputStream (me->request, NULL);
1.81      cvs       377:  
1.4       cvs       378:    /* Initialize the other members of the structure */
1.17      cvs       379:    me->reqStatus = HT_NEW; /* initial status of a request */
1.4       cvs       380:    me->docid = docid;
                    381:    HTRequest_setMethod (me->request, METHOD_GET);
                    382:    HTRequest_setOutputFormat (me->request, WWW_SOURCE);
                    383:    HTRequest_setContext (me->request, me);
1.116     cvs       384: 
1.36      cvs       385:    /* experimental */
                    386:    me->read_sock = INVSOC;
                    387:    me->write_sock = INVSOC;
                    388:    me->except_sock = INVSOC;
1.4       cvs       389: 
                    390:    /* Update the global context */
                    391:    HTList_appendObject (Amaya->reqlist, (void *) me);
                    392: 
                    393:    docid_status = GetDocIdStatus (docid, Amaya->docid_status);
                    394: 
1.7       cvs       395:    if (docid_status == NULL)
                    396:      {
1.116     cvs       397:        docid_status = (AHTDocId_Status *) 
                    398:          TtaGetMemory (sizeof (AHTDocId_Status));
1.7       cvs       399:        docid_status->docid = docid;
                    400:        docid_status->counter = 1;
                    401:        HTList_addObject (Amaya->docid_status, (void *) docid_status);
                    402:      }
                    403:    else
1.4       cvs       404:       docid_status->counter++;
                    405: 
                    406:    Amaya->open_requests++;
                    407: 
1.74      cvs       408: #ifdef DEBUG_LIBWWW
                    409:    fprintf (stderr, "AHTReqContext_new: Created object %p\n", me);
                    410: #endif   
1.116     cvs       411: 
1.4       cvs       412:    return me;
                    413: }
                    414: 
1.5       cvs       415: /*----------------------------------------------------------------------
1.17      cvs       416:   AHTReqContext_delete
                    417:   Delete an Amaya Context Object and update the global Amaya request
                    418:   status.
1.5       cvs       419:   ----------------------------------------------------------------------*/
1.4       cvs       420: 
                    421: #ifdef __STDC__
1.191     cvs       422: ThotBool  AHTReqContext_delete (AHTReqContext * me)
1.4       cvs       423: #else
1.191     cvs       424: ThotBool  AHTReqContext_delete (me)
1.4       cvs       425: AHTReqContext      *me;
                    426: 
                    427: #endif
                    428: {
                    429:    AHTDocId_Status    *docid_status;
                    430: 
1.7       cvs       431:    if (me)
                    432:      {
1.74      cvs       433: #ifdef DEBUG_LIBWWW
1.138     cvs       434:        fprintf (stderr, "AHTReqContext_delete: Deleting object %p\n", me);
1.74      cvs       435: #endif   
1.138     cvs       436:        if (Amaya->reqlist)
                    437:         HTList_removeObject (Amaya->reqlist, (void *) me);
                    438:        
                    439:        docid_status = GetDocIdStatus (me->docid, Amaya->docid_status);
                    440:        if (docid_status)
                    441:         {
                    442:           docid_status->counter--;
                    443:           
                    444:           if (docid_status->counter == 0)
                    445:             {
                    446:               HTList_removeObject (Amaya->docid_status, (void *) docid_status);
                    447:               TtaFreeMemory ((void *) docid_status);
                    448:             }
                    449:         }
1.215     cvs       450: 
                    451:        HTNoFreeStream_delete (HTRequest_outputStream (me->request));
                    452:        HTRequest_setOutputStream (me->request, NULL); 
1.190     cvs       453:        /* JK: no longer needed in libwww 5.2.3
                    454:          if (me->method != METHOD_PUT && HTRequest_outputStream (me->request))
                    455:          AHTFWriter_FREE (HTRequest_outputStream (me->request));
                    456:        */
1.138     cvs       457:        HTRequest_delete (me->request);
                    458:        
                    459:        if (me->output && me->output != stdout)
                    460:         {      
1.85      cvs       461: #ifdef DEBUG_LIBWWW       
1.138     cvs       462:           fprintf (stderr, "AHTReqContext_delete: URL is  %s, closing "
                    463:                    "FILE %p\n", me->urlName, me->output); 
1.85      cvs       464: #endif
1.138     cvs       465:           fclose (me->output);
                    466:           me->output = NULL;
                    467:         }
1.79      cvs       468:          
1.138     cvs       469:        if (me->error_stream != (char *) NULL)
                    470:         HT_FREE (me->error_stream);
                    471: #ifndef _WINDOWS
                    472: #ifdef WWW_XWINDOWS    
                    473:        if (me->read_xtinput_id || me->write_xtinput_id ||
                    474:           me->except_xtinput_id)
                    475:         RequestKillAllXtevents(me);
                    476: #endif /* WWW_XWINDOWS */
                    477: #endif /* !_WINDOWS */
                    478:        
                    479:        if (me->reqStatus == HT_ABORT)
                    480:         {
                    481:           if (me->outputfile && me->outputfile[0] != EOS)
                    482:             {
1.198     cvs       483:               TtaFileUnlink (ISO2WideChar (me->outputfile));
1.138     cvs       484:               me->outputfile[0] = EOS;
                    485:             }
                    486:         }
                    487:        
                    488:        if ((me->mode & AMAYA_ASYNC) || (me->mode & AMAYA_IASYNC))
                    489:         /* for the ASYNC mode, free the memory we allocated in GetObjectWWW
                    490:            or in PutObjectWWW */
                    491:         {
                    492:           if (me->urlName)
                    493:             TtaFreeMemory (me->urlName);
                    494:           if (me->outputfile)
                    495:             TtaFreeMemory (me->outputfile);
                    496:         }
1.206     cvs       497: 
1.208     cvs       498:        /* the real name to which we are publishing */
                    499:        if (me->default_put_name)
                    500:         TtaFreeMemory (me->default_put_name);
                    501: 
1.206     cvs       502:        /* @@ temp change for the %esc conversion */
                    503:        if (me->method == METHOD_PUT && me->urlName)
                    504:         TtaFreeMemory (me->urlName);
                    505: 
1.138     cvs       506:        if (me->content_type)
                    507:         TtaFreeMemory (me->content_type);
                    508:        
                    509:        if (me->formdata)
                    510:         HTAssocList_delete (me->formdata);
                    511:        
                    512:        /* to trace bugs */
                    513:        memset ((void *) me, 0, sizeof (AHTReqContext));
                    514:        
                    515:        TtaFreeMemory ((void *) me);
                    516:        
                    517:        Amaya->open_requests--;
                    518:        
                    519:        return TRUE;
1.7       cvs       520:      }
1.15      cvs       521:    return FALSE;
1.4       cvs       522: }
                    523: 
                    524: 
1.15      cvs       525: /*----------------------------------------------------------------------
1.17      cvs       526:   Thread_deleteAll
                    527:   this function deletes the whole list of active threads.           
1.5       cvs       528:   ----------------------------------------------------------------------*/
1.4       cvs       529: #ifdef __STDC__
                    530: static void         Thread_deleteAll (void)
                    531: #else
                    532: static void         Thread_deleteAll ()
                    533: #endif
                    534: {
1.21      cvs       535:   HTList             *cur;
                    536:   AHTReqContext      *me;
                    537:   AHTDocId_Status    *docid_status;
                    538: 
1.74      cvs       539:   if (Amaya && Amaya->reqlist)
                    540:     {
                    541:       if (Amaya->open_requests > 0)
                    542: #ifdef DEBUG_LIBWWW
                    543:       fprintf (stderr, "Thread_deleteAll: Killing %d outstanding "
                    544:                       "requests\n", Amaya->open_requests);
                    545: #endif   
                    546:        {
                    547:          cur = Amaya->reqlist;
                    548:          
                    549:          /* erase the requests */
                    550:          while ((me = (AHTReqContext *) HTList_removeLastObject (cur)))
                    551:            {
                    552:              if (me->request)
                    553:                {
1.142     cvs       554: #ifndef _WINDOWS
                    555: #ifdef WWW_XWINDOWS 
1.74      cvs       556:                  RequestKillAllXtevents (me);
1.142     cvs       557: #endif /* WWW_XWINDOWS */
1.138     cvs       558: #endif /* !_WINDOWS */
1.140     cvs       559:                  if (!HTRequest_kill (me->request))
                    560:                    AHTReqContext_delete (me);
1.74      cvs       561:                }
                    562:            }           /* while */
                    563:          
                    564:          /* erase the docid_status entities */
                    565:          while ((docid_status = (AHTDocId_Status *) HTList_removeLastObject ((void *) Amaya->docid_status)))
                    566:            TtaFreeMemory ((void *) docid_status);
                    567:          
                    568:        }                       /* if */
1.84      cvs       569:        
1.74      cvs       570:     }
1.4       cvs       571: }
1.198     cvs       572:  
1.5       cvs       573: /*----------------------------------------------------------------------
1.83      cvs       574:   AHTOpen_file
                    575:   ----------------------------------------------------------------------*/
                    576: #ifdef __STDC__
1.85      cvs       577: int                 AHTOpen_file (HTRequest * request)
1.83      cvs       578: #else
1.85      cvs       579: int                 AHTOpen_file (request)
1.83      cvs       580: HTRequest           *request;
                    581: 
                    582: #endif /* __STDC__ */
                    583: {
                    584:   AHTReqContext      *me;      /* current request */
                    585: 
                    586:   me = HTRequest_context (request);
                    587: 
1.93      cvs       588:   if (!me)
                    589:       return HT_ERROR;
                    590: 
1.83      cvs       591: #ifdef DEBUG_LIBWWW
1.116     cvs       592:   fprintf(stderr, "AHTOpen_file: start for object : %p\n", me);
1.85      cvs       593: #endif /* DEBUG_LIBWWW */
                    594: 
                    595:   if (me->reqStatus == HT_ABORT) 
                    596:     {
                    597: #ifdef DEBUG_LIBWWW
                    598:       fprintf(stderr, "AHTOpen_file: caught an abort request, skipping it\n");
1.83      cvs       599: #endif /* DEBUG_LIBWWW */
                    600: 
1.85      cvs       601:       return HT_OK;
                    602:     }
                    603: 
1.136     cvs       604:   if (me->method == METHOD_PUT)
                    605:     {
                    606:       me->reqStatus = HT_WAITING;
                    607:       return HT_OK;
                    608:     }
                    609: 
1.85      cvs       610:   if (HTRequest_outputStream (me->request)) 
                    611:     {
                    612: 
                    613: #ifdef DEBUG_LIBWWW
                    614:       fprintf(stderr, "AHTOpen_file: output stream already existed for url %s\n", me->urlName);
                    615: #endif /* DEBUG_LIBWWW */      
                    616:       return HT_OK;
                    617:     }
                    618: 
                    619: #ifdef DEBUG_LIBWWW
                    620:       fprintf(stderr, "AHTOpen_file: opening output stream for url %s\n", me->urlName);
                    621: #endif /* DEBUG_LIBWWW */      
                    622: 
1.83      cvs       623:   if (!(me->output) && 
                    624:       (me->output != stdout) && 
                    625: #ifndef _WINDOWS
                    626:       (me->output = fopen (me->outputfile, "w")) == NULL)
                    627:     {
1.116     cvs       628: #else /* !_WINDOWS */
1.83      cvs       629:     (me->output = fopen (me->outputfile, "wb")) == NULL) 
                    630:     {
                    631: #endif /* !_WINDOWS */
                    632: 
1.131     cvs       633:       me->outputfile[0] = EOS; /* file could not be opened */
1.85      cvs       634: #ifdef DEBUG_LIBWWW
                    635:       fprintf(stderr, "AHTOpen_file: couldn't open output stream for url %s\n", me->urlName);
                    636: #endif
1.83      cvs       637:       TtaSetStatus (me->docid, 1, 
                    638:                    TtaGetMessage (AMAYA, AM_CANNOT_CREATE_FILE),
1.198     cvs       639:                    ISO2WideChar (me->outputfile));
1.83      cvs       640:       me->reqStatus = HT_ERR;
                    641:       return (HT_ERROR);
                    642:     }
                    643:          
                    644:   HTRequest_setOutputStream (me->request,
                    645:                             AHTFWriter_new (me->request, 
                    646:                                             me->output, YES));
                    647:   me->reqStatus = HT_WAITING;
                    648:   
                    649:   return HT_OK;
                    650: }
                    651: 
                    652: /*----------------------------------------------------------------------
1.17      cvs       653:   redirection_handler
                    654:   this function is registered to handle permanent and temporary
                    655:   redirections.
                    656:   ----------------------------------------------------------------------*/
1.4       cvs       657: #ifdef __STDC__
1.7       cvs       658: static int          redirection_handler (HTRequest * request, HTResponse * response, void *param, int status)
1.4       cvs       659: #else
                    660: static int          redirection_handler (request, context, status)
                    661: HTRequest          *request;
                    662: HTResponse         *response;
                    663: void               *param;
                    664: int                 status;
                    665: 
                    666: #endif
                    667: {
                    668: 
                    669:    HTAnchor           *new_anchor = HTResponse_redirection (response);
1.7       cvs       670:    AHTReqContext      *me = HTRequest_context (request);
1.4       cvs       671:    HTMethod            method = HTRequest_method (request);
1.198     cvs       672:    STRING              ref;
1.206     cvs       673:    STRING              escape_src, dst;
1.98      cvs       674:    char               *tmp;
1.4       cvs       675: 
1.153     cvs       676:    if (!me)
                    677:      /* if the redirect doesn't come from Amaya, we call libwww's standard
                    678:        redirect filter */
                    679:      return (HTRedirectFilter (request, response, param, status));
                    680: 
1.7       cvs       681:    if (!new_anchor)
                    682:      {
                    683:        if (PROT_TRACE)
                    684:           HTTrace ("Redirection. No destination\n");
                    685:        return HT_OK;
                    686:      }
1.4       cvs       687: 
                    688:    /*
1.207     cvs       689:    ** Only do redirect on GET, HEAD, and authorized domains for PUT
1.4       cvs       690:     */
1.207     cvs       691:    if ((me->method == METHOD_PUT && !SafePut_query (me->urlName))
                    692:        || (me->method != METHOD_PUT && !HTMethod_isSafe (method)))
1.7       cvs       693:      {
1.130     cvs       694:        /*
                    695:        ** If we got a 303 See Other then change the method to GET.
                    696:        ** Otherwise ask the user whether we should continue.
                    697:        */
                    698:        if (status == HT_SEE_OTHER) 
                    699:         {
                    700:           if (PROT_TRACE)
                    701:             HTTrace("Redirection. Changing method from %s to GET\n",
                    702:                     HTMethod_name(method));
                    703:           HTRequest_setMethod(request, METHOD_GET);
                    704:         }
                    705:        else 
                    706:         {
                    707:           HTAlertCallback    *prompt = HTAlert_find (HT_A_CONFIRM);
                    708:           if (prompt)
                    709:             {
                    710:               if ((*prompt) (request, HT_A_CONFIRM, HT_MSG_REDIRECTION,
                    711:                              NULL, NULL, NULL) != YES)
1.153     cvs       712:                 return HT_OK;
1.130     cvs       713:             }
                    714:         }
1.7       cvs       715:      }
1.4       cvs       716:    /*
                    717:     **  Start new request with the redirect anchor found in the headers.
                    718:     **  Note that we reuse the same request object which means that we must
                    719:     **  keep this around until the redirected request has terminated. It also           
                    720:     **  allows us in an easy way to keep track of the number of redirections
                    721:     **  so that we can detect endless loops.
                    722:     */
1.166     cvs       723: 
1.7       cvs       724:    if (HTRequest_doRetry (request))
                    725:      {
1.174     cvs       726:        /*
                    727:        ** Start request with new credentials 
                    728:        */
                    729: 
1.166     cvs       730:        /* only do a redirect using a network protocol understood by Amaya */
1.198     cvs       731:        if (IsValidProtocol (ISO2WideChar (new_anchor->parent->address)))
1.7       cvs       732:          {
1.166     cvs       733:            /* if it's a valid URL, we try to normalize it */
1.206     cvs       734:            /* We use the pre-redirection anchor as a base name */
                    735:            dst = ISO2WideChar (new_anchor->parent->address);
                    736:            escape_src = EscapeURL (ISO2WideChar (me->urlName));
                    737:            if (escape_src)
                    738:              {
                    739:                ref = AmayaParseUrl (dst, escape_src, AMAYA_PARSE_ALL);
                    740:                TtaFreeMemory (escape_src);
                    741:              }
                    742:            else
                    743:              ref = NULL;
                    744: 
1.7       cvs       745:             if (ref)
                    746:               {
1.98      cvs       747:                 HT_FREE (new_anchor->parent->address);
1.217     cvs       748:                 new_anchor->parent->address = NULL;
1.98      cvs       749:                 tmp = NULL;
1.198     cvs       750:                 HTSACopy (&tmp, WideChar2ISO (ref));
1.98      cvs       751:                 new_anchor->parent->address = tmp;
                    752:                 TtaFreeMemory (ref);
1.7       cvs       753:               }
1.98      cvs       754:             else
1.166     cvs       755:               return HT_OK; /* We can't redirect anymore */
1.7       cvs       756:          }
1.166     cvs       757:        else
                    758:          return HT_OK; /* We can't redirect anymore */
1.7       cvs       759: 
                    760:        /* update the current file name */
1.206     cvs       761:        if ((me->mode & AMAYA_ASYNC) 
                    762:            || (me->mode & AMAYA_IASYNC)
                    763:            || (me->method == METHOD_PUT)) 
1.7       cvs       764:          {
1.130     cvs       765:            TtaFreeMemory (me->urlName);
1.223     cvs       766:            me->urlName = TtaStrdup (new_anchor->parent->address);
1.7       cvs       767:          }
                    768:        else
1.130     cvs       769:          /* it's a SYNC mode, so we should keep the urlName */
                    770:          {
                    771:            strncpy (me->urlName, new_anchor->parent->address, 
                    772:                     MAX_LENGTH - 1);
                    773:            me->urlName[MAX_LENGTH - 1] = EOS;
                    774:          }
1.38      cvs       775:        ChopURL (me->status_urlName, me->urlName);
1.116     cvs       776: 
1.190     cvs       777:        /* @@ verify if this is important */
                    778:        /* @@@ new libwww doesn't need this free stream while making
                    779:           a PUT. Is it the case everywhere or just for PUT? */
                    780:        if (me->method != METHOD_PUT 
1.192     cvs       781:            && me->request->orig_output_stream != NULL) 
                    782:          {
                    783:            AHTFWriter_FREE (me->request->orig_output_stream);
                    784:            me->request->orig_output_stream = NULL;
                    785:            if (me->output != stdout) { /* Are we writing to a file? */
1.74      cvs       786: #ifdef DEBUG_LIBWWW
1.192     cvs       787:              fprintf (stderr, "redirection_handler: New URL is  %s, closing "
                    788:                       "FILE %p\n", me->urlName, me->output); 
1.74      cvs       789: #endif 
1.192     cvs       790:              fclose (me->output);
                    791:              me->output = NULL;
                    792:            }
1.79      cvs       793:          }
1.68      cvs       794: 
1.174     cvs       795:        /* tell the user what we're doing */
                    796:        TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_RED_FETCHING),
1.198     cvs       797:                      ISO2WideChar (me->status_urlName));
1.174     cvs       798: 
                    799: 
1.171     cvs       800:        /*
                    801:        ** launch the request
                    802:        */
1.192     cvs       803:        /* add a link relationship? */
1.174     cvs       804:        /* reset the request status */
1.116     cvs       805:        me->reqStatus = HT_NEW; 
1.105     cvs       806:        /* clear the errors */
1.116     cvs       807:        HTError_deleteAll (HTRequest_error (request));
1.105     cvs       808:        HTRequest_setError (request, NULL);
1.192     cvs       809:        /* clear the authentication credentials, as they get regenerated  */
1.174     cvs       810:        HTRequest_deleteCredentialsAll (request);
                    811:        
1.171     cvs       812:        if (me->method == METHOD_POST 
                    813:          || me->method == METHOD_PUT)  /* PUT, POST etc. */
                    814:        status = HTLoadAbsolute (me->urlName, request);
1.7       cvs       815:        else
1.74      cvs       816:          HTLoadAnchor (new_anchor, request);
1.7       cvs       817:      }
                    818:    else
1.68      cvs       819:      {
1.74      cvs       820:        HTRequest_addError (request, ERR_FATAL, NO, HTERR_MAX_REDIRECT,
                    821:                           NULL, 0, "HTRedirectFilter");
                    822:        TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REDIRECTIONS_LIMIT),
                    823:                     NULL);
1.173     cvs       824:        /* so that we can show the error message */
1.74      cvs       825:        if (me->error_html)
1.173     cvs       826:         DocNetworkStatus[me->docid] |= AMAYA_NET_ERROR;
                    827:        me->reqStatus = HT_ERR;
1.68      cvs       828:      }
                    829: 
1.4       cvs       830:    /*
1.74      cvs       831:    **  By returning HT_ERROR we make sure that this is the last handler to be
                    832:    **  called. We do this as we don't want any other filter to delete the 
                    833:    **  request object now when we have just started a new one ourselves
                    834:    */
1.4       cvs       835:    return HT_ERROR;
                    836: }
                    837: 
1.151     cvs       838: #ifdef AMAYA_LOST_UPDATE
                    839: /*----------------------------------------------------------------------
                    840:   precondition_handler
                    841:   412 "Precondition failed" handler
                    842:   ----------------------------------------------------------------------*/
                    843: #if __STDC__
                    844: static int          precondition_handler (HTRequest * request, HTResponse * response, void *context, int status)
                    845: #else
                    846: static int          precondition_handler (request, response, context, status)
                    847: HTRequest          *request;
                    848: HTResponse         *response;
                    849: void               *context;
                    850: int                 status;
                    851: #endif /* __STDC__ */
                    852: {
1.168     cvs       853:   AHTReqContext  *me = (AHTReqContext *) HTRequest_context (request);
                    854:   HTAlertCallback    *prompt = HTAlert_find (HT_A_CONFIRM);
1.191     cvs       855:   ThotBool force_put;
1.151     cvs       856: 
                    857:   if (!me)
                    858:     return HT_OK;              /* not an Amaya request */
                    859: 
1.168     cvs       860:   if (prompt)
                    861:        force_put = (*prompt) (request, HT_A_CONFIRM,  HT_MSG_RULES,
                    862:                              NULL, NULL, NULL);
                    863:   else
                    864:     force_put = NO;
                    865:   
                    866:   if (force_put)
                    867:     {
                    868:       /* start a new PUT request without preconditions */
                    869:       /* @@ do we need to kill the request? */
                    870:       if (me->output && me->output != stdout)
                    871:        {
                    872:          fclose (me->output);
                    873:          me->output = NULL;
                    874:        }
                    875:       /*
                    876:       ** reset the Amaya and libwww request status 
                    877:       */
1.176     cvs       878: 
                    879:       /* start with a new, clean request structure */
                    880:       HTRequest_delete (me->request);
                    881:       me->request = HTRequest_new ();
                    882:       /* clean the associated file structure) */
                    883:       HTRequest_setOutputStream (me->request, NULL);
                    884:       /* Initialize the other members of the structure */
1.171     cvs       885:       HTRequest_setMethod (me->request, METHOD_GET);
1.176     cvs       886:       HTRequest_setOutputFormat (me->request, WWW_SOURCE);
                    887:       HTRequest_setContext (me->request, me);
                    888:       HTRequest_setPreemptive (me->request, NO);
                    889:       /*
                    890:       ** Make sure that the first request is flushed immediately and not
                    891:       ** buffered in the output buffer
                    892:       */
                    893:       if (me->mode & AMAYA_FLUSH_REQUEST)
                    894:        HTRequest_setFlush(me->request, YES);
                    895: 
1.171     cvs       896:       /* turn off preconditions */
                    897:       HTRequest_setPreconditions(me->request, HT_NO_MATCH);
                    898:       me->reqStatus = HT_NEW; 
                    899:       /* make the request */      
1.176     cvs       900:       status = HTPutDocumentAnchor (HTAnchor_parent (me->source), 
                    901:                                    me->dest, me->request);
1.168     cvs       902:       /* stop here */
                    903:       return HT_ERROR;
                    904:     }
                    905:   else
                    906:     {
                    907:       /* abort the request */
                    908:       /* @@ should we call StopRequest here? */
                    909:       me->reqStatus = HT_ABORT;
                    910:       /* stop here */
                    911:       return HT_ERROR; 
                    912:     }
                    913: }
1.151     cvs       914: 
1.168     cvs       915: /*----------------------------------------------------------------------
                    916:   check_handler
                    917:   Request HEAD checker filter
                    918:   ----------------------------------------------------------------------*/
                    919: static int check_handler (HTRequest * request, HTResponse * response,
1.151     cvs       920:                            void * param, int status)
                    921: {
1.168     cvs       922:   AHTReqContext  *me = (AHTReqContext *) HTRequest_context (request);
                    923:   HTAlertCallback    *prompt = HTAlert_find (HT_A_CONFIRM);
1.191     cvs       924:   ThotBool force_put;
1.168     cvs       925: 
                    926:   if (!me)
                    927:     return HT_OK;              /* not an Amaya request */
                    928: 
                    929:   HTRequest_deleteAfter(me->request, check_handler);
                    930:   /*
                    931:   ** If head request showed that the document doesn't exist
                    932:   ** then just go ahead and PUT it. Otherwise ask for help
                    933:   */
                    934:   if (status == HT_ERROR || status == HT_INTERRUPTED || status == HT_TIMEOUT)
                    935:     {
                    936:       /* we'd need to call terminate_handler, to free the resources */
                    937:       /* abort the request */
                    938:       /* @@ should we call StopRequest here? */
                    939:       me->reqStatus = HT_ABORT;
                    940:       /* stop here */
                    941:       return HT_ERROR; 
                    942:     } 
                    943:   else if (status == HT_NO_ACCESS || status == HT_NO_PROXY_ACCESS) 
                    944:     {
                    945:       /* we'd need to call terminate_handler, to free the resources */
                    946:       /* abort the request */
                    947:       /* @@ should we call StopRequest here? */
                    948:       me->reqStatus = HT_ABORT;
                    949:       /* stop here */
                    950:       return HT_ERROR; 
                    951:     }
                    952:   else if ( (abs(status)/100) != 2) 
                    953:     {
1.176     cvs       954:       /* start with a new, clean request structure */
                    955:       HTRequest_delete (me->request);
                    956:       me->request = HTRequest_new ();
1.208     cvs       957:       /* add the default PUT name */
                    958:       HTRequest_setDefaultPutName (me->request, me->default_put_name);
1.176     cvs       959:       /* clean the associated file structure) */
                    960:       HTRequest_setOutputStream (me->request, NULL);
                    961:       /* Initialize the other members of the structure */
1.171     cvs       962:       HTRequest_setMethod (me->request, METHOD_GET);
1.176     cvs       963:       HTRequest_setOutputFormat (me->request, WWW_SOURCE);
                    964:       HTRequest_setContext (me->request, me);
                    965:       HTRequest_setPreemptive (me->request, NO);
                    966:       /*
                    967:       ** Make sure that the first request is flushed immediately and not
                    968:       ** buffered in the output buffer
                    969:       */
                    970:       if (me->mode & AMAYA_FLUSH_REQUEST)
                    971:        HTRequest_setFlush(me->request, YES);
                    972: 
                    973:       /* turn on the special preconditions, to avoid having this
                    974:         ressource appear before we do the PUT */
1.168     cvs       975:       HTRequest_setPreconditions(me->request, HT_DONT_MATCH_ANY);
1.171     cvs       976:       me->reqStatus = HT_NEW;
1.168     cvs       977:       status = HTPutDocumentAnchor (HTAnchor_parent (me->source), me->dest, me->request);
                    978:       return HT_ERROR; /* stop here */
1.176     cvs       979:     }
1.168     cvs       980:   else 
                    981:     {
                    982:       if (prompt)
                    983:          force_put = (*prompt) (request, HT_A_CONFIRM, HT_MSG_FILE_REPLACE,
                    984:                                 NULL, NULL, NULL);
                    985:       else
                    986:        force_put = FALSE;
                    987: 
                    988:       if (force_put)
1.151     cvs       989:        {
                    990:          /* Start a new PUT request without preconditions */
1.176     cvs       991: 
                    992:          /* get a new, clean request structure */
                    993:          HTRequest_delete (me->request);
                    994:          me->request = HTRequest_new ();
1.208     cvs       995:          /* add the default PUT name */
                    996:          HTRequest_setDefaultPutName (me->request, me->default_put_name);
1.176     cvs       997:          /* clean the associated file structure) */
                    998:          HTRequest_setOutputStream (me->request, NULL);
                    999:          /* Initialize the other members of the structure */
1.171     cvs      1000:          HTRequest_setMethod (me->request, METHOD_GET);
1.176     cvs      1001:          HTRequest_setOutputFormat (me->request, WWW_SOURCE);
                   1002:          HTRequest_setContext (me->request, me);
                   1003:          HTRequest_setPreemptive (me->request, NO);
                   1004:          /*
                   1005:          ** Make sure that the first request is flushed immediately and not
                   1006:          ** buffered in the output buffer
                   1007:          */
                   1008:          if (me->mode & AMAYA_FLUSH_REQUEST)
                   1009:            HTRequest_setFlush(me->request, YES);
                   1010:          /* remove the preconditions */
1.168     cvs      1011:          HTRequest_setPreconditions(me->request, HT_NO_MATCH);
1.171     cvs      1012:          me->reqStatus = HT_NEW; 
1.176     cvs      1013:          status = HTPutDocumentAnchor (HTAnchor_parent (me->source), 
                   1014:                                        me->dest, me->request);
1.168     cvs      1015:          return HT_ERROR; /* stop here */
1.151     cvs      1016:        } 
1.168     cvs      1017:       else
                   1018:        {
                   1019:          /* we'd need to call terminate_handler, to free the resources */
                   1020:          /* abort the request */
                   1021:          /* @@ should we call StopRequest here? */
                   1022:          me->reqStatus = HT_ABORT;
                   1023:          /* stop here */
                   1024:          return HT_ERROR; 
                   1025:        }
                   1026:     }
                   1027:   return HT_ERROR;
1.151     cvs      1028: }
                   1029: #endif /* AMAYA_LOST_UPDATE */
                   1030: 
1.5       cvs      1031: /*----------------------------------------------------------------------
1.17      cvs      1032:   terminate_handler
                   1033:   this function is registered to handle the result of the request
1.5       cvs      1034:   ----------------------------------------------------------------------*/
1.4       cvs      1035: #if __STDC__
1.7       cvs      1036: static int          terminate_handler (HTRequest * request, HTResponse * response, void *context, int status)
1.4       cvs      1037: #else
                   1038: static int          terminate_handler (request, response, context, status)
                   1039: HTRequest          *request;
                   1040: HTResponse         *response;
                   1041: void               *context;
                   1042: int                 status;
1.123     cvs      1043: #endif /* __STDC__ */
1.4       cvs      1044: {
1.116     cvs      1045:   AHTReqContext      *me = (AHTReqContext *) HTRequest_context (request);
1.191     cvs      1046:   ThotBool            error_flag;
1.116     cvs      1047:   char               *content_type;
1.184     cvs      1048:   HTParentAnchor     *anchor;
1.116     cvs      1049: 
                   1050:   if (!me)
1.214     cvs      1051:      return HT_ERROR;          /* not an Amaya request */
1.116     cvs      1052: 
                   1053:   if (me->reqStatus == HT_END)
                   1054:     /* we have already processed this request! */
                   1055:     return HT_OK;
                   1056: 
                   1057:   /* if Amaya was killed, treat with this request as if it were
                   1058:      issued by a Stop button event */
                   1059: 
                   1060:    if (!AmayaIsAlive ())           
1.80      cvs      1061:       me->reqStatus = HT_ABORT; 
1.220     cvs      1062: 
                   1063:    /* trying to protect against this problem... hard to place
                   1064:       the detection elsewhere :-/ */
                   1065:    if (IsHTTP09Error (request))
                   1066:      status = -1;
                   1067: 
1.77      cvs      1068:    if (status == HT_LOADED || 
                   1069:        status == HT_CREATED || 
1.79      cvs      1070:        status == HT_NO_DATA ||
1.160     cvs      1071:        /* kludge for work around libwww problem */
                   1072:        (status == HT_INTERRUPTED && me->method == METHOD_PUT) ||
1.116     cvs      1073: #ifdef AMAYA_WWW_CACHE
                   1074:        /* what status to use to know we're downloading from a cache? */
                   1075:        status ==  HT_NOT_MODIFIED ||
                   1076: #endif /* AMAYA_WWW_CACHE */
1.79      cvs      1077:        me->reqStatus == HT_ABORT)
1.74      cvs      1078:      error_flag = FALSE;
1.220     cvs      1079:      else
1.74      cvs      1080:      error_flag = TRUE;
1.130     cvs      1081: 
1.4       cvs      1082:    /* output any errors from the server */
1.130     cvs      1083: 
1.77      cvs      1084:    /*
1.74      cvs      1085:    ** me->output = output file which will receive an html file
                   1086:    ** me->error_html = yes, output HTML errors in the screen
                   1087:    ** request->error_stack == if there are any errors, they will be here
                   1088:    ** me->error_stream_size If it's != 0 means an error message has already
                   1089:    **                       been written to the stack
                   1090:    */
                   1091:    
1.4       cvs      1092:    /* First, we verify if there are any errors and if they are not
1.17      cvs      1093:    ** yet written to the error stack. If no, then let's try to write them
                   1094:    ** ourselves
                   1095:    */
1.74      cvs      1096:    
                   1097: #ifdef DEBUG_LIBWWW
                   1098:    fprintf (stderr, "terminate_handler: URL is "
                   1099:            "%s, closing FILE %p status is %d\n", me->urlName, me->output, 
                   1100:            status); 
1.69      cvs      1101: #endif
1.74      cvs      1102:    
1.69      cvs      1103:    if (me->output && me->output != stdout)
                   1104:      {
1.214     cvs      1105:        /* we are writing to a local file */
1.74      cvs      1106:        if (me->reqStatus != HT_ABORT)
                   1107:         {                      /* if the request was not aborted and */
1.80      cvs      1108:           if (error_flag &&
                   1109:               me->error_html == TRUE)
                   1110:               /* there were some errors and we want to print them */
                   1111:             {          
                   1112:               if (me->error_stream_size == 0)/* and the stream is empty */
1.210     cvs      1113:                 {
                   1114:                   /* if the transfer was interrupted, the file may not be
                   1115:                      empty. So, we erase it */
                   1116:                   fflush (me->output);
                   1117:                   rewind (me->output);
                   1118:                   AHTError_MemPrint (request); /* copy errors from 
                   1119:                                                **the error stack 
                   1120:                                                ** into the error stream */
                   1121:                 }
1.80      cvs      1122:               if (me->error_stream)
                   1123:                 {      /* if the stream is non-empty */
                   1124:                   fprintf (me->output, me->error_stream);/* output the errors */
1.85      cvs      1125:                   /* Clear the error context, so that we can deal with
                   1126:                      this answer as if it were a normal reply */
                   1127:                    HTError_deleteAll( HTRequest_error (request));
                   1128:                    HTRequest_setError (request, NULL);
                   1129:                    error_flag = 0;
1.74      cvs      1130:                 }
                   1131:             }                  /* if error_stack */
1.85      cvs      1132:         }
                   1133: 
                   1134:        /* if != HT_ABORT */
                   1135:        
                   1136: #ifdef DEBUG_LIBWWW       
                   1137:        fprintf (stderr, "terminate_handler: URL is  %s, closing "
                   1138:                "FILE %p\n", me->urlName, me->output); 
                   1139: #endif
1.74      cvs      1140:        fclose (me->output);
                   1141:        me->output = NULL;
1.69      cvs      1142:      }
1.80      cvs      1143: 
1.214     cvs      1144:    /* a very special handling so that we can put a message box
                   1145:       to tell the user WHAT he has just done... */
                   1146:    if (UserAborted_flag && me->method == METHOD_PUT)
                   1147:      {
                   1148:        HTRequest_addError (request, ERR_FATAL, NO, HTERR_INTERRUPTED,
                   1149:                           "Operation aborted by user", 0, NULL);
                   1150:      }
                   1151: 
1.80      cvs      1152:    if (error_flag)
                   1153:      me->reqStatus = HT_ERR;
1.214     cvs      1154:    else 
                   1155:      if (me->reqStatus != HT_ABORT)
                   1156:        me->reqStatus = HT_END;
                   1157:    
1.116     cvs      1158:    /* copy the content_type */
1.151     cvs      1159:    if (!me->content_type)
1.88      cvs      1160:      {
1.184     cvs      1161:        anchor = HTRequest_anchor (request);
                   1162:        if (anchor && HTAnchor_format (anchor))
                   1163:         content_type = HTAtom_name (HTAnchor_format (anchor));
1.154     cvs      1164:        else
                   1165:         content_type = "www/unknown";
                   1166: 
1.151     cvs      1167:        if (content_type && content_type [0] != EOS)
                   1168:         {
                   1169:           /* libwww gives www/unknown when it gets an error. As this is 
                   1170:              an HTML test, we force the type to text/html */
                   1171:           if (!strcmp (content_type, "www/unknown"))
1.223     cvs      1172:             me->content_type = TtaStrdup ("text/html");
1.151     cvs      1173:           else
1.223     cvs      1174:             me->content_type = TtaStrdup (content_type);
1.151     cvs      1175:           
                   1176:           /* Content-Type can be specified by an httpd  server's admin.
                   1177:              To be on the safe side, we normalize its case */
1.198     cvs      1178:           ConvertToLowerCase (ISO2WideChar (me->content_type));
1.151     cvs      1179:           
1.88      cvs      1180: #ifdef DEBUG_LIBWWW
1.151     cvs      1181:           fprintf (stderr, "content type is: %s\n", me->content_type);
1.88      cvs      1182: #endif /* DEBUG_LIBWWW */
1.151     cvs      1183:         } 
                   1184:      }
1.114     cvs      1185: 
1.115     cvs      1186:    /* to avoid a hangup while downloading css files */
1.140     cvs      1187:    if (AmayaAlive_flag && (me->mode & AMAYA_LOAD_CSS))
1.116     cvs      1188:      TtaSetStatus (me->docid, 1, 
                   1189:                   TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
1.198     cvs      1190:                   ISO2WideChar (me->status_urlName));
1.116     cvs      1191:    
                   1192:   /* don't remove or Xt will hang up during the PUT */
                   1193:    if (AmayaIsAlive ()  && ((me->method == METHOD_POST) ||
                   1194:                            (me->method == METHOD_PUT)))
1.7       cvs      1195:      {
1.80      cvs      1196:        PrintTerminateStatus (me, status);
                   1197:      } 
1.114     cvs      1198: 
1.111     cvs      1199:    ProcessTerminateRequest (request, response, context, status);
1.116     cvs      1200:    
1.151     cvs      1201:    /* stop here */
1.150     cvs      1202:    return HT_ERROR;
1.4       cvs      1203: }
                   1204: 
1.5       cvs      1205: /*----------------------------------------------------------------------
1.17      cvs      1206:   AHTLoadTerminate_handler
1.74      cvs      1207:   this is an application "AFTER" Callback. It's called by the library
                   1208:   when a request has ended, so that we can setup the correct status.
1.5       cvs      1209:   ----------------------------------------------------------------------*/
1.4       cvs      1210: 
                   1211: #ifdef __STDC__
1.111     cvs      1212: int          AHTLoadTerminate_handler (HTRequest * request, HTResponse * response, void *param, int status)
1.4       cvs      1213: #else
1.111     cvs      1214: int          AHTLoadTerminate_handler (request, response, param, status)
1.4       cvs      1215: HTRequest          *request;
                   1216: HTResponse         *response;
                   1217: void               *param;
                   1218: int                 status;
1.69      cvs      1219: 
1.4       cvs      1220: #endif
                   1221: {
1.116     cvs      1222: 
                   1223:   /** @@@@ use this with printstatus ?? */
                   1224: 
1.4       cvs      1225:    AHTReqContext      *me = HTRequest_context (request);
                   1226:    HTAlertCallback    *cbf;
                   1227:    AHTDocId_Status    *docid_status;
                   1228: 
1.7       cvs      1229:    switch (status)
1.116     cvs      1230:      {
                   1231:         case HT_LOADED:
                   1232:           if (PROT_TRACE)
                   1233:             HTTrace ("Load End.... OK: `%s\' has been accessed\n",
                   1234:                      me->status_urlName);
1.4       cvs      1235: 
1.116     cvs      1236:           docid_status = GetDocIdStatus (me->docid,
                   1237:                                          Amaya->docid_status);
1.7       cvs      1238: 
1.116     cvs      1239:           if (docid_status != NULL && docid_status->counter > 1)
                   1240:             TtaSetStatus (me->docid, 1, 
                   1241:                           TtaGetMessage (AMAYA, AM_ELEMENT_LOADED),
1.198     cvs      1242:                           ISO2WideChar (me->status_urlName));
1.7       cvs      1243:               break;
1.116     cvs      1244:               
                   1245:      case HT_NO_DATA:
                   1246:        if (PROT_TRACE)
                   1247:         HTTrace ("Load End.... OK BUT NO DATA: `%s\'\n", 
                   1248:                  me->status_urlName);
                   1249:        TtaSetStatus (me->docid, 1, 
                   1250:                     TtaGetMessage (AMAYA, AM_LOADED_NO_DATA),
1.198     cvs      1251:                     ISO2WideChar (me->status_urlName));
1.116     cvs      1252:        break;
                   1253:        
                   1254:      case HT_INTERRUPTED:
                   1255:        if (PROT_TRACE)
                   1256:         HTTrace ("Load End.... INTERRUPTED: `%s\'\n", 
                   1257:                  me->status_urlName);
                   1258:        TtaSetStatus (me->docid, 1, 
                   1259:                     TtaGetMessage (AMAYA, AM_LOAD_ABORT), 
                   1260:                     NULL);
                   1261:        break;
1.7       cvs      1262: 
1.116     cvs      1263:      case HT_RETRY:
                   1264:        if (PROT_TRACE)
                   1265:         HTTrace ("Load End.... NOT AVAILABLE, RETRY AT %ld\n",
                   1266:                  HTResponse_retryTime (response));
                   1267:        TtaSetStatus (me->docid, 1, 
                   1268:                     TtaGetMessage (AMAYA, AM_NOT_AVAILABLE_RETRY),
1.198     cvs      1269:                     ISO2WideChar (me->status_urlName));
1.116     cvs      1270:        break;
1.7       cvs      1271: 
1.116     cvs      1272:      case HT_ERROR:
                   1273:        cbf = HTAlert_find (HT_A_MESSAGE);
                   1274:        if (cbf)
                   1275:         (*cbf) (request, HT_A_MESSAGE, HT_MSG_NULL, NULL,
                   1276:                 HTRequest_error (request), NULL);
                   1277:        break;
                   1278:        
                   1279:        if (PROT_TRACE)
                   1280:         HTTrace ("Load End.... ERROR: Can't access `%s\'\n",
                   1281:                  me->status_urlName ? me->status_urlName :"<UNKNOWN>");
                   1282:        TtaSetStatus (me->docid, 1,
                   1283:                     TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
1.198     cvs      1284:                     me->status_urlName ? ISO2WideChar (me->status_urlName) : TEXT("<UNKNOWN>"));
1.116     cvs      1285:        break;
                   1286:      default:
                   1287:        if (PROT_TRACE)
                   1288:         HTTrace ("Load End.... UNKNOWN RETURN CODE %d\n", status);
                   1289:        break;
                   1290:      }
                   1291:    
                   1292:    return HT_OK;
                   1293: }
1.7       cvs      1294: 
1.116     cvs      1295: #ifdef DEBUG_LIBWWW
                   1296: static  int LineTrace (const char * fmt, va_list pArgs)
                   1297: {
                   1298:     return (vfprintf(stderr, fmt, pArgs));
1.4       cvs      1299: }
1.116     cvs      1300: #endif DEBUG_LIBWWW
1.4       cvs      1301: 
1.27      cvs      1302: /*----------------------------------------------------------------------
                   1303:   AHTAcceptTypesInit
1.74      cvs      1304:   This function prepares the Accept header used by Amaya during
                   1305:   the HTTP content negotiation phase
1.27      cvs      1306:   ----------------------------------------------------------------------*/
                   1307: #ifdef __STDC__
                   1308: static void           AHTAcceptTypesInit (HTList *c)
                   1309: #else  /* __STDC__ */
                   1310: static void           AHTAcceptTypesInit (c)
                   1311: HTList             *c;
                   1312: #endif /* __STDC__ */
                   1313: {
1.223     cvs      1314:    if (c == (HTList *) NULL) 
1.27      cvs      1315:       return;
                   1316: 
1.223     cvs      1317:    /* define here all the mime types that Amaya can accept */
1.27      cvs      1318: 
1.223     cvs      1319:    HTConversion_add (c, "image/png",  "www/present", HTThroughLine, 1.0, 0.0, 0.0);
                   1320:    HTConversion_add (c, "image/jpeg", "www/present", HTThroughLine, 1.0, 0.0, 0.0);
                   1321:    HTConversion_add (c, "image/gif",  "www/present", HTThroughLine, 1.0, 0.0, 0.0);
                   1322:    HTConversion_add (c, "image/xbm",  "www/present", HTThroughLine, 1.0, 0.0, 0.0);
                   1323:    HTConversion_add (c, "image/xpm",  "www/present", HTThroughLine, 1.0, 0.0, 0.0);
1.183     cvs      1324: 
1.27      cvs      1325:    /* Define here the equivalences between MIME types and file extensions for
1.223     cvs      1326:       the types that Amaya can display */
1.27      cvs      1327: 
1.176     cvs      1328:    /* Initialize suffix bindings for local files */
                   1329:    HTBind_init();
                   1330: 
1.27      cvs      1331:    /* Register the default set of file suffix bindings */
                   1332:    HTFileInit ();
                   1333: 
                   1334:    /* Don't do any case distinction */
                   1335:    HTBind_caseSensitive (FALSE);
                   1336: }
1.4       cvs      1337: 
1.5       cvs      1338: /*----------------------------------------------------------------------
1.193     cvs      1339:   AHTAcceptLanguagesInit
                   1340:   This function prepares the Accept header used by Amaya during
                   1341:   the HTTP content negotiation phase
                   1342:   ----------------------------------------------------------------------*/
                   1343: #ifdef __STDC__
1.196     cvs      1344: static void         AHTAcceptLanguagesInit (HTList *c)
1.193     cvs      1345: #else  /* __STDC__ */
1.196     cvs      1346: static void         AHTAcceptLanguagesInit (c)
1.193     cvs      1347: HTList             *c;
                   1348: #endif /* __STDC__ */
                   1349: {
1.223     cvs      1350:   CharUnit*         ptr;
                   1351:   CharUnit*         lang_list;
                   1352:   char              s[3];
1.196     cvs      1353:   int               count, lg;
                   1354:   double            quality;
                   1355:   ThotBool          still;
1.193     cvs      1356: 
                   1357:   if (c == (HTList *) NULL) 
                   1358:       return;
                   1359:   
1.203     cvs      1360:   lang_list = TtaGetEnvString ("ACCEPT_LANGUAGES");
1.197     cvs      1361:   s[2] = EOS;
1.223     cvs      1362:   if (lang_list && *lang_list != CUS_EOS)
1.193     cvs      1363:     {
                   1364:       /* add the default language first  */
                   1365:       HTLanguage_add (c, "*", -1.0);
                   1366:       /* how many languages do we have? */
1.196     cvs      1367:       ptr = lang_list;
                   1368:       count = 0;
1.223     cvs      1369:       while (*ptr != CUS_EOS) {
                   1370:             while (*ptr != CUS_EOS && (*ptr < CUSTEXT('A') || (*ptr > CUSTEXT('Z') && *ptr < CUSTEXT('a')) || *ptr > CUSTEXT('z')))
                   1371:                   /* skip the whole separator */
                   1372:                   ptr++;
                   1373:             lg = 0;
                   1374:             while ((*ptr >= CUSTEXT('A') && *ptr <= CUSTEXT('Z')) || (*ptr >= CUSTEXT('a') && *ptr <= CUSTEXT('z')) || *ptr == CUSTEXT('-')) {
                   1375:                   /* it's a new language */
                   1376:                   ptr++;
                   1377:                   lg++;
                   1378:                        }
                   1379:             if (lg >= 2)
                   1380:                count++;
                   1381:             if (*ptr != CUS_EOS)
                   1382:                ptr++;
                   1383:          }
1.193     cvs      1384: 
1.196     cvs      1385:       if (count > 0)
1.223     cvs      1386:          quality = 1.1 - (double) count/10.0;
1.193     cvs      1387:       else
1.223     cvs      1388:           quality = 1.0;
1.193     cvs      1389: 
1.223     cvs      1390:      /* Read the languages from the registry, then inject them one, by one.
                   1391:         The first one is the one with the highest priority.
                   1392:         The libwww ask for the lowest priority first.
1.196     cvs      1393:       */
                   1394:       ptr--;
                   1395:       still = TRUE;
1.223     cvs      1396:       while (count) {
                   1397:             while (still && (*ptr < CUSTEXT('A') || (*ptr > CUSTEXT('Z') && *ptr < CUSTEXT('a')) || *ptr > CUSTEXT('z')))
                   1398:                   /* skip the whole separator */
                   1399:                   if (ptr > lang_list)
                   1400:                      ptr--;
                   1401:                   else
                   1402:                       still = FALSE;
                   1403:             lg = 0;
                   1404:             while (still && ((*ptr >= CUSTEXT('A') && *ptr <= CUSTEXT('Z')) || (*ptr >= CUSTEXT('a') && *ptr <= CUSTEXT('z')) || *ptr == CUSTEXT('-'))) {
                   1405:                   /* it's a new language */
                   1406:                   if (ptr > lang_list)
                   1407:                      ptr--;
                   1408:                   else
                   1409:                       still = FALSE;
                   1410:                   lg++;
                   1411:                        }
                   1412:             if (lg >= 2) {
                   1413:                if (still)
                   1414:                   cus2iso_strncpy  (s, &ptr[1], 2);
                   1415:                else
                   1416:                    cus2iso_strncpy (s, lang_list, 2);
                   1417:                count--;
                   1418:                HTLanguage_add (c, WideChar2ISO(s), quality);
                   1419:                quality += 0.1;
                   1420:                        }
                   1421:             ptr--;
                   1422:          }
                   1423:   }
1.193     cvs      1424: }
                   1425: 
                   1426: /*----------------------------------------------------------------------
1.17      cvs      1427:   AHTConverterInit
                   1428:   Bindings between a source media type and a destination media type
                   1429:   (conversion).
1.5       cvs      1430:   ----------------------------------------------------------------------*/
1.15      cvs      1431: #ifdef __STDC__
                   1432: static void         AHTConverterInit (HTList *c)
                   1433: #else  /* __STDC__ */
                   1434: static void         AHTConverterInit (c)
                   1435: HTList             *c;
                   1436: #endif /* __STDC__ */
1.4       cvs      1437: {
                   1438: 
                   1439:    /* Handler for custom http error messages */
1.7       cvs      1440:    HTConversion_add (c, "*/*", "www/debug", AHTMemConverter, 1.0, 0.0, 0.0);
1.4       cvs      1441: 
                   1442:    /*
                   1443:     ** These are converters that converts to something other than www/present,
                   1444:     ** that is not directly outputting someting to the user on the screen
                   1445:     */
                   1446: 
1.223     cvs      1447:    HTConversion_add (c, "message/rfc822", "*/*", HTMIMEConvert, 1.0, 0.0, 0.0);
                   1448:    HTConversion_add (c, "message/x-rfc822-foot", "*/*", HTMIMEFooter, 1.0, 0.0, 0.0);
                   1449:    HTConversion_add (c, "message/x-rfc822-head", "*/*", HTMIMEHeader, 1.0, 0.0, 0.0);
                   1450:    HTConversion_add(c,"message/x-rfc822-cont", "*/*", HTMIMEContinue, 1.0, 0.0, 0.0);
                   1451:    HTConversion_add(c,"message/x-rfc822-partial","*/*",        HTMIMEPartial, 1.0, 0.0, 0.0);
                   1452:    HTConversion_add (c, "multipart/*", "*/*", HTBoundary, 1.0, 0.0, 0.0);
                   1453:    HTConversion_add (c, "text/plain", "text/html", HTPlainToHTML, 1.0, 0.0, 0.0);
1.4       cvs      1454: 
                   1455:    /*
1.116     cvs      1456:    ** The following conversions are converting ASCII output from various
                   1457:    ** protocols to HTML objects.
                   1458:    */
1.223     cvs      1459:    HTConversion_add (c, "text/x-http", "*/*", HTTPStatus_new, 1.0, 0.0, 0.0);
1.4       cvs      1460: 
                   1461:    /*
1.116     cvs      1462:    ** We also register a special content type guess stream that can figure out
                   1463:    ** the content type by reading the first bytes of the stream
                   1464:    */
1.223     cvs      1465:    HTConversion_add (c, "www/unknown", "*/*", HTGuess_new, 1.0, 0.0, 0.0);
1.4       cvs      1466: 
1.116     cvs      1467: #ifdef AMAYA_WWW_CACHE
1.4       cvs      1468:    /*
1.116     cvs      1469:    ** Register a persistent cache stream which can save an object to local
                   1470:    ** file
                   1471:    */
1.223     cvs      1472:    HTConversion_add (c, "www/cache", "*/*", HTCacheWriter, 1.0, 0.0, 0.0);
                   1473:    HTConversion_add(c,"www/cache-append", "*/*", HTCacheAppend, 1.0, 0.0, 0.0);
1.116     cvs      1474: #endif AMAYA_WWW_CACHE
1.4       cvs      1475: 
                   1476:    /*
1.116     cvs      1477:    ** This dumps all other formats to local disk without any further
                   1478:    ** action taken
                   1479:    */
1.223     cvs      1480:    HTConversion_add (c, "*/*", "www/present", HTSaveLocally, 0.3, 0.0, 0.0);  
1.4       cvs      1481: }
                   1482: 
1.27      cvs      1483: 
1.15      cvs      1484: /*----------------------------------------------------------------------
1.17      cvs      1485:   AHTProtocolInit
                   1486:   Registers all amaya supported protocols.
1.15      cvs      1487:   ----------------------------------------------------------------------*/
1.4       cvs      1488: static void         AHTProtocolInit (void)
                   1489: {
1.223     cvs      1490:   CharUnit* strptr;
1.4       cvs      1491: 
1.116     cvs      1492:   /* 
                   1493:      NB. Preemptive == YES means Blocking requests
                   1494:      Non-preemptive == NO means Non-blocking requests
                   1495:      */
                   1496:   HTTransport_add("tcp", HT_TP_SINGLE, HTReader_new, HTWriter_new);
                   1497:   HTTransport_add("buffered_tcp", HT_TP_SINGLE, HTReader_new, 
                   1498:                  HTBufferWriter_new);
                   1499:   HTProtocol_add ("http", "buffered_tcp", HTTP_PORT, NO, HTLoadHTTP, NULL);
1.136     cvs      1500: #ifdef _WINDOWS
                   1501:   HTProtocol_add ("file", "local", 0, YES, HTLoadFile, NULL);
                   1502: #else
1.116     cvs      1503:   HTProtocol_add ("file", "local", 0, NO, HTLoadFile, NULL);
1.198     cvs      1504: #endif /* _WINDOWS */
1.116     cvs      1505: #ifdef AMAYA_WWW_CACHE
                   1506:    HTProtocol_add("cache",  "local", 0, YES, HTLoadCache, NULL);
                   1507: #endif /* AMAYA_WWW_CACHE */
1.103     cvs      1508: #if 0 /* experimental code */
1.116     cvs      1509:    HTProtocol_add ("ftp", "tcp", FTP_PORT, NO, HTLoadFTP, NULL);
1.17      cvs      1510: #endif
1.116     cvs      1511: 
                   1512:    /* initialize pipelining */
1.223     cvs      1513:   strptr = TtaGetEnvString ("ENABLE_PIPELINING");
                   1514:   if (strptr && *strptr && StringCaseCompare (strptr, CUSTEXT("yes")))
1.116     cvs      1515:     HTTP_setConnectionMode (HTTP_11_NO_PIPELINING);
1.4       cvs      1516: }
                   1517: 
1.15      cvs      1518: /*----------------------------------------------------------------------
1.17      cvs      1519:   AHTNetInit
                   1520:   Reegisters "before" and "after" request filters.
1.15      cvs      1521:   ----------------------------------------------------------------------*/
1.4       cvs      1522: static void         AHTNetInit (void)
                   1523: {
                   1524: 
                   1525: /*      Register BEFORE filters
1.74      cvs      1526: **      The BEFORE filters handle proxies, caches, rule files etc.
                   1527: **      The filters are called in the order by which the are registered
                   1528: **      Not done automaticly - may be done by application!
                   1529: */
1.4       cvs      1530: 
1.116     cvs      1531:   HTNet_addBefore (HTCredentialsFilter, "http://*", NULL, HT_FILTER_LATE);
                   1532:   HTNet_addBefore (HTProxyFilter, NULL, NULL, HT_FILTER_LATE);
1.85      cvs      1533:   HTHost_setActivateRequestCallback (AHTOpen_file);
1.4       cvs      1534: 
                   1535: /*      register AFTER filters
1.74      cvs      1536: **      The AFTER filters handle error messages, logging, redirection,
                   1537: **      authentication etc.
                   1538: **      The filters are called in the order by which the are registered
                   1539: **      Not done automaticly - may be done by application!
                   1540: */
1.4       cvs      1541: 
1.223     cvs      1542:   HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_NO_ACCESS, HT_FILTER_MIDDLE);
                   1543:   HTNet_addAfter (HTAuthFilter, "http://*", NULL, HT_REAUTH, HT_FILTER_MIDDLE);
                   1544:   HTNet_addAfter (redirection_handler, "http://*", NULL, HT_PERM_REDIRECT, HT_FILTER_MIDDLE);
                   1545:   HTNet_addAfter (redirection_handler, "http://*", NULL, HT_FOUND, HT_FILTER_MIDDLE);
                   1546:   HTNet_addAfter (redirection_handler, "http://*", NULL, HT_SEE_OTHER, HT_FILTER_MIDDLE);
                   1547:   HTNet_addAfter (redirection_handler, "http://*", NULL, HT_TEMP_REDIRECT, HT_FILTER_MIDDLE);
                   1548:   HTNet_addAfter (HTAuthInfoFilter,    "http://*", NULL, HT_ALL, HT_FILTER_MIDDLE);
                   1549:   HTNet_addAfter (HTUseProxyFilter, "http://*", NULL, HT_USE_PROXY, HT_FILTER_MIDDLE);
1.151     cvs      1550: #ifdef AMAYA_LOST_UPDATE
1.223     cvs      1551:   HTNet_addAfter (precondition_handler, NULL, NULL, HT_PRECONDITION_FAILED, HT_FILTER_MIDDLE);
1.151     cvs      1552: #endif /* AMAYA_LOST_UPDATE */
1.111     cvs      1553: #ifndef _WINDOWS
1.223     cvs      1554:   HTNet_addAfter (AHTLoadTerminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);       
1.111     cvs      1555: #endif /* !_WINDOWS */
1.116     cvs      1556:    /**** for later ?? ****/
                   1557:    /*  HTNet_addAfter(HTInfoFilter,    NULL,           NULL, HT_ALL,           HT_FILTER_LATE); */
1.51      cvs      1558:    /* handles all errors */
1.116     cvs      1559:   HTNet_addAfter (terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
1.4       cvs      1560: }
                   1561: 
1.15      cvs      1562: /*----------------------------------------------------------------------
1.17      cvs      1563:   AHTAlertInit
                   1564:   Register alert messages and their callbacks.
1.15      cvs      1565:   ----------------------------------------------------------------------*/
                   1566: #ifdef __STDC__
                   1567: static void         AHTAlertInit (void)
                   1568: #else
                   1569: static void         AHTAlertInit ()
                   1570: #endif
                   1571: {
                   1572:    HTAlert_add (AHTProgress, HT_A_PROGRESS);
1.120     cvs      1573: #ifdef __WINDOWS
1.70      cvs      1574:    HTAlert_add ((HTAlertCallback *) WIN_Activate_Request, HT_PROG_CONNECT);
1.116     cvs      1575: #endif /* _WINDOWS */
1.15      cvs      1576:    HTAlert_add (AHTError_print, HT_A_MESSAGE);
1.48      cvs      1577:    HTError_setShow (~((unsigned int) 0 ) & ~((unsigned int) HT_ERR_SHOW_DEBUG));       /* process all messages except debug ones*/
1.15      cvs      1578:    HTAlert_add (AHTConfirm, HT_A_CONFIRM);
                   1579:    HTAlert_add (AHTPrompt, HT_A_PROMPT);
                   1580:    HTAlert_add (AHTPromptUsernameAndPassword, HT_A_USER_PW);
1.116     cvs      1581: }
                   1582: 
1.128     cvs      1583: /*----------------------------------------------------------------------
                   1584:   libwww_CleanCache
                   1585:   frontend to the recursive cache cleaning function
                   1586:   ----------------------------------------------------------------------*/
                   1587: #ifdef __STDC__
                   1588: void libwww_CleanCache (void)
                   1589: #else
                   1590: void libwww_CleanCache ()
                   1591: Document doc;
                   1592: View view;
                   1593: #endif /* __STDC__ */
                   1594: {
1.130     cvs      1595: #ifdef AMAYA_WWW_CACHE
1.198     cvs      1596:   STRING real_dir;
                   1597:   STRING cache_dir;
                   1598:   STRING tmp;
1.128     cvs      1599:   int cache_size;
1.177     cvs      1600:   int cache_expire;
                   1601:   int cache_disconnect;
1.191     cvs      1602:   ThotBool error;
1.185     cvs      1603:   STRING ptr;
1.130     cvs      1604: 
1.128     cvs      1605:   if (!HTCacheMode_enabled ())
1.183     cvs      1606:     /* don't do anything if we're not using a cache */
                   1607:     return;
1.128     cvs      1608:   /* temporarily close down the cache, purge it, then restart */
1.198     cvs      1609:   tmp = ISO2WideChar (HTCacheMode_getRoot ());
1.190     cvs      1610:   /* don't do anything if we don't have a valid cache dir */
                   1611:   if (!tmp || *tmp == EOS)
                   1612:          return;
                   1613:   cache_dir = TtaStrdup (tmp);
1.128     cvs      1614:   cache_size = HTCacheMode_maxSize ();
1.177     cvs      1615:   cache_expire = HTCacheMode_expires ();
                   1616:   cache_disconnect = HTCacheMode_disconnected ();
                   1617: 
1.185     cvs      1618:   /* get something we can work on :) */
1.198     cvs      1619:   tmp = ISO2WideChar (HTWWWToLocal (WideChar2ISO (cache_dir), "file:", NULL));
                   1620:   real_dir = TtaAllocString (ustrlen (tmp) + 20);
                   1621:   ustrcpy (real_dir, tmp);
1.190     cvs      1622:   HT_FREE (tmp);
1.185     cvs      1623: 
                   1624:   /* safeguard... abort the operation if cache_dir doesn't end with
                   1625:      CACHE_DIR_NAME */
                   1626:   error = TRUE;
1.198     cvs      1627:   ptr = ustrstr (real_dir, CACHE_DIR_NAME);  
                   1628:     if (ptr && *ptr && !ustrcasecmp (ptr, CACHE_DIR_NAME))
1.185     cvs      1629:       error = FALSE;
                   1630:   if (error)
                   1631:     return;  
                   1632:   
1.130     cvs      1633:   /* remove the concurrent cache lock */
                   1634: #ifdef DEBUG_LIBWWW
                   1635:   fprintf (stderr, "Clearing the cache lock\n");
                   1636: #endif /* DEBUG_LIBWWW */
                   1637:   clear_cachelock ();
1.128     cvs      1638:   HTCacheTerminate ();
1.185     cvs      1639:   HTCacheMode_setEnabled (FALSE);
                   1640:   
                   1641:   RecCleanCache (real_dir);
1.128     cvs      1642: 
1.177     cvs      1643:   HTCacheMode_setExpires (cache_expire);
                   1644:   HTCacheMode_setDisconnected (cache_disconnect);
1.198     cvs      1645:   HTCacheInit (WideChar2ISO (cache_dir), cache_size);
1.130     cvs      1646:   /* set a new concurrent cache lock */
1.198     cvs      1647:   ustrcat (real_dir, TEXT(".lock"));
1.185     cvs      1648:   if (set_cachelock (real_dir) == -1)
1.130     cvs      1649:     /* couldn't open the .lock file, so, we close the cache to
                   1650:        be in the safe side */
                   1651:     {
                   1652: #ifdef DEBUG_LIBWWW
                   1653:       fprintf (stderr, "couldnt set the cache lock\n");
                   1654: #endif /* DEBUG_LIBWWW */
                   1655:       HTCacheTerminate ();
1.185     cvs      1656:       HTCacheMode_setEnabled (FALSE);
1.130     cvs      1657:     }
                   1658: #ifdef DEBUG_LIBWWW
                   1659:   fprintf (stderr, "set a cache lock\n");
                   1660: #endif /* DEBUG_LIBWWW */
1.185     cvs      1661:   TtaFreeMemory (real_dir);
1.128     cvs      1662:   TtaFreeMemory (cache_dir);
                   1663: #endif /* AMAYA_WWW_CACHE */
                   1664: }
                   1665: 
1.118     cvs      1666: #ifdef AMAYA_WWW_CACHE
                   1667: /*----------------------------------------------------------------------
1.128     cvs      1668:   RecCleanCache
1.118     cvs      1669:   Clears an existing cache directory
                   1670:   ----------------------------------------------------------------------*/
                   1671: #ifdef __STDC__
1.223     cvs      1672: static void RecCleanCache (CharUnit* dirname)
1.118     cvs      1673: #else
1.198     cvs      1674: static void RecCleanCache (dirname)
1.223     cvs      1675: CharUnit*   dirname;
1.118     cvs      1676: #endif /* __STDC__ */
1.128     cvs      1677: 
                   1678: #ifdef _WINDOWS
                   1679: {
1.223     cvs      1680:   HANDLE          hFindFile;
                   1681:   ThotBool        status;
1.128     cvs      1682:   WIN32_FIND_DATA ffd;
1.223     cvs      1683:   CharUnit        t_dir [MAX_LENGTH];
                   1684:   CharUnit*       ptr;
1.128     cvs      1685: 
1.130     cvs      1686:   /* create a t_dir name to start searching for files */
1.223     cvs      1687:   if ((StringLength (dirname) + 10) > MAX_LENGTH)
1.128     cvs      1688:     /* ERROR: directory name is too big */
                   1689:     return;
                   1690: 
1.223     cvs      1691:   StringCopy (t_dir, dirname);
1.130     cvs      1692:   /* save the end of the dirname. We'll use it to make
                   1693:      a complete pathname when erasing files */
1.223     cvs      1694:   ptr = &t_dir[StringLength (t_dir)];
                   1695:   StringConcat (t_dir, CUSTEXT("*"));
1.128     cvs      1696: 
1.130     cvs      1697:   hFindFile = FindFirstFile (t_dir, &ffd);
1.128     cvs      1698:     
                   1699:   if (hFindFile == INVALID_HANDLE_VALUE)
                   1700:     /* nothing to erase? */
                   1701:     return;
                   1702: 
                   1703:   status = TRUE;
1.130     cvs      1704:   while (status) 
                   1705:     {
                   1706:       if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1.133     cvs      1707:        {
                   1708:          /* it's a directory, erase it recursively */
1.223     cvs      1709:          if (StringCompare (ffd.cFileName, CUSTEXT("..")) && StringCompare (ffd.cFileName, TEXT(".")))
1.133     cvs      1710:            {
1.223     cvs      1711:              StringCopy (ptr, ffd.cFileName);
                   1712:              StringConcat (ptr, CUS_DIR_STR);
1.133     cvs      1713:              RecCleanCache (t_dir);
1.198     cvs      1714:              urmdir (t_dir);
1.133     cvs      1715:            }
                   1716:        }
                   1717:        else
1.130     cvs      1718:          {
1.133     cvs      1719:            /* it's a file, erase it */
1.223     cvs      1720:            StringCopy (ptr, ffd.cFileName);
1.133     cvs      1721:            TtaFileUnlink (t_dir);
1.130     cvs      1722:          }
                   1723:       status = FindNextFile (hFindFile, &ffd);
                   1724:     }
1.128     cvs      1725:   FindClose (hFindFile);
                   1726: }
                   1727: 
                   1728: #else /* _WINDOWS */
1.118     cvs      1729: {
                   1730:   DIR *dp;
                   1731:   struct stat st;
                   1732: #ifdef HAVE_DIRENT_H
                   1733:   struct dirent *d;
                   1734: #else
                   1735:   struct direct *d;
                   1736: #endif /* HAVE_DIRENT_H */
1.128     cvs      1737:   char filename[BUFSIZ+1];
1.118     cvs      1738: 
                   1739:   if ((dp = opendir (dirname)) == NULL) 
                   1740:     {
                   1741:       /* @@@ we couldn't open the directory ... we need some msg */
                   1742:       perror (dirname);
1.176     cvs      1743:       return;
1.118     cvs      1744:     }
                   1745:   
                   1746:   while ((d = readdir (dp)) != NULL)
                   1747:     {
                   1748:       /* skip the UNIX . and .. links */
                   1749:       if (!strcmp (d->d_name, "..")
                   1750:          || !strcmp (d->d_name, "."))
                   1751:        continue;
                   1752: 
1.188     cvs      1753:       sprintf (filename, "%s%c%s", dirname, DIR_SEP, d->d_name);
1.118     cvs      1754:       if  (lstat (filename, &st) < 0 ) 
                   1755:        {
                   1756:          /* @@2 need some error message */
                   1757:          perror (filename);
                   1758:          continue;
                   1759:        }
                   1760:       
                   1761:       switch (st.st_mode & S_IFMT)
                   1762:        {
                   1763:        case S_IFDIR:
                   1764:          /* if we find a directory, we erase it, recursively */
1.128     cvs      1765:          strcat (filename, DIR_STR);
                   1766:          RecCleanCache (filename);
                   1767:          rmdir (filename);
1.118     cvs      1768:          break;
                   1769:        case S_IFLNK:
                   1770:          /* skip any links we find */
                   1771:          continue;
                   1772:          break;
                   1773:        default:
                   1774:          /* erase the filename */
                   1775:          TtaFileUnlink (filename);
                   1776:          break;
                   1777:        }
                   1778:     }
                   1779:   closedir (dp);
                   1780: }
1.128     cvs      1781: #endif /* _WINDOWS */
1.118     cvs      1782: #endif /* AMAYA_WWW_CACHE */
                   1783: 
1.116     cvs      1784: /*----------------------------------------------------------------------
                   1785:   CacheInit
                   1786:   Reads the cache settings from the thot.ini file.
                   1787:   ----------------------------------------------------------------------*/
1.118     cvs      1788: #ifdef __STDC__
1.116     cvs      1789: static void CacheInit (void)
1.118     cvs      1790: #else
                   1791: static void Cacheinit ()
                   1792: #endif
                   1793: 
1.116     cvs      1794: {
                   1795: #ifndef AMAYA_WWW_CACHE
                   1796:    HTCacheMode_setEnabled (NO);
                   1797: 
                   1798: #else /* AMAYA_WWW_CACHE */
1.223     cvs      1799:   CharUnit* strptr;
                   1800:   CharUnit* real_dir = NULL;
                   1801:   CharUnit* cache_lockfile;
                   1802:   char      www_realDir[MAX_LENGTH];
                   1803:   char*     cache_dir = NULL;
                   1804:   int       cache_size;
                   1805:   int       cache_entry_size;
                   1806:   ThotBool  cache_enabled;
                   1807:   ThotBool  cache_locked;
                   1808:   ThotBool  tmp_bool;
1.130     cvs      1809: 
1.185     cvs      1810: int i;
                   1811: 
1.116     cvs      1812:   /* activate cache? */
1.203     cvs      1813:   strptr = TtaGetEnvString ("ENABLE_CACHE");
1.223     cvs      1814:   if (strptr && *strptr && StringCaseCompare (strptr, CUSTEXT("yes")))
1.130     cvs      1815:     cache_enabled = NO;
1.116     cvs      1816:   else
1.130     cvs      1817:     cache_enabled = YES;
1.116     cvs      1818: 
1.151     cvs      1819:   /* cache protected documents? */
1.203     cvs      1820:   strptr = TtaGetEnvString ("CACHE_PROTECTED_DOCS");
1.223     cvs      1821:   if (strptr && *strptr && !StringCaseCompare (strptr, CUSTEXT("yes")))
1.151     cvs      1822:     HTCacheMode_setProtected (YES);
                   1823:   else
                   1824:     HTCacheMode_setProtected (NO);
                   1825: 
1.116     cvs      1826:   /* get the cache dir (or use a default one) */
1.203     cvs      1827:   strptr = TtaGetEnvString ("CACHE_DIR");
1.116     cvs      1828:   if (strptr && *strptr) 
                   1829:     {
1.223     cvs      1830:       real_dir = TtaAllocCUString (StringLength (strptr) + StringLength (CACHE_DIR_NAME) + 20);
                   1831:       StringCopy (real_dir, strptr);
                   1832:          if (*(real_dir + StringLength (real_dir) - 1) != CUS_DIR_SEP)
                   1833:            StringConcat (real_dir, CUS_DIR_STR);
1.116     cvs      1834:     }
                   1835:   else
                   1836:     {
1.223     cvs      1837:       real_dir = TtaAllocCUString (StringLength (TempFileDirectory) + StringLength (CACHE_DIR_NAME) + 20);
                   1838:       cus_sprintf (real_dir, CUSTEXT("%s%s"), TempFileDirectory, CACHE_DIR_NAME);
1.185     cvs      1839:     }
                   1840: 
                   1841:   /* compatiblity with previous versions of Amaya: does real_dir
                   1842:      include CACHE_DIR_NAME? If not, add it */
1.223     cvs      1843:   strptr = StringSubstring (real_dir, CACHE_DIR_NAME);
1.185     cvs      1844:   if (!strptr)
1.223     cvs      1845:     StringConcat (real_dir, CACHE_DIR_NAME);
1.185     cvs      1846:   else
                   1847:     {
1.223     cvs      1848:       i = StringLength (CACHE_DIR_NAME);
                   1849:          if (strptr[i] != CUS_EOS)
                   1850:           StringConcat (real_dir, CACHE_DIR_NAME);
1.116     cvs      1851:     }
1.185     cvs      1852: 
1.211     cvs      1853:   /* convert the local cache dir into a file URL, as expected by
                   1854:      libwww */
1.223     cvs      1855:  
                   1856:   cus2iso_strcpy (www_realDir, real_dir);
                   1857: 
                   1858:   cache_dir = HTLocalToWWW (www_realDir, "file:");
1.116     cvs      1859: 
                   1860:   /* get the cache size (or use a default one) */
1.203     cvs      1861:   strptr = TtaGetEnvString ("CACHE_SIZE");
1.116     cvs      1862:   if (strptr && *strptr) 
1.223     cvs      1863:     cache_size = custoi (strptr);
1.116     cvs      1864:   else
                   1865:     cache_size = DEFAULT_CACHE_SIZE;
                   1866: 
1.176     cvs      1867:   /* get the max cached file size (or use a default one) */
1.223     cvs      1868:   if (!TtaGetEnvInt ("MAX_CACHE_ENTRY_SIZE", &cache_entry_size))
1.176     cvs      1869:     cache_entry_size = DEFAULT_MAX_CACHE_ENTRY_SIZE;
                   1870: 
1.130     cvs      1871:   if (cache_enabled) 
1.116     cvs      1872:     {
                   1873:       /* how to remove the lock? force remove it? */
1.223     cvs      1874:       cache_lockfile = TtaAllocCUString (StringLength (real_dir) + 20);
                   1875:       StringCopy (cache_lockfile, real_dir);
                   1876:       StringConcat (cache_lockfile, CUSTEXT(".lock"));
1.130     cvs      1877:       cache_locked = FALSE;
1.223     cvs      1878:       if (TtaFileExist (cache_lockfile) && !(cache_locked = test_cachelock (cache_lockfile)))
1.116     cvs      1879:        {
1.130     cvs      1880: #ifdef DEBUG_LIBWWW
                   1881:          fprintf (stderr, "found a stale cache, removing it\n");
                   1882: #endif /* DEBUG_LIBWWW */
                   1883:          /* remove the lock and clean the cache (the clean cache 
                   1884:             will remove all, making the following call unnecessary */
                   1885:          /* little trick to win some memory */
1.223     cvs      1886:          strptr = StrRChr (cache_lockfile, CUSTEXT('.'));
                   1887:          *strptr = CUS_EOS;
1.130     cvs      1888:          RecCleanCache (cache_lockfile);
1.223     cvs      1889:          *strptr = CUSTEXT('.');
1.116     cvs      1890:        }
                   1891: 
1.130     cvs      1892:       if (!cache_locked) 
                   1893:        {
                   1894:          /* initialize the cache if there's no other amaya
                   1895:             instance running */
1.177     cvs      1896:          HTCacheMode_setMaxCacheEntrySize (cache_entry_size);
1.223     cvs      1897:          if (TtaGetEnvBoolean ("CACHE_EXPIRE_IGNORE", &tmp_bool) && tmp_bool)
1.177     cvs      1898:            HTCacheMode_setExpires (HT_EXPIRES_IGNORE);
                   1899:          else
                   1900:            HTCacheMode_setExpires (HT_EXPIRES_AUTO);
1.223     cvs      1901:          TtaGetEnvBoolean ("CACHE_DISCONNECTED_MODE", &tmp_bool);
1.177     cvs      1902:          if (tmp_bool)
                   1903:            HTCacheMode_setDisconnected (HT_DISCONNECT_NORMAL);
                   1904:          else
                   1905:            HTCacheMode_setDisconnected (HT_DISCONNECT_NONE);
1.211     cvs      1906:          if (HTCacheInit (cache_dir, cache_size))
1.130     cvs      1907:            {
1.188     cvs      1908:              if (set_cachelock (cache_lockfile) == -1)
                   1909:                /* couldn't open the .lock file, so, we close the cache to
                   1910:                   be in the safe side */
                   1911:                {
                   1912:                  HTCacheTerminate ();
                   1913:                  HTCacheMode_setEnabled (FALSE);
                   1914: #ifdef DEBUG_LIBWWW
                   1915:                  fprintf (stderr, "couldnt set the cache lock\n");
                   1916: #endif /* DEBUG_LIBWWW */
                   1917:                }
1.130     cvs      1918: #ifdef DEBUG_LIBWWW
1.188     cvs      1919:              else
                   1920:                fprintf (stderr, "created the cache lock\n");
1.130     cvs      1921: #endif /* DEBUG_LIBWWW */
                   1922:            }
1.188     cvs      1923:          else
                   1924:            {
1.130     cvs      1925: #ifdef DEBUG_LIBWWW
1.188     cvs      1926:              fprintf (stderr, "couldn't create the cache\n");
                   1927: #endif /* DEBUG_LIBWWW */            
                   1928:              HTCacheTerminate ();
                   1929:            }
1.130     cvs      1930:        }
                   1931:       else 
                   1932:        {
1.185     cvs      1933:          HTCacheMode_setEnabled (FALSE);
1.130     cvs      1934: #ifdef DEBUG_LIBWWW
                   1935:          fprintf (stderr, "lock detected, starting libwww without a cache/n");
                   1936: #endif /* DEBUG_LIBWWW */
                   1937:        }
                   1938:       TtaFreeMemory (cache_lockfile);
1.116     cvs      1939:     }
                   1940:   else
1.185     cvs      1941:     {
                   1942:       HTCacheMode_setEnabled (FALSE);
                   1943:     }
1.116     cvs      1944:   if (cache_dir)
1.211     cvs      1945:     HT_FREE (cache_dir);
1.189     cvs      1946:   if (real_dir)
                   1947:     TtaFreeMemory (real_dir);
1.185     cvs      1948:   /* warn the user if the cache isn't active */
                   1949:   if (cache_enabled && !HTCacheMode_enabled ())
1.214     cvs      1950:       InitInfo (TEXT("Cache"), TtaGetMessage (AMAYA, AM_CANT_CREATE_CACHE));
1.116     cvs      1951: #endif /* AMAYA_WWW_CACHE */
1.15      cvs      1952: }
                   1953: 
                   1954: /*----------------------------------------------------------------------
1.97      cvs      1955:   ProxyInit
                   1956:   Reads any proxies settings which may be declared as environmental
                   1957:   variables or in the thot.ini file. The former overrides the latter.
                   1958:   ----------------------------------------------------------------------*/
1.118     cvs      1959: #ifdef __STDC__
1.97      cvs      1960: static void ProxyInit (void)
1.118     cvs      1961: #else
                   1962: static void ProxyInit ()
                   1963: #endif /* __STDC__ */
1.97      cvs      1964: {
1.223     cvs      1965:   CharUnit* strptr;
                   1966:   CharUnit* str = NULL;
                   1967:   char*     name;
                   1968:   ThotBool  proxy_is_onlyproxy;
                   1969:   char*     tmp = (char*) 0;
                   1970:   char*     strptrA;
1.97      cvs      1971: 
                   1972:   /* get the proxy settings from the thot.ini file */
1.203     cvs      1973:   strptr = TtaGetEnvString ("HTTP_PROXY");
1.223     cvs      1974:   if (strptr) {
                   1975:      tmp = (char*) TtaGetMemory (StringLength (strptr) + 1);
                   1976:      cus2iso_strcpy (tmp, strptr);
                   1977:   }
                   1978: 
                   1979:   if (strptr && *strptr) {
                   1980:      /* does the proxy env string has an "http://" prefix? */
                   1981:      if (!StringNCaseCompare (strptr, CUSTEXT("http://"), 7)) 
                   1982:         HTProxy_add ("http", tmp);
                   1983:      else {
                   1984:           strptrA = (char*) TtaGetMemory (ustrlen (strptr) + 9);
                   1985:           strcpy (strptrA, "http://");
                   1986:           strcat (strptrA, tmp);
                   1987:           HTProxy_add ("http", strptrA);
                   1988:           TtaFreeMemory (strptrA);
                   1989:         }
                   1990:      TtaFreeMemory (tmp);
                   1991:      tmp = (char*) 0;
                   1992:   }
1.216     cvs      1993: 
1.97      cvs      1994:   /* get the no_proxy settings from the thot.ini file */
1.212     cvs      1995:   strptr = TtaGetEnvString ("PROXYDOMAIN");
1.223     cvs      1996:   if (strptr) {
                   1997:      tmp = (char*) TtaGetMemory (StringLength (strptr) + 1);
                   1998:      cus2iso_strcpy (tmp, strptr);
                   1999:   }
                   2000: 
                   2001:   if (strptr && *strptr) {
                   2002:      str = StringDuplicate (strptr);          /* Get copy we can mutilate */
                   2003:      strptr = str;
                   2004:      while ((name = HTNextField (&tmp)) != NULL) {
                   2005:            char* portstr = strchr (name, ':');
                   2006:            unsigned port=0;
                   2007:            if (portstr) { 
                   2008:               *portstr++ = EOS;
                   2009:               if (*portstr) port = (unsigned) atoi (portstr);
                   2010:                   }
                   2011:            /* Register it for all access methods */
                   2012:            HTNoProxy_add (name, NULL, port);
                   2013:         }
                   2014:      TtaFreeMemory (str);
                   2015:      TtaFreeMemory (tmp);
                   2016:      tmp = (char*)0;
                   2017:   }
1.212     cvs      2018: 
                   2019:   /* how should we interpret the proxy domain list? */
                   2020:   TtaGetEnvBoolean ("PROXYDOMAIN_IS_ONLYPROXY", &proxy_is_onlyproxy);
                   2021:   HTProxy_setNoProxyIsOnlyProxy (proxy_is_onlyproxy);
                   2022: 
                   2023:   /* use libwww's routine to get all proxy settings from the environment */
1.97      cvs      2024:    HTProxy_getEnvVar ();
                   2025: }
                   2026: 
1.207     cvs      2027: /*----------------------------------------------------------------------
                   2028:   SafePut_init
                   2029:   Sets up the domains which are authorized to make a redirect on 
                   2030:   a PUT.
                   2031:   ----------------------------------------------------------------------*/
                   2032: #ifdef __STDC__
                   2033: static void SafePut_init (void)
                   2034: #else
                   2035: static void SafePut_init ()
                   2036: #endif /* __STDC__ */
                   2037: {
1.224   ! cvs      2038:   /***
1.223     cvs      2039:   CharUnit* strptr;
                   2040:   CharUnit* str = NULL;
                   2041:   char*     ptr, strptrA[MAX_LENGTH];
1.224   ! cvs      2042:   ***/
        !          2043:   STRING strptr;
        !          2044:   STRING str = NULL;
        !          2045:   char  *strptrA, *ptr;
        !          2046:   /*****/
1.223     cvs      2047:   char*     domain;
1.207     cvs      2048: 
                   2049:   /* get the proxy settings from the thot.ini file */
                   2050:   strptr = TtaGetEnvString ("SAFE_PUT_REDIRECT");
                   2051:   if (strptr && *strptr)
                   2052:     {
                   2053:       /* Get copy we can mutilate */
1.224   ! cvs      2054:       /*****
1.223     cvs      2055:       str = StringDuplicate (strptr);
                   2056:       cus2iso_strcpy (strptrA, strptr);
1.224   ! cvs      2057:       ****/
        !          2058:       str = TtaStrdup (strptr); 
        !          2059:       strptrA = WideChar2ISO (str);
        !          2060:       /******/
1.207     cvs      2061:       /* convert to lowercase */
                   2062:       ptr = strptrA;
                   2063:       while (*ptr) 
                   2064:        {
                   2065:          *ptr = tolower (*ptr);
                   2066:          ptr++;
                   2067:        }
                   2068:       
                   2069:       /* create the list container */
                   2070:       safeput_list = HTList_new ();   
                   2071:       /* store the domain list */
                   2072:       while ((domain = HTNextField (&strptrA)) != NULL)
                   2073:          HTList_addObject (safeput_list, TtaStrdup (domain)); 
                   2074: 
                   2075:       TtaFreeMemory (str);
                   2076:     }
                   2077: }
                   2078: 
                   2079: /*----------------------------------------------------------------------
                   2080:   SafePut_delete
                   2081:   Deletes the safeput_list variable
                   2082:   ----------------------------------------------------------------------*/
                   2083: static void SafePut_delete (void)
                   2084: {
                   2085:   HTList *cur = safeput_list;
                   2086:   char *domain;
                   2087: 
                   2088:   if (!safeput_list) 
                   2089:     return;
                   2090: 
                   2091:   while ((domain = (char *) HTList_nextObject (cur))) 
                   2092:       TtaFreeMemory (domain);
                   2093:    HTList_delete (safeput_list);
                   2094:    safeput_list = NULL;
                   2095: }
                   2096: 
                   2097: /*----------------------------------------------------------------------
                   2098:   SafePut_query
                   2099:   returns true if the domain to which belongs the URL accepts an automatic
                   2100:   PUT redirect.
                   2101:   ----------------------------------------------------------------------*/
                   2102: static ThotBool SafePut_query (char *url)
                   2103: {
                   2104:   HTList *cur;
                   2105:   char *me;
                   2106:   ThotBool found;
                   2107: 
                   2108:   /* extract the domain path of the url and normalize it */
                   2109:   /* domain = url; */
                   2110:   cur = safeput_list;
                   2111:   found = FALSE;
                   2112:   while ((me = (char *) HTList_nextObject (cur))) 
                   2113:     {
                   2114:       if (strstr (url, me))
                   2115:        {
                   2116:          found = TRUE;
                   2117:          break;
                   2118:        }
                   2119:     }
                   2120: 
                   2121:   return (found);
                   2122: }
1.97      cvs      2123: 
                   2124: /*----------------------------------------------------------------------
1.17      cvs      2125:   AHTProfile_newAmaya
                   2126:   creates the Amaya client profile for libwww.
1.15      cvs      2127:   ----------------------------------------------------------------------*/
                   2128: #ifdef __STDC__
1.223     cvs      2129: static void         AHTProfile_newAmaya (char* AppName, char* AppVersion)
1.15      cvs      2130: #else  /* __STDC__ */
                   2131: static void         AHTProfile_newAmaya (AppName, AppVersion)
1.223     cvs      2132: char* AppName;
                   2133: char* AppVersion;
1.15      cvs      2134: #endif /* __STDC__ */
1.4       cvs      2135: {
1.223     cvs      2136:    CharUnit* strptr;
1.158     cvs      2137: 
1.4       cvs      2138:    /* If the Library is not already initialized then do it */
                   2139:    if (!HTLib_isInitialized ())
1.223     cvs      2140:       HTLibInit (AppName, AppVersion);
1.4       cvs      2141: 
                   2142:    if (!converters)
                   2143:       converters = HTList_new ();
1.27      cvs      2144:    if (!acceptTypes)
                   2145:       acceptTypes = HTList_new ();
1.193     cvs      2146:    if (!acceptLanguages)
                   2147:       acceptLanguages = HTList_new ();
1.151     cvs      2148:    if (!transfer_encodings)
                   2149:       transfer_encodings = HTList_new ();
                   2150:    if (!content_encodings)
                   2151:       content_encodings = HTList_new ();
1.4       cvs      2152: 
1.169     cvs      2153:    /* inhibits libwww's automatic file_suffix_binding */
                   2154:    HTFile_doFileSuffixBinding (FALSE);
                   2155: 
1.4       cvs      2156:    /* Register the default set of transport protocols */
                   2157:    HTTransportInit ();
                   2158: 
                   2159:    /* Register the default set of application protocol modules */
                   2160:    AHTProtocolInit ();
                   2161: 
1.116     cvs      2162:    /* Register the default set of messages and dialog functions */
                   2163:    AHTAlertInit ();
                   2164:    HTAlert_setInteractive (YES);
                   2165: 
                   2166: #ifdef AMAYA_WWW_CACHE
                   2167:    /* Enable the persistent cache  */
                   2168:    CacheInit ();
                   2169: #else
                   2170:    HTCacheMode_setEnabled (NO);
                   2171: #endif /* AMAYA_WWW_CACHE */
1.4       cvs      2172: 
                   2173:    /* Register the default set of BEFORE and AFTER filters */
                   2174:    AHTNetInit ();
                   2175: 
                   2176:    /* Set up the default set of Authentication schemes */
1.223     cvs      2177:    HTAA_newModule ("basic", HTBasic_generate, HTBasic_parse, NULL, HTBasic_delete);
1.158     cvs      2178:    /* activate MDA by defaul */
1.203     cvs      2179:    strptr = TtaGetEnvString ("ENABLE_MDA");
1.223     cvs      2180:    if (!strptr || (strptr && *strptr && StringCaseCompare (strptr, CUSTEXT("no"))))
                   2181:      HTAA_newModule ("digest", HTDigest_generate, HTDigest_parse, HTDigest_updateInfo, HTDigest_delete);
1.4       cvs      2182: 
1.97      cvs      2183:    /* Get any proxy settings */
                   2184:    ProxyInit ();
1.4       cvs      2185: 
1.207     cvs      2186:    /* Set up the domains where we accept a redirect on PUT */
                   2187:    SafePut_init ();
                   2188: 
1.4       cvs      2189:    /* Register the default set of converters */
                   2190:    AHTConverterInit (converters);
1.151     cvs      2191:    HTFormat_setConversion (converters);
1.27      cvs      2192:    AHTAcceptTypesInit (acceptTypes);
1.193     cvs      2193:    AHTAcceptLanguagesInit (acceptLanguages);
1.4       cvs      2194: 
                   2195:    /* Register the default set of transfer encoders and decoders */
1.151     cvs      2196:    HTTransferEncoderInit (transfer_encodings);
1.190     cvs      2197:    HTFormat_setTransferCoding (transfer_encodings);
                   2198:    /* Register the default set of content encoders and decoders */
                   2199:    HTContentEncoderInit (content_encodings);
                   2200:    /* ignore all other encoding formats (or libwww will send them 
1.181     cvs      2201:       thru a blackhole otherwise */
                   2202:    HTCoding_add (content_encodings, "*", NULL, HTIdentityCoding, 1.0);
1.151     cvs      2203:    if (HTList_count(content_encodings) > 0)
                   2204:      HTFormat_setContentCoding(content_encodings);
                   2205:    else 
                   2206:      {
                   2207:        HTList_delete(content_encodings);
                   2208:        content_encodings = NULL;
                   2209:      }
1.4       cvs      2210: 
                   2211:    /* Register the default set of MIME header parsers */
1.74      cvs      2212:    HTMIMEInit ();   /* must be called again for language selector */
1.4       cvs      2213: 
                   2214:    /* Register the default set of Icons for directory listings */
1.27      cvs      2215:    /*HTIconInit(NULL); *//* experimental */
1.4       cvs      2216: }
                   2217: 
1.5       cvs      2218: /*----------------------------------------------------------------------
1.17      cvs      2219:   AHTProfile_delete
                   2220:   deletes the Amaya client profile.
1.5       cvs      2221:   ----------------------------------------------------------------------*/
1.4       cvs      2222: #ifdef __STDC__
                   2223: static void         AHTProfile_delete (void)
                   2224: #else
                   2225: static void         AHTProfile_delete ()
1.7       cvs      2226: #endif                         /* __STDC__ */
1.4       cvs      2227: {
1.22      cvs      2228:  
                   2229:   /* free the Amaya global context */
1.151     cvs      2230: 
                   2231:   /* Clean up all the registred converters */
                   2232:   HTFormat_deleteAll ();
                   2233:   if (acceptTypes)
1.74      cvs      2234:     HTConversion_deleteAll (acceptTypes);
1.193     cvs      2235:   if (acceptLanguages)
                   2236:     HTLanguage_deleteAll (acceptLanguages);
1.151     cvs      2237: 
1.209     cvs      2238:   StopAllRequests (1);
1.74      cvs      2239:   HTList_delete (Amaya->docid_status);
                   2240:   HTList_delete (Amaya->reqlist);
                   2241:   TtaFreeMemory (Amaya);
1.61      cvs      2242: 
1.120     cvs      2243: #ifdef _WINDOWS
1.209     cvs      2244:   if (HTLib_isInitialized ())      
1.151     cvs      2245:     HTEventTerminate ();
1.198     cvs      2246: #endif /* _WINDOWS; */         
1.74      cvs      2247:     
1.151     cvs      2248:   /* Clean up the persistent cache (if any) */
1.116     cvs      2249: #ifdef AMAYA_WWW_CACHE
1.151     cvs      2250:   clear_cachelock ();
                   2251:   HTCacheTerminate ();
1.116     cvs      2252: #endif /* AMAYA_WWW_CACHE */
1.217     cvs      2253:   
1.218     cvs      2254:   /* call remove functions that are not called automatically by libwww */
                   2255:   HTNetCall_deleteBeforeAll (HTNet_before ());
                   2256:   HTNetCall_deleteAfterAll (HTNet_after ());
                   2257:   HTAA_deleteAllModules ();
                   2258:   HTAlertCall_deleteAll (HTAlert_global () );
                   2259:   HTAlert_setGlobal ((HTList *) NULL);
                   2260:   /* these two functions are broken, so we can't call them right now 
                   2261:   HTHeader_deleteAll ();
                   2262:   HTTimer_deleteAll ();
                   2263:   */
                   2264:   HTTransport_deleteAll ();
1.217     cvs      2265:   /* remove bindings between suffixes, media types*/
                   2266:   HTBind_deleteAll ();
1.151     cvs      2267:   /* Terminate libwww */
                   2268:   HTLibTerminate ();
1.4       cvs      2269: }
                   2270: 
1.5       cvs      2271: /*----------------------------------------------------------------------
1.116     cvs      2272:   AmayacontextInit
                   2273:   initializes an internal Amaya context for our libwww interface 
                   2274:   ----------------------------------------------------------------------*/
                   2275: #ifdef __STDC__
                   2276: static void                AmayaContextInit ()
                   2277: #else
                   2278: static void                AmayaContextInit ()
                   2279: #endif
                   2280: 
                   2281: {
1.140     cvs      2282:   AmayaAlive_flag = TRUE;
1.116     cvs      2283:   /* Initialization of the global context */
                   2284:   Amaya = (AmayaContext *) TtaGetMemory (sizeof (AmayaContext));
                   2285:   Amaya->reqlist = HTList_new ();
                   2286:   Amaya->docid_status = HTList_new ();
                   2287:   Amaya->open_requests = 0;
                   2288: }
                   2289: 
                   2290: /*----------------------------------------------------------------------
1.17      cvs      2291:   QueryInit
                   2292:   initializes the libwww interface 
1.5       cvs      2293:   ----------------------------------------------------------------------*/
1.4       cvs      2294: #ifdef __STDC__
                   2295: void                QueryInit ()
                   2296: #else
                   2297: void                QueryInit ()
                   2298: #endif
                   2299: {
1.223     cvs      2300:   CharUnit* strptr;
1.151     cvs      2301:   int tmp_i;
                   2302:   long tmp_l;
1.4       cvs      2303: 
1.116     cvs      2304:    AmayaContextInit ();
1.4       cvs      2305:    AHTProfile_newAmaya (HTAppName, HTAppVersion);
1.140     cvs      2306:    CanDoStop_set (TRUE);
1.214     cvs      2307:    UserAborted_flag = FALSE;
1.4       cvs      2308: 
1.116     cvs      2309: #ifdef _WINDOWS
1.125     cvs      2310:    HTEventInit ();
1.116     cvs      2311: #endif /* _WINDOWS */
1.72      cvs      2312: 
1.123     cvs      2313: #ifndef _WINDOWS
1.116     cvs      2314:    HTEvent_setRegisterCallback ((void *) AHTEvent_register);
                   2315:    HTEvent_setUnregisterCallback ((void *) AHTEvent_unregister);
1.202     cvs      2316: #ifndef _GTK
1.120     cvs      2317:    HTTimer_registerSetTimerCallback ((void *) AMAYA_SetTimer);
                   2318:    HTTimer_registerDeleteTimerCallback ((void *) AMAYA_DeleteTimer);
1.202     cvs      2319: #endif /* _GTK */
1.116     cvs      2320: #endif /* !_WINDOWS */
1.190     cvs      2321: 
1.213     cvs      2322: #ifdef HTDEBUG
                   2323:    /* an undocumented option for being able to generate an HTTP protocol trace */
1.208     cvs      2324:    strptr = TtaGetEnvString ("ENABLE_LIBWWW_DEBUG");
                   2325:    if (strptr && *strptr)
                   2326:      WWW_TraceFlag = SHOW_PROTOCOL_TRACE;
                   2327:    else
                   2328:      WWW_TraceFlag = 0;
1.213     cvs      2329: #endif /* HTDEBUG */
1.208     cvs      2330: 
1.74      cvs      2331: #ifdef DEBUG_LIBWWW
1.116     cvs      2332:   /* forwards error messages to our own function */
                   2333:    WWW_TraceFlag = THD_TRACE;
1.138     cvs      2334:    HTTrace_setCallback(LineTrace);
1.4       cvs      2335:    /* Trace activation (for debugging) */
1.148     cvs      2336:    /***
1.138     cvs      2337:     WWW_TraceFlag = SHOW_CORE_TRACE | SHOW_THREAD_TRACE | SHOW_PROTOCOL_TRACE;
                   2338:     WWW_TraceFlag |= 0xFFFFFFFFl;
                   2339:     ***/
1.152     cvs      2340: #endif
                   2341: 
1.148     cvs      2342:    /* Setting up different network parameters */
1.151     cvs      2343: 
1.148     cvs      2344:    /* Maximum number of simultaneous open sockets */
1.203     cvs      2345:    strptr = TtaGetEnvString ("MAX_SOCKET");
1.151     cvs      2346:    if (strptr && *strptr) 
1.223     cvs      2347:      tmp_i = custoi (strptr);
1.151     cvs      2348:    else
                   2349:      tmp_i = DEFAULT_MAX_SOCKET;
                   2350:    HTNet_setMaxSocket (tmp_i);
                   2351: 
1.148     cvs      2352:    /* different network services timeouts */
1.151     cvs      2353:    /* dns timeout */
1.203     cvs      2354:    strptr = TtaGetEnvString ("DNS_TIMEOUT");
1.151     cvs      2355:    if (strptr && *strptr) 
1.223     cvs      2356:      tmp_i = custoi (strptr);
1.151     cvs      2357:    else
                   2358:      tmp_i = DEFAULT_DNS_TIMEOUT;
                   2359:    HTDNS_setTimeout (tmp_i);
                   2360: 
                   2361:    /* persistent connections timeout */
1.203     cvs      2362:    strptr = TtaGetEnvString ("PERSIST_CX_TIMEOUT");
1.151     cvs      2363:    if (strptr && *strptr) 
1.223     cvs      2364:      tmp_l = uctol (strptr); 
1.151     cvs      2365:    else
                   2366:      tmp_l = DEFAULT_PERSIST_TIMEOUT;
                   2367:    HTHost_setPersistTimeout (tmp_l);
                   2368: 
1.148     cvs      2369:    /* default timeout in ms */
1.203     cvs      2370:    strptr = TtaGetEnvString ("NET_EVENT_TIMEOUT");
1.151     cvs      2371:    if (strptr && *strptr) 
1.223     cvs      2372:      tmp_i = custoi (strptr);
1.151     cvs      2373:    else
                   2374:      tmp_i = DEFAULT_NET_EVENT_TIMEOUT;
                   2375:    HTHost_setEventTimeout (tmp_i);
                   2376: 
1.173     cvs      2377:    HTRequest_setMaxRetry (8);
1.4       cvs      2378: #ifdef CATCH_SIG
1.148     cvs      2379:    signal (SIGPIPE, SIG_IGN);
1.4       cvs      2380: #endif
1.15      cvs      2381: }
                   2382: 
                   2383: /*----------------------------------------------------------------------
1.17      cvs      2384:   LoopForStop
1.136     cvs      2385:   a copy of the Thop event loop so we can handle the stop button in Unix
                   2386:   and preemptive requests under Windows
1.15      cvs      2387:   ----------------------------------------------------------------------*/
                   2388: #ifdef __STDC__
                   2389: static int          LoopForStop (AHTReqContext * me)
                   2390: #else
                   2391: static int          LoopForStop (AHTReqContext * me)
                   2392: #endif
                   2393: {
1.136     cvs      2394: #ifdef _WINDOWS
                   2395:   MSG msg;
                   2396:   unsigned long libwww_msg;
                   2397:   HWND old_active_window, libwww_window;
                   2398:   int  status_req = HT_OK;
                   2399: 
                   2400:   old_active_window = GetActiveWindow ();
                   2401:   libwww_window = HTEventList_getWinHandle (&libwww_msg);
1.137     cvs      2402:  
1.149     cvs      2403:   while (me->reqStatus != HT_END && me->reqStatus != HT_ERR
                   2404:             && me->reqStatus != HT_ABORT && AmayaIsAlive () &&
                   2405:             GetMessage (&msg, NULL, 0, 0))
                   2406:                {
                   2407:          if (msg.message != WM_QUIT)
                   2408:                        {
                   2409:                      TranslateMessage (&msg);
                   2410:                      DispatchMessage (&msg);
                   2411:                        }
                   2412:          else
                   2413:                break;      
                   2414:                }
1.136     cvs      2415:   if (!AmayaIsAlive ())
                   2416:     /* Amaya was killed by one of the callback handlers */
                   2417:     exit (0);
                   2418: #else /* _WINDOWS */
1.25      cvs      2419:    extern ThotAppContext app_cont;
1.51      cvs      2420:    XEvent                ev;
                   2421:    XtInputMask           status;
1.17      cvs      2422:    int                 status_req = HT_OK;
1.15      cvs      2423: 
                   2424:    /* to test the async calls  */
1.17      cvs      2425:    /* Loop while waiting for new events, exists when the request is over */
1.15      cvs      2426:    while (me->reqStatus != HT_ABORT &&
                   2427:          me->reqStatus != HT_END &&
1.69      cvs      2428:          me->reqStatus != HT_ERR) {
1.116     cvs      2429:         if (!AmayaIsAlive ())
1.69      cvs      2430:            /* Amaya was killed by one of the callback handlers */
                   2431:            exit (0);
                   2432: 
                   2433:         status = XtAppPending (app_cont);
1.144     cvs      2434:         if (status & XtIMXEvent)
                   2435:           {
                   2436:             XtAppNextEvent (app_cont, &ev);
                   2437:             TtaHandleOneEvent (&ev);
                   2438:           } 
                   2439:         else if (status != 0) 
                   2440:           XtAppProcessEvent (app_cont, XtIMAll);
1.69      cvs      2441:    }
1.136     cvs      2442: #endif /* _WINDOWS */
1.69      cvs      2443:    switch (me->reqStatus) {
                   2444:          case HT_ERR:
                   2445:           case HT_ABORT:
1.130     cvs      2446:               status_req = NO;
1.15      cvs      2447:               break;
                   2448: 
1.69      cvs      2449:          case HT_END:
1.130     cvs      2450:               status_req = YES;
1.15      cvs      2451:               break;
                   2452: 
1.69      cvs      2453:          default:
1.15      cvs      2454:               break;
1.69      cvs      2455:    }
1.15      cvs      2456:    return (status_req);
1.4       cvs      2457: }
                   2458: 
1.5       cvs      2459: /*----------------------------------------------------------------------
1.15      cvs      2460:   QueryClose
1.21      cvs      2461:   closes all existing threads, frees all non-automatically deallocated
                   2462:   memory and then ends libwww.
1.5       cvs      2463:   ----------------------------------------------------------------------*/
1.116     cvs      2464: void QueryClose ()
1.4       cvs      2465: {
1.24      cvs      2466: 
1.140     cvs      2467:   AmayaAlive_flag = FALSE;
1.24      cvs      2468: 
1.116     cvs      2469:   /* remove all the handlers and callbacks that may output a message to
                   2470:      a non-existent Amaya window */
                   2471:   HTEvent_setRegisterCallback ((HTEvent_registerCallback *) NULL);
                   2472:   HTEvent_setUnregisterCallback ((HTEvent_unregisterCallback *) NULL);
                   2473: #ifndef _WINDOWS
                   2474:   /** need to erase all existing timers too **/
                   2475:    HTTimer_registerSetTimerCallback (NULL);
                   2476:    HTTimer_registerDeleteTimerCallback (NULL);
                   2477: #endif /* !_WINDOWS */
                   2478:   HTHost_setActivateRequestCallback (NULL);
                   2479:   Thread_deleteAll ();
1.21      cvs      2480:  
1.116     cvs      2481:   HTProxy_deleteAll ();
                   2482:   HTNoProxy_deleteAll ();
1.207     cvs      2483:   SafePut_delete ();
1.116     cvs      2484:   HTGateway_deleteAll ();
                   2485:   AHTProfile_delete ();
                   2486: }
                   2487: 
                   2488: /*----------------------------------------------------------------------
                   2489:   NextNameValue
                   2490:   ---------------------------------------------------------------------*/
                   2491: #ifdef __STDC__
                   2492: static char * NextNameValue (char ** pstr, char **name, char **value)
                   2493: #else
                   2494: static char * NextNameValue (pstr, name, value);
                   2495: char ** pstr;
                   2496: char **name;
                   2497: char **value;
                   2498: #endif /* __STDC__ */
                   2499: {
                   2500:   char * p = *pstr;
                   2501:   char * start = NULL;
                   2502:   if (!pstr || !*pstr) return NULL;
                   2503:   
                   2504:     if (!*p) {
                   2505:       *pstr = p;
                   2506:       *name = NULL;
                   2507:       *value = NULL;
                   2508:       return NULL;                                      /* No field */
                   2509:     }
                   2510:     
                   2511:     /* Now search for the next '&' and ';' delimitators */
                   2512:     start = p;
                   2513:     while (*p && *p != '&' && *p != ';') p++;
                   2514:     if (*p) 
                   2515:       *p++ = '\0';
                   2516:     *pstr = p;
                   2517: 
                   2518:     /* Search for the name and value */
                   2519:     *name = start;
                   2520:     p = start;
                   2521:     
                   2522:     while(*p && *p != '=') 
                   2523:       p++;
                   2524:     if (*p) 
                   2525:       *p++ = '\0';
                   2526:     *value = p;
                   2527: 
                   2528:     return start;
                   2529: }
                   2530: 
                   2531: /*----------------------------------------------------------------------
                   2532:   PrepareFormdata
                   2533:   ---------------------------------------------------------------------*/
                   2534: #ifdef __STDC__
1.198     cvs      2535: static HTAssocList * PrepareFormdata (STRING string)
1.116     cvs      2536: #else
                   2537: static HTAssocList * PrepareFormdata (string)
1.198     cvs      2538: STRING string;
1.116     cvs      2539: #endif /* __STDC__ */
                   2540: {
1.198     cvs      2541:   char*        tmp_string, *tmp_string_ptr;
                   2542:   char*        name;
                   2543:   char*        value;
                   2544:   HTAssocList* formdata;
1.116     cvs      2545: 
                   2546:   if (!string)
                   2547:     return NULL;
                   2548: 
                   2549:   /* store the ptr in another variable, as the original address will
                   2550:      change
                   2551:      */
                   2552: 
1.198     cvs      2553:   tmp_string_ptr = tmp_string = WideChar2ISO (TtaStrdup (string));
1.116     cvs      2554:   formdata = HTAssocList_new();
                   2555:   
                   2556:   while (*tmp_string)
                   2557:     {
                   2558:       NextNameValue (&tmp_string, &name, &value);
                   2559:       HTAssocList_addObject(formdata,
                   2560:                            name, value);
                   2561:     }
                   2562: 
                   2563:   TtaFreeMemory (tmp_string_ptr);
                   2564:   return formdata;
1.4       cvs      2565: }
                   2566: 
1.216     cvs      2567: #ifdef __STDC__
                   2568: void AHTRequest_setCustomAcceptHeader (HTRequest *request, char *value)
                   2569: #else
                   2570: void AHTRequest_setCustomAcceptHeader (request, value)
                   2571: HTRequest *request;
                   2572: char *value;
                   2573: #endif /* __STDC__ */
                   2574: {                              
                   2575:   HTRqHd rqhd = HTRequest_rqHd (request);
                   2576:   rqhd = rqhd & (~HT_C_ACCEPT_TYPE);
                   2577:   HTRequest_setRqHd (request, rqhd);
1.221     cvs      2578:   HTRequest_addExtraHeader (request, "Accept", value);
1.216     cvs      2579: }
                   2580: 
                   2581:               
1.99      cvs      2582: 
                   2583: /*----------------------------------------------------------------------
                   2584:   InvokeGetObjectWWW_callback
                   2585:   A simple function to invoke a callback function whenever there's an error
                   2586:   in GetObjectWWW
                   2587:   ---------------------------------------------------------------------*/
                   2588: 
1.116     cvs      2589: #ifdef __STDC__
1.198     cvs      2590: void      InvokeGetObjectWWW_callback (int docid, STRING urlName, STRING outputfile, TTcbf *terminate_cbf, void *context_tcbf, int status)
1.99      cvs      2591: #else
1.111     cvs      2592: void      InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf, context_tcbf, status)
1.99      cvs      2593: int docid;
1.198     cvs      2594: STRING urlName;
                   2595: STRING outputfile;
1.99      cvs      2596: TTcbf *terminate_cbf;
                   2597: void *context_tcbf;
1.116     cvs      2598: #endif /* __STDC__ */
1.99      cvs      2599: {
                   2600:   if (!terminate_cbf)
                   2601:     return;
                   2602:   
1.116     cvs      2603:   (*terminate_cbf) (docid, status, urlName, outputfile,
1.99      cvs      2604:                    NULL, context_tcbf);  
                   2605: }
                   2606: 
                   2607: 
                   2608: 
1.5       cvs      2609: /*----------------------------------------------------------------------
1.15      cvs      2610:    GetObjectWWW
1.17      cvs      2611:    this function requests a resource designated by a URLname into a
                   2612:    temporary filename. The download can come from a simple GET operation,
                   2613:    or can come from POSTING/GETTING a form. In the latter
                   2614:    case, the function receives a query string to send to the server.
                   2615: 
1.5       cvs      2616:    4  file retrieval modes are proposed:                              
                   2617:    AMAYA_SYNC : blocking mode                            
                   2618:    AMAYA_ISYNC : incremental, blocking mode              
                   2619:    AMAYA_ASYNC : non-blocking mode                       
                   2620:    AMAYA_IASYNC : incremental, non-blocking mode         
                   2621:    
                   2622:    In the incremental mode, each time a package arrives, it will be   
                   2623:    stored in the temporary file. In addition, if an                   
                   2624:    incremental_callback function is defined, this function will be    
                   2625:    called and handled a copy of the newly received data package.      
                   2626:    Finally, if a terminate_callback function is defined, it will be   
                   2627:    invoked when the request terminates. The caller of this function
1.4       cvs      2628:    can define two different contexts to be passed to the callback
                   2629:    functions.
                   2630: 
                   2631:    When the function is called with the SYNC mode, the function will
                   2632:    return only when the requested file has been loaded.
                   2633:    The ASYNC mode will immediately return after setting up the
                   2634:    call.
                   2635: 
                   2636:    Notes:
                   2637:    At the end of a succesful request, the urlName string contains the
                   2638:    name of the actually retrieved URL. As a URL can change over the time,
                   2639:    (e.g., be redirected elsewhere), it is advised that the function
1.17      cvs      2640:    caller verify the value of the urlName variable at the end of
1.4       cvs      2641:    a request.
                   2642: 
                   2643:    Inputs:
                   2644:    - docid  Document identifier for the set of objects being
                   2645:    retrieved.
                   2646:    - urlName The URL to be retrieved (MAX_URL_LENGTH chars length)
                   2647:    - outputfile A pointer to an empty string of MAX_URL_LENGTH.
                   2648:    - mode The retrieval mode.
                   2649:    - incremental_cbf 
                   2650:    - context_icbf
                   2651:    Callback and context for the incremental modes
                   2652:    - terminate_cbf 
                   2653:    - context_icbf
                   2654:    Callback and context for a terminate handler
1.17      cvs      2655:    -error_html if TRUE, then display any server error message as an
                   2656:    HTML document.
1.88      cvs      2657:    - content_type a string
                   2658:  
1.4       cvs      2659:    Outputs:
                   2660:    - urlName The URL that was retrieved
                   2661:    - outputfile The name of the temporary file which holds the
                   2662:    retrieved data. (Only in case of success)
1.88      cvs      2663:    - if content_type wasn't NULL, it will contain a copy of the parameter
                   2664:      sent in the HTTP answer
1.4       cvs      2665:    Returns:
                   2666:    HT_ERROR
                   2667:    HT_OK
1.5       cvs      2668:  
                   2669:   ----------------------------------------------------------------------*/
1.4       cvs      2670: #ifdef __STDC__
1.198     cvs      2671: int GetObjectWWW (int docid, STRING urlName, STRING formdata,
                   2672:                  STRING outputfile, int mode, TIcbf* incremental_cbf, 
1.116     cvs      2673:                  void* context_icbf, TTcbf* terminate_cbf, 
1.198     cvs      2674:                  void* context_tcbf, ThotBool error_html, STRING content_type)
1.4       cvs      2675: #else
1.127     cvs      2676: int GetObjectWWW (docid, urlName, formdata, outputfile, mode, 
1.116     cvs      2677:                  incremental_cbf, context_icbf, 
1.88      cvs      2678:                  terminate_cbf, context_tcbf, error_html, content_type)
1.73      cvs      2679: int           docid;
1.198     cvs      2680: STRING        urlName;
                   2681: STRING        formdata;
                   2682: STRING        outputfile;
1.73      cvs      2683: int           mode;
                   2684: TIcbf        *incremental_cbf;
                   2685: void         *context_icbf;
                   2686: TTcbf        *terminate_cbf;
                   2687: void         *context_tcbf;
1.191     cvs      2688: ThotBool      error_html;
1.198     cvs      2689: STRING        content_type;
1.4       cvs      2690: #endif
                   2691: {
                   2692:    AHTReqContext      *me;
1.198     cvs      2693:    STRING              ref;
1.206     cvs      2694:    STRING              esc_url;
1.107     cvs      2695:    int                 status, l;
1.114     cvs      2696:    int                 tempsubdir;
1.191     cvs      2697:    ThotBool            bool_tmp;
1.7       cvs      2698: 
1.116     cvs      2699:    if (urlName == NULL || docid == 0 || outputfile == NULL) 
                   2700:      {
                   2701:        /* no file to be loaded */
                   2702:        TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
1.69      cvs      2703:        
1.116     cvs      2704:        if (error_html)
1.69      cvs      2705:         /* so we can show the error message */
                   2706:         DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.116     cvs      2707:        InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
                   2708:                                    context_tcbf, HT_ERROR);
                   2709:        return HT_ERROR;
                   2710:      }
1.7       cvs      2711: 
1.159     cvs      2712:    /* if it's a 'docImage', we have already downloaded it */
1.198     cvs      2713:    if (!ustrncmp (TEXT("internal:"), urlName, 9)) 
1.159     cvs      2714:      {
1.198     cvs      2715:        ustrcpy (outputfile, urlName);
1.159     cvs      2716:        InvokeGetObjectWWW_callback (docid, urlName, outputfile,
                   2717:                                    terminate_cbf, context_tcbf, HT_OK);
                   2718:        return HT_OK;
                   2719:      }
                   2720: 
1.4       cvs      2721:    /* do we support this protocol? */
1.116     cvs      2722:    if (IsValidProtocol (urlName) == NO) 
                   2723:      {
                   2724:        /* return error */
                   2725:        outputfile[0] = EOS;    /* file could not be opened */
                   2726:        TtaSetStatus (docid, 1, 
                   2727:                     TtaGetMessage (AMAYA, AM_GET_UNSUPPORTED_PROTOCOL),
                   2728:                     urlName);
                   2729: 
                   2730:        if (error_html)
1.69      cvs      2731:         /* so we can show the error message */
                   2732:         DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.116     cvs      2733:        InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
                   2734:                                    context_tcbf, HT_ERROR);
                   2735:        return HT_ERROR;
                   2736:      }
1.4       cvs      2737: 
1.114     cvs      2738:    /* we store CSS in subdir named 0; all the other files go to a subidr
                   2739:       named after their own docid */
                   2740:    
                   2741:    tempsubdir = (mode & AMAYA_LOAD_CSS) ? 0 : docid;
                   2742: 
1.116     cvs      2743:    /* create a tempfilename */
1.198     cvs      2744:    usprintf (outputfile, TEXT("%s%c%d%c%04dAM"), TempFileDirectory, DIR_SEP, tempsubdir, DIR_SEP, object_counter);
1.116     cvs      2745:    /* update the object_counter (used for the tempfilename) */
1.4       cvs      2746:    object_counter++;
1.116     cvs      2747:    
1.4       cvs      2748:    /* normalize the URL */
1.206     cvs      2749:    esc_url = EscapeURL (urlName);
                   2750:    if (esc_url) 
                   2751:      {
                   2752:        ref = AmayaParseUrl (esc_url, _EMPTYSTR_, AMAYA_PARSE_ALL);
                   2753:        TtaFreeMemory (esc_url);
                   2754:      }
                   2755:    else
                   2756:      ref = NULL;
                   2757: 
1.4       cvs      2758:    /* should we abort the request if we could not normalize the url? */
1.198     cvs      2759:    if (ref == NULL || ref[0] == EOS) {
1.69      cvs      2760:       /*error */
                   2761:       outputfile[0] = EOS;
                   2762:       TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_BAD_URL), urlName);
1.214     cvs      2763:       if (ref)
                   2764:        TtaFreeMemory (ref); 
1.69      cvs      2765:       if (error_html)
1.116     cvs      2766:        /* so we can show the error message */
                   2767:        DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
1.99      cvs      2768:       InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
1.116     cvs      2769:                                   context_tcbf, HT_ERROR);
1.69      cvs      2770:       return HT_ERROR;
                   2771:    }
1.116     cvs      2772: 
1.4       cvs      2773:    /* verify if that file name existed */
1.9       cvs      2774:    if (TtaFileExist (outputfile))
1.77      cvs      2775:      TtaFileUnlink (outputfile);
1.116     cvs      2776:    
1.4       cvs      2777:    /* Initialize the request structure */
                   2778:    me = AHTReqContext_new (docid);
1.116     cvs      2779:    if (me == NULL) 
                   2780:      {
                   2781:        outputfile[0] = EOS;
                   2782:        /* need an error message here */
                   2783:        TtaFreeMemory (ref);
                   2784:        InvokeGetObjectWWW_callback (docid, urlName, outputfile, terminate_cbf,
                   2785:                                   context_tcbf, HT_ERROR);
                   2786:        return HT_ERROR;
                   2787:      }
                   2788: 
1.4       cvs      2789:    /* Specific initializations for POST and GET */
1.222     cvs      2790:    if (mode & AMAYA_FORM_POST
                   2791: #ifdef ANNOTATIONS
                   2792:        || mode & AMAYA_ANNOT_POST
                   2793: #endif /* ANNOTATIONS */
                   2794:        ) 
1.116     cvs      2795:      {
                   2796:        me->method = METHOD_POST;
                   2797:        HTRequest_setMethod (me->request, METHOD_POST);
                   2798:      }
                   2799:    else 
                   2800:      {
                   2801:        me->method = METHOD_GET;
                   2802:        if (!HasKnownFileSuffix (ref))
1.216     cvs      2803:         {
                   2804:           /* try to adjust the Accept header in an netwise economical way */
                   2805:           if (mode & AMAYA_LOAD_IMAGE)
                   2806:             AHTRequest_setCustomAcceptHeader (me->request, IMAGE_ACCEPT_NEGOTIATION);
                   2807:           else if (mode & AMAYA_LOAD_CSS)
                   2808:             AHTRequest_setCustomAcceptHeader (me->request, "*/*;q=0.1,css/*");
                   2809:           /*
                   2810:           HTRequest_setConversion(me->request, acceptTypes, TRUE);
                   2811:           */
                   2812:         }
                   2813:           HTRequest_setLanguage (me->request, acceptLanguages, TRUE);
1.116     cvs      2814:      }
1.93      cvs      2815: 
1.116     cvs      2816:    /* Common initialization for all HTML methods */
1.4       cvs      2817:    me->mode = mode;
                   2818:    me->error_html = error_html;
                   2819:    me->incremental_cbf = incremental_cbf;
                   2820:    me->context_icbf = context_icbf;
                   2821:    me->terminate_cbf = terminate_cbf;
                   2822:    me->context_tcbf = context_tcbf;
1.64      cvs      2823: 
1.69      cvs      2824:    /* for the async. request modes, we need to have our
1.4       cvs      2825:       own copy of outputfile and urlname
1.116     cvs      2826:       */
1.4       cvs      2827: 
1.116     cvs      2828:    if ((mode & AMAYA_ASYNC) || (mode & AMAYA_IASYNC)) 
                   2829:      {
1.198     cvs      2830:        l = ustrlen (outputfile);
1.116     cvs      2831:        if (l > MAX_LENGTH)
                   2832:         me->outputfile = TtaGetMemory (l + 2);
                   2833:        else
                   2834:         me->outputfile = TtaGetMemory (MAX_LENGTH + 2);
1.198     cvs      2835:        strcpy (me->outputfile, WideChar2ISO (outputfile));
                   2836:        l = ustrlen (urlName);
1.116     cvs      2837:        if (l > MAX_LENGTH)
                   2838:         me->urlName = TtaGetMemory (l + 2);
                   2839:        else
                   2840:         me->urlName = TtaGetMemory (MAX_LENGTH + 2);
1.198     cvs      2841:        strcpy (me->urlName, WideChar2ISO (urlName));
1.116     cvs      2842: #ifdef _WINDOWS
                   2843:      /* force windows ASYNC requests to always be non preemptive */
                   2844:      HTRequest_setPreemptive (me->request, NO);
                   2845: #endif /*_WINDOWS */
                   2846:      } /* AMAYA_ASYNC mode */ 
                   2847:    else 
                   2848: #ifdef _WINDOWS
                   2849:      {
1.198     cvs      2850:        me->outputfile = WideChar2ISO (outputfile);
                   2851:        me->urlName = WideChar2ISO (urlName);
1.116     cvs      2852:        /* force windows SYNC requests to always be non preemptive */
                   2853:        HTRequest_setPreemptive (me->request, YES);
                   2854:      }
                   2855: #else /* !_WINDOWS */
                   2856:      {
                   2857:        me->outputfile = outputfile;
                   2858:        me->urlName = urlName;
                   2859:      }
                   2860:    /***
1.136     cvs      2861:      In order to take into account the stop button, 
                   2862:      the requests will be always asynchronous, however, if mode=AMAYA_SYNC,
1.57      cvs      2863:      we will loop until the document has been received or a stop signal
                   2864:      generated
1.77      cvs      2865:      ****/
1.116     cvs      2866:    HTRequest_setPreemptive (me->request, NO);
                   2867: #endif /* _WINDOWS */
1.61      cvs      2868: 
1.151     cvs      2869:    /*
                   2870:    ** Make sure that the first request is flushed immediately and not
                   2871:    ** buffered in the output buffer
                   2872:    */
                   2873:    if (mode & AMAYA_FLUSH_REQUEST)
                   2874:      HTRequest_setFlush(me->request, YES);
                   2875:    HTRequest_setFlush(me->request, YES);
                   2876: 
1.61      cvs      2877:    /* prepare the URLname that will be displayed in teh status bar */
                   2878:    ChopURL (me->status_urlName, me->urlName);
1.77      cvs      2879:    TtaSetStatus (me->docid, 1, 
                   2880:                 TtaGetMessage (AMAYA, AM_FETCHING),
1.198     cvs      2881:                 ISO2WideChar (me->status_urlName));
1.4       cvs      2882: 
1.198     cvs      2883:    me->anchor = (HTParentAnchor *) HTAnchor_findAddress (WideChar2ISO (ref));
1.45      cvs      2884:    TtaFreeMemory (ref);
1.177     cvs      2885:    
1.223     cvs      2886:    TtaGetEnvBoolean ("CACHE_DISCONNECTED_MODE", &bool_tmp);
1.177     cvs      2887:    if (!bool_tmp && (mode & AMAYA_NOCACHE))
1.116     cvs      2888:       HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
                   2889: 
                   2890:    /* prepare the query string and format for POST */
                   2891:    if (mode & AMAYA_FORM_POST)
1.114     cvs      2892:      {
1.116     cvs      2893:        HTAnchor_setFormat ((HTParentAnchor *) me->anchor, 
                   2894:                           HTAtom_for ("application/x-www-form-urlencoded"));
                   2895:        HTAnchor_setLength ((HTParentAnchor *) me->anchor, me->block_size);
                   2896:        HTRequest_setEntityAnchor (me->request, me->anchor);
                   2897:      } 
1.114     cvs      2898: 
1.127     cvs      2899:    /* create the formdata element for libwww */
                   2900:    if (formdata)
                   2901:      me->formdata = PrepareFormdata (formdata);
                   2902: 
1.116     cvs      2903:    /* do the request */
                   2904:    if (mode & AMAYA_FORM_POST)
1.119     cvs      2905:      {
1.191     cvs      2906:        /* this call doesn't give back a ThotBool */
1.119     cvs      2907:        HTParentAnchor * posted = NULL;
                   2908: 
                   2909:        posted = HTPostFormAnchor (me->formdata, (HTAnchor *) me->anchor, 
                   2910:                                    me->request);
                   2911:        status = posted ? YES : NO; 
                   2912:      }
1.222     cvs      2913: #ifdef ANNOTATIONS
                   2914:    if (mode & AMAYA_ANNOT_POST)
                   2915:      {
                   2916:        /* @@@ a very ugly patch :))) */
                   2917:        HTParentAnchor * posted = NULL;
                   2918: 
                   2919:        me->source =  HTAnchor_findAddress (DocumentURLs[docid]);
                   2920:        HTAnchor_setFormat (HTAnchor_parent (me->source),
                   2921:                           HTAtom_for ("application/xml"));
                   2922:        posted = HTPostAnchor (HTAnchor_parent (me->source), 
                   2923:                              (HTAnchor *) me->anchor, 
                   2924:                              me->request);
                   2925:        status = posted ? YES : NO; 
                   2926:      }
                   2927: #endif /* ANNOTATIONS */
1.127     cvs      2928:    else if (formdata)
                   2929:      status = HTGetFormAnchor(me->formdata, (HTAnchor *) me->anchor,
                   2930:                              me->request);
1.116     cvs      2931:    else
1.77      cvs      2932:      status = HTLoadAnchor ((HTAnchor *) me->anchor, me->request);
1.69      cvs      2933: 
1.123     cvs      2934:    /* @@@ may need some special windows error msg here */
1.116     cvs      2935:    /* control the errors */
1.4       cvs      2936: 
1.130     cvs      2937:     if (status == NO)
1.116     cvs      2938:      /* the request invocation failed */
                   2939:      {
                   2940:        /* show an error message on the status bar */
                   2941:        DocNetworkStatus[docid] |= AMAYA_NET_ERROR;
                   2942:        TtaSetStatus (docid, 1, 
                   2943:                     TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
                   2944:                     urlName);
                   2945:        if (me->reqStatus == HT_NEW)
                   2946:         /* manually invoke the last processing that usually gets done
                   2947:            in a succesful request */
                   2948:         InvokeGetObjectWWW_callback (docid, urlName, outputfile, 
                   2949:                                      terminate_cbf, context_tcbf, HT_ERROR);
                   2950:        /* terminate_handler wasn't called */
1.136     cvs      2951:        AHTReqContext_delete (me);
1.116     cvs      2952:      }
                   2953:    else
1.136     cvs      2954:      /* end treatment for SYNC requests */
1.120     cvs      2955:      if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
                   2956:        {
1.136     cvs      2957:         /* wait here untilt the asynchronous request finishes */
1.130     cvs      2958:         status = LoopForStop (me);
1.136     cvs      2959:         /* if status returns HT_ERROR, should we invoke the callback? */
1.120     cvs      2960:         if (!HTRequest_kill (me->request))
                   2961:           AHTReqContext_delete (me);
                   2962:        }
1.130     cvs      2963: 
1.136     cvs      2964:     /* an interface problem!!! */
                   2965:     return (status == YES ? 0 : -1);
1.4       cvs      2966: }
                   2967: 
1.5       cvs      2968: /*----------------------------------------------------------------------
1.17      cvs      2969:    PutObjectWWW
                   2970:    frontend for uploading a resource to a URL. This function downloads
                   2971:    a file to be uploaded into memory, it then calls UploadMemWWW to
                   2972:    finish the job.
                   2973: 
1.5       cvs      2974:    2 upload modes are proposed:                                       
                   2975:    AMAYA_SYNC : blocking mode                            
                   2976:    AMAYA_ASYNC : non-blocking mode                       
                   2977:    
1.4       cvs      2978:    When the function is called with the SYNC mode, the function will
                   2979:    return only when the file has been uploaded.
                   2980:    The ASYNC mode will immediately return after setting up the
                   2981:    call. Furthermore, at the end of an upload, the ASYNC mode will 
                   2982:    call back terminate_cbf, handling it the context defined in
                   2983:    context_tcbf.
                   2984: 
                   2985:    Notes:
                   2986:    At the end of a succesful request, the urlName string contains the
                   2987:    name of the actually uploaded URL. As a URL can change over the time,
                   2988:    (e.g., be redirected elsewhere), it is advised that the function
                   2989:    caller verifies the value of the urlName variable at the end of
                   2990:    a request.
                   2991: 
                   2992:    Inputs:
                   2993:    - docid  Document identifier for the set of objects being
                   2994:    retrieved.
                   2995:    - fileName A pointer to the local file to upload
                   2996:    - urlName The URL to be uploaded (MAX_URL_LENGTH chars length)
                   2997:    - mode The retrieval mode.
                   2998:    - terminate_cbf 
                   2999:    - context_icbf
                   3000:    Callback and context for a terminate handler
                   3001: 
                   3002:    Outputs:
                   3003:    - urlName The URL that was uploaded
                   3004: 
                   3005:    Returns:
                   3006:    HT_ERROR
                   3007:    HT_OK
1.5       cvs      3008:   ----------------------------------------------------------------------*/
1.4       cvs      3009: #ifdef __STDC__
1.198     cvs      3010: int                 PutObjectWWW (int docid, STRING fileName, STRING urlName, int mode, PicType contentType,
1.4       cvs      3011:                                  TTcbf * terminate_cbf, void *context_tcbf)
                   3012: #else
1.26      cvs      3013: int                 PutObjectWWW (docid, urlName, fileName, mode, contentType,
1.4       cvs      3014:                                  ,terminate_cbf, context_tcbf)
                   3015: int                 docid;
1.198     cvs      3016: STRING              urlName;
                   3017: STRING              fileName;
1.4       cvs      3018: int                 mode;
1.27      cvs      3019: PicType             contentType;
1.4       cvs      3020: TTcbf              *terminate_cbf;
                   3021: void               *context_tcbf;
                   3022: 
1.116     cvs      3023: #endif /* __STDC__ */
1.4       cvs      3024: {
1.116     cvs      3025:    AHTReqContext      *me;
1.4       cvs      3026:    int                 status;
                   3027:    int                 fd;
                   3028:    struct stat         file_stat;
1.116     cvs      3029:    char               *fileURL;
1.168     cvs      3030:    char               *etag = NULL;
1.169     cvs      3031:    HTParentAnchor     *dest_anc_parent;
1.198     cvs      3032:    STRING              tmp;
1.206     cvs      3033:    STRING              esc_url;
1.168     cvs      3034:    int                 UsePreconditions;
1.191     cvs      3035:    ThotBool            lost_update_check = TRUE;
1.172     cvs      3036: 
                   3037:    /* should we protect the PUT against lost updates? */
1.203     cvs      3038:    tmp = TtaGetEnvString ("ENABLE_LOST_UPDATE_CHECK");
1.198     cvs      3039:    if (tmp && *tmp && ustrcasecmp (tmp, TEXT("yes")))
1.172     cvs      3040:      lost_update_check = FALSE;
1.168     cvs      3041: 
                   3042:    UsePreconditions = mode & AMAYA_USE_PRECONDITIONS;
1.4       cvs      3043: 
1.33      cvs      3044:    AmayaLastHTTPErrorMsg [0] = EOS;
                   3045:    
1.116     cvs      3046:    if (urlName == NULL || docid == 0 || fileName == NULL 
                   3047:        || !TtaFileExist (fileName))
1.4       cvs      3048:       /* no file to be uploaded */
                   3049:       return HT_ERROR;
                   3050: 
                   3051:    /* do we support this protocol? */
1.7       cvs      3052:    if (IsValidProtocol (urlName) == NO)
                   3053:      {
                   3054:        /* return error */
1.198     cvs      3055:        TtaSetStatus (docid, 1, TtaGetMessage (AMAYA, AM_PUT_UNSUPPORTED_PROTOCOL), urlName);
1.7       cvs      3056:        return HT_ERROR;
                   3057:      }
1.116     cvs      3058: 
                   3059:    /* verify the file's size */
                   3060: #ifndef _WINDOWS
1.7       cvs      3061:    if ((fd = open (fileName, O_RDONLY)) == -1)
1.116     cvs      3062: #else 
1.198     cvs      3063:    if ((fd = uopen (fileName, _O_RDONLY | _O_BINARY)) == -1)
1.116     cvs      3064: #endif /* _WINDOWS */
1.7       cvs      3065:      {
                   3066:        /* if we could not open the file, exit */
                   3067:        /*error msg here */
                   3068:        return (HT_ERROR);
                   3069:      }
1.4       cvs      3070: 
                   3071:    fstat (fd, &file_stat);
1.222     cvs      3072: #ifdef _WINDOWS
1.137     cvs      3073:    _close (fd);
1.222     cvs      3074: #else /* _WINDOWS */
1.116     cvs      3075:    close (fd);
1.222     cvs      3076: #endif /* _WINDOWS */
1.4       cvs      3077: 
1.7       cvs      3078:    if (file_stat.st_size == 0)
                   3079:      {
                   3080:        /* file was empty */
                   3081:        /*errmsg here */
                   3082:        return (HT_ERROR);
                   3083:      }
1.116     cvs      3084: 
                   3085:    /* prepare the request context */
1.4       cvs      3086:    if (THD_TRACE)
1.116     cvs      3087:       fprintf (stderr, "file size == %u\n", (unsigned) file_stat.st_size);
1.4       cvs      3088: 
                   3089:    me = AHTReqContext_new (docid);
1.7       cvs      3090:    if (me == NULL)
                   3091:      {
1.168     cvs      3092:        /* @@ need an error message here */
1.151     cvs      3093:        TtaHandlePendingEvents (); 
1.7       cvs      3094:        return (HT_ERROR);
1.208     cvs      3095:      }
                   3096: 
                   3097:    /*
                   3098:    ** Set up the original URL name
                   3099:    */
                   3100:    if (DocumentMeta[docid]->put_default_name)
                   3101:      {
                   3102:        char *ptr1, *ptr2;
                   3103:        ptr1 = TtaGetEnvString ("DEFAULTNAME");
                   3104:        if (ptr1 && *ptr1) 
                   3105:         {
                   3106:           ptr2 = strstr (urlName, ptr1);
                   3107:           if (ptr2) 
                   3108:             {
                   3109:               me->default_put_name = TtaStrdup (urlName);
                   3110:               me->default_put_name[strlen (me->default_put_name)
                   3111:                                   - strlen (ptr1)] = EOS;
                   3112:               HTRequest_setDefaultPutName (me->request, me->default_put_name);
                   3113:             }
                   3114:         }
1.7       cvs      3115:      }
1.116     cvs      3116: 
1.4       cvs      3117:    me->mode = mode;
                   3118:    me->incremental_cbf = (TIcbf *) NULL;
                   3119:    me->context_icbf = (void *) NULL;
                   3120:    me->terminate_cbf = terminate_cbf;
                   3121:    me->context_tcbf = context_tcbf;
1.206     cvs      3122:    esc_url = EscapeURL (urlName);
                   3123:    me->urlName = TtaStrdup (WideChar2ISO (esc_url));
                   3124:    TtaFreeMemory (esc_url);
1.116     cvs      3125:    me->block_size =  file_stat.st_size;
1.17      cvs      3126:    /* select the parameters that distinguish a PUT from a GET/POST */
1.4       cvs      3127:    me->method = METHOD_PUT;
                   3128:    me->output = stdout;
1.17      cvs      3129:    /* we are not expecting to receive any input from the server */
                   3130:    me->outputfile = (char *) NULL; 
1.4       cvs      3131: 
1.134     cvs      3132: #ifdef _WINDOWS
                   3133:    /* libwww's HTParse function doesn't take into account the drive name;
1.168     cvs      3134:       so we sidestep it */
1.134     cvs      3135:    fileURL = NULL;
                   3136:    StrAllocCopy (fileURL, "file:");
1.198     cvs      3137:    StrAllocCat (fileURL, WideChar2ISO (fileName));
1.134     cvs      3138: #else
1.116     cvs      3139:    fileURL = HTParse (fileName, "file:/", PARSE_ALL);
1.134     cvs      3140: #endif /* _WINDOWS */
1.168     cvs      3141:    me->source = HTAnchor_findAddress (fileURL);
1.116     cvs      3142:    HT_FREE (fileURL);
1.206     cvs      3143:    me->dest = HTAnchor_findAddress (me->urlName);
1.169     cvs      3144:    /* we memorize the anchor's parent @ as we use it a number of times
                   3145:       in the following lines */
                   3146:    dest_anc_parent = HTAnchor_parent (me->dest);
1.168     cvs      3147: 
1.169     cvs      3148:    /*
                   3149:    **  Set the Content-Type of the file we are uploading 
                   3150:    */
                   3151:    /* we try to use any content-type previosuly associated
                   3152:       with the parent. If it doesn't exist, we try to guess it
                   3153:       from the URL */
1.198     cvs      3154:    tmp = ISO2WideChar (HTAtom_name (HTAnchor_format (dest_anc_parent)));
                   3155:    if (!tmp || !ustrcmp (tmp, TEXT("www/unknown")))
1.169     cvs      3156:      {
1.198     cvs      3157:        HTAnchor_setFormat (dest_anc_parent, AHTGuessAtom_for (ISO2WideChar (me->urlName), contentType));
                   3158:        tmp = ISO2WideChar (HTAtom_name (HTAnchor_format (dest_anc_parent)));
1.169     cvs      3159:      }
                   3160:    /* .. and we give the same type to the source anchor */
                   3161:    /* we go thru setOutputFormat, rather than change the parent's
                   3162:       anchor, as that's the place that libwww expects it to be */
1.170     cvs      3163:    HTAnchor_setFormat (HTAnchor_parent (me->source),
1.198     cvs      3164:                       HTAtom_for (WideChar2ISO (tmp)));
1.219     cvs      3165: 
1.169     cvs      3166:    HTRequest_setOutputFormat (me->request,
1.198     cvs      3167:                              HTAtom_for (WideChar2ISO (tmp)));
1.219     cvs      3168: 
                   3169: #if 0 /* JK: code ready, but we're not going to use it yet */
                   3170:    /*
                   3171:    **  Set the Charset of the file we are uploading 
                   3172:    */
                   3173:    /* we try to use any charset previosuly associated
                   3174:       with the parent. If it doesn't exist, we try to guess it
                   3175:       from the metadata */
                   3176:    tmp = ISO2WideChar (HTAtom_name (HTAnchor_charset (dest_anc_parent)));
                   3177:    if (!tmp)
                   3178:      {
                   3179:        HTAnchor_setCharset (dest_anc_parent, HTAtom_for ("iso-8859-3"));
                   3180:        tmp = ISO2WideChar (HTAtom_name (HTAnchor_charset (dest_anc_parent)));
                   3181:      }
                   3182:    /* .. and we give the same charset to the source anchor */
                   3183:    /* we go thru setCharSet, rather than change the parent's
                   3184:       anchor, as that's the place that libwww expects it to be */
                   3185:    HTAnchor_setCharset (HTAnchor_parent (me->source),
                   3186:                        HTAtom_for (WideChar2ISO (tmp)));
                   3187: #endif /* CHARSET */
                   3188: 
                   3189:    /*
                   3190:    ** define other request characteristics
                   3191:    */
1.116     cvs      3192: #ifdef _WINDOWS
1.136     cvs      3193:    HTRequest_setPreemptive (me->request, NO);
1.116     cvs      3194: #else
1.134     cvs      3195:    HTRequest_setPreemptive (me->request, NO);
1.116     cvs      3196: #endif /* _WINDOWS */
                   3197: 
1.151     cvs      3198:    /*
                   3199:    ** Make sure that the first request is flushed immediately and not
                   3200:    ** buffered in the output buffer
                   3201:    */
                   3202:    if (mode & AMAYA_FLUSH_REQUEST)
                   3203:      HTRequest_setFlush(me->request, YES);
1.168     cvs      3204:    
                   3205:    /* Should we use preconditions? */
1.172     cvs      3206:    if (lost_update_check)
1.168     cvs      3207:      {
1.172     cvs      3208:        if (UsePreconditions) 
                   3209:         etag = HTAnchor_etag (HTAnchor_parent (me->dest));
                   3210:        
                   3211:        if (etag) 
                   3212:         {
                   3213:           HTRequest_setPreconditions(me->request, HT_MATCH_THIS);
                   3214:         }
                   3215:        else
                   3216:         {
                   3217:           HTRequest_setPreconditions(me->request, HT_NO_MATCH);
                   3218:           HTRequest_addAfter(me->request, check_handler, NULL, NULL, HT_ALL,
                   3219:                              HT_FILTER_MIDDLE, YES);
1.175     cvs      3220:           HTRequest_addAfter (me->request, HTAuthFilter, "http://*", NULL, 
                   3221:                               HT_NO_ACCESS, HT_FILTER_MIDDLE, YES);
                   3222:           HTRequest_addAfter (me->request, HTAuthFilter, "http://*", NULL,
                   3223:                               HT_REAUTH, HT_FILTER_MIDDLE, YES);
                   3224:           HTRequest_addAfter (me->request, HTAuthInfoFilter, "http://*", NULL,
                   3225:                               HT_ALL, HT_FILTER_MIDDLE, YES);
                   3226:           HTRequest_addAfter (me->request, HTUseProxyFilter, "http://*", NULL,
                   3227:                               HT_USE_PROXY, HT_FILTER_MIDDLE, YES);
1.172     cvs      3228:         }
1.168     cvs      3229:      }
                   3230:    else
                   3231:      {
1.172     cvs      3232:        /* don't use preconditions */
1.168     cvs      3233:        HTRequest_setPreconditions(me->request, HT_NO_MATCH);
                   3234:      }
1.151     cvs      3235:    
1.136     cvs      3236:    /* don't use the cache while saving a document */
                   3237:    HTRequest_setReloadMode (me->request, HT_CACHE_FLUSH);
1.116     cvs      3238: 
1.164     cvs      3239:    /* Throw away any reponse body */
                   3240:    /*
                   3241:    HTRequest_setOutputStream (me->request, HTBlackHole());        
                   3242:    */
                   3243: 
1.168     cvs      3244:    /* prepare the URLname that will be displayed in the status bar */
1.74      cvs      3245:    ChopURL (me->status_urlName, me->urlName);
1.198     cvs      3246:    TtaSetStatus (me->docid, 1, TtaGetMessage (AMAYA, AM_REMOTE_SAVING), ISO2WideChar (me->status_urlName));
1.114     cvs      3247: 
1.164     cvs      3248:    /* make the request */
1.172     cvs      3249:    if (lost_update_check && (!UsePreconditions || !etag))
1.168     cvs      3250:      status = HTHeadAnchor (me->dest, me->request);
                   3251:    else
                   3252:      status = HTPutDocumentAnchor (HTAnchor_parent (me->source), me->dest, me->request);
1.4       cvs      3253: 
1.130     cvs      3254:    if (status == YES && me->reqStatus != HT_ERR)
1.7       cvs      3255:      {
1.168     cvs      3256:        /* part of the stop button handler */
                   3257:        if ((mode & AMAYA_SYNC) || (mode & AMAYA_ISYNC))
                   3258:         status = LoopForStop (me);
1.15      cvs      3259:      }
1.136     cvs      3260:    if (!HTRequest_kill (me->request))
                   3261:      AHTReqContext_delete (me);
1.168     cvs      3262:    
1.116     cvs      3263:    TtaHandlePendingEvents ();
1.90      cvs      3264: 
1.130     cvs      3265:    return (status == YES ? 0 : -1);
1.28      cvs      3266: }
1.4       cvs      3267: 
1.5       cvs      3268: /*----------------------------------------------------------------------
1.138     cvs      3269:   StopRequest
1.17      cvs      3270:   stops (kills) all active requests associated with a docid 
1.5       cvs      3271:   ----------------------------------------------------------------------*/
1.4       cvs      3272: #ifdef __STDC__
                   3273: void                StopRequest (int docid)
                   3274: #else
                   3275: void                StopRequest (docid)
                   3276: int                 docid;
                   3277: #endif
                   3278: {
1.140     cvs      3279:    if (Amaya && CanDoStop ())
1.138     cvs      3280:      { 
1.139     cvs      3281: #if 0 /* for later */
1.140     cvs      3282:        AHTDocId_Status    *docid_status;
                   3283:         /* verify if there are any requests at all associated with docid */
1.138     cvs      3284:        docid_status = (AHTDocId_Status *) GetDocIdStatus (docid,
                   3285:                                                          Amaya->docid_status);
                   3286:        if (docid_status == (AHTDocId_Status *) NULL)
                   3287:         return;
1.139     cvs      3288: #endif /* 0 */
1.138     cvs      3289:        /* temporary call to stop all requests, as libwww changed its API */
                   3290:        StopAllRequests (docid);
                   3291:      }
                   3292: }
                   3293: 
1.190     cvs      3294: /* @@@ the docid parameter isn't used... clean it up */
1.138     cvs      3295: /*----------------------------------------------------------------------
                   3296:   StopAllRequests
                   3297:   stops (kills) all active requests. We use the docid 
                   3298:   ----------------------------------------------------------------------*/
                   3299: #ifdef __STDC__
                   3300: void                StopAllRequests (int docid)
                   3301: #else
1.140     cvs      3302: void                StopAllRequests (docid)
1.138     cvs      3303: int                 docid;
                   3304: #endif
                   3305: {
1.4       cvs      3306:    HTList             *cur;
                   3307:    AHTReqContext      *me;
1.191     cvs      3308:    static ThotBool     lock_stop = 0;
                   3309:    ThotBool            async_flag;
1.116     cvs      3310: 
1.138     cvs      3311:    /* only do the stop if we're not being called while processing a 
1.146     cvs      3312:       request, and if we're not already dealing with a stop */
                   3313:    if (Amaya && CanDoStop () && !lock_stop)
1.7       cvs      3314:      {
1.100     cvs      3315: #ifdef DEBUG_LIBWWW
1.138     cvs      3316:        fprintf (stderr, "StopRequest: number of Amaya requests "
                   3317:                "before kill: %d\n", Amaya->open_requests);
1.100     cvs      3318: #endif /* DEBUG_LIBWWW */
1.150     cvs      3319:        /* enter the critical section */
1.146     cvs      3320:        lock_stop = TRUE; 
1.214     cvs      3321:        /* set a module global variable so that we can do special
                   3322:          processing easier */
                   3323:        UserAborted_flag = TRUE;
1.164     cvs      3324:        /* expire all outstanding timers */
                   3325:        HTTimer_expireAll ();
1.160     cvs      3326:        /* HTNet_killAll (); */
1.116     cvs      3327:        cur = Amaya->reqlist;
                   3328:        while ((me = (AHTReqContext *) HTList_nextObject (cur))) 
                   3329:         {
1.140     cvs      3330:           if (AmayaIsAlive ())
1.160     cvs      3331:             {
1.161     cvs      3332: #ifdef DEBUG_LIBWWW
1.163     cvs      3333:               fprintf (stderr,"StopRequest: killing req %p, url %s, status %d\n", me, me->urlName, me->reqStatus);
1.161     cvs      3334: #endif /* DEBUG_LIBWWW */
                   3335: 
1.165     cvs      3336:               if (me->reqStatus != HT_END && me->reqStatus != HT_ABORT)
1.163     cvs      3337:                 {
                   3338:                   if ((me->mode & AMAYA_ASYNC)
                   3339:                       || (me->mode & AMAYA_IASYNC))
                   3340:                     async_flag = TRUE;
                   3341:                   else
                   3342:                     async_flag = FALSE;
                   3343: 
1.165     cvs      3344:                   /* change the status to say that the request aborted */
                   3345:                   me->reqStatus = HT_ABORT;
                   3346: 
1.163     cvs      3347:                   /* kill the request, using the appropriate function */
                   3348:                   if (me->request->net)
                   3349:                       HTNet_killPipe (me->request->net);
                   3350:                   else
                   3351:                     {
1.160     cvs      3352:                       if (me->terminate_cbf)
1.198     cvs      3353:                         (*me->terminate_cbf) (me->docid, -1, ISO2WideChar (me->urlName),
                   3354:                                               ISO2WideChar (me->outputfile),
                   3355:                                               ISO2WideChar (me->content_type), 
1.160     cvs      3356:                                               me->context_tcbf);
1.164     cvs      3357: 
                   3358:                       if (async_flag) 
1.165     cvs      3359:                         /* explicitly free the request context for async
                   3360:                          requests. The sync requests context is freed by LoopForStop */
1.164     cvs      3361:                           AHTReqContext_delete (me);
1.160     cvs      3362:                     }
1.163     cvs      3363:                   cur = Amaya->reqlist;
                   3364:                 }
1.142     cvs      3365: #ifndef _WINDOWS
                   3366: #ifdef WWW_XWINDOWS
1.140     cvs      3367:           /* to be on the safe side, remove all outstanding X events */
1.160     cvs      3368:                   else 
                   3369:                     RequestKillAllXtevents (me);
1.142     cvs      3370: #endif /* WWW_XWINDOWS */
                   3371: #endif /* !_WINDOWS */
1.160     cvs      3372:             }
1.116     cvs      3373:         }
1.150     cvs      3374:        /* Delete remaining channels */
                   3375:        HTChannel_safeDeleteAll ();
1.214     cvs      3376:        /* reset the stop status */
                   3377:        UserAborted_flag = FALSE;
1.150     cvs      3378:        /* exit the critical section */
1.148     cvs      3379:        lock_stop = FALSE; 
1.100     cvs      3380: #ifdef DEBUG_LIBWWW
1.138     cvs      3381:        fprintf (stderr, "StopRequest: number of Amaya requests "
                   3382:                "after kill: %d\n", Amaya->open_requests);
1.100     cvs      3383: #endif /* DEBUG_LIBWWW */
1.138     cvs      3384:      }
                   3385: } /* StopAllRequests */
1.17      cvs      3386: 
                   3387: 
1.105     cvs      3388: /*----------------------------------------------------------------------
                   3389:   AmayaIsAlive
1.140     cvs      3390:   returns the value of the AmayaAlive_flag
1.105     cvs      3391:   ----------------------------------------------------------------------*/
                   3392: #ifdef __STDC__
1.191     cvs      3393: ThotBool AmayaIsAlive (void)
1.105     cvs      3394: #else
1.191     cvs      3395: ThotBool AmayaIsAlive ()
1.105     cvs      3396: #endif /* _STDC_ */
                   3397: {
1.140     cvs      3398:   return AmayaAlive_flag;
                   3399: }
                   3400: 
                   3401: /*----------------------------------------------------------------------
                   3402:   CanDoStop
                   3403:   returns the value of the CanDoStop flag
                   3404:   ----------------------------------------------------------------------*/
                   3405: #ifdef __STDC__
1.191     cvs      3406: ThotBool CanDoStop (void)
1.140     cvs      3407: #else
1.191     cvs      3408: ThotBool CanDoStop ()
1.140     cvs      3409: #endif /* _STDC_ */
                   3410: {
                   3411:   return CanDoStop_flag;
                   3412: }
                   3413: 
                   3414: /*----------------------------------------------------------------------
                   3415:   CanDoStop_set
                   3416:   sets the value of the CanDoStop flag
                   3417:   ----------------------------------------------------------------------*/
                   3418: #ifdef __STDC__
1.191     cvs      3419: void CanDoStop_set (ThotBool value)
1.140     cvs      3420: #else
                   3421: void CanDoStop (value)
1.191     cvs      3422: ThotBool value;
1.140     cvs      3423: #endif /* _STDC_ */
                   3424: {
                   3425:   CanDoStop_flag = value;
1.176     cvs      3426: }
                   3427: 
                   3428: #ifdef __STDC__
                   3429: void libwww_updateNetworkConf (int status)
                   3430: #else
                   3431: void libwww_updateNetworkConf (status)
                   3432: int status;
                   3433: #endif /*__STDC__*/
                   3434: {
                   3435:   /* @@@ the docid parameter isn't used... clean it up */
                   3436:   int docid = 1;
                   3437: 
                   3438:   /* first, stop all current requests, as the network
                   3439:    may make some changes */
                   3440:   StopAllRequests (docid);
1.207     cvs      3441: 
                   3442:   if (status & AMAYA_SAFEPUT_RESTART)
                   3443:     { 
                   3444:       SafePut_delete ();
                   3445:       SafePut_init ();
                   3446:     }
1.176     cvs      3447: 
                   3448:   if (status & AMAYA_PROXY_RESTART)
                   3449:     {
                   3450:       HTProxy_deleteAll ();
                   3451:       ProxyInit ();
                   3452:     }
                   3453: 
                   3454:   if (status & AMAYA_CACHE_RESTART)
                   3455:     {
                   3456:       clear_cachelock ();
                   3457:       HTCacheTerminate ();
                   3458:       HTCacheMode_setEnabled (NO);
                   3459:       CacheInit ();
                   3460:     }
1.193     cvs      3461: 
                   3462:   if (status & AMAYA_LANNEG_RESTART)
                   3463:     {
                   3464:       /* clear the current values */
                   3465:       if (acceptLanguages)
                   3466:        HTLanguage_deleteAll (acceptLanguages);
                   3467:       /* read in the new ones */
                   3468:       acceptLanguages = HTList_new ();
                   3469:       AHTAcceptLanguagesInit (acceptLanguages);
                   3470:     }
1.105     cvs      3471: }
1.116     cvs      3472: 
1.69      cvs      3473: #endif /* AMAYA_JAVA */
1.77      cvs      3474: 
1.116     cvs      3475: /*
                   3476:   end of Module query.c
                   3477: */

Webmaster