First: sorry about the size of this post.

I have been trying for some time to get basic functionality working using Sofia; essentially send an INVITE to a Sip server (Asterisk) and have it "work". I continually get an error '900' which seems to be translated from an internal error '500'. As near as I can tell, that means I have no session. I really don't understand the meaning of this. I'm trying to create a session, therefore, I don't have one... yet...

Here is my code in its entirety, most of which was culled from various examples from the net. I have tried many different variations, in small detail, and am still stuck with the error 900.

It would be much appreciated If someone could please point out the error in this simple code.

Thanks:


#include <stdio.h>

#include <sofia-sip/nua.h>



typedef struct SipSession
{
        nua_handle_t    *nua_handle;
} SipSession ;


static SipSession *make_call(char const *name, url_string_t const *url);


static void event_callback(nua_event_t   event,
                    int           status,
                    char const   *phrase,
                    nua_t        *nua,
                    nua_magic_t  *magic,
                    nua_handle_t *nh,
                    nua_hmagic_t *hmagic,
                    sip_t const  *sip,
                    tagi_t        tags[]);

static void app_r_invite(int           status,
                  char const   *phrase,
                  nua_t        *nua,
                  nua_magic_t  *magic,
                  nua_handle_t *nh,
                  nua_hmagic_t *hmagic,
                  sip_t const  *sip,
                  tagi_t        tags[]);

static void app_i_invite(int           status,
                  char const   *phrase,
                  nua_t        *nua,
                  nua_magic_t  *magic,
                  nua_handle_t *nh,
                  nua_hmagic_t *hmagic,
                  sip_t const  *sip,
                  tagi_t        tags[]);

static void app_i_active(int           status,
                   char const   *phrase,
                   nua_t        *nua,
                   nua_magic_t  *magic,
                   nua_handle_t *nh,
                   nua_hmagic_t *hmagic,
                   sip_t const  *sip,
                   tagi_t        tags[]);




static su_home_t *su_home = NULL;
static nua_t *nua = NULL;



int
main (int argc, char *argv[])
{

  su_log_set_level (NULL, 9);

  su_root_t *root;

  su_home = su_home_new (sizeof (*su_home));


  /* Initialize Sofia-SIP library and create event loop */

  su_init ();
  root = su_root_create (NULL);

  /* Create a user agent instance. Caller and callee should bind to different
   * address to avoid conflicts. The stack will call the 'event_callback()'
   * callback when events such as succesful registration to network,
   * an incoming call, etc, occur.
   */
  nua = nua_create (root,       /* Event loop */
                    event_callback,     /* Callback for processing events */
                    NULL,       /* Additional data to pass to callback */
                    NUTAG_URL ("sip: 127.0.0.1:5061"),   /* Address to bind to */
                    TAG_END ());        /* Last tag should always finish the sequence */

  char *url = "" href="mailto:sip:[EMAIL PROTECTED]">sip:[EMAIL PROTECTED] ";
  SipSession *ss = make_call ("frank", URL_STRING_MAKE (url));

  /* Run event loop */
  su_root_run (root);

  /* Destroy allocated resources */
  nua_destroy (nua);
  su_root_destroy (root);
  su_deinit ();

  return 0;
}



// Handling of the events coming from NUA stack is done in the callback function that is registered for NUA stack
// with the nua_create() function when the application is initialized. The content of callback function is in
// its simplest form just a switch/case statement that dispatches the incoming events for processing to separate functions.
//
static void
event_callback (nua_event_t event,
                int status,
                char const *phrase,
                nua_t * nua,
                nua_magic_t * magic,
                nua_handle_t * nh,
                nua_hmagic_t * hmagic, sip_t const *sip, tagi_t tags[])
{
  switch (event)
    {
    case nua_i_invite:
      app_i_invite (status, phrase, nua, magic, nh, hmagic, sip, tags);
      break;

    case nua_r_invite:
      app_r_invite (status, phrase, nua, magic, nh, hmagic, sip, tags);
      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);
        }
      tl_print (stdout, "", tags);
      break;
    }
}                               /* event_callback */



