Esempio n. 1
0
int imc_handle_destroy(struct sip_msg* msg, imc_cmd_t *cmd,
		struct sip_uri *src, struct sip_uri *dst)
{
	imc_room_p room = 0;
	imc_member_p member = 0;
	str room_name;
	str body;
	
	/* distrugere camera */
	room_name = cmd->param[0].s?cmd->param[0]:dst->user;

	room= imc_get_room(&room_name, &dst->host);
	if(room== NULL || (room->flags&IMC_ROOM_DELETED))
	{
		LM_ERR("room [%.*s] does not exist!\n",	room_name.len, room_name.s);
		goto error;
	}		

	/* verify is the user is a member of the room*/
	member= imc_get_member(room, &src->user, &src->host);

	if(member== NULL)
	{
		LM_ERR("user [%.*s] is not a member of room [%.*s]!\n", 
				src->user.len, src->user.s,	room_name.len, room_name.s);
		goto error;
	}
			
	if(!(member->flags & IMC_MEMBER_OWNER))
	{
		LM_ERR("user [%.*s] is not owner of room [%.*s] -- cannot destroy it"
				"!\n", src->user.len, src->user.s, room_name.len, room_name.s);
		goto error;
	}
	room->flags |= IMC_ROOM_DELETED;

	body.s = imc_body_buf;
	strcpy(body.s, "The room has been destroyed");
	body.len = strlen(body.s);

	/* braodcast message */
	imc_room_broadcast(room, &all_hdrs, &body);

	imc_release_room(room);

	LM_DBG("deleting room\n");
	imc_del_room(&room_name, &dst->host);

	return 0;

error:
	if(room!=NULL)
		imc_release_room(room);
	return -1;
}
Esempio n. 2
0
/**
 * destroy hash table
 */
int imc_htable_destroy(void)
{
	int i;
	imc_room_p irp = NULL, irp_temp=NULL;
	if(_imc_htable==NULL)
		return -1;
	
	for(i=0; i<imc_hash_size; i++)
	{
		lock_destroy(&_imc_htable[i].lock);
		if(_imc_htable[i].rooms==NULL)
			continue;
			irp = _imc_htable[i].rooms;
			while(irp){
				irp_temp = irp->next;
				imc_del_room(&irp->name, &irp->domain);
				irp = irp_temp;
			}
	}
	shm_free(_imc_htable);
	_imc_htable = NULL;
	return 0;
}
Esempio n. 3
0
int imc_handle_exit(struct sip_msg* msg, imc_cmd_t *cmd,
		struct sip_uri *src, struct sip_uri *dst)
{
	imc_room_p room = 0;
	imc_member_p member = 0;
	str room_name;
	str body;
	
	/* the user wants to leave the room */
	room_name = cmd->param[0].s?cmd->param[0]:dst->user;

	room= imc_get_room(&room_name, &dst->host);
	if(room== NULL || (room->flags&IMC_ROOM_DELETED))
	{
		LM_ERR("room [%.*s] does not exist!\n",	room_name.len, room_name.s);
		goto error;
	}		

	/* verify if the user is a member of the room */
	member= imc_get_member(room, &src->user, &src->host);

	if(member== NULL)
	{
		LM_ERR("user [%.*s] is not member of room [%.*s]!\n", 
				src->user.len, src->user.s,	room_name.len, room_name.s);
		goto error;
	}
			
	if(member->flags & IMC_MEMBER_OWNER)
	{
		/*If the user is the owner of the room, the room is distroyed */
		room->flags |=IMC_ROOM_DELETED;

		body.s = imc_body_buf;
		strcpy(body.s, "The room has been destroyed");
		body.len = strlen(body.s);
		imc_room_broadcast(room, &all_hdrs, &body);

		imc_release_room(room);
		
		imc_del_room(&room_name, &dst->host);
		room = NULL;
		goto done;
	} else {
		/* delete user */
		member->flags |= IMC_MEMBER_DELETED;
		imc_del_member(room, &src->user, &src->host);
		body.s = imc_body_buf;
		body.len = snprintf(body.s, IMC_BUF_SIZE, 
				"The user [%.*s] has left the room",
				src->user.len, src->user.s);
		if(body.len>0)
			imc_room_broadcast(room, &all_hdrs, &body);

		if(body.len>=IMC_BUF_SIZE)
			LM_ERR("user name %.*s truncated\n", src->user.len, src->user.s);
	}

done:
	if(room!=NULL)
		imc_release_room(room);
	return 0;

error:
	if(room!=NULL)
		imc_release_room(room);
	return -1;
}