/usr/include/rutil/resipfaststreams.hxx is in libresiprocate-1.9-dev 1.9.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | #if !defined(RESIP_RESIPFASTSTREAMS_HXX)
#define RESIP_RESIPFASTSTREAMS_HXX
/*! \file resipfaststreams.hxx
\brief Replaces STL streams for general encoding purposes.
#define RESIP_USE_STL_STREAMS will use the STL for stream encoding (std::ostream). Undefining RESIP_USE_STL_STREAMS will
cause resip to use the alternative stream handling defined in this file for encoding objects.
*/
#define RESIP_USE_STL_STREAMS
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream> //for std::endl, std::cerr, etc.
#include <stdio.h> //for snprintf
#include <cassert>
#include "rutil/compat.hxx"
namespace resip
{
class ResipStreamBuf
{
public:
ResipStreamBuf(void)
{}
virtual ~ ResipStreamBuf(void)
{}
virtual size_t writebuf(const char *s, size_t count) = 0;
virtual size_t readbuf(char *buf, size_t count) = 0;
virtual size_t putbuf(char ch) = 0;
virtual void flushbuf(void)=0;
virtual UInt64 tellpbuf(void)=0;
};
class ResipBasicIOStream
{
public:
ResipBasicIOStream(void):good_(false),eof_(true)
{}
~ResipBasicIOStream(void)
{}
bool good(void) const
{
return good_;
}
bool eof(void) const
{
return eof_;
}
void clear(void) const
{}
protected:
bool good_;
bool eof_;
};
/** std::ostream replacement.
*/
class ResipFastOStream : public ResipBasicIOStream
{
public:
ResipFastOStream(ResipStreamBuf *buf):buf_(buf)
{
good_ = true;
}
virtual ~ResipFastOStream(void)
{}
virtual UInt64 tellp(void)
{
if (rdbuf())
{
return rdbuf()->tellpbuf();
}
return 0;
}
ResipStreamBuf * rdbuf(void) const
{
return buf_;
}
void rdbuf(ResipStreamBuf *buf)
{
buf_ = buf;
}
ResipFastOStream & flush(void)
{
if (rdbuf())
{
rdbuf()->flushbuf();
}
return *this;
}
ResipFastOStream &write(const char *s, size_t count)
{
if (rdbuf())
{
rdbuf()->writebuf(s,count);
}
return *this;
}
ResipFastOStream &put(char ch)
{
if (rdbuf())
{
rdbuf()->putbuf(ch);
}
return *this;
}
ResipFastOStream& operator<<(bool b)
{
//int i = (b == true) ? (1):(0);
*this<<(static_cast<Int32>(b));
return *this;
}
ResipFastOStream& operator<<(Int16 i)
{
*this<<(static_cast<Int32>(i));
return *this;
}
ResipFastOStream& operator<<(UInt16 ui)
{
*this<<(static_cast<UInt32>(ui));
return *this;
}
ResipFastOStream& operator<<(Int32 l)
{
if (!buf_)
{
return *this;
}
char buf[33];
//snprintf(buf,33,"%" PRId32,l);
LTOA((long int)l,buf,33,10);
size_t count = strlen(buf);
if (buf_->writebuf(buf,count) < count)
{
good_ = false;
}
return *this;
}
ResipFastOStream& operator<<(UInt32 ul)
{
if (!buf_)
{
return *this;
}
char buf[33];
//snprintf(buf,33,"%" PRIu32,ul);
ULTOA((unsigned long int)ul,buf,33,10);
size_t count = strlen(buf);
if (buf_->writebuf(buf,count) < count)
{
good_ = false;
}
return *this;
}
ResipFastOStream& operator<<(long l)
{
if (!buf_)
{
return *this;
}
char buf[66];
LTOA(l,buf,66,10);
size_t count = strlen(buf);
if (buf_->writebuf(buf,count) < count)
{
good_ = false;
}
return *this;
}
ResipFastOStream& operator<<(unsigned long ul)
{
if (!buf_)
{
return *this;
}
char buf[66];
ULTOA(ul,buf,66,10);
size_t count = strlen(buf);
if (buf_->writebuf(buf,count) < count)
{
good_ = false;
}
return *this;
}
ResipFastOStream& operator<<(Int64 i64)
{
if (!buf_)
{
return *this;
}
char buf[66];
//snprintf(buf,66,"%" PRId64,i64);
I64TOA(i64,buf,66,10);
size_t count = strlen(buf);
if (buf_->writebuf(buf,count) < count)
{
good_ = false;
}
return *this;
}
ResipFastOStream& operator<<(UInt64 ui64)
{
if (!buf_)
{
return *this;
}
char buf[66];
//snprintf(buf,66,"%" PRIu64,ui64);
UI64TOA(ui64,buf,66,10);
size_t count = strlen(buf);
if (buf_->writebuf(buf,count) < count)
{
good_ = false;
}
return *this;
}
ResipFastOStream& operator<<(float f)
{
*this<< (static_cast<double>(f));
return *this;
}
ResipFastOStream& operator<<(double d)
{
if (!buf_)
{
return *this;
}
char buf[_CVTBUFSIZE];
GCVT(d,6,buf,_CVTBUFSIZE);//6 significant digits is the default for %f
size_t count = strlen(buf);
#ifndef WIN32
//not using the non-standard microsoft conversion functions
//remove any trailing zeros. Note that resipfastreams does not support STL stream width or precision
//modifiers
size_t idx=0;
for (; count > 1; count--)
{
idx = count-1;
if (buf[idx] != '0' && buf[idx] != '.')
{
break;
}
}
#endif
if (buf_->writebuf(buf,count) < count)
{
good_ = false;
}
return *this;
}
ResipFastOStream& operator<<(const void *vp)
{
if (!buf_)
{
return *this;
}
char buf[32];
SNPRINTF_1(buf,32,_TRUNCATE,"%p",vp);
size_t count = strlen(buf);
if (buf_->writebuf(buf,count) < count)
{
good_ = false;
}
return *this;
}
#ifdef WIN32
ResipFastOStream& operator<<(std::ostream& (__cdecl *_Pfn)(std::ostream&))
#else
ResipFastOStream& operator<<(std::ostream& (*_Pfn)(std::ostream &))
#endif
{
if (!buf_)
{
return *this;
}
if (_Pfn == static_cast<std::ostream& (*)(std::ostream&)>(std::endl))
{
if (buf_->writebuf("\n",1) < 1)
{
good_ = false;
}
}
else
{
assert(0);
}
return *this;
}
private:
ResipStreamBuf *buf_;
};
inline resip::ResipFastOStream& operator<<(resip::ResipFastOStream& ostr, const char *str)
{
ostr.write(str,strlen(str));
return ostr;
}
inline resip::ResipFastOStream& operator<<(resip::ResipFastOStream& ostr, char ch)
{
ostr.put(ch);
return ostr;
}
inline resip::ResipFastOStream& operator<<(resip::ResipFastOStream& ostr, unsigned char ch)
{
ostr.put((char)ch);
return ostr;
}
inline resip::ResipFastOStream& operator<<(resip::ResipFastOStream& ostr, const unsigned char *str)
{
ostr.write((const char *)str,strlen((const char *)str));
return ostr;
}
inline resip::ResipFastOStream& operator<<(resip::ResipFastOStream& ostr, signed char ch)
{
ostr.put((char)ch);
return ostr;
}
inline resip::ResipFastOStream& operator<<(resip::ResipFastOStream& ostr, const signed char *str)
{
ostr.write((const char *)str,strlen((const char *)str));
return ostr;
}
inline resip::ResipFastOStream & operator<<(resip::ResipFastOStream &ostr, const std::string &str)
{
ostr.write(str.c_str(),str.size());
return ostr;
}
/** std::istream replacement
*/
class ResipFastIStream : public ResipBasicIOStream
{
public:
ResipFastIStream(ResipStreamBuf *buf):buf_(buf)
{}
virtual ~ResipFastIStream(void)
{}
ResipStreamBuf * rdbuf(void) const
{
return buf_;
}
ResipFastIStream &read(char *s, size_t count)
{
if (rdbuf())
{
rdbuf()->readbuf(s,count);
}
return *this;
}
private:
ResipStreamBuf *buf_;
};
/** Used to replace std::cerr, std::cout, etc.
*/
class ResipStdBuf : public ResipStreamBuf
{
public:
typedef enum BufType
{
null,
stdCerr,
stdCout
} BufType;
ResipStdBuf(BufType type)
:type_(type)
{}
~ResipStdBuf(void)
{}
virtual size_t writebuf(const char *s, size_t count)
{
switch (type_)
{
case stdCerr:
{
std::cerr << s;
break;
}
case stdCout:
{
std::cout << s;
break;
}
default:
break;
}
return count;
}
virtual size_t readbuf(char *buf, size_t count)
{
return 0;
}
virtual size_t putbuf(char ch)
{
return writebuf(&ch,1);
}
virtual void flushbuf(void)
{}
virtual UInt64 tellpbuf(void)
{
return 0;
}
private:
BufType type_;
};
/** A direct replacement for std::cout, std::cerr, etc.
*/
class ResipStdCOStream: public ResipFastOStream
{
public:
ResipStdCOStream(ResipStdBuf::BufType type)
:ResipFastOStream(0),buf_(type)
{
rdbuf(&buf_);
}
~ResipStdCOStream(void)
{}
private:
ResipStdBuf buf_;
};
#ifdef RESIP_USE_STL_STREAMS
#define EncodeStream std::ostream
#define DecodeStream std::istream
#define resipCerr std::cerr
#define resipCout std::cout
#else
#define EncodeStream resip::ResipFastOStream
#define DecodeStream resip::ResipFastIStream
extern ResipStdCOStream resipFastCerr;
extern ResipStdCOStream resipFastCout;
#define resipCerr resip::resipFastCerr
#define resipCout resip::resipFastCout
#endif
extern ResipStdCOStream resipFastNull;
} //namespace resip
#endif //RESIP_RESIPFASTSTREAMS_HXX
/* ====================================================================
* The Vovida Software License, Version 1.0
*
* Copyright (c) 2005. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
* and "Vovida Open Communication Application Library (VOCAL)" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact vocal@vovida.org.
*
* 4. Products derived from this software may not be called "VOCAL", nor
* may "VOCAL" appear in their name, without prior written
* permission of Vovida Networks, Inc.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by Vovida
* Networks, Inc. and many individuals on behalf of Vovida Networks,
* Inc. For more information on Vovida Networks, Inc., please see
* <http://www.vovida.org/>.
*
*/
|