Beispiel #1
0
static SECStatus
escapeAndQuote(char *dst, int dstlen, char *src, int srclen, EQMode *pEQMode)
{
    int i, reqLen=0;
    EQMode mode = pEQMode ? *pEQMode : minimalEscape;

    /* space for terminal null */
    reqLen = cert_RFC1485_GetRequiredLen(src, srclen, &mode) + 1;
    if (reqLen > dstlen) {
        PORT_SetError(SEC_ERROR_OUTPUT_LEN);
        return SECFailure;
    }

    if (mode == minimalEscapeAndQuote)
        *dst++ = C_DOUBLE_QUOTE;
    for (i = 0; i < srclen; i++) {
        char c = src[i];
        if (NEEDS_HEX_ESCAPE(c)) {
            *dst++ = C_BACKSLASH;
            *dst++ = hexChars[ (c >> 4) & 0x0f ];
            *dst++ = hexChars[  c       & 0x0f ];
        } else {
            if (NEEDS_ESCAPE(c) || (SPECIAL_CHAR(c) && mode == fullEscape)) {
                *dst++ = C_BACKSLASH;
            }
            *dst++ = c;
        }
    }
Beispiel #2
0
	mem_cache::mem_cache(const char* key_pre /* = NULL */,
		const char* addr /* = "127.0.0.1:11211" */, bool retry /* = true */,
		int conn_timeout /* = 180 */, int rw_timeout /* = 300 */,
		bool encode_key /* = true */)
	: m_coder(false, false)
	, m_conn_timeout(conn_timeout)
	, m_rw_timeout(rw_timeout)
	, m_encode_key(encode_key)	
	, m_opened(false)
	, m_retry(retry)
	, m_conn(NULL)
	{
		if (key_pre && *key_pre)
		{
			bool beCoding = false;

			m_key_pre = NEW acl::string(strlen(key_pre));
			while (*key_pre)
			{
				if (SPECIAL_CHAR(*key_pre) || !ACL_ISPRINT(*key_pre))
				{
					m_coder.encode_update(key_pre, 1, m_key_pre);
					beCoding = true;
				}
				else if (beCoding)
				{
					m_coder.encode_finish(m_key_pre);
					m_coder.reset();
					beCoding = false;
					*m_key_pre << (char) *key_pre;
				}
				else
					*m_key_pre << (char) *key_pre;
				key_pre++;
			}
			if (beCoding)
				m_coder.encode_finish(m_key_pre);
		}
		else
			m_key_pre = NULL;

		acl_assert(addr && *addr);
		m_addr = acl_mystrdup(addr);
		char* ptr = strchr(m_addr, ':');
		if (ptr == NULL)
			logger_fatal("addr(%s) invalid", addr);
		*ptr++ = 0;
		if (*ptr == 0)
			logger_fatal("addr(%s) invalid", addr);
		m_ip = m_addr;
		m_port = atoi(ptr);
		if (m_port <= 0)
			logger_fatal("addr(%s) invalid", addr);
	}
Beispiel #3
0
const string& memcache::build_key(const char* key, size_t klen)
{
	kbuf_.clear();
	if (keypre_)
		kbuf_.format("%s:", keypre_->c_str());

	coder_.reset();

	if (encode_key_)
	{
		coder_.encode_update(key, klen, &kbuf_);
		coder_.encode_finish(&kbuf_);
		return kbuf_;
	}

	bool beCoding = false;

	while (klen > 0)
	{
		if (SPECIAL_CHAR(*key) || !ACL_ISPRINT(*key))
		{
			coder_.encode_update(key, 1, &kbuf_);
			beCoding = true;
		}
		else if (beCoding)
		{
			coder_.encode_finish(&kbuf_);
			coder_.reset();
			beCoding = false;
			kbuf_ << (char) *key;
		}
		else
			kbuf_ << (char) *key;
		key++;
		klen--;
	}

	if (beCoding)
		coder_.encode_finish(&kbuf_);

	return kbuf_;
}
Beispiel #4
0
	const acl::string& mem_cache::get_key(const char* key, size_t klen)
	{
		m_kbuf.clear();
		if (m_key_pre)
			m_kbuf.format("%s:", m_key_pre->c_str());

		m_coder.reset();

		if (m_encode_key)
		{
			m_coder.encode_update(key, klen, &m_kbuf);
			m_coder.encode_finish(&m_kbuf);
			return (m_kbuf);
		}

		bool beCoding = false;

		while (klen > 0)
		{
			if (SPECIAL_CHAR(*key) || !ACL_ISPRINT(*key))
			{
				m_coder.encode_update(key, 1, &m_kbuf);
				beCoding = true;
			}
			else if (beCoding)
			{
				m_coder.encode_finish(&m_kbuf);
				m_coder.reset();
				beCoding = false;
				m_kbuf << (char) *key;
			}
			else
				m_kbuf << (char) *key;
			key++;
			klen--;
		}

		if (beCoding)
			m_coder.encode_finish(&m_kbuf);

		return (m_kbuf);
	}
Beispiel #5
0
/* Some characters must be escaped as a hex string, e.g. c -> \nn .
 * Others must be escaped by preceding with a '\', e.g. c -> \c , but
 * there are certain "special characters" that may be handled by either
 * escaping them, or by enclosing the entire attribute value in quotes.
 * A NULL value for pEQMode implies selecting minimalEscape mode.
 * Some callers will do quoting when needed, others will not.
 * If a caller selects minimalEscapeAndQuote, and the string does not
 * need quoting, then this function changes it to minimalEscape.
 */
static int
cert_RFC1485_GetRequiredLen(const char *src, int srclen, EQMode *pEQMode)
{
    int i, reqLen=0;
    EQMode mode = pEQMode ? *pEQMode : minimalEscape;
    PRBool needsQuoting = PR_FALSE;
    char lastC = 0;

    /* need to make an initial pass to determine if quoting is needed */
    for (i = 0; i < srclen; i++) {
        char c = src[i];
        reqLen++;
        if (NEEDS_HEX_ESCAPE(c)) {      /* c -> \xx  */
            reqLen += 2;
        } else if (NEEDS_ESCAPE(c)) {   /* c -> \c   */
            reqLen++;
        } else if (SPECIAL_CHAR(c)) {
            if (mode == minimalEscapeAndQuote) /* quoting is allowed */
                needsQuoting = PR_TRUE; /* entirety will need quoting */
            else if (mode == fullEscape)
                reqLen++;               /* MAY escape this character */
        } else if (OPTIONAL_SPACE(c) && OPTIONAL_SPACE(lastC)) {
            if (mode == minimalEscapeAndQuote) /* quoting is allowed */
                needsQuoting = PR_TRUE; /* entirety will need quoting */
        }
        lastC = c;
    }
    /* if it begins or ends in optional space it needs quoting */
    if (!needsQuoting && srclen > 0 && mode == minimalEscapeAndQuote &&
            (OPTIONAL_SPACE(src[srclen-1]) || OPTIONAL_SPACE(src[0]))) {
        needsQuoting = PR_TRUE;
    }

    if (needsQuoting)
        reqLen += 2;
    if (pEQMode && mode == minimalEscapeAndQuote && !needsQuoting)
        *pEQMode = minimalEscape;
    return reqLen;
}
Beispiel #6
0
memcache& memcache::set_prefix(const char* keypre)
{
	if (keypre == NULL || *keypre == 0)
	{
		delete keypre_;
		keypre_ = NULL;
		return *this;
	}

	bool beCoding = false;

	if (keypre_ == NULL)
		keypre_ = NEW string(strlen(keypre));
	else
		keypre_->clear();

	while (*keypre)
	{
		if (SPECIAL_CHAR(*keypre) || !ACL_ISPRINT(*keypre))
		{
			coder_.encode_update(keypre, 1, keypre_);
			beCoding = true;
		}
		else if (beCoding)
		{
			coder_.encode_finish(keypre_);
			coder_.reset();
			beCoding = false;
			*keypre_ << (char) *keypre;
		}
		else
			*keypre_ << (char) *keypre;
		keypre++;
	}

	if (beCoding)
		coder_.encode_finish(keypre_);
	return *this;
}
Beispiel #7
0
/* Returns the number of bytes in the value. 0 means failure. */
static int
scanVal(char **pbp, char *endptr, char *valBuf, int valBufSize)
{
    char *bp, *valBufp;
    int vallen = 0;
    PRBool isQuoted;

    PORT_Assert(valBufSize > 0);

    /* skip optional leading space */
    skipSpace(pbp, endptr);
    if(*pbp == endptr) {
        /* nothing left */
        return 0;
    }

    bp = *pbp;

    /* quoted? */
    if (*bp == C_DOUBLE_QUOTE) {
        isQuoted = PR_TRUE;
        /* skip over it */
        bp++;
    } else {
        isQuoted = PR_FALSE;
    }

    valBufp = valBuf;
    while (bp < endptr) {
        char c = *bp;
        if (c == C_BACKSLASH) {
            /* escape character */
            bp++;
            if (bp >= endptr) {
                /* escape charater must appear with paired char */
                *pbp = bp;
                return 0;
            }
            c = *bp;
            if (IS_HEX(c) && (endptr - bp) >= 2 && IS_HEX(bp[1])) {
                bp++;
                c = (char)((x2b[(PRUint8)c] << 4) | x2b[(PRUint8)*bp]);
            }
        } else if (c == '#' && bp == *pbp) {
            /* ignore leading #, quotation not required for it. */
        } else if (!isQuoted && SPECIAL_CHAR(c)) {
            /* unescaped special and not within quoted value */
            break;
        } else if (c == C_DOUBLE_QUOTE) {
            /* reached unescaped double quote */
            break;
        }
        /* append character */
        vallen++;
        if (vallen >= valBufSize) {
            *pbp = bp;
            return 0;
        }
        *valBufp++ = c;
        bp++;
    }

    /* strip trailing spaces from unquoted values */
    if (!isQuoted) {
        while (valBufp > valBuf) {
            char c = valBufp[-1];
            if (! OPTIONAL_SPACE(c))
                break;
            --valBufp;
        }
        vallen = valBufp - valBuf;
    }

    if (isQuoted) {
        /* insist that we stopped on a double quote */
        if (*bp != C_DOUBLE_QUOTE) {
            *pbp = bp;
            return 0;
        }
        /* skip over the quote and skip optional space */
        bp++;
        skipSpace(&bp, endptr);
    }

    *pbp = bp;

    /* null-terminate valBuf -- guaranteed at least one space left */
    *valBufp = 0;

    return vallen;
}
Beispiel #8
0
static void
hello_world			(void)
{
	int ch = 0;
	int i;

	pgno = -1;

	prints (" HELLO WORLD! ");
	PAUSE (30);

	ch = 4;
	TEXT_RESTART;
	prints ("Character set - Text 1");
	CR; CR;
	for (i = 32; i <= 127; i++) {
		printc (i);
		if ((i & 15) == 15)
			CR;
	}
	MIDROW (italic, 0);
	for (i = 32; i <= 127; i++) {
		printc (i);
		if ((i & 15) == 15)
			CR;
	}
	MIDROW (white, underline);
	for (i = 32; i <= 127; i++) {
		printc (i);
		if ((i & 15) == 15)
			CR;
	}
	MIDROW (white, 0);
	prints ("Special: ");
	for (i = 0; i <= 15; i++) {
		SPECIAL_CHAR (i);
	}
	CR;
	prints ("DONE - Text 1 ");
	PAUSE (50);

	ch = 5;
	TEXT_RESTART;
	prints ("Styles - Text 2");
	CR; CR;
	MIDROW (white, 0); prints ("WHITE"); CR;
	MIDROW (red, 0); prints ("RED"); CR;
	MIDROW (green, 0); prints ("GREEN"); CR;
	MIDROW (blue, 0); prints ("BLUE"); CR;
	MIDROW (yellow, 0); prints ("YELLOW"); CR;
	MIDROW (cyan, 0); prints ("CYAN"); CR;
	MIDROW (magenta, 0); prints ("MAGENTA"); BLACK (0); CR;
	BACKG (white, opaque); prints ("WHITE"); BACKG (black, opaque); CR;
	BACKG (red, opaque); prints ("RED"); BACKG (black, opaque); CR;
	BACKG (green, opaque); prints ("GREEN"); BACKG (black, opaque); CR;
	BACKG (blue, opaque); prints ("BLUE"); BACKG (black, opaque); CR;
	BACKG (yellow, opaque); prints ("YELLOW"); BACKG (black, opaque); CR;
	BACKG (cyan, opaque); prints ("CYAN"); BACKG (black, opaque); CR;
	BACKG (magenta, opaque); prints ("MAGENTA"); BACKG (black, opaque); CR;
	TRANSP;
	prints (" TRANSPARENT BACKGROUND ");
	BACKG (black, opaque); CR;
	MIDROW (white, 0); FLASH_ON;
	prints (" Flashing Text  (if implemented) "); CR;
	MIDROW (white, 0); prints ("DONE - Text 2 ");
	PAUSE (50);

	ch = 0;
	ROLL_UP (2);
	ERASE_DISPLAY;
	prints (" ROLL-UP TEST "); CR; PAUSE (20);
	prints (">> A young Jedi named Darth"); CR; PAUSE (20);
	prints ("Vader, who was a pupil of"); CR; PAUSE (20);
	prints ("mine until he turned to evil,"); CR; PAUSE (20);
	prints ("helped the Empire hunt down"); CR; PAUSE (20);
	prints ("and destroy the Jedi Knights."); CR; PAUSE (20);
	prints ("He betrayed and murdered your"); CR; PAUSE (20);
	prints ("father. Now the Jedi are all"); CR; PAUSE (20);
	prints ("but extinct. Vader was seduced"); CR; PAUSE (20);
	prints ("by the dark side of the Force."); CR; PAUSE (20);                        
	prints (">> The Force?"); CR; PAUSE (20);
	prints (">> Well, the Force is what gives"); CR; PAUSE (20);
	prints ("a Jedi his power. It's an energy"); CR; PAUSE (20);
	prints ("field created by all living"); CR; PAUSE (20);
	prints ("things."); CR; PAUSE (20);
	prints ("It surrounds us and penetrates"); CR; PAUSE (20);
	prints ("us."); CR; PAUSE (20);
	prints ("It binds the galaxy together."); CR; PAUSE (20);
	CR; PAUSE (30);
	prints (" DONE - Caption 1 ");
	PAUSE (30);

	ch = 1;
	RESUME_DIRECT;
	ERASE_DISPLAY;
	MIDROW (yellow, 0);
	INDENT (2, 10, 0); prints (" FOO "); CR;
	INDENT (3, 10, 0); prints (" MIKE WAS HERE "); CR; PAUSE (20);
	MIDROW (red, 0);
	INDENT (6, 13, 0); prints (" AND NOW... "); CR;
	INDENT (8, 13, 0); prints (" HE'S HERE "); CR; PAUSE (20);
	PREAMBLE (12, cyan, 0);
	prints ("01234567890123456789012345678901234567890123456789"); CR;
	MIDROW (white, 0);
	prints (" DONE - Caption 2 "); CR;
	PAUSE (30);
}