Changeset 4683

Show
Ignore:
Timestamp:
02/22/07 18:02:10 (2 years ago)
Author:
morris
Message:

Add some p7 message handling, replacing the command handling

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wired/branches/p7/wired/chats.c

    r4576 r4683  
    227227 
    228228void wd_chat_add_client(wd_chat_t *chat, wd_client_t *client) { 
    229       wd_broadcast(chat, 302, WI_STR("%u%c%u%c%u%c%u%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@"), 
     229/*    wd_broadcast(chat, 302, WI_STR("%u%c%u%c%u%c%u%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@"), 
    230230                                 chat->cid,                     WD_FIELD_SEPARATOR, 
    231231                                 client->uid,           WD_FIELD_SEPARATOR, 
     
    238238                                 client->host,          WD_FIELD_SEPARATOR, 
    239239                                 client->status,        WD_FIELD_SEPARATOR, 
    240                                  client->image); 
     240                                 client->image);*/ 
    241241         
    242242        wi_array_wrlock(chat->clients); 
     
    274274        while((client = wi_enumerator_next_data(enumerator))) { 
    275275                if(client->state == WD_CLIENT_STATE_LOGGED_IN) { 
    276                       wd_reply(310, WI_STR("%u%c%u%c%u%c%u%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@"), 
     276/*                    wd_reply(310, WI_STR("%u%c%u%c%u%c%u%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@"), 
    277277                                         chat->cid,                     WD_FIELD_SEPARATOR, 
    278278                                         client->uid,           WD_FIELD_SEPARATOR, 
     
    285285                                         client->host,          WD_FIELD_SEPARATOR, 
    286286                                         client->status,        WD_FIELD_SEPARATOR, 
    287                                          client->image); 
     287                                         client->image);*/ 
    288288                } 
    289289        } 
  • wired/branches/p7/wired/clients.c

    r4596 r4683  
    204204        wi_release(client->version); 
    205205        wi_release(client->status); 
    206         wi_release(client->image); 
     206        wi_release(client->icon); 
    207207 
    208208        wi_release(client->socket_lock); 
  • wired/branches/p7/wired/clients.h

    r4596 r4683  
    5858        wi_socket_t                                                     *socket; 
    5959        wi_p7_socket_t                                          *p7_socket; 
     60        wi_p7_message_t                                         *message; 
    6061         
    6162        wi_lock_t                                                       *flag_lock; 
    6263        wd_uid_t                                                        uid; 
    6364        wd_client_state_t                                       state; 
    64         wd_icon_t                                                      icon; 
     65        wi_data_t                                                      *icon; 
    6566        wi_boolean_t                                            idle; 
    6667        wi_boolean_t                                            admin; 
     
    7576        wi_string_t                                                     *version; 
    7677        wi_string_t                                                     *status; 
    77          
    78         wi_string_t                                                     *image; 
    7978         
    8079        wi_time_interval_t                                      login_time; 
  • wired/branches/p7/wired/commands.c

    r4675 r4683  
    222222        wd_client_t                     *client = argument; 
    223223        wi_string_t                     *string; 
    224         wi_p7_message_t         *message; 
    225224        wi_socket_state_t       state; 
    226225        wi_uinteger_t           i = 0; 
     
    253252                } 
    254253 
    255 /*            wd_client_lock_socket(client); 
     254              wd_client_lock_socket(client); 
    256255                string = wi_socket_read_to_string(client->socket, 0.0, WI_STR(WD_MESSAGE_SEPARATOR_STR)); 
    257256                wd_client_unlock_socket(client); 
     
    264263                } 
    265264 
    266                 wd_parse_command(string);*/ 
    267                  
    268                 wd_client_lock_socket(client); 
    269                 message = wi_p7_socket_read_message(client->p7_socket, 0.0); 
    270                 wd_client_unlock_socket(client); 
    271                  
    272                 if(!message) { 
    273                         wi_log_info(WI_STR("Could not read from %@: %m"), client->ip); 
    274                          
    275                         break; 
    276                 } 
    277                  
    278                 wi_log_info(WI_STR("read %@"), message); 
     265                wd_parse_command(string); 
    279266                 
    280267                if(++i % 10 == 0) 
     
    941928 
    942929static void wd_cmd_icon(wi_array_t *arguments) { 
    943       wd_client_t             *client = wd_client(); 
     930/*    wd_client_t             *client = wd_client(); 
    944931        wd_icon_t               icon; 
    945932 
    946933        icon = wi_string_uint32(WI_ARRAY(arguments, 0)); 
    947934 
    948         /* set icon if changed */ 
    949935        if(client->icon != icon) { 
    950936                client->icon = icon; 
     
    954940        } 
    955941 
    956         /* copy custom icon if changed */ 
    957942        if(wi_array_count(arguments) > 1) { 
    958943                wi_release(client->image); 
     
    964949                                                 client->image); 
    965950                } 
    966         } 
     951        }*/ 
    967952} 
    968953 
     
    10351020        idle    = wi_date_iso8601_string(wi_date_with_time_interval(peer->idle_time)); 
    10361021 
    1037       wd_reply(308, WI_STR("%u%c%u%c%u%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@"), 
     1022/*    wd_reply(308, WI_STR("%u%c%u%c%u%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@%c%u%c%#@%c%#@%c%#@%c%#@%c%#@%c%#@"), 
    10381023                         peer->uid,                                                             WD_FIELD_SEPARATOR, 
    10391024                         peer->idle,                                                    WD_FIELD_SEPARATOR, 
     
    10521037                         uploads,                                                               WD_FIELD_SEPARATOR, 
    10531038                         peer->status,                                                  WD_FIELD_SEPARATOR, 
    1054                          peer->image); 
     1039                         peer->image);*/ 
    10551040} 
    10561041 
  • wired/branches/p7/wired/main.c

    r4568 r4683  
    4343#include "files.h" 
    4444#include "main.h" 
     45#include "messages.h" 
    4546#include "news.h" 
    4647#include "server.h" 
     
    117118 
    118119                        case 'D': 
    119                                 wd_daemonize =false; 
     120                                wd_daemonize = false; 
    120121                                wi_log_stderr = true; 
    121122                                break; 
     
    189190        wd_clients_init(); 
    190191        wd_files_init(); 
     192        wd_messages_init(); 
    191193        wd_news_init(); 
    192194        wd_tempbans_init(); 
  • wired/branches/p7/wired/server.c

    r4675 r4683  
    6666static wi_socket_context_t                      *wd_transfer_socket_context; 
    6767 
    68 static wi_p7_spec_t                                     *wd_p7_spec; 
    6968static wi_rsa_t                                         *wd_rsa; 
     69 
     70wi_p7_spec_t                                            *wd_p7_spec; 
    7071 
    7172wi_string_t                                                     *wd_banner; 
     
    190191                if(!wd_p7_spec) 
    191192                        wi_log_err(WI_STR("Could not load wired.xml: %m")); 
    192                  
    193                 wi_p7_spec_t *p7_spec = wi_p7_spec_init_with_file(wi_p7_spec_alloc(), WI_STR("wired2.xml")); 
    194                  
    195                 wi_log_info(WI_STR("compatible = %d"), wi_p7_spec_is_compatible_with_spec(wd_p7_spec, p7_spec)); 
    196                  
    197                 wi_release(p7_spec); 
    198193        } 
    199194 
     
    262257void wd_ssl_init(void) { 
    263258        wd_rsa = wi_rsa_init_with_bits(wi_rsa_alloc(), 1024); 
    264          
    265 /*      wi_p7_cipher_t *cipher = wi_p7_cipher_init_with_random_key(wi_p7_cipher_alloc(), WI_P7_CIPHER_AES_256); 
    266          
    267         wi_log_info(WI_STR("cipher = %@"), cipher); 
    268          
    269         if(!cipher) 
    270                 wi_log_err(WI_STR("%m")); 
    271          
    272         wi_string_t *string0 = WI_STR("a"); 
    273  
    274         wi_log_info(WI_STR("string0 = %@"), string0); 
    275  
    276         wi_data_t *data0 = wi_string_data(string0); 
    277  
    278         wi_log_info(WI_STR("data0 = %@"), data0); 
    279  
    280         wi_data_t *data1 = wi_p7_cipher_encrypt_data(cipher, data0); 
    281          
    282         wi_log_info(WI_STR("data1 = %@"), data1); 
    283  
    284         wi_data_t *data2 = wi_p7_cipher_decrypt_data(cipher, data1); 
    285          
    286         if(!data2) 
    287                 wi_log_err(WI_STR("%m")); 
    288          
    289         wi_log_info(WI_STR("data2 = %@"), data2); 
    290          
    291         wi_string_t *string1 = wi_string_with_data(data2); 
    292          
    293         wi_log_info(WI_STR("string1 = %@"), string1); 
    294          
    295         wi_release(cipher);*/ 
    296259} 
    297260 
     
    464427#pragma mark - 
    465428 
     429void wd_reply_message(wd_client_t *client, wi_p7_message_t *message) { 
     430        wi_p7_uint32_t  transaction; 
     431         
     432        if(message != client->message) { 
     433                if(wi_p7_message_get_uint32_for_name(client->message, &transaction, WI_STR("wired.transaction"))) 
     434                        wi_p7_message_set_uint32_for_name(message, transaction, WI_STR("wired.transaction")); 
     435        } 
     436         
     437        wd_client_lock_socket(client); 
     438        wi_p7_socket_write_message(client->p7_socket, 0.0, message); 
     439        wd_client_unlock_socket(client); 
     440} 
     441 
     442 
     443 
     444void wd_reply_error2(wd_client_t *client, wi_p7_enum_t error) { 
     445        wi_p7_message_t         *message; 
     446         
     447        message = wi_p7_message_with_name(WI_STR("wired.error"), client->p7_socket); 
     448        wi_p7_message_set_enum_for_name(message, error, WI_STR("wired.error.code")); 
     449         
     450        wd_reply_message(client, message); 
     451} 
     452 
     453 
     454 
     455void wd_broadcast_message(wd_chat_t *chat, wi_p7_message_t *message) { 
     456        wi_enumerator_t *enumerator; 
     457        wd_client_t             *client; 
     458 
     459        wi_array_rdlock(chat->clients); 
     460 
     461        enumerator = wi_array_data_enumerator(chat->clients); 
     462         
     463        while((client = wi_enumerator_next_data(enumerator))) { 
     464                if(client->state == WD_CLIENT_STATE_LOGGED_IN) 
     465                        wd_reply_message(client, message); 
     466        } 
     467         
     468        wi_array_unlock(chat->clients); 
     469} 
     470 
     471 
     472 
    466473void wd_reply(uint32_t n, wi_string_t *fmt, ...) { 
    467474        wd_client_t             *client = wd_client(); 
  • wired/branches/p7/wired/server.h

    r4508 r4683  
    5151void                                                            wd_ssl_init(void); 
    5252 
     53void                                                            wd_reply_message(wd_client_t *, wi_p7_message_t *); 
     54void                                                            wd_reply_error2(wd_client_t *, wi_p7_enum_t); 
     55void                                                            wd_broadcast_message(wd_chat_t *, wi_p7_message_t *); 
    5356void                                                            wd_reply(uint32_t, wi_string_t *, ...); 
    5457void                                                            wd_reply_error(void); 
     
    5760 
    5861 
     62extern wi_p7_spec_t                                     *wd_p7_spec; 
     63 
    5964extern wi_string_t                                      *wd_banner; 
    6065