1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_automation.hxx" 26 27 /************************************************************************* 28 * 29 * ATTENTION 30 * This file is intended to work inside and outside the StarOffice environment. 31 * Only adaption of file commtypes.hxx should be necessary. Else it is a bug! 32 * 33 ************************************************************************/ 34 #include <osl/endian.h> 35 36 #include "cmdbasestream.hxx" 37 #include "rcontrol.hxx" 38 39 CmdBaseStream::CmdBaseStream() 40 : pCommStream( NULL ) 41 { 42 } 43 44 CmdBaseStream::~CmdBaseStream() 45 { 46 } 47 48 void CmdBaseStream::GenError (rtl::OString *pUId, comm_String *pString ) 49 { 50 Write(comm_USHORT(SIReturnError)); 51 Write(pUId); 52 Write(pString); 53 } 54 55 void CmdBaseStream::GenReturn (comm_USHORT nRet, comm_ULONG nUId ) 56 { 57 Write(comm_USHORT(SIReturn)); 58 Write(nRet); 59 Write(nUId); 60 Write(comm_USHORT(PARAM_NONE)); // Typ der folgenden Parameter 61 } 62 63 void CmdBaseStream::GenReturn (comm_USHORT nRet, rtl::OString *pUId, comm_ULONG nNr ) 64 { 65 Write(comm_USHORT(SIReturn)); 66 Write(nRet); 67 if ( pUId->equals( rtl::OString( "UID_ACTIVE" ) ) ) 68 Write(comm_ULONG(0)); 69 else 70 Write(pUId); 71 Write(comm_USHORT(PARAM_ULONG_1)); // Typ der folgenden Parameter 72 Write(nNr); 73 } 74 75 void CmdBaseStream::GenReturn (comm_USHORT nRet, rtl::OString *pUId, comm_String *pString ) 76 { 77 Write(comm_USHORT(SIReturn)); 78 Write(nRet); 79 if ( pUId->equals( rtl::OString( "UID_ACTIVE" ) ) ) 80 Write(comm_ULONG(0)); 81 else 82 Write(pUId); 83 Write(comm_USHORT(PARAM_STR_1)); // Typ der folgenden Parameter 84 Write(pString); 85 } 86 87 void CmdBaseStream::GenReturn (comm_USHORT nRet, rtl::OString *pUId, comm_BOOL bBool ) 88 { 89 Write(comm_USHORT(SIReturn)); 90 Write(nRet); 91 if ( pUId->equals( rtl::OString( "UID_ACTIVE" ) ) ) 92 Write(comm_ULONG(0)); 93 else 94 Write(pUId); 95 Write(comm_USHORT(PARAM_BOOL_1)); // Typ der folgenden Parameter 96 Write(bBool); 97 } 98 99 void CmdBaseStream::GenReturn (comm_USHORT nRet, rtl::OString *pUId, comm_ULONG nNr, comm_String *pString, comm_BOOL bBool ) 100 { 101 Write(comm_USHORT(SIReturn)); 102 Write(nRet); 103 if ( pUId->equals( rtl::OString( "UID_ACTIVE" ) ) ) 104 Write(comm_ULONG(0)); 105 else 106 Write(pUId); 107 Write(comm_USHORT(PARAM_ULONG_1|PARAM_STR_1|PARAM_BOOL_1)); // Typ der folgenden Parameter 108 Write(nNr); 109 Write(pString); 110 Write(bBool); 111 } 112 113 void CmdBaseStream::GenReturn (comm_USHORT nRet, comm_USHORT nMethod, comm_ULONG nNr ) 114 { 115 Write(comm_USHORT(SIReturn)); 116 Write(nRet); 117 Write((comm_ULONG)nMethod); //HELPID BACKWARD (no sal_uLong needed) 118 Write(comm_USHORT(PARAM_ULONG_1)); // Typ der folgenden Parameter 119 Write(nNr); 120 } 121 122 void CmdBaseStream::GenReturn (comm_USHORT nRet, comm_USHORT nMethod, comm_String *pString ) 123 { 124 Write(comm_USHORT(SIReturn)); 125 Write(nRet); 126 Write((comm_ULONG)nMethod); //HELPID BACKWARD (no sal_uLong needed) 127 Write(comm_USHORT(PARAM_STR_1)); // Typ der folgenden Parameter 128 Write(pString); 129 } 130 131 void CmdBaseStream::GenReturn (comm_USHORT nRet, comm_USHORT nMethod, comm_BOOL bBool ) 132 { 133 Write(comm_USHORT(SIReturn)); 134 Write(nRet); 135 Write((comm_ULONG)nMethod); //HELPID BACKWARD (no sal_uLong needed) 136 Write(comm_USHORT(PARAM_BOOL_1)); // Typ der folgenden Parameter 137 Write(bBool); 138 } 139 140 void CmdBaseStream::GenReturn (comm_USHORT nRet, comm_USHORT nMethod, comm_USHORT nNr ) 141 { 142 Write(comm_USHORT(SIReturn)); 143 Write(nRet); 144 Write((comm_ULONG)nMethod); //HELPID BACKWARD (no sal_uLong needed) 145 Write(comm_USHORT(PARAM_USHORT_1)); // Typ der folgenden Parameter 146 Write(nNr); 147 } 148 149 150 // MacroRecorder 151 void CmdBaseStream::GenReturn( comm_USHORT nRet, rtl::OString *pUId, comm_USHORT nMethod ) 152 { 153 Write(comm_USHORT(SIReturn)); 154 Write(nRet); 155 Write(pUId); 156 Write(comm_USHORT(PARAM_USHORT_1)); // Typ der folgenden Parameter 157 Write(nMethod); 158 } 159 160 void CmdBaseStream::GenReturn( comm_USHORT nRet, rtl::OString *pUId, comm_USHORT nMethod, comm_String *pString ) 161 { 162 Write(comm_USHORT(SIReturn)); 163 Write(nRet); 164 Write(pUId); 165 Write(comm_USHORT(PARAM_USHORT_1|PARAM_STR_1)); // Typ der folgenden Parameter 166 Write(nMethod); 167 Write(pString); 168 } 169 170 void CmdBaseStream::GenReturn( comm_USHORT nRet, rtl::OString *pUId, comm_USHORT nMethod, comm_String *pString, comm_BOOL bBool ) 171 { 172 Write(comm_USHORT(SIReturn)); 173 Write(nRet); 174 Write(pUId); 175 Write(comm_USHORT(PARAM_USHORT_1|PARAM_STR_1|PARAM_BOOL_1)); // Typ der folgenden Parameter 176 Write(nMethod); 177 Write(pString); 178 Write(bBool); 179 } 180 181 void CmdBaseStream::GenReturn( comm_USHORT nRet, rtl::OString *pUId, comm_USHORT nMethod, comm_BOOL bBool ) 182 { 183 Write(comm_USHORT(SIReturn)); 184 Write(nRet); 185 Write(pUId); 186 Write(comm_USHORT(PARAM_USHORT_1|PARAM_BOOL_1)); // Typ der folgenden Parameter 187 Write(nMethod); 188 Write(bBool); 189 } 190 191 void CmdBaseStream::GenReturn( comm_USHORT nRet, rtl::OString *pUId, comm_USHORT nMethod, comm_ULONG nNr ) 192 { 193 Write(comm_USHORT(SIReturn)); 194 Write(nRet); 195 Write(pUId); 196 Write(comm_USHORT(PARAM_USHORT_1|PARAM_ULONG_1)); // Typ der folgenden Parameter 197 Write(nMethod); 198 Write(nNr); 199 } 200 201 202 203 void CmdBaseStream::Read (comm_USHORT &nNr) 204 { 205 comm_USHORT nId; 206 *pCommStream >> nId; 207 if (pCommStream->IsEof()) return; 208 #ifdef DBG_UTIL 209 if (nId != BinUSHORT) DBG_ERROR1( "Falscher Typ im Stream: Erwartet USHORT, gefunden :%hu", nId ); 210 #endif 211 *pCommStream >> nNr; 212 } 213 214 void CmdBaseStream::Read (comm_ULONG &nNr) 215 { 216 comm_USHORT nId; 217 *pCommStream >> nId; 218 if (pCommStream->IsEof()) return; 219 #ifdef DBG_UTIL 220 if (nId != BinULONG) DBG_ERROR1( "Falscher Typ im Stream: Erwartet ULONG, gefunden :%hu", nId ); 221 #endif 222 *pCommStream >> nNr; 223 } 224 225 void CmdBaseStream::Read (comm_UniChar* &aString, comm_USHORT &nLenInChars ) 226 { 227 comm_USHORT nId; 228 *pCommStream >> nId; 229 #ifdef DBG_UTIL 230 if (nId != BinString) DBG_ERROR1( "Falscher Typ im Stream: Erwartet String, gefunden :%hu", nId ); 231 #endif 232 233 *pCommStream >> nLenInChars; 234 235 aString = new comm_UniChar [nLenInChars]; 236 pCommStream->Read( aString, ((comm_ULONG)nLenInChars) * sizeof( comm_UniChar ) ); 237 #ifdef OSL_BIGENDIAN 238 // we have to change the byteorder 239 comm_USHORT n; 240 for ( n = 0 ; n < nLenInChars ; n++ ) 241 aString[ n ] = aString[ n ] >> 8 | aString[ n ] << 8; 242 #endif 243 } 244 245 void CmdBaseStream::Read (comm_BOOL &bBool) 246 { 247 comm_USHORT nId; 248 *pCommStream >> nId; 249 #ifdef DBG_UTIL 250 if (nId != BinBool) DBG_ERROR1( "Falscher Typ im Stream: Erwartet BOOL, gefunden :%hu", nId ); 251 #endif 252 *pCommStream >> bBool; 253 } 254 255 comm_USHORT CmdBaseStream::GetNextType() 256 { 257 comm_USHORT nId; 258 *pCommStream >> nId; 259 pCommStream->SeekRel(-2); 260 return nId; 261 } 262 263 264 void CmdBaseStream::Write( comm_USHORT nNr ) 265 { 266 *pCommStream << comm_USHORT( BinUSHORT ); 267 *pCommStream << nNr; 268 } 269 270 void CmdBaseStream::Write( comm_ULONG nNr ) 271 { 272 *pCommStream << comm_USHORT( BinULONG ); 273 *pCommStream << nNr; 274 } 275 276 void CmdBaseStream::Write( const comm_UniChar* aString, comm_USHORT nLenInChars ) 277 { 278 *pCommStream << comm_USHORT(BinString); 279 280 comm_USHORT n; 281 282 // remove BiDi and zero-width-markers 0x200B - 0x200F 283 // remove BiDi and paragraph-markers 0x2028 - 0x202E 284 285 comm_UniChar* aNoBiDiString; 286 aNoBiDiString = new comm_UniChar [nLenInChars]; 287 comm_USHORT nNewLenInChars = 0; 288 for ( n = 0 ; n < nLenInChars ; n++ ) 289 { 290 comm_UniChar c = aString[ n ]; 291 if ( ((c >= 0x200B) && (c <= 0x200F)) 292 ||((c >= 0x2028) && (c <= 0x202E)) ) 293 { //Ignore character 294 } 295 else 296 { 297 aNoBiDiString[ nNewLenInChars ] = c; 298 nNewLenInChars++; 299 } 300 } 301 302 *pCommStream << nNewLenInChars; 303 304 #ifdef OSL_BIGENDIAN 305 // we have to change the byteorder 306 comm_UniChar* aNewString; 307 aNewString = new comm_UniChar [nNewLenInChars]; 308 for ( n = 0 ; n < nNewLenInChars ; n++ ) 309 aNewString[ n ] = aNoBiDiString[ n ] >> 8 | aNoBiDiString[ n ] << 8; 310 pCommStream->Write( aNewString, ((comm_ULONG)nNewLenInChars) * sizeof( comm_UniChar ) ); 311 delete [] aNewString; 312 #else 313 pCommStream->Write( aNoBiDiString, ((comm_ULONG)nNewLenInChars) * sizeof( comm_UniChar ) ); 314 #endif 315 316 delete [] aNoBiDiString; 317 } 318 319 void CmdBaseStream::Write( comm_BOOL bBool ) 320 { 321 *pCommStream << comm_USHORT( BinBool ); 322 *pCommStream << bBool; 323 } 324 325 void CmdBaseStream::Read ( comm_String* &pString ) 326 { 327 (void) pString; /* avoid warning about unused parameter */ 328 DBG_ERROR("Read ( comm_String* &pString ) Not Implemented"); 329 } 330 void CmdBaseStream::Read ( rtl::OString* &pId ) 331 { 332 (void) pId; /* avoid warning about unused parameter */ 333 DBG_ERROR("Read ( rtl::OString* &pId ) Not Implemented"); 334 } 335 336 void CmdBaseStream::Write( comm_String *pString ) 337 { 338 (void) pString; /* avoid warning about unused parameter */ 339 DBG_ERROR("Write( comm_String *pString ) Not Implemented"); 340 } 341 void CmdBaseStream::Write( rtl::OString* pId ) 342 { 343 (void) pId; /* avoid warning about unused parameter */ 344 DBG_ERROR("Write( rtl::OString* pId ) Not Implemented"); 345 } 346 347