pj_status_t create_stun_config(pj_pool_t *pool, pj_stun_config *stun_cfg) { pj_ioqueue_t *ioqueue; pj_timer_heap_t *timer_heap; pj_lock_t *lock; pj_status_t status; status = pj_ioqueue_create(pool, 64, &ioqueue); if (status != PJ_SUCCESS) { app_perror(" pj_ioqueue_create()", status); return status; } status = pj_timer_heap_create(pool, 256, &timer_heap); if (status != PJ_SUCCESS) { app_perror(" pj_timer_heap_create()", status); pj_ioqueue_destroy(ioqueue); return status; } pj_lock_create_recursive_mutex(pool, NULL, &lock); pj_timer_heap_set_lock(timer_heap, lock, PJ_TRUE); pj_stun_config_init(stun_cfg, mem, 0, ioqueue, timer_heap); return PJ_SUCCESS; }
PJStunTurn::PJStunTurn() { if (PJ_SUCCESS != pjnath_init()) { g_warning("cannot init pjnath"); return; } pj_ice_strans_cfg_default(&ice_cfg_); pj_timer_heap_create(PJSIP::this_->pool_, 100, &ice_cfg_.stun_cfg.timer_heap); pj_ioqueue_create(PJSIP::this_->pool_, 512, &ice_cfg_.stun_cfg.ioqueue); ice_cfg_.stun_cfg.pf = PJSIP::this_->pool_->factory; if (PJ_SUCCESS != pj_thread_create(PJSIP::this_->pool_, "switcherSIP", &worker_thread, this, 0, 0, &thread_)) { g_warning("STUN TURN thread creating failed"); return; } ice_cfg_.af = pj_AF_INET(); ice_cfg_.stun.cfg.max_pkt_size = 8192; ice_cfg_.turn.cfg.max_pkt_size = 8192; ice_cfg_.opt.aggressive = PJ_FALSE; ice_cfg_.stun_cfg.rto_msec = 500; // set stun/turn config SIPPlugin::this_->install_method( "Set STUN/TURN parameters", // long name "set_stun_turn", // name "Set STUN/TURN configuration", // description "the server(s) are reachable", // return description Method::make_arg_description("STUN server address", // long name "stun", // name "string", // description "TURN server address", "turn", "string", "TURN user name", "turn_user", "string", "TURN user password", "turn_pass", "string", nullptr), (Method::method_ptr)&set_stun_turn, G_TYPE_BOOLEAN, Method::make_arg_type_description( G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, nullptr), this); }
int stun_sock_test(void) { struct pjlib_state pjlib_state; pj_stun_config stun_cfg; pj_ioqueue_t *ioqueue = NULL; pj_timer_heap_t *timer_heap = NULL; pj_pool_t *pool = NULL; pj_status_t status; int ret = 0; pool = pj_pool_create(mem, NULL, 512, 512, NULL); status = pj_ioqueue_create(pool, 12, &ioqueue); if (status != PJ_SUCCESS) { app_perror(" pj_ioqueue_create()", status); ret = -4; goto on_return; } status = pj_timer_heap_create(pool, 100, &timer_heap); if (status != PJ_SUCCESS) { app_perror(" pj_timer_heap_create()", status); ret = -8; goto on_return; } pj_stun_config_init(&stun_cfg, mem, 0, ioqueue, timer_heap); DO_TEST(timeout_test(&stun_cfg, PJ_FALSE)); DO_TEST(timeout_test(&stun_cfg, PJ_TRUE)); DO_TEST(missing_attr_test(&stun_cfg, PJ_FALSE)); DO_TEST(missing_attr_test(&stun_cfg, PJ_TRUE)); DO_TEST(keep_alive_test(&stun_cfg)); on_return: if (timer_heap) pj_timer_heap_destroy(timer_heap); if (ioqueue) pj_ioqueue_destroy(ioqueue); if (pool) pj_pool_release(pool); return ret; }
pj_status_t getURL(const char *curl) { pj_str_t url; pj_http_req_callback hcb; pj_status_t status; pj_bzero(&hcb, sizeof(hcb)); hcb.on_complete = &on_complete; hcb.on_data_read = &on_data_read; hcb.on_send_data = &on_send_data; hcb.on_response = &on_response; /* Create pool, timer, and ioqueue */ pool = pj_pool_create(mem, NULL, 8192, 4096, NULL); if (pj_timer_heap_create(pool, 16, &timer_heap)) return -31; if (pj_ioqueue_create(pool, 16, &ioqueue)) return -32; pj_strdup2(pool, &url, curl); if ((status = pj_http_req_create(pool, &url, timer_heap, ioqueue, NULL, &hcb, &http_req)) != PJ_SUCCESS) return status; if ((status = pj_http_req_start(http_req)) != PJ_SUCCESS) return status; while (pj_http_req_is_running(http_req)) { pj_time_val delay = {0, 50}; pj_ioqueue_poll(ioqueue, &delay); pj_timer_heap_poll(timer_heap, NULL); } pj_http_req_destroy(http_req); pj_ioqueue_destroy(ioqueue); pj_timer_heap_destroy(timer_heap); pj_pool_release(pool); return PJ_SUCCESS; }
// // Create proactor. // pj_status_t create( Pj_Pool *pool, pj_size_t max_fd, pj_size_t timer_entry_count) { pj_status_t status; destroy(); status = pj_ioqueue_create(pool->pool_(), max_fd, &ioq_); if (status != PJ_SUCCESS) return status; status = pj_timer_heap_create(pool->pool_(), timer_entry_count, &th_); if (status != PJ_SUCCESS) { pj_ioqueue_destroy(ioq_); ioq_ = NULL; return NULL; } return status; }
pj_status_t create_stun_config(pj_pool_t *pool, pj_stun_config *stun_cfg) { pj_ioqueue_t *ioqueue; pj_timer_heap_t *timer_heap; pj_status_t status; status = pj_ioqueue_create(pool, 64, &ioqueue); if (status != PJ_SUCCESS) { app_perror(" pj_ioqueue_create()", status); return status; } status = pj_timer_heap_create(pool, 256, &timer_heap); if (status != PJ_SUCCESS) { app_perror(" pj_timer_heap_create()", status); pj_ioqueue_destroy(ioqueue); return status; } pj_stun_config_init(stun_cfg, mem, 0, ioqueue, timer_heap); return PJ_SUCCESS; }
/* * Create the resolver. */ PJ_DEF(pj_status_t) pj_dns_resolver_create( pj_pool_factory *pf, const char *name, unsigned options, pj_timer_heap_t *timer, pj_ioqueue_t *ioqueue, pj_dns_resolver **p_resolver) { pj_pool_t *pool; pj_dns_resolver *resv; pj_status_t status; /* Sanity check */ PJ_ASSERT_RETURN(pf && p_resolver, PJ_EINVAL); if (name == NULL) name = THIS_FILE; /* Create and initialize resolver instance */ pool = pj_pool_create(pf, name, 4000, 4000, NULL); if (!pool) return PJ_ENOMEM; /* Create pool and name */ resv = PJ_POOL_ZALLOC_T(pool, struct pj_dns_resolver); resv->pool = pool; resv->udp_sock = PJ_INVALID_SOCKET; pj_strdup2_with_null(pool, &resv->name, name); /* Create the mutex */ status = pj_mutex_create_recursive(pool, name, &resv->mutex); if (status != PJ_SUCCESS) goto on_error; /* Timer, ioqueue, and settings */ resv->timer = timer; resv->ioqueue = ioqueue; resv->last_id = 1; pj_dns_settings_default(&resv->settings); resv->settings.options = options; /* Create the timer heap if one is not specified */ if (resv->timer == NULL) { status = pj_timer_heap_create(pool, TIMER_SIZE, &resv->timer); if (status != PJ_SUCCESS) goto on_error; } /* Create the ioqueue if one is not specified */ if (resv->ioqueue == NULL) { status = pj_ioqueue_create(pool, MAX_FD, &resv->ioqueue); if (status != PJ_SUCCESS) goto on_error; } /* Response cache hash table */ resv->hrescache = pj_hash_create(pool, RES_HASH_TABLE_SIZE); /* Query hash table and free list. */ resv->hquerybyid = pj_hash_create(pool, Q_HASH_TABLE_SIZE); resv->hquerybyres = pj_hash_create(pool, Q_HASH_TABLE_SIZE); pj_list_init(&resv->query_free_nodes); /* Initialize the UDP socket */ status = init_sock(resv); if (status != PJ_SUCCESS) goto on_error; /* Looks like everything is okay */ *p_resolver = resv; return PJ_SUCCESS; on_error: pj_dns_resolver_destroy(resv, PJ_FALSE); return status; }
/* * Create the ZRTP transport. */ PJ_DEF(pj_status_t) pjmedia_transport_zrtp_create(pjmedia_endpt *endpt, const char *name, pjmedia_transport *transport, pjmedia_transport **p_tp, pj_bool_t close_slave) { pj_pool_t *pool; struct tp_zrtp *zrtp; pj_status_t rc; if (name == NULL) name = "tzrtp%p"; /* Create the pool and initialize the adapter structure */ pool = pjmedia_endpt_create_pool(endpt, name, 5*1024, 512); zrtp = PJ_POOL_ZALLOC_T(pool, struct tp_zrtp); zrtp->pool = pool; pj_ansi_strncpy(zrtp->base.name, pool->obj_name, sizeof(zrtp->base.name)); zrtp->base.type = (pjmedia_transport_type) (PJMEDIA_TRANSPORT_TYPE_USER + 2); zrtp->base.op = &tp_zrtp_op; #ifndef DYNAMIC_TIMER if (timer_pool == NULL) { timer_pool = pjmedia_endpt_create_pool(endpt, "zrtp_timer", 256, 256); rc = timer_initialize(); if (rc != PJ_SUCCESS) { pj_pool_release(timer_pool); pj_pool_release(zrtp->pool); return rc; } } #else zrtp->timer_heap = NULL; zrtp->timer_pool = pjmedia_endpt_create_pool(endpt, "zrtp_timer", 256, 256); rc = pj_timer_heap_create(zrtp->timer_pool, 4, &zrtp->timer_heap); if (rc != PJ_SUCCESS) { pj_pool_release(zrtp->timer_pool); pj_pool_release(zrtp->pool); return rc; } #endif /* Create the empty wrapper */ zrtp->zrtpCtx = zrtp_CreateWrapper(); /* Initialize standard values */ zrtp->clientIdString = clientId; /* Set standard name */ zrtp->zrtpSeq = 1; /* TODO: randomize */ rc = pj_mutex_create_simple(zrtp->pool, "zrtp", &zrtp->zrtpMutex); zrtp->zrtpBuffer = pj_pool_zalloc(pool, MAX_ZRTP_SIZE); zrtp->sendBuffer = pj_pool_zalloc(pool, MAX_RTP_BUFFER_LEN); zrtp->sendBufferCtrl = pj_pool_zalloc(pool, MAX_RTCP_BUFFER_LEN); zrtp->slave_tp = transport; zrtp->close_slave = close_slave; zrtp->mitmMode = PJ_FALSE; /* Done */ zrtp->refcount++; *p_tp = &zrtp->base; return PJ_SUCCESS; }
static int timer_initialize() { pj_status_t rc; pj_mutex_t* temp_mutex; rc = pj_mutex_create_simple(timer_pool, "zrtp_timer", &temp_mutex); if (rc != PJ_SUCCESS) { return rc; } pj_enter_critical_section(); if (timer_mutex == NULL) timer_mutex = temp_mutex; else pj_mutex_destroy(temp_mutex); pj_leave_critical_section(); pj_mutex_lock(timer_mutex); if (timer_initialized) { pj_mutex_unlock(timer_mutex); return PJ_SUCCESS; } rc = pj_timer_heap_create(timer_pool, 4, &timer); if (rc != PJ_SUCCESS) { goto ERROR; } rc = pj_sem_create(timer_pool, "zrtp_timer", 0, 1, &timer_sem); if (rc != PJ_SUCCESS) { goto ERROR; } rc = pj_thread_create(timer_pool, "zrtp_timer", &timer_thread_run, NULL, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &thread_run); if (rc != PJ_SUCCESS) { goto ERROR; } timer_initialized = 1; pj_mutex_unlock(timer_mutex); return PJ_SUCCESS; ERROR: if (timer != NULL) { pj_timer_heap_destroy(timer); timer = NULL; } if (timer_sem != NULL) { pj_sem_destroy(timer_sem); timer_sem = NULL; } if (timer_mutex != NULL) { pj_mutex_unlock(timer_mutex); pj_mutex_destroy(timer_mutex); timer_mutex = NULL; } return rc; }
pj_status_t natclient_init(ice_trans_t *icetrans, ice_option_t opt) { pj_status_t status; /* Initialize the libraries before anything else */ CHECK( pj_init(), icetrans ); CHECK( pjlib_util_init(), icetrans ); CHECK( pjnath_init(), icetrans ); #if 0 //FIXME: consider if we need to log if (natclient.opt.log_file) { icetrans->log_fhnd = fopen(natclient.opt.log_file, "a"); pj_log_set_log_func(&log_func); } #endif pj_caching_pool_init(&icetrans->cp, NULL, 0); /* Init our ICE settings with null values */ pj_ice_strans_cfg_default(&icetrans->ice_cfg); icetrans->ice_cfg.stun_cfg.pf = &icetrans->cp.factory; /* Create application memory pool */ icetrans->pool = pj_pool_create(&icetrans->cp.factory, "natclient", 512, 512, NULL); /* Create timer heap for timer stuff */ CHECK( pj_timer_heap_create(icetrans->pool, 100, &icetrans->ice_cfg.stun_cfg.timer_heap), icetrans ); /* and create ioqueue for network I/O stuff */ CHECK( pj_ioqueue_create(icetrans->pool, 16, &icetrans->ice_cfg.stun_cfg.ioqueue), icetrans ); /* something must poll the timer heap and ioqueue, * unless we're on Symbian where the timer heap and ioqueue run * on themselves. */ CHECK( pj_thread_create(icetrans->pool, "natclient", &natclient_worker_thread, icetrans, 0, 0, &icetrans->thread), icetrans ); icetrans->ice_cfg.af = pj_AF_INET(); /* Create DNS resolver if nameserver is set */ if (opt.ns.slen) { CHECK( pj_dns_resolver_create(&icetrans->cp.factory, "resolver", 0, icetrans->ice_cfg.stun_cfg.timer_heap, icetrans->ice_cfg.stun_cfg.ioqueue, &icetrans->ice_cfg.resolver), icetrans ); CHECK( pj_dns_resolver_set_ns(icetrans->ice_cfg.resolver, 1, &opt.ns, NULL) , icetrans); } /* -= Start initializing ICE stream transport config =- */ /* Maximum number of host candidates */ if (opt.max_host != -1) icetrans->ice_cfg.stun.max_host_cands = opt.max_host; /* Nomination strategy */ if (opt.regular) icetrans->ice_cfg.opt.aggressive = PJ_FALSE; else icetrans->ice_cfg.opt.aggressive = PJ_TRUE; /* Configure STUN/srflx candidate resolution */ if (opt.stun_srv.slen) { char *pos; /* Command line option may contain port number */ if ((pos=pj_strchr(&opt.stun_srv, ':')) != NULL) { icetrans->ice_cfg.stun.server.ptr = opt.stun_srv.ptr; icetrans->ice_cfg.stun.server.slen = (pos - opt.stun_srv.ptr); icetrans->ice_cfg.stun.port = (pj_uint16_t)atoi(pos+1); } else { icetrans->ice_cfg.stun.server = opt.stun_srv; icetrans->ice_cfg.stun.port = PJ_STUN_PORT; } /* For this demo app, configure longer STUN keep-alive time * so that it does't clutter the screen output. */ icetrans->ice_cfg.stun.cfg.ka_interval = KA_INTERVAL; } /* Configure TURN candidate */ if (opt.turn_srv.slen) { char *pos; /* Command line option may contain port number */ if ((pos=pj_strchr(&opt.turn_srv, ':')) != NULL) { icetrans->ice_cfg.turn.server.ptr = opt.turn_srv.ptr; icetrans->ice_cfg.turn.server.slen = (pos - opt.turn_srv.ptr); icetrans->ice_cfg.turn.port = (pj_uint16_t)atoi(pos+1); } else { icetrans->ice_cfg.turn.server = opt.turn_srv; icetrans->ice_cfg.turn.port = PJ_STUN_PORT; } /* TURN credential */ icetrans->ice_cfg.turn.auth_cred.type = PJ_STUN_AUTH_CRED_STATIC; icetrans->ice_cfg.turn.auth_cred.data.static_cred.username = opt.turn_username; icetrans->ice_cfg.turn.auth_cred.data.static_cred.data_type = PJ_STUN_PASSWD_PLAIN; icetrans->ice_cfg.turn.auth_cred.data.static_cred.data = opt.turn_password; /* Connection type to TURN server */ if (opt.turn_tcp) icetrans->ice_cfg.turn.conn_type = PJ_TURN_TP_TCP; else icetrans->ice_cfg.turn.conn_type = PJ_TURN_TP_UDP; /* For this demo app, configure longer keep-alive time * so that it does't clutter the screen output. */ icetrans->ice_cfg.turn.alloc_param.ka_interval = KA_INTERVAL; } /* -= That's it for now, initialization is complete =- */ return PJ_SUCCESS; }
int krx_ice_init(krx_ice* k) { pj_status_t r; if(!k) { return -1; } /* initialize pj */ r = pj_init(); CHECK_PJ_STATUS(r, "Error: cannot initialize pj.\n", -2); r = pjlib_util_init(); CHECK_PJ_STATUS(r, "Error: cannot initialize pj-util.\n", -3); r = pjnath_init(); CHECK_PJ_STATUS(r, "Error: cannot initialize pjnath.\n", -4); /* create memory pool */ pj_caching_pool_init(&k->caching_pool, NULL, 0); /* initialize the ice settings */ pj_ice_strans_cfg_default(&k->ice_cfg); /* create the pool */ k->pool = pj_pool_create(&k->caching_pool.factory, "krx_ice_pjnath", 512, 512, NULL); /* 512 = initial size, 512 = incremental size */ if(!k->pool) { printf("Error: cannot create pool.\n"); return -5; } k->ice_cfg.stun_cfg.pf = &k->caching_pool.factory; /* create heap for timers */ r = pj_timer_heap_create(k->pool, 100, &k->ice_cfg.stun_cfg.timer_heap); CHECK_PJ_STATUS(r, "Error: cannot create timer heap.\n", -6); /* create ioqueue for network I/O */ r = pj_ioqueue_create(k->pool, 16, &k->ice_cfg.stun_cfg.ioqueue); CHECK_PJ_STATUS(r, "Error: cannot create ioqueue.\n", -7); /* create managing thread */ r = pj_thread_create(k->pool, "krx_ice_pjnath", &krx_ice_worker_thread, k, 0, 0, &k->thread); CHECK_PJ_STATUS(r, "Error: cannot create managing thread.", -8); k->ice_cfg.af = pj_AF_INET(); /* @todo(roxlu): we could add a nameserver */ k->ice_cfg.opt.aggressive = PJ_FALSE; /* @todo(roxlu): read up the aggressive flag in ice_cfg. */ /* default configs */ k->max_hosts = 4; k->ncomp = 4; /* initialize the callbacks */ pj_bzero(&k->ice_cb, sizeof(k->ice_cb)); k->ice_cb.on_rx_data = krx_ice_on_rx_data; k->ice_cb.on_ice_complete = krx_ice_on_complete; /* sdp info */ k->ice_ufrag = NULL; k->ice_pwd = NULL; return 0; }
/* * Create the resolver. */ PJ_DEF(pj_status_t) pj_dns_resolver_create( pj_pool_factory *pf, const char *name, unsigned options, pj_timer_heap_t *timer, pj_ioqueue_t *ioqueue, pj_dns_resolver **p_resolver) { pj_pool_t *pool; pj_dns_resolver *resv; pj_ioqueue_callback socket_cb; pj_status_t status; /* Sanity check */ PJ_ASSERT_RETURN(pf && p_resolver, PJ_EINVAL); if (name == NULL) name = THIS_FILE; /* Create and initialize resolver instance */ pool = pj_pool_create(pf, name, 4000, 4000, NULL); if (!pool) return PJ_ENOMEM; /* Create pool and name */ resv = PJ_POOL_ZALLOC_T(pool, struct pj_dns_resolver); resv->pool = pool; resv->udp_sock = PJ_INVALID_SOCKET; pj_strdup2_with_null(pool, &resv->name, name); /* Create the mutex */ status = pj_mutex_create_recursive(pool, name, &resv->mutex); if (status != PJ_SUCCESS) goto on_error; /* Timer, ioqueue, and settings */ resv->timer = timer; resv->ioqueue = ioqueue; resv->last_id = 1; pj_dns_settings_default(&resv->settings); resv->settings.options = options; /* Create the timer heap if one is not specified */ if (resv->timer == NULL) { status = pj_timer_heap_create(pool, TIMER_SIZE, &resv->timer); if (status != PJ_SUCCESS) goto on_error; } /* Create the ioqueue if one is not specified */ if (resv->ioqueue == NULL) { status = pj_ioqueue_create(pool, MAX_FD, &resv->ioqueue); if (status != PJ_SUCCESS) goto on_error; } /* Response cache hash table */ resv->hrescache = pj_hash_create(pool, RES_HASH_TABLE_SIZE); /* Query hash table and free list. */ resv->hquerybyid = pj_hash_create(pool, Q_HASH_TABLE_SIZE); resv->hquerybyres = pj_hash_create(pool, Q_HASH_TABLE_SIZE); pj_list_init(&resv->query_free_nodes); /* Create the UDP socket */ status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &resv->udp_sock); if (status != PJ_SUCCESS) goto on_error; /* Bind to any address/port */ status = pj_sock_bind_in(resv->udp_sock, 0, 0); if (status != PJ_SUCCESS) goto on_error; /* Register to ioqueue */ pj_bzero(&socket_cb, sizeof(socket_cb)); socket_cb.on_read_complete = &on_read_complete; status = pj_ioqueue_register_sock(pool, resv->ioqueue, resv->udp_sock, resv, &socket_cb, &resv->udp_key); if (status != PJ_SUCCESS) goto on_error; pj_ioqueue_op_key_init(&resv->udp_op_key, sizeof(resv->udp_op_key)); /* Start asynchronous read to the UDP socket */ resv->udp_len = sizeof(resv->udp_rx_pkt); resv->udp_addr_len = sizeof(resv->udp_src_addr); status = pj_ioqueue_recvfrom(resv->udp_key, &resv->udp_op_key, resv->udp_rx_pkt, &resv->udp_len, PJ_IOQUEUE_ALWAYS_ASYNC, &resv->udp_src_addr, &resv->udp_addr_len); if (status != PJ_EPENDING) goto on_error; /* Looks like everything is okay */ *p_resolver = resv; return PJ_SUCCESS; on_error: pj_dns_resolver_destroy(resv, PJ_FALSE); return status; }
int sess_auth_test(void) { pj_pool_t *pool; int rc; PJ_LOG(3,(THIS_FILE, " STUN session authentication test")); /* Init STUN config */ pj_stun_config_init(0, &stun_cfg, mem, 0, NULL, NULL); /* Create pool and timer heap */ pool = pj_pool_create(mem, "authtest", 200, 200, NULL); if (pj_timer_heap_create(pool, 20, &stun_cfg.timer_heap)) { pj_pool_release(pool); return -5; } /* Basic retransmission test */ rc = run_client_test("Retransmission", // title PJ_FALSE, // server responding PJ_STUN_AUTH_NONE, // server auth PJ_STUN_AUTH_NONE, // client auth NULL, // realm NULL, // username NULL, // nonce NULL, // password PJ_FALSE, // dummy MI PJ_TRUE, // expected error PJNATH_ESTUNTIMEDOUT,// expected code NULL, // expected realm NULL, // expected nonce &retransmit_check // more check ); if (rc != 0) { goto done; } /* * Short term credential. * draft-ietf-behave-rfc3489bis-15#section-10.1.2 */ /* * If the message does not contain both a MESSAGE-INTEGRITY and a * USERNAME attribute, If the message is a request, the server MUST * reject the request with an error response. This response MUST * use an error code of 400 (Bad Request). */ rc = run_client_test("Missing MESSAGE-INTEGRITY (short term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_SHORT_TERM, // server auth PJ_STUN_AUTH_NONE, // client auth NULL, // realm NULL, // username NULL, // nonce NULL, // password PJ_FALSE, // dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(400),// expected code NULL, // expected realm NULL, // expected nonce NULL // more check ); if (rc != 0) { goto done; } /* If the USERNAME does not contain a username value currently valid * within the server: If the message is a request, the server MUST * reject the request with an error response. This response MUST use * an error code of 401 (Unauthorized). */ rc = run_client_test("USERNAME mismatch (short term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_SHORT_TERM, // server auth PJ_STUN_AUTH_SHORT_TERM, // client auth NULL, // realm "anotheruser", // username NULL, // nonce "anotherpass", // password PJ_FALSE, // dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(401),// expected code NULL, // expected realm NULL, // expected nonce NULL // more check ); if (rc != 0) { goto done; } /* Using the password associated with the username, compute the value * for the message-integrity as described in Section 15.4. If the * resulting value does not match the contents of the MESSAGE- * INTEGRITY attribute: * * - If the message is a request, the server MUST reject the request * with an error response. This response MUST use an error code * of 401 (Unauthorized). */ rc = run_client_test("MESSAGE-INTEGRITY mismatch (short term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_SHORT_TERM, // server auth PJ_STUN_AUTH_SHORT_TERM, // client auth NULL, // realm USERNAME, // username NULL, // nonce "anotherpass", // password PJ_FALSE, // dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(401),// expected code NULL, // expected realm NULL, // expected nonce NULL // more check ); if (rc != 0) { goto done; } /* USERNAME is not present, server must respond with 400 (Bad * Request). */ rc = run_client_test("Missing USERNAME (short term)",// title PJ_TRUE, // server responding PJ_STUN_AUTH_SHORT_TERM, // server auth PJ_STUN_AUTH_NONE, // client auth NULL, // realm NULL, // username NULL, // nonce NULL, // password PJ_TRUE, // dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(400), // expected code NULL, // expected realm NULL, // expected nonce NULL // more check ); if (rc != 0) { goto done; } /* Successful short term authentication */ rc = run_client_test("Successful scenario (short term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_SHORT_TERM, // server auth PJ_STUN_AUTH_SHORT_TERM, // client auth NULL, // realm USERNAME, // username NULL, // nonce PASSWORD, // password PJ_FALSE, // dummy MI PJ_FALSE, // expected error PJ_SUCCESS, // expected code NULL, // expected realm NULL, // expected nonce NULL // more check ); if (rc != 0) { goto done; } /* * (our own) Extended tests for long term credential */ /* When server wants to use short term credential, but request has * REALM, reject with .... 401 ??? */ rc = run_client_test("Unwanted REALM (short term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_SHORT_TERM, // server auth PJ_STUN_AUTH_NONE, // client auth REALM, // realm USERNAME, // username NULL, // nonce PASSWORD, // password PJ_TRUE, // dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(401), // expected code NULL, // expected realm NULL, // expected nonce &long_term_check2 // more check ); if (rc != 0) { goto done; } /* * Long term credential. * draft-ietf-behave-rfc3489bis-15#section-10.2.2 */ /* If the message does not contain a MESSAGE-INTEGRITY attribute, the * server MUST generate an error response with an error code of 401 * (Unauthorized). This response MUST include a REALM value. It is * RECOMMENDED that the REALM value be the domain name of the * provider of the STUN server. The response MUST include a NONCE, * selected by the server. The response SHOULD NOT contain a * USERNAME or MESSAGE-INTEGRITY attribute. */ rc = run_client_test("Missing M-I (long term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_LONG_TERM, // server auth PJ_STUN_AUTH_NONE, // client auth NULL, // client realm NULL, // client username NULL, // client nonce NULL, // client password PJ_FALSE, // client dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(401), // expected code REALM, // expected realm NONCE, // expected nonce &long_term_check1 // more check ); if (rc != 0) { goto done; } /* If the message contains a MESSAGE-INTEGRITY attribute, but is * missing the USERNAME, REALM or NONCE attributes, the server MUST * generate an error response with an error code of 400 (Bad * Request). This response SHOULD NOT include a USERNAME, NONCE, * REALM or MESSAGE-INTEGRITY attribute. */ /* Missing USERNAME */ rc = run_client_test("Missing USERNAME (long term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_LONG_TERM, // server auth PJ_STUN_AUTH_NONE, // client auth REALM, // client realm NULL, // client username NONCE, // client nonce PASSWORD, // client password PJ_TRUE, // client dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(400), // expected code NULL, // expected realm NULL, // expected nonce &long_term_check2 // more check ); if (rc != 0) { goto done; } /* Missing REALM */ rc = run_client_test("Missing REALM (long term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_LONG_TERM, // server auth PJ_STUN_AUTH_NONE, // client auth NULL, // client realm USERNAME, // client username NONCE, // client nonce PASSWORD, // client password PJ_TRUE, // client dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(400), // expected code NULL, // expected realm NULL, // expected nonce &long_term_check2 // more check ); if (rc != 0) { goto done; } /* Missing NONCE */ rc = run_client_test("Missing NONCE (long term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_LONG_TERM, // server auth PJ_STUN_AUTH_NONE, // client auth REALM, // client realm USERNAME, // client username NULL, // client nonce PASSWORD, // client password PJ_TRUE, // client dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(400), // expected code NULL, // expected realm NULL, // expected nonce &long_term_check2 // more check ); if (rc != 0) { goto done; } /* If the NONCE is no longer valid, the server MUST generate an error * response with an error code of 438 (Stale Nonce). This response * MUST include a NONCE and REALM attribute and SHOULD NOT incude the * USERNAME or MESSAGE-INTEGRITY attribute. Servers can invalidate * nonces in order to provide additional security. See Section 4.3 * of [RFC2617] for guidelines. */ // how?? /* If the username in the USERNAME attribute is not valid, the server * MUST generate an error response with an error code of 401 * (Unauthorized). This response MUST include a REALM value. It is * RECOMMENDED that the REALM value be the domain name of the * provider of the STUN server. The response MUST include a NONCE, * selected by the server. The response SHOULD NOT contain a * USERNAME or MESSAGE-INTEGRITY attribute. */ rc = run_client_test("Invalid username (long term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_LONG_TERM, // server auth PJ_STUN_AUTH_LONG_TERM, // client auth REALM, // client realm "anotheruser", // client username "a nonce", // client nonce "somepassword", // client password PJ_FALSE, // client dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(401), // expected code REALM, // expected realm NONCE, // expected nonce &long_term_check1 // more check ); if (rc != 0) { goto done; } /* Successful long term authentication */ rc = run_client_test("Successful scenario (long term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_LONG_TERM, // server auth PJ_STUN_AUTH_LONG_TERM, // client auth REALM, // client realm USERNAME, // client username "anothernonce", // client nonce PASSWORD, // client password PJ_FALSE, // client dummy MI PJ_FALSE, // expected error 0, // expected code NULL, // expected realm NULL, // expected nonce &long_term_check3 // more check ); if (rc != 0) { goto done; } /* * (our own) Extended tests for long term credential */ /* If REALM doesn't match, server must respond with 401 */ #if 0 // STUN session now will just use the realm sent in the // response, so this test will fail because it will // authenticate successfully. rc = run_client_test("Invalid REALM (long term)", // title PJ_TRUE, // server responding PJ_STUN_AUTH_LONG_TERM, // server auth PJ_STUN_AUTH_LONG_TERM, // client auth "anotherrealm", // client realm USERNAME, // client username NONCE, // client nonce PASSWORD, // client password PJ_FALSE, // client dummy MI PJ_TRUE, // expected error PJ_STATUS_FROM_STUN_CODE(401), // expected code REALM, // expected realm NONCE, // expected nonce &long_term_check1 // more check ); if (rc != 0) { goto done; } #endif /* Invalid HMAC */ /* Valid static short term, without NONCE */ /* Valid static short term, WITH NONCE */ /* Valid static long term (with NONCE */ /* Valid dynamic short term (without NONCE) */ /* Valid dynamic short term (with NONCE) */ /* Valid dynamic long term (with NONCE) */ done: pj_timer_heap_destroy(stun_cfg.timer_heap); pj_pool_release(pool); return rc; }
/* * Create server. */ PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf, pj_turn_srv **p_srv) { pj_pool_t *pool; pj_stun_session_cb sess_cb; pj_turn_srv *srv; unsigned i; pj_status_t status; PJ_ASSERT_RETURN(pf && p_srv, PJ_EINVAL); /* Create server and init core settings */ pool = pj_pool_create(pf, "srv%p", 1000, 1000, NULL); srv = PJ_POOL_ZALLOC_T(pool, pj_turn_srv); srv->obj_name = pool->obj_name; srv->core.pf = pf; srv->core.pool = pool; srv->core.tls_key = srv->core.tls_data = -1; /* Create ioqueue */ status = pj_ioqueue_create(pool, MAX_HANDLES, &srv->core.ioqueue); if (status != PJ_SUCCESS) goto on_error; /* Server mutex */ status = pj_lock_create_recursive_mutex(pool, srv->obj_name, &srv->core.lock); if (status != PJ_SUCCESS) goto on_error; /* Allocate TLS */ status = pj_thread_local_alloc(&srv->core.tls_key); if (status != PJ_SUCCESS) goto on_error; status = pj_thread_local_alloc(&srv->core.tls_data); if (status != PJ_SUCCESS) goto on_error; /* Create timer heap */ status = pj_timer_heap_create(pool, MAX_TIMER, &srv->core.timer_heap); if (status != PJ_SUCCESS) goto on_error; /* Configure lock for the timer heap */ pj_timer_heap_set_lock(srv->core.timer_heap, srv->core.lock, PJ_FALSE); /* Array of listeners */ srv->core.listener = (pj_turn_listener**) pj_pool_calloc(pool, MAX_LISTENERS, sizeof(srv->core.listener[0])); /* Create hash tables */ srv->tables.alloc = pj_hash_create(pool, MAX_CLIENTS); srv->tables.res = pj_hash_create(pool, MAX_CLIENTS); /* Init ports settings */ srv->ports.min_udp = srv->ports.next_udp = MIN_PORT; srv->ports.max_udp = MAX_PORT; srv->ports.min_tcp = srv->ports.next_tcp = MIN_PORT; srv->ports.max_tcp = MAX_PORT; /* Init STUN config */ pj_stun_config_init(&srv->core.stun_cfg, pf, 0, srv->core.ioqueue, srv->core.timer_heap); /* Init STUN credential */ srv->core.cred.type = PJ_STUN_AUTH_CRED_DYNAMIC; srv->core.cred.data.dyn_cred.user_data = srv; srv->core.cred.data.dyn_cred.get_auth = &pj_turn_get_auth; srv->core.cred.data.dyn_cred.get_password = &pj_turn_get_password; srv->core.cred.data.dyn_cred.verify_nonce = &pj_turn_verify_nonce; /* Create STUN session to handle new allocation */ pj_bzero(&sess_cb, sizeof(sess_cb)); sess_cb.on_rx_request = &on_rx_stun_request; sess_cb.on_send_msg = &on_tx_stun_msg; status = pj_stun_session_create(&srv->core.stun_cfg, srv->obj_name, &sess_cb, PJ_FALSE, NULL, &srv->core.stun_sess); if (status != PJ_SUCCESS) { goto on_error; } pj_stun_session_set_user_data(srv->core.stun_sess, srv); pj_stun_session_set_credential(srv->core.stun_sess, PJ_STUN_AUTH_LONG_TERM, &srv->core.cred); /* Array of worker threads */ srv->core.thread_cnt = MAX_THREADS; srv->core.thread = (pj_thread_t**) pj_pool_calloc(pool, srv->core.thread_cnt, sizeof(pj_thread_t*)); /* Start the worker threads */ for (i=0; i<srv->core.thread_cnt; ++i) { status = pj_thread_create(pool, srv->obj_name, &server_thread_proc, srv, 0, 0, &srv->core.thread[i]); if (status != PJ_SUCCESS) goto on_error; } /* We're done. Application should add listeners now */ PJ_LOG(4,(srv->obj_name, "TURN server v%s is running", pj_get_version())); *p_srv = srv; return PJ_SUCCESS; on_error: pj_turn_srv_destroy(srv); return status; }
/* SSL socket try to connect to raw TCP socket server, once * connection established, SSL socket will try to perform SSL * handshake. SSL client socket should be able to close the * connection after specified timeout period (set ms_timeout to * 0 to disable timer). */ static int server_non_ssl(unsigned ms_timeout) { pj_pool_t *pool = NULL; pj_ioqueue_t *ioqueue = NULL; pj_timer_heap_t *timer = NULL; pj_activesock_t *asock_serv = NULL; pj_ssl_sock_t *ssock_cli = NULL; pj_activesock_cb asock_cb = { 0 }; pj_sock_t sock = PJ_INVALID_SOCKET; pj_ssl_sock_param param; struct test_state state_serv = { 0 }; struct test_state state_cli = { 0 }; pj_sockaddr addr, listen_addr; pj_status_t status; pool = pj_pool_create(mem, "ssl_connect_raw_tcp", 256, 256, NULL); status = pj_ioqueue_create(pool, 4, &ioqueue); if (status != PJ_SUCCESS) { goto on_return; } status = pj_timer_heap_create(pool, 4, &timer); if (status != PJ_SUCCESS) { goto on_return; } /* SERVER */ state_serv.pool = pool; state_serv.ioqueue = ioqueue; status = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &sock); if (status != PJ_SUCCESS) { goto on_return; } /* Init bind address */ { pj_str_t tmp_st; pj_sockaddr_init(PJ_AF_INET, &listen_addr, pj_strset2(&tmp_st, "127.0.0.1"), 0); } status = pj_sock_bind(sock, (pj_sockaddr_t*)&listen_addr, pj_sockaddr_get_len((pj_sockaddr_t*)&listen_addr)); if (status != PJ_SUCCESS) { goto on_return; } status = pj_sock_listen(sock, PJ_SOMAXCONN); if (status != PJ_SUCCESS) { goto on_return; } asock_cb.on_accept_complete = &asock_on_accept_complete; status = pj_activesock_create(pool, sock, pj_SOCK_STREAM(), NULL, ioqueue, &asock_cb, &state_serv, &asock_serv); if (status != PJ_SUCCESS) { goto on_return; } status = pj_activesock_start_accept(asock_serv, pool); if (status != PJ_SUCCESS) goto on_return; /* Update listener address */ { int addr_len; addr_len = sizeof(listen_addr); pj_sock_getsockname(sock, (pj_sockaddr_t*)&listen_addr, &addr_len); } /* CLIENT */ pj_ssl_sock_param_default(¶m); param.cb.on_connect_complete = &ssl_on_connect_complete; param.cb.on_data_read = &ssl_on_data_read; param.cb.on_data_sent = &ssl_on_data_sent; param.ioqueue = ioqueue; param.timer_heap = timer; param.timeout.sec = 0; param.timeout.msec = ms_timeout; pj_time_val_normalize(¶m.timeout); param.user_data = &state_cli; state_cli.pool = pool; state_cli.is_server = PJ_FALSE; state_cli.is_verbose = PJ_TRUE; status = pj_ssl_sock_create(pool, ¶m, &ssock_cli); if (status != PJ_SUCCESS) { goto on_return; } /* Init default bind address */ { pj_str_t tmp_st; pj_sockaddr_init(PJ_AF_INET, &addr, pj_strset2(&tmp_st, "127.0.0.1"), 0); } status = pj_ssl_sock_start_connect(ssock_cli, pool, (pj_sockaddr_t*)&addr, (pj_sockaddr_t*)&listen_addr, pj_sockaddr_get_len(&listen_addr)); if (status != PJ_EPENDING) { goto on_return; } /* Wait until everything has been sent/received or error */ while ((!state_serv.err && !state_serv.done) || (!state_cli.err && !state_cli.done)) { #ifdef PJ_SYMBIAN pj_symbianos_poll(-1, 1000); #else pj_time_val delay = {0, 100}; pj_ioqueue_poll(ioqueue, &delay); pj_timer_heap_poll(timer, &delay); #endif } if (state_serv.err || state_cli.err) { if (state_cli.err != PJ_SUCCESS) status = state_cli.err; else status = state_serv.err; goto on_return; } PJ_LOG(3, ("", "...Done!")); on_return: if (asock_serv) pj_activesock_close(asock_serv); if (ssock_cli && !state_cli.err && !state_cli.done) pj_ssl_sock_close(ssock_cli); if (timer) pj_timer_heap_destroy(timer); if (ioqueue) pj_ioqueue_destroy(ioqueue); if (pool) pj_pool_release(pool); return status; }
// // Create // pj_status_t create(Pj_Pool *pool, pj_size_t initial_count) { destroy(); return pj_timer_heap_create(pool->pool_(), initial_count, &ht_); }
static int https_client_test(unsigned ms_timeout) { pj_pool_t *pool = NULL; pj_ioqueue_t *ioqueue = NULL; pj_timer_heap_t *timer = NULL; pj_ssl_sock_t *ssock = NULL; pj_ssl_sock_param param; pj_status_t status; struct test_state state = {0}; pj_sockaddr local_addr, rem_addr; pj_str_t tmp_st; pool = pj_pool_create(mem, "https_get", 256, 256, NULL); status = pj_ioqueue_create(pool, 4, &ioqueue); if (status != PJ_SUCCESS) { goto on_return; } status = pj_timer_heap_create(pool, 4, &timer); if (status != PJ_SUCCESS) { goto on_return; } state.pool = pool; state.send_str = HTTP_REQ; state.send_str_len = pj_ansi_strlen(state.send_str); state.is_verbose = PJ_TRUE; pj_ssl_sock_param_default(¶m); param.cb.on_connect_complete = &ssl_on_connect_complete; param.cb.on_data_read = &ssl_on_data_read; param.cb.on_data_sent = &ssl_on_data_sent; param.ioqueue = ioqueue; param.user_data = &state; param.server_name = pj_str((char*)HTTP_SERVER_ADDR); param.timer_heap = timer; param.timeout.sec = 0; param.timeout.msec = ms_timeout; param.proto = PJ_SSL_SOCK_PROTO_SSL23; pj_time_val_normalize(¶m.timeout); status = pj_ssl_sock_create(pool, ¶m, &ssock); if (status != PJ_SUCCESS) { goto on_return; } pj_sockaddr_init(PJ_AF_INET, &local_addr, pj_strset2(&tmp_st, "0.0.0.0"), 0); pj_sockaddr_init(PJ_AF_INET, &rem_addr, pj_strset2(&tmp_st, HTTP_SERVER_ADDR), HTTP_SERVER_PORT); status = pj_ssl_sock_start_connect(ssock, pool, &local_addr, &rem_addr, sizeof(rem_addr)); if (status == PJ_SUCCESS) { ssl_on_connect_complete(ssock, PJ_SUCCESS); } else if (status == PJ_EPENDING) { status = PJ_SUCCESS; } else { goto on_return; } /* Wait until everything has been sent/received */ while (state.err == PJ_SUCCESS && !state.done) { #ifdef PJ_SYMBIAN pj_symbianos_poll(-1, 1000); #else pj_time_val delay = {0, 100}; pj_ioqueue_poll(ioqueue, &delay); pj_timer_heap_poll(timer, &delay); #endif } if (state.err) { status = state.err; goto on_return; } PJ_LOG(3, ("", "...Done!")); PJ_LOG(3, ("", ".....Sent/recv: %d/%d bytes", state.sent, state.recv)); on_return: if (ssock && !state.err && !state.done) pj_ssl_sock_close(ssock); if (ioqueue) pj_ioqueue_destroy(ioqueue); if (timer) pj_timer_heap_destroy(timer); if (pool) pj_pool_release(pool); return status; }
/* Raw TCP socket try to connect to SSL socket server, once * connection established, it will just do nothing, SSL socket * server should be able to close the connection after specified * timeout period (set ms_timeout to 0 to disable timer). */ static int client_non_ssl(unsigned ms_timeout) { pj_pool_t *pool = NULL; pj_ioqueue_t *ioqueue = NULL; pj_timer_heap_t *timer = NULL; pj_ssl_sock_t *ssock_serv = NULL; pj_activesock_t *asock_cli = NULL; pj_activesock_cb asock_cb = { 0 }; pj_sock_t sock = PJ_INVALID_SOCKET; pj_ssl_sock_param param; struct test_state state_serv = { 0 }; struct test_state state_cli = { 0 }; pj_sockaddr listen_addr; pj_ssl_cert_t *cert = NULL; pj_status_t status; pool = pj_pool_create(mem, "ssl_accept_raw_tcp", 256, 256, NULL); status = pj_ioqueue_create(pool, 4, &ioqueue); if (status != PJ_SUCCESS) { goto on_return; } status = pj_timer_heap_create(pool, 4, &timer); if (status != PJ_SUCCESS) { goto on_return; } /* Set cert */ { pj_str_t tmp1, tmp2, tmp3, tmp4; status = pj_ssl_cert_load_from_files(pool, pj_strset2(&tmp1, (char*)CERT_CA_FILE), pj_strset2(&tmp2, (char*)CERT_FILE), pj_strset2(&tmp3, (char*)CERT_PRIVKEY_FILE), pj_strset2(&tmp4, (char*)CERT_PRIVKEY_PASS), &cert); if (status != PJ_SUCCESS) { goto on_return; } } pj_ssl_sock_param_default(¶m); param.cb.on_accept_complete = &ssl_on_accept_complete; param.cb.on_data_read = &ssl_on_data_read; param.cb.on_data_sent = &ssl_on_data_sent; param.ioqueue = ioqueue; param.timer_heap = timer; param.timeout.sec = 0; param.timeout.msec = ms_timeout; pj_time_val_normalize(¶m.timeout); /* SERVER */ param.user_data = &state_serv; state_serv.pool = pool; state_serv.is_server = PJ_TRUE; state_serv.is_verbose = PJ_TRUE; status = pj_ssl_sock_create(pool, ¶m, &ssock_serv); if (status != PJ_SUCCESS) { goto on_return; } status = pj_ssl_sock_set_certificate(ssock_serv, pool, cert); if (status != PJ_SUCCESS) { goto on_return; } /* Init bind address */ { pj_str_t tmp_st; pj_sockaddr_init(PJ_AF_INET, &listen_addr, pj_strset2(&tmp_st, "127.0.0.1"), 0); } status = pj_ssl_sock_start_accept(ssock_serv, pool, &listen_addr, pj_sockaddr_get_len(&listen_addr)); if (status != PJ_SUCCESS) { goto on_return; } /* Update listener address */ { pj_ssl_sock_info info; pj_ssl_sock_get_info(ssock_serv, &info); pj_sockaddr_cp(&listen_addr, &info.local_addr); } /* CLIENT */ state_cli.pool = pool; status = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &sock); if (status != PJ_SUCCESS) { goto on_return; } asock_cb.on_connect_complete = &asock_on_connect_complete; asock_cb.on_data_read = &asock_on_data_read; status = pj_activesock_create(pool, sock, pj_SOCK_STREAM(), NULL, ioqueue, &asock_cb, &state_cli, &asock_cli); if (status != PJ_SUCCESS) { goto on_return; } status = pj_activesock_start_connect(asock_cli, pool, (pj_sockaddr_t*)&listen_addr, pj_sockaddr_get_len(&listen_addr)); if (status == PJ_SUCCESS) { asock_on_connect_complete(asock_cli, PJ_SUCCESS); } else if (status == PJ_EPENDING) { status = PJ_SUCCESS; } else { goto on_return; } /* Wait until everything has been sent/received or error */ while (!state_serv.err && !state_cli.err && !state_serv.done && !state_cli.done) { #ifdef PJ_SYMBIAN pj_symbianos_poll(-1, 1000); #else pj_time_val delay = {0, 100}; pj_ioqueue_poll(ioqueue, &delay); pj_timer_heap_poll(timer, &delay); #endif } if (state_serv.err || state_cli.err) { if (state_serv.err != PJ_SUCCESS) status = state_serv.err; else status = state_cli.err; goto on_return; } PJ_LOG(3, ("", "...Done!")); on_return: if (ssock_serv) pj_ssl_sock_close(ssock_serv); if (asock_cli && !state_cli.err && !state_cli.done) pj_activesock_close(asock_cli); if (timer) pj_timer_heap_destroy(timer); if (ioqueue) pj_ioqueue_destroy(ioqueue); if (pool) pj_pool_release(pool); return status; }
static int test_timer_heap(void) { int i, j; pj_timer_entry *entry; pj_pool_t *pool; pj_timer_heap_t *timer; pj_time_val delay; pj_status_t rc; int err=0; unsigned size, count; size = pj_timer_heap_mem_size(MAX_COUNT)+MAX_COUNT*sizeof(pj_timer_entry); pool = pj_pool_create( mem, NULL, size, 4000, NULL); if (!pool) { PJ_LOG(3,("test", "...error: unable to create pool of %u bytes", size)); return -10; } entry = (pj_timer_entry*)pj_pool_calloc(pool, MAX_COUNT, sizeof(*entry)); if (!entry) return -20; for (i=0; i<MAX_COUNT; ++i) { entry[i].cb = &timer_callback; } rc = pj_timer_heap_create(pool, MAX_COUNT, &timer); if (rc != PJ_SUCCESS) { app_perror("...error: unable to create timer heap", rc); return -30; } count = MIN_COUNT; for (i=0; i<LOOP; ++i) { int early = 0; int done=0; int cancelled=0; int rc; pj_timestamp t1, t2, t_sched, t_cancel, t_poll; pj_time_val now, expire; pj_gettimeofday(&now); pj_srand(now.sec); t_sched.u32.lo = t_cancel.u32.lo = t_poll.u32.lo = 0; // Register timers for (j=0; j<(int)count; ++j) { delay.sec = pj_rand() % DELAY; delay.msec = pj_rand() % 1000; // Schedule timer pj_get_timestamp(&t1); rc = pj_timer_heap_schedule(timer, &entry[j], &delay); if (rc != 0) return -40; pj_get_timestamp(&t2); t_sched.u32.lo += (t2.u32.lo - t1.u32.lo); // Poll timers. pj_get_timestamp(&t1); rc = pj_timer_heap_poll(timer, NULL); pj_get_timestamp(&t2); if (rc > 0) { t_poll.u32.lo += (t2.u32.lo - t1.u32.lo); early += rc; } } // Set the time where all timers should finish pj_gettimeofday(&expire); delay.sec = DELAY; delay.msec = 0; PJ_TIME_VAL_ADD(expire, delay); // Wait unfil all timers finish, cancel some of them. do { int index = pj_rand() % count; pj_get_timestamp(&t1); rc = pj_timer_heap_cancel(timer, &entry[index]); pj_get_timestamp(&t2); if (rc > 0) { cancelled += rc; t_cancel.u32.lo += (t2.u32.lo - t1.u32.lo); } pj_gettimeofday(&now); pj_get_timestamp(&t1); #if defined(PJ_SYMBIAN) && PJ_SYMBIAN!=0 /* On Symbian, we must use OS poll (Active Scheduler poll) since * timer is implemented using Active Object. */ rc = 0; while (pj_symbianos_poll(-1, 0)) ++rc; #else rc = pj_timer_heap_poll(timer, NULL); #endif pj_get_timestamp(&t2); if (rc > 0) { done += rc; t_poll.u32.lo += (t2.u32.lo - t1.u32.lo); } } while (PJ_TIME_VAL_LTE(now, expire)&&pj_timer_heap_count(timer) > 0); if (pj_timer_heap_count(timer)) { PJ_LOG(3, (THIS_FILE, "ERROR: %d timers left", pj_timer_heap_count(timer))); ++err; } t_sched.u32.lo /= count; t_cancel.u32.lo /= count; t_poll.u32.lo /= count; PJ_LOG(4, (THIS_FILE, "...ok (count:%d, early:%d, cancelled:%d, " "sched:%d, cancel:%d poll:%d)", count, early, cancelled, t_sched.u32.lo, t_cancel.u32.lo, t_poll.u32.lo)); count = count * 2; if (count > MAX_COUNT) break; } pj_pool_release(pool); return err; }
/* Test will perform multiple clients trying to connect to single server. * Once SSL connection established, echo test will be performed. */ static int perf_test(unsigned clients, unsigned ms_handshake_timeout) { pj_pool_t *pool = NULL; pj_ioqueue_t *ioqueue = NULL; pj_timer_heap_t *timer = NULL; pj_ssl_sock_t *ssock_serv = NULL; pj_ssl_sock_t **ssock_cli = NULL; pj_ssl_sock_param param; struct test_state state_serv = { 0 }; struct test_state *state_cli = NULL; pj_sockaddr addr, listen_addr; pj_ssl_cert_t *cert = NULL; pj_status_t status; unsigned i, cli_err = 0, tot_sent = 0, tot_recv = 0; pj_time_val start; pool = pj_pool_create(mem, "ssl_perf", 256, 256, NULL); status = pj_ioqueue_create(pool, PJ_IOQUEUE_MAX_HANDLES, &ioqueue); if (status != PJ_SUCCESS) { goto on_return; } status = pj_timer_heap_create(pool, PJ_IOQUEUE_MAX_HANDLES, &timer); if (status != PJ_SUCCESS) { goto on_return; } /* Set cert */ { pj_str_t tmp1, tmp2, tmp3, tmp4; status = pj_ssl_cert_load_from_files(pool, pj_strset2(&tmp1, (char*)CERT_CA_FILE), pj_strset2(&tmp2, (char*)CERT_FILE), pj_strset2(&tmp3, (char*)CERT_PRIVKEY_FILE), pj_strset2(&tmp4, (char*)CERT_PRIVKEY_PASS), &cert); if (status != PJ_SUCCESS) { goto on_return; } } pj_ssl_sock_param_default(¶m); param.cb.on_accept_complete = &ssl_on_accept_complete; param.cb.on_connect_complete = &ssl_on_connect_complete; param.cb.on_data_read = &ssl_on_data_read; param.cb.on_data_sent = &ssl_on_data_sent; param.ioqueue = ioqueue; param.timer_heap = timer; param.timeout.sec = 0; param.timeout.msec = ms_handshake_timeout; pj_time_val_normalize(¶m.timeout); /* Init default bind address */ { pj_str_t tmp_st; pj_sockaddr_init(PJ_AF_INET, &addr, pj_strset2(&tmp_st, "127.0.0.1"), 0); } /* SERVER */ param.user_data = &state_serv; state_serv.pool = pool; state_serv.echo = PJ_TRUE; state_serv.is_server = PJ_TRUE; status = pj_ssl_sock_create(pool, ¶m, &ssock_serv); if (status != PJ_SUCCESS) { goto on_return; } status = pj_ssl_sock_set_certificate(ssock_serv, pool, cert); if (status != PJ_SUCCESS) { goto on_return; } status = pj_ssl_sock_start_accept(ssock_serv, pool, &addr, pj_sockaddr_get_len(&addr)); if (status != PJ_SUCCESS) { goto on_return; } /* Get listening address for clients to connect to */ { pj_ssl_sock_info info; char buf[64]; pj_ssl_sock_get_info(ssock_serv, &info); pj_sockaddr_cp(&listen_addr, &info.local_addr); pj_sockaddr_print((pj_sockaddr_t*)&listen_addr, buf, sizeof(buf), 1); PJ_LOG(3, ("", "...Listener ready at %s", buf)); } /* CLIENTS */ clients_num = clients; param.timeout.sec = 0; param.timeout.msec = 0; /* Init random seed */ { pj_time_val now; pj_gettimeofday(&now); pj_srand((unsigned)now.sec); } /* Allocate SSL socket pointers and test state */ ssock_cli = pj_pool_calloc(pool, clients, sizeof(pj_ssl_sock_t*)); state_cli = pj_pool_calloc(pool, clients, sizeof(struct test_state)); /* Get start timestamp */ pj_gettimeofday(&start); /* Setup clients */ for (i = 0; i < clients; ++i) { param.user_data = &state_cli[i]; state_cli[i].pool = pool; state_cli[i].check_echo = PJ_TRUE; state_cli[i].send_str_len = (pj_rand() % 5 + 1) * 1024 + pj_rand() % 1024; state_cli[i].send_str = pj_pool_alloc(pool, state_cli[i].send_str_len); { unsigned j; for (j = 0; j < state_cli[i].send_str_len; ++j) state_cli[i].send_str[j] = (char)(pj_rand() % 256); } status = pj_ssl_sock_create(pool, ¶m, &ssock_cli[i]); if (status != PJ_SUCCESS) { app_perror("...ERROR pj_ssl_sock_create()", status); cli_err++; clients_num--; continue; } status = pj_ssl_sock_start_connect(ssock_cli[i], pool, &addr, &listen_addr, pj_sockaddr_get_len(&addr)); if (status == PJ_SUCCESS) { ssl_on_connect_complete(ssock_cli[i], PJ_SUCCESS); } else if (status == PJ_EPENDING) { status = PJ_SUCCESS; } else { app_perror("...ERROR pj_ssl_sock_create()", status); pj_ssl_sock_close(ssock_cli[i]); ssock_cli[i] = NULL; clients_num--; cli_err++; continue; } /* Give chance to server to accept this client */ { unsigned n = 5; #ifdef PJ_SYMBIAN while(n && pj_symbianos_poll(-1, 1000)) n--; #else pj_time_val delay = {0, 100}; while(n && pj_ioqueue_poll(ioqueue, &delay) > 0) n--; #endif } } /* Wait until everything has been sent/received or error */ while (clients_num) { #ifdef PJ_SYMBIAN pj_symbianos_poll(-1, 1000); #else pj_time_val delay = {0, 100}; pj_ioqueue_poll(ioqueue, &delay); pj_timer_heap_poll(timer, &delay); #endif } /* Clean up sockets */ { pj_time_val delay = {0, 500}; while (pj_ioqueue_poll(ioqueue, &delay) > 0); } if (state_serv.err != PJ_SUCCESS) { status = state_serv.err; goto on_return; } PJ_LOG(3, ("", "...Done!")); /* SSL setup and data transfer duration */ { pj_time_val stop; pj_gettimeofday(&stop); PJ_TIME_VAL_SUB(stop, start); PJ_LOG(3, ("", ".....Setup & data transfer duration: %d.%03ds", stop.sec, stop.msec)); } /* Check clients status */ for (i = 0; i < clients; ++i) { if (state_cli[i].err != PJ_SUCCESS) cli_err++; tot_sent += state_cli[1].sent; tot_recv += state_cli[1].recv; } PJ_LOG(3, ("", ".....Clients: %d (%d errors)", clients, cli_err)); PJ_LOG(3, ("", ".....Total sent/recv: %d/%d bytes", tot_sent, tot_recv)); on_return: if (ssock_serv) pj_ssl_sock_close(ssock_serv); for (i = 0; i < clients; ++i) { if (ssock_cli[i] && !state_cli[i].err && !state_cli[i].done) pj_ssl_sock_close(ssock_cli[i]); } if (ioqueue) pj_ioqueue_destroy(ioqueue); if (pool) pj_pool_release(pool); return status; }
static int stun_destroy_test(void) { enum { LOOP = 500 }; struct stun_test_session test_sess; pj_sockaddr bind_addr; int addr_len; pj_caching_pool cp; pj_pool_t *pool; unsigned i; pj_status_t status; int rc = 0; PJ_LOG(3,(THIS_FILE, " STUN destroy concurrency test")); pj_bzero(&test_sess, sizeof(test_sess)); pj_caching_pool_init(&cp, NULL, 0); pool = pj_pool_create(&cp.factory, "testsess", 512, 512, NULL); pj_stun_config_init(&test_sess.stun_cfg, &cp.factory, 0, NULL, NULL); status = pj_timer_heap_create(pool, 1023, &test_sess.stun_cfg.timer_heap); pj_assert(status == PJ_SUCCESS); status = pj_lock_create_recursive_mutex(pool, NULL, &test_sess.lock); pj_assert(status == PJ_SUCCESS); pj_timer_heap_set_lock(test_sess.stun_cfg.timer_heap, test_sess.lock, PJ_TRUE); pj_assert(status == PJ_SUCCESS); status = pj_ioqueue_create(pool, 512, &test_sess.stun_cfg.ioqueue); pj_assert(status == PJ_SUCCESS); pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &test_sess.server_sock); pj_sockaddr_init(pj_AF_INET(), &bind_addr, NULL, 0); status = pj_sock_bind(test_sess.server_sock, &bind_addr, pj_sockaddr_get_len(&bind_addr)); pj_assert(status == PJ_SUCCESS); addr_len = sizeof(bind_addr); status = pj_sock_getsockname(test_sess.server_sock, &bind_addr, &addr_len); pj_assert(status == PJ_SUCCESS); test_sess.server_port = pj_sockaddr_get_port(&bind_addr); status = pj_event_create(pool, NULL, PJ_TRUE, PJ_FALSE, &test_sess.server_event); pj_assert(status == PJ_SUCCESS); for (i=0; i<SERVER_THREAD_CNT; ++i) { status = pj_thread_create(pool, NULL, &server_thread_proc, &test_sess, 0, 0, &test_sess.server_threads[i]); pj_assert(status == PJ_SUCCESS); } for (i=0; i<WORKER_THREAD_CNT; ++i) { status = pj_thread_create(pool, NULL, &worker_thread_proc, &test_sess, 0, 0, &test_sess.worker_threads[i]); pj_assert(status == PJ_SUCCESS); } /* Test 1: Main thread calls destroy while callback is processing response */ PJ_LOG(3,(THIS_FILE, " Destroy in main thread while callback is running")); for (i=0; i<LOOP; ++i) { int sleep = pj_rand() % 5; PJ_LOG(3,(THIS_FILE, " Try %-3d of %d", i+1, LOOP)); /* Test 1: destroy at the same time when receiving response */ pj_bzero(&test_sess.param, sizeof(test_sess.param)); test_sess.param.client_sleep_after_start = 20; test_sess.param.client_sleep_before_destroy = sleep; test_sess.param.server_wait_for_event = PJ_TRUE; stun_destroy_test_session(&test_sess); PJ_LOG(3,(THIS_FILE, " stun test a: sleep delay:%d: clients with response: %d", sleep, test_sess.param.client_got_response)); /* Test 2: destroy at the same time with STUN retransmit timer */ test_sess.param.server_drop_request = PJ_TRUE; test_sess.param.client_sleep_after_start = 0; test_sess.param.client_sleep_before_destroy = PJ_STUN_RTO_VALUE; test_sess.param.server_wait_for_event = PJ_FALSE; stun_destroy_test_session(&test_sess); PJ_LOG(3,(THIS_FILE, " stun test b: retransmit concurrency")); /* Test 3: destroy at the same time with receiving response * AND STUN retransmit timer */ test_sess.param.client_got_response = 0; test_sess.param.server_drop_request = PJ_FALSE; test_sess.param.client_sleep_after_start = PJ_STUN_RTO_VALUE; test_sess.param.client_sleep_before_destroy = 0; test_sess.param.server_wait_for_event = PJ_TRUE; stun_destroy_test_session(&test_sess); PJ_LOG(3,(THIS_FILE, " stun test c: clients with response: %d", test_sess.param.client_got_response)); pj_thread_sleep(10); ice_one_conc_test(&test_sess.stun_cfg, PJ_FALSE); pj_thread_sleep(10); } /* Avoid compiler warning */ goto on_return; on_return: test_sess.thread_quit_flag = PJ_TRUE; for (i=0; i<SERVER_THREAD_CNT; ++i) { pj_thread_join(test_sess.server_threads[i]); } for (i=0; i<WORKER_THREAD_CNT; ++i) { pj_thread_join(test_sess.worker_threads[i]); } pj_event_destroy(test_sess.server_event); pj_sock_close(test_sess.server_sock); pj_ioqueue_destroy(test_sess.stun_cfg.ioqueue); pj_timer_heap_destroy(test_sess.stun_cfg.timer_heap); pj_pool_release(pool); pj_caching_pool_destroy(&cp); PJ_LOG(3,(THIS_FILE, " Done. rc=%d", rc)); return rc; }
int http_client_test_delete() { pj_str_t url; pj_http_req_callback hcb; pj_http_req_param param; char urlbuf[80]; pj_bzero(&hcb, sizeof(hcb)); hcb.on_complete = &on_complete; hcb.on_response = &on_response; /* Create pool, timer, and ioqueue */ pool = pj_pool_create(mem, NULL, 8192, 4096, NULL); if (pj_timer_heap_create(pool, 16, &timer_heap)) return -61; if (pj_ioqueue_create(pool, 16, &ioqueue)) return -62; #ifdef USE_LOCAL_SERVER thread_quit = PJ_FALSE; g_server.action = ACTION_REPLY; g_server.send_content_length = PJ_TRUE; g_server.data_size = 0; g_server.buf_size = 1024; sstatus = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &g_server.sock); if (sstatus != PJ_SUCCESS) return -41; pj_sockaddr_in_init(&addr, NULL, 0); sstatus = pj_sock_bind(g_server.sock, &addr, sizeof(addr)); if (sstatus != PJ_SUCCESS) return -43; { pj_sockaddr_in addr; int addr_len = sizeof(addr); sstatus = pj_sock_getsockname(g_server.sock, &addr, &addr_len); if (sstatus != PJ_SUCCESS) return -44; g_server.port = pj_sockaddr_in_get_port(&addr); pj_ansi_snprintf(urlbuf, sizeof(urlbuf), "http://127.0.0.1:%d/test/test2.txt", g_server.port); url = pj_str(urlbuf); } sstatus = pj_sock_listen(g_server.sock, 8); if (sstatus != PJ_SUCCESS) return -45; sstatus = pj_thread_create(pool, NULL, &server_thread, &g_server, 0, 0, &g_server.thread); if (sstatus != PJ_SUCCESS) return -47; #else pj_cstr(&url, "http://127.0.0.1:280/test/test2.txt"); #endif pj_http_req_param_default(¶m); pj_strset2(¶m.method, (char*)"DELETE"); if (pj_http_req_create(pool, &url, timer_heap, ioqueue, ¶m, &hcb, &http_req)) return -63; if (pj_http_req_start(http_req)) return -65; while (pj_http_req_is_running(http_req)) { pj_time_val delay = {0, 50}; pj_ioqueue_poll(ioqueue, &delay); pj_timer_heap_poll(timer_heap, NULL); } #ifdef USE_LOCAL_SERVER thread_quit = PJ_TRUE; pj_thread_join(g_server.thread); pj_sock_close(g_server.sock); #endif pj_http_req_destroy(http_req); pj_ioqueue_destroy(ioqueue); pj_timer_heap_destroy(timer_heap); pj_pool_release(pool); return PJ_SUCCESS; }
/* * GET request scenario 2: using on_complete() to get the * complete data. Server does not reply with content-length. * Request timed out, application sets a longer timeout, then * then restart the request. */ int http_client_test2() { pj_str_t url; pj_http_req_callback hcb; pj_http_req_param param; pj_time_val timeout; char urlbuf[80]; pj_bzero(&hcb, sizeof(hcb)); hcb.on_complete = &on_complete; hcb.on_response = &on_response; pj_http_req_param_default(¶m); /* Create pool, timer, and ioqueue */ pool = pj_pool_create(mem, NULL, 8192, 4096, NULL); if (pj_timer_heap_create(pool, 16, &timer_heap)) return -41; if (pj_ioqueue_create(pool, 16, &ioqueue)) return -42; #ifdef USE_LOCAL_SERVER pj_cstr(&url, "http://127.0.0.1:380"); param.timeout.sec = 0; param.timeout.msec = 2000; thread_quit = PJ_FALSE; g_server.action = ACTION_IGNORE; g_server.send_content_length = PJ_FALSE; g_server.data_size = 4173; g_server.buf_size = 1024; sstatus = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &g_server.sock); if (sstatus != PJ_SUCCESS) return -41; pj_sockaddr_in_init(&addr, NULL, 0); sstatus = pj_sock_bind(g_server.sock, &addr, sizeof(addr)); if (sstatus != PJ_SUCCESS) return -43; { pj_sockaddr_in addr; int addr_len = sizeof(addr); sstatus = pj_sock_getsockname(g_server.sock, &addr, &addr_len); if (sstatus != PJ_SUCCESS) return -44; g_server.port = pj_sockaddr_in_get_port(&addr); pj_ansi_snprintf(urlbuf, sizeof(urlbuf), "http://127.0.0.1:%d", g_server.port); url = pj_str(urlbuf); } sstatus = pj_sock_listen(g_server.sock, 8); if (sstatus != PJ_SUCCESS) return -45; sstatus = pj_thread_create(pool, NULL, &server_thread, &g_server, 0, 0, &g_server.thread); if (sstatus != PJ_SUCCESS) return -47; #else pj_cstr(&url, "http://www.google.com.sg"); param.timeout.sec = 0; param.timeout.msec = 50; #endif pj_http_headers_add_elmt2(¶m.headers, (char*)"Accept", (char*)"image/gif, image/x-xbitmap, image/jpeg, " "image/pjpeg, application/x-ms-application," " application/vnd.ms-xpsdocument, " "application/xaml+xml, " "application/x-ms-xbap, " "application/x-shockwave-flash, " "application/vnd.ms-excel, " "application/vnd.ms-powerpoint, " "application/msword, */*"); pj_http_headers_add_elmt2(¶m.headers, (char*)"Accept-Language", (char*)"en-sg"); pj_http_headers_add_elmt2(¶m.headers, (char*)"User-Agent", (char*)"Mozilla/4.0 (compatible; MSIE 7.0; " "Windows NT 6.0; SLCC1; " ".NET CLR 2.0.50727; " ".NET CLR 3.0.04506)"); if (pj_http_req_create(pool, &url, timer_heap, ioqueue, ¶m, &hcb, &http_req)) return -43; if (pj_http_req_start(http_req)) return -45; while (pj_http_req_is_running(http_req)) { pj_time_val delay = {0, 50}; pj_ioqueue_poll(ioqueue, &delay); pj_timer_heap_poll(timer_heap, NULL); } #ifdef USE_LOCAL_SERVER g_server.action = ACTION_REPLY; #endif timeout.sec = 0; timeout.msec = 10000; pj_http_req_set_timeout(http_req, &timeout); if (pj_http_req_start(http_req)) return -47; while (pj_http_req_is_running(http_req)) { pj_time_val delay = {0, 50}; pj_ioqueue_poll(ioqueue, &delay); pj_timer_heap_poll(timer_heap, NULL); } #ifdef USE_LOCAL_SERVER thread_quit = PJ_TRUE; pj_thread_join(g_server.thread); pj_sock_close(g_server.sock); #endif pj_http_req_destroy(http_req); pj_ioqueue_destroy(ioqueue); pj_timer_heap_destroy(timer_heap); pj_pool_release(pool); return PJ_SUCCESS; }
static int init() { int i; pj_status_t status; CHECK( pj_init() ); CHECK( pjlib_util_init() ); CHECK( pjnath_init() ); /* Check that server is specified */ if (!o.srv_addr) { printf("Error: server must be specified\n"); return PJ_EINVAL; } pj_caching_pool_init(&g.cp, &pj_pool_factory_default_policy, 0); g.pool = pj_pool_create(&g.cp.factory, "main", 1000, 1000, NULL); /* Init global STUN config */ pj_stun_config_init(&g.stun_config, &g.cp.factory, 0, NULL, NULL); /* Create global timer heap */ CHECK( pj_timer_heap_create(g.pool, 1000, &g.stun_config.timer_heap) ); /* Create global ioqueue */ CHECK( pj_ioqueue_create(g.pool, 16, &g.stun_config.ioqueue) ); /* * Create peers */ for (i=0; i<(int)PJ_ARRAY_SIZE(g.peer); ++i) { pj_stun_sock_cb stun_sock_cb; char name[] = "peer0"; pj_uint16_t port; pj_stun_sock_cfg ss_cfg; pj_str_t server; pj_bzero(&stun_sock_cb, sizeof(stun_sock_cb)); stun_sock_cb.on_rx_data = &stun_sock_on_rx_data; stun_sock_cb.on_status = &stun_sock_on_status; g.peer[i].mapped_addr.addr.sa_family = pj_AF_INET(); pj_stun_sock_cfg_default(&ss_cfg); #if 1 /* make reading the log easier */ ss_cfg.ka_interval = 300; #endif name[strlen(name)-1] = '0'+i; status = pj_stun_sock_create(&g.stun_config, name, pj_AF_INET(), &stun_sock_cb, &ss_cfg, &g.peer[i], &g.peer[i].stun_sock); if (status != PJ_SUCCESS) { my_perror("pj_stun_sock_create()", status); return status; } if (o.stun_server) { server = pj_str(o.stun_server); port = PJ_STUN_PORT; } else { server = pj_str(o.srv_addr); port = (pj_uint16_t)(o.srv_port?atoi(o.srv_port):PJ_STUN_PORT); } status = pj_stun_sock_start(g.peer[i].stun_sock, &server, port, NULL); if (status != PJ_SUCCESS) { my_perror("pj_stun_sock_start()", status); return status; } } /* Start the worker thread */ CHECK( pj_thread_create(g.pool, "stun", &worker_thread, NULL, 0, 0, &g.thread) ); return PJ_SUCCESS; }
int dummy_function() { pj_caching_pool cp; sprintf(NULL, "%d", 0); rand(); #ifdef HAS_PJLIB pj_init(); pj_caching_pool_init(&cp, NULL, 0); pj_array_erase(NULL, 0, 0, 0); pj_create_unique_string(NULL, NULL); pj_hash_create(NULL, 0); pj_hash_get(NULL, NULL, 0, NULL); pj_hash_set(NULL, NULL, NULL, 0, 0, NULL); pj_ioqueue_create(NULL, 0, NULL); pj_ioqueue_register_sock(NULL, NULL, 0, NULL, NULL, NULL); pj_pool_alloc(NULL, 0); pj_timer_heap_create(NULL, 0, NULL); #endif #ifdef HAS_PJLIB_STUN pjstun_get_mapped_addr(&cp.factory, 0, NULL, NULL, 80, NULL, 80, NULL); #endif #ifdef HAS_PJLIB_GETOPT pj_getopt_long(0, NULL, NULL, NULL, NULL); #endif #ifdef HAS_PJLIB_XML pj_xml_parse(NULL, NULL, 100); pj_xml_print(NULL, NULL, 10, PJ_FALSE); pj_xml_clone(NULL, NULL); pj_xml_node_new(NULL, NULL); pj_xml_attr_new(NULL, NULL, NULL); pj_xml_add_node(NULL, NULL); pj_xml_add_attr(NULL, NULL); pj_xml_find_node(NULL, NULL); pj_xml_find_next_node(NULL, NULL, NULL); pj_xml_find_attr(NULL, NULL, NULL); pj_xml_find(NULL, NULL, NULL, NULL); #endif #ifdef HAS_PJLIB_SCANNER pj_cis_buf_init(NULL); pj_cis_init(NULL, NULL); pj_cis_dup(NULL, NULL); pj_cis_add_alpha(NULL); pj_cis_add_str(NULL, NULL); pj_scan_init(NULL, NULL, 0, 0, NULL); pj_scan_fini(NULL); pj_scan_peek(NULL, NULL, NULL); pj_scan_peek_n(NULL, 0, NULL); pj_scan_peek_until(NULL, NULL, NULL); pj_scan_get(NULL, NULL, NULL); pj_scan_get_unescape(NULL, NULL, NULL); pj_scan_get_quote(NULL, 0, 0, NULL); pj_scan_get_n(NULL, 0, NULL); pj_scan_get_char(NULL); pj_scan_get_until(NULL, NULL, NULL); pj_scan_strcmp(NULL, NULL, 0); pj_scan_stricmp(NULL, NULL, 0); pj_scan_stricmp_alnum(NULL, NULL, 0); pj_scan_get_newline(NULL); pj_scan_restore_state(NULL, NULL); #endif #ifdef HAS_PJLIB_DNS pj_dns_make_query(NULL, NULL, 0, 0, NULL); pj_dns_parse_packet(NULL, NULL, 0, NULL); pj_dns_packet_dup(NULL, NULL, 0, NULL); #endif #ifdef HAS_PJLIB_RESOLVER pj_dns_resolver_create(NULL, NULL, 0, NULL, NULL, NULL); pj_dns_resolver_set_ns(NULL, 0, NULL, NULL); pj_dns_resolver_handle_events(NULL, NULL); pj_dns_resolver_destroy(NULL, 0); pj_dns_resolver_start_query(NULL, NULL, 0, 0, NULL, NULL, NULL); pj_dns_resolver_cancel_query(NULL, 0); pj_dns_resolver_add_entry(NULL, NULL, 0); #endif #ifdef HAS_PJLIB_SRV_RESOLVER pj_dns_srv_resolve(NULL, NULL, 0, NULL, NULL, PJ_FALSE, NULL, NULL); #endif #ifdef HAS_PJLIB_CRC32 pj_crc32_init(NULL); pj_crc32_update(NULL, NULL, 0); pj_crc32_final(NULL); #endif #ifdef HAS_PJLIB_HMAC_MD5 pj_hmac_md5(NULL, 0, NULL, 0, NULL); #endif #ifdef HAS_PJLIB_HMAC_SHA1 pj_hmac_sha1(NULL, 0, NULL, 0, NULL); #endif #ifdef HAS_PJNATH_STUN pj_stun_session_create(NULL, NULL, NULL, PJ_FALSE, NULL); pj_stun_session_destroy(NULL); pj_stun_session_set_credential(NULL, NULL); pj_stun_session_create_req(NULL, 0, NULL, NULL); pj_stun_session_create_ind(NULL, 0, NULL); pj_stun_session_create_res(NULL, NULL, 0, NULL, NULL); pj_stun_session_send_msg(NULL, PJ_FALSE, NULL, 0, NULL); #endif #ifdef HAS_PJNATH_ICE pj_ice_strans_create(NULL, NULL, 0, NULL, NULL, NULL); pj_ice_strans_set_stun_domain(NULL, NULL, NULL); pj_ice_strans_create_comp(NULL, 0, 0, NULL); pj_ice_strans_add_cand(NULL, 0, PJ_ICE_CAND_TYPE_HOST, 0, NULL, PJ_FALSE); pj_ice_strans_init_ice(NULL, PJ_ICE_SESS_ROLE_CONTROLLED, NULL, NULL); pj_ice_strans_start_ice(NULL, NULL, NULL, 0, NULL); pj_ice_strans_stop_ice(NULL); pj_ice_strans_sendto(NULL, 0, NULL, 0, NULL, 0); #endif #ifdef HAS_PJSIP_CORE_MSG_ELEM /* Parameter container */ pjsip_param_find(NULL, NULL); pjsip_param_print_on(NULL, NULL, 0, NULL, NULL, 0); /* SIP URI */ pjsip_sip_uri_create(NULL, 0); pjsip_name_addr_create(NULL); /* TEL URI */ pjsip_tel_uri_create(NULL); /* Message and headers */ pjsip_msg_create(NULL, PJSIP_REQUEST_MSG); pjsip_msg_print(NULL, NULL, 0); pjsip_accept_hdr_create(NULL); pjsip_allow_hdr_create(NULL); pjsip_cid_hdr_create(NULL); pjsip_clen_hdr_create(NULL); pjsip_cseq_hdr_create(NULL); pjsip_contact_hdr_create(NULL); pjsip_ctype_hdr_create(NULL); pjsip_expires_hdr_create(NULL, 0); pjsip_from_hdr_create(NULL); pjsip_max_fwd_hdr_create(NULL, 0); pjsip_min_expires_hdr_create(NULL, 0); pjsip_rr_hdr_create(NULL); pjsip_require_hdr_create(NULL); pjsip_retry_after_hdr_create(NULL, 0); pjsip_supported_hdr_create(NULL); pjsip_unsupported_hdr_create(NULL); pjsip_via_hdr_create(NULL); pjsip_warning_hdr_create(NULL, 0, NULL, NULL); pjsip_parse_uri(NULL, NULL, 0, 0); pjsip_parse_msg(NULL, NULL, 0, NULL); pjsip_parse_rdata(NULL, 0, NULL); pjsip_find_msg(NULL, 0, 0, NULL); #endif #ifdef HAS_PJSIP_CORE pjsip_endpt_create(NULL, NULL, NULL); pjsip_tpmgr_create(NULL, NULL, NULL, NULL, NULL); pjsip_tpmgr_destroy(NULL); pjsip_transport_send(NULL, NULL, NULL, 0, NULL, NULL); #endif #ifdef HAS_PJSIP_CORE_MSG_UTIL pjsip_endpt_create_request(NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, NULL, NULL); pjsip_endpt_create_request_from_hdr(NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1, NULL, NULL); pjsip_endpt_create_response(NULL, NULL, -1, NULL, NULL); pjsip_endpt_create_ack(NULL, NULL, NULL, NULL); pjsip_endpt_create_cancel(NULL, NULL, NULL); pjsip_get_request_dest(NULL, NULL); pjsip_endpt_send_request_stateless(NULL, NULL, NULL, NULL); pjsip_get_response_addr(NULL, NULL, NULL); pjsip_endpt_send_response(NULL, NULL, NULL, NULL, NULL); pjsip_endpt_respond_stateless(NULL, NULL, -1, NULL, NULL, NULL); #endif #ifdef HAS_PJSIP_UDP_TRANSPORT pjsip_udp_transport_start(NULL, NULL, NULL, 1, NULL); #endif #ifdef HAS_PJSIP_TCP_TRANSPORT pjsip_tcp_transport_start(NULL, NULL, 1, NULL); #endif #ifdef HAS_PJSIP_TLS_TRANSPORT pjsip_tls_transport_start(NULL, NULL, NULL, NULL, 0, NULL); #endif #ifdef HAS_PJSIP_TRANSACTION pjsip_tsx_layer_init_module(NULL); pjsip_tsx_layer_destroy(); pjsip_tsx_create_uac(NULL, NULL, NULL); pjsip_tsx_create_uas(NULL, NULL, NULL); pjsip_tsx_recv_msg(NULL, NULL); pjsip_tsx_send_msg(NULL, NULL); pjsip_tsx_terminate(NULL, 200); pjsip_endpt_send_request(NULL, NULL, -1, NULL, NULL); pjsip_endpt_respond(NULL, NULL, NULL, -1, NULL, NULL, NULL, NULL); #endif #ifdef HAS_PJMEDIA_SDP pjmedia_sdp_parse(NULL, NULL, 1024, NULL); pjmedia_sdp_print(NULL, NULL, 1024); pjmedia_sdp_validate(NULL); pjmedia_sdp_session_clone(NULL, NULL); pjmedia_sdp_session_cmp(NULL, NULL, 0); pjmedia_sdp_attr_to_rtpmap(NULL, NULL, NULL); pjmedia_sdp_attr_get_fmtp(NULL, NULL); pjmedia_sdp_attr_get_rtcp(NULL, NULL); pjmedia_sdp_conn_clone(NULL, NULL); pjmedia_sdp_media_clone(NULL, NULL); pjmedia_sdp_media_find_attr(NULL, NULL, NULL); #endif #ifdef HAS_PJMEDIA_SDP_NEGOTIATOR pjmedia_sdp_neg_create_w_local_offer(NULL, NULL, NULL); pjmedia_sdp_neg_create_w_remote_offer(NULL, NULL, NULL, NULL); pjmedia_sdp_neg_get_state(NULL); pjmedia_sdp_neg_negotiate(NULL, NULL, PJ_FALSE); #endif #ifdef HAS_PJSIP_UA_LAYER pjsip_ua_init_module(NULL, NULL); pjsip_ua_destroy(); pjsip_dlg_create_uac(NULL, NULL, NULL, NULL, NULL, NULL); pjsip_dlg_create_uas_and_inc_lock(NULL, NULL, NULL, NULL); pjsip_dlg_terminate(NULL); pjsip_dlg_set_route_set(NULL, NULL); pjsip_dlg_create_request(NULL, NULL, -1, NULL); pjsip_dlg_send_request(NULL, NULL, -1, NULL); pjsip_dlg_create_response(NULL, NULL, -1, NULL, NULL); pjsip_dlg_modify_response(NULL, NULL, -1, NULL); pjsip_dlg_send_response(NULL, NULL, NULL); pjsip_dlg_respond(NULL, NULL, -1, NULL, NULL, NULL); #endif #ifdef HAS_PJSIP_AUTH_CLIENT pjsip_auth_clt_init(NULL, NULL, NULL, 0); pjsip_auth_clt_clone(NULL, NULL, NULL); pjsip_auth_clt_set_credentials(NULL, 0, NULL); pjsip_auth_clt_init_req(NULL, NULL); pjsip_auth_clt_reinit_req(NULL, NULL, NULL, NULL); #endif #ifdef HAS_PJSIP_INV_SESSION pjsip_inv_usage_init(NULL, NULL); pjsip_inv_create_uac(NULL, NULL, 0, NULL); pjsip_inv_verify_request(NULL, NULL, NULL, NULL, NULL, NULL); pjsip_inv_create_uas(NULL, NULL, NULL, 0, NULL); pjsip_inv_terminate(NULL, 200, PJ_FALSE); pjsip_inv_invite(NULL, NULL); pjsip_inv_initial_answer(NULL, NULL, 200, NULL, NULL, NULL); pjsip_inv_answer(NULL, 200, NULL, NULL, NULL); pjsip_inv_end_session(NULL, 200, NULL, NULL); pjsip_inv_reinvite(NULL, NULL, NULL, NULL); pjsip_inv_update(NULL, NULL, NULL, NULL); pjsip_inv_send_msg(NULL, NULL); pjsip_dlg_get_inv_session(NULL); //pjsip_tsx_get_inv_session(NULL); pjsip_inv_state_name(PJSIP_INV_STATE_NULL); #endif #ifdef HAS_PJSIP_REGC //pjsip_regc_get_module(); pjsip_regc_create(NULL, NULL, NULL, NULL); pjsip_regc_destroy(NULL); pjsip_regc_get_info(NULL, NULL); pjsip_regc_get_pool(NULL); pjsip_regc_init(NULL, NULL, NULL, NULL, 0, NULL, 600); pjsip_regc_set_credentials(NULL, 1, NULL); pjsip_regc_set_route_set(NULL, NULL); pjsip_regc_register(NULL, PJ_TRUE, NULL); pjsip_regc_unregister(NULL, NULL); pjsip_regc_update_contact(NULL, 10, NULL); pjsip_regc_update_expires(NULL, 600); pjsip_regc_send(NULL, NULL); #endif #ifdef HAS_PJSIP_EVENT_FRAMEWORK pjsip_evsub_init_module(NULL); pjsip_evsub_instance(); pjsip_evsub_register_pkg(NULL, NULL, 30, 10, NULL); pjsip_evsub_create_uac(NULL, NULL, NULL, 10, NULL); pjsip_evsub_create_uas(NULL, NULL, NULL, 10, NULL); pjsip_evsub_terminate(NULL, PJ_FALSE); pjsip_evsub_get_state(NULL); pjsip_evsub_get_state_name(NULL); pjsip_evsub_initiate(NULL, NULL, -1, NULL); pjsip_evsub_accept(NULL, NULL, 200, NULL); pjsip_evsub_notify(NULL, PJSIP_EVSUB_STATE_ACTIVE, NULL, NULL, NULL); pjsip_evsub_current_notify(NULL, NULL); pjsip_evsub_send_request(NULL, NULL); pjsip_tsx_get_evsub(NULL); pjsip_evsub_set_mod_data(NULL, 1, NULL); pjsip_evsub_get_mod_data(NULL, 1); #endif #ifdef HAS_PJSIP_CALL_TRANSFER pjsip_xfer_init_module(NULL); pjsip_xfer_create_uac(NULL, NULL, NULL); pjsip_xfer_create_uas(NULL, NULL, NULL, NULL); pjsip_xfer_initiate(NULL, NULL, NULL); pjsip_xfer_accept(NULL, NULL, 200, NULL); pjsip_xfer_notify(NULL, PJSIP_EVSUB_STATE_ACTIVE, 200, NULL, NULL); pjsip_xfer_current_notify(NULL, NULL); pjsip_xfer_send_request(NULL, NULL); #endif #ifdef HAS_PJSIP_PRESENCE pjsip_pres_init_module(NULL, NULL); pjsip_pres_instance(); pjsip_pres_create_uac(NULL, NULL, 0, NULL); pjsip_pres_create_uas(NULL, NULL, NULL, NULL); pjsip_pres_terminate(NULL, PJ_FALSE); pjsip_pres_initiate(NULL, 100, NULL); pjsip_pres_accept(NULL, NULL, 200, NULL); pjsip_pres_notify(NULL, PJSIP_EVSUB_STATE_ACTIVE, NULL, NULL, NULL); pjsip_pres_current_notify(NULL, NULL); pjsip_pres_send_request(NULL, NULL); pjsip_pres_get_status(NULL, NULL); pjsip_pres_set_status(NULL, NULL); #endif #ifdef HAS_PJSIP_IS_COMPOSING pjsip_iscomposing_create_xml(NULL, PJ_TRUE, NULL, NULL, 0); pjsip_iscomposing_create_body(NULL, PJ_TRUE, NULL, NULL, 0); pjsip_iscomposing_parse(NULL, NULL, 0, NULL, NULL, NULL, NULL); #endif #ifdef HAS_PJMEDIA pjmedia_endpt_create(NULL, NULL, 1, NULL); pjmedia_endpt_destroy(NULL); pjmedia_endpt_create_sdp(NULL, NULL, 1, NULL, NULL); #endif #ifdef HAS_PJMEDIA_EC pjmedia_echo_create(NULL, 0, 0, 0, 0, 0, NULL); pjmedia_echo_destroy(NULL); pjmedia_echo_playback(NULL, NULL); pjmedia_echo_capture(NULL, NULL, 0); pjmedia_echo_cancel(NULL, NULL, NULL, 0, NULL); #endif #ifdef HAS_PJMEDIA_SND_DEV pjmedia_snd_init(NULL); pjmedia_snd_get_dev_count(); pjmedia_snd_get_dev_info(0); pjmedia_snd_open(-1, -1, 8000, 1, 80, 16, NULL, NULL, NULL, NULL); pjmedia_snd_open_rec(-1, 8000, 1, 160, 16, NULL, NULL, NULL); pjmedia_snd_open_player(-1, 8000, 1, 160, 16, NULL, NULL, NULL); pjmedia_snd_stream_start(NULL); pjmedia_snd_stream_stop(NULL); pjmedia_snd_stream_close(NULL); pjmedia_snd_deinit(); #endif #ifdef HAS_PJMEDIA_SND_PORT pjmedia_snd_port_create(NULL, -1, -1, 8000, 1, 180, 16, 0, NULL); pjmedia_snd_port_create_rec(NULL, -1, 8000, 1, 160, 16, 0, NULL); pjmedia_snd_port_create_player(NULL, -1, 8000, 1, 160, 16, 0, NULL); pjmedia_snd_port_destroy(NULL); pjmedia_snd_port_get_snd_stream(NULL); pjmedia_snd_port_connect(NULL, NULL); pjmedia_snd_port_get_port(NULL); pjmedia_snd_port_disconnect(NULL); #endif #ifdef HAS_PJMEDIA_RESAMPLE pjmedia_resample_create(NULL, PJ_TRUE, PJ_TRUE, 0, 0, 0, 0, NULL); pjmedia_resample_run(NULL, NULL, NULL); #endif #ifdef HAS_PJMEDIA_SILENCE_DET pjmedia_silence_det_create(NULL, 8000, 80, NULL); pjmedia_silence_det_detect(NULL, NULL, 0, NULL); pjmedia_silence_det_apply(NULL, 0); #endif #ifdef HAS_PJMEDIA_PLC pjmedia_plc_create(NULL, 8000, 80, 0, NULL); pjmedia_plc_save(NULL, NULL); pjmedia_plc_generate(NULL, NULL); #endif #ifdef HAS_PJMEDIA_CONFERENCE pjmedia_conf_create(NULL, 10, 8000, 1, 160, 16, 0, NULL); pjmedia_conf_destroy(NULL); pjmedia_conf_get_master_port(NULL); pjmedia_conf_add_port(NULL, NULL, NULL, NULL, NULL); pjmedia_conf_configure_port(NULL, 1, 0, 0); pjmedia_conf_connect_port(NULL, 0, 0, 0); pjmedia_conf_disconnect_port(NULL, 0, 0); pjmedia_conf_remove_port(NULL, 0); pjmedia_conf_enum_ports(NULL, NULL, NULL); pjmedia_conf_get_port_info(NULL, 0, NULL); pjmedia_conf_get_ports_info(NULL, NULL, NULL); pjmedia_conf_get_signal_level(NULL, 0, NULL, NULL); pjmedia_conf_adjust_rx_level(NULL, 0, 0); pjmedia_conf_adjust_tx_level(NULL, 0, 0); #endif #ifdef HAS_PJMEDIA_MASTER_PORT pjmedia_master_port_create(NULL, NULL, NULL, 0, NULL); pjmedia_master_port_start(NULL); pjmedia_master_port_stop(NULL); pjmedia_master_port_set_uport(NULL, NULL); pjmedia_master_port_get_uport(NULL); pjmedia_master_port_set_dport(NULL, NULL); pjmedia_master_port_get_dport(NULL); pjmedia_master_port_destroy(NULL, PJ_FALSE); #endif #ifdef HAS_PJMEDIA_RTP pjmedia_rtp_session_init(NULL, 0, 0); pjmedia_rtp_encode_rtp(NULL, 0, 0, 0, 0, NULL, NULL); pjmedia_rtp_decode_rtp(NULL, NULL, 0, NULL, NULL, NULL); pjmedia_rtp_session_update(NULL, NULL, NULL); #endif #ifdef HAS_PJMEDIA_RTCP pjmedia_rtcp_init(NULL, NULL, 0, 0, 0); pjmedia_rtcp_get_ntp_time(NULL, NULL); pjmedia_rtcp_fini(NULL); pjmedia_rtcp_rx_rtp(NULL, 0, 0, 0); pjmedia_rtcp_tx_rtp(NULL, 0); pjmedia_rtcp_rx_rtcp(NULL, NULL, 0); pjmedia_rtcp_build_rtcp(NULL, NULL, NULL); #endif #ifdef HAS_PJMEDIA_JBUF pjmedia_jbuf_create(NULL, NULL, 0, 0, 0, NULL); pjmedia_jbuf_set_fixed(NULL, 0); pjmedia_jbuf_set_adaptive(NULL, 0, 0, 0); pjmedia_jbuf_destroy(NULL); pjmedia_jbuf_put_frame(NULL, NULL, 0, 0); pjmedia_jbuf_get_frame(NULL, NULL, NULL); #endif #ifdef HAS_PJMEDIA_STREAM pjmedia_stream_create(NULL, NULL, NULL, NULL, NULL, NULL); pjmedia_stream_destroy(NULL); pjmedia_stream_get_port(NULL, NULL); pjmedia_stream_get_transport(NULL); pjmedia_stream_start(NULL); pjmedia_stream_get_stat(NULL, NULL); pjmedia_stream_pause(NULL, PJMEDIA_DIR_ENCODING); pjmedia_stream_resume(NULL, PJMEDIA_DIR_ENCODING); pjmedia_stream_dial_dtmf(NULL, NULL); pjmedia_stream_check_dtmf(NULL); pjmedia_stream_get_dtmf(NULL, NULL, NULL); #endif #ifdef HAS_PJMEDIA_TONEGEN pjmedia_tonegen_create(NULL, 0, 0, 0, 0, 0, NULL); pjmedia_tonegen_is_busy(NULL); pjmedia_tonegen_stop(NULL); pjmedia_tonegen_play(NULL, 0, NULL, 0); pjmedia_tonegen_play_digits(NULL, 0, NULL, 0); pjmedia_tonegen_get_digit_map(NULL, NULL); pjmedia_tonegen_set_digit_map(NULL, NULL); #endif #ifdef HAS_PJMEDIA_UDP_TRANSPORT pjmedia_transport_udp_create(NULL, NULL, 0, 0, NULL); pjmedia_transport_udp_close(NULL); #endif #ifdef HAS_PJMEDIA_FILE_PLAYER pjmedia_wav_player_port_create(NULL, NULL, 0, 0, 0, NULL); pjmedia_wav_player_port_set_pos(NULL, 0); pjmedia_wav_player_port_get_pos(NULL); pjmedia_wav_player_set_eof_cb(NULL, NULL, NULL); #endif #ifdef HAS_PJMEDIA_FILE_CAPTURE pjmedia_wav_writer_port_create(NULL, NULL, 8000, 1, 80, 16, 0, 0, NULL); pjmedia_wav_writer_port_get_pos(NULL); pjmedia_wav_writer_port_set_cb(NULL, 0, NULL, NULL); #endif #ifdef HAS_PJMEDIA_MEM_PLAYER pjmedia_mem_player_create(NULL, NULL, 1000, 8000, 1, 80, 16, 0, NULL); #endif #ifdef HAS_PJMEDIA_MEM_CAPTURE pjmedia_mem_capture_create(NULL, NULL, 1000, 8000, 1, 80, 16, 0, NULL); #endif #ifdef HAS_PJMEDIA_ICE pjmedia_ice_create(NULL, NULL, 0, NULL, NULL); pjmedia_ice_destroy(NULL); pjmedia_ice_start_init(NULL, 0, NULL, NULL, NULL); pjmedia_ice_init_ice(NULL, PJ_ICE_SESS_ROLE_CONTROLLED, NULL, NULL); pjmedia_ice_modify_sdp(NULL, NULL, NULL); pjmedia_ice_start_ice(NULL, NULL, NULL, 0); pjmedia_ice_stop_ice(NULL); #endif #ifdef HAS_PJMEDIA_G711_CODEC pjmedia_codec_g711_init(NULL); pjmedia_codec_g711_deinit(); #endif #ifdef HAS_PJMEDIA_GSM_CODEC pjmedia_codec_gsm_init(NULL); pjmedia_codec_gsm_deinit(); #endif #ifdef HAS_PJMEDIA_SPEEX_CODEC pjmedia_codec_speex_init(NULL, 0, 0, 0); pjmedia_codec_speex_deinit(); #endif #ifdef HAS_PJMEDIA_ILBC_CODEC pjmedia_codec_ilbc_init(NULL, 0); pjmedia_codec_ilbc_deinit(); #endif return 0; }