Skip to content

Commit

Permalink
Initial checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Maggard committed Oct 23, 2008
0 parents commit f557f8e
Show file tree
Hide file tree
Showing 46 changed files with 9,775 additions and 0 deletions.
433 changes: 433 additions & 0 deletions Changelog.txt

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MiniDLNA project.
(c) 2008 Justin Maggard
Parts (c) 2006-2008 Thomas Bernard
Homepage : https://sourceforge.net/projects/minidlna/

Prerequisites :

- taglib
- libexif
- sqlite3

To Build and install :

- Just run make, and hope it works. :)
346 changes: 346 additions & 0 deletions LICENCE

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions LICENCE.miniupnpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2006-2007, Thomas BERNARD
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* 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.
* The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.

101 changes: 101 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# $Id$
# MiniUPnP project
# https://miniupnp.free.fr/
# Author : Thomas Bernard
# for use with GNU Make
# To install use :
# $ PREFIX=/dummyinstalldir make -f Makefile.linux install
# or :
# $ INSTALLPREFIX=/usr/local make -f Makefile.linux install
# or :
# $ make -f Makefile.linux install
#
#CFLAGS = -Wall -O -D_GNU_SOURCE -g -DDEBUG
#CFLAGS = -Wall -g -Os -D_GNU_SOURCE
CFLAGS = -Wall -g -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
CC = gcc
RM = rm -f
INSTALL = install

INSTALLPREFIX ?= $(PREFIX)/usr
SBININSTALLDIR = $(INSTALLPREFIX)/sbin
ETCINSTALLDIR = $(PREFIX)/etc/miniupnpd

BASEOBJS = minidlna.o upnphttp.o upnpdescgen.o upnpsoap.o \
upnpreplyparse.o minixml.o \
getifaddr.o daemonize.o upnpglobalvars.o \
options.o minissdp.o upnpevents.o \
sql.o metadata.o scanner.o

ALLOBJS = $(BASEOBJS) $(LNXOBJS)

#LIBS = -liptc
LIBS = -lexif -ltag_c -lsqlite3 #-lgd

TESTUPNPDESCGENOBJS = testupnpdescgen.o upnpdescgen.o

EXECUTABLES = minidlna testupnpdescgen

.PHONY: all clean install depend genuuid

all: $(EXECUTABLES)

clean:
$(RM) $(ALLOBJS)
$(RM) $(EXECUTABLES)
$(RM) testupnpdescgen.o

install: minidlna genuuid
$(INSTALL) -d $(SBININSTALLDIR)
$(INSTALL) minidlna $(SBININSTALLDIR)
$(INSTALL) -d $(ETCINSTALLDIR)
$(INSTALL) netfilter/iptables_init.sh $(ETCINSTALLDIR)
$(INSTALL) netfilter/iptables_removeall.sh $(ETCINSTALLDIR)
$(INSTALL) --mode=0644 minidlna.conf $(ETCINSTALLDIR)
$(INSTALL) -d $(PREFIX)/etc/init.d
$(INSTALL) linux/miniupnpd.init.d.script $(PREFIX)/etc/init.d/miniupnpd

# genuuid is using the uuidgen CLI tool which is part of libuuid
# from the e2fsprogs
genuuid:
sed -i -e "s/^uuid=[-0-9a-f]*/uuid=`(genuuid||uuidgen) 2>/dev/null`/" minidlna.conf

minidlna: $(BASEOBJS) $(LNXOBJS) $(LIBS)

testupnpdescgen: $(TESTUPNPDESCGENOBJS)

config.h: genconfig.sh
./genconfig.sh

depend: config.h
makedepend -f$(MAKEFILE_LIST) -Y \
$(ALLOBJS:.o=.c) $(TESTUPNPDESCGENOBJS:.o=.c) 2>/dev/null

# DO NOT DELETE

