- Timestamp:
- Mar 3, 2007 2:16:36 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjstun-srv-test/server_main.c
r1034 r1037 62 62 pj_thread_t *threads[16]; 63 63 64 64 65 } server; 65 66 67 static struct options 68 { 69 char *realm; 70 char *user_name; 71 char *password; 72 char *nonce; 73 pj_bool_t use_fingerprint; 74 } o; 66 75 67 76 static pj_status_t server_perror(const char *sender, const char *title, … … 132 141 133 142 /* Create MAPPED-ADDRESS attribute */ 134 status = pj_stun_msg_add_ generic_ip_addr_attr(tdata->pool, tdata->msg,135 136 137 143 status = pj_stun_msg_add_ip_addr_attr(tdata->pool, tdata->msg, 144 PJ_STUN_ATTR_MAPPED_ADDR, 145 PJ_FALSE, 146 src_addr, src_addr_len); 138 147 if (status != PJ_SUCCESS) { 139 148 server_perror(THIS_FILE, "Error creating response", status); … … 145 154 if (msg->hdr.magic == PJ_STUN_MAGIC) { 146 155 status = 147 pj_stun_msg_add_ generic_ip_addr_attr(tdata->pool, tdata->msg,148 149 150 156 pj_stun_msg_add_ip_addr_attr(tdata->pool, tdata->msg, 157 PJ_STUN_ATTR_XOR_MAPPED_ADDRESS, 158 PJ_TRUE, 159 src_addr, src_addr_len); 151 160 if (status != PJ_SUCCESS) { 152 161 server_perror(THIS_FILE, "Error creating response", status); … … 157 166 158 167 /* Send */ 159 status = pj_stun_session_send_msg(sess, PJ_ STUN_CACHE_RESPONSE,168 status = pj_stun_session_send_msg(sess, PJ_TRUE, 160 169 src_addr, src_addr_len, tdata); 161 170 return status; … … 264 273 sess_cb.on_rx_request = &on_rx_request; 265 274 status = pj_stun_session_create(server.endpt, "session", 266 &sess_cb, &svc->sess); 275 &sess_cb, 276 o.use_fingerprint!=0, 277 &svc->sess); 267 278 if (status != PJ_SUCCESS) 268 279 goto on_error; 269 280 270 281 pj_stun_session_set_user_data(svc->sess, (void*)svc); 282 283 if (o.user_name) { 284 pj_stun_auth_cred cred; 285 286 pj_bzero(&cred, sizeof(cred)); 287 288 cred.type = PJ_STUN_AUTH_CRED_STATIC; 289 cred.data.static_cred.realm = pj_str(o.realm); 290 cred.data.static_cred.username = pj_str(o.user_name); 291 cred.data.static_cred.data_type = 0; 292 cred.data.static_cred.data = pj_str(o.password); 293 cred.data.static_cred.nonce = pj_str(o.nonce); 294 295 pj_stun_session_set_credential(svc->sess, &cred); 296 puts("Session credential set"); 297 } else { 298 puts("Credential not set"); 299 } 271 300 272 301 pj_bzero(&service_callback, sizeof(service_callback)); … … 438 467 439 468 440 int main() 441 { 469 static void usage(void) 470 { 471 puts("Usage: pjstun_srv_test [OPTIONS]"); 472 puts(""); 473 puts("where OPTIONS:"); 474 puts(" --realm, -r Set realm of the credential"); 475 puts(" --username, -u Set username of the credential"); 476 puts(" --password, -p Set password of the credential"); 477 puts(" --nonce, -N Set NONCE"); 478 puts(" --fingerprint, -F Use fingerprint for outgoing requests"); 479 puts(" --help, -h"); 480 } 481 482 483 int main(int argc, char *argv[]) 484 { 485 struct pj_getopt_option long_options[] = { 486 { "realm", 1, 0, 'r'}, 487 { "username", 1, 0, 'u'}, 488 { "password", 1, 0, 'p'}, 489 { "nonce", 1, 0, 'N'}, 490 { "fingerprint",0, 0, 'F'}, 491 { "help", 0, 0, 'h'} 492 }; 493 int c, opt_id; 494 495 while((c=pj_getopt_long(argc,argv, "r:u:p:hF", long_options, &opt_id))!=-1) { 496 switch (c) { 497 case 'r': 498 o.realm = pj_optarg; 499 break; 500 case 'u': 501 o.user_name = pj_optarg; 502 break; 503 case 'p': 504 o.password = pj_optarg; 505 break; 506 case 'N': 507 o.nonce = pj_optarg; 508 break; 509 case 'h': 510 usage(); 511 return 0; 512 case 'F': 513 o.use_fingerprint = PJ_TRUE; 514 break; 515 default: 516 printf("Argument \"%s\" is not valid. Use -h to see help", 517 argv[pj_optind]); 518 return 1; 519 } 520 } 521 522 if (pj_optind != argc) { 523 puts("Error: invalid arguments"); 524 return 1; 525 } 526 527 442 528 if (server_init()) { 443 529 server_destroy();
Note: See TracChangeset
for help on using the changeset viewer.