[SIPForum-discussion] Script to call( incoming and outgoing ) with ASTERISK.

Shashank Pandey search4shashank at hotmail.com
Thu Aug 27 07:47:23 UTC 2009



 u can do that without script also , elaborate your requirment i will help you .

 

 

 

 

 


Date: Wed, 26 Aug 2009 13:24:33 -0400
From: rachelbaskaran at gmail.com
To: discussion at sipforum.org
Subject: Re: [SIPForum-discussion] Script to call( incoming and outgoing ) with ASTERISK.

Is anybody there to help me with this below mentioned issue. where I use X-Lite as my softphone.


On Mon, Aug 24, 2009 at 1:32 PM, Rachel Baskaran <rachelbaskaran at gmail.com> wrote:

Hey,

Now If I  have a ASTERISK at my workplace, how I need to connect to my other SIP acc or say my colleague?

Will the following script be enough to do the job?

#include<pjsua-lib/pjsua.h>

#define THIS_FILE       "APP"
#define SIP_DOMAIN   "test.com" ( where my company domain fits here )
#define SIP_USER       "rachel"
#define SIP_PASSWD   "test"

//function call for incoming call with acc_id, call_id
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);

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));

pjsua_call_answer(call_id, 200, NULL, NULL);
}


//main() where argv[] contains URI to call to
int main(int argc, char *argv[])
{
pjsua_acc_id acc_id;
pj_status_t status;


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


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

//Variable dec for config files
pjsua_config cfg;
pjsua_logging_config log_cfg;

pjsua_config_default(&cfg);
cfg.cb.on_incoming_call = &on_incoming_call;

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


//Intilize pjsua 
status = pjsua_init(&cfg, &log_cfg, NULL);
if(status != PJ_SUCESS) 
error_exit("Error in pjsua_init()", status);
}

//transport through UDP 
{
pjsua_transport_config cfg;


pjsua_transport_config_default(&cfg);
cfg.port = 5060;
 status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
if(status != PJ_SUCESS) 
error_exit("Error creating transport", status);
}

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

if(argc > 1){
pj_str_t uri = pj_str(argv[1]);
status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL);
if(status != PJ_SUCESS) 
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;
}


let's consider for example, that I'm gonna edit my sip.conf file as
[general]

[1000] (unique identifier)
type= friend ( includes both user and peer )
context = phones
host = dynamic ( client has a dynamic IP address )


Does the acc_id refers to my id( i.e rachel ) or my colleague's? What about the call_id?

If this script is right, where I need to store my script and run with GNU compiler?

Any help would be great!


Thanks
Rachel









 



_________________________________________________________________
News, sports, entertainment and fine living…learn the ropes on MSN India
http://in.msn.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sipforum.org/pipermail/discussion/attachments/20090827/15912041/attachment-0002.html>


More information about the discussion mailing list