/** * \brief This function initialize structure storing informations about * one tag group */ static void vs_taggroup_init(struct VSTagGroup *tg) { #ifdef WITH_MONGODB int i; #endif tg->id = 0; tg->custom_type = 0; v_hash_array_init(&tg->tags, HASH_MOD_256, offsetof(VSTag, id), sizeof(uint16)); tg->last_tag_id = 0; tg->tg_folls.first = NULL; tg->tg_folls.last = NULL; tg->tg_subs.first = NULL; tg->tg_subs.last = NULL; tg->state = ENTITY_RESERVED; tg->version = 0; tg->saved_version = -1; tg->crc32 = 0; #ifdef WITH_MONGODB for(i=0; i<3; i++) { tg->oid.ints[i] = 0; } #endif }
/** * \brief This function initialize structure intended for storing node at server. */ void vs_node_init(struct VSNode *node) { node->id = 0xFFFFFFFF; node->type = 0; node->owner = NULL; node->permissions.first = NULL; node->permissions.last = NULL; node->parent_link = NULL; node->children_links.first = NULL; node->children_links.last = NULL; /* Hashed linked list of TagGroups */ v_hash_array_init(&node->tag_groups, HASH_MOD_256, offsetof(VSTagGroup, id), sizeof(uint16)); node->last_tg_id = 0; /* Hashed linked list of layers */ v_hash_array_init(&node->layers, HASH_MOD_256, offsetof(VSLayer, id), sizeof(uint16)); node->last_layer_id = 0; node->node_folls.first = NULL; node->node_folls.last = NULL; node->node_subs.first = NULL; node->node_subs.last = NULL; node->lock.session = NULL; node->state = ENTITY_RESERVED; }
/** * \brief This function creates new layer * * \param[in] *node The pointer at node, where layer will be created * \param[in] *parent The pointer at parent layer * \param[in] data_type The type of values stored in layer * \param[in] count The count of values stored in one layer item * \param[in] type The client defined type of layer * * \return This function returns pointer at new created layer */ struct VSLayer *vs_layer_create(struct VSNode *node, struct VSLayer *parent, uint8 data_type, uint8 count, uint16 type) { struct VSLayer *layer = calloc(1, sizeof(struct VSLayer)); if(layer == NULL) { return NULL; } layer->prev = NULL; layer->next = NULL; layer->id = node->last_layer_id; node->last_layer_id++; layer->data_type = data_type; layer->type = type; layer->parent = parent; layer->num_vec_comp = count; v_hash_array_init(&layer->values, HASH_MOD_65536, offsetof(VSLayerValue, id), sizeof(uint32)); /* When parent layer is not NULL, then add this layer to the linked list * of child layers */ if(parent != NULL) { v_list_add_tail(&parent->child_layers, layer); } /* Initialize linked list of child layers */ layer->child_layers.first = layer->child_layers.last = NULL; layer->layer_folls.first = layer->layer_folls.last = NULL; layer->layer_subs.first = layer->layer_subs.last = NULL; layer->state = ENTITY_RESERVED; return layer; }
/** * \brief Load default valued for configuration of verse server to the Verse server * context. * \param vs_ctx The Verse server context. */ static void vs_init(struct VS_CTX *vs_ctx) { int i; vs_ctx->max_connection_attempts = 10; vs_ctx->vsessions = NULL; vs_ctx->max_sessions = 10; vs_ctx->max_sockets = vs_ctx->max_sessions; vs_ctx->flag = SERVER_DEBUG_MODE; /* SERVER_MULTI_SOCKET_MODE | SERVER_REQUIRE_SECURE_CONNECTION */ vs_ctx->stream_protocol = TCP; /* For new connection attempts is used TCP protocol */ vs_ctx->dgram_protocol = VRS_TP_UDP; /* For data exchange UDP protocol could be used */ #if ( defined WITH_OPENSSL ) && OPENSSL_VERSION_NUMBER>=0x10000000 vs_ctx->security_protocol = VRS_SEC_DATA_NONE | VRS_SEC_DATA_TLS; #else vs_ctx->security_protocol = VRS_SEC_DATA_NONE; #endif #ifdef WITH_OPENSSL vs_ctx->tcp_port = VRS_DEFAULT_TLS_PORT; /* Secured TCP port number for listening */ #else vs_ctx->tcp_port = VRS_DEFAULT_TCP_PORT; /* UnSecured TCP port number for listening */ #endif vs_ctx->ws_port = VRS_DEFAULT_WEB_PORT; /* WebSocket TCP port for listening */ vs_ctx->port_low = 50000; /* The lowest port number for client-server connection */ vs_ctx->port_high = vs_ctx->port_low + vs_ctx->max_sockets; /* Initialize list of free ports */ vs_ctx->port_list = (struct VS_Port*)calloc(vs_ctx->max_sockets, sizeof(struct VS_Port)); for(i=0; i<vs_ctx->max_sockets; i++) { vs_ctx->port_list[i].port_number = (unsigned short)(vs_ctx->port_low + i); } vs_ctx->tcp_io_ctx.host_addr.ip_ver = IPV6; vs_ctx->tcp_io_ctx.buf = NULL; vs_ctx->ws_io_ctx.host_addr.ip_ver = IPV6; vs_ctx->ws_io_ctx.buf = NULL; vs_ctx->print_log_level = VRS_PRINT_DEBUG_MSG; vs_ctx->log_file = stdout; vs_ctx->private_cert_file = strdup("./pki/private.key.pem"); vs_ctx->ca_cert_file = NULL; vs_ctx->public_cert_file = strdup("./pki/certificate.pem"); vs_ctx->hostname = strdup("localhost"); vs_ctx->ded = strdup("http://uni-verse.org/verse.ded"); vs_ctx->auth_type = AUTH_METHOD_CSV_FILE; vs_ctx->csv_user_file = strdup("./config/users.csv"); vs_ctx->users.first = vs_ctx->users.last = NULL; vs_ctx->default_perm = VRS_PERM_NODE_READ; vs_ctx->cc_meth = CC_NONE; /* "List" of allowed methods of Congestion Control */ vs_ctx->fc_meth = FC_TCP_LIKE; /* "List" of allowed methods of Flow Control */ vs_ctx->cmd_cmpr = CMPR_ADDR_SHARE; vs_ctx->rwin_scale = 0; /* Default scale of Flow Control Window */ vs_ctx->in_queue_max_size = 1048576; /* 1MB */ vs_ctx->out_queue_max_size = 1048576; /* 1MB */ vs_ctx->tls_ctx = NULL; vs_ctx->dtls_ctx = NULL; v_hash_array_init(&vs_ctx->data.nodes, HASH_MOD_65536, offsetof(VSNode, id), sizeof(uint32)); vs_ctx->data.root_node = NULL; vs_ctx->data.scene_node = NULL; vs_ctx->data.user_node = NULL; vs_ctx->data.avatar_node = NULL; vs_ctx->data.sem = NULL; }