Exemplo n.º 1
0
/*
**  Use the set of bindings to find the combination of language,
**  media type and encoding of a given object. This information can either be
**  stored in the anchor obejct or in the response object depending on which
**  function is called.
**
**  We comprise here as bindings only can have one language and one encoding.
**  If more than one suffix is found they are all searched. The last suffix
**  has highest priority, the first one lowest. See also HTBind_getFormat()
*/
PUBLIC BOOL HTBind_getAnchorBindings (HTParentAnchor * anchor)
{
    BOOL status = NO;
    double quality=1.0;		  /* @@@ Should we add this into the anchor? */
    if (anchor) {
	char *addr = HTAnchor_address((HTAnchor *) anchor);
	char *path = HTParse(addr, "", PARSE_PATH+PARSE_PUNCTUATION);
	char *file;
	char *end;
	if ((end = strchr(path, ';')) || (end = strchr(path, '?')) ||
	    (end = strchr(path, '#')))
	    *end = '\0';
	if ((file = strrchr(path, '/'))) {
	    HTFormat format = NULL;
	    HTEncoding encoding = NULL;
	    HTEncoding transfer = NULL;
	    HTLanguage language = NULL;
 	    HTTRACE(BIND_TRACE, "Anchor...... Get bindings for `%s\'\n" _ path);
	    status = HTBind_getFormat(file, &format, &encoding, &transfer,
				      &language, &quality);
	    if (status) {
		HTAnchor_setFormat(anchor, format);
		HTAnchor_setContentTransferEncoding(anchor, transfer);

                HTAnchor_deleteEncodingAll(anchor);
                HTAnchor_addEncoding(anchor, encoding);

                HTAnchor_deleteLanguageAll(anchor);
                HTAnchor_addLanguage(anchor, language);
	    }
	}
        HT_FREE(addr);
        HT_FREE(path);
    }
    return status;
}
Exemplo n.º 2
0
BOOL CWinComDoc::SaveDocument()
{
    CRequest * request = new CRequest(this);
    HTAnchor * source = NULL;
    HTAnchor * destination = NULL;

    // Create the source anchor
    char * src = HTParse(m_Location.m_source, m_cwd, PARSE_ALL);
    source = HTAnchor_findAddress(src);
    HT_FREE(src);
    
    /* If destination is not http://... then error */
    if (!m_Location.m_destination.IsEmpty()) {
	char * access = HTParse(m_Location.m_destination, "", PARSE_ACCESS);
	if (strcasecomp(access, "http")) {
	    CString strMessage;
	    AfxFormatString1(strMessage, IDS_CANNOT_WRITE_TO_DESTINATION, m_Location.m_destination);
	    AfxMessageBox(strMessage);
	    HT_FREE(access);
	    return FALSE;
	} else {
	    char * dest = HTParse(m_Location.m_destination, m_cwd, PARSE_ALL);
	    destination = HTAnchor_findAddress(dest);
            HT_FREE(dest);
	    HT_FREE(access);
	}
    }

    // Do we have any metadata to set up?
    {
        HTParentAnchor * source_parent = HTAnchor_parent(source);
        
        if (!m_EntityInfo.m_mediaType.IsEmpty()) {
            HTAnchor_setFormat(source_parent, HTAtom_for(m_EntityInfo.m_mediaType));
        }
        if (!m_EntityInfo.m_contentEncoding.IsEmpty()) {
            HTAnchor_deleteEncodingAll(source_parent);
            HTAnchor_addEncoding(source_parent, HTAtom_for(m_EntityInfo.m_contentEncoding));
        }
        if (!m_EntityInfo.m_charset.IsEmpty()) {
            HTAnchor_setCharset(source_parent, HTAtom_for(m_EntityInfo.m_charset));
        }
        if (!m_EntityInfo.m_language.IsEmpty()) {
            HTAnchor_deleteLanguageAll(source_parent);
            HTAnchor_addLanguage(source_parent, HTAtom_for(m_EntityInfo.m_language));
        }
    }
    
    // Do we have any link relationships to set up?
    m_Links.AddLinkRelationships(source);

    /* Start the request */
    if (m_detectVersionConflict) {
        char * etag = HTAnchor_etag(HTAnchor_parent(destination));
        if (etag) {
	    request->PutDocument(source, destination, HT_MATCH_THIS);
        } else {
	    request->PutDocumentWithPrecheck(source, destination);
        }
    } else {
	request->PutDocument(source, destination, HT_NO_MATCH);
    }

    return TRUE;
}