minidlna.o: config.h upnpglobalvars.h miniupnpdtypes.h
minidlna.o: upnphttp.h upnpdescgen.h miniupnpdpath.h getifaddr.h upnpsoap.h
minidlna.o: options.h minissdp.h daemonize.h upnpevents.h
minidlna.o: commonrdr.h
upnphttp.o: config.h upnphttp.h upnpdescgen.h miniupnpdpath.h upnpsoap.h
upnphttp.o: upnpevents.h
upnpdescgen.o: config.h upnpdescgen.h miniupnpdpath.h upnpglobalvars.h
upnpdescgen.o: miniupnpdtypes.h upnpdescstrings.h
upnpsoap.o: config.h upnpglobalvars.h miniupnpdtypes.h
upnpsoap.o: upnphttp.h upnpsoap.h upnpreplyparse.h getifaddr.h
upnpreplyparse.o: upnpreplyparse.h minixml.h
minixml.o: minixml.h
getifaddr.o: getifaddr.h
daemonize.o: daemonize.h config.h
upnpglobalvars.o: config.h upnpglobalvars.h
upnpglobalvars.o: miniupnpdtypes.h
options.o: options.h config.h upnpglobalvars.h
options.o: miniupnpdtypes.h
minissdp.o: config.h upnpdescstrings.h miniupnpdpath.h upnphttp.h
minissdp.o: upnpglobalvars.h miniupnpdtypes.h minissdp.h
upnpevents.o: config.h upnpevents.h miniupnpdpath.h upnpglobalvars.h
upnpevents.o: miniupnpdtypes.h upnpdescgen.h
netfilter/iptcrdr.o: netfilter/iptcrdr.h commonrdr.h config.h
testupnpdescgen.o: config.h upnpdescgen.h
upnpdescgen.o: config.h upnpdescgen.h miniupnpdpath.h upnpglobalvars.h
upnpdescgen.o: miniupnpdtypes.h upnpdescstrings.h
25 changes: 25 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
MiniDLNA project
(c) 2008 Justin Maggard
Parts (c) 2006-2007 Thomas Bernard
webpage: https://sourceforge.net/projects/minidlna/

This directory contain the MiniDLNA daemon software.
This software is subject to the conditions detailed in
the LICENCE file provided with this distribution.

Parts of the software including the discovery code are
licensed under the BSD revised license which is detailed
in the LICENSE.miniupnpd file provided with the distribution.
More information on MiniUPnPd can be found at https://miniupnp.free.fr.


The MiniDLNA daemon is an UPnP-A/V and DLNA service which
serves multimedia content to compatible clients on the network.
See https://www.upnp.org/ for more details on UPnP
and https://www.dlna.org/ for mode details on DLNA.

See the INSTALL file for instructions on compiling, installing,
and configuring minidlna.


Justin Maggard
35 changes: 35 additions & 0 deletions commonrdr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* MiniUPnP project
* (c) 2006-2007 Thomas Bernard
* https://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
#ifndef __COMMONRDR_H__
#define __COMMONRDR_H__

#include "config.h"

/* init and shutdown functions */
int
init_redirect(void);

void
shutdown_redirect(void);

/* get_redirect_rule() gets internal IP and port from
* interface, external port and protocl
*/
int
get_redirect_rule(const char * ifname, unsigned short eport, int proto,
char * iaddr, int iaddrlen, unsigned short * iport,
char * desc, int desclen,
u_int64_t * packets, u_int64_t * bytes);

int
get_redirect_rule_by_index(int index,
char * ifname, unsigned short * eport,
char * iaddr, int iaddrlen, unsigned short * iport,
int * proto, char * desc, int desclen,
u_int64_t * packets, u_int64_t * bytes);

#endif

55 changes: 55 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* MiniUPnP Project
* https://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2008 Thomas Bernard
* generated by ./genconfig.sh on Thu Sep 11 15:05:26 PDT 2008 */
#ifndef __CONFIG_H__
#define __CONFIG_H__

