Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add srtp_set_user_data() and srtp_get_user_data() functions. #66

Merged
merged 1 commit into from
Sep 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 54 additions & 3 deletions include/srtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr);
* @warning This function assumes that the SRTP packet is aligned on a
* 32-bit boundary.
*
* @param ctx is a pointer to the srtp_t which applies to the
* particular packet.
* @param ctx is the SRTP session which applies to the particular packet.
*
* @param srtp_hdr is a pointer to the header of the SRTP packet
* (before the call). after the function returns, it points to the
Expand Down Expand Up @@ -392,7 +391,8 @@ srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr);
* initializes an SRTP session context, applying the given policy and
* key.
*
* @param session is the SRTP session to which the policy is to be added.
* @param session is a pointer to the SRTP session to which the policy is
* to be added.
*
* @param policy is the srtp_policy_t struct that describes the policy
* for the session. The struct may be a single element, or it may be
Expand Down Expand Up @@ -1083,6 +1083,57 @@ srtp_unprotect_rtcp(srtp_t ctx, void *srtcp_hdr, int *pkt_octet_len);
* @}
*/


/**
* @defgroup User data associated to a SRTP session.
* @ingroup SRTP
*
* @brief Store custom user data within a SRTP session.
*
* @{
*/

/**
* @brief srtp_set_user_data() stores the given pointer into the SRTP
* session for later retrieval.
*
* @param ctx is the srtp_t context in which the given data pointer is
* stored.
*
* @param data is a pointer to the custom information (struct, function,
* etc) associated with the SRTP session.
*
* @return void.
*
*/

void
srtp_set_user_data(srtp_t ctx, void *data);

/**
* @brief srtp_get_user_data() retrieves the pointer to the custom data
* previously stored with srtp_set_user_data().
*
* This function is mostly useful for retrieving data associated to a
* SRTP session when an event fires. The user can then get such a custom
* data by calling this function with the session field of the
* srtp_event_data_t struct as argument.
*
* @param ctx is the srtp_t context in which the given data pointer was
* stored.
*
* @return void* pointer to the user data.
*
*/

void*
srtp_get_user_data(srtp_t ctx);

/**
* @}
*/


/**
* @defgroup SRTPevents SRTP events and callbacks
* @ingroup SRTP
Expand Down
1 change: 1 addition & 0 deletions include/srtp_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ typedef struct srtp_stream_ctx_t {
typedef struct srtp_ctx_t {
srtp_stream_ctx_t *stream_list; /* linked list of streams */
srtp_stream_ctx_t *stream_template; /* act as template for other streams */
void *user_data; /* user custom data */
} srtp_ctx_t;


Expand Down
15 changes: 15 additions & 0 deletions srtp/srtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,7 @@ srtp_create(srtp_t *session, /* handle for session */
*/
ctx->stream_template = NULL;
ctx->stream_list = NULL;
ctx->user_data = NULL;
while (policy != NULL) {

stat = srtp_add_stream(ctx, policy);
Expand Down Expand Up @@ -3006,6 +3007,20 @@ srtp_unprotect_rtcp(srtp_t ctx, void *srtcp_hdr, int *pkt_octet_len) {
}


/*
* user data within srtp_t context
*/

void
srtp_set_user_data(srtp_t ctx, void *data) {
ctx->user_data = data;
}

void*
srtp_get_user_data(srtp_t ctx) {
return ctx->user_data;
}


/*
* dtls keying for srtp
Expand Down