----- Original Message ----- From: "Sanjay Nayak" <sanjay.nayak....@gmail.com>

main();

It's not a good idea to call a function 'main' - and doing so might even cause problems. Call it something else, eg 'foo'.
And then call foo as:

foo($url); # where $url is a valid SIP URL
__DATA__
__C__

.
.

I don't know what constitutes a valid sip url, but I guess it's a string anyway.
int main(int argc, char *argv[])
Change that to:

int foo(char * url)

{
   pjsua_acc_id acc_id;
   pj_status_t status;

   // Create pjsua first!
   status = pjsua_create();
if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);


I've done away with argc and argv. Therefore:

/* // If argument is specified, it's got to be a valid SIP URL */ /*removed by sisyphus */
   /* if (argc > 1) */ /*removed by sisyphus */
   /* { */ /*removed by sisyphus */
status = pjsua_verify_sip_url(url); */sisyphus changed 'argv[1]' to '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);
   cfg.cb.on_incoming_call = &on_incoming_call;
   cfg.cb.on_call_media_state = &on_call_media_state;
   cfg.cb.on_call_state = &on_call_state;

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

   // Initialization is done, now start pjsua

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

   // Register to SIP server by creating SIP 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(acti.com);
   cfg.cred_info[0].scheme = pj_str("digest");
   cfg.cred_info[0].username = pj_str(sanjay);
   cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
   cfg.cred_info[0].data = pj_str(sanjay);

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


Again, remove this as there's now no argc:

  /*  // If URL is specified, make call to the URL.
   if (argc > 1)
   { */

Again change 'argv[1]' to 'url'

   pj_str_t uri = pj_str(url); /* sisyphus changed 'argv[1]' to 'url' */
   status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL);
   if (status != PJ_SUCCESS) error_exit("Error making call", status);

And remove the closing bracket:

/* } */

   // Wait until user press "q" to quit.
   for (;;)
   {
   char option[10];

   puts("Press 'h' to hangup all calls, 'q' to quit");
   fgets(option, sizeof(option), stdin);

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

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

   // Destroy pjsua
   pjsua_destroy();

return 0;
}

See how that goes.

Cheers,
Rob

Reply via email to