#define UPNP_VERSION "20070827"
#define USE_NETFILTER 1
#define OS_NAME "JM"
#define OS_VERSION "Linux/2.6.25.14-108.fc9.i686"
#define OS_URL "https://www.kernel.org/"

/* syslog facility to be used by miniupnpd */
#define LOG_MINIUPNPD LOG_DAEMON

/* Uncomment the following line to allow miniupnpd to be
* controlled by miniupnpdctl */
/*#define USE_MINIUPNPDCTL*/

/* Comment the following line to disable NAT-PMP operations */
//#define ENABLE_NATPMP

/* Uncomment the following line to enable generation of
* filter rules with pf */
/*#define PF_ENABLE_FILTER_RULES*/

/* Uncomment the following line to enable caching of results of
* the getifstats() function */
/*#define ENABLE_GETIFSTATS_CACHING*/
/* The cache duration is indicated in seconds */
#define GETIFSTATS_CACHING_DURATION 2

/* Uncomment the following line to enable multiple external ip support */
/* note : Thas is EXPERIMENTAL, do not use that unless you know perfectly what you are doing */
/*#define MULTIPLE_EXTERNAL_IP*/

/* Comment the following line to use home made daemonize() func instead
* of BSD daemon() */
#define USE_DAEMON

/* Uncomment the following line to enable lease file support */
/*#define ENABLE_LEASEFILE*/

/* Define one or none of the two following macros in order to make some
* clients happy. It will change the XML Root Description of the IGD.
* Enabling the Layer3Forwarding Service seems to be the more compatible
* option. */
/*#define HAS_DUMMY_SERVICE*/
#define ENABLE_L3F_SERVICE

/* Experimental UPnP Events support. */
#define ENABLE_EVENTS

#endif
129 changes: 129 additions & 0 deletions daemonize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/* $Id$ */
/* MiniUPnP project
* https://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <string.h>
#include <signal.h>

#include "daemonize.h"
#include "config.h"

#ifndef USE_DAEMON

int
daemonize(void)
{
int pid, i;

switch(fork())
{
/* fork error */
case -1:
perror("fork()");
exit(1);

/* child process */
case 0:
/* obtain a new process group */
if( (pid = setsid()) < 0)
{
perror("setsid()");
exit(1);
}

/* close all descriptors */
for (i=getdtablesize();i>=0;--i) close(i);

i = open("/dev/null",O_RDWR); /* open stdin */
dup(i); /* stdout */
dup(i); /* stderr */

umask(027);
chdir("/"); /* chdir to /tmp ? */

return pid;

/* parent process */
default:
exit(0);
}
}
#endif

int
writepidfile(const char * fname, int pid)
{
char pidstring[16];
int pidstringlen;
int pidfile;

if(!fname || (strlen(fname) == 0))
return -1;

if( (pidfile = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0666)) < 0)
{
syslog(LOG_ERR, "Unable to open pidfile for writing %s: %m", fname);
return -1;
}

pidstringlen = snprintf(pidstring, sizeof(pidstring), "%d\n", pid);
if(pidstringlen <= 0)
{
syslog(LOG_ERR,
"Unable to write to pidfile %s: snprintf(): FAILED", fname);
close(pidfile);
return -1;
}
else
{
if(write(pidfile, pidstring, pidstringlen) < 0)
syslog(LOG_ERR, "Unable to write to pidfile %s: %m", fname);
}

close(pidfile);

return 0;
}

int
checkforrunning(const char * fname)
{
char buffer[64];
int pidfile;
pid_t pid;

if(!fname || (strlen(fname) == 0))
return -1;

if( (pidfile = open(fname, O_RDONLY)) < 0)
return 0;

memset(buffer, 0, 64);

if(read(pidfile, buffer, 63))
{
if( (pid = atol(buffer)) > 0)
{
if(!kill(pid, 0))
{
close(pidfile);
return -2;
}
}
}

close(pidfile);

return 0;
}

Loading

0 comments on commit f557f8e

Please sign in to comment.