~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/orber/doc/src/Orber/InitialReference.java

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * %CopyrightBegin%
 
3
 * 
 
4
 * Copyright Ericsson AB 1997-2009. All Rights Reserved.
 
5
 * 
 
6
 * The contents of this file are subject to the Erlang Public License,
 
7
 * Version 1.1, (the "License"); you may not use this file except in
 
8
 * compliance with the License. You should have received a copy of the
 
9
 * Erlang Public License along with this software. If not, it can be
 
10
 * retrieved online at http://www.erlang.org/.
 
11
 * 
 
12
 * Software distributed under the License is distributed on an "AS IS"
 
13
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
 * the License for the specific language governing rights and limitations
 
15
 * under the License.
 
16
 * 
 
17
 * %CopyrightEnd%
 
18
 *
 
19
 */
 
20
/**
 
21
 * InitialReference is a class which generates the INIT reference
 
22
 * which can be used by the InitialReferences interface.
 
23
 */
 
24
package Orber;
 
25
 
 
26
public class InitialReference 
 
27
{
 
28
 
 
29
  /**
 
30
   * Constructor.
 
31
   */
 
32
  public InitialReference(){;}
 
33
 
 
34
  /**
 
35
   * Returns the stringified objectreference to the initial reference server
 
36
   */
 
37
  public String stringified_ior(String host, int port)
 
38
    {
 
39
      String iorByteString;
 
40
      String profileData;
 
41
      String iorString;
 
42
 
 
43
      // byte_order followed by ' {"", [{0, ' 
 
44
      //      char iorBytesFirstPart[] = {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0};
 
45
      char iorBytesFirstPart[] = {0,0,0,0,0,0,0,32,73,68,76,58,79,114,98,101,114,47,73,110,105,116,105,97,108,82,101,102,101,114,101,110,99,101,115,58,49,46,48,0,0,0,0,1,0,0,0,0};
 
46
      // the objectkey "INIT
 
47
      char iorBytesLastPart[] = {0,0,0,4,73,78,73,84};
 
48
 
 
49
      // Fix the ProfileData struct.
 
50
      char pdPrefix[] = {0,1,0,0};
 
51
      char nullbyte[] = {0};
 
52
      profileData = new String(pdPrefix) + enc_ulong(host.length() + 1) + host + new String(nullbyte);
 
53
      profileData = align(profileData, 2);
 
54
      profileData +=  enc_ushort(port);
 
55
      profileData = align(profileData, 4);
 
56
      profileData += new String(iorBytesLastPart);
 
57
      // Fix the whole IOR
 
58
      iorByteString = new String(iorBytesFirstPart) + enc_ulong(profileData.length()) +
 
59
        profileData;
 
60
 
 
61
      //      System.out.print("Start[" + profileData.length() + "]");
 
62
      //      System.out.print("[");
 
63
      //      for(int x = 0; x < iorByteString.length(); x++)
 
64
      //        {
 
65
      //          System.out.print((int) iorByteString.charAt(x) + ",");
 
66
      //        }
 
67
      //      System.out.println("]");
 
68
 
 
69
      iorString = createIOR(iorByteString);
 
70
      //      System.out.println(iorString);
 
71
      return iorString;
 
72
    }
 
73
 
 
74
 
 
75
  private String enc_ushort(int s)
 
76
    {
 
77
      char byteArray[] = {(char) ((s >>> 8) & 0xFF),
 
78
                          (char) ((s >>> 0) & 0xFF)};
 
79
 
 
80
      return new String(byteArray);
 
81
    }
 
82
 
 
83
  private String enc_ulong(int l)
 
84
    {
 
85
      char byteArray[] = {(char) ((l >>> 24) & 0xFF),
 
86
                          (char) ((l >>> 16) & 0xFF),
 
87
                          (char) ((l >>> 8) & 0xFF),
 
88
                          (char) ((l >>> 0) & 0xFF)};
 
89
 
 
90
      return new String(byteArray);
 
91
 
 
92
    }
 
93
 
 
94
  private String createIOR(String bytes)
 
95
    {
 
96
      int i;
 
97
      StringBuffer sb = new StringBuffer("IOR:");
 
98
 
 
99
      for(i = 0; i < bytes.length(); i++)
 
100
        {
 
101
          int b = bytes.charAt(i);
 
102
          if(b<0) b+= 256;
 
103
          int n1 = b / 16;
 
104
          int n2 = b % 16;
 
105
          int c1 = (n1 < 10) ? ('0' + n1) : ('a' + (n1 - 10));
 
106
          int c2 = (n2 < 10) ? ('0' + n2) : ('a' + (n2 - 10));
 
107
          sb.append((char)c1);
 
108
          sb.append((char)c2);    
 
109
        }
 
110
 
 
111
      return sb.toString();
 
112
    }
 
113
 
 
114
  private String align(String buffer, int alignment)
 
115
    {
 
116
      String s = buffer;
 
117
      char nullbyte[] = {0};
 
118
 
 
119
      int remainder = alignment - (buffer.length() % alignment);
 
120
      if (remainder == alignment) return s;
 
121
 
 
122
      for (int i = 0; i < remainder; i++)
 
123
        {
 
124
          s += new String(nullbyte);
 
125
        }
 
126
      return s;
 
127
    }
 
128
 
 
129
  
 
130
}