Ignore:
Timestamp:
Mar 3, 2007 2:16:36 AM (17 years ago)
Author:
bennylp
Message:

Committed today's work on STUN

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib-util/src/pjstun-client/client_main.c

    r1030 r1037  
    3030    pj_timer_heap_t     *th; 
    3131    pj_stun_session     *sess; 
    32     unsigned             sess_options; 
    3332    pj_sock_t            sock; 
    3433    pj_thread_t         *thread; 
     
    4645    char    *user_name; 
    4746    char    *password; 
     47    char    *nonce; 
    4848    pj_bool_t use_fingerprint; 
    4949} o; 
     
    181181    stun_cb.on_request_complete = &on_request_complete; 
    182182 
    183     status = pj_stun_session_create(g.endpt, NULL, &stun_cb, &g.sess); 
    184     pj_assert(status == PJ_SUCCESS); 
    185  
    186     if (o.realm) { 
    187         pj_str_t r, u, p; 
    188  
    189         if (o.user_name == NULL) { 
    190             printf("error: username must be specified\n"); 
    191             return PJ_EINVAL; 
    192         } 
    193         if (o.password == NULL) 
    194             o.password = ""; 
    195         g.sess_options = PJ_STUN_USE_LONG_TERM_CRED; 
    196         pj_stun_session_set_long_term_credential(g.sess, pj_cstr(&r, o.realm), 
    197                                                  pj_cstr(&u, o.user_name), 
    198                                                  pj_cstr(&p, o.password)); 
    199         puts("Using long term credential"); 
    200     } else if (o.user_name) { 
    201         pj_str_t u, p; 
    202  
    203         if (o.password == NULL) 
    204             o.password = ""; 
    205         g.sess_options = PJ_STUN_USE_SHORT_TERM_CRED; 
    206         pj_stun_session_set_short_term_credential(g.sess,  
    207                                                   pj_cstr(&u, o.user_name), 
    208                                                   pj_cstr(&p, o.password)); 
    209         puts("Using short term credential"); 
     183    status = pj_stun_session_create(g.endpt, NULL, &stun_cb,  
     184                                    o.use_fingerprint!=0, &g.sess); 
     185    pj_assert(status == PJ_SUCCESS); 
     186 
     187    if (o.user_name) { 
     188        pj_stun_auth_cred cred; 
     189 
     190        pj_bzero(&cred, sizeof(cred)); 
     191 
     192        cred.type = PJ_STUN_AUTH_CRED_STATIC; 
     193        cred.data.static_cred.realm = pj_str(o.realm); 
     194        cred.data.static_cred.username = pj_str(o.user_name); 
     195        cred.data.static_cred.data_type = 0; 
     196        cred.data.static_cred.data = pj_str(o.password); 
     197        cred.data.static_cred.nonce = pj_str(o.nonce); 
     198 
     199        pj_stun_session_set_credential(g.sess, &cred); 
     200        puts("Session credential set"); 
    210201    } else { 
    211202        puts("Credential not set"); 
    212203    } 
    213  
    214     if (o.use_fingerprint) 
    215         g.sess_options |= PJ_STUN_USE_FINGERPRINT; 
    216204 
    217205    status = pj_thread_create(g.pool, "stun", &worker_thread, NULL,  
     
    276264                pj_assert(rc == PJ_SUCCESS); 
    277265 
    278                 rc = pj_stun_session_send_msg(g.sess, g.sess_options,  
     266                rc = pj_stun_session_send_msg(g.sess, PJ_FALSE,  
    279267                                              &g.dst_addr, sizeof(g.dst_addr), 
    280268                                              tdata); 
     
    303291    puts(" --username, -u    Set username of the credential"); 
    304292    puts(" --password, -p    Set password of the credential"); 
     293    puts(" --nonce, -N       Set NONCE");    
    305294    puts(" --fingerprint, -F Use fingerprint for outgoing requests"); 
    306295    puts(" --help, -h"); 
     
    313302        { "username",   1, 0, 'u'}, 
    314303        { "password",   1, 0, 'p'}, 
     304        { "nonce",      1, 0, 'N'}, 
    315305        { "fingerprint",0, 0, 'F'}, 
    316306        { "help",       0, 0, 'h'} 
     
    331321            o.password = pj_optarg; 
    332322            break; 
     323        case 'N': 
     324            o.nonce = pj_optarg; 
     325            break; 
    333326        case 'h': 
    334327            usage(); 
Note: See TracChangeset for help on using the changeset viewer.