00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifndef _PASN_H
00076 #define _PASN_H
00077
00078 #ifdef P_USE_PRAGMA
00079 #pragma interface
00080 #endif
00081
00082 #include <ptlib/sockets.h>
00083
00084
00085
00086
00087 typedef PInt32 PASNInt;
00088 typedef DWORD PASNUnsigned;
00089 typedef DWORD PASNOid;
00090
00091 class PASNObject;
00092 class PASNSequence;
00093
00094 PLIST(PASNObjectList, PASNObject);
00095
00096
00098
00108 class PASNObject : public PObject
00109 {
00110 PCLASSINFO(PASNObject, PObject)
00111
00112 public:
00116 enum ASNType {
00117 Integer,
00118 String,
00119 ObjectID,
00120 Sequence,
00121 Choice,
00122 IPAddress,
00123 Counter,
00124 Gauge,
00125 TimeTicks,
00126 Opaque,
00127 NsapAddress,
00128 Counter64,
00129 UInteger32,
00130 Null,
00131 Unknown,
00132 ASNTypeMax
00133 };
00134
00138 virtual ASNType GetType() const;
00139
00140
00143 int GetChoice() const;
00144
00146 virtual PString GetTypeAsString() const;
00147
00153 virtual PASNInt GetInteger () const;
00154
00160 virtual PASNUnsigned GetUnsigned () const;
00161
00165 virtual PString GetString () const;
00166
00172 virtual const PASNSequence & GetSequence() const;
00173
00179 virtual PIPSocket::Address GetIPAddress () const;
00180
00184 virtual void PrintOn(
00185 ostream & strm
00186 ) const;
00187
00189 virtual void Encode(
00190 PBYTEArray & buffer
00191 );
00192
00196 virtual WORD GetEncodedLength();
00197
00199 virtual PObject * Clone() const;
00200
00202 static void EncodeASNLength (
00203 PBYTEArray & buffer,
00204 WORD length
00205 );
00206
00208 static WORD GetASNLengthLength (
00209 WORD length
00210 );
00211
00215 static BOOL DecodeASNLength (
00216 const PBYTEArray & buffer,
00217 PINDEX & ptr,
00218 WORD & len
00219 );
00220
00222 static void EncodeASNSequenceStart (
00223 PBYTEArray & buffer,
00224 BYTE type,
00225 WORD length
00226 );
00227
00229 static WORD GetASNSequenceStartLength (
00230 WORD length
00231 );
00232
00234 static void EncodeASNHeader(
00235 PBYTEArray & buffer,
00236 PASNObject::ASNType type,
00237 WORD length
00238 );
00239
00241 static WORD GetASNHeaderLength (
00242 WORD length
00243 );
00244
00245 static void EncodeASNInteger (
00246 PBYTEArray & buffer,
00247 PASNInt data,
00248 PASNObject::ASNType type
00249 );
00250
00251
00252 static void EncodeASNUnsigned (
00253 PBYTEArray & buffer,
00254 PASNUnsigned data,
00255 PASNObject::ASNType type
00256 );
00257
00258
00259 static WORD GetASNIntegerLength (
00260 PASNInt data
00261 );
00262
00263
00264 static WORD GetASNUnsignedLength (
00265 PASNUnsigned data
00266 );
00267
00268
00269 static BOOL DecodeASNInteger (
00270 const PBYTEArray & buffer,
00271 PINDEX & ptr,
00272 PASNInt & value,
00273 ASNType type = Integer
00274 );
00275
00276
00277 static BOOL DecodeASNUnsigned (
00278 const PBYTEArray & buffer,
00279 PINDEX & ptr,
00280 PASNUnsigned & value,
00281 ASNType type = TimeTicks
00282 );
00283
00284
00285 protected:
00287 PASNObject();
00288
00290 static BYTE ASNTypeToType[ASNTypeMax];
00291
00292 };
00293
00294
00296
00299 class PASNInteger : public PASNObject
00300 {
00301 PCLASSINFO(PASNInteger, PASNObject)
00302 public:
00303 PASNInteger(PASNInt val);
00304 PASNInteger(const PBYTEArray & buffer, PINDEX & ptr);
00305
00306 void PrintOn(ostream & strm) const;
00307 void Encode(PBYTEArray & buffer);
00308 WORD GetEncodedLength();
00309 PObject * Clone() const;
00310
00311 PASNInt GetInteger() const;
00312 PString GetString () const;
00313 ASNType GetType() const;
00314 PString GetTypeAsString() const;
00315
00316 private:
00317 PASNInt value;
00318 };
00319
00320
00322
00325 class PASNString : public PASNObject
00326 {
00327 PCLASSINFO(PASNString, PASNObject)
00328 public:
00329 PASNString(const PString & str);
00330 PASNString(const BYTE * ptr, int len);
00331 PASNString(const PBYTEArray & buffer, PASNObject::ASNType = String);
00332 PASNString(const PBYTEArray & buffer, PINDEX & ptr, PASNObject::ASNType = String);
00333
00334 void PrintOn(ostream & strm) const;
00335
00336 void Encode(PBYTEArray & buffer)
00337 { Encode(buffer, String); }
00338
00339 WORD GetEncodedLength();
00340 PObject * Clone() const;
00341
00342 PString GetString() const;
00343 ASNType GetType() const;
00344 PString GetTypeAsString() const;
00345
00346 protected:
00347 BOOL Decode(const PBYTEArray & buffer, PINDEX & i, PASNObject::ASNType type);
00348 void Encode(PBYTEArray & buffer, PASNObject::ASNType type);
00349
00350 PString value;
00351 WORD valueLen;
00352 };
00353
00354
00356
00359 class PASNIPAddress : public PASNString
00360 {
00361 PCLASSINFO(PASNIPAddress, PASNString)
00362 public:
00363 PASNIPAddress(const PIPSocket::Address & addr)
00364 : PASNString((const BYTE *)addr.GetPointer(), addr.GetSize()) { }
00365
00366 PASNIPAddress(const PString & str);
00367
00368 PASNIPAddress(const PBYTEArray & buffer)
00369 : PASNString(buffer, IPAddress) { }
00370
00371 PASNIPAddress(const PBYTEArray & buffer, PINDEX & ptr)
00372 : PASNString(buffer, ptr, IPAddress) { }
00373
00374 PASNObject::ASNType GetType() const
00375 { return IPAddress; }
00376
00377 void Encode(PBYTEArray & buffer)
00378 { PASNString::Encode(buffer, IPAddress); }
00379
00380 PString GetString() const;
00381
00382 PString GetTypeAsString() const;
00383
00384 PObject * Clone() const
00385 { return PNEW PASNIPAddress(*this); }
00386
00387 PIPSocket::Address GetIPAddress () const;
00388 };
00389
00390
00392
00395 class PASNUnsignedInteger : public PASNObject
00396 {
00397 PCLASSINFO(PASNUnsignedInteger, PASNObject)
00398 public:
00399 PASNUnsignedInteger(PASNUnsigned val)
00400 { value = val; }
00401
00402 PASNUnsignedInteger(const PBYTEArray & buffer, PINDEX & ptr);
00403
00404 void PrintOn(ostream & strm) const;
00405 WORD GetEncodedLength();
00406 PString GetString () const;
00407 PASNUnsigned GetUnsigned() const;
00408
00409 protected:
00410 PASNUnsignedInteger()
00411 { value = 0; }
00412
00413 BOOL Decode(const PBYTEArray & buffer, PINDEX & i, PASNObject::ASNType theType);
00414 void Encode(PBYTEArray & buffer, PASNObject::ASNType theType);
00415
00416 private:
00417 PASNUnsigned value;
00418 };
00419
00420
00422
00425 class PASNTimeTicks : public PASNUnsignedInteger
00426 {
00427 PCLASSINFO(PASNTimeTicks, PASNUnsignedInteger)
00428 public:
00429 PASNTimeTicks(PASNUnsigned val)
00430 : PASNUnsignedInteger(val) { }
00431
00432 PASNTimeTicks(const PBYTEArray & buffer, PINDEX & ptr)
00433 { PASNUnsignedInteger::Decode(buffer, ptr, TimeTicks); }
00434
00435 void Encode(PBYTEArray & buffer)
00436 { PASNUnsignedInteger::Encode(buffer, TimeTicks); }
00437
00438 PObject * Clone() const
00439 { return PNEW PASNTimeTicks(*this); }
00440
00441 PASNObject::ASNType GetType() const
00442 { return TimeTicks; }
00443
00444 PString GetTypeAsString() const;
00445 };
00446
00447
00449
00452 class PASNCounter : public PASNUnsignedInteger
00453 {
00454 PCLASSINFO(PASNCounter, PASNUnsignedInteger)
00455 public:
00456 PASNCounter(PASNUnsigned val)
00457 : PASNUnsignedInteger(val) { }
00458
00459 PASNCounter(const PBYTEArray & buffer, PINDEX & ptr)
00460 { PASNUnsignedInteger::Decode(buffer, ptr, Counter); }
00461
00462 void Encode(PBYTEArray & buffer)
00463 { PASNUnsignedInteger::Encode(buffer, Counter); }
00464
00465 PObject * Clone() const
00466 { return PNEW PASNCounter(*this); }
00467
00468 PASNObject::ASNType GetType() const
00469 { return Counter; }
00470
00471 PString GetTypeAsString() const;
00472 };
00473
00474
00476
00479 class PASNGauge : public PASNUnsignedInteger
00480 {
00481 PCLASSINFO(PASNGauge, PASNUnsignedInteger)
00482 public:
00483 PASNGauge(PASNUnsigned val)
00484 : PASNUnsignedInteger(val) { }
00485
00486 PASNGauge(const PBYTEArray & buffer, PINDEX & ptr)
00487 { Decode(buffer, ptr); }
00488
00489 BOOL Decode(const PBYTEArray & buffer, PINDEX & i)
00490 { return PASNUnsignedInteger::Decode(buffer, i, Gauge); }
00491
00492 void Encode(PBYTEArray & buffer)
00493 { PASNUnsignedInteger::Encode(buffer, Gauge); }
00494
00495 PObject * Clone() const
00496 { return PNEW PASNGauge(*this); }
00497
00498 PASNObject::ASNType GetType() const
00499 { return Gauge; }
00500
00501 PString GetTypeAsString() const;
00502 };
00503
00504
00505
00507
00510 class PASNObjectID : public PASNObject
00511 {
00512 PCLASSINFO(PASNObjectID, PASNObject)
00513 public:
00514 PASNObjectID(const PString & str);
00515 PASNObjectID(PASNOid * val, BYTE theLen);
00516 PASNObjectID(const PBYTEArray & buffer);
00517 PASNObjectID(const PBYTEArray & buffer, PINDEX & ptr);
00518
00519 void PrintOn(ostream & strm) const;
00520 void Encode(PBYTEArray & buffer);
00521 WORD GetEncodedLength();
00522 PObject * Clone() const;
00523
00524 ASNType GetType() const;
00525 PString GetString () const;
00526 PString GetTypeAsString() const;
00527
00528 protected:
00529 BOOL Decode(const PBYTEArray & buffer, PINDEX & i);
00530
00531 private:
00532 PDWORDArray value;
00533 };
00534
00535
00537
00540 class PASNNull : public PASNObject
00541 {
00542 PCLASSINFO(PASNNull, PASNObject)
00543 public:
00544 PASNNull();
00545 PASNNull(const PBYTEArray & buffer, PINDEX & ptr);
00546
00547 void PrintOn(ostream & strm) const;
00548
00549 void Encode(PBYTEArray & buffer);
00550 WORD GetEncodedLength();
00551
00552 PObject * Clone() const;
00553
00554 ASNType GetType() const;
00555 PString GetString () const;
00556 PString GetTypeAsString() const;
00557 };
00558
00559
00561
00564 class PASNSequence : public PASNObject
00565 {
00566 PCLASSINFO(PASNSequence, PASNObject)
00567 public:
00568 PASNSequence();
00569 PASNSequence(BYTE selector);
00570 PASNSequence(const PBYTEArray & buffer);
00571 PASNSequence(const PBYTEArray & buffer, PINDEX & i);
00572
00573 void Append(PASNObject * obj);
00574 PINDEX GetSize() const;
00575 PASNObject & operator [] (PINDEX idx) const;
00576 const PASNSequence & GetSequence() const;
00577
00578 void AppendInteger (PASNInt value);
00579 void AppendString (const PString & str);
00580 void AppendObjectID(const PString & str);
00581 void AppendObjectID(PASNOid * val, BYTE len);
00582
00583 int GetChoice() const;
00584
00585
00586
00587
00588 void PrintOn(ostream & strm) const;
00589 void Encode(PBYTEArray & buffer);
00590 BOOL Decode(const PBYTEArray & buffer, PINDEX & i);
00591 WORD GetEncodedLength();
00592 ASNType GetType() const;
00593 PString GetTypeAsString() const;
00594
00595 BOOL Encode(PBYTEArray & buffer, PINDEX maxLen) ;
00596
00597 private:
00598 PASNObjectList sequence;
00599 BYTE type;
00600 ASNType asnType;
00601 WORD encodedLen;
00602 WORD seqLen;
00603 };
00604
00605 #endif
00606
00607
00608
00609