Exemplo n.º 1
0
void do_stuff(msg *received_message){
    if(received_message->msg_type==1){
        //Broadcast message.
        if(check_history(received_message->message_id))
        	return;
        insert_into_history_table(received_message->message_id);
        int *neighbours=get_neighbours(ROUTER_ID);
        int size=neighbours[0];
        int i;
        printf("received by router id:%d from %d.\nSending to others.\n", ROUTER_ID,received_message->coming_from);
        received_message->coming_from=ROUTER_BASE_PORT+ROUTER_ID;
        for(i=1;i<=size;i++){
        	write_to_socket(ROUTER_BASE_PORT+neighbours[i],code_message(received_message));
        }
    }
		//unicast message
    else if(received_message->msg_type==2)
        if(received_message->receiver_id!=check_node_list(ROUTER_ID,received_message->receiver_id)) {
            int *path=find_shorest_path_between_routers(ROUTER_ID,get_parent_id(received_message->receiver_id));
            int next_node_to_send_to=path[1];
            if(next_node_to_send_to==-1){
                printf("Next node not found.Exiting...\n");
                exit(0);
            }
            received_message->coming_from=ROUTER_BASE_PORT+ROUTER_ID;
            printf("Passing from router %d to router %d\n",ROUTER_ID,next_node_to_send_to);
            write_to_socket(ROUTER_BASE_PORT+next_node_to_send_to,code_message(received_message));
        }
        else{
            received_message->coming_from=ROUTER_BASE_PORT+ROUTER_ID;
            printf("Passing from router %d to end node %d\n",ROUTER_ID,received_message->receiver_id );
            write_to_socket(NODE_BASE_PORT+received_message->receiver_id,code_message(received_message));
        }
    //Control message
    else if(received_message->msg_type==3){
      	//operations supported==> print the count of the messages received and forwarded on each link.
    	if(check_history(received_message->message_id))		//node is already visited.
        	return;
        insert_into_history_table(received_message->message_id);
        int *neighbours=get_neighbours(ROUTER_ID);
        int size=neighbours[0];
        int i;
      // printf("received by router id:%d.\nSending to others.\n", ROUTER_ID);
        received_message->coming_from=ROUTER_BASE_PORT+ROUTER_ID;
        printf("Message received by Router # %d are %llu (including the current one!)\n",ROUTER_ID,message_count+1 );
        for(i=1;i<=size;i++){
        	write_to_socket(ROUTER_BASE_PORT+neighbours[i],code_message(received_message));
        }
    }
    message_count++;


}
Exemplo n.º 2
0
static void
open_homepage(ChmSee *self)
{
        ChmseeIhtml *html;

        html = get_active_html(self);

        /* g_signal_handlers_block_by_func(html, html_open_uri_cb, self); */

        chmsee_ihtml_open_uri(html, g_build_filename(chmsee_ichmfile_get_dir(selfp->book),
                                             chmsee_ichmfile_get_home(selfp->book), NULL));

        /* g_signal_handlers_unblock_by_func(html, html_open_uri_cb, self); */

        if (selfp->has_toc) {
          booktree_select_uri(BOOKTREE (selfp->booktree),
                              chmsee_ichmfile_get_home(selfp->book));
        }

        check_history(self, html);
}
Exemplo n.º 3
0
void chat_interface(int new_fd)
{
    clear();
    refresh();
    
    int flag = 3;

    int ch;

    WINDOW *new_window1, *new_window2, *new_window5;

    setlocale(LC_ALL, "");
    //initscr();

    //keypad(ch_window4, 1);

    new_window1 = newwin(3, 91,0,22);
    ch_window2 = newwin(13, 68,4,23);
    new_window5 = newwin(15, 70,3,22);
    ch_window3 = newwin(6, 70,18,22);
    ch_window4 = newwin(21, 21,3,92);
    ch_window5 = newwin(6, 20,0,2);
    ch_window1 = newwin(18, 20,6,2);

    box(new_window1, 0, 0);
    box(ch_window4, 0, 0);
    box(ch_window5, 0, 0);
    box(new_window5, 0, 0);
    box(ch_window1, 0, 0);
    box(ch_window2, ' ', ' ');
    box(ch_window3, 0, 0);

    mvwaddstr(ch_window1, 1, 5, "ONLINE-USER");
    mvwaddstr(ch_window1, 2, 5, "===========");

    mvwaddstr(ch_window5, 2, 7, msg1.name);
    mvwaddstr(ch_window5, 3, 6, msg1.id);
    
    mvwaddstr(ch_window4, 1, 6, "FUNCTION");
    mvwaddstr(ch_window4, 2, 5, "===========");
    mvwaddstr(ch_window4, 3, 5, "私聊");
    mvwaddstr(ch_window4, 4, 5, "群聊");
    mvwaddstr(ch_window4, 5, 5, "发送表情");
    mvwaddstr(ch_window4, 6, 5, "查看聊天记录");
    mvwaddstr(ch_window4, 7, 5, "删除聊天记录");
    mvwaddstr(ch_window4, 8, 5, "发送文件");
    mvwaddstr(ch_window4, 9, 5, "修改昵称");
    mvwaddstr(ch_window4, 10, 5, "修改密码");
    mvwaddstr(ch_window4, 11, 5, "切换用户");

    wrefresh(new_window1);
    wrefresh(ch_window3);
    wrefresh(ch_window5);
    wrefresh(new_window5);
    wrefresh(ch_window1);
    wrefresh(ch_window2);
    wrefresh(ch_window4);
 
    mvwaddstr(ch_window4, flag, 3, "=>");
    wrefresh(ch_window4);

    keypad(ch_window4,true);

    cbreak();

    while(1)
    {
        if(filesend == FILE_SEND)
	{
	    file_receive(new_fd);

	    filesend = 0;
	}

        curs_set(0);
        
        /*mvwaddstr(ch_window4, flag, 3, "  ");
	
	flag = 3;

        mvwaddstr(ch_window4, flag, 3, "=>");
	wrefresh(ch_window4);*/

        noecho();
        while((ch = wgetch(ch_window4)) != '\n')
	{
	    if(ch == KEY_UP)
	    {
		mvwaddstr(ch_window4, flag, 3, "  ");

	        if(flag == 3)
		{
		    flag = 11;
		}
		else
		{
		    flag--;
		}

		mvwaddstr(ch_window4, flag, 3, "=>");
	    }
	    if(ch == KEY_DOWN)
	    {
		mvwaddstr(ch_window4, flag, 3, "  ");
                 
	        if(flag == 11)
		{
		    flag = 3;
		}
		else
		{
		    flag++;
		}

		mvwaddstr(ch_window4, flag, 3, "=>");
	        
	    }

	    wrefresh(ch_window4);
	}

	switch(flag)
	{
	    case 3:
	    {
	        private_chat(new_fd);
                break;
	    }
	    case 4:
	    {
	        group_chat(new_fd);
	        break;
	    }
	    case 5:
	    {   
	        send_face(new_fd);
	        break;
	    }
	    case 6:
	    {
	        check_history(new_fd);
	        break;
	    }
	    case 7:
	    {
	        delete_history(new_fd);
	        break;
	    }
	    case 8:
	    {
	        file_send(new_fd);
	        break;
	    }
	    case 9:
	    {
	        change_name(new_fd);
	        break;
	    }
	    case 10:
	    {
 
	        change_password(new_fd);

    box(new_window1, 0, 0);
    box(ch_window4, 0, 0);
    box(ch_window5, 0, 0);
    box(new_window5, 0, 0);
    box(ch_window1, 0, 0);
    box(ch_window2, ' ', ' ');
    box(ch_window3, 0, 0);

    mvwaddstr(ch_window1, 1, 5, "ONLINE-USER");
    mvwaddstr(ch_window1, 2, 5, "===========");

    mvwaddstr(ch_window5, 2, 7, msg1.name);
    mvwaddstr(ch_window5, 3, 6, msg1.id);
    
    mvwaddstr(ch_window4, 1, 6, "FUNCTION");
    mvwaddstr(ch_window4, 2, 5, "===========");
    mvwaddstr(ch_window4, 3, 5, "私聊");
    mvwaddstr(ch_window4, 4, 5, "群聊");
    mvwaddstr(ch_window4, 5, 5, "发送表情");
    mvwaddstr(ch_window4, 6, 5, "查看聊天记录");
    mvwaddstr(ch_window4, 7, 5, "删除聊天记录");
    mvwaddstr(ch_window4, 8, 5, "发送文件");
    mvwaddstr(ch_window4, 9, 5, "修改昵称");
    mvwaddstr(ch_window4, 10, 5, "修改密码");
    mvwaddstr(ch_window4, 11, 5, "切换用户");

    wrefresh(new_window1);
    wrefresh(ch_window3);
    wrefresh(ch_window5);
    wrefresh(new_window5);
    wrefresh(ch_window1);
    wrefresh(ch_window2);
    wrefresh(ch_window4);
 
    mvwaddstr(ch_window4, flag, 3, "=>");
    wrefresh(ch_window4);


                     break;

	    }
	    case 11:
	    {
                clear();
                refresh();
                new_window2 = newwin(13, 50, 5, 30);
                box(new_window2, 0, 0);
                mvwaddstr(new_window2, 3, 22, "GOODBYE");
                mvwaddstr(new_window2, 5, 22, msg1.name);
		wrefresh(new_window2);

		msg1.action = QUIT;
		write(new_fd, &msg1, sizeof(Node));

	        goto EXIT_CHATINTERFACE;
	        break;
	    }
	}
    }

    EXIT_CHATINTERFACE:

    curs_set(1);
    wgetch(new_window1);

}