// The make_call() function creates an SipSession handle and invokes the SIP INVITE method.
//
static SipSession *
make_call (char const *name, url_string_t const *url)
{
  SipSession *ss;
  sip_to_t *to;

  /* create SipSession context information */
  ss = su_zalloc (su_home, (sizeof *ss));
  if (!ss)
    return NULL;

  /* Destination address */
  to = (sip_to_t *) sip_to_create (NULL, url);
  if (!to)
  {
    return NULL;
        }

  to->a_display = name;

  /* create SipSession handle */
  ss->nua_handle = nua_handle (nua, ss, SIPTAG_TO (to), TAG_END ());

  if (ss->nua_handle == NULL)
    {
      printf ("cannot create SipSession handle\n");
      return NULL;
    }

        // int rtp = OpenRtp ("127.0.0.1", "5061");

  nua_invite (ss->nua_handle, NUTAG_URL (url),
              SOATAG_ADDRESS("127.0.0.1:8000"),
              NUTAG_EARLY_MEDIA (1), TAG_END ());

}                               /* make_call */



// The app_r_invite() function is called by callback function when response to INVITE message is received.
// Here it is assumed that automatic acknowledge is not enabled so ACK response must be sent explicitly.
//
static void
app_r_invite (int status,
              char const *phrase,
              nua_t * nua,
              nua_magic_t * magic,
              nua_handle_t * nh,
              nua_hmagic_t * hmagic, sip_t const *sip, tagi_t tags[])
{
  if (status == 200)
    {
      nua_ack (nh, TAG_END ());
    }
  else
    {
      printf ("response to INVITE: %03d %s\n", status, phrase);
    }
}                               /* app_r_invite */



// The app_i_state() function is called by callback function when call has been successfully set up and the media has been activated.
//
static void
app_i_active (int status,
              char const *phrase,
              nua_t * nua,
              nua_magic_t * magic,
              nua_handle_t * nh,
              nua_hmagic_t * hmagic, sip_t const *sip, tagi_t tags[])
{
  printf ("call active\n");

}                               /* app_i_active */



// Receive a call
// The app_i_invite() function is called by callback function when incoming INVITE message is received.
// This example assumes that autoanswer is not enabled so the response must be sent explicitly.
//
static void
app_i_invite (int status,
              char const *phrase,
              nua_t * nua,
              nua_magic_t * magic,
              nua_handle_t * nh,
              nua_hmagic_t * hmagic, sip_t const *sip, tagi_t tags[])
{
  printf ("incoming call\n");

  nua_respond (nh, 200, "OK", TAG_END ());

}                               /* app_i_invite */



// Terminating a call
// The following three functions show an example of how a basic SIP call is terminated.
// The terminate_call() function sends the SIP BYE message.
//
static void
terminate_call (void)
{
  // nua_bye(ss->handle, TAG_END());

}                               /* terminate call */



// The app_r_bye() function is called by the callback function when answer to the BYE message is received.
// The function destroys the call handle and releases the memory allocated to SipSession context information.
//
static void
app_r_bye (int status,
           char const *phrase,
           nua_t * nua,
           nua_magic_t * magic,
           nua_handle_t * nh,
           nua_hmagic_t * hmagic, sip_t const *sip, tagi_t tags[])
{
  if (status < 200)
    return;

  printf ("call released\n");

  /* release SipSession handle */
  // nua_handle_destroy(ss->handle);
  // ss->handle = NULL;

  /* release SipSession context information */
  su_free (su_home, hmagic);

}                               /* app_r_bye */



// The app_i_bye() function is called by the callback function when an incoming BYE message is received.
// The function destroys the call handle and releases the memory allocated to SipSession context information.
//
static void
app_i_bye (int status,
           char const *phrase,
           nua_t * nua,
           nua_magic_t * magic,
           nua_handle_t * nh,
           nua_hmagic_t * hmagic, sip_t const *sip, tagi_t tags[])
{
  printf ("call released\n");

  /* release SipSession handle */
  // nua_handle_destroy(ss->handle);
  // ss->handle = NULL;

  /* release SipSession context information */
  // su_free(su_home, hmagic);

}                               /* app_i_bye */

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sofia-sip-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to