Exemplo n.º 1
0
ustring DataValue::serializeStrList(void *value) {
	ustring result("#");
	StringList list;
	list = *(ustring*)value;
	for(StringList::iterator line = list.begin(); line != list.end(); line++)
		result += int_to_str(line->size()) + ":" + *line + "|";
	return result;
}
Exemplo n.º 2
0
Command::Command(const char* first, const char* last) throw(parse_error)
		: from(INVALID_SID), to(INVALID_SID), dirty(false), full(first, last)
{
	initNumPosParams();
	// optimize later
	// this is lazy due to a DC++ bug that sends empty parameters...
	// ideally, we should not be using it
	StringList sl = Util::lazyStringTokenize(full);
	full += '\n';
	if(full.size() < 5 || sl[0].size() != 4)
		throw parse_error("invalid message type");
	action = sl[0][0];
	cmd = (CmdInt)(stringToFourCC(sl[0]) & 0xFFFFFF00);
	StringList::size_type loc;	// message parameters start at this index

	switch(action) {
	case 'F':
		from = ADC::toSid(sl[1]);
		features = sl[2];
		checkFeatures();
		loc = 3;
		break;
	case 'D':
	case 'E':
		from = ADC::toSid(sl[1]);
		to = ADC::toSid(sl[2]);
		loc = 3;
		break;
	case 'B':
	case 'S':
		from = ADC::toSid(sl[1]);
		loc = 2;
		break;
	case 'I':
	case 'H':
	case 'L':
		loc = 1;
		break;
	default:
		throw parse_error(string("invalid action type '") + action + '\'');
	}

	if (loc >= sl.size())
		throw parse_error("not enough tokens for message type");
	if (numPosParams.count(cmd)) {
		// known command -- check that positional and named params are correct
		if (loc + numPosParams[cmd] > sl.size())
			throw parse_error("missing parameters");
		for (StringList::iterator i = sl.begin() + loc + numPosParams[cmd]; i != sl.end(); ++i) {
			// param name parts can't be escaped chars
			if (i->size() < 2 || ADC::CSE(i->substr(0, 2)).size() != 2)
				throw parse_error("invalid named parameter: " + *i);
		}
	}
	params.resize(sl.size() - loc);
	transform(sl.begin() + loc, sl.end(), params.begin(), &ADC::CSE);
}