Esempio n. 1
0
/*	Determine a suitable suffix
**	---------------------------
**  Use the set of bindings to find a suitable suffix (or index)
**  for a certain combination of language, media type and encoding
**  given in the anchor.
**
**  Returns a pointer to a suitable suffix string that must be freed 
**  by the caller. If more than one suffix is found they are all
**  concatenated using the first delimiter in HTDelimiters.
**  If no suffix is found, NULL is returned.
*/
PUBLIC char * HTBind_getSuffix (HTParentAnchor * anchor)
{
    int cnt;
    HTList * cur;
    HTChunk * suffix = HTChunk_new(48);
    char delimiter = *HTDelimiters;
    char * ct=NULL, * ce=NULL, * cl=NULL;
    HTFormat format = HTAnchor_format(anchor);
    HTList * encoding = HTAnchor_encoding(anchor);
    HTList * language = HTAnchor_language(anchor);
    if (!HTBindings) HTBind_init();
    if (anchor) {
	for (cnt=0; cnt<HT_L_HASH_SIZE; cnt++) {
	    if ((cur = HTBindings[cnt])) { 
		HTBind *pres;
		while ((pres = (HTBind *) HTList_nextObject(cur))) {
		    if (!ct && (pres->type && pres->type == format)){
			ct = pres->suffix;
		    } else if (!ce && pres->encoding && encoding) {
			HTList * cur_enc = encoding;
			HTEncoding pres_enc;
			while ((pres_enc = (HTEncoding) HTList_nextObject(cur_enc))) {
			    if (pres_enc == pres->encoding) {
				ce = pres->suffix;
				break;
			    }
			}
		    } else if (!cl && pres->language && language) {
			HTList * cur_lang = language;
			HTLanguage pres_lang;
			while ((pres_lang = (HTLanguage) HTList_nextObject(cur_lang))) {
			    if (pres_lang == pres->language) {
				cl = pres->suffix;
				break;
			    }
			}
		    }
		}
	    }
	}

	/* Put the found suffixes together */
	if (ct) {
	    HTChunk_putc(suffix, delimiter);
	    HTChunk_puts(suffix, ct);
	}
	if (ce) {
	    HTChunk_putc(suffix, delimiter);
	    HTChunk_puts(suffix, ce);
	}
	if (cl) {
	    HTChunk_putc(suffix, delimiter);
	    HTChunk_puts(suffix, cl);
	}
    }
    return HTChunk_toCString(suffix);
}
Esempio n. 2
0
PUBLIC char * Range_toStr(Range_t * pRange)
{
    HTChunk * pChunk;
    char * ptr;
    pChunk = HTChunk_new(20);
    ptr = FVal_toStr(&pRange->min);
    HTChunk_puts(pChunk, ptr);
    HT_FREE(ptr);
    if (FVal_initialized(&pRange->max)) {
        ptr = FVal_toStr(&pRange->max);
	HTChunk_puts(pChunk, ":");
	HTChunk_puts(pChunk, ptr);
	HT_FREE(ptr);
    }
    return HTChunk_toCString(pChunk);
}
Esempio n. 3
0
PUBLIC char * HTDialog_errorMessage (HTRequest * request, HTAlertOpcode op,
			             int msgnum, const char * dfault,
				     void * input)
{
    HTList * cur = (HTList *) input;
    HTError * pres;
    HTErrorShow showmask = HTError_show();
    HTChunk * msg = NULL;
    int code;
    if (!request || !cur) return NULL;
    while ((pres = (HTError *) HTList_nextObject(cur))) {
	int index = HTError_index(pres);
	if (HTError_doShow(pres)) {
	    if (!msg) {
		HTSeverity severity = HTError_severity(pres);
		msg = HTChunk_new(128);
		if (severity == ERR_WARN)
		    HTChunk_puts(msg, "Warning: ");
		else if (severity == ERR_NON_FATAL)
		    HTChunk_puts(msg, "Non Fatal Error: ");
		else if (severity == ERR_FATAL)
		    HTChunk_puts(msg, "Fatal Error: ");
		else if (severity == ERR_INFO)
		    HTChunk_puts(msg, "Information: ");
		else {
		    HTChunk_puts(msg, "UNKNOWN ERROR TYPE");
		    return HTChunk_toCString(msg);
		}

		/* Error number */
		if ((code = HTErrors[index].code) > 0) {
		    char buf[10];
		    sprintf(buf, "%d ", code);
		    HTChunk_puts(msg, buf);
		}
	    } else
		HTChunk_puts(msg, "\nReason: ");

	    if (index == HTERR_SYSTEM) {
		int length = 0;
		char * pars = (char *) HTError_parameter(pres, &length);
		HTChunk_puts(msg, HTError_location(pres));
		HTChunk_puts(msg, " ");
		HTChunk_puts(msg, HTErrors[index].msg);
		if (length && pars) {
		    HTChunk_puts(msg, " (");
		    HTChunk_puts(msg, pars);
		    HTChunk_puts(msg, ")");
		}
		
	    } else {

		/* Error message */
		HTChunk_puts(msg, HTErrors[index].msg);

		/* Error parameters */
		if (showmask & HT_ERR_SHOW_PARS) {
		    int length;
		    int cnt;		
		    char *pars = (char *) HTError_parameter(pres, &length);
		    if (length && pars) {
			HTChunk_puts(msg, " (");
			for (cnt=0; cnt<length; cnt++) {
			    char ch = *(pars+cnt);
			    if (ch < 0x20 || ch >= 0x7F)
				HTChunk_putc(msg, '#');
			    else
				HTChunk_putc(msg, ch);
			}
			HTChunk_puts(msg, ") ");
		    }
		}
		
		/* Error Location */
		if (showmask & HT_ERR_SHOW_LOCATION) {
		    HTChunk_puts(msg, "This occured in ");
		    HTChunk_puts(msg, HTError_location(pres));
		    HTChunk_putc(msg, '\n');
		}
	    }

	    /*
	    ** Make sure that we don't get this error more than once even
	    ** if we are keeping the error stack from one request to another
	    */
	    HTError_setIgnore(pres);
	    
	    /* If we only are show the most recent entry then break here */
	    if (showmask & HT_ERR_SHOW_FIRST)
		break;
	}
    }
    return HTChunk_toCString(msg);
}