int
eXosip_message_build_answer (int tid, int status, osip_message_t ** answer)
{
  osip_transaction_t *tr = NULL;
  int i;

  *answer = NULL;

  if (tid <= 0)
    return OSIP_BADPARAMETER;
  if (status < 200 || status > 699)
    return OSIP_BADPARAMETER;

  if (tid > 0)
    {
      eXosip_transaction_find (tid, &tr);
    }
  if (tr == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No call here?\n"));
      return OSIP_NOTFOUND;
    }

  i = -1;
  if (status < 300)             /* 2xx answer */
    i = _eXosip_build_response_default (answer, NULL, status, tr->orig_request);
  else if (status > 300)        /* 3456xx answer */
    i = _eXosip_build_response_default (answer, NULL, status, tr->orig_request);

  if (i != 0)
    return i;
  return OSIP_SUCCESS;
}
int
eXosip_message_send_answer (int tid, int status, osip_message_t * answer)
{
  osip_transaction_t *tr = NULL;
  osip_event_t *evt_answer;
  int i = -1;

  if (tid <= 0)
    return OSIP_BADPARAMETER;
  if (status <= 100 || status > 699)
    return OSIP_BADPARAMETER;
  if (answer == NULL && status > 100 && status < 200)
    return OSIP_BADPARAMETER;

  if (tid > 0)
    {
      eXosip_transaction_find (tid, &tr);
    }
  if (tr == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No MESSAGE transaction found\n"));
      osip_message_free (answer);
      return OSIP_NOTFOUND;
    }

  /* 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 OSIP_WRONG_STATE;
    }

  if (answer == NULL)
    {
      i = -1;
      if (status > 199 && status < 300)
        i = _eXosip_build_response_default (&answer, NULL, status,
                                            tr->orig_request);
      else if (status > 300 && status <= 699)
        i = _eXosip_build_response_default (&answer, NULL, status,
                                            tr->orig_request);
      if (i != 0)
        return i;
    }

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

  osip_transaction_add_event (tr, evt_answer);
  __eXosip_wakeup ();
  return OSIP_SUCCESS;
}
示例#3
0
int
eXosip_options_build_answer (int tid, int status, osip_message_t ** answer)
{
  osip_transaction_t *tr = NULL;
  int i = -1;

  *answer = NULL;
  if (tid > 0)
    {
      eXosip_transaction_find (tid, &tr);
    }
  if (tr == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No call here?\n"));
      return -1;
    }
  if (status > 100 && status < 200)
    {
#if 0
      /* TODO: not implemented */
      i = _eXosip_build_response_default (response, NULL, code, tr->orig_request);
#endif
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: status code 1xx for options not implemented (use 200<status<=699)\n"));
      return -1;
  } else if (status > 199 && status < 300)
    {
      i = _eXosip_build_response_default (answer, NULL, status, tr->orig_request);
  } else if (status > 300 && status <= 699)
    {
      i = _eXosip_build_response_default (answer, NULL, status, tr->orig_request);
  } else
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: wrong status code (200<status<=699)\n"));
      return -1;
    }
  if (i != 0)
    return -1;
  return 0;
}
示例#4
0
static int
eXosip_retry_with_auth (eXosip_event_t * je)
{
  if (!je || !je->request || !je->response)
    return -1;

  if (je->rid>0)
    {
      return _eXosip_retry_register_with_auth (je);
    }
  else if (je->cid>0)
    {
      return _eXosip_retry_invite_with_auth (je);
    }
#ifndef MINISIZE
  else if (je->sid>0)
    {
      return _eXosip_retry_subscribe_with_auth (je);
    }
  else if (je->nid>0)
    {
      return _eXosip_retry_notify_with_auth (je);
    }
  else if (MSG_IS_PUBLISH (je->request))
    return _eXosip_retry_publish_with_auth (je);
#endif
  else
    {
      osip_transaction_t *tr=NULL;
      eXosip_transaction_find(je->tid, &tr);
      if (tr!=NULL)
	{
	  return _eXosip_retry_with_auth (NULL, &tr, NULL);
	}
    }

  OSIP_TRACE (osip_trace
	      (__FILE__, __LINE__, OSIP_ERROR, NULL,
	       "eXosip: Can't retry event %d with auth\n", je->type));
  return -1;
}
int
eXosip_message_send_answer (int tid, int status, osip_message_t * answer)
{
  osip_transaction_t *tr = NULL;
  osip_event_t *evt_answer;
  int i = -1;

  if (tid > 0)
    {
      eXosip_transaction_find (tid, &tr);
    }
  if (tr == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No MESSAGE transaction found\n"));
      osip_message_free (answer);
      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 (status > 100 && status < 200)
        {
#if 0
          /* TODO: not implemented */
          i =
            _eXosip_build_response_default (response, NULL, code,
                                            tr->orig_request);
#endif
          OSIP_TRACE (osip_trace
                      (__FILE__, __LINE__, OSIP_ERROR, NULL,
                       "eXosip: status code 1xx for message not implemented (use 200<status<699)\n"));
          return -1;
      } else if (status > 199 && status < 300)
        {
          i =
            _eXosip_build_response_default (&answer, NULL, status,
                                            tr->orig_request);
      } else if (status > 300 && status <= 699)
        {
          i =
            _eXosip_build_response_default (&answer, NULL, status,
                                            tr->orig_request);
      } else
        {
          OSIP_TRACE (osip_trace
                      (__FILE__, __LINE__, OSIP_ERROR, NULL,
                       "eXosip: wrong status code (200<status<=699)\n"));
          return -1;
        }
      if (i != 0)
        return -1;
    }

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

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