int
eXosip_insubscription_build_answer (int tid, int status, osip_message_t ** answer)
{
  int i = -1;
  eXosip_dialog_t *jd = NULL;
  eXosip_notify_t *jn = NULL;
  osip_transaction_t *tr = NULL;

  *answer = NULL;

  if (tid <= 0)
    return OSIP_BADPARAMETER;

  if (tid > 0)
    {
      _eXosip_insubscription_transaction_find (tid, &jn, &jd, &tr);
    }
  if (tr == NULL || jd == NULL || jn == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No incoming subscription here?\n"));
      return OSIP_NOTFOUND;
    }

  if (status < 101 || status > 699)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: wrong status code (101<status<699)\n"));
      return OSIP_BADPARAMETER;
    }

  if (jd != NULL)
    i =
      _eXosip_build_response_default (answer, jd->d_dialog, status,
                                      tr->orig_request);
  else
    i = _eXosip_build_response_default (answer, NULL, status, tr->orig_request);

  if (i != 0)
    {
      OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL,
                              "ERROR: Could not create response for %s\n",
                              tr->orig_request->sip_method));
      return i;
    }

  if (status >= 200 && status <= 299)
    _eXosip_notify_add_expires_in_2XX_for_subscribe (jn, *answer);

  if (status < 300)
    i = complete_answer_that_establish_a_dialog (*answer, tr->orig_request);

  return i;
}
Example #2
0
static int
_eXosip_retry_notify_with_auth (eXosip_event_t * je)
{
  /* TODO untested */
  eXosip_dialog_t *jd = NULL;
  eXosip_notify_t *jn = NULL;
  osip_transaction_t *tr=NULL;

  if (_eXosip_insubscription_transaction_find (je->tid, &jn, &jd, &tr) < 0)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: notify dialog not found\n"));
      return -1;
    }

  return _eXosip_insubscription_send_request_with_credential (jn, jd, tr);

}
int
eXosip_insubscription_send_answer (int tid, int status, osip_message_t * answer)
{
    int i = -1;
    eXosip_dialog_t *jd = NULL;
    eXosip_notify_t *jn = NULL;
    osip_transaction_t *tr = NULL;
    osip_event_t *evt_answer;

    if (tid > 0)
    {
        _eXosip_insubscription_transaction_find (tid, &jn, &jd, &tr);
    }
    if (jd == NULL || tr == NULL || tr->orig_request == NULL
            || tr->orig_request->sip_method == NULL)
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_ERROR, NULL,
                     "eXosip: No incoming subscription here?\n"));
        osip_message_free (answer);
        return -1;
    }

    if (answer == NULL)
    {
        if (0 == osip_strcasecmp (tr->orig_request->sip_method, "SUBSCRIBE"))
        {
            if (status >= 101 && status <= 199)
            {
            } else if (status >= 300 && status <= 699)
            {
            } else
            {
                OSIP_TRACE (osip_trace
                            (__FILE__, __LINE__, OSIP_ERROR, NULL,
                             "eXosip: Wrong parameter?\n"));
                return -1;
            }
        }
    }

    /* is the transaction already answered? */
    if (tr->state == NIST_COMPLETED || tr->state == NIST_TERMINATED)
    {
        OSIP_TRACE (osip_trace
                    (__FILE__, __LINE__, OSIP_ERROR, NULL,
                     "eXosip: transaction already answered\n"));
        osip_message_free (answer);
        return -1;
    }

    if (answer == NULL)
    {
        if (0 == osip_strcasecmp (tr->orig_request->sip_method, "SUBSCRIBE"))
        {
            if (status < 200)
                i = _eXosip_insubscription_answer_1xx (jn, jd, status);
            else
                i = _eXosip_insubscription_answer_3456xx (jn, jd, status);
            if (i != 0)
            {
                OSIP_TRACE (osip_trace
                            (__FILE__, __LINE__, OSIP_ERROR, NULL,
                             "eXosip: cannot send response!\n"));
                return -1;
            }
        } else
        {
            /* TODO */
            OSIP_TRACE (osip_trace
                        (__FILE__, __LINE__, OSIP_ERROR, NULL,
                         "eXosip: a response must be given!\n"));
            return -1;
        }
        return 0;
    } else
    {
        i = 0;
    }

    if (0 == osip_strcasecmp (tr->orig_request->sip_method, "SUBSCRIBE"))
    {
        if (MSG_IS_STATUS_1XX (answer))
        {
        } else if (MSG_IS_STATUS_2XX (answer))
        {
            eXosip_dialog_set_200ok (jd, answer);
            osip_dialog_set_state (jd->d_dialog, DIALOG_CONFIRMED);
        } else if (answer->status_code >= 300 && answer->status_code <= 699)
        {
            i = 0;
        } else
        {
            OSIP_TRACE (osip_trace
                        (__FILE__, __LINE__, OSIP_ERROR, NULL,
                         "eXosip: wrong status code (101<status<699)\n"));
            osip_message_free (answer);
            return -1;
        }
        if (i != 0)
        {
            osip_message_free (answer);
            return -1;
        }
    }

    evt_answer = osip_new_outgoing_sipmessage (answer);
    evt_answer->transactionid = tr->transactionid;

    osip_transaction_add_event (tr, evt_answer);
    eXosip_update ();
    __eXosip_wakeup ();
    return 0;
}