void verse_send_t_text_set(VNodeID node_id, VBufferID buffer_id, uint32 pos, uint32 length, const char *text) { uint8 *buf; VOrderedStorage *s; unsigned int buffer_pos = 0; VCMDBufHead *head; head = v_cmd_buf_allocate(VCMDBS_1500);/* Allocating the buffer */ buf = ((VCMDBuffer10 *)head)->buf; buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 99);/* Packing the command */ #if defined V_PRINT_SEND_COMMANDS printf("send: verse_send_t_text_set(node_id = %u buffer_id = %u pos = %u length = %u text = %s );\n", node_id, buffer_id, pos, length, text); #endif s = v_con_get_ordered_storage(); buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], buffer_id); buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], pos); buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], length); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], s->text_send_id++); if(text == NULL) buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0); else buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], text, VN_T_MAX_TEXT_CMD_SIZE); v_cmd_buf_set_unique_address_size(head, buffer_pos); v_cmd_buf_set_size(head, buffer_pos); v_noq_send_buf(v_con_get_network_queue(), head); }
/** * \brief This function packs USER_AUTH_FAILURE command to the buffer */ int v_raw_pack_user_auth_failure(char *buffer, const struct User_Authentication_Failure *ua_fail) { int i, count; unsigned short buffer_pos = 0; unsigned char length; /* Pack command ID */ buffer_pos += vnp_raw_pack_uint8(&buffer[buffer_pos], ua_fail->id); /* Compute length of the command */ count = (ua_fail->count<=VRS_MAX_UA_METHOD_COUNT) ? ua_fail->count : VRS_MAX_UA_METHOD_COUNT; /* Compute length of the command: id_len + cmd_len + count */ length = 1 + 1 + count; /* Pack length of the command */ buffer_pos += v_cmd_pack_len(&buffer[buffer_pos], length); /* Pack list of supported methods */ for(i=0; i<count; i++) { buffer_pos += vnp_raw_pack_uint8(&buffer[buffer_pos], ua_fail->method[i]); } /* Check if length and buffer_pos match */ if(buffer_pos!=length) { v_print_log(VRS_PRINT_DEBUG_MSG, "%s: buffer_pos: %d != length: %d\n", __func__, buffer_pos, length); return length; } return buffer_pos; }
/** * \brief Pack header of VMessage to the buffer * \param[in] vmessage The structure with data for message * \param[out] buffer The buffer, that will be sent to the peer. * \return This function return of bytes packed to the buffer. */ int v_pack_message_header(const VMessage *vmessage, char *buffer) { unsigned short buffer_pos=0; unsigned char ver; /* Pack version */ ver = (vmessage->header.version << 4) & 0xF0; buffer_pos += vnp_raw_pack_uint8(&buffer[buffer_pos], ver); /* Pack zeros for reservation space */ buffer_pos += vnp_raw_pack_uint8(&buffer[buffer_pos], 0); /* Pack length of command */ buffer_pos += vnp_raw_pack_uint16(&buffer[buffer_pos], vmessage->header.len); return buffer_pos; }
static unsigned int pack_b_tile_set_head(VCMDBufHead *head, VNodeID node_id, VLayerID layer_id, uint16 tile_x, uint16 tile_y, uint16 z, VNBLayerType type, const VNBTile *tile) { unsigned int buffer_pos = 0; uint8 *buf; buf = ((VCMDBuffer30 *)head)->buf; buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 83); /* Pack the command. */ #if defined V_PRINT_SEND_COMMANDS printf("send: verse_send_b_tile_set(node_id = %u layer_id = %u tile_x = %u tile_y = %u z = %u type = %u tile = %p );\n", node_id, layer_id, tile_x, tile_y, z, type, tile); #endif buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], tile_x); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], tile_y); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], z); buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)type); return buffer_pos; v_cmd_buf_set_address_size(head, 13); v_cmd_buf_set_size(head, buffer_pos); v_noq_send_buf(v_con_get_network_queue(), head); }
void verse_send_c_key_destroy(VNodeID node_id, VLayerID curve_id, uint32 key_id) { uint8 *buf; unsigned int buffer_pos = 0; VCMDBufHead *head; head = v_cmd_buf_allocate(VCMDBS_1500);/* Allocating the buffer */ buf = ((VCMDBuffer10 *)head)->buf; buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 130);/* Packing the command */ #if defined V_PRINT_SEND_COMMANDS printf("send: verse_send_c_key_destroy(node_id = %u curve_id = %u key_id = %u );\n", node_id, curve_id, key_id); #endif buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], curve_id); buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], key_id); buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 0); v_cmd_buf_set_address_size(head, 11); v_cmd_buf_set_size(head, buffer_pos); v_noq_send_buf(v_con_get_network_queue(), head); }
/** * \brief Pack header of VPacket to the buffer * \return This function return of bytes packed to the buffer. */ int v_pack_packet_header(const VPacket *vpacket, char *buffer) { unsigned short buffer_pos=0; unsigned char ver; /* Pack version */ ver = (vpacket->header.version << 4) & 0xF0; buffer_pos += vnp_raw_pack_uint8(&buffer[buffer_pos], ver); /* Flags */ buffer_pos += vnp_raw_pack_uint8(&buffer[buffer_pos], vpacket->header.flags); /* Flow control window */ buffer_pos += vnp_raw_pack_uint16(&buffer[buffer_pos], vpacket->header.window); /* Payload ID */ buffer_pos += vnp_raw_pack_uint32(&buffer[buffer_pos], vpacket->header.payload_id); /* ACK NAK ID */ buffer_pos += vnp_raw_pack_uint32(&buffer[buffer_pos], vpacket->header.ack_nak_id); /* ANK ID */ buffer_pos += vnp_raw_pack_uint32(&buffer[buffer_pos], vpacket->header.ank_id); return buffer_pos; }
void verse_send_c_curve_unsubscribe(VNodeID node_id, VLayerID curve_id) { uint8 *buf; unsigned int buffer_pos = 0; VCMDBufHead *head; head = v_cmd_buf_allocate(VCMDBS_10);/* Allocating the buffer */ buf = ((VCMDBuffer10 *)head)->buf; buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 129); /* Pack the command. */ #if defined V_PRINT_SEND_COMMANDS printf("send: verse_send_c_curve_unsubscribe(node_id = %u curve_id = %u );\n", node_id, curve_id); #endif buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], curve_id); buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], FALSE); if(node_id == (uint32) ~0u || curve_id == (uint16) ~0u) v_cmd_buf_set_unique_address_size(head, 7); else v_cmd_buf_set_address_size(head, 7); v_cmd_buf_set_size(head, buffer_pos); v_noq_send_buf(v_con_get_network_queue(), head); }
void verse_send_b_layer_destroy(VNodeID node_id, VLayerID layer_id) { uint8 *buf; unsigned int buffer_pos = 0; VCMDBufHead *head; head = v_cmd_buf_allocate(VCMDBS_30);/* Allocating the buffer */ buf = ((VCMDBuffer10 *)head)->buf; buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 81); /* Pack the command. */ #if defined V_PRINT_SEND_COMMANDS printf("send: verse_send_b_layer_destroy(node_id = %u layer_id = %u );\n", node_id, layer_id); #endif buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], layer_id); buffer_pos += vnp_raw_pack_string(&buf[buffer_pos], NULL, 16); buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], (uint8)-1); if(node_id == (uint32) ~0u || layer_id == (uint16) ~0u) v_cmd_buf_set_unique_address_size(head, 7); else v_cmd_buf_set_address_size(head, 7); v_cmd_buf_set_size(head, buffer_pos); v_noq_send_buf(v_con_get_network_queue(), head); }
void verse_send_b_dimensions_set(VNodeID node_id, uint16 width, uint16 height, uint16 depth) { uint8 *buf; unsigned int buffer_pos = 0; VCMDBufHead *head; head = v_cmd_buf_allocate(VCMDBS_20);/* Allocating the buffer */ buf = ((VCMDBuffer10 *)head)->buf; buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 80); /* Pack the command. */ #if defined V_PRINT_SEND_COMMANDS printf("send: verse_send_b_dimensions_set(node_id = %u width = %u height = %u depth = %u );\n", node_id, width, height, depth); #endif buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], width); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], height); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], depth); if(node_id == (uint32) ~0u) v_cmd_buf_set_unique_address_size(head, 5); else v_cmd_buf_set_address_size(head, 5); v_cmd_buf_set_size(head, buffer_pos); v_noq_send_buf(v_con_get_network_queue(), head); }
void verse_send_c_key_set(VNodeID node_id, VLayerID curve_id, uint32 key_id, uint8 dimensions, const real64 *pre_value, const uint32 *pre_pos, const real64 *value, real64 pos, const real64 *post_value, const uint32 *post_pos) { uint8 *buf; unsigned int i, buffer_pos = 0; VCMDBufHead *head; head = v_cmd_buf_allocate(VCMDBS_1500);/* Allocating the buffer */ buf = ((VCMDBuffer10 *)head)->buf; if(dimensions == 0 || dimensions > 4) return; buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], 130);/* Packing the command */ #if defined V_PRINT_SEND_COMMANDS switch(dimensions) { case 1: printf("send: verse_send_c_key_set(node_id = %u curve_id = %u key_id = %u dimensions = %u pre_value = %f pre_pos = %u value = %f pos = %f, pre_value = %f pre_pos = %u ); callback = %p\n", node_id, curve_id, key_id, dimensions, pre_value[0], pre_pos[0], value[0], pos, pre_value[0], pre_pos[0], v_fs_get_user_func(130)); break; case 2: printf("sende: verse_send_c_key_set(node_id = %u curve_id = %u key_id = %u dimensions = %u pre_value = {%f, %f} pre_pos = {%u, %u} value = {%f, %f} pos = %f, pre_value = {%f, %f} pre_pos = {%u, %u}); callback = %p\n", node_id, curve_id, key_id, dimensions, pre_value[0], pre_value[1], pre_pos[0], pre_pos[1], value[0], value[1], pos, pre_value[0], pre_value[1], pre_pos[0], pre_pos[1], v_fs_get_user_func(130)); break; case 3: printf("send: verse_send_c_key_set(node_id = %u curve_id = %u key_id = %u dimensions = %u pre_value = {%f, %f, %f} pre_pos = {%u, %u, %u} value = {%f, %f, %f} pos = %f, pre_value = {%f, %f, %f} pre_pos = {%u, %u, %u}); callback = %p\n", node_id, curve_id, key_id, dimensions, pre_value[0], pre_value[1], pre_value[2], pre_pos[0], pre_pos[1], pre_pos[2], value[0], value[1], value[2], pos, pre_value[0], pre_value[1], pre_value[2], pre_pos[0], pre_pos[1], pre_pos[2], v_fs_get_user_func(130)); break; case 4: printf("send: verse_send_c_key_set(node_id = %u curve_id = %u key_id = %u dimensions = %u pre_value = {%f, %f, %f, %f} pre_pos = {%u, %u, %u, %u} value = {%f, %f, %f, %f} pos = %f, pre_value = {%f, %f, %f, %f} pre_pos = {%u, %u, %u, %u}); callback = %p\n", node_id, curve_id, key_id, dimensions, pre_value[0], pre_value[1], pre_value[2], pre_value[3], pre_pos[0], pre_pos[1], pre_pos[2], pre_pos[3], value[0], value[1], value[2], value[3], pos, pre_value[0], pre_value[1], pre_value[2], pre_value[3], pre_pos[0], pre_pos[1], pre_pos[2], pre_pos[3], v_fs_get_user_func(130)); break; } #endif buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], node_id); buffer_pos += vnp_raw_pack_uint16(&buf[buffer_pos], curve_id); buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], key_id); buffer_pos += vnp_raw_pack_uint8(&buf[buffer_pos], dimensions); for(i = 0; i < dimensions; i++) buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], pre_value[i]); for(i = 0; i < dimensions; i++) buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], pre_pos[i]); for(i = 0; i < dimensions; i++) buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], value[i]); buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], pos); for(i = 0; i < dimensions; i++) buffer_pos += vnp_raw_pack_real64(&buf[buffer_pos], post_value[i]); for(i = 0; i < dimensions; i++) buffer_pos += vnp_raw_pack_uint32(&buf[buffer_pos], post_pos[i]); if(key_id == (uint32) ~0u) v_cmd_buf_set_unique_address_size(head, 11); else v_cmd_buf_set_address_size(head, 11); v_cmd_buf_set_size(head, buffer_pos); v_noq_send_buf(v_con_get_network_queue(), head); }
/** * \brief This function packs negotiate commands: Change_L/R and Confirm_L/R * to the buffer */ int v_raw_pack_negotiate_cmd(char *buffer, const struct Negotiate_Cmd *negotiate_cmd) { unsigned short length = 0, buffer_pos = 0; unsigned int i; /* This need not be here, but check it. */ if( !(negotiate_cmd->id == CMD_CHANGE_L_ID || negotiate_cmd->id == CMD_CHANGE_R_ID || negotiate_cmd->id == CMD_CONFIRM_L_ID || negotiate_cmd->id == CMD_CONFIRM_R_ID) ) { v_print_log(VRS_PRINT_WARNING, "This is not negotiation command\n"); return 0; } /* List here only supported feature IDs (reserver feature ID should never be sent) */ if( !(negotiate_cmd->feature == FTR_FC_ID || negotiate_cmd->feature == FTR_CC_ID || negotiate_cmd->feature == FTR_HOST_URL || negotiate_cmd->feature == FTR_TOKEN || negotiate_cmd->feature == FTR_DED || negotiate_cmd->feature == FTR_RWIN_SCALE || negotiate_cmd->feature == FTR_FPS || negotiate_cmd->feature == FTR_CMD_COMPRESS || negotiate_cmd->feature == FTR_CLIENT_NAME || negotiate_cmd->feature == FTR_CLIENT_VERSION) ) { v_print_log(VRS_PRINT_WARNING, "Try to send UNKNOWN feature ID: %d\n", negotiate_cmd->feature); return 0; } /* Pack command ID first */ buffer_pos += vnp_raw_pack_uint8(&buffer[buffer_pos], negotiate_cmd->id); /* Pack length of command */ switch(negotiate_cmd->feature) { case FTR_FC_ID: case FTR_CC_ID: case FTR_RWIN_SCALE: case FTR_CMD_COMPRESS: /* CommandID + Length + FeatureID + features */ length = 1 + 1 + 1 + negotiate_cmd->count*sizeof(uint8); break; case FTR_HOST_URL: case FTR_TOKEN: case FTR_DED: case FTR_CLIENT_NAME: case FTR_CLIENT_VERSION: length = 1 + 1 + 1; /* CommandID + Length + FeatureID */ for(i=0; i<negotiate_cmd->count; i++) { /* + String length + String */ length += 1 + (sizeof(unsigned char))*negotiate_cmd->value[i].string8.length; } break; case FTR_FPS: /* CommandID + Length + FeatureID + features */ length = 1 + 1 + 1 + negotiate_cmd->count*sizeof(real32); break; } /* Pack length of the command */ buffer_pos += v_cmd_pack_len(&buffer[buffer_pos], length); /* Pack negotiated feature */ buffer_pos += vnp_raw_pack_uint8(&buffer[buffer_pos], negotiate_cmd->feature); /* Pack values of preference list */ for(i=0; i<negotiate_cmd->count; i++) { switch(negotiate_cmd->feature) { case FTR_FC_ID: case FTR_CC_ID: case FTR_RWIN_SCALE: case FTR_CMD_COMPRESS: buffer_pos += vnp_raw_pack_uint8(&buffer[buffer_pos], negotiate_cmd->value[i].uint8); break; case FTR_HOST_URL: case FTR_TOKEN: case FTR_DED: case FTR_CLIENT_NAME: case FTR_CLIENT_VERSION: buffer_pos += vnp_raw_pack_string8(&buffer[buffer_pos], (char*)negotiate_cmd->value[i].string8.str); break; case FTR_FPS: buffer_pos += vnp_raw_pack_real32(&buffer[buffer_pos], negotiate_cmd->value[i].real32); break; } } /* Check if length and buffer_pos match */ if(buffer_pos!=length) { v_print_log(VRS_PRINT_DEBUG_MSG, "%s: buffer_pos: %d != length: %d\n", __FUNCTION__, buffer_pos, length); return length; } return buffer_pos; }