1 21 22 package org.apache.derby.impl.drda; 23 24 import java.io.BufferedReader ; 25 import java.io.FileInputStream ; 26 import java.io.FileNotFoundException ; 27 import java.io.IOException ; 28 import java.io.InputStream ; 29 import java.io.InputStreamReader ; 30 import java.io.OutputStream ; 31 import java.io.StreamTokenizer ; 32 import java.io.UnsupportedEncodingException ; 33 import java.net.Socket ; 34 import java.net.UnknownHostException ; 35 import java.util.Enumeration ; 36 import java.util.Hashtable ; 37 import java.util.Locale ; 38 import java.util.Vector ; 39 40 49 50 public class TestProto { 51 52 private static final CodePointNameTable codePointNameTable = new CodePointNameTable(); 53 private static final Hashtable codePointValueTable = new Hashtable (); 54 private static final Hashtable commandTable = new Hashtable (); 55 private static final CcsidManager ccsidManager = new EbcdicCcsidManager(); 56 private static final int CREATE_DSS_REQUEST = 1; 58 private static final int CREATE_DSS_OBJECT = 2; 59 private static final int END_DSS = 3; 60 private static final int END_DDM_AND_DSS = 4; 61 private static final int START_DDM = 5; 62 private static final int END_DDM = 6; 63 private static final int WRITE_BYTE = 7; 64 private static final int WRITE_NETWORK_SHORT = 8; 65 private static final int WRITE_NETWORK_INT = 9; 66 private static final int WRITE_BYTES = 10; 67 private static final int WRITE_CODEPOINT_4BYTES = 11; 68 private static final int WRITE_SCALAR_1BYTE = 12; 69 private static final int WRITE_SCALAR_2BYTES = 13; 70 private static final int WRITE_SCALAR_BYTES = 14; 71 private static final int WRITE_SCALAR_HEADER = 15; 72 private static final int WRITE_SCALAR_STRING = 16; 73 private static final int WRITE_SCALAR_PADDED_STRING = 17; 74 private static final int WRITE_SCALAR_PADDED_BYTES = 18; 75 private static final int WRITE_SHORT = 19; 76 private static final int WRITE_INT = 20; 77 private static final int WRITE_LONG = 21; 78 private static final int WRITE_FLOAT = 22; 79 private static final int WRITE_DOUBLE = 23; 80 private static final int READ_REPLY_DSS = 24; 81 private static final int READ_LENGTH_AND_CODEPOINT = 25; 82 private static final int READ_CODEPOINT = 26; 83 private static final int MARK_COLLECTION = 27; 84 private static final int GET_CODEPOINT = 28; 85 private static final int READ_BYTE = 29; 86 private static final int READ_NETWORK_SHORT = 30; 87 private static final int READ_SHORT = 31; 88 private static final int READ_NETWORK_INT = 32; 89 private static final int READ_INT = 33; 90 private static final int READ_LONG = 34; 91 private static final int READ_BOOLEAN = 35; 92 private static final int READ_STRING = 36; 93 private static final int READ_BYTES = 37; 94 private static final int FLUSH = 38; 95 private static final int DISPLAY = 39; 96 private static final int CHECKERROR = 40; 97 private static final int RESET = 41; 98 private static final int CREATE_DSS_REPLY = 42; 99 private static final int SKIP_DSS = 43; 100 private static final int READ_SCALAR_2BYTES = 44; 101 private static final int READ_SCALAR_1BYTE = 45; 102 private static final int END_TEST = 46; 103 private static final int SKIP_DDM = 47; 104 private static final int INCLUDE = 48; 105 private static final int SKIP_BYTES = 49; 106 private static final int WRITE_PADDED_STRING = 50; 107 private static final int WRITE_STRING = 51; 108 private static final int WRITE_ENCODED_STRING = 52; 109 private static final int WRITE_ENCODED_LDSTRING = 53; 110 private static final int CHECK_SQLCARD = 54; 111 private static final int MORE_DATA = 55; 112 private static final int COMPLETE_TEST = 56; 113 private static final int READ_SECMEC_SECCHKCD = 57; 114 115 private static final String MULTIVAL_START = "MULTIVALSTART"; 116 private static final String MULTIVAL_SEP = "SEP"; 117 private static final String MULTIVAL_END = "MULTIVALEND"; 118 static { 120 init(); 121 } 122 123 124 private Socket monitorSocket = null; 125 private InputStream monitorIs = null; 126 private OutputStream monitorOs = null; 127 private DDMWriter writer = new DDMWriter(ccsidManager, null, null); 128 private DDMReader reader; 129 private boolean failed = false; 130 private StreamTokenizer tkn; 131 private String current_filename; 132 133 public TestProto(String filename) 135 { 136 current_filename = filename; 137 getConnection(); 138 139 try 140 { 141 reader = new DDMReader(ccsidManager, monitorIs); 142 processFile(filename); 143 } 144 catch (Exception e) 145 { 146 int line = 0; 147 if (tkn != null) 148 line = tkn.lineno(); 149 System.err.println("Unexpected exception in line " + line + " file: " + current_filename); 150 e.printStackTrace(); 151 } 152 finally 153 { 154 closeConnection(); 155 } 156 157 } 158 163 private void processIncludeFile() 164 throws IOException , DRDAProtocolException 165 { 166 String fileName = getString(); 167 StreamTokenizer saveTkn = tkn; 168 processFile(fileName); 169 tkn = saveTkn; 170 } 171 177 private void processFile(String filename) 178 throws IOException , DRDAProtocolException 179 { 180 String prev_filename = current_filename; 181 current_filename = filename; 182 String hostName=getHostName(); 183 BufferedReader fr; 184 try 185 { 186 fr = new BufferedReader (new InputStreamReader (new FileInputStream (filename),"UTF-8")); 187 } catch (FileNotFoundException fnfe) { 188 String userdir = System.getProperty("user.dir"); 191 String sep = System.getProperty("file.separator"); 192 fr = new BufferedReader (new InputStreamReader (new FileInputStream (userdir + sep + ".." + sep + filename),"UTF-8")); 193 } 194 tkn = new StreamTokenizer (fr); 195 int val; 196 while ( (val = tkn.nextToken()) != StreamTokenizer.TT_EOF) 197 { 198 switch(val) 199 { 200 case StreamTokenizer.TT_NUMBER: 201 break; 202 case StreamTokenizer.TT_WORD: 203 processCommand(); 204 break; 205 case StreamTokenizer.TT_EOL: 206 break; 207 } 208 } 209 current_filename = prev_filename; 210 } 211 214 private void getConnection() 215 { 216 String hostName=getHostName(); 217 try { 218 monitorSocket = new Socket (hostName,1527); 219 } catch (UnknownHostException e) { 220 System.err.println("Don't know about host: " + hostName); 221 System.exit(1); 222 } catch (IOException e) { 223 System.err.println("Couldn't get I/O for the connection to: " + hostName); 224 System.exit(1); 225 } 226 try 227 { 228 monitorIs = monitorSocket.getInputStream(); 229 monitorOs = monitorSocket.getOutputStream(); 230 } 231 catch (IOException e) 232 { 233 System.err.println("Couldn't get I/O for the connection to: " + hostName); 234 System.exit(1); 235 } 236 } 237 240 private void closeConnection() 241 { 242 try { 243 monitorIs.close(); 244 monitorOs.close(); 245 monitorSocket.close(); 246 } 247 catch (Exception e) {} } 249 252 private void reset() 253 { 254 closeConnection(); 255 getConnection(); 256 reader.initialize(monitorIs); 257 writer.reset(null); 258 } 259 262 private void completeTest() 263 { 264 closeConnection(); 265 } 266 270 private static void init() 271 { 272 commandTable.put("createdssrequest", new Integer (CREATE_DSS_REQUEST)); 273 commandTable.put("createdssobject", new Integer (CREATE_DSS_OBJECT)); 274 commandTable.put("createdssreply", new Integer (CREATE_DSS_REPLY)); 275 commandTable.put("enddss", new Integer (END_DSS)); 276 commandTable.put("enddss", new Integer (END_DSS)); 277 commandTable.put("endddmanddss", new Integer (END_DDM_AND_DSS)); 278 commandTable.put("startddm", new Integer (START_DDM)); 279 commandTable.put("endddm", new Integer (END_DDM)); 280 commandTable.put("writebyte", new Integer (WRITE_BYTE)); 281 commandTable.put("writenetworkshort", new Integer (WRITE_NETWORK_SHORT)); 282 commandTable.put("writenetworkint", new Integer (WRITE_NETWORK_INT)); 283 commandTable.put("writebytes", new Integer (WRITE_BYTES)); 284 commandTable.put("writecodepoint4bytes", new Integer (WRITE_CODEPOINT_4BYTES)); 285 commandTable.put("writescalar1byte", new Integer (WRITE_SCALAR_1BYTE)); 286 commandTable.put("writescalar2bytes", new Integer (WRITE_SCALAR_2BYTES)); 287 commandTable.put("writescalarbytes", new Integer (WRITE_SCALAR_BYTES)); 288 commandTable.put("writescalarheader", new Integer (WRITE_SCALAR_HEADER)); 289 commandTable.put("writescalarstring", new Integer (WRITE_SCALAR_STRING)); 290 commandTable.put("writescalarpaddedstring", new Integer (WRITE_SCALAR_PADDED_STRING)); 291 commandTable.put("writescalarpaddedbytes", new Integer (WRITE_SCALAR_PADDED_BYTES)); 292 commandTable.put("writeshort", new Integer (WRITE_SHORT)); 293 commandTable.put("writeint", new Integer (WRITE_INT)); 294 commandTable.put("writelong", new Integer (WRITE_LONG)); 295 commandTable.put("writefloat", new Integer (WRITE_FLOAT)); 296 commandTable.put("writedouble", new Integer (WRITE_DOUBLE)); 297 commandTable.put("readreplydss", new Integer (READ_REPLY_DSS)); 298 commandTable.put("readlengthandcodepoint", new Integer (READ_LENGTH_AND_CODEPOINT)); 299 commandTable.put("readcodepoint", new Integer (READ_CODEPOINT)); 300 commandTable.put("markcollection", new Integer (MARK_COLLECTION)); 301 commandTable.put("getcodepoint", new Integer (GET_CODEPOINT)); 302 commandTable.put("readbyte", new Integer (READ_BYTE)); 303 commandTable.put("readnetworkshort", new Integer (READ_NETWORK_SHORT)); 304 commandTable.put("readshort", new Integer (READ_SHORT)); 305 commandTable.put("readint", new Integer (READ_INT)); 306 commandTable.put("readlong", new Integer (READ_LONG)); 307 commandTable.put("readboolean", new Integer (READ_BOOLEAN)); 308 commandTable.put("readstring", new Integer (READ_STRING)); 309 commandTable.put("readbytes", new Integer (READ_BYTES)); 310 commandTable.put("flush", new Integer (FLUSH)); 311 commandTable.put("display", new Integer (DISPLAY)); 312 commandTable.put("checkerror", new Integer (CHECKERROR)); 313 commandTable.put("reset", new Integer (RESET)); 314 commandTable.put("skipdss", new Integer (SKIP_DSS)); 315 commandTable.put("skipddm", new Integer (SKIP_DDM)); 316 commandTable.put("readscalar2bytes", new Integer (READ_SCALAR_2BYTES)); 317 commandTable.put("readscalar1byte", new Integer (READ_SCALAR_1BYTE)); 318 commandTable.put("endtest", new Integer (END_TEST)); 319 commandTable.put("include", new Integer (INCLUDE)); 320 commandTable.put("skipbytes", new Integer (SKIP_BYTES)); 321 commandTable.put("writepaddedstring", new Integer (WRITE_PADDED_STRING)); 322 commandTable.put("writestring", new Integer (WRITE_STRING)); 323 commandTable.put("writeencodedstring", new Integer (WRITE_ENCODED_STRING)); 324 commandTable.put("writeencodedldstring", new Integer (WRITE_ENCODED_LDSTRING)); 325 commandTable.put("checksqlcard", new Integer (CHECK_SQLCARD)); 326 commandTable.put("moredata", new Integer (MORE_DATA)); 327 commandTable.put("completetest", new Integer (COMPLETE_TEST)); 328 commandTable.put("readsecmecandsecchkcd", new Integer (READ_SECMEC_SECCHKCD)); 329 330 Integer key; 331 for (Enumeration e = codePointNameTable.keys(); e.hasMoreElements(); ) 332 { 333 key = (Integer )e.nextElement(); 334 codePointValueTable.put(codePointNameTable.get(key), key); 335 } 336 337 } 338 341 private void processCommand() 342 throws IOException , DRDAProtocolException 343 { 344 Integer icmd = (Integer )commandTable.get(tkn.sval.toLowerCase(Locale.ENGLISH)); 345 if (icmd == null) 346 { 347 System.err.println("Unknown command, " + tkn.sval + " in line " + 348 tkn.lineno()); 349 System.exit(1); 350 } 351 int cmd = icmd.intValue(); 352 int codepoint; 353 int val; 354 int reqVal; 355 String str; 356 357 switch (cmd) 358 { 359 case INCLUDE: 360 processIncludeFile(); 361 break; 362 case CREATE_DSS_REQUEST: 363 writer.createDssRequest(); 364 break; 365 case CREATE_DSS_OBJECT: 366 writer.createDssObject(); 367 break; 368 case CREATE_DSS_REPLY: 369 writer.createDssReply(); 370 break; 371 case END_DSS: 372 tkn.nextToken(); 373 tkn.pushBack(); 374 if ((tkn.sval != null) && tkn.sval.startsWith("0x")) 375 writer.endDss((getBytes())[0]); 377 else 378 writer.endDss(); 380 break; 381 case END_DDM: 382 writer.endDdm(); 383 break; 384 case END_DDM_AND_DSS: 385 writer.endDdmAndDss(); 386 break; 387 case START_DDM: 388 writer.startDdm(getCP()); 389 break; 390 case WRITE_SCALAR_STRING: 391 writer.writeScalarString(getCP(), getString()); 392 break; 393 case WRITE_SCALAR_2BYTES: 394 writer.writeScalar2Bytes(getCP(),getIntOrCP()); 395 break; 396 case WRITE_SCALAR_1BYTE: 397 writer.writeScalar1Byte(getCP(),getInt()); 398 break; 399 case WRITE_SCALAR_BYTES: 400 writer.writeScalarBytes(getCP(),getBytes()); 401 break; 402 case WRITE_SCALAR_PADDED_BYTES: 403 writer.writeScalarPaddedBytes(getCP(), getBytes(), getInt(), 404 ccsidManager.space); 405 break; 406 case WRITE_BYTE: 407 writer.writeByte(getInt()); 408 break; 409 case WRITE_BYTES: 410 writer.writeBytes(getBytes()); 411 break; 412 case WRITE_SHORT: 413 writer.writeShort(getInt()); 414 break; 415 case WRITE_INT: 416 writer.writeInt(getInt()); 417 break; 418 case WRITE_CODEPOINT_4BYTES: 419 writer.writeCodePoint4Bytes(getCP(), getInt()); 420 break; 421 case WRITE_STRING: 422 str = getString(); 423 writer.writeBytes(getEBCDIC(str)); 424 break; 425 case WRITE_ENCODED_STRING: 426 writeEncodedString(getString(), getString()); 427 break; 428 case WRITE_ENCODED_LDSTRING: 429 writeEncodedLDString(getString(), getString(), getInt()); 430 break; 431 case WRITE_PADDED_STRING: 432 str = getString(); 433 writer.writeBytes(getEBCDIC(str)); 434 int reqLen = getInt(); 435 int strLen = str.length(); 436 if (strLen < reqLen) 437 writer.padBytes(ccsidManager.space, reqLen-strLen); 438 break; 439 case READ_REPLY_DSS: 440 reader.readReplyDss(); 441 break; 442 case SKIP_DSS: 443 skipDss(); 444 break; 445 case SKIP_DDM: 446 skipDdm(); 447 break; 448 case MORE_DATA: 449 boolean expbool; 450 str = getString(); 451 if (str.equalsIgnoreCase("true")) 452 expbool = true; 453 else 454 expbool = false; 455 if (reader.moreData() && expbool == false ) 456 fail("Failed - more data left"); 457 if (!reader.moreData() && expbool == true ) 458 fail("Failed - no data left"); 459 break; 460 case READ_LENGTH_AND_CODEPOINT: 461 readLengthAndCodePoint(); 462 break; 463 case READ_SCALAR_2BYTES: 464 readLengthAndCodePoint(); 465 val = reader.readNetworkShort(); 466 checkIntOrCP(val); 467 break; 468 case READ_SCALAR_1BYTE: 469 readLengthAndCodePoint(); 470 val = reader.readByte(); 471 checkIntOrCP(val); 472 break; 473 case READ_SECMEC_SECCHKCD: 474 readSecMecAndSECCHKCD(); 475 break; 476 case READ_BYTES: 477 byte[] byteArray = reader.readBytes(); 478 byte[] reqArray = getBytes(); 479 if (byteArray.length != reqArray.length) 480 fail("Failed - byte array didn't match"); 481 for (int i = 0; i < byteArray.length; i++) 482 if (byteArray[i] != reqArray[i]) 483 fail("Failed - byte array didn't match"); 484 break; 485 case READ_NETWORK_SHORT: 486 val = reader.readNetworkShort(); 487 checkIntOrCP(val); 488 break; 489 case FLUSH: 490 writer.finalizeChain(reader.getCurrChainState(), monitorOs); 491 writer.reset(null); 492 break; 493 case DISPLAY: 494 System.out.println(getString()); 495 break; 496 case CHECKERROR: 497 checkError(); 498 break; 499 case CHECK_SQLCARD: 500 checkSQLCARD(getInt(), getString()); 501 break; 502 case COMPLETE_TEST: 503 completeTest(); 504 break; 505 case END_TEST: 506 if (failed == false) 508 System.out.println("PASSED"); 509 failed = false; 510 reset(); 511 break; 512 case RESET: 513 reset(); 514 break; 515 case SKIP_BYTES: 516 reader.skipBytes(); 517 break; 518 default: 519 System.out.println("unknown command in line " + tkn.lineno()); 520 while (tkn.nextToken() != StreamTokenizer.TT_EOL) 522 ; 523 524 } 525 } 526 529 private void skipDss() throws DRDAProtocolException 530 { 531 reader.readReplyDss(); 532 reader.skipDss(); 533 } 534 537 private void skipDdm() throws DRDAProtocolException 538 { 539 reader.readLengthAndCodePoint(); 540 reader.skipBytes(); 541 } 542 546 private int getInt() throws IOException 547 { 548 int mult = 1; 549 int val = tkn.nextToken(); 550 if (tkn.sval != null && tkn.sval.equals("-")) 551 { 552 mult = -1; 553 val = tkn.nextToken(); 554 } 555 556 if (val != StreamTokenizer.TT_NUMBER) 557 { 558 if (tkn.sval == null) 559 { 560 System.err.println("Invalid string on line " + tkn.lineno()); 561 System.exit(1); 562 } 563 String str = tkn.sval.toLowerCase(Locale.ENGLISH); 564 if (!str.startsWith("0x")) 565 { 566 System.err.println("Expecting number, got " + tkn.sval + " on line " + tkn.lineno()); 567 System.exit(1); 568 } 569 else 570 return convertHex(str); 571 } 572 return (new Double (tkn.nval).intValue() * mult); 573 } 574 577 private int convertHex(String str) throws IOException 578 { 579 int retval = 0; 580 int len = str.length(); 581 if ((len % 2) == 1 || len > 10) 582 { 583 System.err.println("Invalid length for byte string, " + len + 584 " on line " + tkn.lineno()); 585 System.exit(1); 586 } 587 for (int i = 2; i < len; i++) 588 { 589 retval = retval << 4; 590 retval += Byte.valueOf(str.substring(i, i+1), 16).byteValue(); 591 } 592 return retval; 593 } 594 595 601 private boolean checkIntOrCP(int val) throws IOException 602 { 603 boolean rval = false; 604 int tknType = tkn.nextToken(); 605 String reqVal = " "; 606 607 608 if (tknType == StreamTokenizer.TT_WORD && tkn.sval.trim().equals(MULTIVAL_START)) 609 { 610 do { 611 int nextVal = getIntOrCP(); 612 reqVal = reqVal + nextVal + " "; 613 rval = rval || (val == nextVal); 615 tkn.nextToken(); 616 } 617 while(tkn.sval.trim().equals(MULTIVAL_SEP)); 618 619 if (! (tkn.sval.trim().equals(MULTIVAL_END))) 620 fail("Invalid test file format requires " + MULTIVAL_END + 621 " got: " + tkn.sval); 622 623 } 624 else 625 { 626 tkn.pushBack(); 627 int nextVal = getIntOrCP(); 628 reqVal = " " + nextVal; 629 rval = (val == nextVal); 631 } 632 if (rval == false) 633 fail("Failed - wrong val = " + val + " Required Value: " + reqVal); 634 635 return rval; 636 } 637 638 639 642 private int getIntOrCP() throws IOException 643 { 644 int val = tkn.nextToken(); 645 if (val == StreamTokenizer.TT_NUMBER) 646 { 647 return new Double (tkn.nval).intValue(); 648 } 649 else if (val == StreamTokenizer.TT_WORD) 650 { 651 return decodeCP(tkn.sval); 652 } 653 else 654 { 655 fail("Expecting number, got " + tkn.sval + " on line " 656 + tkn.lineno()); 657 System.exit(1); 658 } 659 return 0; 660 } 661 669 private byte [] getBytes() throws IOException 670 { 671 byte[] retval = null; 672 int val = tkn.nextToken(); 673 if (tkn.sval == null) 674 { 675 System.err.println("Invalid string on line " + tkn.lineno()); 676 System.exit(1); 677 } 678 String str = tkn.sval.toLowerCase(Locale.ENGLISH); 679 if (!str.startsWith("0x")) 680 { 681 return ccsidManager.convertFromUCS2(str); 683 } 684 else 685 { 686 int len = str.length(); 687 if ((len % 2) == 1) 688 { 689 System.err.println("Invalid length for byte string, " + len + 690 " on line " + tkn.lineno()); 691 System.exit(1); 692 } 693 retval = new byte[(len-2)/2]; 694 int j = 0; 695 for (int i = 2; i < len; i+=2, j++) 696 { 697 retval[j] = (byte)(Byte.valueOf(str.substring(i, i+1), 16).byteValue() << 4); 698 retval[j] += Byte.valueOf(str.substring(i+1, i+2), 16).byteValue(); 699 } 700 } 701 return retval; 702 } 703 709 private String getString() throws IOException 710 { 711 int val = tkn.nextToken(); 712 if (val == StreamTokenizer.TT_NUMBER) 713 { 714 System.err.println("Expecting word, got " + tkn.nval + " on line " + tkn.lineno()); 715 System.exit(1); 716 } 717 return tkn.sval; 718 } 719 724 private int getCP() throws IOException 725 { 726 String strval = getString(); 727 return decodeCP(strval); 728 } 729 735 private int decodeCP(String strval) 736 { 737 Integer cp = (Integer )codePointValueTable.get(strval); 738 if (cp == null) 739 { 740 System.err.println("Unknown codepoint, "+ strval + " in line " 741 + tkn.lineno()); 742 Exception e = new Exception (); 743 e.printStackTrace(); 744 System.exit(1); 745 } 746 return cp.intValue(); 747 } 748 753 private void fail(String msg) throws IOException 754 { 755 System.out.println("FAILED - " + msg + " in line " + tkn.lineno()); 756 int val = tkn.nextToken(); 758 while (val != StreamTokenizer.TT_EOF) 759 { 760 if (val == StreamTokenizer.TT_WORD && tkn.sval.toLowerCase(Locale.ENGLISH).equals("endtest")) 761 break; 762 763 val = tkn.nextToken(); 764 } 765 failed = true; 766 reset(); 768 Exception e = new Exception (); 770 e.printStackTrace(); 771 } 772 777 private void checkError() throws IOException , DRDAProtocolException 778 { 779 int svrcod = 0; 780 int invalidCodePoint = 0; 781 int prccnvcd = 0; 782 int synerrcd = 0; 783 int codepoint; 784 int reqVal; 785 Vector manager = new Vector (), managerLevel = new Vector () ; 786 reader.readReplyDss(); 787 int error = reader.readLengthAndCodePoint(); 788 int reqCP = getCP(); 789 if (error != reqCP) 790 { 791 cpError(error, reqCP); 792 return; 793 } 794 while (reader.moreDssData()) 795 { 796 codepoint = reader.readLengthAndCodePoint(); 797 switch (codepoint) 798 { 799 case CodePoint.SVRCOD: 800 svrcod = reader.readNetworkShort(); 801 break; 802 case CodePoint.CODPNT: 803 invalidCodePoint = reader.readNetworkShort(); 804 break; 805 case CodePoint.PRCCNVCD: 806 prccnvcd = reader.readByte(); 807 break; 808 case CodePoint.SYNERRCD: 809 synerrcd = reader.readByte(); 810 break; 811 case CodePoint.MGRLVLLS: 812 while (reader.moreDdmData()) 813 { 814 manager.addElement(new Integer (reader.readNetworkShort())); 815 managerLevel.addElement(new Integer (reader.readNetworkShort())); 816 } 817 break; 818 default: 819 reader.skipBytes(); 821 822 } 823 } 824 reqVal = getInt(); 825 if (svrcod != reqVal) 826 { 827 fail("wrong svrcod val = " + Integer.toHexString(svrcod) 828 + ", required val = " + Integer.toHexString(reqVal)); 829 return; 830 } 831 if (error == CodePoint.PRCCNVRM) 832 { 833 reqVal = getInt(); 834 if (prccnvcd != reqVal) 835 { 836 fail("wrong prccnvd, val = " + Integer.toHexString(prccnvcd) 837 + ", required val = " + Integer.toHexString(reqVal)); 838 return; 839 } 840 } 841 if (error == CodePoint.SYNTAXRM) 842 { 843 reqVal = getInt(); 844 if (synerrcd != reqVal) 845 { 846 fail("wrong synerrcd, val = " + Integer.toHexString(synerrcd) 847 + ", required val = " + Integer.toHexString(reqVal)); 848 return; 849 } 850 reqVal = getIntOrCP(); 851 if (invalidCodePoint != reqVal) 852 { 853 cpError(invalidCodePoint, reqVal); 854 return; 855 } 856 } 857 if (error == CodePoint.MGRLVLRM) 858 { 859 int mgr, mgrLevel; 860 for (int i = 0; i < manager.size(); i++) 861 { 862 reqVal = getCP(); 863 mgr = ((Integer )(manager.elementAt(i))).intValue(); 864 if (mgr != reqVal) 865 { 866 cpError(mgr, reqVal); 867 return; 868 } 869 mgrLevel = ((Integer )(managerLevel.elementAt(i))).intValue(); 870 reqVal = getInt(); 871 if (mgrLevel != reqVal) 872 { 873 fail("wrong manager level, level = " + Integer.toHexString(mgrLevel) 874 + ", required val = " + Integer.toHexString(reqVal)); 875 return; 876 } 877 } 878 } 879 } 880 885 private void readLengthAndCodePoint() throws IOException , DRDAProtocolException 886 { 887 int codepoint = reader.readLengthAndCodePoint(); 888 int reqCP = getCP(); 889 if (codepoint != reqCP) 890 cpError(codepoint, reqCP); 891 } 892 893 901 private void readSecMecAndSECCHKCD() throws IOException , DRDAProtocolException 902 { 903 int codepoint; 904 boolean notDone = true; 905 int val = -1; 906 do 907 { 908 codepoint = reader.readLengthAndCodePoint(); 909 switch(codepoint) 910 { 911 case CodePoint.SECMEC: 912 { 913 System.out.print("SECMEC="); 914 val = reader.readNetworkShort(); 915 System.out.print(val+" "); 916 } 917 break; 918 case CodePoint.SECCHKCD: 919 { 920 System.out.print("SECCHKCD="); 921 val = reader.readByte(); 922 System.out.println(val); 923 notDone = false; 924 } 925 break; 926 default: 927 notDone=false; 928 } 929 }while(notDone); 930 } 931 932 933 938 private void cpError(int cp, int reqCP) throws IOException 939 { 940 String cpName = codePointNameTable.lookup(cp); 941 String reqCPName = codePointNameTable.lookup(reqCP); 942 fail("wrong codepoint val = " + Integer.toHexString(cp) + 943 "("+cpName+")" + 944 ", required codepoint = " + Integer.toHexString(reqCP) + 945 "("+reqCPName+")"); 946 } 947 953 private byte[] getEBCDIC(String str) 954 { 955 byte [] buf = new byte[str.length()]; 956 ccsidManager.convertFromUCS2(str, buf, 0); 957 return buf; 958 } 959 966 private void writeEncodedString(String str, String encoding) 967 throws IOException 968 { 969 try { 970 byte [] buf = str.getBytes(encoding); 971 writer.writeBytes(buf); 972 } catch (UnsupportedEncodingException e) { 973 fail("Unsupported encoding " + encoding); 974 } 975 } 976 984 private void writeEncodedLDString(String str, String encoding, int len) 985 throws IOException 986 { 987 try { 988 byte [] buf = str.getBytes(encoding); 989 if (len == 2) 990 writer.writeShort(buf.length); 991 else 992 writer.writeInt(buf.length); 993 writer.writeBytes(buf); 994 } catch (UnsupportedEncodingException e) { 995 fail("Unsupported encoding " + encoding); 996 } 997 } 998 1005 private void checkSQLCARD(int sqlCode, String sqlState) 1006 throws IOException , DRDAProtocolException 1007 { 1008 reader.readReplyDss(); 1009 int codepoint = reader.readLengthAndCodePoint(); 1010 if (codepoint != CodePoint.SQLCARD) 1011 { 1012 fail("Expecting SQLCARD got "+ Integer.toHexString(codepoint)); 1013 return; 1014 } 1015 int nullind = reader.readByte(); 1016 int code = reader.readNetworkInt(); 1018 if (code != sqlCode) 1019 { 1020 fail("Expecting sqlCode " + sqlCode + " got "+ Integer.toHexString(code)); 1021 return; 1022 } 1023 String state = reader.readString(5, "UTF-8"); 1024 if (!state.equals(sqlState)) 1025 { 1026 fail("Expecting sqlState " + sqlState + " got "+ state); 1027 return; 1028 } 1029 reader.skipBytes(); 1031 } 1032 1033 private static String getHostName() 1034 { 1035 String hostName = (System.getProperty("hostName")); 1036 if (hostName == null) 1037 hostName="localhost"; 1038 return hostName; 1039 } 1040} 1041 | Popular Tags |