1 /*
2     Ming, an SWF output library
3     Copyright (C) 2002  Opaque Industries - http://www.opaque.net/
4 
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9 
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13     Lesser General Public License for more details.
14 
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19 
20 /* $Id$ */
21 
22 #ifndef __C2MAN__
23 #include <stdlib.h>
24 #include <string.h>
25 #endif
26 
27 #include "protect.h"
28 #include "blocktypes.h"
29 #include "method.h"
30 #include "libming.h"
31 #include "outputblock.h"
32 
33 
34 static void
writeSWFProtectToMethod(SWFBlock block,SWFByteOutputMethod method,void * data)35 writeSWFProtectToMethod(SWFBlock block, SWFByteOutputMethod method, void* data)
36 {
37         SWFOutput out = ((SWFProtect)block)->out;
38         SWFOutput_writeToMethod(out, method, data);
39 }
40 
41 
42 static int
completeSWFProtect(SWFBlock block)43 completeSWFProtect(SWFBlock block)
44 {
45 	SWFProtect protect = (SWFProtect)block;
46 
47 	if( protect->Password ) {
48 		SWFOutput_writeString(protect->out, (byte*)protect->Password);
49 	}
50 
51 	return SWFOutput_getLength(protect->out);
52 }
53 
54 
55 void
destroySWFProtect(SWFProtect protect)56 destroySWFProtect(SWFProtect protect)
57 {
58 	if( protect->out )
59 		destroySWFOutput(protect->out );
60 	if( protect->Password )
61 		free(protect->Password);
62 }
63 
64 
65 SWFBlock
newSWFProtect(const char * password)66 newSWFProtect(const char *password)
67 {
68 	SWFProtect protect = (SWFProtect)malloc(sizeof(struct SWFProtect_s));
69 
70 	SWFBlockInit(BLOCK(protect));
71 	BLOCK(protect)->type = SWF_PROTECT;
72 	BLOCK(protect)->writeBlock = writeSWFProtectToMethod;
73 	BLOCK(protect)->complete = completeSWFProtect;
74 	BLOCK(protect)->dtor = (destroySWFBlockMethod) destroySWFProtect;
75 
76 	protect->out = newSWFOutput();
77 	if(password != NULL)
78 		protect->Password = strdup(password);
79 	else
80 		protect->Password = NULL;
81 
82 	return (SWFBlock)protect;
83 }
84 
85 
86 /*
87  * Local variables:
88  * tab-width: 2
89  * c-basic-offset: 2
90  * End:
91  */
92