Ejemplo n.º 1
0
EXC_TYPE CAttachInfo::InitContentType (LPCTSTR lpszMIMEType, const BOOLEAN fUpdate)
{
	if (IsEmptyStr(lpszMIMEType))
		return EPARAM;

	LPCTSTR	lpszMTD=_tcschr(lpszMIMEType, RFC822_MIMETAG_SEP);
	if (NULL == lpszMTD)
		return ENOTPRESENT;

	*((LPTSTR) lpszMTD) = _T('\0');
	EXC_TYPE	exc=(fUpdate ? UpdateContentType(lpszMIMEType, (lpszMTD+1)) : SetContentType(lpszMIMEType, (lpszMTD+1)));
	*((LPTSTR) lpszMTD) = RFC822_MIMETAG_SEP;

	return exc;
}
Ejemplo n.º 2
0
nsresult
nsGopherContentStream::SendRequest()
{
    char type;
    nsCAutoString request;  // used to build request data

    nsresult rv = ParseTypeAndSelector(type, request);
    if (NS_FAILED(rv))
        return rv;

    // So, we use the selector as is unless it is a search url
    if (type == '7') {
        // Note that we don't use the "standard" nsIURL parsing stuff here
        // because the only special character is ?, and its possible to search
        // for a string containing a #, and so on
        
        // XXX - should this find the last or first entry?
        // '?' is valid in both the search string and the url
        // so no matter what this does, it may be incorrect
        // This only affects people codeing the query directly into the URL
        PRInt32 pos = request.RFindChar('?');
        if (pos != kNotFound) {
            // Just replace it with a tab
            request.SetCharAt('\t', pos);
        } else {
            // We require a query string here - if we don't have one,
            // then we need to ask the user
            nsCAutoString search;
            rv = PromptForQueryString(search);
            if (NS_FAILED(rv))
                return rv;
    
            request.Append('\t');
            request.Append(search);

            // and update our uri (XXX should probably redirect instead to avoid
            //                         confusing consumers of the channel)
            nsCAutoString spec;
            rv = mChannel->URI()->GetAsciiSpec(spec);
            if (NS_FAILED(rv))
                return rv;

            spec.Append('?');
            spec.Append(search);
            rv = mChannel->URI()->SetSpec(spec);
            if (NS_FAILED(rv))
                return rv;
        }
    }

    request.Append(CRLF);
    
    PRUint32 n;
    rv = mSocketOutput->Write(request.get(), request.Length(), &n);
    if (NS_FAILED(rv))
        return rv;
    NS_ENSURE_STATE(n == request.Length());

    // Now, push stream converters appropriately based on our 'type'
    if (type == '1' || type == '7') {
        rv = mChannel->PushStreamConverter("text/gopher-dir",
                                           APPLICATION_HTTP_INDEX_FORMAT);
        if (NS_FAILED(rv))
            return rv;
    } else if (type == '0') {
        nsCOMPtr<nsIStreamListener> converter;
        rv = mChannel->PushStreamConverter(TEXT_PLAIN, TEXT_HTML, PR_TRUE,
                                           getter_AddRefs(converter));
        if (NS_FAILED(rv))
            return rv;
        nsCOMPtr<nsITXTToHTMLConv> config = do_QueryInterface(converter);
        if (config) {
            nsCAutoString spec;
            mChannel->URI()->GetSpec(spec);
            config->SetTitle(NS_ConvertUTF8toUTF16(spec).get());
            config->PreFormatHTML(PR_TRUE);
        }
    }

    UpdateContentType(type);
    return NS_OK;
}