Esempio n. 1
0
/*
** UNLOCK requests
*/
PRIVATE BOOL unlock_request (Cmdline * arg ) {
        
    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * dst = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor *base = NULL;
    BOOL status = NO;

    if (arg->arg1) {
        HTPrint ("Adding Lock-Token header %s\n",arg->arg1);
        HTDAV_setLockTokenHeader (headers,arg->arg1);
    }
        
    if (arg->base_str && *(arg->base_str)) 
            base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);
                
    /* chose func */
    switch (arg->func) {
        case 1: status = HTUNLOCKAnchor (request,dst,headers);
                break;
        case 2: status = HTUNLOCKAbsolute (request,arg->request_uri,headers);
                break;
        case 3: status = HTUNLOCKRelative (request,arg->request_uri,base,headers);
                break;
                    
    }

    return status;
}
Esempio n. 2
0
/*
** MKCOL requests
*/
PRIVATE BOOL mkcol_request (Cmdline * arg) {
    BOOL status = NO;
    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * dst = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor *base = NULL;
    
    if (arg->base_str && *arg->base_str) {
        base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);
    } 

    if (arg->I && *(arg->I)) {
        HTPrint ("If header: %s\n",arg->I);
        HTDAV_setIfHeader (headers,arg->I);
    }

    switch (arg->func) {
        case 1: status = HTMKCOLAnchor (request,dst,headers);
                break; 
        case 2: status = HTMKCOLAbsolute (request,arg->request_uri,headers);
                break; 
        case 3: status = HTMKCOLRelative (request,arg->request_uri,base,headers);
                break; 
    }    

    return status;
}
Esempio n. 3
0
/*
** LOCK requests
*/
PRIVATE BOOL lock_request (Cmdline * arg) {

    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * dst = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor * src = NULL;
    HTParentAnchor * base = NULL;
    BOOL status = NO;
    char * data = NULL;
        
    if (arg->I) {
        HTPrint ("Adding If header %s\n",arg->I);
        HTDAV_setIfHeader (headers,arg->I);
    }

    if (arg->arg1)  {
        data = create_body (arg->arg1);
        HTPrint ("xml body  %s\n",data);
           
        /* chose the func */
        if (arg->func==1) {
            src = HTTmpAnchor(NULL);
            HTAnchor_setDocument(src, data);
            HTAnchor_setFormat(src, HTAtom_for ("text/xml"));
            HTAnchor_setLength(src, strlen(data));
        } 
    }

    if (arg->base_str && *(arg->base_str)) 
        base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);

    if (arg->D) HTDAV_setDepthHeader (headers,arg->D);
    if (arg->T) HTDAV_setTimeoutHeader (headers,arg->T);

    HTPrint ("function %d src? %s\n",arg->func,(src)?"yes":"no");

    switch (arg->func) {
        case 1: status = HTLOCKDocumentAnchor (request,dst,src,headers);
                break;
        case 2: status = HTLOCKAnchor (request,dst,data,headers);
                break;
        case 3: status = HTLOCKAbsolute (request,arg->request_uri,data,headers);
                break;
        case 4: status = HTLOCKRelative (request,arg->request_uri,base,data,headers);
                break;
    }

    return status;
}
Esempio n. 4
0
// Operations
BOOL CLinks::AddLinkRelationships (HTAnchor * source)
{
    ASSERT(source != NULL);
    if (!m_hWnd) return FALSE;
    HTParentAnchor * src = HTAnchor_parent(source);

    // Update the list control with three columns
    CListCtrl &ListCtrl = m_pLinkList->GetListCtrl();
    int iItem = ListCtrl.GetItemCount();
    int cnt;
    for (cnt=0; cnt<iItem; cnt++) {
        CString l_type = ListCtrl.GetItemText(cnt, 0);
        CString l_dir = ListCtrl.GetItemText(cnt, 1);
        CString l_dest = ListCtrl.GetItemText(cnt, 2);
        
        if (!l_type.IsEmpty() && !l_dir.IsEmpty() && !l_dest.IsEmpty()) {
            char * link_addr = HTParse(l_dest, "", PARSE_ALL);
            HTParentAnchor * dest = HTAnchor_parent(HTAnchor_findAddress(link_addr));
            
            /* Now add the new relation */
            if (l_dir == "forward") {
                HTLink_add((HTAnchor *) src, (HTAnchor *) dest,
                    (HTLinkType) HTAtom_caseFor(l_type),
                    METHOD_INVALID);
            } else if (l_dir == "reverse") {
                HTLink_add((HTAnchor *) dest, (HTAnchor *) src,
                    (HTLinkType) HTAtom_caseFor(l_type),
                    METHOD_INVALID);
            } else
                ASSERT(1);
        }
    }
    return TRUE;
}
Esempio n. 5
0
int main (int argc, char ** argv)
{
    HTRequest * request = NULL;
    HTAnchor * anchor = NULL;
    char * uri = NULL;

    /* Create a new premptive client */
    HTProfile_newNoCacheClient("UpgradeApp", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /* Set trace messages and alert messages*/
#if 0
    HTSetTraceMessageMask("sop");
#endif

    /* Add our own AFTER filter to terminate the app */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Don't ask - don't tell */
    HTAlert_setInteractive(NO);

    /* Setup a timeout on the request for 15 secs */
    HTHost_setEventTimeout(15000);

    /* Handle command line args */
    if (argc >= 2) uri = argv[1];

    if (uri && *uri) {

	/* Create a request */
	request = HTRequest_new();

	/* Get an anchor object for the URI */
	anchor = HTAnchor_findAddress(uri);

	/* Get the source stream asis */
	HTRequest_setOutputFormat(request, WWW_SOURCE);

	/* Get the source stream asis */
	HTRequest_setOutputStream(request, HTFWriter_new(request, stdout, YES));

	/* Issue the GET */
	if (HTLoadAnchor(anchor, request)) {

	    /* Go into the event loop... */
	    HTEventList_newLoop();
	}

    } else {
	HTPrint("Type the URI to get (to test for upgrade).\n");
	HTPrint("If an 101 Switching Protocols status is recieved\n");
        HTPrint("then print everything following to stdout.\n\n");
	HTPrint("\t%s <uri>\n", argv[0]);
    }

    return 0;
}
Esempio n. 6
0
int postURL_tcl(ClientData clientData, Tcl_Interp *interp, 
		int argc, char **argv) {

    if (argc == 3) {
	char *url 	      = argv[1];
	char *dest 	      = argv[2];
	if (url && dest) {

	    HTParentAnchor *source = (HTParentAnchor *) HTAnchor_findAddress(url);
	    HTRequest *req    = HTRequest_new();
	    HTChunk *chunk	= HTChunk_new(0x2000);
	    HTStream *stream = HTStreamToChunk(req, &chunk, 0);
	    BOOL work;
	    HTRequest_setOutputFormat(req, DEFAULT_FORMAT);
	    HTRequest_setOutputStream(req, stream);
	    HTRequest_setPreemptive(req, YES);
	    work = HTPostAbsolute (source, dest, req);

	    Tcl_AppendResult(interp, work ? "YES" : "NO", HTChunkData(chunk), NULL);
	    HT_FREE(url);
	    HTRequest_kill(req);
	    HTAnchor_delete(source);
	    HT_FREE(stream);
	    HTChunkFree(chunk);
	    return TCL_OK;
	}
	Tcl_AppendResult(interp, bad_vars, NULL);
	return TCL_ERROR;
    }
    else {
	Tcl_AppendResult(interp, err_string, argv[0], " url destination", NULL);
	return TCL_ERROR;
    }
}
Esempio n. 7
0
/*
** MOVE requests
*/
PRIVATE BOOL move_request ( Cmdline * arg ) { 
        
    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * src = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor * body = NULL;
    HTParentAnchor * base = NULL;
    BOOL status = NO;
        
    if (arg->arg1) {
       HTPrint ("Adding Destination header %s\n",arg->arg1);
       HTDAV_setDestinationHeader (headers,arg->arg1);
    }
        
    if (arg->I) {
       HTPrint ("Adding If header %s\n",arg->I);
       HTDAV_setIfHeader (headers,arg->I);
    }

    /* chose the func */
    if (arg->func==2 && arg->arg2 ) {
        body = HTTmpAnchor(NULL);
        HTAnchor_setDocument(body, arg->arg2);
        HTAnchor_setFormat(body, HTAtom_for ("text/xml"));
        HTAnchor_setLength(body, strlen(arg->arg2));                
     } 

    if (arg->base_str && *(arg->base_str)) 
        base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);

    if (arg->D) HTDAV_setDepthHeader (headers,arg->D);
    if (arg->O == 'T') HTDAV_setOverwriteHeader (headers,YES);
    else if (arg->O == 'F') HTDAV_setOverwriteHeader (headers,NO);

    switch (arg->func) {
        case 1: status = HTMOVEAnchor (request,src,arg->arg2,headers);
                break;
        case 2: status = HTMOVEDocumentAnchor (request,src,body,headers);
                break;
        case 3: status = HTMOVEAbsolute (request,arg->request_uri,arg->arg2, headers);
                break;
        case 4: status = HTMOVERelative (request,arg->request_uri,base,arg->arg2,headers);
                break;
    }

    return status;
}
Esempio n. 8
0
int main (int argc, char ** argv)
{
    char * uri = NULL;

    /* Create a new premptive client */
    HTProfile_newHTMLNoCacheClient ("ShowLinks", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);
    
    /* Set trace messages and alert messages */
#if 0
    HTSetTraceMessageMask("sop");
#endif

    /* Add our own termination filter */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /*
    ** Register our HTML link handler. We don't actually create a HText
    ** object as this is not needed. We only register the specific link
    ** callback.
    */
    HText_registerLinkCallback(foundLink);

    /* Setup a timeout on the request for 15 secs */
    HTHost_setEventTimeout(15000);

    /* Handle command line args */
    if (argc >= 2)
	uri = HTParse(argv[1], NULL, PARSE_ALL);

    if (uri) {
	HTRequest * request = NULL;
	HTAnchor * anchor = NULL;
	BOOL status = NO;

	/* Create a request */
	request = HTRequest_new();

	/* Get an anchor object for the URI */
	anchor = HTAnchor_findAddress(uri);

	/* Issue the GET and store the result in a chunk */
	status = HTLoadAnchor(anchor, request);

	/* Go into the event loop... */
	if (status == YES) HTEventList_loop(request);

    } else {
	HTPrint("Type the URI to print out a list of embedded links\n");
	HTPrint("\t%s <uri>\n", argv[0]);
	HTPrint("For example:\n");
	HTPrint("\t%s http://www.w3.org\n", argv[0]);
    }

    return 0;
}
Esempio n. 9
0
/*
** PROPPATCH requests
*/
PRIVATE BOOL proppatch_request (Cmdline * arg) {
    BOOL status = NO;
    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * dst = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor *base = NULL;
    HTParentAnchor *src = NULL;
    char * xmlbody = NULL;
    
    if (arg->arg1 && *(arg->arg1)) 
        xmlbody = arg->arg1;        
    else 
        return NO;
    
    HTPrint ("xml body **%s**\n",xmlbody);        
    
    if (arg->func==2) {
        src = HTTmpAnchor(NULL);
        HTAnchor_setDocument(src, xmlbody);
        HTAnchor_setFormat(src, HTAtom_for ("text/xml"));
        HTAnchor_setLength(src, strlen(xmlbody));                
    } 

    if (arg->base_str && *(arg->base_str)) 
        base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);

    HTPrint ("setting headers\n");
    if (arg->I && *(arg->I)) {           
        HTPrint ("Adding If header %s\n",arg->I);
        HTDAV_setIfHeader (headers,arg->I);
    }

    HTPrint ("Chosing func\n");
    switch (arg->func) {
        case 1: status = HTPROPPATCHAnchor (request,dst,xmlbody,headers);
                break; 
        case 2: status = HTPROPPATCHDocumentAnchor (request,dst,src,headers);
                break; 
        case 3: status = HTPROPPATCHAbsolute (request,arg->request_uri,xmlbody,headers);
                break; 
        case 4: status = HTPROPPATCHRelative (request,arg->request_uri,base,xmlbody,headers);
                break; 
    }    

    return status;
}
Esempio n. 10
0
/*
** PROPFIND requests
*/
PRIVATE BOOL propfind_request (Cmdline * arg) {
    BOOL status = NO;
    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * dst = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor *base = NULL;
    HTParentAnchor *src = NULL;
    char * xmlbody = NULL;

    /* chose the func */
    HTPrint ("should we set the xml body?\n");
    if (arg->arg1 && *(arg->arg1)) {
        if (!strcasecomp (arg->arg1,"allprop") || !strcasecomp (arg->arg1,"propname")) 
            xmlbody = create_propbody (arg->arg1);
        else
            xmlbody = arg->arg1;
        HTPrint ("xml body %s\n",xmlbody);        
    }        
    
    if (arg->func==2 && xmlbody && *xmlbody) {
        src = HTTmpAnchor(NULL);
        HTAnchor_setDocument(src, xmlbody);
        HTAnchor_setFormat(src, HTAtom_for ("text/xml"));
        HTAnchor_setLength(src, strlen(xmlbody));                
    } 

    if (arg->base_str && *(arg->base_str)) 
        base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);

    HTPrint ("setting headers\n");
    if (arg->D) HTDAV_setDepthHeader (headers,arg->D);


    switch (arg->func) {
        case 1: status = HTPROPFINDAnchor (request,dst,xmlbody,headers);
                break; 
        case 2: status = HTPROPFINDDocumentAnchor (request,dst,src,headers);
                break; 
        case 3: status = HTPROPFINDAbsolute (request,arg->request_uri,xmlbody,headers);
                break; 
        case 4: status = HTPROPFINDRelative (request,arg->request_uri,base,xmlbody,headers);
                break; 
    }    

    return status;
}
Esempio n. 11
0
int getURL_tcl(ClientData clientData, Tcl_Interp *interp, 
 	       int argc, char **argv)
{
    if (argc >= 3) {
	char *listcheck = argv[1];
	char *url       = argv[2];
	char * traceflags = argc==4 ? argv[3] : "";
    
	if (url && (strcmp(listcheck, "listrefs")==0)) {

	    /* Create a new robot object */
	    Robot *robot = Robot_new();

	    /* Turn on trace messages */
	    if (argc==4) HTSetTraceMessageMask(traceflags);

	    /* Set up the HTML parser */
	    {
		HTList * converters = HTFormat_conversion();
		HTMLInit(converters);
	    }

	    /* Find an anchor and load it */
	    robot->anchor = (HTParentAnchor *) HTAnchor_findAddress(url);
	    HTLoadAnchor((HTAnchor *) robot->anchor, robot->request);

	    /* Update TcL return */
	    Tcl_AppendResult(interp, Reference_List(robot), NULL);
	    Robot_delete(robot);
	    return TCL_OK;
	}
	Tcl_AppendResult(interp, bad_vars, NULL);
	return TCL_ERROR;
    } 
    if (argc == 2) {
	char *url = argv[1];
    
	if (url) {
	    /* Create a new robot object */
	    Robot *robot = Robot_new();
	    HTChunk *chunk = 0;

	    /* Find an anchor and load it */
	    HTRequest_setOutputFormat(robot->request, WWW_SOURCE);
	    chunk = HTLoadToChunk(url, robot->request);

	    /* Update TcL return */
	    Tcl_AppendResult(interp, HTChunkData(chunk), NULL);
	    Robot_delete(robot);
	    HTChunk_delete(chunk);
	    return TCL_OK;
	}
	Tcl_AppendResult(interp, bad_vars, NULL);
	return TCL_ERROR;
    }
    Tcl_AppendResult(interp, err_string, argv[0], " [listrefs] url traceflags", NULL);
    return TCL_ERROR;
}	
Esempio n. 12
0
BinURLInputStream::BinURLInputStream(const XMLURL& urlSource)
      : fBuffer(0)
      , fBufferSize(0)
      , fBufferIndex(0)
      , fRemoteFileSize(0)
      , fAnchor(0)
      , fBytesProcessed(0)
      , fMemoryManager(urlSource.getMemoryManager())
{
    fBuffer = (XMLByte*) fMemoryManager->allocate
    (
        URLISBUFMAXSIZE * sizeof(XMLByte)
    );//new XMLByte[URLISBUFMAXSIZE];
    const XMLCh*  uri = urlSource.getURLText();
    char*   uriAsCharStar = localTranscode(uri, fMemoryManager);

    //
    // First find the size of the remote resource being asked for.
    // We use the ContentCounter stream provided by libWWW.
    //

    fAnchor = HTAnchor_findAddress(uriAsCharStar);
    HTRequest*   request = HTRequest_new();
    HTRequest_setOutputFormat(request, WWW_SOURCE);
    HTStream*    counterStrm = HTContentCounter(HTBlackHole(), request, 0xFFFF);
    BOOL  status = HTLoadToStream(uriAsCharStar, counterStrm, request);
    if (status == YES)
    {
        HTParentAnchor * anchor = HTRequest_anchor(request);
        fRemoteFileSize=HTAnchor_length(anchor);
        if(fRemoteFileSize < 0)
        {
            // Patch by Artur Klauser
            // When a redirection is processed in libWWW, it seems that
            // HTAnchor_length(anchor) == -1 on the original anchor, whereas
            // HTResponse_length(response) gives the correct content length of
            // the redirection target. This has confused fRemoteFileSize and it was
            // not checked for a -1 response at all.
            HTResponse * response = HTRequest_response (request);
            fRemoteFileSize = HTResponse_length(response);
            if (fRemoteFileSize < 0) {
                ThrowXMLwithMemMgr(NetAccessorException, XMLExcepts::NetAcc_LengthError, fMemoryManager);
            }
        }
    }

    // Cleanup, before you throw any errors.
    fMemoryManager->deallocate(uriAsCharStar);
    HTRequest_delete(request);
    // Don't know whether I am supposed to delete counterStrm.

    if (status == NO)
    {
        ThrowXMLwithMemMgr(NetAccessorException, XMLExcepts::NetAcc_LengthError, fMemoryManager);
    }
}
Esempio n. 13
0
int main (int argc, char ** argv)
{
    char * uri = NULL;

    /* Create a new premptive client */
    HTProfile_newHTMLNoCacheClient ("ShowXML", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /* Set trace messages */
#if 0
    HTSetTraceMessageMask("sop");
#endif

    /* Add our own termination filter */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Register our new XML Instance handler */
    HTXMLCallback_registerNew (HTXML_newInstance, NULL);

    /* Setup a timeout on the request for 15 secs */
    HTHost_setEventTimeout(15000);

    /* Handle command line args */
    if (argc >= 2)
	uri = HTParse(argv[1], NULL, PARSE_ALL);

    if (uri) {
	HTRequest * request = NULL;
	HTAnchor * anchor = NULL;
	BOOL status = NO;

	/* Create a request */
	request = HTRequest_new();

	/* Get an anchor object for the URI */
	anchor = HTAnchor_findAddress(uri);

	/* Issue the GET and store the result in a chunk */
	status = HTLoadAnchor(anchor, request);

	/* Go into the event loop... */
	if (status == YES) HTEventList_loop(request);

    } else {
	HTPrint("Type the URI to parse\n");
	HTPrint("\t%s <uri>\n", argv[0]);
	HTPrint("For example:\n");
	HTPrint("\t%s http://www.yoursite.com/your.xml\n", argv[0]);
    }

    return 0;
}
Esempio n. 14
0
HTAnchor * HTAnchor_findAddress
  ARGS1 (CONST char *,address)
{
  char *tag = HTParse (address, "", PARSE_ANCHOR);  /* Anchor tag specified ? */

  /* If the address represents a sub-anchor, we recursively load its parent,
     then we create a child anchor within that document. */
  if (tag && *tag) {
    char *docAddress = HTParse(address, "", PARSE_ACCESS | PARSE_HOST |
			                    PARSE_PATH | PARSE_PUNCTUATION);
    HTParentAnchor * foundParent =
      (HTParentAnchor *) HTAnchor_findAddress (docAddress);
    HTChildAnchor * foundAnchor = HTAnchor_findChild (foundParent, tag);
    free (docAddress);
    free (tag);
    return (HTAnchor *) foundAnchor;
  }
  
  else { /* If the address has no anchor tag, check whether we have this node */
    int hash;
    CONST char *p;
    HTList * adults;
    HTList *grownups;
    HTParentAnchor * foundAnchor;

    if (tag && *tag)
      free (tag);
    
    /* Select list from hash table */
    for(p=address, hash=0; *p; p++) hash = (hash * 3 + *p) % HASH_SIZE;
    if (!adult_table)
        adult_table = (HTList**) calloc(HASH_SIZE, sizeof(HTList*));
    if (!adult_table[hash]) adult_table[hash] = HTList_new();
    adults = adult_table[hash];

    /* Search list for anchor */
    grownups = adults;
    while (foundAnchor = HTList_nextObject (grownups)) {
      if (equivalent(foundAnchor->address, address)) {
	if (TRACE) fprintf(stderr, "Anchor %p with address `%s' already exists.\n",
			  foundAnchor, address);
	return (HTAnchor *) foundAnchor;
      }
    }
    
    /* Node not found : create new anchor */
    foundAnchor = HTParentAnchor_new ();
    if (TRACE) fprintf(stderr, "New anchor %p has hash %d and address `%s'\n",
    	foundAnchor, hash, address);
    StrAllocCopy(foundAnchor->address, address);
    HTList_addObject (adults, foundAnchor);
    return (HTAnchor *) foundAnchor;
  }
}
Esempio n. 15
0
/*	Create new or find old named anchor
**	-----------------------------------
**
**	Me one is for a reference which is found in a document, and might
**	not be already loaded.
**	Note: You are not guaranteed a new anchor -- you might get an old one,
**	like with fonts.
*/
PUBLIC HTAnchor * HTAnchor_findAddress (const char * address)
{
    char *tag = HTParse (address, "", PARSE_VIEW);	        /* Any tags? */
    
    /* If the address represents a sub-anchor, we recursively load its parent,
       then we create a child anchor within that document. */
    if (*tag) {
	char *addr = HTParse(address, "", PARSE_ACCESS | PARSE_HOST |
			     PARSE_PATH | PARSE_PUNCTUATION);
	HTParentAnchor * parent = (HTParentAnchor*) HTAnchor_findAddress(addr);
	HTChildAnchor * child = HTAnchor_findChild(parent, tag);
	HT_FREE(addr);
	HT_FREE(tag);
	return (HTAnchor *) child;
    } else {		       	     /* Else check whether we have this node */
	int hash;
	const char *p;
	HTList * adults;
	HTList *grownups;
	HTParentAnchor * foundAnchor;
	char *newaddr = NULL;
	StrAllocCopy(newaddr, address);		         /* Get our own copy */
	HT_FREE(tag);
	newaddr = HTSimplify(&newaddr);

	/* Select list from hash table */
	for(p=newaddr, hash=0; *p; p++)
	    hash = (int) ((hash * 3 + (*(unsigned char*)p)) % PARENT_HASH_SIZE);
	if (!adult_table) {
	    if ((adult_table = (HTList* *) HT_CALLOC(PARENT_HASH_SIZE, sizeof(HTList*))) == NULL)
	        HT_OUTOFMEM("HTAnchor_findAddress");
	}
	if (!adult_table[hash]) adult_table[hash] = HTList_new();
	adults = adult_table[hash];

	/* Search list for anchor */
	grownups = adults;
	while ((foundAnchor = (HTParentAnchor *) HTList_nextObject(grownups))){
	    if (!strcmp(foundAnchor->address, newaddr)) {
		HTTRACE(ANCH_TRACE, "Find Parent. %p with address `%s' already exists.\n" _ 
			    (void*) foundAnchor _ newaddr);
		HT_FREE(newaddr);		       /* We already have it */
		return (HTAnchor *) foundAnchor;
	    }
	}
	
	/* Node not found : create new anchor. */
	foundAnchor = HTParentAnchor_new();
	foundAnchor->address = newaddr;			/* Remember our copy */
	HTList_addObject (adults, foundAnchor);
	HTTRACE(ANCH_TRACE, "Find Parent. %p with hash %d and address `%s' created\n" _ (void*)foundAnchor _ hash _ newaddr);
	return (HTAnchor *) foundAnchor;
    }
}
Esempio n. 16
0
int main (int argc, char ** argv)
{
    char * uri = NULL;
    char * cwd = HTGetCurrentDirectoryURL();

    /* Create a new premptive client */
    HTProfile_newHTMLNoCacheClient ("ParseRDF", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /* Set trace messages */
#if 0
    HTSetTraceMessageMask("sopx");
#endif

    /* Add our own termination filter */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Setup a timeout on the request for 15 secs */
    HTHost_setEventTimeout(15000);

    /* Handle command line args */
    if (argc >= 2) uri = HTParse(argv[1], cwd, PARSE_ALL);
    HT_FREE(cwd);

    /* Set up our RDF To Triple conveter stream */
    HTFormat_addConversion("text/rdf", "*/*", HTRDFParser_new, 1.0, 0.0, 0.0);

    /* Set our new RDF parser instance callback */
    HTRDF_registerNewParserCallback (new_parser_handler, NULL);

    if (uri) {
	HTRequest * request = HTRequest_new();
	HTAnchor * anchor = HTAnchor_findAddress(uri);
	BOOL status = NO;

	/* Start the GET request */
	status = HTLoadAnchor(anchor, request);

	/* Go into the event loop... */
	if (status == YES) HTEventList_loop(request);

    } else {
	HTPrint("Type the URI to parse\n");
	HTPrint("\t%s <uri>\n", argv[0]);
	HTPrint("For example:\n");
	HTPrint("\t%s http://www.yoursite.com/your.rdf\n", argv[0]);
    }

    return 0;
}
Esempio n. 17
0
void CWinComDoc::OnAppUpgrade() 
{
    if (AfxMessageBox(IDS_APP_UPGRADE, MB_YESNO | MB_ICONEXCLAMATION )) {

#if 0
        CRequest * request = new CRequest(this);
        
        request->m_pHTAnchor = HTAnchor_findAddress(WEBCOMMANDER_THIS);
        
        request->CheckDocument(FALSE);
#endif
    }
}
Esempio n. 18
0
/*	Create new or find old named anchor - simple form
**	-------------------------------------------------
**
**     Like HTAnchor_findAddress, but simpler to use for simple cases.
**	No post data etc. can be supplied. - kw
*/
PUBLIC HTParentAnchor * HTAnchor_findSimpleAddress ARGS1(
	CONST char *,	url)
{
    DocAddress urldoc;

    urldoc.address = (char *)url; /* ignore warning, it IS treated like const - kw */
    urldoc.post_data = NULL;
    urldoc.post_content_type = NULL;
    urldoc.bookmark = NULL;
    urldoc.isHEAD = FALSE;
    urldoc.safe = FALSE;
    return HTAnchor_findAddress(&urldoc);
}
Esempio n. 19
0
/*	Create or find a child anchor with a possible link
**	--------------------------------------------------
**
**	Create new anchor with a given parent and possibly
**	a name, and possibly a link to a _relatively_ named anchor.
**	All parameters EXCEPT parent can be NULL
*/
PUBLIC HTChildAnchor * HTAnchor_findChildAndLink (HTParentAnchor *	parent,
						  const char *		tag,
						  const char *		href,
						  HTLinkType		ltype)
{
    HTChildAnchor * child = HTAnchor_findChild(parent, tag);
    if (child && href && *href) {
	char * relative_to = HTAnchor_expandedAddress((HTAnchor *) parent);
	char * parsed_address = HTParse(href, relative_to, PARSE_ALL);
	HTAnchor * dest = HTAnchor_findAddress(parsed_address);
	HTLink_add((HTAnchor *) child, dest, ltype, METHOD_INVALID);
	HT_FREE(parsed_address);
	HT_FREE(relative_to);
    }
    return child;
}
Esempio n. 20
0
/*	Create or find a child anchor with a possible link
**	--------------------------------------------------
**
**	Create new anchor with a given parent and possibly
**	a name, and possibly a link to a _relatively_ named anchor.
**	(Code originally in ParseHTML.h)
*/
PUBLIC HTChildAnchor * HTAnchor_findChildAndLink
  ARGS4(
       HTParentAnchor *,parent,	/* May not be 0 */
       CONST char *,tag,	/* May be "" or 0 */
       CONST char *,href,	/* May be "" or 0 */
       HTLinkType *,ltype	/* May be 0 */
       )
{
  HTChildAnchor * child = HTAnchor_findChild(parent, tag);
  if (href && *href) {
    char * parsed_address;
    HTAnchor * dest;
    parsed_address = HTParse(href, HTAnchor_address((HTAnchor *) parent),
			     PARSE_ALL);
    dest = HTAnchor_findAddress(parsed_address);
    HTAnchor_link((HTAnchor *) child, dest, ltype);
    free(parsed_address);
  }
  return child;
}
Esempio n. 21
0
void CDelete::OnOK() 
{
    CWinComApp * pApp = (CWinComApp *) AfxGetApp();
    ASSERT(pApp != NULL); 

    // Check address to delete
    if (m_deleteList.GetWindowTextLength()) {
	m_deleteList.GetWindowText(m_address);
	if (m_address.IsEmpty()) return;
	
	// Get the base address (if any)
	CString base;
	m_deleteList.GetLBText(0, base);
	char * address = HTParse(m_address, base.IsEmpty() ? "" : base, PARSE_ALL);
	address = HTSimplify(&address);
	m_address = address;
	m_deleteList.SetWindowText(m_address);
	HT_FREE(address);
	HTAnchor * anchor = HTAnchor_findAddress(m_address);
	
	// Update the address combo box
	if (m_deleteList.FindStringExact(-1, m_address) == CB_ERR) {
	    m_deleteList.InsertString(0, m_address);
	    int srcLength = m_deleteList.GetCount();
	    if (srcLength >= MAX_LIST_LENGTH) {
		int cnt;
		for (cnt=MAX_LIST_LENGTH; cnt < srcLength; cnt++)
		    m_deleteList.DeleteString(cnt);
	    }
	    
	    // Write into INI file
	    pApp->AddDeleteAddressToIniFile(m_address);
	}
	
	
	// Start the request
	CRequest * request = new CRequest(m_pDoc);
	request->DeleteDocument(anchor, HT_NO_MATCH);
    }
    CDialog::OnOK();
}
Esempio n. 22
0
/*
**	Scan the request line for METHOD, URI and VERSION
**	Returns:	HT_OK		if 1.x request and OK
**			HT_LOADED     	if 0.9 request and OK
**			HT_ERROR	if invalid request line
*/
PRIVATE int ParseRequest (HTStream * me)
{
    HTRequest * client = HTList_firstObject(me->http->clients);
    char * line = HTChunk_data(me->buffer);
    char * method_str = HTNextField(&line);
    char * request_uri = HTNextField(&line);
    char * version_str = HTNextField(&line);
    HTMethod method;

    /* Check if method is allowed */
    if (!method_str || (method = HTMethod_enum(method_str))==METHOD_INVALID) {
        HTRequest_addError(client, ERR_FATAL, NO, HTERR_NOT_ALLOWED,
                           NULL, 0, "ParseRequest");
        return HT_ERROR;
    }
    HTRequest_setMethod(client, method);

    /* Find an anchor for the request URI */
    if (request_uri) {
        char * uri = HTParse(request_uri, "file:", PARSE_ALL);
        HTRequest_setAnchor(client, HTAnchor_findAddress(uri));
        HT_FREE(uri);
    } else {
        HTRequest_addError(client, ERR_FATAL, NO, HTERR_BAD_REQUEST,
                           NULL, 0, "ParseRequest");
        return HT_ERROR;
    }

    /* Get ready to get the rest of the request */
    if (version_str) {
        me->target = HTStreamStack(WWW_MIME_HEAD,
                                   HTRequest_debugFormat(client),
                                   HTRequest_debugStream(client),
                                   client, NO);
        return HT_OK;
    } else {
        HTRequest_addError(client, ERR_FATAL, NO, HTERR_BAD_VERSION,
                           NULL, 0, "ParseRequest");
        return HT_ERROR;
    }
}
Esempio n. 23
0
/*
**	Creates a temporary anchor that doesn't exist
*/
PUBLIC HTParentAnchor * HTTmpAnchor (HTUserProfile * up)
{
    static int offset = 0;			    /* Just keep counting... */
    HTParentAnchor * htpa = NULL;
    time_t t = time(NULL);
    char * tmpfile = HTGetTmpFileName(HTUserProfile_tmp(up));
    char * tmpurl = HTParse(tmpfile, "file:", PARSE_ALL);
    if (tmpfile && tmpurl && t >= 0) {
	char * result;
	if (!(result = (char *) HT_MALLOC(strlen(tmpurl)+20)))
	    HT_OUTOFMEM("HTTmpAnchor");
#ifdef HAVE_LONG_TIME_T
	sprintf(result, "%s.%ld.%d", tmpurl, t, offset++);
#else
	sprintf(result, "%s.%d.%d", tmpurl, t, offset++);
#endif
	HTTRACE(APP_TRACE, "Tmp Anchor.. With location `%s\'\n" _ result);
	htpa = HTAnchor_parent(HTAnchor_findAddress(result));
	HT_FREE(result);
    }
    HT_FREE(tmpfile);
    HT_FREE(tmpurl);
    return htpa;
}
Esempio n. 24
0
PRIVATE int FileEvent (SOCKET soc, void * pVoid, HTEventType type)
{
    file_info *file = pVoid;			      /* Specific access information */
    int status = HT_ERROR;
    HTNet * net = file->net;
    HTRequest * request = HTNet_request(net);
    HTParentAnchor * anchor = HTRequest_anchor(request);

    /*
    ** Initiate a new file structure and bind to request structure
    ** This is actually state FILE_BEGIN, but it can't be in the state
    ** machine as we need the structure first.
    */
    if (type == HTEvent_CLOSE) {				      /* Interrupted */
	HTRequest_addError(request, ERR_FATAL, NO, HTERR_INTERRUPTED,
			   NULL, 0, "HTLoadFile");
	FileCleanup(request, HT_INTERRUPTED);
	return HT_OK;
    }


    /* Now jump into the machine. We know the state from the previous run */
    while (1) {
	switch (file->state) {
	case FS_BEGIN:

	    /* We only support safe (GET, HEAD, etc) methods for the moment */
	    if (!HTMethod_isSafe(HTRequest_method(request))) {
		HTRequest_addError(request, ERR_FATAL, NO, HTERR_NOT_ALLOWED,
				   NULL, 0, "HTLoadFile");
		file->state = FS_ERROR;
		break;
	    }

	    /* Check whether we have access to local disk at all */
	    if (HTLib_secure()) {
		HTTRACE(PROT_TRACE, "LoadFile.... No access to local file system\n");
		file->state = FS_TRY_FTP;
		break;
	    }
	    file->local = HTWWWToLocal(HTAnchor_physical(anchor), "",
				       HTRequest_userProfile(request));
	    if (!file->local) {
		file->state = FS_TRY_FTP;
		break;
	    }

	    /* Create a new host object and link it to the net object */
	    {
		HTHost * host = NULL;
		if ((host = HTHost_new("localhost", 0)) == NULL) return HT_ERROR;
		HTNet_setHost(net, host);
		if (HTHost_addNet(host, net) == HT_PENDING) {
		    HTTRACE(PROT_TRACE, "HTLoadFile.. Pending...\n");
		    /* move to the hack state */
		    file->state = FS_PENDING;
		    return HT_OK;
		}
	    }
	    file->state = FS_DO_CN;
	    break;

	case FS_PENDING:
	    /*
	    ** 2000/08/10 JK : This is a funny state. Because of the
	    ** internal libwww stacks, when doing multiple local
	    ** requests (e.g., while using the Robot), we need to ask
	    ** again for the host object. If we had jumped directly to
	    ** the FS_DO_CN state, libwww would have blocked because
	    ** of socket starvation.
	    ** This state is similar to FS_BEGINNING, but just requests 
	    ** the host object. 
	    ** YES. THIS IS AN UGLY HACK!!
	    */
	    {
		HTHost * host = NULL;
		if ((host = HTHost_new("localhost", 0)) == NULL) return HT_ERROR;
		HTNet_setHost(net, host);
		if (HTHost_addNet(host, net) == HT_PENDING) {
		    HTTRACE(PROT_TRACE, "HTLoadFile.. Pending...\n");
		    file->state = FS_PENDING;
		    return HT_OK;
		}
	    }
	    file->state = FS_DO_CN;
	    break;

	case FS_DO_CN:
	    /*
	    ** If we have to do content negotiation then find the object that
	    ** fits best into either what the client has indicated in the
	    ** accept headers or what the client has registered on its own.
	    ** The object chosen can in fact be a directory! However, content
	    ** negotiation only makes sense if we can read the directory!
	    ** We stat the file in order to find the size and to see it if
	    ** exists.
	    */
	    if (HTRequest_negotiation(request) &&
		HTMethod_isSafe(HTRequest_method(request))) {
 		char * conneg = HTMulti(request, file->local,&file->stat_info);
		if (conneg) {
		    HT_FREE(file->local);
		    file->local = conneg;
		    HTAnchor_setPhysical(anchor, conneg);
		    HTTRACE(PROT_TRACE, "Load File... Found `%s\'\n" _ conneg);
		} else {
		    HTTRACE(PROT_TRACE, "Load File... Not found - even tried content negotiation\n");
		    HTRequest_addError(request, ERR_FATAL, NO, HTERR_NOT_FOUND,
				       NULL, 0, "HTLoadFile");
		    file->state = FS_ERROR;
		    break;
		}
	    } else {
		if (HT_STAT(file->local, &file->stat_info) == -1) {
		    HTTRACE(PROT_TRACE, "Load File... Not found `%s\'\n" _ file->local);
		    HTRequest_addError(request, ERR_FATAL, NO, HTERR_NOT_FOUND,
				       NULL, 0, "HTLoadFile");
		    file->state = FS_ERROR;
		    break;
		}
	    }

	    /*
	    ** Check to see if the 'localname' is in fact a directory.
	    ** Note that we can't do a HEAD on a directory
	    */
	    if (((file->stat_info.st_mode) & S_IFMT) == S_IFDIR) {
		if (HTRequest_method(request) == METHOD_GET)
		    file->state = FS_PARSE_DIR;
		else {
		    HTRequest_addError(request, ERR_INFO, NO, HTERR_NO_CONTENT,
				       NULL, 0, "HTLoadFile");
		    file->state = FS_NO_DATA;
		}
		break;
	    }

	    /*
	    ** If empty file then only serve it if it is editable. We also get
	    ** the bindings for the file suffixes in lack of better bindings
	    */
	    {
		BOOL editable = HTEditable(file->local, &file->stat_info);
		if (file_suffix_binding) HTBind_getAnchorBindings(anchor);
		if (editable) HTAnchor_appendAllow(anchor, METHOD_PUT);

		/* Set the file size */
		if (file->stat_info.st_size)
		    HTAnchor_setLength(anchor, file->stat_info.st_size);

		/* Set the file last modified time stamp */
		if (file->stat_info.st_mtime > 0)
		    HTAnchor_setLastModified(anchor, file->stat_info.st_mtime);

		/* Check to see if we can edit it */
		if (!editable && !file->stat_info.st_size) {
		    HTRequest_addError(request, ERR_INFO, NO, HTERR_NO_CONTENT,
				       NULL, 0, "HTLoadFile");
		    file->state = FS_NO_DATA;
		} else {
		    file->state = (HTRequest_method(request)==METHOD_GET) ? 
			FS_NEED_OPEN_FILE : FS_GOT_DATA;
		}
	    }
	    break;

	  case FS_NEED_OPEN_FILE:
	    status = HTFileOpen(net, file->local, HT_FB_RDONLY);
	    if (status == HT_OK) {
		/* 
		** Create the stream pipe FROM the channel to the application.
		** The target for the input stream pipe is set up using the
		** stream stack.
		*/
		{
		    HTStream * rstream = HTStreamStack(HTAnchor_format(anchor),
						       HTRequest_outputFormat(request),
						       HTRequest_outputStream(request),
						       request, YES);
		    HTNet_setReadStream(net, rstream);
		    HTRequest_setOutputConnected(request, YES);
		}

		/*
		** Create the stream pipe TO the channel from the application
		** and hook it up to the request object
		*/
		{
		    HTOutputStream * output = HTNet_getOutput(net, NULL, 0);
		    HTRequest_setInputStream(request, (HTStream *) output);
		}

		/*
		** Set up concurrent read/write if this request isn't the
		** source for a PUT or POST. As source we don't start reading
		** before all destinations are ready. If destination then
		** register the input stream and get ready for read
		*/
		if (HTRequest_isSource(request) && !HTRequest_destinationsReady(request))
		    return HT_OK;
		HTRequest_addError(request, ERR_INFO, NO, HTERR_OK, NULL, 0,
				   "HTLoadFile");
		file->state = FS_NEED_BODY;

		/* If we are _not_ using preemptive mode and we are Unix fd's
		** then return here to get the same effect as when we are
		** connecting to a socket. That way, HTFile acts just like any
		** other protocol module even though we are in fact doing
		** blocking connect
		*/
		if (HTEvent_isCallbacksRegistered()) {
		    if (!HTRequest_preemptive(request)) {
			if (!HTNet_preemptive(net)) {
			    HTTRACE(PROT_TRACE, "HTLoadFile.. Returning\n");
			    HTHost_register(HTNet_host(net), net, HTEvent_READ);
			} else if (!file->timer) {
			    HTTRACE(PROT_TRACE, "HTLoadFile.. Returning\n");
			    file->timer =
				HTTimer_new(NULL, ReturnEvent, file, 1, YES, NO);
			}
			return HT_OK;
		    }
		}
	    } else if (status == HT_WOULD_BLOCK || status == HT_PENDING)
		return HT_OK;
	    else {
		HTRequest_addError(request, ERR_INFO, NO, HTERR_INTERNAL,
				   NULL, 0, "HTLoadFile");
		file->state = FS_ERROR;		       /* Error or interrupt */
	    }
	    break;

	  case FS_NEED_BODY:
	    status = HTHost_read(HTNet_host(net), net);
	    if (status == HT_WOULD_BLOCK)
		return HT_OK;
	    else if (status == HT_LOADED || status == HT_CLOSED) {
		file->state = FS_GOT_DATA;
	    } else {
		HTRequest_addError(request, ERR_INFO, NO, HTERR_FORBIDDEN,
				   NULL, 0, "HTLoadFile");
		file->state = FS_ERROR;
	    }
	    break;

	  case FS_PARSE_DIR:
	    status = HTFile_readDir(request, file);
	    if (status == HT_LOADED)
		file->state = FS_GOT_DATA;
	    else
		file->state = FS_ERROR;
	    break;

	  case FS_TRY_FTP:
	    {
		char *url = HTAnchor_physical(anchor);
		HTAnchor *anchor;
		char *newname = NULL;
		StrAllocCopy(newname, "ftp:");
		if (!strncmp(url, "file:", 5))
		    StrAllocCat(newname, url+5);
		else
		    StrAllocCat(newname, url);
		anchor = HTAnchor_findAddress(newname);
		HTRequest_setAnchor(request, anchor);
		HT_FREE(newname);
		FileCleanup(request, HT_IGNORE);
		return HTLoad(request, YES);
	    }
	    break;

	  case FS_GOT_DATA:
	    FileCleanup(request, HT_LOADED);
	    return HT_OK;
	    break;

	  case FS_NO_DATA:
	    FileCleanup(request, HT_NO_DATA);
	    return HT_OK;
	    break;

	  case FS_RETRY:
	    FileCleanup(request, HT_RETRY);
	    return HT_OK;
	    break;

	  case FS_ERROR:
	    FileCleanup(request, HT_ERROR);
	    return HT_OK;
	    break;
	}
    } /* End of while(1) */
}
Esempio n. 25
0
/*	Generate the anchor for the home page
**	-------------------------------------
**
**	As it involves file access, this should only be done once
**	when the program first runs.
**	This is a default algorithm -- browser don't HAVE to use this.
**	But consistency betwen browsers is STRONGLY recommended!
**
**	Priority order is:
**
**		1	WWW_HOME environment variable (logical name, etc)
**		2	~/WWW/default.html
**		3	/usr/local/bin/default.html
**		4	http://www.w3.org/default.html
**
*/
PUBLIC HTParentAnchor * HTHomeAnchor (void)
{
    char * my_home_document = NULL;
    char * home = (char *) getenv(LOGICAL_DEFAULT);
    char * ref;
    HTParentAnchor * anchor;
    
    /* Someone telnets in, they get a special home */
    if (home) {
        StrAllocCopy(my_home_document, home);
    } else  if (HTLib_secure()) {				    /* Telnet server */
    	FILE * fp = fopen(REMOTE_POINTER, "r");
	char * status;
	if (fp) {
	    if ((my_home_document = (char *) HT_MALLOC(HT_MAX_PATH)) == NULL)
	        HT_OUTOFMEM("my_home_document ");
	    status = fgets(my_home_document, HT_MAX_PATH, fp);
	    if (!status) {
	        HT_FREE(my_home_document);
		my_home_document = NULL;
	    }
	    fclose(fp);
	}
	if (!my_home_document) StrAllocCopy(my_home_document, REMOTE_ADDRESS);
    }

    if (!my_home_document) {
	FILE * fp = NULL;
	char * home = (char *) getenv("HOME");
	if (home) { 
	    if ((my_home_document = (char  *) HT_MALLOC(strlen(home)+1+ strlen(PERSONAL_DEFAULT)+1)) == NULL)
	        HT_OUTOFMEM("HTLocalName");
	    sprintf(my_home_document, "%s/%s", home, PERSONAL_DEFAULT);
	    fp = fopen(my_home_document, "r");
	}
	
	if (!fp) {
	    StrAllocCopy(my_home_document, LOCAL_DEFAULT_FILE);
	    fp = fopen(my_home_document, "r");
	}
	if (fp) {
	    fclose(fp);
	} else {
	    HTTRACE(APP_TRACE, "Home Anchor. No local home document in ~/%s or %s\n" _ 
			PERSONAL_DEFAULT _ LOCAL_DEFAULT_FILE);
	    HT_FREE(my_home_document);
	    my_home_document = NULL;
	}
    }

    ref = HTParse(my_home_document ? my_home_document :
		  HTLib_secure() ? REMOTE_ADDRESS : LAST_RESORT, "file:",
		  PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
    if (my_home_document) {
	HTTRACE(APP_TRACE, "Home Anchor. `%s\' used for custom home page as\n`%s\'\n" _ 
		    my_home_document _ ref);
	HT_FREE(my_home_document);
    }
    anchor = (HTParentAnchor*) HTAnchor_findAddress(ref);
    HT_FREE(ref);
    return anchor;
}
Esempio n. 26
0
/*
 * This function makes the history page seem like any other type of file since
 * more info is needed than can be provided by the normal link structure.  We
 * saved out the history number to a special URL.
 *
 * The info looks like:  LYNXHIST:#
 */
BOOLEAN historytarget(DocInfo *newdoc)
{
    int number;
    DocAddress WWWDoc;
    HTParentAnchor *tmpanchor;
    HText *text;
    BOOLEAN treat_as_intern = FALSE;

    if ((!newdoc || !newdoc->address) ||
	strlen(newdoc->address) < 10 || !isdigit(UCH(*(newdoc->address + 9))))
	return (FALSE);

    if ((number = atoi(newdoc->address + 9)) > nhist + nhist_extra || number < 0)
	return (FALSE);

    /*
     * Optimization: assume we came from the History Page,
     * so never return back - always a new version next time.
     * But check first whether HTMainText is really the History
     * Page document - in some obscure situations this may not be
     * the case.  If HTMainText seems to be a History Page document,
     * also check that it really hasn't been pushed. - LP, kw
     */
    if (HTMainText && nhist > 0 &&
	!strcmp(HTLoadedDocumentTitle(), HISTORY_PAGE_TITLE) &&
	LYIsUIPage3(HTLoadedDocumentURL(), UIP_HISTORY, 0) &&
	strcmp(HTLoadedDocumentURL(), HDOC(nhist - 1).address)) {
	HTuncache_current_document();	/* don't waste the cache */
    }

    LYpop_num(number, newdoc);
    if (((newdoc->internal_link &&
	  history[number].intern_seq_start == history[nhist - 1].intern_seq_start)
	 || (number < nhist - 1 &&
	     HDOC(nhist - 1).internal_link &&
	     number == history[nhist - 1].intern_seq_start))
	&& !(LYforce_no_cache == TRUE && LYoverride_no_cache == FALSE)) {
	if (track_internal_links) {
	    LYforce_no_cache = FALSE;
	    LYinternal_flag = TRUE;
	    newdoc->internal_link = TRUE;
	    treat_as_intern = TRUE;
	}
    } else {
	newdoc->internal_link = FALSE;
    }
    /*
     * If we have POST content, and have LYresubmit_posts set or have no_cache
     * set or do not still have the text cached, ask the user whether to
     * resubmit the form.  - FM
     */
    if (newdoc->post_data != NULL) {
	WWWDoc.address = newdoc->address;
	WWWDoc.post_data = newdoc->post_data;
	WWWDoc.post_content_type = newdoc->post_content_type;
	WWWDoc.bookmark = newdoc->bookmark;
	WWWDoc.isHEAD = newdoc->isHEAD;
	WWWDoc.safe = newdoc->safe;
	tmpanchor = HTAnchor_findAddress(&WWWDoc);
	text = (HText *) HTAnchor_document(tmpanchor);
	if (((((LYresubmit_posts == TRUE) ||
	       (LYforce_no_cache == TRUE &&
		LYoverride_no_cache == FALSE)) &&
	      !(treat_as_intern && !reloading)) ||
	     text == NULL) &&
	    (isLYNXIMGMAP(newdoc->address) ||
	     HTConfirm(CONFIRM_POST_RESUBMISSION) == TRUE)) {
	    LYforce_no_cache = TRUE;
	    LYoverride_no_cache = FALSE;
	} else if (text != NULL) {
	    LYforce_no_cache = FALSE;
	    LYoverride_no_cache = TRUE;
	} else {
	    HTInfoMsg(CANCELLED);
	    return (FALSE);
	}
    }

    if (number != 0)
	StrAllocCat(newdoc->title, gettext(" (From History)"));
    return (TRUE);
}
Esempio n. 27
0
/*
 * Push the current filename, link and line number onto the history list.
 */
int LYpush(DocInfo *doc, int force_push)
{
    /*
     * Don't push NULL file names.
     */
    if (*doc->address == '\0')
	return 0;

    /*
     * Check whether this is a document we don't push unless forced.  - FM
     */
    if (!force_push) {
	/*
	 * Don't push the history, printer, or download lists.
	 */
	if (!LYwouldPush(doc->title, doc->address)) {
	    if (!LYforce_no_cache)
		LYoverride_no_cache = TRUE;
	    return 0;
	}
    }

    /*
     * If file is identical to one before it, don't push it.
     * But do not duplicate it if there is only one on the stack,
     * note that HDOC() starts from 0, so nhist should be > 0.
     */
    if (nhist >= 1 && are_identical(&(history[nhist - 1]), doc)) {
	if (HDOC(nhist - 1).internal_link == doc->internal_link) {
	    /* But it is nice to have the last position remembered!
	       - kw */
	    HDOC(nhist - 1).link = doc->link;
	    HDOC(nhist - 1).line = doc->line;
	    return 0;
	}
    }

    /*
     * If file is identical to the current document, just move the pointer.
     */
    if (nhist_extra >= 1 && are_identical(&(history[nhist]), doc)) {
	HDOC(nhist).link = doc->link;
	HDOC(nhist).line = doc->line;
	nhist_extra--;
	LYAllocHistory(nhist);
	nhist++;
	trace_history("LYpush: just move the cursor");
	return 1;
    }

    clean_extra_history();
#ifdef LY_FIND_LEAKS
    if (!already_registered_clean_all_history) {
	already_registered_clean_all_history = 1;
	atexit(clean_all_history);
    }
#endif

    /*
     * OK, push it...
     */
    LYAllocHistory(nhist);
    HDOC(nhist).link = doc->link;
    HDOC(nhist).line = doc->line;

    HDOC(nhist).title = NULL;
    LYformTitle(&(HDOC(nhist).title), doc->title);

    HDOC(nhist).address = NULL;
    StrAllocCopy(HDOC(nhist).address, doc->address);

    HDOC(nhist).post_data = NULL;
    BStrCopy(HDOC(nhist).post_data, doc->post_data);

    HDOC(nhist).post_content_type = NULL;
    StrAllocCopy(HDOC(nhist).post_content_type, doc->post_content_type);

    HDOC(nhist).bookmark = NULL;
    StrAllocCopy(HDOC(nhist).bookmark, doc->bookmark);

    HDOC(nhist).isHEAD = doc->isHEAD;
    HDOC(nhist).safe = doc->safe;

    HDOC(nhist).internal_link = FALSE;	/* by default */
    history[nhist].intern_seq_start = -1;	/* by default */
    if (doc->internal_link) {
	/* Now some tricky stuff: if the caller thinks that the doc
	   to push was the result of following an internal
	   (fragment) link, we check whether we believe it.
	   It is only accepted as valid if the immediately preceding
	   item on the history stack is actually the same document
	   except for fragment and location info.  I.e. the Parent
	   Anchors are the same.
	   Also of course this requires that this is not the first
	   history item. - kw */
	if (nhist > 0) {
	    DocAddress WWWDoc;
	    HTParentAnchor *thisparent, *thatparent = NULL;

	    WWWDoc.address = doc->address;
	    WWWDoc.post_data = doc->post_data;
	    WWWDoc.post_content_type = doc->post_content_type;
	    WWWDoc.bookmark = doc->bookmark;
	    WWWDoc.isHEAD = doc->isHEAD;
	    WWWDoc.safe = doc->safe;
	    thisparent =
		HTAnchor_findAddress(&WWWDoc);
	    /* Now find the ParentAnchor for the previous history
	     * item - kw
	     */
	    if (thisparent) {
		/* If the last-pushed item is a LYNXIMGMAP but THIS one
		 * isn't, compare the physical URLs instead. - kw
		 */
		if (isLYNXIMGMAP(HDOC(nhist - 1).address) &&
		    !isLYNXIMGMAP(doc->address)) {
		    WWWDoc.address = HDOC(nhist - 1).address + LEN_LYNXIMGMAP;
		    /*
		     * If THIS item is a LYNXIMGMAP but the last-pushed one
		     * isn't, fake it by using THIS item's address for
		     * thatparent... - kw
		     */
		} else if (isLYNXIMGMAP(doc->address) &&
			   !isLYNXIMGMAP(HDOC(nhist - 1).address)) {
		    char *temp = NULL;

		    StrAllocCopy(temp, STR_LYNXIMGMAP);
		    StrAllocCat(temp, doc->address + LEN_LYNXIMGMAP);
		    WWWDoc.address = temp;
		    WWWDoc.post_content_type = HDOC(nhist - 1).post_content_type;
		    WWWDoc.bookmark = HDOC(nhist - 1).bookmark;
		    WWWDoc.isHEAD = HDOC(nhist - 1).isHEAD;
		    WWWDoc.safe = HDOC(nhist - 1).safe;
		    thatparent =
			HTAnchor_findAddress(&WWWDoc);
		    FREE(temp);
		} else {
		    WWWDoc.address = HDOC(nhist - 1).address;
		}
		if (!thatparent) {	/* if not yet done */
		    WWWDoc.post_data = HDOC(nhist - 1).post_data;
		    WWWDoc.post_content_type = HDOC(nhist - 1).post_content_type;
		    WWWDoc.bookmark = HDOC(nhist - 1).bookmark;
		    WWWDoc.isHEAD = HDOC(nhist - 1).isHEAD;
		    WWWDoc.safe = HDOC(nhist - 1).safe;
		    thatparent =
			HTAnchor_findAddress(&WWWDoc);
		}
		/* In addition to equality of the ParentAnchors, require
		 * that IF we have a HTMainText (i.e., it wasn't just
		 * HTuncache'd by mainloop), THEN it has to be consistent
		 * with what we are trying to push.
		 *
		 * This may be overkill...  - kw
		 */
		if (thatparent == thisparent &&
		    (!HTMainText || HTMainAnchor == thisparent)
		    ) {
		    HDOC(nhist).internal_link = TRUE;
		    history[nhist].intern_seq_start =
			history[nhist - 1].intern_seq_start >= 0 ?
			history[nhist - 1].intern_seq_start : nhist - 1;
		    CTRACE((tfp, "\nLYpush: pushed as internal link, OK\n"));
		}
	    }
	}
	if (!HDOC(nhist).internal_link) {
	    CTRACE((tfp, "\nLYpush: push as internal link requested, %s\n",
		    "but didn't check out!"));
	}
    }
    CTRACE((tfp, "\nLYpush[%d]: address:%s\n        title:%s\n",
	    nhist, doc->address, doc->title));
    nhist++;
    return 1;
}
Esempio n. 28
0
int main (int argc, char ** argv)
{
    HTRequest * request = NULL;
    HTAnchor * src = NULL;
    HTAnchor * dst = NULL;
    char * src_str = NULL;
    char * dst_str = NULL;
    BOOL status = NO;

    /* Create a new premptive client */
    HTProfile_newNoCacheClient("libwww-PUT", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /* And the traces... */
#if 0
    HTSetTraceMessageMask("sop");
#endif

    /* Add our own filter to update the history list */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Handle command line args */
    if (argc >= 3) {
	src_str = argv[1];
	dst_str = argv[2];
    } else {
	HTPrint("Type the URI of the source and the URI of the destination.\n");
	HTPrint("\t%s <src> <dst>\n", argv[0]);
	HTPrint("For example, %s http://www.w3.org http://myserver/destination.html\n",
	       argv[0]);
	return -1;
    }

    if (src_str && *src_str && dst_str && *dst_str) {

	/* Make source relative to where we are */
	char * cwd = HTGetCurrentDirectoryURL();
	char * full_src_str = HTParse(src_str, cwd, PARSE_ALL);

	HTPrint("Saving %s to %s\n", full_src_str, dst_str);

	/* Create a request */
	request = HTRequest_new();

	/* Get an anchor object for the src and dest URIs */
	src = HTAnchor_findAddress(full_src_str);
	dst = HTAnchor_findAddress(dst_str);

	/* PUT the source to the dest */
	status = HTPutDocumentAnchor(HTAnchor_parent(src), dst, request);

	/* We don't need these anymore */
	HT_FREE(cwd);
	HT_FREE(full_src_str);

	/* Go into the event loop... */
	if (status == YES) HTEventList_loop(request);

    }

    return 0;
}
Esempio n. 29
0
int main (int argc, char ** argv)
{
    HTRequest * request = NULL;
    HTAnchor * anchor = NULL;
    HTAssocList * formfields = NULL;
    char * uri = NULL;

    /* Create a new premptive client */
    HTProfile_newNoCacheClient("TestApp", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /* Get trace messages */
#if 0
    HTSetTraceMessageMask("sop");
#endif

    /* Add our own filter to update the history list */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Set the timeout for long we are going to wait for a response */
    HTHost_setEventTimeout(20000);

    /* Handle command line args */
    if (argc >= 2) {
	int arg;
	uri = argv[1];
	for (arg=2; arg<argc; arg++) {
	    char * string = argv[arg];
	    
	    /* Create a list to hold the form arguments */
	    if (!formfields) formfields = HTAssocList_new();

	    /* Parse the content and add it to the association list */
	    HTParseFormInput(formfields, string);
	}
    }

    if (uri && formfields) {

	/* Create a request */
	request = HTRequest_new();

	/* Set the default output to "asis" */
	HTRequest_setOutputFormat(request, WWW_SOURCE);

	/* Get an anchor object for the URI */
	anchor = HTAnchor_findAddress(uri);

	/* Post the data and get the result in a chunk */
	result = HTPostFormAnchorToChunk(formfields, anchor, request);

	/* Clean up the form fields */
	HTAssocList_delete(formfields);

	/* Go into the event loop... */
	HTEventList_loop(request);

    } else {
	HTPrint("Type the URI to post to and the arguments for the POST operation. Encode spaces as '+'\n");
	HTPrint("\t%s <uri> 'a=1' 'b=+2+' 'c=3 ...'\n", argv[0]);
    }

    return 0;
}
Esempio n. 30
0
int main (int argc, char ** argv)
{
    HTRequest * request = NULL;
    HTParentAnchor * src = NULL;
    HTAnchor * dst = NULL;
    char * dst_str = NULL;
    char * data = NULL;
    BOOL status = NO;

    /* Create a new premptive client */
    HTProfile_newNoCacheClient("libwww-POST", "1.0");

    /* Need our own trace and print functions */
    HTPrint_setCallback(printer);
    HTTrace_setCallback(tracer);

    /* Add our own filter to update the history list */
    HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);

    /* Handle command line args */
    if (argc >= 3) {
	dst_str = argv[1];
	data = argv[2];
    } else {
	HTPrint("Type the URI of the destination you want to POST to and the contents that you want to post.\n");
	HTPrint("\t%s <destination> <data>\n", argv[0]);
	HTPrint("For example, %s http://myserver/destination.html \"This is some testdata\"\n",
	       argv[0]);
	return -1;
    }

    if (data && *data && dst_str && *dst_str) {

	/* Make source relative to where we are */
	char * cwd = HTGetCurrentDirectoryURL();

	HTPrint("Posting to %s\n", dst_str);

	/* Create a request */
	request = HTRequest_new();

	/* Get an anchor object for the destination URI */
	dst = HTAnchor_findAddress(dst_str);

	/*
	** Dream up a source anchor (an editor can for example use this).
	** After creation we associate the data that we want to post and
	** set some metadata about what the data is. More formats can be found
	** ../src/HTFormat.html
	*/
	src = HTTmpAnchor(NULL);
	HTAnchor_setDocument(src, data);
	HTAnchor_setFormat(src, WWW_PLAINTEXT);

	/*
	** If not posting to an HTTP/1.1 server then content length MUST be
	** there. If HTTP/1.1 then it doesn't matter as we just use chunked
	** encoding under the covers
	*/
	HTAnchor_setLength(src, strlen(data));

	/* POST the source to the dest */
	status = HTPostAnchor(src, dst, request);

	/* We don't need these anymore */
	HT_FREE(cwd);

	/* Go into the event loop... */
	if (status == YES) HTEventList_loop(request);

    }

    return 0;
}