Commit b3374f40 authored by Bastien Nocera's avatar Bastien Nocera Committed by Bastien Nocera

Remove internal copy, and use of, memmem, use glib's g_strstr_len()

2008-08-27  Bastien Nocera  <hadess@hadess.net>

	* configure.in:
	* lib/Makefile.am:
	* lib/memmem.c:
	* lib/totem_internal.h:
	* plparse/totem-pl-parser-podcast.c (totem_pl_parser_is_rss),
	(totem_pl_parser_is_atom), (totem_pl_parser_is_opml):
	* plparse/totem-pl-parser-qt.c (totem_pl_parser_is_quicktime):
	* plparse/totem-pl-parser-wm.c (totem_pl_parser_is_asx):
	Remove internal copy, and use of, memmem, use glib's g_strstr_len()
	instead (Closes: #548612)


svn path=/trunk/; revision=180
parent e445e834
2008-08-27 Bastien Nocera <hadess@hadess.net>
* configure.in:
* lib/Makefile.am:
* lib/memmem.c:
* lib/totem_internal.h:
* plparse/totem-pl-parser-podcast.c (totem_pl_parser_is_rss),
(totem_pl_parser_is_atom), (totem_pl_parser_is_opml):
* plparse/totem-pl-parser-qt.c (totem_pl_parser_is_quicktime):
* plparse/totem-pl-parser-wm.c (totem_pl_parser_is_asx):
Remove internal copy, and use of, memmem, use glib's g_strstr_len()
instead (Closes: #548612)
2008-08-25 Bastien Nocera <hadess@hadess.net>
* plparse/totem-pl-parser.c: Also parse video/mp4 files as possible
......
......@@ -26,10 +26,10 @@ AM_PROG_CC_C_O
AC_PROG_LIBTOOL()
PKG_PROG_PKG_CONFIG
dnl Use local version of asprintf/memmem when not on the current system.
AC_CHECK_FUNCS(asprintf memmem)
dnl Use local version of asprintf when not on the current system.
AC_CHECK_FUNCS(asprintf)
AC_CONFIG_LIBOBJ_DIR([lib])
AC_REPLACE_FUNCS([asprintf memmem])
AC_REPLACE_FUNCS([asprintf])
AC_PATH_PROG([GLIB_GENMARSHAL],[glib-genmarshal])
AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
......
......@@ -11,5 +11,5 @@ noinst_HEADERS = totem_internal.h
libtotem_glibc_la_SOURCES =
libtotem_glibc_la_LIBADD = @LTLIBOBJS@
EXTRA_DIST = asprintf.c memmem.c
EXTRA_DIST = asprintf.c
/*-
* Copyright (c) 2001 Andrew L. Neporada <andr@dgap.mipt.ru>
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef __sun
#include "bbs.h"
#include <sys/cdefs.h>
#endif
#include <sys/types.h>
#include <limits.h>
#include <string.h>
#ifndef HAVE_MEMMEM
/*
* Find the first occurrence of byte string p in byte string s.
*
* This implementation uses simplified Boyer-Moore algorithm (only
* bad-character shift table is used).
* See:
* Boyer R.S., Moore J.S. 1977, "A fast string searching algorithm",
* Communications of ACM. 20:762-772.
*/
void *totem_private_memmem(s, slen, p, plen)
register const void *s, *p;
size_t slen, plen;
{
register const u_char *str, *substr;
register size_t i, max_shift, curr_shift;
size_t shift[UCHAR_MAX + 1];
if (!plen)
return ((void *) s);
if (plen > slen)
return (NULL);
str = (const u_char *) s;
substr = (const u_char *) p;
for (i = 0; i <= UCHAR_MAX; i++)
shift[i] = plen + 1;
for (i = 0; i < plen; i++)
shift[substr[i]] = plen - i;
i = 0;
max_shift = slen - plen;
while (i <= max_shift) {
if (*str == *substr && !memcmp(str + 1, substr + 1, plen - 1))
return ((void *) str);
curr_shift = shift[str[plen]];
str += curr_shift;
i += curr_shift;
}
return (NULL);
}
#endif /* ! HAVE_MEMMEM */
......@@ -14,8 +14,3 @@
int totem_private_asprintf(char **string, const char *format, ...);
#endif
#ifndef HAVE_MEMMEM
#define memmem(s, slen, p, plen) totem_private_memmem(s, slen, p, plen)
void *totem_private_memmem(register const void *s, size_t slen, register const void *p, size_t plen);
#endif
......@@ -50,11 +50,9 @@ totem_pl_parser_is_rss (const char *data, gsize len)
if (len > MIME_READ_CHUNK_SIZE)
len = MIME_READ_CHUNK_SIZE;
if (memmem (data, len,
RSS_NEEDLE, strlen (RSS_NEEDLE)) != NULL)
if (g_strstr_len (data, len, RSS_NEEDLE) != NULL)
return RSS_MIME_TYPE;
if (memmem (data, len,
RSS_NEEDLE2, strlen (RSS_NEEDLE2)) != NULL)
if (g_strstr_len (data, len, RSS_NEEDLE2) != NULL)
return RSS_MIME_TYPE;
return NULL;
......@@ -68,8 +66,7 @@ totem_pl_parser_is_atom (const char *data, gsize len)
if (len > MIME_READ_CHUNK_SIZE)
len = MIME_READ_CHUNK_SIZE;
if (memmem (data, len,
ATOM_NEEDLE, strlen (ATOM_NEEDLE)) != NULL)
if (g_strstr_len (data, len, ATOM_NEEDLE) != NULL)
return ATOM_MIME_TYPE;
return NULL;
......@@ -83,8 +80,7 @@ totem_pl_parser_is_opml (const char *data, gsize len)
if (len > MIME_READ_CHUNK_SIZE)
len = MIME_READ_CHUNK_SIZE;
if (memmem (data, len,
OPML_NEEDLE, strlen (OPML_NEEDLE)) != NULL)
if (g_strstr_len (data, len, OPML_NEEDLE) != NULL)
return OPML_MIME_TYPE;
return NULL;
......
......@@ -57,8 +57,7 @@ totem_pl_parser_is_quicktime (const char *data, gsize len)
if (g_str_has_prefix (data, "SMILtext") != FALSE)
return QUICKTIME_META_MIME_TYPE;
if (memmem (data, len,
QT_NEEDLE, strlen (QT_NEEDLE)) != NULL)
if (g_strstr_len (data, len, QT_NEEDLE) != NULL)
return QUICKTIME_META_MIME_TYPE;
return NULL;
......
......@@ -51,14 +51,11 @@ totem_pl_parser_is_asx (const char *data, gsize len)
if (len > MIME_READ_CHUNK_SIZE)
len = MIME_READ_CHUNK_SIZE;
if (memmem (data, len,
ASX_NEEDLE, strlen (ASX_NEEDLE)) != NULL)
if (g_strstr_len (data, len, ASX_NEEDLE) != NULL)
return ASX_MIME_TYPE;
if (memmem (data, len,
ASX_NEEDLE2, strlen (ASX_NEEDLE2)) != NULL)
if (g_strstr_len (data, len, ASX_NEEDLE2) != NULL)
return ASX_MIME_TYPE;
if (memmem (data, len,
ASX_NEEDLE3, strlen (ASX_NEEDLE3)) != NULL)
if (g_strstr_len (data, len, ASX_NEEDLE3) != NULL)
return ASX_MIME_TYPE;
return FALSE;
......
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