⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 telnet.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 2 页
字号:
                continue;            }            if (ufd[i].revents & POLLOUT && (cl->i_buffer_write > 0))            {                ssize_t i_len;                i_len = send( cl->fd, cl->p_buffer_write ,                              cl->i_buffer_write, 0 );                if( i_len > 0 )                {                    cl->p_buffer_write += i_len;                    cl->i_buffer_write -= i_len;                }            }            if (ufd[i].revents & POLLIN)            {                bool end = false;                ssize_t i_recv;                while( ((i_recv=recv( cl->fd, cl->p_buffer_read, 1, 0 )) > 0) &&                       ((cl->p_buffer_read - cl->buffer_read) < 999) )                {                    switch( cl->i_tel_cmd )                    {                    case 0:                        switch( *(uint8_t *)cl->p_buffer_read )                        {                        case '\r':                            break;                        case '\n':                            *cl->p_buffer_read = '\n';                            end = true;                            break;                        case TEL_IAC: // telnet specific command                            cl->i_tel_cmd = 1;                            cl->p_buffer_read++;                            break;                        default:                            cl->p_buffer_read++;                            break;                        }                        break;                    case 1:                        switch( *(uint8_t *)cl->p_buffer_read )                        {                        case TEL_WILL: case TEL_WONT:                        case TEL_DO: case TEL_DONT:                            cl->i_tel_cmd++;                            cl->p_buffer_read++;                            break;                        default:                            cl->i_tel_cmd = 0;                            cl->p_buffer_read--;                            break;                        }                        break;                    case 2:                        cl->i_tel_cmd = 0;                        cl->p_buffer_read -= 2;                        break;                    }                    if( end ) break;                }                if( (cl->p_buffer_read - cl->buffer_read) == 999 )                {                    Write_message( cl, NULL, "Line too long\r\n",                                   cl->i_mode + 2 );                }                if (i_recv <= 0 && ( end || errno != EAGAIN ) )                    goto drop;            }        }        /* and now we should bidouille the data we received / send */        for(int i = 0 ; i < p_sys->i_clients ; i++ )        {            telnet_client_t *cl = p_sys->clients[i];            if( cl->i_mode >= WRITE_MODE_PWD && cl->i_buffer_write == 0 )            {               // we have finished to send               cl->i_mode -= 2; // corresponding READ MODE            }            else if( cl->i_mode == READ_MODE_PWD &&                     *cl->p_buffer_read == '\n' )            {                *cl->p_buffer_read = '\0';                if( !psz_password || !strcmp( psz_password, cl->buffer_read ) )                {                    Write_message( cl, NULL, "\xff\xfc\x01\r\nWelcome, "                                   "Master\r\n> ", WRITE_MODE_CMD );                }                else                {                    /* wrong password */                    Write_message( cl, NULL,                                   "\r\nWrong password.\r\nPassword: ",                                   WRITE_MODE_PWD );                }            }            else if( cl->i_mode == READ_MODE_CMD &&                     *cl->p_buffer_read == '\n' )            {                /* ok, here is a command line */                if( !strncmp( cl->buffer_read, "logout", 6 ) ||                    !strncmp( cl->buffer_read, "quit", 4 )  ||                    !strncmp( cl->buffer_read, "exit", 4 ) )                {                    net_Close( cl->fd );                    TAB_REMOVE( p_intf->p_sys->i_clients ,                                p_intf->p_sys->clients , cl );                    free( cl->buffer_write );                    free( cl );                }                else if( !strncmp( cl->buffer_read, "shutdown", 8 ) )                {                    msg_Err( p_intf, "shutdown requested" );                    vlc_object_kill( p_intf->p_libvlc );                }                else if( *cl->buffer_read == '@'                          && strchr( cl->buffer_read, ' ' ) )                {                    /* Module specific commands (use same syntax as in the                     * rc interface) */                    char *psz_name = cl->buffer_read + 1;                    char *psz_cmd, *psz_arg, *psz_msg;                    int i_ret;                    psz_cmd = strchr( cl->buffer_read, ' ' );                    *psz_cmd = '\0';  psz_cmd++;                    if( ( psz_arg = strchr( psz_cmd, '\n' ) ) ) *psz_arg = '\0';                    if( ( psz_arg = strchr( psz_cmd, '\r' ) ) ) *psz_arg = '\0';                    if( ( psz_arg = strchr( psz_cmd, ' ' ) )                        && *psz_arg )                    {                        *psz_arg = '\0';                        psz_arg++;                    }                    i_ret = var_Command( p_intf, psz_name, psz_cmd, psz_arg,                                         &psz_msg );                    if( psz_msg )                    {                        vlm_message_t *message;                        message = vlm_MessageNew( "Module command", psz_msg );                        Write_message( cl, message, NULL, WRITE_MODE_CMD );                        vlm_MessageDelete( message );                        free( psz_msg );                    }                }                else                {                    vlm_message_t *message;                    /* create a standard string */                    *cl->p_buffer_read = '\0';                    vlm_ExecuteCommand( p_sys->mediatheque, cl->buffer_read,                                        &message );                    if( !strncmp( cl->buffer_read, "help", 4 ) )                    {                        vlm_message_t *p_my_help =                            vlm_MessageNew( "Telnet Specific Commands:", NULL );                        vlm_MessageAdd( p_my_help,                            vlm_MessageNew( "logout, quit, exit" , NULL ) );                        vlm_MessageAdd( p_my_help,                            vlm_MessageNew( "shutdown" , NULL ) );                        vlm_MessageAdd( p_my_help,                            vlm_MessageNew( "@moduleinstance command argument",                                             NULL) );                        vlm_MessageAdd( message, p_my_help );                    }                    Write_message( cl, message, NULL, WRITE_MODE_CMD );                    vlm_MessageDelete( message );                }            }        }        /* handle new connections */        for (unsigned i = 0; i < nlisten; i++)        {            int fd;            if (ufd[ncli + i].revents == 0)                continue;            fd = net_AcceptSingle (VLC_OBJECT(p_intf), ufd[ncli + i].fd);            if (fd == -1)                continue;            telnet_client_t *cl = malloc( sizeof( telnet_client_t ));            if (cl == NULL)            {                net_Close (fd);                continue;            }            memset( cl, 0, sizeof(telnet_client_t) );            cl->i_tel_cmd = 0;            cl->fd = fd;            cl->buffer_write = NULL;            cl->p_buffer_write = cl->buffer_write;            Write_message( cl, NULL,                           "Password: \xff\xfb\x01" , WRITE_MODE_PWD );            TAB_APPEND( p_sys->i_clients, p_sys->clients, cl );        }    }    free( psz_password );}static void Write_message( telnet_client_t *client, vlm_message_t *message,                           const char *string_message, int i_mode ){    char *psz_message;    client->p_buffer_read = client->buffer_read;    (client->p_buffer_read)[0] = 0; // if (cl->p_buffer_read)[0] = '\n'    free( client->buffer_write );    /* generate the psz_message string */    if( message )    {        /* ok, look for vlm_message_t */        psz_message = MessageToString( message, 0 );    }    else    {        /* it is a basic string_message */        psz_message = strdup( string_message );    }    client->buffer_write = client->p_buffer_write = psz_message;    client->i_buffer_write = strlen( psz_message );    client->i_mode = i_mode;}/* We need the level of the message to put a beautiful indentation. * first level is 0 */static char *MessageToString( vlm_message_t *message, int i_level ){#define STRING_CR "\r\n"#define STRING_TAIL "> "    char *psz_message;    int i, i_message = sizeof( STRING_TAIL );    if( !message || !message->psz_name )    {        return strdup( STRING_CR STRING_TAIL );    }    else if( !i_level && !message->i_child && !message->psz_value  )    {        /* A command is successful. Don't write anything */        return strdup( /*STRING_CR*/ STRING_TAIL );    }    i_message += strlen( message->psz_name ) + i_level * sizeof( "    " ) + 1;    psz_message = malloc( i_message );    *psz_message = 0;    for( i = 0; i < i_level; i++ ) strcat( psz_message, "    " );    strcat( psz_message, message->psz_name );    if( message->psz_value )    {        i_message += sizeof( " : " ) + strlen( message->psz_value ) +            sizeof( STRING_CR );        psz_message = realloc( psz_message, i_message );        strcat( psz_message, " : " );        strcat( psz_message, message->psz_value );        strcat( psz_message, STRING_CR );    }    else    {        i_message += sizeof( STRING_CR );        psz_message = realloc( psz_message, i_message );        strcat( psz_message, STRING_CR );    }    for( i = 0; i < message->i_child; i++ )    {        char *child_message =            MessageToString( message->child[i], i_level + 1 );        i_message += strlen( child_message );        psz_message = realloc( psz_message, i_message );        strcat( psz_message, child_message );        free( child_message );    }    if( i_level == 0 ) strcat( psz_message, STRING_TAIL );    return psz_message;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -