string CNetScheduleKeyGenerator::GenerateCompoundID(unsigned id, CCompoundIDPool id_pool) const { CCompoundID ns_key_cid = id_pool.NewID(eCIC_NetScheduleJobKey); ns_key_cid.AppendID(id); if (m_UseIPv4Addr) ns_key_cid.AppendIPv4SockAddr(m_HostIPv4Addr, m_Port); else { ns_key_cid.AppendHost(m_HostName); ns_key_cid.AppendPort(m_Port); } if (!m_QueueName.empty()) ns_key_cid.AppendDatabaseName(m_QueueName); return ns_key_cid.ToString(); }
CCompoundID CCompoundIDDumpParser::ParseID() { SkipSpace(); x_SaveErrPos(); if (x_EOF() || !isalpha(*m_Ch)) { CID_PARSER_EXCEPTION("missing compound ID class name"); } const char* token_begin = m_Ch; do ++m_Ch; while (!x_EOF() && isalpha(*m_Ch)); CTempString new_id_class_name(token_begin, m_Ch - token_begin); ECompoundIDClass new_id_class = eCIC_NumberOfClasses; switch (*token_begin) { case 'C': if (new_id_class_name == CIC_GENERICID_CLASS_NAME) new_id_class = eCIC_GenericID; break; case 'N': if (new_id_class_name == CIC_NETCACHEBLOBKEY_CLASS_NAME) new_id_class = eCIC_NetCacheBlobKey; else if (new_id_class_name == CIC_NETSCHEDULEJOBKEY_CLASS_NAME) new_id_class = eCIC_NetScheduleJobKey; else if (new_id_class_name == CIC_NETSTORAGEOBJECTLOC_CLASS_NAME) new_id_class = eCIC_NetStorageObjectLoc; else if (new_id_class_name == CIC_NETSTORAGEOBJECTLOC_CLASS_NAME_V1) new_id_class = eCIC_NetStorageObjectLocV1; } if (new_id_class == eCIC_NumberOfClasses) { CID_PARSER_EXCEPTION("unknown compound ID class '" << new_id_class_name << '\''); } SkipSpace(); if (x_EOF() || *m_Ch != '{') { x_SaveErrPos(); CID_PARSER_EXCEPTION("missing '{'"); } ++m_Ch; SkipSpaceToNextToken(); CCompoundID result(m_Pool.NewID(new_id_class)); if (*m_Ch != '}') for (;;) { token_begin = m_Ch; x_SaveErrPos(); do ++m_Ch; while (isalnum(*m_Ch) || *m_Ch == '_'); CTempString field_type_name(token_begin, m_Ch - token_begin); ECompoundIDFieldType field_type = eCIT_NumberOfTypes; switch (*token_begin) { case '}': CID_PARSER_EXCEPTION("a field type name is required"); case 'b': if (field_type_name == CIT_BOOLEAN_TYPE_NAME) field_type = eCIT_Boolean; break; case 'd': if (field_type_name == CIT_DATABASE_NAME_TYPE_NAME) field_type = eCIT_DatabaseName; break; case 'f': if (field_type_name == CIT_FLAGS_TYPE_NAME) field_type = eCIT_Flags; break; case 'h': if (field_type_name == CIT_HOST_TYPE_NAME) field_type = eCIT_Host; break; case 'i': if (field_type_name == CIT_ID_TYPE_NAME) field_type = eCIT_ID; else if (field_type_name == CIT_INTEGER_TYPE_NAME) field_type = eCIT_Integer; else if (field_type_name == CIT_IPV4_ADDRESS_TYPE_NAME) field_type = eCIT_IPv4Address; else if (field_type_name == CIT_IPV4_SOCK_ADDR_TYPE_NAME) field_type = eCIT_IPv4SockAddr; break; case 'n': if (field_type_name == CIT_NESTED_CID_TYPE_NAME) field_type = eCIT_NestedCID; else if (field_type_name == CIT_CUE_TYPE_NAME) field_type = eCIT_Cue; break; case 'p': if (field_type_name == CIT_OBJECTREF_TYPE_NAME) field_type = eCIT_ObjectRef; else if (field_type_name == CIT_PORT_TYPE_NAME) field_type = eCIT_Port; break; case 'r': if (field_type_name == CIT_RANDOM_TYPE_NAME) field_type = eCIT_Random; break; case 's': if (field_type_name == CIT_SEQ_ID_TYPE_NAME) field_type = eCIT_SeqID; else if (field_type_name == CIT_SERVICE_NAME_TYPE_NAME) field_type = eCIT_ServiceName; else if (field_type_name == CIT_STRING_TYPE_NAME) field_type = eCIT_String; break; case 't': if (field_type_name == CIT_LABEL_TYPE_NAME) field_type = eCIT_Label; else if (field_type_name == CIT_TAX_ID_TYPE_NAME) field_type = eCIT_TaxID; else if (field_type_name == CIT_TIMESTAMP_TYPE_NAME) field_type = eCIT_Timestamp; } if (field_type == eCIT_NumberOfTypes) { CID_PARSER_EXCEPTION("unknown field type '" << field_type_name << '\''); } SkipSpaceToNextToken(); switch (field_type) { case eCIT_ID: result.AppendID(x_ReadUint8()); break; case eCIT_Integer: result.AppendInteger(x_ReadInt8()); break; case eCIT_ServiceName: result.AppendServiceName(x_ReadString()); break; case eCIT_DatabaseName: result.AppendDatabaseName(x_ReadString()); break; case eCIT_Timestamp: result.AppendTimestamp(x_ReadInt8()); break; case eCIT_Random: { x_SaveErrPos(); Uint8 random_number = x_ReadUint8(); if (random_number >= ((Uint8) 1) << 8 * sizeof(Uint4)) { CID_PARSER_EXCEPTION( "random number exceeds maximum allowed value"); } result.AppendRandom((Uint4) random_number); } break; case eCIT_IPv4Address: result.AppendIPv4Address(x_ReadIPv4Address()); break; case eCIT_Host: result.AppendHost(x_ReadString()); break; case eCIT_Port: result.AppendPort(x_ReadPortNumber()); break; case eCIT_IPv4SockAddr: { Uint4 ipv4_address = x_ReadIPv4Address(); if (x_EOF() || *m_Ch != ':') { x_SaveErrPos(); CID_PARSER_EXCEPTION("missing ':'"); } ++m_Ch; result.AppendIPv4SockAddr(ipv4_address, x_ReadPortNumber()); } break; case eCIT_ObjectRef: result.AppendObjectRef(x_ReadString()); break; case eCIT_String: result.AppendString(x_ReadString()); break; case eCIT_Boolean: { token_begin = m_Ch; x_SaveErrPos(); while (!x_EOF() && isalpha(*m_Ch)) ++m_Ch; CTempString bool_val(token_begin, m_Ch - token_begin); if (bool_val == "false") result.AppendBoolean(false); else if (bool_val == "true") result.AppendBoolean(true); else { CID_PARSER_EXCEPTION("invalid boolean value \"" << bool_val << '\"'); } } break; case eCIT_Flags: result.AppendFlags(x_ReadUint8()); break; case eCIT_Label: result.AppendLabel(x_ReadString()); break; case eCIT_Cue: result.AppendCue(x_ReadUint8()); break; case eCIT_SeqID: result.AppendSeqID(x_ReadString()); break; case eCIT_TaxID: result.AppendTaxID(x_ReadUint8()); break; case eCIT_NestedCID: result.AppendNestedCID(ParseID()); break; case eCIT_NumberOfTypes: break; } SkipSpaceToNextToken(); if (*m_Ch == ',') ++m_Ch; else if (*m_Ch == '}') break; else { x_SaveErrPos(); CID_PARSER_EXCEPTION("either ',' or '}' expected"); } SkipSpaceToNextToken(); } ++m_Ch; return result; }