コード例 #1
0
ファイル: anoubis_dump.c プロジェクト: genua/anoubis
void __anoubis_dump(struct anoubis_msg * m, const char * pre, char **pstr)
{
	uint32_t opcode;

	__dstr = malloc(BUFSIZ);
	if (!__dstr)
		return;
	memset(__dstr, 0, BUFSIZ);

	snprintf(DSTR, DLEN, "%s:", pre?pre:"(null)");
	ASSERT(VERIFY_FIELD(m, general, type));
	ASSERT(m->length < INT_MAX);
	ASSERT(crc32_check(m->u.buf, (int) m->length));
	opcode = get_value(m->u.general->type);
	switch(opcode) {
	CASE(ANOUBIS_REPLY, ack)
	CASE(ANOUBIS_N_DELEGATE, ack)
	CASE(ANOUBIS_C_HELLO, hello)
	CASE(ANOUBIS_C_VERSEL, versel)
	CASE(ANOUBIS_C_AUTH, general)
	CASE(ANOUBIS_C_AUTHREPLY, authreply)
	CASE(ANOUBIS_C_OPTREQ, stringlist)
	CASE(ANOUBIS_C_OPTACK, stringlist)
	CASE(ANOUBIS_C_PROTOSEL, stringlist)
	CASE(ANOUBIS_C_CLOSEREQ, general)
	CASE(ANOUBIS_C_CLOSEACK, general)
	CASE2(ANOUBIS_N_NOTIFY, notify, 0)
	CASE2(ANOUBIS_N_ASK, notify, 0)
	CASE2(ANOUBIS_N_LOGNOTIFY, notify, 1)
	CASE(ANOUBIS_N_POLICYCHANGE, policychange)
	CASE(ANOUBIS_N_PGCHANGE, pgchange)
	CASE(ANOUBIS_N_STATUSNOTIFY, statusnotify)
	CASE(ANOUBIS_N_REGISTER, notifyreg)
	CASE(ANOUBIS_N_UNREGISTER, notifyreg)
	CASE(ANOUBIS_N_RESYOU, notifyresult)
	CASE(ANOUBIS_N_RESOTHER, notifyresult)
	CASE(ANOUBIS_P_REQUEST, policyrequest)
	CASE(ANOUBIS_P_REPLY, policyreply)
	CASE(ANOUBIS_P_CSUMREQUEST, checksumrequest)
	CASE(ANOUBIS_P_CSUM_LIST, checksumpayload)
	CASE(ANOUBIS_P_CSMULTIREQUEST, csmultireq)
	CASE(ANOUBIS_P_CSMULTIREPLY, csmultireply)
	CASE(ANOUBIS_P_VERSION, general)
	CASE(ANOUBIS_P_VERSIONREPLY, version)
	CASE(ANOUBIS_P_LISTREQ, listreq)
	CASE(ANOUBIS_P_LISTREP, listreply)
	default:
		snprintf(DSTR, DLEN, " type = %x", opcode);
		dump_general(m->u.general, m->length-CSUM_LEN);
	}

	if (pstr) {
		*pstr = __dstr;
	} else {
		printf("%s\n", __dstr);
		free(__dstr);
	}
}
コード例 #2
0
QByteArray getCommandName(const DoorActionType action)
{
#define CASE2(UPPER, s) \
    do { \
    case DoorActionType::UPPER: \
        return s; \
    } while (false)
    switch (action) {
        CASE2(OPEN, "open");
        CASE2(CLOSE, "close");
        CASE2(LOCK, "lock");
        CASE2(UNLOCK, "unlock");
        CASE2(PICK, "pick");
        CASE2(ROCK, "throw rock");
        CASE2(BASH, "bash");
        CASE2(BREAK, "cast 'break door'");
        CASE2(BLOCK, "cast 'block door'");

    case DoorActionType::NONE:
        break;
    }

    // REVISIT: use "look" ?
    return "";
#undef CASE2
}
コード例 #3
0
ファイル: 3.02.escape.c プロジェクト: liuyang1/test
int test() {
	CASE0("abc");
	CASE0("a\tc");
	CASE0("a\bc");
	CASE0("a\b\nc");
	CASE0("a\'\"\\c");
	CASE0("ac\x0e");
	CASE0("ac\x7f");
	CASE1("abc");
	CASE1("a\\tc");
	CASE1("a\\bc");
	CASE1("a\\b\\nc");
	CASE1("a\\\'\\\"\\\\c");
	CASE1("ac\\x0e");
	CASE1("ac\\x7f");
	CASE2("abc");
	CASE2("a\tc");
	CASE2("a\bc");
	CASE2("a\b\nc");
	CASE2("a\'\"\\c");
	CASE2("ac\x0e");
	CASE2("ac\x7f");
	CASE3("abc");
	CASE3("a\\tc");
	CASE3("a\\bc");
	CASE3("a\\b\\nc");
	CASE3("a\\\'\\\"\\\\c");
	CASE3("ac\\x0e");
	CASE3("ac\\x7f");
	return 0;
}