Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
b64straw.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program 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
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Command & Conquer *
24 * *
25 * $Archive:: /Commando/Library/B64STRAW.CPP $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 7/22/97 11:37a $*
30 * *
31 * $Revision:: 1 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * Base64Straw::Get -- Fetch data and convert it to/from base 64 encoding. *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38#include "always.h"
39#include "b64straw.h"
40#include "base64.h"
41#include <string.h>
42
43
44/***********************************************************************************************
45 * Base64Straw::Get -- Fetch data and convert it to/from base 64 encoding. *
46 * *
47 * This routine will fetch the number of bytes requested and perform any conversion as *
48 * necessary upon the data. The nature of Base 64 encoding means that the data will *
49 * increase in size by 30% when encoding and decrease in like manner when decoding. *
50 * *
51 * INPUT: source -- The buffer to hold the processed data. *
52 * *
53 * length -- The number of bytes requested. *
54 * *
55 * OUTPUT: Returns with the number of bytes stored into the buffer. If the number is less *
56 * than requested, then this indicates that the data stream has been exhausted. *
57 * *
58 * WARNINGS: none *
59 * *
60 * HISTORY: *
61 * 07/03/1996 JLB : Created. *
62 *=============================================================================================*/
63int Base64Straw::Get(void * source, int slen)
64{
65 int total = 0;
66
67 char * from;
68 int fromsize;
69 char * to;
70 int tosize;
71
72 if (Control == ENCODE) {
73 from = PBuffer;
74 fromsize = sizeof(PBuffer);
75 to = CBuffer;
76 tosize = sizeof(CBuffer);
77 } else {
78 from = CBuffer;
79 fromsize = sizeof(CBuffer);
80 to = PBuffer;
81 tosize = sizeof(PBuffer);
82 }
83
84 /*
85 ** Process the byte request in code blocks until there are either
86 ** no more source bytes available or the request has been fulfilled.
87 */
88 while (slen > 0) {
89
90 /*
91 ** Transfer any processed bytes available to the request buffer.
92 */
93 if (Counter > 0) {
94 int len = (slen < Counter) ? slen : Counter;
95 memmove(source, &to[tosize-Counter], len);
96 Counter -= len;
97 slen -= len;
98 source = ((char *)source) + len;
99 total += len;
100 }
101 if (slen == 0) break;
102
103 /*
104 ** More bytes are needed, so fetch and process another base 64 block.
105 */
106 int incount = Straw::Get(from, fromsize);
107 if (Control == ENCODE) {
108 Counter = Base64_Encode(from, incount, to, tosize);
109 } else {
110 Counter = Base64_Decode(from, incount, to, tosize);
111 }
112 if (Counter == 0) break;
113 }
114
115 return(total);
116}
int Base64_Encode(void const *source, int slen, void *dest, int dlen)
Definition base64.cpp:142
int Base64_Decode(void const *source, int slen, void *dest, int dlen)
Definition base64.cpp:243
virtual int Get(void *source, int slen)
Definition b64straw.cpp:63
virtual int Get(void *buffer, int slen)
Definition straw.cpp:132