Commit e0742b87 authored by Tim-Philipp Müller's avatar Tim-Philipp Müller

rtsp: add boxed types for new authentication credential API

To make the structs usable in bindings, and fix

gstrtspmessage.c:1188: Warning: GstRtsp:
gst_rtsp_message_parse_auth_credentials: return value: Invalid
non-constant return of bare structure or union; register as
boxed type or (skip)

https://bugzilla.gnome.org/show_bug.cgi?id=774416
parent 97951155
......@@ -1186,6 +1186,8 @@ parse_auth_credentials (GPtrArray * auth_credentials, const gchar * header,
* Parses the credentials given in a WWW-Authenticate or Authorization header.
*
* Returns: %NULL-terminated array of GstRTSPAuthCredential or %NULL.
*
* Since: 1.12
*/
GstRTSPAuthCredential **
gst_rtsp_message_parse_auth_credentials (GstRTSPMessage * msg,
......@@ -1211,6 +1213,81 @@ gst_rtsp_message_parse_auth_credentials (GstRTSPMessage * msg,
return (GstRTSPAuthCredential **) g_ptr_array_free (auth_credentials, FALSE);
}
static GstRTSPAuthParam *
gst_rtsp_auth_param_copy (GstRTSPAuthParam * param)
{
GstRTSPAuthParam *copy;
if (param == NULL)
return NULL;
copy = g_new0 (GstRTSPAuthParam, 1);
copy->name = g_strdup (param->name);
copy->value = g_strdup (param->value);
return copy;
}
static void
gst_rtsp_auth_param_free (GstRTSPAuthParam * param)
{
if (param != NULL) {
g_free (param->name);
g_free (param->value);
g_free (param);
}
}
G_DEFINE_BOXED_TYPE (GstRTSPAuthParam, gst_rtsp_auth_param,
(GBoxedCopyFunc) gst_rtsp_auth_param_copy,
(GBoxedFreeFunc) gst_rtsp_auth_param_free);
static void
gst_rtsp_auth_credential_free (GstRTSPAuthCredential * credential)
{
GstRTSPAuthParam **p;
if (credential == NULL)
return;
for (p = credential->params; p != NULL && *p != NULL; ++p)
gst_rtsp_auth_param_free (*p);
g_free (credential->params);
g_free (credential->authorization);
g_free (credential);
}
static GstRTSPAuthCredential *
gst_rtsp_auth_credential_copy (GstRTSPAuthCredential * cred)
{
GstRTSPAuthCredential *copy;
if (cred == NULL)
return NULL;
copy = g_new0 (GstRTSPAuthCredential, 1);
copy->scheme = cred->scheme;
if (cred->params) {
guint i, n_params = g_strv_length ((gchar **) cred->params);
copy->params = g_new0 (GstRTSPAuthParam *, n_params + 1);
for (i = 0; i < n_params; ++i)
copy->params[i] = gst_rtsp_auth_param_copy (cred->params[i]);
}
copy->authorization = g_strdup (cred->authorization);
return copy;
}
/**
* gst_rtsp_auth_credentials_free:
* @credentials: a %NULL-terminated array of #GstRTSPAuthCredential
*
* Free a %NULL-terminated array of credentials returned from
* gst_rtsp_message_parse_auth_credentials().
*
* Since: 1.12
*/
void
gst_rtsp_auth_credentials_free (GstRTSPAuthCredential ** credentials)
{
......@@ -1219,24 +1296,12 @@ gst_rtsp_auth_credentials_free (GstRTSPAuthCredential ** credentials)
if (!credentials)
return;
p = credentials;
while (*p) {
GstRTSPAuthParam **param = (*p)->params;
if (param) {
while (*param) {
g_free ((*param)->name);
g_free ((*param)->value);
g_free (*param);
param++;
}
g_free ((*p)->params);
}
if ((*p)->authorization)
g_free ((*p)->authorization);
g_free (*p);
p++;
}
for (p = credentials; p != NULL && *p != NULL; ++p)
gst_rtsp_auth_credential_free (*p);
g_free (credentials);
}
G_DEFINE_BOXED_TYPE (GstRTSPAuthCredential, gst_rtsp_auth_credential,
(GBoxedCopyFunc) gst_rtsp_auth_credential_copy,
(GBoxedFreeFunc) gst_rtsp_auth_credential_free);
......@@ -201,6 +201,7 @@ GstRTSPResult gst_rtsp_message_steal_body (GstRTSPMessage *msg,
typedef struct _GstRTSPAuthCredential GstRTSPAuthCredential;
typedef struct _GstRTSPAuthParam GstRTSPAuthParam;
struct _GstRTSPAuthCredential {
GstRTSPAuthMethod scheme;
......@@ -220,6 +221,14 @@ struct _GstRTSPAuthParam {
GstRTSPAuthCredential ** gst_rtsp_message_parse_auth_credentials (GstRTSPMessage * msg, GstRTSPHeaderField field);
void gst_rtsp_auth_credentials_free (GstRTSPAuthCredential ** credentials);
#define GST_TYPE_RTSP_AUTH_CREDENTIAL gst_rtsp_auth_credential_get_type()
GType gst_rtsp_auth_credential_get_type (void);
#define GST_TYPE_RTSP_AUTH_PARAM gst_rtsp_auth_param_get_type()
GType gst_rtsp_auth_param_get_type (void);
/* debug */
GstRTSPResult gst_rtsp_message_dump (GstRTSPMessage *msg);
......
......@@ -936,6 +936,37 @@ GST_START_TEST (test_rtsp_message_auth_credentials)
GST_END_TEST;
GST_START_TEST (test_rtsp_message_auth_credentials_boxed)
{
GstRTSPAuthCredential **credentials, *credentials2;
GstRTSPAuthParam *param2;
GstRTSPMessage *msg;
GstRTSPResult res;
res = gst_rtsp_message_new_request (&msg, GST_RTSP_PLAY,
"rtsp://foo.bar:8554/test");
fail_unless_equals_int (res, GST_RTSP_OK);
res =
gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
"Basic foo=\"bar\", baz=foo");
res =
gst_rtsp_message_add_header (msg, GST_RTSP_HDR_WWW_AUTHENTICATE,
"Basic foo1=\"bar\", baz1=foo");
credentials =
gst_rtsp_message_parse_auth_credentials (msg,
GST_RTSP_HDR_WWW_AUTHENTICATE);
credentials2 = g_boxed_copy (GST_TYPE_RTSP_AUTH_CREDENTIAL, credentials[0]);
gst_rtsp_auth_credentials_free (credentials);
gst_rtsp_message_free (msg);
param2 = g_boxed_copy (GST_TYPE_RTSP_AUTH_PARAM, credentials2->params[0]);
g_boxed_free (GST_TYPE_RTSP_AUTH_CREDENTIAL, credentials2);
g_boxed_free (GST_TYPE_RTSP_AUTH_PARAM, param2);
}
GST_END_TEST;
static Suite *
rtsp_suite (void)
{
......@@ -953,6 +984,7 @@ rtsp_suite (void)
tcase_add_test (tc_chain, test_rtsp_range_convert);
tcase_add_test (tc_chain, test_rtsp_message);
tcase_add_test (tc_chain, test_rtsp_message_auth_credentials);
tcase_add_test (tc_chain, test_rtsp_message_auth_credentials_boxed);
return s;
}
......
EXPORTS
gst_rtsp_auth_credential_get_type
gst_rtsp_auth_credentials_free
gst_rtsp_auth_method_get_type
gst_rtsp_auth_param_get_type
gst_rtsp_connection_accept
gst_rtsp_connection_clear_auth_params
gst_rtsp_connection_close
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment