1 // Copyright 2009 The Archiveopteryx Developers <info@aox.org> 2 3 #ifndef PGMESSAGE_H 4 #define PGMESSAGE_H 5 6 #include "database.h" 7 #include "estring.h" 8 #include "query.h" 9 #include "event.h" 10 #include "list.h" 11 12 class Buffer; 13 14 15 class PgServerMessage 16 : public Garbage 17 { 18 public: 19 PgServerMessage( Buffer *b ); ~PgServerMessage()20 virtual ~PgServerMessage() {} 21 22 enum Error { Syntax }; 23 24 protected: 25 Buffer * buf; 26 uint l, n; 27 char t; 28 29 char type() const; 30 uint size() const; 31 int16 decodeInt16(); 32 int decodeInt32(); 33 char decodeByte(); 34 EString decodeString(); 35 EString decodeByten( uint ); 36 void end(); 37 }; 38 39 40 class PgClientMessage 41 : public Garbage 42 { 43 public: 44 PgClientMessage( char t ); ~PgClientMessage()45 virtual ~PgClientMessage() {} 46 47 void enqueue( Buffer * ); 48 49 protected: 50 char type; 51 EString msg; 52 53 void appendInt16( int16 ); 54 void appendInt32( int ); 55 void appendByte( char ); 56 void appendByten( const EString & ); 57 void appendString( const EString & ); 58 59 virtual void encodeData() = 0; 60 }; 61 62 63 class PgStartup 64 : public PgClientMessage 65 { 66 public: PgStartup()67 PgStartup() : PgClientMessage( '\0' ) {} 68 void setOption( const EString &, const EString & ); 69 70 private: 71 EString options; 72 void encodeData(); 73 }; 74 75 76 class PgCancel 77 : public PgClientMessage 78 { 79 public: PgCancel(class PgKeyData * key)80 PgCancel( class PgKeyData * key ) 81 : PgClientMessage( '\0' ), k( key ) 82 {} 83 84 private: 85 class PgKeyData * k; 86 void encodeData(); 87 }; 88 89 90 class PgMessage 91 : public PgServerMessage 92 { 93 public: 94 PgMessage( Buffer * ); 95 96 enum Type { Notification, Error }; 97 type()98 Type type() const { return t; } severity()99 EString severity() const { return S; } code()100 EString code() const { return C; } message()101 EString message() const { return M; } detail()102 EString detail() const { return D; } hint()103 EString hint() const { return H; } position()104 EString position() const { return P; } where()105 EString where() const { return W; } file()106 EString file() const { return F; } line()107 EString line() const { return L; } routine()108 EString routine() const { return R; } 109 110 private: 111 Type t; 112 EString S, C, M, D, H, P, W, F, L, R; 113 }; 114 115 116 class PgAuthRequest 117 : public PgServerMessage 118 { 119 public: 120 PgAuthRequest( Buffer * ); 121 122 enum Type { 123 Success, 124 Kerberos4, Kerberos5, 125 Password, Crypt, MD5, 126 Credential 127 }; 128 type()129 Type type() const { return t; } salt()130 EString salt() const { return s; } 131 132 private: 133 Type t; 134 EString s; 135 }; 136 137 138 class PgPasswordMessage 139 : public PgClientMessage 140 { 141 public: 142 PgPasswordMessage( const EString & ); 143 144 private: 145 void encodeData(); 146 147 EString p; 148 }; 149 150 151 class PgParameterStatus 152 : public PgServerMessage 153 { 154 public: 155 PgParameterStatus( Buffer * ); 156 name()157 EString name() { return k; } value()158 EString value() { return v; } 159 160 private: 161 EString k, v; 162 }; 163 164 165 class PgKeyData 166 : public PgServerMessage 167 { 168 public: 169 PgKeyData( Buffer * ); 170 pid()171 uint pid() { return p; } key()172 uint key() { return k; } 173 174 private: 175 uint p, k; 176 }; 177 178 179 class PgParse 180 : public PgClientMessage 181 { 182 public: 183 PgParse( const EString &, const EString & = "" ); 184 void bindTypes( List< int > * ); 185 186 private: 187 void encodeData(); 188 189 EString name; 190 EString stmt; 191 List< int > *types; 192 }; 193 194 195 class PgParseComplete 196 : public PgServerMessage 197 { 198 public: 199 PgParseComplete( Buffer * ); 200 }; 201 202 203 class PgBind 204 : public PgClientMessage 205 { 206 public: 207 PgBind( const EString & = "", const EString & = "" ); 208 void bind( List< Query::Value > * ); 209 210 private: 211 void encodeData(); 212 213 EString stmt; 214 EString portal; 215 List< Query::Value > *values; 216 }; 217 218 219 class PgBindComplete 220 : public PgServerMessage 221 { 222 public: 223 PgBindComplete( Buffer * ); 224 }; 225 226 227 class PgDescribe 228 : public PgClientMessage 229 { 230 public: 231 PgDescribe( char = 'P', const EString & = "" ); 232 233 private: 234 void encodeData(); 235 236 char type; 237 EString name; 238 }; 239 240 241 class PgNoData 242 : public PgServerMessage 243 { 244 public: 245 PgNoData( Buffer * ); 246 }; 247 248 249 class PgParameterDescription 250 : public PgServerMessage 251 { 252 public: 253 PgParameterDescription( Buffer * ); 254 }; 255 256 257 class PgRowDescription 258 : public PgServerMessage 259 { 260 public: 261 PgRowDescription( Buffer * ); 262 263 class Column 264 : public Garbage 265 { 266 public: 267 EString name; 268 int table, column, type, size, mod, format, column2; 269 }; 270 271 List<Column> columns; 272 PatriciaTree<int> names; 273 uint count; 274 }; 275 276 277 class PgExecute 278 : public PgClientMessage 279 { 280 public: 281 PgExecute( const EString & = "", uint = 0 ); 282 283 private: 284 void encodeData(); 285 286 EString name; 287 uint rows; 288 }; 289 290 291 class PgDataRow 292 : public PgServerMessage 293 { 294 public: 295 PgDataRow( Buffer *, const PgRowDescription * ); 296 Row *row() const; 297 298 private: 299 Row *r; 300 }; 301 302 303 class PgEmptyQueryResponse 304 : public PgServerMessage 305 { 306 public: 307 PgEmptyQueryResponse( Buffer * ); 308 }; 309 310 311 class PgCommandComplete 312 : public PgServerMessage 313 { 314 public: 315 PgCommandComplete( Buffer * ); 316 tag()317 EString tag() { return t; } 318 319 private: 320 EString t; 321 }; 322 323 324 class PgSync 325 : public PgClientMessage 326 { 327 public: PgSync()328 PgSync() : PgClientMessage( 'S' ) {} 329 330 private: 331 void encodeData(); 332 }; 333 334 335 class PgFlush 336 : public PgClientMessage 337 { 338 public: PgFlush()339 PgFlush() : PgClientMessage( 'H' ) {} 340 341 private: 342 void encodeData(); 343 }; 344 345 346 class PgReady 347 : public PgServerMessage 348 { 349 public: 350 PgReady( Buffer * ); 351 352 Database::State state() const; 353 354 private: 355 Database::State s; 356 }; 357 358 359 class PgQuery 360 : public PgClientMessage 361 { 362 public: 363 PgQuery( const EString & ); 364 365 private: 366 void encodeData(); 367 368 EString stmt; 369 }; 370 371 372 class PgTerminate 373 : public PgClientMessage 374 { 375 public: PgTerminate()376 PgTerminate() : PgClientMessage( 'X' ) {} 377 378 private: 379 void encodeData(); 380 }; 381 382 383 class PgCopyInResponse 384 : public PgServerMessage 385 { 386 public: 387 PgCopyInResponse( Buffer * ); 388 389 private: 390 }; 391 392 393 class PgCopyData 394 : public PgClientMessage 395 { 396 public: 397 PgCopyData( const Query * ); 398 399 private: 400 void encodeData(); 401 void encodeText(); 402 void encodeBinary(); 403 const Query *query; 404 }; 405 406 407 class PgCopyDone 408 : public PgClientMessage 409 { 410 public: PgCopyDone()411 PgCopyDone() : PgClientMessage( 'c' ) {} 412 413 private: 414 void encodeData(); 415 }; 416 417 418 class PgCopyFail 419 : public PgClientMessage 420 { 421 public: PgCopyFail()422 PgCopyFail() : PgClientMessage( 'f' ) {} 423 424 private: 425 void encodeData(); 426 }; 427 428 429 class PgNotificationResponse 430 : public PgServerMessage 431 { 432 public: 433 PgNotificationResponse( Buffer * ); 434 435 EString name() const; 436 EString source() const; 437 uint pid() const; 438 439 private: 440 EString n, s; 441 uint p; 442 }; 443 444 445 class CitextLookup 446 : public EventHandler { 447 public: 448 CitextLookup(); 449 450 static bool necessary(); 451 452 void execute(); 453 454 Query * q; 455 }; 456 457 458 #endif 459