ht2-registration.dox 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * @ingroup libeXosip2 The eXtented eXosip stack
  3. * @defgroup howto_registration How-To send or update registrations.
  4. <H2>Initiate a registration</H2>
  5. To start a registration, you need to build a default REGISTER request
  6. by providing several mandatory headers.
  7. You can start as many registration you want even in one eXosip_t context.
  8. ~~~~~~~{.c}
  9. osip_message_t *reg = NULL;
  10. int rid;
  11. int i;
  12. eXosip_lock (ctx);
  13. rid = eXosip_register_build_initial_register (ctx, "sip:me@sip.antisip.com", "sip.antisip.com", NULL, 1800, &reg);
  14. if (rid < 0)
  15. {
  16. eXosip_unlock (ctx);
  17. return -1;
  18. }
  19. osip_message_set_supported (reg, "100rel");
  20. osip_message_set_supported (reg, "path");
  21. i = eXosip_register_send_register (ctx, rid, reg);
  22. eXosip_unlock (ctx);
  23. return i;
  24. ~~~~~~~
  25. The returned element of eXosip_register_build_initial_register is the
  26. registration identifier that you can use to update your registration.
  27. In future events about this registration, you'll see that registration
  28. identifier when applicable.
  29. <H2>Contact headers in REGISTER</H2>
  30. You should let eXosip2 manage contact headers alone. The setup you
  31. have provided will generate various behavior, all being controlled
  32. by eXosip2. See the "NAT and Contact header" section in setup
  33. documentation.
  34. <H2>Set password(s)!</H2>
  35. Usually, you will need a login/password to access a service!
  36. eXosip can be used to access several service at the same time and thus
  37. the realm (identify the service) needs to be provided if you are
  38. using several services in the same instance.
  39. The simple way when you use one service with username being the same
  40. as the login:
  41. ~~~~~~~{.c}
  42. eXosip_lock (ctx);
  43. eXosip_add_authentication_info (ctx, login, login, passwd, NULL, NULL);
  44. eXosip_unlock (ctx);
  45. ~~~~~~~
  46. OR the complete way:
  47. ~~~~~~~{.c}
  48. eXosip_lock (ctx);
  49. eXosip_add_authentication_info (ctx, login, login, passwd, NULL, "sip.antisip.com");
  50. eXosip_add_authentication_info (ctx, from_username, login, passwd, NULL, "otherservice.com");
  51. eXosip_unlock (ctx);
  52. ~~~~~~~
  53. <H2>Delete all registration</H2>
  54. This feature is not advised by sip specification, but it exists for some
  55. purpose & reasons! You can send "*" in Contact header of a REGISTER to
  56. ask for immediate removal of all active registrations for a particular
  57. SIP agent:
  58. ~~~~~~~{.c}
  59. rid = eXosip_register_build_initial_register (ctx, "sip:me@sip.antisip.com", "sip.antisip.com", "*", 1800, &reg);
  60. ~~~~~~~
  61. <H2>Update a registration</H2>
  62. You just need to reuse the registration identifier:
  63. ~~~~~~~{.c}
  64. int i;
  65. eXosip_lock (ctx);
  66. i = eXosip_register_build_register (ctx, rid, 1800, &reg);
  67. if (i < 0)
  68. {
  69. eXosip_unlock (ctx);
  70. return -1;
  71. }
  72. eXosip_register_send_register (ctx, rid, reg);
  73. eXosip_unlock (ctx);
  74. ~~~~~~~
  75. <b>Note</b>: The above code also shows that the stack is sometimes able to
  76. build and send a default SIP messages with only one API call
  77. <H2>Closing the registration</H2>
  78. A softphone should delete its registration on the SIP server when terminating.
  79. To do so, you have to send a REGISTER request with the expires header set to
  80. value "0".
  81. The same code as for updating a registration is used with 0 instead of 1800
  82. for the expiration delay.
  83. ~~~~~~~{.c}
  84. int i;
  85. eXosip_lock (ctx);
  86. i = eXosip_register_build_register (ctx, rid, 0, &reg);
  87. if (i < 0)
  88. {
  89. eXosip_unlock (ctx);
  90. return -1;
  91. }
  92. eXosip_register_send_register (ctx, rid, reg);
  93. eXosip_unlock (ctx);
  94. ~~~~~~~
  95. <H2>Discard registration context</H2>
  96. If you need to delete a context without sending a REGISTER with expires 0,
  97. you can use eXosip_register_remove to release memory.
  98. ~~~~~~~{.c}
  99. int i;
  100. eXosip_lock (ctx);
  101. i = eXosip_register_remove (ctx, rid);
  102. if (i == 0) {
  103. }
  104. eXosip_unlock (ctx);
  105. ~~~~~~~
  106. */