Commit d24a53ab authored by Brendan Long's avatar Brendan Long

Merge pull request #135 from gdesmott/util-refactor

Util refactor
parents 71ad50ae 805ff11f
......@@ -109,10 +109,8 @@ dlna_src_parse_npt_range (GstDlnaSrc * dlna_src, const gchar * field_str,
gchar ** start_str, gchar ** stop_str, gchar ** total_str,
guint64 * start, guint64 * stop, guint64 * total)
{
gchar *header = NULL;
gchar *header_value = NULL;
gint ret_code = 0;
gchar *field, *cursor;
gint ret_code;
gchar tmp1[32] = { 0 };
gchar tmp2[32] = { 0 };
gchar tmp3[32] = { 0 };
......@@ -128,54 +126,65 @@ dlna_src_parse_npt_range (GstDlnaSrc * dlna_src, const gchar * field_str,
*stop = 0;
*total = 0;
/* Convert everything to upper case */
field = g_ascii_strup (field_str, -1);
/* Extract NPT portion of header value */
header =
strstr (g_ascii_strup (field_str, strlen (field_str)), "NPT");
if (header)
header_value = strstr (header, "=");
if (header_value)
header_value++;
else {
GST_WARNING_OBJECT (dlna_src,
"Problems parsing npt from HEAD response field header value: %s",
field_str);
return FALSE;
cursor = strstr (field, "NPT");
if (!cursor)
goto fail;
cursor = strstr (cursor, "=");
if (!cursor)
goto fail;
cursor++; /* '=' */
/* Read start value and '-' */
ret_code = sscanf (cursor, "%31[^-]-%*s", tmp1);
if (ret_code == -1)
goto fail;
cursor += strlen (tmp1) + 1;
*start_str = g_strdup (tmp1);
if (!dlna_src_npt_to_nanos (dlna_src, *start_str, start))
goto fail;
/* Read stop value, if any */
if (g_ascii_isdigit (cursor[0])) {
ret_code = sscanf (cursor, "%31[^/ ]%*s", tmp2);
if (ret_code == -1)
goto fail;
cursor += strlen (tmp2);
*stop_str = g_strdup (tmp2);
if (!dlna_src_npt_to_nanos (dlna_src, *stop_str, stop))
goto fail;
}
/* Determine if npt string includes total */
if (strstr (header_value, "/")) {
/* Extract start and end and total NPT */
if ((ret_code =
sscanf (header_value, "%31[^-]-%31[^/]/%31s %*s", tmp1, tmp2,
tmp3)) != 3) {
GST_WARNING_OBJECT (dlna_src,
"Problems parsing NPT from HEAD response field header %s, value: %s, retcode: %d, tmp: %s, %s, %s",
field_str, header_value, ret_code, tmp1, tmp2, tmp3);
return FALSE;
}
/* Do we have the total length? */
if (cursor[0] == '/') {
cursor++; /* '/' */
ret_code = sscanf (cursor, "%31s %*s", tmp3);
if (ret_code == -1)
goto fail;
*total_str = g_strdup (tmp3);
if (strcmp (*total_str, "*") != 0)
if (!dlna_src_npt_to_nanos (dlna_src, *total_str, total))
return FALSE;
} else {
/* Extract start and end (there is no total) NPT */
if ((ret_code = sscanf (header_value, "%31[^-]-%31s %*s", tmp1, tmp2)) != 2) {
GST_WARNING_OBJECT (dlna_src,
"Problems parsing NPT from HEAD response field header %s, value: %s, retcode: %d, tmp: %s, %s",
field_str, header_value, ret_code, tmp1, tmp2);
return FALSE;
}
goto fail;
}
*start_str = g_strdup (tmp1);
if (!dlna_src_npt_to_nanos (dlna_src, *start_str, start))
return FALSE;
*stop_str = g_strdup (tmp2);
if (!dlna_src_npt_to_nanos (dlna_src, *stop_str, stop))
return FALSE;
g_free (field);
return TRUE;
}
fail:
GST_WARNING_OBJECT (dlna_src,
"Problems parsing npt from HEAD response field header value: %s",
field_str);
g_free (field);
return FALSE;
}
......@@ -36,6 +36,8 @@ test_parse_ntp_range (void)
"335.1", "336.1", "40445.4", 335099985920, 336099999744, 40445400842240);
do_test_parse_ntp_range ("availableSeekRange.dlna.org: 0 npt=0:00:00.000-0:00:48.716 bytes=0-5219255 cleartextbytes=0-5219255",
"0:00:00.000", "0:00:48.716", NULL, 0, 48716001280, 0);
do_test_parse_ntp_range ("npt=10.0-/* bytes=24409920-198755327/198755328",
"10.0", NULL, "*", 10000000000, 0, 0);
}
int
......
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