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 #ifndef _PASN_H
00070 #define _PASN_H
00071
00072 #ifdef P_USE_PRAGMA
00073 #pragma interface
00074 #endif
00075
00076 #include <ptlib/sockets.h>
00077
00078
00079
00080
00081 typedef PInt32 PASNInt;
00082 typedef DWORD PASNUnsigned;
00083 typedef DWORD PASNOid;
00084
00085 class PASNObject;
00086 class PASNSequence;
00087
00088 PLIST(PASNObjectList, PASNObject);
00089
00090
00092
00102 class PASNObject : public PObject
00103 {
00104 PCLASSINFO(PASNObject, PObject)
00105
00106 public:
00110 enum ASNType {
00111 Integer,
00112 String,
00113 ObjectID,
00114 Sequence,
00115 Choice,
00116 IPAddress,
00117 Counter,
00118 Gauge,
00119 TimeTicks,
00120 Opaque,
00121 NsapAddress,
00122 Counter64,
00123 UInteger32,
00124 Null,
00125 Unknown,
00126 ASNTypeMax
00127 };
00128
00132 virtual ASNType GetType() const;
00133
00134
00137 int GetChoice() const;
00138
00140 virtual PString GetTypeAsString() const;
00141
00147 virtual PASNInt GetInteger () const;
00148
00154 virtual PASNUnsigned GetUnsigned () const;
00155
00159 virtual PString GetString () const;
00160
00166 virtual const PASNSequence & GetSequence() const;
00167
00173 virtual PIPSocket::Address GetIPAddress () const;
00174
00178 virtual void PrintOn(
00179 ostream & strm
00180 ) const;
00181
00183 virtual void Encode(
00184 PBYTEArray & buffer
00185 );
00186
00190 virtual WORD GetEncodedLength();
00191
00193 virtual PObject * Clone() const;
00194
00196 static void EncodeASNLength (
00197 PBYTEArray & buffer,
00198 WORD length
00199 );
00200
00202 static WORD GetASNLengthLength (
00203 WORD length
00204 );
00205
00209 static BOOL DecodeASNLength (
00210 const PBYTEArray & buffer,
00211 PINDEX & ptr,
00212 WORD & len
00213 );
00214
00216 static void EncodeASNSequenceStart (
00217 PBYTEArray & buffer,
00218 BYTE type,
00219 WORD length
00220 );
00221
00223 static WORD GetASNSequenceStartLength (
00224 WORD length
00225 );
00226
00228 static void EncodeASNHeader(
00229 PBYTEArray & buffer,
00230 PASNObject::ASNType type,
00231 WORD length
00232 );
00233
00235 static WORD GetASNHeaderLength (
00236 WORD length
00237 );
00238
00239 static void EncodeASNInteger (
00240 PBYTEArray & buffer,
00241 PASNInt data,
00242 PASNObject::ASNType type
00243 );
00244
00245
00246 static void EncodeASNUnsigned (
00247 PBYTEArray & buffer,
00248 PASNUnsigned data,
00249 PASNObject::ASNType type
00250 );
00251
00252
00253 static WORD GetASNIntegerLength (
00254 PASNInt data
00255 );
00256
00257
00258 static WORD GetASNUnsignedLength (
00259 PASNUnsigned data
00260 );
00261
00262
00263 static BOOL DecodeASNInteger (
00264 const PBYTEArray & buffer,
00265 PINDEX & ptr,
00266 PASNInt & value,
00267 ASNType type = Integer
00268 );
00269
00270
00271 static BOOL DecodeASNUnsigned (
00272 const PBYTEArray & buffer,
00273 PINDEX & ptr,
00274 PASNUnsigned & value,
00275 ASNType type = TimeTicks
00276 );
00277
00278
00279 protected:
00281 PASNObject();
00282
00284 static BYTE ASNTypeToType[ASNTypeMax];
00285
00286 };
00287
00288
00290
00293 class PASNInteger : public PASNObject
00294 {
00295 PCLASSINFO(PASNInteger, PASNObject)
00296 public:
00297 PASNInteger(PASNInt val);
00298 PASNInteger(const PBYTEArray & buffer, PINDEX & ptr);
00299
00300 void PrintOn(ostream & strm) const;
00301 void Encode(PBYTEArray & buffer);
00302 WORD GetEncodedLength();
00303 PObject * Clone() const;
00304
00305 PASNInt GetInteger() const;
00306 PString GetString () const;
00307 ASNType GetType() const;
00308 PString GetTypeAsString() const;
00309
00310 private:
00311 PASNInt value;
00312 };
00313
00314
00316
00319 class PASNString : public PASNObject
00320 {
00321 PCLASSINFO(PASNString, PASNObject)
00322 public:
00323 PASNString(const PString & str);
00324 PASNString(const BYTE * ptr, int len);
00325 PASNString(const PBYTEArray & buffer, PASNObject::ASNType = String);
00326 PASNString(const PBYTEArray & buffer, PINDEX & ptr, PASNObject::ASNType = String);
00327
00328 void PrintOn(ostream & strm) const;
00329
00330 void Encode(PBYTEArray & buffer)
00331 { Encode(buffer, String); }
00332
00333 WORD GetEncodedLength();
00334 PObject * Clone() const;
00335
00336 PString GetString() const;
00337 ASNType GetType() const;
00338 PString GetTypeAsString() const;
00339
00340 protected:
00341 BOOL Decode(const PBYTEArray & buffer, PINDEX & i, PASNObject::ASNType type);
00342 void Encode(PBYTEArray & buffer, PASNObject::ASNType type);
00343
00344 PString value;
00345 WORD valueLen;
00346 };
00347
00348
00350
00353 class PASNIPAddress : public PASNString
00354 {
00355 PCLASSINFO(PASNIPAddress, PASNString)
00356 public:
00357 PASNIPAddress(const PIPSocket::Address & addr)
00358 : PASNString(PString((const char *)&addr, 4)) { }
00359
00360 PASNIPAddress(const PString & str);
00361
00362 PASNIPAddress(const PBYTEArray & buffer)
00363 : PASNString(buffer, IPAddress) { }
00364
00365 PASNIPAddress(const PBYTEArray & buffer, PINDEX & ptr)
00366 : PASNString(buffer, ptr, IPAddress) { }
00367
00368 PASNObject::ASNType GetType() const
00369 { return IPAddress; }
00370
00371 void Encode(PBYTEArray & buffer)
00372 { PASNString::Encode(buffer, IPAddress); }
00373
00374 PString GetString() const;
00375
00376 PString GetTypeAsString() const;
00377
00378 PObject * Clone() const
00379 { return PNEW PASNIPAddress(*this); }
00380
00381 PIPSocket::Address GetIPAddress () const;
00382 };
00383
00384
00386
00389 class PASNUnsignedInteger : public PASNObject
00390 {
00391 PCLASSINFO(PASNUnsignedInteger, PASNObject)
00392 public:
00393 PASNUnsignedInteger(PASNUnsigned val)
00394 { value = val; }
00395
00396 PASNUnsignedInteger(const PBYTEArray & buffer, PINDEX & ptr);
00397
00398 void PrintOn(ostream & strm) const;
00399 WORD GetEncodedLength();
00400 PString GetString () const;
00401 PASNUnsigned GetUnsigned() const;
00402
00403 protected:
00404 PASNUnsignedInteger()
00405 { value = 0; }
00406
00407 BOOL Decode(const PBYTEArray & buffer, PINDEX & i, PASNObject::ASNType theType);
00408 void Encode(PBYTEArray & buffer, PASNObject::ASNType theType);
00409
00410 private:
00411 PASNUnsigned value;
00412 };
00413
00414
00416
00419 class PASNTimeTicks : public PASNUnsignedInteger
00420 {
00421 PCLASSINFO(PASNTimeTicks, PASNUnsignedInteger)
00422 public:
00423 PASNTimeTicks(PASNUnsigned val)
00424 : PASNUnsignedInteger(val) { }
00425
00426 PASNTimeTicks(const PBYTEArray & buffer, PINDEX & ptr)
00427 { PASNUnsignedInteger::Decode(buffer, ptr, TimeTicks); }
00428
00429 void Encode(PBYTEArray & buffer)
00430 { PASNUnsignedInteger::Encode(buffer, TimeTicks); }
00431
00432 PObject * Clone() const
00433 { return PNEW PASNTimeTicks(*this); }
00434
00435 PASNObject::ASNType GetType() const
00436 { return TimeTicks; }
00437
00438 PString GetTypeAsString() const;
00439 };
00440
00441
00443
00446 class PASNCounter : public PASNUnsignedInteger
00447 {
00448 PCLASSINFO(PASNCounter, PASNUnsignedInteger)
00449 public:
00450 PASNCounter(PASNUnsigned val)
00451 : PASNUnsignedInteger(val) { }
00452
00453 PASNCounter(const PBYTEArray & buffer, PINDEX & ptr)
00454 { PASNUnsignedInteger::Decode(buffer, ptr, Counter); }
00455
00456 void Encode(PBYTEArray & buffer)
00457 { PASNUnsignedInteger::Encode(buffer, Counter); }
00458
00459 PObject * Clone() const
00460 { return PNEW PASNCounter(*this); }
00461
00462 PASNObject::ASNType GetType() const
00463 { return Counter; }
00464
00465 PString GetTypeAsString() const;
00466 };
00467
00468
00470
00473 class PASNGauge : public PASNUnsignedInteger
00474 {
00475 PCLASSINFO(PASNGauge, PASNUnsignedInteger)
00476 public:
00477 PASNGauge(PASNUnsigned val)
00478 : PASNUnsignedInteger(val) { }
00479
00480 PASNGauge(const PBYTEArray & buffer, PINDEX & ptr)
00481 { Decode(buffer, ptr); }
00482
00483 BOOL Decode(const PBYTEArray & buffer, PINDEX & i)
00484 { return PASNUnsignedInteger::Decode(buffer, i, Gauge); }
00485
00486 void Encode(PBYTEArray & buffer)
00487 { PASNUnsignedInteger::Encode(buffer, Gauge); }
00488
00489 PObject * Clone() const
00490 { return PNEW PASNGauge(*this); }
00491
00492 PASNObject::ASNType GetType() const
00493 { return Gauge; }
00494
00495 PString GetTypeAsString() const;
00496 };
00497
00498
00499
00501
00504 class PASNObjectID : public PASNObject
00505 {
00506 PCLASSINFO(PASNObjectID, PASNObject)
00507 public:
00508 PASNObjectID(const PString & str);
00509 PASNObjectID(PASNOid * val, BYTE theLen);
00510 PASNObjectID(const PBYTEArray & buffer);
00511 PASNObjectID(const PBYTEArray & buffer, PINDEX & ptr);
00512
00513 void PrintOn(ostream & strm) const;
00514 void Encode(PBYTEArray & buffer);
00515 WORD GetEncodedLength();
00516 PObject * Clone() const;
00517
00518 ASNType GetType() const;
00519 PString GetString () const;
00520 PString GetTypeAsString() const;
00521
00522 protected:
00523 BOOL Decode(const PBYTEArray & buffer, PINDEX & i);
00524
00525 private:
00526 PDWORDArray value;
00527 };
00528
00529
00531
00534 class PASNNull : public PASNObject
00535 {
00536 PCLASSINFO(PASNNull, PASNObject)
00537 public:
00538 PASNNull();
00539 PASNNull(const PBYTEArray & buffer, PINDEX & ptr);
00540
00541 void PrintOn(ostream & strm) const;
00542
00543 void Encode(PBYTEArray & buffer);
00544 WORD GetEncodedLength();
00545
00546 PObject * Clone() const;
00547
00548 ASNType GetType() const;
00549 PString GetString () const;
00550 PString GetTypeAsString() const;
00551 };
00552
00553
00555
00558 class PASNSequence : public PASNObject
00559 {
00560 PCLASSINFO(PASNSequence, PASNObject)
00561 public:
00562 PASNSequence();
00563 PASNSequence(BYTE selector);
00564 PASNSequence(const PBYTEArray & buffer);
00565 PASNSequence(const PBYTEArray & buffer, PINDEX & i);
00566
00567 void Append(PASNObject * obj);
00568 PINDEX GetSize() const;
00569 PASNObject & operator [] (PINDEX idx) const;
00570 const PASNSequence & GetSequence() const;
00571
00572 void AppendInteger (PASNInt value);
00573 void AppendString (const PString & str);
00574 void AppendObjectID(const PString & str);
00575 void AppendObjectID(PASNOid * val, BYTE len);
00576
00577 int GetChoice() const;
00578
00579
00580
00581
00582 void PrintOn(ostream & strm) const;
00583 void Encode(PBYTEArray & buffer);
00584 BOOL Decode(const PBYTEArray & buffer, PINDEX & i);
00585 WORD GetEncodedLength();
00586 ASNType GetType() const;
00587 PString GetTypeAsString() const;
00588
00589 BOOL Encode(PBYTEArray & buffer, PINDEX maxLen) ;
00590
00591 private:
00592 PASNObjectList sequence;
00593 BYTE type;
00594 ASNType asnType;
00595 WORD encodedLen;
00596 WORD seqLen;
00597 };
00598
00599 #endif
00600
00601
00602
00603