static bool simplechat_ChatMessage_extraInfo_get_seq_val_cb(uintptr_t in_data, int index, CDR_TypeCode_t type, qeo_t2d_types_t *value){ const org_qeo_sample_simplechat_ChatMessage_extraInfo_seq *extraInfo = (const org_qeo_sample_simplechat_ChatMessage_extraInfo_seq *)in_data; value->char_val = ((int8_t *)DDS_SEQ_DATA(*extraInfo))[index]; return true; }
static bool simplechat_ChatMessage_colorlist_get_seq_val_cb(uintptr_t in_data, int index, CDR_TypeCode_t type, qeo_t2d_types_t *value){ const myenum_seq *colorlist = (const myenum_seq *)in_data; value->enum_val = ((qeo_enum_value_t *)DDS_SEQ_DATA(*colorlist))[index]; return true; }
DDS_ReturnCode_t get_identity_token (Identity_t handle, unsigned char *identity, size_t *identity_length) { Token_t *tokens, *token; DDS_IdentityToken *idp; DDS_ReturnCode_t error; tokens = sec_get_identity_tokens (handle, SECC_DTLS_UDP, &error); if (!tokens) return (error); for (token = tokens; token; token = token->next) if (token->encoding) { idp = token->data; if (!idp->binary_value1 || DDS_SEQ_LENGTH (*idp->binary_value1) > *identity_length || !DDS_SEQ_LENGTH (*idp->binary_value1)) return (DDS_RETCODE_BAD_PARAMETER); memcpy (identity, DDS_SEQ_DATA (*idp->binary_value1), DDS_SEQ_LENGTH (*idp->binary_value1)); break; } sec_release_id_tokens (tokens); return ((token) ? DDS_RETCODE_OK : DDS_RETCODE_BAD_PARAMETER); }
static void run_writer(pid_t peer) { qeo_factory_t *factory; qeocore_type_t *type; qeocore_writer_t *writer; qeocore_data_t *data, *seqdata; byte_array_t array; int status, i; /* initialize */ assert(NULL != (factory = qeocore_factory_new(QEO_IDENTITY_DEFAULT))); init_factory(factory); assert(NULL != (type = type_register(factory))); assert(NULL != (writer = qeocore_writer_open(factory, type, NULL, QEOCORE_EFLAG_STATE_DATA | QEOCORE_EFLAG_ENABLE, NULL, NULL))); log_pid("writer initialized"); assert(NULL != (data = qeocore_writer_data_new(writer))); assert(QEO_OK == qeocore_data_set_member(data, _size_id, &_test_size)); /* init sequence */ DDS_SEQ_INIT(array); assert(NULL != (DDS_SEQ_DATA(array) = malloc(_test_size * sizeof(char)))); DDS_SEQ_LENGTH(array) = DDS_SEQ_MAXIMUM(array) = _test_size; for (i = 0; i < _test_size; i++) { DDS_SEQ_ITEM(array, i) = i & 0xff; } assert(QEO_OK == qeocore_data_get_member(data, _buf_id, &seqdata)); assert(QEO_OK == qeocore_data_sequence_set(seqdata, (const qeo_sequence_t *)&array, 0)); assert(QEO_OK == qeocore_data_set_member(data, _buf_id, &seqdata)); /* write */ assert(QEO_OK == qeocore_writer_write(writer, data)); log_pid("writer wrote data"); assert(peer == waitpid(peer, &status, 0)); assert(0 == status); log_pid("writer done"); /* clean up */ free(DDS_SEQ_DATA(array)); qeocore_data_free(seqdata); qeocore_data_free(data); qeocore_writer_close(writer); qeocore_type_free(type); qeocore_factory_close(factory); }
static bool simplechat_ChatMessage_colorlist_set_seq_val_cb(uintptr_t out_data, int index, CDR_TypeCode_t type, qeo_t2d_types_t *value){ DDS_VoidPtrSeq *seq = (DDS_VoidPtrSeq *)out_data; switch(type){ case CDR_TYPECODE_ENUM: ((qeo_enum_value_t *)DDS_SEQ_DATA(*seq))[index] = value->enum_val; break; default: qeo_log_e("Unsupported type %d", type); return false; } return true; }
void ctt_send (Domain_t *dp, Participant_t *pp, Endpoint_t *sep, Endpoint_t *dep, DDS_ParticipantVolatileSecureMessage *msg) { Writer_t *wp; DDS_Time_t time; DDS_InstanceHandleSeq handles; DDS_InstanceHandle_t h; int error; CTT_ASSERT (dp); memcpy (msg->message_identity.source_guid, dp->participant.p_guid_prefix.prefix, 12); msg->message_identity.sequence_number = psmp_seqnr++; if (pp) memcpy (msg->destination_participant_key, pp->p_guid_prefix.prefix, 12); if (dep) { memcpy (msg->destination_endpoint_key, pp->p_guid_prefix.prefix, 12); memcpy (msg->destination_endpoint_key + 12, dep->entity_id.id, 4); memcpy (msg->source_endpoint_key, dp->participant.p_guid_prefix.prefix, 12); memcpy (msg->source_endpoint_key + 12, sep->entity_id.id, 4); } CTT_TRACE ('T', msg); wp = (Writer_t *) dp->participant.p_builtin_ep [EPB_PARTICIPANT_VOL_SEC_W]; /* Send participant data. */ if (pp) { DDS_SEQ_INIT (handles); h = pp->p_builtin_ep [EPB_PARTICIPANT_VOL_SEC_R]->entity.handle; DDS_SEQ_LENGTH (handles) = DDS_SEQ_MAXIMUM (handles) = 1; DDS_SEQ_DATA (handles) = &h; sys_gettime ((Time_t *) &time); error = DDS_DataWriter_write_w_timestamp_directed (wp, msg, 0, &time, &handles); if (error) fatal_printf ("ctt_send: error sending crypto tokens message!"); } else { sys_gettime ((Time_t *) &time); error = DDS_DataWriter_write_w_timestamp (wp, msg, 0, &time); if (error) fatal_printf ("ctt_send: error sending crypto tokens message!"); } CTT_ASSERT (dp); }
static Permissions_t sp_check_rem_perms (const SEC_PERM *pp, Identity_t local, Identity_t remote, DDS_PermissionsToken *token, DDS_PermissionsCredential *cred) { DDS_SecurityReqData data; DDS_ReturnCode_t ret; ARG_NOT_USED (pp) ARG_NOT_USED (token) data.handle = remote; data.secure = local; data.data = DDS_SEQ_DATA (*cred->binary_value1); data.length = DDS_SEQ_LENGTH (*cred->binary_value1); data.name = cred->class_id; ret = sec_access_control_request (DDS_VALIDATE_REMOTE_PERM, &data); if (ret) return (0); return (data.handle); }
static qeo_retcode_t array_to_data(json_t *elemtype, json_t *json_data, qeocore_data_t *data) { qeo_retcode_t result = QEO_EINVAL; json_t *type = json_object_get(elemtype, KEY_QEO_TYPE_CODE); // Mandatory if ((NULL == type) || (!json_is_integer(type))) { return result; } qeo_sequence_t seq = { 0 }; if (QEO_OK != qeocore_data_sequence_new(data, &seq, json_array_size(json_data))) { result = QEO_EFAIL; return result; } qeocore_typecode_t qeoTypeCode = (qeocore_typecode_t) json_integer_value(type); result = QEO_OK; int i; int numOfElem = json_array_size(json_data); for (i = 0; i < numOfElem; ++i) { json_t *elem = json_array_get(json_data, i); if (NULL == elem) { result = QEO_EFAIL; break; } result = QEO_EFAIL; switch (qeoTypeCode) { case QEOCORE_TYPECODE_BOOLEAN: { if (json_is_boolean(elem)) { ((qeo_boolean_t *)DDS_SEQ_DATA(seq))[i] = json_is_true(elem); result = QEO_OK; } } break; case QEOCORE_TYPECODE_INT8: { if (json_is_integer(elem)) { json_int_t json_value = json_integer_value(elem); if ((-128LL <= json_value) && (json_value <= 127LL)) { ((int8_t *)DDS_SEQ_DATA(seq))[i] = (int8_t) json_value; result = QEO_OK; } } } break; case QEOCORE_TYPECODE_INT16: { if (json_is_integer(elem)) { json_int_t json_value = json_integer_value(elem); if ((-32768LL <= json_value) && (json_value <= 32767LL)) { ((int16_t *)DDS_SEQ_DATA(seq))[i] = (int16_t) json_value; result = QEO_OK; } } } break; case QEOCORE_TYPECODE_INT32: { if (json_is_integer(elem)) { json_int_t json_value = json_integer_value(elem); if ((-2147483648LL <= json_value) && (json_value <= 2147483647LL)) { ((int32_t *)DDS_SEQ_DATA(seq))[i] = (int32_t) json_value; result = QEO_OK; } } } break; case QEOCORE_TYPECODE_INT64: { if (json_is_integer(elem)) { ((int64_t *)DDS_SEQ_DATA(seq))[i] = (int64_t) json_integer_value(elem); result = QEO_OK; } if (json_is_string(elem)) { const char *qeo_value = json_string_value(elem); intmax_t num = strtoimax(qeo_value, NULL, 10); ((int64_t *)DDS_SEQ_DATA(seq))[i] = (int64_t) num; result = QEO_OK; } } break; case QEOCORE_TYPECODE_FLOAT32: { /* *Also allow integer values, when float:0.0 is written in a webview then JSON.stringify can result into float:0 *meaning that the float 0.0 is transformed in an integer like 0, that's why we also need to allow integers, to be *able to handle these rounding issues. */ if (json_is_real(json_data) || json_is_integer(json_data)) { ((float *)DDS_SEQ_DATA(seq))[i] = (float) json_real_value(elem); result = QEO_OK; } } break; case QEOCORE_TYPECODE_STRING: { if (json_is_string(elem)) { ((char **)DDS_SEQ_DATA(seq))[i] = strdup(json_string_value(elem)); result = QEO_OK; } } break; case QEOCORE_TYPECODE_STRUCT: { if (json_is_object(elem)) { json_t *item = json_object_get(elemtype, KEY_ITEM); if ((NULL != item) && json_is_object(item)) { qeocore_data_t *qeo_value = ((qeocore_data_t **)DDS_SEQ_DATA(seq))[i]; result = object_to_data(item, elem, qeo_value); } } } break; case QEOCORE_TYPECODE_SEQUENCE: { if (json_is_array(elem)) { json_t *items = json_object_get(elemtype, KEY_ITEMS); if ((NULL != items) && json_is_object(items)) { qeocore_data_t *qeo_value = ((qeocore_data_t **)DDS_SEQ_DATA(seq))[i]; result = array_to_data(items, elem, qeo_value); } } } break; case QEOCORE_TYPECODE_ENUM: { if (!json_is_integer(json_data)){ qeo_log_e("Enum should be integer"); break; } qeo_enum_value_t enum_val = (qeo_enum_value_t) json_integer_value(json_data); if (is_valid_enum_value(elemtype, enum_val) == false){ qeo_log_e("Could not convert json to enum"); break; } ((qeo_enum_value_t *)DDS_SEQ_DATA(seq))[i] = enum_val; } break; } if (QEO_OK != result) { break; } } if (QEO_OK == result) { result = qeocore_data_sequence_set(data, &seq, 0); } return result; }
static json_t *array_data_to_json(const json_t *typedesc, qeocore_data_t *data) { json_t *json_data = NULL; qeo_sequence_t seq = { 0 }; json_t *type = json_object_get(typedesc, KEY_QEO_TYPE_CODE); // Mandatory if ((NULL == type) || (!json_is_integer(type)) || (QEO_OK != qeocore_data_sequence_get(data, &seq, 0, QEOCORE_SIZE_UNLIMITED))) { return json_data; } json_data = json_array(); qeocore_typecode_t qeoTypeCode = (qeocore_typecode_t) json_integer_value(type); int i; int numOfElem = DDS_SEQ_LENGTH(seq); for (i = 0; i < numOfElem; ++i) { switch (qeoTypeCode) { case QEOCORE_TYPECODE_BOOLEAN: { qeo_boolean_t bool_value = ((qeo_boolean_t *)DDS_SEQ_DATA(seq))[i]; json_array_append_new(json_data, bool_value ? (json_true()) : (json_false())); } break; case QEOCORE_TYPECODE_INT8: { int8_t int_value = ((int8_t *)DDS_SEQ_DATA(seq))[i]; json_array_append_new(json_data, json_integer((json_int_t)int_value)); } break; case QEOCORE_TYPECODE_INT16: { int8_t int_value = ((int16_t *)DDS_SEQ_DATA(seq))[i]; json_array_append_new(json_data, json_integer((json_int_t)int_value)); } break; case QEOCORE_TYPECODE_INT32: { int8_t int_value = ((int32_t *)DDS_SEQ_DATA(seq))[i]; json_array_append_new(json_data, json_integer((json_int_t)int_value)); } break; case QEOCORE_TYPECODE_INT64: { int64_t int_value = ((int64_t *)DDS_SEQ_DATA(seq))[i]; char *char_value = NULL; if (-1 != asprintf(&char_value, "%" PRId64 "", int_value)) { json_array_append_new(json_data, json_string(char_value)); free(char_value); } } break; case QEOCORE_TYPECODE_STRING: { char *char_value = ((char **)DDS_SEQ_DATA(seq))[i]; json_array_append_new(json_data, json_string(char_value)); } break; case QEOCORE_TYPECODE_STRUCT: { json_t *item = json_object_get(typedesc, KEY_ITEM); if ((NULL != item) && json_is_object(item)) { qeocore_data_t *object_value = ((qeocore_data_t **)DDS_SEQ_DATA(seq))[i]; json_t *json_element = object_data_to_json(item, object_value); if (NULL != json_element) { json_array_append_new(json_data, json_element); } else { json_decref(json_data); json_data = NULL; } } else { json_decref(json_data); json_data = NULL; } } break; case QEOCORE_TYPECODE_SEQUENCE: { json_t *items = json_object_get(typedesc, KEY_ITEMS); if ((NULL != items) && json_is_object(items)) { qeocore_data_t *element_value = ((qeocore_data_t **)DDS_SEQ_DATA(seq))[i]; json_t *json_element = array_data_to_json(items, element_value); if (NULL != json_element) { json_array_append_new(json_data, json_element); } else { json_decref(json_data); json_data = NULL; } } else { json_decref(json_data); json_data = NULL; } } break; case QEOCORE_TYPECODE_ENUM: { qeo_enum_value_t enum_value = ((qeo_enum_value_t *)DDS_SEQ_DATA(seq))[i]; if (is_valid_enum_value(typedesc, enum_value) == false){ qeo_log_e("Not a valid enum value"); break; } json_t *json_enum = json_integer(enum_value); json_array_append_new(json_data, json_enum); } break; case QEOCORE_TYPECODE_FLOAT32: { float float_value = ((float *)DDS_SEQ_DATA(seq))[i]; json_array_append_new(json_data, json_real(float_value)); } break; } if (NULL == json_data) { break; } } qeocore_data_sequence_free(data, &seq); return json_data; }
static Token_t *sp_get_perm_token (const SEC_PERM *pp, Permissions_t id) { Token_t *tp; unsigned char *p; DDS_SecurityReqData data; DDS_PermissionsToken *token; size_t cred_len; DDS_ReturnCode_t error; ARG_NOT_USED (pp) tp = xmalloc (sizeof (Token_t)); if (!tp) return (NULL); token = DDS_DataHolder__alloc (GMCLASSID_SECURITY_PERMISSIONS_TOKEN); if (!token) { xfree (tp); return (NULL); } token->binary_value1 = DDS_OctetSeq__alloc (); if (!token->binary_value1) goto free_dh; error = dds_seq_require (token->binary_value1, 32); if (error) goto free_dh; data.handle = id; data.data = NULL; data.kdata = NULL; data.length = 0; data.rlength = 0; error = sec_access_control_request (DDS_GET_PERM_CRED, &data); if (error) goto free_dh; cred_len = data.rlength; p = xmalloc (cred_len); if (!p) goto free_dh; data.data = p; data.kdata = NULL; data.length = cred_len; error = sec_access_control_request (DDS_GET_PERM_CRED, &data); if (error) goto free_p; error = sec_hash_sha256 ((unsigned char *) p, cred_len, DDS_SEQ_DATA (*token->binary_value1)); xfree (p); if (error) goto free_dh; tp->data = token; tp->nusers = 1; tp->encoding = 0; tp->integral = 0; tp->next = NULL; return (tp); free_p: xfree (p); free_dh: DDS_DataHolder__free (token); xfree (tp); return (NULL); }
static void ctt_dump_binary_value (unsigned i, DDS_OctetSeq *sp) { log_printf (SPDP_ID, 0, " BV%u:\r\n", i); log_print_region (SPDP_ID, 0, DDS_SEQ_DATA (*sp), DDS_SEQ_LENGTH (*sp), 1, 1); }
static Token_t *sd_get_perm_token (const SEC_PERM *pp, Permissions_t perm) { Token_t *token; DDS_IdentityToken *tp; DDS_OctetSeq *p; PermissionsData_t *pdp; DDS_SecurityReqData data; char buf [128]; char *bp; MD5_CONTEXT md5; DDS_ReturnCode_t ret; ARG_NOT_USED (pp) token = xmalloc (sizeof (Token_t)); if (!token) return (NULL); pdp = perm_lookup (perm, NULL); if (!pdp) goto no_perm; data.handle = pdp->id; data.data = NULL; data.length = 0; ret = sec_authentication_request (DDS_GET_ID_NAME, &data); if (ret || !data.rlength) goto no_perm; if (data.rlength >= sizeof (buf)) { bp = Alloc (data.rlength); if (!bp) goto no_perm; } else bp = buf; data.handle = pdp->id; data.data = bp; data.length = data.rlength; ret = sec_authentication_request (DDS_GET_ID_NAME, &data); if (ret) goto done; tp = DDS_DataHolder__alloc (GMCLASSID_SECURITY_DTLS_PERM_TOKEN); if (!tp) goto done; tp->binary_value1 = p = DDS_OctetSeq__alloc (); if (!p) goto out_of_mem; ret = dds_seq_require (p, 16); if (ret) { DDS_DataHolder__free (tp); return (NULL); } md5_init (&md5); md5_update (&md5, (unsigned char *) bp, strlen (bp)); md5_final (DDS_SEQ_DATA (*p), &md5); if (bp != buf) Free (bp); token->data = tp; token->encoding = PID_V_PERMS; token->integral = 0; token->nusers = 1; token->next = NULL; return (token); out_of_mem: DDS_DataHolder__free (tp); done: if (bp != buf) Free (bp); no_perm: xfree (token); return (NULL); }