Initial revision

This commit is contained in:
Hans Lambermont
2002-10-12 11:37:38 +00:00
commit 12315f4d0e
1699 changed files with 444708 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* 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; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* 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, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* streamglue loopback adds a streamGlueHeader to start of the write stream
*/
#include <stdio.h>
#include <stdlib.h>
#include "GEN_messaging.h"
#include "zlib.h"
#include "BLO_writeStreamGlue.h"
#include "BLO_dumpFromMemory.h"
int
BLO_dumpFromMemory(
unsigned char *data,
unsigned int dataIn,
struct streamGlueHeaderStruct *streamGlueHeader)
{
struct writeStreamGlueStruct *streamGlue = NULL;
int err = 0;
#ifndef NDEBUG
fprintf(GEN_errorstream,
"BLO_dumpFromMemory: %u streamGlueHeader + %u data = %u\n",
STREAMGLUEHEADERSIZE,
dataIn,
STREAMGLUEHEADERSIZE + dataIn);
#endif
// all data is in. set size in streamGlueHeader and write it out
streamGlueHeader->totalStreamLength = htonl(dataIn);
streamGlueHeader->crc = htonl(crc32(0L, (const Bytef *) streamGlueHeader,
STREAMGLUEHEADERSIZE - 4));
err = writeStreamGlue(
Global_streamGlueControl,
&streamGlue,
(unsigned char *)streamGlueHeader,
STREAMGLUEHEADERSIZE,
0);
if (err) return err;
// write out data
err = writeStreamGlue(
Global_streamGlueControl,
&streamGlue,
data,
dataIn,
1);
return err;
}

View File

@@ -0,0 +1,39 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* 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; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* 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, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* streamglue loopback adds a streamGlueHeader to start of the write stream
*/
int
BLO_dumpFromMemory(
unsigned char *data,
unsigned int dataIn,
struct streamGlueHeaderStruct *streamGlueHeader);

View File

@@ -0,0 +1,72 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* 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; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* 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, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* Publisher only: get the public key from the .BPkeyfile
*/
#include <stdlib.h>
#include "BLO_keyStore.h"
#include "BLO_getPubKey.h"
int
getPubKey(byte *dataStreamPubKey,
int dataStreamPubKeyLen,
byte **publisherPubKey,
int *publisherPubKeyLen)
{
int err = 0;
*publisherPubKeyLen = keyStoreGetPubKey(publisherPubKey);
if (*publisherPubKeyLen == 0) {
// we're a publisher without .BPkey
*publisherPubKey = NULL;
return 1;
}
if (dataStreamPubKeyLen != *publisherPubKeyLen) {
// different keys
*publisherPubKeyLen = 0;
*publisherPubKey = NULL;
return 2;
}
if (memcmp(dataStreamPubKey, *publisherPubKey, *publisherPubKeyLen)
!= 0) {
// different keys
*publisherPubKeyLen = 0;
*publisherPubKey = NULL;
return 3;
}
return err;
}

View File

@@ -0,0 +1,90 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* 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; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* 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, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* define what actions a write stream should do
*/
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "BLO_writeStreamGlue.h"
struct streamGlueControlStruct *
streamGlueControlConstructor(
void)
{
struct streamGlueControlStruct *control;
control = malloc(sizeof(struct streamGlueControlStruct));
assert(control);
// TODO handle malloc errors
control->actions = 0;
control->actionsDone = 0;
memset(control->action, 0, MAXSTREAMLENGTH);
return(control);
}
void
streamGlueControlDestructor(
struct streamGlueControlStruct *streamControl)
{
free(streamControl);
}
int
streamGlueControlAppendAction(
struct streamGlueControlStruct *streamControl,
unsigned char nextAction)
{
assert(streamControl);
assert(streamControl->actions < MAXSTREAMLENGTH);
streamControl->action[streamControl->actions] = nextAction;
streamControl->actions++;
return(streamControl->actions);
}
unsigned char
streamGlueControlGetNextAction(
struct streamGlueControlStruct *streamControl)
{
unsigned char nextAction;
assert(streamControl);
assert(streamControl->actionsDone < streamControl->actions);
if (streamControl->actionsDone >= streamControl->actions) {
// the stream should have been terminated by a data
// processor, but instead streamGlue is called again ...
nextAction = UNKNOWN; // best guess ...
} else {
nextAction = streamControl->action[streamControl->actionsDone];
streamControl->actionsDone++;
}
return(nextAction);
}

View File

