Hello list,
I'm trying to get a simple "hello world" sample up and going and I am
having trouble sending and receiving an INVITE. I've looked at
http://wiki.opensource.nokia.com/projects/SofiaTutorial and I can send and
receive a simple message. But I would like help sending and receiving an
INVITE (the API is still very new to me).
Below is my humble attempt, can anyone see where I have messed up big time
and help me resolve the issue.
I would like the Caller to send the invite to the Callee.
Thank you in advance!
---code---
#include <stdio.h>
#include <sofia-sip/nua.h>
// #define CALLER 1
struct application
{
su_home_t home; /* memory home */
su_root_t* root; /* root object */
nua_t* nua; /* NUA stack object */
};
void event_callback(nua_event_t event, int status, const char* phrase,
nua_t* nua, nua_magic_t* magic, nua_handle_t* nh, nua_hmagic_t* hmagic,
const sip_t* sip, tagi_t tags[]);
void send_invite(nua_t* nua, su_home_t*);
void event_i_invite(int status, const char* phrase, nua_t* nua,
nua_magic_t* magic, nua_handle_t* nh, nua_hmagic_t* hmagic, const sip_t*
sip, tagi_t tags[]);
void event_r_invite(int status, const char* phrase, nua_t* nua,
nua_magic_t* magic, nua_handle_t* nh, nua_hmagic_t* hmagic, const sip_t*
sip, tagi_t tags[]);
int main(int argc, char* argv[])
{
application app = {0};
app.home.suh_size = sizeof(application);
su_init();
su_home_init(&app.home);
app.root = su_root_create(&app);
#ifdef CALLER
printf("I am the Caller\n");
#else
printf("I am the Callee\n");
#endif
if (app.root != NULL)
{
app.nua = nua_create(app.root, event_callback, &app,
#ifdef CALLER
NUTAG_URL("sip:0.0.0.0:5062"),
/* Address to bind to */
#else
NUTAG_URL("sip:0.0.0.0:5060"),
#endif
TAG_END());
if (app.nua != NULL)
{
nua_set_params(app.nua, SIPTAG_USER_AGENT_STR("Simon/1.0"),
SIPTAG_ALLOW_STR("INVITE,CANCEL,BYE,ACK"),
SIPTAG_USER_AGENT(NULL),
NUTAG_AUTOACK(1),
TAG_END());
#ifdef CALLER
send_invite(app.nua, &app.home);
#endif
su_root_run(app.root);
nua_destroy(app.nua);
}
su_root_destroy(app.root);
}
su_home_deinit(&app.home);
su_deinit();
return 0;
}
void event_callback(nua_event_t event, int status, const char* phrase,
nua_t* nua, nua_magic_t* magic, nua_handle_t* nh, nua_hmagic_t* hmagic,
const sip_t* sip, tagi_t tags[])
{
switch (event)
{
case nua_i_invite:
event_i_invite(status, phrase, nua, magic, nh, hmagic, sip, tags);
break;
case nua_r_invite:
event_r_invite(status, phrase, nua, magic, nh, hmagic, sip, tags);
break;
case nua_r_set_params:
break;
/* and so on ... */
default:
/* unknown event -> print out error message */
if (status > 100)
{
printf("Unknown event %d: %03d %s\n", event, status, phrase);
}
else
{
printf("Unknown event %d\n", event);
}
}
return;
}
void send_invite(nua_t* nua, su_home_t* h)
{
nua_handle_t* handle = nua_handle(nua, h,
SIPTAG_TO_STR("sip:[EMAIL PROTECTED]:5060"), TAG_END());
nua_invite(handle, TAG_END());
nua_handle_destroy(handle);
return;
}
void event_i_invite(int status, const char* phrase, nua_t* nua,
nua_magic_t* magic, nua_handle_t* nh, nua_hmagic_t* hmagic, const sip_t*
sip, tagi_t tags[])
{
printf("Incoming call...\n");
return;
}
void event_r_invite(int status, const char* phrase, nua_t* nua,
nua_magic_t* magic, nua_handle_t* nh, nua_hmagic_t* hmagic, const sip_t*
sip, tagi_t tags[])
{
printf("Response to INVITE: %03d %s\n", status, phrase);
return;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Sofia-sip-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel