diff --git a/configure.in b/configure.in index d25ed35a..70edbba0 100644 --- a/configure.in +++ b/configure.in @@ -28,10 +28,15 @@ AC_ARG_ENABLE(howl,[ --enable-howl Use the howl mDNS library], AM_CONDITIONAL(COND_REND_HOWL, test x$rend_howl = xtrue) AM_CONDITIONAL(COND_REND_POSIX, test x$rend_howl = xfalse) +AM_CONDITIONAL(COND_NEED_STRCASESTR,false) +AM_CONDITIONAL(COND_NEED_STRSEP,false) + dnl Darwin's stupid cpp preprocessor.... echo Host type is $host case $host in *solaris*) + AM_CONDITIONAL(COND_NEED_STRCASESTR,true) + AM_CONDITIONAL(COND_NEED_STRSEP,true) CPPFLAGS="$CPPFLAGS -DHAVE_SOCKLEN_T" LDFLAGS="$LDFLAGS -lnsl -lsocket";; *linux*) diff --git a/src/Makefile.am b/src/Makefile.am index ef363bb5..bd7e62df 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,6 +6,14 @@ AM_YFLAGS=-d sbin_PROGRAMS = mt-daapd +if COND_NEED_STRCASESTR +STRCASESTR=strcasestr.c +endif + +if COND_NEED_STRSEP +STRSEP=strsep.c +endif + if COND_REND_POSIX RENDSRC=mdns/mDNS.c mdns/mDNSClientAPI.h mdns/mDNSDebug.h mdns/mDNSPosix.c mdns/mDNSUNP.c rend-posix.c mdns/mDNSPlatformFunctions.h endif @@ -22,10 +30,11 @@ mt_daapd_SOURCES = main.c daapd.h rend.h uici.c uici.h webserver.c \ webserver.h configfile.c configfile.h err.c err.h restart.c restart.h \ daap-proto.c daap-proto.h daap.c daap.h db-memory.c db-memory.h \ mp3-scanner.h mp3-scanner.c playlist.c playlist.h \ - lexer.l parser.y $(RENDSRC) + lexer.l parser.y $(RENDSRC) $(STRCASESTR) $(STRSEP) EXTRA_DIST = mdns/mDNS.c mdns/mDNSClientAPI.h mdns/mDNSDebug.h mdns/mDNSPosix.c \ mdns/mDNSUNP.c mdns/mDNSPlatformFunctions.h mdns/mDNSPosix.h mdns/mDNSUNP.h \ - rend-howl.c rend-posix.c rend-osx.c + rend-howl.c rend-posix.c rend-osx.c strcasestr.c strsep.c + diff --git a/src/strcasestr.c b/src/strcasestr.c new file mode 100644 index 00000000..1d0e71fc --- /dev/null +++ b/src/strcasestr.c @@ -0,0 +1,22 @@ +#include + +/* case-independent string matching, similar to strstr but + * matching */ +char * strcasestr(char* haystack, char* needle) { + int i; + int nlength = strlen (needle); + int hlength = strlen (haystack); + + if (nlength > hlength) return NULL; + if (hlength <= 0) return NULL; + if (nlength <= 0) return haystack; + /* hlength and nlength > 0, nlength <= hlength */ + for (i = 0; i <= (hlength - nlength); i++) { + if (strncasecmp (haystack + i, needle, nlength) == 0) { + return haystack + i; + } + } + /* substring not found */ + return NULL; +} + diff --git a/src/strsep.c b/src/strsep.c new file mode 100644 index 00000000..54f836b3 --- /dev/null +++ b/src/strsep.c @@ -0,0 +1,13 @@ +/* Compliments of Jay Freeman */ + +#include + +char *strsep(char **stringp, const char *delim) { + char *ret = *stringp; + if (ret == NULL) return(NULL); /* grrr */ + if ((*stringp = strpbrk(*stringp, delim)) != NULL) { + *((*stringp)++) = '\0'; + } + return(ret); +} +