Registers but doesn't call the specified URL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey,

I tried a script to register and once registered call the specified URL. It
registers and I hope since it's example.com, it shows the SIP registration
failed, timeout.

I want to make it work for a proper sip provider to handle the sip calls
where it registers in right way . I'm attaching the code I'm not sure what
am I'm missing?


#include<pjsua-lib/pjsua.h>
#define THIS_FILE "APP"

#define SIP_DST_URI   "<sip:100 at example.com <sip%3A100 at example.com>>"



#define SIP_DOMAIN "example.com"
#define SIP_USER   "rachel"
#define SIP_PASSWD "secret"

/* Globals */

static pjsua_acc_id  acc_id = PJSUA_INVALID_ID;


/* callback for incoming call */

static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id,
pjsip_rx_data *rdata)
{

pjsua_call_info ci;

PJ_UNUSED_ARG(acc_id);
PJ_UNUSED_ARG(rdata);

if(acc_id != PJSUA_INVALID_ID) {
pjsua_call_answer(call_id, PJSIP_SC_BUSY_HERE, NULL, NULL);
return;
}

pjsua_call_get_info(call_id, &ci);

PJ_LOG(3,(THIS_FILE, "Incoming call from
%.*s!!",(int)ci.remote_info.slen,ci.remote_info.ptr));

}



/* Display error and exit the app */
static void error_exit(const char *title,pj_status_t status)
{
pjsua_perror(THIS_FILE, title, status);
pjsua_destroy();
exit(1);
}


int main(int argc,char *url)
{
pjsua_acc_id acc_id;
pj_status_t status;


status = pjsua_create();
if(status != PJ_SUCCESS)  error_exit("Error in pjsua_create()", status);


if(argc > 1)
{
status = pjsua_verify_sip_url(url);
if(status != PJ_SUCCESS)  error_exit("Invalid URL in argv", status);
}

/* Init pjsua */
 {

pjsua_config cfg;
pjsua_logging_config log_cfg;


pjsua_config_default(&cfg);



pjsua_logging_config_default(&log_cfg);
log_cfg.console_level = 4;


status = pjsua_init(&cfg, &log_cfg, NULL);
if(status != PJ_SUCCESS)  error_exit("Error in pjsua_init()", status);
}



/* add UDP transport */
{

pjsua_transport_config cfg;
 pjsua_transport_config_default(&cfg);
cfg.port = 5060;
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
if(status != PJ_SUCCESS)  error_exit("Error creating transport", status);
}
/* start pjsua */

status = pjsua_start();
if(status != PJ_SUCCESS) error_exit("Error starting pjsua", status);

/* Register to SIP server creating an account */

{
pjsua_acc_config cfg;


pjsua_acc_config_default(&cfg);
cfg.id = pj_str("sip:" SIP_USER "@" SIP_DOMAIN);
cfg.reg_uri = pj_str("sip:" SIP_DOMAIN);
cfg.cred_count = 1;
cfg.cred_info[0].realm = pj_str(SIP_DOMAIN);
cfg.cred_info[0].username = pj_str(SIP_USER);
cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
cfg.cred_info[0].data = pj_str(SIP_PASSWD);

status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);
if(status != PJ_SUCCESS)  error_exit("Error adding account", status);
}

if(argc > 1)
{

url = SIP_DST_URI;

pj_str_t uri = pj_str(url);
status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL);
if(status != PJ_SUCCESS) error_exit("Error making call", status);
}

for(;;){
char option[10];

puts("Press h to hangup all calls, 'q' to quit");
if(fgets(option, sizeof(option), stdin) == NULL){
puts("EOF while reading stdin, will quit now...");
break;
}

if(option[0] == 'q')
break;

if(option[0] == 'h')
pjsua_call_hangup_all();
}

pjsua_destroy();
return 0;
}


Any help would be great!

Will the above work If I use a phone number (
sip:423-678-9983 at sipprovider.com <sip%3A423-678-9983 at sipprovider.com> )?

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20090908/5872acf5/attachment.html>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux