static void tcp_unlock(Channel * channel) {
    ChannelTCP * c = channel2tcp(channel);
    assert(is_dispatch_thread());
    assert(c->magic == CHANNEL_MAGIC);
    assert(c->lock_cnt > 0);
    c->lock_cnt--;
    if (c->lock_cnt == 0 && !c->read_pending) {
        delete_channel(c);
    }
}
Beispiel #2
0
static void pipe_unlock(Channel * channel) {
    ChannelPIPE * c = channel2pipe(channel);
    assert(is_dispatch_thread());
    assert(c->magic == CHANNEL_MAGIC);
    assert(c->lock_cnt > 0);
    c->lock_cnt--;
    if (c->lock_cnt == 0) {
        assert(!c->read_pending);
        delete_channel(c);
    }
}
Beispiel #3
0
void ChannelEditWindow::delete_channel(Channel *channel)
{
	int i;
	for(i = 0; i < thread->new_channels->size(); i++)
	{
		if(thread->new_channels->get(i) == channel)
		{
			break;
		}
	}
	if(i < thread->new_channels->size()) delete_channel(i);
}
Beispiel #4
0
OPJ_BOOL close_channel(query_param_t query_param,
                       sessionlist_param_t *sessionlist,
                       session_param_t **cursession,
                       channel_param_t **curchannel)
{
    char *cclose;
    int i;

    if (query_param.cclose[0] == '*') {
#ifndef SERVER
        fprintf(logstream, "local log: close all\n");
#endif
        /* all channels associatd with the session will be closed */
        if (!delete_session(cursession, sessionlist)) {
            return OPJ_FALSE;
        }
    } else {
        /* check if all entry belonging to the same session */

        for (i = 0, cclose = query_param.cclose; i < query_param.numOfcclose;
                i++, cclose += (strlen(cclose) + 1)) {

            /* In case of the first entry of close cid */
            if (*cursession == NULL) {
                if (!search_session_and_channel(cclose, sessionlist, cursession, curchannel)) {
                    return OPJ_FALSE;
                }
            } else /* second or more entry of close cid */
                if (!(*curchannel = search_channel(cclose, (*cursession)->channellist))) {
                    fprintf(FCGI_stdout, "Reason: Cclose id %s is from another session\r\n",
                            cclose);
                    return OPJ_FALSE;
                }
        }

        /* delete channels */
        for (i = 0, cclose = query_param.cclose; i < query_param.numOfcclose;
                i++, cclose += (strlen(cclose) + 1)) {
            *curchannel = search_channel(cclose, (*cursession)->channellist);
            delete_channel(curchannel, (*cursession)->channellist);
        }

        if ((*cursession)->channellist->first == NULL ||
                (*cursession)->channellist->last == NULL)
            /* In case of empty session */
        {
            delete_session(cursession, sessionlist);
        }
    }
    return OPJ_TRUE;
}
Beispiel #5
0
static int end_of_names_hook(int argc, char *argv[])
{
	const char **nicks = users_in_channel(argv[3]);
	channel_t *ch = find_channel(argv[3], irc_pick_server());
	int del_chn = 0;
	if(ch == NULL) {
		ch = new_channel(argv[3], irc_pick_server());
		del_chn = 1;
	}
	int j;

	/**************************************
	 * find the longest nick
	 **************************************/
	int longest = 0;
	for(j = 0; nicks[j] != NULL; j++) {
		if(strlen(nicks[j]) > longest)
			longest = strlen(nicks[j]);
	}

	int sizex = io_get_width();
	int times = sizex / (longest + 4);

	/**************************************
	 * show the nicks
	 **************************************/
	wio_colored_out(ch->win, USER_BLUE, " [%s]\n", argv[3]);
	if(nicks[1] != NULL) {
		for(j = 0; nicks[j] != NULL; j++) {
			if(j && j % times == 0)
				wio_out(ch->win, "\n");
			wio_colored_out(ch->win, USER_RED, " [");
			wio_colored_out(ch->win, USER_WHITE, "%-*s", longest, nicks[j]);
			wio_colored_out(ch->win, USER_RED, "] ");
		}
		wio_out(ch->win, "\n");
	}

	free(nicks);

	if(del_chn)
		delete_channel(ch);
	return 0;

}
Beispiel #6
0
void		ft_leave(char *buff, t_client *client, t_server *server)
{
	int		i;

	(void)server;
	i = 0;
	if (ft_strlen(buff) > 6)
	{
		delete_channel(buff, client);
	}
	else
	{
		while (i < MAX_CHANNEL)
			client->channel[i++] = NULL;
		client->n_channel = 0;
		write_to_client(client->sock, "leave with success !");
	}
}
Beispiel #7
0
bool update(const char * field, std::vector<uint8_t> data) {
    if (!strcmp(field, "dlpkt")) {
        return delete_packet(data);
    } else if (!strcmp(field, "dlcha")) {
        return delete_channel(data);
    } else if (!strcmp(field, "pnum")) {
        return set_pnumber(data);
    } else if (!strcmp(field, "chan")) {
        return set_channel(data);
    } else if (!strcmp(field, "pol")) {
        set_poll(data);
    } else if (!strcmp(field, "dir")) {
        const char * dirStr = byteVec2cstr(data);
        if (!strcmp(dirStr, "pos"))
            set_direction(DIR_POS);
        else if (!strcmp(dirStr, "neg"))
            set_direction(DIR_NEG);
        else return false;
    } else if (!strcmp(field, "data")) {
        return set_current(data);
    } else if (!strcmp(field, "wait")) {
        set_delay(data);
    } else if (!strcmp(field, "send")) {
        flag_return = true;
        send_packets();
    } else if (!strcmp(field, "reset")) {
        send_global_reset();
    } else if (!strcmp(field, "glob")) {
        set_global();
    } else if (!strcmp(field, "conn")) {
        flag_return = true;
        return connect_serial();
    } else if (!strcmp(field, "exit")) {
        return exit();
    } else if (!strcmp(field, "clrpks")) {
        clear_packets();
    } else if (!strcmp(field, "prev")) {
        if (debug_) preview_packets();
        preview_packet_bytes();
        flag_return = true;
    } else { return false; }
    return true;
}
int			pop_in_channel(char *name, int fd, t_channel **root)
{
  t_channel		*tmp;

  tmp = (*root)->next;
  while (tmp != (*root))
    {
      if (strcmp(name, tmp->channel_name) == 0)
	{
	  if (is_in_fds(fd, tmp->root) == FALSE)
	    return (-2);
	  pop_fd_list(&(tmp->root), fd);
	  tmp->size -= 1;
	  if (tmp->size == 0)
	    return (delete_channel(tmp));
	  return (0);
	}
      tmp = tmp->next;
    }
  return (-1);
}
Beispiel #9
0
int cmd_check(char* buffer,User* user){
  int ret;
  int descriptor= user->socket;
  if(strcmp(buffer,QUIT_COMMAND)==0){

    if(user->user_channel==NULL){
      char buffer[BUFFER_SIZE];
      snprintf(buffer,sizeof(buffer),"%s",QUIT_CLIENT);
      send_message(user->socket,buffer,strlen(buffer));
      return QUIT_RET;
    }

    Channel* desc_channel= user->user_channel;

    if(num_channels>0){
      if(isAdmin(descriptor,desc_channel)){
        if(desc_channel->sub_num>1){
          char buffer[BUFFER_SIZE];
          snprintf(buffer,sizeof(buffer),"%s","Do you want to close the channel? (y/n)");
          do{
            ret= send_message(descriptor,buffer,strlen(buffer));
            ret= receive_message(descriptor,buffer);
            if(strlen(buffer)==1){
              if(buffer[0]=='y'){
                delete_channel(desc_channel,descriptor);
                printf("Client disconnesso\n");
                return QUIT_RET;
              }
              else if(buffer[0]=='n') break;
            }
            memset(buffer,0,sizeof(buffer));
            snprintf(buffer,sizeof(buffer),"%s","Invalid input: choose between y or n!\n");
          }while(1);

        }
        else {
          char buffer[BUFFER_SIZE];
          snprintf(buffer,sizeof(buffer),"%s","You're the last active member. If you leave, the chat will be closed.\nDo you want to exit anyway? (y/n)\n");
          do{
            ret= send_message(descriptor,buffer,strlen(buffer));
            ret= receive_message(descriptor,buffer);
            if(strlen(buffer)==1){
              if(buffer[0]=='y'){
                delete_channel(desc_channel,descriptor);
                return QUIT_RET;
              }
              else if(buffer[0]=='n'){
                snprintf(buffer,sizeof(buffer),"%s","You're still in the chat.\n");
                send_message(descriptor,buffer,strlen(buffer));
                return 0;
              }
            }
            snprintf(buffer,sizeof(buffer),"%s","Invalid input: choose between y or n!\n");
          }while(1);
        }
      }
      delete_user_from_channel(descriptor,desc_channel);
      char buff_leave[BUFFER_SIZE];
      snprintf(buff_leave,sizeof(buff_leave),"%s","leave the chat");
      send_all(desc_channel,user,buff_leave);
      }
      send_message(descriptor,QUIT_CLIENT,strlen(QUIT_CLIENT));
      printf("Client disconnesso\n");
      return QUIT_RET;
    }
  return -1;
}