1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
number(&self) -> u3215  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 /*
21  * XSEC
22  *
23  * TXFMSB := Class that takes an input safeBuffer to start a transform pipe
24  *
25  * $Id: TXFMSB.cpp 1817117 2017-12-04 19:03:16Z scantor $
26  *
27  */
28 
29 #include <xsec/transformers/TXFMSB.hpp>
30 
31 XERCES_CPP_NAMESPACE_USE
32 
33 // General includes
34 
35 #include <memory.h>
36 
37 TXFMSB::TXFMSB(DOMDocument *doc) : TXFMBase(doc) {
38 
39 	toOutput = 0;
40 
41 }
my_object_set_number(this: &mut Object, _cmd: Sel, number: u32)42 
43 
44 TXFMSB::~TXFMSB() {
45 
46 }
47 
48 	// Methods to set the inputs
49 
50 void TXFMSB::setInput(TXFMBase *newInput) {
51 
52 	// We're the start of the actual data pipe, but we need to track
53     // the pointer for chain disposal.
54     input = newInput;
55 
56 	return;
57 
58 }
59 
60 void TXFMSB::setInput(const safeBuffer& sbIn) {
61 
62 	// Assume this is a string
63 
main()64 	sb = sbIn;
65 	toOutput = sb.sbStrlen();
66 	sbs = toOutput;
67 
68 }
69 
70 void TXFMSB::setInput(const safeBuffer& sbIn, unsigned int sbSize) {
71 
72 	// Assume this is a string
73 
74 	sb = sbIn;
75 	if (sbSize > sb.sbRawBufferSize())
76 		toOutput = sb.sbRawBufferSize();
77 	else
78 		toOutput = sbSize;
79 	sbs = toOutput;
80 
81 }
82 
83 
84 	// Methods to get tranform output type and input requirement
85 
86 TXFMBase::ioType TXFMSB::getInputType(void) const {
87 
88 	return TXFMBase::BYTE_STREAM;
89 
90 }
91 
92 TXFMBase::ioType TXFMSB::getOutputType(void) const {
93 
94 	return TXFMBase::BYTE_STREAM;
95 
96 }
97 
98 
99 TXFMBase::nodeType TXFMSB::getNodeType(void) const {
100 
101 	return TXFMBase::DOM_NODE_NONE;
102 
103 }
104 
105 
106 
107 	// Methods to get output data
108 
109 unsigned int TXFMSB::readBytes(XMLByte * const toFill, unsigned int maxToFill) {
110 
111 	// Return from the buffer
112 
113 	unsigned int ret;
114 
115 	if (toOutput == 0)
116 		return 0;
117 
118 	// Check if we can just output everything left
119 	if (toOutput <= maxToFill) {
120 
121 		memcpy((char *) toFill, &(sb.rawBuffer()[sbs - toOutput]), toOutput);
122 		ret = (unsigned int) toOutput;
123 		toOutput = 0;
124 
125 		return ret;
126 
127 	}
128 
129 	// Output just some
130 
131 	memcpy((char *) toFill, &(sb.rawBuffer()[sbs - toOutput]), maxToFill);
132 	ret = maxToFill;
133 	toOutput -= maxToFill;
134 
135 	return ret;
136 }
137