Beispiel #1
0
static gboolean
append_entryid_section (GByteArray *entryid, const char **permanenturl)
{
	const char *p;
	char buf[44], byte;
	int endlen;

	p = *permanenturl;
	if (strspn (p, "0123456789abcdefABCDEF") != 32)
		return FALSE;
	if (p[32] != '-')
		return FALSE;
	endlen = strspn (p + 33, "0123456789abcdefABCDEF");
	if (endlen > 6)
		return FALSE;

	/* Expand to the full form by replacing the "-" with "0"s */
	memcpy (buf, p, 32);
	memset (buf + 32, '0', sizeof (buf) - 32 - endlen);
	memcpy (buf + sizeof (buf) - endlen, p + 33, endlen);

	p = buf;
	while (p < buf + sizeof (buf)) {
		byte = (HEXVAL (*p) << 4) + HEXVAL (*(p + 1));
		g_byte_array_append (entryid, &byte, 1);
		p += 2;
	}

	*permanenturl += 33 + endlen;
	return TRUE;
}
Beispiel #2
0
/**
 * e2k_uri_decode:
 * @part: a piece of a URI
 *
 * Undoes URI-escaping in @part in-place.
 **/
void
e2k_uri_decode (char *part)
{
	guchar *s, *d;

	s = d = (guchar *)part;
	while (*s) {
		if (*s == '%') {
			if (isxdigit (s[1]) && isxdigit (s[2])) {
				*d++ = HEXVAL (s[1]) * 16 + HEXVAL (s[2]);
				s += 3;
			} else
				*d++ = *s++;
		} else
			*d++ = *s++;
	}
	*d = '\0';
}
void CLasNmeaSource::StoreNmeaString(const TDesC8& aData)
	{
	TInt length = aData.Length();
	
	for (TInt index = 0; index < length; index++)
		{
		TUint ch = aData[index];
	
		//<<TODO>> Still need to handle the escape char "^"
			
		switch(iNmeaReadState)
			{
			case ENmeaWantStart:
				{
				if (ch == '$' || ch == '!')
					{
					iNmeaReadState   = ENmeaWantTerminator;
					iNmeaSentence.SetLength(0);
					iNmeaCheckSum    = 0;
					iNmeaNumFields   = 0;
					iNmeaFieldStart  = 0;
					iNmeaFieldLength = 0;
					}
				break;
				}
		
			case ENmeaWantTerminator:
				{
				AppendNmeaFieldChar(ch);

				if (ch == '*') // Got the sentence terminator
					{
					iNmeaReadState = ENmeaWantCheck1;
					}
				else 
					{
					iNmeaCheckSum ^= ch;
					}
				break;
				}

			case ENmeaWantCheck1:
				{
				iNmeaCheckValue = HEXVAL(ch) << 4;	
				iNmeaReadState = ENmeaWantCheck2;
				break;
				}

			case ENmeaWantCheck2:
				{
				iNmeaCheckValue += HEXVAL(ch);	
				iNmeaReadState   = ENmeaWantStart;
				LASLOG2("CLasNmeaSource::StoreNmeaString - CheckSum: %d", iNmeaCheckSum);
				LASLOG2("CLasNmeaSource::StoreNmeaString - CheckVal: %d", iNmeaCheckValue);		
				LASLOGDES(iNmeaSentence);
				
				if (iNmeaCheckSum == iNmeaCheckValue)
					{
					if (iMonitoring)
						{
						iObserver->HandleNmeaSentence(iNmeaFields, iNmeaNumFields);					
						}
					}
					else
						{
						LASLOG("***WARNING - BAD CHECKSUM***");
						}
				break;
				}
			}
		}
	}