ht0-initialize.dox 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @ingroup libosip2 The GNU oSIP stack
  3. * @defgroup howto_initialize How-To initialize libosip2.
  4. * @section howto_initialize1 Initialize osip.
  5. When using osip, your first task is to initialize
  6. the parser and the state machine. This must be done
  7. prior to any use of libosip2.
  8. ~~~~~~~{.c}
  9. #include <osip2/osip.h>
  10. int i;
  11. osip_t *osip;
  12. i=osip_init(&osip);
  13. if (i!=0)
  14. return -1;
  15. ~~~~~~~
  16. In case you want to use the state machines (transaction management),
  17. the second step will be to set a few callbacks which will inform
  18. you of any change in the state of a SIP transaction.
  19. Most of the following callbacks are optional. The following ones are
  20. usefull.
  21. ~~~~~~~{.c}
  22. // callback called when a SIP message must be sent.
  23. osip_set_cb_send_message(osip, &cb_udp_snd_message);
  24. // callback called when a SIP transaction is TERMINATED.
  25. osip_set_kill_transaction_callback(osip ,OSIP_ICT_KILL_TRANSACTION,
  26. &cb_ict_kill_transaction);
  27. osip_set_kill_transaction_callback(osip ,OSIP_IST_KILL_TRANSACTION,
  28. &cb_ist_kill_transaction);
  29. osip_set_kill_transaction_callback(osip ,OSIP_NICT_KILL_TRANSACTION,
  30. &cb_nict_kill_transaction);
  31. osip_set_kill_transaction_callback(osip ,OSIP_NIST_KILL_TRANSACTION,
  32. &cb_nist_kill_transaction);
  33. // callback called when the callback to send message have failed.
  34. osip_set_transport_error_callback(osip ,OSIP_ICT_TRANSPORT_ERROR,
  35. &cb_transport_error);
  36. osip_set_transport_error_callback(osip ,OSIP_IST_TRANSPORT_ERROR,
  37. &cb_transport_error);
  38. osip_set_transport_error_callback(osip ,OSIP_NICT_TRANSPORT_ERROR,
  39. &cb_transport_error);
  40. osip_set_transport_error_callback(osip ,OSIP_NIST_TRANSPORT_ERROR,
  41. &cb_transport_error);
  42. // callback called when a received answer has been accepted by the transaction.
  43. osip_set_message_callback(osip ,OSIP_ICT_STATUS_1XX_RECEIVED, &cb_rcv1xx);
  44. osip_set_message_callback(osip ,OSIP_ICT_STATUS_2XX_RECEIVED, &cb_rcv2xx);
  45. osip_set_message_callback(osip ,OSIP_ICT_STATUS_3XX_RECEIVED, &cb_rcv3456xx);
  46. osip_set_message_callback(osip ,OSIP_ICT_STATUS_4XX_RECEIVED, &cb_rcv3456xx);
  47. osip_set_message_callback(osip ,OSIP_ICT_STATUS_5XX_RECEIVED, &cb_rcv3456xx);
  48. osip_set_message_callback(osip ,OSIP_ICT_STATUS_6XX_RECEIVED, &cb_rcv3456xx);
  49. // callback called when a received answer has been accepted by the transaction.
  50. osip_set_message_callback(osip ,OSIP_NICT_STATUS_1XX_RECEIVED, &cb_rcv1xx);
  51. osip_set_message_callback(osip ,OSIP_NICT_STATUS_2XX_RECEIVED, &cb_rcv2xx);
  52. osip_set_message_callback(osip ,OSIP_NICT_STATUS_3XX_RECEIVED, &cb_rcv3456xx);
  53. osip_set_message_callback(osip ,OSIP_NICT_STATUS_4XX_RECEIVED, &cb_rcv3456xx);
  54. osip_set_message_callback(osip ,OSIP_NICT_STATUS_5XX_RECEIVED, &cb_rcv3456xx);
  55. osip_set_message_callback(osip ,OSIP_NICT_STATUS_6XX_RECEIVED, &cb_rcv3456xx);
  56. // callback called when a received request has been accepted by the transaction.
  57. osip_set_message_callback(osip ,OSIP_IST_INVITE_RECEIVED, &cb_rcvreq);
  58. osip_set_message_callback(osip ,OSIP_IST_ACK_RECEIVED, &cb_rcvreq);
  59. osip_set_message_callback(osip ,OSIP_NIST_REGISTER_RECEIVED, &cb_rcvreq);
  60. osip_set_message_callback(osip ,OSIP_NIST_BYE_RECEIVED, &cb_rcvreq);
  61. osip_set_message_callback(osip ,OSIP_NIST_CANCEL_RECEIVED, &cb_rcvreq);
  62. osip_set_message_callback(osip ,OSIP_NIST_INFO_RECEIVED, &cb_rcvreq);
  63. osip_set_message_callback(osip ,OSIP_NIST_OPTIONS_RECEIVED, &cb_rcvreq);
  64. osip_set_message_callback(osip ,OSIP_NIST_SUBSCRIBE_RECEIVED, &cb_rcvreq);
  65. osip_set_message_callback(osip ,OSIP_NIST_NOTIFY_RECEIVED, &cb_rcvreq);
  66. osip_set_message_callback(osip ,OSIP_NIST_UNKNOWN_REQUEST_RECEIVED, &cb_rcvreq);
  67. // other callbacks exists... They are optionnal.
  68. ~~~~~~~
  69. */