dlg_request.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include "dlg_request.h"
  2. #include "dlg_mod_internal.h"
  3. /*
  4. * Send an initial request that will start a dialog with given route header
  5. * the dialog must be created before!!!
  6. */
  7. int request_outside(str* method, str* headers, str* body, dlg_t* dialog, transaction_cb cb, void* cbp)
  8. {
  9. uac_req_t uac_r;
  10. /* check parameters */
  11. if ((!dialog) || (!method)) goto err;
  12. if ((method->len < 0) || (!method->s)) goto err;
  13. if (dialog->state != DLG_NEW) {
  14. LOG(L_ERR, "req_within: Dialog is not in DLG_NEW state\n");
  15. goto err;
  16. }
  17. if (!dialog->hooks.next_hop) {
  18. /* FIXME: this is only experimental - hooks are calculated only when
  19. * next hop is not known */
  20. if (tmb.calculate_hooks(dialog) < 0) {
  21. LOG(L_ERR, "Error while calculating hooks\n");
  22. return -2;
  23. }
  24. }
  25. set_uac_req(&uac_r,
  26. method,
  27. headers,
  28. body,
  29. dialog,
  30. TMCB_LOCAL_COMPLETED,
  31. cb,
  32. cbp);
  33. return tmb.t_uac(&uac_r);
  34. err:
  35. /* if (cbp) shm_free(cbp);*/ /* !!! never do this automaticaly??? !!! */
  36. /* call the callback? Probably not because we can be in locked section
  37. * and the callback can try to lock it too. */
  38. return -1;
  39. }
  40. /*
  41. * Send a message within a dialog
  42. */
  43. int request_inside(str* method, str* headers, str* body, dlg_t* dialog, transaction_cb completion_cb, void* cbp)
  44. {
  45. uac_req_t uac_r;
  46. if (!method || !dialog) {
  47. LOG(L_ERR, "req_within: Invalid parameter value\n");
  48. goto err;
  49. }
  50. if (dialog->state != DLG_CONFIRMED) {
  51. LOG(L_ERR, "req_within: Dialog is not confirmed yet\n");
  52. goto err;
  53. }
  54. if ((method->len == 3) && (!memcmp("ACK", method->s, 3))) goto send;
  55. if ((method->len == 6) && (!memcmp("CANCEL", method->s, 6))) goto send;
  56. dialog->loc_seq.value++; /* Increment CSeq */
  57. send:
  58. set_uac_req(&uac_r,
  59. method,
  60. headers,
  61. body,
  62. dialog,
  63. TMCB_LOCAL_COMPLETED,
  64. completion_cb,
  65. cbp);
  66. return tmb.t_uac(&uac_r);
  67. err:
  68. /* if (cbp) shm_free(cbp); */ /* !!! never !!! */
  69. return -1;
  70. }