Re #1643: Code restructure+add callback to support symbian gui app
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@4461 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
83bded706b
commit
bc9c677287
|
@ -32,6 +32,9 @@ OPTION GCCE -x c++
|
|||
// PJLIB-UTIL files
|
||||
//
|
||||
SOURCE base64.c
|
||||
SOURCE cli.c
|
||||
SOURCE cli_console.c
|
||||
SOURCE cli_telnet.c
|
||||
SOURCE crc32.c
|
||||
SOURCE dns.c
|
||||
SOURCE dns_dump.c
|
||||
|
|
|
@ -63,4 +63,7 @@
|
|||
/* HTTP */
|
||||
#include <pjlib-util/http_client.h>
|
||||
|
||||
/** CLI Telnet **/
|
||||
#include <pjlib-util/cli_telnet.h>
|
||||
|
||||
#endif /* __PJLIB_UTIL_H__ */
|
||||
|
|
|
@ -34,6 +34,31 @@ PJ_BEGIN_DECL
|
|||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* This structure contains the information about the telnet.
|
||||
* Application will get updated information each time the telnet is started/
|
||||
* restarted.
|
||||
*/
|
||||
typedef struct pj_cli_telnet_info
|
||||
{
|
||||
/**
|
||||
* The telnet's ip address.
|
||||
*/
|
||||
pj_str_t ip_address;
|
||||
|
||||
/**
|
||||
* The telnet's port number.
|
||||
*/
|
||||
pj_uint16_t port;
|
||||
} pj_cli_telnet_info;
|
||||
|
||||
/**
|
||||
* This specifies the callback called when telnet is started
|
||||
*
|
||||
* @param telnet_info The telnet runtime information.
|
||||
*
|
||||
*/
|
||||
typedef void (*pj_cli_telnet_on_started)(pj_cli_telnet_info *telnet_info);
|
||||
|
||||
/**
|
||||
* This structure contains various options to instantiate the telnet daemon.
|
||||
|
@ -85,8 +110,14 @@ typedef struct pj_cli_telnet_cfg
|
|||
*/
|
||||
pj_str_t prompt_str;
|
||||
|
||||
} pj_cli_telnet_cfg;
|
||||
/**
|
||||
* Specify the pj_cli_telnet_on_started callback.
|
||||
*
|
||||
* Default: empty
|
||||
*/
|
||||
pj_cli_telnet_on_started on_started;
|
||||
|
||||
} pj_cli_telnet_cfg;
|
||||
|
||||
/**
|
||||
* Initialize pj_cli_telnet_cfg with its default values.
|
||||
|
|
|
@ -291,7 +291,7 @@
|
|||
* Default: 120
|
||||
*/
|
||||
#ifndef PJ_CLI_MAX_CMDBUF
|
||||
# define PJ_CLI_MAX_CMDBUF 120
|
||||
# define PJ_CLI_MAX_CMDBUF 512
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,15 @@
|
|||
#include <pj/except.h>
|
||||
#include <pjlib-util/errno.h>
|
||||
#include <pjlib-util/scanner.h>
|
||||
#include <pj/addr_resolv.h>
|
||||
#include <pj/compat/socket.h>
|
||||
|
||||
#if (defined(PJ_WIN32) && PJ_WIN32!=0) || \
|
||||
(defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0)
|
||||
|
||||
#define EADDRINUSE WSAEADDRINUSE
|
||||
|
||||
#endif
|
||||
|
||||
#define CLI_TELNET_BUF_SIZE 256
|
||||
|
||||
|
@ -44,6 +53,14 @@
|
|||
#endif
|
||||
|
||||
#define MAX_CLI_TELNET_OPTIONS 256
|
||||
/** Maximum retry on Telnet Restart **/
|
||||
#define MAX_RETRY_ON_TELNET_RESTART 100
|
||||
/** Minimum number of millisecond to wait before retrying to re-bind on
|
||||
* telnet restart **/
|
||||
#define MIN_WAIT_ON_TELNET_RESTART 20
|
||||
/** Maximum number of millisecod to wait before retrying to re-bind on
|
||||
* telnet restart **/
|
||||
#define MAX_WAIT_ON_TELNET_RESTART 1000
|
||||
|
||||
/**
|
||||
* This specify the state for the telnet option negotiation.
|
||||
|
@ -261,7 +278,7 @@ typedef struct cli_telnet_sess
|
|||
unsigned buf_len;
|
||||
} cli_telnet_sess;
|
||||
|
||||
struct cli_telnet_fe
|
||||
typedef struct cli_telnet_fe
|
||||
{
|
||||
pj_cli_front_end base;
|
||||
pj_pool_t *pool;
|
||||
|
@ -272,8 +289,8 @@ struct cli_telnet_fe
|
|||
pj_activesock_t *asock;
|
||||
pj_thread_t *worker_thread;
|
||||
pj_bool_t is_quitting;
|
||||
pj_mutex_t *mutex;
|
||||
};
|
||||
pj_mutex_t *mutex;
|
||||
} cli_telnet_fe;
|
||||
|
||||
/* Forward Declaration */
|
||||
static pj_status_t telnet_sess_send2(cli_telnet_sess *sess,
|
||||
|
@ -282,6 +299,9 @@ static pj_status_t telnet_sess_send2(cli_telnet_sess *sess,
|
|||
static pj_status_t telnet_sess_send(cli_telnet_sess *sess,
|
||||
const pj_str_t *str);
|
||||
|
||||
static pj_status_t telnet_start(cli_telnet_fe *fe);
|
||||
static pj_status_t telnet_restart(cli_telnet_fe *tfe);
|
||||
|
||||
/**
|
||||
* Return the number of characters between the current cursor position
|
||||
* to the end of line.
|
||||
|
@ -645,7 +665,7 @@ static void send_prompt_str(cli_telnet_sess *sess)
|
|||
{
|
||||
pj_str_t send_data;
|
||||
char data_str[128];
|
||||
struct cli_telnet_fe *fe = (struct cli_telnet_fe *)sess->base.fe;
|
||||
cli_telnet_fe *fe = (cli_telnet_fe *)sess->base.fe;
|
||||
|
||||
send_data.ptr = &data_str[0];
|
||||
send_data.slen = 0;
|
||||
|
@ -669,7 +689,7 @@ static void send_err_arg(cli_telnet_sess *sess,
|
|||
char data_str[256];
|
||||
unsigned len;
|
||||
unsigned i;
|
||||
struct cli_telnet_fe *fe = (struct cli_telnet_fe *)sess->base.fe;
|
||||
cli_telnet_fe *fe = (cli_telnet_fe *)sess->base.fe;
|
||||
|
||||
send_data.ptr = &data_str[0];
|
||||
send_data.slen = 0;
|
||||
|
@ -743,7 +763,7 @@ static void send_ambi_arg(cli_telnet_sess *sess,
|
|||
unsigned len;
|
||||
pj_str_t send_data;
|
||||
char data[1028];
|
||||
struct cli_telnet_fe *fe = (struct cli_telnet_fe *)sess->base.fe;
|
||||
cli_telnet_fe *fe = (cli_telnet_fe *)sess->base.fe;
|
||||
const pj_cli_hint_info *hint = info->hint;
|
||||
out_parse_state parse_state = OP_NORMAL;
|
||||
pj_ssize_t max_length = 0;
|
||||
|
@ -1318,7 +1338,7 @@ static pj_status_t telnet_sess_send2(cli_telnet_sess *sess,
|
|||
static void telnet_sess_destroy(pj_cli_sess *sess)
|
||||
{
|
||||
cli_telnet_sess *tsess = (cli_telnet_sess *)sess;
|
||||
pj_mutex_t *mutex = ((struct cli_telnet_fe *)sess->fe)->mutex;
|
||||
pj_mutex_t *mutex = ((cli_telnet_fe *)sess->fe)->mutex;
|
||||
|
||||
pj_mutex_lock(mutex);
|
||||
pj_list_erase(sess);
|
||||
|
@ -1334,7 +1354,7 @@ static void telnet_sess_destroy(pj_cli_sess *sess)
|
|||
static void telnet_fe_write_log(pj_cli_front_end *fe, int level,
|
||||
const char *data, int len)
|
||||
{
|
||||
struct cli_telnet_fe * tfe = (struct cli_telnet_fe *)fe;
|
||||
cli_telnet_fe *tfe = (cli_telnet_fe *)fe;
|
||||
pj_cli_sess *sess;
|
||||
|
||||
pj_mutex_lock(tfe->mutex);
|
||||
|
@ -1357,7 +1377,7 @@ static void telnet_fe_write_log(pj_cli_front_end *fe, int level,
|
|||
|
||||
static void telnet_fe_destroy(pj_cli_front_end *fe)
|
||||
{
|
||||
struct cli_telnet_fe *tfe = (struct cli_telnet_fe *)fe;
|
||||
cli_telnet_fe *tfe = (cli_telnet_fe *)fe;
|
||||
pj_cli_sess *sess;
|
||||
|
||||
tfe->is_quitting = PJ_TRUE;
|
||||
|
@ -1391,7 +1411,7 @@ static void telnet_fe_destroy(pj_cli_front_end *fe)
|
|||
|
||||
static int poll_worker_thread(void *p)
|
||||
{
|
||||
struct cli_telnet_fe *fe = (struct cli_telnet_fe *)p;
|
||||
cli_telnet_fe *fe = (cli_telnet_fe *)p;
|
||||
|
||||
while (!fe->is_quitting) {
|
||||
pj_time_val delay = {0, 50};
|
||||
|
@ -1408,9 +1428,10 @@ static pj_bool_t telnet_sess_on_data_sent(pj_activesock_t *asock,
|
|||
cli_telnet_sess *sess = (cli_telnet_sess *)
|
||||
pj_activesock_get_user_data(asock);
|
||||
|
||||
PJ_UNUSED_ARG(op_key);
|
||||
PJ_UNUSED_ARG(op_key);
|
||||
|
||||
if (sent <= 0) {
|
||||
TRACE_((THIS_FILE, "Error On data send"));
|
||||
pj_cli_sess_end_session(&sess->base);
|
||||
return PJ_FALSE;
|
||||
}
|
||||
|
@ -1441,21 +1462,21 @@ static pj_bool_t telnet_sess_on_data_read(pj_activesock_t *asock,
|
|||
{
|
||||
cli_telnet_sess *sess = (cli_telnet_sess *)
|
||||
pj_activesock_get_user_data(asock);
|
||||
struct cli_telnet_fe *tfe = (struct cli_telnet_fe *)sess->base.fe;
|
||||
cli_telnet_fe *tfe = (cli_telnet_fe *)sess->base.fe;
|
||||
unsigned char *cdata = (unsigned char*)data;
|
||||
pj_status_t is_valid = PJ_TRUE;
|
||||
|
||||
PJ_UNUSED_ARG(size);
|
||||
PJ_UNUSED_ARG(remainder);
|
||||
|
||||
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
|
||||
pj_cli_sess_end_session(&sess->base);
|
||||
return PJ_FALSE;
|
||||
}
|
||||
|
||||
if (tfe->is_quitting)
|
||||
return PJ_FALSE;
|
||||
|
||||
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
|
||||
TRACE_((THIS_FILE, "Error on data read %d", status));
|
||||
return PJ_FALSE;
|
||||
}
|
||||
|
||||
pj_mutex_lock(sess->smutex);
|
||||
|
||||
switch (sess->parse_state) {
|
||||
|
@ -1551,13 +1572,14 @@ static pj_bool_t telnet_sess_on_data_read(pj_activesock_t *asock,
|
|||
static pj_bool_t telnet_fe_on_accept(pj_activesock_t *asock,
|
||||
pj_sock_t newsock,
|
||||
const pj_sockaddr_t *src_addr,
|
||||
int src_addr_len)
|
||||
int src_addr_len,
|
||||
pj_status_t status)
|
||||
{
|
||||
struct cli_telnet_fe *fe = (struct cli_telnet_fe *)
|
||||
pj_activesock_get_user_data(asock);
|
||||
cli_telnet_fe *fe = (cli_telnet_fe *) pj_activesock_get_user_data(asock);
|
||||
|
||||
pj_status_t sstatus;
|
||||
pj_pool_t *pool;
|
||||
cli_telnet_sess *sess;
|
||||
cli_telnet_sess *sess = NULL;
|
||||
pj_activesock_cb asock_cb;
|
||||
|
||||
PJ_UNUSED_ARG(src_addr);
|
||||
|
@ -1566,6 +1588,14 @@ static pj_bool_t telnet_fe_on_accept(pj_activesock_t *asock,
|
|||
if (fe->is_quitting)
|
||||
return PJ_FALSE;
|
||||
|
||||
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
|
||||
TRACE_((THIS_FILE, "Error on data accept %d", status));
|
||||
if (status == PJ_ESOCKETSTOP)
|
||||
telnet_restart(fe);
|
||||
|
||||
return PJ_FALSE;
|
||||
}
|
||||
|
||||
/* An incoming connection is accepted, create a new session */
|
||||
pool = pj_pool_create(fe->pool->factory, "telnet_sess",
|
||||
PJ_CLI_TELNET_POOL_SIZE, PJ_CLI_TELNET_POOL_INC,
|
||||
|
@ -1657,19 +1687,16 @@ PJ_DEF(pj_status_t) pj_cli_telnet_create(pj_cli_t *cli,
|
|||
pj_cli_telnet_cfg *param,
|
||||
pj_cli_front_end **p_fe)
|
||||
{
|
||||
struct cli_telnet_fe *fe;
|
||||
cli_telnet_fe *fe;
|
||||
pj_pool_t *pool;
|
||||
pj_sock_t sock = PJ_INVALID_SOCKET;
|
||||
pj_activesock_cb asock_cb;
|
||||
pj_sockaddr_in addr;
|
||||
pj_status_t sstatus;
|
||||
pj_status_t status;
|
||||
|
||||
PJ_ASSERT_RETURN(cli, PJ_EINVAL);
|
||||
|
||||
pool = pj_pool_create(pj_cli_get_param(cli)->pf, "telnet_fe",
|
||||
PJ_CLI_TELNET_POOL_SIZE, PJ_CLI_TELNET_POOL_INC,
|
||||
NULL);
|
||||
fe = PJ_POOL_ZALLOC_T(pool, struct cli_telnet_fe);
|
||||
fe = PJ_POOL_ZALLOC_T(pool, cli_telnet_fe);
|
||||
if (!fe)
|
||||
return PJ_ENOMEM;
|
||||
|
||||
|
@ -1687,42 +1714,86 @@ PJ_DEF(pj_status_t) pj_cli_telnet_create(pj_cli_t *cli,
|
|||
fe->base.op->on_destroy = &telnet_fe_destroy;
|
||||
fe->pool = pool;
|
||||
|
||||
if (!fe->cfg.ioqueue) {
|
||||
if (!fe->cfg.ioqueue) {
|
||||
/* Create own ioqueue if application doesn't supply one */
|
||||
sstatus = pj_ioqueue_create(pool, 8, &fe->cfg.ioqueue);
|
||||
if (sstatus != PJ_SUCCESS)
|
||||
status = pj_ioqueue_create(pool, 8, &fe->cfg.ioqueue);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
fe->own_ioqueue = PJ_TRUE;
|
||||
}
|
||||
|
||||
sstatus = pj_mutex_create_recursive(pool, "mutex_telnet_fe", &fe->mutex);
|
||||
if (sstatus != PJ_SUCCESS)
|
||||
status = pj_mutex_create_recursive(pool, "mutex_telnet_fe", &fe->mutex);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
|
||||
/* Start telnet daemon */
|
||||
sstatus = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0,
|
||||
&sock);
|
||||
if (sstatus != PJ_SUCCESS)
|
||||
telnet_start(fe);
|
||||
|
||||
pj_cli_register_front_end(cli, &fe->base);
|
||||
|
||||
if (p_fe)
|
||||
*p_fe = &fe->base;
|
||||
|
||||
return PJ_SUCCESS;
|
||||
|
||||
on_exit:
|
||||
if (fe->own_ioqueue)
|
||||
pj_ioqueue_destroy(fe->cfg.ioqueue);
|
||||
|
||||
if (fe->mutex)
|
||||
pj_mutex_destroy(fe->mutex);
|
||||
|
||||
pj_pool_release(pool);
|
||||
return status;
|
||||
}
|
||||
|
||||
static pj_status_t telnet_start(cli_telnet_fe *fe)
|
||||
{
|
||||
pj_sock_t sock = PJ_INVALID_SOCKET;
|
||||
pj_activesock_cb asock_cb;
|
||||
pj_sockaddr_in addr;
|
||||
pj_status_t status;
|
||||
int val;
|
||||
int restart_retry;
|
||||
unsigned msec;
|
||||
|
||||
/* Start telnet daemon */
|
||||
status = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &sock);
|
||||
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
|
||||
pj_sockaddr_in_init(&addr, NULL, fe->cfg.port);
|
||||
|
||||
sstatus = pj_sock_bind(sock, &addr, sizeof(addr));
|
||||
if (sstatus == PJ_SUCCESS) {
|
||||
pj_sockaddr_in addr;
|
||||
int addr_len = sizeof(addr);
|
||||
val = 1;
|
||||
status = pj_sock_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
||||
&val, sizeof(val));
|
||||
|
||||
sstatus = pj_sock_getsockname(sock, &addr, &addr_len);
|
||||
if (sstatus != PJ_SUCCESS)
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
|
||||
/* The loop is silly, but what else can we do? */
|
||||
for (msec=MIN_WAIT_ON_TELNET_RESTART, restart_retry=0;
|
||||
restart_retry < MAX_RETRY_ON_TELNET_RESTART;
|
||||
++restart_retry, msec=(msec<MAX_WAIT_ON_TELNET_RESTART?
|
||||
msec*2 : MAX_WAIT_ON_TELNET_RESTART))
|
||||
{
|
||||
status = pj_sock_bind(sock, &addr, sizeof(addr));
|
||||
if (status != PJ_STATUS_FROM_OS(EADDRINUSE))
|
||||
break;
|
||||
PJ_LOG(4,(THIS_FILE, "Address is still in use, retrying.."));
|
||||
pj_thread_sleep(msec);
|
||||
}
|
||||
|
||||
if (status == PJ_SUCCESS) {
|
||||
int addr_len = sizeof(addr);
|
||||
|
||||
status = pj_sock_getsockname(sock, &addr, &addr_len);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
|
||||
fe->cfg.port = pj_sockaddr_in_get_port(&addr);
|
||||
if (param)
|
||||
param->port = fe->cfg.port;
|
||||
|
||||
PJ_LOG(3, (THIS_FILE, "CLI telnet daemon listening at port %d",
|
||||
fe->cfg.port));
|
||||
|
||||
fe->cfg.port = pj_sockaddr_in_get_port(&addr);
|
||||
|
||||
if (fe->cfg.prompt_str.slen == 0) {
|
||||
pj_str_t prompt_sign = {"> ", 2};
|
||||
char *prompt_data = pj_pool_alloc(fe->pool,
|
||||
|
@ -1737,35 +1808,51 @@ PJ_DEF(pj_status_t) pj_cli_telnet_create(pj_cli_t *cli,
|
|||
goto on_exit;
|
||||
}
|
||||
|
||||
sstatus = pj_sock_listen(sock, 4);
|
||||
if (sstatus != PJ_SUCCESS)
|
||||
status = pj_sock_listen(sock, 4);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
|
||||
pj_bzero(&asock_cb, sizeof(asock_cb));
|
||||
asock_cb.on_accept_complete = &telnet_fe_on_accept;
|
||||
sstatus = pj_activesock_create(pool, sock, pj_SOCK_STREAM(),
|
||||
NULL, fe->cfg.ioqueue,
|
||||
&asock_cb, fe, &fe->asock);
|
||||
if (sstatus != PJ_SUCCESS)
|
||||
asock_cb.on_accept_complete2 = &telnet_fe_on_accept;
|
||||
status = pj_activesock_create(fe->pool, sock, pj_SOCK_STREAM(),
|
||||
NULL, fe->cfg.ioqueue,
|
||||
&asock_cb, fe, &fe->asock);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
|
||||
sstatus = pj_activesock_start_accept(fe->asock, pool);
|
||||
if (sstatus != PJ_SUCCESS)
|
||||
status = pj_activesock_start_accept(fe->asock, fe->pool);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
|
||||
if (fe->own_ioqueue) {
|
||||
/* Create our own worker thread */
|
||||
sstatus = pj_thread_create(pool, "worker_telnet_fe",
|
||||
&poll_worker_thread, fe, 0, 0,
|
||||
&fe->worker_thread);
|
||||
if (sstatus != PJ_SUCCESS)
|
||||
status = pj_thread_create(fe->pool, "worker_telnet_fe",
|
||||
&poll_worker_thread, fe, 0, 0,
|
||||
&fe->worker_thread);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
}
|
||||
|
||||
pj_cli_register_front_end(cli, &fe->base);
|
||||
/** Fill telnet information and call pj_cli_telnet_on_started callback */
|
||||
if (fe->cfg.on_started) {
|
||||
char ip_addr[32];
|
||||
pj_cli_telnet_info telnet_info;
|
||||
pj_sockaddr hostip;
|
||||
|
||||
if (p_fe)
|
||||
*p_fe = &fe->base;
|
||||
telnet_info.ip_address.ptr = ip_addr;
|
||||
telnet_info.ip_address.slen = 0;
|
||||
|
||||
status = pj_gethostip(pj_AF_INET(), &hostip);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
|
||||
pj_strcpy2(&telnet_info.ip_address,
|
||||
pj_inet_ntoa(hostip.ipv4.sin_addr));
|
||||
|
||||
telnet_info.port = fe->cfg.port;
|
||||
|
||||
(*fe->cfg.on_started)(&telnet_info);
|
||||
}
|
||||
|
||||
return PJ_SUCCESS;
|
||||
|
||||
|
@ -1781,6 +1868,48 @@ on_exit:
|
|||
if (fe->mutex)
|
||||
pj_mutex_destroy(fe->mutex);
|
||||
|
||||
pj_pool_release(pool);
|
||||
return sstatus;
|
||||
pj_pool_release(fe->pool);
|
||||
return status;
|
||||
}
|
||||
|
||||
static pj_status_t telnet_restart(cli_telnet_fe *fe)
|
||||
{
|
||||
pj_status_t status;
|
||||
pj_cli_sess *sess;
|
||||
|
||||
fe->is_quitting = PJ_TRUE;
|
||||
if (fe->worker_thread) {
|
||||
pj_thread_join(fe->worker_thread);
|
||||
}
|
||||
|
||||
pj_mutex_lock(fe->mutex);
|
||||
|
||||
/* Destroy all the sessions */
|
||||
sess = fe->sess_head.next;
|
||||
while (sess != &fe->sess_head) {
|
||||
(*sess->op->destroy)(sess);
|
||||
sess = fe->sess_head.next;
|
||||
}
|
||||
|
||||
pj_mutex_unlock(fe->mutex);
|
||||
|
||||
/** Close existing activesock **/
|
||||
status = pj_activesock_close(fe->asock);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_exit;
|
||||
|
||||
if (fe->worker_thread) {
|
||||
pj_thread_destroy(fe->worker_thread);
|
||||
fe->worker_thread = NULL;
|
||||
}
|
||||
|
||||
fe->is_quitting = PJ_FALSE;
|
||||
|
||||
/** Start Telnet **/
|
||||
status = telnet_start(fe);
|
||||
if (status == PJ_SUCCESS)
|
||||
TRACE_((THIS_FILE, "Telnet Restarted"));
|
||||
|
||||
on_exit:
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -132,7 +132,8 @@ typedef struct pj_activesock_cb
|
|||
|
||||
/**
|
||||
* This callback is called when new connection arrives as the result
|
||||
* of pj_activesock_start_accept().
|
||||
* of pj_activesock_start_accept(). If the status of accept operation is
|
||||
* needed use on_accept_complete2 instead of this callback.
|
||||
*
|
||||
* @param asock The active socket.
|
||||
* @param newsock The new incoming socket.
|
||||
|
@ -149,6 +150,30 @@ typedef struct pj_activesock_cb
|
|||
const pj_sockaddr_t *src_addr,
|
||||
int src_addr_len);
|
||||
|
||||
/**
|
||||
* This callback is called when new connection arrives as the result
|
||||
* of pj_activesock_start_accept().
|
||||
*
|
||||
* @param asock The active socket.
|
||||
* @param newsock The new incoming socket.
|
||||
* @param src_addr The source address of the connection.
|
||||
* @param addr_len Length of the source address.
|
||||
* @param status The status of the accept operation. This may contain
|
||||
* non-PJ_SUCCESS for example when the TCP listener is in
|
||||
* bad state for example on iOS platform after the
|
||||
* application waking up from background.
|
||||
*
|
||||
* @return PJ_TRUE if further accept() is desired, and PJ_FALSE
|
||||
* when application no longer wants to accept incoming
|
||||
* connection. Application may destroy the active socket
|
||||
* in the callback and return PJ_FALSE here.
|
||||
*/
|
||||
pj_bool_t (*on_accept_complete2)(pj_activesock_t *asock,
|
||||
pj_sock_t newsock,
|
||||
const pj_sockaddr_t *src_addr,
|
||||
int src_addr_len,
|
||||
pj_status_t status);
|
||||
|
||||
/**
|
||||
* This callback is called when pending connect operation has been
|
||||
* completed.
|
||||
|
|
|
@ -427,6 +427,11 @@ PJ_DECL(pj_status_t) pj_register_strerror(pj_status_t start_code,
|
|||
* Object no longer exists
|
||||
*/
|
||||
#define PJ_EGONE (PJ_ERRNO_START_STATUS + 23)/* 70023 */
|
||||
/**
|
||||
* @hideinitializer
|
||||
* Socket is stopped
|
||||
*/
|
||||
#define PJ_ESOCKETSTOP (PJ_ERRNO_START_STATUS + 24)/* 70024 */
|
||||
|
||||
/** @} */ /* pj_errnum */
|
||||
|
||||
|
|
|
@ -843,6 +843,16 @@ static void ioqueue_on_accept_complete(pj_ioqueue_key_t *key,
|
|||
PJ_LOG(3, ("", "Received %d consecutive errors: %d for the accept()"
|
||||
" operation, stopping further ioqueue accepts.",
|
||||
asock->err_counter, asock->last_err));
|
||||
|
||||
if ((status == PJ_STATUS_FROM_OS(OSERR_EWOULDBLOCK)) &&
|
||||
(asock->cb.on_accept_complete2))
|
||||
{
|
||||
(*asock->cb.on_accept_complete2)(asock,
|
||||
accept_op->new_sock,
|
||||
&accept_op->rem_addr,
|
||||
accept_op->rem_addr_len,
|
||||
PJ_ESOCKETSTOP);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
@ -850,13 +860,23 @@ static void ioqueue_on_accept_complete(pj_ioqueue_key_t *key,
|
|||
asock->last_err = status;
|
||||
}
|
||||
|
||||
if (status==PJ_SUCCESS && asock->cb.on_accept_complete) {
|
||||
if (status==PJ_SUCCESS && (asock->cb.on_accept_complete2 ||
|
||||
asock->cb.on_accept_complete)) {
|
||||
pj_bool_t ret;
|
||||
|
||||
/* Notify callback */
|
||||
ret = (*asock->cb.on_accept_complete)(asock, accept_op->new_sock,
|
||||
&accept_op->rem_addr,
|
||||
accept_op->rem_addr_len);
|
||||
if (asock->cb.on_accept_complete2) {
|
||||
ret = (*asock->cb.on_accept_complete2)(asock,
|
||||
accept_op->new_sock,
|
||||
&accept_op->rem_addr,
|
||||
accept_op->rem_addr_len,
|
||||
status);
|
||||
} else {
|
||||
ret = (*asock->cb.on_accept_complete)(asock,
|
||||
accept_op->new_sock,
|
||||
&accept_op->rem_addr,
|
||||
accept_op->rem_addr_len);
|
||||
}
|
||||
|
||||
/* If callback returns false, we have been destroyed! */
|
||||
if (!ret)
|
||||
|
|
|
@ -78,7 +78,8 @@ static const struct
|
|||
PJ_BUILD_ERR(PJ_EIGNORED, "Ignored"),
|
||||
PJ_BUILD_ERR(PJ_EIPV6NOTSUP, "IPv6 is not supported"),
|
||||
PJ_BUILD_ERR(PJ_EAFNOTSUP, "Unsupported address family"),
|
||||
PJ_BUILD_ERR(PJ_EGONE, "Object no longer exists")
|
||||
PJ_BUILD_ERR(PJ_EGONE, "Object no longer exists"),
|
||||
PJ_BUILD_ERR(PJ_ESOCKETSTOP, "Socket is in bad state")
|
||||
};
|
||||
#endif /* PJ_HAS_ERROR_STRING */
|
||||
|
||||
|
|
|
@ -33,7 +33,8 @@ export _CXXFLAGS:= $(_CFLAGS) $(CC_CXXFLAGS) $(OS_CXXFLAGS) $(M_CXXFLAGS) \
|
|||
#
|
||||
export PJSUA_SRCDIR = ../src/pjsua
|
||||
export PJSUA_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
|
||||
main.o pjsua_app.o pjsua_cmd.o pjsua_cli_cmd.o pjsua_ui_cmd.o
|
||||
main.o pjsua_app.o pjsua_cli.o pjsua_cli_cmd.o pjsua_common.o \
|
||||
pjsua_config.o pjsua_legacy.o
|
||||
export PJSUA_CFLAGS += $(_CFLAGS)
|
||||
export PJSUA_LDFLAGS += $(APP_LDFLAGS) $(APP_LDLIBS) $(LDFLAGS)
|
||||
export PJSUA_EXE:=../bin/pjsua-$(TARGET_NAME)$(HOST_EXE)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -26,91 +26,7 @@
|
|||
/*
|
||||
* These are defined in pjsua_app.c.
|
||||
*/
|
||||
extern pj_bool_t app_restart;
|
||||
pj_status_t app_init(int argc, char *argv[]);
|
||||
pj_status_t app_main(void);
|
||||
pj_status_t app_destroy();
|
||||
pj_status_t receive_end_sig;
|
||||
pj_thread_t *sig_thread;
|
||||
|
||||
#if defined(PJ_WIN32) && PJ_WIN32!=0
|
||||
#include <windows.h>
|
||||
|
||||
static pj_thread_desc handler_desc;
|
||||
|
||||
static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType)
|
||||
{
|
||||
switch (fdwCtrlType)
|
||||
{
|
||||
// Handle the CTRL+C signal.
|
||||
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_CLOSE_EVENT:
|
||||
case CTRL_BREAK_EVENT:
|
||||
case CTRL_LOGOFF_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
pj_thread_register("ctrlhandler", handler_desc, &sig_thread);
|
||||
PJ_LOG(3,(THIS_FILE, "Ctrl-C detected, quitting.."));
|
||||
receive_end_sig = PJ_TRUE;
|
||||
app_destroy();
|
||||
ExitProcess(1);
|
||||
PJ_UNREACHED(return TRUE;)
|
||||
|
||||
default:
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void setup_signal_handler(void)
|
||||
{
|
||||
SetConsoleCtrlHandler(&CtrlHandler, TRUE);
|
||||
}
|
||||
|
||||
static void setup_socket_signal()
|
||||
{
|
||||
}
|
||||
|
||||
#else
|
||||
#include <signal.h>
|
||||
|
||||
static void setup_signal_handler(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void setup_socket_signal()
|
||||
{
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int main_func(int argc, char *argv[])
|
||||
{
|
||||
receive_end_sig = PJ_FALSE;
|
||||
setup_socket_signal();
|
||||
|
||||
do {
|
||||
app_restart = PJ_FALSE;
|
||||
|
||||
if (app_init(argc, argv) != PJ_SUCCESS)
|
||||
return 1;
|
||||
|
||||
setup_signal_handler();
|
||||
|
||||
app_main();
|
||||
if (!receive_end_sig) {
|
||||
app_destroy();
|
||||
|
||||
/* This is on purpose */
|
||||
app_destroy();
|
||||
} else {
|
||||
pj_thread_join(sig_thread);
|
||||
}
|
||||
} while (app_restart);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int main_func(int argc, char *argv[]);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,269 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
|
||||
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "pjsua_common.h"
|
||||
#include <pjlib-util/cli.h>
|
||||
#include <pjlib-util/cli_imp.h>
|
||||
#include <pjlib-util/cli_console.h>
|
||||
#include <pjlib-util/cli_telnet.h>
|
||||
#include <pjlib-util/scanner.h>
|
||||
|
||||
#define THIS_FILE "pjsua_cli.c"
|
||||
|
||||
pj_cli_telnet_on_started cli_telnet_on_started_cb = NULL;
|
||||
pj_cli_on_quit cli_on_quit_cb = NULL;
|
||||
pj_cli_on_destroy cli_on_destroy_cb = NULL;
|
||||
pj_cli_on_restart_pjsua cli_on_restart_pjsua_cb = NULL;
|
||||
|
||||
pj_bool_t pjsua_restarted = PJ_TRUE;
|
||||
static pj_bool_t pj_inited = PJ_FALSE;
|
||||
static pj_caching_pool cli_cp;
|
||||
static pj_cli_t *cli = NULL;
|
||||
static pj_cli_sess *cli_cons_sess = NULL;
|
||||
|
||||
/** Forward declaration **/
|
||||
pj_status_t setup_command(pj_cli_t *cli);
|
||||
|
||||
static void log_writer(int level, const char *buffer, int len)
|
||||
{
|
||||
if (cli)
|
||||
pj_cli_write_log(cli, level, buffer, len);
|
||||
|
||||
if (app_config.disable_cli_console)
|
||||
pj_log_write(level, buffer, len);
|
||||
}
|
||||
|
||||
void destroy_cli(pj_bool_t app_restart)
|
||||
{
|
||||
pj_log_set_log_func(&pj_log_write);
|
||||
|
||||
if (cli) {
|
||||
pj_cli_destroy(cli);
|
||||
cli = NULL;
|
||||
}
|
||||
|
||||
if (cli_cp.factory.create_pool) {
|
||||
pj_caching_pool_destroy(&cli_cp);
|
||||
pj_bzero(&cli_cp, sizeof(cli_cp));
|
||||
}
|
||||
|
||||
if (pj_inited) {
|
||||
pj_shutdown();
|
||||
pj_inited = PJ_FALSE;
|
||||
}
|
||||
if (!app_restart) {
|
||||
if (cli_on_destroy_cb)
|
||||
(*cli_on_destroy_cb)();
|
||||
}
|
||||
}
|
||||
|
||||
pj_status_t setup_cli(pj_bool_t with_console, pj_bool_t with_telnet,
|
||||
pj_uint16_t telnet_port,
|
||||
pj_cli_telnet_on_started on_started_cb,
|
||||
pj_cli_on_quit on_quit_cb,
|
||||
pj_cli_on_destroy on_destroy_cb,
|
||||
pj_cli_on_restart_pjsua on_restart_pjsua_cb)
|
||||
{
|
||||
pj_cli_cfg cli_cfg;
|
||||
pj_status_t status;
|
||||
|
||||
/* Destroy CLI if initialized */
|
||||
destroy_cli(PJ_TRUE);
|
||||
|
||||
/* Init PJLIB */
|
||||
status = pj_init();
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_error;
|
||||
|
||||
pj_inited = PJ_TRUE;
|
||||
|
||||
/* Init PJLIB-UTIL */
|
||||
status = pjlib_util_init();
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_error;
|
||||
|
||||
/* Init CLI */
|
||||
pj_caching_pool_init(&cli_cp, NULL, 0);
|
||||
pj_cli_cfg_default(&cli_cfg);
|
||||
cli_cfg.pf = &cli_cp.factory;
|
||||
cli_cfg.name = pj_str("pjsua_cli");
|
||||
cli_cfg.title = pj_str("Pjsua CLI Application");
|
||||
status = pj_cli_create(&cli_cfg, &cli);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_error;
|
||||
|
||||
status = setup_command(cli);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_error;
|
||||
|
||||
if (on_destroy_cb)
|
||||
cli_on_destroy_cb = on_destroy_cb;
|
||||
|
||||
if (on_restart_pjsua_cb)
|
||||
cli_on_restart_pjsua_cb = on_restart_pjsua_cb;
|
||||
|
||||
if (on_quit_cb)
|
||||
cli_on_quit_cb = on_quit_cb;
|
||||
|
||||
/* Init telnet frontend */
|
||||
if (with_telnet) {
|
||||
pj_cli_telnet_cfg telnet_cfg;
|
||||
pj_pool_t *pool;
|
||||
|
||||
pool = pj_pool_create(&cli_cp.factory, "cli_cp", 128, 128, NULL);
|
||||
pj_assert(pool);
|
||||
|
||||
pj_cli_telnet_cfg_default(&telnet_cfg);
|
||||
telnet_cfg.log_level = 5;
|
||||
telnet_cfg.port = telnet_port;
|
||||
if (on_started_cb)
|
||||
cli_telnet_on_started_cb = on_started_cb;
|
||||
|
||||
telnet_cfg.on_started = cli_telnet_on_started_cb;
|
||||
|
||||
status = pj_cli_telnet_create(cli, &telnet_cfg, NULL);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
/* Init console frontend */
|
||||
if (with_console) {
|
||||
pj_cli_console_cfg console_cfg;
|
||||
|
||||
pj_cli_console_cfg_default(&console_cfg);
|
||||
console_cfg.quit_command = pj_str("shutdown");
|
||||
status = pj_cli_console_create(cli, &console_cfg,
|
||||
&cli_cons_sess, NULL);
|
||||
if (status != PJ_SUCCESS)
|
||||
goto on_error;
|
||||
}
|
||||
|
||||
return PJ_SUCCESS;
|
||||
|
||||
on_error:
|
||||
destroy_cli(PJ_FALSE);
|
||||
return status;
|
||||
}
|
||||
|
||||
PJ_DEF(pj_bool_t) is_cli_inited()
|
||||
{
|
||||
return (cli != NULL);
|
||||
}
|
||||
|
||||
static pj_status_t setup_timer(pj_timer_heap_t **timer,
|
||||
pj_ioqueue_t **ioqueue)
|
||||
{
|
||||
pj_status_t status = pj_timer_heap_create(app_config.pool, 16, timer);
|
||||
|
||||
if (status != PJ_SUCCESS)
|
||||
return status;
|
||||
|
||||
status = pj_ioqueue_create(app_config.pool, 16, ioqueue);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static pj_status_t stop_timer(pj_timer_heap_t *timer,
|
||||
pj_ioqueue_t *ioqueue)
|
||||
{
|
||||
if ((!timer) || (!ioqueue))
|
||||
return PJ_SUCCESS;
|
||||
|
||||
pj_timer_heap_destroy(timer);
|
||||
|
||||
return pj_ioqueue_destroy(ioqueue);
|
||||
}
|
||||
|
||||
pj_status_t cli_pjsua_start(pj_str_t *uri_to_call,
|
||||
pj_timer_heap_t **main_timer_heap,
|
||||
pj_ioqueue_t **main_ioqueue)
|
||||
{
|
||||
pj_status_t status = PJ_SUCCESS;
|
||||
|
||||
pjsua_restarted = PJ_FALSE;
|
||||
|
||||
if (app_config.disable_cli_console) {
|
||||
status = setup_timer(main_timer_heap, main_ioqueue);
|
||||
if (status != PJ_SUCCESS)
|
||||
return status;
|
||||
}
|
||||
|
||||
status = pjsua_start();
|
||||
if (status != PJ_SUCCESS)
|
||||
return status;
|
||||
|
||||
pj_log_set_log_func(&log_writer);
|
||||
|
||||
setup_signal_handler();
|
||||
|
||||
/* If user specifies URI to call, then call the URI */
|
||||
if (uri_to_call->slen) {
|
||||
pjsua_call_make_call(current_acc, uri_to_call, &call_opt, NULL,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
if (!app_config.disable_cli_console)
|
||||
PJ_LOG(3,(THIS_FILE, "CLI console is ready, press '?' for help"));
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void start_cli_main(pj_str_t *uri_to_call, pj_bool_t *app_restart)
|
||||
{
|
||||
pj_status_t status;
|
||||
char cmdline[PJ_CLI_MAX_CMDBUF];
|
||||
pj_timer_heap_t *main_timer_heap = NULL;
|
||||
pj_ioqueue_t *main_ioqueue = NULL;
|
||||
|
||||
*app_restart = PJ_FALSE;
|
||||
pjsua_restarted = PJ_TRUE;
|
||||
|
||||
do {
|
||||
if (pjsua_restarted) {
|
||||
status = cli_pjsua_start(uri_to_call, &main_timer_heap,
|
||||
&main_ioqueue);
|
||||
|
||||
if (status != PJ_SUCCESS)
|
||||
return;
|
||||
}
|
||||
|
||||
if (app_config.disable_cli_console) {
|
||||
pj_time_val delay = {0, 10};
|
||||
pj_ioqueue_poll(main_ioqueue, &delay);
|
||||
if (pj_cli_is_quitting(cli))
|
||||
continue;
|
||||
pj_timer_heap_poll(main_timer_heap, NULL);
|
||||
} else {
|
||||
pj_cli_console_process(cli_cons_sess, &cmdline[0], sizeof(cmdline));
|
||||
}
|
||||
if (pjsua_restarted) {
|
||||
status = stop_timer(main_timer_heap, main_ioqueue);
|
||||
if (status != PJ_SUCCESS)
|
||||
return;
|
||||
|
||||
status = app_init(NULL, NULL, NULL, NULL);
|
||||
if (status != PJ_SUCCESS)
|
||||
return;
|
||||
}
|
||||
|
||||
} while (!pj_cli_is_quitting(cli));
|
||||
stop_timer(main_timer_heap, main_ioqueue);
|
||||
*app_restart = pj_cli_is_restarting(cli);
|
||||
}
|
|
@ -18,14 +18,18 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "pjsua_cmd.h"
|
||||
#include "pjsua_common.h"
|
||||
#include <pjlib-util/cli.h>
|
||||
#include <pjlib-util/cli_imp.h>
|
||||
#include <pjlib-util/cli_console.h>
|
||||
#include <pjlib-util/cli_telnet.h>
|
||||
#include <pjlib-util/scanner.h>
|
||||
|
||||
#define THIS_FILE "pjsua_cli_cmd.c"
|
||||
|
||||
#define CHECK_PJSUA_RUNNING() if (pjsua_get_state()!=PJSUA_STATE_RUNNING) \
|
||||
return PJ_EINVALIDOP
|
||||
|
||||
/* CLI command id */
|
||||
/* level 1 command */
|
||||
#define CMD_CALL 100
|
||||
|
@ -38,6 +42,8 @@
|
|||
#define CMD_ECHO 800
|
||||
#define CMD_NETWORK 900
|
||||
#define CMD_QUIT 110
|
||||
#define CMD_RESTART 120
|
||||
#define CMD_RELOAD 130
|
||||
|
||||
/* call level 2 command */
|
||||
#define CMD_CALL_NEW ((CMD_CALL*10)+1)
|
||||
|
@ -143,17 +149,11 @@
|
|||
#define DYN_CHOICE_CALL_ID (DYN_CHOICE_START)+11
|
||||
#define DYN_CHOICE_ADDED_BUDDY_ID (DYN_CHOICE_START)+12
|
||||
|
||||
static pj_cli_cfg cli_cfg;
|
||||
static pj_cli_telnet_cfg telnet_cfg;
|
||||
static pj_cli_t *cli = NULL;
|
||||
static pj_cli_sess *sess = NULL;
|
||||
static pj_cli_console_cfg console_cfg;
|
||||
|
||||
/* Get input URL */
|
||||
static void get_input_url(char *buf,
|
||||
int len,
|
||||
pj_cli_cmd_val *cval,
|
||||
struct input_result *result)
|
||||
struct input_result *result)
|
||||
{
|
||||
static const pj_str_t err_invalid_input = {"Invalid input\n", 15};
|
||||
result->nb_result = NO_NB;
|
||||
|
@ -202,7 +202,7 @@ struct input_result *result)
|
|||
return;
|
||||
|
||||
pj_cli_sess_write_msg(cval->sess, err_invalid_input.ptr,
|
||||
err_invalid_input.slen);
|
||||
err_invalid_input.slen);
|
||||
result->nb_result = NO_NB;
|
||||
return;
|
||||
|
||||
|
@ -615,41 +615,10 @@ static void get_choice_value(pj_cli_dyn_choice_param *param)
|
|||
#endif
|
||||
default:
|
||||
param->cnt = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void cli_console_app_main(const pj_str_t *uri_to_call, pj_bool_t *app_restart)
|
||||
{
|
||||
pjsua_call_setting_default(&call_opt);
|
||||
call_opt.aud_cnt = app_config.aud_cnt;
|
||||
call_opt.vid_cnt = app_config.vid.vid_cnt;
|
||||
|
||||
/* If user specifies URI to call, then call the URI */
|
||||
if (uri_to_call->slen) {
|
||||
pjsua_call_make_call(current_acc, uri_to_call, &call_opt, NULL,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Main loop.
|
||||
*/
|
||||
for (;;) {
|
||||
char cmdline[PJ_CLI_MAX_CMDBUF];
|
||||
pj_status_t status;
|
||||
|
||||
status = pj_cli_console_process(sess, &cmdline[0], sizeof(cmdline));
|
||||
|
||||
if (status == PJ_CLI_EEXIT) {
|
||||
/* exit is called */
|
||||
break;
|
||||
} else if (status != PJ_SUCCESS) {
|
||||
/* Something wrong with the cmdline */
|
||||
PJ_PERROR(1,(THIS_FILE, status, "Exec error"));
|
||||
}
|
||||
}
|
||||
*app_restart = pj_cli_is_restarting(cli);
|
||||
}
|
||||
|
||||
/*
|
||||
* CLI command handler
|
||||
*/
|
||||
|
@ -795,6 +764,8 @@ pj_status_t cmd_account_handler(pj_cli_cmd_val *cval)
|
|||
{
|
||||
pj_status_t status = PJ_SUCCESS;
|
||||
|
||||
CHECK_PJSUA_RUNNING();
|
||||
|
||||
switch(pj_cli_get_cmd_id(cval->cmd)) {
|
||||
case CMD_ACCOUNT_ADD:
|
||||
status = cmd_add_account(cval);
|
||||
|
@ -1064,6 +1035,8 @@ pj_status_t cmd_presence_handler(pj_cli_cmd_val *cval)
|
|||
{
|
||||
pj_status_t status = PJ_SUCCESS;
|
||||
|
||||
CHECK_PJSUA_RUNNING();
|
||||
|
||||
switch(pj_cli_get_cmd_id(cval->cmd)) {
|
||||
case CMD_PRESENCE_ADD_BUDDY:
|
||||
status = cmd_add_buddy(cval);
|
||||
|
@ -1106,8 +1079,8 @@ static pj_status_t cmd_media_list(pj_cli_cmd_val *cval)
|
|||
pjsua_enum_conf_ports(id, &count);
|
||||
|
||||
for (i=0; i<count; ++i) {
|
||||
char out_str[PJSUA_MAX_CALLS*6];
|
||||
char txlist[PJSUA_MAX_CALLS*4+10];
|
||||
char out_str[128];
|
||||
char txlist[16];
|
||||
unsigned j;
|
||||
pjsua_conf_port_info info;
|
||||
|
||||
|
@ -1223,6 +1196,8 @@ pj_status_t cmd_media_handler(pj_cli_cmd_val *cval)
|
|||
{
|
||||
pj_status_t status = PJ_SUCCESS;
|
||||
|
||||
CHECK_PJSUA_RUNNING();
|
||||
|
||||
switch(pj_cli_get_cmd_id(cval->cmd)) {
|
||||
case CMD_MEDIA_LIST:
|
||||
status = cmd_media_list(cval);
|
||||
|
@ -1306,6 +1281,8 @@ pj_status_t cmd_config_handler(pj_cli_cmd_val *cval)
|
|||
{
|
||||
pj_status_t status = PJ_SUCCESS;
|
||||
|
||||
CHECK_PJSUA_RUNNING();
|
||||
|
||||
switch(pj_cli_get_cmd_id(cval->cmd)) {
|
||||
case CMD_CONFIG_DUMP_STAT:
|
||||
status = cmd_stat_dump(PJ_FALSE);
|
||||
|
@ -1523,7 +1500,6 @@ static pj_status_t cmd_call_reinvite()
|
|||
static pj_status_t cmd_call_update()
|
||||
{
|
||||
if (current_call != PJSUA_INVALID_ID) {
|
||||
call_opt.flag |= PJSUA_CALL_UNHOLD;
|
||||
pjsua_call_update2(current_call, &call_opt, NULL);
|
||||
} else {
|
||||
PJ_LOG(3,(THIS_FILE, "No current call"));
|
||||
|
@ -1922,6 +1898,8 @@ pj_status_t cmd_call_handler(pj_cli_cmd_val *cval)
|
|||
pj_status_t status = PJ_SUCCESS;
|
||||
pj_cli_cmd_id cmd_id = pj_cli_get_cmd_id(cval->cmd);
|
||||
|
||||
CHECK_PJSUA_RUNNING();
|
||||
|
||||
switch(cmd_id) {
|
||||
case CMD_CALL_NEW:
|
||||
status = cmd_make_single_call(cval);
|
||||
|
@ -2012,6 +1990,8 @@ static pj_status_t cmd_video_acc_handler(pj_cli_cmd_val *cval)
|
|||
pjsua_acc_config acc_cfg;
|
||||
pj_cli_cmd_id cmd_id = pj_cli_get_cmd_id(cval->cmd);
|
||||
|
||||
CHECK_PJSUA_RUNNING();
|
||||
|
||||
pjsua_acc_get_config(current_acc, &acc_cfg);
|
||||
|
||||
switch(cmd_id) {
|
||||
|
@ -2321,6 +2301,8 @@ static pj_status_t cmd_video_handler(pj_cli_cmd_val *cval)
|
|||
pj_status_t status = PJ_SUCCESS;
|
||||
pj_cli_cmd_id cmd_id = pj_cli_get_cmd_id(cval->cmd);
|
||||
|
||||
CHECK_PJSUA_RUNNING();
|
||||
|
||||
switch(cmd_id) {
|
||||
case CMD_VIDEO_ENABLE:
|
||||
status = cmd_set_video_enable(PJ_TRUE);
|
||||
|
@ -2414,7 +2396,10 @@ static pj_status_t cmd_sleep_handler(pj_cli_cmd_val *cval)
|
|||
static pj_status_t cmd_network_handler(pj_cli_cmd_val *cval)
|
||||
{
|
||||
pj_status_t status = PJ_SUCCESS;
|
||||
PJ_UNUSED_ARG(cval);
|
||||
PJ_UNUSED_ARG(cval);
|
||||
|
||||
CHECK_PJSUA_RUNNING();
|
||||
|
||||
status = pjsua_detect_nat_type();
|
||||
if (status != PJ_SUCCESS)
|
||||
pjsua_perror(THIS_FILE, "Error", status);
|
||||
|
@ -2424,15 +2409,83 @@ static pj_status_t cmd_network_handler(pj_cli_cmd_val *cval)
|
|||
|
||||
static pj_status_t cmd_quit_handler(pj_cli_cmd_val *cval)
|
||||
{
|
||||
extern pj_cli_on_quit cli_on_quit_cb;
|
||||
PJ_LOG(3,(THIS_FILE, "Quitting app.."));
|
||||
pj_cli_quit(cval->sess->fe->cli, cval->sess, PJ_FALSE);
|
||||
pj_cli_quit(cval->sess->fe->cli, cval->sess, PJ_FALSE);
|
||||
/** Call pj_cli_on_quit callback **/
|
||||
if (cli_on_quit_cb)
|
||||
(*cli_on_quit_cb)(PJ_FALSE);
|
||||
|
||||
return PJ_SUCCESS;
|
||||
}
|
||||
|
||||
static pj_status_t cmd_restart_handler(pj_cli_cmd_val *cval)
|
||||
{
|
||||
extern pj_cli_on_quit cli_on_quit_cb;
|
||||
PJ_LOG(3,(THIS_FILE, "Restarting app.."));
|
||||
pj_cli_quit(cval->sess->fe->cli, cval->sess, PJ_TRUE);
|
||||
pj_cli_quit(cval->sess->fe->cli, cval->sess, PJ_TRUE);
|
||||
/** Call pj_cli_on_quit callback **/
|
||||
if (cli_on_quit_cb)
|
||||
(*cli_on_quit_cb)(PJ_TRUE);
|
||||
|
||||
return PJ_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Syntax error handler for parser.
|
||||
*/
|
||||
static void on_syntax_error(pj_scanner *scanner)
|
||||
{
|
||||
PJ_UNUSED_ARG(scanner);
|
||||
PJ_THROW(PJ_EINVAL);
|
||||
}
|
||||
|
||||
static pj_status_t get_options(pj_str_t *options, unsigned *cmd_count)
|
||||
{
|
||||
pj_scanner scanner;
|
||||
pj_str_t str;
|
||||
|
||||
PJ_USE_EXCEPTION;
|
||||
|
||||
if (!options)
|
||||
return PJ_SUCCESS;
|
||||
|
||||
pj_scan_init(&scanner, options->ptr, options->slen, PJ_SCAN_AUTOSKIP_WS,
|
||||
&on_syntax_error);
|
||||
PJ_TRY {
|
||||
while (!pj_scan_is_eof(&scanner)) {
|
||||
++(*cmd_count);
|
||||
pj_scan_get_until_chr(&scanner, " \t\r\n", &str);
|
||||
/** Store to command arguments **/
|
||||
add_reload_config(*cmd_count, &str);
|
||||
}
|
||||
}
|
||||
PJ_CATCH_ANY {
|
||||
pj_scan_fini(&scanner);
|
||||
return PJ_GET_EXCEPTION();
|
||||
}
|
||||
PJ_END;
|
||||
return PJ_SUCCESS;
|
||||
}
|
||||
|
||||
static pj_status_t cmd_reload_handler(pj_cli_cmd_val *cval)
|
||||
{
|
||||
int i;
|
||||
unsigned cmd_count = 0;
|
||||
extern pj_bool_t pjsua_restarted;
|
||||
extern pj_cli_on_restart_pjsua cli_on_restart_pjsua_cb;
|
||||
|
||||
PJ_LOG(3,(THIS_FILE, "Reloading Pjsua.."));
|
||||
/** Get the pjsua option **/
|
||||
|
||||
for (i=1;i<cval->argc;i++) {
|
||||
get_options(&cval->argv[i], &cmd_count);
|
||||
}
|
||||
pjsua_restarted = PJ_TRUE;
|
||||
|
||||
if (cli_on_restart_pjsua_cb)
|
||||
(*cli_on_restart_pjsua_cb)();
|
||||
|
||||
return PJ_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -2831,11 +2884,20 @@ static pj_status_t add_other_command(pj_cli_t *cli)
|
|||
char* restart_command =
|
||||
"<CMD name='restart' id='120' desc='Restart application'/>";
|
||||
|
||||
char* reload_command =
|
||||
"<CMD name='reload' id='130' desc='Reload pjsua'>"
|
||||
" <ARG name='options1' type='string' desc='Options' optional='1'/>"
|
||||
" <ARG name='options2' type='string' desc='Options' optional='1'/>"
|
||||
" <ARG name='options3' type='string' desc='Options' optional='1'/>"
|
||||
" <ARG name='options4' type='string' desc='Options' optional='1'/>"
|
||||
"</CMD>";
|
||||
|
||||
pj_status_t status;
|
||||
pj_str_t sleep_xml = pj_str(sleep_command);
|
||||
pj_str_t network_xml = pj_str(network_command);
|
||||
pj_str_t shutdown_xml = pj_str(shutdown_command);
|
||||
pj_str_t restart_xml = pj_str(restart_command);
|
||||
pj_str_t reload_xml = pj_str(reload_command);
|
||||
|
||||
status = pj_cli_add_cmd_from_xml(cli, NULL,
|
||||
&sleep_xml, cmd_sleep_handler,
|
||||
|
@ -2859,11 +2921,17 @@ static pj_status_t add_other_command(pj_cli_t *cli)
|
|||
status = pj_cli_add_cmd_from_xml(cli, NULL,
|
||||
&restart_xml, cmd_restart_handler,
|
||||
NULL, NULL);
|
||||
if (status != PJ_SUCCESS)
|
||||
return status;
|
||||
|
||||
status = pj_cli_add_cmd_from_xml(cli, NULL,
|
||||
&reload_xml, cmd_reload_handler,
|
||||
NULL, NULL);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static pj_status_t setup_command()
|
||||
pj_status_t setup_command(pj_cli_t *cli)
|
||||
{
|
||||
pj_status_t status;
|
||||
|
||||
|
@ -2897,58 +2965,3 @@ static pj_status_t setup_command()
|
|||
|
||||
return status;
|
||||
}
|
||||
|
||||
static void log_writer(int level, const char *buffer, int len)
|
||||
{
|
||||
if (cli)
|
||||
pj_cli_write_log(cli, level, buffer, len);
|
||||
}
|
||||
|
||||
pj_status_t setup_cli()
|
||||
{
|
||||
pj_status_t status;
|
||||
pj_cli_cfg_default(&cli_cfg);
|
||||
cli_cfg.pf = app_config.pool->factory;
|
||||
cli_cfg.name = pj_str("pjsua_cli");
|
||||
cli_cfg.title = pj_str("Pjsua CLI Application");
|
||||
|
||||
status = pj_cli_create(&cli_cfg, &cli);
|
||||
if (status != PJ_SUCCESS)
|
||||
return status;
|
||||
|
||||
status = setup_command();
|
||||
if (status != PJ_SUCCESS)
|
||||
return status;
|
||||
|
||||
pj_log_set_log_func(&log_writer);
|
||||
|
||||
/*
|
||||
* Init telnet
|
||||
*/
|
||||
pj_cli_telnet_cfg_default(&telnet_cfg);
|
||||
telnet_cfg.log_level = 5;
|
||||
if (app_config.cli_telnet_port)
|
||||
telnet_cfg.port = (pj_uint16_t)app_config.cli_telnet_port;
|
||||
|
||||
status = pj_cli_telnet_create(cli, &telnet_cfg, NULL);
|
||||
if (status != PJ_SUCCESS)
|
||||
return status;
|
||||
|
||||
app_config.cli_telnet_port = telnet_cfg.port;;
|
||||
|
||||
/*
|
||||
* Init console
|
||||
*/
|
||||
pj_cli_console_cfg_default(&console_cfg);
|
||||
console_cfg.quit_command = pj_str("shutdown");
|
||||
status = pj_cli_console_create(cli, &console_cfg, &sess, NULL);
|
||||
return status;
|
||||
}
|
||||
|
||||
void destroy_cli()
|
||||
{
|
||||
pj_log_set_log_func(&pj_log_write);
|
||||
pj_cli_destroy(cli);
|
||||
cli = NULL;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,356 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
|
||||
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "pjsua_common.h"
|
||||
|
||||
#define THIS_FILE "pjsua_common.c"
|
||||
|
||||
#if defined(PJMEDIA_HAS_RTCP_XR) && (PJMEDIA_HAS_RTCP_XR != 0)
|
||||
# define SOME_BUF_SIZE (1024 * 10)
|
||||
#else
|
||||
# define SOME_BUF_SIZE (1024 * 3)
|
||||
#endif
|
||||
|
||||
static char some_buf[SOME_BUF_SIZE];
|
||||
|
||||
/** Variable definition **/
|
||||
int stdout_refresh = -1;
|
||||
pj_bool_t stdout_refresh_quit = PJ_FALSE;
|
||||
pjsua_call_id current_call = PJSUA_INVALID_ID;
|
||||
pjsua_app_config app_config;
|
||||
pjsua_call_setting call_opt;
|
||||
pjsua_msg_data msg_data;
|
||||
|
||||
PJ_DEF(int) my_atoi(const char *cs)
|
||||
{
|
||||
pj_str_t s;
|
||||
|
||||
pj_cstr(&s, cs);
|
||||
if (cs[0] == '-') {
|
||||
s.ptr++, s.slen--;
|
||||
return 0 - (int)pj_strtoul(&s);
|
||||
} else if (cs[0] == '+') {
|
||||
s.ptr++, s.slen--;
|
||||
return pj_strtoul(&s);
|
||||
} else {
|
||||
return pj_strtoul(&s);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Find next call when current call is disconnected or when user
|
||||
* press ']'
|
||||
*/
|
||||
PJ_DEF(pj_bool_t) find_next_call()
|
||||
{
|
||||
int i, max;
|
||||
|
||||
max = pjsua_call_get_max_count();
|
||||
for (i=current_call+1; i<max; ++i) {
|
||||
if (pjsua_call_is_active(i)) {
|
||||
current_call = i;
|
||||
return PJ_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0; i<current_call; ++i) {
|
||||
if (pjsua_call_is_active(i)) {
|
||||
current_call = i;
|
||||
return PJ_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
current_call = PJSUA_INVALID_ID;
|
||||
return PJ_FALSE;
|
||||
}
|
||||
|
||||
PJ_DEF(pj_bool_t) find_prev_call()
|
||||
{
|
||||
int i, max;
|
||||
|
||||
max = pjsua_call_get_max_count();
|
||||
for (i=current_call-1; i>=0; --i) {
|
||||
if (pjsua_call_is_active(i)) {
|
||||
current_call = i;
|
||||
return PJ_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
for (i=max-1; i>current_call; --i) {
|
||||
if (pjsua_call_is_active(i)) {
|
||||
current_call = i;
|
||||
return PJ_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
current_call = PJSUA_INVALID_ID;
|
||||
return PJ_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Send arbitrary request to remote host
|
||||
*/
|
||||
PJ_DEF(void) send_request(char *cstr_method, const pj_str_t *dst_uri)
|
||||
{
|
||||
pj_str_t str_method;
|
||||
pjsip_method method;
|
||||
pjsip_tx_data *tdata;
|
||||
pjsip_endpoint *endpt;
|
||||
pj_status_t status;
|
||||
|
||||
endpt = pjsua_get_pjsip_endpt();
|
||||
|
||||
str_method = pj_str(cstr_method);
|
||||
pjsip_method_init_np(&method, &str_method);
|
||||
|
||||
status = pjsua_acc_create_request(current_acc, &method, dst_uri, &tdata);
|
||||
|
||||
status = pjsip_endpt_send_request(endpt, tdata, -1, NULL, NULL);
|
||||
if (status != PJ_SUCCESS) {
|
||||
pjsua_perror(THIS_FILE, "Unable to send request", status);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Print log of call states. Since call states may be too long for logger,
|
||||
* printing it is a bit tricky, it should be printed part by part as long
|
||||
* as the logger can accept.
|
||||
*/
|
||||
PJ_DEF(void) log_call_dump(int call_id)
|
||||
{
|
||||
unsigned call_dump_len;
|
||||
unsigned part_len;
|
||||
unsigned part_idx;
|
||||
unsigned log_decor;
|
||||
|
||||
pjsua_call_dump(call_id, PJ_TRUE, some_buf, sizeof(some_buf), " ");
|
||||
call_dump_len = strlen(some_buf);
|
||||
|
||||
log_decor = pj_log_get_decor();
|
||||
pj_log_set_decor(log_decor & ~(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR));
|
||||
PJ_LOG(3,(THIS_FILE, "\n"));
|
||||
pj_log_set_decor(0);
|
||||
|
||||
part_idx = 0;
|
||||
part_len = PJ_LOG_MAX_SIZE-80;
|
||||
while (part_idx < call_dump_len) {
|
||||
char p_orig, *p;
|
||||
|
||||
p = &some_buf[part_idx];
|
||||
if (part_idx + part_len > call_dump_len)
|
||||
part_len = call_dump_len - part_idx;
|
||||
p_orig = p[part_len];
|
||||
p[part_len] = '\0';
|
||||
PJ_LOG(3,(THIS_FILE, "%s", p));
|
||||
p[part_len] = p_orig;
|
||||
part_idx += part_len;
|
||||
}
|
||||
pj_log_set_decor(log_decor);
|
||||
}
|
||||
|
||||
#ifdef PJSUA_HAS_VIDEO
|
||||
PJ_DEF(void) app_config_init_video(pjsua_acc_config *acc_cfg)
|
||||
{
|
||||
acc_cfg->vid_in_auto_show = app_config.vid.in_auto_show;
|
||||
acc_cfg->vid_out_auto_transmit = app_config.vid.out_auto_transmit;
|
||||
/* Note that normally GUI application will prefer a borderless
|
||||
* window.
|
||||
*/
|
||||
acc_cfg->vid_wnd_flags = PJMEDIA_VID_DEV_WND_BORDER |
|
||||
PJMEDIA_VID_DEV_WND_RESIZABLE;
|
||||
acc_cfg->vid_cap_dev = app_config.vid.vcapture_dev;
|
||||
acc_cfg->vid_rend_dev = app_config.vid.vrender_dev;
|
||||
|
||||
if (app_config.avi_auto_play &&
|
||||
app_config.avi_def_idx != PJSUA_INVALID_ID &&
|
||||
app_config.avi[app_config.avi_def_idx].dev_id != PJMEDIA_VID_INVALID_DEV)
|
||||
{
|
||||
acc_cfg->vid_cap_dev = app_config.avi[app_config.avi_def_idx].dev_id;
|
||||
}
|
||||
}
|
||||
#else
|
||||
PJ_DEF(void) app_config_init_video(pjsua_acc_config *acc_cfg)
|
||||
{
|
||||
PJ_UNUSED_ARG(acc_cfg);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MULTIPART_TEST
|
||||
/*
|
||||
* Enable multipart in msg_data and add a dummy body into the
|
||||
* multipart bodies.
|
||||
*/
|
||||
PJ_DEF(void) add_multipart(pjsua_msg_data *msg_data)
|
||||
{
|
||||
static pjsip_multipart_part *alt_part;
|
||||
|
||||
if (!alt_part) {
|
||||
pj_str_t type, subtype, content;
|
||||
|
||||
alt_part = pjsip_multipart_create_part(app_config.pool);
|
||||
|
||||
type = pj_str("text");
|
||||
subtype = pj_str("plain");
|
||||
content = pj_str("Sample text body of a multipart bodies");
|
||||
alt_part->body = pjsip_msg_body_create(app_config.pool, &type,
|
||||
&subtype, &content);
|
||||
}
|
||||
|
||||
msg_data->multipart_ctype.type = pj_str("multipart");
|
||||
msg_data->multipart_ctype.subtype = pj_str("mixed");
|
||||
pj_list_push_back(&msg_data->multipart_parts, alt_part);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* arrange windows. arg:
|
||||
* -1: arrange all windows
|
||||
* != -1: arrange only this window id
|
||||
*/
|
||||
PJ_DEF(void) arrange_window(pjsua_vid_win_id wid)
|
||||
{
|
||||
#if PJSUA_HAS_VIDEO
|
||||
pjmedia_coord pos;
|
||||
int i, last;
|
||||
|
||||
pos.x = 0;
|
||||
pos.y = 10;
|
||||
last = (wid == PJSUA_INVALID_ID) ? PJSUA_MAX_VID_WINS : wid;
|
||||
|
||||
for (i=0; i<last; ++i) {
|
||||
pjsua_vid_win_info wi;
|
||||
pj_status_t status;
|
||||
|
||||
status = pjsua_vid_win_get_info(i, &wi);
|
||||
if (status != PJ_SUCCESS)
|
||||
continue;
|
||||
|
||||
if (wid == PJSUA_INVALID_ID)
|
||||
pjsua_vid_win_set_pos(i, &pos);
|
||||
|
||||
if (wi.show)
|
||||
pos.y += wi.size.h;
|
||||
}
|
||||
|
||||
if (wid != PJSUA_INVALID_ID)
|
||||
pjsua_vid_win_set_pos(wid, &pos);
|
||||
#else
|
||||
PJ_UNUSED_ARG(wid);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if PJSUA_HAS_VIDEO
|
||||
PJ_DEF(void) vid_print_dev(int id, const pjmedia_vid_dev_info *vdi,
|
||||
const char *title)
|
||||
{
|
||||
char capnames[120];
|
||||
char formats[120];
|
||||
const char *dirname;
|
||||
unsigned i;
|
||||
|
||||
if (vdi->dir == PJMEDIA_DIR_CAPTURE_RENDER) {
|
||||
dirname = "capture, render";
|
||||
} else if (vdi->dir == PJMEDIA_DIR_CAPTURE) {
|
||||
dirname = "capture";
|
||||
} else {
|
||||
dirname = "render";
|
||||
}
|
||||
|
||||
|
||||
capnames[0] = '\0';
|
||||
for (i=0; i<sizeof(int)*8 && (1 << i) < PJMEDIA_VID_DEV_CAP_MAX; ++i) {
|
||||
if (vdi->caps & (1 << i)) {
|
||||
const char *capname = pjmedia_vid_dev_cap_name(1 << i, NULL);
|
||||
if (capname) {
|
||||
if (*capnames)
|
||||
strcat(capnames, ", ");
|
||||
strncat(capnames, capname,
|
||||
sizeof(capnames)-strlen(capnames)-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
formats[0] = '\0';
|
||||
for (i=0; i<vdi->fmt_cnt; ++i) {
|
||||
const pjmedia_video_format_info *vfi =
|
||||
pjmedia_get_video_format_info(NULL, vdi->fmt[i].id);
|
||||
if (vfi) {
|
||||
if (*formats)
|
||||
strcat(formats, ", ");
|
||||
strncat(formats, vfi->name, sizeof(formats)-strlen(formats)-1);
|
||||
}
|
||||
}
|
||||
|
||||
PJ_LOG(3,(THIS_FILE, "%3d %s [%s][%s] %s", id, vdi->name, vdi->driver,
|
||||
dirname, title));
|
||||
PJ_LOG(3,(THIS_FILE, " Supported capabilities: %s", capnames));
|
||||
PJ_LOG(3,(THIS_FILE, " Supported formats: %s", formats));
|
||||
}
|
||||
|
||||
PJ_DEF(void) vid_list_devs()
|
||||
{
|
||||
unsigned i, count;
|
||||
pjmedia_vid_dev_info vdi;
|
||||
pj_status_t status;
|
||||
|
||||
PJ_LOG(3,(THIS_FILE, "Video device list:"));
|
||||
count = pjsua_vid_dev_count();
|
||||
if (count == 0) {
|
||||
PJ_LOG(3,(THIS_FILE, " - no device detected -"));
|
||||
return;
|
||||
} else {
|
||||
PJ_LOG(3,(THIS_FILE, "%d device(s) detected:", count));
|
||||
}
|
||||
|
||||
status = pjsua_vid_dev_get_info(PJMEDIA_VID_DEFAULT_RENDER_DEV, &vdi);
|
||||
if (status == PJ_SUCCESS)
|
||||
vid_print_dev(PJMEDIA_VID_DEFAULT_RENDER_DEV, &vdi,
|
||||
"(default renderer device)");
|
||||
|
||||
status = pjsua_vid_dev_get_info(PJMEDIA_VID_DEFAULT_CAPTURE_DEV, &vdi);
|
||||
if (status == PJ_SUCCESS)
|
||||
vid_print_dev(PJMEDIA_VID_DEFAULT_CAPTURE_DEV, &vdi,
|
||||
"(default capture device)");
|
||||
|
||||
for (i=0; i<count; ++i) {
|
||||
status = pjsua_vid_dev_get_info(i, &vdi);
|
||||
if (status == PJ_SUCCESS)
|
||||
vid_print_dev(i, &vdi, "");
|
||||
}
|
||||
}
|
||||
|
||||
PJ_DEF(void) app_config_show_video(int acc_id, const pjsua_acc_config *acc_cfg)
|
||||
{
|
||||
PJ_LOG(3,(THIS_FILE,
|
||||
"Account %d:\n"
|
||||
" RX auto show: %d\n"
|
||||
" TX auto transmit: %d\n"
|
||||
" Capture dev: %d\n"
|
||||
" Render dev: %d",
|
||||
acc_id,
|
||||
acc_cfg->vid_in_auto_show,
|
||||
acc_cfg->vid_out_auto_transmit,
|
||||
acc_cfg->vid_cap_dev,
|
||||
acc_cfg->vid_rend_dev));
|
||||
}
|
||||
|
||||
|
||||
#endif
|
|
@ -16,8 +16,8 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef __PJSUA_CMD_H__
|
||||
#define __PJSUA_CMD_H__
|
||||
#ifndef __PJSUA_COMMON_H__
|
||||
#define __PJSUA_COMMON_H__
|
||||
|
||||
#include <pjsua-lib/pjsua.h>
|
||||
|
||||
|
@ -36,12 +36,12 @@ typedef struct input_result
|
|||
} input_result;
|
||||
|
||||
/* Call specific data */
|
||||
typedef struct call_data
|
||||
typedef struct app_call_data
|
||||
{
|
||||
pj_timer_entry timer;
|
||||
pj_bool_t ringback_on;
|
||||
pj_bool_t ring_on;
|
||||
} call_data;
|
||||
} app_call_data;
|
||||
|
||||
/* Video settings */
|
||||
typedef struct app_vid
|
||||
|
@ -75,7 +75,7 @@ typedef struct pjsua_app_config
|
|||
unsigned buddy_cnt;
|
||||
pjsua_buddy_config buddy_cfg[PJSUA_MAX_BUDDIES];
|
||||
|
||||
call_data call_data[PJSUA_MAX_CALLS];
|
||||
app_call_data call_data[PJSUA_MAX_CALLS];
|
||||
|
||||
pj_pool_t *pool;
|
||||
/* Compatibility with older pjsua */
|
||||
|
@ -139,16 +139,25 @@ typedef struct pjsua_app_config
|
|||
|
||||
/* CLI setting */
|
||||
pj_bool_t use_cli;
|
||||
unsigned cli_telnet_port;
|
||||
int cli_telnet_port;
|
||||
pj_bool_t disable_cli_console;
|
||||
} pjsua_app_config;
|
||||
|
||||
/** CLI callback **/
|
||||
/** This specifies the callback called when cli quit is called. **/
|
||||
typedef void (*pj_cli_on_quit)(pj_bool_t is_restarting);
|
||||
/** This callback is called when the cli is completely destroyed **/
|
||||
typedef void (*pj_cli_on_destroy)(void);
|
||||
/** This callback is called when pjsua restart command is invode by cli **/
|
||||
typedef void (*pj_cli_on_restart_pjsua)(void);
|
||||
|
||||
/** Extern variable declaration **/
|
||||
extern pjsua_call_id current_call;
|
||||
extern pjsua_app_config app_config;
|
||||
extern int stdout_refresh;
|
||||
extern pj_bool_t stdout_refresh_quit;
|
||||
extern pjsua_call_setting call_opt;
|
||||
extern pjsua_msg_data msg_data;
|
||||
extern pjsua_call_setting call_opt;
|
||||
extern pjsua_msg_data msg_data;
|
||||
|
||||
PJ_DECL(int) my_atoi(const char *cs);
|
||||
PJ_DECL(pj_bool_t) find_next_call();
|
||||
|
@ -159,10 +168,32 @@ PJ_DECL(int) write_settings(pjsua_app_config *cfg, char *buf, pj_size_t max);
|
|||
PJ_DECL(void) app_config_init_video(pjsua_acc_config *acc_cfg);
|
||||
PJ_DECL(void) arrange_window(pjsua_vid_win_id wid);
|
||||
|
||||
/** Defined in pjsua_cli_cmd.c **/
|
||||
PJ_DECL(pj_bool_t) is_cli_inited();
|
||||
|
||||
/** Defined in pjsua_app.c **/
|
||||
PJ_DECL(pj_status_t) app_init(pj_cli_telnet_on_started on_started_cb,
|
||||
pj_cli_on_quit on_quit_cb,
|
||||
pj_cli_on_destroy on_destroy_cb,
|
||||
pj_cli_on_restart_pjsua on_restart_pjsua_cb);
|
||||
PJ_DECL(void) setup_signal_handler(void);
|
||||
|
||||
/** Defined in pjsua_config.c **/
|
||||
/** This is to store the app runtime/startup options **/
|
||||
PJ_DECL(void) add_startup_config(int argc, char *argv[]);
|
||||
/** This is to store the app reload options **/
|
||||
PJ_DECL(void) add_reload_config(unsigned idx, pj_str_t *option);
|
||||
/** This is to load the configuration **/
|
||||
PJ_DECL(pj_status_t) load_config(pjsua_app_config *app_config,
|
||||
pj_str_t *uri_arg,
|
||||
pj_bool_t app_running);
|
||||
|
||||
#if PJSUA_HAS_VIDEO
|
||||
PJ_DECL(void) vid_print_dev(int id, const pjmedia_vid_dev_info *vdi, const char *title);
|
||||
PJ_DECL(void) vid_print_dev(int id, const pjmedia_vid_dev_info *vdi,
|
||||
const char *title);
|
||||
PJ_DECL(void) vid_list_devs();
|
||||
PJ_DECL(void) app_config_show_video(int acc_id, const pjsua_acc_config *acc_cfg);
|
||||
PJ_DECL(void) app_config_show_video(int acc_id,
|
||||
const pjsua_acc_config *acc_cfg);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MULTIPART_TEST
|
||||
|
@ -176,5 +207,8 @@ PJ_DECL(void) app_config_show_video(int acc_id, const pjsua_acc_config *acc_cfg)
|
|||
# define TEST_MULTIPART(msg_data)
|
||||
#endif
|
||||
|
||||
|
||||
PJ_END_DECL
|
||||
|
||||
#endif /* __PJSUA_CMD_H__ */
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -19,9 +19,10 @@
|
|||
*/
|
||||
|
||||
#include <pjsua-lib/pjsua.h>
|
||||
#include "pjsua_cmd.h"
|
||||
#include "pjsua_common.h"
|
||||
#include "gui.h"
|
||||
|
||||
#define THIS_FILE "pjsua_ui_cmd.c"
|
||||
#define THIS_FILE "pjsua_legacy.c"
|
||||
|
||||
static pj_bool_t cmd_echo;
|
||||
|
||||
|
@ -970,8 +971,7 @@ static void ui_call_reinvite()
|
|||
|
||||
static void ui_send_update()
|
||||
{
|
||||
if (current_call != -1) {
|
||||
call_opt.flag |= PJSUA_CALL_UNHOLD;
|
||||
if (current_call != -1) {
|
||||
pjsua_call_update2(current_call, &call_opt, NULL);
|
||||
} else {
|
||||
PJ_LOG(3,(THIS_FILE, "No current call"));
|
||||
|
@ -1936,5 +1936,24 @@ void console_app_main(const pj_str_t *uri_to_call, pj_bool_t *app_restart)
|
|||
|
||||
on_exit:
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void start_ui_main(pj_str_t *uri_to_call, pj_bool_t *app_restart)
|
||||
{
|
||||
pj_status_t status;
|
||||
*app_restart = PJ_FALSE;
|
||||
|
||||
status = pjsua_start();
|
||||
if (status != PJ_SUCCESS)
|
||||
return;
|
||||
|
||||
setup_signal_handler();
|
||||
|
||||
/* If user specifies URI to call, then call the URI */
|
||||
if (uri_to_call->slen) {
|
||||
pjsua_call_make_call(current_acc, uri_to_call, &call_opt, NULL,
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
console_app_main(uri_to_call, app_restart);
|
||||
}
|
Loading…
Reference in New Issue