/** * \brief This function destroy branch of nodes */ int vs_node_destroy_branch(struct VS_CTX *vs_ctx, struct VSNode *node, uint8 send) { struct VSNode *child_node; struct VSEntityFollower *node_follower; struct VSLink *link, *next_link; int ret = 0; link = node->children_links.first; /* Remove all sub-branches */ while(link != NULL) { child_node = link->child; next_link = link->next; vs_node_destroy_branch(vs_ctx, child_node, send); link = next_link; } node_follower = node->node_folls.first; if(node_follower != NULL && send == 1) { /* Send node_destroy command to all clients that knows about this node */ ret = vs_node_send_destroy(node); /* Own node will be destroyed, when verse server receive confirmation * of receiving node_destroy command */ } else { /* When all clients consider this node as destroyed, then it is * possible to remove it from server */ ret = vs_node_destroy(vs_ctx, node); } return ret; }
/** * \brief This function tries to handle node_destroy command */ int vs_handle_node_destroy(struct VS_CTX *vs_ctx, struct VSession *vsession, struct Generic_Cmd *node_destroy) { struct VSUser *user; struct VSNode *node; uint32 node_id = UINT32(node_destroy->data[0]); /* Try to find node */ if((node = vs_node_find(vs_ctx, node_id)) == NULL) { v_print_log(VRS_PRINT_DEBUG_MSG, "%s() node (id: %d) not found\n", __FUNCTION__, node_id); return 0; } /* Node has to be created */ if(! (node->state == ENTITY_CREATED || node->state == ENTITY_CREATING)) { v_print_log(VRS_PRINT_DEBUG_MSG, "%s() node (id: %d) is not in NODE_CREATED state: %d\n", __FUNCTION__, node->id, node->state); return 0; } /* Try to find user */ if((user = vs_user_find(vs_ctx, vsession->user_id)) == NULL) { v_print_log(VRS_PRINT_DEBUG_MSG, "vsession->user_id: %d not found\n", vsession->user_id); return 0; } /* Is this user owner of this node? */ if(user != node->owner) { v_print_log(VRS_PRINT_DEBUG_MSG, "user_id: %d is not owner of the node (id: %d) and can't delete this node.\n", vsession->user_id, node->id); return 0; } return vs_node_send_destroy(node); }