Commit 4098651d authored by Scott Deboy's avatar Scott Deboy

Adding autotools and libtool support

parent aa442349
This diff is collapsed.
This diff is collapsed.
###
#
# Makefile for Mock DTCP library customized for OCAP RI.
#
###
HOSTOS := $(shell uname -o)
export HOSTOS
ifeq ($(HOSTOS),Cygwin)
CC = gcc-3 -mno-cygwin
DLL_SUFFIX = dll
MODULES_LINK_EXT = -lws2_32 -lwinmm
LINK_PATHS = -Llib/win32
else ifeq ($(HOSTOS),GNU/Linux)
CC = gcc
DLL_SUFFIX = so
LINK_PATHS = -Llib/linux
else
$(error Unsupported OS.)
endif
DTCPIP_DLL ?= dtcpip_mock.$(DLL_SUFFIX)
MODULE_MOCKDLL = mockdll
MODULE_LINK_PFX = $(addprefix -l,mockdll)
MODULE_LINK = $(addprefix -l,$(MODULE_MOCKDLL))
default: all
$(MODULE_MOCKDLL):
$(MAKE) -C _build build
all: $(MODULE_MOCKDLL)
build: $(MODULE_MOCKDLL)
shlib: build $(MODULE_MOCKDLL)
$(CC) -shared -o $(DTCPIP_DLL) -Wl,--whole-archive -lmockdll $(LINK_PATHS) -Wl,--no-whole-archive $(MODULE_LINK_EXT)
clean:
$(MAKE) -C _build clean
purge:
rm -f $(DTCPIP_DLL)
SUBDIRS=src
ACLOCAL_AMFLAGS=-I m4
INC_DIRS = ../src
MOCKDLL_SRC_DIR = ../src
MOCKDLL_LIBNAME = libmockdll.a
COPT = -c -efi2 -fPIC\
-D_ARCH_IA32 -O0 -g \
$(addprefix -I, $(INC_DIRS))
CSRC := $(wildcard $(MOCKDLL_SRC_DIR)/*.c)
ifeq ($(HOSTOS),Cygwin)
MOCKDLL_LIB_DIR = ../lib/win32
MOCKDLL_OBJ_DIR = ../obj/win32
MOCKDLL_OBJ_SUBDIR = ../obj/win32/win32
CC = gcc-3 -mno-cygwin
COPT += -DWINSOCK2
INC_DIRS += ../src/win32
INC_DIRS += ../src/win32/include
CSRCTEMP := $(wildcard $(MOCKDLL_SRC_DIR)/win32/*.c)
COBJ := $(patsubst %.c,$(MOCKDLL_OBJ_DIR)/%.o,$(notdir $(CSRC)))
CSRC += $CSRCTEMP;
COBJ += $(patsubst %.c,$(MOCKDLL_OBJ_DIR)/win32/%.o,$(notdir $(CSRCTEMP)))
else ifeq ($(HOSTOS),GNU/Linux)
MOCKDLL_LIB_DIR = ../lib/linux
MOCKDLL_OBJ_DIR = ../obj/linux
MOCKDLL_OBJ_SUBDIR = ../obj/linux/linux
CC = gcc
COPT += -Dunix -Dlinux -Dlinux32 -D_POSIX
INC_DIRS += ../src/linux
INC_DIRS += ../src/linux/include
CSRCTEMP := $(wildcard $(MOCKDLL_SRC_DIR)/linux/*.c)
COBJ := $(patsubst %.c,$(MOCKDLL_OBJ_DIR)/%.o,$(notdir $(CSRC)))
CSRC += $CSRCTEMP;
COBJ += $(patsubst %.c,$(MOCKDLL_OBJ_DIR)/linux/%.o,$(notdir $(CSRCTEMP)))
else
$(error Unsupported OS.)
endif
build: clean_lib prepare $(MOCKDLL_LIBNAME)
$(MOCKDLL_LIBNAME) : $(COBJ)
/usr/bin/ar q $(MOCKDLL_LIB_DIR)/$@ $(COBJ)
$(COBJ) : $(MOCKDLL_OBJ_DIR)/%.o : $(MOCKDLL_SRC_DIR)/%.c $(wildcard $(addsuffix /*.h, $(INC_DIRS)))
$(CC) $(COPT) -o $@ $<
clean: clean_lib
rm -fR $(MOCKDLL_OBJ_DIR)
clean_lib:
rm -fR $(MOCKDLL_LIB_DIR)/$(MOCKDLL_LIBNAME)
prepare:
mkdir -p $(MOCKDLL_OBJ_DIR)
mkdir -p $(MOCKDLL_OBJ_SUBDIR)
mkdir -p $(MOCKDLL_LIB_DIR)
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
test -n "$srcdir" || srcdir=`dirname "$0"`
test -n "$srcdir" || srcdir=.
olddir=`pwd`
cd "$srcdir"
AUTORECONF=`which autoreconf`
if test -z $AUTORECONF; then
echo "*** No autoreconf found, please install it ***"
exit 1
fi
autoreconf --force --install --verbose || exit $?
cd "$olddir"
test -n "$NOCONFIGURE" || "$srcdir/configure" "$@"
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
AC_INIT([dtcpip_mock_lib], [1.0], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([src/MockDLL.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])
LT_INIT
AC_CANONICAL_HOST
AM_CONDITIONAL([LINUX],false)
case "$host" in
*linux*)
AC_DEFINE(LINUX,[1],[Linux Host])
AM_CONDITIONAL([LINUX],true)
;;
esac
# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AM_INIT_AUTOMAKE
AM_PROG_CC_C_O
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h unistd.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_INLINE
AC_TYPE_INT64_T
AC_TYPE_SIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T
# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([rmdir strchr strerror strstr])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUT
This diff is collapsed.
This diff is collapsed.
# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*-
#
# Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
# Written by Gary V. Vaughan, 2004
#
# This file is free software; the Free Software Foundation gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
# serial 6 ltsugar.m4
# This is to help aclocal find these macros, as it can't see m4_define.
AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
# lt_join(SEP, ARG1, [ARG2...])
# -----------------------------
# Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
# associated separator.
# Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
# versions in m4sugar had bugs.
m4_define([lt_join],
[m4_if([$#], [1], [],
[$#], [2], [[$2]],
[m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
m4_define([_lt_join],
[m4_if([$#$2], [2], [],
[m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
# lt_car(LIST)
# lt_cdr(LIST)
# ------------
# Manipulate m4 lists.
# These macros are necessary as long as will still need to support
# Autoconf-2.59 which quotes differently.
m4_define([lt_car], [[$1]])
m4_define([lt_cdr],
[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
[$#], 1, [],
[m4_dquote(m4_shift($@))])])
m4_define([lt_unquote], $1)
# lt_append(MACRO-NAME, STRING, [SEPARATOR])
# ------------------------------------------
# Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
# Note that neither SEPARATOR nor STRING are expanded; they are appended
# to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
# No SEPARATOR is output if MACRO-NAME was previously undefined (different
# than defined and empty).
#
# This macro is needed until we can rely on Autoconf 2.62, since earlier
# versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
m4_define([lt_append],
[m4_define([$1],
m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
# lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
# ----------------------------------------------------------
# Produce a SEP delimited list of all paired combinations of elements of
# PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list
# has the form PREFIXmINFIXSUFFIXn.
# Needed until we can rely on m4_combine added in Autoconf 2.62.
m4_define([lt_combine],
[m4_if(m4_eval([$# > 3]), [1],
[m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
[[m4_foreach([_Lt_prefix], [$2],
[m4_foreach([_Lt_suffix],
]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
[_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
# lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
# -----------------------------------------------------------------------
# Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
# by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
m4_define([lt_if_append_uniq],
[m4_ifdef([$1],
[m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
[lt_append([$1], [$2], [$3])$4],
[$5])],
[lt_append([$1], [$2], [$3])$4])])
# lt_dict_add(DICT, KEY, VALUE)
# -----------------------------
m4_define([lt_dict_add],
[m4_define([$1($2)], [$3])])
# lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
# --------------------------------------------
m4_define([lt_dict_add_subkey],
[m4_define([$1($2:$3)], [$4])])
# lt_dict_fetch(DICT, KEY, [SUBKEY])
# ----------------------------------
m4_define([lt_dict_fetch],
[m4_ifval([$3],
m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
# lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
# -----------------------------------------------------------------
m4_define([lt_if_dict_fetch],
[m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
[$5],
[$6])])
# lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
# --------------------------------------------------------------
m4_define([lt_dict_filter],
[m4_if([$5], [], [],
[lt_join(m4_quote(m4_default([$4], [[, ]])),
lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
[lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
])
# ltversion.m4 -- version numbers -*- Autoconf -*-
#
# Copyright (C) 2004 Free Software Foundation, Inc.
# Written by Scott James Remnant, 2004
#
# This file is free software; the Free Software Foundation gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
# @configure_input@
# serial 3337 ltversion.m4
# This file is part of GNU Libtool
m4_define([LT_PACKAGE_VERSION], [2.4.2])
m4_define([LT_PACKAGE_REVISION], [1.3337])
AC_DEFUN([LTVERSION_VERSION],
[macro_version='2.4.2'
macro_revision='1.3337'
_LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
_LT_DECL(, macro_revision, 0)
])
# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*-
#
# Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
# Written by Scott James Remnant, 2004.
#
# This file is free software; the Free Software Foundation gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
# serial 5 lt~obsolete.m4
# These exist entirely to fool aclocal when bootstrapping libtool.
#
# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
# which have later been changed to m4_define as they aren't part of the
# exported API, or moved to Autoconf or Automake where they belong.
#
# The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN
# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
# using a macro with the same name in our local m4/libtool.m4 it'll
# pull the old libtool.m4 in (it doesn't see our shiny new m4_define
# and doesn't know about Autoconf macros at all.)
#
# So we provide this file, which has a silly filename so it's always
# included after everything else. This provides aclocal with the
# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
# because those macros already exist, or will be overwritten later.
# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6.
#
# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
# Yes, that means every name once taken will need to remain here until
# we give up compatibility with versions before 1.7, at which point
# we need to keep only those names which we still refer to.
# This is to help aclocal find these macros, as it can't see m4_define.
AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])])
m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])])
m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])])
m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])])
m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])])
m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])])
m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])])
m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])])
m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])])
m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])])
m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])])
m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])])
m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])])
m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])])
m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])])
m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])])
m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])])
m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])])
m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])])
m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])])
m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])])
m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])])
m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])])
m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])])
m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])])
m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])])
m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])])
m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])])
m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])])
m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])])
AUTOMAKE_OPTIONS = subdir-objects
#bin_PROGRAMS = dtcpip_mock_lib
lib_LTLIBRARIES=libdtcpip.la
libdtcpip_la_SOURCES = \
MockDLL.c \
MockDLL.h \
mpe_error.h \
mpe_types.h \
os_error.h \
os_util_common.h
libdtcpip_la_LDFLAGS = -version-info 1:0:0
if LINUX
AM_CPPFLAGS = -I$(srcdir) -I$(srcdir)/linux -I$(srcdir)/linux/include
libdtcpip_la_SOURCES += \
linux/mock_sync.h \
linux/mock_sync.c \
linux/include/os_types.h \
linux/include/os_sync.h
libdtcpip_la_CFLAGS = -pthread
else
AM_CPPFLAGS = -I$(srcdir) -I$(srcdir)/win32 -I$(srcdir)/win32/include
libdtcpip_la_SOURCES += \
win32/mock_sync.h \
win32/mock_sync.c \
win32/include/os_types.h \
win32/include/os_sync.h
endif
// COPYRIGHT_BEGIN
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
//
// Copyright (C) 2008-2011, Cable Television Laboratories, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2. This program is distributed
// in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Please contact CableLabs if you need additional information or
// have any questions.
//
// CableLabs
// 858 Coal Creek Cir
// Louisville, CO 80027-9750
// 303 661-9100
// oc-mail@cablelabs.com
//
// If you or the company you represent has a separate agreement with CableLabs
// concerning the use of this code, your rights and obligations with respect
// to this code shall be as set forth therein. No license is granted hereunder
// for any other purpose.
// COPYRIGHT_END
#include "mock_sync.h"
#include <stdio.h>
#include <string.h> // memcpy, strrchr, strlen
#if defined( WIN32 )
#define snprintf _snprintf
#endif
#include "MockDLL.h"
#define DTCPIP_SERVER_SESSION_START 65536
#define DTCPIP_SERVER_SESSIONS_MAX sizeof(uint32_t)
static struct
{
mock_Mutex mutex;
uint32_t sessions;
}
server_data;
int dtcpip_cmn_init(const char* storage_path)
{
return 0;
}
void dtcpip_cmn_get_version(char* string, size_t length)
{
snprintf(string, length, "NO-OP DTCP-IP library for OCAP Reference Implementation.");
}
int dtcpip_src_init(unsigned short dtcp_port)
{
int ret_code = -1;
if (mock_mutexNew(&server_data.mutex) != MPE_SUCCESS)
{
ret_code = -2;
}
else
{
ret_code = 0;
}
return ret_code;
}
int dtcpip_src_open(int* session_handle, int is_audio_only)
{
int ret_code = -1;
if (session_handle == NULL)
{
ret_code = -2;
}
else
{
int i = 0;
uint32_t session = 0;
mock_mutexAcquire(server_data.mutex);
for (i = 0; i < DTCPIP_SERVER_SESSIONS_MAX; i++)
{
session = 1 << i;
if ((server_data.sessions & session) == 0)
{
break;
}
}
if (i == DTCPIP_SERVER_SESSIONS_MAX)
{
ret_code = -3;
}
else
{
server_data.sessions ^= session;
*session_handle = (int) (DTCPIP_SERVER_SESSION_START + i);
ret_code = 0;
}
mock_mutexRelease(server_data.mutex);
}
return ret_code;
}
int dtcpip_src_alloc_encrypt(int session_handle,
unsigned char cci,
char* cleartext_data, size_t cleartext_size,
char** encrypted_data, size_t* encrypted_size)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_SERVER_SESSION_START);
mock_mutexAcquire(server_data.mutex);
if ((server_data.sessions & session) == 0)
{
ret_code = -2;
}
else if (cleartext_data == NULL && cleartext_size > 0) // only read if we have data
{
ret_code = -3;
}
else if (encrypted_data == NULL && cleartext_size > 0) // only written if we have data
{
ret_code = -4;
}
else if (encrypted_size == NULL) // always written
{
ret_code = -5;
}
else if (cleartext_size == 0)
{
*encrypted_size = 0;
ret_code = 0;
}
else if ((*encrypted_data = malloc(cleartext_size)) == NULL)
{
ret_code = -6;
}
else
{
memcpy(*encrypted_data, cleartext_data, cleartext_size);
*encrypted_size = cleartext_size;
ret_code = 0;
}
mock_mutexRelease(server_data.mutex);
return ret_code;
}
int dtcpip_src_free(char* encrypted_data)
{
free((void *)encrypted_data);
return 0;
}
int dtcpip_src_close(int session_handle)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_SERVER_SESSION_START);
mock_mutexAcquire(server_data.mutex);
if ((server_data.sessions & session) == 0)
{
ret_code = -2;
}
else
{
server_data.sessions ^= session;
ret_code = 0;
}
mock_mutexRelease(server_data.mutex);
return ret_code;
}
#define DTCPIP_PLAYER_SESSION_START 16777216
#define DTCPIP_PLAYER_SESSIONS_MAX sizeof(uint32_t)
static struct
{
mock_Mutex mutex;
uint32_t sessions;
}
player_data;
int dtcpip_snk_init(void)
{
int ret_code = -1;
if (mock_mutexNew(&player_data.mutex) != MPE_SUCCESS)
{
ret_code = -2;
}
else
{
player_data.sessions = 0;
ret_code = 0;
}
return ret_code;
}
int dtcpip_snk_open(
char* ip_addr, unsigned short ip_port,
int *session_handle)
{
int ret_code = -1;
if (ip_addr == NULL)
{
ret_code = -2;
}
else if (session_handle == NULL)
{
ret_code = -3;
}
else
{
int i = 0;
uint32_t session = 0;
mock_mutexAcquire(player_data.mutex);
for (i = 0; i < DTCPIP_PLAYER_SESSIONS_MAX; i++)
{
session = 1 << i;
if ((player_data.sessions & session) == 0)
{
break;
}
}
if (i == DTCPIP_PLAYER_SESSIONS_MAX)
{
ret_code = -4;
}
else
{
player_data.sessions ^= session;
*session_handle = (int) (DTCPIP_PLAYER_SESSION_START + i);
ret_code = 0;
}
mock_mutexRelease(player_data.mutex);
}
return ret_code;
}
int dtcpip_snk_alloc_decrypt(int session_handle,
char* encrypted_data, size_t encrypted_size,
char** cleartext_data, size_t* cleartext_size)
{
int ret_code = -1;
uint32_t session = 1 << ((uint32_t) session_handle - DTCPIP_PLAYER_SESSION_START);
mock_mutexAcquire(player_data.mutex);
if ((player_data.sessions & session) == 0)
{
ret_code = -2;
}
else if (encrypted_data == NULL && encrypted_size > 0) // only read if we have data
{
ret_code = -3;
}
else if (cleartext_data == NULL && encrypted_size > 0) // only written if we have data
{
ret_code = -4;
}
else if (cleartext_size == NULL) // always written
{
ret_code = -5;
}
else if (encrypted_size == 0)
{
*cleartext_size = 0;
ret_code = 0;
}
else if ((*cleartext_data = malloc(encrypted_size)) == NULL)
{
ret_code = -6;
}
else
{