Logo Search packages:      
Sourcecode: srtp version File versions  Download package

err_status_t srtp_add_stream ( srtp_t  session,
const srtp_policy_t policy 
)

srtp_add_stream() allocates and initializes an SRTP stream within a given SRTP session.

The function call srtp_add_stream(session, policy) allocates and initializes a new SRTP stream within a given, previously created session, applying the policy given as the other argument to that stream.

Returns:
values:
  • err_status_ok if stream creation succeded.
  • err_status_alloc_fail if stream allocation failed
  • err_status_init_fail if stream initialization failed.

Definition at line 1183 of file srtp.c.

References err_status_bad_param, err_status_ok, srtp_policy_t::key, srtp_policy_t::ssrc, ssrc_any_inbound, ssrc_any_outbound, ssrc_specific, ssrc_undefined, and ssrc_t::type.

Referenced by srtp_create().

                                          {
  err_status_t status;
  srtp_stream_t tmp;

  /* sanity check arguments */
  if ((session == NULL) || (policy == NULL) || (policy->key == NULL))
    return err_status_bad_param;

  /* allocate stream  */
  status = srtp_stream_alloc(&tmp, policy);
  if (status) {
    return status;
  }
  
  /* initialize stream  */
  status = srtp_stream_init(tmp, policy);
  if (status) {
    crypto_free(tmp);
    return status;
  }
  
  /* 
   * set the head of the stream list or the template to point to the
   * stream that we've just alloced and init'ed, depending on whether
   * or not it has a wildcard SSRC value or not
   *
   * if the template stream has already been set, then the policy is
   * inconsistent, so we return a bad_param error code
   */
  switch (policy->ssrc.type) {
  case (ssrc_any_outbound):
    if (session->stream_template) {
      return err_status_bad_param;
    }
    session->stream_template = tmp;
    session->stream_template->direction = dir_srtp_sender;
    break;
  case (ssrc_any_inbound):
    if (session->stream_template) {
      return err_status_bad_param;
    }
    session->stream_template = tmp;
    session->stream_template->direction = dir_srtp_receiver;
    break;
  case (ssrc_specific):
    tmp->next = session->stream_list;
    session->stream_list = tmp;
    break;
  case (ssrc_undefined):
  default:
    crypto_free(tmp);
    return err_status_bad_param;
  }
    
  return err_status_ok;
}


Generated by  Doxygen 1.6.0   Back to index