Changeset 5181

Show
Ignore:
Timestamp:
01/18/08 18:04:15 (6 months ago)
Author:
morris
Message:

Support downloads/uploads of full directories

Add /download command to set the local download directory

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wire/trunk/NEWS

    r5172 r5181  
    33 
    441.1.3 
     5- Support downloads/uploads of full directories 
     6- Add /download command to set the local download directory 
    57- Make /open command take its options before the hostname, instead of after 
     8- Add more descriptions to /help command 
    69- Fix problems with completing file paths 
    710- Fix parsing of IPv6 addresses 
  • wire/trunk/wire/client.c

    r5160 r5181  
    139139        "Vy/xW31D+jfvNtPdS+ASBQAAAABJRU5ErkJggg=="; 
    140140 
    141 static wi_socket_context_t                      *wr_socket_context; 
    142  
     141wi_socket_context_t                                     *wr_socket_context; 
    143142wi_socket_t                                                     *wr_socket; 
    144143wi_address_t                                            *wr_address; 
     
    157156 
    158157void wr_client_init(void) { 
    159         wi_integer_t    options; 
    160          
    161158        wr_socket_context = wi_socket_context_init(wi_socket_context_alloc()); 
    162159         
     
    167164                wi_log_err(WI_STR("Could not set SSL ciphers: %m")); 
    168165         
     166        wr_server_string_encoding = wi_string_encoding_init_with_charset( 
     167                wi_string_encoding_alloc(), 
     168                WI_STR("UTF-8"), 
     169                WI_STRING_ENCODING_IGNORE | WI_STRING_ENCODING_TRANSLITERATE); 
     170         
     171        wr_set_charset(WI_STR("ISO-8859-1")); 
     172         
     173        wr_nick = wi_retain(wi_user_name()); 
     174        wr_icon = wi_string_init_with_cstring(wi_string_alloc(), wr_default_icon); 
     175} 
     176 
     177 
     178 
     179#pragma mark - 
     180 
     181wi_boolean_t wr_set_charset(wi_string_t *charset) { 
     182        wi_string_encoding_t    *encoding; 
     183        wi_integer_t                    options; 
     184         
     185        if(wr_client_string_encoding && wi_is_equal(charset, wi_string_encoding_charset(wr_client_string_encoding))) 
     186                return true; 
     187         
    169188        options = WI_STRING_ENCODING_IGNORE | WI_STRING_ENCODING_TRANSLITERATE; 
    170          
    171         wr_client_string_encoding = wi_string_encoding_init_with_charset(wi_string_encoding_alloc(), 
    172                                                                                                                                          WI_STR("ISO-8859-1"), 
    173                                                                                                                                          options); 
    174          
    175         wr_server_string_encoding = wi_string_encoding_init_with_charset(wi_string_encoding_alloc(), 
    176                                                                                                                                          WI_STR("UTF-8"), 
    177                                                                                                                                          options); 
    178          
    179         wr_icon = wi_string_init_with_cstring(wi_string_alloc(), wr_default_icon); 
     189        encoding = wi_string_encoding_init_with_charset(wi_string_encoding_alloc(), 
     190                                                                                                        charset, 
     191                                                                                                        options); 
     192         
     193        if(!encoding) 
     194                return false; 
     195 
     196        wi_release(wr_client_string_encoding); 
     197        wr_client_string_encoding = encoding; 
     198         
     199        wr_printf_prefix(WI_STR("Using character set %@"), charset); 
     200         
     201        return true; 
    180202} 
    181203 
     
    408430 
    409431                case 521: 
    410                         wr_printf_prefix(WI_STR("%@: File or directory already exists"), 
    411                                 wr_last_command); 
     432                        if(!wr_transfers_recursive_upload) { 
     433                                wr_printf_prefix(WI_STR("%@: File or directory already exists"), 
     434                                        wr_last_command); 
     435                        } 
    412436                        break; 
    413437 
     
    9961020 
    9971021static void wr_msg_400(wi_array_t *arguments) { 
    998         wi_address_t            *address; 
    9991022        wr_transfer_t           *transfer; 
    10001023 
    1001         transfer = wr_transfers_transfer_with_path(WI_ARRAY(arguments, 0)); 
     1024        transfer = wr_transfers_transfer_with_remote_path(WI_ARRAY(arguments, 0)); 
    10021025 
    10031026        if(!transfer) 
    10041027                return; 
    10051028         
    1006         address = wi_copy(wr_address); 
    1007         wi_address_set_port(address, wi_address_port(address) + 1); 
    1008          
    1009         transfer->state                 = WR_TRANSFER_RUNNING; 
    1010         transfer->offset                = wi_string_uint64(WI_ARRAY(arguments, 1)); 
    1011         transfer->transferred   = transfer->offset; 
    1012         transfer->key                   = wi_retain(WI_ARRAY(arguments, 2)); 
    1013         transfer->start_time    = wi_time_interval(); 
    1014         transfer->socket                = wi_socket_init_with_address(wi_socket_alloc(), address, WI_SOCKET_TCP); 
    1015  
    1016         wi_socket_set_interactive(transfer->socket, false); 
    1017          
    1018         if(!wi_socket_connect(transfer->socket, wr_socket_context, 15.0)) { 
    1019                 wr_printf_prefix(WI_STR("Could not connect to %@: %m"), wi_address_string(address)); 
    1020                  
    1021                 wr_transfer_stop(transfer); 
    1022  
    1023                 goto end; 
    1024         } 
    1025          
    1026         wi_file_seek(transfer->file, transfer->offset); 
    1027  
    1028         if(transfer->type == WR_TRANSFER_DOWNLOAD) { 
    1029                 wi_socket_set_direction(transfer->socket, WI_SOCKET_READ); 
    1030                 wr_runloop_add_socket(transfer->socket, wr_runloop_download_callback); 
    1031         } else { 
    1032                 wi_socket_set_direction(transfer->socket, WI_SOCKET_WRITE); 
    1033                 wr_runloop_add_socket(transfer->socket, wr_runloop_upload_callback); 
    1034         } 
    1035  
    1036         wr_send_command_on_socket(transfer->socket, WI_STR("TRANSFER %#@"), transfer->key); 
    1037  
    1038         wr_printf_prefix(WI_STR("Starting transfer of \"%@\""), transfer->name); 
    1039          
    1040         wr_draw_transfers(true); 
    1041  
    1042 end: 
    1043         wi_release(address); 
     1029        wr_transfer_open(transfer, wi_string_uint64(WI_ARRAY(arguments, 1)), WI_ARRAY(arguments, 2)); 
    10441030} 
    10451031 
     
    10491035        wr_transfer_t   *transfer; 
    10501036 
    1051         transfer = wr_transfers_transfer_with_path(WI_ARRAY(arguments, 0)); 
     1037        transfer = wr_transfers_transfer_with_remote_path(WI_ARRAY(arguments, 0)); 
    10521038 
    10531039        if(transfer) { 
     
    10621048        wi_date_t                       *date; 
    10631049        wi_string_t                     *path, *kind, *string; 
     1050        wr_file_t                       *file; 
    10641051        wr_transfer_t           *transfer; 
    10651052        wi_file_offset_t        size; 
     
    11211108        } 
    11221109        else if(wr_stat_state == WR_STAT_TRANSFER) { 
    1123                 transfer = wr_transfers_transfer_with_path(WI_ARRAY(arguments, 0)); 
     1110                transfer = wr_transfers_transfer_with_remote_path(WI_ARRAY(arguments, 0)); 
    11241111                 
    11251112                if(transfer) { 
     
    11271114                                if(transfer->checksum && !wi_is_equal(transfer->checksum, WI_ARRAY(arguments, 5))) { 
    11281115                                        wr_printf_prefix(WI_STR("get: Checksum mismatch for \"%@\""), 
    1129                                                                          transfer->name); 
     1116                                                transfer->name); 
     1117                                         
    11301118                                        wr_transfer_stop(transfer); 
    11311119                                         
     
    11331121                                } 
    11341122                                 
    1135                                 transfer->size = size; 
     1123                                if(!transfer->recursive) { 
     1124                                        file = wr_file_init_with_arguments(wr_file_alloc(), arguments); 
     1125                                        wr_transfer_download_add_file(transfer, file, false); 
     1126                                        wi_release(file); 
     1127                                } 
    11361128                                 
    1137                                 wr_send_command(WI_STR("GET %#@%c%llu"), 
    1138                                                                 transfer->path,         WR_FIELD_SEPARATOR, 
    1139                                                                 transfer->offset); 
     1129                                wr_transfer_request(transfer); 
    11401130                        } else { 
    1141                                 wr_printf_prefix(WI_STR("get: Cannot download directories")); 
     1131                                wr_ls_state = WR_LS_TRANSFER; 
     1132                                transfer->recursive = true; 
     1133                                 
     1134                                wr_files_clear(); 
     1135                                wr_send_command(WI_STR("LISTRECURSIVE %#@"), path); 
    11421136                        } 
    11431137                } 
     
    11491143static void wr_msg_410(wi_array_t *arguments) { 
    11501144        wr_file_t               *file; 
    1151  
     1145         
    11521146        file = wr_file_init_with_arguments(wr_file_alloc(), arguments); 
    11531147        wi_array_add_data(wr_files, file); 
     
    11581152 
    11591153static void wr_msg_411(wi_array_t *arguments) { 
     1154        wr_transfer_t           *transfer; 
    11601155        wi_file_offset_t        free; 
    11611156 
     
    11701165                        wr_print_files(); 
    11711166        } 
     1167        else if(wr_ls_state == WR_LS_TRANSFER) { 
     1168                transfer = wr_transfers_transfer_with_remote_path(WI_ARRAY(arguments, 0)); 
     1169                 
     1170                if(transfer) { 
     1171                        if(transfer->type == WR_TRANSFER_DOWNLOAD) 
     1172                                wr_transfer_download_add_files(transfer, wr_files); 
     1173                        else 
     1174                                wr_transfer_upload_remove_files(transfer, wr_files); 
     1175                                 
     1176                        transfer->state = WR_TRANSFER_WAITING; 
     1177                        transfer->listed = true; 
     1178                         
     1179                        wr_transfer_request(transfer); 
     1180                } 
     1181        } 
    11721182} 
    11731183 
  • wire/trunk/wire/client.h

    r5079 r5181  
    5252void                                                                    wr_client_init(void); 
    5353 
     54wi_boolean_t                                                    wr_set_charset(wi_string_t *); 
     55 
    5456void                                                                    wr_connect(wi_string_t *, wi_uinteger_t, wi_string_t *, wi_string_t *); 
    5557void                                                                    wr_disconnect(void); 
     
    8486extern wi_time_interval_t                               wr_ping_time; 
    8587 
     88extern wi_socket_context_t                              *wr_socket_context; 
    8689extern wi_socket_t                                              *wr_socket; 
    8790extern wi_address_t                                             *wr_address; 
  • wire/trunk/wire/commands.c

    r5163 r5181  
    5050 
    5151        wi_boolean_t                            help; 
     52        const char                                      *description; 
    5253        const char                                      *usage; 
    5354 
     
    7475static void                                             wr_cmd_comment(wi_array_t *); 
    7576static void                                             wr_cmd_disconnect(wi_array_t *); 
     77static void                                             wr_cmd_download(wi_array_t *); 
    7678static void                                             wr_cmd_echo(wi_array_t *); 
    7779static void                                             wr_cmd_get(wi_array_t *); 
     
    117119 
    118120 
     121#define WR_CMD_INFO_DESCRIPTION "Get info for the user" 
     122#define WR_CMD_INFO_USAGE               "<user>" 
     123 
     124#define WR_CMD_OPEN_DESCRIPTION "Connect to a server" 
     125#define WR_CMD_OPEN_USAGE               "[-l <login>] [-p <password>] [-P <port>] <server>" 
     126 
     127#define WR_CMD_MV_DESCRIPTION   "Move or rename a path" 
     128#define WR_CMD_MV_USAGE                 "<path> <path>" 
     129 
     130#define WR_CMD_QUIT_DESCRIPTION "Quit wire" 
     131#define WR_CMD_QUIT_USAGE               "" 
     132 
     133#define WR_CMD_RM_DESCRIPTION   "Delete the path" 
     134#define WR_CMD_RM_USAGE                 "<path>" 
     135 
    119136static wr_commands_t                    wr_commands[] = { 
    120137        { "ban", 
    121           true, "<user> <message>", 
     138          true, "Ban the user from the server with a message", "<user> <message>", 
    122139          true, 2, 1, WR_COMPLETER_NICKNAME, 
    123140          wr_cmd_ban }, 
    124141        { "broadcast", 
    125           true, "<message>", 
     142          true, "Broadcast a message to all users", "<message>", 
    126143          true, 1, 0, WR_COMPLETER_NICKNAME, 
    127144          wr_cmd_broadcast }, 
    128145        { "cd", 
    129           true, "<path>", 
     146          true, "Change the working directory", "<path>", 
    130147          true, 1, -1, WR_COMPLETER_DIRECTORY, 
    131148          wr_cmd_cd }, 
    132149        { "charset", 
    133           true, "<charset>", 
     150          true, "Set the character set that is used to convert text from the server", "<charset>", 
    134151          false, 1, -1, WR_COMPLETER_NONE, 
    135152          wr_cmd_charset }, 
    136153        { "clear", 
    137           true, "", 
     154          true, "Clear all output", "", 
    138155          false, 0, -1, WR_COMPLETER_NONE, 
    139156          wr_cmd_clear }, 
    140157        { "clearnews", 
    141           true, "", 
     158          true, "Clear the news", "", 
    142159          true, 0, -1, WR_COMPLETER_NONE, 
    143160          wr_cmd_clearnews }, 
    144161        { "close", 
    145           true, "",    
     162          true, "Close the current window, or disconnect from the server if in main window", "",       
    146163          false, 0, -1, WR_COMPLETER_NONE, 
    147164          wr_cmd_close }, 
    148165        { "comment", 
    149           true, "<path> <comment>", 
     166          true, "Set the comment for the path", "<path> <comment>", 
    150167          true, 1, -1, WR_COMPLETER_FILENAME, 
    151168          wr_cmd_comment }, 
    152169        { "connect", 
    153           false, "[-l <login>] [-p <password>] [-P <port>] <server>"
     170          false, WR_CMD_OPEN_DESCRIPTION, WR_CMD_OPEN_USAGE
    154171          false, 1, -1, WR_COMPLETER_NONE, 
    155172          wr_cmd_open }, 
    156173        { "delete", 
    157           true, "<path>"
     174          true, WR_CMD_RM_DESCRIPTION, WR_CMD_RM_USAGE
    158175          true, 1, -1, WR_COMPLETER_FILENAME, 
    159176          wr_cmd_rm }, 
    160177        { "disconnect", 
    161           true, "",    
     178          true, "Disconnect from the server", "",      
    162179          true, 0, -1, WR_COMPLETER_NONE, 
    163180          wr_cmd_disconnect }, 
     181        { "download", 
     182          true, "Set the directory where downloads will be created", "<path>", 
     183          false, 1, -1, WR_COMPLETER_LOCAL_FILENAME, 
     184          wr_cmd_download }, 
    164185        { "echo", 
    165           false, "<text>", 
     186          false, "Print the string", "<text>", 
    166187          false, 1, 0, WR_COMPLETER_NONE, 
    167188          wr_cmd_echo }, 
    168189        { "exit", 
    169           false, ""
     190          false, WR_CMD_QUIT_DESCRIPTION, WR_CMD_QUIT_USAGE
    170191          false, 0, -1, WR_COMPLETER_NONE, 
    171192          wr_cmd_quit }, 
    172193        { "get", 
    173           true, "<path>", 
     194          true, "Downloads the path", "<path>", 
    174195          true, 1, -1, WR_COMPLETER_FILENAME, 
    175196          wr_cmd_get }, 
    176197        { "help", 
    177           true, "[<command>]", 
     198          true, "Print a list of commands, or help for a specific command", "[<command>]", 
    178199          false, 0, -1, WR_COMPLETER_COMMAND, 
    179200          wr_cmd_help }, 
    180201        { "icon", 
    181           true, "<path>", 
     202          true, "Load a custom icon from a 32x32 PNG image file", "<path>", 
    182203          false, 1, -1, WR_COMPLETER_LOCAL_FILENAME, 
    183204          wr_cmd_icon }, 
    184205        { "ignore", 
    185           true, "[<nick>]", 
     206          true, "Add the user to the ignore list", "[<nick>]", 
    186207          false, 0, -1, WR_COMPLETER_NICKNAME, 
    187208          wr_cmd_ignore }, 
    188209        { "ignores", 
    189           true, "[<nick>]", 
     210          true, "List ignores", "[<nick>]", 
    190211          false, 0, -1, WR_COMPLETER_NICKNAME, 
    191212          wr_cmd_ignore }, 
    192213        { "info", 
    193           true, "<user>"
     214          true, WR_CMD_INFO_DESCRIPTION, WR_CMD_INFO_USAGE
    194215          true, 1, -1, WR_COMPLETER_NICKNAME, 
    195216          wr_cmd_info }, 
    196217        { "invite", 
    197           true, "<user>", 
     218          true, "Invite the user to the current private chat", "<user>", 
    198219          true, 1, -1, WR_COMPLETER_NICKNAME, 
    199220          wr_cmd_invite }, 
    200221        { "join", 
    201           false, "[-l <login>] [-p <password>] [-P <port>] <server>"
     222          false, WR_CMD_OPEN_DESCRIPTION, WR_CMD_OPEN_USAGE
    202223          false, 1, -1, WR_COMPLETER_NONE, 
    203224          wr_cmd_open }, 
    204225        { "kick", 
    205           true, "<user> <message>", 
     226          true, "Kick the user from the server with a message", "<user> <message>", 
    206227          true, 1, 1, WR_COMPLETER_NICKNAME, 
    207228          wr_cmd_kick }, 
    208229        { "load", 
    209           true, "<bookmark>", 
     230          true, "Load the bookmark from the ~/.wire/ directory", "<bookmark>", 
    210231          false, 1, -1, WR_COMPLETER_BOOKMARK, 
    211232          wr_cmd_load }, 
    212233        { "log", 
    213           true, "<filename>", 
     234          true, "Save a copy of the current output to a file", "<filename>", 
    214235          false, 1, -1, WR_COMPLETER_NONE, 
    215236          wr_cmd_log }, 
    216237        { "ls", 
    217           true, "<path>", 
     238          true, "List the current directory, or a path", "[<path>]", 
    218239          true, 0, -1, WR_COMPLETER_DIRECTORY, 
    219240          wr_cmd_ls }, 
    220241        { "me", 
    221           true, "<chat>", 
     242          true, "Say text as action chat", "<chat>", 
    222243          true, 1, 0, WR_COMPLETER_NICKNAME, 
    223244          wr_cmd_me }, 
    224245        { "mkdir", 
    225           true, "<path>", 
     246          true, "Create a new directory", "<path>", 
    226247          true, 1, -1, WR_COMPLETER_FILENAME, 
    227248          wr_cmd_mkdir }, 
    228249        { "move", 
    229           true, "<path> <path>"
     250          true, WR_CMD_MV_DESCRIPTION, WR_CMD_MV_USAGE
    230251          true, 2, -1, WR_COMPLETER_FILENAME, 
    231252          wr_cmd_mv }, 
    232253        { "msg", 
    233           true, "<user> <message>", 
     254          true, "Send a private message to the user", "<user> <message>", 
    234255          true, 2, 1, WR_COMPLETER_NICKNAME, 
    235256          wr_cmd_msg }, 
    236257        { "mv", 
    237           true, "<path> <path>"
     258          true, WR_CMD_MV_DESCRIPTION, WR_CMD_MV_USAGE
    238259          true, 2, -1, WR_COMPLETER_FILENAME, 
    239260          wr_cmd_mv }, 
    240261        { "news", 
    241           true, "[-<number> | -ALL]", 
     262          true, "Print parts or all of the server news", "[-<number> | -ALL]", 
    242263          true, 0, -1, WR_COMPLETER_NONE, 
    243264          wr_cmd_news }, 
    244265        { "nick", 
    245           true, "<nick>", 
     266          true, "Set your current nick name", "<nick>", 
    246267          false, 1, 0, WR_COMPLETER_NICKNAME, 
    247268          wr_cmd_nick }, 
    248269        { "open", 
    249           true, "[-l <login>] [-p <password>] [-P <port>] <server>"
     270          true, WR_CMD_OPEN_DESCRIPTION, WR_CMD_OPEN_USAGE
    250271          false, 1, -1, WR_COMPLETER_NONE, 
    251272          wr_cmd_open }, 
    252273        { "ping", 
    253           true, "", 
     274          true, "Ping the server to determine latency", "", 
    254275          true, 0, -1, WR_COMPLETER_NONE, 
    255276          wr_cmd_ping }, 
    256277        { "post", 
    257           true, "<message>", 
     278          true, "Post a new message to the server news", "<message>", 
    258279          true, 1, 0, WR_COMPLETER_NICKNAME, 
    259280          wr_cmd_post }, 
    260281        { "privchat", 
    261           true, "[<user>]", 
     282          true, "Create a private chat, optionally inviting the user", "[<user>]", 
    262283          true, 0, -1, WR_COMPLETER_NICKNAME, 
    263284          wr_cmd_privchat }, 
    264285        { "put", 
    265           true, "<path>", 
     286          true, "Upload the path to the current working directory", "<path>", 
    266287          true, 1, -1, WR_COMPLETER_LOCAL_FILENAME, 
    267288          wr_cmd_put }, 
    268289        { "pwd", 
    269           true, "", 
     290          true, "Print the current working directory", "", 
    270291          true, 0, -1, WR_COMPLETER_NONE, 
    271292          wr_cmd_pwd }, 
    272293        { "quit", 
    273           true, ""
     294          true, WR_CMD_QUIT_DESCRIPTION, WR_CMD_QUIT_USAGE
    274295          false, 0, -1, WR_COMPLETER_NONE, 
    275296          wr_cmd_quit }, 
    276297        { "remove", 
    277           true, "<path>"
     298          true, WR_CMD_RM_DESCRIPTION, WR_CMD_RM_USAGE
    278299          true, 1, -1, WR_COMPLETER_FILENAME, 
    279300          wr_cmd_rm }, 
    280301        { "reply", 
    281           true, "<message>", 
     302          true, "Send a private message to the last user who messaged you", "<message>", 
    282303          true, 1, 0, WR_COMPLETER_NICKNAME, 
    283304          wr_cmd_reply }, 
    284305        { "rm", 
    285           true, "<path>"
     306          true, WR_CMD_RM_DESCRIPTION, WR_CMD_RM_USAGE
    286307          true, 1, -1, WR_COMPLETER_FILENAME, 
    287308          wr_cmd_rm }, 
    288309        { "save", 
    289           true, "<bookmark>", 
     310          true, "Save a bookmark to the ~/.wire/ directory", "<bookmark>", 
    290311          false, 1, -1, WR_COMPLETER_BOOKMARK, 
    291312          wr_cmd_save }, 
    292313        { "say", 
    293           false, "<chat>", 
     314          false, "Say text", "<chat>", 
    294315          true, 1, 0, WR_COMPLETER_NICKNAME, 
    295316          wr_cmd_say }, 
    296317        { "search", 
    297           true, "<query>", 
     318          true, "Search files", "<query>", 
    298319          true, 1, -1, WR_COMPLETER_FILENAME, 
    299320          wr_cmd_search }, 
    300321        { "server", 
    301           false, "[-l <login>] [-p <password>] [-P <port>] <server>"
     322          false, WR_CMD_OPEN_DESCRIPTION, WR_CMD_OPEN_USAGE
    302323          false, 1, -1, WR_COMPLETER_NONE, 
    303324          wr_cmd_open }, 
    304325        { "serverinfo", 
    305           true, "", 
     326          true, "Print server info", "", 
    306327          true, 0, -1, WR_COMPLETER_NONE, 
    307328          wr_cmd_serverinfo }, 
    308329        { "start", 
    309           true, "<transfer>", 
     330          true, "Start the transfer", "<transfer>", 
    310331          true, 1, -1, WR_COMPLETER_NONE, 
    311332          wr_cmd_start }, 
    312333        { "stat", 
    313           true, "<path>", 
     334          true, "Print file info for the path", "<path>", 
    314335          true, 1, -1, WR_COMPLETER_FILENAME, 
    315336          wr_cmd_stat }, 
    316337        { "status", 
    317           true, "<status>", 
     338          true, "Set your current status message", "<status>", 
    318339          false, 1, 0, WR_COMPLETER_NONE, 
    319340          wr_cmd_status }, 
    320341        { "stop", 
    321           true, "<transfer>", 
     342          true, "Stop the transfer", "<transfer>", 
    322343          true, 1, -1, WR_COMPLETER_NONE, 
    323344          wr_cmd_stop }, 
    324345        { "timestamp", 
    325           true, "[<format>]", 
     346          true, "Set or disable the timestamp", "[<format>]", 
    326347          false, 0, 0, WR_COMPLETER_NONE, 
    327348          wr_cmd_timestamp }, 
    328349        { "topic", 
    329           true, "[<topic>]", 
     350          true, "Set or print the chat topic", "[<topic>]", 
    330351          true, 0, 0, WR_COMPLETER_NICKNAME, 
    331352          wr_cmd_topic }, 
    332353        { "type", 
    333           true, "<path> (folder | uploads | dropbox)", 
     354          true, "Set the folder type for the path", "<path> (folder | uploads | dropbox)", 
    334355          true, 2, -1, WR_COMPLETER_FILENAME, 
    335356          wr_cmd_type }, 
    336357        { "unignore", 
    337           true, "[<ignore> | <nick>]", 
     358          true, "Remove the user or the ignore from the ignore list", "[<ignore> | <nick>]", 
    338359          false, 0, -1, WR_COMPLETER_IGNORE, 
    339360          wr_cmd_unignore }, 
    340361        { "uptime", 
    341           true, "", 
     362          true, "Print uptime statistics for wire", "", 
    342363          false, 0, -1, WR_COMPLETER_NONE, 
    343364          wr_cmd_uptime }, 
    344365        { "version", 
    345           true, "", 
     366          true, "Print version information for wire", "", 
    346367          false, 0, -1, WR_COMPLETER_NONE, 
    347368          wr_cmd_version }, 
    348369        { "who", 
    349           true, "", 
     370          true, "Print the user list", "", 
    350371          true, 0, -1, WR_COMPLETER_NONE, 
    351372          wr_cmd_who }, 
    352373        { "whois", 
    353           false, "<user>"
     374          false, WR_CMD_INFO_DESCRIPTION, WR_CMD_INFO_USAGE
    354375          true, 1, -1, WR_COMPLETER_NICKNAME, 
    355376          wr_cmd_info }, 
     
    437458        } 
    438459 
     460        wr_printf_prefix(WI_STR("%s: %s"), 
     461                wr_commands[index].name, wr_commands[index].description); 
     462         
    439463        wr_printf_prefix(WI_STR("Usage: %s %s"), 
    440464                wr_commands[index].name, wr_commands[index].usage); 
     
    578602 
    579603static void wr_cmd_charset(wi_array_t *arguments) { 
    580         wi_string_encoding_t    *encoding; 
    581         wi_string_t                             *charset; 
    582         wi_integer_t                    options; 
    583          
    584         charset = WI_ARRAY(arguments, 0); 
    585         options = WI_STRING_ENCODING_IGNORE | WI_STRING_ENCODING_TRANSLITERATE; 
    586         encoding = wi_string_encoding_init_with_charset(wi_string_encoding_alloc(), 
    587                                                                                                         charset, 
    588                                                                                                         options); 
    589          
    590         if(!encoding) { 
    591                 wr_printf_prefix(WI_STR("charset: Could not use charset \"%@\": %m"), charset); 
    592         } else { 
    593                 wi_release(wr_client_string_encoding); 
    594                 wr_client_string_encoding = wi_retain(encoding); 
    595                  
    596                 wr_printf_prefix(WI_STR("Using character set %@"), 
    597                         charset); 
    598         } 
    599          
    600         wi_release(encoding); 
     604        if(!wr_set_charset(WI_ARRAY(arguments, 0))) 
     605                wr_printf_prefix(WI_STR("charset: Could not use charset \"%@\": %m"), WI_ARRAY(arguments, 0)); 
    601606} 
    602607 
     
    694699 
    695700/* 
     701        /download <path> 
     702*/ 
     703 
     704static void wr_cmd_download(wi_array_t *arguments) { 
     705        wr_transfers_set_download_path(WI_ARRAY(arguments, 0)); 
     706} 
     707 
     708 
     709 
     710/* 
    696711        /echo <text> 
    697712*/ 
     
    786801 
    787802        path = wi_string_by_normalizing_path(WI_ARRAY(arguments, 0)); 
    788         string = wi_string_init_with_contents_of_file(wi_string_alloc(), wi_string_by_normalizing_path(path)); 
     803        string = wi_string_init_with_contents_of_file(wi_string_alloc(), path); 
    789804         
    790805        if(string) { 
     
    14161431 
    14171432/* 
    1418         /say <chat> 
    1419 */ 
    1420  
    1421 static void wr_cmd_say(wi_array_t *arguments) { 
    1422         wi_string_t             *chat; 
    1423          
    1424         chat = WI_ARRAY(arguments, 0); 
    1425          
    1426         if(wr_window_is_chat(wr_current_window)) { 
    1427                 wr_send_command(WI_STR("SAY %u%c%#@"), 
    1428                         wr_chat_id(wr_current_window->chat),            WR_FIELD_SEPARATOR, 
    1429                         chat); 
    1430         } 
    1431         else if(wr_window_is_user(wr_current_window)) { 
    1432                 wr_send_command(WI_STR("MSG %u%c%#@"), 
    1433                         wr_user_id(wr_current_window->user),            WR_FIELD_SEPARATOR, 
    1434                         chat); 
    1435                  
    1436                 wr_wprint_say(wr_current_window, wr_nick, chat); 
    1437         } 
    1438 
    1439  
    1440  
    1441  
    1442 /* 
    1443         /search <query> 
    1444 */ 
    1445  
    1446 static void wr_cmd_search(wi_array_t *arguments) { 
    1447         wr_files_clear(); 
    1448          
    1449         wr_send_command(WI_STR("SEARCH %#@"), WI_ARRAY(arguments, 0)); 
    1450 
    1451  
    1452  
    1453  
    1454 /* 
    1455         /serverinfo 
    1456 */ 
    1457  
    1458 static void wr_cmd_serverinfo(wi_array_t *arguments) { 
    1459         wr_print_server_info(); 
    1460 
    1461  
    1462  
    1463  
    1464 /* 
    1465         /save <bookmark> 
    1466 */ 
     1433 /save <bookmark> 
     1434 */ 
    14671435 
    14681436static void wr_cmd_save(wi_array_t *arguments) { 
    14691437        wi_file_t               *file; 
    14701438        wi_string_t             *path, *login, *password, *port; 
    1471  
     1439         
    14721440        path = wi_user_home(); 
    14731441        wi_string_append_path_component(path, WI_STR(WR_WIRE_PATH)); 
     
    14751443         
    14761444        file = wi_file_for_writing(path); 
    1477  
     1445         
    14781446        if(!file) { 
    14791447                wr_printf_prefix(WI_STR("save: %@: %m"), path); 
    1480  
     1448                 
    14811449                return; 
    14821450        } 
     
    14841452        wi_file_write(file, WI_STR("charset %@\n"), wi_string_encoding_charset(wr_client_string_encoding)); 
    14851453        wi_file_write(file, WI_STR("timestamp %@\n"), wr_timestamp_format); 
     1454        wi_file_write(file, WI_STR("download %@\n"), wr_download_path); 
    14861455        wi_file_write(file, WI_STR("nick %@\n"), wr_nick); 
    1487  
     1456         
    14881457        if(wi_string_length(wr_status) > 0) 
    14891458                wi_file_write(file, WI_STR("status %@\n"), wr_status); 
    1490  
     1459         
    14911460        if(wr_icon_path) 
    14921461                wi_file_write(file, WI_STR("icon %@\n"), wr_icon_path); 
     
    15081477                        port = NULL; 
    15091478                 
    1510                 wi_file_write(file, WI_STR("open %@ %#@ %#@ %#@\n"), wr_host, login, password, port); 
    1511         } 
    1512  
     1479                wi_file_write(file, WI_STR("open %#@ %#@ %#@ %@\n"), login, password, port, wr_host); 
     1480        } 
     1481         
    15131482        wr_printf_prefix(WI_STR("save: \"%@\" saved"), path); 
     1483} 
     1484 
     1485 
     1486 
     1487/* 
     1488        /say <chat> 
     1489*/ 
     1490 
     1491static void wr_cmd_say(wi_array_t *arguments) { 
     1492        wi_string_t             *chat; 
     1493         
     1494        chat = WI_ARRAY(arguments, 0); 
     1495         
     1496        if(wr_window_is_chat(wr_current_window)) { 
     1497                wr_send_command(WI_STR("SAY %u%c%#@"), 
     1498                        wr_chat_id(wr_current_window->chat),            WR_FIELD_SEPARATOR, 
     1499                        chat); 
     1500        } 
     1501        else if(wr_window_is_user(wr_current_window)) { 
     1502                wr_send_command(WI_STR("MSG %u%c%#@"), 
     1503                        wr_user_id(wr_current_window->user),            WR_FIELD_SEPARATOR, 
     1504                        chat); 
     1505                 
     1506                wr_wprint_say(wr_current_window, wr_nick, chat); 
     1507        } 
     1508} 
     1509 
     1510 
     1511 
     1512/* 
     1513        /search <query> 
     1514*/ 
     1515 
     1516static void wr_cmd_search(wi_array_t *arguments) { 
     1517        wr_files_clear(); 
     1518         
     1519        wr_send_command(WI_STR("SEARCH %#@"), WI_ARRAY(arguments, 0)); 
     1520} 
     1521 
     1522 
     1523 
     1524/* 
     1525        /serverinfo 
     1526*/ 
     1527 
     1528static void wr_cmd_serverinfo(wi_array_t *arguments) { 
     1529        wr_print_server_info(); 
    15141530} 
    15151531 
     
    16361652 
    16371653static void wr_cmd_timestamp(wi_array_t *arguments) { 
    1638         if(wi_array_count(arguments) == 0) { 
    1639                 wi_release(wr_timestamp_format); 
    1640                 wr_timestamp_format = wi_retain(WI_STR("")); 
    1641         } else { 
    1642                 wi_release(wr_timestamp_format); 
    1643                 wr_timestamp_format = wi_retain(WI_ARRAY(arguments, 0)); 
    1644         } 
    1645  
    1646         wr_printf_prefix(WI_STR("Using timestamp format %@"), 
    1647                 wr_timestamp_format); 
     1654        if(wi_array_count(arguments) == 0) 
     1655                wr_windows_set_timestamp_format(WI_STR("")); 
     1656        else 
     1657                wr_windows_set_timestamp_format(WI_ARRAY(arguments, 0)); 
    16481658} 
    16491659 
  • wire/trunk/wire/files.c

    r5161 r5181  
    203203                 
    204204                if(globpaths) { 
    205                         glob_enumerator = wi_array_data_enumerator(wr_files_glob(path)); 
     205                        glob_enumerator = wi_array_data_enumerator(globpaths); 
    206206                         
    207                         while((globpath = wi_enumerator_next_data(glob_enumerator))) 
    208                                 wi_array_add_data(array, wr_files_full_path(globpath)); 
     207                        while((globpath = wi_enumerator_next_data(glob_enumerator))) { 
     208                                if(wi_string_length(globpath) > 0) 
     209                                        wi_array_add_data(array, wr_files_full_path(globpath)); 
     210                        } 
    209211                } 
    210212        } 
     
    320322         
    321323        dir->count = wi_array_count(wr_files); 
    322         dir->entries = wi_malloc(sizeof(struct dirent) * (dir->count + 1)); 
     324        dir->entries = wi_malloc(sizeof(struct dirent *) * (dir->count + 1)); 
    323325         
    324326        for(i = 0; i < dir->count; i++) { 
    325327                file = WI_ARRAY(wr_files, i); 
    326  
     328                 
    327329                dir->entries[i] = wi_malloc(sizeof(struct dirent)); 
    328                 dir->entries[i]->d_ino = 0
    329                 dir->entries[i]->d_reclen = 0
     330                dir->entries[i]->d_ino = random