@@ -0,0 +1,170 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* 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; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* 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, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* connect the data stream processors
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "zlib.h"
#include "GEN_messaging.h"
#include "BLO_writeStreamGlue.h"
#include "BLO_dumpFromMemory.h"
#include "BLO_writeblenfile.h"
#include "BLO_deflate.h"
#include "BLO_encrypt.h"
#include "BLO_sign.h"
/**
* streamGlueWrite does not really stream; it buffers all data it gets
* because it needs everything to create the header, which is in front
* of the data (to make reading easier, which occurs much more often
* than writing and is thus more important to optimize for).
* @param streamControl contains a list of Glue actions. Every
* streamGlueWrite constructor eats up the next first action.
*/
int
writeStreamGlue(
struct streamGlueControlStruct *streamGlueControl,
struct writeStreamGlueStruct **streamGlue,
unsigned char *data,
unsigned int dataIn,
int finishUp)
{
int err = 0;
if (NULL == *streamGlue) {
/* we are called for the first time; play constructor */
(*streamGlue) = malloc(sizeof(struct writeStreamGlueStruct));
if (!(*streamGlue)) {
err = BWS_SETFUNCTION(BWS_WRITESTREAMGLUE) |
BWS_SETGENERR(BWS_MALLOC);
return err;
}
(*streamGlue)->dataProcessorType =
streamGlueControlGetNextAction(streamGlueControl);
(*streamGlue)->streamBufferCount = 0;
(*streamGlue)->streamBuffer = NULL;
}
if (dataIn > 0) {
/* simply buffer it */
(*streamGlue)->streamBuffer = realloc((*streamGlue)->streamBuffer,
dataIn + (*streamGlue)->streamBufferCount);
if (!(*streamGlue)->streamBuffer) {
err = BWS_SETFUNCTION(BWS_WRITESTREAMGLUE) |
BWS_SETGENERR(BWS_MALLOC);
free(*streamGlue);
return err;
}
memcpy((*streamGlue)->streamBuffer + (*streamGlue)->streamBufferCount,
data, dataIn);
(*streamGlue)->streamBufferCount += dataIn;
}
if (finishUp) {
/* all data is in, create header and call data processor */
/* first create the streamGlueHeaderStruct */
struct streamGlueHeaderStruct *streamGlueHeader;
streamGlueHeader = malloc(STREAMGLUEHEADERSIZE);
if (!streamGlueHeader) {
err = BWS_SETFUNCTION(BWS_WRITESTREAMGLUE) |
BWS_SETGENERR(BWS_MALLOC);
free((*streamGlue)->streamBuffer);
free(*streamGlue);
return err;
}
streamGlueHeader->magic = 'A';
streamGlueHeader->totalStreamLength = 0; // set in the actions _end
streamGlueHeader->dataProcessorType =
htonl((*streamGlue)->dataProcessorType);
streamGlueHeader->crc = 0; // set in in the actions _end
#ifndef NDEBUG
fprintf(GEN_errorstream,
"streamGlue: write %d gets %u data + %u streamGlueHeader = %u\n",
(*streamGlue)->dataProcessorType,
(*streamGlue)->streamBufferCount,
STREAMGLUEHEADERSIZE,
(*streamGlue)->streamBufferCount + STREAMGLUEHEADERSIZE);
#endif
/* all data ready, start the right data processor */
switch ((*streamGlue)->dataProcessorType) {
case DUMPFROMMEMORY:
err = BLO_dumpFromMemory((*streamGlue)->streamBuffer,
(*streamGlue)->streamBufferCount,
streamGlueHeader);
break;
case DEFLATE:
err = BLO_deflate((*streamGlue)->streamBuffer,
(*streamGlue)->streamBufferCount,
streamGlueHeader);
break;
case ENCRYPT:
err = BLO_encrypt((*streamGlue)->streamBuffer,
(*streamGlue)->streamBufferCount,
streamGlueHeader);
break;
case SIGN:
err = BLO_sign((*streamGlue)->streamBuffer,
(*streamGlue)->streamBufferCount,
streamGlueHeader);
break;
case WRITEBLENFILE:
err = BLO_writeblenfile((*streamGlue)->streamBuffer,
(*streamGlue)->streamBufferCount,
streamGlueHeader);
break;
default:
#ifndef NDEBUG
fprintf(GEN_errorstream,
"unknown dataProcessorType %d\n",
(*streamGlue)->dataProcessorType);
#endif
err = BWS_SETFUNCTION(BWS_WRITESTREAMGLUE) |
BWS_SETSPECERR(BWS_UNKNOWN);
break;
}
free(streamGlueHeader);
free((*streamGlue)->streamBuffer);
free(*streamGlue);
}
return err;
}

View File

@@ -0,0 +1,71 @@
#
# $Id$
#
# ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
#
# 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; either version 2
# of the License, or (at your option) any later version. The Blender
# Foundation also sells licenses for use in proprietary software under
# the Blender License. See http://www.blender.org/BL/ for information
# about this.
#
# 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, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
#
# The Original Code is: all of this file.
#
# Contributor(s): none yet.
#
# ***** END GPL/BL DUAL LICENSE BLOCK *****
#
#
LIBNAME = writestreamglue
DIR = $(OCGDIR)/blender/$(LIBNAME)
include nan_compile.mk
ifeq ($(OS),$(findstring $(OS), "beos darwin freebsd linux openbsd solaris windows"))
CFLAGS += -funsigned-char
endif
CFLAGS += $(LEVEL_2_C_WARNINGS)
# path to our own private header files
CPPFLAGS += -I.
# path to our own external header files
CPPFLAGS += -I..
# path to external modules
CPPFLAGS += -I../../../kernel/gen_messaging
CPPFLAGS += -I../../readstreamglue
CPPFLAGS += -I../../writeblenfile
CPPFLAGS += -I../../blenloader
CPPFLAGS += -I../../deflate
CPPFLAGS += -I../../encrypt
CPPFLAGS += -I../../sign
CPPFLAGS += -I$(NAN_OPENSSL)/include
#TODO make keystore this a seperate lib
CPPFLAGS += -I$(NAN_BLENKEY)/include
ifeq ($(OS),$(findstring $(OS), "solaris windows"))
CPPFLAGS += -I$(NAN_ZLIB)/include
endif